summaryrefslogtreecommitdiff
path: root/src/ns3/nix/simulator/modules/energy.cc
diff options
context:
space:
mode:
authorLoic Guegan <manzerberdes@gmx.com>2019-05-22 11:24:17 +0200
committerLoic Guegan <manzerberdes@gmx.com>2019-05-22 11:24:17 +0200
commit8bdcd37ac44fe96d2c59424a24752f87f0444e36 (patch)
treee31a0fe38c01bc6814a0b35474875fe538ea87c2 /src/ns3/nix/simulator/modules/energy.cc
parent5a77b67d6baae0414310d29cab6f240963866062 (diff)
Update paper
Diffstat (limited to 'src/ns3/nix/simulator/modules/energy.cc')
-rw-r--r--src/ns3/nix/simulator/modules/energy.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/ns3/nix/simulator/modules/energy.cc b/src/ns3/nix/simulator/modules/energy.cc
new file mode 100644
index 0000000..56c38e5
--- /dev/null
+++ b/src/ns3/nix/simulator/modules/energy.cc
@@ -0,0 +1,68 @@
+
+#include "modules.hpp"
+
+DeviceEnergyModelContainer setupCellEnergy(Cell cell){
+ NodeContainer nodes(cell.first.first,cell.first.second);
+ NetDeviceContainer nodesNetDev(cell.second.first,cell.second.second);
+
+ // Install energy source
+ BasicEnergySourceHelper edgeBasicSourceHelper;
+ edgeBasicSourceHelper.Set ("BasicEnergySourceInitialEnergyJ", DoubleValue (BASICENERGYSOURCEINITIALENERGYJ));
+ edgeBasicSourceHelper.Set ("BasicEnergySupplyVoltageV", DoubleValue (BASICENERGYSUPPLYVOLTAGEV));
+ EnergySourceContainer apEdgeNodesSources = edgeBasicSourceHelper.Install (cell.first.first);
+ EnergySourceContainer wifiEdgeNodesSources = edgeBasicSourceHelper.Install (cell.first.second);
+
+ // Install device energy model
+ WifiRadioEnergyModelHelper radioEnergyHelper;
+ radioEnergyHelper.Set ("TxCurrentA", DoubleValue (TXCURRENTA));
+ radioEnergyHelper.Set ("RxCurrentA", DoubleValue (RXCURRENTA));
+ radioEnergyHelper.Set ("IdleCurrentA", DoubleValue (IDLECURRENTA));
+ DeviceEnergyModelContainer edgeApDeviceModels = radioEnergyHelper.Install (cell.second.first, apEdgeNodesSources);
+ DeviceEnergyModelContainer edgeDeviceModels = radioEnergyHelper.Install (cell.second.second, wifiEdgeNodesSources);
+
+
+ // Trace
+ // 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));
+
+ // Ptr<BasicEnergySource> basicSourcePtr0 = DynamicCast<BasicEnergySource> (wifiEdgeNodesSources.Get (0));
+ // //basicSourcePtr0->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy));
+ // //device energy model
+ // Ptr<DeviceEnergyModel> basicRadioModelPtr0 =
+ // basicSourcePtr0->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0);
+ // NS_ASSERT (basicRadioModelPtr0 != NULL);
+ // basicRadioModelPtr0->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));
+ return(DeviceEnergyModelContainer(edgeApDeviceModels,edgeDeviceModels));
+}
+
+void setupCloudEnergy(CloudInfos cloudInfos){
+ NodeContainer cloudNodes=cloudInfos.first;
+
+ // Install basic energy
+ ns3::BasicNodeEnergyHelper basicNodeEnergy;
+ basicNodeEnergy.Set("OnConso", ns3::DoubleValue (ONCONSO));
+ basicNodeEnergy.Set("OffConso", ns3::DoubleValue (OFFCONSO));
+ basicNodeEnergy.Install (cloudNodes);
+
+ ns3::CompleteNetdeviceEnergyHelper completeNetdeviceEnergy;
+ completeNetdeviceEnergy.Set ("OffConso", ns3::DoubleValue (OFFCONSO));
+ completeNetdeviceEnergy.Set ("IdleConso", ns3::DoubleValue (IDLECONSO));
+ completeNetdeviceEnergy.Set ("RecvByteEnergy", ns3::DoubleValue (RECVBYTEENERGY));
+ completeNetdeviceEnergy.Set ("SentByteEnergy", ns3::DoubleValue (SENTBYTEENERGY));
+ completeNetdeviceEnergy.Set ("RecvPktEnergy", ns3::DoubleValue (RECVPKTENERGY));
+ completeNetdeviceEnergy.Set ("SentPktEnergy", ns3::DoubleValue (SENTPKTENERGY));
+ completeNetdeviceEnergy.Install(cloudNodes);
+
+ ns3::ConsumptionLogger conso;
+ conso.NodeConso(ns3::Seconds (ECOFEN_LOG_EVERY), ns3::Seconds(SIM_TIME), cloudNodes);
+}
+