Start some simulation tests

This commit is contained in:
Loic Guegan 2019-04-25 15:51:05 +02:00
parent 1399886f4d
commit a6e70544bb
37 changed files with 53416 additions and 5509 deletions

View file

@ -4,6 +4,7 @@ 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)))))
NS3_VERSION=$(shell cat ${NS3_PATH}/VERSION)
##### Source Files
SRC=main.cc modules/platform.cc modules/energy.cc modules/callbacks.cc
@ -11,10 +12,9 @@ SRC=main.cc modules/platform.cc modules/energy.cc modules/callbacks.cc
all: $(EXEC)
$(EXEC): $(SRC)
@echo -e "\e[32mDon't forget to define NS3_PATH env variable !\e[0m"
g++ $(NS3_ARGS) $(SRC) -o $@
g++ -D NS3_VERSION=${NS3_VERSION} $(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"

View file

@ -37,12 +37,28 @@ int main(int argc, char* argv[]){
// Don't forget the following
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
// Run Simulations
uint32_t nNode=ns3::NodeList::GetNNodes();
NS_LOG_UNCOND("Starting simulation with "<< nNode << " nodes");
Simulator::Stop (Seconds (20));
Simulator::Run ();
Simulator::Destroy ();
// Setup Logs
uint32_t nNode=ns3::NodeList::GetNNodes();
FlowMonitorHelper flowmon;
Ptr<FlowMonitor> monitor = flowmon.InstallAll();
Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
// Run Simulations
Simulator::Stop (Seconds (30));
Simulator::Run ();
// Print logs
NS_LOG_UNCOND("NS-3 Version " << NS3_VERSION);
NS_LOG_UNCOND("Simulation used "<< nNode << " nodes");
std::map<FlowId, FlowMonitor::FlowStats> stats = monitor->GetFlowStats ();
for (std::map< FlowId, FlowMonitor::FlowStats>::iterator flow=stats.begin(); flow!=stats.end(); flow++)
{
Ipv4FlowClassifier::FiveTuple t = classifier->FindFlow(flow->first);
NS_LOG_UNCOND("Flow " <<t.sourceAddress<< " -> "<< t.destinationAddress << " delay = " <<flow->second.delaySum.GetSeconds());
}
// Finish
Simulator::Destroy ();
return(0);
}

View file

@ -6,5 +6,11 @@ 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-oldValue << "J" << " at time " << Simulator::Now ().GetSeconds () << "s");
double currentTime=Simulator::Now ().GetSeconds ();
double energyConsumes=newValue-oldValue;
NS_LOG_UNCOND("Node " << nodeName << " consumes " << energyConsumes << "J" << " at time " << currentTime << "s");
NS_LOG_UNCOND("Node " << nodeName << " newVal " << newValue << "J" << " at time " << currentTime << "s");
NS_LOG_UNCOND("Node " << nodeName << " oldValue " << oldValue << "J" << " at time " << currentTime << "s");
}

View file

@ -26,6 +26,7 @@
#include "ns3/point-to-point-helper.h"
#include "ns3/ecofen-module.h"
#include "ns3/node-list.h"
#include "ns3/flow-monitor-module.h"
// C++ library
#include <iostream> // Why not ?
@ -33,11 +34,11 @@
#include <iomanip> // To use std::setw
// ECOFEN
#define ECOFEN_LOG_UNTIL 1
#define ECOFEN_LOG_UNTIL 100
#define ECOFEN_LOG_EVERY 0.1
// WIFI Energy Values
#define BASICENERGYSOURCEINITIALENERGYJ 1000
#define BASICENERGYSOURCEINITIALENERGYJ 2.9009
#define BASICENERGYSUPPLYVOLTAGEV 3.3
#define TXCURRENTA 0.38
#define RXCURRENTA 0.313