Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / examples / cpp / network-wifi / s4u-network-wifi.cpp
1 /* Copyright (c) 2017-2023. 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 namespace sg4 = simgrid::s4u;
14
15 static void sender(sg4::Mailbox* mailbox, int data_size)
16 {
17   XBT_INFO("Send a message to the other station.");
18   static std::string message = "message";
19   mailbox->put(&message, data_size);
20   XBT_INFO("Done.");
21 }
22 static void receiver(sg4::Mailbox* mailbox)
23 {
24   XBT_INFO("Wait for a message.");
25   mailbox->get<std::string>();
26   XBT_INFO("Done.");
27 }
28
29 int main(int argc, char* argv[])
30 {
31   sg4::Engine e(&argc, argv);
32
33   xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
34
35   e.load_platform(argv[1]);
36
37   /* Exchange a message between the 2 stations */
38   auto* mailbox  = sg4::Mailbox::by_name("mailbox");
39   auto* station1 = e.host_by_name("Station 1");
40   auto* station2 = e.host_by_name("Station 2");
41   sg4::Actor::create("sender", station1, sender, mailbox, 1e7);
42   sg4::Actor::create("receiver", station2, receiver, mailbox);
43
44   /* Declare that the stations are not at the same distance from their AP */
45   const auto* ap = e.link_by_name("AP1");
46   ap->set_host_wifi_rate(station1, 1); // The host "Station 1" uses the second level of bandwidths on that AP
47   ap->set_host_wifi_rate(station2, 0); // This is perfectly useless as level 0 is used by default
48
49   e.run();
50
51   return 0;
52 }