#!/bin/sh

set -x

if [ $# -ne 3 ]; then
    echo "$0 prefix host ip"
    echo "host and ip of the iperf server"
fi

prefix=$1; shift
host=$1; shift
port=$1; shift

flags="-c ${host} -p $port -O 10 -t 190"
fbase="iperf-${prefix}"

if echo $host | grep -q ':'; then
    flags="$flags -6"
    fbase="${fbase}-from-v6"
else
    flags="$flags -4"
    fbase="${fbase}-from-v4"
fi

do_benchmark()
{
    run=$1; shift
    full_flags="$@"
    iperf3_flags=$(echo $full_flags | sed 's/ //g')

    filename="${fbase}${iperf3_flags}-run${run}"
    iperf3 $full_flags | tee "${filename}"

}

for run in 1 2 3; do
    for p in 1 10 20 50; do
        do_benchmark $run $flags -P$p
        do_benchmark $run $flags -P$p -u -b0
    done
done
