Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
merge conflicts resolved
[simgrid.git] / src / surf / surf_routing_rulebased.c
index 53e39b6..b4f3765 100644 (file)
@@ -8,7 +8,6 @@
 
 /* Global vars */
 extern routing_global_t global_routing;
-extern xbt_dynar_t link_list;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_rulebased, surf, "Routing part of surf");
 
@@ -74,8 +73,7 @@ static void model_rulebased_parse_PU(AS_t rc, const char *name)
 static void model_rulebased_parse_AS(AS_t rc, const char *name)
 {
   AS_rulebased_t routing = (AS_rulebased_t) rc;
-  xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
-               NULL);
+  xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1), NULL);
 }
 
 static void model_rulebased_parse_route(AS_t rc,
@@ -100,9 +98,11 @@ static void model_rulebased_parse_route(AS_t rc,
   xbt_assert(ruleroute->re_src,
               "PCRE compilation failed at offset %d (\"%s\"): %s\n",
               erroffset, dst, error);
+
   ruleroute->re_str_link = route->link_list;
+  route->link_list = NULL; // Don't free it twice in each container
+
   xbt_dynar_push(routing->list_route, &ruleroute);
-  xbt_free(route);
 }
 
 static void model_rulebased_parse_ASroute(AS_t rc,
@@ -134,9 +134,10 @@ static void model_rulebased_parse_ASroute(AS_t rc,
   ruleroute_e->re_src_gateway = route->src_gateway;
   ruleroute_e->re_dst_gateway = route->dst_gateway;
   xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
-//  xbt_free(route->src_gateway);
-//  xbt_free(route->dst_gateway);
-  xbt_free(route);
+
+  /* make sure that they don't get freed */
+  route->link_list = NULL;
+  route->src_gateway = route->dst_gateway = NULL;
 }
 
 static void model_rulebased_parse_bypassroute(AS_t rc,
@@ -205,9 +206,9 @@ static char *remplace(char *value, const char **src_list, int src_size,
   return memcpy(res, result, i_res);
 }
 
-static void rulebased_get_route(AS_t rc,
+static void rulebased_get_route_and_latency(AS_t rc,
                                 const char *src, const char *dst,
-                                route_t res);
+                                route_t res,double*lat);
 static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
 {
   xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
@@ -236,7 +237,7 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
   xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
     route_t route = xbt_new0(s_route_t,1);
     route->link_list = xbt_dynar_new(global_routing->size_of_link,NULL);
-    rulebased_get_route (rc, router, k1, route);
+    rulebased_get_route_and_latency (rc, router, k1, route,NULL);
 
     int number_of_links = xbt_dynar_length(route->link_list);
 
@@ -261,9 +262,9 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
 }
 
 /* Business methods */
-static void rulebased_get_route(AS_t rc,
+static void rulebased_get_route_and_latency(AS_t rc,
                                 const char *src, const char *dst,
-                                route_t route)
+                                route_t route, double *lat)
 {
   xbt_assert(rc && src
               && dst,
@@ -285,8 +286,7 @@ static void rulebased_get_route(AS_t rc,
     are_processing_units = 0;
     rule_list = routing->list_ASroute;
   } else
-    xbt_die("Ask for route \"from\"(%s)  or \"to\"(%s) no found in "
-            "the local table", src, dst);
+    THROWF(arg_error,0,"No route from '%s' to '%s'",src,dst);
 
   int rc_src = -1;
   int rc_dst = -1;
@@ -319,9 +319,11 @@ static void rulebased_get_route(AS_t rc,
               remplace(link_name, list_src, rc_src, list_dst, rc_dst);
           void *link =
                          xbt_lib_get_or_null(link_lib, new_link_name, SURF_LINK_LEVEL);
-          if (link)
+          if (link) {
             xbt_dynar_push(route->link_list, &link);
-          else
+            if (lat)
+              *lat += surf_network_model->extension.network.get_link_latency(link);
+          } else
             THROWF(mismatch_error, 0, "Link %s not found", new_link_name);
           xbt_free(new_link_name);
         }
@@ -335,8 +337,11 @@ static void rulebased_get_route(AS_t rc,
     /* matched src and dest, nothing more to do (?) */
   } else if (!strcmp(src, dst) && are_processing_units) {
     xbt_dynar_push(route->link_list, &(global_routing->loopback));
+    if (lat)
+      *lat += surf_network_model->extension.network.get_link_latency(global_routing->loopback);
   } else {
-    xbt_dynar_reset(route->link_list);
+    THROWF(arg_error,0,"No route from '%s' to '%s'??",src,dst);
+    //xbt_dynar_reset(route->link_list);
   }
 
   if (!are_processing_units && !xbt_dynar_is_empty(route->link_list)) {
@@ -369,8 +374,8 @@ static void rulebased_finalize(AS_t rc)
     xbt_dict_free(&routing->dict_autonomous_systems);
     xbt_dynar_free(&routing->list_route);
     xbt_dynar_free(&routing->list_ASroute);
-    /* Delete structure */
-    xbt_free(routing);
+
+    model_generic_finalize(rc);
   }
 }
 
@@ -386,12 +391,12 @@ AS_t model_rulebased_create(void) {
   new_component->generic_routing.parse_ASroute = model_rulebased_parse_ASroute;
   new_component->generic_routing.parse_bypassroute = model_rulebased_parse_bypassroute;
   new_component->generic_routing.get_onelink_routes = rulebased_get_onelink_routes;
-  new_component->generic_routing.get_route = rulebased_get_route;
+  new_component->generic_routing.get_route_and_latency = rulebased_get_route_and_latency;
   new_component->generic_routing.get_bypass_route = rulebased_get_bypass_route;
   new_component->generic_routing.finalize = rulebased_finalize;
   /* initialization of internal structures */
-  new_component->dict_processing_units = xbt_dict_new();
-  new_component->dict_autonomous_systems = xbt_dict_new();
+  new_component->dict_processing_units = xbt_dict_new_homogeneous(NULL);
+  new_component->dict_autonomous_systems = xbt_dict_new_homogeneous(NULL);
   new_component->list_route = xbt_dynar_new(sizeof(rule_route_t), &rule_route_free);
   new_component->list_ASroute =
       xbt_dynar_new(sizeof(rule_route_extended_t),