entrypoint.sh 1.74 KB
Newer Older
Andreas Schmidt's avatar
Andreas Schmidt committed
1
#!/bin/sh
2 3 4 5 6 7

dev=eth0

command=$1
shift

8
if [[ "$command" == "sender" || "$command" == "receiver" || "$command" == "time-sender" || "$command" == "time-receiver" ]]; then
9 10 11
    :
else
    echo "Command should be either sender or receiver."
12
    exit 0;
13 14
fi

15 16
TARGET="127.0.0.1"
OUTPUT="/dev/null"
17 18 19 20 21
NETEM=()
PRRT=()
while [[ $# -gt 0 ]]
do
key="$1"
22

23
case $key in
24 25 26 27 28 29 30 31 32 33 34 35 36
    -t|--target)
    if [[  "$command" == "sender" || "$command" == "time-sender" ]]; then
    PRRT+=("$1 $2")
    fi
    TARGET=("$2")
    shift
    shift
    ;;
    -w|--wireshark)
    OUTPUT=("$2")
    shift
    shift
    ;;
Andreas Schmidt's avatar
Andreas Schmidt committed
37
    -T|--threadpinning|-U)
38 39 40
    PRRT+=("$1")
    shift
    ;;
Andreas Schmidt's avatar
Andreas Schmidt committed
41
    -p|--port|-r|--rounds|-s|--size|-R|--rcvbuf|-S|--sndbuf|-o|--output|-a|--appdelay|-j|--appjitter)
42 43 44 45 46 47 48 49 50 51
    PRRT+=("$1 $2")
    shift
    shift
    ;;
    *)    # unknown option
    NETEM+=("$1") # save it in an array for later
    shift # past argument
    ;;
esac
done
52

53 54
PRRT_PARAMS="${PRRT[@]}"
NETEM_PARAMS="${NETEM[@]}"
55

56 57 58
echo "Starting Wireshark."
tshark -i eth0 -w $OUTPUT.pcap &
TSHARK_PID=$!
Andreas Schmidt's avatar
Andreas Schmidt committed
59
sleep 2
60 61 62

start=$(date +%s.%N);
echo "Checking reachability of $TARGET."
Andreas Schmidt's avatar
Andreas Schmidt committed
63
until ping -c1 $TARGET &>/dev/null; do sleep 1; done
64 65
dur=$(echo "$(date +%s.%N) - $start" | bc);

Andreas Schmidt's avatar
Andreas Schmidt committed
66
printf "Reachable after %.6f seconds\n" $dur
67 68 69 70 71 72 73

if [[ "$command" == "sender" || "$command" == "time-sender" ]]; then
    echo "Delaying sender start."
else
    echo "Delaying receiver start."
fi

Andreas Schmidt's avatar
Andreas Schmidt committed
74
start=$(date +%s.%N);
75
echo "Running PRRT with command: \"$command $PRRT_PARAMS\" and link parameters: \"$NETEM_PARAMS\""
Andreas Schmidt's avatar
Andreas Schmidt committed
76 77 78 79 80 81
trap 'echo "Caught SIGINT."; echo "$(ps -a)"; killall -SIGINT $command' INT
LOG=$(/prrt/$command $PRRT_PARAMS 2>&1)
echo "Exit status: $?"
printf "$LOG\n"
dur=$(echo "$(date +%s.%N) - $start" | bc);
printf "Done after %.6f seconds\n" $dur
82
kill $TSHARK_PID