-
Notifications
You must be signed in to change notification settings - Fork 3
/
iperf-client
executable file
·287 lines (266 loc) · 7.64 KB
/
iperf-client
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
exec >iperf-client-stderrout.txt
exec 2>&1
. /usr/bin/iperf-base || (echo "/usr/bin/iperf-base not found"; exit 1)
dump_runtime
validate_label
validate_sw_prereqs jq ss iperf3 getopt ip
# defaults
ifname=""
protocol=""
length=""
time=10
bit_rate=None
remotehost=""
control_port=""
data_port=""
cpu_pin=""
pt_opts=""
ipv="4"
bstart=0
bend=0
bitrate_range=
max_loss_pct=0
omit=0
echo "opts before: $@"
longopts="ipv:,ifname:,protocol:,length:,remotehost:,time:,bitrate:,cpu-pin:,passthru:,bitrate-range:,max-loss-pct:,omit:"
opts=$(getopt -q -o "" --longoptions "$longopts" -n "getopt.sh" -- "$@");
if [ $? -ne 0 ]; then
exit_error "Unrecognized option specified"
fi
eval set -- "$opts";
echo "opts after: $@"
while true; do
case "$1" in
--ipv)
shift;
ipv="$1"
echo "ipv=$ipv"
shift
;;
--ifname)
shift;
ifname="$1"
echo "ifname=$ifname"
shift
;;
--cpu-pin)
shift;
cpu_pin=$1
echo "cpu_pin=${cpu_pin}"
shift;
;;
--protocol)
shift;
if [ "$1" == "udp" ]; then
protocol="--udp"
fi
echo "protocol=$protocol"
shift
;;
--length)
shift;
length="--length $1"
echo "length=$length"
shift
;;
--bitrate)
shift;
bit_rate=$1
echo "bitrate=$bit_rate"
shift
;;
--max-loss-pct)
shift;
max_loss_pct=$1
echo "max-loss-pct=$max-loss-pct"
shift
;;
--remotehost)
shift;
remotehost=$1
echo "remotehost=$remotehost"
shift
;;
--time)
shift;
time=$1
echo "time=$time"
shift
;;
--passthru) # iperf options that user wants passthru
shift;
pt_opts=$1
echo "pt_opts=$pt_opts"
shift
;;
--bitrate-range) # iperf zero-drop hunt
shift;
bitrate_range=$1
echo "bitrate-range=$bitrate_range"
bstart=$(echo $bitrate_range | awk -F'-' '{print $1}')
bend=$(echo $bitrate_range | awk -F'-' '{print $2}')
shift
;;
--omit) # skip first number of seconds
shift;
omit=$1
echo "omit=$omit"
shift
;;
--)
shift;
break
;;
*)
exit_error "Invalid option: $1"
esac
done
case "${cpu_pin}" in
""|"numa"|"cpu-numa")
;;
*)
exit_error "unsupported cpu-pin value '${cpu_pin}'"
;;
esac
uname -a
# Unless the user specifies a specific remotehost argument, this must
# be sourced from the endpoint (which gets it from the client)
if [ -z "$remotehost" ]; then
echo "--remotehost was not set via cmdline args, checking any messages from the endpoint"
echo "These files exist in ./msgs/rx:"
/bin/ls -l msgs/rx
file="msgs/rx/endpoint-start-end:1"
if [ ! -e "${file}" ]; then
# File exists when EP created SVC to frontend server.
# EP does not create SVC when hostNetwork or remotehost server
# in which cases server IP is in server-start-end:1
file="msgs/rx/server-start-end:1"
fi
if [ -e "$file" ]; then
echo "Found $file"
ipaddr=`jq -r '.svc.ip' $file`
if [ ! -z "$ipaddr" ]; then
echo "Found server IP $ipaddr"
remotehost=$ipaddr
fi
port=`jq -r '.svc.ports[0]' $file`
if [ ! -z "$port" ]; then
echo "Found server control port $port"
control_port=$port
fi
port=`jq -r '.svc.ports[1]' $file`
if [ ! -z "$port" ]; then
echo "Found server data port $port"
data_port=$port
fi
else
echo "Did not find $file, so cannot get an IP from the server/endpoint"
fi
fi
# Confirm we have a remotehost (server) and ports
if [ -z "$remotehost" ]; then
exit_error "remotehost is not set"
fi
# TODO: validate $remotehost with regex
#
# The cpu_pin="cpu-numa" mode, pin client and server to a CPU.
# If they colocate (INTRA-xxx), they should also be on the same NUMA.
#
ifname=$(ip route get ${remotehost} | head -n 1 | awk -F" dev " '{ print $2 }' | awk -F" src " '{ print $1 }')
if [ ! -e /sys/class/net/${ifname} ]; then
exit_error "invalid interface '${ifname}' found"
fi
ifname_numa_node=
ifname_numa_node_cpus=
if [ -e /sys/class/net/${ifname}/device/numa_node ]; then
ifname_numa_node=$(cat /sys/class/net/${ifname}/device/numa_node)
if [ "$ifname_numa_node" == "-1" ]; then
# VM case, use numa 0
ifname_numa_node=0
fi
else
# If there is no numa associated with ifname, just use numa 0.
ifname_numa_node=0
fi
ifname_numa_node_cpus=$(cat /sys/devices/system/node/node${ifname_numa_node}/cpulist)
# convert to comma separated list if there are ranges i.e 0-5 items
ifname_numa_node_cpus=$(echo $ifname_numa_node_cpus | perl -pe 's/(\d+)-(\d+)/join(",",$1..$2)/eg')
echo "ifname=${ifname}"
echo "ifname_numa_node=${ifname_numa_node}"
echo "ifname_numa_node_cpus=${ifname_numa_node_cpus}"
# These ports should come from the endpoint, but if for some
# reason they don't the default port numbers are calculated
# in this way:
if [ -z "$control_port" ]; then
let "control_port = 2 * $id"
let "control_port = $control_port + 30000"
echo "control_port was not set, using default of $control_port"
fi
if [ -z "$data_port" ]; then
let "data_port = $control_port + 1"
echo "data_port was not set, using default of $data_port"
fi
echo "ifname=${ifname}"
echo "ifname_numa_node=${ifname_numa_node}"
echo "remotehost=$remotehost"
echo "control_port=$control_port"
echo "data_port=$data_port"
echo "time=$time"
echo "length=$length"
echo "protocol=$protocol"
cpu_pin_cmd=""
case "${cpu_pin}" in
"numa")
cpu_pin_cmd="taskset --cpu-list ${ifname_numa_node_cpus}"
;;
"cpu-numa")
assign-pin-cpu client ${ifname_numa_node_cpus}
;;
esac
options="--format k -c $remotehost -p $control_port $protocol $length --get-server-output"
if [ "$omit" -ne 0 ]; then
options+=" --omit $omit"
fi
#options+=" --cport $data_port"
# strip ',' from the passthru options
passthru_opts=$(echo "$pt_opts" | sed 's/,/ /g')
options+=" $passthru_opts"
time_opt="-t $time"
# If passthru has --time or -t, let it override our $time value
for p in ${passthru_opts}; do
if echo "$p" | grep -Eq '\-t[0-9]|\-\-time'; then
echo "passthru $p overrides time=$time"
time_opt=""
break
fi
done
options+=" $time_opt"
if [ $bit_rate != None ]; then
options+=" --bitrate $bit_rate"
fi
cmd+="${cpu_pin_cmd} iperf3 $options"
if [ "$ipv" == "6" ]; then
cmd+=" -6"
fi
echo "going to run: ${cmd}"
if [ "$bitrate_range" != "" ]; then
# We are in a hunting run
source /usr/bin/iperf-hunter
echo "Hunting for zero drop"
#extract the last char, the unit i.e KMG
unit=$(echo ${bstart: -1})
bstart=${bstart::-1}
bend=${bend::-1}
echo "HUNTING begin:" > iperf-client-result.txt
generic-hunter --begin $bstart --end $bend --max-loss-pct $max_loss_pct iperf-drop-hunter $unit
exit
fi
echo BEGIN-TS-0 $(date +%s.%N) > iperf-client-result.txt
${cmd} 2>&1 >> iperf-client-result.txt
iperf_rc=$?
echo END-TS-0 $(date +%s.%N) >> iperf-client-result.txt
if [ $iperf_rc -gt 0 ]; then
iperf_errors=`grep -i error iperf-client-result.txt`
exit_error "$iperf_errors"
fi