Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'pikachuyann/simgrid-stoprofiles'
[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
15 XBT_LOG_NEW_DEFAULT_CATEGORY(test_wifi, "Wifi energy demo");
16
17 static void sender()
18 {
19   // start sending after 5 seconds
20   simgrid::s4u::this_actor::sleep_until(5);
21
22   std::string mbName = "MailBoxRCV";
23   simgrid::s4u::Mailbox *dst = simgrid::s4u::Mailbox::by_name(mbName);
24
25   int size = 6750000;
26
27   XBT_INFO("SENDING 1 msg of size %d to %s", size, mbName.c_str());
28   static std::string message = "message";
29   dst->put(&message, size);
30   XBT_INFO("finished sending");
31 }
32
33 static void receiver()
34 {
35   std::string mbName = "MailBoxRCV";
36   XBT_INFO("RECEIVING on mb %s", mbName.c_str());
37   simgrid::s4u::Mailbox *myBox = simgrid::s4u::Mailbox::by_name(mbName);
38   myBox->get();
39
40   XBT_INFO("received all messages");
41 }
42
43 int main(int argc, char** argv)
44 {
45   simgrid::s4u::Engine engine(&argc, argv);
46   sg_wifi_energy_plugin_init();
47   engine.load_platform(argv[1]);
48
49   // setup WiFi bandwidths
50   const auto* l = simgrid::s4u::Link::by_name("AP1");
51   l->set_host_wifi_rate(simgrid::s4u::Host::by_name("Station 1"), 0);
52   l->set_host_wifi_rate(simgrid::s4u::Host::by_name("Station 2"), 0);
53
54   // create the two actors for the test
55   simgrid::s4u::Actor::create("act0", simgrid::s4u::Host::by_name("Station 1"), sender);
56   simgrid::s4u::Actor::create("act1", simgrid::s4u::Host::by_name("Station 2"), receiver);
57
58   engine.run();
59
60   return 0;
61 }