Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
4ac5f122c9904a1f50c451ad943a5da922c59e33
[simgrid.git] / examples / cpp / network-wifi / s4u-network-wifi.cpp
1 /* Copyright (c) 2017-2021. 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: examples/platforms/wifi.xml
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 std::string 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<std::string>();
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   /* Exchange a message between the 2 stations */
37   auto mailbox  = simgrid::s4u::Mailbox::by_name("mailbox");
38   auto station1 = simgrid::s4u::Host::by_name("Station 1");
39   auto station2 = simgrid::s4u::Host::by_name("Station 2");
40   simgrid::s4u::Actor::create("sender", station1, sender, mailbox, 1e7);
41   simgrid::s4u::Actor::create("receiver", station2, receiver, mailbox);
42
43   /* Declare that the stations are not at the same distance from their AP */
44   auto ap = simgrid::s4u::Link::by_name("AP1");
45   ap->set_host_wifi_rate(station1, 1); // The host "Station 1" uses the second level of bandwidths on that AP
46   ap->set_host_wifi_rate(station2, 0); // This is perfectly useless as level 0 is used by default
47
48   e.run();
49
50   return 0;
51 }