Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[NS3] using maxmin precision to avoid infinite loop
[simgrid.git] / src / surf / network_ns3.c
index b9f2de5..1185fda 100644 (file)
@@ -5,6 +5,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "surf_private.h"
+#include "surf/maxmin.h"
 #include "surf/ns3/ns3_interface.h"
 #include "xbt/lib.h"
 #include "surf/network_ns3_private.h"
@@ -417,20 +418,19 @@ static double ns3_share_resources(double min)
          surf_network_model->states.running_action_set;
 
        //get the first relevant value from the running_actions list
-       if (!xbt_swag_size(running_actions))
-       return -1.0;
+       if (!xbt_swag_size(running_actions) || min == 0.0)
+         return -1.0;
+       else
+        do {
+          ns3_simulator(min);
+          time_to_next_flow_completion = ns3_time() - surf_get_clock();
+        } while(double_equals(time_to_next_flow_completion,0));
+
+       XBT_DEBUG("min       : %f",min);
+       XBT_DEBUG("ns3  time : %f",ns3_time());
+       XBT_DEBUG("surf time : %f",surf_get_clock());
+       XBT_DEBUG("Next completion %f :",time_to_next_flow_completion);
 
-       ns3_simulator(min);
-       time_to_next_flow_completion = ns3_time() - surf_get_clock();
-
-//     XBT_INFO("min       : %f",min);
-//     XBT_INFO("ns3  time : %f",ns3_time());
-//     XBT_INFO("surf time : %f",surf_get_clock());
-
-       xbt_assert(time_to_next_flow_completion,
-                         "Time to next flow completion not initialized!\n");
-
-       XBT_DEBUG("ns3_share_resources return %f",time_to_next_flow_completion);
        return time_to_next_flow_completion;
 }
 
@@ -445,8 +445,12 @@ static void ns3_update_actions_state(double now, double delta)
              surf_network_model->states.running_action_set;
 
          /* If there are no running flows, just return */
-         if (!xbt_swag_size(running_actions))
-               return;
+         if (!xbt_swag_size(running_actions)) {
+           while(double_positive(now-ns3_time())) {
+             ns3_simulator(now-ns3_time());
+           }
+           return;
+         }
 
          xbt_dict_foreach(dict_socket,cursor,key,data){
            action = (surf_action_network_ns3_t)ns3_get_socket_action(data);