#!/bin/bash
set -eo pipefail
set -x

. "$(dirname $0)/../common.sh"

set -u

threads=$1
time=$2
dst="$3"

cleanup() {
    set +e

    sudo pkill -SIGTERM iperf3
}

trap cleanup EXIT

$hexec l3ep1 \
    iperf3 --server -p 12865 --json \
    > "${dst}server.json" \
    &
# $! only gives use the pid of sudo.

sleep 1

$hexec l3h1 \
    iperf3 -c 20.20.20.1 -t $time -p 12865 -P $threads --json \
    > "${dst}client.json"

sudo pkill -SIGTERM iperf3
wait
