1 /* Copyright (c) 2019. The SimGrid Team. All rights reserved. */
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. */
6 #include "simgrid/s4u.hpp"
9 #include "simgrid/msg.h"
10 #include "src/surf/network_cm02.hpp"
16 XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[usage] wifi_usage <platform-file>");
18 void run_ping_test(const char* src, const char* dest, int data_size);
20 /* We need a separate actor so that it can sleep after each test */
21 static void main_dispatcher()
23 bool crosstraffic = simgrid::kernel::resource::NetworkModel::cfg_crosstraffic;
25 XBT_INFO("TEST: Send from a station to a node on the wired network after the AP.");
26 XBT_INFO("----------------------------------------------------------------------");
27 XBT_INFO("Since AP1 is the limiting link, we have the following constraint for AP1:");
29 XBT_INFO("1.05/r_STA1 * rho_STA1 <= 1 (1.05 instead of 1 because of cross-traffic)");
30 XBT_INFO("We should thus have:");
31 XBT_INFO(" mu = 1 / [ 1/1 * 1.05/54Mbps ] = 51428571");
32 XBT_INFO(" simulation_time = 1000*8 / mu = 0.0001555556s (rounded to 0.000156s in SimGrid)");
34 XBT_INFO("1/r_STA1 * rho_STA1 <= 1 (there is no cross-traffic)");
35 XBT_INFO("We should thus have:");
36 XBT_INFO(" mu = 1 / [ 1/1 * 1/54Mbps ] = 5.4e+07");
37 XBT_INFO(" simulation_time = 1000*8 / mu = 0.0001481481s");
39 run_ping_test("Station 1", "NODE1", 1000);
41 XBT_INFO("TEST: Send from a station to another station on the same AP.");
42 XBT_INFO("------------------------------------------------------------");
43 XBT_INFO("We have the following constraint for AP1:");
45 XBT_INFO("1.05/r_STA1 * rho_STA1 + 1.05/r_STA2 * rho_2 <= 1 (1.05 instead of 1 because of cross-traffic)");
46 XBT_INFO("We should thus have:");
47 XBT_INFO(" mu = 1 / [ 1/2 * 1.05/54Mbps + 1.05/54Mbps ] = 51428571");
48 XBT_INFO(" simulation_time = 1000*8 / [ mu / 2 ] = 0.0003111111s");
50 XBT_INFO("1/r_STA1 * rho_STA1 + 1/r_STA2 * rho_2 <= 1 (there is no cross-traffic)");
51 XBT_INFO(" mu = 1 / [ 1/2 * 1/54Mbps + 1/54Mbps ] = 5.4e+07");
52 XBT_INFO(" simulation_time = 1000*8 / [ mu / 2 ] = 0.0002962963s");
54 run_ping_test("Station 1", "Station 2", 1000);
56 int main(int argc, char** argv)
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);
66 void run_ping_test(const char* src, const char* dest, int data_size)
68 auto* mailbox = simgrid::s4u::Mailbox::by_name("Test");
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 mailbox->put(const_cast<char*>("message"), data_size);
73 double end_time = simgrid::s4u::Engine::get_clock();
74 XBT_INFO("Actual result: Sending %d bytes from '%s' to '%s' takes %f seconds.", data_size,
75 simgrid::s4u::this_actor::get_host()->get_cname(), dest, end_time - start_time);
77 simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name(dest), [mailbox]() { mailbox->get(); });
78 auto* l = (simgrid::kernel::resource::NetworkWifiLink*)simgrid::s4u::Link::by_name("AP1")->get_impl();
79 l->set_host_rate(simgrid::s4u::Host::by_name(src), 0);
80 simgrid::s4u::this_actor::sleep_for(10);