summaryrefslogtreecommitdiff
path: root/ns3-simulations/ns3-simulator
diff options
context:
space:
mode:
authorLoic Guegan <manzerberdes@gmx.com>2019-04-25 15:51:05 +0200
committerLoic Guegan <manzerberdes@gmx.com>2019-04-25 15:51:05 +0200
commita6e70544bb28c209891ea5335be0d2939f0737d6 (patch)
tree361f3989128bff0633fd956b00f10ce7ee629003 /ns3-simulations/ns3-simulator
parent1399886f4d56370d713ba3262b83df1df008d2a7 (diff)
Start some simulation tests
Diffstat (limited to 'ns3-simulations/ns3-simulator')
-rw-r--r--ns3-simulations/ns3-simulator/Makefile4
-rw-r--r--ns3-simulations/ns3-simulator/main.cc24
-rw-r--r--ns3-simulations/ns3-simulator/modules/callbacks.cc8
-rw-r--r--ns3-simulations/ns3-simulator/modules/modules.hpp5
-rwxr-xr-xns3-simulations/ns3-simulator/simulatorbin277424 -> 330504 bytes
5 files changed, 32 insertions, 9 deletions
diff --git a/ns3-simulations/ns3-simulator/Makefile b/ns3-simulations/ns3-simulator/Makefile
index d7bf341..a9cee83 100644
--- a/ns3-simulations/ns3-simulator/Makefile
+++ b/ns3-simulations/ns3-simulator/Makefile
@@ -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"
diff --git a/ns3-simulations/ns3-simulator/main.cc b/ns3-simulations/ns3-simulator/main.cc
index 7d9338c..f3800ca 100644
--- a/ns3-simulations/ns3-simulator/main.cc
+++ b/ns3-simulations/ns3-simulator/main.cc
@@ -37,12 +37,28 @@ int main(int argc, char* argv[]){
// Don't forget the following
Ipv4GlobalRoutingHelper::PopulateRoutingTables ();
- // Run Simulations
+
+ // Setup Logs
uint32_t nNode=ns3::NodeList::GetNNodes();
- NS_LOG_UNCOND("Starting simulation with "<< nNode << " nodes");
- Simulator::Stop (Seconds (20));
+ FlowMonitorHelper flowmon;
+ Ptr<FlowMonitor> monitor = flowmon.InstallAll();
+ Ptr<Ipv4FlowClassifier> classifier = DynamicCast<Ipv4FlowClassifier> (flowmon.GetClassifier ());
+
+ // Run Simulations
+ Simulator::Stop (Seconds (30));
Simulator::Run ();
- Simulator::Destroy ();
+ // 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);
}
diff --git a/ns3-simulations/ns3-simulator/modules/callbacks.cc b/ns3-simulations/ns3-simulator/modules/callbacks.cc
index ca04730..8e9e00f 100644
--- a/ns3-simulations/ns3-simulator/modules/callbacks.cc
+++ b/ns3-simulations/ns3-simulator/modules/callbacks.cc
@@ -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");
+
}
diff --git a/ns3-simulations/ns3-simulator/modules/modules.hpp b/ns3-simulations/ns3-simulator/modules/modules.hpp
index c47dc39..321926d 100644
--- a/ns3-simulations/ns3-simulator/modules/modules.hpp
+++ b/ns3-simulations/ns3-simulator/modules/modules.hpp
@@ -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
diff --git a/ns3-simulations/ns3-simulator/simulator b/ns3-simulations/ns3-simulator/simulator
index ecccc15..87c188e 100755
--- a/ns3-simulations/ns3-simulator/simulator
+++ b/ns3-simulations/ns3-simulator/simulator
Binary files differ