Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : get std_heap with mmalloc_get_current_heap instead of function argument
[simgrid.git] / src / surf / surf_routing_rulebased.c
index 788e87a..ca03d30 100644 (file)
@@ -7,7 +7,7 @@
 #include <pcre.h>               /* regular expression library */
 
 /* Global vars */
-extern routing_global_t global_routing;
+extern routing_platf_t routing_platf;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_rulebased, surf, "Routing part of surf");
 
@@ -62,14 +62,14 @@ static void rule_route_extended_free(void *e)
 
 /* Parse routing model functions */
 
-static int model_rulebased_parse_PU(AS_t rc, network_element_t elm)
+static int model_rulebased_parse_PU(AS_t rc, sg_routing_edge_t elm)
 {
   AS_rulebased_t routing = (AS_rulebased_t) rc;
   xbt_dynar_push(routing->generic_routing.index_network_elm,(void *)elm);
   return -1;
 }
 
-static int model_rulebased_parse_AS(AS_t rc, network_element_t elm)
+static int model_rulebased_parse_AS(AS_t rc, sg_routing_edge_t elm)
 {
   AS_rulebased_t routing = (AS_rulebased_t) rc;
   xbt_dynar_push(routing->generic_routing.index_network_elm,(void *)elm);
@@ -131,8 +131,13 @@ static void model_rulebased_parse_ASroute(AS_t rc,
       erroffset, dst, error);
   ruleroute_e->generic_rule_route.re_str_link =
       route->link_list;
-  ruleroute_e->re_src_gateway = xbt_strdup((char *)route->src_gateway); // DIRTY HACK possible only
-  ruleroute_e->re_dst_gateway = xbt_strdup((char *)route->dst_gateway); // because of what is in routing_parse_E_ASroute
+
+  // DIRTY PERL HACK AHEAD: with the rulebased routing, the {src,dst}_gateway fields
+  // store the provided name instead of the entity directly (routing_parse_E_ASroute knows)
+  //
+  // This is because the user will provide something like "^AS_(.*)$" instead of the proper name of a given entity
+  ruleroute_e->re_src_gateway = xbt_strdup((char *)route->src_gateway);
+  ruleroute_e->re_dst_gateway = xbt_strdup((char *)route->dst_gateway);
   xbt_dynar_push(routing->list_ASroute, &ruleroute_e);
 
   /* make sure that they don't get freed */
@@ -207,7 +212,7 @@ static char *remplace(char *value, const char **src_list, int src_size,
 }
 
 static void rulebased_get_route_and_latency(AS_t rc,
-    network_element_t src, network_element_t dst,
+    sg_routing_edge_t src, sg_routing_edge_t dst,
     route_t res,double*lat);
 static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
 {
@@ -219,7 +224,7 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
   char *k1;
 
   //find router
-  network_element_t router = NULL;
+  sg_routing_edge_t router = NULL;
   xbt_lib_cursor_t cursor;
   xbt_lib_foreach(as_router_lib, cursor, k1, router)
   {
@@ -230,7 +235,7 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
   if (!router)
     xbt_die ("rulebased_get_onelink_routes works only if the AS is a cluster, sorry.");
 
-  network_element_t host = NULL;
+  sg_routing_edge_t host = NULL;
   xbt_lib_foreach(as_router_lib, cursor, k1, host){
     route_t route = xbt_new0(s_route_t,1);
     route->link_list = xbt_dynar_new(sizeof(sg_routing_link_t),NULL);
@@ -260,7 +265,7 @@ static xbt_dynar_t rulebased_get_onelink_routes(AS_t rc)
 
 /* Business methods */
 static void rulebased_get_route_and_latency(AS_t rc,
-    network_element_t src, network_element_t dst,
+    sg_routing_edge_t src, sg_routing_edge_t dst,
     route_t route, double *lat)
 {
   XBT_DEBUG("rulebased_get_route_and_latency from '%s' to '%s'",src->name,dst->name);
@@ -335,9 +340,9 @@ static void rulebased_get_route_and_latency(AS_t rc,
   if (rc_src >= 0 && rc_dst >= 0) {
     /* matched src and dest, nothing more to do (?) */
   } else if (!strcmp(src_name, dst_name) && are_processing_units) {
-    xbt_dynar_push(route->link_list, &(global_routing->loopback));
+    xbt_dynar_push(route->link_list, &(routing_platf->loopback));
     if (lat)
-      *lat += surf_network_model->extension.network.get_link_latency(global_routing->loopback);
+      *lat += surf_network_model->extension.network.get_link_latency(routing_platf->loopback);
   } else {
     THROWF(arg_error,0,"No route from '%s' to '%s'??",src_name,dst_name);
     //xbt_dynar_reset(route->link_list);
@@ -348,30 +353,12 @@ static void rulebased_get_route_and_latency(AS_t rc,
         (rule_route_extended_t) ruleroute;
     char *gw_src_name = remplace(ruleroute_extended->re_src_gateway, list_src, rc_src,
         list_dst, rc_dst);
-    route->src_gateway = xbt_lib_get_or_null(host_lib, gw_src_name,
-        ROUTING_HOST_LEVEL);
-    route->src_gateway = xbt_lib_get_or_null(host_lib, gw_src_name,
-        ROUTING_HOST_LEVEL);
-    if (!route->src_gateway)
-      route->src_gateway = xbt_lib_get_or_null(as_router_lib, gw_src_name,
-          ROUTING_ASR_LEVEL);
-    if (!route->src_gateway)
-      route->src_gateway = xbt_lib_get_or_null(as_router_lib, gw_src_name,
-          ROUTING_ASR_LEVEL);
+    route->src_gateway = sg_routing_edge_by_name_or_null(gw_src_name);
     xbt_free(gw_src_name);
 
     char *gw_dst_name = remplace(ruleroute_extended->re_dst_gateway, list_src, rc_src,
         list_dst, rc_dst);
-    route->dst_gateway = xbt_lib_get_or_null(host_lib, gw_dst_name,
-        ROUTING_HOST_LEVEL);
-    route->dst_gateway = xbt_lib_get_or_null(host_lib, gw_dst_name,
-        ROUTING_HOST_LEVEL);
-    if (!route->dst_gateway)
-      route->dst_gateway = xbt_lib_get_or_null(as_router_lib, gw_dst_name,
-          ROUTING_ASR_LEVEL);
-    if (!route->dst_gateway)
-      route->dst_gateway = xbt_lib_get_or_null(as_router_lib, gw_dst_name,
-          ROUTING_ASR_LEVEL);
+    route->dst_gateway = sg_routing_edge_by_name_or_null(gw_dst_name);
     xbt_free(gw_dst_name);
   }
 
@@ -381,7 +368,7 @@ static void rulebased_get_route_and_latency(AS_t rc,
     pcre_free_substring_list(list_dst);
 }
 
-static route_t rulebased_get_bypass_route(AS_t rc, network_element_t src, network_element_t dst, double *lat) {
+static route_t rulebased_get_bypass_route(AS_t rc, sg_routing_edge_t src, sg_routing_edge_t dst, double *lat) {
   return NULL;
 }