Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: mirror: mirror_test(): Allow exact count of packets

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>

authored by

Petr Machata and committed by
David S. Miller
a86e0df9 83341535

+13 -9
+1 -1
tools/testing/selftests/net/forwarding/mirror_gre_bridge_1q_lag.sh
··· 239 239 setup_wait_dev $host_dev 240 240 $ARPING -I br1 192.0.2.130 -qfc 1 241 241 sleep 2 242 - mirror_test vrf-h1 192.0.2.1 192.0.2.18 $host_dev 1 10 242 + mirror_test vrf-h1 192.0.2.1 192.0.2.18 $host_dev 1 ">= 10" 243 243 244 244 # Test lack of connectivity when both slaves are down. 245 245 ip link set dev $up_dev down
+1 -1
tools/testing/selftests/net/forwarding/mirror_gre_changes.sh
··· 81 81 82 82 ip link set dev $tundev type $type ttl 50 83 83 sleep 2 84 - mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 10 84 + mirror_test v$h1 192.0.2.1 192.0.2.2 $h3 77 ">= 10" 85 85 86 86 ip link set dev $tundev type $type ttl 100 87 87 tc filter del dev $h3 ingress pref 77
+1 -1
tools/testing/selftests/net/forwarding/mirror_gre_lib.sh
··· 76 76 tc filter add dev $h3 ingress pref 77 prot 802.1q \ 77 77 flower $vlan_match \ 78 78 action pass 79 - mirror_test v$h1 $ip1 $ip2 $h3 77 10 79 + mirror_test v$h1 $ip1 $ip2 $h3 77 '>= 10' 80 80 tc filter del dev $h3 ingress pref 77 81 81 82 82 mirror_uninstall $swp1 $direction
+9 -5
tools/testing/selftests/net/forwarding/mirror_lib.sh
··· 44 44 local type="icmp echoreq" 45 45 fi 46 46 47 + if [[ -z ${expect//[[:digit:]]/} ]]; then 48 + expect="== $expect" 49 + fi 50 + 47 51 local t0=$(tc_rule_stats_get $dev $pref) 48 52 $MZ $proto $vrf_name ${sip:+-A $sip} -B $dip -a own -b bc -q \ 49 53 -c 10 -d 100msec -t $type 50 54 sleep 0.5 51 55 local t1=$(tc_rule_stats_get $dev $pref) 52 56 local delta=$((t1 - t0)) 53 - # Tolerate a couple stray extra packets. 54 - ((expect <= delta && delta <= expect + 2)) 57 + ((delta $expect)) 55 58 check_err $? "Expected to capture $expect packets, got $delta." 56 59 } 57 60 ··· 149 146 # The traffic is meant for local box anyway, so will be trapped to 150 147 # kernel. 151 148 vlan_capture_install $dev "skip_hw vlan_id $vid vlan_ethtype $ul_proto" 152 - mirror_test v$h1 $ip1 $ip2 $dev 100 $expect 153 - mirror_test v$h2 $ip2 $ip1 $dev 100 $expect 149 + mirror_test v$h1 $ip1 $ip2 $dev 100 "$expect" 150 + mirror_test v$h2 $ip2 $ip1 $dev 100 "$expect" 154 151 vlan_capture_uninstall $dev 155 152 } 156 153 ··· 162 159 local ip1=$1; shift 163 160 local ip2=$1; shift 164 161 165 - do_test_span_vlan_dir_ips 10 "$dev" "$vid" "$ul_proto" "$ip1" "$ip2" 162 + do_test_span_vlan_dir_ips '>= 10' "$dev" "$vid" "$ul_proto" \ 163 + "$ip1" "$ip2" 166 164 } 167 165 168 166 fail_test_span_vlan_dir_ips()
+1 -1
tools/testing/selftests/net/forwarding/mirror_vlan.sh
··· 85 85 RET=0 86 86 87 87 mirror_install $swp1 $direction $swp3.555 "matchall $tcflags" 88 - do_test_span_vlan_dir_ips 10 "$h3.555" 111 ip 192.0.2.17 192.0.2.18 88 + do_test_span_vlan_dir_ips '>= 10' "$h3.555" 111 ip 192.0.2.17 192.0.2.18 89 89 do_test_span_vlan_dir_ips 0 "$h3.555" 555 ip 192.0.2.17 192.0.2.18 90 90 mirror_uninstall $swp1 $direction 91 91