Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A few spelling mistakes and many replacements: [Ss]imgrid -> SimGrid.
[simgrid.git] / teshsuite / models / wifi_usage_decay / wifi_usage_decay.cpp
1 /* Copyright (c) 2019-2023. 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 #include "simgrid/s4u.hpp"
7 #include "xbt/config.hpp"
8 #include "xbt/log.h"
9
10 #include "src/kernel/resource/WifiLinkImpl.hpp"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[usage] wifi_usage <platform-file>");
13
14 void run_ping_test(const std::vector<std::pair<std::string,std::string>>& mboxes, int data_size);
15
16 /* We need a separate actor so that it can sleep after each test */
17 static void main_dispatcher()
18 {
19   const std::vector<std::pair<std::string, std::string>> flows = {
20     {"Station 1", "Station 2"},
21     {"Station 3", "Station 4"},
22     {"Station 5", "Station 6"},
23     {"Station 7", "Station 8"},
24     {"Station 9", "Station 10"},
25     {"Station 11", "Station 12"},
26     {"Station 13", "Station 14"},
27     {"Station 15", "Station 16"},
28     {"Station 17", "Station 18"},
29     {"Station 19", "Station 20"},
30     {"Station 21", "Station 22"},
31   };
32
33   XBT_INFO("1/r_STA1 * rho_STA1 <= 1  (there is no cross-traffic)");
34   XBT_INFO("22 concurrent flows, decay model deactivated, we have 54Mbps to share between the flows");
35   XBT_INFO("We should thus have:");
36   XBT_INFO("  mu = 1 / [ 1/22 * (1/54Mbps)*22 ] = 54000000");
37   XBT_INFO("  simulation_time = 100000*8 / (mu/22) = 0.3259259259259259 (rounded to 0.325926s in SimGrid)");
38
39   run_ping_test(flows, 100000);
40
41   XBT_INFO("1/r_STA1 * rho_STA1 <= 1  (there is no cross-traffic)");
42   XBT_INFO("22 concurrent flows, decay model activated, we have 54Mbps to share between the flows, but the number of concurrent flows is above the limit (20)");
43   XBT_INFO("We should thus have:");
44   XBT_INFO("Maximum throughput of the link reduced by:");
45   XBT_INFO("updated link capacity = ( 5678270 + (22-20) * -5424 ) / 5678270 =~ 0.998086");
46   XBT_INFO("  mu = 1 / [ 1/22 * (1/54Mbps*0.998086)*22 ] = 53896644");
47   XBT_INFO("  simulation_time = 100000*8 / (mu/22) = 0.3265509444335718 (rounded to 0.326550 in SimGrid)");
48
49   auto* l = (simgrid::kernel::resource::WifiLinkImpl*)simgrid::s4u::Link::by_name("AP1")->get_impl();
50   l->toggle_callback();
51   run_ping_test(flows, 100000);
52 }
53
54 int main(int argc, char** argv)
55 {
56   simgrid::s4u::Engine engine(&argc, argv);
57   engine.load_platform(argv[1]);
58   simgrid::s4u::Actor::create("dispatcher", engine.host_by_name("node1"), main_dispatcher);
59   engine.run();
60
61   return 0;
62 }
63
64 void run_ping_test(const std::vector<std::pair<std::string,std::string>>& mboxes, int data_size)
65 {
66   auto* mailbox = simgrid::s4u::Mailbox::by_name("Test");
67   for (auto const& pair : mboxes) {
68     simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name(pair.first.c_str()), [mailbox, pair, data_size]() {
69       double start_time          = simgrid::s4u::Engine::get_clock();
70       static std::string message = "message";
71       mailbox->put(&message, data_size);
72       double end_time = simgrid::s4u::Engine::get_clock();
73       XBT_INFO("Actual result: Sending %d bytes from '%s' to '%s' takes %f seconds.", data_size,
74               simgrid::s4u::this_actor::get_host()->get_cname(), pair.second.c_str(), end_time - start_time);
75     });
76     simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name(pair.second.c_str()),
77                                 [mailbox]() { mailbox->get<std::string>(); });
78     auto* l = (simgrid::kernel::resource::WifiLinkImpl*)simgrid::s4u::Link::by_name("AP1")->get_impl();
79     for(auto i=1; i<=22; i++) {
80       l->set_host_rate(simgrid::s4u::Host::by_name("Station "+std::to_string(i)), 0);
81     }
82   }
83   simgrid::s4u::this_actor::sleep_for(10);
84   XBT_INFO("\n");
85 }