working at transport level delay measurement
authorP2P-Next <p2p@p2p-next.grid.pub.ro>
Tue, 28 Jun 2011 12:05:10 +0000 (15:05 +0300)
committerP2P-Next <p2p@p2p-next.grid.pub.ro>
Tue, 28 Jun 2011 12:05:10 +0000 (15:05 +0300)
ControlScripts/clients/transmission/start_transmission_seeder.sh
ControlScripts/clients/transmission/stop_transmission.sh
ControlScripts/delay-measurement/handle-packets-server.py [new file with mode: 0755]
ControlScripts/delay-measurement/handle-packets.py [new file with mode: 0755]
ControlScripts/delay-measurement/hook.stp [new file with mode: 0644]
ControlScripts/delay-measurement/links.txt [new file with mode: 0644]
ControlScripts/delay-measurement/measure-delay.sh [new file with mode: 0755]
ControlScripts/delay-measurement/old/measure-delay_iperf.sh [new file with mode: 0755]
ControlScripts/delay-measurement/old/request-http.sh [new file with mode: 0755]
ControlScripts/globalconfig
ControlScripts/schedule_client.sh

index 39de395..a7c14c2 100755 (executable)
@@ -32,4 +32,9 @@ rm ~/.config/transmission/torrents/*
 
 cd $WORKING_FOLDER_REL_PATH/TorrentsAndData/
 
+# Start transport level delay measurement.
+sudo /home/p2p/P2P-Testing-Infrastructure/ControlScripts/delay-measurement/measure-delay.sh p2p-next-02.local 5002 "/tmp/background.log" &
+echo $! > "/tmp/pid"
+
 $TRANSMISSION_ABS_PATH/transmission-cli $TORRENT_FILE -w .
+
index dbc76b3..3bfc8b4 100755 (executable)
@@ -12,3 +12,6 @@ if [ ! $# -eq 0 ]; then
 fi
 
 pkill -KILL -f transmission-cli
+
+# Kill transport level delay measurement.
+sudo kill -INT $(cat /tmp/pid)
diff --git a/ControlScripts/delay-measurement/handle-packets-server.py b/ControlScripts/delay-measurement/handle-packets-server.py
new file mode 100755 (executable)
index 0000000..6abda4f
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+#
+# Calin-Andrei Burloiu, 2011, calin.burloiu@gmail.com
+#
+# This script acts as a server for handle packets script by receiving TCP
+# packets. These packets does not have any meaning, they are sent by the
+# client for the purpose of measuring transport level delay.
+#
+
+import sys
+import socket
+
+
+def main():
+    if len(sys.argv) != 2:
+        sys.stderr.write('usage: python ' + sys.argv[0] + ' listen_port\n')
+        exit(1)
+    
+    HOST = ''
+    PORT = int(sys.argv[1])
+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    s.bind((HOST, PORT))
+    s.listen(socket.SOMAXCONN)
+    conn, addr = s.accept()
+    print 'Connected by', addr
+    i = 0
+    while True:
+        data = conn.recv(1024)
+        if not data: continue
+        print i
+        i = i + 1
+
+    conn.close()
+    return 0
+
+
+if __name__ == '__main__':
+    exit(main())
diff --git a/ControlScripts/delay-measurement/handle-packets.py b/ControlScripts/delay-measurement/handle-packets.py
new file mode 100755 (executable)
index 0000000..8e0b5c1
--- /dev/null
@@ -0,0 +1,93 @@
+#!/usr/bin/python
+#
+# Calin-Andrei Burloiu, 2011, calin.burloiu@gmail.com
+#
+# This script does the following in a loop until a SIGUSR1 is received:
+#   1. Sends a TCP packet to the handle packets server.
+#   2. Parses the SystemTap output file and dumps the delay of the packet from
+#   the transport level.
+#
+
+import sys
+import signal
+import socket
+import time
+
+# Socket
+s = None
+# Files
+fIn = None
+fOut = None
+
+def signalHandler(signum, frame):
+    global s
+    global fIn
+    global fOut
+    s.close()
+    fIn.close()
+    fOut.close()
+    print "Handle packets script exited."
+    exit(0)
+
+def main():
+    if len(sys.argv) != 4:
+        sys.stderr.write('usage: python ' + sys.argv[0] + ' server_host server_port\n')
+        exit(1)
+
+    global s
+    global fIn
+    global fOut
+    HOST = sys.argv[1]
+    PORT = int(sys.argv[2])
+    DATA = 'x' * 1000
+    stapOutput = "stap.log"
+    delaysOutput = sys.argv[3]
+
+    # Set the signal handler.
+    signal.signal(signal.SIGUSR1, signalHandler)
+
+    # Wait until SystemTap finishes initialization
+    # i.e. creates the output file.
+    while True:
+        try:
+                       fIn = open(stapOutput, 'r')
+        except IOError:
+            time.sleep(1)
+            continue
+        break
+
+    # Open the output file.
+    fOut = open(delaysOutput, 'w')
+    fOut.truncate(0)
+
+    # Connect to the server.
+    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+    s.connect((HOST, PORT))
+
+    # The loop
+    while True:
+        # Send a TCP packet to the server.
+        # SystemTap will write new information in stap.log.
+        s.send(DATA, socket.MSG_EOR)
+
+        time.sleep(1)
+
+        # Process stap.log.
+        t1 = -1
+        t2 = -1
+        delta = -1
+        while True:
+            line = fIn.readline()
+            if not line: break
+            if line.find('sendmsg') != -1:
+                t1 = int(line.partition(' ')[0])
+            if t1 != -1 and t2 == -1 and line.find('transmit') != -1:
+                t2 = int(line.partition(' ')[0])
+                delta = t2 - t1
+                fOut.write(str(delta) + '\n')
+
+    return 0
+
+if __name__ == "__main__":
+    sys.exit(main())
diff --git a/ControlScripts/delay-measurement/hook.stp b/ControlScripts/delay-measurement/hook.stp
new file mode 100644 (file)
index 0000000..56c654c
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/env stap
+#
+# Calin-Andrei Burloiu, 2011, calin.burloiu@gmail.com
+#
+# This script is used by SystemTap to hook the moments when TCP system calls 
+# tcp_sendmsg (net/ipv4/tcp_output.c) and tcp_transmit_skb 
+# (net/ipv4/tcp_output.c) are called and logs them to the output file.
+# The output is going to be processed in the handle packets client script.
+#
+
+function print_info()
+{
+       if (pid() == target())
+               printf("%d %s -> %s\n", gettimeofday_ns(), thread_indent(1), probefunc())
+}
+
+probe kernel.function("tcp_sendmsg@net/ipv4/tcp.c")
+{
+       print_info();
+}
+
+probe kernel.function("tcp_transmit_skb@net/ipv4/tcp_output.c")
+{
+       print_info();
+}
diff --git a/ControlScripts/delay-measurement/links.txt b/ControlScripts/delay-measurement/links.txt
new file mode 100644 (file)
index 0000000..0af541d
--- /dev/null
@@ -0,0 +1,2 @@
+http://vger.kernel.org/~davem/tcp_output.html
+http://lxr.linux.no/#linux+v2.6.39/net/ipv4/
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
+
diff --git a/ControlScripts/delay-measurement/old/measure-delay_iperf.sh b/ControlScripts/delay-measurement/old/measure-delay_iperf.sh
new file mode 100755 (executable)
index 0000000..0e84422
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+
+if [ $# != 1 ]; then
+       echo "usage: $0 iperf_server" >&2
+       exit 1
+fi
+
+iperf_server=$1
+
+iperf_time=60
+
+
+# Start uploading to iperf server.
+iperf -c "$iperf_server" -t "$iperf_time" &> iperf.log &
+
+# Start SystemTap.
+stap hook.stp -x $iperf_pid -o stap.log &
+stap_pid=$!
+
+# Wait for iperf to finish.
+sleep $iperf_time
+
+# kill SystemTap.
+kill $stap_pid
diff --git a/ControlScripts/delay-measurement/old/request-http.sh b/ControlScripts/delay-measurement/old/request-http.sh
new file mode 100755 (executable)
index 0000000..6552325
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+while true; do
+        sleep 5
+        wget http://141.85.37.41/~cburloiu/sample.txt
+        rm sample*
+done
index 4ed9c60..035b92c 100644 (file)
@@ -32,7 +32,7 @@ HRK_ABS_PATH="/home/p2p/p2p-clients/hrktorrent/hrktorrent"
 HRK_LOG_ABS_PATH="/home/p2p/p2p-clients/hrktorrent-logging/hrktorrent"
 
 # TRANSMISSION_PATH
-TRANSMISSION_ABS_PATH="/home/p2p/p2p-clients/transmission/cli"
+TRANSMISSION_ABS_PATH="/home/p2p/export2/p2p-clients/transmission/cli"
 
 # XBTUT_PATH
 XBTUT_ABS_PATH="/home/p2p/export/unified-tracker/trunk/xbt/Tracker" 
@@ -55,6 +55,9 @@ CONFIG_FILES_REL_PATH="../TestSpecs/gen"
 # CONFIG_FILES_REL_PATH is relative to ControlScripts folder - used by run_campaign.sh
 RESULTS_FOLDER_REL_PATH="../Results"
 
+# Transport level delay measurement script
+DELAY_MEASUREMENT_ABS_PATH="${TEST_INFRASTRUCTURE_ABS_PATH}/ControlScripts/delay-measurement/measure-delay.sh"
+
 # DEBUG function
 DEBUG()
 {
index c0f4de6..96ee8db 100755 (executable)
@@ -122,18 +122,8 @@ DEBUG echo "$(basename $0): background_pid is ${background_pid}"
 # wait for client to start
 sleep 5
 while true; do
-       #echo "ps --ppid ${background_pid} -o pid -o cmd"
-       #ps --ppid ${background_pid} -o pid -o cmd
-       #echo "ps --ppid ${background_pid} -o 'pid=' -o 'cmd=' | grep './swift' | grep -v 'grep' | grep -v 'ps'"
-       #ps --ppid ${background_pid} -o 'pid=' -o 'cmd=' | grep './swift' | grep -v 'grep' | grep -v 'ps'
-       #client_pid=$(ps --ppid ${background_pid} -o 'pid=' -o 'cmd=' | grep './swift' | grep -v 'grep' | grep -v 'ps' | awk '{print $1;}')
-       #client_pid=$(ps --ppid ${background_pid} | grep -v '/bin/.*sh' | grep -v 'PID' | tail -1 | awk '{print $1;}')
        client_pid=$(pgrep -P ${background_pid})
        DEBUG echo "background_pid=${background_pid}; client_pid=${client_pid}"
-       #if ! test -z ${client_pid}; then # ps ended successfully
-
-#      pidof swift
-#      client_pid=$(pidof swift)
 
        if [ ! -z "$client_pid" ]; then
                break
@@ -152,7 +142,6 @@ fi
 
 # Monitor client's resources
 ./hook_monitor_pid.sh "$client_pid" >> $REMOTE_PATH/P2P-Testing-Infrastructure/ClientWorkingFolders/TmpLogs/$(hostname).log.mon 2>&1 &
-ps -ef
 mon_pid=$!
 
 old_time=${start_time}