-
Notifications
You must be signed in to change notification settings - Fork 0
/
tubetest
executable file
·163 lines (147 loc) · 4.92 KB
/
tubetest
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/ksh
#
# dependencies: pv, socat
# invoke with
# ./tubetest your.server.org 1080 6991 1080 8888
log="tubetest.log"
debug=/bin/false
testserver=$1; shift 1
function cleanup {
# is a bit drastic, let's hope there are no other socat instances
# running on the testserver
ssh -q $testserver killall socat 2>/dev/null
}
function getownip {
ssh -q $testserver socat TCP4-LISTEN:4000,pktinfo,reuseaddr system:'"echo \"\\\"\$SOCAT_PEERADDR\\\"\""' &
socat tcp4:$testserver:4000,reuseaddr,retry=3,interval=3 -
}
function startlocalsink {
port=$1
# client to receive tcp stream
$debug && print "\tstarting local sink"
echo 'asdf' | socat "$proto"4:$testserver:$port,retry=3,interval=3 - 2>/dev/null |
pv -ftrab 2>&1 >/dev/null |&
}
function startlocalsource {
port=$1
# client sending constant stream of random data
$debug && print "\tstarting local random source"
[[ "$proto" == "tcp" ]] && { bsize="" ; retry=",retry=3,interval=3"; } || { retry="" ; bsize="-b 1472"; }
(openssl enc -aes-128-ofb -k $RANDOM -in /dev/zero 2>/dev/null |
pv -ftrab |
socat $bsize - "$proto"4:$testserver:$port$retry >/dev/null 2>/dev/null) 2>&1 |&
}
function startremotesink {
port=$1
# server acting as sink for sent data
$debug && print "\tstarting remote sink"
ssh -q $testserver socat "$proto"4-listen:$port,reuseaddr /dev/null 2>/dev/null &
}
function startremotesource {
port=$1
# server sending constant stream of random numbers
$debug && print "\tstarting remote random source"
ssh -q $testserver socat exec:\"openssl enc -aes-128-ofb -k $RANDOM -in /dev/zero\" "$proto"4-listen:$port,reuseaddr 2>/dev/null &
}
function startlocaludpsink {
port=$1
# client to receive tcp stream
$debug && print "\tstarting local sink"
socat udp4-recv:$port,reuseaddr - 2>/dev/null |
pv -ftrab 2>&1 >/dev/null |&
}
function startremoteudpsource {
[[ -z "$ownip" ]] && ownip=$(getownip)
port=$1
timer=$2
# server sending constant stream of random numbers
$debug && print "\tstarting remote random source"
ssh -q $testserver socat -b 1472 exec:\"openssl enc -aes-128-ofb -k $RANDOM -in /dev/zero\" udp4-sendto:$ownip:$port,reuseaddr \& \; sleep $timer \; kill '$!' &
}
function throughput {
direction=$1
port=$2
timer=${3:-30}
cleanup
if [[ "$proto" == "udp" ]]; then
if [[ "$direction" == "down" ]]; then
startlocaludpsink $port
pid=$!
startremoteudpsource $port $timer
else
# UP
startremotesink $port
sleep 1
startlocalsource $port
pid=$!
fi
else
# TCP
if [[ "$direction" == "down" ]]; then
startremotesource $port
sleep 1
startlocalsink $port
pid=$!
else
# UP
startlocalsource $port
pid=$!
startremotesink $port
fi
fi
printf "\t[%4s] for ${timer}s " $direction
printf "$(date --rfc-3339=ns|tr ' ' 't') $proto $port $direction ${timer}s\n" >>$log
# start progress feedback
(i=0; while [[ $i -le $timer ]] do printf "%3d%%" $(($i*100/$timer)); i=$((i+1)); sleep 1; done) &
# set timer
(sleep $timer; kill $pid ) &
# print metrix
sparkline=""; max=""; maxs=""; min=""; mins=""; avg=""
cat <&p | sed 's/\r/\n/g' | while read line; do
[[ -z "$line" ]] && continue
# lineformat example: 1.97MB 0:00:00 [ 580kB/s] [ 504kB/s]
s=$(echo "$line" | sed 's/.*\[\([^]]*\)].*/\1/') # extract human readable speed
m=$(echo "$s" | sed 's/.*\(.\)...$/\1/' | tr '[:upper:]' '[:lower:]') # get kilo/mega modifier
v=$(echo "$s" | sed 's/\(.*\)....$/\1/') # get speed
b=$(./kilo.awk $v $m b) # convert to speed to bytes/s
sparkline="$sparkline $b"
[[ -z "$max" || "$max" -lt "$b" ]] && {
maxs="$s"
max="$b"
}
[[ -z "$min" || "$min" -gt "$b" ]] && {
mins="$s"
min="$b"
}
avg=$(echo "$line" | sed 's/.*] \[\([^]]*\)].*/\1/') # extract human readable speed
t=$(echo "$line" | cut -d' ' -f2) # surgeon extraction
print "$t $s $avg" >>$log
done
printf " $mins(min) $avg(avg) $maxs(max) "
print "$(date --rfc-3339=ns) results $mins(min) $avg(avg) $maxs(max)" >>$log
./spark $sparkline
cleanup
}
cleanup
trap cleanup KILL TERM
proto="tcp"
len="10"
ownip=''
while [[ "$#" -gt 0 ]]; do
[[ "$1" == "udp" || "$1" == "tcp" ]] && {
proto="$1"
print "changing proto to $proto"
shift 1
continue
}
print "$1" | egrep -qs "^[0-9]+s" && {
len=$(echo "$1" | sed 's/\(.*\)s$/\1/')
print "adjusting timelimit to $len"
shift 1
continue
}
print "testing $proto/$1"
throughput down "$1" "$len"
throughput up "$1" "$len"
shift 1
done