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 bb50e63..0819e31 100644 (file)
@@ -8,7 +8,8 @@
 #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;*/
@@ -140,11 +141,12 @@ 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 */
@@ -153,6 +155,25 @@ static void route_new(int src_id, int dst_id, char **links, int nb_link)
   }
 }
 
+/* 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_onehop_route(src_id, dst_id, linkid)) {
+    xbt_assert0(0,"Cannot create GTNetS route");
+  }
+}
+
 /* Parse the XML for a network link */
 static void parse_network_link(void)
 {
@@ -206,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)
 {
@@ -214,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 */
@@ -231,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();
@@ -270,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)
@@ -334,16 +394,19 @@ static void update_actions_state(double now, double delta)
 #endif
 
   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;
 
+    num_flows = 0;
+
     if (gtnets_run_until_next_flow_completion(&metadata, &num_flows)) {
       xbt_assert0(0,"Cannot run GTNetS simulation until next flow completion");
     }
@@ -357,7 +420,7 @@ static void update_actions_state(double now, double delta)
 
       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 */
@@ -536,8 +599,6 @@ static void surf_network_resource_init_internal(void)
   }
 }
 
-
-
 void surf_network_resource_init_GTNETS(const char *filename)
 {
   if (surf_network_resource)
@@ -545,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);
 }