Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert S4U to my current coding convention
[simgrid.git] / src / surf / surf_routing_full.cpp
index 9cf68f1..9a000f4 100644 (file)
@@ -4,7 +4,6 @@
 /* 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 "src/surf/surf_routing_private.hpp"
 #include "src/surf/surf_routing_full.hpp"
 #include "src/surf/network_interface.hpp"
 
@@ -15,7 +14,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_full, surf, "Routing part of surf");
 namespace simgrid {
 namespace surf {
   AsFull::AsFull(const char*name)
-    : AsGeneric(name)
+    : AsRoutedGraph(name)
   {
   }
 
@@ -130,58 +129,32 @@ static int full_pointer_resource_cmp(const void *a, const void *b)
   return a != b;
 }
 
-void AsFull::parseRoute(sg_platf_route_cbarg_t route)
+void AsFull::addRoute(sg_platf_route_cbarg_t route)
 {
   const char *src = route->src;
   const char *dst = route->dst;
   NetCard *src_net_elm = sg_netcard_by_name_or_null(src);
   NetCard *dst_net_elm = sg_netcard_by_name_or_null(dst);
 
-  parseRouteCheckParams(route);
+  addRouteCheckParams(route);
 
   size_t table_size = xbt_dynar_length(vertices_);
 
   if (!routingTable_)
     routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size);
 
-  if (TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id())) {
-    char *link_name;
-    unsigned int i;
-    xbt_dynar_t link_route_to_test =
-        xbt_dynar_new(sizeof(Link*), NULL);
-    xbt_dynar_foreach(route->link_list, i, link_name) {
-      void *link = Link::byName(link_name);
-      xbt_assert(link, "Link : '%s' doesn't exists.", link_name);
-      xbt_dynar_push(link_route_to_test, &link);
-    }
-    if (xbt_dynar_compare(TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id())->link_list,
-        link_route_to_test, full_pointer_resource_cmp)) {
-      surf_parse_error("A route between \"%s\" and \"%s\" already exists "
-          "with a different content. "
-          "If you are trying to define a reverse route, "
-          "you must set the symmetrical=no attribute to "
-          "your routes tags.", src, dst);
-    } else {
-      surf_parse_warn("Ignoring the identical redefinition of the route "
-          "between \"%s\" and \"%s\"", src, dst);
-    }
-  } else {
-    if (!route->gw_src && !route->gw_dst)
-      XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
-    else {
-      XBT_DEBUG("Load ASroute from \"%s\" to \"%s\"", src, dst);
-      if (!route->gw_src || route->gw_src->getRcType() == SURF_NETWORK_ELEMENT_NULL)
-        surf_parse_error("The src_gateway \"%s\" does not exist!",
-            route->gw_src ? route->gw_src->name() : "(null)");
-      if (!route->gw_dst || route->gw_dst->getRcType() == SURF_NETWORK_ELEMENT_NULL)
-      surf_parse_error("The dst_gateway \"%s\" does not exist!",
-                route->gw_dst ? route->gw_dst->name() : "(null)");
-      XBT_DEBUG("ASroute goes from \"%s\" to \"%s\"",
-                route->gw_src->name(), route->gw_dst->name());
-    }
-    TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()) = newExtendedRoute(hierarchy_, route, 1);
-    xbt_dynar_shrink(TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id())->link_list, 0);
-  }
+  /* Check that the route does not already exist */
+  if (route->gw_dst) // AS route (to adapt the error message, if any)
+    xbt_assert(nullptr == TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()),
+        "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).",
+        src,route->gw_src->name(),dst,route->gw_dst->name());
+  else
+    xbt_assert(nullptr == TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()),
+        "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src,dst);
+
+  /* Add the route to the base */
+  TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()) = newExtendedRoute(hierarchy_, route, 1);
+  xbt_dynar_shrink(TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id())->link_list, 0);
 
   if (route->symmetrical == TRUE) {
     if (route->gw_dst && route->gw_src) {