From f6d01996eb72fc71681efd4aacd8d8cb903be753 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sat, 4 May 2019 10:32:19 +0200 Subject: Nix integration --- 2019-Mascots.org | 13 +- 2019-Mascots.pdf | Bin 52266 -> 61359 bytes 2019-Mascots.tex | 47 ++-- ns3-simulations/g5k-root.sh | 309 +++++++++++++++++++++ ns3-simulations/g5k-worker.sh | 68 +++++ ns3-simulations/nix/default.nix | 5 + ns3-simulations/nix/ns3/default.nix | 36 +++ ns3-simulations/nix/result | 1 + ns3-simulations/nix/result-2 | 1 + ns3-simulations/nix/simulator/default.nix | 18 ++ ns3-simulations/nix/simulator/src/Makefile | 26 ++ ns3-simulations/nix/simulator/src/main.cc | 64 +++++ .../nix/simulator/src/modules/callbacks.cc | 12 + .../nix/simulator/src/modules/energy.cc | 68 +++++ .../nix/simulator/src/modules/modules.hpp | 101 +++++++ .../nix/simulator/src/modules/platform.cc | 124 +++++++++ ns3-simulations/simulate.org | 131 +++++++++ ns3-simulations/simulator/Makefile | 25 -- ns3-simulations/simulator/main.cc | 64 ----- ns3-simulations/simulator/modules/callbacks.cc | 12 - ns3-simulations/simulator/modules/energy.cc | 68 ----- ns3-simulations/simulator/modules/modules.hpp | 101 ------- ns3-simulations/simulator/modules/platform.cc | 124 --------- ns3-simulations/simulator/simulator | Bin 330504 -> 0 bytes 24 files changed, 1005 insertions(+), 413 deletions(-) create mode 100755 ns3-simulations/g5k-root.sh create mode 100755 ns3-simulations/g5k-worker.sh create mode 100644 ns3-simulations/nix/default.nix create mode 100644 ns3-simulations/nix/ns3/default.nix create mode 120000 ns3-simulations/nix/result create mode 120000 ns3-simulations/nix/result-2 create mode 100644 ns3-simulations/nix/simulator/default.nix create mode 100644 ns3-simulations/nix/simulator/src/Makefile create mode 100644 ns3-simulations/nix/simulator/src/main.cc create mode 100644 ns3-simulations/nix/simulator/src/modules/callbacks.cc create mode 100644 ns3-simulations/nix/simulator/src/modules/energy.cc create mode 100644 ns3-simulations/nix/simulator/src/modules/modules.hpp create mode 100644 ns3-simulations/nix/simulator/src/modules/platform.cc delete mode 100644 ns3-simulations/simulator/Makefile delete mode 100644 ns3-simulations/simulator/main.cc delete mode 100644 ns3-simulations/simulator/modules/callbacks.cc delete mode 100644 ns3-simulations/simulator/modules/energy.cc delete mode 100644 ns3-simulations/simulator/modules/modules.hpp delete mode 100644 ns3-simulations/simulator/modules/platform.cc delete mode 100755 ns3-simulations/simulator/simulator diff --git a/2019-Mascots.org b/2019-Mascots.org index 534c47d..cb27d17 100644 --- a/2019-Mascots.org +++ b/2019-Mascots.org @@ -39,11 +39,22 @@ component, formatting, style, styling, insert ** Cloud Infrastructure * System Model ** IoT Part + The IoT part is composed of an Access Point (AP), connected to several sensors using WIFI. In the + system, the IoT part is considered as the part where the system data are created. In fact, the + data life cycle start when the sensors records their respectives local temperature at a frequency + $f$ and the local timestamp. Then, these data are transmitted through the network along with an + arbitrary sensor id of 128 bits. Finally, the AP is in charge to transmit the data to the cloud + using the network part. + ** Network Part + The network part is considered as the medium that link the IoT part to the cloud. It is composed + of several network switches and router and it is considered to be a wired network. + + ** Cloud Part * Evaluation ** IoT/Network Consumption -** Cloud Consmption +** Cloud Energy Consumption ** Virtual Machine Size Impact ** Application Accuracy Refresh frequency etc... diff --git a/2019-Mascots.pdf b/2019-Mascots.pdf index fbde41d..2508d2b 100644 Binary files a/2019-Mascots.pdf and b/2019-Mascots.pdf differ diff --git a/2019-Mascots.tex b/2019-Mascots.tex index cd9243b..80d8f8b 100644 --- a/2019-Mascots.tex +++ b/2019-Mascots.tex @@ -36,38 +36,49 @@ component, formatting, style, styling, insert \section{Introduction} -\label{sec:org9f2a447} +\label{sec:org9428352} \section{Related Work} -\label{sec:org3f89763} +\label{sec:orga22ca2a} \section{Use-Case} -\label{sec:org465840a} +\label{sec:org3241664} \subsection{Application Characteristic} -\label{sec:orgec764c1} +\label{sec:org8ebb00c} \subsection{Cloud Infrastructure} -\label{sec:orgd297b7a} +\label{sec:org17d08e8} \section{System Model} -\label{sec:orgb795527} +\label{sec:org2051e46} \subsection{IoT Part} -\label{sec:org2cfffb6} +\label{sec:org9fc7024} +The IoT part is composed of an Access Point (AP), connected to several sensors using WIFI. In the +system, the IoT part is considered as the part where the system data are created. In fact, the +data life cycle start when the sensors records their respectives local temperature at a frequency +\(f\) and the local timestamp. Then, these data are transmitted through the network along with an +arbitrary sensor id of 128 bits. Finally, the AP is in charge to transmit the data to the cloud +using the network part. + \subsection{Network Part} -\label{sec:orgc144d77} +\label{sec:orgb1e4614} +The network part is considered as the medium that link the IoT part to the cloud. It is composed +of several network switches and router and it is mostly considered as wired network. + + \subsection{Cloud Part} -\label{sec:org39e083c} +\label{sec:org4dad506} \section{Evaluation} -\label{sec:org0d3d97d} +\label{sec:org373c2b1} \subsection{IoT/Network Consumption} -\label{sec:orgcb0df05} -\subsection{Cloud Consmption} -\label{sec:org4ed126a} +\label{sec:org993439d} +\subsection{Cloud Energy Consumption} +\label{sec:org7ae8276} \subsection{Virtual Machine Size Impact} -\label{sec:org9aec0d5} +\label{sec:orgde03152} \subsection{Application Accuracy} -\label{sec:org88409a4} +\label{sec:org79ddac3} Refresh frequency etc\ldots{} \subsection{End-To-End Consumption} -\label{sec:org1492f49} +\label{sec:org275997a} \section{Discussion} -\label{sec:org6627b27} +\label{sec:org25eaadf} \section{Conclusion} -\label{sec:org0643947} +\label{sec:orgff11457} \end{document} diff --git a/ns3-simulations/g5k-root.sh b/ns3-simulations/g5k-root.sh new file mode 100755 index 0000000..0ec56b2 --- /dev/null +++ b/ns3-simulations/g5k-root.sh @@ -0,0 +1,309 @@ +#!/bin/bash +##### Arguments ##### +nHost=15 +nProcesses=8 # Max number of parrallel simulations +nHours=3 # Reservation duration +simArgsLoc=~/args/ # Don't change this path witouth changing it in workder scripts +finishedFile="$simArgsLoc/finished-microBenchmarks.txt" +logsFinalDst=~/logs/ +##################### + +# Check +[ "$1" == "subscribe" ] && subscribe=1 ||subscribe=0 +[ "$1" == "deploy" ] && deploy=1 || deploy=0 +[ "$1" == "-p" ] && progress=1 || progress=0 + + + +handleSim () { + outF="$simArgsLoc/$(uuidgen).sh" # Args file based on host name (avoid conflict) + + # Add Shebang + echo '#!/bin/bash' > $outF + echo "finishedFile=\"$finishedFile\"" >> $outF + echo "nProcesses=$nProcesses" >> $outF + echo "logsFinalDst=\"$logsFinalDst\"" >> $outF + # Save arguments + echo "sensorsSendInterval=${sensorsSendInterval}" >> $outF + echo "sensorsPktSize=${sensorsPktSize}" >> $outF + echo "nbHop=${nbHop}" >> $outF + echo "simKey=\"${simKey}\"" >> $outF + echo "sensorsNumber=${sensorsNumber}" >> $outF + echo "linksLatency=${linksLatency}" >> $outF + echo "sensorsNumber=${sensorsNumber}" >> $outF + echo "linksBandwidth=${linksBandwidth}" >> $outF +} + + +# Start subscribe/deploy +if [ $subscribe -eq 1 ] +then + echo "Starting oarsub..." + oarsub -l host=$nHost,walltime=$nHours 'sleep "10d"' # Start reservation + echo "Please join your node manually when your reservation is ready by using oarsub -C " + exit 0 +elif [ $deploy -eq 1 ] +then + echo "Starting deployment..." + + ##### Usefull Variables ##### + wai=$(dirname "$(readlink -f $0)") # Where Am I ? + hostList=($(cat $OAR_NODE_FILE | uniq)) + ############################# + + # Initialize logsFinalDst + mkdir -p $logsFinalDst + rm -rf $logsFinalDst/* # Clean log dst just in case (it is dangerous but avoid conflict) + mkdir -p $simArgsLoc + rm -rf $simArgsLoc/* # Clean old args + + # Add your simulation code block here + 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 () { + # If another function want to handle simulation (tipically used on g5k) + type -t handleSim > /dev/null && { handleSim; return; } + + 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") + + # Compute some metrics + energyLog=$(echo "$log" | $parseEnergyScript) + avgDelay=$(echo "$log" | $parseDelayScript) + totalEnergy=$(echo "$energyLog"| awk 'BEGIN{power=0;FS=","}NR!=1{power+=$2}END{print(power)}') + nbPacketCloud=$(echo "$log"|grep -c "CloudSwitch receive") + nbNodes=$(echo "$log"|awk '/Simulation used/{print($3)}') + ns3Version=$(echo "$log"|awk '/NS-3 Version/{print($3)}') + + # Save logs + echo -e "#+TITLE: $(date) ns-3 (version ${ns3Version}) simulation\n" > $logFile + echo "* Environment Variables" >> $logFile + env >> $logFile + echo "* Full Command" >> $logFile + echo "$simCMD" >> $logFile + echo "* Output" >> $logFile + echo "$log" >> $logFile + 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} simKey:${simKey}" >> $logFile + + } + + simKey="NBHOP" + for sensorsNumber in $(seq 1 15) + do + for nbHop in $(seq 1 10) + do + run + done + done + 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 () { + # If another function want to handle simulation (tipically used on g5k) + type -t handleSim > /dev/null && { handleSim; return; } + + 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") + + # Compute some metrics + energyLog=$(echo "$log" | $parseEnergyScript) + avgDelay=$(echo "$log" | $parseDelayScript) + totalEnergy=$(echo "$energyLog"| awk 'BEGIN{power=0;FS=","}NR!=1{power+=$2}END{print(power)}') + nbPacketCloud=$(echo "$log"|grep -c "CloudSwitch receive") + nbNodes=$(echo "$log"|awk '/Simulation used/{print($3)}') + ns3Version=$(echo "$log"|awk '/NS-3 Version/{print($3)}') + + # Save logs + echo -e "#+TITLE: $(date) ns-3 (version ${ns3Version}) simulation\n" > $logFile + echo "* Environment Variables" >> $logFile + env >> $logFile + echo "* Full Command" >> $logFile + echo "$simCMD" >> $logFile + echo "* Output" >> $logFile + echo "$log" >> $logFile + 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} simKey:${simKey}" >> $logFile + + } + + simKey="BW" + for sensorsNumber in $(seq 1 15) + do + for linksBandwidth in $(seq 10 20 100) + do + run + done + done + 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 () { + # If another function want to handle simulation (tipically used on g5k) + type -t handleSim > /dev/null && { handleSim; return; } + + 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") + + # Compute some metrics + energyLog=$(echo "$log" | $parseEnergyScript) + avgDelay=$(echo "$log" | $parseDelayScript) + totalEnergy=$(echo "$energyLog"| awk 'BEGIN{power=0;FS=","}NR!=1{power+=$2}END{print(power)}') + nbPacketCloud=$(echo "$log"|grep -c "CloudSwitch receive") + nbNodes=$(echo "$log"|awk '/Simulation used/{print($3)}') + ns3Version=$(echo "$log"|awk '/NS-3 Version/{print($3)}') + + # Save logs + echo -e "#+TITLE: $(date) ns-3 (version ${ns3Version}) simulation\n" > $logFile + echo "* Environment Variables" >> $logFile + env >> $logFile + echo "* Full Command" >> $logFile + echo "$simCMD" >> $logFile + echo "* Output" >> $logFile + echo "$log" >> $logFile + 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} simKey:${simKey}" >> $logFile + + } + + simKey="LATENCY" + for sensorsNumber in $(seq 1 15) + do + for linksLatency in $(seq 1 1 10) + do + run + done + done + + 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 () { + # If another function want to handle simulation (tipically used on g5k) + type -t handleSim > /dev/null && { handleSim; return; } + + 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") + + # Compute some metrics + energyLog=$(echo "$log" | $parseEnergyScript) + avgDelay=$(echo "$log" | $parseDelayScript) + totalEnergy=$(echo "$energyLog"| awk 'BEGIN{power=0;FS=","}NR!=1{power+=$2}END{print(power)}') + nbPacketCloud=$(echo "$log"|grep -c "CloudSwitch receive") + nbNodes=$(echo "$log"|awk '/Simulation used/{print($3)}') + ns3Version=$(echo "$log"|awk '/NS-3 Version/{print($3)}') + + # Save logs + echo -e "#+TITLE: $(date) ns-3 (version ${ns3Version}) simulation\n" > $logFile + echo "* Environment Variables" >> $logFile + env >> $logFile + echo "* Full Command" >> $logFile + echo "$simCMD" >> $logFile + echo "* Output" >> $logFile + echo "$log" >> $logFile + 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} simKey:${simKey}" >> $logFile + + } + + simKey="NBSENSORS" + for sensorsNumber in $(seq 1 5) + do + run + done + + # Distribute argument according to subsribed nodes + cd $simArgsLoc + curHostId=0 + for file in $(find ./ -type f) + do + [ $curHostId -eq $nHost ] && curHostId=0 + mv -- ${file} ${hostList[$curHostId]}-$(basename ${file}) + curHostId=$(( curHostId + 1 )) + done + cd - + + + # Run simulations + echo "Host who finished their work:" > $finishedFile + for host in ${hostList[@]} + do + #oarsh lguegan@$host bash g5k-worker.sh & + echo "$host" + done + + exit 0 +elif [ $progress -eq 1 ] +then + alreadyFinished=$(cat $finishedFile| tail -n +2| wc -l) + percent=$(echo $alreadyFinished $nHost| awk '{print $1/$2*100}') + echo "Progression: " $alreadyFinished/$nHost "(${percent}%)" +else + echo "Invalid arguments, make sure you know what you are doing !" + exit 1 +fi diff --git a/ns3-simulations/g5k-worker.sh b/ns3-simulations/g5k-worker.sh new file mode 100755 index 0000000..00a1aff --- /dev/null +++ b/ns3-simulations/g5k-worker.sh @@ -0,0 +1,68 @@ +#!/bin/bash +g5kLogFolder="/tmp/logs/" +mkdir -p $g5kLogFolder # Create log folder just in case +rm -rf $g5kLogFolder/* # Clean previous logs just in case + +hostname=$(hostname) + +# Run simulations with sourced arguments :D +simArgsLoc=~/args/ # Don't change this path without changing it in root scripts + +argsId=0 +argsFile="$simArgsLoc/${hostname}-args-${argsId}.sh" # Arguments generated by Root Node +for argsFile in $(find $simArgsLoc -type f -name "$hostname*") +do + 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 () { + # If another function want to handle simulation (tipically used on g5k) + type -t handleSim > /dev/null && { handleSim; return; } + + 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") + + # Compute some metrics + energyLog=$(echo "$log" | $parseEnergyScript) + avgDelay=$(echo "$log" | $parseDelayScript) + totalEnergy=$(echo "$energyLog"| awk 'BEGIN{power=0;FS=","}NR!=1{power+=$2}END{print(power)}') + nbPacketCloud=$(echo "$log"|grep -c "CloudSwitch receive") + nbNodes=$(echo "$log"|awk '/Simulation used/{print($3)}') + ns3Version=$(echo "$log"|awk '/NS-3 Version/{print($3)}') + + # Save logs + echo -e "#+TITLE: $(date) ns-3 (version ${ns3Version}) simulation\n" > $logFile + echo "* Environment Variables" >> $logFile + env >> $logFile + echo "* Full Command" >> $logFile + echo "$simCMD" >> $logFile + echo "* Output" >> $logFile + echo "$log" >> $logFile + 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} simKey:${simKey}" >> $logFile + + } + + logFolder=$g5kLogFolder # Don't forget override default g5kLogFolder + source $argsFile # Fetch argument + run +done + +cp -r $g5kLogFolder/* "$logsFinalDst" # Fetch log from tmp into nfs +echo $(hostname) >> $finishedFile # Just say I finished diff --git a/ns3-simulations/nix/default.nix b/ns3-simulations/nix/default.nix new file mode 100644 index 0000000..04134fb --- /dev/null +++ b/ns3-simulations/nix/default.nix @@ -0,0 +1,5 @@ +with (import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/19.03.tar.gz") {}); +rec { + ns3 = callPackage ./ns3 { inherit stdenv; inherit fetchurl; inherit python; inherit gsl; }; + simulator = callPackage ./simulator { inherit stdenv; inherit ns3; }; +} diff --git a/ns3-simulations/nix/ns3/default.nix b/ns3-simulations/nix/ns3/default.nix new file mode 100644 index 0000000..ed58501 --- /dev/null +++ b/ns3-simulations/nix/ns3/default.nix @@ -0,0 +1,36 @@ +{ stdenv, fetchurl, python, gsl }: + +stdenv.mkDerivation rec { + ##### Configure NIX ##### + name="ns3"; + sourceRoot="ns-allinone-3.29/ns-3.29/"; # Since we have 2 source tarball (ns-3 & ECOFEN) nix need to know which one to use + + ##### Fetch ns-3 And ECOFEN ##### + src = [ + (fetchurl { + url = https://www.nsnam.org/releases/ns-allinone-3.29.tar.bz2; + sha256 = "0m9dpmby116qk1m4x645i1p92syn30yzn9dgxxji5i25g30abpsd"; + }) + + (fetchurl { + url = http://people.irisa.fr/Anne-Cecile.Orgerie/ECOFEN/ecofen-v2.tar.bz2; + sha256 = "1dnmm20ihas6hwwb8qbx8sr3h66nrg8h55x6f2aqpf3xima29dyh"; + }) + ]; + + ##### Configure Dependencies ##### + buildInputs= [ python gsl ]; + + ##### Configure Phases ##### + postUnpack=''mv ecofen-module-v2 ${sourceRoot}/contrib/ecofen''; + configurePhase='' + export CXXFLAGS="-Wall -g -O0" # Don't treat warning as error when compiling ns-3 + python2 waf configure + ''; + buildPhase=''python2 waf''; + installPhase='' + mkdir -p $out/include + cp -r ./build/lib $out/ + cp -r ./build/ns3 $out/include + ''; +} diff --git a/ns3-simulations/nix/result b/ns3-simulations/nix/result new file mode 120000 index 0000000..a569d5e --- /dev/null +++ b/ns3-simulations/nix/result @@ -0,0 +1 @@ +/nix/store/c7vpaw8k0qvv1fzw5fz1vp5s13xyki2y-ns3 \ No newline at end of file diff --git a/ns3-simulations/nix/result-2 b/ns3-simulations/nix/result-2 new file mode 120000 index 0000000..715b58d --- /dev/null +++ b/ns3-simulations/nix/result-2 @@ -0,0 +1 @@ +/nix/store/2srcpv0g78mz3xk2ycgq6da3sjfggzbb-simulator \ No newline at end of file diff --git a/ns3-simulations/nix/simulator/default.nix b/ns3-simulations/nix/simulator/default.nix new file mode 100644 index 0000000..0a55322 --- /dev/null +++ b/ns3-simulations/nix/simulator/default.nix @@ -0,0 +1,18 @@ +{ stdenv, ns3 }: + +stdenv.mkDerivation rec { + ##### Configure NIX ##### + name="simulator"; + src=./src; + + ##### Export ns3 location ##### + NS3_PATH=ns3; + + ##### Configure Phases ##### + buildPhase=''make''; + installPhase='' + mkdir -p $out/bin + install -D -t $out/bin simulator + ''; + +} diff --git a/ns3-simulations/nix/simulator/src/Makefile b/ns3-simulations/nix/simulator/src/Makefile new file mode 100644 index 0000000..ffe03a4 --- /dev/null +++ b/ns3-simulations/nix/simulator/src/Makefile @@ -0,0 +1,26 @@ + +EXEC=simulator + +##### NS3 g++ Arguments +NS3_ARGS= -D NS3_LOG_ENABLE -L ${NS3_PATH}/lib -I ${NS3_PATH}/include +NS3_ARGS+=$(addprefix -l, $(subst lib,,$(subst .so,,$(notdir $(wildcard ${NS3_PATH}/lib/libns3*.so))))) +NS3_VERSION="3.29" + + +##### Source Files +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++ -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}:${NIX}/lib\e[0m" + +clean: + - rm $(EXEC) + + +.PHONY: clean diff --git a/ns3-simulations/nix/simulator/src/main.cc b/ns3-simulations/nix/simulator/src/main.cc new file mode 100644 index 0000000..b7f043c --- /dev/null +++ b/ns3-simulations/nix/simulator/src/main.cc @@ -0,0 +1,64 @@ +#include "modules/modules.hpp" + +NS_LOG_COMPONENT_DEFINE ("WIFISensorsSimulator"); + + +/** + * To get more details about functions please have a look at modules/modules.hpp + */ +int main(int argc, char* argv[]){ + + uint32_t sensorsFrequency=1; + 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 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", nbHop); + 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,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 (); + + + // Setup Logs + uint32_t nNode=ns3::NodeList::GetNNodes(); + FlowMonitorHelper flowmon; + Ptr monitor = flowmon.InstallAll(); + Ptr classifier = DynamicCast (flowmon.GetClassifier ()); + + // Run Simulations + Simulator::Stop (Seconds (SIM_TIME)); + Simulator::Run (); + + // Print logs + NS_LOG_UNCOND("NS-3 Version " << NS3_VERSION); + NS_LOG_UNCOND("Simulation used "<< nNode << " nodes"); + std::map 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.destinationAddress << " delay = " <second.delaySum.GetSeconds()); + } + + // Finish + Simulator::Destroy (); + return(0); +} diff --git a/ns3-simulations/nix/simulator/src/modules/callbacks.cc b/ns3-simulations/nix/simulator/src/modules/callbacks.cc new file mode 100644 index 0000000..4ae0c97 --- /dev/null +++ b/ns3-simulations/nix/simulator/src/modules/callbacks.cc @@ -0,0 +1,12 @@ + +#include "modules.hpp" + +void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address){ + NS_LOG_UNCOND("Node " << nodeName << " receive a packet" << " at time " << Simulator::Now ().GetSeconds () << "s"); +} + +void EnergyUpdated(std::string nodeName,double oldValue, double newValue){ + double currentTime=Simulator::Now ().GetSeconds (); + double energyConsumes=newValue-oldValue; + NS_LOG_UNCOND("Node " << nodeName << " consumes " << energyConsumes << "J" << " at time " << currentTime << "s"); +} diff --git a/ns3-simulations/nix/simulator/src/modules/energy.cc b/ns3-simulations/nix/simulator/src/modules/energy.cc new file mode 100644 index 0000000..c8cca6a --- /dev/null +++ b/ns3-simulations/nix/simulator/src/modules/energy.cc @@ -0,0 +1,68 @@ + +#include "modules.hpp" + +void 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 basicSourcePtr0 = DynamicCast (wifiEdgeNodesSources.Get (0)); + // //basicSourcePtr0->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy)); + // //device energy model + // Ptr basicRadioModelPtr0 = + // basicSourcePtr0->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0); + // 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 (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); +} + diff --git a/ns3-simulations/nix/simulator/src/modules/modules.hpp b/ns3-simulations/nix/simulator/src/modules/modules.hpp new file mode 100644 index 0000000..b537e92 --- /dev/null +++ b/ns3-simulations/nix/simulator/src/modules/modules.hpp @@ -0,0 +1,101 @@ + + +#ifndef MODULES_HPP +#define MODULES_HPP + +#include "ns3/command-line.h" +#include "ns3/config.h" +#include "ns3/string.h" +#include "ns3/log.h" +#include "ns3/yans-wifi-helper.h" +#include "ns3/ssid.h" +#include "ns3/mobility-helper.h" +#include "ns3/on-off-helper.h" +#include "ns3/yans-wifi-channel.h" +#include "ns3/mobility-model.h" +#include "ns3/packet-sink.h" +#include "ns3/packet-sink-helper.h" +#include "ns3/udp-echo-helper.h" +#include "ns3/tcp-westwood.h" +#include "ns3/internet-stack-helper.h" +#include "ns3/ipv4-address-helper.h" +#include "ns3/ipv4-global-routing-helper.h" +#include "ns3/constant-position-mobility-model.h" +#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" +#include "ns3/node-list.h" +#include "ns3/flow-monitor-module.h" + +// C++ library +#include // Why not ? +#include // To use std::pair +#include // To use std::setw + +#define SIM_TIME 60 + +// ECOFEN +#define ECOFEN_LOG_EVERY 0.5 + +// WIFI Energy Values +#define BASICENERGYSOURCEINITIALENERGYJ 10000 +#define BASICENERGYSUPPLYVOLTAGEV 3.3 +#define TXCURRENTA 0.38 +#define RXCURRENTA 0.313 +#define IDLECURRENTA 0.273 + +// Cloud Energy Values +#define ONCONSO 0 +#define OFFCONSO 0 +#define IDLECONSO 1 +#define RECVBYTEENERGY 3.4 +#define SENTBYTEENERGY 3.4 +#define RECVPKTENERGY 192.2 +#define SENTPKTENERGY 192.2 + +using namespace ns3; + +// ---------- Data types ---------- +typedef std::pair CellNodes; // Format (APNode, SensorsNodes) +typedef std::pair CellNetDevices; // Format (APNetDev, SensorsNetDev) +typedef std::pair Cell; +typedef std::pair EndPoint; // Format (IP,Port) +typedef std::pair CloudInfos; // Format (CloudHops,CloudEndPoint), here data sent to CloudEndPoint + + +// ---------- platform.cc ---------- +/** + * Create a WIFI cell paltform composed of nbSensors sensors and ap as an access point + */ +Cell createCell(uint32_t nbSensors, Ptr ap); +/** + * Build P2P network composed of nbHop hops (to simulate edge->cloud communications) + * Note: Cloud Servers are not considered here and completely ignored ! + */ +CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency); +/** + * Setup simulation scenario on the platforms. Sensors in cell will send packets of sensorsPktSize size every + * sensorsSensInterval second to the cloud using cloudInfos. + */ +void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sensorsSendInterval); + + +// ---------- energy.cc ---------- +/* + * Configure WIFI energy module for cell + */ +void setupCellEnergy(Cell cell); +/* + * Configure link/port energy using ecofen + */ +void setupCloudEnergy(CloudInfos cloudInfos); + + +// ---------- callbacks.cc ---------- +void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address); +void EnergyUpdated(std::string nodeName,double oldValue, double newValue); + + + +#endif diff --git a/ns3-simulations/nix/simulator/src/modules/platform.cc b/ns3-simulations/nix/simulator/src/modules/platform.cc new file mode 100644 index 0000000..52f91b0 --- /dev/null +++ b/ns3-simulations/nix/simulator/src/modules/platform.cc @@ -0,0 +1,124 @@ +#include "modules.hpp" + +/** + * Create a sensors cell base on + * nbSensors Number of temperature sensors in the cell + * ap the Access Point (usually linked to the cloud) + */ +Cell createCell(uint32_t nbSensors, Ptr ap){ + // Create sensors + NodeContainer sensors; + sensors.Create(nbSensors); + + // Place nodes somehow, this is required by every wireless simulation + for (uint32_t i = 0; i < nbSensors; i++) + { + sensors.Get (i)->AggregateObject (CreateObject ()); + } + ap->AggregateObject (CreateObject ()); + + // To apply XXWifiPhy and WifiMac on sensors + WifiHelper wifiHelper; + wifiHelper.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ); + + /* Set up Legacy Channel */ + YansWifiChannelHelper wifiChannel; + wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); + wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel", "Frequency", DoubleValue (5e9)); + + /* Setup Physical Layer */ + YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); + wifiPhy.SetChannel (wifiChannel.Create ()); + wifiPhy.Set ("TxPowerStart", DoubleValue (10.0)); + wifiPhy.Set ("TxPowerEnd", DoubleValue (10.0)); + wifiPhy.Set ("TxPowerLevels", UintegerValue (1)); + wifiPhy.Set ("TxGain", DoubleValue (0)); + wifiPhy.Set ("RxGain", DoubleValue (0)); + wifiPhy.Set ("RxNoiseFigure", DoubleValue (10)); + wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-79)); + wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-79 + 3)); + // wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel"); + wifiHelper.SetRemoteStationManager ("ns3::ConstantRateWifiManager", + "DataMode", StringValue ("HtMcs7"), + "ControlMode", StringValue ("HtMcs0")); + /* Configure AP */ + Ssid ssid = Ssid ("network"); + WifiMacHelper wifiMac; + wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid)); + NetDeviceContainer apNetDevice; + apNetDevice = wifiHelper.Install (wifiPhy, wifiMac, ap); + /* Configure STA */ + wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid)); + NetDeviceContainer sensorsNetDevices; + sensorsNetDevices = wifiHelper.Install (wifiPhy, wifiMac, sensors); + + return(std::make_pair(std::make_pair(ap,sensors),std::make_pair(apNetDevice,sensorsNetDevices))); +} + +/** + * Install network stack and applications + */ +void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sensorsSendInterval){ + NodeContainer ap=cell.first.first; + NodeContainer sensors=cell.first.second; + NetDeviceContainer apNetDev= cell.second.first; + NetDeviceContainer sensorsNetDev= cell.second.second; + + // 6. Install TCP/IP stack & assign IP addresses + InternetStackHelper internet; + // internet.Install (ap); + internet.Install (sensors); + Ipv4AddressHelper ipv4; + ipv4.SetBase ("10.0.0.0", "255.255.0.0"); + Ipv4InterfaceContainer apInt,sensorsInt; + apInt=ipv4.Assign(apNetDev); + sensorsInt=ipv4.Assign(sensorsNetDev); + + UdpEchoClientHelper echoClientHelper (InetSocketAddress (cloudInfos.second.first, cloudInfos.second.second)); + // echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (10)); + echoClientHelper.SetAttribute ("Interval", TimeValue (Seconds (sensorsSendInterval))); + echoClientHelper.SetAttribute ("PacketSize", UintegerValue (sensorsPktSize)); + ApplicationContainer pingApps; + + // again using different start times to workaround Bug 388 and Bug 912 + echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (1))); // Start at 1 (WIFI seems to not work when t<1) + echoClientHelper.Install (sensors); +} + + +CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency){ + + NodeContainer HopNodes; + HopNodes.Create(nbHop); + InternetStackHelper stack; + stack.Install(HopNodes); + + Ipv4Address cloudIP; // Will be fill in the following for loop + int cloudPort=80; + for(int i=0;iTraceConnect("Rx","CloudSwitch",MakeCallback(&PktReceived)); + sinkApp.Start (Seconds (0)); + } + } + + return(std::make_pair(HopNodes,std::make_pair(cloudIP,cloudPort))); + +} diff --git a/ns3-simulations/simulate.org b/ns3-simulations/simulate.org index 43aa253..c02aeca 100644 --- a/ns3-simulations/simulate.org +++ b/ns3-simulations/simulate.org @@ -74,6 +74,7 @@ #+RESULTS: runNbHop + ** Single Run #+NAME: singleRun @@ -94,6 +95,9 @@ simKey="NOKEY" run () { + # If another function want to handle simulation (tipically used on g5k) + type -t handleSim > /dev/null && { handleSim; return; } + 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" @@ -124,6 +128,133 @@ #+END_SRC +** Grid 5000 +*** Master Node Script + This code generate and distribute simulation argument to the slave worker nodes and + run start their simulations processes: + #+BEGIN_SRC sh :tangle ./g5k-root.sh :shebang "#!/bin/bash" :noweb yes + ##### Arguments ##### + nHost=15 + nProcesses=8 # Max number of parrallel simulations + nHours=3 # Reservation duration + simArgsLoc=~/args/ # Don't change this path witouth changing it in workder scripts + finishedFile="$simArgsLoc/finished-microBenchmarks.txt" + logsFinalDst=~/logs/ + ##################### + + # Check + [ "$1" == "subscribe" ] && subscribe=1 ||subscribe=0 + [ "$1" == "deploy" ] && deploy=1 || deploy=0 + [ "$1" == "-p" ] && progress=1 || progress=0 + + + + handleSim () { + outF="$simArgsLoc/$(uuidgen).sh" # Args file based on host name (avoid conflict) + + # Add Shebang + echo '#!/bin/bash' > $outF + echo "finishedFile=\"$finishedFile\"" >> $outF + echo "nProcesses=$nProcesses" >> $outF + echo "logsFinalDst=\"$logsFinalDst\"" >> $outF + # Save arguments + echo "sensorsSendInterval=${sensorsSendInterval}" >> $outF + echo "sensorsPktSize=${sensorsPktSize}" >> $outF + echo "nbHop=${nbHop}" >> $outF + echo "simKey=\"${simKey}\"" >> $outF + echo "sensorsNumber=${sensorsNumber}" >> $outF + echo "linksLatency=${linksLatency}" >> $outF + echo "sensorsNumber=${sensorsNumber}" >> $outF + echo "linksBandwidth=${linksBandwidth}" >> $outF + } + + + # Start subscribe/deploy + if [ $subscribe -eq 1 ] + then + echo "Starting oarsub..." + oarsub -l host=$nHost,walltime=$nHours 'sleep "10d"' # Start reservation + echo "Please join your node manually when your reservation is ready by using oarsub -C " + exit 0 + elif [ $deploy -eq 1 ] + then + echo "Starting deployment..." + + ##### Usefull Variables ##### + wai=$(dirname "$(readlink -f $0)") # Where Am I ? + hostList=($(cat $OAR_NODE_FILE | uniq)) + ############################# + + # Initialize logsFinalDst + mkdir -p $logsFinalDst + rm -rf $logsFinalDst/* # Clean log dst just in case (it is dangerous but avoid conflict) + mkdir -p $simArgsLoc + rm -rf $simArgsLoc/* # Clean old args + + # Add your simulation code block here + <> + <> + <> + <> + <> + + # Distribute argument according to subsribed nodes + cd $simArgsLoc + curHostId=0 + for file in $(find ./ -type f) + do + [ $curHostId -eq $nHost ] && curHostId=0 + mv -- ${file} ${hostList[$curHostId]}-$(basename ${file}) + curHostId=$(( curHostId + 1 )) + done + cd - + + + # Run simulations + echo "Host who finished their work:" > $finishedFile + for host in ${hostList[@]} + do + #oarsh lguegan@$host bash g5k-worker.sh & + echo "$host" + done + + exit 0 + elif [ $progress -eq 1 ] + then + alreadyFinished=$(cat $finishedFile| tail -n +2| wc -l) + percent=$(echo $alreadyFinished $nHost| awk '{print $1/$2*100}') + echo "Progression: " $alreadyFinished/$nHost "(${percent}%)" + else + echo "Invalid arguments, make sure you know what you are doing !" + exit 1 + fi + #+END_SRC +*** Worker Node Script + Almost like the [[microBenchmarksSingle][single run script]] but with additionnal code to handle g5k simulation platform (arguments,logs etc..). + #+BEGIN_SRC sh :tangle ./g5k-worker.sh :shebang "#!/bin/bash" :noweb yes + g5kLogFolder="/tmp/logs/" + mkdir -p $g5kLogFolder # Create log folder just in case + rm -rf $g5kLogFolder/* # Clean previous logs just in case + + hostname=$(hostname) + + # Run simulations with sourced arguments :D + simArgsLoc=~/args/ # Don't change this path without changing it in root scripts + + argsId=0 + argsFile="$simArgsLoc/${hostname}-args-${argsId}.sh" # Arguments generated by Root Node + for argsFile in $(find $simArgsLoc -type f -name "$hostname*") + do + <> + logFolder=$g5kLogFolder # Don't forget override default g5kLogFolder + source $argsFile # Fetch argument + run + done + + cp -r $g5kLogFolder/* "$logsFinalDst" # Fetch log from tmp into nfs + echo $(hostname) >> $finishedFile # Just say I finished + #+END_SRC + * Logs Analysis To Generate all the plots, please execute the following line: #+NAME: runAnalysis diff --git a/ns3-simulations/simulator/Makefile b/ns3-simulations/simulator/Makefile deleted file mode 100644 index a9cee83..0000000 --- a/ns3-simulations/simulator/Makefile +++ /dev/null @@ -1,25 +0,0 @@ - -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 - - -all: $(EXEC) - -$(EXEC): $(SRC) - @echo -e "\e[32mDon't forget to define NS3_PATH env variable !\e[0m" - 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" - -clean: - - rm $(EXEC) - - -.PHONY: clean diff --git a/ns3-simulations/simulator/main.cc b/ns3-simulations/simulator/main.cc deleted file mode 100644 index b7f043c..0000000 --- a/ns3-simulations/simulator/main.cc +++ /dev/null @@ -1,64 +0,0 @@ -#include "modules/modules.hpp" - -NS_LOG_COMPONENT_DEFINE ("WIFISensorsSimulator"); - - -/** - * To get more details about functions please have a look at modules/modules.hpp - */ -int main(int argc, char* argv[]){ - - uint32_t sensorsFrequency=1; - 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 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", nbHop); - 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,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 (); - - - // Setup Logs - uint32_t nNode=ns3::NodeList::GetNNodes(); - FlowMonitorHelper flowmon; - Ptr monitor = flowmon.InstallAll(); - Ptr classifier = DynamicCast (flowmon.GetClassifier ()); - - // Run Simulations - Simulator::Stop (Seconds (SIM_TIME)); - Simulator::Run (); - - // Print logs - NS_LOG_UNCOND("NS-3 Version " << NS3_VERSION); - NS_LOG_UNCOND("Simulation used "<< nNode << " nodes"); - std::map 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.destinationAddress << " delay = " <second.delaySum.GetSeconds()); - } - - // Finish - Simulator::Destroy (); - return(0); -} diff --git a/ns3-simulations/simulator/modules/callbacks.cc b/ns3-simulations/simulator/modules/callbacks.cc deleted file mode 100644 index 4ae0c97..0000000 --- a/ns3-simulations/simulator/modules/callbacks.cc +++ /dev/null @@ -1,12 +0,0 @@ - -#include "modules.hpp" - -void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address){ - NS_LOG_UNCOND("Node " << nodeName << " receive a packet" << " at time " << Simulator::Now ().GetSeconds () << "s"); -} - -void EnergyUpdated(std::string nodeName,double oldValue, double newValue){ - double currentTime=Simulator::Now ().GetSeconds (); - double energyConsumes=newValue-oldValue; - NS_LOG_UNCOND("Node " << nodeName << " consumes " << energyConsumes << "J" << " at time " << currentTime << "s"); -} diff --git a/ns3-simulations/simulator/modules/energy.cc b/ns3-simulations/simulator/modules/energy.cc deleted file mode 100644 index c8cca6a..0000000 --- a/ns3-simulations/simulator/modules/energy.cc +++ /dev/null @@ -1,68 +0,0 @@ - -#include "modules.hpp" - -void 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 basicSourcePtr0 = DynamicCast (wifiEdgeNodesSources.Get (0)); - // //basicSourcePtr0->TraceConnectWithoutContext ("RemainingEnergy", MakeCallback (&RemainingEnergy)); - // //device energy model - // Ptr basicRadioModelPtr0 = - // basicSourcePtr0->FindDeviceEnergyModels ("ns3::WifiRadioEnergyModel").Get (0); - // 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 (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); -} - diff --git a/ns3-simulations/simulator/modules/modules.hpp b/ns3-simulations/simulator/modules/modules.hpp deleted file mode 100644 index b537e92..0000000 --- a/ns3-simulations/simulator/modules/modules.hpp +++ /dev/null @@ -1,101 +0,0 @@ - - -#ifndef MODULES_HPP -#define MODULES_HPP - -#include "ns3/command-line.h" -#include "ns3/config.h" -#include "ns3/string.h" -#include "ns3/log.h" -#include "ns3/yans-wifi-helper.h" -#include "ns3/ssid.h" -#include "ns3/mobility-helper.h" -#include "ns3/on-off-helper.h" -#include "ns3/yans-wifi-channel.h" -#include "ns3/mobility-model.h" -#include "ns3/packet-sink.h" -#include "ns3/packet-sink-helper.h" -#include "ns3/udp-echo-helper.h" -#include "ns3/tcp-westwood.h" -#include "ns3/internet-stack-helper.h" -#include "ns3/ipv4-address-helper.h" -#include "ns3/ipv4-global-routing-helper.h" -#include "ns3/constant-position-mobility-model.h" -#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" -#include "ns3/node-list.h" -#include "ns3/flow-monitor-module.h" - -// C++ library -#include // Why not ? -#include // To use std::pair -#include // To use std::setw - -#define SIM_TIME 60 - -// ECOFEN -#define ECOFEN_LOG_EVERY 0.5 - -// WIFI Energy Values -#define BASICENERGYSOURCEINITIALENERGYJ 10000 -#define BASICENERGYSUPPLYVOLTAGEV 3.3 -#define TXCURRENTA 0.38 -#define RXCURRENTA 0.313 -#define IDLECURRENTA 0.273 - -// Cloud Energy Values -#define ONCONSO 0 -#define OFFCONSO 0 -#define IDLECONSO 1 -#define RECVBYTEENERGY 3.4 -#define SENTBYTEENERGY 3.4 -#define RECVPKTENERGY 192.2 -#define SENTPKTENERGY 192.2 - -using namespace ns3; - -// ---------- Data types ---------- -typedef std::pair CellNodes; // Format (APNode, SensorsNodes) -typedef std::pair CellNetDevices; // Format (APNetDev, SensorsNetDev) -typedef std::pair Cell; -typedef std::pair EndPoint; // Format (IP,Port) -typedef std::pair CloudInfos; // Format (CloudHops,CloudEndPoint), here data sent to CloudEndPoint - - -// ---------- platform.cc ---------- -/** - * Create a WIFI cell paltform composed of nbSensors sensors and ap as an access point - */ -Cell createCell(uint32_t nbSensors, Ptr ap); -/** - * Build P2P network composed of nbHop hops (to simulate edge->cloud communications) - * Note: Cloud Servers are not considered here and completely ignored ! - */ -CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency); -/** - * Setup simulation scenario on the platforms. Sensors in cell will send packets of sensorsPktSize size every - * sensorsSensInterval second to the cloud using cloudInfos. - */ -void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sensorsSendInterval); - - -// ---------- energy.cc ---------- -/* - * Configure WIFI energy module for cell - */ -void setupCellEnergy(Cell cell); -/* - * Configure link/port energy using ecofen - */ -void setupCloudEnergy(CloudInfos cloudInfos); - - -// ---------- callbacks.cc ---------- -void PktReceived(std::string nodeName,Ptr< const Packet > packet, const Address &address); -void EnergyUpdated(std::string nodeName,double oldValue, double newValue); - - - -#endif diff --git a/ns3-simulations/simulator/modules/platform.cc b/ns3-simulations/simulator/modules/platform.cc deleted file mode 100644 index 52f91b0..0000000 --- a/ns3-simulations/simulator/modules/platform.cc +++ /dev/null @@ -1,124 +0,0 @@ -#include "modules.hpp" - -/** - * Create a sensors cell base on - * nbSensors Number of temperature sensors in the cell - * ap the Access Point (usually linked to the cloud) - */ -Cell createCell(uint32_t nbSensors, Ptr ap){ - // Create sensors - NodeContainer sensors; - sensors.Create(nbSensors); - - // Place nodes somehow, this is required by every wireless simulation - for (uint32_t i = 0; i < nbSensors; i++) - { - sensors.Get (i)->AggregateObject (CreateObject ()); - } - ap->AggregateObject (CreateObject ()); - - // To apply XXWifiPhy and WifiMac on sensors - WifiHelper wifiHelper; - wifiHelper.SetStandard (WIFI_PHY_STANDARD_80211n_5GHZ); - - /* Set up Legacy Channel */ - YansWifiChannelHelper wifiChannel; - wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel"); - wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel", "Frequency", DoubleValue (5e9)); - - /* Setup Physical Layer */ - YansWifiPhyHelper wifiPhy = YansWifiPhyHelper::Default (); - wifiPhy.SetChannel (wifiChannel.Create ()); - wifiPhy.Set ("TxPowerStart", DoubleValue (10.0)); - wifiPhy.Set ("TxPowerEnd", DoubleValue (10.0)); - wifiPhy.Set ("TxPowerLevels", UintegerValue (1)); - wifiPhy.Set ("TxGain", DoubleValue (0)); - wifiPhy.Set ("RxGain", DoubleValue (0)); - wifiPhy.Set ("RxNoiseFigure", DoubleValue (10)); - wifiPhy.Set ("CcaMode1Threshold", DoubleValue (-79)); - wifiPhy.Set ("EnergyDetectionThreshold", DoubleValue (-79 + 3)); - // wifiPhy.SetErrorRateModel ("ns3::YansErrorRateModel"); - wifiHelper.SetRemoteStationManager ("ns3::ConstantRateWifiManager", - "DataMode", StringValue ("HtMcs7"), - "ControlMode", StringValue ("HtMcs0")); - /* Configure AP */ - Ssid ssid = Ssid ("network"); - WifiMacHelper wifiMac; - wifiMac.SetType ("ns3::ApWifiMac", "Ssid", SsidValue (ssid)); - NetDeviceContainer apNetDevice; - apNetDevice = wifiHelper.Install (wifiPhy, wifiMac, ap); - /* Configure STA */ - wifiMac.SetType ("ns3::StaWifiMac", "Ssid", SsidValue (ssid)); - NetDeviceContainer sensorsNetDevices; - sensorsNetDevices = wifiHelper.Install (wifiPhy, wifiMac, sensors); - - return(std::make_pair(std::make_pair(ap,sensors),std::make_pair(apNetDevice,sensorsNetDevices))); -} - -/** - * Install network stack and applications - */ -void setupScenario(Cell cell, CloudInfos cloudInfos, int sensorsPktSize, int sensorsSendInterval){ - NodeContainer ap=cell.first.first; - NodeContainer sensors=cell.first.second; - NetDeviceContainer apNetDev= cell.second.first; - NetDeviceContainer sensorsNetDev= cell.second.second; - - // 6. Install TCP/IP stack & assign IP addresses - InternetStackHelper internet; - // internet.Install (ap); - internet.Install (sensors); - Ipv4AddressHelper ipv4; - ipv4.SetBase ("10.0.0.0", "255.255.0.0"); - Ipv4InterfaceContainer apInt,sensorsInt; - apInt=ipv4.Assign(apNetDev); - sensorsInt=ipv4.Assign(sensorsNetDev); - - UdpEchoClientHelper echoClientHelper (InetSocketAddress (cloudInfos.second.first, cloudInfos.second.second)); - // echoClientHelper.SetAttribute ("MaxPackets", UintegerValue (10)); - echoClientHelper.SetAttribute ("Interval", TimeValue (Seconds (sensorsSendInterval))); - echoClientHelper.SetAttribute ("PacketSize", UintegerValue (sensorsPktSize)); - ApplicationContainer pingApps; - - // again using different start times to workaround Bug 388 and Bug 912 - echoClientHelper.SetAttribute ("StartTime", TimeValue (Seconds (1))); // Start at 1 (WIFI seems to not work when t<1) - echoClientHelper.Install (sensors); -} - - -CloudInfos createCloud(int nbHop, uint32_t bandwidth, uint32_t latency){ - - NodeContainer HopNodes; - HopNodes.Create(nbHop); - InternetStackHelper stack; - stack.Install(HopNodes); - - Ipv4Address cloudIP; // Will be fill in the following for loop - int cloudPort=80; - for(int i=0;iTraceConnect("Rx","CloudSwitch",MakeCallback(&PktReceived)); - sinkApp.Start (Seconds (0)); - } - } - - return(std::make_pair(HopNodes,std::make_pair(cloudIP,cloudPort))); - -} diff --git a/ns3-simulations/simulator/simulator b/ns3-simulations/simulator/simulator deleted file mode 100755 index ed894ca..0000000 Binary files a/ns3-simulations/simulator/simulator and /dev/null differ -- cgit v1.2.3