Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
plugin wifi
[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   * Launche with: ./test test_platform_2STA.xml --cfg=plugin:link_energy_wifi --cfg=network/crosstraffic:0 
5   */
6
7 #include "simgrid/s4u.hpp"
8 #include "xbt/log.h"
9 #include "simgrid/msg.h"
10 #include "simgrid/s4u/Activity.hpp"
11 #include "simgrid/plugins/energy.h"
12 #include "src/surf/network_wifi.hpp"
13
14 #include <exception>
15 #include <iostream>
16 #include <random>
17 #include <sstream>
18 #include <string>
19
20 XBT_LOG_NEW_DEFAULT_CATEGORY(experience, "Wifi exp");
21 static void sender();
22 static void receiver();
23
24 int main(int argc, char **argv)
25 {
26   // engine
27   simgrid::s4u::Engine engine(&argc, argv);
28   XBT_INFO("Activating the SimGrid link energy plugin");
29   sg_wifi_energy_plugin_init();
30   engine.load_platform(argv[1]);
31
32   // setup WiFi bandwidths
33   simgrid::kernel::resource::NetworkWifiLink *l = (simgrid::kernel::resource::NetworkWifiLink *)simgrid::s4u::Link::by_name(
34                                                       "AP1")
35                                                       ->get_impl();
36   l->set_host_rate(simgrid::s4u::Host::by_name("Station 1"), 0);
37   l->set_host_rate(simgrid::s4u::Host::by_name("Station 2"), 0);
38
39   // create the two actors for the test
40   simgrid::s4u::Actor::create("act0", simgrid::s4u::Host::by_name("Station 1"), sender);
41   simgrid::s4u::Actor::create("act1", simgrid::s4u::Host::by_name("Station 2"), receiver);
42
43   engine.run();
44
45   return 0;
46 }
47
48 static void sender()
49 {
50   // start sending after 5 seconds
51   simgrid::s4u::this_actor::sleep_until(5);
52
53   std::string mbName = "MailBoxRCV";
54   simgrid::s4u::Mailbox *dst = simgrid::s4u::Mailbox::by_name(mbName);
55
56   int size = 6750000;
57
58   XBT_INFO("SENDING 1 msg of size %d to %s", size, mbName.c_str());
59   static char message[] = "message";
60   dst->put(message, size);
61   XBT_INFO("finished sending");
62 }
63
64 static void receiver()
65 {
66   std::string mbName = "MailBoxRCV";
67   XBT_INFO("RECEIVING on mb %s", mbName.c_str());
68   simgrid::s4u::Mailbox *myBox = simgrid::s4u::Mailbox::by_name(mbName);
69   myBox->get();
70
71   XBT_INFO("received all messages");
72 }