diff --git a/hack/README.md b/hack/README.md new file mode 100644 index 0000000..bd40568 --- /dev/null +++ b/hack/README.md @@ -0,0 +1,11 @@ +# Container based test bed for sshuttle + +```bash +test-bed up -d # start containers + +exec-sshuttle node-1 # start sshuttle to connect to node-1 + +exec-tool curl node-1 # curl to nginx instance running on node1 via IP that is only reachable via sshuttle +exec-tool iperf3 node-1 # measure throughput to node-1 + +``` diff --git a/hack/compose.yml b/hack/compose.yml index e008e6d..cd086e8 100644 --- a/hack/compose.yml +++ b/hack/compose.yml @@ -5,8 +5,6 @@ services: image: ghcr.io/sshuttle/sshuttle-testbed container_name: sshuttle-testbed-node-1 hostname: node-1 - ports: - - 22001:2222 cap_add: - "NET_ADMIN" environment: @@ -15,8 +13,6 @@ services: image: ghcr.io/sshuttle/sshuttle-testbed container_name: sshuttle-testbed-node-2 hostname: node-2 - ports: - - 22002:2222 cap_add: - "NET_ADMIN" environment: diff --git a/hack/exec-sshuttle b/hack/exec-sshuttle index 5d5f692..b76a90f 100755 --- a/hack/exec-sshuttle +++ b/hack/exec-sshuttle @@ -9,9 +9,9 @@ if [[ ! $node =~ [1-9]+ ]]; then fi shift -port="2200$node" +port="2222" subnet_args="-N" -host=localhost +host=$("$(dirname "$0")/test-bed" get-ip "$node") user="test:test" if ! command -v sshpass >/dev/null; then diff --git a/hack/exec-tool b/hack/exec-tool index 28a0882..e70de9c 100755 --- a/hack/exec-tool +++ b/hack/exec-tool @@ -2,10 +2,11 @@ set -e tool=${1?:"tool argument missing. should be one of iperf3,ping,curl,ab"} -node=${2?:"node argument missing. should be '1' , '2' etc"} +node=${2?:"node argument missing. should be 'node-1' , 'node-2' etc"} shift 2 -ip="10.55.$node.77" +index=${node#node-} +ip="10.55.$index.77" connect_timeout_sec=3 function with_set_x() { @@ -34,4 +35,8 @@ ab) port=8080 with_set_x exec ab -n 100 -c 20 -s $connect_timeout_sec "$@" "http://$ip:$port/" ;; +*) + echo "Unknown tool: $tool" >&2 + exit 2 + ;; esac diff --git a/hack/run-benchmark b/hack/run-benchmark index 2ba4386..07a858b 100755 --- a/hack/run-benchmark +++ b/hack/run-benchmark @@ -5,14 +5,15 @@ cd "$(dirname "$0")" function with_set_x() { set -x "$@" - { ec=$?; set +x;return $ec; } 2>/dev/null + { + ec=$? + set +x + return $ec + } 2>/dev/null } - ./test-bed up -d - - benchmark() { local sshuttle_bin="${1?:}" echo -e "\n======== Benchmarking sshuttle: $sshuttle_bin ========" @@ -29,12 +30,9 @@ benchmark() { wait $sshuttle_pid || true } - if [[ "$1" ]]; then benchmark "$1" else benchmark "${SSHUTTLE_BIN:-/bin/sshuttle}" benchmark dev fi - - diff --git a/hack/run-checks b/hack/run-checks index 72bead2..92b606a 100755 --- a/hack/run-checks +++ b/hack/run-checks @@ -6,4 +6,4 @@ export PYTHONPATH=. set -x python -m pytest . -python -m flake8 . \ No newline at end of file +python -m flake8 . diff --git a/hack/setup.service b/hack/setup.service index 8a6b0b7..4e36124 100755 --- a/hack/setup.service +++ b/hack/setup.service @@ -8,10 +8,13 @@ echo -e ">>> Setting up $(hostname) | id: $(id) | $(python --version) \nip: $(ip function with_set_x() { set -x "$@" - { ec=$?; set +x;return $ec; } 2>/dev/null + { + ec=$? + set +x + return $ec + } 2>/dev/null } - iface="$(ip route | awk '/default/ { print $5 }')" default_gw="$(ip route | awk '/default/ { print $3 }')" for addr in ${IP_ADDRESSES//,/ }; do diff --git a/hack/test-bed b/hack/test-bed index dddb04f..cb05043 100755 --- a/hack/test-bed +++ b/hack/test-bed @@ -2,7 +2,6 @@ set -e cd "$(dirname "$0")" - if [[ -z $1 || $1 = -* ]]; then set -- up "$@" fi @@ -10,7 +9,11 @@ fi function with_set_x() { set -x "$@" - { ec=$?; set +x;return $ec; } 2>/dev/null + { + ec=$? + set +x + return $ec + } 2>/dev/null } function build() { @@ -23,8 +26,17 @@ function compose() { with_set_x docker compose "$@" } +function get-ip() { + local container_name=sshuttle-testbed-"$1" + docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container_name" +} -if [[ $* = *--build* ]]; then - build +if [[ $1 == get-ip ]]; then + shift + get-ip "$@" +else + if [[ $* = *--build* ]]; then + build + fi + compose "$@" fi -compose "$@"