3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 # bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_LNET_EXCEPT "
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
17 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
19 . $LUSTRE/tests/test-framework.sh
23 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
28 [[ -z $LNETCTL ]] && skip "Need lnetctl"
32 if is_mounted $MOUNT || is_mounted $MOUNT2; then
33 cleanupall || error "Failed cleanup prior to test execution"
38 echo "Cleaning up LNet"
39 lsmod | grep -q lnet &&
40 $LNETCTL lnet unconfigure 2>/dev/null
45 if module_loaded lnet ; then
46 cleanup_lnet || error "Failed to unload modules before test execution"
52 # Cleanup any tmp files created by the sub tests
53 rm -f $TMP/sanity-lnet-*.yaml $LNET_PARAMS_FILE
56 if $restore_mounts; then
57 setupall || error "Failed to setup Lustre after test execution"
58 elif $restore_modules; then
60 error "Couldn't load modules after test execution"
69 echo "ip netns exec $TESTNS $*"
70 ip netns exec $TESTNS "$@"
78 netns_arg="netns $netns"
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
86 ip addr add "${FAKE_IP}/31" dev $FAKE_IF
87 ip link set $FAKE_IF up
92 ip link show test1pl >& /dev/null && ip link del test1pl || return 0
103 (ip netns list | grep -q $TESTNS) && ip netns del $TESTNS
108 echo "Loading LNet and configuring DLC"
110 do_lnetctl lnet configure
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 $?"
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 $?"
126 configure_dlc || error "configure_dlc failed $?"
131 append_global_yaml() {
132 [[ ! -e ${GLOBAL_YAML_FILE} ]] &&
133 error "Missing global yaml at ${GLOBAL_YAML_FILE}"
135 cat ${GLOBAL_YAML_FILE} >> $TMP/sanity-lnet-$testnum-expected.yaml
138 create_base_yaml_file() {
142 compare_yaml_files() {
143 local expected="$TMP/sanity-lnet-$testnum-expected.yaml"
144 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
146 ! [[ -e $expected ]] && echo "$expected not found" && return 1
147 ! [[ -e $actual ]] && echo "$actual not found" && return 1
148 diff -upN ${actual} ${expected} || rc=$?
158 local net="${nid//*@/}"
159 local addr="${nid//@*/}"
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}"
164 if [[ $net =~ gni[0-9]* ]] || [[ $net =~ kfi[0-9]* ]]; then
165 [[ $addr =~ ${num_re} ]] && return 0
167 [[ $addr =~ ${ip_re} ]] && return 0
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)
178 for nid in $primary_nids $secondary_nids; do
179 validate_nid "$nid" || error "Bad NID \"${nid}\""
184 validate_peer_nids() {
186 local nids_per_peer="$2"
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))))"
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
196 error "Expected $expect_p but found $actual_p primary nids"
197 elif [[ $expect_s -ne $actual_s ]]; then
199 error "Expected $expect_s but found $actual_s secondary nids"
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
209 error "Expected $expect_gw gateways but found $actual_gw gateways"
215 setup_netns || error "setup_netns failed with $?"
217 # Determine the local interface(s) used for LNet
218 load_lnet "config_on_load=1" || error "Failed to load modules"
223 INTERFACES=( $(lnet_if_list) )
225 cleanup_lnet || error "Failed to cleanup LNet"
227 stack_trap 'cleanup_testsuite' EXIT
230 load_module ../lnet/lnet/lnet || error "Failed to load module rc = $?"
231 do_lnetctl lnet configure || error "lnet configure failed rc = $?"
233 reinit_dlc || return $?
234 do_lnetctl import < ${GLOBAL_YAML_FILE} || error "Import failed $?"
235 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
236 create_base_yaml_file
237 compare_yaml_files || error "Configuration changed after import"
239 run_test 0 "Export empty config, import the config, compare"
242 local prim_nid="${1:+--prim_nid $1}"
243 local nid="${2:+--nid $2}"
245 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
247 do_lnetctl peer add ${prim_nid} ${nid} || error "peer add failed $?"
248 $LNETCTL export --backup > $actual || error "export failed $?"
254 reinit_dlc || return $?
255 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
257 - primary nid: 1.1.1.1@tcp
263 compare_peer_add "1.1.1.1@tcp"
265 run_test 1 "Add peer with single nid (tcp)"
268 reinit_dlc || return $?
269 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
271 - primary nid: 2.2.2.2@o2ib
277 compare_peer_add "2.2.2.2@o2ib"
279 run_test 2 "Add peer with single nid (o2ib)"
282 reinit_dlc || return $?
283 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
285 - primary nid: 3.3.3.3@tcp
292 compare_peer_add "3.3.3.3@tcp" "3.3.3.3@o2ib"
294 run_test 3 "Add peer with tcp primary o2ib secondary"
297 reinit_dlc || return $?
298 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
300 - primary nid: 4.4.4.4@tcp
309 echo "Add peer with nidrange (tcp)"
310 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-3]@tcp"
312 echo "Add peer with nidrange that overlaps primary nid (tcp)"
313 compare_peer_add "4.4.4.4@tcp" "4.4.4.[1-4]@tcp"
315 run_test 4 "Add peer with nidrange (tcp)"
318 reinit_dlc || return $?
319 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
321 - primary nid: 5.5.5.5@o2ib
331 echo "Add peer with nidrange (o2ib)"
332 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
334 echo "Add peer with nidranage that overlaps primary nid (o2ib)"
335 compare_peer_add "5.5.5.5@o2ib" "5.5.5.[1-4]@o2ib"
337 run_test 5 "Add peer with nidrange (o2ib)"
340 reinit_dlc || return $?
341 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
343 - primary nid: 6.6.6.6@tcp
366 local nid_expr="6.6.[6-7].[0-4/2]@tcp"
367 nid_expr+=",6.6.[1-4/2].[0-6/3]@o2ib"
368 nid_expr+=",[6-12/4]@gni"
369 nid_expr+=",[6-12/4]@kfi"
371 compare_peer_add "6.6.6.6@tcp" "${nid_expr}"
373 run_test 6 "Add peer with multiple nidranges"
376 local prim_nid="${1:+--prim_nid $1}"
377 local nid="${2:+--nid $2}"
379 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
381 do_lnetctl peer del ${prim_nid} ${nid} || error "peer del failed $?"
382 $LNETCTL export --backup > $actual || error "export failed $?"
388 reinit_dlc || return $?
389 create_base_yaml_file
391 echo "Delete peer with single nid (tcp)"
392 do_lnetctl peer add --prim_nid 7.7.7.7@tcp || error "Peer add failed $?"
393 compare_peer_del "7.7.7.7@tcp"
395 echo "Delete peer with single nid (o2ib)"
396 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib || error "Peer add failed $?"
397 compare_peer_del "7.7.7.7@o2ib"
399 echo "Delete peer that has multiple nids (tcp)"
400 do_lnetctl peer add --prim_nid 7.7.7.7@tcp --nid 7.7.7.[8-12]@tcp ||
401 error "Peer add failed $?"
402 compare_peer_del "7.7.7.7@tcp"
404 echo "Delete peer that has multiple nids (o2ib)"
405 do_lnetctl peer add --prim_nid 7.7.7.7@o2ib --nid 7.7.7.[8-12]@o2ib ||
406 error "Peer add failed $?"
407 compare_peer_del "7.7.7.7@o2ib"
409 echo "Delete peer that has both tcp and o2ib nids"
410 do_lnetctl peer add --prim_nid 7.7.7.7@tcp \
411 --nid 7.7.7.[9-12]@tcp,7.7.7.[13-15]@o2ib ||
412 error "Peer add failed $?"
413 compare_peer_del "7.7.7.7@tcp"
415 echo "Delete peer with single nid (gni)"
416 do_lnetctl peer add --prim_nid 7@gni || error "Peer add failed $?"
417 compare_peer_del "7@gni"
419 echo "Delete peer that has multiple nids (gni)"
420 do_lnetctl peer add --prim_nid 7@gni --nid [8-12]@gni ||
421 error "Peer add failed $?"
422 compare_peer_del "7@gni"
424 echo "Delete peer with single nid (kfi)"
425 do_lnetctl peer add --prim_nid 7@kfi || error "Peer add failed $?"
426 compare_peer_del "7@kfi"
428 echo "Delete peer that has multiple nids (kfi)"
429 do_lnetctl peer add --prim_nid 7@kfi --nid [8-12]@kfi ||
430 error "Peer add failed $?"
431 compare_peer_del "7@kfi"
433 echo "Delete peer that has tcp, o2ib, gni and kfi nids"
434 do_lnetctl peer add --prim_nid 7@gni \
435 --nid [8-12]@gni,7.7.7.[1-4]@tcp,7.7.7.[5-9]@o2ib,[1-5]@kfi ||
436 error "Peer add failed $?"
437 compare_peer_del "7@gni"
439 run_test 7 "Various peer delete tests"
442 reinit_dlc || return $?
444 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
446 - primary nid: 8.8.8.8@tcp
458 do_lnetctl peer add --prim_nid 8.8.8.8@tcp --nid 8.8.8.[10-15]@tcp ||
459 error "Peer add failed $?"
460 compare_peer_del "8.8.8.8@tcp" "8.8.8.13@tcp"
462 run_test 8 "Delete single secondary nid from peer (tcp)"
465 reinit_dlc || return $?
467 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
469 - primary nid: 9.9.9.9@tcp
476 do_lnetctl peer add --prim_nid 9.9.9.9@tcp \
477 --nid 9.9.9.[11-16]@tcp || error "Peer add failed $?"
478 compare_peer_del "9.9.9.9@tcp" "9.9.9.[11-16]@tcp"
480 run_test 9 "Delete all secondary nids from peer (tcp)"
483 reinit_dlc || return $?
485 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
487 - primary nid: 10.10.10.10@tcp
490 - nid: 10.10.10.10@tcp
491 - nid: 10.10.10.12@tcp
492 - nid: 10.10.10.13@tcp
493 - nid: 10.10.10.15@tcp
494 - nid: 10.10.10.16@tcp
497 do_lnetctl peer add --prim_nid 10.10.10.10@tcp \
498 --nid 10.10.10.[12-16]@tcp || error "Peer add failed $?"
499 compare_peer_del "10.10.10.10@tcp" "10.10.10.14@tcp"
501 run_test 10 "Delete single secondary nid from peer (o2ib)"
504 reinit_dlc || return $?
506 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
508 - primary nid: 11.11.11.11@tcp
511 - nid: 11.11.11.11@tcp
514 do_lnetctl peer add --prim_nid 11.11.11.11@tcp \
515 --nid 11.11.11.[13-17]@tcp || error "Peer add failed $?"
516 compare_peer_del "11.11.11.11@tcp" "11.11.11.[13-17]@tcp"
518 run_test 11 "Delete all secondary nids from peer (o2ib)"
521 reinit_dlc || return $?
523 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
525 - primary nid: 12.12.12.12@o2ib
528 - nid: 12.12.12.12@o2ib
529 - nid: 13.13.13.13@o2ib
530 - nid: 14.13.13.13@o2ib
531 - nid: 14.15.13.13@o2ib
533 - nid: 15.17.1.10@tcp
534 - nid: 15.17.1.20@tcp
537 do_lnetctl peer add --prim_nid 12.12.12.12@o2ib \
538 --nid [13-14/1].[13-15/2].13.13@o2ib,[15-16/3].[17-19/4].[1].[5-20/5]@tcp ||
539 error "Peer add failed $?"
540 compare_peer_del "12.12.12.12@o2ib" "13.15.13.13@o2ib,15.17.1.15@tcp"
542 run_test 12 "Delete a secondary nid from peer (tcp and o2ib)"
545 reinit_dlc || return $?
547 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
549 - primary nid: 13.13.13.13@o2ib
552 - nid: 13.13.13.13@o2ib
555 do_lnetctl peer add --prim_nid 13.13.13.13@o2ib \
556 --nid [14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib ||
557 error "Peer add failed $?"
558 compare_peer_del "13.13.13.13@o2ib" \
559 "[14-15].[1-2/1].[1].[100-254/10]@tcp,14.14.[254].14@o2ib"
561 run_test 13 "Delete all secondary nids from peer (tcp and o2ib)"
567 if [[ $net =~ gni* ]] || [[ $net =~ kfi* ]]; then
570 echo "${num}.${num}.${num}.${num}@${net}"
574 create_mr_peer_yaml() {
576 local secondary_nids="$2"
579 echo "Generating peer yaml for $num_peers peers with $secondary_nids secondary nids"
580 echo "peer:" >> $TMP/sanity-lnet-$testnum-expected.yaml
582 local total_nids=$((num_peers + $((num_peers * secondary_nids))))
585 while [[ $created -lt $num_peers ]]; do
586 local primary=$(create_nid ${nidnum} ${net})
587 cat <<EOF >> $TMP/sanity-lnet-$testnum-expected.yaml
588 - primary nid: $primary
594 local start=$((nidnum + 1))
595 local end=$((nidnum + $secondary_nids))
596 for j in $(seq ${start} ${end}); do
597 local nid=$(create_nid $j ${net})
598 echo " - nid: $nid" >> $TMP/sanity-lnet-$testnum-expected.yaml
606 reinit_dlc || return $?
608 echo "Create single peer, single nid, using import"
609 create_mr_peer_yaml 1 0 tcp
610 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
611 error "Import failed $?"
613 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
616 echo "Delete single peer using import --del"
617 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
618 error "Import failed $?"
619 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
620 create_base_yaml_file
621 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
624 run_test 14 "import peer create/delete with single nid"
627 reinit_dlc || return $?
629 echo "Create multiple peers, single nid per peer, using import"
630 create_mr_peer_yaml 5 0 o2ib
631 # The ordering of nids for this use-case is non-deterministic, so we
632 # we can't just diff the expected/actual output.
633 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
634 error "Import failed $?"
635 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
636 validate_peer_nids 5 0
638 echo "Delete multiple peers, single nid per peer, using import --del"
639 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
640 error "Import failed $?"
641 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
642 create_base_yaml_file
643 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
646 run_test 15 "import multi peer create/delete with single nid per peer"
649 reinit_dlc || return $?
651 echo "Create single peer, multiple nids, using import"
652 create_mr_peer_yaml 1 5 tcp
653 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
654 error "Import failed $?"
655 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
656 validate_peer_nids 1 5
658 echo "Delete single peer, multiple nids, using import --del"
659 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
660 error "Import failed $?"
661 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
662 create_base_yaml_file
663 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
666 run_test 16 "import peer create/delete with multiple nids"
669 reinit_dlc || return $?
671 echo "Create multiple peers, multiple nids per peer, using import"
672 create_mr_peer_yaml 5 7 o2ib
673 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
674 error "Import failed $?"
675 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
676 validate_peer_nids 5 7
678 echo "Delete multiple peers, multiple nids per peer, using import --del"
679 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml ||
680 error "Import failed $?"
681 rm -f $TMP/sanity-lnet-$testnum-expected.yaml
682 create_base_yaml_file
683 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
686 run_test 17 "import multi peer create/delete with multiple nids"
689 reinit_dlc || return $?
691 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
693 - primary nid: 1.1.1.1@tcp
702 echo "Import peer with 5 nids"
703 cat $TMP/sanity-lnet-$testnum-expected.yaml
704 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
705 error "Import failed $?"
706 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
708 - primary nid: 1.1.1.1@tcp
715 echo "Delete three of the nids"
716 cat $TMP/sanity-lnet-$testnum-expected.yaml
717 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
718 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
720 - primary nid: 1.1.1.1@tcp
726 echo "Check peer has expected nids remaining"
727 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
731 run_test 18a "Delete a subset of nids from a single peer using import --del"
734 reinit_dlc || return $?
736 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
738 - primary nid: 1.1.1.1@tcp
746 - primary nid: 6.6.6.6@o2ib
755 echo "Import two peers with 5 nids each"
756 cat $TMP/sanity-lnet-$testnum-expected.yaml
757 do_lnetctl import < $TMP/sanity-lnet-$testnum-expected.yaml ||
758 error "Import failed $?"
759 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
761 - primary nid: 1.1.1.1@tcp
767 - primary nid: 6.6.6.6@o2ib
774 echo "Delete three of the nids from each peer"
775 cat $TMP/sanity-lnet-$testnum-expected.yaml
776 do_lnetctl import --del < $TMP/sanity-lnet-$testnum-expected.yaml
777 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
779 - primary nid: 6.6.6.6@o2ib
784 - primary nid: 1.1.1.1@tcp
791 echo "Check peers have expected nids remaining"
792 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
794 validate_peer_nids 2 1
796 run_test 18b "Delete multiple nids from multiple peers using import --del"
799 reinit_dlc || return $?
800 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
802 - primary nid: 19@gni
808 compare_peer_add "19@gni"
810 run_test 19 "Add peer with single nid (gni)"
813 reinit_dlc || return $?
814 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
816 - primary nid: 20@gni
820 - nid: 20.20.20.20@tcp
821 - nid: 20.20.20.20@o2ib
824 compare_peer_add "20@gni" "20.20.20.20@tcp,20.20.20.20@o2ib"
826 run_test 20 "Add peer with gni primary and tcp, o2ib secondary"
829 reinit_dlc || return $?
830 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
832 - primary nid: 21@gni
842 echo "Add peer with nidrange (gni)"
843 compare_peer_add "21@gni" "[22-25]@gni" || error
844 echo "Add peer with nidrange that overlaps primary nid (gni)"
845 compare_peer_add "21@gni" "[21-25]@gni"
847 run_test 21 "Add peer with nidrange (gni)"
850 reinit_dlc || return $?
851 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
853 - primary nid: 22@gni
864 do_lnetctl peer add --prim_nid 22@gni --nid [24-29]@gni ||
865 error "Peer add failed $?"
866 compare_peer_del "22@gni" "26@gni"
868 run_test 22 "Delete single secondary nid from peer (gni)"
871 reinit_dlc || return $?
872 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
874 - primary nid: 23@gni
881 do_lnetctl peer add --prim_nid 23@gni --nid [25-29]@gni ||
882 error "Peer add failed $?"
883 compare_peer_del "23@gni" "[25-29]@gni"
885 run_test 23 "Delete all secondary nids from peer (gni)"
888 reinit_dlc || return $?
889 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
891 - primary nid: 24@gni
896 - nid: 13.13.13.13@o2ib
897 - nid: 14.13.13.13@o2ib
898 - nid: 14.15.13.13@o2ib
900 - nid: 15.17.1.10@tcp
901 - nid: 15.17.1.20@tcp
904 do_lnetctl peer add --prim_nid 24@gni \
905 --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 ||
906 error "Peer add failed $?"
907 compare_peer_del "24@gni" "5@gni,13.15.13.13@o2ib,15.17.1.15@tcp"
909 run_test 24 "Delete a secondary nid from peer (tcp, o2ib and gni)"
912 reinit_dlc || return $?
913 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
915 - primary nid: 25@gni
921 do_lnetctl peer add --prim_nid 25@gni \
922 --nid [26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni ||
923 error "Peer add failed $?"
924 compare_peer_del "25@gni" \
925 "[26-27].[4-10/3].26.26@tcp,26.26.26.26@o2ib,[30-35]@gni"
927 run_test 25 "Delete all secondary nids from peer (tcp, gni and o2ib)"
930 reinit_dlc || return $?
932 echo "Invalid prim_nid - peer add"
933 do_lnetctl peer add --prim_nid foobar &&
934 error "Command should have failed"
936 echo "Invalid prim_nid - peer del"
937 do_lnetctl peer del --prim_nid foobar &&
938 error "Command should have failed"
940 echo "Delete non-existing peer"
941 do_lnetctl peer del --prim_nid 1.1.1.1@o2ib &&
942 error "Command should have failed"
944 echo "Don't provide mandatory argument for peer del"
945 do_lnetctl peer del --nid 1.1.1.1@tcp &&
946 error "Command should have failed"
948 echo "Don't provide mandatory argument for peer add"
949 do_lnetctl peer add --nid 1.1.1.1@tcp &&
950 error "Command should have failed"
952 echo "Don't provide mandatory arguments peer add"
953 do_lnetctl peer add &&
954 error "Command should have failed"
956 echo "Invalid secondary nids"
957 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid foobar &&
958 error "Command should have failed"
960 echo "Exceed max nids per peer"
961 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid 1.1.1.[2-255]@tcp &&
962 error "Command should have failed"
964 echo "Invalid net type"
965 do_lnetctl peer add --prim_nid 1@foo &&
966 error "Command should have failed"
968 echo "Invalid nid format"
969 local invalid_nids="1@tcp 1@o2ib 1.1.1.1@gni"
972 for nid in ${invalid_nids}; do
973 echo "Check invalid primary nid - '$nid'"
974 do_lnetctl peer add --prim_nid $nid &&
975 error "Command should have failed"
978 local invalid_strs="[2-1]@gni [a-f/x]@gni 256.256.256.256@tcp"
979 invalid_strs+=" 1.1.1.1.[2-5/f]@tcp 1.]2[.3.4@o2ib"
980 invalid_strs+="1.[2-4,[5-6],7-8].1.1@tcp foobar"
983 for nidstr in ${invalid_strs}; do
984 echo "Check invalid nidstring - '$nidstr'"
985 do_lnetctl peer add --prim_nid 1.1.1.1@tcp --nid $nidstr &&
986 error "Command should have failed"
989 echo "Add non-local gateway"
990 do_lnetctl route add --net tcp --gateway 1@gni &&
991 error "Command should have failed"
995 run_test 99a "Check various invalid inputs to lnetctl peer"
998 reinit_dlc || return $?
1000 create_base_yaml_file
1002 cat <<EOF > $TMP/sanity-lnet-$testnum-invalid.yaml
1004 - primary nid: 99.99.99.99@tcp
1007 - nid: 99.99.99.99@tcp
1009 do_lnetctl import < $TMP/sanity-lnet-$testnum-invalid.yaml &&
1010 error "import should have failed"
1011 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
1014 run_test 99b "Invalid value for Multi-Rail in yaml import"
1018 local ip=$(ip addr show dev $if | awk '/ inet /{print $2}')
1026 if ! lsmod | grep -q ksocklnd ; then
1027 load_module ../lnet/klnds/socklnd/ksocklnd ||
1028 error "Can't load ksocklnd.ko"
1031 do_lnetctl net add --net ${net} --if ${if} ||
1032 error "Failed to add net ${net} on if ${if}"
1035 compare_route_add() {
1039 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1041 do_lnetctl route add --net ${rnet} --gateway ${gw} ||
1042 error "route add failed $?"
1043 # CPT configuration is pruned from the exported yaml, since the default
1044 # can vary across test systems (unlike default values for things like
1045 # peer_credits, peer_timeout, etc.)
1046 $LNETCTL export --backup | grep -v CPT > $actual ||
1047 error "export failed $?"
1048 validate_gateway_nids
1053 reinit_dlc || return $?
1054 add_net "tcp" "${INTERFACES[0]}"
1055 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1064 peer_buffer_credits: 0
1070 gateway: 7.7.7.7@tcp
1073 health_sensitivity: 1
1075 - primary nid: 7.7.7.7@tcp
1081 compare_route_add "tcp7" "7.7.7.7@tcp" || return $?
1084 run_test 100 "Add route with single gw (tcp)"
1087 reinit_dlc || return $?
1088 add_net "tcp" "${INTERFACES[0]}"
1089 cat <<EOF > $TMP/sanity-lnet-$testnum-expected.yaml
1098 peer_buffer_credits: 0
1104 gateway: 8.8.8.10@tcp
1107 health_sensitivity: 1
1109 gateway: 8.8.8.9@tcp
1112 health_sensitivity: 1
1114 gateway: 8.8.8.8@tcp
1117 health_sensitivity: 1
1119 - primary nid: 8.8.8.9@tcp
1123 - primary nid: 8.8.8.10@tcp
1127 - primary nid: 8.8.8.8@tcp
1133 compare_route_add "tcp8" "8.8.8.[8-10]@tcp"
1135 run_test 101 "Add route with multiple gw (tcp)"
1137 compare_route_del() {
1141 local actual="$TMP/sanity-lnet-$testnum-actual.yaml"
1143 do_lnetctl route del --net ${rnet} --gateway ${gw} ||
1144 error "route del failed $?"
1145 $LNETCTL export --backup > $actual ||
1146 error "export failed $?"
1147 validate_gateway_nids
1151 reinit_dlc || return $?
1152 add_net "tcp" "${INTERFACES[0]}"
1153 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1154 do_lnetctl route add --net tcp102 --gateway 102.102.102.102@tcp ||
1155 error "route add failed $?"
1156 compare_route_del "tcp102" "102.102.102.102@tcp"
1158 run_test 102 "Delete route with single gw (tcp)"
1161 reinit_dlc || return $?
1162 add_net "tcp" "${INTERFACES[0]}"
1163 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
1164 do_lnetctl route add --net tcp103 \
1165 --gateway 103.103.103.[103-120/4]@tcp ||
1166 error "route add failed $?"
1167 compare_route_del "tcp103" "103.103.103.[103-120/4]@tcp"
1169 run_test 103 "Delete route with multiple gw (tcp)"
1172 local tyaml="$TMP/sanity-lnet-$testnum-expected.yaml"
1174 reinit_dlc || return $?
1176 # Default value is '3'
1177 local val=$($LNETCTL global show | awk '/response_tracking/{print $NF}')
1179 error "Expect 3 found $val"
1181 echo "Set < 0; Should fail"
1182 do_lnetctl set response_tracking -1 &&
1183 error "should have failed $?"
1185 reinit_dlc || return $?
1188 response_tracking: -10
1190 do_lnetctl import < $tyaml &&
1191 error "should have failed $?"
1193 echo "Check valid values; Should succeed"
1195 for ((i = 0; i < 4; i++)); do
1196 reinit_dlc || return $?
1197 do_lnetctl set response_tracking $i ||
1198 error "should have succeeded $?"
1199 $LNETCTL global show | grep -q "response_tracking: $i" ||
1200 error "Failed to set response_tracking to $i"
1201 reinit_dlc || return $?
1204 response_tracking: $i
1206 do_lnetctl import < $tyaml ||
1207 error "should have succeeded $?"
1208 $LNETCTL global show | grep -q "response_tracking: $i" ||
1209 error "Failed to set response_tracking to $i"
1212 reinit_dlc || return $?
1213 echo "Set > 3; Should fail"
1214 do_lnetctl set response_tracking 4 &&
1215 error "should have failed $?"
1217 reinit_dlc || return $?
1220 response_tracking: 10
1222 do_lnetctl import < $tyaml &&
1223 error "should have failed $?"
1226 run_test 104 "Set/check response_tracking param"
1229 reinit_dlc || return $?
1230 add_net "tcp" "${INTERFACES[0]}"
1231 do_lnetctl route add --net tcp105 --gateway 105.105.105.105@tcp ||
1232 error "route add failed $?"
1233 do_lnetctl peer add --prim 105.105.105.105@tcp &&
1234 error "peer add should fail"
1238 run_test 105 "Adding duplicate GW peer should fail"
1241 reinit_dlc || return $?
1242 add_net "tcp" "${INTERFACES[0]}"
1243 do_lnetctl route add --net tcp106 --gateway 106.106.106.106@tcp ||
1244 error "route add failed $?"
1245 do_lnetctl peer del --prim 106.106.106.106@tcp &&
1246 error "peer del should fail"
1250 run_test 106 "Deleting GW peer should fail"
1253 cleanup_lnet || exit 1
1254 load_lnet "networks=\"\""
1255 do_ns $LNETCTL lnet configure --all || exit 1
1256 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1258 run_test 200 "load lnet w/o module option, configure in a non-default namespace"
1261 cleanup_lnet || exit 1
1262 load_lnet "networks=tcp($FAKE_IF)"
1263 do_ns $LNETCTL lnet configure --all || exit 1
1264 $LNETCTL net show --net tcp | grep -q "nid: ${FAKE_IP}@tcp$"
1266 run_test 201 "load lnet using networks module options in a non-default namespace"
1269 cleanup_lnet || exit 1
1270 load_lnet "networks=\"\" ip2nets=\"tcp0($FAKE_IF) ${FAKE_IP}\""
1271 do_ns $LNETCTL lnet configure --all || exit 1
1272 $LNETCTL net show | grep -q "nid: ${FAKE_IP}@tcp$"
1274 run_test 202 "load lnet using ip2nets in a non-default namespace"
1277 ### Add the interfaces in the target namespace
1280 cleanup_lnet || exit 1
1282 do_lnetctl lnet configure || exit 1
1283 do_ns $LNETCTL net add --net tcp0 --if $FAKE_IF
1285 run_test 203 "add a network using an interface in the non-default namespace"
1287 LNET_PARAMS_FILE="$TMP/$TESTSUITE.parameters"
1288 function save_lnet_params() {
1289 $LNETCTL global show | egrep -v '^global:$' |
1290 sed 's/://' > $LNET_PARAMS_FILE
1293 function restore_lnet_params() {
1295 while read param value; do
1296 [[ $param == max_intf ]] && continue
1297 [[ $param == lnd_timeout ]] && continue
1298 $LNETCTL set ${param} ${value} ||
1299 error "Failed to restore ${param} to ${value}"
1300 done < $LNET_PARAMS_FILE
1303 function lnet_health_pre() {
1306 # Lower transaction timeout to speed up test execution
1307 $LNETCTL set transaction_timeout 10 ||
1308 error "Failed to set transaction_timeout $?"
1310 RETRY_PARAM=$($LNETCTL global show | awk '/retry_count/{print $NF}')
1311 RSND_PRE=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1312 LO_HVAL_PRE=$($LNETCTL net show -v 2 | awk '/health value/{print $NF}' |
1313 xargs echo | sed 's/ /+/g' | bc -l)
1315 RMT_HVAL_PRE=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1316 awk '/health value/{print $NF}' | xargs echo |
1317 sed 's/ /+/g' | bc -l)
1319 # Might not have any peers so initialize to zero.
1320 RMT_HVAL_PRE=${RMT_HVAL_PRE:-0}
1325 function lnet_health_post() {
1326 RSND_POST=$($LNETCTL stats show | awk '/resend_count/{print $NF}')
1327 LO_HVAL_POST=$($LNETCTL net show -v 2 |
1328 awk '/health value/{print $NF}' |
1329 xargs echo | sed 's/ /+/g' | bc -l)
1331 RMT_HVAL_POST=$($LNETCTL peer show --nid ${RNIDS[0]} -v 2 2>/dev/null |
1332 awk '/health value/{print $NF}' | xargs echo |
1333 sed 's/ /+/g' | bc -l)
1335 # Might not have any peers so initialize to zero.
1336 RMT_HVAL_POST=${RMT_HVAL_POST:-0}
1339 echo "Pre resends: $RSND_PRE" &&
1340 echo "Post resends: $RSND_POST" &&
1341 echo "Resends delta: $((RSND_POST - RSND_PRE))" &&
1342 echo "Pre local health: $LO_HVAL_PRE" &&
1343 echo "Post local health: $LO_HVAL_POST" &&
1344 echo "Pre remote health: $RMT_HVAL_PRE" &&
1345 echo "Post remote health: $RMT_HVAL_POST"
1349 do_lnetctl peer set --health 1000 --all
1350 do_lnetctl net set --health 1000 --all
1355 function check_no_resends() {
1356 echo "Check that no resends took place"
1357 [[ $RSND_POST -ne $RSND_PRE ]] &&
1358 error "Found resends: $RSND_POST != $RSND_PRE"
1363 function check_resends() {
1364 local delta=$((RSND_POST - RSND_PRE))
1366 echo "Check that $RETRY_PARAM resends took place"
1367 [[ $delta -ne $RETRY_PARAM ]] &&
1368 error "Expected $RETRY_PARAM resends found $delta"
1373 function check_no_local_health() {
1374 echo "Check that local NI health is unchanged"
1375 [[ $LO_HVAL_POST -ne $LO_HVAL_PRE ]] &&
1376 error "Local health changed: $LO_HVAL_POST != $LO_HVAL_PRE"
1381 function check_local_health() {
1382 echo "Check that local NI health has been changed"
1383 [[ $LO_HVAL_POST -eq $LO_HVAL_PRE ]] &&
1384 error "Local health unchanged: $LO_HVAL_POST == $LO_HVAL_PRE"
1389 function check_no_remote_health() {
1390 echo "Check that remote NI health is unchanged"
1391 [[ $RMT_HVAL_POST -ne $RMT_HVAL_PRE ]] &&
1392 error "Remote health changed: $RMT_HVAL_POST != $RMT_HVAL_PRE"
1397 function check_remote_health() {
1398 echo "Check that remote NI health has been changed"
1399 [[ $RMT_HVAL_POST -eq $RMT_HVAL_PRE ]] &&
1400 error "Remote health unchanged: $RMT_HVAL_POST == $RMT_HVAL_PRE"
1410 setup_health_test() {
1414 local rnodes=$(remote_nodes_list)
1415 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
1417 cleanup_lnet || error "Failed to cleanup before test execution"
1419 # Loading modules should configure LNet with the appropriate
1420 # test-framework configuration
1421 load_lnet "config_on_load=1" || error "Failed to load modules"
1423 LNIDS=( $($LCTL list_nids | xargs echo) )
1425 RNODE=$(awk '{print $1}' <<<$rnodes)
1426 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1428 if [[ -z ${RNIDS[@]} ]]; then
1429 do_rpc_nodes $RNODE load_lnet "config_on_load=1"
1431 RNIDS=( $(do_node $RNODE $LCTL list_nids | xargs echo) )
1434 [[ ${#LNIDS[@]} -lt 1 ]] &&
1435 error "No NIDs configured for local host $HOSTNAME"
1436 [[ ${#RNIDS[@]} -lt 1 ]] &&
1437 error "No NIDs configured for remote host $RNODE"
1439 do_lnetctl discover ${RNIDS[0]} ||
1440 error "Unable to discover ${RNIDS[0]}"
1442 local mr=$($LNETCTL peer show --nid ${RNIDS[0]} |
1443 awk '/Multi-Rail/{print $NF}')
1445 if ${need_mr} && [[ $mr == False ]]; then
1446 cleanup_health_test || return $?
1450 if ( ! ${need_mr} && [[ ${#RNIDS[@]} -gt 1 ]] ) ||
1451 ( ! ${need_mr} && [[ ${#LNIDS[@]} -gt 1 ]] ); then
1452 cleanup_health_test || return $?
1456 if ${need_mr} && [[ ${#RNIDS[@]} -lt 2 ]]; then
1457 # Add a second, reachable NID to rnode.
1458 local net=${RNIDS[0]}
1462 local if=$(do_rpc_nodes --quiet $RNODE lnet_if_list)
1464 error "Failed to determine interface for $RNODE"
1466 do_rpc_nodes $RNODE "$LNETCTL lnet configure"
1467 do_rpc_nodes $RNODE "$LNETCTL net add --net $net --if $if" ||
1469 if [[ $rc -ne 0 ]]; then
1470 error "Failed to add interface to $RNODE rc=$?"
1472 RNIDS[1]="${RNIDS[0]}1"
1473 NET_DEL_ARGS="--net $net --if $if"
1477 if ${need_mr} && [[ ${#LNIDS[@]} -lt 2 ]]; then
1478 local net=${LNIDS[0]}
1481 do_lnetctl lnet configure &&
1482 do_lnetctl net add --net $net --if ${INTERFACES[0]} ||
1484 if [[ $rc -ne 0 ]]; then
1485 error "Failed to add interface rc=$?"
1487 LNIDS[1]="${LNIDS[0]}1"
1493 $LNETCTL peer show -v 2 | egrep -e nid -e health
1495 $LCTL set_param debug=+net
1501 cleanup_health_test() {
1504 if [[ -n $NET_DEL_ARGS ]]; then
1505 do_rpc_nodes $RNODE \
1506 "$LNETCTL net del $NET_DEL_ARGS" ||
1511 unload_modules || rc=$?
1514 do_rpc_nodes $RNODE unload_modules_local ||
1520 error "Failed cleanup"
1525 add_health_test_drop_rules() {
1526 local args="-m GET -r 1 -e ${1}"
1529 for src in "${LNIDS[@]}"; do
1530 for dst in "${RNIDS[@]}" "${LNIDS[@]}"; do
1531 $LCTL net_drop_add -s $src -d $dst ${args} ||
1532 error "Failed to add drop rule $src $dst $args"
1537 do_lnet_health_ping_test() {
1540 echo "Simulate $hstatus"
1542 lnet_health_pre || return $?
1544 add_health_test_drop_rules ${hstatus}
1545 do_lnetctl ping ${RNIDS[0]} &&
1546 error "Should have failed"
1550 $LCTL net_drop_del -a
1555 # See lnet/lnet/lib-msg.c:lnet_health_check()
1556 LNET_LOCAL_RESEND_STATUSES="local_interrupt local_dropped local_aborted"
1557 LNET_LOCAL_RESEND_STATUSES+=" local_no_route local_timeout"
1558 LNET_LOCAL_NO_RESEND_STATUSES="local_error"
1560 setup_health_test false || return $?
1563 for hstatus in ${LNET_LOCAL_RESEND_STATUSES} \
1564 ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1565 do_lnet_health_ping_test "${hstatus}" || return $?
1566 check_no_resends || return $?
1567 check_no_local_health || return $?
1570 cleanup_health_test || return $?
1574 run_test 204 "Check no health or resends for single-rail local failures"
1577 setup_health_test true || return $?
1580 for hstatus in ${LNET_LOCAL_RESEND_STATUSES}; do
1581 do_lnet_health_ping_test "${hstatus}" || return $?
1582 check_resends || return $?
1583 check_local_health || return $?
1586 for hstatus in ${LNET_LOCAL_NO_RESEND_STATUSES}; do
1587 do_lnet_health_ping_test "${hstatus}" || return $?
1588 check_no_resends || return $?
1589 check_local_health || return $?
1592 cleanup_health_test || return $?
1596 run_test 205 "Check health and resends for multi-rail local failures"
1598 # See lnet/lnet/lib-msg.c:lnet_health_check()
1599 LNET_REMOTE_RESEND_STATUSES="remote_dropped"
1600 LNET_REMOTE_NO_RESEND_STATUSES="remote_error remote_timeout"
1602 setup_health_test false || return $?
1605 for hstatus in ${LNET_REMOTE_RESEND_STATUSES} \
1606 ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1607 do_lnet_health_ping_test "${hstatus}" || return $?
1608 check_no_resends || return $?
1609 check_no_local_health || return $?
1610 check_no_remote_health || return $?
1613 cleanup_health_test || return $?
1617 run_test 206 "Check no health or resends for single-rail remote failures"
1620 setup_health_test true || return $?
1623 for hstatus in ${LNET_REMOTE_RESEND_STATUSES}; do
1624 do_lnet_health_ping_test "${hstatus}" || return $?
1625 check_resends || return $?
1626 check_no_local_health || return $?
1627 check_remote_health || return $?
1628 do_lnetctl peer set --health 1000 --all ||
1629 error "Unable to reset health rc=$?"
1631 for hstatus in ${LNET_REMOTE_NO_RESEND_STATUSES}; do
1632 do_lnet_health_ping_test "${hstatus}" || return $?
1633 check_no_resends || return $?
1634 check_no_local_health || return $?
1635 check_remote_health || return $?
1636 do_lnetctl peer set --health 1000 --all ||
1637 error "Unable to reset health rc=$?"
1640 cleanup_health_test || return $?
1644 run_test 207 "Check health and resends for multi-rail remote errors"
1646 test_208_load_and_check_lnet() {
1650 local num_expected=1
1652 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1655 error "Failed to load LNet with ip2nets \"${ip2nets_str}\""
1661 nids=( $($LCTL list_nids) )
1663 [[ ${#nids[@]} -ne ${num_expected} ]] &&
1664 error "Expect ${num_expected} NIDs found ${#nids[@]}"
1666 [[ ${nids[0]} == ${p_nid} ]] ||
1667 error "Expect NID \"${p_nid}\" found \"${nids[0]}\""
1669 [[ -n $s_nid ]] && [[ ${nids[1]} != ${s_nid} ]] &&
1670 error "Expect second NID \"${s_nid}\" found \"${nids[1]}\""
1672 $LCTL net down &>/dev/null
1677 cleanup_netns || error "Failed to cleanup netns before test execution"
1678 cleanup_lnet || error "Failed to unload modules before test execution"
1679 setup_fakeif || error "Failed to add fake IF"
1681 have_interface "$FAKE_IF" ||
1682 error "Expect $FAKE_IF configured but not found"
1684 local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
1685 awk '/inet /{print $4}' |
1687 if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
1688 local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
1690 echo "Configure single NID \"$ip2nets_str\""
1691 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp"
1693 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp1($FAKE_IF) $FAKE_IP"
1694 echo "Configure two NIDs; two NETs \"$ip2nets_str\""
1695 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1698 ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip; tcp($FAKE_IF) $FAKE_IP"
1699 echo "Configure two NIDs; one NET \"$ip2nets_str\""
1700 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1702 local addr1=( ${if0_ip//./ } )
1703 local addr2=( ${FAKE_IP//./ } )
1704 local range="[${addr1[0]},${addr2[0]}]"
1707 for i in $(seq 1 3); do
1708 range+=".[${addr1[$i]},${addr2[$i]}]"
1710 ip2nets_str="tcp(${INTERFACES[0]},${FAKE_IF}) ${range}"
1712 echo "Configured two NIDs; one NET alt syntax \"$ip2nets_str\""
1713 test_208_load_and_check_lnet "${ip2nets_str}" "${if0_ip}@tcp" \
1718 echo "alt syntax with missing IF \"$ip2nets_str\""
1719 load_lnet "networks=\"\" ip2nets=\"${ip2nets_str}\""
1721 echo "$LCTL net up should fail"
1723 error "LNet bring up should have failed"
1727 run_test 208 "Test various kernel ip2nets configurations"
1730 setup_health_test false || return $?
1732 echo "Simulate network_timeout w/SR config"
1735 add_health_test_drop_rules network_timeout
1737 do_lnetctl discover ${RNIDS[0]} &&
1738 error "Should have failed"
1742 check_no_resends || return $?
1743 check_no_local_health || return $?
1744 check_no_remote_health || return $?
1746 cleanup_health_test || return $?
1748 setup_health_test true || return $?
1750 echo "Simulate network_timeout w/MR config"
1754 add_health_test_drop_rules network_timeout
1756 do_lnetctl discover ${RNIDS[0]} &&
1757 error "Should have failed"
1761 check_no_resends || return $?
1762 check_local_health || return $?
1763 check_remote_health || return $?
1765 cleanup_health_test || return $?
1769 run_test 209 "Check health, but not resends, for network timeout"
1771 check_nid_in_recovq() {
1772 local recovq=$($LNETCTL debug recovery $1)
1774 local nids=$($LCTL list_nids | xargs echo)
1778 echo "Check \"$1\" recovery queue"
1780 if [[ $(grep -c 'nid-'<<<$recovq) -ne $expect ]]; then
1781 error "Expect $expect NIDs found: \"$recovq\""
1784 [[ $expect -eq 0 ]] && return 0
1786 for nid in ${nids}; do
1787 grep -q "nid-0: $nid"<<<$recovq &&
1792 error "Didn't find local NIDs in recovery queue: \"$recovq\""
1798 # First enqueue happens at time 0.
1799 # 2nd at 0 + 2^0 = 1
1800 # 3rd at 1 + 2^1 = 3
1801 # 4th at 3 + 2^2 = 7
1802 # 5th at 7 + 2^3 = 15
1803 # e.g. after 10 seconds we would expect to have seen the 4th enqueue,
1804 # (3 pings sent, 4th about to happen) and the 5th enqueue is yet to
1806 # If the recovery limit is 10 seconds, then when the 5th enqueue happens
1807 # we expect the peer NI to have aged out, so it will not actually be
1809 # If max_recovery_ping_interval is set to 4 then:
1810 # First enqueue happens at time 0.
1811 # 2nd at 0 + min(2^0, 4) = 1
1812 # 3rd at 1 + min(2^1, 4) = 3
1813 # 4th at 3 + min(2^2, 4) = 7
1814 # 5th at 7 + min(2^3, 4) = 11
1815 # 6th at 11 + min(2^4, 4) = 15
1816 # 7th at 15 + min(2^5, 4) = 19
1817 # e.g. after 4 seconds we would expect to have seen the 3rd enqueue,
1818 # (2 pings sent, 3rd about to happen), and the 4th enqueue is yet to happen
1819 # e.g. after 13 seconds we would expect to have seen the 5th enqueue,
1820 # (4 pings sent, 5th about to happen), and the 6th enqueue is yet to happen
1821 check_ping_count() {
1825 echo "Check ping counts:"
1827 if [[ $queue == "ni" ]]; then
1828 $LNETCTL net show -v 2 | egrep 'nid|health value|ping'
1829 ping_count=( $($LNETCTL net show -v 2 |
1830 awk '/ping_count/{print $NF}') )
1831 elif [[ $queue == "peer_ni" ]]; then
1832 $LNETCTL peer show -v 2 | egrep 'nid|health value|ping'
1833 ping_count=( $($LNETCTL peer show -v 2 |
1834 awk '/ping_count/{print $NF}') )
1836 error "Unrecognized queue \"$queue\""
1842 for count in "${ping_count[@]}"; do
1843 if [[ $count -eq $expect ]]; then
1844 if [[ $expect -ne 0 ]] && $found ; then
1845 error "Found more than one interface matching \"$expect\" ping count"
1848 echo "Expect ping count \"$expect\" found \"$count\""
1851 elif [[ $count -ne 0 ]]; then
1852 error "Found interface with ping count \"$count\" but expect \"$expect\""
1861 reinit_dlc || return $?
1862 add_net "tcp" "${INTERFACES[0]}" || return $?
1863 add_net "tcp1" "${INTERFACES[0]}" || return $?
1865 local prim_nid=$($LCTL list_nids | head -n 1)
1867 do_lnetctl discover $prim_nid ||
1868 error "failed to discover myself"
1870 local default=$($LNETCTL global show |
1871 awk '/recovery_limit/{print $NF}')
1872 # Set recovery limit to 10 seconds.
1873 do_lnetctl set recovery_limit 10 ||
1874 error "failed to set recovery_limit"
1876 $LCTL set_param debug=+net
1877 # Use local_error so LNet doesn't attempt to resend the discovery ping
1878 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1879 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1880 do_lnetctl discover $prim_nid &&
1881 error "Expected discovery to fail"
1883 # See comment for check_ping_count()
1885 check_nid_in_recovq "-l" "1"
1886 check_ping_count "ni" "2"
1890 check_nid_in_recovq "-l" "1"
1891 check_ping_count "ni" "3"
1893 $LCTL net_drop_del -a
1895 reinit_dlc || return $?
1896 add_net "tcp" "${INTERFACES[0]}" || return $?
1897 add_net "tcp1" "${INTERFACES[0]}" || return $?
1899 local prim_nid=$($LCTL list_nids | head -n 1)
1901 do_lnetctl discover $prim_nid ||
1902 error "failed to discover myself"
1904 do_lnetctl set recovery_limit $default ||
1905 error "failed to set recovery_limit"
1907 default=$($LNETCTL global show |
1908 awk '/max_recovery_ping_interval/{print $NF}')
1909 do_lnetctl set max_recovery_ping_interval 4 ||
1910 error "failed to set max_recovery_ping_interval"
1912 $LCTL set_param debug=+net
1913 # Use local_error so LNet doesn't attempt to resend the discovery ping
1914 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e local_error
1915 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e local_error
1916 do_lnetctl discover $prim_nid &&
1917 error "Expected discovery to fail"
1919 # See comment for check_ping_count()
1921 check_nid_in_recovq "-l" "1"
1922 check_ping_count "ni" "2"
1925 check_nid_in_recovq "-l" "1"
1926 check_ping_count "ni" "4"
1928 $LCTL net_drop_del -a
1930 do_lnetctl set max_recovery_ping_interval $default ||
1931 error "failed to set max_recovery_ping_interval"
1935 run_test 210 "Local NI recovery checks"
1938 reinit_dlc || return $?
1939 add_net "tcp" "${INTERFACES[0]}" || return $?
1940 add_net "tcp1" "${INTERFACES[0]}" || return $?
1942 local prim_nid=$($LCTL list_nids | head -n 1)
1944 do_lnetctl discover $prim_nid ||
1945 error "failed to discover myself"
1947 local default=$($LNETCTL global show |
1948 awk '/recovery_limit/{print $NF}')
1949 # Set recovery limit to 10 seconds.
1950 do_lnetctl set recovery_limit 10 ||
1951 error "failed to set recovery_limit"
1953 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
1954 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
1956 # Set health to 0 on one interface. This forces it onto the recovery
1958 $LNETCTL peer set --nid $prim_nid --health 0
1960 # After 5 seconds, we expect the peer NI to still be in recovery
1962 check_nid_in_recovq "-p" 1
1963 check_ping_count "peer_ni" "2"
1965 # After 15 seconds, the peer NI should have been fully processed out of
1966 # the recovery queue. We'll allow a total of 17 seconds to account for
1967 # differences in sleeping for whole seconds vs. the more accurate time
1968 # keeping that is done in the recovery code.
1970 check_nid_in_recovq "-p" 0
1971 check_ping_count "peer_ni" "4"
1973 $LCTL net_drop_del -a
1975 # Set health to force it back onto the recovery queue. Set to 500 means
1976 # in 5 seconds it should be back at maximum value. We'll wait a couple
1977 # more seconds than that to be safe.
1978 # NB: we reset the recovery limit to 0 (indefinite) so the peer NI is
1980 do_lnetctl set recovery_limit 0 ||
1981 error "failed to set recovery_limit"
1983 $LNETCTL peer set --nid $prim_nid --health 500
1985 check_nid_in_recovq "-p" 1
1986 check_ping_count "peer_ni" "2"
1990 check_nid_in_recovq "-p" 0
1991 check_ping_count "peer_ni" "0"
1993 reinit_dlc || return $?
1994 add_net "tcp" "${INTERFACES[0]}" || return $?
1995 add_net "tcp1" "${INTERFACES[0]}" || return $?
1997 local prim_nid=$($LCTL list_nids | head -n 1)
1999 do_lnetctl discover $prim_nid ||
2000 error "failed to discover myself"
2002 do_lnetctl set recovery_limit $default ||
2003 error "failed to set recovery_limit"
2005 default=$($LNETCTL global show |
2006 awk '/max_recovery_ping_interval/{print $NF}')
2007 do_lnetctl set max_recovery_ping_interval 4 ||
2008 error "failed to set max_recovery_ping_interval"
2010 $LCTL net_drop_add -s *@tcp -d *@tcp -m GET -r 1 -e remote_error
2011 $LCTL net_drop_add -s *@tcp1 -d *@tcp1 -m GET -r 1 -e remote_error
2013 # Set health to 0 on one interface. This forces it onto the recovery
2015 $LNETCTL peer set --nid $prim_nid --health 0
2017 # See comment for check_ping_count()
2019 check_nid_in_recovq "-p" "1"
2020 check_ping_count "peer_ni" "2"
2023 check_nid_in_recovq "-p" "1"
2024 check_ping_count "peer_ni" "4"
2026 $LCTL net_drop_del -a
2028 do_lnetctl set max_recovery_ping_interval $default ||
2029 error "failed to set max_recovery_ping_interval"
2033 run_test 211 "Remote NI recovery checks"
2036 local rnodes=$(remote_nodes_list)
2037 [[ -z $rnodes ]] && skip "Need at least 1 remote node"
2039 cleanup_lnet || error "Failed to cleanup before test execution"
2041 # Loading modules should configure LNet with the appropriate
2042 # test-framework configuration
2043 load_lnet "config_on_load=1" || error "Failed to load modules"
2045 local my_nid=$($LCTL list_nids | head -n 1)
2047 error "Failed to get primary NID for local host $HOSTNAME"
2049 local rnode=$(awk '{print $1}' <<<$rnodes)
2050 local rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2053 if [[ -z $rnodenids ]]; then
2054 do_rpc_nodes $rnode load_lnet "config_on_load=1"
2056 rnodenids=$(do_node $rnode $LCTL list_nids | xargs echo)
2059 local rnodepnid=$(awk '{print $1}' <<< $rnodenids)
2061 [[ -z $rnodepnid ]] &&
2062 error "Failed to get primary NID for remote host $rnode"
2064 log "Initial discovery"
2065 do_lnetctl discover --force $rnodepnid ||
2066 error "Failed to discover $rnodepnid"
2068 do_node $rnode "$LNETCTL discover --force $my_nid" ||
2069 error "$rnode failed to discover $my_nid"
2071 log "Fail local discover ping to set LNET_PEER_REDISCOVER flag"
2072 $LCTL net_drop_add -s "*@$NETTYPE" -d "*@$NETTYPE" -r 1 -e local_error
2073 do_lnetctl discover --force $rnodepnid &&
2074 error "Discovery should have failed"
2075 $LCTL net_drop_del -a
2078 for nid in $rnodenids; do
2079 # We need GET (PING) delay just long enough so we can trigger
2080 # discovery on the remote peer
2081 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -l 3
2082 $LCTL net_drop_add -s "*@$NETTYPE" -d $nid -r 1 -m GET -e local_error
2083 # We need PUT (PUSH) delay just long enough so we can process
2085 $LCTL net_delay_add -s "*@$NETTYPE" -d $nid -r 1 -m PUT -l 6
2088 log "Force $HOSTNAME to discover $rnodepnid (in background)"
2089 # We want to get a PING sent that we know will eventually fail.
2090 # The delay rules we added will ensure the ping is not sent until
2091 # the PUSH is also in flight (see below), and the drop rule ensures that
2092 # when the PING is eventually sent it will error out
2093 do_lnetctl discover --force $rnodepnid &
2096 # We want a discovery PUSH from rnode to put rnode back on our
2097 # discovery queue. This should cause us to try and send a PUSH to rnode
2098 # while the PING is still outstanding.
2099 log "Force $rnode to discover $my_nid"
2100 do_node $rnode $LNETCTL discover --force $my_nid
2102 # At this point we'll have both PING_SENT and PUSH_SENT set for the
2103 # rnode peer. Wait for the PING to error out which should terminate the
2104 # discovery process that we backgrounded.
2105 log "Wait for $pid1"
2107 log "Finished wait on $pid1"
2109 # The PING send failure clears the PING_SENT flag and puts the peer back
2110 # on the discovery queue. When discovery thread processes the peer it
2111 # will mistakenly clear the PUSH_SENT flag (and set PUSH_FAILED).
2112 # Discovery will then complete for this peer even though we have an
2114 # When PUSH is actually unlinked it will be forced back onto the
2115 # discovery queue, but we no longer have a ref on the peer. When
2116 # discovery completes again, we'll trip the ASSERT in
2117 # lnet_destroy_peer_locked()
2119 # Delete the delay rules to send the PUSH
2120 $LCTL net_delay_del -a
2121 # Delete the drop rules
2122 $LCTL net_drop_del -a
2125 error "Failed to unload modules"
2127 do_rpc_nodes $rnode unload_modules_local ||
2128 error "Failed to unload modules on $rnode"
2133 run_test 212 "Check discovery refcount loss bug (LU-14627)"
2136 cleanup_netns || error "Failed to cleanup netns before test execution"
2137 cleanup_lnet || error "Failed to unload modules before test execution"
2139 setup_fakeif || error "Failed to add fake IF"
2140 have_interface "$FAKE_IF" ||
2141 error "Expect $FAKE_IF configured but not found"
2143 reinit_dlc || return $?
2145 add_net "tcp" "${INTERFACES[0]}" || return $?
2146 add_net "tcp" "$FAKE_IF" || return $?
2148 local nid1=$(lctl list_nids | head -n 1)
2149 local nid2=$(lctl list_nids | tail --lines 1)
2151 [[ $(lctl which_nid $nid1 $nid2) == $nid1 ]] ||
2152 error "Expect nid1 \"$nid1\" to be preferred"
2154 [[ $(lctl which_nid $nid2 $nid1) == $nid2 ]] ||
2155 error "Expect nid2 \"$nid2\" to be preferred"
2159 run_test 213 "Check LNetDist calculation for multiple local NIDs"
2161 function check_ni_status() {
2165 local status=$($LNETCTL net show |
2167 awk '/status/{print $NF}')
2169 echo "NI ${nid} expect status \"${expect}\" found \"${status}\""
2170 if [[ $status != $expect ]]; then
2171 error "Error: Expect NI status \"$expect\" for NID \"$nid\" but found \"$status\""
2178 cleanup_netns || error "Failed to cleanup netns before test execution"
2179 cleanup_lnet || error "Failed to unload modules before test execution"
2181 setup_fakeif || error "Failed to add fake IF"
2182 have_interface "$FAKE_IF" ||
2183 error "Expect $FAKE_IF configured but not found"
2185 reinit_dlc || return $?
2187 add_net "tcp" "${INTERFACES[0]}" || return $?
2188 add_net "tcp" "$FAKE_IF" || return $?
2190 local nid1=$(lctl list_nids | head -n 1)
2191 local nid2=$(lctl list_nids | tail --lines 1)
2193 check_ni_status "0@lo" up
2194 check_ni_status "$nid1" up
2195 check_ni_status "$nid2" up
2197 echo "Set $FAKE_IF down"
2198 echo "ip link set dev $FAKE_IF down"
2199 ip link set dev $FAKE_IF down
2200 check_ni_status "0@lo" up
2201 check_ni_status "$nid1" up
2202 check_ni_status "$nid2" down
2204 run_test 214 "Check local NI status when link is downed"
2210 $LNETCTL net show -v 2 |
2211 egrep -e nid -e $stat |
2213 awk '/'$stat':/{print $NF}'
2218 for nidvar in nid1 nid2; do
2219 for stat in send_count recv_count; do
2220 s=$(get_ni_stat ${!nidvar} $stat)
2221 eval ${nidvar}_pre_${stat}=$s
2228 for nidvar in nid1 nid2; do
2229 for stat in send_count recv_count; do
2230 s=$(get_ni_stat ${!nidvar} $stat)
2231 eval ${nidvar}_post_${stat}=$s
2241 eval pre=\${${nidvar}_pre_${stat}}
2242 eval post=\${${nidvar}_post_${stat}}
2244 echo "${!nidvar} pre ${stat} $pre post ${stat} $post"
2246 [[ $pre -ne $post ]]
2250 cleanup_netns || error "Failed to cleanup netns before test execution"
2251 cleanup_lnet || error "Failed to unload modules before test execution"
2253 reinit_dlc || return $?
2255 add_net "tcp1" "${INTERFACES[0]}" || return $?
2256 add_net "tcp2" "${INTERFACES[0]}" || return $?
2258 local nid1=$($LCTL list_nids | head -n 1)
2259 local nid2=$($LCTL list_nids | tail --lines 1)
2261 do_lnetctl peer add --prim $nid1 --nid $nid2 ||
2262 error "Failed to add peer"
2266 for nidvarA in nid1 nid2; do
2269 for nidvarB in nid1 nid2; do
2270 [[ $nidvarA == $nidvarB ]] && continue
2274 echo "$LNETCTL ping $dst x $npings"
2275 for i in $(seq 1 $npings); do
2276 $LNETCTL ping $dst &>/dev/null ||
2277 error "$LNETCTL ping $dst failed"
2282 # No source specified, sends to either NID should cause
2283 # counts to increase across both NIs
2284 for nidvar in nid1 nid2; do
2285 for stat in send_count recv_count; do
2286 ni_stat_changed $nidvar $stat ||
2287 error "$stat unchanged for ${!nidvar}"
2293 echo "$LNETCTL ping --source $src $dst x $npings"
2294 for i in $(seq 1 $npings); do
2295 $LNETCTL ping --source $src $dst &>/dev/null ||
2296 error "$LNETCTL ping --source $src $dst failed"
2301 # src nid == dest nid means stats for the _other_ NI
2302 # should be unchanged
2303 for nidvar in nid1 nid2; do
2304 for stat in send_count recv_count; do
2305 if [[ ${!nidvar} == $src ]]; then
2306 ni_stat_changed $nidvar $stat ||
2307 error "$stat unchanged for ${!nidvar}"
2309 ni_stat_changed $nidvar $stat &&
2310 error "$stat changed for ${!nidvar}"
2315 # Double number of pings for next iteration because the net
2316 # sequence numbers will have diverged
2317 npings=$(($npings * 2))
2320 # Ping from nid1 to nid2 should fail
2321 do_lnetctl ping --source $nid1 $nid2 &&
2322 error "ping from $nid1 to $nid2 should fail"
2324 # Ping from nid2 to nid1 should fail
2325 do_lnetctl ping --source $nid2 $nid1 &&
2326 error "ping from $nid2 to $nid1 should fail"
2330 run_test 215 "Test lnetctl ping --source option"
2335 reinit_dlc || return $?
2337 add_net "tcp" "${INTERFACES[0]}" || return $?
2338 add_net "tcp1" "${INTERFACES[0]}" || return $?
2340 local nids=( $($LCTL list_nids | xargs echo) )
2342 do_lnetctl discover ${nids[0]} ||
2343 error "Initial discovery failed"
2345 do_lnetctl ping --source ${nids[0]} ${nids[0]} ||
2346 error "Initial ping failed $?"
2348 do_lnetctl ping --source ${nids[1]} ${nids[1]} ||
2349 error "Initial ping failed $?"
2352 for src in "${nids[@]}"; do
2353 for dst in "${nids[@]}"; do
2354 $LCTL net_drop_add -r 1 -s $src -d $dst -e network_timeout
2358 do_lnetctl ping ${nids[0]} || rc=$?
2360 $LCTL net_drop_del -a
2363 error "expected ping to fail"
2365 check_nid_in_recovq "-p" 0
2366 check_nid_in_recovq "-l" 1
2370 run_test 216 "Failed send to peer NI owned by local host should not trigger peer NI recovery"
2373 reinit_dlc || return $?
2375 [[ $($LNETCTL net show | grep -c nid) -ne 1 ]] &&
2376 error "Unexpected number of NIs after initalizing DLC"
2378 do_lnetctl discover 0@lo ||
2379 error "Failed to discover 0@lo"
2383 run_test 217 "Don't leak memory when discovering peer with nnis <= 1"
2386 reinit_dlc || return $?
2388 [[ ${#INTERFACES[@]} -lt 2 ]] &&
2389 skip "Need two LNet interfaces"
2391 add_net "tcp" "${INTERFACES[0]}" || return $?
2393 local nid1=$($LCTL list_nids | head -n 1)
2395 do_lnetctl ping $nid1 ||
2398 add_net "tcp" "${INTERFACES[1]}" || return $?
2400 local nid2=$($LCTL list_nids | tail --lines 1)
2402 do_lnetctl ping $nid2 ||
2405 $LCTL net_drop_add -s $nid1 -d $nid1 -e local_error -r 1
2407 do_lnetctl ping --source $nid1 $nid1 &&
2408 error "ping should have failed"
2410 local health_recovered
2413 for i in $(seq 1 5); do
2414 health_recovered=$($LNETCTL net show -v 2 |
2415 grep -c 'health value: 1000')
2417 if [[ $health_recovered -ne 2 ]]; then
2418 echo "Wait 1 second for health to recover"
2425 health_recovered=$($LNETCTL net show -v 2 |
2426 grep -c 'health value: 1000')
2428 $LCTL net_drop_del -a
2430 [[ $health_recovered -ne 2 ]] &&
2431 do_lnetctl net show -v 2 | egrep -e nid -e health &&
2432 error "Health hasn't recovered"
2436 run_test 218 "Local recovery pings should exercise all available paths"
2439 reinit_dlc || return $?
2440 add_net "tcp" "${INTERFACES[0]}" || return $?
2441 add_net "tcp1" "${INTERFACES[0]}" || return $?
2443 local nid1=$(lctl list_nids | head -n 1)
2444 local nid2=$(lctl list_nids | tail --lines 1)
2446 do_lnetctl ping $nid1 ||
2447 error "Ping failed $?"
2448 do_lnetctl ping $nid2 ||
2449 error "Ping failed $?"
2451 do_lnetctl discover $nid2 ||
2452 error "Discovery failed"
2454 $LNETCTL peer show --nid $nid1 | grep -q $nid2 ||
2455 error "$nid2 is not listed under $nid1"
2457 run_test 219 "Consolidate peer entries"
2465 do_rpc_nodes $node "$LNETCTL net add --net $net --if $if $opts" ||
2466 error "add $net on interface $if on node $node failed rc=$?"
2474 do_node $node "$LNETCTL route add --net $net --gateway $gw" ||
2475 error "route add to $net via $gw failed rc=$?"
2479 ROUTER_INTERFACES=()
2482 init_router_test_vars() {
2483 local rnodes=$(remote_nodes_list)
2484 [[ -z $rnodes || $(wc -w <<<$rnodes) -lt 2 ]] &&
2485 skip "Need at least 2 remote nodes found \"$rnodes\""
2487 ROUTER=$(awk '{print $1}' <<<$rnodes)
2488 RPEER=$(awk '{print $2}' <<<$rnodes)
2490 rnodes=$(comma_list $ROUTER $RPEER)
2491 local all_nodes=$(comma_list $rnodes $HOSTNAME)
2493 do_nodes $rnodes $LUSTRE_RMMOD ||
2494 error "failed to unload modules"
2496 do_rpc_nodes $rnodes "load_lnet config_on_load=1" ||
2497 error "Failed to load and configure LNet"
2499 ROUTER_INTERFACES=( $(do_rpc_nodes --quiet $ROUTER lnet_if_list) )
2501 RPEER_INTERFACES=( $(do_rpc_nodes --quiet $RPEER lnet_if_list) )
2503 do_nodes $all_nodes $LUSTRE_RMMOD ||
2504 error "Failed to unload modules"
2506 [[ ${#INTERFACES[@]} -eq 0 ]] &&
2507 error "No interfaces configured for local host $HOSTNAME"
2508 [[ ${#ROUTER_INTERFACES[@]} -eq 0 ]] &&
2509 error "No interfaces configured for router $ROUTER"
2510 [[ ${#RPEER_INTERFACES[@]} -eq 0 ]] &&
2511 error "No interfaces configured for remote peer $RPEER"
2519 LOCAL_NET=${NETTYPE}1
2520 REMOTE_NET=${NETTYPE}2
2521 setup_router_test() {
2523 local rtr_net_opts="$2"
2525 (( $MDS1_VERSION >= $(version_code 2.15.0) )) ||
2526 skip "need at least 2.15.0 for load_lnet"
2528 if [[ ${#RPEER_INTERFACES[@]} -eq 0 ]]; then
2529 init_router_test_vars ||
2533 local all_nodes=$(comma_list $ROUTER $RPEER $HOSTNAME)
2535 do_nodes $all_nodes $LUSTRE_RMMOD ||
2536 error "failed to unload modules"
2538 mod_opts+=" alive_router_check_interval=5"
2539 mod_opts+=" router_ping_timeout=5"
2540 mod_opts+=" large_router_buffers=4"
2541 mod_opts+=" small_router_buffers=8"
2542 mod_opts+=" tiny_router_buffers=16"
2543 do_rpc_nodes $all_nodes load_lnet "${mod_opts}" ||
2544 error "Failed to load lnet"
2546 do_nodes $all_nodes "$LNETCTL lnet configure" ||
2547 error "Failed to initialize DLC"
2549 do_net_add $ROUTER $LOCAL_NET ${ROUTER_INTERFACES[0]} $rtr_net_opts ||
2552 do_net_add $ROUTER $REMOTE_NET ${ROUTER_INTERFACES[0]} ||
2555 do_net_add $RPEER $REMOTE_NET ${RPEER_INTERFACES[0]} ||
2558 add_net $LOCAL_NET ${INTERFACES[0]} ||
2561 ROUTER_NIDS=( $(do_node $ROUTER $LCTL list_nids 2>/dev/null |
2563 RPEER_NIDS=( $(do_node $RPEER $LCTL list_nids 2>/dev/null |
2565 LNIDS=( $($LCTL list_nids 2>/dev/null | xargs echo) )
2573 do_nodesv $node "if $LNETCTL route show --net $net --gateway $gw; then \
2574 $LNETCTL route del --net $net --gateway $gw; \
2580 cleanup_router_test() {
2581 local all_nodes=$(comma_list $HOSTNAME $ROUTER $RPEER)
2583 do_route_del $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2584 error "Failed to delete $REMOTE_NET route"
2586 do_route_del $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2587 error "Failed to delete $LOCAL_NET route"
2589 do_nodes $all_nodes $LUSTRE_RMMOD ||
2590 error "failed to unload modules"
2595 check_route_aliveness() {
2600 local lnetctl_actual
2604 chk_intvl=$(cat /sys/module/lnet/parameters/alive_router_check_interval)
2606 lctl_actual=$(do_node $node $LCTL show_route | awk '{print $7}')
2607 lnetctl_actual=$(do_node $node $LNETCTL route show -v |
2608 awk '/state/{print $NF}')
2610 for ((i = 0; i < $chk_intvl; i++)); do
2611 if [[ $lctl_actual == $expected ]] &&
2612 [[ $lnetctl_actual == $expected ]]; then
2616 echo "wait 1s for route state change"
2619 lctl_actual=$(do_node $node $LCTL show_route | awk '{print $7}')
2620 lnetctl_actual=$(do_node $node $LNETCTL route show -v |
2621 awk '/state/{print $NF}')
2624 [[ $lctl_actual != $expected ]] &&
2625 error "Wanted \"$expected\" lctl found \"$lctl_actual\""
2627 [[ $lnetctl_actual != $expected ]] &&
2628 error "Wanted \"$expected\" lnetctl found \"$lnetctl_actual\""
2633 check_router_ni_status() {
2634 local expected_local="$1"
2635 local expected_remote="$2"
2643 chk_intvl=$(cat /sys/module/lnet/parameters/alive_router_check_interval)
2644 timeout=$(cat /sys/module/lnet/parameters/router_ping_timeout)
2646 actual_local=$(do_node $ROUTER "$LNETCTL net show --net $LOCAL_NET" |
2647 awk '/status/{print $NF}')
2648 actual_remote=$(do_node $ROUTER "$LNETCTL net show --net $REMOTE_NET" |
2649 awk '/status/{print $NF}')
2651 for ((i = 0; i < $((chk_intvl + timeout)); i++)); do
2652 if [[ $actual_local == $expected_local ]] &&
2653 [[ $actual_remote == $expected_remote ]]; then
2657 echo "wait 1s for NI state change"
2660 actual_local=$(do_node $ROUTER \
2661 "$LNETCTL net show --net $LOCAL_NET" |
2662 awk '/status/{print $NF}')
2663 actual_remote=$(do_node $ROUTER \
2664 "$LNETCTL net show --net $REMOTE_NET" |
2665 awk '/status/{print $NF}')
2668 [[ $actual_local == $expected_local ]] ||
2669 error "$LOCAL_NET should be $expected_local"
2671 [[ $actual_remote == $expected_remote ]] ||
2672 error "$REMOTE_NET should be $expected_remote"
2677 do_basic_rtr_test() {
2678 do_node $ROUTER "$LNETCTL set routing 1" ||
2679 error "Unable to enable routing on $ROUTER"
2681 do_route_add $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2684 do_route_add $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2687 check_route_aliveness "$HOSTNAME" "up" ||
2690 check_route_aliveness "$RPEER" "up" ||
2693 do_lnetctl ping ${RPEER_NIDS[0]} ||
2694 error "Failed to ping ${RPEER_NIDS[0]}"
2696 do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" ||
2697 error "$RPEER failed to ping ${LNIDS[0]}"
2703 setup_router_test || return $?
2705 do_basic_rtr_test || return $?
2707 cleanup_router_test || return $?
2709 run_test 220 "Add routes w/default options - check aliveness"
2712 setup_router_test lnet_peer_discovery_disabled=1 || return $?
2714 do_basic_rtr_test || return $?
2716 cleanup_router_test || return $?
2718 run_test 221 "Add routes w/DD disabled - check aliveness"
2720 do_aarf_enabled_test() {
2721 do_node $ROUTER "$LNETCTL set routing 1" ||
2722 error "Unable to enable routing on $ROUTER"
2724 check_router_ni_status "down" "down"
2726 do_lnetctl ping ${RPEER_NIDS[0]} &&
2727 error "Ping should fail"
2729 do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" &&
2730 error "$RPEER ping should fail"
2732 # Adding a route should cause the router's NI on LOCAL_NET to get up
2733 do_route_add $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2736 check_router_ni_status "up" "down" ||
2739 # But route should still be down because of avoid_asym_router_failure
2740 check_route_aliveness "$HOSTNAME" "down" ||
2743 do_lnetctl ping ${RPEER_NIDS[0]} &&
2744 error "Ping should fail"
2746 do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" &&
2747 error "$RPEER ping should fail"
2749 # Adding the symmetric route should cause the remote NI to go up and
2751 do_route_add $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2754 check_router_ni_status "up" "up" ||
2757 check_route_aliveness "$HOSTNAME" "up" ||
2760 check_route_aliveness "$RPEER" "up" ||
2763 do_lnetctl ping ${RPEER_NIDS[0]} ||
2764 error "Failed to ping ${RPEER_NIDS[0]}"
2766 do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" ||
2767 error "$RPEER failed to ping ${LNIDS[0]}"
2769 # Stop LNet on local host
2770 do_lnetctl lnet unconfigure ||
2771 error "Failed to stop LNet rc=$?"
2773 check_router_ni_status "down" "up" ||
2776 check_route_aliveness "$RPEER" "down" ||
2779 do_lnetctl ping ${RPEER_NIDS[0]} &&
2780 error "Ping should fail"
2782 do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" &&
2783 error "$RPEER ping should fail"
2789 setup_router_test avoid_asym_router_failure=1 || return $?
2791 do_aarf_enabled_test || return $?
2793 cleanup_router_test || return $?
2795 run_test 222 "Check avoid_asym_router_failure=1"
2798 local opts="avoid_asym_router_failure=1 lnet_peer_discovery_disabled=1"
2800 setup_router_test "$opts" || return $?
2802 do_aarf_enabled_test || return $?
2804 cleanup_router_test || return $?
2806 run_test 223 "Check avoid_asym_router_failure=1 w/DD disabled"
2808 do_aarf_disabled_test() {
2809 do_node $ROUTER "$LNETCTL set routing 1" ||
2810 error "Unable to enable routing on $ROUTER"
2812 check_router_ni_status "down" "down"
2814 do_route_add $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2817 check_router_ni_status "up" "down" ||
2820 check_route_aliveness "$HOSTNAME" "up" ||
2823 do_route_add $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2826 check_router_ni_status "up" "up" ||
2829 check_route_aliveness "$HOSTNAME" "up" ||
2832 check_route_aliveness "$RPEER" "up" ||
2835 do_lnetctl ping ${RPEER_NIDS[0]} ||
2836 error "Failed to ping ${RPEER_NIDS[0]}"
2838 do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" ||
2839 error "$RPEER failed to ping ${LNIDS[0]}"
2841 # Stop LNet on local host
2842 do_lnetctl lnet unconfigure ||
2843 error "Failed to stop LNet rc=$?"
2845 check_router_ni_status "down" "up" ||
2848 check_route_aliveness "$RPEER" "up" ||
2855 setup_router_test avoid_asym_router_failure=0 ||
2858 do_aarf_disabled_test ||
2861 cleanup_router_test ||
2864 run_test 224 "Check avoid_asym_router_failure=0"
2867 local opts="avoid_asym_router_failure=0 lnet_peer_discovery_disabled=1"
2869 setup_router_test "$opts" || return $?
2871 do_aarf_disabled_test || return $?
2873 cleanup_router_test ||
2876 run_test 225 "Check avoid_asym_router_failure=0 w/DD disabled"
2878 do_rtr_peer_health_test() {
2881 do_node $ROUTER "$LNETCTL set routing 1" ||
2882 error "Unable to enable routing on $ROUTER"
2884 do_route_add $HOSTNAME $REMOTE_NET ${ROUTER_NIDS[0]} ||
2887 do_route_add $RPEER $LOCAL_NET ${ROUTER_NIDS[1]} ||
2890 check_router_ni_status "up" "up" ||
2893 check_route_aliveness "$HOSTNAME" "up" ||
2896 check_route_aliveness "$RPEER" "up" ||
2899 do_lnetctl ping ${RPEER_NIDS[0]} ||
2900 error "Failed to ping ${RPEER_NIDS[0]}"
2902 do_node $RPEER "$LNETCTL ping ${LNIDS[0]}" ||
2903 error "$RPEER failed to ping ${LNIDS[0]}"
2905 # Stop LNet on local host
2906 do_lnetctl lnet unconfigure ||
2907 error "Failed to stop LNet rc=$?"
2909 check_router_ni_status "down" "up" ||
2912 check_route_aliveness "$RPEER" "up" ||
2915 # The NI used to send the message to the destination will be the
2916 # router's NI on LOCAL_NET, so that's the drop count that will be
2918 local d1=$(do_node $ROUTER $LNETCTL net show -v --net $LOCAL_NET | \
2919 awk '/drop_count:/{print $NF}')
2921 # Ping from RPEER to local host should be dropped by the router
2922 do_node $RPEER "$LCTL ping ${LNIDS[0]}" &&
2923 error "$RPEER expected ping to fail"
2925 local d2=$(do_node $ROUTER $LNETCTL net show -v --net $LOCAL_NET | \
2926 awk '/drop_count:/{print $NF}')
2928 [[ $((d2 - d1)) -ne $expected ]] &&
2929 error "Expected drop count change by $expected: $d1 -> $d2"
2935 setup_router_test avoid_asym_router_failure=0 --peer-timeout=10 ||
2938 do_rtr_peer_health_test 1 ||
2941 cleanup_router_test ||
2944 run_test 226 "Check router peer health enabled"
2947 setup_router_test avoid_asym_router_failure=0 --peer-timeout=0 ||
2950 do_rtr_peer_health_test 0 ||
2953 cleanup_router_test ||
2956 run_test 227 "Check router peer health disabled"
2960 echo "Check valid values; Should succeed"
2964 for ((i = 4; i < 16; i+=1)); do
2965 reinit_dlc || return $?
2966 add_net "tcp" "${INTERFACES[0]}" || return $?
2967 do_lnetctl net set --all --conns-per-peer $i ||
2968 error "should have succeeded $?"
2969 $LNETCTL net show -v 1 | grep -q "conns_per_peer: $i" ||
2970 error "failed to set conns-per-peer to $i"
2971 lnid="$(lctl list_nids | head -n 1)"
2972 do_lnetctl ping "$lnid" ||
2973 error "failed to ping myself"
2975 # "lctl --net tcp conn_list" prints the list of active
2976 # connections. Since we're pinging ourselves, there should be
2977 # 2 Control connections plus 2*conns_per_peer connections
2978 # created (one Bulk Input, one Bulk Output in each pair).
2979 # Here's the sample output for conns_per_peer set to 1:
2980 # 12345-1.1.1.1@tcp I[0]host01->host01:988 2626560/1061296 nonagle
2981 # 12345-1.1.1.1@tcp O[0]host01->host01:1022 2626560/1061488 nonagle
2982 # 12345-1.1.1.1@tcp C[0]host01->host01:988 2626560/1061296 nonagle
2983 # 12345-1.1.1.1@tcp C[0]host01->host01:1023 2626560/1061488 nonagle
2984 cmd="printf 'network tcp\nconn_list\n' | lctl | grep -c '$lnid'"
2986 # Expect 2+conns_per_peer*2 connections. Wait no longer
2988 wait_update $HOSTNAME "$cmd" "$((2+i*2))" 2 ||
2989 error "expected number of tcp connections $((2+i*2))"
2992 reinit_dlc || return $?
2993 add_net "tcp" "${INTERFACES[0]}" || return $?
2994 echo "Set > 127; Should fail"
2995 do_lnetctl net set --all --conns-per-peer 128 &&
2996 error "should have failed $?"
2998 reinit_dlc || return $?
2999 add_net "tcp" "${INTERFACES[0]}" || return $?
3000 echo "Set < 0; Should be ignored"
3001 do_lnetctl net set --all --conns-per-peer -1 ||
3002 error "should have succeeded $?"
3003 $LNETCTL net show -v 1 | grep -q "conns_per_peer: 1" ||
3004 error "Did not stay at default"
3006 run_test 230 "Test setting conns-per-peer"
3009 reinit_dlc || return $?
3011 do_lnetctl net add --net tcp --if ${INTERFACES[0]} ||
3012 error "Failed to add net"
3014 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-expected.yaml
3015 sed -i 's/peer_timeout: .*$/peer_timeout: 0/' \
3016 $TMP/sanity-lnet-$testnum-expected.yaml
3018 reinit_dlc || return $?
3020 do_lnetctl import $TMP/sanity-lnet-$testnum-expected.yaml ||
3021 error "Failed to import configuration"
3023 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
3025 compare_yaml_files || error "Wrong config after import"
3027 do_lnetctl net del --net tcp --if ${INTERFACES[0]} ||
3028 error "Failed to delete net tcp"
3030 do_lnetctl net add --net tcp --if ${INTERFACES[0]} --peer-timeout=0 ||
3031 error "Failed to add net with peer-timeout=0"
3033 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
3035 compare_yaml_files || error "Wrong config after lnetctl net add"
3037 reinit_dlc || return $?
3039 # lnet/include/lnet/lib-lnet.h defines DEFAULT_PEER_TIMEOUT 180
3040 sed -i 's/peer_timeout: .*$/peer_timeout: 180/' \
3041 $TMP/sanity-lnet-$testnum-expected.yaml
3043 sed -i '/^.*peer_timeout:.*$/d' $TMP/sanity-lnet-$testnum-actual.yaml
3045 do_lnetctl import $TMP/sanity-lnet-$testnum-actual.yaml ||
3046 error "Failed to import config without peer_timeout"
3048 $LNETCTL export --backup > $TMP/sanity-lnet-$testnum-actual.yaml
3052 run_test 231 "Check DLC handling of peer_timeout parameter"
3054 ### Test that linux route is added for each ni
3056 reinit_dlc || return $?
3057 add_net "tcp" "${INTERFACES[0]}" || return $?
3058 ip route show table ${INTERFACES[0]} | grep -q "${INTERFACES[0]}"
3060 run_test 250 "test that linux routes are added"
3063 [[ ${NETTYPE} =~ kfi* ]] ||
3064 skip "Need kfi NETTYPE"
3066 reinit_dlc || return $?
3067 add_net "kfi" "${INTERFACES[0]}" || return $?
3068 add_net "kfi1" "${INTERFACES[0]}" || return $?
3069 add_net "kfi10" "${INTERFACES[0]}" || return $?
3072 run_test 251 "Define multiple kfi networks on single interface"
3077 local out=$TMP/$tfile
3078 local prefix=/usr/include/linux/lnet
3080 # We use a hard coded prefix so that this test will not fail
3083 if ! which $CC > /dev/null 2>&1; then
3084 skip_env "$CC is not installed"
3087 cleanup_lnet || exit 1
3090 local cc_args="-Wall -Werror -std=c99 -c -x c /dev/null -o $out"
3091 if ! [[ -d $prefix ]]; then
3092 # Assume we're running in tree and fixup the include path.
3093 prefix=$LUSTRE/../lnet/include/uapi/linux/lnet
3094 cc_args+=" -I $LUSTRE/../lnet/include/uapi"
3097 for header in $prefix/*.h; do
3098 if ! [[ -f "$header" ]]; then
3102 echo "$CC $cc_args -include $header"
3103 $CC $cc_args -include $header ||
3104 error "cannot compile '$header'"
3108 run_test 300 "packaged LNet UAPI headers can be compiled"
3110 # LU-16081 lnet: Memory leak on adding existing interface
3113 reinit_dlc || return $?
3114 do_lnetctl net add --net tcp --if ${INTERFACES[0]} ||
3115 error "Failed to add net"
3116 do_lnetctl net add --net tcp --if ${INTERFACES[0]} &&
3117 error "add net should have failed"
3118 do_lnetctl net del --net tcp --if ${INTERFACES[0]} ||
3119 error "Failed to del net"
3122 run_test 301 "Check for dynamic adds of same/wrong interface (memory leak)"
3125 ! [[ $NETTYPE =~ (tcp|o2ib) ]] && skip "Need tcp or o2ib NETTYPE"
3126 reinit_dlc || return $?
3128 add_net "${NETTYPE}" "${INTERFACES[0]}" || return $?
3130 local nid=$($LCTL list_nids)
3132 do_lnetctl ping ${nid} ||
3133 error "pinging self failed $?"
3134 do_lnetctl debug peer --nid ${nid} ||
3135 error "failed to dump peer debug info $?"
3137 run_test 302 "Check that peer debug info can be dumped"