Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / examples / cpp / energy-wifi / s4u-energy-wifi.cpp
1 /* Copyright (c) 2020-2023. 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 namespace sg4 = simgrid::s4u;
22
23 static void sender()
24 {
25   // start sending after 5 seconds
26   sg4::this_actor::sleep_until(5);
27
28   std::string mbName = "MailBoxRCV";
29   sg4::Mailbox* dst  = sg4::Mailbox::by_name(mbName);
30
31   int size = 6750000;
32
33   XBT_INFO("SENDING 1 msg of size %d to %s", size, mbName.c_str());
34   static std::string message = "message";
35   dst->put(&message, size);
36   XBT_INFO("finished sending");
37 }
38
39 static void receiver()
40 {
41   std::string mbName = "MailBoxRCV";
42   XBT_INFO("RECEIVING on mb %s", mbName.c_str());
43   sg4::Mailbox* myBox = sg4::Mailbox::by_name(mbName);
44   myBox->get<std::string>();
45
46   XBT_INFO("received all messages");
47 }
48
49 int main(int argc, char** argv)
50 {
51   sg4::Engine engine(&argc, argv);
52   sg_wifi_energy_plugin_init();
53   engine.load_platform(argv[1]);
54
55   // setup WiFi bandwidths
56   const auto* l = engine.link_by_name("AP1");
57   l->set_host_wifi_rate(engine.host_by_name("Station 1"), 0);
58   l->set_host_wifi_rate(engine.host_by_name("Station 2"), 0);
59
60   // create the two actors for the test
61   sg4::Actor::create("act0", engine.host_by_name("Station 1"), sender);
62   sg4::Actor::create("act1", engine.host_by_name("Station 2"), receiver);
63
64   engine.run();
65
66   return 0;
67 }