include examples/s4u/network-ns3/onelink_d.xml
include examples/s4u/network-ns3/s4u-network-ns3.cpp
include examples/s4u/network-ns3/s4u-network-ns3.tesh
+include examples/s4u/network-wifi/s4u-network-wifi.cpp
+include examples/s4u/network-wifi/s4u-network-wifi.tesh
include examples/s4u/platform-failures/s4u-platform-failures.cpp
include examples/s4u/platform-failures/s4u-platform-failures.tesh
include examples/s4u/platform-failures/s4u-platform-failures_d.xml
.. showfile:: examples/platforms/small_platform_one_link_routes.xml
:language: xml
+
+ - **wifi links**
+
+ This demonstrates how to declare a wifi link in your platform and
+ how to use it in your simulation. The basics is to have a link
+ which sharing policy is set to `WIFI`. Such links can have more
+ than one bandwidth value (separated by commas), corresponding to
+ the several SNR level of your wifi link.
+
+ In this case, SimGrid automatically switches to validated
+ performance models of wifi networks, where the time is shared
+ between users instead of the bandwidth for wired links (the
+ corresponding publication is currently being written).
+
+ If your wifi link provides more than one SNR level, you can switch
+ the level of a given host using
+ :cpp:func:`simgrid::s4u::Link::set_host_wifi_rate`. By default,
+ the first level is used.
+
+ .. tabs::
+
+ .. example-tab:: examples/s4u/network-wifi/s4u-network-wifi.cpp
+
+ .. group-tab:: XML
+
+ **Platform files:**
+
+ .. showfile:: examples/platforms/wifi.xml
+ :language: xml
=======================
Model-Checking Examples
<zone id="WIFI zone" routing="Cluster">
<!-- First declare the Access Point (ie, the wifi media) -->
- <link id="AP1" sharing_policy="WIFI" bandwidth="54Mbps" latency="0ms" />
+ <link id="AP1" sharing_policy="WIFI" bandwidth="54Mbps,36Mbps,24Mbps" latency="0ms" />
<!-- Two stations in the wifi zone -->
<host id="Station 1" speed="100.0Mf,50.0Mf,20.0Mf" />
exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor exec-dependent
maestro-set
mc-bugged1 mc-bugged1-liveness mc-bugged2 mc-electric-fence mc-failing-assert
+ network-wifi
io-async io-file-system io-file-remote io-disk-raw io-dependent
platform-failures platform-profile platform-properties
plugin-hostload
--- /dev/null
+/* Copyright (c) 2017-2020. The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "simgrid/s4u.hpp"
+
+/* This example demonstrates how to use wifi links in SimGrid. Most of the interesting things happen in the
+ * corresponding XML file.
+ */
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_network_wifi, "Messages specific for this s4u example");
+
+static void sender(simgrid::s4u::Mailbox* mailbox, int data_size)
+{
+ XBT_INFO("Send a message to the other station.");
+ static char message[] = "message";
+ mailbox->put(message, data_size);
+ XBT_INFO("Done.");
+}
+static void receiver(simgrid::s4u::Mailbox* mailbox)
+{
+ XBT_INFO("Wait for a message.");
+ mailbox->get();
+ XBT_INFO("Done.");
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine e(&argc, argv);
+
+ xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml deployment.xml\n", argv[0], argv[0]);
+
+ e.load_platform(argv[1]);
+
+ auto mailbox = simgrid::s4u::Mailbox::by_name("mailbox");
+ auto station1 = simgrid::s4u::Host::by_name("Station 1");
+ auto station2 = simgrid::s4u::Host::by_name("Station 2");
+ simgrid::s4u::Actor::create("sender", station1, sender, mailbox, 1e7);
+ simgrid::s4u::Actor::create("receiver", station2, receiver, mailbox);
+
+ auto ap = simgrid::s4u::Link::by_name("AP1");
+ ap->set_host_wifi_rate(station1, 1); // The host "Station 1" uses the second level of bandwidths on that AP
+ ap->set_host_wifi_rate(station2, 0); // This is perfectly useless as level 0 is used by default
+
+ e.run();
+
+ return 0;
+}
--- /dev/null
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-network-wifi ${platfdir}/wifi.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (1:sender@Station 1) Send a message to the other station.
+> [ 0.000000] (2:receiver@Station 2) Wait for a message.
+> [ 3.888889] (1:sender@Station 1) Done.
+> [ 3.888889] (2:receiver@Station 2) Done.
return -1;
int rate_id = host_rates_it->second;
- xbt_assert(rate_id >= 0 && rate_id < (int)bandwidths_.size(), "Host '%s' has an invalid rate '%d' on wifi link '%s'",
- host->get_name().c_str(), rate_id, this->get_cname());
+ xbt_assert(rate_id >= 0,
+ "Negative host wifi rate levels are invalid but host '%s' uses %d as a rate level on link '%s'",
+ host->get_cname(), rate_id, this->get_cname());
+ xbt_assert(rate_id < (int)bandwidths_.size(),
+ "Link '%s' only has %zu wifi rate levels, so the provided level %d is invalid for host '%s'.",
+ this->get_cname(), bandwidths_.size(), rate_id, host->get_cname());
Metric rate = use_decay_model_ ? decay_bandwidths_[rate_id] : bandwidths_[rate_id];
return rate.peak * rate.scale;
std::vector<double> bandwidths;
std::vector<std::string> tokens;
- boost::split(tokens, string, boost::is_any_of(";"));
+ boost::split(tokens, string, boost::is_any_of(";,"));
for (auto token : tokens) {
bandwidths.push_back(surf_parse_get_value_with_unit(
filename, lineno, token.c_str(), units, entity_kind, name,