Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / teshsuite / surf / wifi_usage / wifi_usage.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_interface.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("We should thus have:");
27     XBT_INFO("  mu = 1 / [ 1/1 * 1.05/54Mbps ] = 51428571");
28     XBT_INFO("  simulation_time = 1000*8 / mu = 0.0001555556s (rounded to 0.000156s in SimGrid)");
29   } else {
30     XBT_INFO("1/r_STA1 * rho_STA1 <= 1  (there is no cross-traffic)");
31     XBT_INFO("We should thus have:");
32     XBT_INFO("  mu = 1 / [ 1/1 * 1/54Mbps ] = 5.4e+07");
33     XBT_INFO("  simulation_time = 1000*8 / mu = 0.0001481481s");
34   }
35   run_ping_test("Station 1", "node1", 1000);
36
37   XBT_INFO("TEST: Send from a station to another station on the same AP.");
38   XBT_INFO("------------------------------------------------------------");
39   XBT_INFO("We have the following constraint for AP1:");
40   if (crosstraffic) {
41     XBT_INFO("1.05/r_STA1 * rho_STA1 + 1.05/r_STA2 * rho_2 <= 1     (1.05 instead of 1 because of cross-traffic)");
42     XBT_INFO("We should thus have:");
43     XBT_INFO("  mu = 1 / [ 1/2 * 1.05/54Mbps + 1.05/54Mbps ] =  51428571");
44     XBT_INFO("  simulation_time = 1000*8 / [ mu / 2 ] = 0.0003111111s");
45   } else {
46     XBT_INFO("1/r_STA1 * rho_STA1 +    1/r_STA2 * rho_2 <= 1   (there is no cross-traffic)");
47     XBT_INFO("  mu = 1 / [ 1/2 * 1/54Mbps + 1/54Mbps ] = 5.4e+07");
48     XBT_INFO("  simulation_time = 1000*8 / [ mu / 2 ] = 0.0002962963s");
49   }
50   run_ping_test("Station 1", "Station 2", 1000);
51 }
52 int main(int argc, char** argv)
53 {
54   simgrid::s4u::Engine engine(&argc, argv);
55   engine.load_platform(argv[1]);
56   simgrid::s4u::Actor::create("dispatcher", simgrid::s4u::Host::by_name("node1"), main_dispatcher);
57   engine.run();
58
59   return 0;
60 }
61
62 void run_ping_test(const char* src, const char* dest, int data_size)
63 {
64   auto* mailbox = simgrid::s4u::Mailbox::by_name("Test");
65
66   simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name(src), [mailbox, dest, data_size]() {
67     double start_time = simgrid::s4u::Engine::get_clock();
68     static std::string message = "message";
69     mailbox->put(&message, data_size);
70     double end_time = simgrid::s4u::Engine::get_clock();
71     XBT_INFO("Actual result: Sending %d bytes from '%s' to '%s' takes %f seconds.", data_size,
72              simgrid::s4u::this_actor::get_host()->get_cname(), dest, end_time - start_time);
73   });
74   simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name(dest),
75                               [mailbox]() { mailbox->get<std::string>(); });
76   const auto* ap1 = simgrid::s4u::Link::by_name("AP1");
77   ap1->set_host_wifi_rate(simgrid::s4u::Host::by_name(src), 0);
78   ap1->set_host_wifi_rate(simgrid::s4u::Host::by_name(dest), 0);
79   simgrid::s4u::this_actor::sleep_for(10);
80   XBT_INFO("\n");
81 }