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
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
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)){
# 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})
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()
--- /dev/null
+/* 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;
+}
--- /dev/null
+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
+