Whamcloud - gitweb
LU-14939 lnet: Allow specifying a source NID for lnetctl ping
[fs/lustre-release.git] / lustre / tests / sanity-lnet.sh
index a11e680..ea76ab1 100755 (executable)
@@ -255,11 +255,15 @@ if [[ -z ${NIDS[@]} ]]; then
        error "No NID configured after module load"
 fi
 
+do_lnetctl net show
+ip a
+
 declare -a INTERFACES
 for ((i = 0; i < ${#NIDS[@]}; i++)); do
        ip=$(sed 's/^\(.*\)@.*$/\1/'<<<${NIDS[i]})
        INTERFACES[i]=$(ip -o a s |
                        awk '$4 ~ /^'$ip'\//{print $2}')
+       INTERFACES=($(echo "${INTERFACES[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
        if [[ -z ${INTERFACES[i]} ]]; then
                error "Can't determine interface name for NID ${NIDS[i]}"
        elif [[ 1 -ne $(wc -w <<<${INTERFACES[i]}) ]]; then
@@ -1254,7 +1258,29 @@ EOF
 }
 run_test 104 "Set/check response_tracking param"
 
-### load lnet in default namespace, configure in target namespace
+test_105() {
+       reinit_dlc || return $?
+       add_net "tcp" "${INTERFACES[0]}"
+       do_lnetctl route add --net tcp105 --gateway 105.105.105.105@tcp ||
+               error "route add failed $?"
+       do_lnetctl peer add --prim 105.105.105.105@tcp &&
+               error "peer add should fail"
+
+       return 0
+}
+run_test 105 "Adding duplicate GW peer should fail"
+
+test_106() {
+       reinit_dlc || return $?
+       add_net "tcp" "${INTERFACES[0]}"
+       do_lnetctl route add --net tcp106 --gateway 106.106.106.106@tcp ||
+               error "route add failed $?"
+       do_lnetctl peer del --prim 106.106.106.106@tcp &&
+               error "peer del should fail"
+
+       return 0
+}
+run_test 106 "Deleting GW peer should fail"
 
 test_200() {
        cleanup_lnet || exit 1
@@ -1613,6 +1639,7 @@ test_208() {
        local if0_ip=$(ip --oneline addr show dev ${INTERFACES[0]} |
                       awk '/inet /{print $4}' |
                       sed 's:/.*::')
+       if0_ip=($(echo "${if0_ip[@]}" | tr ' ' '\n' | uniq | tr '\n' ' '))
        local ip2nets_str="tcp(${INTERFACES[0]}) $if0_ip"
 
        echo "Configure single NID \"$ip2nets_str\""
@@ -2045,6 +2072,126 @@ test_214() {
 }
 run_test 214 "Check local NI status when link is downed"
 
+get_ni_stat() {
+       local nid=$1
+       local stat=$2
+
+       $LNETCTL net show -v 2 |
+               egrep -e nid -e $stat |
+               grep -wA 1 $nid |
+               awk '/'$stat':/{print $NF}'
+}
+
+ni_stats_pre() {
+       local nidvar s
+       for nidvar in nid1 nid2; do
+               for stat in send_count recv_count; do
+                       s=$(get_ni_stat ${!nidvar} $stat)
+                       eval ${nidvar}_pre_${stat}=$s
+               done
+       done
+}
+
+ni_stats_post() {
+       local nidvar s
+       for nidvar in nid1 nid2; do
+               for stat in send_count recv_count; do
+                       s=$(get_ni_stat ${!nidvar} $stat)
+                       eval ${nidvar}_post_${stat}=$s
+               done
+       done
+}
+
+ni_stat_changed() {
+       local nidvar=$1
+       local stat=$2
+
+       local pre post
+       eval pre=\${${nidvar}_pre_${stat}}
+       eval post=\${${nidvar}_post_${stat}}
+
+       echo "${!nidvar} pre ${stat} $pre post ${stat} $post"
+
+       [[ $pre -ne $post ]]
+}
+
+test_215() {
+       have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
+
+       cleanup_netns || error "Failed to cleanup netns before test execution"
+       cleanup_lnet || error "Failed to unload modules before test execution"
+
+       reinit_dlc || return $?
+
+       add_net "tcp1" "eth0" || return $?
+       add_net "tcp2" "eth0" || return $?
+
+       local nid1=$($LCTL list_nids | head -n 1)
+       local nid2=$($LCTL list_nids | tail --lines 1)
+
+       do_lnetctl peer add --prim $nid1 --nid $nid2 ||
+               error "Failed to add peer"
+
+       local npings=25
+
+       for nidvarA in nid1 nid2; do
+               src=${!nidvarA}
+               dst=${!nidvarA}
+               for nidvarB in nid1 nid2; do
+                       [[ $nidvarA == $nidvarB ]] && continue
+
+                       ni_stats_pre
+
+                       echo "$LNETCTL ping $dst x $npings"
+                       for i in $(seq 1 $npings); do
+                               $LNETCTL ping $dst &>/dev/null ||
+                                       error "$LNETCTL ping $dst failed"
+                       done
+
+                       ni_stats_post
+
+                       # No source specified, sends to either NID should cause
+                       # counts to increase across both NIs
+                       for nidvar in nid1 nid2; do
+                               for stat in send_count recv_count; do
+                                       ni_stat_changed $nidvar $stat ||
+                                               error "$stat unchanged for ${!nidvar}"
+                               done
+                       done
+
+                       ni_stats_pre
+
+                       echo "$LNETCTL ping --source $src $dst x $npings"
+                       for i in $(seq 1 $npings); do
+                               $LNETCTL ping --source $src $dst &>/dev/null ||
+                                       error "$LNETCTL ping --source $src $dst failed"
+                       done
+
+                       ni_stats_post
+
+                       # src nid == dest nid means stats for the _other_ NI
+                       # should be unchanged
+                       for nidvar in nid1 nid2; do
+                               for stat in send_count recv_count; do
+                                       if [[ ${!nidvar} == $src ]]; then
+                                               ni_stat_changed $nidvar $stat ||
+                                                       error "$stat unchanged for ${!nidvar}"
+                                       else
+                                               ni_stat_changed $nidvar $stat &&
+                                                       error "$stat changed for ${!nidvar}"
+                                       fi
+                               done
+                       done
+               done
+               # Double number of pings for next iteration because the net
+               # sequence numbers will have diverged
+               npings=$(($npings * 2))
+       done
+
+       return 0
+}
+run_test 215 "Test lnetctl ping --source option"
+
 test_230() {
        # LU-12815
        echo "Check valid values; Should succeed"
@@ -2061,6 +2208,7 @@ test_230() {
                lnid="$(lctl list_nids | head -n 1)"
                do_lnetctl ping "$lnid" ||
                        error "failed to ping myself"
+
                # "lctl --net tcp conn_list" prints the list of active
                # connections. Since we're pinging ourselves, there should be
                # 2 Control connections plus 2*conns_per_peer connections
@@ -2094,6 +2242,15 @@ test_230() {
 }
 run_test 230 "Test setting conns-per-peer"
 
+### Test that linux route is added for each ni
+test_250() {
+       have_interface "eth0" || skip "Need eth0 interface with ipv4 configured"
+       reinit_dlc || return $?
+       add_net "tcp" "eth0" || return $?
+       ip route show table eth0 | grep -q "eth0"
+}
+run_test 250 "test that linux routes are added"
+
 test_300() {
        # LU-13274
        local header