From 593950532e7b3bca5efef014d7459abf85640ab6 Mon Sep 17 00:00:00 2001 From: Giles Hutton Date: Thu, 28 Nov 2024 13:38:47 +0000 Subject: [PATCH] Misc --- scripts/network/Dockerfile | 9 ++++++ scripts/network/init.sh | 28 +++++++++++++++++++ scripts/network/prepare-tap.sh | 9 ++++-- scripts/network/workloads/network-client.toml | 12 ++++++++ scripts/network/workloads/network-server.toml | 12 ++++++++ 5 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 scripts/network/Dockerfile create mode 100755 scripts/network/init.sh create mode 100644 scripts/network/workloads/network-client.toml create mode 100644 scripts/network/workloads/network-server.toml diff --git a/scripts/network/Dockerfile b/scripts/network/Dockerfile new file mode 100644 index 0000000..af9f341 --- /dev/null +++ b/scripts/network/Dockerfile @@ -0,0 +1,9 @@ +FROM berserker:latest + +RUN dnf install -y which iproute bpftool procps iptables + +COPY prepare-tap.sh /scripts/ +COPY init.sh /scripts/ +COPY workloads /etc/berserker/ + +ENTRYPOINT ["/scripts/init.sh"] diff --git a/scripts/network/init.sh b/scripts/network/init.sh new file mode 100755 index 0000000..d3feb1b --- /dev/null +++ b/scripts/network/init.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -eo pipefail + +IP_BASE="223.42.0.1/16" + +/scripts/prepare-tap.sh -a "$IP_BASE" -o + +berserker /etc/berserker/network-server.toml & + +SERVER_PID=$! + +berserker /etc/berserker/network-client.toml & + +CLIENT_PID=$! + +cleanup() { + echo "Killing client ($CLIENT_PID) and server ($SERVER_PID)" + + kill -9 $CLIENT_PID + kill -9 $SERVER_PID + + exit +} + +trap cleanup SIGINT SIGKILL SIGABRT + +wait $SERVER_PID diff --git a/scripts/network/prepare-tap.sh b/scripts/network/prepare-tap.sh index a135539..fcf3a0a 100755 --- a/scripts/network/prepare-tap.sh +++ b/scripts/network/prepare-tap.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eou pipefail +set -x # This script helps to prepare an environment for developing berserker network # workload. It has the following preparatory steps: @@ -14,9 +15,7 @@ stop() { echo "$*" 1>&2 ; exit 1; } which ip &>/dev/null || stop "Don't have the ip tool" which whoami &>/dev/null || stop "Don't have the whoami tool" -which iptables &>/dev/null || stop "Don't have the iptables tool" which sysctl &>/dev/null || stop "Don't have the sysctl tool" -which firewall-cmd &>/dev/null || stop "Don't have the firewal-cmd tool" ADDRESS="10.0.0.1/16" NAME="berserker0" @@ -53,6 +52,8 @@ then then exit 1; fi + + ip link delete "${NAME}" fi echo "Creating tun device ${NAME} for user ${USER}..." @@ -64,12 +65,16 @@ ip addr add "${ADDRESS}" dev "${NAME}" if [[ "${CONFIGURE_FIREWALLD}" == "true" ]]; then + which firewall-cmd &>/dev/null || stop "Don't have the firewal-cmd tool" + echo "Adding to the trusted zone..." firewall-cmd --zone=trusted --add-interface="${NAME}" fi if [[ "${CONFIGURE_IPTABLE}" == "true" ]]; then + which iptables &>/dev/null || stop "Don't have the iptables tool" + echo "Enabling ip forward..." sysctl net.ipv4.ip_forward=1 diff --git a/scripts/network/workloads/network-client.toml b/scripts/network/workloads/network-client.toml new file mode 100644 index 0000000..746ffb3 --- /dev/null +++ b/scripts/network/workloads/network-client.toml @@ -0,0 +1,12 @@ +restart_interval = 10 +workers = 1 +per_core = false + +[workload] +type = "network" +server = false +address = [223, 42, 0, 1] +target_port = 1337 +arrival_rate = 0.1 +departure_rate = 0.1 +nconnections = 100 diff --git a/scripts/network/workloads/network-server.toml b/scripts/network/workloads/network-server.toml new file mode 100644 index 0000000..58e2e5c --- /dev/null +++ b/scripts/network/workloads/network-server.toml @@ -0,0 +1,12 @@ +restart_interval = 10 +workers = 1 +per_core = false + +[workload] +type = "network" +server = true +address = [223, 42, 0, 1] +target_port = 1337 +arrival_rate = 0.1 +departure_rate = 0.1 +nconnections = 100