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 /* Send from a station to a node on the wired network after the AP
25 * - AP1 is the limiting constraint
26 * - When two STA communicates on the same AP we have the following AP constraint:
27 * w/o cross-traffic: 1/r_STA1 * rho_STA1 <= 1
28 * with cross-traffic: 1.05/r_STA1 * rho_STA1 <= 1
29 * - Thus without cross-traffic:
30 * mu = 1 / [ 1/1 * 1/54Mbps ] = 5.4e+07
31 * simulation_time = 1000*8 / mu = 0.0001481481s
32 * - Thus with cross-traffic:
33 * mu = 1 / [ 1/1 * 1.05/54Mbps ] = 51428571
34 * simulation_time = 1000*8 / mu = 0.0001555556s (rounded to 0.000156s in SimGrid)
36 run_ping_test("Station 1", "NODE1", 1000);
38 /* Send from a station to another station of the same AP
40 * - When two STA communicates on the same AP we have the following AP constraint:
41 * w/o cross-traffic: 1/r_STA1 * rho_STA1 + 1/r_STA2 * rho_2 <= 1
42 * with cross-traffic: 1.05/r_STA1 * rho_STA1 + 1.05/r_STA2 * rho_2 <= 1
43 * - Thus without cross-traffic:
44 * mu = 1 / [ 1/2 * 1/54Mbps + 1/54Mbps ] = 5.4e+07
45 * simulation_time = 1000*8 / [ mu / 2 ] = 0.0002962963s
46 * - Thus with cross-traffic:
47 * mu = 1 / [ 1/2 * 1.05/54Mbps + 1.05/54Mbps ] = 51428571
48 * simulation_time = 1000*8 / [ mu / 2 ] = 0.0003111111s
50 run_ping_test("Station 1", "Station 2", 1000);
52 int main(int argc, char** argv)
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);
62 void run_ping_test(const char* src, const char* dest, int data_size)
64 static int test_count = 0;
65 simgrid::s4u::this_actor::sleep_until(10 * test_count);
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("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);