mirror of
https://gitlab.com/manzerbredes/paper-lowrate-iot.git
synced 2025-06-07 15:17:40 +00:00
Update simulators
This commit is contained in:
parent
9305e544d3
commit
026a84902c
505 changed files with 3375873 additions and 5912458 deletions
8
ns3-simulations/nix/simulator/before.txt
Normal file
8
ns3-simulations/nix/simulator/before.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
nodeId,energy
|
||||
-1,8.9274
|
||||
-2,8.9274
|
||||
0,18.932
|
||||
1,20
|
||||
2,20
|
||||
3,20
|
||||
4,10
|
1126
ns3-simulations/nix/simulator/log
Normal file
1126
ns3-simulations/nix/simulator/log
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,7 @@
|
|||
#include "modules/modules.hpp"
|
||||
#ifndef NS3_VERSION
|
||||
#define NS3_VERSION "unknown"
|
||||
#endif
|
||||
|
||||
NS_LOG_COMPONENT_DEFINE ("WIFISensorsSimulator");
|
||||
|
||||
|
@ -14,6 +17,7 @@ int main(int argc, char* argv[]){
|
|||
uint32_t nbHop=5;
|
||||
uint32_t linksBandwidth=5;
|
||||
uint32_t linksLatency=2;
|
||||
uint32_t positionSeed=5;
|
||||
|
||||
CommandLine cmd;
|
||||
cmd.AddValue ("sensorsSendInterval", "Number of sensors measurement per second", sensorsFrequency);
|
||||
|
@ -22,22 +26,28 @@ int main(int argc, char* argv[]){
|
|||
cmd.AddValue ("nbHop", "Number of hop between AP and Cloud", nbHop);
|
||||
cmd.AddValue ("linksBandwidth", "Links bandwidth between AP and Cloud", linksBandwidth);
|
||||
cmd.AddValue ("linksLatency", "Links latency between AP and Cloud", linksLatency);
|
||||
cmd.AddValue ("positionSeed", "RandomRectangle Sensors placement seed", positionSeed);
|
||||
cmd.Parse (argc, argv);
|
||||
|
||||
// Check sensors frequency
|
||||
if(sensorsFrequency<1){
|
||||
NS_LOG_UNCOND("SensorsSendInterval too small: " << sensorsFrequency << " (it should be >1)." );
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//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
|
||||
Cell cell=createCell(sensorsNumber,cloud.first.Get(0),positionSeed); // Use first cloud node as Access Point
|
||||
setupScenario(cell,cloud,sensorsPktSize,sensorsFrequency); // Send data from Sensors to Cloud
|
||||
setupCellEnergy(cell);
|
||||
DeviceEnergyModelContainer wifi=setupCellEnergy(cell);
|
||||
|
||||
// Don't forget the following
|
||||
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
|
||||
|
||||
|
||||
// Setup Logs
|
||||
uint32_t nNode=ns3::NodeList::GetNNodes();
|
||||
FlowMonitorHelper flowmon;
|
||||
|
@ -58,6 +68,17 @@ int main(int argc, char* argv[]){
|
|||
NS_LOG_UNCOND("Flow " <<t.sourceAddress<< " -> "<< t.destinationAddress << " delay = " <<flow->second.delaySum.GetSeconds());
|
||||
}
|
||||
|
||||
|
||||
// Trace
|
||||
DeviceEnergyModelContainer::Iterator it=wifi.Begin();
|
||||
int i=0; // Note that node 0 is the AP
|
||||
while(it!=wifi.End()){
|
||||
NS_LOG_UNCOND ("Node " << i << " consumes " <<(*it)->GetTotalEnergyConsumption());
|
||||
it++;
|
||||
i--; // Edge device will have id < 0 and ap will have id 0
|
||||
}
|
||||
|
||||
|
||||
// Finish
|
||||
Simulator::Destroy ();
|
||||
return(0);
|
||||
|
|
12
ns3-simulations/nix/simulator/modules/#callbacks.cc#
Normal file
12
ns3-simulations/nix/simulator/modules/#callbacks.cc#
Normal file
|
@ -0,0 +1,12 @@
|
|||
|
||||
#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){
|
||||
double currentTime=Simulator::Now ().GetSeconds ();
|
||||
:q! double energyConsumes=newValue-oldValue;
|
||||
NS_LOG_UNCOND("Node " << nodeName << " consumes " << energyConsumes << "J" << " at time " << currentTime << "s");
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
#include "modules.hpp"
|
||||
|
||||
void setupCellEnergy(Cell cell){
|
||||
DeviceEnergyModelContainer setupCellEnergy(Cell cell){
|
||||
NodeContainer nodes(cell.first.first,cell.first.second);
|
||||
NetDeviceContainer nodesNetDev(cell.second.first,cell.second.second);
|
||||
|
||||
|
@ -22,17 +22,17 @@ void setupCellEnergy(Cell cell){
|
|||
|
||||
|
||||
// Trace
|
||||
DeviceEnergyModelContainer::Iterator it=edgeDeviceModels.Begin();
|
||||
int i=1; // Node 0 will be AP, other node will have negative id (cf following while)
|
||||
// DeviceEnergyModelContainer::Iterator it=edgeDeviceModels.Begin();
|
||||
//int i=1; // Node 0 will be AP, other node will have negative id (cf following while)
|
||||
// This is usefull in logs, in fact ECOFEN nodes will have positive ID and WIFI energy nodes negative id
|
||||
// AP will have id 0 in ECOFEN and WIFI (in order to combine their energy value when parsing logs
|
||||
while(it!=edgeDeviceModels.End()){
|
||||
(*it)->TraceConnect ("TotalEnergyConsumption", std::to_string(0-i),MakeCallback (&EnergyUpdated));
|
||||
it++;
|
||||
i++;
|
||||
}
|
||||
// AP will have id 0
|
||||
(*edgeApDeviceModels.Begin())->TraceConnect ("TotalEnergyConsumption", std::to_string(0),MakeCallback (&EnergyUpdated));
|
||||
// while(it!=edgeDeviceModels.End()){
|
||||
// (*it)->TraceConnect ("TotalEnergyConsumption", std::to_string(0-i),MakeCallback (&EnergyUpdated));
|
||||
// it++;
|
||||
// i++;
|
||||
// }
|
||||
// // AP will have id 0
|
||||
// (*edgeApDeviceModels.Begin())->TraceConnect ("TotalEnergyConsumption", std::to_string(0),MakeCallback (&EnergyUpdated));
|
||||
|
||||
// Ptr<BasicEnergySource> basicSourcePtr0 = DynamicCast<BasicEnergySource> (wifiEdgeNodesSources.Get (0));
|
||||
// //basicSourcePtr0->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy));
|
||||
|
@ -41,7 +41,7 @@ void setupCellEnergy(Cell cell){
|
|||
// basicSourcePtr0->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
|
||||
// NS_ASSERT (basicRadioModelPtr0 != NULL);
|
||||
// basicRadioModelPtr0->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));
|
||||
|
||||
return(DeviceEnergyModelContainer(edgeApDeviceModels,edgeDeviceModels));
|
||||
}
|
||||
|
||||
void setupCloudEnergy(CloudInfos cloudInfos){
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
|
||||
#ifndef MODULES_HPP
|
||||
#define MODULES_HPP
|
||||
|
||||
|
@ -33,13 +32,15 @@
|
|||
#include <utility> // To use std::pair
|
||||
#include <iomanip> // To use std::setw
|
||||
|
||||
#define SIM_TIME 60
|
||||
#define SIM_TIME 60 // 30mins simulations
|
||||
#define RECT_SIZE 10 // Sensors random rectangle position size
|
||||
#define MAX_PACKET_BY_SENSOR 900000 // Reasonable big number (in order that simulation end before sensors stop sending packets)
|
||||
|
||||
// ECOFEN
|
||||
#define ECOFEN_LOG_EVERY 0.5
|
||||
|
||||
// WIFI Energy Values
|
||||
#define BASICENERGYSOURCEINITIALENERGYJ 10000
|
||||
#define BASICENERGYSOURCEINITIALENERGYJ 10000000
|
||||
#define BASICENERGYSUPPLYVOLTAGEV 3.3
|
||||
#define TXCURRENTA 0.38
|
||||
#define RXCURRENTA 0.313
|
||||
|
@ -68,7 +69,8 @@ typedef std::pair<NodeContainer,EndPoint> CloudInfos; // Format (CloudHops,Cloud
|
|||
/**
|
||||
* 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,int positionSeed);
|
||||
|
||||
/**
|
||||
* Build P2P network composed of nbHop hops (to simulate edge->cloud communications)
|
||||
* Note: Cloud Servers are not considered here and completely ignored !
|
||||
|
@ -85,7 +87,7 @@ void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sen
|
|||
/*
|
||||
* Configure WIFI energy module for cell
|
||||
*/
|
||||
void setupCellEnergy(Cell cell);
|
||||
DeviceEnergyModelContainer setupCellEnergy(Cell cell);
|
||||
/*
|
||||
* Configure link/port energy using ecofen
|
||||
*/
|
||||
|
|
|
@ -1,21 +1,32 @@
|
|||
#include "modules.hpp"
|
||||
#include "ns3/pointer.h"
|
||||
|
||||
/**
|
||||
* 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){
|
||||
Cell createCell(uint32_t nbSensors, Ptr<ns3::Node> ap,int positionSeed){
|
||||
// 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> ());
|
||||
|
||||
// Define sensors position/mobility
|
||||
MobilityHelper mobility;
|
||||
mobility.SetMobilityModel ("ns3::ConstantPositionMobilityModel"); // Sensors are fixed
|
||||
Ptr<UniformRandomVariable> X = CreateObject<UniformRandomVariable> ();
|
||||
X->SetAttribute ("Min", DoubleValue (0));
|
||||
X->SetAttribute ("Max", DoubleValue (RECT_SIZE));
|
||||
X->SetAttribute("Stream",IntegerValue(positionSeed));
|
||||
Ptr<UniformRandomVariable> Y = CreateObject<UniformRandomVariable> ();
|
||||
Y->SetAttribute ("Min", DoubleValue (0));
|
||||
Y->SetAttribute ("Max", DoubleValue (RECT_SIZE));
|
||||
Y->SetAttribute("Stream",IntegerValue(positionSeed+1));
|
||||
mobility.SetPositionAllocator("ns3::RandomRectanglePositionAllocator",
|
||||
"X",PointerValue(X),
|
||||
"Y",PointerValue(Y));
|
||||
mobility.Install(NodeContainer(ap,sensors));
|
||||
|
||||
// To apply XXWifiPhy and WifiMac on sensors
|
||||
WifiHelper wifiHelper;
|
||||
|
@ -75,14 +86,16 @@ void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sen
|
|||
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));
|
||||
echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (MAX_PACKET_BY_SENSOR));
|
||||
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);
|
||||
for(int i=0;i<sensors.GetN();i++){
|
||||
echoClientHelper.SetAttribute ("StartTime", TimeValue (MilliSeconds (1+i)));
|
||||
echoClientHelper.Install (sensors.Get(i));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
BIN
ns3-simulations/nix/simulator/simulator
Executable file
BIN
ns3-simulations/nix/simulator/simulator
Executable file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue