Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert and simplify network-ns3 example
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 8 Mar 2020 17:28:55 +0000 (18:28 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Sun, 8 Mar 2020 17:28:55 +0000 (18:28 +0100)
14 files changed:
MANIFEST.in
examples/deprecated/msg/CMakeLists.txt
examples/deprecated/msg/network-ns3/network-ns3.c [deleted file]
examples/deprecated/msg/network-ns3/network-ns3.tesh [deleted file]
examples/s4u/CMakeLists.txt
examples/s4u/network-ns3/3hosts_2links_d.xml [moved from examples/deprecated/msg/network-ns3/3hosts_2links_d.xml with 100% similarity]
examples/s4u/network-ns3/3links-timer_d.xml [moved from examples/deprecated/msg/network-ns3/3links-timer_d.xml with 100% similarity]
examples/s4u/network-ns3/3links_d.xml [moved from examples/deprecated/msg/network-ns3/3links_d.xml with 100% similarity]
examples/s4u/network-ns3/crosstraffic_d.xml [moved from examples/deprecated/msg/network-ns3/crosstraffic_d.xml with 100% similarity]
examples/s4u/network-ns3/dogbone_d.xml [moved from examples/deprecated/msg/network-ns3/dogbone_d.xml with 100% similarity]
examples/s4u/network-ns3/one_cluster_d.xml [moved from examples/deprecated/msg/network-ns3/one_cluster_d.xml with 100% similarity]
examples/s4u/network-ns3/onelink_d.xml [moved from examples/deprecated/msg/network-ns3/onelink_d.xml with 100% similarity]
examples/s4u/network-ns3/s4u-network-ns3.cpp [new file with mode: 0644]
examples/s4u/network-ns3/s4u-network-ns3.tesh [new file with mode: 0644]

index 76bc1f6..4ab1a27 100644 (file)
@@ -264,15 +264,6 @@ include examples/deprecated/msg/mc/electric_fence.c
 include examples/deprecated/msg/mc/platform.xml
 include examples/deprecated/msg/mc/promela_bugged1_liveness
 include examples/deprecated/msg/mc/promela_bugged2_liveness
-include examples/deprecated/msg/network-ns3/3hosts_2links_d.xml
-include examples/deprecated/msg/network-ns3/3links-timer_d.xml
-include examples/deprecated/msg/network-ns3/3links_d.xml
-include examples/deprecated/msg/network-ns3/crosstraffic_d.xml
-include examples/deprecated/msg/network-ns3/dogbone_d.xml
-include examples/deprecated/msg/network-ns3/network-ns3.c
-include examples/deprecated/msg/network-ns3/network-ns3.tesh
-include examples/deprecated/msg/network-ns3/one_cluster_d.xml
-include examples/deprecated/msg/network-ns3/onelink_d.xml
 include examples/deprecated/msg/synchro-semaphore/synchro-semaphore.c
 include examples/deprecated/msg/synchro-semaphore/synchro-semaphore.tesh
 include examples/deprecated/msg/trace-categories/trace-categories.c
@@ -472,6 +463,14 @@ include examples/s4u/maestro-set/s4u-maestro-set.cpp
 include examples/s4u/maestro-set/s4u-maestro-set.tesh
 include examples/s4u/mc-failing-assert/s4u-mc-failing-assert.cpp
 include examples/s4u/mc-failing-assert/s4u-mc-failing-assert.tesh
+include examples/s4u/network-ns3/3hosts_2links_d.xml
+include examples/s4u/network-ns3/3links-timer_d.xml
+include examples/s4u/network-ns3/3links_d.xml
+include examples/s4u/network-ns3/crosstraffic_d.xml
+include examples/s4u/network-ns3/dogbone_d.xml
+include examples/s4u/network-ns3/one_cluster_d.xml
+include examples/s4u/network-ns3/onelink_d.xml
+include examples/s4u/network-ns3/s4u-network-ns3.tesh
 include examples/s4u/platform-failures/s4u-platform-failures.cpp
 include examples/s4u/platform-failures/s4u-platform-failures.tesh
 include examples/s4u/platform-failures/s4u-platform-failures_d.xml
index cbbc1d5..51ff5fd 100644 (file)
@@ -14,13 +14,6 @@ foreach(x app-masterworker cloud-masterworker
   set(tesh_files   ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.tesh)
 endforeach()
 
-if(SIMGRID_HAVE_NS3 AND enable_msg)
-  add_executable       (network-ns3 EXCLUDE_FROM_ALL network-ns3/network-ns3.c)
-  target_link_libraries(network-ns3 simgrid)
-  set_target_properties(network-ns3  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/network-ns3)
-  add_dependencies(tests network-ns3)    
-endif()
-
 if(enable_msg)
   add_executable       (dht-kademlia EXCLUDE_FROM_ALL dht-kademlia/dht-kademlia.c dht-kademlia/node.c dht-kademlia/routing_table.c dht-kademlia/task.c dht-kademlia/answer.c)
   target_link_libraries(dht-kademlia simgrid)
@@ -38,21 +31,14 @@ endforeach()
 set(txt_files    ${txt_files}     ${CMAKE_CURRENT_SOURCE_DIR}/README.doc          PARENT_SCOPE)
 set(bin_files    ${bin_files}     ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/generate.py
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-pastry/generate.py                       PARENT_SCOPE)
-set(examples_src ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/common.h
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/network-ns3.c                    PARENT_SCOPE)
+set(examples_src ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/common.h                        PARENT_SCOPE)
 set(tesh_files   ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/dht-kademlia.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-multicore.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-vivaldi.tesh
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/network-ns3.tesh                 PARENT_SCOPE)
+                                  PARENT_SCOPE)
 set(xml_files    ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-multicore_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/app-masterworker-vivaldi_d.xml
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3hosts_2links_d.xml
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3links-timer_d.xml
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3links_d.xml
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/crosstraffic_d.xml
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/dogbone_d.xml
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/onelink_d.xml
-                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/one_cluster_d.xml        PARENT_SCOPE)
+                                  PARENT_SCOPE)
 
 if(enable_msg)
   foreach(x app-masterworker cloud-masterworker
@@ -97,11 +83,4 @@ if(enable_msg)
                                                  --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
                                                  ${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg/app-masterworker/app-masterworker-vivaldi.tesh)
 
-  if(SIMGRID_HAVE_NS3)
-    ADD_TESH_FACTORIES(msg-network-ns3 "thread;ucontext;raw;boost"
-                                        --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg
-                                        --setenv bindir=${CMAKE_BINARY_DIR}/examples/deprecated/msg
-                                        --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
-                                        ${CMAKE_HOME_DIRECTORY}/examples/deprecated/msg/network-ns3/network-ns3.tesh)
-  endif()
 endif(enable_msg)
\ No newline at end of file
diff --git a/examples/deprecated/msg/network-ns3/network-ns3.c b/examples/deprecated/msg/network-ns3/network-ns3.c
deleted file mode 100644 (file)
index a0f3163..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/* Copyright (c) 2007-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. */
-
-#include "simgrid/msg.h"
-
-#include <stdio.h> /* snprintf */
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-
-int timer_start; //set as 1 in the master process
-
-//keep a pointer to all surf running tasks.
-#define NTASKS 1500
-double start_time, end_time, elapsed_time;
-double gl_data_size[NTASKS];
-msg_task_t gl_task_array[NTASKS];
-const char *workernames[NTASKS];
-const char *masternames[NTASKS];
-int gl_task_array_id = 0;
-int count_finished = 0;
-
-#define FINALIZE ((void*)221297)        /* a magic number to tell people to stop working */
-
-static int master(int argc, char *argv[])
-{
-  msg_task_t todo;
-
-  xbt_assert(argc==4,"Strange number of arguments expected 3 got %d", argc - 1);
-
-  XBT_DEBUG ("Master started");
-
-  /* data size */
-  double task_comm_size = xbt_str_parse_double(argv[1], "Invalid task communication size: %s");
-
-  /* worker name */
-  char *workername = argv[2];
-  int id = xbt_str_parse_int(argv[3], "Invalid ID as argument 3: %s");   //unique id to control statistics
-  char *id_alias = xbt_malloc(20*sizeof(char));
-  snprintf(id_alias, 20, "flow_%d", id);
-  workernames[id] = workername;
-  TRACE_category(id_alias);
-
-  masternames[id] = MSG_host_get_name(MSG_host_self());
-
-  {                             /*  Task creation.  */
-    todo = MSG_task_create("Task_0", 100*task_comm_size, task_comm_size, NULL);
-    MSG_task_set_category(todo, id_alias);
-    //keep track of running tasks
-    gl_task_array[id] = todo;
-    gl_data_size[id] = task_comm_size;
-  }
-
-  MSG_host_by_name(workername);
-
-  count_finished++;
-  timer_start = 1 ;
-
-  /* time measurement */
-  snprintf(id_alias,20,"%d", id);
-  start_time = MSG_get_clock();
-  MSG_task_send(todo, id_alias);
-  end_time = MSG_get_clock();
-
-  XBT_DEBUG ("Finished");
-  xbt_free(id_alias);
-  return 0;
-}
-
-static int timer(int argc, char *argv[])
-{
-  double sleep_time;
-  double first_sleep;
-
-  xbt_assert(argc==3,"Strange number of arguments expected 2 got %d", argc - 1);
-
-  sscanf(argv[1], "%lf", &first_sleep);
-  sscanf(argv[2], "%lf", &sleep_time);
-
-  XBT_DEBUG ("Timer started");
-
-  if(first_sleep){
-      MSG_process_sleep(first_sleep);
-  }
-
-  do {
-    XBT_DEBUG ("Get sleep");
-    MSG_process_sleep(sleep_time);
-  } while(timer_start);
-
-  XBT_DEBUG ("Finished");
-  return 0;
-}
-
-static int worker(int argc, char *argv[])
-{
-  msg_task_t task = NULL;
-  char id_alias[10];
-
-  xbt_assert(argc==2,"Strange number of arguments expected 1 got %d", argc - 1);
-
-  XBT_DEBUG ("Worker started");
-
-  int id = xbt_str_parse_int(argv[1], "Invalid id: %s");
-  snprintf(id_alias,10, "%d", id);
-
-  msg_error_t a = MSG_task_receive(&(task), id_alias);
-
-  count_finished--;
-  if(count_finished == 0){
-      timer_start = 0;
-  }
-
-  xbt_assert(a == MSG_OK,"Hey?! What's up? Unexpected behavior");
-
-  elapsed_time = MSG_get_clock() - start_time;
-
-  XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s", id, MSG_task_get_bytes_amount(task), masternames[id],
-           workernames[id]);
-//  MSG_task_execute(task);
-  MSG_task_destroy(task);
-
-  XBT_DEBUG ("Finished");
-  return 0;
-}
-
-int main(int argc, char *argv[])
-{
-  MSG_init(&argc, argv);
-  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
-             "\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
-
-  MSG_create_environment(argv[1]);
-  TRACE_declare_mark("endmark");
-
-  MSG_function_register("master", master);
-  MSG_function_register("worker", worker);
-  MSG_function_register("timer", timer);
-
-  MSG_launch_application(argv[2]);
-
-  msg_error_t res = MSG_main();
-
-  return res != MSG_OK;
-}
diff --git a/examples/deprecated/msg/network-ns3/network-ns3.tesh b/examples/deprecated/msg/network-ns3/network-ns3.tesh
deleted file mode 100644 (file)
index 61400ac..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/usr/bin/env tesh
-
-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.
-
-p 3hosts 2links
-
-$ ${bindir:=.}/network-ns3/network-ns3 ${platfdir}/small_platform_one_link_routes.xml ${srcdir}/network-ns3/3hosts_2links_d.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'
-> [Jupiter:worker(2)] [msg_test/INFO] FLOW[1] : Receive 100 bytes from Tremblay to Jupiter
-
-p 6hosts 3links
-
-$ ${bindir:=.}/network-ns3/network-ns3 ${platfdir}/small_platform_one_link_routes.xml ${srcdir}/network-ns3/3links_d.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'
-> [Jupiter:worker(2)] [msg_test/INFO] FLOW[1] : Receive 10000 bytes from Tremblay to Jupiter
-> [Ginette:worker(4)] [msg_test/INFO] FLOW[2] : Receive 10000 bytes from Fafard to Ginette
-> [Lovelace:worker(6)] [msg_test/INFO] FLOW[3] : Receive 10000 bytes from Bourassa to Lovelace
-
-$ ${bindir:=.}/network-ns3/network-ns3 ${platfdir}/small_platform_one_link_routes.xml ${srcdir}/network-ns3/3links-timer_d.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'
-> [Jupiter:worker(2)] [msg_test/INFO] FLOW[1] : Receive 10000 bytes from Tremblay to Jupiter
-> [Ginette:worker(4)] [msg_test/INFO] FLOW[2] : Receive 10000 bytes from Fafard to Ginette
-> [Lovelace:worker(6)] [msg_test/INFO] FLOW[3] : Receive 10000 bytes from Bourassa to Lovelace
-> [Lovelace:worker(7)] [msg_test/INFO] FLOW[4] : Receive 10000 bytes from Bourassa to Lovelace
-
-p One cluster
-
-$ ${bindir:=.}/network-ns3/network-ns3 ${platfdir}/cluster_backbone.xml ${srcdir}/network-ns3/one_cluster_d.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'
-> [node-6.simgrid.org:worker(2)] [msg_test/INFO] FLOW[1] : Receive 100 bytes from node-2.simgrid.org to node-6.simgrid.org
-
-p Dogbone
-
-! timeout 10
-$ ${bindir:=.}/network-ns3/network-ns3 ${platfdir}/dogbone.xml ${srcdir}/network-ns3/dogbone_d.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] Ignoring a route between S1 and C1 of length 3: Only routes of length 1 are considered with ns-3.
-> WARNING: You can ignore this warning if your hosts can still communicate when only considering routes of length 1.
-> WARNING: Remove long routes to avoid this harmless message; subsequent long routes will be silently ignored.
-> [C1:worker(3)] [msg_test/INFO] FLOW[0] : Receive 10000 bytes from S1 to C1
-> [C2:worker(4)] [msg_test/INFO] FLOW[1] : Receive 10000 bytes from S2 to C2
-
-p 2hosts 1link
-
-$ ${bindir:=.}/network-ns3/network-ns3 ${platfdir}/onelink.xml ${srcdir}/network-ns3/onelink_d.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'
-> [C1:worker(2)] [msg_test/INFO] FLOW[1] : Receive 10000 bytes from S1 to C1
-
-p Crosstraffic TCP option DISABLED
-! output ignore 
-$ ${bindir:=.}/network-ns3/network-ns3 ${platfdir}/crosstraffic.xml ${srcdir}/network-ns3/crosstraffic_d.xml --cfg=network/model:ns-3 --cfg=network/crosstraffic:0 
-
-p Crosstraffic TCP option ENABLED
-! output ignore
-$ ${bindir:=.}/network-ns3/network-ns3 ${platfdir}/crosstraffic.xml ${srcdir}/network-ns3/crosstraffic_d.xml --cfg=network/model:ns-3 --cfg=network/crosstraffic:1
index 9083b97..cd10767 100644 (file)
@@ -10,7 +10,7 @@ set(_dht-chord_sources    dht-chord/s4u-dht-chord.cpp dht-chord/s4u-dht-chord.hp
 set(_dht-kademlia_sources dht-kademlia/s4u-dht-kademlia.cpp dht-kademlia/s4u-dht-kademlia.hpp
                           dht-kademlia/node.cpp dht-kademlia/node.hpp
                           dht-kademlia/routing_table.cpp dht-kademlia/routing_table.hpp
-                         dht-kademlia/answer.cpp dht-kademlia/answer.hpp dht-kademlia/message.hpp)
+                          dht-kademlia/answer.cpp dht-kademlia/answer.hpp dht-kademlia/message.hpp)
 
 set(_actor-stacksize_factories "raw;boost;ucontext") # Threads ignore modifications of the stack size
 
@@ -27,6 +27,13 @@ foreach (example mc-failing-assert)
   set(_${example}_factories "ucontext;raw;boost")
 endforeach()
 
+if(SIMGRID_HAVE_NS3)
+  add_executable       (s4u-network-ns3 EXCLUDE_FROM_ALL network-ns3/s4u-network-ns3.cpp)
+  target_link_libraries(s4u-network-ns3 simgrid)
+  set_target_properties(s4u-network-ns3  PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/network-ns3)
+  add_dependencies(tests s4u-network-ns3)    
+endif()
+
 # Deal with each example
 
 foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill
@@ -35,12 +42,12 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill
                  async-ready async-wait async-waitany async-waitall async-waituntil
                  comm-dependent
                  cloud-capping cloud-migration cloud-simple
-                dht-chord dht-kademlia
+                 dht-chord dht-kademlia
                  energy-exec energy-boot energy-link energy-vm energy-exec-ptask
                  engine-filtering
                  exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor exec-dependent
-                maestro-set
-                mc-failing-assert
+                 maestro-set
+                 mc-failing-assert
                  io-async io-file-system io-file-remote io-disk-raw io-dependent
                  platform-failures platform-profile platform-properties
                  plugin-hostload
@@ -121,6 +128,14 @@ foreach(example app-bittorrent app-masterworkers
                                             ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example}/s4u-${example}.tesh)
 endforeach()
 
+# ns3-tests
+if(SIMGRID_HAVE_NS3)
+  ADD_TESH_FACTORIES(s4u-network-ns3 "thread;ucontext;raw;boost"
+                                     --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/s4u
+                                     --setenv bindir=${CMAKE_BINARY_DIR}/examples/s4u
+                                     --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
+                                     ${CMAKE_HOME_DIRECTORY}/examples/s4u/network-ns3/s4u-network-ns3.tesh)
+endif()
 # Examples not accepting factories
 ##################################
 
@@ -148,7 +163,8 @@ endif()
 ####################################
 
 set(examples_src  ${examples_src}                                                                          PARENT_SCOPE)
-set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/app-pingpong/simix-breakpoint.tesh           PARENT_SCOPE)
+set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/app-pingpong/simix-breakpoint.tesh
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/s4u-network-ns3.tesh             PARENT_SCOPE)
 set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/s4u-actor-create_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-yield/s4u-actor-yield_d.xml
@@ -168,7 +184,13 @@ set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/s4u-a
                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm-split_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-io/s4u-replay-io_d.xml
-                  PARENT_SCOPE)
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3hosts_2links_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3links-timer_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/3links_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/crosstraffic_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/dogbone_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/onelink_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/network-ns3/one_cluster_d.xml                PARENT_SCOPE)
 set(bin_files     ${bin_files}    ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/generate.py                     PARENT_SCOPE)
 set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm-split-p0.txt
                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-replay-comm-split-p1.txt
diff --git a/examples/s4u/network-ns3/s4u-network-ns3.cpp b/examples/s4u/network-ns3/s4u-network-ns3.cpp
new file mode 100644 (file)
index 0000000..107c85e
--- /dev/null
@@ -0,0 +1,111 @@
+/* Copyright (c) 2007-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. */
+
+#include "simgrid/s4u.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+int timer_start; // set as 1 in the master process
+
+#define NTASKS 1500
+double start_time;
+const char* workernames[NTASKS];
+const char* masternames[NTASKS];
+int count_finished = 0;
+
+static void master(int argc, char* argv[])
+{
+  xbt_assert(argc == 4, "Strange number of arguments expected 3 got %d", argc - 1);
+
+  XBT_DEBUG("Master started");
+
+  /* data size */
+  double task_comm_size = std::stod(argv[1]);
+  int id                = std::stoi(argv[3]); // unique id to control statistics
+
+  /* worker name */
+  workernames[id] = xbt_strdup(argv[2]);
+
+  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(argv[3]);
+
+  masternames[id] = simgrid::s4u::Host::current()->get_cname();
+
+  double* payload = new double();
+  *payload        = task_comm_size;
+
+  count_finished++;
+  timer_start = 1;
+
+  /* time measurement */
+  start_time = simgrid::s4u::Engine::get_clock();
+  mbox->put(payload, task_comm_size);
+
+  XBT_DEBUG("Finished");
+}
+
+static void timer(int argc, char* argv[])
+{
+  xbt_assert(argc == 3, "Strange number of arguments expected 2 got %d", argc - 1);
+  double first_sleep = std::stod(argv[1]);
+  double sleep_time  = std::stod(argv[2]);
+
+  XBT_DEBUG("Timer started");
+
+  if (first_sleep)
+    simgrid::s4u::this_actor::sleep_for(first_sleep);
+
+  do {
+    XBT_DEBUG("Get sleep");
+    simgrid::s4u::this_actor::sleep_for(sleep_time);
+  } while (timer_start);
+
+  XBT_DEBUG("Finished");
+}
+
+static void worker(int argc, char* argv[])
+{
+  xbt_assert(argc == 2, "Strange number of arguments expected 1 got %d", argc - 1);
+
+  int id                      = std::stoi(argv[1]);
+  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(argv[1]);
+
+  XBT_DEBUG("Worker started");
+
+  const double* payload = static_cast<double*>(mbox->get());
+
+  count_finished--;
+  if (count_finished == 0) {
+    timer_start = 0;
+  }
+
+  double elapsed_time = simgrid::s4u::Engine::get_clock() - start_time;
+
+  XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s", id, *payload, masternames[id], workernames[id]);
+  XBT_DEBUG("FLOW[%d] : transferred in  %f seconds", id, elapsed_time);
+  delete payload;
+
+  XBT_DEBUG("Finished");
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  xbt_assert(argc > 2,
+             "Usage: %s platform_file deployment_file\n"
+             "\tExample: %s platform.xml deployment.xml\n",
+             argv[0], argv[0]);
+
+  e.load_platform(argv[1]);
+
+  e.register_function("master", master);
+  e.register_function("worker", worker);
+  e.register_function("timer", timer);
+
+  e.load_deployment(argv[2]);
+
+  e.run();
+
+  return 0;
+}
diff --git a/examples/s4u/network-ns3/s4u-network-ns3.tesh b/examples/s4u/network-ns3/s4u-network-ns3.tesh
new file mode 100644 (file)
index 0000000..2d38df4
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env tesh
+
+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.
+
+p 3hosts 2links
+
+$ ${bindir:=.}/network-ns3/s4u-network-ns3 ${platfdir}/small_platform_one_link_routes.xml ${srcdir}/network-ns3/3hosts_2links_d.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'
+> [Jupiter:worker(2)] [s4u_test/INFO] FLOW[1] : Receive 100 bytes from Tremblay to Jupiter
+
+p 6hosts 3links
+
+$ ${bindir:=.}/network-ns3/s4u-network-ns3 ${platfdir}/small_platform_one_link_routes.xml ${srcdir}/network-ns3/3links_d.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'
+> [Jupiter:worker(2)] [s4u_test/INFO] FLOW[1] : Receive 10000 bytes from Tremblay to Jupiter
+> [Ginette:worker(4)] [s4u_test/INFO] FLOW[2] : Receive 10000 bytes from Fafard to Ginette
+> [Lovelace:worker(6)] [s4u_test/INFO] FLOW[3] : Receive 10000 bytes from Bourassa to Lovelace
+
+$ ${bindir:=.}/network-ns3/s4u-network-ns3 ${platfdir}/small_platform_one_link_routes.xml ${srcdir}/network-ns3/3links-timer_d.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'
+> [Jupiter:worker(2)] [s4u_test/INFO] FLOW[1] : Receive 10000 bytes from Tremblay to Jupiter
+> [Ginette:worker(4)] [s4u_test/INFO] FLOW[2] : Receive 10000 bytes from Fafard to Ginette
+> [Lovelace:worker(6)] [s4u_test/INFO] FLOW[3] : Receive 10000 bytes from Bourassa to Lovelace
+> [Lovelace:worker(7)] [s4u_test/INFO] FLOW[4] : Receive 10000 bytes from Bourassa to Lovelace
+
+p One cluster
+
+$ ${bindir:=.}/network-ns3/s4u-network-ns3 ${platfdir}/cluster_backbone.xml ${srcdir}/network-ns3/one_cluster_d.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'
+> [node-6.simgrid.org:worker(2)] [s4u_test/INFO] FLOW[1] : Receive 100 bytes from node-2.simgrid.org to node-6.simgrid.org
+
+p Dogbone
+
+! timeout 10
+$ ${bindir:=.}/network-ns3/s4u-network-ns3 ${platfdir}/dogbone.xml ${srcdir}/network-ns3/dogbone_d.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] Ignoring a route between S1 and C1 of length 3: Only routes of length 1 are considered with ns-3.
+> WARNING: You can ignore this warning if your hosts can still communicate when only considering routes of length 1.
+> WARNING: Remove long routes to avoid this harmless message; subsequent long routes will be silently ignored.
+> [C1:worker(3)] [s4u_test/INFO] FLOW[0] : Receive 10000 bytes from S1 to C1
+> [C2:worker(4)] [s4u_test/INFO] FLOW[1] : Receive 10000 bytes from S2 to C2
+
+p 2hosts 1link
+
+$ ${bindir:=.}/network-ns3/s4u-network-ns3 ${platfdir}/onelink.xml ${srcdir}/network-ns3/onelink_d.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'
+> [C1:worker(2)] [s4u_test/INFO] FLOW[1] : Receive 10000 bytes from S1 to C1
+
+p Crosstraffic TCP option DISABLED
+! output ignore 
+$ ${bindir:=.}/network-ns3/s4u-network-ns3 ${platfdir}/crosstraffic.xml ${srcdir}/network-ns3/crosstraffic_d.xml --cfg=network/model:ns-3 --cfg=network/crosstraffic:0 
+
+p Crosstraffic TCP option ENABLED
+! output ignore
+$ ${bindir:=.}/network-ns3/s4u-network-ns3 ${platfdir}/crosstraffic.xml ${srcdir}/network-ns3/crosstraffic_d.xml --cfg=network/model:ns-3 --cfg=network/crosstraffic:1