Add ECOFEN

This commit is contained in:
Loic Guegan 2019-04-12 16:05:29 +02:00
parent cb10ad2490
commit 32ccf612d0
7 changed files with 54 additions and 18 deletions

View file

@ -1,20 +1,25 @@
EXEC=simulator
##### NS3 g++ Arguments
NS3_ARGS= -D NS3_LOG_ENABLE -L ${NS3_PATH}/build/lib -I ${NS3_PATH}/build/
NS3_ARGS+=$(addprefix -l, $(subst lib,,$(subst .so,,$(notdir $(wildcard ${NS3_PATH}/build/lib/*.so)))))
##### Source Files
SRC=main.cc modules/platform.cc modules/energy.cc modules/callbacks.cc
EXEC=simulator
all: $(EXEC)
$(EXEC): $(SRC)
g++ $(NS3_ARGS) $(SRC) -o $@
run:
@LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${NS3_PATH}/build/lib ./wifi-test
export:
@echo export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${NS3_PATH}/build/lib
@echo -e "\e[32mDon't forget to define NS3_PATH env variable !\e[0m"
g++ $(NS3_ARGS) $(SRC) -o $@
@echo -e "\e[32mRun the following command before running $(EXEC):\e[0m"
@echo -e "\e[32mexport LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${NS3_PATH}/build/lib\e[0m"
clean:
- rm $(EXEC)
.PHONY: clean

View file

@ -12,23 +12,28 @@ int main(int argc, char* argv[]){
uint32_t sensorsPktSize=150;
uint32_t sensorsNumber=2;
uint32_t nbHop=5;
uint32_t linksBandwidth=5;
uint32_t linksLatency=2;
CommandLine cmd;
cmd.AddValue ("sensorsSendInterval", "Number of temperature measurement per second", sensorsFrequency);
cmd.AddValue ("sensorsPktSize", "Sensor measurements packet size (bytes)", sensorsPktSize);
cmd.AddValue ("sensorsNumber", "Number of sensors", sensorsNumber);
cmd.AddValue ("nbHop", "Number of hop between AP and Cloud sensors", sensorsNumber);
cmd.AddValue ("sensorsSendInterval", "Number of sensors measurement per second", sensorsFrequency);
cmd.AddValue ("sensorsPktSize", "Sensors packet size (bytes)", sensorsPktSize);
cmd.AddValue ("sensorsNumber", "Number of sensors connected to AP", sensorsNumber);
cmd.AddValue ("nbHop", "Number of hop between AP and Cloud", sensorsNumber);
cmd.AddValue ("linksBandwidth", "Links bandwidth between AP and Cloud", linksBandwidth);
cmd.AddValue ("linksLatency", "Links latency between AP and Cloud", linksLatency);
cmd.Parse (argc, argv);
//LogComponentEnable("UdpEchoClientApplication", LOG_LEVEL_INFO);
//LogComponentEnable("PacketSink", LOG_LEVEL_INFO);
// ---------- Setup Simulations ----------
CloudInfos cloud=createCloud(nbHop,5,2); // Create cloud P2P node chain o--o--o--o--o
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
setupScenario(cell,cloud,sensorsPktSize,sensorsFrequency); // Send data from Sensors to Cloud
setupCellEnergy(cell);
// Don't forget the following
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();

View file

@ -6,5 +6,5 @@ void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address
}
void EnergyUpdated(std::string nodeName,double oldValue, double newValue){
NS_LOG_UNCOND("Node " << nodeName << " consumes " << newValue << "J");
NS_LOG_UNCOND("Node " << nodeName << " consumes " << newValue-oldValue << "J");
}

View file

@ -46,6 +46,27 @@ void setupCellEnergy(Cell cell){
// NS_ASSERT (basicRadioModelPtr0 != NULL);
// basicRadioModelPtr0->TraceConnectWithoutContext ("TotalEnergyConsumption", MakeCallback (&TotalEnergy));
}
void setupCloudEnergy(CloudInfos cloudInfos){
NodeContainer cloudNodes=cloudInfos.first;
// Install basic energy
ns3::BasicNodeEnergyHelper basicNodeEnergy;
basicNodeEnergy.Set("OnConso", ns3::DoubleValue (0.0));
basicNodeEnergy.Set("OffConso", ns3::DoubleValue (0.0));
basicNodeEnergy.Install (cloudNodes);
ns3::CompleteNetdeviceEnergyHelper completeNetdeviceEnergy;
completeNetdeviceEnergy.Set ("OffConso", ns3::DoubleValue (0));
completeNetdeviceEnergy.Set ("IdleConso", ns3::DoubleValue (0));
completeNetdeviceEnergy.Set ("RecvByteEnergy", ns3::DoubleValue (10));
completeNetdeviceEnergy.Set ("SentByteEnergy", ns3::DoubleValue (10));
completeNetdeviceEnergy.Set ("RecvPktEnergy", ns3::DoubleValue (10));
completeNetdeviceEnergy.Set ("SentPktEnergy", ns3::DoubleValue (10));
completeNetdeviceEnergy.Install(cloudNodes);
ns3::ConsumptionLogger conso;
conso.NodeConso(ns3::Seconds (1), ns3::Seconds(10), cloudNodes);
}

View file

@ -24,6 +24,7 @@
#include "ns3/energy-module.h"
#include "ns3/wifi-radio-energy-model-helper.h"
#include "ns3/point-to-point-helper.h"
#include "ns3/ecofen-module.h"
// C++ library
#include <iostream> // Why not ?
@ -62,6 +63,10 @@ void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sen
* Configure WIFI energy module for cell
*/
void setupCellEnergy(Cell cell);
/*
* Configure link/port energy using ecofen
*/
void setupCloudEnergy(CloudInfos cloudInfos);
// ---------- callbacks.cc ----------

View file

@ -11,7 +11,7 @@ Cell createCell(uint32_t nbSensors, Ptr<ns3::Node> ap){
sensors.Create(nbSensors);
// Place nodes somehow, this is required by every wireless simulation
for (uint8_t i = 0; i < nbSensors; ++i)
for (uint32_t i = 0; i < nbSensors; i++)
{
sensors.Get (i)->AggregateObject (CreateObject<ConstantPositionMobilityModel> ());
}
@ -106,7 +106,7 @@ CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency){
p2pDevices = pointToPoint.Install (curNodes);
Ipv4AddressHelper address;
address.SetBase (("10.1."+std::to_string(i)+".0").c_str(), "255.255.255.0");
address.SetBase (("10."+std::to_string(i+1)+".0.0").c_str(), "255.255.0.0"); // Remember: 10.0.0.0 is used by WIFI
Ipv4InterfaceContainer p2pInterfaces;
p2pInterfaces = address.Assign (p2pDevices);

Binary file not shown.