entrypoint.sh 1.81 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

Andreas Schmidt's avatar
Andreas Schmidt committed
56 57 58
echo "Starting Wireshark."
tshark -i eth0 -w $OUTPUT.pcap &
TSHARK_PID=$!
Andreas Schmidt's avatar
Andreas Schmidt committed
59
sleep 2
Andreas Schmidt's avatar
Andreas Schmidt committed
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
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
sleep 5
Andreas Schmidt's avatar
Andreas Schmidt committed
67 68 69 70

traceroute $TARGET > $OUTPUT.tr
echo "Traceroute done."

71 72
iperf3 --version

Andreas Schmidt's avatar
Andreas Schmidt committed
73 74 75 76 77
if [[ "$command" == "sender" || "$command" == "time-sender" ]]; then
    iperf3 -c $TARGET
else
    iperf3 -s -1
fi
Andreas Schmidt's avatar
Andreas Schmidt committed
78
echo "iperf3 for TCP done."
Andreas Schmidt's avatar
Andreas Schmidt committed
79

Andreas Schmidt's avatar
Andreas Schmidt committed
80
if [[ "$command" == "sender" || "$command" == "time-sender" ]]; then
81
    iperf3 -u -c $TARGET
Andreas Schmidt's avatar
Andreas Schmidt committed
82
else
83
    iperf3 -s -1
Andreas Schmidt's avatar
Andreas Schmidt committed
84
fi
Andreas Schmidt's avatar
Andreas Schmidt committed
85
echo "iperf3 for UDP done."
Andreas Schmidt's avatar
Andreas Schmidt committed
86

Andreas Schmidt's avatar
Andreas Schmidt committed
87 88
sleep 5

89 90 91
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
92 93
/prrt/$command $PRRT_PARAMS
echo "Done."
94
tc qdisc del dev $dev root
Andreas Schmidt's avatar
Andreas Schmidt committed
95 96

kill $TSHARK_PID