Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
added code and tesh files for ns3 wifi example
authoradrien gougeon <adrien.gougeon@inria.fr>
Thu, 22 Oct 2020 09:12:06 +0000 (11:12 +0200)
committeradrien gougeon <adrien.gougeon@inria.fr>
Thu, 22 Oct 2020 09:12:06 +0000 (11:12 +0200)
examples/s4u/network-ns3-wifi/s4u-network-ns3-wifi.cpp [new file with mode: 0644]
examples/s4u/network-ns3-wifi/s4u-network-ns3-wifi.tesh [new file with mode: 0644]

diff --git a/examples/s4u/network-ns3-wifi/s4u-network-ns3-wifi.cpp b/examples/s4u/network-ns3-wifi/s4u-network-ns3-wifi.cpp
new file mode 100644 (file)
index 0000000..6d3eb3c
--- /dev/null
@@ -0,0 +1,95 @@
+/* Copyright (c) 2007-2020. The SimGrid Team. LEVEL_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"
+#include <iostream>
+#include <iomanip>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(ns3_wifi_example, "Messages specific for this s4u example");
+
+double start_time;
+
+class Message
+{
+    public:
+    std::string sender;
+    int size;
+
+    Message(std::string sender_, int size_) : sender(sender_), size(size_){}
+};
+
+static void sender(std::string mailbox, double msg_size, unsigned sleep_time)
+{
+  simgrid::s4u::this_actor::sleep_for(sleep_time);
+  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mailbox);
+  Message* msg = new Message(simgrid::s4u::this_actor::get_host()->get_name(), msg_size);
+  start_time = simgrid::s4u::Engine::get_clock();
+  mbox->put(msg, msg_size);
+}
+
+static void receiver(std::string mailbox)
+{
+  simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mailbox);
+  Message* msg = (Message*) mbox->get();
+  double elapsed_time = simgrid::s4u::Engine::get_clock() - start_time;
+  XBT_INFO("[%s] %s received %d bytes from %s      Communication time: %f seconds      Throughput: %f Mbps",
+          mailbox.c_str(), simgrid::s4u::this_actor::get_host()->get_name().c_str(), msg->size,
+          msg->sender.c_str(), elapsed_time, msg->size * 8 / elapsed_time / 1E6);
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+
+  e.load_platform(argv[1]);
+  double msg_size = 1E5;
+
+  /* Communication between STA in the same wifi zone */
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA0-0"), sender, "1", msg_size, 10);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA0-1"), receiver, "1");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA0-1"), sender, "2", msg_size, 20);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA0-0"), receiver, "2");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-0"), sender, "3", msg_size, 30);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-1"), receiver, "3");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-1"), sender, "4", msg_size, 40);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-0"), receiver, "4");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-0"), sender, "5", msg_size, 50);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-2"), receiver, "5");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-0"), sender, "6", msg_size, 60);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-2"), receiver, "6");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-1"), sender, "7", msg_size, 70);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-2"), receiver, "7");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-2"), sender, "8", msg_size, 80);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-1"), receiver, "8");
+
+  /* Communication between STA of different wifi zones */
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA0-0"), sender, "9", msg_size, 90);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-0"), receiver, "9");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-0"), sender, "10", msg_size, 100);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA0-0"), receiver, "10");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA0-0"), sender, "11", msg_size, 110);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-1"), receiver, "11");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-1"), sender, "12", msg_size, 120);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA0-0"), receiver, "12");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA0-0"), sender, "13", msg_size, 130);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-2"), receiver, "13");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-2"), sender, "14", msg_size, 140);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA0-0"), receiver, "14");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA0-1"), sender, "15", msg_size, 150);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-0"), receiver, "15");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-0"), sender, "16", msg_size, 160);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA0-1"), receiver, "16");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA0-1"), sender, "17", msg_size, 170);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-1"), receiver, "17");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-1"), sender, "18", msg_size, 180);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA0-1"), receiver, "18");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA0-1"), sender, "19", msg_size, 190);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA1-2"), receiver, "19");
+  simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("STA1-2"), sender, "20", msg_size, 200);
+  simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("STA0-1"), receiver, "20");
+
+  e.run();
+  return 0;
+}
diff --git a/examples/s4u/network-ns3-wifi/s4u-network-ns3-wifi.tesh b/examples/s4u/network-ns3-wifi/s4u-network-ns3-wifi.tesh
new file mode 100644 (file)
index 0000000..bb0368c
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/network-ns3-wifi/s4u-network-ns3-wifi ${platfdir}/wifi_ns3.xml
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'network/model' to 'ns-3'
+> [STA0-1:receiver:(2) 10.067479] [ns3_wifi_example/INFO] [1] STA0-1 received 100000 bytes from STA0-0      Communication time: 0.067479 seconds      Throughput: 11.855563 Mbps
+> [STA0-0:receiver:(4) 20.052418] [ns3_wifi_example/INFO] [2] STA0-0 received 100000 bytes from STA0-1      Communication time: 0.052418 seconds      Throughput: 15.261961 Mbps
+> [STA1-1:receiver:(6) 30.053340] [ns3_wifi_example/INFO] [3] STA1-1 received 100000 bytes from STA1-0      Communication time: 0.053340 seconds      Throughput: 14.998159 Mbps
+> [STA1-0:receiver:(8) 40.040141] [ns3_wifi_example/INFO] [4] STA1-0 received 100000 bytes from STA1-1      Communication time: 0.040141 seconds      Throughput: 19.929638 Mbps
+> [STA1-2:receiver:(10) 50.048253] [ns3_wifi_example/INFO] [5] STA1-2 received 100000 bytes from STA1-0      Communication time: 0.048253 seconds      Throughput: 16.579389 Mbps
+> [STA1-2:receiver:(12) 60.040532] [ns3_wifi_example/INFO] [6] STA1-2 received 100000 bytes from STA1-0      Communication time: 0.040532 seconds      Throughput: 19.737352 Mbps
+> [STA1-2:receiver:(14) 70.049620] [ns3_wifi_example/INFO] [7] STA1-2 received 100000 bytes from STA1-1      Communication time: 0.049620 seconds      Throughput: 16.122677 Mbps
+> [STA1-1:receiver:(16) 80.041005] [ns3_wifi_example/INFO] [8] STA1-1 received 100000 bytes from STA1-2      Communication time: 0.041005 seconds      Throughput: 19.509617 Mbps
+> [STA1-0:receiver:(18) 90.069681] [ns3_wifi_example/INFO] [9] STA1-0 received 100000 bytes from STA0-0      Communication time: 0.069681 seconds      Throughput: 11.480933 Mbps
+> [STA0-0:receiver:(20) 100.059332] [ns3_wifi_example/INFO] [10] STA0-0 received 100000 bytes from STA1-0      Communication time: 0.059332 seconds      Throughput: 13.483461 Mbps
+> [STA1-1:receiver:(22) 110.061719] [ns3_wifi_example/INFO] [11] STA1-1 received 100000 bytes from STA0-0      Communication time: 0.061719 seconds      Throughput: 12.962074 Mbps
+> [STA0-0:receiver:(24) 120.055915] [ns3_wifi_example/INFO] [12] STA0-0 received 100000 bytes from STA1-1      Communication time: 0.055915 seconds      Throughput: 14.307543 Mbps
+> [STA1-2:receiver:(26) 130.072193] [ns3_wifi_example/INFO] [13] STA1-2 received 100000 bytes from STA0-0      Communication time: 0.072193 seconds      Throughput: 11.081443 Mbps
+> [STA0-0:receiver:(28) 140.062123] [ns3_wifi_example/INFO] [14] STA0-0 received 100000 bytes from STA1-2      Communication time: 0.062123 seconds      Throughput: 12.877717 Mbps
+> [STA1-0:receiver:(30) 150.059718] [ns3_wifi_example/INFO] [15] STA1-0 received 100000 bytes from STA0-1      Communication time: 0.059718 seconds      Throughput: 13.396185 Mbps
+> [STA0-1:receiver:(32) 160.057425] [ns3_wifi_example/INFO] [16] STA0-1 received 100000 bytes from STA1-0      Communication time: 0.057425 seconds      Throughput: 13.931195 Mbps
+> [STA1-1:receiver:(34) 170.056372] [ns3_wifi_example/INFO] [17] STA1-1 received 100000 bytes from STA0-1      Communication time: 0.056372 seconds      Throughput: 14.191439 Mbps
+> [STA0-1:receiver:(36) 180.056698] [ns3_wifi_example/INFO] [18] STA0-1 received 100000 bytes from STA1-1      Communication time: 0.056698 seconds      Throughput: 14.109858 Mbps
+> [STA1-2:receiver:(38) 190.060964] [ns3_wifi_example/INFO] [19] STA1-2 received 100000 bytes from STA0-1      Communication time: 0.060964 seconds      Throughput: 13.122510 Mbps
+> [STA0-1:receiver:(40) 200.058518] [ns3_wifi_example/INFO] [20] STA0-1 received 100000 bytes from STA1-2      Communication time: 0.058518 seconds      Throughput: 13.671020 Mbps