Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename a global to avoid namespace pollution (and other cosmetics)
[simgrid.git] / src / surf / surf_routing_rulebased.c
index 3c55f26..46309a6 100644 (file)
@@ -8,7 +8,7 @@
 
 /* Global vars */
 extern routing_global_t global_routing;
-extern xbt_dynar_t link_list;
+extern xbt_dynar_t parsed_link_list;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_rulebased, surf, "Routing part of surf");
 
@@ -20,7 +20,7 @@ typedef struct {
   xbt_dict_t dict_autonomous_systems;
   xbt_dynar_t list_route;
   xbt_dynar_t list_ASroute;
-} s_routing_component_rulebased_t, *routing_component_rulebased_t;
+} s_AS_rulebased_t, *AS_rulebased_t;
 
 typedef struct s_rule_route s_rule_route_t, *rule_route_t;
 typedef struct s_rule_route_extended s_rule_route_extended_t,
@@ -65,19 +65,15 @@ static void rule_route_extended_free(void *e)
 
 /* Parse routing model functions */
 
-static void model_rulebased_parse_PU(AS_t rc,
-                                                const char *name)
+static void model_rulebased_parse_PU(AS_t rc, const char *name)
 {
-  routing_component_rulebased_t routing =
-      (routing_component_rulebased_t) rc;
+  AS_rulebased_t routing = (AS_rulebased_t) rc;
   xbt_dict_set(routing->dict_processing_units, name, (void *) (-1), NULL);
 }
 
-static void model_rulebased_parse_AS(AS_t rc,
-                                                  const char *name)
+static void model_rulebased_parse_AS(AS_t rc, const char *name)
 {
-  routing_component_rulebased_t routing =
-      (routing_component_rulebased_t) rc;
+  AS_rulebased_t routing = (AS_rulebased_t) rc;
   xbt_dict_set(routing->dict_autonomous_systems, name, (void *) (-1),
                NULL);
 }
@@ -86,8 +82,7 @@ static void model_rulebased_parse_route(AS_t rc,
                                       const char *src, const char *dst,
                                       route_t route)
 {
-  routing_component_rulebased_t routing =
-      (routing_component_rulebased_t) rc;
+  AS_rulebased_t routing = (AS_rulebased_t) rc;
   rule_route_t ruleroute = xbt_new0(s_rule_route_t, 1);
   const char *error;
   int erroffset;
@@ -114,8 +109,7 @@ static void model_rulebased_parse_ASroute(AS_t rc,
                                         const char *src, const char *dst,
                                         route_t route)
 {
-  routing_component_rulebased_t routing =
-      (routing_component_rulebased_t) rc;
+  AS_rulebased_t routing = (AS_rulebased_t) rc;
   rule_route_extended_t ruleroute_e = xbt_new0(s_rule_route_extended_t, 1);
   const char *error;
   int erroffset;
@@ -211,9 +205,9 @@ static char *remplace(char *value, const char **src_list, int src_size,
   return memcpy(res, result, i_res);
 }
 
-static route_t rulebased_get_route(AS_t rc,
-                                            const char *src,
-                                            const char *dst);
+static void rulebased_get_route(AS_t rc,
+                                const char *src, const char *dst,
+                                route_t res);
 static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
 {
   xbt_dynar_t ret = xbt_dynar_new (sizeof(onelink_t), xbt_free);
@@ -222,7 +216,7 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
   if(!strcmp(surf_network_model->name,"network NS3"))
        return ret;
 
-  routing_component_rulebased_t routing = (routing_component_rulebased_t)rc;
+  AS_rulebased_t routing = (AS_rulebased_t)rc;
 
   xbt_dict_cursor_t c1 = NULL;
   char *k1, *d1;
@@ -232,15 +226,17 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
   xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
     if (routing_get_network_element_type(k1) == SURF_NETWORK_ELEMENT_ROUTER){
       router = k1;
+      break;
     }
   }
 
-  if (!router){
+  if (!router)
     xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
-  }
 
   xbt_dict_foreach(routing->dict_processing_units, c1, k1, d1) {
-    route_t route = rulebased_get_route (rc, router, k1);
+    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);
 
     int number_of_links = xbt_dynar_length(route->link_list);
 
@@ -265,9 +261,9 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
 }
 
 /* Business methods */
-static route_t rulebased_get_route(AS_t rc,
-                                            const char *src,
-                                            const char *dst)
+static void rulebased_get_route(AS_t rc,
+                                const char *src, const char *dst,
+                                route_t route)
 {
   xbt_assert(rc && src
               && dst,
@@ -275,8 +271,7 @@ static route_t rulebased_get_route(AS_t rc,
               rc->name);
 
   /* set utils vars */
-  routing_component_rulebased_t routing =
-      (routing_component_rulebased_t) rc;
+  AS_rulebased_t routing = (AS_rulebased_t) rc;
 
   int are_processing_units=0;
   xbt_dynar_t rule_list;
@@ -290,17 +285,13 @@ static route_t 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;
   int src_length = (int) strlen(src);
   int dst_length = (int) strlen(dst);
 
-  xbt_dynar_t links_list =
-      xbt_dynar_new(global_routing->size_of_link, NULL);
-
   rule_route_t ruleroute;
   unsigned int cpt;
   int ovector_src[OVECCOUNT];
@@ -328,7 +319,7 @@ static route_t rulebased_get_route(AS_t rc,
           void *link =
                          xbt_lib_get_or_null(link_lib, new_link_name, SURF_LINK_LEVEL);
           if (link)
-            xbt_dynar_push(links_list, &link);
+            xbt_dynar_push(route->link_list, &link);
           else
             THROWF(mismatch_error, 0, "Link %s not found", new_link_name);
           xbt_free(new_link_name);
@@ -339,25 +330,22 @@ static route_t rulebased_get_route(AS_t rc,
       break;
   }
 
-  route_t new_e_route = NULL;
   if (rc_src >= 0 && rc_dst >= 0) {
-    new_e_route = xbt_new0(s_route_t, 1);
-    new_e_route->link_list = links_list;
+    /* matched src and dest, nothing more to do (?) */
   } else if (!strcmp(src, dst) && are_processing_units) {
-    new_e_route = xbt_new0(s_route_t, 1);
-    xbt_dynar_push(links_list, &(global_routing->loopback));
-    new_e_route->link_list = links_list;
+    xbt_dynar_push(route->link_list, &(global_routing->loopback));
   } else {
-    xbt_dynar_free(&link_list);
+    THROWF(arg_error,0,"No route from '%s' to '%s'??",src,dst);
+    //xbt_dynar_reset(route->link_list);
   }
 
-  if (!are_processing_units && new_e_route) {
+  if (!are_processing_units && !xbt_dynar_is_empty(route->link_list)) {
     rule_route_extended_t ruleroute_extended =
         (rule_route_extended_t) ruleroute;
-    new_e_route->src_gateway =
+    route->src_gateway =
         remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
                  list_dst, rc_dst);
-    new_e_route->dst_gateway =
+    route->dst_gateway =
         remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
                  list_dst, rc_dst);
   }
@@ -366,8 +354,6 @@ static route_t rulebased_get_route(AS_t rc,
     pcre_free_substring_list(list_src);
   if (list_dst)
     pcre_free_substring_list(list_dst);
-
-  return new_e_route;
 }
 
 static route_t rulebased_get_bypass_route(AS_t rc, const char *src, const char *dst) {
@@ -376,8 +362,8 @@ static route_t rulebased_get_bypass_route(AS_t rc, const char *src, const char *
 
 static void rulebased_finalize(AS_t rc)
 {
-  routing_component_rulebased_t routing =
-      (routing_component_rulebased_t) rc;
+  AS_rulebased_t routing =
+      (AS_rulebased_t) rc;
   if (routing) {
     xbt_dict_free(&routing->dict_processing_units);
     xbt_dict_free(&routing->dict_autonomous_systems);
@@ -391,8 +377,8 @@ static void rulebased_finalize(AS_t rc)
 /* Creation routing model functions */
 AS_t model_rulebased_create(void) {
 
-  routing_component_rulebased_t new_component = (routing_component_rulebased_t)
-      model_generic_create_sized(sizeof(s_routing_component_rulebased_t));
+  AS_rulebased_t new_component = (AS_rulebased_t)
+      model_generic_create_sized(sizeof(s_AS_rulebased_t));
 
   new_component->generic_routing.parse_PU = model_rulebased_parse_PU;
   new_component->generic_routing.parse_AS = model_rulebased_parse_AS;