From cb10ad2490706fc87f19ef556f36aee679887ad6 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Fri, 12 Apr 2019 14:48:47 +0200 Subject: Refactoring --- ns3-simulator/modules/energy.cc | 2 +- ns3-simulator/modules/modules.hpp | 39 ++++++++++++++++++++++++++++----------- ns3-simulator/modules/platform.cc | 30 +++++++++++++++--------------- 3 files changed, 44 insertions(+), 27 deletions(-) (limited to 'ns3-simulator/modules') diff --git a/ns3-simulator/modules/energy.cc b/ns3-simulator/modules/energy.cc index b07c835..9c91bf4 100644 --- a/ns3-simulator/modules/energy.cc +++ b/ns3-simulator/modules/energy.cc @@ -1,7 +1,7 @@ #include "modules.hpp" -void setupEnergy(Cell cell){ +void setupCellEnergy(Cell cell){ NodeContainer nodes(cell.first.first,cell.first.second); NetDeviceContainer nodesNetDev(cell.second.first,cell.second.second); diff --git a/ns3-simulator/modules/modules.hpp b/ns3-simulator/modules/modules.hpp index fa6a255..9423866 100644 --- a/ns3-simulator/modules/modules.hpp +++ b/ns3-simulator/modules/modules.hpp @@ -26,31 +26,48 @@ #include "ns3/point-to-point-helper.h" // C++ library -#include -#include // To use std::pair -#include +#include // Why not ? +#include // To use std::pair +#include // To use std::setw using namespace ns3; -// Data types +// ---------- Data types ---------- typedef std::pair CellNodes; // Format (APNode, SensorsNodes) typedef std::pair CellNetDevices; // Format (APNetDev, SensorsNetDev) typedef std::pair Cell; typedef std::pair EndPoint; // Format (IP,Port) typedef std::pair CloudInfos; // Format (CloudHops,CloudEndPoint), here data sent to CloudEndPoint - // via CloudHops.Get(0) will flow throw all hops until the reaching the cloud + // via CloudHops.Get(0) will flow throw all hops until the reaching the cloud -// Platform functions +// ---------- platform.cc ---------- +/** + * Create a WIFI cell paltform composed of nbSensors sensors and ap as an access point + */ Cell createCell(uint32_t nbSensors, Ptr ap); -CloudInfos buildEdgeAndCloud(int nbOp); -void applyScenarios(Cell cell,int sensorsPktSize, int sensorsSendInterval, CloudInfos cloudInfos); +/** + * 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 functions -void setupEnergy(Cell cell); +// ---------- energy.cc ---------- +/* + * Configure WIFI energy module for cell + */ +void setupCellEnergy(Cell cell); -// Callbacks + +// ---------- callbacks.cc ---------- void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address); void EnergyUpdated(std::string nodeName,double oldValue, double newValue); + + #endif diff --git a/ns3-simulator/modules/platform.cc b/ns3-simulator/modules/platform.cc index 81d53cb..82c293d 100644 --- a/ns3-simulator/modules/platform.cc +++ b/ns3-simulator/modules/platform.cc @@ -58,7 +58,7 @@ Cell createCell(uint32_t nbSensors, Ptr ap){ /** * Install network stack and applications */ -void applyScenarios(Cell cell,int sensorsPktSize, int sensorsSendInterval, CloudInfos cloudInfos){ +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; @@ -69,7 +69,7 @@ void applyScenarios(Cell cell,int sensorsPktSize, int sensorsSendInterval, Cloud // internet.Install (ap); internet.Install (sensors); Ipv4AddressHelper ipv4; - ipv4.SetBase ("10.0.0.0", "255.255.255.0"); + ipv4.SetBase ("10.0.0.0", "255.255.0.0"); Ipv4InterfaceContainer apInt,sensorsInt; apInt=ipv4.Assign(apNetDev); sensorsInt=ipv4.Assign(sensorsNetDev); @@ -85,22 +85,22 @@ void applyScenarios(Cell cell,int sensorsPktSize, int sensorsSendInterval, Cloud echoClientHelper.Install (sensors); } -CloudInfos buildEdgeAndCloud(int nbOp){ - - NodeContainer OpNodes; - OpNodes.Create(nbOp); +CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency){ + + NodeContainer HopNodes; + HopNodes.Create(nbHop); InternetStackHelper stack; - stack.Install(OpNodes); + stack.Install(HopNodes); - Ipv4Address cloudIP; - int cloudPort=99; - for(int i=0;i