So lets assume we have everything installed and we want to run an example. You are inside the NS3DockerEmulator folder and assuming we are running the Beacon example that comes OOTB. So we have the following script.

This basically creates everything, and emulates the network for 120 seconds and it iterates for 100 times. Then it destroys everything. There are some comments to guide you through. There are two extra things, one is that it backup the logs every time it runs and two there are some comments referring to running a custom script to collect information from the application logs.

For example, in a emulation of my own, my main application was logging a lot of information I wanted to measure (like accuracy, convergence time, packets sent, packet size and others), then this custom script collected that information from the logs and sent it to a MongoDB, after all the simulations ran I would run queries to calculate averages, standard deviations and any other calculation that I needed.

If you want to follow up the emulation, you could tail the logs in ./var/logs/*.

#!/usr/bin/env bash

COUNTER=0
MAIN_SCRIPT="main.new.py"

NODES=20 # Number of nodes
TIMEEMU=120 # Time of the emulation in seconds
SIZE=300 # Size of the network, 300m x 300m
SPEED=5 # Speed in m/s
PAUSE=0 # Pause time of the nodes in seconds

export NS3_HOME=/home/ubuntu/workspace/source/ns-3.26

# We create everything
python3 ${MAIN_SCRIPT} -n ${NODES} -t ${TIMEEMU} -s ${SIZE} -ns ${SPEED} -np ${PAUSE} create
# We run the NS3 simulation
python3 ${MAIN_SCRIPT} -n ${NODES} -t ${TIMEEMU} -s ${SIZE} -ns ${SPEED} -np ${PAUSE} ns3

while [  $COUNTER -lt 100 ]; do

    DATENOW=$(date +"%y_%m_%d_%H_%M")

    # Making a backup from the last iteration's logs
    echo "---------------------------"
    echo ${DATENOW}
    echo "---------------------------"
    mkdir -p var/archive/${DATENOW}
    mv var/log/* var/archive/${DATENOW}/

    # Run the emulation
    python3 ${MAIN_SCRIPT} -n ${NODES} -t ${TIMEEMU} -s ${SIZE} -ns ${SPEED} -np ${PAUSE} emulation

    ####################################################################
    # Run a custom script to gather data from the logs for further analysis
    # python3 statscollector2.py bla bla bla
    ####################################################################

	let COUNTER=COUNTER+1
done

# We destroy everything cause we don't need it anymore
python3 ${MAIN_SCRIPT} -n ${NODES} -t ${TIMEEMU} -s ${SIZE} -ns ${SPEED} -np ${PAUSE} destroy