forked from facebook/wdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wdt_network_test.sh
executable file
·323 lines (285 loc) · 9.58 KB
/
wdt_network_test.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
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#! /bin/bash
# without the following line, wdt piped to tee effectively has exit status of
# tee. source : http://petereisentraut.blogspot.com/2010/11/pipefail.html
set -o pipefail
checkLastCmdStatus() {
LAST_STATUS=$?
if [ $LAST_STATUS -ne 0 ] ; then
sudo iptables-restore < $DIR/iptable
echo "exiting abnormally with status $LAST_STATUS - aborting/failing test"
exit $LAST_STATUS
fi
}
usage="
The possible options to this script are
-s sender protocol version
-r receiver protocol version
"
#protocol versions, used to check version verification
#version 0 represents default version
SENDER_PROTOCOL_VERSION=0
RECEIVER_PROTOCOL_VERSION=0
if [ "$1" == "-h" ]; then
echo "$usage"
exit 0
fi
while getopts ":s:r:" opt; do
case $opt in
s) SENDER_PROTOCOL_VERSION="$OPTARG"
;;
r) RECEIVER_PROTOCOL_VERSION="$OPTARG"
;;
h) echo "$usage"
exit
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
echo "sender protocol version $SENDER_PROTOCOL_VERSION, receiver protocol \
version $RECEIVER_PROTOCOL_VERSION"
threads=4
# starting port is different from default because e2e test and this test will be
# run in parallel during runtests.
STARTING_PORT=22400
ERROR_COUNT=25
TEST_COUNT=0
WDTBIN_OPTS="-ipv4 -ipv6=false -start_port=$STARTING_PORT \
-avg_mbytes_per_sec=60 -max_mbytes_per_sec=65 -run_as_daemon=false \
-full_reporting -read_timeout_millis=495 -write_timeout_millis=495 \
-progress_report_interval_millis=-1 -abort_check_interval_millis=100 \
-max_transfer_retries=5"
WDTBIN="_bin/wdt/wdt -num_ports=$threads $WDTBIN_OPTS"
WDTBIN_SERVER="$WDTBIN -protocol_version=$RECEIVER_PROTOCOL_VERSION"
WDTBIN_CLIENT="$WDTBIN -protocol_version=$SENDER_PROTOCOL_VERSION"
WDTBIN_MORE_THREADS="_bin/wdt/wdt -num_ports=$((threads + 1)) $WDTBIN_OPTS"
WDTBIN_LESS_THREADS="_bin/wdt/wdt -num_ports=$((threads - 1)) $WDTBIN_OPTS"
BASEDIR=/dev/shm/tmpWDT
mkdir -p $BASEDIR
DIR=`mktemp -d --tmpdir=$BASEDIR`
echo "Testing in $DIR"
#pkill -x wdt
mkdir -p $DIR/src/dir1
cp -R folly $DIR/src/dir1
for ((i = 2; i <= 200; i++))
do
mkdir $DIR/src/dir${i}
cp -R $DIR/src/dir1 $DIR/src/dir${i}
done
# Testing with different start ports
echo "Testing with different start ports in sender and receiver"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
_bin/wdt/wdt -ipv6=false -num_ports=$threads -start_port=$((STARTING_PORT + 1)) \
-destination $HOSTNAME -directory $DIR/src -full_reporting \
|& tee -a $DIR/client${TEST_COUNT}.log
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
TEST_COUNT=$((TEST_COUNT + 1))
# Testing with different less number of threads in sender
echo "Testing with less number of threads in client"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
_bin/wdt/wdt -ipv6=false -num_ports=$((threads - 1)) -start_port=$STARTING_PORT \
-destination $HOSTNAME -directory $DIR/src -full_reporting \
|& tee -a $DIR/client${TEST_COUNT}.log
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
TEST_COUNT=$((TEST_COUNT + 1))
echo "Testing with more number of threads in client"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
_bin/wdt/wdt -ipv6=false -num_ports=$((threads + 1)) -start_port=$STARTING_PORT \
-destination $HOSTNAME -directory $DIR/src -full_reporting \
|& tee -a $DIR/client${TEST_COUNT}.log
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
TEST_COUNT=$((TEST_COUNT + 1))
# Blocking sender port before transfer by
sudo iptables-save > $DIR/iptable
sudo iptables -A INPUT -p tcp --sport $STARTING_PORT -j DROP
echo "Testing with port blocked before transfer(1)"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
$WDTBIN_CLIENT -directory $DIR/src -destination $HOSTNAME |& tee -a \
$DIR/client${TEST_COUNT}.log
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
sudo iptables-restore < $DIR/iptable
TEST_COUNT=$((TEST_COUNT + 1))
sudo iptables-save > $DIR/iptable
sudo iptables -A INPUT -p tcp --dport $STARTING_PORT -j DROP
echo "Testing with port blocked before transfer(2)"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
$WDTBIN_CLIENT -directory $DIR/src -destination $HOSTNAME |& tee -a \
$DIR/client${TEST_COUNT}.log
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
sudo iptables-restore < $DIR/iptable
TEST_COUNT=$((TEST_COUNT + 1))
# Blocking a port in the middle of the transfer
echo "Testing by blocking a port in the middle of the transfer(1)"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
$WDTBIN_CLIENT -directory $DIR/src -destination $HOSTNAME |& tee -a \
$DIR/client${TEST_COUNT}.log &
pidofsender=$!
sleep 5
sudo iptables-save > $DIR/iptable
echo "blocking $STARTING_PORT"
sudo iptables -A INPUT -p tcp --sport $STARTING_PORT -j DROP
wait $pidofsender
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
sudo iptables-restore < $DIR/iptable
TEST_COUNT=$((TEST_COUNT + 1))
echo "Testing by blocking a port in the middle of the transfer(2)"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
$WDTBIN_CLIENT -directory $DIR/src -destination $HOSTNAME |& tee -a \
$DIR/client${TEST_COUNT}.log &
pidofsender=$!
sleep 5
sudo iptables-save > $DIR/iptable
echo "blocking $STARTING_PORT"
sudo iptables -A INPUT -p tcp --dport $((STARTING_PORT + 1)) -j DROP
wait $pidofsender
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
sudo iptables-restore < $DIR/iptable
TEST_COUNT=$((TEST_COUNT + 1))
echo "Testing by blocking a port in the middle of the transfer and more \
client threads"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
$WDTBIN_MORE_THREADS -directory $DIR/src -destination $HOSTNAME |& tee -a \
$DIR/client${TEST_COUNT}.log &
pidofsender=$!
sleep 5
sudo iptables-save > $DIR/iptable
echo "blocking $STARTING_PORT"
sudo iptables -A INPUT -p tcp --dport $((STARTING_PORT + 1)) -j DROP
wait $pidofsender
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
sudo iptables-restore < $DIR/iptable
TEST_COUNT=$((TEST_COUNT + 1))
echo "Testing by blocking a port in the middle of the transfer and less \
client threads"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
$WDTBIN_LESS_THREADS -directory $DIR/src -destination $HOSTNAME |& tee -a \
$DIR/client${TEST_COUNT}.log &
pidofsender=$!
sleep 5
sudo iptables-save > $DIR/iptable
echo "blocking $STARTING_PORT"
sudo iptables -A INPUT -p tcp --dport $((STARTING_PORT + 1)) -j DROP
wait $pidofsender
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
sudo iptables-restore < $DIR/iptable
TEST_COUNT=$((TEST_COUNT + 1))
# Simulating network glitches by rejecting packets
echo "Simulating network glitches by rejecting packets"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
$WDTBIN_CLIENT -directory $DIR/src -destination $HOSTNAME |& tee -a \
$DIR/client${TEST_COUNT}.log &
pidofsender=$!
for ((i = 1; i <= ERROR_COUNT; i++))
do
sleep 0.3 # sleep for 300ms
port=$((STARTING_PORT + RANDOM % threads))
echo "blocking $port"
sudo iptables-save > $DIR/iptable
if [ $(($i % 2)) -eq 0 ]; then
sudo iptables -A INPUT -p tcp --sport $port -j REJECT
else
sudo iptables -A INPUT -p tcp --dport $port -j REJECT
fi
sleep 0.7 # sleep for 700ms, read/write timeout is 500ms, so must sleep more
# than that
echo "unblocking $port"
sudo iptables-restore < $DIR/iptable
done
wait $pidofsender # wait for the sender to finish
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
TEST_COUNT=$((TEST_COUNT + 1))
# Simulating network glitches by dropping packets
echo "Simulating network glitches by dropping packets"
$WDTBIN_SERVER -directory $DIR/dst${TEST_COUNT} > \
$DIR/server${TEST_COUNT}.log 2>&1 &
pidofreceiver=$!
$WDTBIN_CLIENT -directory $DIR/src -destination $HOSTNAME |& tee -a \
$DIR/client${TEST_COUNT}.log &
pidofsender=$!
for ((i = 1; i <= ERROR_COUNT; i++))
do
sleep 0.3 # sleep for 300ms
port=$((STARTING_PORT + RANDOM % threads))
echo "blocking $port"
sudo iptables-save > $DIR/iptable
if [ $(($i % 2)) -eq 0 ]; then
sudo iptables -A INPUT -p tcp --sport $port -j DROP
else
sudo iptables -A INPUT -p tcp --dport $port -j DROP
fi
sleep 0.7 # sleep for 700ms, read/write timeout is 500ms, so must sleep more
# than that
echo "unblocking $port"
sudo iptables-restore < $DIR/iptable
done
wait $pidofsender # wait for the sender to finish
checkLastCmdStatus
wait $pidofreceiver
checkLastCmdStatus
TEST_COUNT=$((TEST_COUNT + 1))
STATUS=0
(cd $DIR/src ; ( find . -type f -print0 | xargs -0 md5sum | sort ) > ../src.md5s )
for ((i = 0; i < TEST_COUNT; i++))
do
(cd $DIR/dst${i} ; ( find . -type f -print0 | xargs -0 md5sum | sort ) > \
../dst${i}.md5s )
echo "Verifying correctness for test $((i + 1))"
echo "Should be no diff"
(cd $DIR; diff -u src.md5s dst${i}.md5s)
CUR_STATUS=$?
if [ $STATUS -eq 0 ] ; then
STATUS=$CUR_STATUS
fi
# treating PROTOCOL_ERROR as errors
cd $DIR; grep "PROTOCOL_ERROR" server${i}.log > /dev/null && STATUS=1
cd $DIR; grep "PROTOCOL_ERROR" client${i}.log > /dev/null && STATUS=1
cat $DIR/server${i}.log
done
if [ $STATUS -eq 0 ] ; then
echo "Good run, deleting logs in $DIR"
find $DIR -type d | xargs chmod 755 # cp -r makes lib/locale not writeable somehow
rm -rf $DIR
else
echo "Bad run ($STATUS) - keeping full logs and partial transfer in $DIR"
fi
exit $STATUS