]> AND Public Git Repository - simgrid.git/blobdiff - src/surf/surf_routing.c
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Read and store coordinates.
[simgrid.git] / src / surf / surf_routing.c
index e16cdfcedef191453a38e76d6f53bd6475f1d772..496c1521483427fb61ce4b25967245e9e89e6aed 100644 (file)
@@ -157,10 +157,13 @@ static const char *dst = NULL;        /* temporary store the destination name of
 static char *gw_src = NULL;     /* temporary store the gateway source name of a route */
 static char *gw_dst = NULL;     /* temporary store the gateway destination name of a route */
 static xbt_dynar_t link_list = NULL;    /* temporary store of current list link of a route */
+
+static xbt_dict_t coordinates = NULL;
+
 /**
  * \brief Add a "host" to the network element list
  */
-static void parse_S_host(char *host_id)
+static void parse_S_host(char *host_id, char* coord)
 {
   network_element_info_t info = NULL;
   if (current_routing->hierarchy == SURF_ROUTING_NULL)
@@ -178,6 +181,12 @@ static void parse_S_host(char *host_id)
   info->rc_type = SURF_NETWORK_ELEMENT_HOST;
   xbt_dict_set(global_routing->where_network_elements, host_id,
                (void *) info, NULL);
+
+  if (strcmp(coord,"")) {
+       xbt_dynar_t ctn = xbt_str_split_str(coord, " ");
+       xbt_dynar_shrink(ctn,0);
+       xbt_dict_set (coordinates,host_id,ctn,NULL);
+  }
 }
 
 /*
@@ -185,15 +194,15 @@ static void parse_S_host(char *host_id)
  */
 static void parse_S_host_XML(void)
 {
-  parse_S_host(A_surfxml_host_id);
+       parse_S_host(A_surfxml_host_id, A_surfxml_host_coordinates);
 }
 
 /*
  * \brief Add a host to the network element list from lua script
  */
-static void parse_S_host_lua(char *host_id)
+static void parse_S_host_lua(char *host_id, char *coord)
 {
-  parse_S_host(host_id);
+  parse_S_host(host_id, coord);
 }
 
 
@@ -314,12 +323,18 @@ static void parse_E_link_ctn_new_elem(char *link_id)
 
 static void parse_E_link_ctn_new_elem_XML(void)
 {
-  if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
-         parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
-  if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP)
-         parse_E_link_ctn_new_elem(bprintf("%s_UP",A_surfxml_link_ctn_id));
-  if( A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN)
-         parse_E_link_ctn_new_elem(bprintf("%s_DOWN",A_surfxml_link_ctn_id));
+  if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_NONE)
+    parse_E_link_ctn_new_elem(A_surfxml_link_ctn_id);
+  if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_UP) {
+    char *link_id = bprintf("%s_UP", A_surfxml_link_ctn_id);
+    parse_E_link_ctn_new_elem(link_id);
+    free(link_id);
+  }
+  if (A_surfxml_link_ctn_direction == A_surfxml_link_ctn_direction_DOWN) {
+    char *link_id = bprintf("%s_DOWN", A_surfxml_link_ctn_id);
+    parse_E_link_ctn_new_elem(link_id);
+    free(link_id);
+  }
 }
 
 /**
@@ -946,6 +961,7 @@ static void finalize(void)
   _finalize(global_routing->root);
   /* delete "where" dict */
   xbt_dict_free(&(global_routing->where_network_elements));
+  xbt_dict_free(&(coordinates));
   /* delete last_route */
   xbt_dynar_free(&(global_routing->last_route));
   /* delete global routing structure */
@@ -1018,6 +1034,8 @@ void routing_model_create(size_t size_of_links, void *loopback, double_f_cpvoid_
   /* no current routing at moment */
   current_routing = NULL;
 
+  coordinates = xbt_dict_new();
+
   /* parse generic elements */
   surfxml_add_callback(STag_surfxml_host_cb_list, &parse_S_host_XML);
   surfxml_add_callback(STag_surfxml_router_cb_list, &parse_S_router);
@@ -1284,10 +1302,10 @@ static void model_full_set_route(routing_component_t rc, const char *src,
        {
                if(route->dst_gateway && route->src_gateway)
                {
-                       char * gw_src = bprintf("%s",route->src_gateway);
-                       char * gw_dst = bprintf("%s",route->dst_gateway);
-                       route->src_gateway = bprintf("%s",gw_dst);
-                       route->dst_gateway = bprintf("%s",gw_src);
+                  char *gw_src = xbt_strdup(route->src_gateway);
+                  char *gw_dst = xbt_strdup(route->dst_gateway);
+                  route->src_gateway = gw_dst;
+                  route->dst_gateway = gw_src;
                }
                if(TO_ROUTE_FULL(*dst_id, *src_id))
                {
@@ -1682,10 +1700,10 @@ static void model_floyd_set_route(routing_component_t rc, const char *src,
                {
                        if(route->dst_gateway && route->src_gateway)
                        {
-                               char * gw_src = bprintf("%s",route->src_gateway);
-                               char * gw_dst = bprintf("%s",route->dst_gateway);
-                               route->src_gateway = bprintf("%s",gw_dst);
-                               route->dst_gateway = bprintf("%s",gw_src);
+                          char *gw_src = xbt_strdup(route->src_gateway);
+                          char *gw_dst = xbt_strdup(route->dst_gateway);
+                          route->src_gateway = gw_dst;
+                          route->dst_gateway = gw_src;
                        }
 
                        if(!route->dst_gateway && !route->src_gateway)
@@ -3271,6 +3289,8 @@ static void routing_parse_Scluster(void)
       SURFXML_START_TAG(link);
       SURFXML_END_TAG(link);
 
+      free(link_id);
+      free(host_id);
       break;
 
     case 2:
@@ -3311,6 +3331,9 @@ static void routing_parse_Scluster(void)
         SURFXML_BUFFER_SET(link_state_file, "");
         SURFXML_START_TAG(link);
         SURFXML_END_TAG(link);
+
+        free(link_id);
+        free(host_id);
       }
       break;
 
@@ -3320,6 +3343,7 @@ static void routing_parse_Scluster(void)
 
     xbt_dynar_free(&radical_ends);
   }
+  xbt_dynar_free(&radical_elements);
 
   DEBUG0(" ");
   router_id =
@@ -3366,15 +3390,23 @@ static void routing_parse_Scluster(void)
   DEBUG0(" ");
 
 #ifdef HAVE_PCRE_LIB
-  char *new_suffix = bprintf("%s", "");
+  char *new_suffix = xbt_strdup("");
 
   radical_elements = xbt_str_split(cluster_suffix, ".");
   xbt_dynar_foreach(radical_elements, iter, groups) {
     if (strcmp(groups, "")) {
-      new_suffix = bprintf("%s\\.%s", new_suffix, groups);
+      char *old_suffix = new_suffix;
+      new_suffix = bprintf("%s\\.%s", old_suffix, groups);
+      free(old_suffix);
     }
   }
   route_src_dst = bprintf("%s(.*)%s", cluster_prefix, new_suffix);
+  xbt_dynar_free(&radical_elements);
+  free(new_suffix);
+
+  char *pcre_link_src = bprintf("%s_link_$1src", cluster_id);
+  char *pcre_link_backbone = bprintf("%s_backbone", cluster_id);
+  char *pcre_link_dst = bprintf("%s_link_$1dst", cluster_id);
 
   DEBUG2("<route\tsrc=\"%s\"\tdst=\"%s\"", route_src_dst, route_src_dst);
   DEBUG0("symmetrical=\"NO\">");
@@ -3383,22 +3415,22 @@ static void routing_parse_Scluster(void)
   A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO;
   SURFXML_START_TAG(route);
 
-  DEBUG1("<link_ctn\tid=\"%s_link_$1src\"/>", cluster_id);
-  SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1src", cluster_id));
+  DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_src);
+  SURFXML_BUFFER_SET(link_ctn_id, pcre_link_src);
   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_UP;}
   SURFXML_START_TAG(link_ctn);
   SURFXML_END_TAG(link_ctn);
 
-  DEBUG1("<link_ctn\tid=\"%s_backbone\"/>", cluster_id);
-  SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_backbone", cluster_id));
+  DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_backbone);
+  SURFXML_BUFFER_SET(link_ctn_id, pcre_link_backbone);
   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
   SURFXML_START_TAG(link_ctn);
   SURFXML_END_TAG(link_ctn);
 
-  DEBUG1("<link_ctn\tid=\"%s_link_$1dst\"/>", cluster_id);
-  SURFXML_BUFFER_SET(link_ctn_id, bprintf("%s_link_$1dst", cluster_id));
+  DEBUG1("<link_ctn\tid=\"%s\"/>", pcre_link_dst);
+  SURFXML_BUFFER_SET(link_ctn_id, pcre_link_dst);
   A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE;
   if(cluster_sharing_policy == A_surfxml_cluster_sharing_policy_FULLDUPLEX)
   {A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_DOWN;}
@@ -3407,6 +3439,11 @@ static void routing_parse_Scluster(void)
 
   DEBUG0("</route>");
   SURFXML_END_TAG(route);
+
+  free(pcre_link_dst);
+  free(pcre_link_backbone);
+  free(pcre_link_src);
+  free(route_src_dst);
 #else
   for (i = 0; i <= xbt_dynar_length(tab_elements_num); i++) {
     for (j = 0; j <= xbt_dynar_length(tab_elements_num); j++) {
@@ -3478,8 +3515,13 @@ static void routing_parse_Scluster(void)
     }
   }
   xbt_dynar_free(&tab_elements_num);
+  free(router_id);
+
 #endif
 
+  free(link_backbone);
+  free(link_router);
+
   DEBUG0("</AS>");
   SURFXML_END_TAG(AS);
   DEBUG0(" ");
@@ -3513,7 +3555,7 @@ void routing_AS_end(const char *AS_id)
 
 void routing_add_host(const char *host_id)
 {
-  parse_S_host_lua((char *) host_id);
+  parse_S_host_lua((char *) host_id, (char*)""); // FIXME propagate coordinate system to lua
 }
 
 /*