Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New macros were added. Update the doc
[simgrid.git] / src / surf / network_gtnets.c
index 0d18534..5fffbe0 100644 (file)
@@ -140,11 +140,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 +154,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 +226,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 +245,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,8 +270,27 @@ 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();
@@ -270,8 +328,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 +393,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 +419,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,9 +598,7 @@ static void surf_network_resource_init_internal(void)
   }
 }
 
-/* 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)
 {