Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[NS3, trace] instrumentation point to be implemented
[simgrid.git] / src / surf / network_ns3.c
index db84ca0..16f4cc1 100644 (file)
@@ -27,7 +27,7 @@ static double time_to_next_flow_completion = -1;
 static double ns3_share_resources(double min);
 static void ns3_update_actions_state(double now, double delta);
 static void finalize(void);
-static surf_action_t communicate(const char *src_name,
+static surf_action_t ns3_communicate(const char *src_name,
                                  const char *dst_name, double size, double rate);
 static void action_suspend(surf_action_t action);
 static void action_resume(surf_action_t action);
@@ -368,7 +368,7 @@ void surf_network_model_init_NS3(const char *filename)
        surf_network_model->resume = action_resume;
        surf_network_model->is_suspended = action_is_suspended;
        surf_network_model->action_unref = action_unref;
-       surf_network_model->extension.network.communicate = communicate;
+       surf_network_model->extension.network.communicate = ns3_communicate;
 
        /* Added the initialization for NS3 interface */
        if (ns3_initialize()) {
@@ -428,7 +428,7 @@ static void ns3_update_actions_state(double now, double delta)
          char *key;
          void *data;
 
-         surf_action_t action = NULL;
+         surf_action_network_ns3_t action = NULL;
          xbt_swag_t running_actions =
              surf_network_model->states.running_action_set;
 
@@ -437,28 +437,42 @@ static void ns3_update_actions_state(double now, double delta)
                return;
 
          xbt_dict_foreach(dict_socket,cursor,key,data){
-           action = (surf_action_t)ns3_get_socket_action(data);
-           action->remains = ns3_get_socket_remains(data);
+           action = (surf_action_network_ns3_t)ns3_get_socket_action(data);
+           action->generic_action.remains = action->generic_action.cost - ns3_get_socket_sent(data);
+
+#ifdef HAVE_TRACING
+           if (surf_action_state_get(&(action->generic_action)) == SURF_ACTION_RUNNING){
+//           double data_sent = ns3_get_socket_sent(data) - action->last_sent;
+             //TRACE here using data_sent/delta as data rate
+//           action->last_sent = ns3_get_socket_sent(data);
+           }
+#endif
 
            if(ns3_get_socket_is_finished(data) == 1){
-             action->finish = now;
-             surf_action_state_set(action, SURF_ACTION_DONE);
+             action->generic_action.finish = now;
+             surf_action_state_set(&(action->generic_action), SURF_ACTION_DONE);
            }
          }
          return;
 }
 
 /* Max durations are not supported */
-static surf_action_t communicate(const char *src_name,
+static surf_action_t ns3_communicate(const char *src_name,
                                  const char *dst_name, double size, double rate)
 {
-  surf_action_t action = NULL;
+  surf_action_network_ns3_t action = NULL;
 
   XBT_DEBUG("Communicate from %s to %s",src_name,dst_name);
-  action = surf_action_new(sizeof(s_surf_action_t), size, surf_network_model, 0);
+  action = surf_action_new(sizeof(s_surf_action_network_ns3_t), size, surf_network_model, 0);
 
   ns3_create_flow(src_name, dst_name, surf_get_clock(), size, action);
 
+#ifdef HAVE_TRACING
+  action->last_sent = 0;
+  action->src_name = xbt_strdup (src_name);
+  action->dst_name = xbt_strdup (dst_name);
+#endif
+
   return (surf_action_t) action;
 }
 
@@ -485,6 +499,14 @@ static int action_unref(surf_action_t action)
   action->refcount--;
   if (!action->refcount) {
     xbt_swag_remove(action, action->state_set);
+
+#ifdef HAVE_TRACING
+    xbt_free(((surf_action_network_ns3_t)action)->src_name);
+    xbt_free(((surf_action_network_ns3_t)action)->dst_name);
+    if (action->category)
+      xbt_free(action->category);
+#endif
+
     surf_action_free(&action);
     return 1;
   }