mirror of
https://gitlab.com/manzerbredes/paper-lowrate-iot.git
synced 2025-06-05 22:27:39 +00:00
Update org+add ns-3 wifi source code
This commit is contained in:
parent
62b56e52ac
commit
457e27d81d
4 changed files with 166 additions and 1 deletions
|
@ -1,5 +1,4 @@
|
||||||
#+TITLE: A Large-Scale Wired Network Energy Model for Flow-Level Simulations
|
#+TITLE: A Large-Scale Wired Network Energy Model for Flow-Level Simulations
|
||||||
#+AUTHOR: Loic Guegan, Anne-Cécile Orgerie, Martin Quinson
|
|
||||||
|
|
||||||
#+EXPORT_EXCLUDE_TAGS: noexport
|
#+EXPORT_EXCLUDE_TAGS: noexport
|
||||||
#+STARTUP: hideblocks
|
#+STARTUP: hideblocks
|
||||||
|
|
17
ns-3_wifi_tests/Makefile
Normal file
17
ns-3_wifi_tests/Makefile
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
NS3_ARGS= -D NS3_LOG_ENABLE -L ${NS3_PATH}/build/lib -I ${NS3_PATH}/build/
|
||||||
|
NS3_ARGS+=$(addprefix -l, $(subst lib,,$(subst .so,,$(notdir $(wildcard ${NS3_PATH}/build/lib/*.so)))))
|
||||||
|
|
||||||
|
all: wifi-test
|
||||||
|
|
||||||
|
wifi-test: wifi-test.cc
|
||||||
|
g++ $(NS3_ARGS) $^ -o $@
|
||||||
|
|
||||||
|
run:
|
||||||
|
@LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${NS3_PATH}/build/lib ./wifi-test
|
||||||
|
|
||||||
|
export:
|
||||||
|
@echo export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${NS3_PATH}/build/lib
|
||||||
|
|
||||||
|
clean:
|
||||||
|
- rm wifi-test
|
BIN
ns-3_wifi_tests/wifi-test
Executable file
BIN
ns-3_wifi_tests/wifi-test
Executable file
Binary file not shown.
149
ns-3_wifi_tests/wifi-test.cc
Normal file
149
ns-3_wifi_tests/wifi-test.cc
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
// ns-3
|
||||||
|
#include "ns3/log.h"
|
||||||
|
#include "ns3/uinteger.h"
|
||||||
|
#include "ns3/boolean.h"
|
||||||
|
#include "ns3/string.h"
|
||||||
|
#include "ns3/command-line.h"
|
||||||
|
#include "ns3/internet-stack-helper.h"
|
||||||
|
#include "ns3/internet-stack-helper.h"
|
||||||
|
#include "ns3/ipv4-address-helper.h"
|
||||||
|
#include "ns3/on-off-helper.h"
|
||||||
|
#include "ns3/packet-sink-helper.h"
|
||||||
|
#include "ns3/udp-echo-helper.h"
|
||||||
|
#include "ns3/constant-position-mobility-model.h"
|
||||||
|
#include "ns3/propagation-loss-model.h"
|
||||||
|
#include "ns3/propagation-delay-model.h"
|
||||||
|
#include "ns3/yans-wifi-channel.h"
|
||||||
|
#include "ns3/yans-wifi-helper.h"
|
||||||
|
|
||||||
|
// C++ library
|
||||||
|
#include <iostream>
|
||||||
|
#include <utility> // To use std::pair
|
||||||
|
|
||||||
|
using namespace ns3;
|
||||||
|
|
||||||
|
NS_LOG_COMPONENT_DEFINE ("wifi-tcp");
|
||||||
|
|
||||||
|
typedef std::pair<NodeContainer,NetDeviceContainer> Cell;
|
||||||
|
|
||||||
|
Cell createCell(uint32_t nbSensors){
|
||||||
|
// Create sensors
|
||||||
|
NodeContainer sensors;
|
||||||
|
sensors.Create(nbSensors);
|
||||||
|
|
||||||
|
// Place nodes somehow, this is required by every wireless simulation
|
||||||
|
for (uint8_t i = 0; i < nbSensors; ++i)
|
||||||
|
{
|
||||||
|
sensors.Get (i)->AggregateObject (CreateObject<ConstantPositionMobilityModel> ());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create propagation loss matrix
|
||||||
|
Ptr<MatrixPropagationLossModel> lossModel = CreateObject<MatrixPropagationLossModel> ();
|
||||||
|
lossModel->SetDefaultLoss (200); // set default loss to 200 dB (no link)
|
||||||
|
lossModel->SetLoss (sensors.Get (0)->GetObject<MobilityModel> (), sensors.Get (1)->GetObject<MobilityModel> (), 50); // set symmetric loss 0 <-> 1 to 50 dB
|
||||||
|
lossModel->SetLoss (sensors.Get (2)->GetObject<MobilityModel> (), sensors.Get (1)->GetObject<MobilityModel> (), 50); // set symmetric loss 2 <-> 1 to 50 dB
|
||||||
|
|
||||||
|
// 4. Create & setup wifi channel
|
||||||
|
Ptr<YansWifiChannel> wifiChannel = CreateObject <YansWifiChannel> ();
|
||||||
|
wifiChannel->SetPropagationLossModel (lossModel);
|
||||||
|
wifiChannel->SetPropagationDelayModel (CreateObject <ConstantSpeedPropagationDelayModel> ());
|
||||||
|
|
||||||
|
|
||||||
|
// Install wireless devices
|
||||||
|
WifiHelper wifi;
|
||||||
|
wifi.SetStandard (WIFI_PHY_STANDARD_80211b);
|
||||||
|
wifi.SetRemoteStationManager ("ns3::ArfWifiManager");
|
||||||
|
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
|
||||||
|
wifiPhy.SetChannel (wifiChannel);
|
||||||
|
WifiMacHelper wifiMac;
|
||||||
|
wifiMac.SetType ("ns3::AdhocWifiMac"); // use ad-hoc MAC
|
||||||
|
NetDeviceContainer devices = wifi.Install (wifiPhy, wifiMac, sensors);
|
||||||
|
|
||||||
|
return(std::make_pair(sensors,devices));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void applyScenarios(Cell cell){
|
||||||
|
NodeContainer sensors=cell.first;
|
||||||
|
NetDeviceContainer devices= cell.second;
|
||||||
|
|
||||||
|
// 6. Install TCP/IP stack & assign IP addresses
|
||||||
|
InternetStackHelper internet;
|
||||||
|
internet.Install (sensors);
|
||||||
|
Ipv4AddressHelper ipv4;
|
||||||
|
ipv4.SetBase ("10.0.0.0", "255.0.0.0");
|
||||||
|
ipv4.Assign (devices);
|
||||||
|
|
||||||
|
// Install applications: two CBR streams each saturating the channel
|
||||||
|
ApplicationContainer cbrApps;
|
||||||
|
uint16_t cbrPort = 12345;
|
||||||
|
OnOffHelper onOffHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address ("10.0.0.2"), cbrPort));
|
||||||
|
onOffHelper.SetAttribute ("PacketSize", UintegerValue (1400));
|
||||||
|
onOffHelper.SetAttribute ("OnTime", StringValue ("ns3::ConstantRandomVariable[Constant=1]"));
|
||||||
|
onOffHelper.SetAttribute ("OffTime", StringValue ("ns3::ConstantRandomVariable[Constant=0]"));
|
||||||
|
|
||||||
|
// flow 1: node 0 -> node 1
|
||||||
|
onOffHelper.SetAttribute ("DataRate", StringValue ("3000000bps"));
|
||||||
|
onOffHelper.SetAttribute ("StartTime", TimeValue (Seconds (1.000000)));
|
||||||
|
cbrApps.Add (onOffHelper.Install (sensors.Get (0)));
|
||||||
|
|
||||||
|
// flow 2: node 2 -> node 1
|
||||||
|
/** \internal
|
||||||
|
* The slightly different start times and data rates are a workaround
|
||||||
|
* for \bugid{388} and \bugid{912}
|
||||||
|
*/
|
||||||
|
onOffHelper.SetAttribute ("DataRate", StringValue ("3001100bps"));
|
||||||
|
onOffHelper.SetAttribute ("StartTime", TimeValue (Seconds (1.001)));
|
||||||
|
cbrApps.Add (onOffHelper.Install (sensors.Get (2)));
|
||||||
|
|
||||||
|
/** \internal
|
||||||
|
* We also use separate UDP applications that will send a single
|
||||||
|
* packet before the CBR flows start.
|
||||||
|
* This is a workaround for the lack of perfect ARP, see \bugid{187}
|
||||||
|
*/
|
||||||
|
uint16_t echoPort = 9;
|
||||||
|
UdpEchoClientHelper echoClientHelper (Ipv4Address ("10.0.0.2"), echoPort);
|
||||||
|
echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (1));
|
||||||
|
echoClientHelper.SetAttribute ("Interval", TimeValue (Seconds (0.1)));
|
||||||
|
echoClientHelper.SetAttribute ("PacketSize", UintegerValue (10));
|
||||||
|
ApplicationContainer pingApps;
|
||||||
|
|
||||||
|
// again using different start times to workaround Bug 388 and Bug 912
|
||||||
|
echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (0.001)));
|
||||||
|
pingApps.Add (echoClientHelper.Install (sensors.Get (0)));
|
||||||
|
echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (0.006)));
|
||||||
|
pingApps.Add (echoClientHelper.Install (sensors.Get (2)));
|
||||||
|
|
||||||
|
PacketSinkHelper s("ns3::UdpSocketFactory",Address(InetSocketAddress (Ipv4Address::GetAny (), echoPort)));
|
||||||
|
ApplicationContainer as=s.Install(sensors.Get(1));
|
||||||
|
as.Start (Seconds (0));
|
||||||
|
as.Stop (Seconds (10.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]){
|
||||||
|
|
||||||
|
LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
||||||
|
LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t sensingRate=1;
|
||||||
|
uint32_t sensorPktSize=150;
|
||||||
|
|
||||||
|
CommandLine cmd;
|
||||||
|
cmd.AddValue ("sensingRate", "Number of temperature measurement per second", sensingRate);
|
||||||
|
cmd.AddValue ("sensorPktSize", "Sensor measurements packet size", sensorPktSize);
|
||||||
|
cmd.Parse (argc, argv);
|
||||||
|
|
||||||
|
|
||||||
|
Cell c=createCell(3);
|
||||||
|
applyScenarios(c);
|
||||||
|
|
||||||
|
// Run simulators
|
||||||
|
Simulator::Stop (Seconds (10));
|
||||||
|
Simulator::Run ();
|
||||||
|
|
||||||
|
// Destroy
|
||||||
|
Simulator::Destroy ();
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue