Skip to content

Commit

Permalink
docker: easily start a simulation in a docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
dpugliese6 committed Jan 5, 2025
1 parent 53ad70a commit d412d37
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 47 deletions.
47 changes: 0 additions & 47 deletions .devcontainer/Dockerfile

This file was deleted.

45 changes: 45 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM ubuntu:22.04

ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive

####
# Machine setup and dependecies installation
####
RUN apt-get update \
&& apt-get install --no-install-recommends --quiet --assume-yes \
clang-format \
cmake \
g++ \
gdb \
gcc \
git \
make \
libgsl-dev \
libxml2-dev \
patch \
pkg-config \
python3 \
python3-venv \
python3-pip \
python-is-python3 \
rapidjson-dev \
doxygen \
graphviz

# Use local versione of the simulator

#RUN mkdir IoD_Sim
#COPY . ./IoD_Sim/

# Use remote version of the simulator
RUN git clone https://github.com/telematics-lab/IoD_Sim.git

WORKDIR ./IoD_Sim
RUN ./tools/prepare-ns3-docker.sh
RUN ./tools/configure-iodsim.sh
WORKDIR ./ns3
RUN ./ns3 build -j$(grep -c ^processor /proc/cpuinfo)
WORKDIR ..

ENTRYPOINT ["/bin/bash","./tools/simulate.sh"]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ The documentation can be generated in HTML and LaTeX formats by running:
doxygen ./docs/IoD_Sim_doc
```

## Working with docker

After creating your own scenario through the JSON file, you can use [Docker](https://docs.docker.com/engine/) to quickly proceed to simulation in a few steps. The first time, the container image must be built by running the following command in the main directory of the repository:

```
docker build . -t docker_iod_sim
```

Next, the simulation can be run by launching:

```
sudo docker run --rm -v ./results:/IoD_Sim/results -v ./scenario:/IoD_Sim/scenario docker_iod_sim [--help] <simulation_file_name>
```

When completed, the `results` folder will contain the results of the simulation. It should be noted that if a new scenario is placed in `./scenario`, there will be no need to rebuild the container.

## License

Expand Down
27 changes: 27 additions & 0 deletions tools/prepare-ns3-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

set -e

check_availability() {
PRG_NAME=$1

command -v $PRG_NAME &> /dev/null
if [ "$?" -ne 0 ]; then
echo "The program \"${PRG_NAME}\" is not available in your system. \
Please install it, then re-run this script."
exit 1
fi
}

# check dependencies
check_availability git
check_availability patch

git submodule update --init

pushd ns3 > /dev/null
for patchfile in ../tools/*.patch
do
patch -s -p1 < $patchfile
done
popd > /dev/null
23 changes: 23 additions & 0 deletions tools/simulate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

usage() {
echo "Usage:"
echo "sudo docker run --rm -v ./results:/IoD_Sim/results -v ./scenario:/IoD_Sim/scenario docker_iod_sim [--help] <simulation_file_name>"
echo
echo "Options:"
echo " --help Shows help message."
echo " <simulation_file_name> Name of the .json file to simulate."
exit 1
}

if [[ "$1" == "--help" ]]; then
usage
elif [[ -z "$1" ]]; then
usage
elif [[ ! -f "./scenario/$1.json" ]]; then
echo "Error: File '$1.json' doesn't exist."
usage
else
source .venv/bin/activate && ./ns3/ns3 run "iodsim --config=../scenario/$1.json"
chmod -R 777 ./results/*
fi

0 comments on commit d412d37

Please sign in to comment.