]> www.infradead.org Git - nvme.git/commitdiff
selftests: mirror: mirror_test(): Allow exact count of packets
authorPetr Machata <petrm@nvidia.com>
Thu, 27 Jun 2024 14:48:43 +0000 (16:48 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 28 Jun 2024 09:55:37 +0000 (10:55 +0100)
The mirroring selftests work by sending ICMP traffic between two hosts.
Along the way, this traffic is mirrored to a gretap netdevice, and counter
taps are then installed strategically along the path of the mirrored
traffic to verify the mirroring took place.

The problem with this is that besides mirroring the primary traffic, any
other service traffic is mirrored as well. At the same time, because the
tests need to work in HW-offloaded scenarios, the ability of the device to
do arbitrary packet inspection should not be taken for granted. Most tests
therefore simply use matchall, one uses flower to match on IP address.

As a result, the selftests are noisy, because besides the primary ICMP
traffic, any amount of other service traffic is mirrored as well.

mirror_test() accommodated this noisiness by giving the counters an
allowance of several packets. But in the previous patch, where possible,
counter taps were changed to match only on an exact ICMP message. At least
in those cases, we can demand an exact number of packets to match.

Where the tap is installed on a connective netdevice, the exact matching is
not practical (though with u32, anything is possible). In those places,
there should still be some leeway -- and probably bigger than before,
because experience shows that these tests are very noisy.

To that end, change mirror_test() so that it can be either called with an
exact number to expect, or with an expression. Where leeway is needed,
adjust callers to pass a ">= 10" instead of mere 10.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Danielle Ratson <danieller@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/forwarding/mirror_gre_bridge_1q_lag.sh
tools/testing/selftests/net/forwarding/mirror_gre_changes.sh
tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
tools/testing/selftests/net/forwarding/mirror_lib.sh
tools/testing/selftests/net/forwarding/mirror_vlan.sh

index c53148b1dc6360eba21372d78e5117891be2f485..b719d24a4ae56388a9f46564dadbae2e4334478d 100755 (executable)
@@ -239,7 +239,7 @@ test_lag_slave()
        setup_wait_dev $host_dev
        $ARPING -I br1 192.0.2.130 -qfc 1
        sleep 2
-       mirror_test vrf-h1 192.0.2.1 192.0.2.18 $host_dev 1 10
+       mirror_test vrf-h1 192.0.2.1 192.0.2.18 $host_dev 1 ">= 10"
 
        # Test lack of connectivity when both slaves are down.
        ip link set dev $up_dev down
index 3796f4256c9c9908a70d96cb59bc5874738c0251..b57fb9f069f4e0a5de669cc0d0929ee130307dde 100755 (executable)
@@ -81,7 +81,7 @@ test_span_gre_ttl()
 
        ip link set dev $tundev type $type ttl 50
        sleep 2
-       mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10
+       mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 ">= 10"
 
        ip link set dev $tundev type $type ttl 100
        tc filter del dev $h3 ingress pref 77
index e49535ce1cdd74f66dcd39e49319690050bb5a41..cc3a0a3f83ba909859aeb3645068bf7dfdc107ea 100644 (file)
@@ -76,7 +76,7 @@ full_test_span_gre_dir_vlan_ips()
        tc filter add dev $h3 ingress pref 77 prot 802.1q \
                flower $vlan_match \
                action pass
-       mirror_test v$h1 $ip1 $ip2 $h3 77 10
+       mirror_test v$h1 $ip1 $ip2 $h3 77 '>= 10'
        tc filter del dev $h3 ingress pref 77
 
        mirror_uninstall $swp1 $direction
index 6a0c66d7ba7f8dd09250b58568eaa4bb2d9f7031..1fc8545da6e0349a34562589808268d3cf5aea60 100644 (file)
@@ -44,14 +44,17 @@ mirror_test()
                local type="icmp echoreq"
        fi
 
+       if [[ -z ${expect//[[:digit:]]/} ]]; then
+               expect="== $expect"
+       fi
+
        local t0=$(tc_rule_stats_get $dev $pref)
        $MZ $proto $vrf_name ${sip:+-A $sip} -B $dip -a own -b bc -q \
            -c 10 -d 100msec -t $type
        sleep 0.5
        local t1=$(tc_rule_stats_get $dev $pref)
        local delta=$((t1 - t0))
-       # Tolerate a couple stray extra packets.
-       ((expect <= delta && delta <= expect + 2))
+       ((delta $expect))
        check_err $? "Expected to capture $expect packets, got $delta."
 }
 
@@ -146,8 +149,8 @@ do_test_span_vlan_dir_ips()
        # The traffic is meant for local box anyway, so will be trapped to
        # kernel.
        vlan_capture_install $dev "skip_hw vlan_id $vid vlan_ethtype $ul_proto"
-       mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
-       mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
+       mirror_test v$h1 $ip1 $ip2 $dev 100 "$expect"
+       mirror_test v$h2 $ip2 $ip1 $dev 100 "$expect"
        vlan_capture_uninstall $dev
 }
 
@@ -159,7 +162,8 @@ quick_test_span_vlan_dir_ips()
        local ip1=$1; shift
        local ip2=$1; shift
 
-       do_test_span_vlan_dir_ips 10 "$dev" "$vid" "$ul_proto" "$ip1" "$ip2"
+       do_test_span_vlan_dir_ips '>= 10' "$dev" "$vid" "$ul_proto" \
+                                 "$ip1" "$ip2"
 }
 
 fail_test_span_vlan_dir_ips()
index 074165f46a9d0bdec74ea3ed2c8e5a1a1bbf598a..bc32978465118e219fffb25f086e5a7136cb1f10 100755 (executable)
@@ -85,7 +85,7 @@ test_tagged_vlan_dir()
        RET=0
 
        mirror_install $swp1 $direction $swp3.555 "matchall $tcflags"
-       do_test_span_vlan_dir_ips 10 "$h3.555" 111 ip 192.0.2.17 192.0.2.18
+       do_test_span_vlan_dir_ips '>= 10' "$h3.555" 111 ip 192.0.2.17 192.0.2.18
        do_test_span_vlan_dir_ips  0 "$h3.555" 555 ip 192.0.2.17 192.0.2.18
        mirror_uninstall $swp1 $direction