Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6525f735a1e07356750c018fc16bd33a4d612a5d
[simgrid.git] / teshsuite / models / wifi_usage_decay / wifi_usage_decay.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 #include "simgrid/s4u.hpp"
7 #include "xbt/config.hpp"
8 #include "xbt/log.h"
9
10 #include "src/surf/network_wifi.hpp"
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[usage] wifi_usage <platform-file>");
13
14 void run_ping_test(const char* src, const char* dest, 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   bool crosstraffic = simgrid::kernel::resource::NetworkModel::cfg_crosstraffic;
20
21   XBT_INFO("TEST: Send from a station to a node on the wired network after the AP.");
22   XBT_INFO("----------------------------------------------------------------------");
23   XBT_INFO("Since AP1 is the limiting link, we have the following constraint for AP1:");
24   if (crosstraffic) {
25     XBT_INFO("1.05/r_STA1 * rho_STA1 <= 1   (1.05 instead of 1 because of cross-traffic)");
26     XBT_INFO("However, decay model specify that for 2 stations, we have 54Mbps become 49.00487");
27     XBT_INFO("We should thus have:");
28     XBT_INFO("  mu = 1 / [ 1/1 * 1.05/49.00487Mbps ] = 46671305");
29     XBT_INFO("  simulation_time = 1000*8 / mu = 0.0001714115 (rounded to 0.000171s in SimGrid)");
30   } else {
31     XBT_INFO("1/r_STA1 * rho_STA1 <= 1  (there is no cross-traffic)");
32     XBT_INFO("However, decay model specify that for 2 stations, we have 54Mbps become 49.00487");
33     XBT_INFO("We should thus have:");
34     XBT_INFO("  mu = 1 / [ 1/1 * 1/49.00487Mbps ] = 49004870");
35     XBT_INFO("  simulation_time = 1000*8 / mu = 0.0001632491s (rounded to 0.000163s in SimGrid)");
36   }
37   run_ping_test("Station 1", "node1", 1000);
38
39   XBT_INFO("TEST: Send from a station to another station on the same AP.");
40   XBT_INFO("------------------------------------------------------------");
41   XBT_INFO("We have the following constraint for AP1:");
42   if (crosstraffic) {
43     XBT_INFO("1.05/r_STA1 * rho_STA1 + 1.05/r_STA2 * rho_2 <= 1     (1.05 instead of 1 because of cross-traffic)");
44     XBT_INFO("However, decay model specify that for 2 stations, we have 54Mbps become 49.00487");
45     XBT_INFO("We should thus have:");
46     XBT_INFO("  mu = 1 / [ 1/2 * 1.05/49.00487Mbps + 1.05/49.00487Mbps ] = 46671305");
47     XBT_INFO("  simulation_time = 1000*8 / [ mu / 2 ] = 0.0003428231s (rounded to 0.000343s in SimGrid)");
48   } else {
49     XBT_INFO("1/r_STA1 * rho_STA1 +    1/r_STA2 * rho_2 <= 1   (there is no cross-traffic)");
50     XBT_INFO("However, decay model specify that for 2 stations, we have 54Mbps become 49.00487");
51     XBT_INFO("  mu = 1 / [ 1/2 * 1/49.00487Mbps + 1/49.00487Mbps ] = 49004870");
52     XBT_INFO("  simulation_time = 1000*8 / [ mu / 2 ] =  0.0003264982s (rounded to 0.000326s in SimGrid)");
53   }
54   run_ping_test("Station 1", "Station 2", 1000);
55 }
56 int main(int argc, char** argv)
57 {
58   simgrid::s4u::Engine engine(&argc, argv);
59   engine.load_platform(argv[1]);
60   simgrid::s4u::Actor::create("dispatcher", simgrid::s4u::Host::by_name("node1"), main_dispatcher);
61   engine.run();
62
63   return 0;
64 }
65
66 void run_ping_test(const char* src, const char* dest, int data_size)
67 {
68   auto* mailbox = simgrid::s4u::Mailbox::by_name("Test");
69
70   simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name(src), [mailbox, dest, data_size]() {
71     double start_time          = simgrid::s4u::Engine::get_clock();
72     static std::string message = "message";
73     mailbox->put(&message, data_size);
74     double end_time = simgrid::s4u::Engine::get_clock();
75     XBT_INFO("Actual result: Sending %d bytes from '%s' to '%s' takes %f seconds.", data_size,
76              simgrid::s4u::this_actor::get_host()->get_cname(), dest, end_time - start_time);
77   });
78   simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name(dest),
79                               [mailbox]() { mailbox->get<std::string>(); });
80   auto* l = (simgrid::kernel::resource::NetworkWifiLink*)simgrid::s4u::Link::by_name("AP1")->get_impl();
81   if (not l->toggle_decay_model())
82     l->toggle_decay_model();
83   l->set_host_rate(simgrid::s4u::Host::by_name("Station 1"), 0);
84   l->set_host_rate(simgrid::s4u::Host::by_name("Station 2"), 0);
85   simgrid::s4u::this_actor::sleep_for(10);
86   XBT_INFO("\n");
87 }