Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
By default setting route symetrical to YES
[simgrid.git] / src / surf / surf_routing.c
index 4a8c742..51eeb16 100644 (file)
@@ -114,6 +114,7 @@ static void generic_set_ASroute(routing_component_t rc, const char *src,
 static void generic_set_bypassroute(routing_component_t rc,
                                     const char *src, const char *dst,
                                     route_extended_t e_route);
+int compare_routes(route_t route1, route_t route2);
 
 /* ************************************************************************** */
 /* *************** GENERIC BUSINESS METHODS (declarations) ****************** */
@@ -2505,9 +2506,13 @@ static void generic_set_route(routing_component_t rc, const char *src,
   xbt_assert2(xbt_dynar_length(route->link_list) > 0,
               "Invalid count of links, must be greater than zero (%s,%s)",
               src, dst);
-  xbt_assert2(!xbt_dict_get_or_null(_parse_routes, route_name),
-              "The route between \"%s\" and \"%s\" already exist", src,
-              dst);
+
+  if( compare_routes(route,xbt_dict_get_or_null(_parse_routes, route_name)) )
+         xbt_die(bprintf("The route between \"%s\" and \"%s\" already exist", src,dst));
+
+//  xbt_assert2(!xbt_dict_get_or_null(_parse_routes, route_name),
+//              "The route between \"%s\" and \"%s\" already exist", src,
+//              dst);
 
   xbt_dict_set(_parse_routes, route_name, route, NULL);
   xbt_free(route_name);
@@ -2524,6 +2529,8 @@ static void generic_set_route(routing_component_t rc, const char *src,
                 xbt_dynar_push_as(route_sym->link_list ,char *, link_name);
          }
          DEBUG2("Load Route from \"%s\" to \"%s\"", dst, src);
+         if( compare_routes(route_sym,xbt_dict_get_or_null(_parse_routes, bprintf("%d#%d",*dst_id, *src_id))) )
+                 xbt_die(bprintf("The route between \"%s\" and \"%s\" already exist", dst,src));
          xbt_dict_set(_parse_routes, bprintf("%d#%d",*dst_id, *src_id), route_sym, NULL);
    }
 }
@@ -2552,9 +2559,10 @@ static void generic_set_ASroute(routing_component_t rc, const char *src,
   xbt_assert2(xbt_dynar_length(e_route->generic_route.link_list) > 0,
               "Invalid count of links, must be greater than zero (%s,%s)",
               src, dst);
-  xbt_assert4(!xbt_dict_get_or_null(_parse_routes, route_name),
-              "The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
-              src, e_route->src_gateway, dst, e_route->dst_gateway);
+
+  if( compare_routes((route_t) &(e_route->generic_route),xbt_dict_get_or_null(_parse_routes, route_name)) )
+  xbt_die(bprintf("The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
+              src, e_route->src_gateway, dst, e_route->dst_gateway));
 
   xbt_dict_set(_parse_routes, route_name, e_route, NULL);
   xbt_free(route_name);
@@ -2576,6 +2584,11 @@ static void generic_set_ASroute(routing_component_t rc, const char *src,
          route_sym->dst_gateway = xbt_new0( char,strlen(e_route->src_gateway) );
          route_sym->dst_gateway = bprintf("%s",e_route->src_gateway);
          DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",dst, route_sym->src_gateway,src,route_sym->dst_gateway);
+
+         if( compare_routes((route_t) &(route_sym->generic_route),xbt_dict_get_or_null(_parse_routes,bprintf("%d#%d", *dst_id, *src_id))) )
+         xbt_die(bprintf("The route between \"%s\"(\"%s\") and \"%s\"(\"%s\") already exist",
+                     dst, route_sym->src_gateway, src, route_sym->dst_gateway));
+
          xbt_dict_set(_parse_routes, bprintf("%d#%d", *dst_id, *src_id), route_sym, NULL);
    }
 }
@@ -3281,3 +3294,26 @@ void routing_store_route(void)
 {
   parse_E_route_store_route();
 }
+
+/*
+ * Compare two routes to know if the second route is in the table.
+ *  route1 : route to store
+ *  route2 : old route in the table
+ */
+int compare_routes(route_t route1, route_t route2)
+{
+       if(!route2) return 0;
+       if(xbt_dynar_length(route1->link_list) == xbt_dynar_length(route2->link_list))
+       {
+                 int i;
+                 int nb_links = xbt_dynar_length(route1->link_list);
+                 for(i=0 ; i<nb_links ; i++)
+                 {
+                        char *link_name1 = xbt_dynar_get_as(route1->link_list, i, char *);
+                        char *link_name2 = xbt_dynar_get_as(route2->link_list, i, char *);
+                        if(strcmp(link_name1,link_name2)) return 1;
+                 }
+                 return 0;
+       }
+       return 1;
+}