1 /* Copyright (c) 2020-2023. The SimGrid Team. All rights reserved. */
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. */
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
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"
20 XBT_LOG_NEW_DEFAULT_CATEGORY(test_wifi, "Wifi energy demo");
21 namespace sg4 = simgrid::s4u;
25 // start sending after 5 seconds
26 sg4::this_actor::sleep_until(5);
28 std::string mbName = "MailBoxRCV";
29 sg4::Mailbox* dst = sg4::Mailbox::by_name(mbName);
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");
39 static void receiver()
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>();
46 XBT_INFO("received all messages");
49 int main(int argc, char** argv)
51 sg4::Engine engine(&argc, argv);
52 sg_wifi_energy_plugin_init();
53 engine.load_platform(argv[1]);
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);
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);