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 232fc7e..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
 /* 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 "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,
 
 
 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
 
 /** QUESTIONS for GTNetS integration
  **   1. Check that we did the right thing with name_service and get_resource_name
@@ -28,13 +39,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network_gtnets, surf,
 static int src_id = -1;
 static int dst_id = -1;
 
 static int src_id = -1;
 static int dst_id = -1;
 
-/* Free memory for a network link */
-static void link_free(void *nw_link)
-{
-  xbt_dict_free(&(((network_link_GTNETS_t) nw_link)->properties));
-  surf_resource_free(nw_link);
-}
-
 /* Instantiate a new network link */
 /* name: some name for the link, from the XML */
 /* bw: The bandwidth value            */
 /* Instantiate a new network link */
 /* name: some name for the link, from the XML */
 /* bw: The bandwidth value            */
@@ -77,13 +81,13 @@ static void link_new(char *name, double bw, double lat, xbt_dict_t props)
   /* KF: Insert entry in the dictionary */
   gtnets_link = xbt_new0(s_network_link_GTNETS_t, 1);
   gtnets_link->generic_resource.name = name;
   /* KF: Insert entry in the dictionary */
   gtnets_link = xbt_new0(s_network_link_GTNETS_t, 1);
   gtnets_link->generic_resource.name = name;
+  gtnets_link->generic_resource.properties = props;
   gtnets_link->bw_current = bw;
   gtnets_link->lat_current = lat;
   gtnets_link->id = link_count;
   gtnets_link->bw_current = bw;
   gtnets_link->lat_current = lat;
   gtnets_link->id = link_count;
-  /* Add the properties */
-  gtnets_link->properties = props;
 
 
-  xbt_dict_set(surf_network_model->resource_set, name, gtnets_link, link_free);
+  xbt_dict_set(surf_network_model->resource_set, name, gtnets_link,
+               surf_resource_free);
 
   return;
 }
 
   return;
 }
@@ -104,7 +108,7 @@ static int network_card_new(const char *name)
 
     /* KF: just use the dictionary to map link names to link indices */
     card = xbt_new0(s_network_card_GTNETS_t, 1);
 
     /* KF: just use the dictionary to map link names to link indices */
     card = xbt_new0(s_network_card_GTNETS_t, 1);
-    card->generic_resource.name = xbt_strdup(name);
+    card->name = xbt_strdup(name);
     card->id = card_count;
     xbt_dict_set(surf_model_resource_set(surf_network_model), name, card,
                  surf_resource_free);
     card->id = card_count;
     xbt_dict_set(surf_model_resource_set(surf_network_model), name, card,
                  surf_resource_free);
@@ -157,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 */
 
 
 /* Parse the XML for a network link */
@@ -165,20 +176,20 @@ static void parse_link_init(void)
   char *name;
   double bw;
   double lat;
   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);
 
   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;
 
 
   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");
 
   if (bw_trace)
     INFO0("The GTNetS network model doesn't support bandwidth state traces");
@@ -216,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);
   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);
     manage_route(route_table, name, route_action, 0);
+
+    DEBUG2("Setting a route from NIC %d to NIC %d", src_id, dst_id);
     free(name);
   }
 }
     free(name);
   }
 }
@@ -250,14 +276,17 @@ static void add_route()
 
     xbt_dynar_foreach(links, cpt, link) {
       TRY {
 
     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);
       }
     }
       }
       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);
       route_onehop_new(src_id, dst_id, link_list, nb_link);
+    }
   }
 
   xbt_dict_foreach(route_table, cursor, key, data) {
   }
 
   xbt_dict_foreach(route_table, cursor, key, data) {
@@ -275,7 +304,8 @@ static void add_route()
 
     xbt_dynar_foreach(links, cpt, link) {
       TRY {
 
     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);
       }
       CATCH(e) {
         RETHROW1("Link %s not found (dict raised this exception: %s)", link);
@@ -286,27 +316,31 @@ static void add_route()
   }
 
   xbt_dict_free(&route_table);
   }
 
   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)
 {
   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);
   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);
-}
 
 
-static xbt_dict_t get_properties(void *link)
-{
-  return ((network_card_GTNETS_t) link)->properties;
 }
 
 }
 
-
 /* We do not care about this: only used for traces */
 static int resource_used(void *resource_id)
 {
 /* We do not care about this: only used for traces */
 static int resource_used(void *resource_id)
 {
@@ -337,8 +371,13 @@ static void action_recycle(surf_action_t action)
   return;
 }
 
   return;
 }
 
-static void action_change_state(surf_action_t action,
-                                e_surf_action_state_t state)
+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)
 {
 /*   if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */
 /*     if(((surf_action_network_GTNETS_t)action)->variable) { */
 {
 /*   if((state==SURF_ACTION_DONE) || (state==SURF_ACTION_FAILED)) */
 /*     if(((surf_action_network_GTNETS_t)action)->variable) { */
@@ -354,8 +393,7 @@ static void action_change_state(surf_action_t action,
 /* share_resources() */
 static double share_resources(double now)
 {
 /* share_resources() */
 static double share_resources(double now)
 {
-  xbt_swag_t running_actions =
-    surf_network_model->common_public.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))
 
   //get the first relevant value from the running_actions list
   if (!xbt_swag_size(running_actions))
@@ -364,7 +402,9 @@ static double share_resources(double now)
   xbt_assert0(time_to_next_flow_completion,
               "Time to next flow completion not initialized!\n");
 
   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();
   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;
 }
 
   return time_to_next_flow_completion;
 }
@@ -380,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;
 {
   surf_action_network_GTNETS_t action = NULL;
   //  surf_action_network_GTNETS_t next_action = NULL;
-  xbt_swag_t running_actions =
-    surf_network_model->common_public.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) {
 
   /* If there are no renning flows, just return */
   if (time_to_next_flow_completion < 0.0) {
@@ -423,7 +462,7 @@ static void update_actions_state(double now, double delta)
       action = (surf_action_network_GTNETS_t) (metadata[i]);
 
       action->generic_action.finish = now + time_to_next_flow_completion;
       action = (surf_action_network_GTNETS_t) (metadata[i]);
 
       action->generic_action.finish = now + time_to_next_flow_completion;
-      action_change_state((surf_action_t) action, SURF_ACTION_DONE);
+      action_state_set((surf_action_t) action, SURF_ACTION_DONE);
       DEBUG1("----> Action (%p) just terminated", action);
     }
 
       DEBUG1("----> Action (%p) just terminated", action);
     }
 
@@ -447,42 +486,22 @@ static void update_resource_state(void *id,
 }
 
 /* KF: Rate not supported */
 }
 
 /* KF: Rate not supported */
-static surf_action_t communicate(void *src, void *dst, double size,
-                                 double rate)
+/* 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)
 {
   surf_action_network_GTNETS_t action = NULL;
 {
   surf_action_network_GTNETS_t action = NULL;
-  network_card_GTNETS_t card_src = src;
-  network_card_GTNETS_t card_dst = dst;
-/*
-  int route_size = ROUTE_SIZE(card_src->id, card_dst->id);
-  network_link_GTNETS_t *route = ROUTE(card_src->id, card_dst->id);
-*/
-
-/*
-  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);
-*/
-
-  action = xbt_new0(s_surf_action_network_GTNETS_t, 1);
-
-  action->generic_action.refcount = 1;
-  action->generic_action.cost = size;
-  action->generic_action.remains = size;
-  /* Max durations are not supported */
-  action->generic_action.max_duration = NO_MAX_DURATION;
-  action->generic_action.start = surf_get_clock();
-  action->generic_action.finish = -1.0;
-  action->generic_action.model_type = surf_network_model;
 
 
-  action->generic_action.state_set =
-    surf_network_model->common_public.states.running_action_set;
+  DEBUG4("Setting flow src %d \"%s\", dst %d \"%s\"", src, src_name, dst, dst_name);
 
 
-  xbt_swag_insert(action, action->generic_action.state_set);
+  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 */
 
   /* KF: Add a flow to the GTNets Simulation, associated to this action */
-  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->generic_resource.name,
-                card_dst->generic_resource.name);
+  if (gtnets_create_flow(src, dst, size, (void *) action) < 0) {
+    xbt_assert2(0, "Not route between host %s and host %s", src_name,
+                dst_name);
   }
 
   return (surf_action_t) action;
   }
 
   return (surf_action_t) action;
@@ -520,15 +539,14 @@ static void finalize(void)
 
 static void surf_network_model_init_internal(void)
 {
 
 static void surf_network_model_init_internal(void)
 {
-  s_surf_action_t action;
-
   surf_network_model = surf_model_init();
 
   surf_network_model->name = "network GTNetS";
   surf_network_model->action_unref = action_unref;
   surf_network_model->action_cancel = action_cancel;
   surf_network_model->action_recycle = action_recycle;
   surf_network_model = surf_model_init();
 
   surf_network_model->name = "network GTNetS";
   surf_network_model->action_unref = action_unref;
   surf_network_model->action_cancel = action_cancel;
   surf_network_model->action_recycle = action_recycle;
-  surf_network_model->action_change_state = action_change_state;
+  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;
 
   surf_network_model->model_private->resource_used = resource_used;
   surf_network_model->model_private->share_resources = share_resources;
@@ -544,13 +562,11 @@ static void surf_network_model_init_internal(void)
 
   surf_network_model->extension.network.communicate = communicate;
 
 
   surf_network_model->extension.network.communicate = communicate;
 
-  /*for the props of the link */
-  surf_network_model->get_properties = get_properties;
-
   /* KF: Added the initialization for GTNetS interface */
   if (gtnets_initialize()) {
     xbt_assert0(0, "impossible to initialize GTNetS interface");
   }
   /* KF: Added the initialization for GTNetS interface */
   if (gtnets_initialize()) {
     xbt_assert0(0, "impossible to initialize GTNetS interface");
   }
+
 }
 
 #ifdef HAVE_GTNETS
 }
 
 #ifdef HAVE_GTNETS