initial commit: add scripts
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sun, 21 Nov 2010 19:37:22 +0000 (21:37 +0200)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Sun, 21 Nov 2010 19:37:22 +0000 (21:37 +0200)
config [new file with mode: 0644]
hook_monitor_pid [new file with mode: 0755]
local_start_swift_leecher [new file with mode: 0755]
local_start_swift_seeder [new file with mode: 0755]
local_start_utp_receiver [new file with mode: 0755]
local_start_utp_sender [new file with mode: 0755]
remote_start_swift_session [new file with mode: 0755]
remote_start_utp_session [new file with mode: 0755]

diff --git a/config b/config
new file mode 100644 (file)
index 0000000..f1d77c0
--- /dev/null
+++ b/config
@@ -0,0 +1,22 @@
+SEEDER_DATA=/home/p2p/razvan/seeder/Data.700M.bin
+LEECHER_DIR=/home/p2p/razvan/leecher/
+LEECHER_DATA=/home/p2p/razvan/leecher/Data.700M.bin
+DATA_HASH=261d3ff85652eb50a4bb294a2d2611c3148c3adf
+
+UTP_RECEIVER=/home/p2p/p2p-clients/utp/libutp/utp_files/utp_recv
+UTP_SENDER=/home/p2p/p2p-clients/utp/libutp/utp_files/utp_send
+UTP_RECEIVER_PORT=12345
+UTP_SENDER_OUT_LOG=/home/p2p/razvan/seeder/$(hostname)_utp-sender_$(date %F-%M).log
+UTP_RECEIVER_OUT_LOG=/home/p2p/razvan/leecher/$(hostname)_utp-receiver_$(date %F-%M).log
+UTP_SENDER_MONITOR_LOG=/home/p2p/razvan/seeder/$(hostname)_utp-sender_$(date %F-%M).log
+UTP_RECEIVER_MONITOR_LOG=/home/p2p/razvan/leecher/$(hostname)_utp-receiver_$(date %F-%M).log
+UTP_SENDER_LOG_FILE=/home/p2p/razvan/seeder/mon_$(hostname)_utp-sender_$(date %F-%M).log
+UTP_RECEIVER_LOG_FILE=/home/p2p/razvan/leecher/mon_$(hostname)_utp-receiver_$(date %F-%M).log
+
+SWIFT=/home/p2p/p2p-clients/swift/swift
+SWIFT_SEEDER_PORT=13337
+SWIFT_LEECHER_PORT=13338
+SWIFT_SEEDER_OUT_LOG=/home/p2p/razvan/seeder/$(hostname)_swift-seeder_$(date %F-%M).log
+SWIFT_LEECHER_OUT_LOG=/home/p2p/razvan/seeder/$(hostname)_swift-leecher_$(date %F-%M).log
+SWIFT_SEEDER_MONITOR_LOG=/home/p2p/razvan/seeder/$(hostname)_swift-seeder_$(date %F-%M).log
+SWIFT_LEECHER_MONITOR_LOG=/home/p2p/razvan/seeder/$(hostname)_swift-leecher_$(date %F-%M).log
diff --git a/hook_monitor_pid b/hook_monitor_pid
new file mode 100755 (executable)
index 0000000..435251d
--- /dev/null
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+#
+# monitor process resources using systat (/proc), free, iptables and /sys
+#
+# 2010, Razvan Deaconescu, razvan.deaconescu@cs.pub.ro
+#
+
+# command line argument must be a process id
+if test $# -ne 1; then
+       echo "Usage: $0 <pid>" 1>&2
+       exit 1
+fi
+
+pid=$1
+
+# check if pid exists
+kill -0 $pid > /dev/null 2>&1
+if test $? -ne 0; then
+       echo -e "PID $pid does not exists.\nUsage: $0 <pid>" 1>&2
+       exit 1
+fi
+
+# use _DEBUG="off" to turn off debug printing
+_DEBUG="off"
+
+# cleanup code (run as signal handler)
+cleanup()
+{
+       kill -TERM $pidstat_pid
+       kill -TERM $iostat_pid
+       kill -TERM $free_pid
+       kill -TERM $timer_callback_pid
+}
+
+# function acting like a periodic callback
+timer_callback()
+{
+       while true; do
+               date +%F-%X
+               sudo iptables -t filter -L -n -v
+               cat /sys/class/net/eth0/statistics/rx_bytes /sys/class/net/eth0/statistics/tx_bytes
+               sleep 1
+       done
+}
+
+# run cleanup on signal receive
+trap cleanup 0 1 2 3 15
+
+# per-process processor (-u), disk (-d) and memory usage (-r)
+pidstat -u -d -r -p $pid 1 &
+pidstat_pid=$!
+
+# per-system (iostat and free)
+iostat -d -c 1 &
+iostat_pid=$!
+free -s 1 &
+free_pid=$!
+
+# per-process network bandwidth usage (iptables)
+# /sys/class/net/$iface/statistics/{tx,rx}_bytes (per system)
+
+# remove old iptables rules/chains
+sudo iptables -t filter -F udp_out > /dev/null 2>&1
+sudo iptables -t filter -F udp_in > /dev/null 2>&1
+sudo iptables -t filter -X udp_out > /dev/null 2>&1
+sudo iptables -t filter -X udp_in > /dev/null 2>&1
+sudo iptables -t filter -F OUTPUT > /dev/null 2>&1
+
+# add iptables rule
+sudo iptables -t filter -N udp_out
+sudo iptables -t filter -N udp_in
+sudo iptables -t filter -A OUTPUT -p udp -j udp_out
+sudo iptables -t filter -A udp_out -j ACCEPT
+sudo iptables -t filter -A OUTPUT -p udp -j udp_in
+sudo iptables -t filter -A udp_in -j ACCEPT
+
+timer_callback &
+timer_callback_pid=$!
+
+# wait for child processes to end (shouldn't happen)
+wait
diff --git a/local_start_swift_leecher b/local_start_swift_leecher
new file mode 100755 (executable)
index 0000000..c307b3e
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/bash
+
+if test $# -ne 1; then
+       echo "Usage: $0 seeder-ip" 1>&2
+       exit 1
+fi
+
+seeder_ip=$1
+
+cleanup()
+{
+       kill -TERM $client_pid > /dev/null 2>&1
+       kill -TERM $hook_pid > /dev/null 2>&1
+}
+
+# wait for seeder startup
+sleep 30
+
+pushd $LEECHER_DIR
+
+> $SWIFT_LEECHER_OUT_LOG
+> $SWIFT_LEECHER_MONITOR_LOG
+
+# start client
+cd $LEECHER_DIR
+$SWIFT -l $SWIFT_LEECHER_PORT -t $seeder_ip:$SWIFT_SEEDER_PORT -h $DATA_HASH -p >> $SWIFT_LEECHER_OUT_LOG 2>&1 &
+client_pid=$!
+
+popd
+
+# start monitoring on pid
+./hook_monitor_pid $client_pid >> $SWIFT_LEECHER_MONITOR_LOG 2>&1 &
+hook_pid=$!
+
+trap cleanup 0 1 2 3 15
+
+wait
diff --git a/local_start_swift_seeder b/local_start_swift_seeder
new file mode 100755 (executable)
index 0000000..2e4a668
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+if test $# -ne 1; then
+       echo "Usage: $0 local-ip" 1>&2
+       exit 1
+fi
+
+local_ip=$1
+
+cleanup()
+{
+       kill -TERM $client_pid > /dev/null 2>&1
+       kill -TERM $hook_pid > /dev/null 2>&1
+}
+
+> $SWIFT_SEEDER_OUT_LOG
+> $SWIFT_SEEDER_MONITOR_LOG
+
+# start client
+$SWIFT -l $local_ip:$SWIFT_SEEDER_PORT -f $SEEDER_DATA -p >> $SWIFT_SEEDER_OUT_LOG 2>&1 &
+client_pid=$!
+
+# wait for hash check and initial startup
+sleep 20
+
+# start monitoring on pid
+./hook_monitor_pid $client_pid >> $SWIFT_SEEDER_MONITOR_LOG 2>&1 &
+hook_pid=$!
+
+trap cleanup 0 1 2 3 15
+
+wait
diff --git a/local_start_utp_receiver b/local_start_utp_receiver
new file mode 100755 (executable)
index 0000000..3570efa
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+cleanup()
+{
+       kill -TERM $client_pid > /dev/null 2>&1
+       kill -TERM $hook_pid > /dev/null 2>&1
+}
+
+> $UTP_RECEIVER_OUT_LOG
+> $UTP_RECEIVER_LOG_FILE
+> $UTP_RECEIVER_MONITOR_LOG
+
+# start client
+$UTP_RECEIVER $UTP_RECEIVER_LOG_FILE $UTP_RECEIVER_PORT $LEECHER_DATA >> $UTP_RECEIVER_OUT_LOG 2>&1 &
+client_pid=$!
+
+# start monitoring on pid
+./hook_monitor_pid $client_pid >> $UTP_RECEIVER_MONITOR_LOG 2>&1 &
+hook_pid=$!
+
+trap cleanup 0 1 2 3 15
+
+wait
diff --git a/local_start_utp_sender b/local_start_utp_sender
new file mode 100755 (executable)
index 0000000..c212650
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+if test $# -ne 1; then
+       echo "Usage: $0 receiver_ip" 1>&2
+       exit 1
+fi
+
+cleanup()
+{
+       kill -TERM $client_pid > /dev/null 2>&1
+       kill -TERM $hook_pid > /dev/null 2>&1
+}
+
+> $UTP_SENDER_OUT_LOG
+> $UTP_SENDER_LOG_FILE
+> $UTP_SENDER_MONITOR_LOG
+
+# start client
+$UTP_SENDER $UTP_SENDER_LOG_FILE $receiver_ip:$UTP_RECEIVER_PORT $SEEDER_DATA >> $UTP_SENDER_OUT_LOG 2>&1 &
+client_pid=$!
+
+# start monitoring on pid
+./hook_monitor_pid $client_pid >> $UTP_SENDER_MONITOR_LOG 2>&1 &
+hook_pid=$!
+
+trap cleanup 0 1 2 3 15
+
+wait
diff --git a/remote_start_swift_session b/remote_start_swift_session
new file mode 100755 (executable)
index 0000000..2c32380
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+if test $# -ne 1; then
+       echo "Usage: $0 seeder_ip leecher_ip" 1>&2
+       exit 1
+fi
+
+seeder_ip=$1
+leecher_ip=$2
+
+# start
+ssh -n -f p2p@$seeder_ip "/home/p2p/razvan/scripts/local_start_swift_seeder $seeder_ip"
+ssh -n -f p2p@$leecher_ip "/home/p2p/razvan/scripts/local_start_swift_leecher $seeder_ip"
+
+sleep 180
+
+# stop
+ssh -n -f p2p@$seeder_ip "pkill -f local_start_swift_seeder"
+ssh -n -f p2p@$leecher_ip "pkill -f local_start_swift_leecher"
diff --git a/remote_start_utp_session b/remote_start_utp_session
new file mode 100755 (executable)
index 0000000..0b40fc6
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+if test $# -ne 1; then
+       echo "Usage: $0 sender_ip receiver_ip" 1>&2
+       exit 1
+fi
+
+sender_ip=$1
+receiver_ip=$2
+
+# start
+ssh -n -f p2p@$sender_ip "/home/p2p/razvan/scripts/local_start_utp_sender $receiver_ip"
+ssh -n -f p2p@$receiver_ip "/home/p2p/razvan/scripts/local_start_utp_receiver"
+
+sleep 180
+
+# stop
+ssh -n -f p2p@$sender_ip "pkill -f local_start_utp_sender"
+ssh -n -f p2p@$receiver_ip "pkill -f local_start_utp_receiver"