1 /* Copyright (c) 2020-2022. 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");
24 // start sending after 5 seconds
25 simgrid::s4u::this_actor::sleep_until(5);
27 std::string mbName = "MailBoxRCV";
28 simgrid::s4u::Mailbox *dst = simgrid::s4u::Mailbox::by_name(mbName);
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");
38 static void receiver()
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>();
45 XBT_INFO("received all messages");
48 int main(int argc, char** argv)
50 simgrid::s4u::Engine engine(&argc, argv);
51 sg_wifi_energy_plugin_init();
52 engine.load_platform(argv[1]);
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);
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);