Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / teshsuite / s4u / ns3-from-src-to-itself / ns3-from-src-to-itself.cpp
1 /* Copyright (c) 2019-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 /* This test checks that ns-3 behave correctly when multiple flows finish   */
7 /* at the exact same time. Given the amount of simultaneous senders, it     */
8 /* also serves as a (small) crash test for ns-3.                            */
9
10 #include "simgrid/s4u.hpp"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u tests");
13
14 const int payload            = 1000;
15 const int nb_message_to_send = 5;
16 const int nb_sender = 2;
17
18 static void test_send()
19 {
20   simgrid::s4u::Mailbox* box  = simgrid::s4u::Mailbox::by_name("test");
21   static int nb_messages_sent = 0;
22   for (int nb_message = 0; nb_message < nb_message_to_send; nb_message++) {
23     nb_messages_sent++;
24     XBT_VERB("start sending test #%i", nb_messages_sent);
25     box->put(new int(nb_messages_sent), payload);
26     XBT_VERB("done sending test #%i", nb_messages_sent);
27   }
28 }
29
30 static void test_receive()
31 {
32   simgrid::s4u::Mailbox* box = simgrid::s4u::Mailbox::by_name("test");
33   for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
34     XBT_VERB("waiting for messages");
35     auto ptr = box->get_unique<int>();
36     int id   = *ptr;
37     XBT_VERB("received messages #%i", id);
38   }
39   XBT_INFO("Done receiving from %d senders, each of them sending %d messages", nb_sender, nb_message_to_send);
40 }
41
42 int main(int argc, char* argv[])
43 {
44   simgrid::s4u::Engine e(&argc, argv);
45
46   e.load_platform(argv[1]);
47
48   auto hosts = e.get_all_hosts();
49   simgrid::s4u::Actor::create("receiver", hosts[0], test_receive);
50   simgrid::s4u::Actor::create("send_same", hosts[0], test_send);
51   simgrid::s4u::Actor::create("send_other", hosts[1], test_send);
52
53   e.run();
54
55   return 0;
56 }