#! /bin/sh
# The SPIMS software is covered by a license. The use of the software
# represents acceptance of the terms and conditions in the license.
# ******************************************************************
# Copyright (c) 1989, Swedish Institute of Computer Science
# run - run a benchmark on a set of protocols
# output from each run is stored on file protocol.host.script
# Usage: run [protocols] measurment-script [host] 
DEF_PROTOCOLS="udp tcp ftp ftam sunrpc tcprpc isoros tsap ssap"
FROM_HOST=`hostname`

PROTOCOLS=""
TO_HOST=""
if [ $# = 0 ]; then
	echo 'usage: run  [host] [protocols]  measurement-script'
	exit 1
fi

if [ ! -d $SPIMSDIR/$1 ]; then
	TO_HOST=$1
	shift
fi

for i in $*; do
	if [ -d "$SPIMSDIR/$i" ]; then
		PROTOCOLS="$PROTOCOLS $i"
		shift
	else
		break;
	fi
done

if [ -f "$1" ]; then
	SCRIPT=$1
	SCRIPTSFX=`basename $SCRIPT`
	shift
else
	echo "Can't open measurement script \"$1\""
	exit 1
fi

if [ "$PROTOCOLS" = "" ]; then
	PROTOCOLS=$DEF_PROTOCOLS
fi
if [ "$TO_HOST" = "" ]; then
	$TO_HOST=$FROM_HOST
	ALLHOSTS=$TO_HOST
else
	ALLHOSTS="$TO_HOST $FROM_HOST"
fi

echo "Running measurment script \"$SCRIPT\" on protocols \"$PROTOCOLS\" to host \"$TO_HOST\""

for p in $PROTOCOLS; do
	startdemons $ALLHOSTS $p
	if [ $TO_HOST != $FROM_HOST ]; then
		startdemon $FROM_HOST $p
	fi
	sleep 10
	$SPIMSDIR/$p/bench $TO_HOST <$SCRIPT 2>&1 > $p.$TO_HOST.$SCRIPTSFX
	killdemons $TO_HOST $FROM_HOST $p
done



