Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make GTNETS compatible with new parsing and variable name convention.
[simgrid.git] / src / surf / network_gtnets.c
index 758ef59..e3f081d 100644 (file)
@@ -7,24 +7,11 @@
 
 #include "network_gtnets_private.h"
 #include "gtnets/gtnets_interface.h"
+#include "xbt/str.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets, surf,
                                "Logging specific to the SURF network module");
 
-/* surf_network_model_t surf_network_model = NULL; */
-/*static xbt_dict_t link_set = NULL;*/
-
-/* xbt_dict_t network_card_set = NULL; */
-
-#if 0
-static int card_number = 0;
-static link_GTNETS_t **routing_table = NULL;
-static int *routing_table_size = NULL;
-
-#define ROUTE(i,j) routing_table[(i)+(j)*card_number]
-#define ROUTE_SIZE(i,j) routing_table_size[(i)+(j)*card_number]
-#endif
-
 /** QUESTIONS for GTNetS integration
  **   1. Check that we did the right thing with name_service and get_resource_name
  **   2. Right now there is no "kill flow" in our GTNetS implementation. Do we
@@ -38,7 +25,7 @@ static int *routing_table_size = NULL;
 /* Free memory for a network link */
 static void link_free(void *nw_link)
 {
-  free(((link_GTNETS_t) nw_link)->name);
+  free(((network_link_GTNETS_t) nw_link)->name);
   free(nw_link);
 }
 
@@ -49,9 +36,9 @@ static void link_free(void *nw_link)
 static void link_new(char *name, double bw, double lat, xbt_dict_t props)
 {
   static int link_count = -1;
-  link_GTNETS_t gtnets_link;
+  network_link_GTNETS_t gtnets_link;
 
-  /* KF: Check that the link wasn't added before */
+  /* If link already exists, nothing to do (FIXME: check that multiple definition match?) */
   if (xbt_dict_get_or_null(link_set, name)) {
     return;
   }
@@ -82,7 +69,7 @@ static void link_new(char *name, double bw, double lat, xbt_dict_t props)
   }
 
   /* KF: Insert entry in the dictionary */
-  gtnets_link = xbt_new0(s_link_GTNETS_t, 1);
+  gtnets_link = xbt_new0(s_network_link_GTNETS_t, 1);
   gtnets_link->name = name;
   gtnets_link->bw_current = bw;
   gtnets_link->lat_current = lat;
@@ -130,12 +117,12 @@ static int network_card_new(const char *name)
 static void route_new(int src_id, int dst_id, char **links, int nb_link)
 {
 #if 0
-  link_GTNETS_t *link_list = NULL;
+  network_link_GTNETS_t *link_list = NULL;
   int i;
 
   ROUTE_SIZE(src_id, dst_id) = nb_link;
   link_list = (ROUTE(src_id, dst_id) =
-              xbt_new0(link_GTNETS_t, nb_link));
+              xbt_new0(network_link_GTNETS_t, nb_link));
   for (i = 0; i < nb_link; i++) {
     link_list[i] = xbt_dict_get_or_null(link_set, links[i]);
     free(links[i]);
@@ -149,7 +136,7 @@ static void route_new(int src_id, int dst_id, char **links, int nb_link)
   gtnets_links = (int *) calloc(nb_link, sizeof(int));
   for (i = 0; i < nb_link; i++) {
     gtnets_links[i] =
-       ((link_GTNETS_t)
+       ((network_link_GTNETS_t)
         (xbt_dict_get(link_set, links[i])))->id;
   }
 
@@ -171,7 +158,7 @@ static void route_onehop_new(int src_id, int dst_id, char **links,
 
   /* KF: Build the list of gtnets link IDs */
   linkid =
-      ((link_GTNETS_t)
+      ((network_link_GTNETS_t)
        (xbt_dict_get(link_set, links[0])))->id;
 
   /* KF: Create the GTNets route */
@@ -190,10 +177,10 @@ static void parse_link_init(void)
   double lat;
   e_surf_link_state_t state;
 
-  name = xbt_strdup(A_surfxml_link_name);
+  name = xbt_strdup(A_surfxml_link_id);
   surf_parse_get_double(&bw, A_surfxml_link_bandwidth);
   surf_parse_get_double(&lat, A_surfxml_link_latency);
-  state = SURF_link_ON;
+  state = SURF_LINK_ON;
 
   /* Print values when no traces are specified */
   {
@@ -233,14 +220,17 @@ static void parse_route_set_endpoints(void)
 {
   src_id = network_card_new(A_surfxml_route_src);
   dst_id = network_card_new(A_surfxml_route_dst);
-  nb_link = 0;
+
+/*  nb_link = 0;
   link_name = NULL;
+*/
+  route_link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
 }
 
 /* KF*/
 static void parse_route_set_routers(void)
 {
-  int id = network_card_new(A_surfxml_router_name);
+  int id = network_card_new(A_surfxml_router_id);
 
   /* KF: Create the GTNets router */
   if (gtnets_add_router(id)) {
@@ -248,21 +238,28 @@ static void parse_route_set_routers(void)
   }
 }
 
+//The following is common to all and has been relocated to surfxml_parse
 /* Parses a route element from the XML: UNMODIFIED BY HC */
-static void parse_route_elem(void)
+/*static void parse_route_elem(void)
 {
   nb_link++;
   link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *));
   link_name[(nb_link) - 1] = xbt_strdup(A_surfxml_route_element_name);
 }
+*/
 
 /* Create the route (more than one hops): MODIFIED BY KF */
 static void parse_route_set_route(void)
 {
-  if (nb_link > 1)
+/*  if (nb_link > 1)
     route_new(src_id, dst_id, link_name, nb_link);
+*/
+    char *name = bprintf("%x#%x",src_id, dst_id);
+    xbt_dict_set(route_table, name, route_link_list, NULL);
+    free(name);    
 }
 
+//This is not used anymore. one hop routes are created in add_route
 /* Create the one-hope route: BY KF */
 static void parse_route_set_onehop_route(void)
 {
@@ -270,23 +267,63 @@ static void parse_route_set_onehop_route(void)
     route_onehop_new(src_id, dst_id, link_name, nb_link);
 }
 
+static void add_route()
+{
+  xbt_ex_t e;
+  unsigned int cpt = 0;    
+  int i = 0;
+  xbt_dict_cursor_t cursor = NULL;
+  char *key,*data, *end;
+  const char *sep = "#";
+  xbt_dynar_t links, keys;
+
+  xbt_dict_foreach(route_table, cursor, key, data) {
+    nb_link = 0;
+    links = (xbt_dynar_t)data;
+    keys = xbt_str_split_str(key, sep);
+
+    nb_link = xbt_dynar_length(links);
+    link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *));
+
+    src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16);
+    dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16);
+  
+    i = 0;
+    char* link = NULL;
+    xbt_dynar_foreach (links, cpt, link) {
+      TRY {
+        link_name[i++] = xbt_dict_get(link_set, link);
+      }
+      CATCH(e) {
+        RETHROW1("Link %s not found (dict raised this exception: %s)", link);
+      }     
+    }
+    if (nb_link > 1)
+      route_new(src_id, dst_id, link_name, nb_link);
+    if (nb_link == 1)
+      route_onehop_new(src_id, dst_id, link_name, nb_link);
+   }
+
+   xbt_dict_free(&route_table);
+}
+
 /* Main XML parsing */
-static void parse_file(const char *file)
+static void define_callbacks(const char *file)
 {
-  surf_parse_reset_parser();
-
   surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
   surfxml_add_callback(STag_surfxml_router_cb_list, &parse_route_set_routers);
   surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
   surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
-  surfxml_add_callback(ETag_surfxml_route_element_cb_list, &parse_route_elem);
-  surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_onehop_route);
+  surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
+/* surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_onehop_route);*/
+  surfxml_add_callback(STag_surfxml_platform_cb_list, &init_data);
   surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
-
-  surf_parse_open(file);
-  xbt_assert1((!surf_parse()), "Parse error in %s", file);
-  surf_parse_close();
-
+  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
+  surfxml_add_callback(STag_surfxml_set_cb_list, &parse_sets);
+  surfxml_add_callback(STag_surfxml_route_c_multi_cb_list, &parse_route_multi_set_endpoints);
+  surfxml_add_callback(ETag_surfxml_route_c_multi_cb_list, &parse_route_multi_set_route);
+  surfxml_add_callback(STag_surfxml_foreach_cb_list, &parse_foreach);
+  surfxml_add_callback(STag_surfxml_cluster_cb_list, &parse_cluster);
 }
 
 static void *name_service(const char *name)
@@ -299,7 +336,7 @@ static const char *get_resource_name(void *resource_id)
   return ((network_card_GTNETS_t) resource_id)->name;
 }
 
-static xbt_dict_t get_link_property_list(void *link)
+static xbt_dict_t get_properties(void *link)
 {
   return ((network_card_GTNETS_t) link)->properties;
 }
@@ -428,7 +465,7 @@ static void update_actions_state(double now, double delta)
 /* UNUSED HERE: no traces */
 static void update_resource_state(void *id,
                                  tmgr_trace_event_t event_type,
-                                 double value)
+                                 double value, double date)
 {
   xbt_assert0(0, "Cannot update model state for GTNetS simulation");
   return;
@@ -443,7 +480,7 @@ static surf_action_t communicate(void *src, void *dst, double size,
   network_card_GTNETS_t card_dst = dst;
 /*
   int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
-  link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
+  network_link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
 */
 
 /*
@@ -576,8 +613,7 @@ static void surf_network_model_init_internal(void)
   surf_network_model->common_private->share_resources = share_resources;
   surf_network_model->common_private->update_actions_state =
       update_actions_state;
-  surf_network_model->common_private->update_resource_state =
-      update_resource_state;
+  surf_network_model->common_private->update_resource_state = update_resource_state;
   surf_network_model->common_private->finalize = finalize;
 
   surf_network_model->common_public->suspend = action_suspend;
@@ -587,7 +623,7 @@ static void surf_network_model_init_internal(void)
   surf_network_model->extension_public->communicate = communicate;
 
   /*for the props of the link*/
-  surf_network_model->common_public->get_link_properties =  get_link_property_list;
+  surf_network_model->common_public->get_properties =  get_properties;
 
   link_set = xbt_dict_new();
   network_card_set = xbt_dict_new();
@@ -603,7 +639,7 @@ void surf_network_model_init_GTNETS(const char *filename)
   if (surf_network_model)
     return;
   surf_network_model_init_internal();
-  parse_file(filename);
+  define_callbacks(filename);
   xbt_dynar_push(model_list, &surf_network_model);
 
   update_model_description(surf_network_model_description,