Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
5d810fe92f8cbbff375313d9e3dac92fee656db7
[simgrid.git] / teshsuite / surf / wifi_usage / 1STA-1LINK-1NODE-NOCT.cpp
1 /* Copyright (c) 2017-2018. 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/log.h"
8
9 #include "simgrid/msg.h"
10 #include "src/surf/network_cm02.hpp"
11 #include <exception>
12 #include <iostream>
13 #include <random>
14 #include <string>
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(simulator, "[wifi_usage] 1STA-1LINK-1NODE");
17
18 void setup_simulation();
19 static void flowActor(std::vector<std::string> args);
20
21 /**
22  * Theory says:
23  *   - AP1 is the most constraint constraint
24  *   - When two STA communicates on the same AP we have the following AP constraint:
25  *     1/r_STA1 * rho_STA1 <= 1
26  *   - Thus:
27  *      mu = 1 / [ 1/1 * 1/54Mbps ] = 5.4e+07
28  *      simulation_time = 1000*8 / mu = 0.0001481481s
29  *
30  */
31 int main(int argc, char** argv)
32 {
33
34   // Build engine
35   simgrid::s4u::Engine engine(&argc, argv);
36   engine.load_platform(argv[1]);
37   setup_simulation();
38   engine.run();
39   XBT_INFO("Simulation took %fs", simgrid::s4u::Engine::get_clock());
40
41   return (0);
42 }
43
44 void setup_simulation()
45 {
46
47   std::vector<std::string> args, noArgs;
48   args.push_back("NODE1");
49   args.push_back("1000");
50   simgrid::s4u::Actor::create("STA1", simgrid::s4u::Host::by_name("STA1"), flowActor, args);
51   simgrid::s4u::Actor::create("NODE1", simgrid::s4u::Host::by_name("NODE1"), flowActor, noArgs);
52   simgrid::kernel::resource::NetworkWifiLink* l =
53       (simgrid::kernel::resource::NetworkWifiLink*)simgrid::s4u::Link::by_name("AP1")->get_impl();
54   l->set_host_rate(simgrid::s4u::Host::by_name("STA1"), 0);
55 }
56
57 static void flowActor(std::vector<std::string> args)
58 {
59   std::string selfName               = simgrid::s4u::this_actor::get_host()->get_name();
60   simgrid::s4u::Mailbox* selfMailbox = simgrid::s4u::Mailbox::by_name(simgrid::s4u::this_actor::get_host()->get_name());
61
62   if (args.size() > 0) { // We should send
63     simgrid::s4u::Mailbox* dstMailbox = simgrid::s4u::Mailbox::by_name(args.at(0));
64
65     int dataSize        = std::atoi(args.at(1).c_str());
66     double comStartTime = simgrid::s4u::Engine::get_clock();
67     dstMailbox->put(const_cast<char*>("message"), dataSize);
68     double comEndTime = simgrid::s4u::Engine::get_clock();
69     XBT_INFO("%s sent %d bytes to %s in %f seconds from %f to %f", selfName.c_str(), dataSize, args.at(0).c_str(),
70              comEndTime - comStartTime, comStartTime, comEndTime);
71   } else { // We should receive
72     selfMailbox->get();
73   }
74 }