Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the wifi energy plugin to the SimGrid build system and let it compile
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 9 Jul 2020 22:36:28 +0000 (00:36 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 9 Jul 2020 22:41:48 +0000 (00:41 +0200)
examples/s4u/CMakeLists.txt
examples/s4u/energy-wifi/s4u-energy-wifi.cpp
src/plugins/link_energy_wifi.cpp
tools/cmake/DefinePackages.cmake

index 21c1aa1..8b51493 100644 (file)
@@ -66,7 +66,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill
                  comm-dependent
                  cloud-capping cloud-migration cloud-simple
                  dht-chord dht-kademlia
-                 energy-exec energy-boot energy-link energy-vm energy-exec-ptask
+                 energy-exec energy-boot energy-link energy-vm energy-exec-ptask energy-wifi
                  engine-filtering
                  exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor exec-dependent
                  maestro-set
index e3db9cd..0f5c909 100644 (file)
@@ -1,49 +1,25 @@
 /**
-  * Test the wifi energy plugin 
 * Desactivate cross-factor to get round values
-  * Launche with: ./test test_platform_2STA.xml --cfg=plugin:link_energy_wifi --cfg=network/crosstraffic:0 
 */
+ * Test the wifi energy plugin
+ * Desactivate cross-factor to get round values
+ * Launch with: ./test test_platform_2STA.xml --cfg=plugin:link_energy_wifi --cfg=network/crosstraffic:0
+ */
 
-#include "simgrid/s4u.hpp"
-#include "xbt/log.h"
-#include "simgrid/msg.h"
-#include "simgrid/s4u/Activity.hpp"
 #include "simgrid/plugins/energy.h"
-#include "src/surf/network_wifi.hpp"
-
-#include <exception>
-#include <iostream>
-#include <random>
-#include <sstream>
-#include <string>
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(experience, "Wifi exp");
-static void sender();
-static void receiver();
-
-int main(int argc, char **argv)
-{
-  // engine
-  simgrid::s4u::Engine engine(&argc, argv);
-  XBT_INFO("Activating the SimGrid link energy plugin");
-  sg_wifi_energy_plugin_init();
-  engine.load_platform(argv[1]);
-
-  // setup WiFi bandwidths
-  simgrid::kernel::resource::NetworkWifiLink *l = (simgrid::kernel::resource::NetworkWifiLink *)simgrid::s4u::Link::by_name(
-                                                      "AP1")
-                                                      ->get_impl();
-  l->set_host_rate(simgrid::s4u::Host::by_name("Station 1"), 0);
-  l->set_host_rate(simgrid::s4u::Host::by_name("Station 2"), 0);
-
-  // create the two actors for the test
-  simgrid::s4u::Actor::create("act0", simgrid::s4u::Host::by_name("Station 1"), sender);
-  simgrid::s4u::Actor::create("act1", simgrid::s4u::Host::by_name("Station 2"), receiver);
+#include "simgrid/s4u/Activity.hpp"
+#include "simgrid/s4u/Actor.hpp"
+#include "simgrid/s4u/Engine.hpp"
+#include "simgrid/s4u/Host.hpp"
+#include "simgrid/s4u/Link.hpp"
+#include "simgrid/s4u/Mailbox.hpp"
+#include "xbt/log.h"
 
-  engine.run();
+//#include <exception>
+//#include <iostream>
+//#include <random>
+//#include <sstream>
+//#include <string>
 
-  return 0;
-}
+XBT_LOG_NEW_DEFAULT_CATEGORY(test_wifi, "Wifi energy demo");
 
 static void sender()
 {
@@ -70,3 +46,25 @@ static void receiver()
 
   XBT_INFO("received all messages");
 }
+
+int main(int argc, char** argv)
+{
+  // engine
+  simgrid::s4u::Engine engine(&argc, argv);
+  XBT_INFO("Activating the SimGrid link energy plugin");
+  sg_wifi_energy_plugin_init();
+  engine.load_platform(argv[1]);
+
+  // setup WiFi bandwidths
+  auto* l = simgrid::s4u::Link::by_name("AP1");
+  l->set_host_wifi_rate(simgrid::s4u::Host::by_name("Station 1"), 0);
+  l->set_host_wifi_rate(simgrid::s4u::Host::by_name("Station 2"), 0);
+
+  // create the two actors for the test
+  simgrid::s4u::Actor::create("act0", simgrid::s4u::Host::by_name("Station 1"), sender);
+  simgrid::s4u::Actor::create("act1", simgrid::s4u::Host::by_name("Station 2"), receiver);
+
+  engine.run();
+
+  return 0;
+}
index f31afec..33f677c 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <boost/algorithm/string/classification.hpp>
 #include <boost/algorithm/string/split.hpp>
+#include <map>
 
 SIMGRID_REGISTER_PLUGIN(link_energy_wifi, "Energy wifi test", &sg_wifi_energy_plugin_init);
 /** @degroup plugin_link_energy_wifi Plugin WiFi energy
@@ -29,8 +30,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(link_energy_wifi, surf, "Logging specific to the
 namespace simgrid {
 namespace plugin {
 
-//class __attribute__ ((visibility("hidden")))LinkEnergyWifi {
-class LinkEnergyWifi {
+class XBT_PRIVATE LinkEnergyWifi {
 
 public:
   static simgrid::xbt::Extension<simgrid::s4u::Link, LinkEnergyWifi> EXTENSION_ID;
@@ -74,7 +74,7 @@ public:
   
 private:
   // associative array keeping size of data already sent for a given flow (required for interleaved actions)
-  std::map<simgrid::kernel::resource::NetworkWifiAction *, std::pair<int, double>> flowTmp{};
+  std::map<simgrid::kernel::resource::NetworkWifiAction*, std::pair<int, double>> flowTmp{};
 
   // WiFi link the plugin instance is attached to
   s4u::Link* link_{};
@@ -114,10 +114,10 @@ void LinkEnergyWifi::updateDestroy() {
   durIdle += duration;
 
   // add IDLE energy usage, as well as beacons consumption since previous update
-  eDyn_ += duration*controlDuration_*wifi_link->get_nb_hosts_on_link()*pRx_;
-  eStat_ += (duration-(duration*controlDuration_)) * pIdle_ * (wifi_link->get_nb_hosts_on_link()+1);
+  eDyn_ += duration * controlDuration_ * wifi_link->get_host_count() * pRx_;
+  eStat_ += (duration - (duration * controlDuration_)) * pIdle_ * (wifi_link->get_host_count() + 1);
 
-  XBT_DEBUG("finish eStat_ += %f * %f * (%d+1) | eStat = %f", duration, pIdle_, wifi_link->get_nb_hosts_on_link(), eStat_);
+  XBT_DEBUG("finish eStat_ += %f * %f * (%d+1) | eStat = %f", duration, pIdle_, wifi_link->get_host_count(), eStat_);
 }
 
 void LinkEnergyWifi::update(const simgrid::kernel::resource::NetworkAction& action) {
@@ -188,7 +188,7 @@ void LinkEnergyWifi::update(const simgrid::kernel::resource::NetworkAction& acti
   XBT_DEBUG("durUsage: %f", durUsage);
 
   // beacons cost
-  eDyn_+=duration*controlDuration_*wifi_link->get_nb_hosts_on_link()*pRx_;
+  eDyn_ += duration * controlDuration_ * wifi_link->get_host_count() * pRx_;
 
   /**
    * Same principle as ns3:
@@ -197,16 +197,17 @@ void LinkEnergyWifi::update(const simgrid::kernel::resource::NetworkAction& acti
    * P_{tot} = P_{dyn}+P_{stat}
    */
   if(link_->get_usage()){
-    eDyn_ += /*duration * */durUsage * ((wifi_link->get_nb_hosts_on_link()*pRx_)+pTx_);
-    eStat_ += (duration-durUsage)* pIdle_ * (wifi_link->get_nb_hosts_on_link()+1);
-    XBT_DEBUG("eDyn +=  %f * ((%d * %f) + %f) | eDyn = %f (durusage =%f)", durUsage, wifi_link->get_nb_hosts_on_link(), pRx_, pTx_, eDyn_, durUsage);
+    eDyn_ += /*duration * */ durUsage * ((wifi_link->get_host_count() * pRx_) + pTx_);
+    eStat_ += (duration - durUsage) * pIdle_ * (wifi_link->get_host_count() + 1);
+    XBT_DEBUG("eDyn +=  %f * ((%d * %f) + %f) | eDyn = %f (durusage =%f)", durUsage, wifi_link->get_host_count(), pRx_,
+              pTx_, eDyn_, durUsage);
     durTxRx+=duration;
   }else{
     durIdle+=duration;
-    eStat_ += (duration-(duration*controlDuration_)) * pIdle_ * (wifi_link->get_nb_hosts_on_link()+1);
+    eStat_ += (duration - (duration * controlDuration_)) * pIdle_ * (wifi_link->get_host_count() + 1);
   }
 
-  XBT_DEBUG("eStat_ += %f * %f * (%d+1) | eStat = %f", duration, pIdle_, wifi_link->get_nb_hosts_on_link(), eStat_);
+  XBT_DEBUG("eStat_ += %f * %f * (%d+1) | eStat = %f", duration, pIdle_, wifi_link->get_host_count(), eStat_);
 }
   
 
index 687ce0d..b806212 100644 (file)
@@ -373,6 +373,7 @@ set(PLUGINS_SRC
   src/plugins/host_dvfs.cpp
   src/plugins/host_energy.cpp
   src/plugins/link_energy.cpp
+  src/plugins/link_energy_wifi.cpp
   src/plugins/host_load.cpp
   src/plugins/file_system/s4u_FileSystem.cpp
   src/plugins/vm/VirtualMachineImpl.hpp