typeset -i iter

mkdir -p results
if [ $# -ne 1 ]
then
	echo "Require a unique filename to output result"
	exit
fi

res=results/$1
if [ -f $res -o -d $res ]
then
	echo $res already exists
	exit
fi

DEV=ib0
SERVER=10.1.1.42
TCP_PORT=1600
TCP_N_PORT=1700
UDP_PORT=1800

TIME=90
SIZES="32 128 512 4096"
PROCS="1 4 16 64"
ITERS=10

echo "4096 524288 4194304" > /proc/sys/net/ipv4/tcp_wmem
echo "4096 1048576 4194304" > /proc/sys/net/ipv4/tcp_rmem
echo 4194304 > /proc/sys/net/core/rmem_max
echo 4194304 > /proc/sys/net/core/wmem_max
echo 120000 > /proc/sys/net/core/netdev_max_backlog

#Loaded module with:
#modprobe ib_ipoib send_queue_size=256 recv_queue_size=256

iter=1

(
while [ $iter -le $ITERS ]
do
	echo "****************** ITER: $iter starting at `date` ******************************"
	echo $batch > /sys/class/net/$DEV/tx_batch_skbs

	for s in $SIZES
	do
		for p in $PROCS
		do
			sleep 5
			echo "Starting TCP : Size:$s Procs:$p"
			iperf -f K -l $s -w 131072 -c $SERVER -t $TIME -P $p -p $TCP_PORT
			sleep 5
			echo "Starting TCP No Delay: Size:$s Procs:$p"
			iperf -f K -l $s -w 131072 -c $SERVER -t $TIME -P $p -p $TCP_N_PORT -N
			# Giving weird results (eg always exact numbers like
			# 128KB/s, 256KB/s, 784KB/s, etc), use netperf instead.
			#
			#sleep 5
			#echo "Starting UDP : Size:$s Procs:$p"
			#iperf -f K -u -l $s -w 131072 -c $SERVER -t $TIME -P $p -p $UDP_PORT
		done
	done
	echo "****************** ITER: $iter ending at `date` ******************************"
	iter=$iter+1
done
) > $res 2>&1
