mirror of
https://gitlab.com/manzerbredes/paper-lowrate-iot.git
synced 2025-05-01 01:17:46 +00:00
Add simulation scripts
This commit is contained in:
parent
39507e0bb5
commit
1da73fb609
18 changed files with 4043 additions and 2 deletions
1
ns3-simulations/.#simulate.org
Symbolic link
1
ns3-simulations/.#simulate.org
Symbolic link
|
@ -0,0 +1 @@
|
|||
loic@lguegan.7447:1555309869
|
1947
ns3-simulations/logs/log.txt
Normal file
1947
ns3-simulations/logs/log.txt
Normal file
File diff suppressed because it is too large
Load diff
6
ns3-simulations/logs/log.txt-energy.csv
Normal file
6
ns3-simulations/logs/log.txt-energy.csv
Normal file
|
@ -0,0 +1,6 @@
|
|||
node,energy
|
||||
0,1.00026
|
||||
1,2.00021
|
||||
2,2.00021
|
||||
3,2
|
||||
4,1
|
|
1
ns3-simulations/logs/log.txt-energy.csv-energy.csv
Normal file
1
ns3-simulations/logs/log.txt-energy.csv-energy.csv
Normal file
|
@ -0,0 +1 @@
|
|||
node,energy
|
|
5
ns3-simulations/logs/log.txt.csv
Normal file
5
ns3-simulations/logs/log.txt.csv
Normal file
|
@ -0,0 +1,5 @@
|
|||
0,1.00026
|
||||
1,2.00021
|
||||
2,2.00021
|
||||
3,2
|
||||
4,1
|
|
1
ns3-simulations/logs/log.txt.csv-energy.csv
Normal file
1
ns3-simulations/logs/log.txt.csv-energy.csv
Normal file
|
@ -0,0 +1 @@
|
|||
node,energy
|
|
1
ns3-simulations/logs/log.txt.csv-energy.csv-energy.csv
Normal file
1
ns3-simulations/logs/log.txt.csv-energy.csv-energy.csv
Normal file
|
@ -0,0 +1 @@
|
|||
node,energy
|
|
1961
ns3-simulations/logs/ns-3_1SSI_10SPS_2SN_2NH_10LB_10LL.org
Normal file
1961
ns3-simulations/logs/ns-3_1SSI_10SPS_2SN_2NH_10LB_10LL.org
Normal file
File diff suppressed because it is too large
Load diff
1
ns3-simulations/ns-3_1SSI_10SPS_2SN_2NH_10LB_10LL.org
Normal file
1
ns3-simulations/ns-3_1SSI_10SPS_2SN_2NH_10LB_10LL.org
Normal file
|
@ -0,0 +1 @@
|
|||
#TITLE: mer. avril 24 16:37:06 CEST 2019 ns-3 simulation
|
25
ns3-simulations/ns3-simulator/Makefile
Normal file
25
ns3-simulations/ns3-simulator/Makefile
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
EXEC=simulator
|
||||
|
||||
##### NS3 g++ Arguments
|
||||
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)))))
|
||||
|
||||
##### Source Files
|
||||
SRC=main.cc modules/platform.cc modules/energy.cc modules/callbacks.cc
|
||||
|
||||
|
||||
all: $(EXEC)
|
||||
|
||||
|
||||
$(EXEC): $(SRC)
|
||||
@echo -e "\e[32mDon't forget to define NS3_PATH env variable !\e[0m"
|
||||
g++ $(NS3_ARGS) $(SRC) -o $@
|
||||
@echo -e "\e[32mRun the following command before running $(EXEC):\e[0m"
|
||||
@echo -e "\e[32mexport LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${NS3_PATH}/build/lib\e[0m"
|
||||
|
||||
clean:
|
||||
- rm $(EXEC)
|
||||
|
||||
|
||||
.PHONY: clean
|
46
ns3-simulations/ns3-simulator/main.cc
Normal file
46
ns3-simulations/ns3-simulator/main.cc
Normal file
|
@ -0,0 +1,46 @@
|
|||
#include "modules/modules.hpp"
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("WIFISensorsSimulator");
|
||||
|
||||
|
||||
/**
|
||||
* To get more details about functions please have a look at modules/modules.hpp
|
||||
*/
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
uint32_t sensorsFrequency=1;
|
||||
uint32_t sensorsPktSize=150;
|
||||
uint32_t sensorsNumber=2;
|
||||
uint32_t nbHop=5;
|
||||
uint32_t linksBandwidth=5;
|
||||
uint32_t linksLatency=2;
|
||||
|
||||
CommandLine cmd;
|
||||
cmd.AddValue ("sensorsSendInterval", "Number of sensors measurement per second", sensorsFrequency);
|
||||
cmd.AddValue ("sensorsPktSize", "Sensors packet size (bytes)", sensorsPktSize);
|
||||
cmd.AddValue ("sensorsNumber", "Number of sensors connected to AP", sensorsNumber);
|
||||
cmd.AddValue ("nbHop", "Number of hop between AP and Cloud", sensorsNumber);
|
||||
cmd.AddValue ("linksBandwidth", "Links bandwidth between AP and Cloud", linksBandwidth);
|
||||
cmd.AddValue ("linksLatency", "Links latency between AP and Cloud", linksLatency);
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
//LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
||||
//LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
|
||||
|
||||
// ---------- Setup Simulations ----------
|
||||
CloudInfos cloud=createCloud(nbHop,linksBandwidth,linksLatency); // Create cloud P2P node chain o--o--o--o--o
|
||||
setupCloudEnergy(cloud); // DO IT JUST AFTER createCloud !!!!! Otherwise you will be in trouble
|
||||
Cell cell=createCell(sensorsNumber,cloud.first.Get(0)); // Use first cloud node as Access Point
|
||||
setupScenario(cell,cloud,sensorsPktSize,sensorsFrequency); // Send data from Sensors to Cloud
|
||||
setupCellEnergy(cell);
|
||||
|
||||
// Don't forget the following
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
// Run Simulations
|
||||
Simulator::Stop (Seconds (20));
|
||||
Simulator::Run ();
|
||||
Simulator::Destroy ();
|
||||
|
||||
return(0);
|
||||
}
|
10
ns3-simulations/ns3-simulator/modules/callbacks.cc
Normal file
10
ns3-simulations/ns3-simulator/modules/callbacks.cc
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
#include "modules.hpp"
|
||||
|
||||
void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address){
|
||||
NS_LOG_UNCOND("Node " << nodeName << " receive a packet" << " at time " << Simulator::Now ().GetSeconds () << "s");
|
||||
}
|
||||
|
||||
void EnergyUpdated(std::string nodeName,double oldValue, double newValue){
|
||||
NS_LOG_UNCOND("Node " << nodeName << " consumes " << newValue-oldValue << "J" << " at time " << Simulator::Now ().GetSeconds () << "s");
|
||||
}
|
66
ns3-simulations/ns3-simulator/modules/energy.cc
Normal file
66
ns3-simulations/ns3-simulator/modules/energy.cc
Normal file
|
@ -0,0 +1,66 @@
|
|||
|
||||
#include "modules.hpp"
|
||||
|
||||
void setupCellEnergy(Cell cell){
|
||||
NodeContainer nodes(cell.first.first,cell.first.second);
|
||||
NetDeviceContainer nodesNetDev(cell.second.first,cell.second.second);
|
||||
|
||||
// Install energy source
|
||||
BasicEnergySourceHelper edgeBasicSourceHelper;
|
||||
edgeBasicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (BASICENERGYSOURCEINITIALENERGYJ));
|
||||
edgeBasicSourceHelper.Set ("BasicEnergySupplyVoltageV", DoubleValue (BASICENERGYSUPPLYVOLTAGEV));
|
||||
EnergySourceContainer apEdgeNodesSources = edgeBasicSourceHelper.Install (cell.first.first);
|
||||
EnergySourceContainer wifiEdgeNodesSources = edgeBasicSourceHelper.Install (cell.first.second);
|
||||
|
||||
// Install device energy model
|
||||
WifiRadioEnergyModelHelper radioEnergyHelper;
|
||||
radioEnergyHelper.Set ("TxCurrentA", DoubleValue (TXCURRENTA));
|
||||
radioEnergyHelper.Set ("RxCurrentA", DoubleValue (RXCURRENTA));
|
||||
radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (IDLECURRENTA));
|
||||
DeviceEnergyModelContainer edgeApDeviceModels = radioEnergyHelper.Install (cell.second.first, apEdgeNodesSources);
|
||||
DeviceEnergyModelContainer edgeDeviceModels = radioEnergyHelper.Install (cell.second.second, wifiEdgeNodesSources);
|
||||
|
||||
|
||||
// Trace
|
||||
DeviceEnergyModelContainer energyModels(edgeApDeviceModels, edgeDeviceModels);
|
||||
DeviceEnergyModelContainer::Iterator it=energyModels.Begin();
|
||||
|
||||
int i=0;
|
||||
while(it!=energyModels.End()){
|
||||
(*it)->TraceConnect ("TotalEnergyConsumption", std::to_string(i),MakeCallback (&EnergyUpdated));
|
||||
it++;
|
||||
i++;
|
||||
}
|
||||
|
||||
// Ptr<BasicEnergySource> basicSourcePtr0 = DynamicCast<BasicEnergySource> (wifiEdgeNodesSources.Get (0));
|
||||
// //basicSourcePtr0->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy));
|
||||
// //device energy model
|
||||
// Ptr<DeviceEnergyModel> basicRadioModelPtr0 =
|
||||
// basicSourcePtr0->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
|
||||
// NS_ASSERT (basicRadioModelPtr0 != NULL);
|
||||
// basicRadioModelPtr0->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));
|
||||
|
||||
}
|
||||
|
||||
void setupCloudEnergy(CloudInfos cloudInfos){
|
||||
NodeContainer cloudNodes=cloudInfos.first;
|
||||
|
||||
// Install basic energy
|
||||
ns3::BasicNodeEnergyHelper basicNodeEnergy;
|
||||
basicNodeEnergy.Set("OnConso", ns3::DoubleValue (ONCONSO));
|
||||
basicNodeEnergy.Set("OffConso", ns3::DoubleValue (OFFCONSO));
|
||||
basicNodeEnergy.Install (cloudNodes);
|
||||
|
||||
ns3::CompleteNetdeviceEnergyHelper completeNetdeviceEnergy;
|
||||
completeNetdeviceEnergy.Set ("OffConso", ns3::DoubleValue (OFFCONSO));
|
||||
completeNetdeviceEnergy.Set ("IdleConso", ns3::DoubleValue (IDLECONSO));
|
||||
completeNetdeviceEnergy.Set ("RecvByteEnergy", ns3::DoubleValue (RECVBYTEENERGY));
|
||||
completeNetdeviceEnergy.Set ("SentByteEnergy", ns3::DoubleValue (SENTBYTEENERGY));
|
||||
completeNetdeviceEnergy.Set ("RecvPktEnergy", ns3::DoubleValue (RECVPKTENERGY));
|
||||
completeNetdeviceEnergy.Set ("SentPktEnergy", ns3::DoubleValue (SENTPKTENERGY));
|
||||
completeNetdeviceEnergy.Install(cloudNodes);
|
||||
|
||||
ns3::ConsumptionLogger conso;
|
||||
conso.NodeConso(ns3::Seconds (ECOFEN_LOG_EVERY), ns3::Seconds(ECOFEN_LOG_UNTIL), cloudNodes);
|
||||
}
|
||||
|
98
ns3-simulations/ns3-simulator/modules/modules.hpp
Normal file
98
ns3-simulations/ns3-simulator/modules/modules.hpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
|
||||
|
||||
#ifndef MODULES_HPP
|
||||
#define MODULES_HPP
|
||||
|
||||
#include "ns3/command-line.h"
|
||||
#include "ns3/config.h"
|
||||
#include "ns3/string.h"
|
||||
#include "ns3/log.h"
|
||||
#include "ns3/yans-wifi-helper.h"
|
||||
#include "ns3/ssid.h"
|
||||
#include "ns3/mobility-helper.h"
|
||||
#include "ns3/on-off-helper.h"
|
||||
#include "ns3/yans-wifi-channel.h"
|
||||
#include "ns3/mobility-model.h"
|
||||
#include "ns3/packet-sink.h"
|
||||
#include "ns3/packet-sink-helper.h"
|
||||
#include "ns3/udp-echo-helper.h"
|
||||
#include "ns3/tcp-westwood.h"
|
||||
#include "ns3/internet-stack-helper.h"
|
||||
#include "ns3/ipv4-address-helper.h"
|
||||
#include "ns3/ipv4-global-routing-helper.h"
|
||||
#include "ns3/constant-position-mobility-model.h"
|
||||
#include "ns3/energy-module.h"
|
||||
#include "ns3/wifi-radio-energy-model-helper.h"
|
||||
#include "ns3/point-to-point-helper.h"
|
||||
#include "ns3/ecofen-module.h"
|
||||
|
||||
// C++ library
|
||||
#include <iostream> // Why not ?
|
||||
#include <utility> // To use std::pair
|
||||
#include <iomanip> // To use std::setw
|
||||
|
||||
// ECOFEN
|
||||
#define ECOFEN_LOG_UNTIL 1
|
||||
#define ECOFEN_LOG_EVERY 0.1
|
||||
|
||||
// WIFI Energy Values
|
||||
#define BASICENERGYSOURCEINITIALENERGYJ 1000
|
||||
#define BASICENERGYSUPPLYVOLTAGEV 3.3
|
||||
#define TXCURRENTA 0.38
|
||||
#define RXCURRENTA 0.313
|
||||
#define IDLECURRENTA 0.273
|
||||
|
||||
// Cloud Energy Values
|
||||
#define ONCONSO 0
|
||||
#define OFFCONSO 0
|
||||
#define IDLECONSO 1
|
||||
#define RECVBYTEENERGY 10
|
||||
#define SENTBYTEENERGY 10
|
||||
#define RECVPKTENERGY 10
|
||||
#define SENTPKTENERGY 0
|
||||
|
||||
using namespace ns3;
|
||||
|
||||
// ---------- Data types ----------
|
||||
typedef std::pair<NodeContainer,NodeContainer> CellNodes; // Format (APNode, SensorsNodes)
|
||||
typedef std::pair<NetDeviceContainer,NetDeviceContainer> CellNetDevices; // Format (APNetDev, SensorsNetDev)
|
||||
typedef std::pair<CellNodes,CellNetDevices> Cell;
|
||||
typedef std::pair<Ipv4Address,int> EndPoint; // Format (IP,Port)
|
||||
typedef std::pair<NodeContainer,EndPoint> CloudInfos; // Format (CloudHops,CloudEndPoint), here data sent to CloudEndPoint
|
||||
|
||||
|
||||
// ---------- platform.cc ----------
|
||||
/**
|
||||
* Create a WIFI cell paltform composed of nbSensors sensors and ap as an access point
|
||||
*/
|
||||
Cell createCell(uint32_t nbSensors, Ptr<ns3::Node> ap);
|
||||
/**
|
||||
* Build P2P network composed of nbHop hops (to simulate edge->cloud communications)
|
||||
* Note: Cloud Servers are not considered here and completely ignored !
|
||||
*/
|
||||
CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency);
|
||||
/**
|
||||
* Setup simulation scenario on the platforms. Sensors in cell will send packets of sensorsPktSize size every
|
||||
* sensorsSensInterval second to the cloud using cloudInfos.
|
||||
*/
|
||||
void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sensorsSendInterval);
|
||||
|
||||
|
||||
// ---------- energy.cc ----------
|
||||
/*
|
||||
* Configure WIFI energy module for cell
|
||||
*/
|
||||
void setupCellEnergy(Cell cell);
|
||||
/*
|
||||
* Configure link/port energy using ecofen
|
||||
*/
|
||||
void setupCloudEnergy(CloudInfos cloudInfos);
|
||||
|
||||
|
||||
// ---------- callbacks.cc ----------
|
||||
void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address);
|
||||
void EnergyUpdated(std::string nodeName,double oldValue, double newValue);
|
||||
|
||||
|
||||
|
||||
#endif
|
124
ns3-simulations/ns3-simulator/modules/platform.cc
Normal file
124
ns3-simulations/ns3-simulator/modules/platform.cc
Normal file
|
@ -0,0 +1,124 @@
|
|||
#include "modules.hpp"
|
||||
|
||||
/**
|
||||
* Create a sensors cell base on
|
||||
* nbSensors Number of temperature sensors in the cell
|
||||
* ap the Access Point (usually linked to the cloud)
|
||||
*/
|
||||
Cell createCell(uint32_t nbSensors, Ptr<ns3::Node> ap){
|
||||
// Create sensors
|
||||
NodeContainer sensors;
|
||||
sensors.Create(nbSensors);
|
||||
|
||||
// Place nodes somehow, this is required by every wireless simulation
|
||||
for (uint32_t i = 0; i < nbSensors; i++)
|
||||
{
|
||||
sensors.Get (i)->AggregateObject (CreateObject<ConstantPositionMobilityModel> ());
|
||||
}
|
||||
ap->AggregateObject (CreateObject<ConstantPositionMobilityModel> ());
|
||||
|
||||
// To apply XXWifiPhy and WifiMac on sensors
|
||||
WifiHelper wifiHelper;
|
||||
wifiHelper.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ);
|
||||
|
||||
/* Set up Legacy Channel */
|
||||
YansWifiChannelHelper wifiChannel;
|
||||
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
|
||||
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel", "Frequency", DoubleValue (5e9));
|
||||
|
||||
/* Setup Physical Layer */
|
||||
YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default ();
|
||||
wifiPhy.SetChannel (wifiChannel.Create ());
|
||||
wifiPhy.Set ("TxPowerStart", DoubleValue (10.0));
|
||||
wifiPhy.Set ("TxPowerEnd", DoubleValue (10.0));
|
||||
wifiPhy.Set ("TxPowerLevels", UintegerValue (1));
|
||||
wifiPhy.Set ("TxGain", DoubleValue (0));
|
||||
wifiPhy.Set ("RxGain", DoubleValue (0));
|
||||
wifiPhy.Set ("RxNoiseFigure", DoubleValue (10));
|
||||
wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-79));
|
||||
wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-79 + 3));
|
||||
// wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel");
|
||||
wifiHelper.SetRemoteStationManager ("ns3::ConstantRateWifiManager",
|
||||
"DataMode", StringValue ("HtMcs7"),
|
||||
"ControlMode", StringValue ("HtMcs0"));
|
||||
/* Configure AP */
|
||||
Ssid ssid = Ssid ("network");
|
||||
WifiMacHelper wifiMac;
|
||||
wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid));
|
||||
NetDeviceContainer apNetDevice;
|
||||
apNetDevice = wifiHelper.Install (wifiPhy, wifiMac, ap);
|
||||
/* Configure STA */
|
||||
wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid));
|
||||
NetDeviceContainer sensorsNetDevices;
|
||||
sensorsNetDevices = wifiHelper.Install (wifiPhy, wifiMac, sensors);
|
||||
|
||||
return(std::make_pair(std::make_pair(ap,sensors),std::make_pair(apNetDevice,sensorsNetDevices)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Install network stack and applications
|
||||
*/
|
||||
void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sensorsSendInterval){
|
||||
NodeContainer ap=cell.first.first;
|
||||
NodeContainer sensors=cell.first.second;
|
||||
NetDeviceContainer apNetDev= cell.second.first;
|
||||
NetDeviceContainer sensorsNetDev= cell.second.second;
|
||||
|
||||
// 6. Install TCP/IP stack & assign IP addresses
|
||||
InternetStackHelper internet;
|
||||
// internet.Install (ap);
|
||||
internet.Install (sensors);
|
||||
Ipv4AddressHelper ipv4;
|
||||
ipv4.SetBase ("10.0.0.0", "255.255.0.0");
|
||||
Ipv4InterfaceContainer apInt,sensorsInt;
|
||||
apInt=ipv4.Assign(apNetDev);
|
||||
sensorsInt=ipv4.Assign(sensorsNetDev);
|
||||
|
||||
UdpEchoClientHelper echoClientHelper (InetSocketAddress (cloudInfos.second.first, cloudInfos.second.second));
|
||||
// echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (10));
|
||||
echoClientHelper.SetAttribute ("Interval", TimeValue (Seconds (sensorsSendInterval)));
|
||||
echoClientHelper.SetAttribute ("PacketSize", UintegerValue (sensorsPktSize));
|
||||
ApplicationContainer pingApps;
|
||||
|
||||
// again using different start times to workaround Bug 388 and Bug 912
|
||||
echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (1))); // Start at 1 (WIFI seems to not work when t<1)
|
||||
echoClientHelper.Install (sensors);
|
||||
}
|
||||
|
||||
|
||||
CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency){
|
||||
|
||||
NodeContainer HopNodes;
|
||||
HopNodes.Create(nbHop);
|
||||
InternetStackHelper stack;
|
||||
stack.Install(HopNodes);
|
||||
|
||||
Ipv4Address cloudIP; // Will be fill in the following for loop
|
||||
int cloudPort=80;
|
||||
for(int i=0;i<nbHop-1;i++){
|
||||
NodeContainer curNodes(HopNodes.Get(i),HopNodes.Get(i+1));
|
||||
|
||||
PointToPointHelper pointToPoint;
|
||||
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ((std::to_string(bandwidth)+"Mbps").c_str()));
|
||||
pointToPoint.SetChannelAttribute ("Delay", StringValue ((std::to_string(latency)+"ms").c_str()));
|
||||
|
||||
NetDeviceContainer p2pDevices;
|
||||
p2pDevices = pointToPoint.Install (curNodes);
|
||||
|
||||
Ipv4AddressHelper address;
|
||||
address.SetBase (("10."+std::to_string(i+1)+".0.0").c_str(), "255.255.0.0"); // Remember: 10.0.0.0 is used by WIFI
|
||||
Ipv4InterfaceContainer p2pInterfaces;
|
||||
p2pInterfaces = address.Assign (p2pDevices);
|
||||
|
||||
if(i==nbHop-2){ // If we are on the last for loop (before last node)
|
||||
cloudIP=p2pInterfaces.GetAddress (1); // Get Last node interface
|
||||
PacketSinkHelper apSink("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), cloudPort));
|
||||
ApplicationContainer sinkApp=apSink.Install(curNodes.Get(1)); // Instal sink on last node
|
||||
sinkApp.Get(0)->TraceConnect("Rx","CloudSwitch",MakeCallback(&PktReceived));
|
||||
sinkApp.Start (Seconds (0));
|
||||
}
|
||||
}
|
||||
|
||||
return(std::make_pair(HopNodes,std::make_pair(cloudIP,cloudPort)));
|
||||
|
||||
}
|
BIN
ns3-simulations/ns3-simulator/simulator
Executable file
BIN
ns3-simulations/ns3-simulator/simulator
Executable file
Binary file not shown.
59
ns3-simulations/parseEnergy.awk
Executable file
59
ns3-simulations/parseEnergy.awk
Executable file
|
@ -0,0 +1,59 @@
|
|||
#!/bin/awk -f
|
||||
|
||||
BEGIN {
|
||||
durationECOFEN=0
|
||||
}
|
||||
|
||||
# For ECOFEN energy model
|
||||
/Node [0-9]+ Conso/ {
|
||||
if (!($4 in energyECOFEN)){
|
||||
energyECOFEN[$4]=$6
|
||||
countECOFEN[$4]=1
|
||||
}
|
||||
else {
|
||||
energyECOFEN[$4]=$6+energyECOFEN[$4]
|
||||
countECOFEN[$4]++
|
||||
}
|
||||
durationECOFEN=$2
|
||||
}
|
||||
|
||||
# For WIFI ns-3 energy model
|
||||
/Node [0-9]+ consumes/ {
|
||||
gsub("J","",$4) # Remove trailling Joule symbol
|
||||
if (!($2 in energy)){
|
||||
energyWIFI[$2]=$4
|
||||
}
|
||||
else {
|
||||
energyWIFI[$2]=$4+energyWIFI[$2]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
END {
|
||||
# Extract ECOFEN energy
|
||||
for(key in energyECOFEN){
|
||||
if (countECOFEN[key]>0){ # Otherwise: 0 division
|
||||
overallEnergy[key]=energyECOFEN[key]/countECOFEN[key]*durationECOFEN
|
||||
}
|
||||
else {
|
||||
overallEnergy[key]=0
|
||||
}
|
||||
}
|
||||
|
||||
# Extract WIFI energy
|
||||
for(key in energyWIFI){
|
||||
if(key in overallEnergy){ # Combine WIFI+ECOFEN
|
||||
overallEnergy[key]+=energyWIFI[key] # Add wifi to ECOFEN
|
||||
}
|
||||
else {
|
||||
overallEnergy[key]=energyWIFI[key] # Only add WIFI since there is no ECOFEN value
|
||||
}
|
||||
}
|
||||
|
||||
# CSV output
|
||||
print("node,energy")
|
||||
for(key in overallEnergy){
|
||||
print(key "," overallEnergy[key])
|
||||
}
|
||||
}
|
54
ns3-simulations/simulate.org
Normal file
54
ns3-simulations/simulate.org
Normal file
|
@ -0,0 +1,54 @@
|
|||
|
||||
|
||||
|
||||
|
||||
* Run simulations
|
||||
|
||||
|
||||
** Single Run
|
||||
#+BEGIN_SRC bash :noweb yes :results output
|
||||
<<singleRun>>
|
||||
run
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: sensorsSendInterval:1 sensorsPktSize:10 sensorsNumber:2 nbHop:2 linksBandwidth:10 linksLatency:10
|
||||
|
||||
|
||||
#+NAME: singleRun
|
||||
#+BEGIN_SRC bash :noweb yes
|
||||
simulator="ns3-simulator/simulator"
|
||||
parseEnergyScript="./parseEnergy.awk"
|
||||
logFolder="logs/"
|
||||
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${NS3_PATH}/build/lib
|
||||
run () {
|
||||
[ -z ${sensorsSendInterval+x} ] && sensorsSendInterval=1
|
||||
[ -z ${sensorsPktSize+x} ] && sensorsPktSize=10
|
||||
[ -z ${sensorsNumber+x} ] && sensorsNumber=2
|
||||
[ -z ${nbHop+x} ] && nbHop=2
|
||||
[ -z ${linksBandwidth+x} ] && linksBandwidth=10
|
||||
[ -z ${linksLatency+x} ] && linksLatency=10
|
||||
logFile="${logFolder}/ns-3_${sensorsSendInterval}SSI_${sensorsPktSize}SPS_${sensorsNumber}SN_${nbHop}NH_${linksBandwidth}LB_${linksLatency}LL.org"
|
||||
simCMD="$simulator --sensorsSendInterval=${sensorsSendInterval} --sensorsPktSize=${sensorsPktSize} --sensorsNumber=${sensorsNumber} --nbHop=${nbHop} --linksBandwidth=${linksBandwidth} --linksLatency=${linksLatency} 2>&1"
|
||||
log=$(bash -c "$simCMD")
|
||||
|
||||
|
||||
echo -e "#+TITLE: $(date) ns-3 simulation\n" > $logFile
|
||||
echo "* Full Command" >> $logFile
|
||||
echo "$simCMD" >> $logFile
|
||||
echo "* Output" >> $logFile
|
||||
echo "$log" >> $logFile
|
||||
echo "* Energy CSV" >> $logFile
|
||||
echo "$log" | $parseEnergyScript >> $logFile
|
||||
echo "* Metrics" >> $logFile
|
||||
echo " sensorsSendInterval:${sensorsSendInterval} sensorsPktSize:${sensorsPktSize} sensorsNumber:${sensorsNumber} nbHop:${nbHop} linksBandwidth:${linksBandwidth} linksLatency:${linksLatency}" >> $logFile
|
||||
|
||||
}
|
||||
#+END_SRC
|
||||
|
||||
#+RESULTS:
|
||||
: Processing logs/logs/log.txt
|
||||
: Processing logs/logs/log.txt.csv-energy.csv
|
||||
: Processing logs/logs/log.txt.csv
|
||||
: Processing logs/logs/log.txt-energy.csv
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue