Whamcloud - gitweb
LU-16998 lnet: Error when missing discover arg
[fs/lustre-release.git] / lustre / tests / sanity-lnet.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10
11 # bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
16
17 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
18
19 . $LUSTRE/tests/test-framework.sh
20 CLEANUP=${CLEANUP:-:}
21 SETUP=${SETUP:-:}
22 init_test_env "$@"
23 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
24 init_logging
25
26 build_test_filter
27
28 [[ -z $LNETCTL ]] && skip "Need lnetctl"
29
30 restore_mounts=false
31
32 if is_mounted $MOUNT || is_mounted $MOUNT2; then
33         cleanupall || error "Failed cleanup prior to test execution"
34         restore_mounts=true
35 fi
36
37 cleanup_lnet() {
38         echo "Cleaning up LNet"
39         lsmod | grep -q lnet &&
40                 $LNETCTL lnet unconfigure 2>/dev/null
41         unload_modules
42 }
43
44 restore_modules=false
45 if module_loaded lnet ; then
46         cleanup_lnet || error "Failed to unload modules before test execution"
47         restore_modules=true
48 fi
49
50 cleanup_testsuite() {
51         trap "" EXIT
52         # Cleanup any tmp files created by the sub tests
53         rm -f $TMP/sanity-lnet-*.yaml $LNET_PARAMS_FILE
54         cleanup_netns
55         cleanup_lnet
56         if $restore_mounts; then
57                 setupall || error "Failed to setup Lustre after test execution"
58         elif $restore_modules; then
59                 load_modules ||
60                         error "Couldn't load modules after test execution"
61         fi
62         return 0
63 }
64
65 TESTNS='test_ns'
66 FAKE_IF="test1pg"
67 FAKE_IP="10.1.2.3"
68 do_ns() {
69         echo "ip netns exec $TESTNS $*"
70         ip netns exec $TESTNS "$@"
71 }
72
73 setup_fakeif() {
74         local netns="$1"
75
76         local netns_arg=""
77         [[ -n $netns ]] &&
78                 netns_arg="netns $netns"
79
80         ip link add 'test1pl' type veth peer name $FAKE_IF $netns_arg
81         ip link set 'test1pl' up
82         if [[ -n $netns ]]; then
83                 do_ns ip addr add "${FAKE_IP}/31" dev $FAKE_IF
84                 do_ns ip link set $FAKE_IF up
85         else
86                 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
87                 ip link set $FAKE_IF up
88         fi
89 }
90
91 cleanup_fakeif() {
92         ip link show test1pl >& /dev/null && ip link del test1pl || return 0
93 }
94
95 setup_netns() {
96         cleanup_netns
97
98         ip netns add $TESTNS
99         setup_fakeif $TESTNS
100 }
101
102 cleanup_netns() {
103         (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
104         cleanup_fakeif
105 }
106
107 configure_dlc() {
108         echo "Loading LNet and configuring DLC"
109         load_lnet || return $?
110         do_lnetctl lnet configure
111 }
112
113 GLOBAL_YAML_FILE=$TMP/sanity-lnet-global.yaml
114 define_global_yaml() {
115         $LNETCTL export --backup >${GLOBAL_YAML_FILE} ||
116                 error "Failed to export global yaml $?"
117 }
118
119 reinit_dlc() {
120         if lsmod | grep -q lnet; then
121                 do_lnetctl lnet unconfigure ||
122                         error "lnetctl lnet unconfigure failed $?"
123                 do_lnetctl lnet configure ||
124                         error "lnetctl lnet configure failed $?"
125         else
126                 configure_dlc || error "configure_dlc failed $?"
127         fi
128         define_global_yaml
129 }
130
131 append_global_yaml() {
132         [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
133                 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
134
135         cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
136 }
137
138 create_base_yaml_file() {
139         append_global_yaml
140 }
141
142 compare_yaml_files() {
143         local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
144         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
145         local rc=0
146         ! [[ -e $expected ]] && echo "$expected not found" && return 1
147         ! [[ -e $actual ]] && echo "$actual not found" && return 1
148         if [ verify_yaml_available ]; then
149                 verify_compare_yaml $actual $expected || rc=$?
150         else
151                 diff -upN ${actual} ${expected} || rc=$?
152         fi
153         echo "Expected:"
154         cat $expected
155         echo "Actual:"
156         cat $actual
157         return $rc
158 }
159
160 validate_nid() {
161         local nid="$1"
162         local net="${nid//*@/}"
163         local addr="${nid//@*/}"
164
165         local num_re='[0-9]+'
166         local ip_re="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
167
168         if [[ $net =~ (gni|kfi)[0-9]* ]]; then
169                 [[ $addr =~ ${num_re} ]] && return 0
170         else
171                 [[ $addr =~ ${ip_re} ]] && return 0
172         fi
173 }
174
175 validate_nids() {
176         local yfile=$TMP/sanity-lnet-$testnum-actual.yaml
177         local primary_nids=$(awk '/- primary nid:/{print $NF}' $yfile | xargs echo)
178         local secondary_nids=$(awk '/- nid:/{print $NF}' $yfile | xargs echo)
179         local gateway_nids=$(awk '/gateway:/{print $NF}' $yfile | xargs echo)
180
181         local nid
182         for nid in $primary_nids $secondary_nids; do
183                 validate_nid "$nid" || error "Bad NID \"${nid}\""
184         done
185         return 0
186 }
187
188 validate_peer_nids() {
189         local num_peers="$1"
190         local nids_per_peer="$2"
191
192         local expect_p="$num_peers"
193         # The primary nid also shows up in the list of secondary nids
194         local expect_s="$(($num_peers + $(($nids_per_peer*$num_peers))))"
195
196         local actual_p=$(grep -c -- '- primary nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
197         local actual_s=$(grep -c -- '- nid:' $TMP/sanity-lnet-$testnum-actual.yaml)
198         if [[ $expect_p -ne $actual_p ]]; then
199                 compare_yaml_files
200                 error "Expected $expect_p but found $actual_p primary nids"
201         elif [[ $expect_s -ne $actual_s ]]; then
202                 compare_yaml_files
203                 error "Expected $expect_s but found $actual_s secondary nids"
204         fi
205         validate_nids
206 }
207
208 validate_gateway_nids() {
209         local expect_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-expected.yaml)
210         local actual_gw=$(grep -c -- 'gateway:' $TMP/sanity-lnet-$testnum-actual.yaml)
211         if [[ $expect_gw -ne $actual_gw ]]; then
212                 compare_yaml_files
213                 error "Expected $expect_gw gateways but found $actual_gw gateways"
214         fi
215
216         local expect_gwnids=$(awk '/gateway:/{print $NF}' $TMP/sanity-lnet-$testnum-expected.yaml |
217                               xargs echo)
218         local nid
219         for nid in ${expect_gwnids}; do
220                 if ! grep -q "gateway: ${nid}" $TMP/sanity-lnet-$testnum-actual.yaml; then
221                         error "${nid} not configured as gateway"
222                 fi
223         done
224
225         validate_nids
226 }
227
228 cleanupall -f
229 setup_netns || error "setup_netns failed with $?"
230
231 # Determine the local interface(s) used for LNet
232 load_lnet "config_on_load=1" || error "Failed to load modules"
233
234 do_lnetctl net show
235 ip a
236
237 INTERFACES=( $(lnet_if_list) )
238
239 cleanup_lnet || error "Failed to cleanup LNet"
240
241 stack_trap 'cleanup_testsuite' EXIT
242
243 test_0() {
244         configure_dlc || error "Failed to configure DLC rc = $?"
245         define_global_yaml
246         reinit_dlc || return $?
247         do_lnetctl import <  ${GLOBAL_YAML_FILE} || error "Import failed $?"
248         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
249         create_base_yaml_file
250         compare_yaml_files || error "Configuration changed after import"
251 }
252 run_test 0 "Export empty config, import the config, compare"
253
254 compare_peer_add() {
255         local prim_nid="${1:+--prim_nid $1}"
256         local nid="${2:+--nid $2}"
257
258         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
259
260         do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
261         $LNETCTL export --backup > $actual || error "export failed $?"
262         compare_yaml_files
263         return $?
264 }
265
266 test_1() {
267         reinit_dlc || return $?
268         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
269 peer:
270     - primary nid: 1.1.1.1@tcp
271       Multi-Rail: True
272       peer ni:
273         - nid: 1.1.1.1@tcp
274 EOF
275         append_global_yaml
276         compare_peer_add "1.1.1.1@tcp"
277 }
278 run_test 1 "Add peer with single nid (tcp)"
279
280 test_2() {
281         reinit_dlc || return $?
282         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
283 peer:
284     - primary nid: 2.2.2.2@o2ib
285       Multi-Rail: True
286       peer ni:
287         - nid: 2.2.2.2@o2ib
288 EOF
289         append_global_yaml
290         compare_peer_add "2.2.2.2@o2ib"
291 }
292 run_test 2 "Add peer with single nid (o2ib)"
293
294 test_3() {
295         reinit_dlc || return $?
296         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
297 peer:
298     - primary nid: 3.3.3.3@tcp
299       Multi-Rail: True
300       peer ni:
301         - nid: 3.3.3.3@tcp
302         - nid: 3.3.3.3@o2ib
303 EOF
304         append_global_yaml
305         compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
306 }
307 run_test 3 "Add peer with tcp primary o2ib secondary"
308
309 test_4() {
310         reinit_dlc || return $?
311         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
312 peer:
313     - primary nid: 4.4.4.4@tcp
314       Multi-Rail: True
315       peer ni:
316         - nid: 4.4.4.4@tcp
317         - nid: 4.4.4.1@tcp
318         - nid: 4.4.4.2@tcp
319         - nid: 4.4.4.3@tcp
320 EOF
321         append_global_yaml
322         echo "Add peer with nidrange (tcp)"
323         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
324
325         echo "Add peer with nidrange that overlaps primary nid (tcp)"
326         compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
327 }
328 run_test 4 "Add peer with nidrange (tcp)"
329
330 test_5() {
331         reinit_dlc || return $?
332         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
333 peer:
334     - primary nid: 5.5.5.5@o2ib
335       Multi-Rail: True
336       peer ni:
337         - nid: 5.5.5.5@o2ib
338         - nid: 5.5.5.1@o2ib
339         - nid: 5.5.5.2@o2ib
340         - nid: 5.5.5.3@o2ib
341         - nid: 5.5.5.4@o2ib
342 EOF
343         append_global_yaml
344         echo "Add peer with nidrange (o2ib)"
345         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
346
347         echo "Add peer with nidranage that overlaps primary nid (o2ib)"
348         compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
349 }
350 run_test 5 "Add peer with nidrange (o2ib)"
351
352 test_6() {
353         reinit_dlc || return $?
354         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
355 peer:
356     - primary nid: 6.6.6.6@tcp
357       Multi-Rail: True
358       peer ni:
359         - nid: 6.6.6.6@tcp
360         - nid: 6.6.6.0@tcp
361         - nid: 6.6.6.2@tcp
362         - nid: 6.6.6.4@tcp
363         - nid: 6.6.7.0@tcp
364         - nid: 6.6.7.2@tcp
365         - nid: 6.6.7.4@tcp
366         - nid: 6.6.1.0@o2ib
367         - nid: 6.6.1.3@o2ib
368         - nid: 6.6.1.6@o2ib
369         - nid: 6.6.3.0@o2ib
370         - nid: 6.6.3.3@o2ib
371         - nid: 6.6.3.6@o2ib
372         - nid: 6@gni
373         - nid: 10@gni
374         - nid: 6@kfi
375         - nid: 10@kfi
376 EOF
377         append_global_yaml
378
379         local nid_expr="6.6.[6-7].[0-4/2]@tcp"
380         nid_expr+=",6.6.[1-4/2].[0-6/3]@o2ib"
381         nid_expr+=",[6-12/4]@gni"
382         nid_expr+=",[6-12/4]@kfi"
383
384         compare_peer_add "6.6.6.6@tcp" "${nid_expr}"
385 }
386 run_test 6 "Add peer with multiple nidranges"
387
388 compare_peer_del() {
389         local prim_nid="${1:+--prim_nid $1}"
390         local nid="${2:+--nid $2}"
391
392         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
393
394         do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
395         $LNETCTL export --backup > $actual || error "export failed $?"
396         compare_yaml_files
397         return $?
398 }
399
400 test_7() {
401         reinit_dlc || return $?
402         create_base_yaml_file
403
404         echo "Delete peer with single nid (tcp)"
405         do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
406         compare_peer_del "7.7.7.7@tcp"
407
408         echo "Delete peer with single nid (o2ib)"
409         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
410         compare_peer_del "7.7.7.7@o2ib"
411
412         echo "Delete peer that has multiple nids (tcp)"
413         do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
414                 error "Peer add failed $?"
415         compare_peer_del "7.7.7.7@tcp"
416
417         echo "Delete peer that has multiple nids (o2ib)"
418         do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
419                 error "Peer add failed $?"
420         compare_peer_del "7.7.7.7@o2ib"
421
422         echo "Delete peer that has both tcp and o2ib nids"
423         do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
424                 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
425                 error "Peer add failed $?"
426         compare_peer_del "7.7.7.7@tcp"
427
428         echo "Delete peer with single nid (gni)"
429         do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
430         compare_peer_del "7@gni"
431
432         echo "Delete peer that has multiple nids (gni)"
433         do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
434                 error "Peer add failed $?"
435         compare_peer_del "7@gni"
436
437         echo "Delete peer with single nid (kfi)"
438         do_lnetctl peer add --prim_nid 7@kfi || error "Peer add failed $?"
439         compare_peer_del "7@kfi"
440
441         echo "Delete peer that has multiple nids (kfi)"
442         do_lnetctl peer add --prim_nid 7@kfi --nid [8-12]@kfi ||
443                 error "Peer add failed $?"
444         compare_peer_del "7@kfi"
445
446         echo "Delete peer that has tcp, o2ib, gni and kfi nids"
447         do_lnetctl peer add --prim_nid 7@gni \
448                 --nid [8-12]@gni,7.7.7.[1-4]@tcp,7.7.7.[5-9]@o2ib,[1-5]@kfi ||
449                 error "Peer add failed $?"
450         compare_peer_del "7@gni"
451 }
452 run_test 7 "Various peer delete tests"
453
454 test_8() {
455         reinit_dlc || return $?
456
457         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
458 peer:
459     - primary nid: 8.8.8.8@tcp
460       Multi-Rail: True
461       peer ni:
462         - nid: 8.8.8.8@tcp
463         - nid: 8.8.8.10@tcp
464         - nid: 8.8.8.11@tcp
465         - nid: 8.8.8.12@tcp
466         - nid: 8.8.8.14@tcp
467         - nid: 8.8.8.15@tcp
468 EOF
469         append_global_yaml
470
471         do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
472                 error "Peer add failed $?"
473         compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
474 }
475 run_test 8 "Delete single secondary nid from peer (tcp)"
476
477 test_9() {
478         reinit_dlc || return $?
479
480         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
481 peer:
482     - primary nid: 9.9.9.9@tcp
483       Multi-Rail: True
484       peer ni:
485         - nid: 9.9.9.9@tcp
486 EOF
487         append_global_yaml
488
489         do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
490                 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
491         compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
492 }
493 run_test 9 "Delete all secondary nids from peer (tcp)"
494
495 test_10() {
496         reinit_dlc || return $?
497
498         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
499 peer:
500     - primary nid: 10.10.10.10@tcp
501       Multi-Rail: True
502       peer ni:
503         - nid: 10.10.10.10@tcp
504         - nid: 10.10.10.12@tcp
505         - nid: 10.10.10.13@tcp
506         - nid: 10.10.10.15@tcp
507         - nid: 10.10.10.16@tcp
508 EOF
509         append_global_yaml
510         do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
511                 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
512         compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
513 }
514 run_test 10 "Delete single secondary nid from peer (o2ib)"
515
516 test_11() {
517         reinit_dlc || return $?
518
519         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
520 peer:
521     - primary nid: 11.11.11.11@tcp
522       Multi-Rail: True
523       peer ni:
524         - nid: 11.11.11.11@tcp
525 EOF
526         append_global_yaml
527         do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
528                 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
529         compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
530 }
531 run_test 11 "Delete all secondary nids from peer (o2ib)"
532
533 test_12() {
534         reinit_dlc || return $?
535
536         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
537 peer:
538     - primary nid: 12.12.12.12@o2ib
539       Multi-Rail: True
540       peer ni:
541         - nid: 12.12.12.12@o2ib
542         - nid: 13.13.13.13@o2ib
543         - nid: 14.13.13.13@o2ib
544         - nid: 14.15.13.13@o2ib
545         - nid: 15.17.1.5@tcp
546         - nid: 15.17.1.10@tcp
547         - nid: 15.17.1.20@tcp
548 EOF
549         append_global_yaml
550         do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
551                 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
552                 error "Peer add failed $?"
553         compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
554 }
555 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
556
557 test_13() {
558         reinit_dlc || return $?
559
560         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
561 peer:
562     - primary nid: 13.13.13.13@o2ib
563       Multi-Rail: True
564       peer ni:
565         - nid: 13.13.13.13@o2ib
566 EOF
567         append_global_yaml
568         do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
569                 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
570                 error "Peer add failed $?"
571         compare_peer_del "13.13.13.13@o2ib" \
572                 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
573 }
574 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
575
576 create_nid() {
577         local num="$1"
578         local net="$2"
579
580         if [[ $net =~ gni* ]] || [[ $net =~ kfi* ]]; then
581                 echo "${num}@${net}"
582         else
583                 echo "${num}.${num}.${num}.${num}@${net}"
584         fi
585 }
586
587 create_mr_peer_yaml() {
588         local num_peers="$1"
589         local secondary_nids="$2"
590         local net="$3"
591
592         echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
593         echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
594         local i
595         local total_nids=$((num_peers + $((num_peers * secondary_nids))))
596         local created=0
597         local nidnum=1
598         while [[ $created -lt $num_peers ]]; do
599                 local primary=$(create_nid ${nidnum} ${net})
600         cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
601     - primary nid: $primary
602       Multi-Rail: True
603       peer ni:
604         - nid: $primary
605 EOF
606                 local j
607                 local start=$((nidnum + 1))
608                 local end=$((nidnum + $secondary_nids))
609                 for j in $(seq ${start} ${end}); do
610                         local nid=$(create_nid $j ${net})
611                         echo "        - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
612                 done
613                 nidnum=$((end + 1))
614                 ((created++))
615         done
616 }
617
618 test_14() {
619         reinit_dlc || return $?
620
621         echo "Create single peer, single nid, using import"
622         create_mr_peer_yaml 1 0 tcp
623         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
624                 error "Import failed $?"
625         append_global_yaml
626         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
627         compare_yaml_files
628
629         echo "Delete single peer using import --del"
630         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
631                 error "Import failed $?"
632         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
633         create_base_yaml_file
634         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
635         compare_yaml_files
636 }
637 run_test 14 "import peer create/delete with single nid"
638
639 test_15() {
640         reinit_dlc || return $?
641
642         echo "Create multiple peers, single nid per peer, using import"
643         create_mr_peer_yaml 5 0 o2ib
644         # The ordering of nids for this use-case is non-deterministic, so we
645         # we can't just diff the expected/actual output.
646         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
647                 error "Import failed $?"
648         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
649         validate_peer_nids 5 0
650
651         echo "Delete multiple peers, single nid per peer, using import --del"
652         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
653                 error "Import failed $?"
654         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
655         create_base_yaml_file
656         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
657         compare_yaml_files
658 }
659 run_test 15 "import multi peer create/delete with single nid per peer"
660
661 test_16() {
662         reinit_dlc || return $?
663
664         echo "Create single peer, multiple nids, using import"
665         create_mr_peer_yaml 1 5 tcp
666         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
667                 error "Import failed $?"
668         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
669         validate_peer_nids 1 5
670
671         echo "Delete single peer, multiple nids, using import --del"
672         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
673                 error "Import failed $?"
674         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
675         create_base_yaml_file
676         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
677         compare_yaml_files
678 }
679 run_test 16 "import peer create/delete with multiple nids"
680
681 test_17() {
682         reinit_dlc || return $?
683
684         echo "Create multiple peers, multiple nids per peer, using import"
685         create_mr_peer_yaml 5 7 o2ib
686         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
687                 error "Import failed $?"
688         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
689         validate_peer_nids 5 7
690
691         echo "Delete multiple peers, multiple nids per peer, using import --del"
692         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
693                 error "Import failed $?"
694         rm -f $TMP/sanity-lnet-$testnum-expected.yaml
695         create_base_yaml_file
696         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
697         compare_yaml_files
698 }
699 run_test 17 "import multi peer create/delete with multiple nids"
700
701 test_18a() {
702         reinit_dlc || return $?
703
704         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
705 peer:
706     - primary nid: 1.1.1.1@tcp
707       Multi-Rail: True
708       peer ni:
709         - nid: 1.1.1.1@tcp
710         - nid: 2.2.2.2@tcp
711         - nid: 4.4.4.4@tcp
712         - nid: 3.3.3.3@o2ib
713         - nid: 5@gni
714 EOF
715         echo "Import peer with 5 nids"
716         cat $TMP/sanity-lnet-$testnum-expected.yaml
717         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
718                 error "Import failed $?"
719         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
720 peer:
721     - primary nid: 1.1.1.1@tcp
722       Multi-Rail: True
723       peer ni:
724         - nid: 2.2.2.2@tcp
725         - nid: 3.3.3.3@o2ib
726         - nid: 5@gni
727 EOF
728         echo "Delete three of the nids"
729         cat $TMP/sanity-lnet-$testnum-expected.yaml
730         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
731         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
732 peer:
733     - primary nid: 1.1.1.1@tcp
734       Multi-Rail: True
735       peer ni:
736         - nid: 1.1.1.1@tcp
737         - nid: 4.4.4.4@tcp
738 EOF
739         echo "Check peer has expected nids remaining"
740         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
741         append_global_yaml
742         compare_yaml_files
743 }
744 run_test 18a "Delete a subset of nids from a single peer using import --del"
745
746 test_18b() {
747         reinit_dlc || return $?
748
749         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
750 peer:
751     - primary nid: 1.1.1.1@tcp
752       Multi-Rail: True
753       peer ni:
754         - nid: 1.1.1.1@tcp
755         - nid: 2.2.2.2@tcp
756         - nid: 4.4.4.4@tcp
757         - nid: 3.3.3.3@o2ib
758         - nid: 5@gni
759     - primary nid: 6.6.6.6@o2ib
760       Multi-Rail: True
761       peer ni:
762         - nid: 6.6.6.6@o2ib
763         - nid: 7.7.7.7@tcp
764         - nid: 8.8.8.8@tcp
765         - nid: 9.9.9.9@tcp
766         - nid: 10@gni
767 EOF
768         echo "Import two peers with 5 nids each"
769         cat $TMP/sanity-lnet-$testnum-expected.yaml
770         do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
771                 error "Import failed $?"
772         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
773 peer:
774     - primary nid: 1.1.1.1@tcp
775       Multi-Rail: True
776       peer ni:
777         - nid: 2.2.2.2@tcp
778         - nid: 3.3.3.3@o2ib
779         - nid: 5@gni
780     - primary nid: 6.6.6.6@o2ib
781       Multi-Rail: True
782       peer ni:
783         - nid: 7.7.7.7@tcp
784         - nid: 8.8.8.8@tcp
785         - nid: 10@gni
786 EOF
787         echo "Delete three of the nids from each peer"
788         cat $TMP/sanity-lnet-$testnum-expected.yaml
789         do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
790         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
791 peer:
792     - primary nid: 6.6.6.6@o2ib
793       Multi-Rail: True
794       peer ni:
795         - nid: 6.6.6.6@o2ib
796         - nid: 7.7.7.7@tcp
797     - primary nid: 1.1.1.1@tcp
798       Multi-Rail: True
799       peer ni:
800         - nid: 1.1.1.1@tcp
801         - nid: 4.4.4.4@tcp
802 EOF
803         append_global_yaml
804         echo "Check peers have expected nids remaining"
805         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
806         compare_yaml_files
807         validate_peer_nids 2 1
808 }
809 run_test 18b "Delete multiple nids from multiple peers using import --del"
810
811 test_19() {
812         reinit_dlc || return $?
813         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
814 peer:
815     - primary nid: 19@gni
816       Multi-Rail: True
817       peer ni:
818         - nid: 19@gni
819 EOF
820         append_global_yaml
821         compare_peer_add "19@gni"
822 }
823 run_test 19 "Add peer with single nid (gni)"
824
825 test_20() {
826         reinit_dlc || return $?
827         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
828 peer:
829     - primary nid: 20@gni
830       Multi-Rail: True
831       peer ni:
832         - nid: 20@gni
833         - nid: 20.20.20.20@tcp
834         - nid: 20.20.20.20@o2ib
835 EOF
836         append_global_yaml
837         compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
838 }
839 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
840
841 test_21() {
842         reinit_dlc || return $?
843         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
844 peer:
845     - primary nid: 21@gni
846       Multi-Rail: True
847       peer ni:
848         - nid: 21@gni
849         - nid: 22@gni
850         - nid: 23@gni
851         - nid: 24@gni
852         - nid: 25@gni
853 EOF
854         append_global_yaml
855         echo "Add peer with nidrange (gni)"
856         compare_peer_add "21@gni" "[22-25]@gni" || error
857         echo "Add peer with nidrange that overlaps primary nid (gni)"
858         compare_peer_add "21@gni" "[21-25]@gni"
859 }
860 run_test 21 "Add peer with nidrange (gni)"
861
862 test_22() {
863         reinit_dlc || return $?
864         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
865 peer:
866     - primary nid: 22@gni
867       Multi-Rail: True
868       peer ni:
869         - nid: 22@gni
870         - nid: 24@gni
871         - nid: 25@gni
872         - nid: 27@gni
873         - nid: 28@gni
874         - nid: 29@gni
875 EOF
876         append_global_yaml
877         do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
878                 error "Peer add failed $?"
879         compare_peer_del "22@gni" "26@gni"
880 }
881 run_test 22 "Delete single secondary nid from peer (gni)"
882
883 test_23() {
884         reinit_dlc || return $?
885         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
886 peer:
887     - primary nid: 23@gni
888       Multi-Rail: True
889       peer ni:
890         - nid: 23@gni
891 EOF
892         append_global_yaml
893
894         do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
895                 error "Peer add failed $?"
896         compare_peer_del "23@gni" "[25-29]@gni"
897 }
898 run_test 23 "Delete all secondary nids from peer (gni)"
899
900 test_24() {
901         reinit_dlc || return $?
902         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
903 peer:
904     - primary nid: 24@gni
905       Multi-Rail: True
906       peer ni:
907         - nid: 24@gni
908         - nid: 11@gni
909         - nid: 13.13.13.13@o2ib
910         - nid: 14.13.13.13@o2ib
911         - nid: 14.15.13.13@o2ib
912         - nid: 15.17.1.5@tcp
913         - nid: 15.17.1.10@tcp
914         - nid: 15.17.1.20@tcp
915 EOF
916         append_global_yaml
917         do_lnetctl peer add --prim_nid 24@gni \
918                 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp,[5-12/6]@gni ||
919                 error "Peer add failed $?"
920         compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
921 }
922 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
923
924 test_25() {
925         reinit_dlc || return $?
926         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
927 peer:
928     - primary nid: 25@gni
929       Multi-Rail: True
930       peer ni:
931         - nid: 25@gni
932 EOF
933         append_global_yaml
934         do_lnetctl peer add --prim_nid 25@gni \
935                 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
936                 error "Peer add failed $?"
937         compare_peer_del "25@gni" \
938                 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
939 }
940 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
941
942 test_26() {
943         reinit_dlc || return $?
944
945         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --lock_prim ||
946                 error "Peer add with --lock_prim option failed $?"
947         local peer_state=$($LNETCTL peer show -v 4 --nid 1.1.1.1@tcp |
948                 awk '/peer state/ {print $NF}')
949         # This relies on the following peer state definition:
950         # #define LNET_PEER_LOCK_PRIMARY          BIT(20)
951         if ((!("$peer_state" & (1 << 20)))); then
952                 error "Peer state does not have 'locked' bit set: $peer_state"
953         fi
954         do_lnetctl peer del --prim_nid 1.1.1.1@tcp ||
955                 error "Peer del failed $?"
956         $LNETCTL peer show --nid 1.1.1.1@tcp | grep -q 1.1.1.1@tcp ||
957                 error "1.1.1.1@tcp is not listed"
958         do_lnetctl peer del --prim_nid 1.1.1.1@tcp --force ||
959                 error "Peer del --force failed $?"
960         do_lnetctl peer show --nid 1.1.1.1@tcp &&
961                 error "failed to delete 1.1.1.1@tcp"
962
963         return 0
964 }
965 run_test 26 "Delete peer with primary nid locked"
966
967 test_99a() {
968         reinit_dlc || return $?
969
970         echo "Invalid prim_nid - peer add"
971         do_lnetctl peer add --prim_nid foobar &&
972                 error "Command should have failed"
973
974         echo "Invalid prim_nid - peer del"
975         do_lnetctl peer del --prim_nid foobar &&
976                 error "Command should have failed"
977
978         echo "Delete non-existing peer"
979         do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
980                 error "Command should have failed"
981
982         echo "Don't provide mandatory argument for peer del"
983         do_lnetctl peer del --nid 1.1.1.1@tcp &&
984                 error "Command should have failed"
985
986         echo "Don't provide mandatory argument for peer add"
987         do_lnetctl peer add --nid 1.1.1.1@tcp &&
988                 error "Command should have failed"
989
990         echo "Don't provide mandatory arguments peer add"
991         do_lnetctl peer add &&
992                 error "Command should have failed"
993
994         echo "Invalid secondary nids"
995         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
996                 error "Command should have failed"
997
998         echo "Exceed max nids per peer"
999         do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
1000                 error "Command should have failed"
1001
1002         echo "Invalid net type"
1003         do_lnetctl peer add --prim_nid 1@foo &&
1004                 error "Command should have failed"
1005
1006         echo "Invalid nid format"
1007         local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
1008
1009         local nid
1010         for nid in ${invalid_nids}; do
1011                 echo "Check invalid primary nid - '$nid'"
1012                 do_lnetctl peer add --prim_nid $nid &&
1013                         error "Command should have failed"
1014         done
1015
1016         local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
1017         invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
1018         invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
1019
1020         local nidstr
1021         for nidstr in ${invalid_strs}; do
1022                 echo "Check invalid nidstring - '$nidstr'"
1023                 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
1024                         error "Command should have failed"
1025         done
1026
1027         echo "Add non-local gateway"
1028         do_lnetctl route add --net tcp --gateway 1@gni &&
1029                 error "Command should have failed"
1030
1031         return 0
1032 }
1033 run_test 99a "Check various invalid inputs to lnetctl peer"
1034
1035 test_99b() {
1036         reinit_dlc || return $?
1037
1038         create_base_yaml_file
1039
1040         cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
1041 peer:
1042     - primary nid: 99.99.99.99@tcp
1043       Multi-Rail: Foobar
1044       peer ni:
1045         - nid: 99.99.99.99@tcp
1046 EOF
1047         do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1048                 error "import should have failed"
1049         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1050         compare_yaml_files
1051 }
1052 run_test 99b "Invalid value for Multi-Rail in yaml import"
1053
1054 have_interface() {
1055         local if="$1"
1056         local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1057         [[ -n $ip ]]
1058 }
1059
1060 add_net() {
1061         local net="$1"
1062         local if="$2"
1063
1064         do_lnetctl net add --net ${net} --if ${if} ||
1065                 error "Failed to add net ${net} on if ${if}"
1066 }
1067
1068 compare_route_add() {
1069         local rnet="$1"
1070         local gw="$2"
1071
1072         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1073
1074         do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1075                 error "route add failed $?"
1076         $LNETCTL export --backup > $actual ||
1077                 error "export failed $?"
1078         validate_gateway_nids
1079         return $?
1080 }
1081
1082 append_net_tunables() {
1083         local net=${1:-tcp}
1084
1085         $LNETCTL net show -v --net ${net} | grep -v 'dev cpt' |
1086                 awk '/^\s+tunables:$/,/^\s+CPT:/' >> $TMP/sanity-lnet-$testnum-expected.yaml
1087 }
1088
1089 IF0_IP=$(ip -o -4 a s ${INTERFACES[0]} |
1090          awk '{print $4}' | sed 's/\/.*//')
1091 IF0_NET=$(awk -F. '{print $1"."$2"."$3}'<<<"${IF0_IP}")
1092 IF0_HOSTNUM=$(awk -F. '{print $4}'<<<"${IF0_IP}")
1093 if (((IF0_HOSTNUM + 5) > 254)); then
1094         GW_HOSTNUM=1
1095 else
1096         GW_HOSTNUM=$((IF0_HOSTNUM + 1))
1097 fi
1098 GW_NID="${IF0_NET}.${GW_HOSTNUM}@${NETTYPE}"
1099 test_100() {
1100         [[ ${NETTYPE} == tcp* ]] ||
1101                 skip "Need tcp NETTYPE"
1102         reinit_dlc || return $?
1103         add_net "${NETTYPE}" "${INTERFACES[0]}"
1104         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1105 net:
1106     - net type: ${NETTYPE}
1107       local NI(s):
1108         - interfaces:
1109               0: ${INTERFACES[0]}
1110 EOF
1111         append_net_tunables tcp
1112         cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
1113 route:
1114     - net: tcp7
1115       gateway: ${GW_NID}
1116       hop: -1
1117       priority: 0
1118       health_sensitivity: 1
1119 peer:
1120     - primary nid: ${GW_NID}
1121       Multi-Rail: False
1122       peer ni:
1123         - nid: ${GW_NID}
1124 EOF
1125         append_global_yaml
1126         compare_route_add "tcp7" "${GW_NID}"
1127 }
1128 run_test 100 "Add route with single gw (tcp)"
1129
1130 test_101() {
1131         [[ ${NETTYPE} == tcp* ]] ||
1132                 skip "Need tcp NETTYPE"
1133         reinit_dlc || return $?
1134         add_net "${NETTYPE}" "${INTERFACES[0]}"
1135         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1136 net:
1137     - net type: ${NETTYPE}
1138       local NI(s):
1139         - interfaces:
1140               0: ${INTERFACES[0]}
1141 EOF
1142         append_net_tunables tcp
1143
1144         echo "route:" >> $TMP/sanity-lnet-$testnum-expected.yaml
1145         for i in $(seq $GW_HOSTNUM $((GW_HOSTNUM + 4))); do
1146                 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
1147     - net: tcp8
1148       gateway: ${IF0_NET}.${i}@tcp
1149       hop: -1
1150       priority: 0
1151       health_sensitivity: 1
1152 EOF
1153         done
1154
1155         echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
1156         for i in $(seq $GW_HOSTNUM $((GW_HOSTNUM + 4))); do
1157                 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
1158     - primary nid: ${IF0_NET}.${i}@tcp
1159       Multi-Rail: False
1160       peer ni:
1161         - nid: ${IF0_NET}.${i}@tcp
1162 EOF
1163         done
1164         append_global_yaml
1165
1166         local gw="${IF0_NET}.[$GW_HOSTNUM-$((GW_HOSTNUM + 4))]@tcp"
1167
1168         compare_route_add "tcp8" "${gw}"
1169 }
1170 run_test 101 "Add route with multiple gw (tcp)"
1171
1172 compare_route_del() {
1173         local rnet="$1"
1174         local gw="$2"
1175
1176         local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1177
1178         do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1179                 error "route del failed $?"
1180         $LNETCTL export --backup > $actual ||
1181                 error "export failed $?"
1182         validate_gateway_nids
1183 }
1184
1185 generate_gw_nid() {
1186         local net=${1}
1187
1188         if [[ ${net} =~ (tcp|o2ib)[0-9]* ]]; then
1189                 echo "${GW_NID}"
1190         else
1191                 echo "$((${testnum} % 255))@${net}"
1192         fi
1193 }
1194
1195 test_102() {
1196         reinit_dlc || return $?
1197         add_net "${NETTYPE}" "${INTERFACES[0]}"
1198         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1199
1200         local gwnid=$(generate_gw_nid ${NETTYPE})
1201
1202         do_lnetctl route add --net ${NETTYPE}2 --gateway ${gwnid} ||
1203                 error "route add failed $?"
1204         compare_route_del "${NETTYPE}2" "${gwnid}"
1205 }
1206 run_test 102 "Delete route with single gw"
1207
1208 IP_NID_EXPR='103.103.103.[103-120/4]'
1209 NUM_NID_EXPR='[103-120/4]'
1210 test_103() {
1211         reinit_dlc || return $?
1212         add_net "${NETTYPE}" "${INTERFACES[0]}"
1213         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1214
1215         local nid_expr
1216
1217         if [[ $NETTYPE =~ (tcp|o2ib)[0-9]* ]]; then
1218                 nid_expr="${IF0_NET}.[$GW_HOSTNUM-$((GW_HOSTNUM+5))/2]"
1219         else
1220                 nid_expr="${NUM_NID_EXPR}"
1221         fi
1222
1223         do_lnetctl route add --net ${NETTYPE}103 \
1224                 --gateway ${nid_expr}@${NETTYPE} ||
1225                 error "route add failed $?"
1226         compare_route_del "${NETTYPE}103" "${nid_expr}@${NETTYPE}"
1227 }
1228 run_test 103 "Delete route with multiple gw"
1229
1230 test_104() {
1231         local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1232
1233         reinit_dlc || return $?
1234
1235         # Default value is '3'
1236         local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1237         [[ $val -ne 3 ]] &&
1238                 error "Expect 3 found $val"
1239
1240         echo "Set < 0;  Should fail"
1241         do_lnetctl set response_tracking -1 &&
1242                 error "should have failed $?"
1243
1244         reinit_dlc || return $?
1245         cat <<EOF > $tyaml
1246 global:
1247     response_tracking: -10
1248 EOF
1249         do_lnetctl import < $tyaml &&
1250                 error "should have failed $?"
1251
1252         echo "Check valid values; Should succeed"
1253         local i
1254         for ((i = 0; i < 4; i++)); do
1255                 reinit_dlc || return $?
1256                 do_lnetctl set response_tracking $i ||
1257                         error "should have succeeded $?"
1258                 $LNETCTL global show | grep -q "response_tracking: $i" ||
1259                         error "Failed to set response_tracking to $i"
1260                 reinit_dlc || return $?
1261                 cat <<EOF > $tyaml
1262 global:
1263     response_tracking: $i
1264 EOF
1265                 do_lnetctl import < $tyaml ||
1266                         error "should have succeeded $?"
1267                 $LNETCTL global show | grep -q "response_tracking: $i" ||
1268                         error "Failed to set response_tracking to $i"
1269         done
1270
1271         reinit_dlc || return $?
1272         echo "Set > 3; Should fail"
1273         do_lnetctl set response_tracking 4 &&
1274                 error "should have failed $?"
1275
1276         reinit_dlc || return $?
1277         cat <<EOF > $tyaml
1278 global:
1279     response_tracking: 10
1280 EOF
1281         do_lnetctl import < $tyaml &&
1282                 error "should have failed $?"
1283         return 0
1284 }
1285 run_test 104 "Set/check response_tracking param"
1286
1287 test_105() {
1288         reinit_dlc || return $?
1289         add_net "${NETTYPE}" "${INTERFACES[0]}"
1290
1291         local gwnid=$(generate_gw_nid ${NETTYPE})
1292
1293         do_lnetctl route add --net ${NETTYPE}105 --gateway ${gwnid} ||
1294                 error "route add failed $?"
1295         do_lnetctl peer add --prim ${gwnid} &&
1296                 error "peer add should fail"
1297
1298         return 0
1299 }
1300 run_test 105 "Adding duplicate GW peer should fail"
1301
1302 test_106() {
1303         reinit_dlc || return $?
1304         add_net "${NETTYPE}" "${INTERFACES[0]}"
1305
1306         local gwnid=$(generate_gw_nid ${NETTYPE})
1307
1308         do_lnetctl route add --net ${NETTYPE}106 --gateway ${gwnid} ||
1309                 error "route add failed $?"
1310         do_lnetctl peer del --prim ${gwnid} &&
1311                 error "peer del should fail"
1312
1313         return 0
1314 }
1315 run_test 106 "Deleting GW peer should fail"
1316
1317 test_200() {
1318         [[ ${NETTYPE} == tcp* ]] ||
1319                 skip "Need tcp NETTYPE"
1320         cleanup_lnet || exit 1
1321         load_lnet "networks=\"\""
1322         do_ns $LNETCTL lnet configure --all || exit 1
1323         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1324 }
1325 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1326
1327 test_201() {
1328         [[ ${NETTYPE} == tcp* ]] ||
1329                 skip "Need tcp NETTYPE"
1330         cleanup_lnet || exit 1
1331         load_lnet "networks=tcp($FAKE_IF)"
1332         do_ns $LNETCTL lnet configure --all || exit 1
1333         $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1334 }
1335 run_test 201 "load lnet using networks module options in a non-default namespace"
1336
1337 test_202() {
1338         [[ ${NETTYPE} == tcp* ]] ||
1339                 skip "Need tcp NETTYPE"
1340         cleanup_lnet || exit 1
1341         load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1342         do_ns $LNETCTL lnet configure --all || exit 1
1343         $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1344 }
1345 run_test 202 "load lnet using ip2nets in a non-default namespace"
1346
1347
1348 ### Add the interfaces in the target namespace
1349
1350 test_203() {
1351         [[ ${NETTYPE} == tcp* ]] ||
1352                 skip "Need tcp NETTYPE"
1353         cleanup_lnet || exit 1
1354         load_lnet
1355         do_lnetctl lnet configure || exit 1
1356         do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1357 }
1358 run_test 203 "add a network using an interface in the non-default namespace"
1359
1360 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1361 function save_lnet_params() {
1362         $LNETCTL global show | egrep -v '^global:$' |
1363                                sed 's/://' > $LNET_PARAMS_FILE
1364 }
1365
1366 function restore_lnet_params() {
1367         local param value
1368         while read param value; do
1369                 [[ $param == max_intf ]] && continue
1370                 [[ $param == lnd_timeout ]] && continue
1371                 $LNETCTL set ${param} ${value} ||
1372                         error "Failed to restore ${param} to ${value}"
1373         done < $LNET_PARAMS_FILE
1374 }
1375
1376 function lnet_health_pre() {
1377         save_lnet_params
1378
1379         # Lower transaction timeout to speed up test execution
1380         $LNETCTL set transaction_timeout 10 ||
1381                 error "Failed to set transaction_timeout $?"
1382
1383         RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1384         RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1385         LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1386                       xargs echo | sed 's/ /+/g' | bc -l)
1387
1388         RMT_HVAL_PRE=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1389                        awk '/health value/{print $NF}' | xargs echo |
1390                        sed 's/ /+/g' | bc -l)
1391
1392         # Might not have any peers so initialize to zero.
1393         RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1394
1395         return 0
1396 }
1397
1398 function lnet_health_post() {
1399         RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1400         LO_HVAL_POST=$($LNETCTL net show -v 2 |
1401                        awk '/health value/{print $NF}' |
1402                        xargs echo | sed 's/ /+/g' | bc -l)
1403
1404         RMT_HVAL_POST=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1405                         awk '/health value/{print $NF}' | xargs echo |
1406                         sed 's/ /+/g' | bc -l)
1407
1408         # Might not have any peers so initialize to zero.
1409         RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1410
1411         ${VERBOSE} &&
1412         echo "Pre resends: $RSND_PRE" &&
1413         echo "Post resends: $RSND_POST" &&
1414         echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1415         echo "Pre local health: $LO_HVAL_PRE" &&
1416         echo "Post local health: $LO_HVAL_POST" &&
1417         echo "Pre remote health: $RMT_HVAL_PRE" &&
1418         echo "Post remote health: $RMT_HVAL_POST"
1419
1420         restore_lnet_params
1421
1422         do_lnetctl peer set --health 1000 --all
1423         do_lnetctl net set --health 1000 --all
1424
1425         return 0
1426 }
1427
1428 function check_no_resends() {
1429         echo "Check that no resends took place"
1430         [[ $RSND_POST -ne $RSND_PRE ]] &&
1431                 error "Found resends: $RSND_POST != $RSND_PRE"
1432
1433         return 0
1434 }
1435
1436 function check_resends() {
1437         local delta=$((RSND_POST - RSND_PRE))
1438
1439         echo "Check that $RETRY_PARAM resends took place"
1440         [[ $delta -ne $RETRY_PARAM ]] &&
1441                 error "Expected $RETRY_PARAM resends found $delta"
1442
1443         return 0
1444 }
1445
1446 function check_no_local_health() {
1447         echo "Check that local NI health is unchanged"
1448         [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1449                 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1450
1451         return 0
1452 }
1453
1454 function check_local_health() {
1455         echo "Check that local NI health has been changed"
1456         [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1457                 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1458
1459         return 0
1460 }
1461
1462 function check_no_remote_health() {
1463         echo "Check that remote NI health is unchanged"
1464         [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1465                 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1466
1467         return 0
1468 }
1469
1470 function check_remote_health() {
1471         echo "Check that remote NI health has been changed"
1472         [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1473                 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1474
1475         return 0
1476 }
1477
1478 RNODE=""
1479 RLOADED=false
1480 NET_DEL_ARGS=""
1481 RNIDS=( )
1482 LNIDS=( )
1483 setup_health_test() {
1484         local need_mr=$1
1485         local rc=0
1486
1487         [[ ${NETTYPE} == kfi* ]] && skip "kfi doesn't support drop rules"
1488
1489         local rnodes=$(remote_nodes_list)
1490         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1491
1492         cleanup_lnet || error "Failed to cleanup before test execution"
1493
1494         # Loading modules should configure LNet with the appropriate
1495         # test-framework configuration
1496         load_lnet "config_on_load=1" || error "Failed to load modules"
1497
1498         LNIDS=( $($LCTL list_nids | xargs echo) )
1499
1500         RNODE=$(awk '{print $1}' <<<$rnodes)
1501         RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1502
1503         if [[ -z ${RNIDS[@]} ]]; then
1504                 do_rpc_nodes $RNODE load_lnet "config_on_load=1"
1505                 RLOADED=true
1506                 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1507         fi
1508
1509         [[ ${#LNIDS[@]} -lt 1 ]] &&
1510                 error "No NIDs configured for local host $HOSTNAME"
1511         [[ ${#RNIDS[@]} -lt 1 ]] &&
1512                 error "No NIDs configured for remote host $RNODE"
1513
1514         # Ensure all peer NIs are local (i.e. non-routed config)
1515         local rnid rnet lnid lnet
1516
1517         for rnid in ${RNIDS[@]}; do
1518                 rnet=${rnid##*@}
1519                 for lnid in ${LNIDS[@]}; do
1520                         lnet=${lnid##*@}
1521                         [[ ${lnet} == ${rnet} ]] &&
1522                                 break
1523                 done
1524                 [[ ${lnet} != ${rnet} ]] &&
1525                         skip "Need non-routed configuration"
1526         done
1527
1528         do_lnetctl discover ${RNIDS[0]} ||
1529                 error "Unable to discover ${RNIDS[0]}"
1530
1531         local mr=$($LNETCTL peer show --nid ${RNIDS[0]} |
1532                    awk '/Multi-Rail/{print $NF}')
1533
1534         if ${need_mr} && [[ $mr == False ]]; then
1535                 cleanup_health_test || return $?
1536                 skip "Need MR peer"
1537         fi
1538
1539         if ( ! ${need_mr} && [[ ${#RNIDS[@]} -gt 1 ]] ) ||
1540            ( ! ${need_mr} && [[ ${#LNIDS[@]} -gt 1 ]] ); then
1541                 cleanup_health_test || return $?
1542                 skip "Need SR peer"
1543         fi
1544
1545         if ${need_mr} && [[ ${#RNIDS[@]} -lt 2 ]]; then
1546                 # Add a second, reachable NID to rnode.
1547                 local net=${RNIDS[0]}
1548
1549                 net="${net//*@/}1"
1550
1551                 local if=$(do_rpc_nodes --quiet $RNODE lnet_if_list)
1552                 [[ -z $if ]] &&
1553                         error "Failed to determine interface for $RNODE"
1554
1555                 do_rpc_nodes $RNODE "$LNETCTL lnet configure"
1556                 do_rpc_nodes $RNODE "$LNETCTL net add --net $net --if $if" ||
1557                         rc=$?
1558                 if [[ $rc -ne 0 ]]; then
1559                         error "Failed to add interface to $RNODE rc=$?"
1560                 else
1561                         RNIDS[1]="${RNIDS[0]}1"
1562                         NET_DEL_ARGS="--net $net --if $if"
1563                 fi
1564         fi
1565
1566         if ${need_mr} && [[ ${#LNIDS[@]} -lt 2 ]]; then
1567                 local net=${LNIDS[0]}
1568                 net="${net//*@/}1"
1569
1570                 do_lnetctl lnet configure &&
1571                         do_lnetctl net add --net $net --if ${INTERFACES[0]} ||
1572                         rc=$?
1573                 if [[ $rc -ne 0 ]]; then
1574                         error "Failed to add interface rc=$?"
1575                 else
1576                         LNIDS[1]="${LNIDS[0]}1"
1577                 fi
1578         fi
1579
1580         $LNETCTL net show
1581
1582         $LNETCTL peer show -v 2 | egrep -e nid -e health
1583
1584         $LCTL set_param debug=+net
1585
1586         return 0
1587
1588 }
1589
1590 cleanup_health_test() {
1591         local rc=0
1592
1593         if [[ -n $NET_DEL_ARGS ]]; then
1594                 do_rpc_nodes $RNODE \
1595                         "$LNETCTL net del $NET_DEL_ARGS" ||
1596                         rc=$((rc + $?))
1597                 NET_DEL_ARGS=""
1598         fi
1599
1600         unload_modules || rc=$?
1601
1602         if $RLOADED; then
1603                 do_rpc_nodes $RNODE unload_modules_local ||
1604                         rc=$((rc + $?))
1605                 RLOADED=false
1606         fi
1607
1608         [[ $rc -ne 0 ]] &&
1609                 error "Failed cleanup"
1610
1611         return $rc
1612 }
1613
1614 add_health_test_drop_rules() {
1615         local args="-m GET -r 1 -e ${1}"
1616         local src dst
1617
1618         for src in "${LNIDS[@]}"; do
1619                 for dst in "${RNIDS[@]}" "${LNIDS[@]}"; do
1620                         $LCTL net_drop_add -s $src -d $dst ${args} ||
1621                                 error "Failed to add drop rule $src $dst $args"
1622                 done
1623         done
1624 }
1625
1626 do_lnet_health_ping_test() {
1627         local hstatus="$1"
1628
1629         echo "Simulate $hstatus"
1630
1631         lnet_health_pre || return $?
1632
1633         add_health_test_drop_rules ${hstatus}
1634         do_lnetctl ping ${RNIDS[0]} &&
1635                 error "Should have failed"
1636
1637         lnet_health_post
1638
1639         $LCTL net_drop_del -a
1640
1641         return 0
1642 }
1643
1644 # See lnet/lnet/lib-msg.c:lnet_health_check()
1645 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1646 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1647 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1648 test_204() {
1649         setup_health_test false || return $?
1650
1651         local hstatus
1652         for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1653                        ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1654                 do_lnet_health_ping_test "${hstatus}" || return $?
1655                 check_no_resends || return $?
1656                 check_no_local_health || return $?
1657         done
1658
1659         cleanup_health_test || return $?
1660
1661         return 0
1662 }
1663 run_test 204 "Check no health or resends for single-rail local failures"
1664
1665 test_205() {
1666         setup_health_test true || return $?
1667
1668         local hstatus
1669         for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1670                 do_lnet_health_ping_test "${hstatus}" || return $?
1671                 check_resends || return $?
1672                 check_local_health || return $?
1673         done
1674
1675         for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1676                 do_lnet_health_ping_test "${hstatus}" || return $?
1677                 check_no_resends || return $?
1678                 check_local_health || return $?
1679         done
1680
1681         cleanup_health_test || return $?
1682
1683         return 0
1684 }
1685 run_test 205 "Check health and resends for multi-rail local failures"
1686
1687 # See lnet/lnet/lib-msg.c:lnet_health_check()
1688 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1689 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1690 test_206() {
1691         setup_health_test false || return $?
1692
1693         local hstatus
1694         for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1695                        ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1696                 do_lnet_health_ping_test "${hstatus}" || return $?
1697                 check_no_resends || return $?
1698                 check_no_local_health || return $?
1699                 check_no_remote_health || return $?
1700         done
1701
1702         cleanup_health_test || return $?
1703
1704         return 0
1705 }
1706 run_test 206 "Check no health or resends for single-rail remote failures"
1707
1708 test_207() {
1709         setup_health_test true || return $?
1710
1711         local hstatus
1712         for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1713                 do_lnet_health_ping_test "${hstatus}" || return $?
1714                 check_resends || return $?
1715                 check_no_local_health || return $?
1716                 check_remote_health || return $?
1717                 do_lnetctl peer set --health 1000 --all ||
1718                         error "Unable to reset health rc=$?"
1719         done
1720         for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1721                 do_lnet_health_ping_test "${hstatus}" || return $?
1722                 check_no_resends || return $?
1723                 check_no_local_health || return $?
1724                 check_remote_health || return $?
1725                 do_lnetctl peer set --health 1000 --all ||
1726                         error "Unable to reset health rc=$?"
1727         done
1728
1729         cleanup_health_test || return $?
1730
1731         return 0
1732 }
1733 run_test 207 "Check health and resends for multi-rail remote errors"
1734
1735 test_208_load_and_check_lnet() {
1736         local ip2nets="$1"
1737         local p_nid="$2"
1738         local s_nid="$3"
1739         local num_expected=1
1740
1741         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1742
1743         $LCTL net up ||
1744                 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1745
1746         [[ -n $s_nid ]] &&
1747                 num_expected=2
1748
1749         declare -a nids
1750         nids=( $($LCTL list_nids) )
1751
1752         [[ ${#nids[@]} -ne ${num_expected} ]] &&
1753                 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1754
1755         [[ ${nids[0]} == ${p_nid} ]] ||
1756                 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1757
1758         [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1759                 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1760
1761         $LCTL net down &>/dev/null
1762         cleanup_lnet
1763 }
1764
1765 test_208() {
1766         [[ ${NETTYPE} == tcp* ]] ||
1767                 skip "Need tcp NETTYPE"
1768
1769         cleanup_netns || error "Failed to cleanup netns before test execution"
1770         cleanup_lnet || error "Failed to unload modules before test execution"
1771         setup_fakeif || error "Failed to add fake IF"
1772
1773         have_interface "$FAKE_IF" ||
1774                 error "Expect $FAKE_IF configured but not found"
1775
1776         local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
1777                        awk '/inet /{print $4}' |
1778                        sed 's:/.*::')
1779         if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
1780         local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
1781
1782         echo "Configure single NID \"$ip2nets_str\""
1783         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp"
1784
1785         ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp1($FAKE_IF) $FAKE_IP"
1786         echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1787         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1788                                      "${FAKE_IP}@tcp1"
1789
1790         ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp($FAKE_IF) $FAKE_IP"
1791         echo "Configure two NIDs; one NET \"$ip2nets_str\""
1792         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1793                                      "${FAKE_IP}@tcp"
1794         local addr1=( ${if0_ip//./ } )
1795         local addr2=( ${FAKE_IP//./ } )
1796         local range="[${addr1[0]},${addr2[0]}]"
1797
1798         local i
1799         for i in $(seq 1 3); do
1800                 range+=".[${addr1[$i]},${addr2[$i]}]"
1801         done
1802         ip2nets_str="tcp(${INTERFACES[0]},${FAKE_IF}) ${range}"
1803
1804         echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1805         test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1806                                      "${FAKE_IP}@tcp"
1807
1808         cleanup_fakeif
1809
1810         echo "alt syntax with missing IF \"$ip2nets_str\""
1811         load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1812
1813         echo "$LCTL net up should fail"
1814         $LCTL net up &&
1815                 error "LNet bring up should have failed"
1816
1817         cleanup_lnet
1818 }
1819 run_test 208 "Test various kernel ip2nets configurations"
1820
1821 test_209() {
1822         setup_health_test false || return $?
1823
1824         echo "Simulate network_timeout w/SR config"
1825         lnet_health_pre
1826
1827         add_health_test_drop_rules network_timeout
1828
1829         do_lnetctl discover ${RNIDS[0]} &&
1830                 error "Should have failed"
1831
1832         lnet_health_post
1833
1834         check_no_resends || return $?
1835         check_no_local_health || return $?
1836         check_no_remote_health || return $?
1837
1838         cleanup_health_test || return $?
1839
1840         setup_health_test true || return $?
1841
1842         echo "Simulate network_timeout w/MR config"
1843
1844         lnet_health_pre
1845
1846         add_health_test_drop_rules network_timeout
1847
1848         do_lnetctl discover ${RNIDS[0]} &&
1849                 error "Should have failed"
1850
1851         lnet_health_post
1852
1853         check_no_resends || return $?
1854         check_local_health || return $?
1855         check_remote_health || return $?
1856
1857         cleanup_health_test || return $?
1858
1859         return 0
1860 }
1861 run_test 209 "Check health, but not resends, for network timeout"
1862
1863 check_nid_in_recovq() {
1864         local recovq=$($LNETCTL debug recovery $1)
1865         local expect="$2"
1866         local nids=$($LCTL list_nids | xargs echo)
1867         local found=false
1868         local nid=""
1869
1870         echo "Check \"$1\" recovery queue"
1871         echo "$recovq"
1872         if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1873                 error "Expect $expect NIDs found: \"$recovq\""
1874         fi
1875
1876         [[ $expect -eq 0 ]] && return 0
1877
1878         for nid in ${nids}; do
1879                 grep -q "nid-0: $nid"<<<$recovq &&
1880                         found=true
1881         done
1882
1883         if ! $found; then
1884                 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1885         fi
1886
1887         return 0
1888 }
1889
1890 # First enqueue happens at time 0.
1891 # 2nd at 0 + 2^0 = 1
1892 # 3rd at 1 + 2^1 = 3
1893 # 4th at 3 + 2^2 = 7
1894 # 5th at 7 + 2^3 = 15
1895 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1896 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1897 # happen
1898 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1899 # we expect the peer NI to have aged out, so it will not actually be
1900 # queued.
1901 # If max_recovery_ping_interval is set to 4 then:
1902 #  First enqueue happens at time 0.
1903 #  2nd at 0 + min(2^0, 4) = 1
1904 #  3rd at 1 + min(2^1, 4) = 3
1905 #  4th at 3 + min(2^2, 4) = 7
1906 #  5th at 7 + min(2^3, 4) = 11
1907 #  6th at 11 + min(2^4, 4) = 15
1908 #  7th at 15 + min(2^5, 4) = 19
1909 # e.g. after 4 seconds we would expect to have seen the 3rd enqueue,
1910 # (2 pings sent, 3rd about to happen), and the 4th enqueue is yet to happen
1911 # e.g. after 13 seconds we would expect to have seen the 5th enqueue,
1912 # (4 pings sent, 5th about to happen), and the 6th enqueue is yet to happen
1913 check_ping_count() {
1914         local queue="$1"
1915         local expect="$2"
1916
1917         echo "Check ping counts:"
1918         local ping_count
1919         if [[ $queue == "ni" ]]; then
1920                 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1921                 ping_count=( $($LNETCTL net show -v 2 |
1922                                 awk '/ping_count/{print $NF}') )
1923         elif [[ $queue == "peer_ni" ]]; then
1924                 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1925                 ping_count=( $($LNETCTL peer show -v 2 |
1926                                 awk '/ping_count/{print $NF}') )
1927         else
1928                 error "Unrecognized queue \"$queue\""
1929                 return 1
1930         fi
1931
1932         local count
1933         local found=false
1934         for count in "${ping_count[@]}"; do
1935                 if [[ $count -eq $expect ]]; then
1936                         if [[ $expect -ne 0 ]] && $found ; then
1937                                 error "Found more than one interface matching \"$expect\" ping count"
1938                                 return 1
1939                         else
1940                                 echo "Expect ping count \"$expect\" found \"$count\""
1941                                 found=true;
1942                         fi
1943                 elif [[ $count -ne 0 ]]; then
1944                         error "Found interface with ping count \"$count\" but expect \"$expect\""
1945                         return 1
1946                 fi
1947         done
1948
1949         return 0
1950 }
1951
1952 test_210() {
1953         [[ ${NETTYPE} == kfi* ]] && skip "kfi doesn't support drop rules"
1954
1955         reinit_dlc || return $?
1956         add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
1957         add_net "${NETTYPE}1" "${INTERFACES[0]}" || return $?
1958
1959         local prim_nid=$($LCTL list_nids | head -n 1)
1960
1961         do_lnetctl discover $prim_nid ||
1962                 error "failed to discover myself"
1963
1964         local default=$($LNETCTL global show |
1965                         awk '/recovery_limit/{print $NF}')
1966         # Set recovery limit to 10 seconds.
1967         do_lnetctl set recovery_limit 10 ||
1968                 error "failed to set recovery_limit"
1969
1970         $LCTL set_param debug=+net
1971         # Use local_error so LNet doesn't attempt to resend the discovery ping
1972         $LCTL net_drop_add -s *@${NETTYPE} -d *@${NETTYPE} -m GET -r 1 -e local_error
1973         $LCTL net_drop_add -s *@${NETTYPE}1 -d *@${NETTYPE}1 -m GET -r 1 -e local_error
1974         do_lnetctl discover $prim_nid &&
1975                 error "Expected discovery to fail"
1976
1977         # See comment for check_ping_count()
1978         sleep 5
1979         check_nid_in_recovq "-l" "1"
1980         check_ping_count "ni" "2"
1981
1982         sleep 5
1983
1984         check_nid_in_recovq "-l" "1"
1985         check_ping_count "ni" "3"
1986
1987         $LCTL net_drop_del -a
1988
1989         reinit_dlc || return $?
1990         add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
1991         add_net "${NETTYPE}1" "${INTERFACES[0]}" || return $?
1992
1993         local prim_nid=$($LCTL list_nids | head -n 1)
1994
1995         do_lnetctl discover $prim_nid ||
1996                 error "failed to discover myself"
1997
1998         do_lnetctl set recovery_limit $default ||
1999                 error "failed to set recovery_limit"
2000
2001         default=$($LNETCTL global show |
2002                   awk '/max_recovery_ping_interval/{print $NF}')
2003         do_lnetctl set max_recovery_ping_interval 4 ||
2004                 error "failed to set max_recovery_ping_interval"
2005
2006         $LCTL set_param debug=+net
2007         # Use local_error so LNet doesn't attempt to resend the discovery ping
2008         $LCTL net_drop_add -s *@${NETTYPE} -d *@${NETTYPE} -m GET -r 1 -e local_error
2009         $LCTL net_drop_add -s *@${NETTYPE}1 -d *@${NETTYPE}1 -m GET -r 1 -e local_error
2010         do_lnetctl discover $prim_nid &&
2011                 error "Expected discovery to fail"
2012
2013         # See comment for check_ping_count()
2014         sleep 4
2015         check_nid_in_recovq "-l" "1"
2016         check_ping_count "ni" "2"
2017
2018         sleep 9
2019         check_nid_in_recovq "-l" "1"
2020         check_ping_count "ni" "4"
2021
2022         $LCTL net_drop_del -a
2023
2024         do_lnetctl set max_recovery_ping_interval $default ||
2025                 error "failed to set max_recovery_ping_interval"
2026
2027         return 0
2028 }
2029 run_test 210 "Local NI recovery checks"
2030
2031 test_211() {
2032         [[ ${NETTYPE} == kfi* ]] && skip "kfi doesn't support drop rules"
2033
2034         reinit_dlc || return $?
2035         add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
2036         add_net "${NETTYPE}1" "${INTERFACES[0]}" || return $?
2037
2038         local prim_nid=$($LCTL list_nids | head -n 1)
2039
2040         do_lnetctl discover $prim_nid ||
2041                 error "failed to discover myself"
2042
2043         local default=$($LNETCTL global show |
2044                         awk '/recovery_limit/{print $NF}')
2045         # Set recovery limit to 10 seconds.
2046         do_lnetctl set recovery_limit 10 ||
2047                 error "failed to set recovery_limit"
2048
2049         $LCTL net_drop_add -s *@${NETTYPE} -d *@${NETTYPE} -m GET -r 1 -e remote_error
2050         $LCTL net_drop_add -s *@${NETTYPE}1 -d *@${NETTYPE}1 -m GET -r 1 -e remote_error
2051
2052         # Set health to 0 on one interface. This forces it onto the recovery
2053         # queue.
2054         $LNETCTL peer set --nid $prim_nid --health 0
2055
2056         # After 5 seconds, we expect the peer NI to still be in recovery
2057         sleep 5
2058         check_nid_in_recovq "-p" 1
2059         check_ping_count "peer_ni" "2"
2060
2061         # After 15 seconds, the peer NI should have been fully processed out of
2062         # the recovery queue. We'll allow a total of 17 seconds to account for
2063         # differences in sleeping for whole seconds vs. the more accurate time
2064         # keeping that is done in the recovery code.
2065         sleep 12
2066         check_nid_in_recovq "-p" 0
2067         check_ping_count "peer_ni" "4"
2068
2069         $LCTL net_drop_del -a
2070
2071         # Set health to force it back onto the recovery queue. Set to 500 means
2072         # in 5 seconds it should be back at maximum value. We'll wait a couple
2073         # more seconds than that to be safe.
2074         # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
2075         # eligible again
2076         do_lnetctl set recovery_limit 0 ||
2077                 error "failed to set recovery_limit"
2078
2079         $LNETCTL peer set --nid $prim_nid --health 500
2080
2081         check_nid_in_recovq "-p" 1
2082         check_ping_count "peer_ni" "2"
2083
2084         sleep 7
2085
2086         check_nid_in_recovq "-p" 0
2087         check_ping_count "peer_ni" "0"
2088
2089         reinit_dlc || return $?
2090         add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
2091         add_net "${NETTYPE}1" "${INTERFACES[0]}" || return $?
2092
2093         local prim_nid=$($LCTL list_nids | head -n 1)
2094
2095         do_lnetctl discover $prim_nid ||
2096                 error "failed to discover myself"
2097
2098         do_lnetctl set recovery_limit $default ||
2099                 error "failed to set recovery_limit"
2100
2101         default=$($LNETCTL global show |
2102                   awk '/max_recovery_ping_interval/{print $NF}')
2103         do_lnetctl set max_recovery_ping_interval 4 ||
2104                 error "failed to set max_recovery_ping_interval"
2105
2106         $LCTL net_drop_add -s *@${NETTYPE} -d *@${NETTYPE} -m GET -r 1 -e remote_error
2107         $LCTL net_drop_add -s *@${NETTYPE}1 -d *@${NETTYPE}1 -m GET -r 1 -e remote_error
2108
2109         # Set health to 0 on one interface. This forces it onto the recovery
2110         # queue.
2111         $LNETCTL peer set --nid $prim_nid --health 0
2112
2113         # See comment for check_ping_count()
2114         sleep 4
2115         check_nid_in_recovq "-p" "1"
2116         check_ping_count "peer_ni" "2"
2117
2118         sleep 9
2119         check_nid_in_recovq "-p" "1"
2120         check_ping_count "peer_ni" "4"
2121
2122         $LCTL net_drop_del -a
2123
2124         do_lnetctl set max_recovery_ping_interval $default ||
2125                 error "failed to set max_recovery_ping_interval"
2126
2127         return 0
2128 }
2129 run_test 211 "Remote NI recovery checks"
2130
2131 test_212() {
2132         [[ ${NETTYPE} == kfi* ]] && skip "kfi doesn't support drop rules"
2133
2134         local rnodes=$(remote_nodes_list)
2135         [[ -z $rnodes ]] && skip "Need at least 1 remote node"
2136
2137         cleanup_lnet || error "Failed to cleanup before test execution"
2138
2139         # Loading modules should configure LNet with the appropriate
2140         # test-framework configuration
2141         load_lnet "config_on_load=1" || error "Failed to load modules"
2142
2143         local my_nid=$($LCTL list_nids | head -n 1)
2144         [[ -z $my_nid ]] &&
2145                 error "Failed to get primary NID for local host $HOSTNAME"
2146
2147         local rnode=$(awk '{print $1}' <<<$rnodes)
2148         local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2149         local rloaded=false
2150
2151         if [[ -z $rnodenids ]]; then
2152                 do_rpc_nodes $rnode load_lnet "config_on_load=1"
2153                 rloaded=true
2154                 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2155         fi
2156
2157         local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
2158
2159         [[ -z $rnodepnid ]] &&
2160                 error "Failed to get primary NID for remote host $rnode"
2161
2162         log "Initial discovery"
2163         do_lnetctl discover --force $rnodepnid ||
2164                 error "Failed to discover $rnodepnid"
2165
2166         do_node $rnode "$LNETCTL discover --force $my_nid" ||
2167                 error "$rnode failed to discover $my_nid"
2168
2169         log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
2170         $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
2171         do_lnetctl discover --force $rnodepnid &&
2172                 error "Discovery should have failed"
2173         $LCTL net_drop_del -a
2174
2175         local nid
2176         for nid in $rnodenids; do
2177                 # We need GET (PING) delay just long enough so we can trigger
2178                 # discovery on the remote peer
2179                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
2180                 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
2181                 # We need PUT (PUSH) delay just long enough so we can process
2182                 # the PING failure
2183                 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
2184         done
2185
2186         log "Force $HOSTNAME to discover $rnodepnid (in background)"
2187         # We want to get a PING sent that we know will eventually fail.
2188         # The delay rules we added will ensure the ping is not sent until
2189         # the PUSH is also in flight (see below), and the drop rule ensures that
2190         # when the PING is eventually sent it will error out
2191         do_lnetctl discover --force $rnodepnid &
2192         local pid1=$!
2193
2194         # We want a discovery PUSH from rnode to put rnode back on our
2195         # discovery queue. This should cause us to try and send a PUSH to rnode
2196         # while the PING is still outstanding.
2197         log "Force $rnode to discover $my_nid"
2198         do_node $rnode $LNETCTL discover --force $my_nid
2199
2200         # At this point we'll have both PING_SENT and PUSH_SENT set for the
2201         # rnode peer. Wait for the PING to error out which should terminate the
2202         # discovery process that we backgrounded.
2203         log "Wait for $pid1"
2204         wait $pid1
2205         log "Finished wait on $pid1"
2206
2207         # The PING send failure clears the PING_SENT flag and puts the peer back
2208         # on the discovery queue. When discovery thread processes the peer it
2209         # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
2210         # Discovery will then complete for this peer even though we have an
2211         # outstanding PUSH.
2212         # When PUSH is actually unlinked it will be forced back onto the
2213         # discovery queue, but we no longer have a ref on the peer. When
2214         # discovery completes again, we'll trip the ASSERT in
2215         # lnet_destroy_peer_locked()
2216
2217         # Delete the delay rules to send the PUSH
2218         $LCTL net_delay_del -a
2219         # Delete the drop rules
2220         $LCTL net_drop_del -a
2221
2222         unload_modules ||
2223                 error "Failed to unload modules"
2224         if $rloaded; then
2225                 do_rpc_nodes $rnode unload_modules_local ||
2226                         error "Failed to unload modules on $rnode"
2227         fi
2228
2229         return 0
2230 }
2231 run_test 212 "Check discovery refcount loss bug (LU-14627)"
2232
2233 test_213() {
2234         [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
2235
2236         cleanup_netns || error "Failed to cleanup netns before test execution"
2237         cleanup_lnet || error "Failed to unload modules before test execution"
2238
2239         setup_fakeif || error "Failed to add fake IF"
2240         have_interface "$FAKE_IF" ||
2241                 error "Expect $FAKE_IF configured but not found"
2242
2243         reinit_dlc || return $?
2244
2245         add_net "tcp" "${INTERFACES[0]}" || return $?
2246         add_net "tcp" "$FAKE_IF" || return $?
2247
2248         local nid1=$(lctl list_nids | head -n 1)
2249         local nid2=$(lctl list_nids | tail --lines 1)
2250
2251         [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
2252                 error "Expect nid1 \"$nid1\" to be preferred"
2253
2254         [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
2255                 error "Expect nid2 \"$nid2\" to be preferred"
2256
2257         return 0
2258 }
2259 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2260
2261 function check_ni_status() {
2262         local nid="$1"
2263         local expect="$2"
2264
2265         local status=$($LNETCTL net show |
2266                        grep -A 1 ${nid} |
2267                        awk '/status/{print $NF}')
2268
2269         echo "NI ${nid} expect status \"${expect}\" found \"${status}\""
2270         if [[ $status != $expect ]]; then
2271                 error "Error: Expect NI status \"$expect\" for NID \"$nid\" but found \"$status\""
2272         fi
2273
2274         return 0
2275 }
2276
2277 test_214() {
2278         [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
2279
2280         cleanup_netns || error "Failed to cleanup netns before test execution"
2281         cleanup_lnet || error "Failed to unload modules before test execution"
2282
2283         setup_fakeif || error "Failed to add fake IF"
2284         have_interface "$FAKE_IF" ||
2285                 error "Expect $FAKE_IF configured but not found"
2286
2287         reinit_dlc || return $?
2288
2289         add_net "tcp" "${INTERFACES[0]}" || return $?
2290         add_net "tcp" "$FAKE_IF" || return $?
2291
2292         local nid1=$(lctl list_nids | head -n 1)
2293         local nid2=$(lctl list_nids | tail --lines 1)
2294
2295         check_ni_status "0@lo" up
2296         check_ni_status "$nid1" up
2297         check_ni_status "$nid2" up
2298
2299         do_lnetctl ping --source $nid2 $nid1 ||
2300                 error "$LNETCTL ping --source $nid2 $nid1 failed"
2301
2302         echo "Set $FAKE_IF down"
2303         echo "ip link set dev $FAKE_IF down"
2304         ip link set dev $FAKE_IF down
2305         check_ni_status "0@lo" up
2306         check_ni_status "$nid1" up
2307         check_ni_status "$nid2" down
2308 }
2309 run_test 214 "Check local NI status when link is downed"
2310
2311 get_ni_stat() {
2312         local nid=$1
2313         local stat=$2
2314
2315         $LNETCTL net show -v 2 |
2316                 egrep -e nid -e $stat |
2317                 grep -wA 1 $nid |
2318                 awk '/'$stat':/{print $NF}'
2319 }
2320
2321 ni_stats_pre() {
2322         local nidvar s
2323         for nidvar in nid1 nid2; do
2324                 for stat in send_count recv_count; do
2325                         s=$(get_ni_stat ${!nidvar} $stat)
2326                         eval ${nidvar}_pre_${stat}=$s
2327                 done
2328         done
2329 }
2330
2331 ni_stats_post() {
2332         local nidvar s
2333         for nidvar in nid1 nid2; do
2334                 for stat in send_count recv_count; do
2335                         s=$(get_ni_stat ${!nidvar} $stat)
2336                         eval ${nidvar}_post_${stat}=$s
2337                 done
2338         done
2339 }
2340
2341 ni_stat_changed() {
2342         local nidvar=$1
2343         local stat=$2
2344
2345         local pre post
2346         eval pre=\${${nidvar}_pre_${stat}}
2347         eval post=\${${nidvar}_post_${stat}}
2348
2349         echo "${!nidvar} pre ${stat} $pre post ${stat} $post"
2350
2351         [[ $pre -ne $post ]]
2352 }
2353
2354 test_215() {
2355         cleanup_netns || error "Failed to cleanup netns before test execution"
2356         cleanup_lnet || error "Failed to unload modules before test execution"
2357
2358         reinit_dlc || return $?
2359
2360         add_net "${NETTYPE}1" "${INTERFACES[0]}" || return $?
2361         add_net "${NETTYPE}2" "${INTERFACES[0]}" || return $?
2362
2363         local nid1=$($LCTL list_nids | head -n 1)
2364         local nid2=$($LCTL list_nids | tail --lines 1)
2365
2366         do_lnetctl peer add --prim $nid1 --nid $nid2 ||
2367                 error "Failed to add peer"
2368
2369         local npings=25
2370
2371         for nidvarA in nid1 nid2; do
2372                 src=${!nidvarA}
2373                 dst=${!nidvarA}
2374                 for nidvarB in nid1 nid2; do
2375                         [[ $nidvarA == $nidvarB ]] && continue
2376
2377                         ni_stats_pre
2378
2379                         echo "$LNETCTL ping $dst x $npings"
2380                         for i in $(seq 1 $npings); do
2381                                 $LNETCTL ping $dst &>/dev/null ||
2382                                         error "$LNETCTL ping $dst failed"
2383                         done
2384
2385                         ni_stats_post
2386
2387                         # No source specified, sends to either NID should cause
2388                         # counts to increase across both NIs
2389                         for nidvar in nid1 nid2; do
2390                                 for stat in send_count recv_count; do
2391                                         ni_stat_changed $nidvar $stat ||
2392                                                 error "$stat unchanged for ${!nidvar}"
2393                                 done
2394                         done
2395
2396                         ni_stats_pre
2397
2398                         echo "$LNETCTL ping --source $src $dst x $npings"
2399                         for i in $(seq 1 $npings); do
2400                                 $LNETCTL ping --source $src $dst &>/dev/null ||
2401                                         error "$LNETCTL ping --source $src $dst failed"
2402                         done
2403
2404                         ni_stats_post
2405
2406                         # src nid == dest nid means stats for the _other_ NI
2407                         # should be unchanged
2408                         for nidvar in nid1 nid2; do
2409                                 for stat in send_count recv_count; do
2410                                         if [[ ${!nidvar} == $src ]]; then
2411                                                 ni_stat_changed $nidvar $stat ||
2412                                                         error "$stat unchanged for ${!nidvar}"
2413                                         else
2414                                                 ni_stat_changed $nidvar $stat &&
2415                                                         error "$stat changed for ${!nidvar}"
2416                                         fi
2417                                 done
2418                         done
2419                 done
2420                 # Double number of pings for next iteration because the net
2421                 # sequence numbers will have diverged
2422                 npings=$(($npings * 2))
2423         done
2424
2425         # Ping from nid1 to nid2 should fail
2426         do_lnetctl ping --source $nid1 $nid2 &&
2427                 error "ping from $nid1 to $nid2 should fail"
2428
2429         # Ping from nid2 to nid1 should fail
2430         do_lnetctl ping --source $nid2 $nid1 &&
2431                 error "ping from $nid2 to $nid1 should fail"
2432
2433         return 0
2434 }
2435 run_test 215 "Test lnetctl ping --source option"
2436
2437 test_216() {
2438         [[ ${NETTYPE} == kfi* ]] && skip "kfi doesn't support drop rules"
2439
2440         local rc=0
2441
2442         reinit_dlc || return $?
2443
2444         add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
2445         add_net "${NETTYPE}1" "${INTERFACES[0]}" || return $?
2446
2447         local nids=( $($LCTL list_nids | xargs echo) )
2448
2449         do_lnetctl discover ${nids[0]} ||
2450                 error "Initial discovery failed"
2451
2452         do_lnetctl ping --source ${nids[0]} ${nids[0]} ||
2453                 error "Initial ping failed $?"
2454
2455         do_lnetctl ping --source ${nids[1]} ${nids[1]} ||
2456                 error "Initial ping failed $?"
2457
2458         local src dst
2459         for src in "${nids[@]}"; do
2460                 for dst in "${nids[@]}"; do
2461                         $LCTL net_drop_add -r 1 -s $src -d $dst -e network_timeout
2462                 done
2463         done
2464
2465         do_lnetctl ping ${nids[0]} || rc=$?
2466
2467         $LCTL net_drop_del -a
2468
2469         [[ $rc -eq 0 ]] &&
2470                 error "expected ping to fail"
2471
2472         check_nid_in_recovq "-p" 0
2473         check_nid_in_recovq "-l" 1
2474
2475         return 0
2476 }
2477 run_test 216 "Failed send to peer NI owned by local host should not trigger peer NI recovery"
2478
2479 test_217() {
2480         reinit_dlc || return $?
2481
2482         [[ $($LNETCTL net show | grep -c nid) -ne 1 ]] &&
2483                 error "Unexpected number of NIs after initalizing DLC"
2484
2485         do_lnetctl discover 0@lo ||
2486                 error "Failed to discover 0@lo"
2487
2488         unload_modules
2489 }
2490 run_test 217 "Don't leak memory when discovering peer with nnis <= 1"
2491
2492 test_218() {
2493         [[ ${NETTYPE} == kfi* ]] && skip "kfi doesn't support drop rules"
2494
2495         reinit_dlc || return $?
2496
2497         [[ ${#INTERFACES[@]} -lt 2 ]] &&
2498                 skip "Need two LNet interfaces"
2499
2500         add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
2501
2502         local nid1=$($LCTL list_nids | head -n 1)
2503
2504         do_lnetctl ping $nid1 ||
2505                 error "ping failed"
2506
2507         add_net "${NETTYPE}" "${INTERFACES[1]}" || return $?
2508
2509         local nid2=$($LCTL list_nids | tail --lines 1)
2510
2511         do_lnetctl ping $nid2 ||
2512                 error "ping failed"
2513
2514         $LCTL net_drop_add -s $nid1 -d $nid1 -e local_error -r 1
2515
2516         do_lnetctl ping --source $nid1 $nid1 &&
2517                 error "ping should have failed"
2518
2519         local health_recovered
2520         local i
2521
2522         for i in $(seq 1 5); do
2523                 health_recovered=$($LNETCTL net show -v 2 |
2524                                    grep -c 'health value: 1000')
2525
2526                 if [[ $health_recovered -ne 2 ]]; then
2527                         echo "Wait 1 second for health to recover"
2528                         sleep 1
2529                 else
2530                         break
2531                 fi
2532         done
2533
2534         health_recovered=$($LNETCTL net show -v 2 |
2535                            grep -c 'health value: 1000')
2536
2537         $LCTL net_drop_del -a
2538
2539         [[ $health_recovered -ne 2 ]] &&
2540                 do_lnetctl net show -v 2 | egrep -e nid -e health &&
2541                 error "Health hasn't recovered"
2542
2543         return 0
2544 }
2545 run_test 218 "Local recovery pings should exercise all available paths"
2546
2547 test_219() {
2548         reinit_dlc || return $?
2549         add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
2550         add_net "${NETTYPE}1" "${INTERFACES[0]}" || return $?
2551
2552         local nid1=$(lctl list_nids | head -n 1)
2553         local nid2=$(lctl list_nids | tail --lines 1)
2554
2555         do_lnetctl ping $nid1 ||
2556                 error "Ping failed $?"
2557         do_lnetctl ping $nid2 ||
2558                 error "Ping failed $?"
2559
2560         do_lnetctl discover $nid2 ||
2561                 error "Discovery failed"
2562
2563         $LNETCTL peer show --nid $nid1 | grep -q $nid2 ||
2564                 error "$nid2 is not listed under $nid1"
2565 }
2566 run_test 219 "Consolidate peer entries"
2567
2568 do_net_add() {
2569         local node=$1
2570         local net=$2
2571         local if=$3
2572         local opts=$4
2573
2574         do_rpc_nodes $node "$LNETCTL net add --net $net --if $if $opts" ||
2575                 error "add $net on interface $if on node $node failed rc=$?"
2576 }
2577
2578 do_route_add() {
2579         local node=$1
2580         local net=$2
2581         local gw=$3
2582
2583         do_node $node "$LNETCTL route add --net $net --gateway $gw" ||
2584                 error "route add to $net via $gw failed rc=$?"
2585 }
2586
2587 ROUTER=""
2588 ROUTER_INTERFACES=()
2589 RPEER=""
2590 RPEER_INTERFACES=()
2591 init_router_test_vars() {
2592         local rnodes=$(remote_nodes_list)
2593         [[ -z $rnodes || $(wc -w <<<$rnodes) -lt 2 ]] &&
2594                 skip "Need at least 2 remote nodes found \"$rnodes\""
2595
2596         ROUTER=$(awk '{print $1}' <<<$rnodes)
2597         RPEER=$(awk '{print $2}' <<<$rnodes)
2598
2599         rnodes=$(comma_list $ROUTER $RPEER)
2600         local all_nodes=$(comma_list $rnodes $HOSTNAME)
2601
2602         do_nodes $rnodes $LUSTRE_RMMOD ||
2603                 error "failed to unload modules"
2604
2605         do_rpc_nodes $rnodes "load_lnet config_on_load=1" ||
2606                 error "Failed to load and configure LNet"
2607
2608         ROUTER_INTERFACES=( $(do_rpc_nodes --quiet $ROUTER lnet_if_list) )
2609
2610         RPEER_INTERFACES=( $(do_rpc_nodes --quiet $RPEER lnet_if_list) )
2611
2612         do_nodes $all_nodes $LUSTRE_RMMOD ||
2613                 error "Failed to unload modules"
2614
2615         [[ ${#INTERFACES[@]} -eq 0 ]] &&
2616                 error "No interfaces configured for local host $HOSTNAME"
2617         [[ ${#ROUTER_INTERFACES[@]} -eq 0 ]] &&
2618                 error "No interfaces configured for router $ROUTER"
2619         [[ ${#RPEER_INTERFACES[@]} -eq 0 ]] &&
2620                 error "No interfaces configured for remote peer $RPEER"
2621
2622         return 0
2623 }
2624
2625 ROUTER_NIDS=()
2626 RPEER_NIDS=()
2627 LNIDS=()
2628 LOCAL_NET=${NETTYPE}1
2629 REMOTE_NET=${NETTYPE}2
2630 setup_router_test() {
2631         local mod_opts="$1"
2632         local rtr_net_opts="$2"
2633
2634         (( $MDS1_VERSION >= $(version_code 2.15.0) )) ||
2635                 skip "need at least 2.15.0 for load_lnet"
2636
2637         if [[ ${#RPEER_INTERFACES[@]} -eq 0 ]]; then
2638                 init_router_test_vars ||
2639                         return $?
2640         fi
2641
2642         local all_nodes=$(comma_list $ROUTER $RPEER $HOSTNAME)
2643
2644         do_nodes $all_nodes $LUSTRE_RMMOD ||
2645                 error "failed to unload modules"
2646
2647         mod_opts+=" alive_router_check_interval=5"
2648         mod_opts+=" router_ping_timeout=5"
2649         mod_opts+=" large_router_buffers=4"
2650         mod_opts+=" small_router_buffers=8"
2651         mod_opts+=" tiny_router_buffers=16"
2652         do_rpc_nodes $all_nodes load_lnet "${mod_opts}" ||
2653                 error "Failed to load lnet"
2654
2655         do_nodes $all_nodes "$LNETCTL lnet configure" ||
2656                 error "Failed to initialize DLC"
2657
2658         do_net_add $ROUTER $LOCAL_NET ${ROUTER_INTERFACES[0]} $rtr_net_opts ||
2659                 return $?
2660
2661         do_net_add $ROUTER $REMOTE_NET ${ROUTER_INTERFACES[0]} ||
2662                 return $?
2663
2664         do_net_add $RPEER $REMOTE_NET ${RPEER_INTERFACES[0]} ||
2665                 return $?
2666
2667         add_net $LOCAL_NET ${INTERFACES[0]} ||
2668                 return $?
2669
2670         ROUTER_NIDS=( $(do_node $ROUTER $LCTL list_nids 2>/dev/null |
2671                         xargs echo) )
2672         RPEER_NIDS=( $(do_node $RPEER $LCTL list_nids 2>/dev/null |
2673                        xargs echo) )
2674         LNIDS=( $($LCTL list_nids 2>/dev/null | xargs echo) )
2675 }
2676
2677 do_route_del() {
2678         local node=$1
2679         local net=$2
2680         local gw=$3
2681
2682         do_nodesv $node "if $LNETCTL route show --net $net --gateway $gw; then \
2683                                 $LNETCTL route del --net $net --gateway $gw;   \
2684                          else                                                  \
2685                                 exit 0;                                        \
2686                          fi"
2687 }
2688
2689 cleanup_router_test() {
2690         local all_nodes=$(comma_list $HOSTNAME $ROUTER $RPEER)
2691
2692         do_route_del $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2693                 error "Failed to delete $REMOTE_NET route"
2694
2695         do_route_del $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2696                 error "Failed to delete $LOCAL_NET route"
2697
2698         do_nodes $all_nodes $LUSTRE_RMMOD ||
2699                 error "failed to unload modules"
2700
2701         return 0
2702 }
2703
2704 check_route_aliveness() {
2705         local node="$1"
2706         local expected="$2"
2707
2708         local lctl_actual
2709         local lnetctl_actual
2710         local chk_intvl
2711         local i
2712
2713         chk_intvl=$(cat /sys/module/lnet/parameters/alive_router_check_interval)
2714
2715         lctl_actual=$(do_node $node $LCTL show_route | awk '{print $7}')
2716         lnetctl_actual=$(do_node $node $LNETCTL route show -v |
2717                          awk '/state/{print $NF}')
2718
2719         for ((i = 0; i < $chk_intvl; i++)); do
2720                 if [[ $lctl_actual == $expected ]] &&
2721                    [[ $lnetctl_actual == $expected ]]; then
2722                         break
2723                 fi
2724
2725                 echo "wait 1s for route state change"
2726                 sleep 1
2727
2728                 lctl_actual=$(do_node $node $LCTL show_route | awk '{print $7}')
2729                 lnetctl_actual=$(do_node $node $LNETCTL route show -v |
2730                                  awk '/state/{print $NF}')
2731         done
2732
2733         [[ $lctl_actual != $expected ]] &&
2734                 error "Wanted \"$expected\" lctl found \"$lctl_actual\""
2735
2736         [[ $lnetctl_actual != $expected ]] &&
2737                 error "Wanted \"$expected\" lnetctl found \"$lnetctl_actual\""
2738
2739         return 0
2740 }
2741
2742 check_router_ni_status() {
2743         local expected_local="$1"
2744         local expected_remote="$2"
2745
2746         local actual_local
2747         local actual_remote
2748         local chk_intvl
2749         local timeout
2750         local i
2751
2752         chk_intvl=$(cat /sys/module/lnet/parameters/alive_router_check_interval)
2753         timeout=$(cat /sys/module/lnet/parameters/router_ping_timeout)
2754
2755         actual_local=$(do_node $ROUTER "$LNETCTL net show --net $LOCAL_NET" |
2756                        awk '/status/{print $NF}')
2757         actual_remote=$(do_node $ROUTER "$LNETCTL net show --net $REMOTE_NET" |
2758                         awk '/status/{print $NF}')
2759
2760         for ((i = 0; i < $((chk_intvl + timeout)); i++)); do
2761                 if [[ $actual_local == $expected_local ]] &&
2762                    [[ $actual_remote == $expected_remote ]]; then
2763                         break
2764                 fi
2765
2766                 echo "wait 1s for NI state change"
2767                 sleep 1
2768
2769                 actual_local=$(do_node $ROUTER \
2770                                "$LNETCTL net show --net $LOCAL_NET" |
2771                                 awk '/status/{print $NF}')
2772                 actual_remote=$(do_node $ROUTER \
2773                                 "$LNETCTL net show --net $REMOTE_NET" |
2774                                 awk '/status/{print $NF}')
2775         done
2776
2777         [[ $actual_local == $expected_local ]] ||
2778                 error "$LOCAL_NET should be $expected_local"
2779
2780         [[ $actual_remote == $expected_remote ]] ||
2781                 error "$REMOTE_NET should be $expected_remote"
2782
2783         return 0
2784 }
2785
2786 do_basic_rtr_test() {
2787         do_node $ROUTER "$LNETCTL set routing 1" ||
2788                 error "Unable to enable routing on $ROUTER"
2789
2790         do_route_add $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2791                 return $?
2792
2793         do_route_add $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2794                 return $?
2795
2796         check_route_aliveness "$HOSTNAME" "up" ||
2797                 return $?
2798
2799         check_route_aliveness "$RPEER" "up" ||
2800                 return $?
2801
2802         do_lnetctl ping ${RPEER_NIDS[0]} ||
2803                 error "Failed to ping ${RPEER_NIDS[0]}"
2804
2805         do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" ||
2806                 error "$RPEER failed to ping ${LNIDS[0]}"
2807
2808         return 0
2809 }
2810
2811 test_220() {
2812         setup_router_test || return $?
2813
2814         do_basic_rtr_test || return $?
2815
2816         do_rpc_nodes $HOSTNAME,$RPEER load_module ../lnet/selftest/lnet_selftest ||
2817                 error "Failed to load lnet-selftest module"
2818
2819         $LSTSH -H -t $HOSTNAME -f $RPEER -m rw -s 4k ||
2820                 error "lst failed"
2821
2822         $LSTSH -H -t $HOSTNAME -f $RPEER -m rw ||
2823                 error "lst failed"
2824
2825         cleanup_router_test || return $?
2826 }
2827 run_test 220 "Add routes w/default options - check aliveness"
2828
2829 test_221() {
2830         setup_router_test lnet_peer_discovery_disabled=1 || return $?
2831
2832         do_basic_rtr_test || return $?
2833
2834         cleanup_router_test || return $?
2835 }
2836 run_test 221 "Add routes w/DD disabled - check aliveness"
2837
2838 do_aarf_enabled_test() {
2839         do_node $ROUTER "$LNETCTL set routing 1" ||
2840                 error "Unable to enable routing on $ROUTER"
2841
2842         check_router_ni_status "down" "down"
2843
2844         do_lnetctl ping ${RPEER_NIDS[0]} &&
2845                 error "Ping should fail"
2846
2847         do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" &&
2848                 error "$RPEER ping should fail"
2849
2850         # Adding a route should cause the router's NI on LOCAL_NET to get up
2851         do_route_add $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2852                 return $?
2853
2854         check_router_ni_status "up" "down" ||
2855                 return $?
2856
2857         # But route should still be down because of avoid_asym_router_failure
2858         check_route_aliveness "$HOSTNAME" "down" ||
2859                 return $?
2860
2861         do_lnetctl ping ${RPEER_NIDS[0]} &&
2862                 error "Ping should fail"
2863
2864         do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" &&
2865                 error "$RPEER ping should fail"
2866
2867         # Adding the symmetric route should cause the remote NI to go up and
2868         # routes to go up
2869         do_route_add $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2870                 return $?
2871
2872         check_router_ni_status "up" "up" ||
2873                 return $?
2874
2875         check_route_aliveness "$HOSTNAME" "up" ||
2876                 return $?
2877
2878         check_route_aliveness "$RPEER" "up" ||
2879                 return $?
2880
2881         do_lnetctl ping ${RPEER_NIDS[0]} ||
2882                 error "Failed to ping ${RPEER_NIDS[0]}"
2883
2884         do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" ||
2885                 error "$RPEER failed to ping ${LNIDS[0]}"
2886
2887         # Stop LNet on local host
2888         do_lnetctl lnet unconfigure ||
2889                 error "Failed to stop LNet rc=$?"
2890
2891         check_router_ni_status "down" "up" ||
2892                 return $?
2893
2894         check_route_aliveness "$RPEER" "down" ||
2895                 return $?
2896
2897         do_lnetctl ping ${RPEER_NIDS[0]} &&
2898                 error "Ping should fail"
2899
2900         do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" &&
2901                 error "$RPEER ping should fail"
2902
2903         return 0
2904 }
2905
2906 test_222() {
2907         setup_router_test avoid_asym_router_failure=1 || return $?
2908
2909         do_aarf_enabled_test || return $?
2910
2911         cleanup_router_test || return $?
2912 }
2913 run_test 222 "Check avoid_asym_router_failure=1"
2914
2915 test_223() {
2916         local opts="avoid_asym_router_failure=1 lnet_peer_discovery_disabled=1"
2917
2918         setup_router_test "$opts" || return $?
2919
2920         do_aarf_enabled_test || return $?
2921
2922         cleanup_router_test || return $?
2923 }
2924 run_test 223 "Check avoid_asym_router_failure=1 w/DD disabled"
2925
2926 do_aarf_disabled_test() {
2927         do_node $ROUTER "$LNETCTL set routing 1" ||
2928                 error "Unable to enable routing on $ROUTER"
2929
2930         check_router_ni_status "down" "down"
2931
2932         do_route_add $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2933                 return $?
2934
2935         check_router_ni_status "up" "down" ||
2936                 return $?
2937
2938         check_route_aliveness "$HOSTNAME" "up" ||
2939                 return $?
2940
2941         do_route_add $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2942                 return $?
2943
2944         check_router_ni_status "up" "up" ||
2945                 return $?
2946
2947         check_route_aliveness "$HOSTNAME" "up" ||
2948                 return $?
2949
2950         check_route_aliveness "$RPEER" "up" ||
2951                 return $?
2952
2953         do_lnetctl ping ${RPEER_NIDS[0]} ||
2954                 error "Failed to ping ${RPEER_NIDS[0]}"
2955
2956         do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" ||
2957                 error "$RPEER failed to ping ${LNIDS[0]}"
2958
2959         # Stop LNet on local host
2960         do_lnetctl lnet unconfigure ||
2961                 error "Failed to stop LNet rc=$?"
2962
2963         check_router_ni_status "down" "up" ||
2964                 return $?
2965
2966         check_route_aliveness "$RPEER" "up" ||
2967                 return $?
2968
2969         return 0
2970 }
2971
2972 test_224() {
2973         setup_router_test avoid_asym_router_failure=0 ||
2974                 return $?
2975
2976         do_aarf_disabled_test ||
2977                 return $?
2978
2979         cleanup_router_test ||
2980                 return $?
2981 }
2982 run_test 224 "Check avoid_asym_router_failure=0"
2983
2984 test_225() {
2985         local opts="avoid_asym_router_failure=0 lnet_peer_discovery_disabled=1"
2986
2987         setup_router_test "$opts" || return $?
2988
2989         do_aarf_disabled_test || return $?
2990
2991         cleanup_router_test ||
2992                 return $?
2993 }
2994 run_test 225 "Check avoid_asym_router_failure=0 w/DD disabled"
2995
2996 do_rtr_peer_health_test() {
2997         local expected="$1"
2998
2999         do_node $ROUTER "$LNETCTL set routing 1" ||
3000                 error "Unable to enable routing on $ROUTER"
3001
3002         do_route_add $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
3003                 return $?
3004
3005         do_route_add $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
3006                 return $?
3007
3008         check_router_ni_status "up" "up" ||
3009                 return $?
3010
3011         check_route_aliveness "$HOSTNAME" "up" ||
3012                 return $?
3013
3014         check_route_aliveness "$RPEER" "up" ||
3015                 return $?
3016
3017         do_lnetctl ping ${RPEER_NIDS[0]} ||
3018                 error "Failed to ping ${RPEER_NIDS[0]}"
3019
3020         do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" ||
3021                 error "$RPEER failed to ping ${LNIDS[0]}"
3022
3023         # Stop LNet on local host
3024         do_lnetctl lnet unconfigure ||
3025                 error "Failed to stop LNet rc=$?"
3026
3027         check_router_ni_status "down" "up" ||
3028                 return $?
3029
3030         check_route_aliveness "$RPEER" "up" ||
3031                 return $?
3032
3033         # The NI used to send the message to the destination will be the
3034         # router's NI on LOCAL_NET, so that's the drop count that will be
3035         # incremented
3036         local d1=$(do_node $ROUTER $LNETCTL net show -v --net $LOCAL_NET | \
3037                                    awk '/drop_count:/{print $NF}')
3038
3039         # Ping from RPEER to local host should be dropped by the router
3040         do_node $RPEER "$LCTL ping ${LNIDS[0]}" &&
3041                 error "$RPEER expected ping to fail"
3042
3043         local d2=$(do_node $ROUTER $LNETCTL net show -v --net $LOCAL_NET | \
3044                                    awk '/drop_count:/{print $NF}')
3045
3046         [[ $((d2 - d1)) -ne $expected ]] &&
3047                 error "Expected drop count change by $expected: $d1 -> $d2"
3048
3049         return 0
3050 }
3051
3052 test_226() {
3053         setup_router_test avoid_asym_router_failure=0 --peer-timeout=10 ||
3054                 return $?
3055
3056         do_rtr_peer_health_test 1 ||
3057                 return $?
3058
3059         cleanup_router_test ||
3060                 return $?
3061 }
3062 run_test 226 "Check router peer health enabled"
3063
3064 test_227() {
3065         setup_router_test avoid_asym_router_failure=0 --peer-timeout=0 ||
3066                 return $?
3067
3068         do_rtr_peer_health_test 0 ||
3069                 return $?
3070
3071         cleanup_router_test ||
3072                 return $?
3073 }
3074 run_test 227 "Check router peer health disabled"
3075
3076 test_230() {
3077         [[ ${NETTYPE} == tcp* ]] ||
3078                 skip "Need tcp NETTYPE"
3079         # LU-12815
3080         echo "Check valid values; Should succeed"
3081         local i
3082         local lnid
3083         local cmd
3084         for ((i = 4; i < 16; i+=1)); do
3085                 reinit_dlc || return $?
3086                 add_net "tcp" "${INTERFACES[0]}" || return $?
3087                 do_lnetctl net set --all --conns-per-peer $i ||
3088                         error "should have succeeded $?"
3089                 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
3090                         error "failed to set conns-per-peer to $i"
3091                 lnid="$(lctl list_nids | head -n 1)"
3092                 do_lnetctl ping "$lnid" ||
3093                         error "failed to ping myself"
3094
3095                 # "lctl --net tcp conn_list" prints the list of active
3096                 # connections. Since we're pinging ourselves, there should be
3097                 # 2 Control connections plus 2*conns_per_peer connections
3098                 # created (one Bulk Input, one Bulk Output in each pair).
3099                 # Here's the sample output for conns_per_peer set to 1:
3100                 # 12345-1.1.1.1@tcp I[0]host01->host01:988 2626560/1061296 nonagle
3101                 # 12345-1.1.1.1@tcp O[0]host01->host01:1022 2626560/1061488 nonagle
3102                 # 12345-1.1.1.1@tcp C[0]host01->host01:988 2626560/1061296 nonagle
3103                 # 12345-1.1.1.1@tcp C[0]host01->host01:1023 2626560/1061488 nonagle
3104                 cmd="printf 'network tcp\nconn_list\n' | lctl | grep -c '$lnid'"
3105
3106                 # Expect 2+conns_per_peer*2 connections. Wait no longer
3107                 # than 2 seconds.
3108                 wait_update $HOSTNAME "$cmd" "$((2+i*2))" 2 ||
3109                         error "expected number of tcp connections $((2+i*2))"
3110         done
3111
3112         reinit_dlc || return $?
3113         add_net "tcp" "${INTERFACES[0]}" || return $?
3114         echo "Set > 127; Should fail"
3115         do_lnetctl net set --all --conns-per-peer 128 &&
3116                 error "should have failed $?"
3117
3118         reinit_dlc || return $?
3119         add_net "tcp" "${INTERFACES[0]}" || return $?
3120
3121         local default=$($LNETCTL net show -v 1 |
3122                         awk '/conns_per_peer/{print $NF}')
3123
3124         echo "Set < 0; Should be ignored"
3125         do_lnetctl net set --all --conns-per-peer -1 ||
3126                 error "should have succeeded $?"
3127         $LNETCTL net show -v 1 | grep -q "conns_per_peer: ${default}" ||
3128                 error "Did not stay at default"
3129 }
3130 run_test 230 "Test setting conns-per-peer"
3131
3132 test_231() {
3133         reinit_dlc || return $?
3134
3135         local net=${NETTYPE}231
3136
3137         do_lnetctl net add --net $net --if ${INTERFACES[0]} ||
3138                 error "Failed to add net"
3139
3140         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
3141         sed -i 's/peer_timeout: .*$/peer_timeout: 0/' \
3142                 $TMP/sanity-lnet-$testnum-expected.yaml
3143
3144         reinit_dlc || return $?
3145
3146         do_lnetctl import $TMP/sanity-lnet-$testnum-expected.yaml ||
3147                 error "Failed to import configuration"
3148
3149         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
3150
3151         compare_yaml_files || error "Wrong config after import"
3152
3153         do_lnetctl net del --net $net --if ${INTERFACES[0]} ||
3154                 error "Failed to delete net $net"
3155
3156         do_lnetctl net add --net $net --if ${INTERFACES[0]} --peer-timeout=0 ||
3157                 error "Failed to add net with peer-timeout=0"
3158
3159         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
3160
3161         compare_yaml_files || error "Wrong config after lnetctl net add"
3162
3163         reinit_dlc || return $?
3164
3165         # lnet/include/lnet/lib-lnet.h defines DEFAULT_PEER_TIMEOUT 180
3166         sed -i 's/peer_timeout: .*$/peer_timeout: 180/' \
3167                 $TMP/sanity-lnet-$testnum-expected.yaml
3168
3169         sed -i '/^.*peer_timeout:.*$/d' $TMP/sanity-lnet-$testnum-actual.yaml
3170
3171         do_lnetctl import $TMP/sanity-lnet-$testnum-actual.yaml ||
3172                 error "Failed to import config without peer_timeout"
3173
3174         $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
3175
3176         compare_yaml_files
3177 }
3178 run_test 231 "Check DLC handling of peer_timeout parameter"
3179
3180 ### Test that linux route is added for each ni
3181 test_250() {
3182         local skip_param
3183
3184         [[ ${NETTYPE} == tcp* ]] ||
3185                 skip "Need tcp NETTYPE"
3186         reinit_dlc || return $?
3187         add_net "tcp" "${INTERFACES[0]}" || return $?
3188
3189         skip_param=$(cat /sys/module/ksocklnd/parameters/skip_mr_route_setup)
3190         [[ ${skip_param:-0} -ne 0 ]] &&
3191                 skip "Need skip_mr_route_setup=0 found $skip_param"
3192
3193         ip route show table ${INTERFACES[0]} | grep -q "${INTERFACES[0]}"
3194 }
3195 run_test 250 "test that linux routes are added"
3196
3197 test_251() {
3198         [[ ${NETTYPE} =~ kfi* ]] ||
3199                 skip "Need kfi NETTYPE"
3200
3201         reinit_dlc || return $?
3202         add_net "kfi" "${INTERFACES[0]}" || return $?
3203         add_net "kfi1" "${INTERFACES[0]}" || return $?
3204         add_net "kfi10" "${INTERFACES[0]}" || return $?
3205         return 0
3206 }
3207 run_test 251 "Define multiple kfi networks on single interface"
3208
3209 test_252() {
3210         setup_health_test false || return $?
3211
3212         local rc=0
3213
3214         do_rpc_nodes $RNODE unload_modules_local || rc=$?
3215
3216         if [[ $rc -ne 0 ]]; then
3217                 cleanup_health_test || return $?
3218
3219                 error "Failed to unload modules on $RNODE rc=$rc"
3220         else
3221                 RLOADED=false
3222         fi
3223
3224         local ts1=$(date +%s)
3225
3226         do_lnetctl ping --timeout 15 ${RNIDS[0]} &&
3227                 error "Expected ping ${RNIDS[0]} to fail"
3228
3229         local ts2=$(date +%s)
3230
3231         local delta=$(echo "$ts2 - $ts1" | bc)
3232
3233         [[ $delta -lt 15 ]] ||
3234                 error "Ping took longer than expected to fail: $delta"
3235
3236         cleanup_health_test
3237 }
3238 run_test 252 "Ping to down peer should unlink quickly"
3239
3240 do_expired_message_drop_test() {
3241         local rnid lnid old_tto
3242
3243         old_tto=$($LNETCTL global show |
3244                   awk '/transaction_timeout:/{print $NF}')
3245
3246         [[ -z $old_tto ]] &&
3247                 error "Cannot determine LNet transaction timeout"
3248
3249         local tto=10
3250
3251         do_lnetctl set transaction_timeout "${tto}" ||
3252                 error "Failed to set transaction_timeout"
3253
3254         # We want to consume all peer credits for at least transaction_timeout
3255         # seconds
3256         local delay
3257
3258         delay=$((tto + 1))
3259
3260         for lnid in "${LNIDS[@]}"; do
3261                 for rnid in "${RNIDS[@]}"; do
3262                         $LCTL net_delay_add -s "${lnid}" -d "${rnid}" \
3263                                 -l "${delay}" -r 1 -m GET
3264                 done
3265         done
3266
3267         declare -a pcs
3268
3269         pcs=( $($LNETCTL peer show -v --nid "${RNIDS[0]}" |
3270                 awk '/max_ni_tx_credits:/{print $NF}' |
3271                 xargs echo) )
3272
3273         [[ ${#RNIDS[@]} -ne ${#pcs[@]} ]] &&
3274                 error "Expect ${#RNIDS[@]} peer credit values found ${#pcs[@]}"
3275
3276         local rnet lnid lnet i j
3277
3278         # Need to use --source for multi-rail configs to ensure we consume
3279         # all available peer credits
3280         for ((i = 0; i < ${#RNIDS[@]}; i++)); do
3281                 local ping_args="--timeout $((delay+2))"
3282
3283                 rnet=${RNIDS[i]##*@}
3284                 for lnid in ${LNIDS[@]}; do
3285                         lnet=${lnid##*@}
3286                         [[ $rnet == $lnet ]] && break
3287                 done
3288
3289                 ping_args+=" --source ${lnid} ${RNIDS[i]}"
3290                 for j in $(seq 1 "${pcs[i]}"); do
3291                         $LNETCTL ping ${ping_args} 1>/dev/null &
3292                 done
3293
3294                 echo "Issued ${pcs[i]} pings to ${RNIDS[i]} from $lnid"
3295         done
3296
3297         # This ping should be queued on peer NI tx credit
3298         $LNETCTL ping --timeout $((delay+2)) "${RNIDS[0]}" &
3299
3300         sleep ${delay}
3301
3302         $LCTL net_delay_del -a
3303
3304         wait
3305
3306         # Messages sent from the delay list do not go through
3307         # lnet_post_send_locked(), thus we should only have a single drop
3308         local dropped
3309
3310         dropped=$($LNETCTL peer show -v 2 --nid "${RNIDS[0]}" |
3311                         grep -A 2 dropped_stats |
3312                         awk '/get:/{print $2}' |
3313                         xargs echo |
3314                         sed 's/ /\+/g' | bc)
3315
3316         [[ $dropped -ne 1 ]] &&
3317                 error "Expect 1 dropped GET but found $dropped"
3318
3319         do_lnetctl set transaction_timeout "${old_tto}"
3320
3321         return 0
3322 }
3323
3324 test_253() {
3325         setup_health_test false || return $?
3326
3327         do_expired_message_drop_test || return $?
3328
3329         cleanup_health_test
3330 }
3331 run_test 253 "Message delayed beyond deadline should be dropped (single-rail)"
3332
3333 test_254() {
3334         setup_health_test true || return $?
3335
3336         do_expired_message_drop_test || return $?
3337
3338         cleanup_health_test
3339 }
3340 run_test 254 "Message delayed beyond deadline should be dropped (multi-rail)"
3341
3342 test_255() {
3343         [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
3344
3345         reinit_dlc || return $?
3346
3347         cleanup_lnet || return $?
3348
3349         local routes_str="o2ib ${IF0_NET}.[$GW_HOSTNUM-$((GW_HOSTNUM+4))]"
3350         local network_str="${NETTYPE}(${INTERFACES[0]})"
3351
3352         load_lnet "networks=\"${network_str}\" routes=\"${routes_str}\"" ||
3353                 error "Failed to load LNet"
3354
3355         $LCTL net up ||
3356                 error "Failed to load LNet with networks=\"${network_str}\" routes=\"${routes_str}\""
3357
3358         cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
3359 net:
3360     - net type: ${NETTYPE}
3361       local NI(s):
3362         - interfaces:
3363               0: ${INTERFACES[0]}
3364 EOF
3365         append_net_tunables tcp
3366
3367         echo "route:" >> $TMP/sanity-lnet-$testnum-expected.yaml
3368         for i in $(seq $GW_HOSTNUM $((GW_HOSTNUM + 4))); do
3369                 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
3370     - net: o2ib
3371       gateway: ${IF0_NET}.${i}@${NETTYPE}
3372       hop: -1
3373       priority: 0
3374       health_sensitivity: 1
3375 EOF
3376         done
3377
3378         echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
3379         for i in $(seq $GW_HOSTNUM $((GW_HOSTNUM + 4))); do
3380                 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
3381     - primary nid: ${IF0_NET}.${i}@${NETTYPE}
3382       Multi-Rail: False
3383       peer ni:
3384         - nid: ${IF0_NET}.${i}@${NETTYPE}
3385 EOF
3386         done
3387
3388         append_global_yaml
3389
3390         $LNETCTL export --backup >  $TMP/sanity-lnet-$testnum-actual.yaml ||
3391                 error "export failed $?"
3392
3393         validate_gateway_nids
3394 }
3395 run_test 255 "Use lnet routes param with pdsh syntax"
3396
3397 test_300() {
3398         # LU-13274
3399         local header
3400         local out=$TMP/$tfile
3401         local prefix=/usr/include/linux/lnet
3402
3403         # We use a hard coded prefix so that this test will not fail
3404         # when run in tree.
3405         CC=${CC:-cc}
3406         if ! which $CC > /dev/null 2>&1; then
3407                 skip_env "$CC is not installed"
3408         fi
3409
3410         cleanup_lnet || exit 1
3411         load_lnet
3412
3413         local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
3414         if ! [[ -d $prefix ]]; then
3415                 # Assume we're running in tree and fixup the include path.
3416                 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
3417                 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
3418         fi
3419
3420         for header in $prefix/*.h; do
3421                 if ! [[ -f "$header" ]]; then
3422                         continue
3423                 fi
3424
3425                 echo "$CC $cc_args -include $header"
3426                 $CC $cc_args -include $header ||
3427                         error "cannot compile '$header'"
3428         done
3429         rm -f $out
3430 }
3431 run_test 300 "packaged LNet UAPI headers can be compiled"
3432
3433 # LU-16081 lnet: Memory leak on adding existing interface
3434
3435 test_301() {
3436         reinit_dlc || return $?
3437         do_lnetctl net add --net ${NETTYPE} --if ${INTERFACES[0]} ||
3438                 error "Failed to add net"
3439         do_lnetctl net add --net ${NETTYPE} --if ${INTERFACES[0]} &&
3440                 error "add net should have failed"
3441         do_lnetctl net del --net ${NETTYPE} --if ${INTERFACES[0]} ||
3442                 error "Failed to del net"
3443         unload_modules
3444 }
3445 run_test 301 "Check for dynamic adds of same/wrong interface (memory leak)"
3446
3447 test_302() {
3448         ! [[ $NETTYPE =~ (tcp|o2ib) ]] && skip "Need tcp or o2ib NETTYPE"
3449         reinit_dlc || return $?
3450
3451         add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
3452
3453         local nid=$($LCTL list_nids)
3454
3455         do_lnetctl ping ${nid} ||
3456                 error "pinging self failed $?"
3457         do_lnetctl debug peer --nid ${nid} ||
3458                 error "failed to dump peer debug info $?"
3459 }
3460 run_test 302 "Check that peer debug info can be dumped"
3461
3462 test_303() {
3463         [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
3464
3465         setup_health_test true || return $?
3466
3467         cleanup_netns || error "Failed to cleanup netns before test execution"
3468         setup_fakeif || error "Failed to add fake IF"
3469         have_interface "$FAKE_IF" ||
3470                 error "Expect $FAKE_IF configured but not found"
3471
3472         add_net "${NETTYPE}99" "$FAKE_IF" || return $?
3473
3474         local nid=$($LCTL list_nids | tail --lines 1)
3475
3476         # Our updated config should be pushed to RNODE
3477         local found=$(do_node $RNODE "$LNETCTL peer show --nid $nid")
3478
3479         [[ -z $found ]] && error "Peer not updated on $RNODE"
3480
3481         local prim=$($LCTL list_nids | head -n 1)
3482
3483         if ! grep -q -- "- primary nid: $prim"<<<"${found}"; then
3484                 echo "$found"
3485                 error "Wrong primary nid"
3486         fi
3487
3488         echo "Set $FAKE_IF down"
3489         echo "ip link set dev $FAKE_IF down"
3490         ip link set dev $FAKE_IF down
3491         check_ni_status "$nid" down
3492
3493         local hval=$(do_node $RNODE "$LNETCTL peer show --nid $nid -v 2 | \
3494                                      grep -e '- nid:' -e 'health value:'")
3495
3496         hval=$(grep -A 1 $nid<<<"$hval" | tail -n 1 | awk '{print $NF}')
3497         (( hval < 1000 )) ||
3498                 error "Expect $hval < 1000"
3499
3500         return 0
3501 }
3502 run_test 303 "Check peer NI health after link down"
3503
3504 test_304() {
3505         [[ ${NETTYPE} == tcp* ]] || skip "Need tcp NETTYPE"
3506
3507         cleanup_netns || error "Failed to cleanup netns before test execution"
3508         cleanup_lnet || error "Failed to unload modules before test execution"
3509
3510         setup_fakeif || error "Failed to add fake IF"
3511         have_interface "$FAKE_IF" ||
3512                 error "Expect $FAKE_IF configured but not found"
3513
3514         reinit_dlc || return $?
3515
3516         add_net "tcp" "${INTERFACES[0]}" || return $?
3517         add_net "tcp" "$FAKE_IF" || return $?
3518
3519         local nid1=$(lctl list_nids | head -n 1)
3520         local nid2=$(lctl list_nids | tail --lines 1)
3521
3522         check_ni_status "$nid1" up
3523         check_ni_status "$nid2" up
3524
3525         do_lnetctl peer add --prim_nid ${nid2} --lock_prim ||
3526                 error "peer add failed $?"
3527         local locked_peer_state=($(do_lnetctl peer show -v 4 --nid ${nid2} |
3528                 awk '/peer state/{print $NF}'))
3529
3530         # Expect peer state bits:
3531         #   LNET_PEER_MULTI_RAIL(0) | LNET_PEER_CONFIGURED(3) |
3532         #   LNET_PEER_LOCK_PRIMARY(20)
3533         (( $locked_peer_state != "1048585")) &&
3534                 error "Wrong peer state \"$locked_peer_state\" expected 1048585"
3535
3536         # Clear LNET_PEER_CONFIGURED bit and verify
3537         do_lnetctl peer set --nid ${nid2} --state 1048577 ||
3538                 error "peer add failed $?"
3539         locked_peer_state=($(do_lnetctl peer show -v 4 --nid ${nid2} |
3540                 awk '/peer state/{print $NF}'))
3541         (( $locked_peer_state != "1048577")) &&
3542                 error "Wrong peer state \"$locked_peer_state\" expected 1048577"
3543         do_lnetctl discover ${nid1} ||
3544                 error "Failed to discover peer"
3545
3546         # Expect nid2 and nid1 peer entries to be consolidated,
3547         # nid2 to stay primary
3548         cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
3549 peer:
3550     - primary nid: ${nid2}
3551       Multi-Rail: True
3552       peer ni:
3553         - nid: ${nid1}
3554           state: NA
3555         - nid: ${nid2}
3556           state: NA
3557 EOF
3558         $LNETCTL peer show > $TMP/sanity-lnet-$testnum-actual.yaml
3559         compare_yaml_files ||
3560                 error "Unexpected peer configuration"
3561
3562         locked_peer_state=($(do_lnetctl peer show -v 4 --nid ${nid2} |
3563                 awk '/peer state/{print $NF}'))
3564         # Expect peer state bits to be added:
3565         #   LNET_PEER_DISCOVERED(4) | LNET_PEER_NIDS_UPTODATE(8)
3566         (( $locked_peer_state != "1048849")) &&
3567                 error "Wrong peer state \"$locked_peer_state\" expected 1048849"
3568         return 0
3569 }
3570 run_test 304 "Check locked primary peer nid consolidation"
3571
3572 check_parameter() {
3573         local para=$1
3574         local value=$2
3575
3576         echo "check parameter ${para} value ${value}"
3577
3578         return $(( $(do_lnetctl net show -v | \
3579                      tee /dev/stderr | \
3580                      grep -c "^ \+${para}: ${value}$") != 1 ))
3581 }
3582
3583 static_config() {
3584         local module=$1
3585         local setting=$2
3586
3587         cleanup_lnet || error "Failed to cleanup LNet"
3588
3589         load_module ../libcfs/libcfs/libcfs ||
3590                 error "Failed to load module libcfs rc = $?"
3591
3592         load_module ../lnet/lnet/lnet ||
3593                 error "Failed to load module lnet rc = $?"
3594
3595         echo "loading ${module} ${setting} type ${NETTYPE}"
3596         load_module "${module}" "${setting}" ||
3597                 error "Failed to load module ${module} rc = $?"
3598
3599         do_lnetctl lnet configure --all || error "lnet configure failed rc = $?"
3600
3601         return 0
3602 }
3603
3604 test_310() {
3605         local value=65
3606
3607         if [[ ${NETTYPE} == tcp* ]];then
3608                 static_config "../lnet/klnds/socklnd/ksocklnd" \
3609                               "sock_timeout=${value}"
3610         elif [[ ${NETTYPE} == o2ib* ]]; then
3611                 static_config "../lnet/klnds/o2iblnd/ko2iblnd" \
3612                               "timeout=${value}"
3613         elif [[ ${NETTYPE} == gni* ]]; then
3614                 static_config "../lnet/klnds/gnilnd/kgnilnd" \
3615                               "timeout=${value}"
3616         else
3617                 skip "NETTYPE ${NETTYPE} not supported"
3618         fi
3619
3620         check_parameter "timeout" $value
3621
3622         return $?
3623 }
3624 run_test 310 "Set timeout and verify"
3625
3626 test_311() {
3627         [[ $NETTYPE == kfi* ]] ||
3628                 skip "Need kfi network type"
3629
3630         setupall || error "setupall failed"
3631
3632         mkdir -p $DIR/$tdir || error "mkdir failed"
3633         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 oflag=direct ||
3634                 error "dd write failed"
3635
3636         local list=$(comma_list $(osts_nodes))
3637
3638 #define CFS_KFI_FAIL_WAIT_SEND_COMP1 0xF115
3639         do_nodes $list $LCTL set_param fail_loc=0x8000F115
3640         dd if=$DIR/$tdir/$tfile of=/dev/null bs=1M count=1 ||
3641                 error "dd read failed"
3642
3643         rm -f $DIR/$tdir/$tfile
3644         rmdir $DIR/$tdir
3645
3646         cleanupall || error "Failed cleanup"
3647 }
3648 run_test 311 "Fail bulk put in send wait completion"
3649
3650 test_312() {
3651         [[ $NETTYPE == kfi* ]] ||
3652                 skip "Need kfi network type"
3653
3654         setupall || error "setupall failed"
3655
3656         mkdir -p $DIR/$tdir || error "mkdir failed"
3657
3658         local list=$(comma_list $(osts_nodes))
3659
3660 #define CFS_KFI_FAIL_WAIT_SEND_COMP3 0xF117
3661         do_nodes $list $LCTL set_param fail_loc=0x8000F117
3662         dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=1 oflag=direct ||
3663                 error "dd write failed"
3664
3665         local tfile2="$DIR/$tdir/testfile2"
3666
3667         do_nodes $list $LCTL set_param fail_loc=0x8000F117
3668         dd if=$DIR/$tdir/$tfile of=$tfile2 bs=1M count=1 oflag=direct ||
3669                 error "dd read failed"
3670
3671         rm -f $DIR/$tdir/$tfile
3672         rm -f $tfile2
3673         rmdir $DIR/$tdir
3674
3675         cleanupall || error "Failed cleanup"
3676 }
3677 run_test 312 "TAG_RX_OK is possible after TX_FAIL"
3678
3679 check_udsp_prio() {
3680         local target_net="${1}"
3681         local target_nid="${2}"
3682         local expect_net="${3}"
3683         local expect_nid="${4}"
3684         local type="${5}"
3685
3686         declare -a nids
3687         declare -a net_prios
3688         declare -a nid_prios
3689
3690         nids=( $($LNETCTL ${type} show -v 5 | awk '/- nid:/{print $NF}' |
3691                  xargs echo) )
3692
3693         net_prios=( $($LNETCTL ${type} show -v 5 |
3694                       awk '/net priority:/{print $NF}' | xargs echo) )
3695
3696         nid_prios=( $($LNETCTL ${type} show -v 5 |
3697                       awk '/nid priority:/{print $NF}' | xargs echo) )
3698
3699         (( ${#nids[@]} != ${#net_prios[@]} )) &&
3700                 error "Wrong # net prios ${#nids[@]} != ${#net_prios[@]}"
3701
3702         (( ${#nids[@]} != ${#nid_prios[@]} )) &&
3703                 error "Wrong # nid prios ${#nids[@]} != ${#nid_prios[@]}"
3704
3705         local i
3706
3707         for ((i = 0; i < ${#nids[@]}; i++)); do
3708                 [[ -n ${target_net} ]] &&
3709                         [[ ${nids[i]##*@} != "${target_net}" ]] &&
3710                         continue
3711                 [[ -n ${target_nid} ]] &&
3712                         [[ ${nids[i]} != "${target_nid}" ]] &&
3713                         continue
3714
3715                 echo "${nids[i]}: net_prio ${net_prios[i]} expect ${expect_net}"
3716                 (( net_prios[i] != expect_net )) &&
3717                         error "Wrong net priority \"${net_prios[i]}\" expect ${expect_net}"
3718
3719                 echo "${nids[i]}: nid_prio ${nid_prios[i]} expect ${expect_nid}"
3720                 (( nid_prios[i] != expect_nid )) &&
3721                         error "Wrong nid priority \"${nid_prios[i]}\" expect ${expect_nid}"
3722         done
3723
3724         return 0
3725 }
3726
3727 check_peer_udsp_prio() {
3728         check_udsp_prio "${1}" "${2}" "${3}" "${4}" "peer"
3729 }
3730
3731 check_net_udsp_prio() {
3732         check_udsp_prio "${1}" "${2}" "${3}" "${4}" "net"
3733 }
3734
3735 test_400() {
3736         reinit_dlc || return $?
3737
3738         do_lnetctl udsp add --src tcp --priority 0 ||
3739                 error "Failed to add udsp rule"
3740         do_lnetctl udsp del --idx 0 ||
3741                 error "Failed to del udsp rule"
3742         unload_modules
3743 }
3744 run_test 400 "Check for udsp add/delete net rule without net num"
3745
3746 test_401() {
3747         reinit_dlc || return $?
3748
3749         do_lnetctl net add --net ${NETTYPE} --if ${INTERFACES[0]} ||
3750                 error "Failed to add net"
3751
3752         do_lnetctl udsp add --dst ${NETTYPE} --prio 1 ||
3753                 error "Failed to add peer net priority rule"
3754
3755         do_lnetctl discover $($LCTL list_nids | head -n 1) ||
3756                 error "Failed to discover peer"
3757
3758         check_peer_udsp_prio "${NETTYPE}" "" "1" "-1"
3759
3760         return 0
3761 }
3762 run_test 401 "Discover peer after adding peer net UDSP rule"
3763
3764 test_402() {
3765         reinit_dlc || return $?
3766
3767         do_lnetctl udsp add --dst kfi --priority 0 ||
3768                 error "Failed to add UDSP rule"
3769
3770         do_lnetctl peer add --prim 402@kfi ||
3771                 error "Failed to add peer"
3772
3773         return 0
3774 }
3775 run_test 402 "Destination net rule should not panic"
3776
3777 complete_test $SECONDS
3778 cleanup_testsuite
3779 exit_status