From 3a2e010df11371c99e2cbe15ed44f63e50863535 Mon Sep 17 00:00:00 2001 From: Bruno Donassolo Date: Thu, 13 May 2021 18:41:26 +0200 Subject: [PATCH] Get netzones traversed by a route Preparing field to implement dynamic bandwidth and latency factors --- .../simgrid/kernel/routing/NetZoneImpl.hpp | 15 ++++++++--- src/kernel/routing/NetZoneImpl.cpp | 25 +++++++++++++------ src/surf/network_cm02.cpp | 7 ++++-- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index 94b474c67a..2485bed16b 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -13,6 +13,7 @@ #include #include +#include #include 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& links, double* latency); + /* OUT */ std::vector& links, double* latency, + std::unordered_set& netzones); public: enum class RoutingMode { @@ -172,7 +174,7 @@ public: void set_disk_model(std::shared_ptr disk_model); void set_host_model(std::shared_ptr 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& 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& links, double* latency, + std::unordered_set& netzones); + virtual void get_graph(const s_xbt_graph_t* graph, std::map>* nodes, std::map>* edges) = 0; @@ -193,7 +200,9 @@ private: std::shared_ptr disk_model_; std::shared_ptr 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 diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index c56eb1b435..2cce0c2b44 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -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& links, double* latency) + /* OUT */ std::vector& links, double* latency, + std::unordered_set& 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& links, double* latency) +{ + std::unordered_set 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& links, double* latency, + std::unordered_set& 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() diff --git a/src/surf/network_cm02.cpp b/src/surf/network_cm02.cpp index 3ddb8cee94..19db714d5d 100644 --- a/src/surf/network_cm02.cpp +++ b/src/surf/network_cm02.cpp @@ -170,10 +170,13 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz double latency = 0.0; std::vector back_route; std::vector route; + std::unordered_set 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; -- 2.20.1