Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / teshsuite / s4u / ns3-from-src-to-itself / ns3-from-src-to-itself.cpp
1 /* Copyright (c) 2019-2021. 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 int nb_messages_sent = 0;
19
20 simgrid::s4u::Mailbox* box = simgrid::s4u::Mailbox::by_name("test");
21
22 static void test_send()
23 {
24   for (int nb_message = 0; nb_message < nb_message_to_send; nb_message++) {
25     nb_messages_sent++;
26     XBT_VERB("start sending test #%i", nb_messages_sent);
27     box->put(new int(nb_messages_sent), payload);
28     XBT_VERB("done sending test #%i", nb_messages_sent);
29   }
30 }
31
32 static void test_receive()
33 {
34   for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
35     XBT_VERB("waiting for messages");
36     auto ptr = box->get_unique<int>();
37     int id   = *ptr;
38     XBT_VERB("received messages #%i", id);
39   }
40   XBT_INFO("Done receiving from %d senders, each of them sending %d messages", nb_sender, nb_message_to_send);
41 }
42
43 int main(int argc, char* argv[])
44 {
45   simgrid::s4u::Engine e(&argc, argv);
46
47   e.load_platform(argv[1]);
48
49   auto hosts = e.get_all_hosts();
50   simgrid::s4u::Actor::create("receiver", hosts[0], test_receive);
51   simgrid::s4u::Actor::create("send_same", hosts[0], test_send);
52   simgrid::s4u::Actor::create("send_other", hosts[1], test_send);
53
54   e.run();
55
56   return 0;
57 }