#!/bin/zsh
USE_BIG_PACKETS=0

function hostcheck
{
	until ping -c 3 -l 3 -t 1 -q $1 > /dev/null; do
		echo "[EE] Host not up"
	done
}

function testconn
{
	hostcheck $2
	abc=`ping -q -t 5 -c 50 -i 0.01 -s $i $2`
	loss=`echo $abc | grep loss | awk '{print $7}' | sed s/%//`
	if [ "$loss" = "ID" ]; then loss="FAIL"; fi
	echo "Run $count :: Size $i :: Loss $loss%"
	total=$((total+loss))
	hostcheck $2
}

[ "$1" = "" ] && exit 1

count=1
while [ 1 ]; do
	echo " --- Run $count starting"
	total=0
	for i in 56 120 248; do
		testconn $i $1
	done
	if [ "$total" = "0" ] && [ "$USE_BIG_PACKETS" = "1" ]; then
		for i in 4088 16376 65507; do
			testconn $i $1
		done
	fi
	echo " --- Run $count complete, total loss: $total%"
	hostcheck $1
	count=$((count+1))
done
