#!/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 iperf
}

trap cleanup EXIT

$hexec l3ep1 \
  iperf -s -p 12865 --reportstyle c \
  > "${dst}server.csv" \
  &
# $! only gives use the pid of sudo.

sleep 1

# --sum-only is not supported with CSV reportstyle.
$hexec l3h1 \
  iperf -c 20.20.20.1 -t $time -p 12865 -P $threads --reportstyle c \
  > "${dst}client.csv"

sudo pkill -SIGTERM iperf
wait
