Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ptask_L07 can now do execute and communicate via execute_parallel_task
[simgrid.git] / src / surf / network_gtnets.c
index 4fbbaa1..0819e31 100644 (file)
@@ -6,11 +6,13 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "network_gtnets_private.h"
+#include "gtnets/gtnets_interface.h"
 
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_network_gtnets);
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets, surf,
+                               "Logging specific to the SURF network module");
 
 /* surf_network_resource_t surf_network_resource = NULL; */
-static xbt_dict_t network_link_set = NULL;
+/*static xbt_dict_t network_link_set = NULL;*/
 
 /* xbt_dict_t network_card_set = NULL; */
 
@@ -77,13 +79,13 @@ static void network_link_new(char *name,
 */
 
   /* KF: Add the link to the GTNetS simulation */
-  if (GTNetS_add_link(link_count, bw, lat)) {
+  if (gtnets_add_link(link_count, bw, lat)) {
     xbt_assert0(0,"Cannot create GTNetS link");
   }
 
   /* KF: Insert entry in the dictionary */
   gtnets_link = xbt_new0(s_network_link_GTNETS_t,1);
-  gtnets_link->name = strcpy(name);
+  gtnets_link->name = name;
   gtnets_link->bw_current = bw;
   gtnets_link->lat_current = lat;
   gtnets_link->id = link_count;
@@ -105,20 +107,21 @@ static int network_card_new(const char *name)
   static int card_count=-1;
 
   /* KF: Check that we haven't seen the network card before */ 
-  if (xbt_dict_get_or_null(network_card_set, name)) 
-    return;
+  network_card_GTNETS_t card = xbt_dict_get_or_null(network_card_set, name);
 
-  /* KF: Increment the card counter for GTNetS */
-  card_count++;
+  if (!card){
+    /* KF: Increment the card counter for GTNetS */
+    card_count++;
 
-  /* KF: just use the dictionary to map link names to link indices */
-  gtnets_network_card = xbt_new0(s_network_card_GTNETS_t,1);
-  gtnets_network_card->name = strcpy(name);
-  gtnets_network_card->id = card_count;
-  xbt_dict_set(network_card_set, name, gtnets_network_card, network_card_free);
+    /* KF: just use the dictionary to map link names to link indices */
+    card = xbt_new0(s_network_card_GTNETS_t,1);
+    card->name = xbt_strdup(name);
+    card->id = card_count;
+    xbt_dict_set(network_card_set, name, card, network_card_free);
+  }
 
   /* KF: just return the GTNetS ID as the SURF ID */
-  return card_count;
+  return card->id;
 }
 
 /* Instantiate a new route: MODIFY BY KF */
@@ -138,15 +141,35 @@ static void route_new(int src_id, int dst_id, char **links, int nb_link)
 #endif
   int i;
   int *gtnets_links;
+
   /* KF: Build the list of gtnets link IDs */
   gtnets_links = (int *)calloc(nb_link, sizeof(int));
   for (i=0; i<nb_link; i++) {
-    gtnets_links[i]=(int)(xbt_dict_get(network_link_set, links[i]))
+    gtnets_links[i]=
+      ((network_link_GTNETS_t)(xbt_dict_get(network_link_set, links[i])))->id;
+  }
+
+  /* KF: Create the GTNets route */
+  if (gtnets_add_route(src_id, dst_id, gtnets_links, nb_link)) {
+    xbt_assert0(0,"Cannot create GTNetS route");
+  }
+}
+
+/* Instantiate a new route: MODIFY BY KF */
+static void route_onehop_new(int src_id, int dst_id, char **links, int nb_link)
+{
+  int linkid;
+
+  if (nb_link != 1){
+    xbt_assert0(0, "In onehop_new, nb_link should be 1");
   }
 
+  /* KF: Build the list of gtnets link IDs */
+  linkid = 
+      ((network_link_GTNETS_t)(xbt_dict_get(network_link_set, links[0])))->id;
+
   /* KF: Create the GTNets route */
-  if (GTNetS_add_route(src_id, dst_id, gtnets_links, nb_link)) {
+  if (gtnets_add_onehop_route(src_id, dst_id, linkid)) {
     xbt_assert0(0,"Cannot create GTNetS route");
   }
 }
@@ -167,21 +190,25 @@ static void parse_network_link(void)
   /* Print values when no traces are specified */
   {
     tmgr_trace_t bw_trace;
-    tmgr_trace_t state;
+    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);
-  
+
+    /*TODO Where is WARNING0 defined???*/
+#if 0  
     if (bw_trace) 
       WARNING0("The GTNetS network model doesn't support bandwidth state traces");
     if (lat_trace)
       WARNING0("The GTNetS network model doesn't support latency state traces");
     if (state_trace)
       WARNING0("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);
 }
@@ -200,6 +227,17 @@ static void parse_route_set_endpoints(void)
   link_name = NULL;
 }
 
+/* KF*/
+static void parse_route_set_routers(void)
+{
+  int id = network_card_new(A_surfxml_router_name);
+
+  /* KF: Create the GTNets router */
+  if (gtnets_add_router(id)) {
+    xbt_assert0(0,"Cannot add GTNetS router");
+  }
+}
+
 /* Parses a route element from the XML: UNMODIFIED BY HC */
 static void parse_route_elem(void)
 {
@@ -208,10 +246,18 @@ static void parse_route_elem(void)
   link_name[(nb_link) - 1] = xbt_strdup(A_surfxml_route_element_name);
 }
 
-/* Create the route: UNMODIFIED BY HC */
+/* Create the route (more than one hops): MODIFIED BY KF */
 static void parse_route_set_route(void)
 {
-  route_new(src_id, dst_id, link_name, nb_link);
+  if (nb_link > 1)
+    route_new(src_id, dst_id, link_name, nb_link);
+}
+
+/* Create the one-hope route: BY KF */
+static void parse_route_set_onehop_route(void)
+{
+  if (nb_link == 1)
+    route_onehop_new(src_id, dst_id, link_name, nb_link);
 }
 
 /* Main XML parsing */
@@ -225,11 +271,30 @@ static void parse_file(const char *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();
@@ -264,8 +329,9 @@ static int action_free(surf_action_t action)
     xbt_swag_remove(action, action->state_set);
     /* KF: No explicit freeing needed for GTNeTS here */
     free(action);
+    return 1;
   }
-  return 1;
+  return 0;
 }
 
 static void action_use(surf_action_t action)
@@ -308,7 +374,7 @@ static double share_resources(double now)
   xbt_swag_t running_actions = surf_network_resource->common_public->states.running_action_set;
 #endif
 
-  return GTNetS_get_time_to_next_flow_completion();
+  return gtnets_get_time_to_next_flow_completion();
 }
 
 /* delta: by how many time units the simulation must advance */
@@ -320,23 +386,28 @@ static double share_resources(double now)
 
 static void update_actions_state(double now, double delta)
 {
+#if 0
   surf_action_network_GTNETS_t action = NULL;
   surf_action_network_GTNETS_t next_action = NULL;
   xbt_swag_t running_actions =
       surf_network_resource->common_public->states.running_action_set;
+#endif
+
+  double time_to_next_flow_completion =  gtnets_get_time_to_next_flow_completion();
 
-  double time_to_next_flow_completion =  GTNetS_get_time_to_next_flow_completion();
-  
   /* If there are no renning flows, just return */
   if (time_to_next_flow_completion < 0.0) {
     return;
   }
-  
-  if (time_to_next_flow_completion < delta) { /* run until the first flow completes */
-    void **metadata; 
+
+  /*KF: if delta == time_to_next_flow_completion, too.*/
+  if (time_to_next_flow_completion <= delta) { /* run until the first flow completes */
+    void **metadata;
     int i,num_flows;
 
-    if (GTNetS_run_until_next_flow_completion(&metadata, &num_flows)) {
+    num_flows = 0;
+
+    if (gtnets_run_until_next_flow_completion(&metadata, &num_flows)) {
       xbt_assert0(0,"Cannot run GTNetS simulation until next flow completion");
     }
     if (num_flows < 1) {
@@ -344,15 +415,16 @@ static void update_actions_state(double now, double delta)
     }
 
     for (i=0; i<num_flows; i++) {
-      surf_action_t action = (surf_action_t)(metadata[i]);
+      surf_action_network_GTNETS_t action = 
+       (surf_action_network_GTNETS_t)(metadata[i]);
 
       action->generic_action.remains = 0;
       action->generic_action.finish =  now + time_to_next_flow_completion;
-      action->generic_action.finish =  SURF_ACTION_DONE;
+      action_change_state((surf_action_t) action, SURF_ACTION_DONE);
       /* TODO: Anything else here? */
     }
   } else { /* run for a given number of seconds */
-    if (GTNetS_run(delta)) {
+    if (gtnets_run(delta)) {
       xbt_assert0(0,"Cannot run GTNetS simulation");
     }
   }
@@ -379,7 +451,6 @@ static surf_action_t communicate(void *src, void *dst, double size, double rate)
   int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
   network_link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
 */
-  int i;
 
 /*
   xbt_assert2(route_size,"You're trying to send data from %s to %s but there is no connexion between these two cards.", card_src->name, card_dst->name);
@@ -403,7 +474,7 @@ static surf_action_t communicate(void *src, void *dst, double size, double rate)
   xbt_swag_insert(action, action->generic_action.state_set);
 
   /* KF: Add a flow to the GTNets Simulation, associated to this action */
-  if (GTNetS_create_flow(src->id, dst->id, size, (void *)action) < 0) {
+  if (gtnets_create_flow(card_src->id, card_dst->id, size, (void *)action) < 0) {
     xbt_assert2(0,"Not route between host %s and host %s", card_src->name, card_dst->name);
   }
 
@@ -430,8 +501,9 @@ static int action_is_suspended(surf_action_t action)
 
 static void finalize(void)
 {
+#if 0
   int i,j;
-
+#endif
   xbt_dict_free(&network_card_set);
   xbt_dict_free(&network_link_set);
   xbt_swag_free(surf_network_resource->common_public->states.
@@ -461,7 +533,7 @@ static void finalize(void)
 #endif
 
   /* ADDED BY KF */
-  GTNetS_finalize();
+  gtnets_finalize();
   /* END ADDITION */
 }
 
@@ -522,15 +594,11 @@ static void surf_network_resource_init_internal(void)
   xbt_assert0(maxmin_system, "surf_init has to be called first!");
 
   /* KF: Added the initialization for GTNetS interface */
-  if (GTNetS_initialize()) {
+  if (gtnets_initialize()) {
     xbt_assert0(0, "impossible to initialize GTNetS interface");
   }
 }
 
-/* HC: I put this prototype here for now but it will have to go in 
-   src/include/surf.h when it is functionnal. */
-void surf_network_resource_init_GTNETS(const char *filename);
-
 void surf_network_resource_init_GTNETS(const char *filename)
 {
   if (surf_network_resource)
@@ -538,4 +606,9 @@ void surf_network_resource_init_GTNETS(const char *filename)
   surf_network_resource_init_internal();
   parse_file(filename);
   xbt_dynar_push(resource_list, &surf_network_resource);
+
+  update_resource_description(surf_network_resource_description,
+                             surf_network_resource_description_size,
+                             "GTNets",
+                             (surf_resource_t) surf_network_resource);
 }