#undef ROUTING_HIERARCHY_MAXDEPTH
}
-
/* 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())
- 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()) {
- 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());
+ 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) {
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();
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);
+ 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 (bypassRoutes_.find(key) != bypassRoutes_.end())
+ if (bypassRoutes_.find(key) != bypassRoutes_.end()) {
bypassedRoute = bypassRoutes_.at(key);
+ break;
+ }
}
- if (bypassedRoute)
- break;
}
if (bypassedRoute)
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);
+ 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;
}
/**
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;
- }
/* If src and dst are in the same AS, life is good */
if (src_ancestor == dst_ancestor) { /* SURF_ROUTING_BASE */
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);