diff options
| author | Loic Guegan <manzerberdes@gmx.com> | 2019-05-16 14:32:18 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerberdes@gmx.com> | 2019-05-16 14:32:18 +0200 |
| commit | 026a84902cdc22f64b53aea3678d576bc29f479b (patch) | |
| tree | 5b0cb6540533337c6c331f1333ac37979ad49ae4 /ns3-simulations/nix/simulator/modules | |
| parent | 9305e544d3c3b3ad49a47587616f2bde1dd8d323 (diff) | |
Update simulators
Diffstat (limited to 'ns3-simulations/nix/simulator/modules')
| -rw-r--r-- | ns3-simulations/nix/simulator/modules/#callbacks.cc# | 12 | ||||
| -rw-r--r-- | ns3-simulations/nix/simulator/modules/energy.cc | 22 | ||||
| -rw-r--r-- | ns3-simulations/nix/simulator/modules/modules.hpp | 12 | ||||
| -rw-r--r-- | ns3-simulations/nix/simulator/modules/platform.cc | 33 |
4 files changed, 53 insertions, 26 deletions
diff --git a/ns3-simulations/nix/simulator/modules/#callbacks.cc# b/ns3-simulations/nix/simulator/modules/#callbacks.cc# new file mode 100644 index 0000000..d68e82c --- /dev/null +++ b/ns3-simulations/nix/simulator/modules/#callbacks.cc# @@ -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"); +} diff --git a/ns3-simulations/nix/simulator/modules/energy.cc b/ns3-simulations/nix/simulator/modules/energy.cc index c8cca6a..56c38e5 100644 --- a/ns3-simulations/nix/simulator/modules/energy.cc +++ b/ns3-simulations/nix/simulator/modules/energy.cc @@ -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){ diff --git a/ns3-simulations/nix/simulator/modules/modules.hpp b/ns3-simulations/nix/simulator/modules/modules.hpp index b537e92..e1f197d 100644 --- a/ns3-simulations/nix/simulator/modules/modules.hpp +++ b/ns3-simulations/nix/simulator/modules/modules.hpp @@ -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 */ diff --git a/ns3-simulations/nix/simulator/modules/platform.cc b/ns3-simulations/nix/simulator/modules/platform.cc index 52f91b0..7cfc2b9 100644 --- a/ns3-simulations/nix/simulator/modules/platform.cc +++ b/ns3-simulations/nix/simulator/modules/platform.cc @@ -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)); + } } |
