1 /* Copyright (c) 2017-2021. 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. */
6 #include "simgrid/s4u.hpp"
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
12 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_network_wifi, "Messages specific for this s4u example");
14 static void sender(simgrid::s4u::Mailbox* mailbox, int data_size)
16 XBT_INFO("Send a message to the other station.");
17 static std::string message = "message";
18 mailbox->put(&message, data_size);
21 static void receiver(simgrid::s4u::Mailbox* mailbox)
23 XBT_INFO("Wait for a message.");
24 mailbox->get<std::string>();
28 int main(int argc, char* argv[])
30 simgrid::s4u::Engine e(&argc, argv);
32 xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
34 e.load_platform(argv[1]);
36 /* Exchange a message between the 2 stations */
37 auto mailbox = simgrid::s4u::Mailbox::by_name("mailbox");
38 auto station1 = e.host_by_name("Station 1");
39 auto station2 = e.host_by_name("Station 2");
40 simgrid::s4u::Actor::create("sender", station1, sender, mailbox, 1e7);
41 simgrid::s4u::Actor::create("receiver", station2, receiver, mailbox);
43 /* Declare that the stations are not at the same distance from their AP */
44 auto ap = e.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