Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Get netzones traversed by a route
authorBruno Donassolo <bruno.donassolo@inria.fr>
Thu, 13 May 2021 16:41:26 +0000 (18:41 +0200)
committerBruno Donassolo <bruno.donassolo@inria.fr>
Mon, 24 May 2021 07:31:55 +0000 (09:31 +0200)
Preparing field to implement dynamic bandwidth and latency factors

include/simgrid/kernel/routing/NetZoneImpl.hpp
src/kernel/routing/NetZoneImpl.cpp
src/surf/network_cm02.cpp

index 94b474c..2485bed 100644 (file)
@@ -13,6 +13,7 @@
 #include <xbt/graph.h>
 
 #include <map>
+#include <unordered_set>
 #include <vector>
 
 namespace simgrid {
@@ -103,7 +104,8 @@ protected:
   /** @brief retrieves the list of all routes of size 1 (of type src x dst x Link) */
   /* returns whether we found a bypass path */
   bool get_bypass_route(routing::NetPoint* src, routing::NetPoint* dst,
-                        /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency);
+                        /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency,
+                        std::unordered_set<NetZoneImpl*>& netzones);
 
 public:
   enum class RoutingMode {
@@ -172,7 +174,7 @@ public:
   void set_disk_model(std::shared_ptr<resource::DiskModel> disk_model);
   void set_host_model(std::shared_ptr<surf::HostModel> host_model);
 
-  /* @brief get the route between two nodes in the full platform
+  /** @brief get the route between two nodes in the full platform
    *
    * @param src where from
    * @param dst where to
@@ -182,6 +184,11 @@ public:
   static void get_global_route(routing::NetPoint* src, routing::NetPoint* dst,
                                /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency);
 
+  /** @brief Similar to get_global_route but get the NetZones traversed by route */
+  static void get_global_route_with_netzones(routing::NetPoint* src, routing::NetPoint* dst,
+                                             /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency,
+                                             std::unordered_set<NetZoneImpl*>& netzones);
+
   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;
 
@@ -193,7 +200,9 @@ private:
   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() { /* obviously nothing to do by default */ }
+  virtual void do_seal()
+  { /* obviously nothing to do by default */
+  }
   void add_child(NetZoneImpl* new_zone);
 };
 } // namespace routing
index c56eb1b..2cce0c2 100644 (file)
@@ -330,7 +330,8 @@ static void find_common_ancestors(NetPoint* src, NetPoint* dst,
 
 /* PRECONDITION: this is the common ancestor of src and dst */
 bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
-                                   /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency)
+                                   /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency,
+                                   std::unordered_set<NetZoneImpl*>& netzones)
 {
   // If never set a bypass route return nullptr without any further computations
   if (bypass_routes_.empty())
@@ -407,14 +408,14 @@ bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
               "calls to getRoute",
               src->get_cname(), dst->get_cname(), bypassedRoute->links.size());
     if (src != key.first)
-      get_global_route(src, bypassedRoute->gw_src, links, latency);
+      get_global_route_with_netzones(src, bypassedRoute->gw_src, links, latency, netzones);
     for (resource::LinkImpl* const& link : bypassedRoute->links) {
       links.push_back(link);
       if (latency)
         *latency += link->get_latency();
     }
     if (dst != key.second)
-      get_global_route(bypassedRoute->gw_dst, dst, links, latency);
+      get_global_route_with_netzones(bypassedRoute->gw_dst, dst, links, latency, netzones);
     return true;
   }
   XBT_DEBUG("No bypass route from '%s' to '%s'.", src->get_cname(), dst->get_cname());
@@ -423,6 +424,14 @@ bool NetZoneImpl::get_bypass_route(NetPoint* src, NetPoint* dst,
 
 void NetZoneImpl::get_global_route(NetPoint* src, NetPoint* dst,
                                    /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency)
+{
+  std::unordered_set<NetZoneImpl*> netzones;
+  get_global_route_with_netzones(src, dst, links, latency, netzones);
+}
+
+void NetZoneImpl::get_global_route_with_netzones(NetPoint* src, NetPoint* dst,
+                                                 /* OUT */ std::vector<resource::LinkImpl*>& links, double* latency,
+                                                 std::unordered_set<NetZoneImpl*>& netzones)
 {
   Route route;
 
@@ -436,8 +445,11 @@ void NetZoneImpl::get_global_route(NetPoint* src, NetPoint* dst,
   XBT_DEBUG("elements_father: common ancestor '%s' src ancestor '%s' dst ancestor '%s'", common_ancestor->get_cname(),
             src_ancestor->get_cname(), dst_ancestor->get_cname());
 
+  netzones.insert(src->get_englobing_zone());
+  netzones.insert(dst->get_englobing_zone());
+  netzones.insert(common_ancestor);
   /* Check whether a direct bypass is defined. If so, use it and bail out */
-  if (common_ancestor->get_bypass_route(src, dst, links, latency))
+  if (common_ancestor->get_bypass_route(src, dst, links, latency, netzones))
     return;
 
   /* If src and dst are in the same netzone, life is good */
@@ -449,19 +461,18 @@ void NetZoneImpl::get_global_route(NetPoint* src, NetPoint* dst,
   }
 
   /* Not in the same netzone, no bypass. We'll have to find our path between the netzones recursively */
-
   common_ancestor->get_local_route(src_ancestor->netpoint_, dst_ancestor->netpoint_, &route, latency);
   xbt_assert((route.gw_src_ != nullptr) && (route.gw_dst_ != nullptr), "Bad gateways for route from '%s' to '%s'.",
              src->get_cname(), dst->get_cname());
 
   /* If source gateway is not our source, we have to recursively find our way up to this point */
   if (src != route.gw_src_)
-    get_global_route(src, route.gw_src_, links, latency);
+    get_global_route_with_netzones(src, route.gw_src_, links, latency, netzones);
   links.insert(links.end(), begin(route.link_list_), end(route.link_list_));
 
   /* If dest gateway is not our destination, we have to recursively find our way from this point */
   if (route.gw_dst_ != dst)
-    get_global_route(route.gw_dst_, dst, links, latency);
+    get_global_route_with_netzones(route.gw_dst_, dst, links, latency, netzones);
 }
 
 void NetZoneImpl::seal()
index 3ddb8ce..19db714 100644 (file)
@@ -170,10 +170,13 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz
   double latency = 0.0;
   std::vector<LinkImpl*> back_route;
   std::vector<LinkImpl*> route;
+  std::unordered_set<kernel::routing::NetZoneImpl*> netzones;
 
   XBT_IN("(%s,%s,%g,%g)", src->get_cname(), dst->get_cname(), size, rate);
 
-  src->route_to(dst, route, &latency);
+  kernel::routing::NetZoneImpl::get_global_route_with_netzones(src->get_netpoint(), dst->get_netpoint(), route,
+                                                               &latency, netzones);
+
   xbt_assert(not route.empty() || latency > 0,
              "You're trying to send data from %s to %s but there is no connecting path between these two hosts.",
              src->get_cname(), dst->get_cname());
@@ -370,7 +373,7 @@ LinkImpl* NetworkCm02Link::set_latency(double value)
 {
   latency_check(value);
 
-  double delta = value - latency_.peak;
+  double delta                         = value - latency_.peak;
   const kernel::lmm::Element* elem     = nullptr;
   const kernel::lmm::Element* nextelem = nullptr;
   int numelem                          = 0;