Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Berserker network deployment #32

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scripts/network/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
28 changes: 28 additions & 0 deletions scripts/network/init.sh
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions scripts/network/prepare-tap.sh
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -53,6 +52,8 @@ then
then
exit 1;
fi

ip link delete "${NAME}"
fi

echo "Creating tun device ${NAME} for user ${USER}..."
Expand All @@ -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

Expand Down
12 changes: 12 additions & 0 deletions scripts/network/workloads/network-client.toml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions scripts/network/workloads/network-server.toml
Original file line number Diff line number Diff line change
@@ -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