Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a platform with a bypass route. Add the test to cmake.
[simgrid.git] / teshsuite / simdag / platforms / flatifier.c
index 813c866..5695df8 100644 (file)
@@ -50,21 +50,25 @@ int main(int argc, char **argv)
   unsigned int i;
   xbt_dict_t props = NULL;
   xbt_dict_cursor_t cursor = NULL;
-  xbt_dict_cursor_t cursor_src = NULL;
-  xbt_dict_cursor_t cursor_dst = NULL;
+  xbt_lib_cursor_t cursor_src = NULL;
+  xbt_lib_cursor_t cursor_dst = NULL;
   char *src,*dst,*key,*data;
+  char **value;
   xbt_ex_t e;
 
   const SD_workstation_t *hosts;
   const SD_link_t *links;
 
+  setvbuf(stdout, NULL, _IOLBF, 0);
+
   SD_init(&argc, argv);
 
   platformFile = argv[1];
   XBT_DEBUG("%s", platformFile);
   TRY {
     SD_create_environment(platformFile);
-  } CATCH(e) {
+  }
+  CATCH(e) {
     xbt_die("Error while loading %s: %s",platformFile,e.msg);
   }
 
@@ -84,7 +88,7 @@ int main(int argc, char **argv)
            SD_workstation_get_name(hosts[i]),
            SD_workstation_get_power(hosts[i]));
     props = SD_workstation_get_properties(hosts[i]);
-    if (xbt_dict_length(props) > 0) {
+    if (props && !xbt_dict_is_empty(props)) {
       printf(">\n");
       xbt_dict_foreach(props, cursor, key, data) {
         printf("    <prop id=\"%s\" value=\"%s\"/>\n", key, data);
@@ -96,9 +100,9 @@ int main(int argc, char **argv)
   }
 
   // Routers
-  xbt_dict_foreach(global_routing->where_network_elements, cursor, key, data) {
-         if(((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, key))->rc_type
-                         == SURF_NETWORK_ELEMENT_ROUTER)
+  xbt_lib_foreach(as_router_lib, cursor_src, key, value) {
+         if(((network_element_info_t)xbt_lib_get_or_null(as_router_lib, key,
+                         ROUTING_ASR_LEVEL))->rc_type == SURF_NETWORK_ELEMENT_ROUTER)
          {
                  printf("  <router id=\"%s\"/>\n",key);
          }
@@ -107,6 +111,7 @@ int main(int argc, char **argv)
   // Links
   totalLinks = SD_link_get_number();
   links = SD_link_get_list();
+
   qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
 
   for (i = 0; i < totalLinks; i++) {
@@ -123,35 +128,84 @@ int main(int argc, char **argv)
     }
   }
 
-  // Routes
-  xbt_dict_foreach(global_routing->where_network_elements, cursor_src, src, data)
+
+  xbt_lib_foreach(host_lib, cursor_src, src, value) // Routes from host
   {
-         if(((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, src))->rc_type
-                         == SURF_NETWORK_ELEMENT_ROUTER ||
-                         ((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, src))->rc_type
-                         == SURF_NETWORK_ELEMENT_HOST)
-         {
-                 xbt_dict_foreach(global_routing->where_network_elements, cursor_dst, dst, data)
+                 xbt_lib_foreach(host_lib, cursor_dst, dst, value) //to host
+                 {
+                               printf("  <route src=\"%s\" dst=\"%s\">\n  "
+                                         ,src
+                                         ,dst);
+                               xbt_dynar_t route=NULL;
+                               routing_get_route_and_latency(src,dst,&route,NULL);
+                               for(i=0;i<xbt_dynar_length(route) ;i++)
+                               {
+                                       void *link = xbt_dynar_get_as(route,i,void *);
+
+                                       char *link_name = xbt_strdup(((surf_resource_t)link)->name);
+                                       printf("<link_ctn id=\"%s\"/>",link_name);
+                                       free(link_name);
+                               }
+                               printf("\n  </route>\n");
+                 }
+                 xbt_lib_foreach(as_router_lib, cursor_dst, dst, value) //to router
                  {
-                         if(((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, dst))->rc_type
-                                         == SURF_NETWORK_ELEMENT_ROUTER ||
-                                         ((network_element_info_t)xbt_dict_get(global_routing->where_network_elements, dst))->rc_type
-                                         == SURF_NETWORK_ELEMENT_HOST)
-                         {
-                               printf("  <route src=\"%s\" dst=\"%s\">\n       "
+                           if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){
+                               printf("  <route src=\"%s\" dst=\"%s\">\n  "
                                          ,src
                                          ,dst);
-                               xbt_dynar_t route = global_routing->get_route(src,dst);
+                               xbt_dynar_t route=NULL;
+                               routing_get_route_and_latency(src,dst,&route,NULL);
                                for(i=0;i<xbt_dynar_length(route) ;i++)
                                {
                                        void *link = xbt_dynar_get_as(route,i,void *);
 
-                                       char *link_name = bprintf("%s",((surf_resource_t) link)->name);
+                                       char *link_name = xbt_strdup(((surf_resource_t)link)->name);
                                        printf("<link_ctn id=\"%s\"/>",link_name);
+                                       free(link_name);
                                }
                                printf("\n  </route>\n");
+                           }
+                 }
+  }
 
-                         }
+  xbt_lib_foreach(as_router_lib, cursor_src, src, value) // Routes from router
+  {
+         if(routing_get_network_element_type(src) == SURF_NETWORK_ELEMENT_ROUTER){
+                 xbt_lib_foreach(as_router_lib, cursor_dst, dst, value) //to router
+                 {
+                               if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){
+                               printf("  <route src=\"%s\" dst=\"%s\">\n  "
+                                         ,src
+                                         ,dst);
+                               xbt_dynar_t route=NULL;
+                               routing_get_route_and_latency(src,dst,&route,NULL);
+                               for(i=0;i<xbt_dynar_length(route) ;i++)
+                               {
+                                       void *link = xbt_dynar_get_as(route,i,void *);
+
+                                       char *link_name = xbt_strdup(((surf_resource_t)link)->name);
+                                       printf("<link_ctn id=\"%s\"/>",link_name);
+                                       free(link_name);
+                               }
+                               printf("\n  </route>\n");
+                               }
+                 }
+                 xbt_lib_foreach(host_lib, cursor_dst, dst, value) //to host
+                 {
+                               printf("  <route src=\"%s\" dst=\"%s\">\n  "
+                                         ,src, dst);
+                               xbt_dynar_t route=NULL;
+                               routing_get_route_and_latency(src,dst,&route, NULL);
+                               for(i=0;i<xbt_dynar_length(route) ;i++)
+                               {
+                                       void *link = xbt_dynar_get_as(route,i,void *);
+
+                                       char *link_name = xbt_strdup(((surf_resource_t)link)->name);
+                                       printf("<link_ctn id=\"%s\"/>",link_name);
+                                       free(link_name);
+                               }
+                               printf("\n  </route>\n");
                  }
          }
   }