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 .
+
fi
pkill -KILL -f transmission-cli
+
+# Kill transport level delay measurement.
+sudo kill -INT $(cat /tmp/pid)
--- /dev/null
+#!/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())
--- /dev/null
+#!/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())
--- /dev/null
+#!/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();
+}
--- /dev/null
+http://vger.kernel.org/~davem/tcp_output.html
+http://lxr.linux.no/#linux+v2.6.39/net/ipv4/
--- /dev/null
+#!/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
+
--- /dev/null
+#!/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
--- /dev/null
+#!/bin/bash
+
+while true; do
+ sleep 5
+ wget http://141.85.37.41/~cburloiu/sample.txt
+ rm sample*
+done
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"
# 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()
{
# 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
# 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}