Skip to content

Commit

Permalink
Add run script
Browse files Browse the repository at this point in the history
  • Loading branch information
dstolpmann committed Jun 4, 2021
1 parent 64258f7 commit f24cfa0
Show file tree
Hide file tree
Showing 9 changed files with 810 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
BUILD
config/graphs/autosave.json
results
6 changes: 6 additions & 0 deletions config/environments/docker/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

source config/environments/docker/config.sh

# Build Docker image
docker build -t $DOCKER_IMAGE_EMULATOR -f $DOCKER_FILE_EMULATOR .
14 changes: 14 additions & 0 deletions config/environments/docker/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# Stop and delete Docker containers and network namespaces
cleanup() {
(docker stop channel; docker rm channel) || true
(docker stop source; docker rm source) || true
(docker stop sink; docker rm sink) || true

sudo ip netns delete channel || true
sudo ip netns delete source || true
sudo ip netns delete sink || true
}

cleanup &> /dev/null
12 changes: 12 additions & 0 deletions config/environments/docker/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh

# Build normal emulator Docker image
DOCKER_FILE_EMULATOR="Dockerfile"
DOCKER_IMAGE_EMULATOR="channel_emulator"

# Build emulator Docker image with machine learning support
#DOCKER_FILE_EMULATOR="Dockerfile_ml"
#DOCKER_IMAGE_EMULATOR="channel_emulator_ml"

# User emulator Docker image for source and sink
DOCKER_IMAGE_SOURCE_SINK=$DOCKER_IMAGE_EMULATOR
17 changes: 17 additions & 0 deletions config/environments/docker/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[metadata]
name = "Docker"
description = "Docker environment"

[config]
mqtt.host = "172.17.0.1"

interface.source = "in"
interface.sink = "out"

docker_container.source = "source"
docker_container.channel = "channel"
docker_container.sink = "sink"

#run_prefix.source = ""
#run_prefix.channel = ""
#run_prefix.sink = ""
38 changes: 38 additions & 0 deletions config/environments/docker/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

source config/environments/docker/config.sh

# Start Docker containers
docker run -d -it -v $(pwd)/config:/config --name channel $DOCKER_IMAGE_EMULATOR
docker run -d -it --privileged --name source $DOCKER_IMAGE_SOURCE_SINK
docker run -d -it --privileged --name sink $DOCKER_IMAGE_SOURCE_SINK

# Create links between Docker containers
setup_network() {
pid_channel=$(docker inspect -f '{{.State.Pid}}' channel)
pid_source=$(docker inspect -f '{{.State.Pid}}' source)
pid_sink=$(docker inspect -f '{{.State.Pid}}' sink)

sudo mkdir -p /var/run/netns/
sudo ln -sfT /proc/$pid_channel/ns/net /var/run/netns/channel
sudo ln -sfT /proc/$pid_source/ns/net /var/run/netns/source
sudo ln -sfT /proc/$pid_sink/ns/net /var/run/netns/sink

sudo ip link add emulator netns source type veth peer name in netns channel
sudo ip netns exec source ethtool -K emulator rx off tx off
sudo ip netns exec source ip addr add 10.0.1.1/24 dev emulator
sudo ip netns exec channel ip link set in up
sudo ip netns exec source ip link set lo up
sudo ip netns exec source ip link set emulator up
sudo ip netns exec source ip route add 10.0.2.0/24 dev emulator

sudo ip link add emulator netns sink type veth peer name out netns channel
sudo ip netns exec sink ethtool -K emulator rx off tx off
sudo ip netns exec sink ip addr add 10.0.2.1/24 dev emulator
sudo ip netns exec channel ip link set out up
sudo ip netns exec sink ip link set lo up
sudo ip netns exec sink ip link set emulator up
sudo ip netns exec sink ip route add 10.0.1.0/24 dev emulator
}

setup_network > /dev/null
Loading

0 comments on commit f24cfa0

Please sign in to comment.