mirror of
https://gitlab.com/manzerbredes/paper-lowrate-iot.git
synced 2025-06-07 23:27:39 +00:00
Update simulators
This commit is contained in:
parent
9305e544d3
commit
026a84902c
505 changed files with 3375873 additions and 5912458 deletions
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue