Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add an example of wifi communication
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 9 Jul 2020 00:44:01 +0000 (02:44 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 9 Jul 2020 00:44:56 +0000 (02:44 +0200)
MANIFEST.in
examples/README.rst
examples/platforms/wifi.xml
examples/s4u/CMakeLists.txt
examples/s4u/network-wifi/s4u-network-wifi.cpp [new file with mode: 0644]
examples/s4u/network-wifi/s4u-network-wifi.tesh [new file with mode: 0644]
src/surf/network_wifi.cpp
src/xbt/xbt_parse_units.cpp

index 3736b50..d1763be 100644 (file)
@@ -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
index f334c3b..7a4d9fd 100644 (file)
@@ -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
index fed5614..1cd232e 100755 (executable)
@@ -6,7 +6,7 @@
 
     <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" />
index 56906c4..21c1aa1 100644 (file)
@@ -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 (file)
index 0000000..57c896a
--- /dev/null
@@ -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 (file)
index 0000000..b4e49d1
--- /dev/null
@@ -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.
index 2c062cd..6d90be5 100644 (file)
@@ -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;
index a77b852..7321a37 100644 (file)
@@ -119,7 +119,7 @@ std::vector<double> xbt_parse_get_bandwidths(const std::string& filename, int li
 
   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,