summaryrefslogtreecommitdiff
path: root/ns3-simulations/simulate.org
diff options
context:
space:
mode:
Diffstat (limited to 'ns3-simulations/simulate.org')
-rw-r--r--ns3-simulations/simulate.org220
1 files changed, 180 insertions, 40 deletions
diff --git a/ns3-simulations/simulate.org b/ns3-simulations/simulate.org
index 1f3a2af..30b4f14 100644
--- a/ns3-simulations/simulate.org
+++ b/ns3-simulations/simulate.org
@@ -2,35 +2,91 @@
* Run simulations
+ To run all the simulations, execute the following call:
+ #+NAME: runSim
+ #+CALL: runBW(lat=runLat(nbSens=runNbSensors(nbHop=runNbHop())))
+
+ #+RESULTS: runSim
+
** Experiments
+*** Bandwidth
+ #+NAME: runBW
+ #+BEGIN_SRC bash :noweb yes :results output
+ <<singleRun>>
+ simKey="BW"
+ sensorsNumber=10
+ for linksBandwidth in $(seq 10 20 100)
+ do
+ run
+ done
+ #+END_SRC
+
+ #+RESULTS: runBW
+
+ #+RESULTS:
+
+*** Latency
+ #+NAME: runLat
+ #+BEGIN_SRC bash :noweb yes :results output
+ <<singleRun>>
+ simKey="LATENCY"
+ sensorsNumber=10
+ for linksLatency in $(seq 1 1 10)
+ do
+ run
+ done
+ #+END_SRC
+
+ #+RESULTS: runLat
+
+ #+RESULTS:
+
*** Number of sensors
+ #+NAME: runNbSensors
#+BEGIN_SRC bash :noweb yes :results output
<<singleRun>>
- for sensorsNumber in $(seq 0 20)
+ simKey="NBSENSORS"
+ for sensorsNumber in $(seq 1 5)
do
run
- done
-
+ done
#+END_SRC
#+RESULTS:
+*** Number of Hop
+ #+NAME: runNbHop
+ #+BEGIN_SRC bash :noweb yes :results output
+ <<singleRun>>
+ simKey="NBHOP"
+ for nbHop in $(seq 1 10)
+ do
+ run
+ done
+ #+END_SRC
+
** Single Run
+
#+NAME: singleRun
- #+BEGIN_SRC bash :noweb yes
- simulator="ns3-simulator/simulator"
+ #+BEGIN_SRC bash :eval never :noweb yes :results output
+ simulator="simulator/simulator"
parseEnergyScript="./parseEnergy.awk"
parseDelayScript="./parseDelay.awk"
logFolder="logs/"
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${NS3_PATH}/build/lib
+
+ # Default Parameters
+ sensorsSendInterval=10
+ sensorsPktSize=5 # 1 byte temperature (-128 à +128 °C) and 4Byte sensorsId
+ sensorsNumber=10
+ nbHop=10 # Cf paper AC/Yunbo
+ linksBandwidth=10
+ linksLatency=2
+ simKey="NOKEY"
+
run () {
- [ -z ${sensorsSendInterval+x} ] && sensorsSendInterval=1
- [ -z ${sensorsPktSize+x} ] && sensorsPktSize=10
- [ -z ${sensorsNumber+x} ] && sensorsNumber=2
- [ -z ${nbHop+x} ] && nbHop=2
- [ -z ${linksBandwidth+x} ] && linksBandwidth=10
- [ -z ${linksLatency+x} ] && linksLatency=10
- logFile="${logFolder}/ns-3_${sensorsSendInterval}SSI_${sensorsPktSize}SPS_${sensorsNumber}SN_${nbHop}NH_${linksBandwidth}LB_${linksLatency}LL.org"
+ logFile="${logFolder}/${simKey}_${sensorsSendInterval}SSI_${sensorsPktSize}SPS_${sensorsNumber}SN_${nbHop}NH_${linksBandwidth}LB_${linksLatency}LL.org"
+ [ -f "$logFile" ] && return
simCMD="$simulator --sensorsSendInterval=${sensorsSendInterval} --sensorsPktSize=${sensorsPktSize} --sensorsNumber=${sensorsNumber} --nbHop=${nbHop} --linksBandwidth=${linksBandwidth} --linksLatency=${linksLatency} 2>&1"
log=$(bash -c "$simCMD")
@@ -53,19 +109,123 @@
echo "* Energy CSV (negative nodeId = WIFI, 0 = AP (Wireless+Wired), positive nodeId = ECOFEN" >> $logFile
echo "$energyLog" >> $logFile
echo "* Metrics" >> $logFile
- echo "-METRICSLINE- sensorsSendInterval:${sensorsSendInterval} sensorsPktSize:${sensorsPktSize} sensorsNumber:${sensorsNumber} nbHop:${nbHop} linksBandwidth:${linksBandwidth} linksLatency:${linksLatency} totalEnergy:$totalEnergy nbPacketCloud:$nbPacketCloud nbNodes:$nbNodes avgDelay:${avgDelay} ns3Version:${ns3Version}" >> $logFile
+ echo "-METRICSLINE- sensorsSendInterval:${sensorsSendInterval} sensorsPktSize:${sensorsPktSize} sensorsNumber:${sensorsNumber} nbHop:${nbHop} linksBandwidth:${linksBandwidth} linksLatency:${linksLatency} totalEnergy:$totalEnergy nbPacketCloud:$nbPacketCloud nbNodes:$nbNodes avgDelay:${avgDelay} ns3Version:${ns3Version} simKey:${simKey}" >> $logFile
}
+
+ #+END_SRC
+
+* Logs Analysis
+ To Generate all the plots, please execute the following line:
+ #+NAME: runAnalysis
+ #+CALL: plotToPDF(plots=genAllPlots(data=logToCSV()))
+
+ #+RESULTS: runAnalysis
+
+** R Scripts
+*** Generate all plots script
+ Available variables:
+ |---------------------|
+ | Name |
+ |---------------------|
+ | sensorsSendInterval |
+ | sensorsPktSize |
+ | sensorsNumber |
+ | nbHop |
+ | linksBandwidth |
+ | linksLatency |
+ | totalEnergy |
+ | nbPacketCloud |
+ | nbNodes |
+ | avgDelay |
+ | simKey |
+ |---------------------|
+
+ #+NAME: genAllPlots
+ #+BEGIN_SRC R :noweb yes :results output
+ <<RUtils>>
+ easyPlot("linksLatency","totalEnergy", "LATENCY")
+ easyPlot("linksBandwidth","totalEnergy", "BW")
+ easyPlot("sensorsNumber","totalEnergy", "NBSENSORS")
+ easyPlot("nbHop","totalEnergy", "NBHOP")
+ #+END_SRC
+
+*** R Utils
+ RUtils is intended to load logs (data.csv) and providing
+ simple plot function for them.
+
+ #+NAME: RUtils
+ #+BEGIN_SRC R :eval never
+ library("tidyverse")
+
+ # Fell free to update the following
+ labels=c(nbNodes="Number of nodes",nbSensors="Number of sensors",totalEnergy="Total Energy (J)",
+ nbHop="Number of hop (AP to Cloud)", linksBandwidth="Links Bandwidth (Mbps)",
+ linksLatency="Links Latency (ms)")
+
+ # Load Data
+ data=read_csv("logs/data.csv")
+
+ # Get label according to varName
+ getLabel=function(varName){
+ if(is.na(labels[varName])){
+ return(varName)
+ }
+ return(labels[varName])
+ }
+
+ easyPlot=function(X,Y,KEY){
+ curData=data%>%filter(simKey==KEY)
+ stopifnot(NROW(curData)>0)
+ ggplot(curData,aes_string(x=X,y=Y))+geom_point()+geom_line()+xlab(getLabel(X))+ylab(getLabel(Y))
+ ggsave(paste0("plots/",KEY,"-",X,"_",Y,".png"))
+ }
+ #+END_SRC
+
+** Plots -> PDF
+ Merge all plots in plots/ folder into a pdf file.
+ #+NAME: plotToPDF
+ #+BEGIN_SRC bash :results output :noweb yes
+ orgFile="plots/plots.org"
+ <<singleRun>> # To get all default arguments
+
+ # Write helper function
+ function write {
+ echo "$1" >> $orgFile
+ }
+
+ echo "#+TITLE: Analysis" > $orgFile
+ write "#+LATEX_HEADER: \usepackage{fullpage}"
+ write "#+OPTIONS: toc:nil"
+ # Default arguments
+ write '\begin{center}'
+ write '\begin{tabular}{lr}'
+ write 'Parameters & Values\\'
+ write '\hline'
+ write "sensorsPktSize & ${sensorsPktSize} bytes\\\\"
+ write "sensorsSendInterval & ${sensorsSendInterval}s\\\\"
+ write "sensorsNumber & ${sensorsNumber}\\\\"
+ write "nbHop & ${nbHop}\\\\"
+ write "linksBandwidth & ${linksBandwidth}Mbps\\\\"
+ write "linksLatency & ${linksLatency}ms\\\\"
+ write '\end{tabular}'
+ write '\newline'
+ write '\end{center}'
+
+ for plot in $(find plots/ -type f -name "*.png")
+ do
+ write "\includegraphics[width=0.5\linewidth]{$(basename ${plot})}"
+ done
+
+ # Export to pdf
+ emacs $orgFile --batch -f org-latex-export-to-pdf --kill
#+END_SRC
#+RESULTS:
- : Processing logs/logs/log.txt
- : Processing logs/logs/log.txt.csv-energy.csv
- : Processing logs/logs/log.txt.csv
- : Processing logs/logs/log.txt-energy.csv
-* Logs Analysis
-** Log -> CSV
+** Log -> CSV
+ logToCSV extract usefull data from logs and put them into logs/data.csv.
+
#+NAME: logToCSV
#+BEGIN_SRC bash :results none
csvOutput="logs/data.csv"
@@ -82,27 +242,7 @@
echo $metrics | awk '{for(i=1;i<=NF;i++){split($i,elem,":");printf(elem[2]);if(i<NF)printf(",");else{print("")}}}' >> $csvOutput
done
#+END_SRC
-** R Scripts
-*** Load Data
- #+NAME: loadData
- #+BEGIN_SRC R :var genLog=logToCSV()
- library("tidyverse")
-
-
- getLabel=function(varName){
- labels=c(nbNodes="Node Number",nbSensors="Sensor Number",totalEnergy="Total Energy (J)")
- if(is.na(labels[varName])){
- return(varName)
- }
- return(labels[varName])
- }
-
- # Load Data
- data=read_csv("logs/data.csv")
- ggplot(data,aes(x=nbNodes,y=totalEnergy))+geom_point()+geom_line()+xlab(getLabel("nbNodes"))+ylab(getLabel("totalEnergy"))
- ggsave("plot.png")
- #+END_SRC
-
+