entrypoint.sh 1.61 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/bash

dev=eth0

command=$1
shift

Andreas Schmidt's avatar
Andreas Schmidt committed
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

Andreas Schmidt's avatar
Andreas Schmidt committed
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
Andreas Schmidt's avatar
Andreas Schmidt committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    -t|--target)
    if [[  "$command" == "sender" || "$command" == "time-sender" ]]; then
    PRRT+=("$1 $2")
    fi
    TARGET=("$2")
    shift
    shift
    ;;
    -w|--wireshark)
    OUTPUT=("$2")
    shift
    shift
    ;;
    -T|--threadpinning)
    PRRT+=("$1")
    shift
    ;;
    -p|--port|-r|--rounds|-s|--size|-R|--rcvbuf|-S|--sndbuf|-o|--output|-a|--appdelay)
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 59 60
echo "Starting Wireshark."
tshark -i eth0 -w $OUTPUT.pcap &
TSHARK_PID=$!
sleep 2

Andreas Schmidt's avatar
Andreas Schmidt committed
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
Andreas Schmidt's avatar
Andreas Schmidt committed
64 65
dur=$(echo "$(date +%s.%N) - $start" | bc);
printf "Reachable after %.6f seconds\n" $dur
Andreas Schmidt's avatar
Andreas Schmidt committed
66

67 68 69 70
if [[ "$command" == "sender" || "$command" == "time-sender" ]]; then
    sleep 5
fi

Andreas Schmidt's avatar
Andreas Schmidt committed
71
start=$(date +%s.%N);
72 73 74
echo "Running PRRT with command: \"$command $PRRT_PARAMS\" and link parameters: \"$NETEM_PARAMS\""

tc qdisc add dev $dev root netem $NETEM_PARAMS
Andreas Schmidt's avatar
Andreas Schmidt committed
75
/prrt/$command $PRRT_PARAMS
Andreas Schmidt's avatar
Andreas Schmidt committed
76 77
dur=$(echo "$(date +%s.%N) - $start" | bc);
printf "Done after %.6f seconds\n" $dur
78
tc qdisc del dev $dev root
79 80

kill $TSHARK_PID