Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
split NetZone and NetZoneImpl as it should in s4u realm
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 23 Jun 2018 18:52:13 +0000 (20:52 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 23 Jun 2018 19:23:24 +0000 (21:23 +0200)
32 files changed:
include/simgrid/kernel/routing/ClusterZone.hpp
include/simgrid/kernel/routing/DijkstraZone.hpp
include/simgrid/kernel/routing/DragonflyZone.hpp
include/simgrid/kernel/routing/EmptyZone.hpp
include/simgrid/kernel/routing/FatTreeZone.hpp
include/simgrid/kernel/routing/FloydZone.hpp
include/simgrid/kernel/routing/FullZone.hpp
include/simgrid/kernel/routing/NetZoneImpl.hpp
include/simgrid/kernel/routing/RoutedZone.hpp
include/simgrid/kernel/routing/TorusZone.hpp
include/simgrid/kernel/routing/VivaldiZone.hpp
include/simgrid/s4u/Engine.hpp
include/simgrid/s4u/NetZone.hpp
src/bindings/java/jmsg_as.cpp
src/bindings/lua/lua_platf.cpp
src/instr/instr_platform.cpp
src/instr/jedule/jedule_platform.cpp
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/DijkstraZone.cpp
src/kernel/routing/DragonflyZone.cpp
src/kernel/routing/EmptyZone.cpp
src/kernel/routing/FatTreeZone.cpp
src/kernel/routing/FloydZone.cpp
src/kernel/routing/FullZone.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/RoutedZone.cpp
src/kernel/routing/TorusZone.cpp
src/kernel/routing/VivaldiZone.cpp
src/s4u/s4u_Engine.cpp
src/s4u/s4u_Netzone.cpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp

index cb1d330..c3135dc 100644 (file)
@@ -67,7 +67,7 @@ namespace routing {
 
 class ClusterZone : public NetZoneImpl {
 public:
-  explicit ClusterZone(NetZone* father, std::string name);
+  explicit ClusterZone(NetZoneImpl* father, std::string name);
 
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   void get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
index bf7fe76..c435463 100644 (file)
@@ -33,7 +33,7 @@ namespace routing {
  */
 class XBT_PRIVATE DijkstraZone : public RoutedZone {
 public:
-  DijkstraZone(NetZone* father, std::string name, bool cached);
+  DijkstraZone(NetZoneImpl* father, std::string name, bool cached);
   void seal() override;
 
   ~DijkstraZone() override;
index 193f109..c300f7a 100644 (file)
@@ -61,7 +61,7 @@ public:
  */
 class XBT_PUBLIC DragonflyZone : public ClusterZone {
 public:
-  explicit DragonflyZone(NetZone* father, std::string name);
+  explicit DragonflyZone(NetZoneImpl* father, std::string name);
   ~DragonflyZone() override;
   //      void create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int rank, int position) override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
index 421e552..b015de0 100644 (file)
@@ -21,7 +21,7 @@ namespace routing {
 
 class XBT_PRIVATE EmptyZone : public NetZoneImpl {
 public:
-  explicit EmptyZone(NetZone* father, std::string name);
+  explicit EmptyZone(NetZoneImpl* father, std::string name);
   ~EmptyZone() override;
 
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override
index 7fbf25f..e39ef33 100644 (file)
@@ -98,7 +98,7 @@ public:
  */
 class XBT_PRIVATE FatTreeZone : public ClusterZone {
 public:
-  explicit FatTreeZone(NetZone* father, std::string name);
+  explicit FatTreeZone(NetZoneImpl* father, std::string name);
   ~FatTreeZone() override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
 
index 92fe57f..172c694 100644 (file)
@@ -23,7 +23,7 @@ namespace routing {
  */
 class XBT_PRIVATE FloydZone : public RoutedZone {
 public:
-  explicit FloydZone(NetZone* father, std::string name);
+  explicit FloydZone(NetZoneImpl* father, std::string name);
   ~FloydZone() override;
 
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
index 99722a1..bbf16f6 100644 (file)
@@ -20,7 +20,7 @@ namespace routing {
  */
 class XBT_PRIVATE FullZone : public RoutedZone {
 public:
-  explicit FullZone(NetZone* father, std::string name);
+  explicit FullZone(NetZoneImpl* father, std::string name);
   void seal() override;
   ~FullZone() override;
 
index fd6aff2..39d737c 100644 (file)
@@ -11,6 +11,7 @@
 #include <xbt/graph.h>
 
 #include <map>
+#include <vector>
 
 namespace simgrid {
 namespace kernel {
@@ -46,20 +47,31 @@ class BypassRoute;
  * called Autonomous Systems in this article).
  *
  */
-class XBT_PUBLIC NetZoneImpl : public s4u::NetZone {
+class XBT_PUBLIC NetZoneImpl {
   friend simgrid::kernel::EngineImpl; // it destroys netRoot_
 
 protected:
-  explicit NetZoneImpl(NetZone* father, std::string name);
+  explicit NetZoneImpl(NetZoneImpl* father, std::string name);
   virtual ~NetZoneImpl();
 
+  s4u::NetZone piface_;
+
 public:
+  s4u::NetZone* get_iface() { return &piface_; }
+
   /** @brief Make an host within that NetZone */
   simgrid::s4u::Host* create_host(const char* name, std::vector<double>* speed_per_pstate, int core_count,
                                   std::map<std::string, std::string>* props);
   /** @brief Creates a new route in this NetZone */
-  void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
-                        std::vector<resource::LinkImpl*>& link_list, bool symmetrical) override;
+  virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
+                                std::vector<resource::LinkImpl*>& link_list, bool symmetrical);
+
+  /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */
+  virtual void seal();
+  virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
+  virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
+                         kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
+                         std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
 
 protected:
   /**
@@ -76,7 +88,35 @@ protected:
   bool get_bypass_route(routing::NetPoint* src, routing::NetPoint* dst,
                         /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency);
 
+private:
+  // our content, as known to our graph routing algorithm (maps vertex_id -> vertex)
+  std::vector<kernel::routing::NetPoint*> vertices_;
+
+  NetZoneImpl* father_ = nullptr;
+
+  std::vector<NetZoneImpl*> children_; // sub-netzones
+
 public:
+  unsigned int get_table_size() { return vertices_.size(); }
+  std::vector<kernel::routing::NetPoint*> get_vertices() { return vertices_; }
+
+  NetZoneImpl* get_father();
+
+  std::vector<NetZoneImpl*>* get_children(); // Sub netzones
+
+private:
+  std::string name_;
+  bool sealed_ = false; // We cannot add more content when sealed
+
+public:
+  /** @brief Retrieves the name of that netzone as a C++ string */
+  const std::string& get_name() const { return name_; }
+  /** @brief Retrieves the name of that netzone as a C string */
+  const char* get_cname() const;
+
+  std::vector<s4u::Host*> get_all_hosts();
+  int get_host_count();
+
   /* @brief get the route between two nodes in the full platform
    *
    * @param src where from
index 097e849..0d19377 100644 (file)
@@ -50,7 +50,7 @@ namespace routing {
 
 class XBT_PRIVATE RoutedZone : public NetZoneImpl {
 public:
-  explicit RoutedZone(NetZone* father, std::string name);
+  explicit RoutedZone(NetZoneImpl* father, std::string name);
 
   void get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
                  std::map<std::string, xbt_edge_t>* edges) override;
index 22a172e..29e9855 100644 (file)
@@ -21,7 +21,7 @@ namespace routing {
 
 class XBT_PRIVATE TorusZone : public ClusterZone {
 public:
-  explicit TorusZone(NetZone* father, std::string name);
+  explicit TorusZone(NetZoneImpl* father, std::string name);
   void create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, unsigned int position) override;
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
   void parse_specific_arguments(ClusterCreationArgs* cluster) override;
index d1bc241..873eddd 100644 (file)
@@ -46,7 +46,7 @@ namespace routing {
 
 class XBT_PRIVATE VivaldiZone : public ClusterZone {
 public:
-  explicit VivaldiZone(NetZone* father, std::string name);
+  explicit VivaldiZone(NetZoneImpl* father, std::string name);
 
   void set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, std::string coord);
   void get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* into, double* latency) override;
index 7f9c0ef..d30bc2f 100644 (file)
@@ -132,6 +132,8 @@ public:
   /** @brief Retrieves all netzones of the type indicated by the template argument */
   template <class T> std::vector<T*> get_filtered_netzones()
   {
+    static_assert(std::is_base_of<kernel::routing::NetZoneImpl, T>::value,
+                  "Filtering netzones is only possible for subclasses of kernel::routing::NetZoneImpl");
     std::vector<T*> res;
     get_filtered_netzones_recursive(get_netzone_root(), &res);
     return res;
@@ -271,10 +273,12 @@ extern XBT_PUBLIC xbt::signal<void(void)> on_deadlock;
 
 template <class T> XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone* current, std::vector<T*>* whereto)
 {
-  for (auto const& elem : *(current->get_children())) {
+  static_assert(std::is_base_of<kernel::routing::NetZoneImpl, T>::value,
+                "Filtering netzones is only possible for subclasses of kernel::routing::NetZoneImpl");
+  for (auto const& elem : current->get_children()) {
     get_filtered_netzones_recursive(elem, whereto);
-    if (elem == dynamic_cast<T*>(elem))
-      whereto->push_back(dynamic_cast<T*>(elem));
+    if (elem->get_impl() == dynamic_cast<T*>(elem->get_impl()))
+      whereto->push_back(dynamic_cast<T*>(elem->get_impl()));
   }
 }
 }
index 5229b92..f43ca18 100644 (file)
@@ -27,23 +27,24 @@ class XBT_PUBLIC NetZone {
 protected:
   friend simgrid::kernel::routing::NetZoneImpl;
 
-  explicit NetZone(NetZone * father, std::string name);
-  virtual ~NetZone();
+  explicit NetZone(kernel::routing::NetZoneImpl* impl);
+  ~NetZone();
+
+  kernel::routing::NetZoneImpl* pimpl_;
 
 public:
-  /** @brief Seal your netzone once you're done adding content, and before routing stuff through it */
-  virtual void seal();
   /** @brief Retrieves the name of that netzone as a C++ string */
-  const std::string& get_name() const { return name_; }
+  const std::string& get_name() const;
   /** @brief Retrieves the name of that netzone as a C string */
   const char* get_cname() const;
 
   NetZone* get_father();
-  std::vector<NetZone*>* get_children(); // Sub netzones
 
   std::vector<Host*> get_all_hosts();
   int get_host_count();
 
+  kernel::routing::NetZoneImpl* get_impl() { return pimpl_; }
+
 private:
   std::unordered_map<std::string, std::string> properties_;
 
@@ -51,18 +52,20 @@ public:
   /** Get the properties assigned to a netzone */
   std::unordered_map<std::string, std::string>* get_properties();
 
+  std::vector<NetZone*> get_children();
+
   /** Retrieve the property value (or nullptr if not set) */
   const char* get_property(const char* key);
   void set_property(const char* key, const char* value);
 
   /* Add content to the netzone, at parsing time. It should be sealed afterward. */
-  virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
-  virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
-                         kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
-                         std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
-  virtual void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
-                                kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
-                                std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical) = 0;
+  int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */
+  void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, kernel::routing::NetPoint* gw_src,
+                 kernel::routing::NetPoint* gw_dst, std::vector<kernel::resource::LinkImpl*>& link_list,
+                 bool symmetrical);
+  void add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
+                        kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
+                        std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical);
 
   /*** Called on each newly created regular route (not on bypass routes) */
   static simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
@@ -72,22 +75,6 @@ public:
   static simgrid::xbt::signal<void(NetZone&)> on_creation;
   static simgrid::xbt::signal<void(NetZone&)> on_seal;
 
-private:
-  // our content, as known to our graph routing algorithm (maps vertex_id -> vertex)
-  std::vector<kernel::routing::NetPoint*> vertices_;
-
-protected:
-  unsigned int get_table_size() { return vertices_.size(); }
-  std::vector<kernel::routing::NetPoint*> get_vertices() { return vertices_; }
-
-private:
-  NetZone* father_ = nullptr;
-  std::string name_;
-
-  bool sealed_ = false; // We cannot add more content when sealed
-
-  std::vector<NetZone*>* children_ = nullptr; // sub-netzones
-
 public: // Deprecation wrappers
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_father()") NetZone* getFather() { return get_father(); }
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_name()") const std::string& getName() const { return get_name(); }
@@ -116,21 +103,20 @@ public: // Deprecation wrappers
   {
     set_property(key, value);
   }
-  XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::add_component()") virtual int addComponent(
-      kernel::routing::NetPoint* elm)
+  XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::add_component()") int addComponent(kernel::routing::NetPoint* elm)
   {
     return add_component(elm);
   }
-  XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_vertices()") std::vector<kernel::routing::NetPoint*> getVertices()
-  {
-    return get_vertices();
-  }
+  XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_vertices()") std::vector<kernel::routing::NetPoint*> getVertices();
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_host_count()") int getHostCount() { return get_host_count(); }
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_all_hosts()") void getHosts(
       std::vector<s4u::Host*>* whereto); // retrieve my content as a vector of hosts
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_children()") std::vector<NetZone*>* getChildren()
   {
-    return get_children();
+    std::vector<NetZone*>* res = new std::vector<NetZone*>();
+    for (auto child : get_children())
+      res->push_back(child);
+    return res;
   }
 };
 }
index 2e08d3b..0d4d89f 100644 (file)
@@ -69,14 +69,14 @@ JNIEXPORT jobjectArray JNICALL Java_org_simgrid_msg_As_getSons(JNIEnv * env, job
   if (not cls)
     return nullptr;
 
-  jtable = env->NewObjectArray(static_cast<jsize>(self_as->get_children()->size()), cls, nullptr);
+  jtable = env->NewObjectArray(static_cast<jsize>(self_as->get_children().size()), cls, nullptr);
 
   if (not jtable) {
     jxbt_throw_jni(env, "Hosts table allocation failed");
     return nullptr;
   }
 
-  for (auto const& tmp_as : *self_as->get_children()) {
+  for (auto const& tmp_as : self_as->get_children()) {
     jobject tmp_jas = jnetzone_new_instance(env);
     if (not tmp_jas) {
       jxbt_throw_jni(env, "java As instantiation failed");
index dac0399..1b8431d 100644 (file)
@@ -476,12 +476,12 @@ int console_AS_open(lua_State *L) {
  simgrid::kernel::routing::ZoneCreationArgs AS;
  AS.id = id;
  AS.routing = mode_int;
- simgrid::s4u::NetZone* new_as = sg_platf_new_Zone_begin(&AS);
+ simgrid::kernel::routing::NetZoneImpl* new_as = sg_platf_new_Zone_begin(&AS);
 
  /* Build a Lua representation of the new AS on the stack */
  lua_newtable(L);
- simgrid::s4u::NetZone** lua_as =
-     (simgrid::s4u::NetZone**)lua_newuserdata(L, sizeof(simgrid::s4u::NetZone*)); /* table userdatum */
+ simgrid::kernel::routing::NetZoneImpl** lua_as = (simgrid::kernel::routing::NetZoneImpl**)lua_newuserdata(
+     L, sizeof(simgrid::kernel::routing::NetZoneImpl*)); /* table userdatum */
  *lua_as = new_as;
  luaL_getmetatable(L, PLATF_MODULE_NAME); /* table userdatum metatable */
  lua_setmetatable(L, -2);                 /* table userdatum */
index 0184c25..ec0639d 100644 (file)
@@ -127,9 +127,9 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t
     return;
   }
   XBT_DEBUG("Graph extraction for NetZone = %s", netzone->get_cname());
-  if (not netzone->get_children()->empty()) {
+  if (not netzone->get_children().empty()) {
     // bottom-up recursion
-    for (auto const& nz_son : *netzone->get_children()) {
+    for (auto const& nz_son : netzone->get_children()) {
       container_t child_container = container->children_.at(nz_son->get_cname());
       recursiveGraphExtraction(nz_son, child_container, filter);
     }
@@ -139,7 +139,7 @@ static void recursiveGraphExtraction(simgrid::s4u::NetZone* netzone, container_t
   std::map<std::string, xbt_node_t>* nodes = new std::map<std::string, xbt_node_t>;
   std::map<std::string, xbt_edge_t>* edges = new std::map<std::string, xbt_edge_t>;
 
-  static_cast<simgrid::kernel::routing::NetZoneImpl*>(netzone)->get_graph(graph, nodes, edges);
+  netzone->get_impl()->get_graph(graph, nodes, edges);
   for (auto elm : *edges) {
     xbt_edge_t edge = elm.second;
     linkContainers(simgrid::instr::Container::by_name(static_cast<const char*>(edge->src->data)),
@@ -466,15 +466,15 @@ static void recursiveXBTGraphExtraction(xbt_graph_t graph, std::map<std::string,
                                         std::map<std::string, xbt_edge_t>* edges, sg_netzone_t netzone,
                                         container_t container)
 {
-  if (not netzone->get_children()->empty()) {
+  if (not netzone->get_children().empty()) {
     // bottom-up recursion
-    for (auto const& netzone_child : *netzone->get_children()) {
+    for (auto const& netzone_child : netzone->get_children()) {
       container_t child_container = container->children_.at(netzone_child->get_cname());
       recursiveXBTGraphExtraction(graph, nodes, edges, netzone_child, child_container);
     }
   }
 
-  static_cast<simgrid::kernel::routing::NetZoneImpl*>(netzone)->get_graph(graph, nodes, edges);
+  netzone->get_impl()->get_graph(graph, nodes, edges);
 }
 
 xbt_graph_t instr_routing_platform_graph()
index 2b80a60..9a02ccb 100644 (file)
@@ -64,13 +64,13 @@ void Container::add_resources(std::vector<sg_host_t> hosts)
 void Container::create_hierarchy(sg_netzone_t from_as)
 {
 
-  if (from_as->get_children()->empty()) {
+  if (from_as->get_children().empty()) {
     // I am no AS
     // add hosts to jedule platform
     std::vector<sg_host_t> table = from_as->get_all_hosts();
     this->add_resources(table);
   } else {
-    for (auto const& nz : *from_as->get_children()) {
+    for (auto const& nz : from_as->get_children()) {
       jed_container_t child_container = new simgrid::jedule::Container(std::string(nz->get_cname()));
       this->add_child(child_container);
       child_container->create_hierarchy(nz);
index 3013d78..500a1d1 100644 (file)
@@ -17,9 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf"
 namespace simgrid {
 namespace kernel {
 namespace routing {
-ClusterZone::ClusterZone(NetZone* father, std::string name) : NetZoneImpl(father, name)
-{
-}
+ClusterZone::ClusterZone(NetZoneImpl* father, std::string name) : NetZoneImpl(father, name) {}
 
 void ClusterZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* route, double* lat)
 {
index b5642e3..1ce64e2 100644 (file)
@@ -266,7 +266,8 @@ DijkstraZone::~DijkstraZone()
 
 /* Creation routing model functions */
 
-DijkstraZone::DijkstraZone(NetZone* father, std::string name, bool cached) : RoutedZone(father, name), cached_(cached)
+DijkstraZone::DijkstraZone(NetZoneImpl* father, std::string name, bool cached)
+    : RoutedZone(father, name), cached_(cached)
 {
 }
 
index 6d13fb2..a5a268d 100644 (file)
@@ -18,9 +18,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-DragonflyZone::DragonflyZone(NetZone* father, std::string name) : ClusterZone(father, name)
-{
-}
+DragonflyZone::DragonflyZone(NetZoneImpl* father, std::string name) : ClusterZone(father, name) {}
 
 DragonflyZone::~DragonflyZone()
 {
index 78a1c67..a50a06c 100644 (file)
@@ -15,9 +15,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-EmptyZone::EmptyZone(NetZone* father, std::string name) : NetZoneImpl(father, name)
-{
-}
+EmptyZone::EmptyZone(NetZoneImpl* father, std::string name) : NetZoneImpl(father, name) {}
 
 EmptyZone::~EmptyZone() = default;
 
index f32dc54..917b40d 100644 (file)
@@ -22,7 +22,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-FatTreeZone::FatTreeZone(NetZone* father, std::string name) : ClusterZone(father, name)
+FatTreeZone::FatTreeZone(NetZoneImpl* father, std::string name) : ClusterZone(father, name)
 {
   XBT_DEBUG("Creating a new fat tree.");
 }
index 5286d2e..57e7ffd 100644 (file)
@@ -22,7 +22,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-FloydZone::FloydZone(NetZone* father, std::string name) : RoutedZone(father, name)
+FloydZone::FloydZone(NetZoneImpl* father, std::string name) : RoutedZone(father, name)
 {
   predecessor_table_ = nullptr;
   cost_table_        = nullptr;
index 77904a4..765e13e 100644 (file)
@@ -16,9 +16,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
 namespace simgrid {
 namespace kernel {
 namespace routing {
-FullZone::FullZone(NetZone* father, std::string name) : RoutedZone(father, name)
-{
-}
+FullZone::FullZone(NetZoneImpl* father, std::string name) : RoutedZone(father, name) {}
 
 void FullZone::seal()
 {
index e19d3ce..9f5d38a 100644 (file)
@@ -26,22 +26,70 @@ public:
   std::vector<resource::LinkImpl*> links;
 };
 
-NetZoneImpl::NetZoneImpl(NetZone* father, std::string name) : NetZone(father, name)
+NetZoneImpl::NetZoneImpl(NetZoneImpl* father, std::string name) : piface_(this), father_(father), name_(name)
 {
   xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name.c_str()),
              "Refusing to create a second NetZone called '%s'.", name.c_str());
 
-  netpoint_ = new NetPoint(name, NetPoint::Type::NetZone, static_cast<NetZoneImpl*>(father));
+  netpoint_ = new NetPoint(name, NetPoint::Type::NetZone, father);
   XBT_DEBUG("NetZone '%s' created with the id '%u'", name.c_str(), netpoint_->id());
 }
 
 NetZoneImpl::~NetZoneImpl()
 {
+  for (auto const& nz : children_)
+    delete nz;
+
   for (auto const& kv : bypass_routes_)
     delete kv.second;
 
   simgrid::s4u::Engine::get_instance()->netpoint_unregister(netpoint_);
 }
+const char* NetZoneImpl::get_cname() const
+{
+  return name_.c_str();
+}
+NetZoneImpl* NetZoneImpl::get_father()
+{
+  return father_;
+}
+void NetZoneImpl::seal()
+{
+  sealed_ = true;
+}
+/** @brief Returns the list of direct children (no grand-children)
+ *
+ * This returns the internal data, no copy. Don't mess with it.
+ */
+std::vector<NetZoneImpl*>* NetZoneImpl::get_children()
+{
+  return &children_;
+}
+/** @brief Returns the list of the hosts found in this NetZone (not recursively)
+ *
+ * Only the hosts that are directly contained in this NetZone are retrieved,
+ * not the ones contained in sub-netzones.
+ */
+std::vector<s4u::Host*> NetZoneImpl::get_all_hosts()
+{
+  std::vector<s4u::Host*> res;
+  for (auto const& card : get_vertices()) {
+    s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
+    if (host != nullptr)
+      res.push_back(host);
+  }
+  return res;
+}
+int NetZoneImpl::get_host_count()
+{
+  int count = 0;
+  for (auto const& card : get_vertices()) {
+    s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
+    if (host != nullptr)
+      count++;
+  }
+  return count;
+}
 
 simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, std::vector<double>* speedPerPstate, int coreAmount,
                                              std::map<std::string, std::string>* props)
@@ -64,6 +112,18 @@ simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, std::vector<doubl
   return res;
 }
 
+int NetZoneImpl::add_component(kernel::routing::NetPoint* elm)
+{
+  vertices_.push_back(elm);
+  return vertices_.size() - 1; // The rank of the newly created object
+}
+void NetZoneImpl::add_route(kernel::routing::NetPoint* /*src*/, kernel::routing::NetPoint* /*dst*/,
+                            kernel::routing::NetPoint* /*gw_src*/, kernel::routing::NetPoint* /*gw_dst*/,
+                            std::vector<kernel::resource::LinkImpl*>& /*link_list*/, bool /*symmetrical*/)
+{
+  xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_.c_str());
+}
+
 void NetZoneImpl::add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
                                    std::vector<resource::LinkImpl*>& link_list, bool symmetrical)
 {
@@ -230,7 +290,7 @@ bool NetZoneImpl::get_bypass_route(routing::NetPoint* src, routing::NetPoint* ds
 
   /* (1) find the path to the root routing component */
   std::vector<NetZoneImpl*> path_src;
-  NetZone* current = src->get_englobing_zone();
+  NetZoneImpl* current = src->get_englobing_zone();
   while (current != nullptr) {
     path_src.push_back(static_cast<NetZoneImpl*>(current));
     current = current->father_;
index dc502fd..1a2058b 100644 (file)
@@ -59,9 +59,7 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-RoutedZone::RoutedZone(NetZone* father, std::string name) : NetZoneImpl(father, name)
-{
-}
+RoutedZone::RoutedZone(NetZoneImpl* father, std::string name) : NetZoneImpl(father, name) {}
 
 void RoutedZone::get_graph(xbt_graph_t graph, std::map<std::string, xbt_node_t>* nodes,
                            std::map<std::string, xbt_edge_t>* edges)
@@ -152,8 +150,8 @@ void RoutedZone::get_route_check_params(NetPoint* src, NetPoint* dst)
   xbt_assert(src, "Cannot find a route from nullptr to %s", dst->get_cname());
   xbt_assert(dst, "Cannot find a route from %s to nullptr", src->get_cname());
 
-  NetZone* src_as = src->get_englobing_zone();
-  NetZone* dst_as = dst->get_englobing_zone();
+  NetZoneImpl* src_as = src->get_englobing_zone();
+  NetZoneImpl* dst_as = dst->get_englobing_zone();
 
   xbt_assert(src_as == dst_as,
              "Internal error: %s@%s and %s@%s are not in the same netzone as expected. Please report that bug.",
@@ -201,7 +199,7 @@ void RoutedZone::add_route_check_params(NetPoint* src, NetPoint* dst, NetPoint*
                dstName, gw_dst->get_cname());
   }
 
-  on_route_creation(symmetrical, src, dst, gw_src, gw_dst, link_list);
+  piface_.on_route_creation(symmetrical, src, dst, gw_src, gw_dst, link_list);
 }
 }
 }
index 56896c6..7955bd1 100644 (file)
@@ -29,9 +29,7 @@ inline void rankId_to_coords(int rankId, std::vector<unsigned int> dimensions, u
 namespace simgrid {
 namespace kernel {
 namespace routing {
-TorusZone::TorusZone(NetZone* father, std::string name) : ClusterZone(father, name)
-{
-}
+TorusZone::TorusZone(NetZoneImpl* father, std::string name) : ClusterZone(father, name) {}
 
 void TorusZone::create_links_for_node(ClusterCreationArgs* cluster, int id, int rank, unsigned int position)
 {
index 8bc5201..cac8eb5 100644 (file)
@@ -59,9 +59,7 @@ static std::vector<double>* netpoint_get_coords(NetPoint* np)
   return &coords->coords;
 }
 
-VivaldiZone::VivaldiZone(NetZone* father, std::string name) : ClusterZone(father, name)
-{
-}
+VivaldiZone::VivaldiZone(NetZoneImpl* father, std::string name) : ClusterZone(father, name) {}
 
 void VivaldiZone::set_peer_link(NetPoint* netpoint, double bw_in, double bw_out, std::string coord)
 {
index 330b7ea..e437212 100644 (file)
@@ -263,13 +263,13 @@ void Engine::run()
 /** @brief Retrieve the root netzone, containing all others */
 s4u::NetZone* Engine::get_netzone_root()
 {
-  return pimpl->netzone_root_;
+  return pimpl->netzone_root_->get_iface();
 }
 /** @brief Set the root netzone, containing all others. Once set, it cannot be changed. */
 void Engine::set_netzone_root(s4u::NetZone* netzone)
 {
   xbt_assert(pimpl->netzone_root_ == nullptr, "The root NetZone cannot be changed once set");
-  pimpl->netzone_root_ = static_cast<kernel::routing::NetZoneImpl*>(netzone);
+  pimpl->netzone_root_ = netzone->get_impl();
 }
 
 static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char* name)
@@ -277,7 +277,7 @@ static s4u::NetZone* netzone_by_name_recursive(s4u::NetZone* current, const char
   if (not strcmp(current->get_cname(), name))
     return current;
 
-  for (auto const& elem : *(current->get_children())) {
+  for (auto const& elem : current->get_children()) {
     simgrid::s4u::NetZone* tmp = netzone_by_name_recursive(elem, name);
     if (tmp != nullptr) {
       return tmp;
index d361ce0..c9dc1bd 100644 (file)
@@ -21,21 +21,10 @@ simgrid::xbt::signal<void(bool symmetrical, kernel::routing::NetPoint* src, kern
 simgrid::xbt::signal<void(NetZone&)> NetZone::on_creation;
 simgrid::xbt::signal<void(NetZone&)> NetZone::on_seal;
 
-NetZone::NetZone(NetZone* father, std::string name) : father_(father), name_(name)
-{
-  children_ = new std::vector<NetZone*>();
-}
-
-void NetZone::seal()
-{
-  sealed_ = true;
-}
+NetZone::NetZone(kernel::routing::NetZoneImpl* impl) : pimpl_(impl) {}
 
 NetZone::~NetZone()
 {
-  for (auto const& nz : *children_)
-    delete nz;
-  delete children_;
 }
 
 std::unordered_map<std::string, std::string>* NetZone::get_properties()
@@ -53,22 +42,26 @@ void NetZone::set_property(const char* key, const char* value)
   simgrid::simix::simcall([this, key, value] { properties_[key] = value; });
 }
 
-/** @brief Returns the list of direct children (no grand-children)
- *
- * This function returns the internal copy of the children, not a copy. Don't mess with it!
- */
-std::vector<NetZone*>* NetZone::get_children()
+/** @brief Returns the list of direct children (no grand-children) */
+std::vector<NetZone*> NetZone::get_children()
 {
-  return children_;
+  std::vector<NetZone*> res;
+  for (auto child : *(pimpl_->get_children()))
+    res.push_back(child->get_iface());
+  return res;
 }
 
+const std::string& NetZone::get_name() const
+{
+  return pimpl_->get_name();
+}
 const char* NetZone::get_cname() const
 {
-  return name_.c_str();
+  return pimpl_->get_cname();
 }
 NetZone* NetZone::get_father()
 {
-  return father_;
+  return pimpl_->get_father()->get_iface();
 }
 
 /** @brief Returns the list of the hosts found in this NetZone (not recursively)
@@ -78,18 +71,12 @@ NetZone* NetZone::get_father()
  */
 std::vector<Host*> NetZone::get_all_hosts()
 {
-  std::vector<Host*> res;
-  for (auto const& card : vertices_) {
-    s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
-    if (host != nullptr)
-      res.push_back(host);
-  }
-  return res;
+  return pimpl_->get_all_hosts();
 }
 
 void NetZone::getHosts(std::vector<s4u::Host*>* whereto)
 {
-  for (auto const& card : vertices_) {
+  for (auto const& card : pimpl_->get_vertices()) {
     s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
     if (host != nullptr)
       whereto->push_back(host);
@@ -98,28 +85,30 @@ void NetZone::getHosts(std::vector<s4u::Host*>* whereto)
 
 int NetZone::get_host_count()
 {
-  int count = 0;
-  for (auto const& card : vertices_) {
-    s4u::Host* host = simgrid::s4u::Host::by_name_or_null(card->get_name());
-    if (host != nullptr)
-      count++;
-  }
-  return count;
+  return pimpl_->get_host_count();
 }
 
 int NetZone::add_component(kernel::routing::NetPoint* elm)
 {
-  vertices_.push_back(elm);
-  return vertices_.size() - 1; // The rank of the newly created object
+  return pimpl_->add_component(elm);
 }
 
-void NetZone::add_route(kernel::routing::NetPoint* /*src*/, kernel::routing::NetPoint* /*dst*/,
-                        kernel::routing::NetPoint* /*gw_src*/, kernel::routing::NetPoint* /*gw_dst*/,
-                        std::vector<kernel::resource::LinkImpl*>& /*link_list*/, bool /*symmetrical*/)
+void NetZone::add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
+                        kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
+                        std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical)
 {
-  xbt_die("NetZone '%s' does not accept new routes (wrong class).", name_.c_str());
+  pimpl_->add_route(src, dst, gw_src, gw_dst, link_list, symmetrical);
+}
+void NetZone::add_bypass_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst,
+                               kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst,
+                               std::vector<kernel::resource::LinkImpl*>& link_list, bool symmetrical)
+{
+  pimpl_->add_bypass_route(src, dst, gw_src, gw_dst, link_list, symmetrical);
+}
+std::vector<kernel::routing::NetPoint*> NetZone::getVertices()
+{
+  return pimpl_->get_vertices();
 }
-
 } // namespace s4u
 } // namespace simgrid
 
@@ -142,7 +131,7 @@ sg_netzone_t sg_zone_get_by_name(const char* name)
 
 void sg_zone_get_sons(sg_netzone_t netzone, xbt_dict_t whereto)
 {
-  for (auto const& elem : *netzone->get_children()) {
+  for (auto const& elem : netzone->get_children()) {
     xbt_dict_set(whereto, elem->get_cname(), static_cast<void*>(elem), nullptr);
   }
 }
index f2a5971..f521fd9 100644 (file)
@@ -542,7 +542,7 @@ static void surf_config_models_setup()
  *
  * @param zone the parameters defining the Zone to build.
  */
-simgrid::s4u::NetZone* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone)
+simgrid::kernel::routing::NetZoneImpl* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone)
 {
   if (not surf_parse_models_setup_already_called) {
     simgrid::s4u::on_platform_creation();
@@ -600,18 +600,18 @@ simgrid::s4u::NetZone* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCre
   }
 
   if (current_routing == nullptr) { /* it is the first one */
-    simgrid::s4u::Engine::get_instance()->set_netzone_root(new_zone);
+    simgrid::s4u::Engine::get_instance()->set_netzone_root(new_zone->get_iface());
   } else {
     /* set the father behavior */
     if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)
       current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::recursive;
     /* add to the sons dictionary */
-    current_routing->get_children()->push_back(static_cast<simgrid::s4u::NetZone*>(new_zone));
+    current_routing->get_children()->push_back(new_zone);
   }
 
   /* set the new current component of the tree */
   current_routing = new_zone;
-  simgrid::s4u::NetZone::on_creation(*new_zone); // notify the signal
+  simgrid::s4u::NetZone::on_creation(*new_zone->get_iface()); // notify the signal
 
   return new_zone;
 }
@@ -626,7 +626,7 @@ void sg_platf_new_Zone_seal()
 {
   xbt_assert(current_routing, "Cannot seal the current AS: none under construction");
   current_routing->seal();
-  simgrid::s4u::NetZone::on_seal(*current_routing);
+  simgrid::s4u::NetZone::on_seal(*current_routing->get_iface());
   current_routing = static_cast<simgrid::kernel::routing::NetZoneImpl*>(current_routing->get_father());
 }
 
index 8ae587d..0f24ff8 100644 (file)
@@ -185,7 +185,8 @@ public:
 void routing_cluster_add_backbone(simgrid::kernel::resource::LinkImpl* bb);
 /*** END of the parsing cruft ***/
 
-XBT_PUBLIC simgrid::s4u::NetZone* sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone); // Begin description of new Zone
+XBT_PUBLIC simgrid::kernel::routing::NetZoneImpl*
+sg_platf_new_Zone_begin(simgrid::kernel::routing::ZoneCreationArgs* zone);         // Begin description of new Zone
 XBT_PUBLIC void sg_platf_new_Zone_seal();                                          // That Zone is fully described
 
 XBT_PUBLIC void sg_platf_new_host(simgrid::kernel::routing::HostCreationArgs* host);      // Add a host      to the current Zone