Logo AND Algorithmique Numérique Distribuée

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