Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add to the rule-based model the loopback routes
[simgrid.git] / src / surf / surf_routing.c
index 2ec0872..9b46793 100644 (file)
@@ -1596,7 +1596,7 @@ static char* remplace(char* value, const char** src_list, int src_size, const ch
 /* Business methods */
 static route_extended_t rulebased_get_route(routing_component_t rc, const char* src,const char* dst) {
   xbt_assert1(rc&&src&&dst, "Invalid params for \"get_route\" function at AS \"%s\"",rc->name);
-  
+
   /* set utils vars */
   routing_component_rulebased_t routing = (routing_component_rulebased_t) rc;
 
@@ -1611,7 +1611,8 @@ static route_extended_t rulebased_get_route(routing_component_t rc, const char*
   } else
      xbt_assert2(NULL, "Ask for route \"from\"(%s)  or \"to\"(%s) no found in the local table",src,dst); 
 
-  int rc_src,rc_dst;
+  int rc_src = -1;
+  int rc_dst = -1;
   int src_length = (int)strlen(src);
   int dst_length = (int)strlen(dst);
   
@@ -1649,8 +1650,14 @@ static route_extended_t rulebased_get_route(routing_component_t rc, const char*
   if(rc_src >= 0 && rc_dst >= 0) {
     new_e_route = xbt_new0(s_route_extended_t,1);
     new_e_route->generic_route.link_list = links_list;
+  } else if( !strcmp(src,dst) && are_processing_units ) {
+    new_e_route = xbt_new0(s_route_extended_t,1);
+    xbt_dynar_push(links_list,&(global_routing->loopback));
+    new_e_route->generic_route.link_list = links_list;
+  } else { 
+    xbt_dynar_free(&link_list);
   }
-  
+
   if(!are_processing_units && new_e_route)
   {
     rule_route_extended_t ruleroute_extended = (rule_route_extended_t)ruleroute;
@@ -1838,6 +1845,7 @@ static void generic_set_autonomous_system(routing_component_t rc, const char* na
 
 static void generic_set_route(routing_component_t rc, const char* src, const char* dst, route_t route) {
   DEBUG2("Load Route from \"%s\" to \"%s\"",src,dst);
+  printf("Load Route from \"%s\" to \"%s\"\n",src,dst);
   model_type_t modeltype = rc->routing;
   xbt_dict_t _parse_routes;
   xbt_dict_t _to_index;
@@ -1875,6 +1883,7 @@ static void generic_set_route(routing_component_t rc, const char* src, const cha
 
 static void generic_set_ASroute(routing_component_t rc, const char* src, const char* dst, route_extended_t e_route) {
   DEBUG4("Load ASroute from \"%s(%s)\" to \"%s(%s)\"",src,e_route->src_gateway,dst,e_route->dst_gateway);
+  printf("Load ASroute from \"%s(%s)\" to \"%s(%s)\"\n",src,e_route->src_gateway,dst,e_route->dst_gateway);
   model_type_t modeltype = rc->routing;
   xbt_dict_t _parse_routes;
   xbt_dict_t _to_index;
@@ -2206,14 +2215,17 @@ static void routing_full_parse_Scluster(void)
        static int AX_ptr = 0;
        static int surfxml_bufferstack_size = 2048;
 
-       DEBUG4("id='%s' prefix='%s' suffix='%s' radical='%s'",
-         cluster_id,cluster_prefix,cluster_suffix,cluster_radical);
-       DEBUG5("power='%s' bw='%s' lat='%s' bb_bw='%s' bb_lat='%s'",
-                 cluster_power,cluster_bw,cluster_lat,cluster_bb_bw,cluster_bb_lat);
+       /* allocating memory for the buffer, I think 2kB should be enough */
+       surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size);
+
+//     DEBUG4("id='%s' prefix='%s' suffix='%s' radical='%s'",
+//       cluster_id,cluster_prefix,cluster_suffix,cluster_radical);
+//     DEBUG5("power='%s' bw='%s' lat='%s' bb_bw='%s' bb_lat='%s'",
+//               cluster_power,cluster_bw,cluster_lat,cluster_bb_bw,cluster_bb_lat);
 
-       DEBUG1("<AS id=\"%s\"\trouting=\"Full\">",cluster_id);
+       DEBUG1("<AS id=\"%s\"\trouting=\"RuleBased\">",cluster_id);
        SURFXML_BUFFER_SET(AS_id, cluster_id);
-       SURFXML_BUFFER_SET(AS_routing, "Full");
+       SURFXML_BUFFER_SET(AS_routing, "RuleBased");
        SURFXML_START_TAG(AS);
 
        radical_elements = xbt_str_split(cluster_radical, ",");
@@ -2227,16 +2239,31 @@ static void routing_full_parse_Scluster(void)
                          host_id = bprintf("%s%d%s", cluster_prefix, start, cluster_suffix);
                          link_id = bprintf("%s_link_%d", cluster_id, start);
 
-                         DEBUG2("\t<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
+                         DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
+                         SURFXML_BUFFER_RESET();
                          SURFXML_BUFFER_SET(host_id, host_id);
                          SURFXML_BUFFER_SET(host_power, cluster_power);
+                         SURFXML_BUFFER_SET(host_availability, "1.0");
+                         SURFXML_BUFFER_SET(host_availability_file, "");
+                         A_surfxml_host_state = A_surfxml_host_state_ON;
+                         SURFXML_BUFFER_SET(host_state_file, "");
+                         SURFXML_BUFFER_SET(host_interference_send, "1.0");
+                         SURFXML_BUFFER_SET(host_interference_recv, "1.0");
+                         SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
+                         SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
                          SURFXML_START_TAG(host);
                          SURFXML_END_TAG(host);
 
-                         DEBUG3("\t<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
+                         DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
+                         SURFXML_BUFFER_RESET();
                          SURFXML_BUFFER_SET(link_id, link_id);
                          SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
                          SURFXML_BUFFER_SET(link_latency, cluster_lat);
+                         SURFXML_BUFFER_SET(link_bandwidth_file, "");
+                         SURFXML_BUFFER_SET(link_latency_file, "");
+                         A_surfxml_link_state = A_surfxml_link_state_ON;
+                         SURFXML_BUFFER_SET(link_state_file, "");
+                         A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
                          SURFXML_START_TAG(link);
                          SURFXML_END_TAG(link);
 
@@ -2251,16 +2278,31 @@ static void routing_full_parse_Scluster(void)
                                  host_id = bprintf("%s%d%s", cluster_prefix, i, cluster_suffix);
                                  link_id = bprintf("%s_link_%d", cluster_id, i);
 
-                                 DEBUG2("\t<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
+                                 DEBUG2("<host\tid=\"%s\"\tpower=\"%s\"/>",host_id,cluster_power);
+                                 SURFXML_BUFFER_RESET();
                                  SURFXML_BUFFER_SET(host_id, host_id);
                                  SURFXML_BUFFER_SET(host_power, cluster_power);
+                                 SURFXML_BUFFER_SET(host_availability, "1.0");
+                                 SURFXML_BUFFER_SET(host_availability_file, "");
+                                 A_surfxml_host_state = A_surfxml_host_state_ON;
+                                 SURFXML_BUFFER_SET(host_state_file, "");
+                                 SURFXML_BUFFER_SET(host_interference_send, "1.0");
+                                 SURFXML_BUFFER_SET(host_interference_recv, "1.0");
+                                 SURFXML_BUFFER_SET(host_interference_send_recv, "1.0");
+                                 SURFXML_BUFFER_SET(host_max_outgoing_rate, "-1.0");
                                  SURFXML_START_TAG(host);
                                  SURFXML_END_TAG(host);
 
-                                 DEBUG3("\t<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
+                                 DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_id,cluster_bw,cluster_lat);
+                                 SURFXML_BUFFER_RESET();
                                  SURFXML_BUFFER_SET(link_id, link_id);
                                  SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
                                  SURFXML_BUFFER_SET(link_latency, cluster_lat);
+                                 SURFXML_BUFFER_SET(link_bandwidth_file, "");
+                                 SURFXML_BUFFER_SET(link_latency_file, "");
+                                 A_surfxml_link_state = A_surfxml_link_state_ON;
+                                 SURFXML_BUFFER_SET(link_state_file, "");
+                                 A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
                                  SURFXML_START_TAG(link);
                                  SURFXML_END_TAG(link);
                          }
@@ -2274,13 +2316,41 @@ static void routing_full_parse_Scluster(void)
        }
 
        DEBUG0(" ");
-       router_id = bprintf("%s.router%s",cluster_prefix,cluster_suffix);
+       router_id = bprintf("%srouter%s",cluster_prefix,cluster_suffix);
        link_router = bprintf("%s_link_router",cluster_id);
        link_backbone = bprintf("%s_backbone",cluster_id);
 
-       DEBUG1("\t<router id=\"%s\"\">",router_id);
-       DEBUG3("\t<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_router,cluster_bw,cluster_lat);
-       DEBUG3("\t<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_backbone,cluster_bb_bw,cluster_bb_lat);
+       DEBUG1("<router id=\"%s\"\">",router_id);
+       SURFXML_BUFFER_RESET();
+       SURFXML_BUFFER_SET(router_id, router_id);;
+       SURFXML_START_TAG(router);
+       SURFXML_END_TAG(router);
+
+       DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_router,cluster_bw,cluster_lat);
+       SURFXML_BUFFER_RESET();
+       SURFXML_BUFFER_SET(link_id, link_router);
+       SURFXML_BUFFER_SET(link_bandwidth, cluster_bw);
+       SURFXML_BUFFER_SET(link_latency, cluster_lat);
+       SURFXML_BUFFER_SET(link_bandwidth_file, "");
+       SURFXML_BUFFER_SET(link_latency_file, "");
+       A_surfxml_link_state = A_surfxml_link_state_ON;
+       SURFXML_BUFFER_SET(link_state_file, "");
+       A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
+       SURFXML_START_TAG(link);
+       SURFXML_END_TAG(link);
+
+       DEBUG3("<link\tid=\"%s\"\tbw=\"%s\"\tlat=\"%s\"/>",link_backbone,cluster_bb_bw,cluster_bb_lat);
+       SURFXML_BUFFER_RESET();
+       SURFXML_BUFFER_SET(link_id, link_backbone);
+       SURFXML_BUFFER_SET(link_bandwidth, cluster_bb_bw);
+       SURFXML_BUFFER_SET(link_latency, cluster_bb_lat);
+       SURFXML_BUFFER_SET(link_bandwidth_file, "");
+       SURFXML_BUFFER_SET(link_latency_file, "");
+       A_surfxml_link_state = A_surfxml_link_state_ON;
+       SURFXML_BUFFER_SET(link_state_file, "");
+       A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
+       SURFXML_START_TAG(link);
+       SURFXML_END_TAG(link);
 
        char *new_suffix = bprintf("%s","");
 
@@ -2295,33 +2365,36 @@ static void routing_full_parse_Scluster(void)
        route_src_dst = bprintf("%s(.*)%s",cluster_prefix,new_suffix);
 
        DEBUG0(" ");
-       DEBUG2("\t<route\tsrc=\"%s\"\tdst=\"%s\">",route_src_dst,route_src_dst);
-       DEBUG1("\t<link:ctn\tid=\"%s_link_$src1\"/>",cluster_id);
-       DEBUG1("\t<link:ctn\tid=\"%s_backbone\"/>",cluster_id);
-       DEBUG1("\t<link:ctn\tid=\"%s_link_$dst1\"/>",cluster_id);
-       DEBUG0("\t</route>");
+
+       DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\">",route_src_dst,route_src_dst);
+       SURFXML_BUFFER_RESET();
+       SURFXML_BUFFER_SET(route_src, route_src_dst);
+       SURFXML_BUFFER_SET(route_dst, route_src_dst);
+       SURFXML_START_TAG(route);
+
+       DEBUG1("<link:ctn\tid=\"%s_link_$1src\"/>",cluster_id);
+       SURFXML_BUFFER_RESET();
+       SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$1src",cluster_id));
+       SURFXML_START_TAG(link_c_ctn);
+       SURFXML_END_TAG(link_c_ctn);
+
+       DEBUG1("<link:ctn\tid=\"%s_backbone\"/>",cluster_id);
+       SURFXML_BUFFER_RESET();
+       SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_backbone",cluster_id));
+       SURFXML_START_TAG(link_c_ctn);
+       SURFXML_END_TAG(link_c_ctn);
+
+       DEBUG1("<link:ctn\tid=\"%s_link_$1dst\"/>",cluster_id);
+       SURFXML_BUFFER_RESET();
+       SURFXML_BUFFER_SET(link_c_ctn_id, bprintf("%s_link_$1dst",cluster_id));
+       SURFXML_START_TAG(link_c_ctn);
+       SURFXML_END_TAG(link_c_ctn);
+
+       DEBUG0("</route>");
+       SURFXML_END_TAG(route);
+
        DEBUG0("</AS>");
        SURFXML_END_TAG(AS);
-//
-//  /*   <link id="LinkA" bandwidth="10000000.0" latency="0.2"/> */
-//    SURFXML_BUFFER_SET(link_id, "LinkA");
-//    SURFXML_BUFFER_SET(link_bandwidth, "10000000.0");
-//    SURFXML_BUFFER_SET(link_bandwidth_file, "");
-//    SURFXML_BUFFER_SET(link_latency, "0.2");
-//    SURFXML_BUFFER_SET(link_latency_file, "");
-//    A_surfxml_link_state = A_surfxml_link_state_ON;
-//    SURFXML_BUFFER_SET(link_state_file, "");
-//    A_surfxml_link_sharing_policy = A_surfxml_link_sharing_policy_SHARED;
-//    SURFXML_START_TAG(link);
-//    SURFXML_END_TAG(link);
-//
-//  /*   <route src="host A" dst="host B"><link:ctn id="LinkA"/></route> */
-//  // OLD THINGS COMMENTED
-//  //   SURFXML_BUFFER_SET(route_src, "host A");
-//  //   SURFXML_BUFFER_SET(route_dst, "host B");
-//  //   SURFXML_BUFFER_SET(route_impact_on_src, "0.0");
-//  //   SURFXML_BUFFER_SET(route_impact_on_dst, "0.0");
-//  //   SURFXML_BUFFER_SET(route_impact_on_src_with_other_recv, "0.0");
-//  //   SURFXML_BUFFER_SET(route_impact_on_dst_with_other_send, "0.0");
+       DEBUG0(" ");
 
 }