Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce the public exposure of netcards_dict
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 17 Dec 2016 18:14:40 +0000 (19:14 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 17 Dec 2016 18:14:40 +0000 (19:14 +0100)
include/simgrid/s4u/engine.hpp
src/instr/instr_paje_containers.cpp
src/kernel/routing/NetCard.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/VivaldiZone.cpp
src/s4u/s4u_engine.cpp
src/surf/sg_platf.cpp
teshsuite/surf/maxmin_bench/maxmin_bench_medium.tesh
teshsuite/surf/maxmin_bench/maxmin_bench_small.tesh

index c89b3e2..a6ee0bd 100644 (file)
@@ -66,12 +66,15 @@ public:
   /** @brief Retrieve the engine singleton */
   static s4u::Engine *instance();
 
-  /** @brief Retrieve the root AS, containing all others */
+  /** @brief Retrieve the root netzone, containing all others */
   simgrid::s4u::NetZone* netRoot();
 
-  /** @brief Retrieve the AS of the given name (or nullptr if not found) */
+  /** @brief Retrieve the netzone of the given name (or nullptr if not found) */
   simgrid::s4u::NetZone* netzoneByNameOrNull(const char* name);
 
+  /** @brief Retrieve the netcard of the given name (or nullptr if not found) */
+  simgrid::kernel::routing::NetCard* netcardByNameOrNull(const char* name);
+
   template<class F>
   void registerFunction(const char* name)
   {
index 4ca2981..6af90f2 100644 (file)
@@ -4,7 +4,8 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include <simgrid/s4u/host.hpp>
+#include "simgrid/s4u/engine.hpp"
+#include "simgrid/s4u/host.hpp"
 
 #include <xbt/dict.h>
 #include <xbt/lib.h>
@@ -71,11 +72,11 @@ container_t PJ_container_new (const char *name, e_container_types kind, containe
       xbt_assert(newContainer->netcard, "Element '%s' not found",name);
       break;
     case INSTR_ROUTER:
-      newContainer->netcard = static_cast<sg_netcard_t>(xbt_dict_get_or_null(netcards_dict, name));
+      newContainer->netcard = simgrid::s4u::Engine::instance()->netcardByNameOrNull(name);
       xbt_assert(newContainer->netcard, "Element '%s' not found",name);
       break;
     case INSTR_AS:
-      newContainer->netcard = static_cast<sg_netcard_t>(xbt_dict_get_or_null(netcards_dict, name));
+      newContainer->netcard = simgrid::s4u::Engine::instance()->netcardByNameOrNull(name);
       xbt_assert(newContainer->netcard, "Element '%s' not found",name);
       break;
     default:
index 26f551c..799983e 100644 (file)
@@ -5,8 +5,9 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "src/kernel/routing/NetCard.hpp"
+#include "simgrid/s4u/engine.hpp"
+#include "simgrid/s4u/host.hpp"
 #include "surf/surf_routing.h"
-#include <simgrid/s4u/host.hpp>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route, surf, "Routing part of surf");
 
@@ -26,6 +27,5 @@ simgrid::xbt::signal<void(NetCard*)> NetCard::onCreation;
 simgrid::kernel::routing::NetCard* sg_netcard_by_name_or_null(const char* name)
 {
   sg_host_t host = sg_host_by_name(name);
-  return (host != nullptr) ? host->pimpl_netcard
-                           : static_cast<simgrid::kernel::routing::NetCard*>(xbt_dict_get_or_null(netcards_dict, name));
+  return (host != nullptr) ? host->pimpl_netcard : simgrid::s4u::Engine::instance()->netcardByNameOrNull(name);
 }
index 2944f7b..57619a8 100644 (file)
@@ -3,14 +3,15 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include "xbt/log.h"
-
+#include "src/kernel/routing/NetZoneImpl.hpp"
+#include "simgrid/s4u/engine.hpp"
 #include "simgrid/s4u/host.hpp"
 #include "src/kernel/routing/NetCard.hpp"
-#include "src/kernel/routing/NetZoneImpl.hpp"
 #include "src/surf/cpu_interface.hpp"
 #include "src/surf/network_interface.hpp"
 
+#include "xbt/log.h"
+
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_route);
 
 namespace simgrid {
@@ -27,8 +28,8 @@ public:
 
 NetZoneImpl::NetZoneImpl(NetZone* father, const char* name) : NetZone(father, name)
 {
-  xbt_assert(nullptr == xbt_dict_get_or_null(netcards_dict, name), "Refusing to create a second NetZone called '%s'.",
-             name);
+  xbt_assert(nullptr == simgrid::s4u::Engine::instance()->netcardByNameOrNull(name),
+             "Refusing to create a second NetZone called '%s'.", name);
 
   netcard_ = new NetCard(name, NetCard::Type::NetZone, static_cast<NetZoneImpl*>(father));
   xbt_dict_set(netcards_dict, name, static_cast<void*>(netcard_), nullptr);
index 04b14a6..7549998 100644 (file)
@@ -5,7 +5,8 @@
 
 #include <boost/algorithm/string.hpp>
 
-#include <simgrid/s4u/host.hpp>
+#include "simgrid/s4u/engine.hpp"
+#include "simgrid/s4u/host.hpp"
 
 #include "src/kernel/routing/NetCard.hpp"
 #include "src/kernel/routing/VivaldiZone.hpp"
@@ -80,8 +81,8 @@ void VivaldiZone::getLocalRoute(NetCard* src, NetCard* dst, sg_platf_route_cbarg
   if (src->isNetZone()) {
     char* srcName = bprintf("router_%s", src->cname());
     char* dstName = bprintf("router_%s", dst->cname());
-    route->gw_src = (sg_netcard_t)xbt_dict_get_or_null(netcards_dict, srcName);
-    route->gw_dst = (sg_netcard_t)xbt_dict_get_or_null(netcards_dict, dstName);
+    route->gw_src = simgrid::s4u::Engine::instance()->netcardByNameOrNull(srcName);
+    route->gw_dst = simgrid::s4u::Engine::instance()->netcardByNameOrNull(dstName);
     xbt_free(srcName);
     xbt_free(dstName);
   }
index 0f8798d..71bf838 100644 (file)
@@ -111,5 +111,10 @@ NetZone* Engine::netzoneByNameOrNull(const char* name)
   return netzoneByNameRecursive(netRoot(), name);
 }
 
+/** @brief Retrieve the netcard of the given name (or nullptr if not found) */
+simgrid::kernel::routing::NetCard* Engine::netcardByNameOrNull(const char* name)
+{
+  return static_cast<simgrid::kernel::routing::NetCard*>(xbt_dict_get_or_null(netcards_dict, name));
+}
 }
 }
index af64bde..9c95b66 100644 (file)
@@ -115,7 +115,7 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router)
 
   if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)
     current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base;
-  xbt_assert(nullptr == xbt_dict_get_or_null(netcards_dict, router->id),
+  xbt_assert(nullptr == simgrid::s4u::Engine::instance()->netcardByNameOrNull(router->id),
              "Refusing to create a router named '%s': this name already describes a node.", router->id);
 
   simgrid::kernel::routing::NetCard* netcard =
@@ -307,7 +307,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
   if (!router.id || !strcmp(router.id, ""))
     router.id = newid = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix);
   sg_platf_new_router(&router);
-  current_as->router_ = (simgrid::kernel::routing::NetCard*)xbt_dict_get_or_null(netcards_dict, router.id);
+  current_as->router_ = simgrid::s4u::Engine::instance()->netcardByNameOrNull(router.id);
   free(newid);
 
   //Make the backbone
index 8ececd2..a7e4472 100644 (file)
@@ -5,7 +5,6 @@
 ! output sort
 $ $SG_TEST_EXENV ${bindir:=.}/maxmin_bench medium 5 test
 > [0.000000]: [surf_kernel/DEBUG] Add SURF levels
-> [0.000000]: [surf_kernel/DEBUG] Add routing levels
 > [0.000000]: [surf_kernel/DEBUG] Create all Libs
 > [0.000000]: [surf_maxmin/DEBUG] Setting selective_update_active flag to 1
 > [0.000000]: [surf_maxmin/DEBUG] Active constraints : 100
index 3033535..b3edd1c 100644 (file)
@@ -5,7 +5,6 @@
 ! output sort
 $ $SG_TEST_EXENV ${bindir:=.}/maxmin_bench small  10 test
 > [0.000000]: [surf_kernel/DEBUG] Add SURF levels
-> [0.000000]: [surf_kernel/DEBUG] Add routing levels
 > [0.000000]: [surf_kernel/DEBUG] Create all Libs
 > [0.000000]: [surf_maxmin/DEBUG] Setting selective_update_active flag to 1
 > [0.000000]: [surf_maxmin/DEBUG] Active constraints : 10