Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adding modifications for 1 pass & for adding routes only when platform end tag reached
[simgrid.git] / src / surf / network_gtnets.c
index c0c0eb0..02d05c8 100644 (file)
 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 network_link_set = NULL;*/
-
-/* xbt_dict_t network_card_set = NULL; */
-
-#if 0
-static int card_number = 0;
-static network_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_model_name
+ **   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
  **      need to do something about this?
  **   3. We ignore the fact there is some max_duration on flows (see #2 above)
- **   4. share_models() returns a duration, not a date, right?
+ **   4. share_resources() returns a duration, not a date, right?
  **   5. We don't suppoer "rates"
  **   6. We don't update "remaining" for ongoing flows. Is it bad?
  **/
 
 /* Free memory for a network link */
-static void network_link_free(void *nw_link)
+static void link_free(void *nw_link)
 {
-  free(((network_link_GTNETS_t) nw_link)->name);
+  free(((link_GTNETS_t) nw_link)->name);
   free(nw_link);
 }
 
@@ -46,13 +32,13 @@ static void network_link_free(void *nw_link)
 /* name: some name for the link, from the XML */
 /* bw: The bandwidth value            */
 /* lat: The latency value             */
-static void network_link_new(char *name, double bw, double lat)
+static void link_new(char *name, double bw, double lat, xbt_dict_t props)
 {
   static int link_count = -1;
-  network_link_GTNETS_t gtnets_link;
+  link_GTNETS_t gtnets_link;
 
-  /* KF: Check that the link wasn't added before */
-  if (xbt_dict_get_or_null(network_link_set, name)) {
+  /* If link already exists, nothing to do (FIXME: check that multiple definition match?) */
+  if (xbt_dict_get_or_null(link_set, name)) {
     return;
   }
 
@@ -82,12 +68,15 @@ static void network_link_new(char *name, double bw, double lat)
   }
 
   /* KF: Insert entry in the dictionary */
-  gtnets_link = xbt_new0(s_network_link_GTNETS_t, 1);
+  gtnets_link = xbt_new0(s_link_GTNETS_t, 1);
   gtnets_link->name = name;
   gtnets_link->bw_current = bw;
   gtnets_link->lat_current = lat;
   gtnets_link->id = link_count;
-  xbt_dict_set(network_link_set, name, gtnets_link, network_link_free);
+  /* Add the properties */
+  gtnets_link->properties = current_property_set;
+
+  xbt_dict_set(link_set, name, gtnets_link, link_free);
 
   return;
 }
@@ -127,14 +116,14 @@ 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
-  network_link_GTNETS_t *link_list = NULL;
+  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(network_link_GTNETS_t, nb_link));
+              xbt_new0(link_GTNETS_t, nb_link));
   for (i = 0; i < nb_link; i++) {
-    link_list[i] = xbt_dict_get_or_null(network_link_set, links[i]);
+    link_list[i] = xbt_dict_get_or_null(link_set, links[i]);
     free(links[i]);
   }
   free(links);
@@ -146,8 +135,8 @@ 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] =
-       ((network_link_GTNETS_t)
-        (xbt_dict_get(network_link_set, links[i])))->id;
+       ((link_GTNETS_t)
+        (xbt_dict_get(link_set, links[i])))->id;
   }
 
   /* KF: Create the GTNets route */
@@ -168,8 +157,8 @@ static void route_onehop_new(int src_id, int dst_id, char **links,
 
   /* KF: Build the list of gtnets link IDs */
   linkid =
-      ((network_link_GTNETS_t)
-       (xbt_dict_get(network_link_set, links[0])))->id;
+      ((link_GTNETS_t)
+       (xbt_dict_get(link_set, links[0])))->id;
 
   /* KF: Create the GTNets route */
   if (gtnets_add_onehop_route(src_id, dst_id, linkid)) {
@@ -177,18 +166,20 @@ static void route_onehop_new(int src_id, int dst_id, char **links,
   }
 }
 
+
+
 /* Parse the XML for a network link */
-static void parse_network_link(void)
+static void parse_link_init(void)
 {
   char *name;
   double bw;
   double lat;
-  e_surf_network_link_state_t state;
+  e_surf_link_state_t state;
 
-  name = xbt_strdup(A_surfxml_network_link_name);
-  surf_parse_get_double(&bw, A_surfxml_network_link_bandwidth);
-  surf_parse_get_double(&lat, A_surfxml_network_link_latency);
-  state = SURF_NETWORK_LINK_ON;
+  name = xbt_strdup(A_surfxml_link_name);
+  surf_parse_get_double(&bw, A_surfxml_link_bandwidth);
+  surf_parse_get_double(&lat, A_surfxml_link_latency);
+  state = SURF_link_ON;
 
   /* Print values when no traces are specified */
   {
@@ -196,9 +187,9 @@ static void parse_network_link(void)
     tmgr_trace_t state_trace;
     tmgr_trace_t lat_trace;
 
-    surf_parse_get_trace(&bw_trace, A_surfxml_network_link_bandwidth_file);
-    surf_parse_get_trace(&lat_trace, A_surfxml_network_link_latency_file);
-    surf_parse_get_trace(&state_trace, A_surfxml_network_link_state_file);
+    surf_parse_get_trace(&bw_trace, A_surfxml_link_bandwidth_file);
+    surf_parse_get_trace(&lat_trace, A_surfxml_link_latency_file);
+    surf_parse_get_trace(&state_trace, A_surfxml_link_state_file);
 
     /*TODO Where is WARNING0 defined??? */
 #if 0
@@ -213,10 +204,9 @@ static void parse_network_link(void)
          ("The GTNetS network model doesn't support link state traces");
 #endif
   }
-
-
-  /* KF: remove several arguments to network_link_new */
-  network_link_new(name, bw, lat);
+  /* KF: remove several arguments to link_new */
+  current_property_set = xbt_dict_new();
+  link_new(name, bw, lat, current_property_set);
 }
 
 static int nb_link = 0;
@@ -229,8 +219,11 @@ 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 *), &free_string);
 }
 
 /* KF*/
@@ -244,21 +237,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);
+*/
+    name = bprintf("%d##%d",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)
 {
@@ -266,50 +266,45 @@ 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;
+  int cpt = 0;    
+  int i = 0;
+
+  nb_link = xbt_dynar_length(links);
+  link_name = xbt_realloc(link_name, (nb_link) * sizeof(char *));
+
+  src_id = atoi(xbt_dynar_get_as(keys, 0, char*));
+  dst_id = atoi(xbt_dynar_get_as(keys, 1, char*));
+  
+  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);
+}
+
 /* Main XML parsing */
-static void parse_file(const char *file)
-{
-  /* Figuring out the network links */
-  surf_parse_reset_parser();
-  ETag_surfxml_network_link_fun = parse_network_link;
-  surf_parse_open(file);
-  xbt_assert1((!surf_parse()), "Parse error in %s", file);
-  surf_parse_close();
-
-  /* Figuring out the network cards used */
-  /* KF
-     surf_parse_reset_parser();
-     STag_surfxml_route_fun=parse_route_set_endpoints;
-     surf_parse_open(file);
-     xbt_assert1((!surf_parse()),"Parse error in %s",file);
-     surf_parse_close();
-   */
-
-  /* KF: Figuring out the router (considered as part of
-     network cards) used. */
-  surf_parse_reset_parser();
-  STag_surfxml_router_fun = parse_route_set_routers;
-  surf_parse_open(file);
-  xbt_assert1((!surf_parse()), "Parse error in %s", file);
-  surf_parse_close();
-
-  /* Building the one-hop routes */
-  surf_parse_reset_parser();
-  STag_surfxml_route_fun = parse_route_set_endpoints;
-  ETag_surfxml_route_element_fun = parse_route_elem;
-  ETag_surfxml_route_fun = parse_route_set_onehop_route;
-  surf_parse_open(file);
-  xbt_assert1((!surf_parse()), "Parse error in %s", file);
-  surf_parse_close();
-
-  /* Building the routes */
-  surf_parse_reset_parser();
-  STag_surfxml_route_fun = parse_route_set_endpoints;
-  ETag_surfxml_route_element_fun = parse_route_elem;
-  ETag_surfxml_route_fun = parse_route_set_route;
-  surf_parse_open(file);
-  xbt_assert1((!surf_parse()), "Parse error in %s", file);
-  surf_parse_close();
+static void define_callbacks(const char *file)
+{
+  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_route_cb_list, &parse_route_set_route);
+  surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
 }
 
 static void *name_service(const char *name)
@@ -317,13 +312,19 @@ static void *name_service(const char *name)
   return xbt_dict_get_or_null(network_card_set, name);
 }
 
-static const char *get_model_name(void *model_id)
+static const char *get_resource_name(void *resource_id)
+{
+  return ((network_card_GTNETS_t) resource_id)->name;
+}
+
+static xbt_dict_t get_properties(void *link)
 {
-  return ((network_card_GTNETS_t) model_id)->name;
+  return ((network_card_GTNETS_t) link)->properties;
 }
 
+
 /* We do not care about this: only used for traces */
-static int model_used(void *model_id)
+static int resource_used(void *resource_id)
 {
   return 0;                    /* We don't care */
 }
@@ -371,8 +372,8 @@ static void action_change_state(surf_action_t action,
 }
 
 
-/* share_models() */
-static double share_models(double now)
+/* share_resources() */
+static double share_resources(double now)
 {
 #if 0
   s_surf_action_network_GTNETS_t s_action;
@@ -443,7 +444,7 @@ static void update_actions_state(double now, double delta)
 }
 
 /* UNUSED HERE: no traces */
-static void update_model_state(void *id,
+static void update_resource_state(void *id,
                                  tmgr_trace_event_t event_type,
                                  double value)
 {
@@ -460,7 +461,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);
-  network_link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
+  link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
 */
 
 /*
@@ -520,7 +521,7 @@ static void finalize(void)
   int i, j;
 #endif
   xbt_dict_free(&network_card_set);
-  xbt_dict_free(&network_link_set);
+  xbt_dict_free(&link_set);
   xbt_swag_free(surf_network_model->common_public->states.
                ready_action_set);
   xbt_swag_free(surf_network_model->common_public->states.
@@ -575,8 +576,8 @@ static void surf_network_model_init_internal(void)
       xbt_swag_new(xbt_swag_offset(action, state_hookup));
 
   surf_network_model->common_public->name_service = name_service;
-  surf_network_model->common_public->get_model_name =
-      get_model_name;
+  surf_network_model->common_public->get_resource_name =
+      get_resource_name;
   surf_network_model->common_public->action_get_state =
       surf_action_get_state;
   surf_network_model->common_public->action_use = action_use;
@@ -589,12 +590,12 @@ static void surf_network_model_init_internal(void)
       surf_action_set_data;
   surf_network_model->common_public->name = "network";
 
-  surf_network_model->common_private->model_used = model_used;
-  surf_network_model->common_private->share_models = share_models;
+  surf_network_model->common_private->resource_used = resource_used;
+  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_model_state =
-      update_model_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;
@@ -603,11 +604,11 @@ static void surf_network_model_init_internal(void)
 
   surf_network_model->extension_public->communicate = communicate;
 
-  network_link_set = xbt_dict_new();
-  network_card_set = xbt_dict_new();
+  /*for the props of the link*/
+  surf_network_model->common_public->get_properties =  get_properties;
 
-  /* HC: I am assuming that this stays in for simulation of compute tasks */
-  xbt_assert0(maxmin_system, "surf_init has to be called first!");
+  link_set = xbt_dict_new();
+  network_card_set = xbt_dict_new();
 
   /* KF: Added the initialization for GTNetS interface */
   if (gtnets_initialize()) {
@@ -620,7 +621,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,