Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2023.
[simgrid.git] / src / kernel / routing / StarZone.cpp
index 489ecd9..ada9bb6 100644 (file)
@@ -1,19 +1,17 @@
-/* Copyright (c) 2009-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2009-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "simgrid/kernel/routing/StarZone.hpp"
 #include "simgrid/kernel/routing/NetPoint.hpp"
-#include "simgrid/kernel/routing/RoutedZone.hpp"
 #include "src/kernel/resource/NetworkModel.hpp"
 #include "xbt/string.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_routing_star, ker_routing, "Kernel Star Routing");
 
 namespace simgrid {
-namespace kernel {
-namespace routing {
+namespace kernel::routing {
 StarZone::StarZone(const std::string& name) : ClusterZone(name) {}
 
 void StarZone::add_links_to_route(const std::vector<resource::StandardLinkImpl*>& links, Route* route, double* latency,
@@ -64,8 +62,9 @@ void StarZone::get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_n
   xbt_node_t star_node = new_xbt_graph_node(graph, get_cname(), nodes);
 
   for (auto const& src : get_vertices()) {
+    const char* src_name = routes_[src->id()].gateway ? routes_[src->id()].gateway->get_cname() : src->get_cname();
+    xbt_node_t src_node  = new_xbt_graph_node(graph, src_name, nodes);
     /* going up */
-    xbt_node_t src_node = new_xbt_graph_node(graph, src->get_cname(), nodes);
     xbt_node_t previous = src_node;
     for (auto const* link : routes_[src->id()].links_up) {
       xbt_node_t current = new_xbt_graph_node(graph, link->get_cname(), nodes);
@@ -77,10 +76,10 @@ void StarZone::get_graph(const s_xbt_graph_t* graph, std::map<std::string, xbt_n
     previous = star_node;
     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, current, previous, edges);
+      new_xbt_graph_edge(graph, previous, current, edges);
       previous = current;
     }
-    new_xbt_graph_edge(graph, src_node, previous, edges);
+    new_xbt_graph_edge(graph, previous, src_node, edges);
   }
 }
 
@@ -111,7 +110,7 @@ void StarZone::check_add_route_param(const NetPoint* src, const NetPoint* dst, c
                              src->get_cname(), gw_src->get_cname()));
 
     const auto* netzone_src = get_netzone_recursive(src);
-    if (not netzone_src->is_component_recursive(gw_src))
+    if (not netzone_src || not netzone_src->is_component_recursive(gw_src))
       throw std::invalid_argument(xbt::string_printf(
           "Invalid NetzoneRoute from %s@%s to %s: gw_src %s belongs to %s, not to %s.", src_name, gw_src->get_cname(),
           dst_name, gw_src->get_cname(), gw_src->get_englobing_zone()->get_cname(), src_name));
@@ -127,7 +126,7 @@ void StarZone::check_add_route_param(const NetPoint* src, const NetPoint* dst, c
                              dst->get_cname(), gw_dst->get_cname()));
 
     const auto* netzone_dst = get_netzone_recursive(dst);
-    if (not netzone_dst->is_component_recursive(gw_dst))
+    if (not netzone_dst || not netzone_dst->is_component_recursive(gw_dst))
       throw std::invalid_argument(xbt::string_printf(
           "Invalid NetzoneRoute from %s@%s to %s: gw_dst %s belongs to %s, not to %s.", dst_name, gw_dst->get_cname(),
           src_name, gw_dst->get_cname(), gw_dst->get_englobing_zone()->get_cname(), dst_name));
@@ -170,16 +169,15 @@ void StarZone::do_seal()
 {
   /* add default empty links if nothing was configured by user */
   for (auto const& node : get_vertices()) {
-    auto route = routes_.emplace(node->id(), StarRoute());
-    if (route.second) {
-      route.first->second.links_down_set = true;
-      route.first->second.links_up_set   = true;
+    auto [route, inserted] = routes_.try_emplace(node->id());
+    if (inserted) {
+      route->second.links_down_set = true;
+      route->second.links_up_set   = true;
     }
   }
 }
 
-} // namespace routing
-} // namespace kernel
+} // namespace kernel::routing
 
 namespace s4u {
 NetZone* create_star_zone(const std::string& name)