Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics in bypass routing
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 1 Nov 2016 14:28:08 +0000 (15:28 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 1 Nov 2016 14:32:57 +0000 (15:32 +0100)
src/kernel/routing/AsImpl.cpp
src/kernel/routing/AsImpl.hpp

index afca765..c5fef78 100644 (file)
@@ -92,26 +92,35 @@ namespace simgrid {
 #undef ROUTING_HIERARCHY_MAXDEPTH
     }
 
 #undef ROUTING_HIERARCHY_MAXDEPTH
     }
 
-
     /* PRECONDITION: this is the common ancestor of src and dst */
     /* PRECONDITION: this is the common ancestor of src and dst */
-    std::vector<surf::Link*> *AsImpl::getBypassRoute(routing::NetCard *src, routing::NetCard *dst)
+    bool AsImpl::getBypassRoute(routing::NetCard* src, routing::NetCard* dst,
+                                /* OUT */ std::vector<surf::Link*>* links, double* latency)
     {
       // If never set a bypass route return nullptr without any further computations
       XBT_DEBUG("generic_get_bypassroute from %s to %s", src->name(), dst->name());
       if (bypassRoutes_.empty())
     {
       // If never set a bypass route return nullptr without any further computations
       XBT_DEBUG("generic_get_bypassroute from %s to %s", src->name(), dst->name());
       if (bypassRoutes_.empty())
-        return nullptr;
-
-      std::vector<surf::Link*> *bypassedRoute = nullptr;
+        return false;
 
 
+      /* Base case, no recursion is needed */
       if(dst->containingAS() == this && src->containingAS() == this ){
         if (bypassRoutes_.find({src->name(),dst->name()}) != bypassRoutes_.end()) {
       if(dst->containingAS() == this && src->containingAS() == this ){
         if (bypassRoutes_.find({src->name(),dst->name()}) != bypassRoutes_.end()) {
-          bypassedRoute = bypassRoutes_.at({src->name(),dst->name()});
+          std::vector<surf::Link*>* bypassedRoute = bypassRoutes_.at({src->name(), dst->name()});
+          for (surf::Link* link : *bypassedRoute) {
+            links->push_back(link);
+            if (latency)
+              *latency += link->latency();
+          }
           XBT_DEBUG("Found a bypass route with %zu links",bypassedRoute->size());
           XBT_DEBUG("Found a bypass route with %zu links",bypassedRoute->size());
+          return true;
         }
         }
-        return bypassedRoute;
+        return false;
       }
 
       }
 
-      /* (2) find the path to the root routing component */
+      /* Engage recursive search */
+
+      std::vector<surf::Link*>* bypassedRoute = nullptr;
+
+      /* (1) find the path to the root routing component */
       std::vector<As*> path_src;
       As *current = src->containingAS();
       while (current != nullptr) {
       std::vector<As*> path_src;
       As *current = src->containingAS();
       while (current != nullptr) {
@@ -126,7 +135,7 @@ namespace simgrid {
         current = current->father_;
       }
 
         current = current->father_;
       }
 
-      /* (3) find the common father */
+      /* (2) find the common father */
       while (path_src.size() > 1 && path_dst.size() >1
           && path_src.at(path_src.size() -1) == path_dst.at(path_dst.size() -1)) {
         path_src.pop_back();
       while (path_src.size() > 1 && path_dst.size() >1
           && path_src.at(path_src.size() -1) == path_dst.at(path_dst.size() -1)) {
         path_src.pop_back();
@@ -142,18 +151,18 @@ namespace simgrid {
         for (int i = 0; i < max; i++) {
           if (i <= max_index_src && max <= max_index_dst) {
             const std::pair<std::string, std::string> key = {path_src.at(i)->name(), path_dst.at(max)->name()};
         for (int i = 0; i < max; i++) {
           if (i <= max_index_src && max <= max_index_dst) {
             const std::pair<std::string, std::string> key = {path_src.at(i)->name(), path_dst.at(max)->name()};
-            if (bypassRoutes_.find(key) != bypassRoutes_.end())
+            if (bypassRoutes_.find(key) != bypassRoutes_.end()) {
               bypassedRoute = bypassRoutes_.at(key);
               bypassedRoute = bypassRoutes_.at(key);
+              break;
+            }
           }
           }
-          if (bypassedRoute)
-            break;
           if (max <= max_index_src && i <= max_index_dst) {
             const std::pair<std::string, std::string> key = {path_src.at(max)->name(), path_dst.at(i)->name()};
           if (max <= max_index_src && i <= max_index_dst) {
             const std::pair<std::string, std::string> key = {path_src.at(max)->name(), path_dst.at(i)->name()};
-            if (bypassRoutes_.find(key) != bypassRoutes_.end())
+            if (bypassRoutes_.find(key) != bypassRoutes_.end()) {
               bypassedRoute = bypassRoutes_.at(key);
               bypassedRoute = bypassRoutes_.at(key);
+              break;
+            }
           }
           }
-          if (bypassedRoute)
-            break;
         }
 
         if (bypassedRoute)
         }
 
         if (bypassedRoute)
@@ -161,14 +170,22 @@ namespace simgrid {
 
         if (max <= max_index_src && max <= max_index_dst) {
           const std::pair<std::string, std::string> key = {path_src.at(max)->name(), path_dst.at(max)->name()};
 
         if (max <= max_index_src && max <= max_index_dst) {
           const std::pair<std::string, std::string> key = {path_src.at(max)->name(), path_dst.at(max)->name()};
-          if (bypassRoutes_.find(key) != bypassRoutes_.end())
+          if (bypassRoutes_.find(key) != bypassRoutes_.end()) {
             bypassedRoute = bypassRoutes_.at(key);
             bypassedRoute = bypassRoutes_.at(key);
+            break;
+          }
         }
         }
-        if (bypassedRoute)
-          break;
       }
 
       }
 
-      return bypassedRoute;
+      if (bypassedRoute) {
+        for (surf::Link* link : *bypassedRoute) {
+          links->push_back(link);
+          if (latency)
+            *latency += link->latency();
+        }
+        return true;
+      }
+      return false;
     }
 
     /**
     }
 
     /**
@@ -194,15 +211,8 @@ namespace simgrid {
           common_ancestor->name(), src_ancestor->name(), dst_ancestor->name());
 
       /* Check whether a direct bypass is defined. If so, use it and bail out */
           common_ancestor->name(), src_ancestor->name(), dst_ancestor->name());
 
       /* Check whether a direct bypass is defined. If so, use it and bail out */
-      std::vector<surf::Link*> *bypassed_route = common_ancestor->getBypassRoute(src, dst);
-      if (nullptr != bypassed_route) {
-        for (surf::Link *link : *bypassed_route) {
-          links->push_back(link);
-          if (latency)
-            *latency += link->latency();
-        }
+      if (common_ancestor->getBypassRoute(src, dst, links, latency))
         return;
         return;
-      }
 
       /* If src and dst are in the same AS, life is good */
       if (src_ancestor == dst_ancestor) {       /* SURF_ROUTING_BASE */
 
       /* If src and dst are in the same AS, life is good */
       if (src_ancestor == dst_ancestor) {       /* SURF_ROUTING_BASE */
index 7ebe6a3..5abdb28 100644 (file)
@@ -60,7 +60,9 @@ public:
   virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency)=0;
   /** @brief retrieves the list of all routes of size 1 (of type src x dst x Link) */
   virtual xbt_dynar_t getOneLinkRoutes();
   virtual void getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t into, double *latency)=0;
   /** @brief retrieves the list of all routes of size 1 (of type src x dst x Link) */
   virtual xbt_dynar_t getOneLinkRoutes();
-  std::vector<surf::Link*> *getBypassRoute(routing::NetCard *src, routing::NetCard *dst);
+  /* returns whether we found a bypass path */
+  bool getBypassRoute(routing::NetCard * src, routing::NetCard * dst,
+                      /* OUT */ std::vector<surf::Link*> * links, double* latency);
 
   virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
   static void getRouteRecursive(routing::NetCard *src, routing::NetCard *dst, /* OUT */ std::vector<surf::Link*> * links, double *latency);
 
   virtual void getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)=0;
   static void getRouteRecursive(routing::NetCard *src, routing::NetCard *dst, /* OUT */ std::vector<surf::Link*> * links, double *latency);