Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add debug on topology.
[simgrid.git] / src / surf / network_gtnets.c
index d1c58eb..59a344a 100644 (file)
@@ -101,6 +101,7 @@ static int network_card_new(const char *name)
 {
   static int card_count = -1;
 
+  XBT_IN1("(%s)",name);
   /* KF: Check that we haven't seen the network card before */
   network_card_GTNETS_t card =
       xbt_dict_get_or_null(network_card_set, name);
@@ -115,7 +116,9 @@ static int network_card_new(const char *name)
     card->id = card_count;
     xbt_dict_set(network_card_set, name, card, network_card_free);
   }
-
+  
+  LOG1(xbt_log_priority_trace, "   return %d",card->id);
+  XBT_OUT;
   /* KF: just return the GTNetS ID as the SURF ID */
   return card->id;
 }
@@ -125,6 +128,8 @@ static void route_new(int src_id, int dst_id, network_link_GTNETS_t *links, int
 {
   int i;
   int *gtnets_links;
+  XBT_IN4("(src_id=%d, dst_id=%d, links=%p, nb_link=%d)",
+         src_id,dst_id,links,nb_link);
 
   /* KF: Build the list of gtnets link IDs */
   gtnets_links = (int *) calloc(nb_link, sizeof(int));
@@ -136,6 +141,7 @@ static void route_new(int src_id, int dst_id, network_link_GTNETS_t *links, int
   if (gtnets_add_route(src_id, dst_id, gtnets_links, nb_link)) {
     xbt_assert0(0, "Cannot create GTNetS route");
   }
+  XBT_OUT;
 }
 
 /* Instantiate a new route: MODIFY BY KF */
@@ -233,7 +239,7 @@ static void add_route()
   static network_link_GTNETS_t *link_list = NULL;
 
 
-  DEBUG0("Entering add_route()");
+  XBT_IN;
   xbt_dict_foreach(route_table, cursor, key, data) {
     char *link = NULL;
     nb_link = 0;
@@ -255,14 +261,38 @@ static void add_route()
         RETHROW1("Link %s not found (dict raised this exception: %s)", link);
       }     
     }
-    if (nb_link > 1)
-      route_new(src_id, dst_id, link_list, nb_link);
     if (nb_link == 1)
       route_onehop_new(src_id, dst_id, link_list, nb_link);
    }
 
+  xbt_dict_foreach(route_table, cursor, key, data) {
+    char *link = NULL;
+    nb_link = 0;
+    links = (xbt_dynar_t)data;
+    keys = xbt_str_split_str(key, sep);
+
+    link_list_capacity = xbt_dynar_length(links);
+    link_list = xbt_new(network_link_GTNETS_t, link_list_capacity);
+
+    src_id = strtol(xbt_dynar_get_as(keys, 0, char*), &end, 16);
+    dst_id = strtol(xbt_dynar_get_as(keys, 1, char*), &end, 16);
+    xbt_dynar_free(&keys);
+
+    xbt_dynar_foreach (links, cpt, link) {
+      TRY {
+        link_list[nb_link++] = 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_list, nb_link);
+   }
+
   xbt_dict_free(&route_table);
-  DEBUG0("Bailling add_route()");
+  gtnets_print_topology();
+  XBT_OUT;
 }
 
 /* Main XML parsing */
@@ -299,8 +329,8 @@ static int resource_used(void *resource_id)
 
 static int action_free(surf_action_t action)
 {
-  action->using--;
-  if (!action->using) {
+  action->refcount--;
+  if (!action->refcount) {
     xbt_swag_remove(action, action->state_set);
     /* KF: No explicit freeing needed for GTNeTS here */
     free(action);
@@ -311,7 +341,7 @@ static int action_free(surf_action_t action)
 
 static void action_use(surf_action_t action)
 {
-  action->using++;
+  action->refcount++;
 }
 
 static void action_cancel(surf_action_t action)
@@ -391,18 +421,17 @@ static void update_actions_state(double now, double delta)
                  "GTNetS simulation couldn't find a flow that would complete");
     }
 
-
-
     xbt_swag_foreach(action, running_actions) {
-      DEBUG1("]]]]]]]]] Action remains old value: %f", action->generic_action.remains);
+      DEBUG2("Action (%p) remains old value: %f", action, action->generic_action.remains);
       double remain = gtnets_get_flow_rx(action);
+      DEBUG1("Remain value returned by GTNetS : %f", remain);
       //need to trust this remain value
       if(remain == 0){
        action->generic_action.remains=0;
       }else {
-       action->generic_action.remains-=remain;
+       action->generic_action.remains=action->generic_action.cost-remain;
       }
-      DEBUG1("[[[[[[[[[ Action remains new value: %f", action->generic_action.remains);
+      DEBUG2("Action (%p) remains new value: %f", action, action->generic_action.remains);
     }
 
     for (i = 0; i < num_flows; i++) {
@@ -410,12 +439,7 @@ static void update_actions_state(double now, double delta)
       
       action->generic_action.finish = now + time_to_next_flow_completion;
       action_change_state((surf_action_t) action, SURF_ACTION_DONE);
-      /* TODO: Anything else here? */
-
-      //need to map this action to the gtnets engine
-      DEBUG1("]]]]]]]]] Action remains old value: %f", action->generic_action.remains);
-      action->generic_action.remains -= gtnets_get_flow_rx(metadata[i]);
-      DEBUG1("[[[[[[[[[ Action remains new value: %f", action->generic_action.remains);
+      DEBUG1("----> Action (%p) just terminated",action);
     }
 
 
@@ -455,7 +479,7 @@ static surf_action_t communicate(void *src, void *dst, double size,
 
   action = xbt_new0(s_surf_action_network_GTNETS_t, 1);
 
-  action->generic_action.using = 1;
+  action->generic_action.refcount = 1;
   action->generic_action.cost = size;
   action->generic_action.remains = size;
   /* Max durations are not supported */