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

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
    -t|--target)
    if [[  "$command" == "sender" || "$command" == "time-sender" ]]; then
    PRRT+=("$1 $2")
    fi
    TARGET=("$2")
    shift
    shift
    ;;
    -w|--wireshark)
    OUTPUT=("$2")
    shift
    shift
    ;;
37
    -T|--threadpinning|-U)
Andreas Schmidt's avatar
Andreas Schmidt committed
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 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

rna's avatar
rna committed
67
if [[ "$command" == "sender" || "$command" == "time-sender" ]]; then
rna's avatar
rna committed
68 69
    echo "Delaying $command"
    sleep 10
rna's avatar
rna committed
70 71
fi

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

rna's avatar
rna committed
75 76 77 78 79 80 81 82
#tc qdisc add dev $dev root netem $NETEM_PARAMS
trap 'echo "Caught SIGINT."; echo "$(ps -a)"; killall -SIGINT $command' INT
LOG=$(/prrt/$command $PRRT_PARAMS 2>&1)
printf "$LOG\n"
echo "Exit status: $?"
dur=$(echo "$(date +%s.%N) - $start" | bc);
printf "Done after %.6f seconds\n" $dur
#tc qdisc del dev $dev root
83 84

kill $TSHARK_PID