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