From 66865b5143936d71be5df5f11a5c8570dc1fa08f Mon Sep 17 00:00:00 2001 From: agougeon Date: Wed, 24 Feb 2021 09:08:14 +0100 Subject: [PATCH] add wifi zone option to delay nodes start time --- src/surf/network_ns3.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/surf/network_ns3.cpp b/src/surf/network_ns3.cpp index 7087c97b13..8bad9179dc 100644 --- a/src/surf/network_ns3.cpp +++ b/src/surf/network_ns3.cpp @@ -76,6 +76,10 @@ NetPointNs3::NetPointNs3() : ns3_node_(ns3::CreateObject(0)) stack.Install(ns3_node_); } +void resumeWifiDevice(ns3::Ptr device) { + device->GetPhy()->ResumeFromOff(); +} + /************* * Callbacks * *************/ @@ -144,6 +148,18 @@ static void zoneCreation_cb(simgrid::s4u::NetZone const& zone) { netDevices.Add(wifi.Install(wifiPhy, wifiMac, station_ns3_node)); } + const char* start_time = wifizone->get_property("start_time"); + int start_time_value = start_time ? atoi(start_time) : 0; + auto resume = [](ns3::Ptr device){device->GetPhy()->ResumeFromOff();}; + for (int i = 0; i < netDevices.GetN(); i++) { + ns3::Ptr device = ns3::StaticCast(netDevices.Get(i)); + device->GetPhy()->SetOffMode(); + ns3::Simulator::Schedule( + ns3::Seconds(start_time_value), + &resumeWifiDevice, + device); + } + ns3::Config::Set("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/ChannelWidth", ns3::UintegerValue(40)); mobility.SetPositionAllocator(positionAllocS); -- 2.20.1