Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
ns3: ensure that sending from an host to itself does not segfault
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 18 Oct 2020 00:04:00 +0000 (02:04 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 18 Oct 2020 00:08:49 +0000 (02:08 +0200)
Also add a word in the doc about how we deal with this border case,
and a little test case.

MANIFEST.in
docs/source/ns3.rst
src/surf/network_ns3.cpp
teshsuite/s4u/CMakeLists.txt
teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.cpp [new file with mode: 0644]
teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.tesh [new file with mode: 0644]

index 0c8e23d..674e662 100644 (file)
@@ -717,6 +717,8 @@ include teshsuite/s4u/is-router/is-router.cpp
 include teshsuite/s4u/is-router/is-router.tesh
 include teshsuite/s4u/listen_async/listen_async.cpp
 include teshsuite/s4u/listen_async/listen_async.tesh
+include teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.cpp
+include teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.tesh
 include teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp
 include teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.tesh
 include teshsuite/s4u/pid/pid.cpp
index a2cb51c..b125056 100644 (file)
@@ -12,7 +12,9 @@ The SimGrid/ns-3 binding only contains features that are common to both systems.
 Not all ns-3 models are available from SimGrid (only the TCP and WiFi ones are),
 while not all SimGrid platform files can be used in conjunction ns-3 (routes
 must be of length 1). Also, the platform built in ns-3 from the SimGrid
-description is very basic.
+description is very basic. Finally, communicating from an host to
+itself is forbidden in ns-3, so every such communication completes
+immediately upon startup.
 
 
 Compiling the ns-3/SimGrid binding
index bb14828..f82de06 100644 (file)
@@ -460,6 +460,21 @@ void LinkNS3::set_latency_profile(profile::Profile*)
 NetworkNS3Action::NetworkNS3Action(Model* model, double totalBytes, s4u::Host* src, s4u::Host* dst)
     : NetworkAction(model, *src, *dst, totalBytes, false)
 {
+
+  // ns-3 fails when src = dst, so avoid the problem by considering that communications are infinitely fast on the
+  // loopback that does not exists
+  if (src == dst) {
+    static bool warned = false;
+    if (not warned) {
+      XBT_WARN("Sending from an host %s to itself is not supported by ns-3. Every such communication finishes "
+               "immediately upon startup.",
+               src->get_cname());
+      warned = true;
+    }
+    finish(Action::State::FINISHED);
+    return;
+  }
+
   // 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)){
index a19f6d3..b9d58a9 100644 (file)
@@ -41,7 +41,7 @@ ADD_TEST(tesh-s4u-comm-pt2pt    ${CMAKE_BINARY_DIR}/teshsuite/s4u/comm-pt2pt/com
 
 # NS-3 specific tests
 if(SIMGRID_HAVE_NS3)
-  foreach(x ns3-simultaneous-send-rcv)
+  foreach(x ns3-simultaneous-send-rcv ns3-from-src-to-itself)
     add_executable       (${x}  EXCLUDE_FROM_ALL ${x}/${x}.cpp)
     target_link_libraries(${x}  simgrid)
     set_target_properties(${x}  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x})
@@ -50,7 +50,7 @@ if(SIMGRID_HAVE_NS3)
   endforeach()
 endif()
 
-foreach(x ns3-simultaneous-send-rcv)
+foreach(x ns3-simultaneous-send-rcv ns3-from-src-to-itself)
   set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp)
   set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh)
 endforeach()
diff --git a/teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.cpp b/teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.cpp
new file mode 100644 (file)
index 0000000..dbe6027
--- /dev/null
@@ -0,0 +1,62 @@
+/* Copyright (c) 2019-2020. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+/* This test checks that ns-3 behave correctly when multiple flows finish   */
+/* at the exact same time. Given the amount of simultaneous senders, it     */
+/* also serves as a (small) crash test for ns-3.                            */
+
+#include "simgrid/s4u.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u tests");
+
+const int payload            = 1000;
+const int nb_message_to_send = 5;
+// const double sleep_time      = 5;
+const int nb_sender = 2;
+
+int nb_messages_sent = 0;
+
+simgrid::s4u::Mailbox* box;
+
+static void test_send()
+{
+  for (int nb_message = 0; nb_message < nb_message_to_send; nb_message++) {
+    nb_messages_sent++;
+    XBT_VERB("start sending test #%i", nb_messages_sent);
+    box->put(new int(nb_messages_sent), payload);
+    XBT_VERB("done sending test #%i", nb_messages_sent);
+    //    simgrid::s4u::this_actor::sleep_until(sleep_time * (nb_message + 1));
+  }
+}
+
+static void test_receive()
+{
+  for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
+    XBT_VERB("waiting for messages");
+    int* ptr = (int*)(box->get());
+    int id   = *ptr;
+    XBT_VERB("received messages #%i", id);
+    delete ptr;
+  }
+  XBT_INFO("Done receiving from %d senders, each of them sending %d messages", nb_sender, nb_message_to_send);
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+
+  e.load_platform(argv[1]);
+
+  auto host       = e.get_all_hosts()[0];
+  auto receiver   = simgrid::s4u::Actor::create("receiver", host, test_receive);
+  auto send_same  = simgrid::s4u::Actor::create("send_same", host, test_send);
+  auto send_other = simgrid::s4u::Actor::create("send_other", e.get_all_hosts()[1], test_send);
+
+  box = simgrid::s4u::Mailbox::by_name("test");
+
+  e.run();
+
+  return 0;
+}
diff --git a/teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.tesh b/teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.tesh
new file mode 100644 (file)
index 0000000..2e032a2
--- /dev/null
@@ -0,0 +1,8 @@
+p In the ns-3 tests, the timings are not shown because the exact values may vary with your ns-3 version.
+p We just want to check that the ns-3 bindings of SimGrid are working correctly, we don't want to thoroughly test ns-3.
+
+$ ./ns3-from-src-to-itself ${platfdir}/ns3-big-cluster.xml --cfg=network/model:ns-3 "--log=root.fmt:[%h:%P(%i)]%e[%c/%p]%e%m%n"
+> [:maestro(0)] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'ns-3'
+> [:maestro(0)] [ns3/WARNING] Sending from an host c-01.rennes to itself is not supported by ns-3. Every such communication finishes immediately upon startup.
+> [c-01.rennes:receiver(1)] [s4u_test/INFO] Done receiving from 2 senders, each of them sending 5 messages
+