From eabd83894de59f28621ce9dd1148cf070446d934 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 1 Nov 2016 15:28:08 +0100 Subject: [PATCH] cosmetics in bypass routing --- src/kernel/routing/AsImpl.cpp | 64 ++++++++++++++++++++--------------- src/kernel/routing/AsImpl.hpp | 4 ++- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/kernel/routing/AsImpl.cpp b/src/kernel/routing/AsImpl.cpp index afca765766..c5fef78327 100644 --- a/src/kernel/routing/AsImpl.cpp +++ b/src/kernel/routing/AsImpl.cpp @@ -92,26 +92,35 @@ namespace simgrid { #undef ROUTING_HIERARCHY_MAXDEPTH } - /* PRECONDITION: this is the common ancestor of src and dst */ - std::vector *AsImpl::getBypassRoute(routing::NetCard *src, routing::NetCard *dst) + bool AsImpl::getBypassRoute(routing::NetCard* src, routing::NetCard* dst, + /* OUT */ std::vector* 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()) - return nullptr; - - std::vector *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()) { - bypassedRoute = bypassRoutes_.at({src->name(),dst->name()}); + std::vector* 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()); + return true; } - return bypassedRoute; + return false; } - /* (2) find the path to the root routing component */ + /* Engage recursive search */ + + std::vector* bypassedRoute = nullptr; + + /* (1) find the path to the root routing component */ std::vector path_src; As *current = src->containingAS(); while (current != nullptr) { @@ -126,7 +135,7 @@ namespace simgrid { 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(); @@ -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 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); + break; + } } - if (bypassedRoute) - break; if (max <= max_index_src && i <= max_index_dst) { const std::pair 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); + break; + } } - if (bypassedRoute) - break; } if (bypassedRoute) @@ -161,14 +170,22 @@ namespace simgrid { if (max <= max_index_src && max <= max_index_dst) { const std::pair 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); + 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 */ - std::vector *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; - } /* If src and dst are in the same AS, life is good */ if (src_ancestor == dst_ancestor) { /* SURF_ROUTING_BASE */ diff --git a/src/kernel/routing/AsImpl.hpp b/src/kernel/routing/AsImpl.hpp index 7ebe6a35c6..5abdb2840b 100644 --- a/src/kernel/routing/AsImpl.hpp +++ b/src/kernel/routing/AsImpl.hpp @@ -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(); - std::vector *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 * 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 * links, double *latency); -- 2.20.1