-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.sh
132 lines (119 loc) · 3.66 KB
/
bench.sh
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
#!/bin/sh
# shellcheck disable=SC3000-SC4000
mode=$1
dest=$2
usage() {
echo "Usage: ${0} <mode> <destination> [show [<number>]|<iterations>]"
echo
echo "Mode is one of 'connect', 'send' or 'receive'."
echo
echo "Destination is a host name or IP, optionally prefixed by username@."
echo
echo "If 'show' is given, benchmarking is skipped and existing results are shown."
echo "The optional <number> specifies how many of the results are shown; by"
echo "default only the top 10 fastest are displayed."
echo
echo "Alternatively, if instead of 'show' a number is given for <iterations>,"
echo "the benchmark is run that many times before showing the results. The"
echo "<number> can in this case not be overridden."
echo
echo "Results shown are an average of all collected results for the given host/mode."
exit
}
if [ ! "$mode" ] ; then
echo 'Mode not specified!'
usage
fi
if [ ! "$dest" ] ; then
echo 'Dest not specified!'
usage
fi
kex=$(ssh -Q kex|grep -Ev -- '-(group-exchange|sha1|sha512|md5|nistp[^2])')
if [ -f "kex.lst" ] ; then
kex=$(cat kex.lst)
fi
macs=$(ssh -Q macs|grep -Ev -- '-(sha1|512|md5)')
if [ -f "macs.lst" ] ; then
macs=$(cat macs.lst)
fi
ciphers=$(ssh -Q cipher | grep -Ev -- '(3des|aes1[^2]|aes2)')
if [ -f "ciphers.lst" ] ; then
ciphers=$(cat ciphers.lst)
fi
case "$mode" in
'connect')
prefix=''
command='echo -n'
;;
'send')
prefix='dd if=/dev/zero bs=4k count=2048'
command='cat > /dev/null'
;;
'receive')
prefix=''
command='dd if=/dev/zero bs=4k count=2048'
;;
*)
echo "Mode must be one of connect, send, receive"
usage
;;
esac
showstats() {
local _dest="$1"
local _mode="$2"
local _top="$3"
local f
local headcmd="head -10"
if [ "${_top}" ] ; then
if top=$(echo "${_top}" | grep -Ev '[^0-9]' | grep -E '[0-9]') ; then
headcmd="head -${top}"
elif [ "${_top}" = 'all' ] ; then
headcmd="cat"
else
echo "Could not decipher number of lines to show (${_top}); ignoring"
fi
fi
if [ -d "$_dest" ] ; then
(
echo 'Destination Mode MAC Cipher KEX Time'
for f in "${_dest}"/"${_mode}"__*.log ; do
echo -n "$f " | sed -e 's/\.log//' -e 's/\// /'
cut -f 2 -w < "$f" | awk '{s+=$0}END{print s/NR}' RS=" "
done | sort -gk 3 | $headcmd | tr '_' ' '
) | column -t
else
echo "${_dest} directory not found!"
fi
}
runbench() {
mkdir -p "$dest"
for m in $macs ; do
for c in $ciphers ; do
for k in $kex ; do
echo
echo "${dest}/${mode}__${m}__${c}__${k}.log"
if [ "$prefix" ] ; then
$prefix 2>/dev/null | /usr/bin/time ssh -o MACs="$m" -o Ciphers="$c" -o KexAlgorithms="$k" "$dest" "${command} 2>/dev/null" 2>&1 >/dev/null |
tee -a "${dest}/${mode}__${m}__${c}__${k}.log"
else
/usr/bin/time ssh -o MACs="$m" -o Ciphers="$c" -o KexAlgorithms="$k" "$dest" "${command} 2>/dev/null" 2>&1 >/dev/null |
tee -a "${dest}/${mode}__${m}__${c}__${k}.log"
fi
sleep 0.1 || break
done
sleep 0.1 || break
done
sleep .01 || break
done
}
if ! [ "$3" = 'show' ] ; then
if iterations=$(echo "$3" | grep -Ev '[^0-9]' | grep -E '[0-9]') ; then
for i in $(jot -n "$iterations") ; do
echo "Executing iteration $i of $iterations .."
runbench
done
else
runbench
fi
fi
showstats "$dest" "$mode" "$4"