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

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 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
echo "Starting Wireshark."
tshark -i eth0 -w $OUTPUT.pcap &
TSHARK_PID=$!
sleep 5

start=$(date +%s.%N);
echo "Checking reachability of $TARGET."
until ping -c1 $TARGET &>/dev/null; sleep 1; do :; done
dur=$(echo "$(date +%s.%N) - $start" | bc);
printf "Reachable after %.6f seconds\n" $dur

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

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

76 77 78
echo "Running PRRT with command: \"$command $PRRT_PARAMS\" and link parameters: \"$NETEM_PARAMS\""

tc qdisc add dev $dev root netem $NETEM_PARAMS
79 80
/prrt/$command $PRRT_PARAMS
echo "Done."
81
tc qdisc del dev $dev root
82 83

kill $TSHARK_PID