Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add an example of wifi communication
[simgrid.git] / examples / s4u / network-wifi / s4u-network-wifi.cpp
1 /* Copyright (c) 2017-2020. 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 #include "simgrid/s4u.hpp"
7
8 /* This example demonstrates how to use wifi links in SimGrid. Most of the interesting things happen in the
9  * corresponding XML file.
10  */
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_network_wifi, "Messages specific for this s4u example");
13
14 static void sender(simgrid::s4u::Mailbox* mailbox, int data_size)
15 {
16   XBT_INFO("Send a message to the other station.");
17   static char message[] = "message";
18   mailbox->put(message, data_size);
19   XBT_INFO("Done.");
20 }
21 static void receiver(simgrid::s4u::Mailbox* mailbox)
22 {
23   XBT_INFO("Wait for a message.");
24   mailbox->get();
25   XBT_INFO("Done.");
26 }
27
28 int main(int argc, char* argv[])
29 {
30   simgrid::s4u::Engine e(&argc, argv);
31
32   xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
33
34   e.load_platform(argv[1]);
35
36   auto mailbox  = simgrid::s4u::Mailbox::by_name("mailbox");
37   auto station1 = simgrid::s4u::Host::by_name("Station 1");
38   auto station2 = simgrid::s4u::Host::by_name("Station 2");
39   simgrid::s4u::Actor::create("sender", station1, sender, mailbox, 1e7);
40   simgrid::s4u::Actor::create("receiver", station2, receiver, mailbox);
41
42   auto ap = simgrid::s4u::Link::by_name("AP1");
43   ap->set_host_wifi_rate(station1, 1); // The host "Station 1" uses the second level of bandwidths on that AP
44   ap->set_host_wifi_rate(station2, 0); // This is perfectly useless as level 0 is used by default
45
46   e.run();
47
48   return 0;
49 }