Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Simplify NetZone's hierarchy
authorBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 6 Apr 2021 08:52:21 +0000 (10:52 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Tue, 6 Apr 2021 08:52:21 +0000 (10:52 +0200)
A NetZone is RoutingMode::base by default. When we add a child to it, it
becomes RoutingMode::recursive.

include/simgrid/kernel/routing/NetZoneImpl.hpp
src/kernel/routing/DijkstraZone.cpp
src/kernel/routing/FloydZone.cpp
src/kernel/routing/FullZone.cpp
src/kernel/routing/NetZoneImpl.cpp
src/kernel/routing/RoutedZone.cpp
src/surf/sg_platf.cpp

index d2eab40..ae410c5 100644 (file)
@@ -70,14 +70,6 @@ class XBT_PUBLIC NetZoneImpl : public xbt::PropertyHolder {
 
   std::map<std::pair<NetPoint*, NetPoint*>, BypassRoute*> bypass_routes_; // src x dst -> route
   routing::NetPoint* netpoint_ = nullptr;                                 // Our representative in the father NetZone
-  std::shared_ptr<resource::NetworkModel> network_model_;
-  std::shared_ptr<resource::CpuModel> cpu_model_vm_;
-  std::shared_ptr<resource::CpuModel> cpu_model_pm_;
-  std::shared_ptr<resource::DiskModel> disk_model_;
-  std::shared_ptr<simgrid::surf::HostModel> host_model_;
-  /** @brief Perform sealing procedure for derived classes, if necessary */
-  virtual void do_seal(){};
-  void add_child(NetZoneImpl* new_zone);
 
 protected:
   explicit NetZoneImpl(const std::string& name);
@@ -101,14 +93,10 @@ protected:
 
 public:
   enum class RoutingMode {
-    unset = 0, /**< Undefined type                                   */
-    base,      /**< Base case: use simple link lists for routing     */
-    recursive  /**< Recursive case: also return gateway information  */
+    base,     /**< Base case: use simple link lists for routing     */
+    recursive /**< Recursive case: also return gateway information  */
   };
 
-  /* FIXME: protect the following fields once the construction madness is sorted out */
-  RoutingMode hierarchy_ = RoutingMode::unset;
-
   /** @brief Retrieves the network model associated to this NetZone */
   const std::shared_ptr<resource::NetworkModel>& get_network_model() const { return network_model_; }
   /** @brief Retrieves the CPU model for virtual machines associated to this NetZone */
@@ -129,6 +117,8 @@ public:
   /** @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*>* get_children() { return &children_; }
+  /** @brief Get current netzone hierarchy */
+  RoutingMode get_hierarchy() const { return hierarchy_; }
 
   /** @brief Retrieves the name of that netzone as a C++ string */
   const std::string& get_name() const { return name_; }
@@ -176,6 +166,17 @@ public:
 
   virtual void get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_node_t, std::less<>>* nodes,
                          std::map<std::string, xbt_edge_t, std::less<>>* edges) = 0;
+
+private:
+  RoutingMode hierarchy_ = RoutingMode::base;
+  std::shared_ptr<resource::NetworkModel> network_model_;
+  std::shared_ptr<resource::CpuModel> cpu_model_vm_;
+  std::shared_ptr<resource::CpuModel> cpu_model_pm_;
+  std::shared_ptr<resource::DiskModel> disk_model_;
+  std::shared_ptr<simgrid::surf::HostModel> host_model_;
+  /** @brief Perform sealing procedure for derived classes, if necessary */
+  virtual void do_seal(){};
+  void add_child(NetZoneImpl* new_zone);
 };
 } // namespace routing
 } // namespace kernel
index 3b6a036..6270976 100644 (file)
@@ -40,7 +40,7 @@ void DijkstraZone::do_seal()
   xbt_node_t node = nullptr;
 
   /* Add the loopback if needed */
-  if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) {
+  if (get_network_model()->loopback_ && get_hierarchy() == RoutingMode::base) {
     xbt_dynar_foreach (xbt_graph_get_nodes(route_graph_.get()), cursor, node) {
       bool found      = false;
       xbt_edge_t edge = nullptr;
@@ -187,7 +187,8 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr
     if (v == dst_node_id)
       first_gw = gw_dst;
 
-    if (hierarchy_ == RoutingMode::recursive && v != dst_node_id && gw_dst->get_name() != prev_gw_src->get_name()) {
+    if (get_hierarchy() == RoutingMode::recursive && v != dst_node_id &&
+        gw_dst->get_name() != prev_gw_src->get_name()) {
       std::vector<resource::LinkImpl*> e_route_as_to_as;
 
       NetPoint* gw_dst_net_elm      = nullptr;
@@ -209,7 +210,7 @@ void DijkstraZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationAr
     }
   }
 
-  if (hierarchy_ == RoutingMode::recursive) {
+  if (get_hierarchy() == RoutingMode::recursive) {
     route->gw_src = gw_src;
     route->gw_dst = first_gw;
   }
@@ -223,10 +224,10 @@ void DijkstraZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, Net
 {
   add_route_check_params(src, dst, gw_src, gw_dst, link_list, symmetrical);
 
-  new_edge(src->id(), dst->id(), new_extended_route(hierarchy_, gw_src, gw_dst, link_list, true));
+  new_edge(src->id(), dst->id(), new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, true));
 
   if (symmetrical)
-    new_edge(dst->id(), src->id(), new_extended_route(hierarchy_, gw_dst, gw_src, link_list, false));
+    new_edge(dst->id(), src->id(), new_extended_route(get_hierarchy(), gw_dst, gw_src, link_list, false));
 }
 
 void DijkstraZone::new_edge(int src_id, int dst_id, RouteCreationArgs* route)
index 98903cb..5e109f3 100644 (file)
@@ -57,7 +57,7 @@ void FloydZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
     cur = pred;
   } while (cur != src->id());
 
-  if (hierarchy_ == RoutingMode::recursive) {
+  if (get_hierarchy() == RoutingMode::recursive) {
     route->gw_src = route_stack.back()->gw_src;
     route->gw_dst = route_stack.front()->gw_dst;
   }
@@ -66,7 +66,7 @@ void FloydZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs*
   while (not route_stack.empty()) {
     const RouteCreationArgs* e_route = route_stack.back();
     route_stack.pop_back();
-    if (hierarchy_ == RoutingMode::recursive && prev_dst_gw != nullptr &&
+    if (get_hierarchy() == RoutingMode::recursive && prev_dst_gw != nullptr &&
         prev_dst_gw->get_cname() != e_route->gw_src->get_cname()) {
       get_global_route(prev_dst_gw, e_route->gw_src, route->link_list, lat);
     }
@@ -100,7 +100,7 @@ void FloydZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoi
                "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src->get_cname(),
                dst->get_cname());
 
-  TO_FLOYD_LINK(src->id(), dst->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, true);
+  TO_FLOYD_LINK(src->id(), dst->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, true);
   TO_FLOYD_PRED(src->id(), dst->id()) = src->id();
   TO_FLOYD_COST(src->id(), dst->id()) = (TO_FLOYD_LINK(src->id(), dst->id()))->link_list.size();
 
@@ -127,7 +127,7 @@ void FloydZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoi
       XBT_DEBUG("Load NetzoneRoute from \"%s(%s)\" to \"%s(%s)\"", dst->get_cname(), gw_src->get_cname(),
                 src->get_cname(), gw_dst->get_cname());
 
-    TO_FLOYD_LINK(dst->id(), src->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, false);
+    TO_FLOYD_LINK(dst->id(), src->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, false);
     TO_FLOYD_PRED(dst->id(), src->id()) = dst->id();
     TO_FLOYD_COST(dst->id(), src->id()) =
         (TO_FLOYD_LINK(dst->id(), src->id()))->link_list.size(); /* count of links, old model assume 1 */
@@ -141,7 +141,7 @@ void FloydZone::do_seal()
   init_tables(table_size);
 
   /* Add the loopback if needed */
-  if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) {
+  if (get_network_model()->loopback_ && get_hierarchy() == RoutingMode::base) {
     for (unsigned int i = 0; i < table_size; i++) {
       RouteCreationArgs* route = TO_FLOYD_LINK(i, i);
       if (not route) {
index 9f0c860..ab756c1 100644 (file)
@@ -26,7 +26,7 @@ void FullZone::do_seal()
     routing_table_.resize(table_size * table_size, nullptr);
 
   /* Add the loopback if needed */
-  if (get_network_model()->loopback_ && hierarchy_ == RoutingMode::base) {
+  if (get_network_model()->loopback_ && get_hierarchy() == RoutingMode::base) {
     for (unsigned int i = 0; i < table_size; i++) {
       RouteCreationArgs* route = TO_ROUTE_FULL(i, i);
       if (not route) {
@@ -84,7 +84,7 @@ void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoin
                dst->get_cname());
 
   /* Add the route to the base */
-  TO_ROUTE_FULL(src->id(), dst->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, true);
+  TO_ROUTE_FULL(src->id(), dst->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, true);
 
   if (symmetrical && src != dst) {
     if (gw_dst && gw_src) {
@@ -102,7 +102,7 @@ void FullZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoin
                  "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.",
                  dst->get_cname(), src->get_cname());
 
-    TO_ROUTE_FULL(dst->id(), src->id()) = new_extended_route(hierarchy_, gw_src, gw_dst, link_list, false);
+    TO_ROUTE_FULL(dst->id(), src->id()) = new_extended_route(get_hierarchy(), gw_src, gw_dst, link_list, false);
   }
 }
 } // namespace routing
index 775009a..1db3805 100644 (file)
@@ -109,6 +109,8 @@ NetZoneImpl::~NetZoneImpl()
 void NetZoneImpl::add_child(NetZoneImpl* new_zone)
 {
   xbt_assert(not sealed_, "Cannot add a new child to the sealed zone %s", get_cname());
+  /* set the father behavior */
+  hierarchy_ = RoutingMode::recursive;
   children_.push_back(new_zone);
 }
 
@@ -157,9 +159,6 @@ s4u::Link* NetZoneImpl::create_wifi_link(const std::string& name, const std::vec
 
 s4u::Host* NetZoneImpl::create_host(const std::string& name, const std::vector<double>& speed_per_pstate)
 {
-  if (hierarchy_ == RoutingMode::unset)
-    hierarchy_ = RoutingMode::base;
-
   auto* res = (new surf::HostImpl(name))->get_iface();
   res->set_netpoint((new NetPoint(name, NetPoint::Type::Host))->set_englobing_zone(this));
 
index 4df9a27..4a07c1a 100644 (file)
@@ -117,9 +117,6 @@ RouteCreationArgs* RoutedZone::new_extended_route(RoutingMode hierarchy, NetPoin
 {
   auto* result = new RouteCreationArgs();
 
-  xbt_assert(hierarchy == RoutingMode::base || hierarchy == RoutingMode::recursive,
-             "The hierarchy of this netzone is neither BASIC nor RECURSIVE, I'm lost here.");
-
   if (hierarchy == RoutingMode::recursive) {
     xbt_assert(gw_src && gw_dst, "nullptr is obviously a deficient gateway");
 
index e256c36..e9e0039 100644 (file)
@@ -91,8 +91,6 @@ void sg_platf_new_host(const simgrid::kernel::routing::HostCreationArgs* args)
 /** @brief Add a "router" to the network element list */
 simgrid::kernel::routing::NetPoint* sg_platf_new_router(const std::string& name, const char* coords)
 {
-  if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)
-    current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base;
   xbt_assert(nullptr == simgrid::s4u::Engine::get_instance()->netpoint_by_name_or_null(name),
              "Refusing to create a router named '%s': this name already describes a node.", name.c_str());
 
@@ -473,11 +471,6 @@ sg_platf_create_zone(const simgrid::kernel::routing::ZoneCreationArgs* zone)
   }
   new_zone->set_parent(current_routing);
 
-  if (current_routing) {
-    /* set the father behavior */
-    if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)
-      current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::recursive;
-  }
   return new_zone;
 }