mirror of
https://gitlab.com/manzerbredes/paper-lowrate-iot.git
synced 2025-06-06 14:47:39 +00:00
Refactoring
This commit is contained in:
parent
9272834371
commit
cb10ad2490
5 changed files with 57 additions and 40 deletions
|
@ -3,6 +3,9 @@
|
||||||
NS_LOG_COMPONENT_DEFINE ("WIFISensorsSimulator");
|
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[]){
|
int main(int argc, char* argv[]){
|
||||||
|
|
||||||
uint32_t sensorsFrequency=1;
|
uint32_t sensorsFrequency=1;
|
||||||
|
@ -20,22 +23,19 @@ int main(int argc, char* argv[]){
|
||||||
//LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
//LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
|
||||||
//LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
|
//LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
|
||||||
|
|
||||||
// Setup Simulations
|
// ---------- Setup Simulations ----------
|
||||||
CloudInfos cloud=buildEdgeAndCloud(nbHop);
|
CloudInfos cloud=createCloud(nbHop,5,2); // Create cloud P2P node chain o--o--o--o--o
|
||||||
Cell c=createCell(sensorsNumber,cloud.first.Get(0));
|
Cell cell=createCell(sensorsNumber,cloud.first.Get(0)); // Use first cloud node as Access Point
|
||||||
applyScenarios(c,sensorsPktSize,sensorsFrequency,cloud); // Send data from Sensors to Cloud
|
setupScenario(cell,cloud,sensorsPktSize,sensorsFrequency); // Send data from Sensors to Cloud
|
||||||
// setupEnergy(c);
|
setupCellEnergy(cell);
|
||||||
|
|
||||||
|
// Don't forget the following
|
||||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||||
|
|
||||||
|
// Run Simulations
|
||||||
|
|
||||||
|
|
||||||
// Run simulators
|
|
||||||
Simulator::Stop (Seconds (20));
|
Simulator::Stop (Seconds (20));
|
||||||
Simulator::Run ();
|
Simulator::Run ();
|
||||||
Simulator::Destroy (); // Destroy
|
Simulator::Destroy ();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#include "modules.hpp"
|
#include "modules.hpp"
|
||||||
|
|
||||||
void setupEnergy(Cell cell){
|
void setupCellEnergy(Cell cell){
|
||||||
NodeContainer nodes(cell.first.first,cell.first.second);
|
NodeContainer nodes(cell.first.first,cell.first.second);
|
||||||
NetDeviceContainer nodesNetDev(cell.second.first,cell.second.second);
|
NetDeviceContainer nodesNetDev(cell.second.first,cell.second.second);
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,13 @@
|
||||||
#include "ns3/point-to-point-helper.h"
|
#include "ns3/point-to-point-helper.h"
|
||||||
|
|
||||||
// C++ library
|
// C++ library
|
||||||
#include <iostream>
|
#include <iostream> // Why not ?
|
||||||
#include <utility> // To use std::pair
|
#include <utility> // To use std::pair
|
||||||
#include <iomanip>
|
#include <iomanip> // To use std::setw
|
||||||
|
|
||||||
using namespace ns3;
|
using namespace ns3;
|
||||||
|
|
||||||
// Data types
|
// ---------- Data types ----------
|
||||||
typedef std::pair<NodeContainer,NodeContainer> CellNodes; // Format (APNode, SensorsNodes)
|
typedef std::pair<NodeContainer,NodeContainer> CellNodes; // Format (APNode, SensorsNodes)
|
||||||
typedef std::pair<NetDeviceContainer,NetDeviceContainer> CellNetDevices; // Format (APNetDev, SensorsNetDev)
|
typedef std::pair<NetDeviceContainer,NetDeviceContainer> CellNetDevices; // Format (APNetDev, SensorsNetDev)
|
||||||
typedef std::pair<CellNodes,CellNetDevices> Cell;
|
typedef std::pair<CellNodes,CellNetDevices> Cell;
|
||||||
|
@ -40,17 +40,34 @@ typedef std::pair<Ipv4Address,int> EndPoint; // Format (IP,Port)
|
||||||
typedef std::pair<NodeContainer,EndPoint> CloudInfos; // Format (CloudHops,CloudEndPoint), here data sent to CloudEndPoint
|
typedef std::pair<NodeContainer,EndPoint> 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<ns3::Node> ap);
|
Cell createCell(uint32_t nbSensors, Ptr<ns3::Node> 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 !
|
||||||
// Energy functions
|
*/
|
||||||
void setupEnergy(Cell cell);
|
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);
|
||||||
|
|
||||||
|
|
||||||
// Callbacks
|
// ---------- energy.cc ----------
|
||||||
|
/*
|
||||||
|
* Configure WIFI energy module for cell
|
||||||
|
*/
|
||||||
|
void setupCellEnergy(Cell cell);
|
||||||
|
|
||||||
|
|
||||||
|
// ---------- callbacks.cc ----------
|
||||||
void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address);
|
void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address);
|
||||||
void EnergyUpdated(std::string nodeName,double oldValue, double newValue);
|
void EnergyUpdated(std::string nodeName,double oldValue, double newValue);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -58,7 +58,7 @@ Cell createCell(uint32_t nbSensors, Ptr<ns3::Node> ap){
|
||||||
/**
|
/**
|
||||||
* Install network stack and applications
|
* 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 ap=cell.first.first;
|
||||||
NodeContainer sensors=cell.first.second;
|
NodeContainer sensors=cell.first.second;
|
||||||
NetDeviceContainer apNetDev= cell.second.first;
|
NetDeviceContainer apNetDev= cell.second.first;
|
||||||
|
@ -69,7 +69,7 @@ void applyScenarios(Cell cell,int sensorsPktSize, int sensorsSendInterval, Cloud
|
||||||
// internet.Install (ap);
|
// internet.Install (ap);
|
||||||
internet.Install (sensors);
|
internet.Install (sensors);
|
||||||
Ipv4AddressHelper ipv4;
|
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;
|
Ipv4InterfaceContainer apInt,sensorsInt;
|
||||||
apInt=ipv4.Assign(apNetDev);
|
apInt=ipv4.Assign(apNetDev);
|
||||||
sensorsInt=ipv4.Assign(sensorsNetDev);
|
sensorsInt=ipv4.Assign(sensorsNetDev);
|
||||||
|
@ -85,22 +85,22 @@ void applyScenarios(Cell cell,int sensorsPktSize, int sensorsSendInterval, Cloud
|
||||||
echoClientHelper.Install (sensors);
|
echoClientHelper.Install (sensors);
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudInfos buildEdgeAndCloud(int nbOp){
|
|
||||||
|
|
||||||
NodeContainer OpNodes;
|
CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency){
|
||||||
OpNodes.Create(nbOp);
|
|
||||||
|
|
||||||
|
NodeContainer HopNodes;
|
||||||
|
HopNodes.Create(nbHop);
|
||||||
InternetStackHelper stack;
|
InternetStackHelper stack;
|
||||||
stack.Install(OpNodes);
|
stack.Install(HopNodes);
|
||||||
|
|
||||||
Ipv4Address cloudIP;
|
Ipv4Address cloudIP; // Will be fill in the following for loop
|
||||||
int cloudPort=99;
|
int cloudPort=80;
|
||||||
for(int i=0;i<nbOp-1;i++){
|
for(int i=0;i<nbHop-1;i++){
|
||||||
NodeContainer curNodes(OpNodes.Get(i),OpNodes.Get(i+1));
|
NodeContainer curNodes(HopNodes.Get(i),HopNodes.Get(i+1));
|
||||||
|
|
||||||
PointToPointHelper pointToPoint;
|
PointToPointHelper pointToPoint;
|
||||||
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
|
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ((std::to_string(bandwidth)+"Mbps").c_str()));
|
||||||
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
|
pointToPoint.SetChannelAttribute ("Delay", StringValue ((std::to_string(latency)+"ms").c_str()));
|
||||||
|
|
||||||
NetDeviceContainer p2pDevices;
|
NetDeviceContainer p2pDevices;
|
||||||
p2pDevices = pointToPoint.Install (curNodes);
|
p2pDevices = pointToPoint.Install (curNodes);
|
||||||
|
@ -110,7 +110,7 @@ CloudInfos buildEdgeAndCloud(int nbOp){
|
||||||
Ipv4InterfaceContainer p2pInterfaces;
|
Ipv4InterfaceContainer p2pInterfaces;
|
||||||
p2pInterfaces = address.Assign (p2pDevices);
|
p2pInterfaces = address.Assign (p2pDevices);
|
||||||
|
|
||||||
if(i==nbOp-2){ // If we are on the last FOR LOOP
|
if(i==nbHop-2){ // If we are on the last for loop (before last node)
|
||||||
cloudIP=p2pInterfaces.GetAddress (1); // Get Last node interface
|
cloudIP=p2pInterfaces.GetAddress (1); // Get Last node interface
|
||||||
PacketSinkHelper apSink("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), cloudPort));
|
PacketSinkHelper apSink("ns3::UdpSocketFactory",InetSocketAddress (Ipv4Address::GetAny (), cloudPort));
|
||||||
ApplicationContainer sinkApp=apSink.Install(curNodes.Get(1)); // Instal sink on last node
|
ApplicationContainer sinkApp=apSink.Install(curNodes.Get(1)); // Instal sink on last node
|
||||||
|
@ -119,6 +119,6 @@ CloudInfos buildEdgeAndCloud(int nbOp){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(std::make_pair(OpNodes,std::make_pair(cloudIP,cloudPort)));
|
return(std::make_pair(HopNodes,std::make_pair(cloudIP,cloudPort)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue