X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0dbfc6eaefbb74850b401cdf1c5c9c37dc02ad74..fee678043c1ace05bae8ef3489bbbef2235dc596:/src/kernel/routing/StarZone.cpp diff --git a/src/kernel/routing/StarZone.cpp b/src/kernel/routing/StarZone.cpp index 57a2c8c719..72fb1e4499 100644 --- a/src/kernel/routing/StarZone.cpp +++ b/src/kernel/routing/StarZone.cpp @@ -8,6 +8,7 @@ #include "simgrid/kernel/routing/RoutedZone.hpp" #include "src/surf/network_interface.hpp" #include "src/surf/xml/platf_private.hpp" // RouteCreationArgs and friends +#include "xbt/string.hpp" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_star, surf, "Routing part of surf"); @@ -17,13 +18,12 @@ namespace routing { StarZone::StarZone(const std::string& name) : NetZoneImpl(name) {} void StarZone::add_links_to_route(const std::vector& links, RouteCreationArgs* route, - double* latency, std::unordered_set& added_links) + double* latency, std::unordered_set& added_links) const { for (auto* link : links) { - /* do not add duplicated links */ - if (added_links.find(link) != added_links.end()) + /* do not add duplicated links in route->link_list */ + if (not added_links.insert(link).second) continue; - added_links.insert(link); if (latency) *latency += link->get_latency(); route->link_list.push_back(link); @@ -35,27 +35,30 @@ void StarZone::get_local_route(NetPoint* src, NetPoint* dst, RouteCreationArgs* XBT_VERB("StarZone getLocalRoute from '%s'[%u] to '%s'[%u]", src->get_cname(), src->id(), dst->get_cname(), dst->id()); - xbt_assert(((src == dst) and (loopback_.find(src->id()) != loopback_.end())) or - (links_up_.find(src->id()) != links_up_.end()), - "StarZone routing (%s - %s): no link UP from source node. Did you use add_route() to set it?", - src->get_cname(), dst->get_cname()); - xbt_assert(((src == dst) and (loopback_.find(dst->id()) != loopback_.end())) or - (links_down_.find(dst->id()) != links_down_.end()), - "StarZone routing (%s - %s): no link DOWN to destination node. Did you use add_route() to set it?", - src->get_cname(), dst->get_cname()); - + const auto& src_route = routes_.at(src->id()); + const auto& dst_route = routes_.at(dst->id()); std::unordered_set added_links; /* loopback */ - if ((src == dst) and (loopback_.find(src->id()) != loopback_.end())) { - add_links_to_route(loopback_[src->id()], route, latency, added_links); + if (src == dst && src_route.has_loopback()) { + add_links_to_route(src_route.loopback, route, latency, added_links); return; } + xbt_assert(src_route.has_links_up(), + "StarZone routing (%s - %s): no link UP from source node. Did you use add_route() to set it?", + src->get_cname(), dst->get_cname()); + xbt_assert(dst_route.has_links_down(), + "StarZone routing (%s - %s): no link DOWN to destination node. Did you use add_route() to set it?", + src->get_cname(), dst->get_cname()); + /* going UP */ - add_links_to_route(links_up_[src->id()], route, latency, added_links); + add_links_to_route(src_route.links_up, route, latency, added_links); /* going DOWN */ - add_links_to_route(links_down_[dst->id()], route, latency, added_links); + add_links_to_route(dst_route.links_down, route, latency, added_links); + /* gateways */ + route->gw_src = src_route.gateway; + route->gw_dst = dst_route.gateway; } void StarZone::get_graph(const s_xbt_graph_t* graph, std::map>* nodes, @@ -67,7 +70,7 @@ void StarZone::get_graph(const s_xbt_graph_t* graph, std::mapget_cname(), nodes); xbt_node_t previous = src_node; - for (auto* link : links_up_[src->id()]) { + for (auto const* link : routes_[src->id()].links_up) { xbt_node_t current = new_xbt_graph_node(graph, link->get_cname(), nodes); new_xbt_graph_edge(graph, previous, current, edges); previous = current; @@ -75,7 +78,7 @@ void StarZone::get_graph(const s_xbt_graph_t* graph, std::mapid()]) { + for (auto const* link : routes_[src->id()].links_down) { xbt_node_t current = new_xbt_graph_node(graph, link->get_cname(), nodes); new_xbt_graph_edge(graph, previous, current, edges); previous = current; @@ -84,49 +87,85 @@ void StarZone::get_graph(const s_xbt_graph_t* graph, std::map& link_list, bool symmetrical) +void StarZone::check_add_route_param(const NetPoint* src, const NetPoint* dst, const NetPoint* gw_src, + const NetPoint* gw_dst, bool symmetrical) const { const char* src_name = src ? src->get_cname() : "nullptr"; const char* dst_name = dst ? dst->get_cname() : "nullptr"; - xbt_assert((src == dst) or (not src and dst) or (src and not dst), - "Cannot add route from %s to %s. In a StarZone, route must be: i) from source host to everyone, ii) from " - "everyone to a single host or iii) loopback, same source and destination", - src_name, dst_name); - xbt_assert((not symmetrical) or (symmetrical and src), - "Cannot add route from %s to %s. In a StarZone, symmetrical routes must be set from source to everyone " - "(not the contrary).", - src_name, dst_name); + if ((not src && not dst) || (dst && src && src != dst)) + throw std::invalid_argument(xbt::string_printf( + "Cannot add route from %s to %s. In a StarZone, route must be: i) from source netpoint to everyone, ii) from " + "everyone to a single netpoint or iii) loopback, same source and destination", + src_name, dst_name)); + + if (symmetrical && not src) + throw std::invalid_argument(xbt::string_printf("Cannot add route from %s to %s. In a StarZone, symmetrical routes " + "must be set from source to everyone (not the contrary)", + src_name, dst_name)); + + if (src && src->is_netzone()) { + if (not gw_src) + throw std::invalid_argument(xbt::string_printf( + "StarZone::add_route(): source %s is a netzone but gw_src isn't configured", src->get_cname())); + if (gw_src->is_netzone()) + throw std::invalid_argument( + xbt::string_printf("StarZone::add_route(): src(%s) is a netzone, gw_src(%s) cannot be a netzone", + src->get_cname(), gw_src->get_cname())); + } + + if (dst && dst->is_netzone()) { + if (not gw_dst) + throw std::invalid_argument(xbt::string_printf( + "StarZone::add_route(): destination %s is a netzone but gw_dst isn't configured", dst->get_cname())); + if (gw_dst->is_netzone()) + throw std::invalid_argument( + xbt::string_printf("StarZone::add_route(): dst(%s) is a netzone, gw_dst(%s) cannot be a netzone", + dst->get_cname(), gw_dst->get_cname())); + } +} + +void StarZone::add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst, + const std::vector& link_list, bool symmetrical) +{ + check_add_route_param(src, dst, gw_src, gw_dst, symmetrical); + + s4u::NetZone::on_route_creation(symmetrical, gw_src, gw_dst, gw_src, gw_dst, link_list); /* loopback */ if (src == dst) { - loopback_[src->id()] = link_list; + routes_[src->id()].loopback = link_list; } else { /* src to everyone */ if (src) { - links_up_[src->id()] = link_list; + auto& route = routes_[src->id()]; + route.links_up = link_list; + route.gateway = gw_src; + route.links_up_set = true; if (symmetrical) { - links_down_[src->id()] = link_list; /* reverse it for down/symmetrical links */ - std::reverse(links_down_[src->id()].begin(), links_down_[src->id()].end()); + route.links_down.assign(link_list.rbegin(), link_list.rend()); + route.links_down_set = true; } } /* dst to everyone */ if (dst) { - links_down_[dst->id()] = link_list; + auto& route = routes_[dst->id()]; + route.links_down = link_list; + route.gateway = gw_dst; + route.links_down_set = true; } } - s4u::NetZone::on_route_creation(symmetrical, gw_src, gw_dst, gw_src, gw_dst, link_list); } void StarZone::do_seal() { /* add default empty links if nothing was configured by user */ for (auto const& node : get_vertices()) { - if ((links_up_.find(node->id()) == links_up_.end()) and (links_down_.find(node->id()) == links_down_.end())) { - links_down_[node->id()] = {}; - links_up_[node->id()] = {}; + auto route = routes_.emplace(node->id(), StarRoute()); + if (route.second) { + route.first->second.links_down_set = true; + route.first->second.links_up_set = true; } } }