Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix bug introduced by the new routing mechanism, added more debug and error checking.
[simgrid.git] / src / surf / network_gtnets.c
index eb561fa..ae7a6ce 100644 (file)
@@ -1,5 +1,3 @@
-/*     $Id$     */
-
 /* Copyright (c) 2005 Henri Casanova. All rights reserved.                  */
 
 /* This program is free software; you can redistribute it and/or modify it
@@ -8,12 +6,25 @@
 #include "network_gtnets_private.h"
 #include "gtnets/gtnets_interface.h"
 #include "xbt/str.h"
+#include "surf_private.h"
+#include "surf/datatypes.h"
+
+/* ************************************************************************** */
+/* *************************** FULL ROUTING ********************************* */
+typedef struct {
+  s_routing_t generic_routing;
+  xbt_dynar_t *routing_table;
+  void *loopback;
+  size_t size_of_link;
+} s_routing_full_t,*routing_full_t;
 
 
 static double time_to_next_flow_completion = -1;
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets, surf,
-                                "Logging specific to the SURF network module");
+                                "Logging specific to the SURF network GTNetS module");
+
+extern routing_t used_routing;
 
 /** QUESTIONS for GTNetS integration
  **   1. Check that we did the right thing with name_service and get_resource_name
@@ -75,7 +86,8 @@ static void link_new(char *name, double bw, double lat, xbt_dict_t props)
   gtnets_link->lat_current = lat;
   gtnets_link->id = link_count;
 
-  xbt_dict_set(surf_network_model->resource_set, name, gtnets_link, surf_resource_free);
+  xbt_dict_set(surf_network_model->resource_set, name, gtnets_link,
+               surf_resource_free);
 
   return;
 }
@@ -149,6 +161,13 @@ static void route_onehop_new(int src_id, int dst_id,
   }
 }
 
+/* Read hosts using a full-fledged topollogy */
+static void routing_full_parse_Shost(void) {
+  int *val = xbt_malloc(sizeof(int));
+  DEBUG2("Seen host %s (#%d)",A_surfxml_host_id,used_routing->host_count);
+  *val = used_routing->host_count++;
+  xbt_dict_set(used_routing->host_id,A_surfxml_host_id,val,xbt_free);
+}
 
 
 /* Parse the XML for a network link */
@@ -157,20 +176,20 @@ static void parse_link_init(void)
   char *name;
   double bw;
   double lat;
-  e_surf_link_state_t state;
+  e_surf_resource_state_t state;
 
   name = xbt_strdup(A_surfxml_link_id);
   surf_parse_get_double(&bw, A_surfxml_link_bandwidth);
   surf_parse_get_double(&lat, A_surfxml_link_latency);
-  state = SURF_LINK_ON;
+  state = SURF_RESOURCE_ON;
 
   tmgr_trace_t bw_trace;
   tmgr_trace_t state_trace;
   tmgr_trace_t lat_trace;
 
-  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);
+  bw_trace = tmgr_trace_new(A_surfxml_link_bandwidth_file);
+  lat_trace = tmgr_trace_new(A_surfxml_link_latency_file);
+  state_trace = tmgr_trace_new(A_surfxml_link_state_file);
 
   if (bw_trace)
     INFO0("The GTNetS network model doesn't support bandwidth state traces");
@@ -208,7 +227,22 @@ static void parse_route_set_route(void)
   char *name;
   if (src_id != -1 && dst_id != -1) {
     name = bprintf("%x#%x", src_id, dst_id);
+    DEBUG0("Calling manage route with route_action=");
+    switch (route_action) {
+           case A_surfxml_route_action_PREPEND:
+                                  DEBUG0("PREPEND");
+                                  break;
+           case A_surfxml_route_action_POSTPEND:
+                                  DEBUG0("POSTPEND");
+                                  break;
+           case A_surfxml_route_action_OVERRIDE:
+                                  DEBUG0("OVERRIDE");
+                   break;
+           default:break;
+    }
     manage_route(route_table, name, route_action, 0);
+
+    DEBUG2("Setting a route from NIC %d to NIC %d", src_id, dst_id);
     free(name);
   }
 }
@@ -242,14 +276,17 @@ static void add_route()
 
     xbt_dynar_foreach(links, cpt, link) {
       TRY {
-        link_list[nb_link++] = xbt_dict_get(surf_network_model->resource_set, link);
+        link_list[nb_link++] =
+          xbt_dict_get(surf_network_model->resource_set, link);
       }
       CATCH(e) {
         RETHROW1("Link %s not found (dict raised this exception: %s)", link);
       }
     }
-    if (nb_link == 1)
+    if (nb_link == 1){
+      DEBUG0("Calling a one link route");
       route_onehop_new(src_id, dst_id, link_list, nb_link);
+    }
   }
 
   xbt_dict_foreach(route_table, cursor, key, data) {
@@ -267,7 +304,8 @@ static void add_route()
 
     xbt_dynar_foreach(links, cpt, link) {
       TRY {
-        link_list[nb_link++] = xbt_dict_get(surf_network_model->resource_set, link);
+        link_list[nb_link++] =
+          xbt_dict_get(surf_network_model->resource_set, link);
       }
       CATCH(e) {
         RETHROW1("Link %s not found (dict raised this exception: %s)", link);
@@ -278,19 +316,29 @@ static void add_route()
   }
 
   xbt_dict_free(&route_table);
-  gtnets_print_topology();
+  if (XBT_LOG_ISENABLED(surf_network_gtnets, xbt_log_priority_debug)) {
+         gtnets_print_topology();
+  }
   XBT_OUT;
 }
 
 /* Main XML parsing */
 static void define_callbacks(const char *file)
 {
+  routing_full_t routing = xbt_new0(s_routing_full_t,1);
+  routing->generic_routing.name = "Full";
+  routing->generic_routing.host_count = 0;
+  routing->generic_routing.host_id = xbt_dict_new();
+  used_routing = (routing_t) routing;
+  surfxml_add_callback(STag_surfxml_host_cb_list, &routing_full_parse_Shost);
+
   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_cb_list, &parse_route_set_route);
   surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
+
 }
 
 /* We do not care about this: only used for traces */
@@ -323,8 +371,13 @@ static void action_recycle(surf_action_t action)
   return;
 }
 
+static double action_get_remains(surf_action_t action)
+{
+  return action->remains;
+}
+
 static void action_state_set(surf_action_t action,
-                                e_surf_action_state_t state)
+                             e_surf_action_state_t state)
 {
 /*   if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */
 /*     if(((surf_action_network_GTNETS_t)action)->variable) { */
@@ -340,8 +393,7 @@ static void action_state_set(surf_action_t action,
 /* share_resources() */
 static double share_resources(double now)
 {
-  xbt_swag_t running_actions =
-    surf_network_model->states.running_action_set;
+  xbt_swag_t running_actions = surf_network_model->states.running_action_set;
 
   //get the first relevant value from the running_actions list
   if (!xbt_swag_size(running_actions))
@@ -350,7 +402,9 @@ static double share_resources(double now)
   xbt_assert0(time_to_next_flow_completion,
               "Time to next flow completion not initialized!\n");
 
+  DEBUG0("Calling gtnets_get_time_to_next_flow_completion");
   time_to_next_flow_completion = gtnets_get_time_to_next_flow_completion();
+  DEBUG1("gtnets_get_time_to_next_flow_completion received %lg", time_to_next_flow_completion);
 
   return time_to_next_flow_completion;
 }
@@ -366,8 +420,7 @@ static void update_actions_state(double now, double delta)
 {
   surf_action_network_GTNETS_t action = NULL;
   //  surf_action_network_GTNETS_t next_action = NULL;
-  xbt_swag_t running_actions =
-    surf_network_model->states.running_action_set;
+  xbt_swag_t running_actions = surf_network_model->states.running_action_set;
 
   /* If there are no renning flows, just return */
   if (time_to_next_flow_completion < 0.0) {
@@ -434,12 +487,16 @@ static void update_resource_state(void *id,
 
 /* KF: Rate not supported */
 /* Max durations are not supported */
-static surf_action_t communicate(const char *src_name, const char *dst_name,int src, int dst, double size,
-                                 double rate)
+static surf_action_t communicate(const char *src_name, const char *dst_name,
+                                 int src, int dst, double size, double rate)
 {
   surf_action_network_GTNETS_t action = NULL;
 
-  action = surf_action_new(sizeof(s_surf_action_network_GTNETS_t),size,surf_network_model,0);
+  DEBUG4("Setting flow src %d \"%s\", dst %d \"%s\"", src, src_name, dst, dst_name);
+
+  action =
+    surf_action_new(sizeof(s_surf_action_network_GTNETS_t), size,
+                    surf_network_model, 0);
 
   /* KF: Add a flow to the GTNets Simulation, associated to this action */
   if (gtnets_create_flow(src, dst, size, (void *) action) < 0) {
@@ -489,6 +546,7 @@ static void surf_network_model_init_internal(void)
   surf_network_model->action_cancel = action_cancel;
   surf_network_model->action_recycle = action_recycle;
   surf_network_model->action_state_set = action_state_set;
+  surf_network_model->get_remains = action_get_remains;
 
   surf_network_model->model_private->resource_used = resource_used;
   surf_network_model->model_private->share_resources = share_resources;
@@ -508,6 +566,7 @@ static void surf_network_model_init_internal(void)
   if (gtnets_initialize()) {
     xbt_assert0(0, "impossible to initialize GTNetS interface");
   }
+
 }
 
 #ifdef HAVE_GTNETS