From 8e07254f3777d8ecca2276e9ce60e3ae4473f47e Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Thu, 9 Jul 2020 02:44:01 +0200 Subject: [PATCH] Add an example of wifi communication --- MANIFEST.in | 2 + examples/README.rst | 29 +++++++++++ examples/platforms/wifi.xml | 2 +- examples/s4u/CMakeLists.txt | 1 + .../s4u/network-wifi/s4u-network-wifi.cpp | 49 +++++++++++++++++++ .../s4u/network-wifi/s4u-network-wifi.tesh | 7 +++ src/surf/network_wifi.cpp | 8 ++- src/xbt/xbt_parse_units.cpp | 2 +- 8 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 examples/s4u/network-wifi/s4u-network-wifi.cpp create mode 100644 examples/s4u/network-wifi/s4u-network-wifi.tesh diff --git a/MANIFEST.in b/MANIFEST.in index 3736b503b9..d1763be095 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -480,6 +480,8 @@ include examples/s4u/network-ns3/one_cluster_d.xml 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 diff --git a/examples/README.rst b/examples/README.rst index f334c3bd68..7a4d9fdca7 100644 --- a/examples/README.rst +++ b/examples/README.rst @@ -900,6 +900,35 @@ Model-Related Examples .. 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 diff --git a/examples/platforms/wifi.xml b/examples/platforms/wifi.xml index fed5614afa..1cd232e80a 100755 --- a/examples/platforms/wifi.xml +++ b/examples/platforms/wifi.xml @@ -6,7 +6,7 @@ - + diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 56906c400d..21c1aa1c56 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -71,6 +71,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill 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 diff --git a/examples/s4u/network-wifi/s4u-network-wifi.cpp b/examples/s4u/network-wifi/s4u-network-wifi.cpp new file mode 100644 index 0000000000..57c896a501 --- /dev/null +++ b/examples/s4u/network-wifi/s4u-network-wifi.cpp @@ -0,0 +1,49 @@ +/* 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; +} diff --git a/examples/s4u/network-wifi/s4u-network-wifi.tesh b/examples/s4u/network-wifi/s4u-network-wifi.tesh new file mode 100644 index 0000000000..b4e49d11f5 --- /dev/null +++ b/examples/s4u/network-wifi/s4u-network-wifi.tesh @@ -0,0 +1,7 @@ +#!/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. diff --git a/src/surf/network_wifi.cpp b/src/surf/network_wifi.cpp index 2c062cd830..6d90be5044 100644 --- a/src/surf/network_wifi.cpp +++ b/src/surf/network_wifi.cpp @@ -46,8 +46,12 @@ double NetworkWifiLink::get_host_rate(const s4u::Host* host) 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; diff --git a/src/xbt/xbt_parse_units.cpp b/src/xbt/xbt_parse_units.cpp index a77b852c44..7321a37464 100644 --- a/src/xbt/xbt_parse_units.cpp +++ b/src/xbt/xbt_parse_units.cpp @@ -119,7 +119,7 @@ std::vector xbt_parse_get_bandwidths(const std::string& filename, int li std::vector bandwidths; std::vector 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, -- 2.20.1