working at transport level delay measurement
[p2p-testing-infrastructure.git] / ControlScripts / delay-measurement / measure-delay.sh
diff --git a/ControlScripts/delay-measurement/measure-delay.sh b/ControlScripts/delay-measurement/measure-delay.sh
new file mode 100755 (executable)
index 0000000..aa80865
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Calin-Andrei Burloiu, 2011, calin.burloiu@gmail.com
+#
+# This script is used to start delay measurement. It does the following:
+#   1. Start the handle packets script (that is going to wait for SystemTap to start
+#   hooking).
+#   2. Starts SystemTap.
+#   3. Waits until a SIGINT is received. When this happens kills the above
+#   processes and makes cleanup.
+#
+
+if [ $# != 3 ]; then
+       echo "usage: $0 server_host server_port output_file" >&2
+       exit 1
+fi
+
+host="$1"
+port=$2
+output="$3"
+
+stap_output="stap.log"
+handle_packets_output=/dev/null #"handle-packets.log"
+handle_packets_script="handle-packets.py"
+
+# Called at the end when SIGINT is received.
+cleanup()
+{
+    # Kill handle packets script.
+    kill -s SIGUSR1 $handle_packets_script_pid
+    # Kill SystemTap.
+    kill $stap_pid
+    # Delete stap's output file.
+    rm "$stap_output"
+    echo "Measure Delay Finished."
+}
+
+trap cleanup SIGINT
+
+# Delete stap's output file.
+rm "$stap_output"
+
+# Start handle packets script which sends TCP data and processes stap output.
+python "$handle_packets_script" $host $port "$output" &> "$handle_packets_output" &
+handle_packets_script_pid=$!
+
+# Start SystemTap.
+stap hook.stp -x $handle_packets_script_pid -o "$stap_output" &
+stap_pid=$!
+
+# Wait for the signal.
+sleep 1000000
+