Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0f5c909857cb59c62c00d23970a5979a60d4a8b3
[simgrid.git] / examples / s4u / energy-wifi / s4u-energy-wifi.cpp
1 /**
2  * Test the wifi energy plugin
3  * Desactivate cross-factor to get round values
4  * Launch with: ./test test_platform_2STA.xml --cfg=plugin:link_energy_wifi --cfg=network/crosstraffic:0
5  */
6
7 #include "simgrid/plugins/energy.h"
8 #include "simgrid/s4u/Activity.hpp"
9 #include "simgrid/s4u/Actor.hpp"
10 #include "simgrid/s4u/Engine.hpp"
11 #include "simgrid/s4u/Host.hpp"
12 #include "simgrid/s4u/Link.hpp"
13 #include "simgrid/s4u/Mailbox.hpp"
14 #include "xbt/log.h"
15
16 //#include <exception>
17 //#include <iostream>
18 //#include <random>
19 //#include <sstream>
20 //#include <string>
21
22 XBT_LOG_NEW_DEFAULT_CATEGORY(test_wifi, "Wifi energy demo");
23
24 static void sender()
25 {
26   // start sending after 5 seconds
27   simgrid::s4u::this_actor::sleep_until(5);
28
29   std::string mbName = "MailBoxRCV";
30   simgrid::s4u::Mailbox *dst = simgrid::s4u::Mailbox::by_name(mbName);
31
32   int size = 6750000;
33
34   XBT_INFO("SENDING 1 msg of size %d to %s", size, mbName.c_str());
35   static char message[] = "message";
36   dst->put(message, size);
37   XBT_INFO("finished sending");
38 }
39
40 static void receiver()
41 {
42   std::string mbName = "MailBoxRCV";
43   XBT_INFO("RECEIVING on mb %s", mbName.c_str());
44   simgrid::s4u::Mailbox *myBox = simgrid::s4u::Mailbox::by_name(mbName);
45   myBox->get();
46
47   XBT_INFO("received all messages");
48 }
49
50 int main(int argc, char** argv)
51 {
52   // engine
53   simgrid::s4u::Engine engine(&argc, argv);
54   XBT_INFO("Activating the SimGrid link energy plugin");
55   sg_wifi_energy_plugin_init();
56   engine.load_platform(argv[1]);
57
58   // setup WiFi bandwidths
59   auto* l = simgrid::s4u::Link::by_name("AP1");
60   l->set_host_wifi_rate(simgrid::s4u::Host::by_name("Station 1"), 0);
61   l->set_host_wifi_rate(simgrid::s4u::Host::by_name("Station 2"), 0);
62
63   // create the two actors for the test
64   simgrid::s4u::Actor::create("act0", simgrid::s4u::Host::by_name("Station 1"), sender);
65   simgrid::s4u::Actor::create("act1", simgrid::s4u::Host::by_name("Station 2"), receiver);
66
67   engine.run();
68
69   return 0;
70 }