From: Martin Quinson Date: Mon, 23 Sep 2019 19:29:04 +0000 (+0200) Subject: Merge branch 'master' into 'master' X-Git-Tag: v3.24~68^2^2~5 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/7e3052a90110227b0628cfde015552c1dd154563?hp=374954c4425321a5455848b03803c62084cb2c26 Merge branch 'master' into 'master' Improving the performance of the NS-3 bindings by: See merge request simgrid/simgrid!18 --- diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 741622330a..d5a4eccfec 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "network_ns3.hpp" #include "ns3/ns3_simulator.hpp" @@ -196,6 +197,10 @@ double NetworkNS3Model::next_occuring_event(double now) XBT_DEBUG("ns3_next_occuring_event"); //get the first relevant value from the running_actions list + + // If there is no comms in NS-3, then we do not move it forward. + // We will synchronize NS-3 with SimGrid when starting a new communication. + // (see NetworkNS3Action::NetworkNS3Action() for more details on this point) if (get_started_action_set()->empty() || now == 0.0) return -1.0; @@ -220,15 +225,6 @@ void NetworkNS3Model::update_actions_state(double now, double delta) { static std::vector socket_to_destroy; - /* If there are no running flows, advance the ns-3 simulator and return */ - if (get_started_action_set()->empty()) { - - while(double_positive(now - ns3::Simulator::Now().GetSeconds(), sg_surf_precision)) - ns3_simulator(now-ns3::Simulator::Now().GetSeconds()); - - return; - } - std::string ns3_socket; for (const auto& elm : flow_from_sock) { ns3_socket = elm.first; @@ -315,6 +311,15 @@ void LinkNS3::set_latency_profile(profile::Profile*) NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* src, s4u::Host* dst) : NetworkAction(model, totalBytes, false), src_(src), dst_(dst) { + + // If there is no other started actions, we need to move NS-3 forward to be sync with SimGrid + if (model->get_started_action_set()->size()==1){ + while(double_positive(surf_get_clock() - ns3::Simulator::Now().GetSeconds(), sg_surf_precision)){ + XBT_DEBUG("Synchronizing NS-3 (time %f) with SimGrid (time %f)", ns3::Simulator::Now().GetSeconds(), surf_get_clock()); + ns3_simulator(surf_get_clock() - ns3::Simulator::Now().GetSeconds()); + } + } + XBT_DEBUG("Communicate from %s to %s", src->get_cname(), dst->get_cname()); static int port_number = 1025; // Port number is limited from 1025 to 65 000 @@ -377,10 +382,16 @@ void NetworkNS3Action::update_remains_lazy(double /*now*/) void ns3_simulator(double maxSeconds) { + ns3::EventId id; if (maxSeconds > 0.0) // If there is a maximum amount of time to run - ns3::Simulator::Stop(ns3::Seconds(maxSeconds)); + id = ns3::Simulator::Schedule(ns3::Seconds(maxSeconds), &ns3::Simulator::Stop); + XBT_DEBUG("Start simulator for at most %fs (current time: %f)", maxSeconds, surf_get_clock()); ns3::Simulator::Run (); + XBT_DEBUG("Simulator stopped at %fs", ns3::Simulator::Now().GetSeconds()); + + if(maxSeconds > 0.0) + id.Cancel(); } // initialize the ns-3 interface and environment diff --git a/src/surf/ns3/ns3_simulator.cpp b/src/surf/ns3/ns3_simulator.cpp index 63a0e8bb9e..72171b31f2 100644 --- a/src/surf/ns3/ns3_simulator.cpp +++ b/src/surf/ns3/ns3_simulator.cpp @@ -52,8 +52,7 @@ static void receive_callback(ns3::Ptr socket) flow->finished_ = true; XBT_DEBUG("recv_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_); XBT_DEBUG("Stop simulator at %f seconds", ns3::Simulator::Now().GetSeconds()); - ns3::Simulator::Stop(ns3::Seconds(0.0)); - ns3::Simulator::Run(); + ns3::Simulator::Stop(); } }