#!/bin/sh

set -x 

MEDIANET=/local_home/mwh/media-net
ttcpout=/local_home/mwh/ttcp-results

packetsizes="8192 4096 2048"
#packetsizes="32768 16384 8192 4096 2048 1024 512 256 128 64"
numpackets=50000
iters=1

# emulab
# pc1=pc1.line.medianet
# pc2=pc2.line.medianet
# pc3=pc3.line.medianet
# l1=192.168.1.3
# l2=192.168.2.3

# ri machines
SSH="ssh -n"
pc1=ri03
pc2=ri02
pc3=ri05
l1=rim02
l2=rim05

# penn machines
# SSH="ssh -n"
# pc1=artemis.cis.upenn.edu
# pc2=aphrodite.cis.upenn.edu
# pc3=apollo.cis.upenn.edu
# l1=10.0.1.3
# l2=10.0.2.1

# locally
# SSH=./localssh
# pc1=localhost
# pc2=localhost
# pc3=localhost
# l1=localhost
# l2=localhost

# set up the medianet program
#bridge_tmp=$MEDIANET/src/lsched/configs/bridge-ttcp.xml.in
bridge=$MEDIANET/src/lsched/configs/bridge-ttcp.xml
#sed -e "s/xx1/$l2/" $bridge_tmp > $bridge
#if [ "$SSH" != "./localssh" ]; then
#  scp $bridge $pc2:$bridge
#fi

# run the test
for sz in $packetsizes
do
  i=0
  while [ $i -lt $iters ]; do 
    # do the test, when the send finishes, we can clean up after a brief pause
    $SSH $pc3 $MEDIANET/scripts/startrecv 5000 $sz $numpackets $ttcpout
    $SSH $pc2 $MEDIANET/scripts/startLS 7777 $bridge
    $SSH $pc1 $MEDIANET/src/apps/ttcp/ttcp -s -t -l $sz -n $numpackets -p 5001 -P $l1 > /dev/null

    sleep 1

    $SSH $pc3 $MEDIANET/scripts/stoprecv 5000
    $SSH $pc2 $MEDIANET/scripts/stopLS 7777

    scp $pc2:amon.out /tmp/amon.out.medianet-gc.$sz
    $SSH $pc2 \rm -f amon.out

    i=`expr $i + 1`
  done
done
