Skip to content

Instantly share code, notes, and snippets.

@jzlka
Created April 19, 2018 17:47
Show Gist options
  • Save jzlka/751d7425746db290392c75b5dc1ec741 to your computer and use it in GitHub Desktop.
Save jzlka/751d7425746db290392c75b5dc1ec741 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -ne 4 -a $# -ne 3 ]; then
echo "Wrong arguments"
echo "./client.sh <left_neighbor_ip> <left_neighbor_port> <clients> [right_neighbor_port]"
exit 1
fi
SPEEDS=(20 40 60 80 100 128)
SPEEDSLEN=${#SPEEDS[@]}
INSTANCES=(1 2 3 5 10)
INSTANCESLEN=${#INSTANCES[@]}
# check if right neighbor ended
if [ $# -eq 4 ]; then
# wait for right neighbor to start
nc -lvp "$4"
# wait for right neighbor to end
nc -lvp "$4" &
LISTEN_PID=$!
fi
# test various speed limits
for (( i=0; i<${SPEEDSLEN}; ((i++)) )); do
# test various numbers of instances
for (( j=0; j<${INSTANCESLEN}; ((j++)) )); do
for (( k=0; k<${INSTANCES[$j]}; ((k++)) )); do
# make an SSL connection
wget https://10.10.10.1:443/test5g.bin -O /dev/null --no-check-certificate --limit-rate=${SPEEDS[$i]}m &>/dev/null &
clientPIDs+=($!)
done
# wait for instances to finish downloading
for pid in "${clientPIDs[@]}"; do
echo "Waiting for $pid to finish downloading"
wait $pid
done
# wait for right neighbor to quit
if [ -n "$LISTEN_PID" ]; then
echo "Waiting for neighbor on port $4 to end"
wait $LISTEN_PID
fi
canContinue=0
while [ $canContinue -ne 1 ]; do
# notify left neighbor
nc $1 $2 -c "echo ${SPEEDS[$i]},${INSTANCES[$j]},$3,"
if [ $? -ne 0 ]; then
echo "Run Server!!"
read
else
canContinue=1
fi
done
# Delete stored PIDs
unset clientPIDs
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment