Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / src / kernel / routing / AsRoutedGraph.cpp
index db43c0c..e0c289d 100644 (file)
@@ -10,6 +10,7 @@
 #include "xbt/graph.h"
 
 #include "src/kernel/routing/AsRoutedGraph.hpp"
+#include "src/kernel/routing/NetCard.hpp"
 #include "src/surf/network_interface.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_routing_generic, surf_route, "Generic implementation of the surf routing");
@@ -22,19 +23,6 @@ void routing_route_free(sg_platf_route_cbarg_t route)
   }
 }
 
-namespace simgrid {
-namespace kernel {
-namespace routing {
-  
-AsRoutedGraph::AsRoutedGraph(const char*name)
-  : AsImpl(name)
-{
-}
-
-AsRoutedGraph::~AsRoutedGraph()=default;
-
-}}} // namespace simgrid::kernel::routing
-
 /* ************************************************************************** */
 /* *********************** GENERIC BUSINESS METHODS ************************* */
 
@@ -82,35 +70,36 @@ namespace simgrid {
 namespace kernel {
 namespace routing {
 
-  xbt_dynar_t AsRoutedGraph::getOneLinkRoutes()
-  {
-    xbt_dynar_t ret = xbt_dynar_new(sizeof(Onelink*), xbt_free_f);
-    sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t,1);
-    route->link_list = new std::vector<Link*>();
-
-    int table_size = static_cast<int>(vertices_.size());
-    for(int src=0; src < table_size; src++) {
-      for(int dst=0; dst< table_size; dst++) {
-        route->link_list->clear();
-        NetCard *src_elm = vertices_.at(src);
-        NetCard *dst_elm = vertices_.at(dst);
-        this->getRouteAndLatency(src_elm, dst_elm,route, nullptr);
-
-        if (route->link_list->size() == 1) {
-          Link *link = route->link_list->at(0);
-          Onelink *onelink;
-          if (hierarchy_ == RoutingMode::base)
-            onelink = new Onelink(link, src_elm, dst_elm);
-          else if (hierarchy_ == RoutingMode::recursive)
-            onelink = new Onelink(link, route->gw_src, route->gw_dst);
-          else
-            onelink = new Onelink(link, nullptr, nullptr);
-          xbt_dynar_push(ret, &onelink);
-        }
+AsRoutedGraph::AsRoutedGraph(As* father, const char* name) : AsImpl(father, name)
+{
+}
+
+void AsRoutedGraph::getOneLinkRoutes(std::vector<Onelink*>* accumulator)
+{
+  sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
+  route->link_list             = new std::vector<Link*>();
+
+  int table_size = static_cast<int>(vertices_.size());
+  for (int src = 0; src < table_size; src++) {
+    for (int dst = 0; dst < table_size; dst++) {
+      route->link_list->clear();
+      NetCard* src_elm = vertices_.at(src);
+      NetCard* dst_elm = vertices_.at(dst);
+      getLocalRoute(src_elm, dst_elm, route, nullptr);
+
+      if (route->link_list->size() == 1) {
+        Link* link = route->link_list->at(0);
+        if (hierarchy_ == RoutingMode::base)
+          accumulator->push_back(new Onelink(link, src_elm, dst_elm));
+        else if (hierarchy_ == RoutingMode::recursive)
+          accumulator->push_back(new Onelink(link, route->gw_src, route->gw_dst));
+        else
+          accumulator->push_back(new Onelink(link, nullptr, nullptr));
       }
     }
-    return ret;
   }
+  AsImpl::getOneLinkRoutes(accumulator); // Recursivly call this function on all my childs too
+}
 
 void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
 {
@@ -122,19 +111,19 @@ void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edg
       sg_platf_route_cbarg_t route = xbt_new0(s_sg_platf_route_cbarg_t, 1);
       route->link_list = new std::vector<Link*>();
 
-      getRouteAndLatency(my_src, my_dst, route, nullptr);
+      getLocalRoute(my_src, my_dst, route, nullptr);
 
-      XBT_DEBUG ("get_route_and_latency %s -> %s", my_src->name(), my_dst->name());
+      XBT_DEBUG("get_route_and_latency %s -> %s", my_src->cname(), my_dst->cname());
 
       xbt_node_t current, previous;
       const char *previous_name, *current_name;
 
       if (route->gw_src) {
-        previous = new_xbt_graph_node(graph, route->gw_src->name(), nodes);
-        previous_name = route->gw_src->name();
+        previous      = new_xbt_graph_node(graph, route->gw_src->cname(), nodes);
+        previous_name = route->gw_src->cname();
       } else {
-        previous = new_xbt_graph_node(graph, my_src->name(), nodes);
-        previous_name = my_src->name();
+        previous      = new_xbt_graph_node(graph, my_src->cname(), nodes);
+        previous_name = my_src->cname();
       }
 
       for (auto link: *route->link_list) {
@@ -148,11 +137,11 @@ void AsRoutedGraph::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edg
       }
 
       if (route->gw_dst) {
-        current = new_xbt_graph_node(graph, route->gw_dst->name(), nodes);
-        current_name = route->gw_dst->name();
+        current      = new_xbt_graph_node(graph, route->gw_dst->cname(), nodes);
+        current_name = route->gw_dst->cname();
       } else {
-        current = new_xbt_graph_node(graph, my_dst->name(), nodes);
-        current_name = my_dst->name();
+        current      = new_xbt_graph_node(graph, my_dst->cname(), nodes);
+        current_name = my_dst->cname();
       }
       new_xbt_graph_edge(graph, previous, current, edges);
       XBT_DEBUG ("  %s -> %s", previous_name, current_name);
@@ -195,24 +184,25 @@ sg_platf_route_cbarg_t AsRoutedGraph::newExtendedRoute(RoutingMode hierarchy, sg
 
 void AsRoutedGraph::getRouteCheckParams(NetCard *src, NetCard *dst)
 {
-  xbt_assert(src,"Cannot find a route from nullptr to %s", dst->name());
-  xbt_assert(dst,"Cannot find a route from %s to nullptr", src->name());
+  xbt_assert(src, "Cannot find a route from nullptr to %s", dst->cname());
+  xbt_assert(dst, "Cannot find a route from %s to nullptr", src->cname());
 
   As *src_as = src->containingAS();
   As *dst_as = dst->containingAS();
 
-  xbt_assert(src_as == dst_as, "Internal error: %s@%s and %s@%s are not in the same AS as expected. Please report that bug.",
-        src->name(), src_as->name(), dst->name(), dst_as->name());
+  xbt_assert(src_as == dst_as,
+             "Internal error: %s@%s and %s@%s are not in the same AS as expected. Please report that bug.",
+             src->cname(), src_as->name(), dst->cname(), dst_as->name());
 
-  xbt_assert(this == dst_as,
-      "Internal error: route destination %s@%s is not in AS %s as expected (route source: %s@%s). Please report that bug.",
-        src->name(), dst->name(),  src_as->name(), dst_as->name(),  name());
+  xbt_assert(this == dst_as, "Internal error: route destination %s@%s is not in AS %s as expected (route source: "
+                             "%s@%s). Please report that bug.",
+             src->cname(), dst->cname(), src_as->name(), dst_as->name(), name());
 }
 void AsRoutedGraph::addRouteCheckParams(sg_platf_route_cbarg_t route) {
   NetCard *src = route->src;
   NetCard *dst = route->dst;
-  const char *srcName = src->name();
-  const char *dstName = dst->name();
+  const char* srcName = src->cname();
+  const char* dstName = dst->cname();
 
   if(!route->gw_dst && !route->gw_src) {
     XBT_DEBUG("Load Route from \"%s\" to \"%s\"", srcName, dstName);
@@ -222,7 +212,7 @@ void AsRoutedGraph::addRouteCheckParams(sg_platf_route_cbarg_t route) {
     xbt_assert(! src->isAS(), "When defining a route, src cannot be an AS such as '%s'. Did you meant to have an ASroute?", srcName);
     xbt_assert(! dst->isAS(), "When defining a route, dst cannot be an AS such as '%s'. Did you meant to have an ASroute?", dstName);
   } else {
-    XBT_DEBUG("Load ASroute from %s@%s to %s@%s", srcName, route->gw_src->name(), dstName, route->gw_dst->name());
+    XBT_DEBUG("Load ASroute from %s@%s to %s@%s", srcName, route->gw_src->cname(), dstName, route->gw_dst->cname());
     xbt_assert(src->isAS(), "When defining an ASroute, src must be an AS but '%s' is not", srcName);
     xbt_assert(dst->isAS(), "When defining an ASroute, dst must be an AS but '%s' is not", dstName);
 
@@ -231,14 +221,14 @@ void AsRoutedGraph::addRouteCheckParams(sg_platf_route_cbarg_t route) {
     xbt_assert(route->gw_dst->isHost() || route->gw_dst->isRouter(),
         "When defining an ASroute, gw_dst must be an host or a router but '%s' is not.", dstName);
 
-    xbt_assert(route->gw_src != route->gw_dst, "Cannot define an ASroute from '%s' to itself", route->gw_src->name());
+    xbt_assert(route->gw_src != route->gw_dst, "Cannot define an ASroute from '%s' to itself", route->gw_src->cname());
 
-    xbt_assert(src, "Cannot add a route from %s@%s to %s@%s: %s does not exist.",
-        srcName,route->gw_src->name(), dstName,route->gw_dst->name(), srcName);
-    xbt_assert(dst, "Cannot add a route from %s@%s to %s@%s: %s does not exist.",
-        srcName,route->gw_src->name(), dstName,route->gw_dst->name(), dstName);
-    xbt_assert(! route->link_list->empty(), "Empty route (between %s@%s and %s@%s) forbidden.",
-        srcName,route->gw_src->name(), dstName,route->gw_dst->name());
+    xbt_assert(src, "Cannot add a route from %s@%s to %s@%s: %s does not exist.", srcName, route->gw_src->cname(),
+               dstName, route->gw_dst->cname(), srcName);
+    xbt_assert(dst, "Cannot add a route from %s@%s to %s@%s: %s does not exist.", srcName, route->gw_src->cname(),
+               dstName, route->gw_dst->cname(), dstName);
+    xbt_assert(!route->link_list->empty(), "Empty route (between %s@%s and %s@%s) forbidden.", srcName,
+               route->gw_src->cname(), dstName, route->gw_dst->cname());
   }
 }