Skip to content

Commit

Permalink
Merge branch 'net-selftests-mirroring-cleanup' into main
Browse files Browse the repository at this point in the history
Petr Machata says:

====================
selftest: Clean-up and stabilize mirroring tests

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.

mirror_test() accommodated this noisiness by giving the counters an
allowance of several packets. But that only works up to a point, and on
busy systems won't be always enough.

In this patch set, clean up and stabilize the mirroring selftests. The
original intention was to port the tests over to UDP, but the logic of
ICMP ends up being so entangled in the mirroring selftests that the
changes feel overly invasive. Instead, ICMP is kept, but where possible,
we match on ICMP message type, thus filtering out hits by other ICMP
messages.

Where this is not practical (where the counter tap is put on a device
that carries encapsulated packets), switch the counter condition to _at
least_ X observed packets. This is less robust, but barely so --
probably the only scenario that this would not catch is something like
erroneous packet duplication, which would hopefully get caught by the
numerous other tests in this extensive suite.

- Patches #1 to #3 clean up parameters at various helpers.

- Patches #4 to #6 stabilize the mirroring selftests as described above.

- Mirroring tests currently allow testing SW datapath even on HW
  netdevices by trapping traffic to the SW datapath. This complicates
  the tests a bit without a good reason: to test SW datapath, just run
  the selftests on the veth topology. Thus in patch #7, drop support for
  this dual SW/HW testing.

- At this point, some cleanups were either made possible by the previous
  patches, or were always possible. In patches #8 to #11, realize these
  cleanups.

- In patch #12, fix mlxsw mirror_gre selftest to respect setting TESTS.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Jun 28, 2024
2 parents c977ac4 + 098ba97 commit 748e3bb
Show file tree
Hide file tree
Showing 20 changed files with 355 additions and 538 deletions.
71 changes: 28 additions & 43 deletions tools/testing/selftests/drivers/net/mlxsw/mirror_gre.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ source $lib_dir/mirror_lib.sh
source $lib_dir/mirror_gre_lib.sh
source $lib_dir/mirror_gre_topo_lib.sh

ALL_TESTS="
test_keyful
test_soft
test_tos_fixed
test_ttl_inherit
"

setup_keyful()
{
tunnel_create gt6-key ip6gretap 2001:db8:3::1 2001:db8:3::2 \
Expand Down Expand Up @@ -118,15 +125,15 @@ test_span_gre_ttl_inherit()
RET=0

ip link set dev $tundev type $type ttl inherit
mirror_install $swp1 ingress $tundev "matchall $tcflags"
fail_test_span_gre_dir $tundev ingress
mirror_install $swp1 ingress $tundev "matchall"
fail_test_span_gre_dir $tundev

ip link set dev $tundev type $type ttl 100

quick_test_span_gre_dir $tundev ingress
quick_test_span_gre_dir $tundev
mirror_uninstall $swp1 ingress

log_test "$what: no offload on TTL of inherit ($tcflags)"
log_test "$what: no offload on TTL of inherit"
}

test_span_gre_tos_fixed()
Expand All @@ -138,61 +145,49 @@ test_span_gre_tos_fixed()
RET=0

ip link set dev $tundev type $type tos 0x10
mirror_install $swp1 ingress $tundev "matchall $tcflags"
fail_test_span_gre_dir $tundev ingress
mirror_install $swp1 ingress $tundev "matchall"
fail_test_span_gre_dir $tundev

ip link set dev $tundev type $type tos inherit
quick_test_span_gre_dir $tundev ingress
quick_test_span_gre_dir $tundev
mirror_uninstall $swp1 ingress

log_test "$what: no offload on a fixed TOS ($tcflags)"
log_test "$what: no offload on a fixed TOS"
}

test_span_failable()
{
local should_fail=$1; shift
local tundev=$1; shift
local what=$1; shift

RET=0

mirror_install $swp1 ingress $tundev "matchall $tcflags"
if ((should_fail)); then
fail_test_span_gre_dir $tundev ingress
else
quick_test_span_gre_dir $tundev ingress
fi
mirror_install $swp1 ingress $tundev "matchall"
fail_test_span_gre_dir $tundev
mirror_uninstall $swp1 ingress

log_test "$what: should_fail=$should_fail ($tcflags)"
log_test "fail $what"
}

test_failable()
test_keyful()
{
local should_fail=$1; shift

test_span_failable $should_fail gt6-key "mirror to keyful gretap"
test_span_failable $should_fail gt6-soft "mirror to gretap w/ soft underlay"
test_span_failable gt6-key "mirror to keyful gretap"
}

test_sw()
test_soft()
{
slow_path_trap_install $swp1 ingress
slow_path_trap_install $swp1 egress

test_failable 0

slow_path_trap_uninstall $swp1 egress
slow_path_trap_uninstall $swp1 ingress
test_span_failable gt6-soft "mirror to gretap w/ soft underlay"
}

test_hw()
test_tos_fixed()
{
test_failable 1

test_span_gre_tos_fixed gt4 gretap "mirror to gretap"
test_span_gre_tos_fixed gt6 ip6gretap "mirror to ip6gretap"
}


test_ttl_inherit()
{
test_span_gre_ttl_inherit gt4 gretap "mirror to gretap"
test_span_gre_ttl_inherit gt6 ip6gretap "mirror to ip6gretap"
}
Expand All @@ -202,16 +197,6 @@ trap cleanup EXIT
setup_prepare
setup_wait

if ! tc_offload_check; then
check_err 1 "Could not test offloaded functionality"
log_test "mlxsw-specific tests for mirror to gretap"
exit
fi

tcflags="skip_hw"
test_sw

tcflags="skip_sw"
test_hw
tests_run

exit $EXIT_STATUS
18 changes: 2 additions & 16 deletions tools/testing/selftests/drivers/net/mlxsw/mirror_gre_scale.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mirror_gre_tunnels_create()
cat >> $MIRROR_GRE_BATCH_FILE <<-EOF
filter add dev $swp1 ingress pref 1000 \
protocol ipv6 \
flower $tcflags dst_ip $match_dip \
flower skip_sw dst_ip $match_dip \
action mirred egress mirror dev $tun
EOF
done
Expand Down Expand Up @@ -107,7 +107,7 @@ mirror_gre_tunnels_destroy()
done
}

__mirror_gre_test()
mirror_gre_test()
{
local count=$1; shift
local should_fail=$1; shift
Expand All @@ -131,20 +131,6 @@ __mirror_gre_test()
done
}

mirror_gre_test()
{
local count=$1; shift
local should_fail=$1; shift

if ! tc_offload_check $TC_FLOWER_NUM_NETIFS; then
check_err 1 "Could not test offloaded functionality"
return
fi

tcflags="skip_sw"
__mirror_gre_test $count $should_fail
}

mirror_gre_setup_prepare()
{
h1=${NETIFS[p1]}
Expand Down
83 changes: 56 additions & 27 deletions tools/testing/selftests/net/forwarding/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1225,22 +1225,6 @@ trap_uninstall()
tc filter del dev $dev $direction pref 1 flower
}

slow_path_trap_install()
{
# For slow-path testing, we need to install a trap to get to
# slow path the packets that would otherwise be switched in HW.
if [ "${tcflags/skip_hw}" != "$tcflags" ]; then
trap_install "$@"
fi
}

slow_path_trap_uninstall()
{
if [ "${tcflags/skip_hw}" != "$tcflags" ]; then
trap_uninstall "$@"
fi
}

__icmp_capture_add_del()
{
local add_del=$1; shift
Expand All @@ -1257,22 +1241,34 @@ __icmp_capture_add_del()

icmp_capture_install()
{
__icmp_capture_add_del add 100 "" "$@"
local tundev=$1; shift
local filter=$1; shift

__icmp_capture_add_del add 100 "" "$tundev" "$filter"
}

icmp_capture_uninstall()
{
__icmp_capture_add_del del 100 "" "$@"
local tundev=$1; shift
local filter=$1; shift

__icmp_capture_add_del del 100 "" "$tundev" "$filter"
}

icmp6_capture_install()
{
__icmp_capture_add_del add 100 v6 "$@"
local tundev=$1; shift
local filter=$1; shift

__icmp_capture_add_del add 100 v6 "$tundev" "$filter"
}

icmp6_capture_uninstall()
{
__icmp_capture_add_del del 100 v6 "$@"
local tundev=$1; shift
local filter=$1; shift

__icmp_capture_add_del del 100 v6 "$tundev" "$filter"
}

__vlan_capture_add_del()
Expand All @@ -1290,12 +1286,18 @@ __vlan_capture_add_del()

vlan_capture_install()
{
__vlan_capture_add_del add 100 "$@"
local dev=$1; shift
local filter=$1; shift

__vlan_capture_add_del add 100 "$dev" "$filter"
}

vlan_capture_uninstall()
{
__vlan_capture_add_del del 100 "$@"
local dev=$1; shift
local filter=$1; shift

__vlan_capture_add_del del 100 "$dev" "$filter"
}

__dscp_capture_add_del()
Expand Down Expand Up @@ -1655,34 +1657,61 @@ __start_traffic()
local sip=$1; shift
local dip=$1; shift
local dmac=$1; shift
local -a mz_args=("$@")

$MZ $h_in -p $pktsize -A $sip -B $dip -c 0 \
-a own -b $dmac -t "$proto" -q "$@" &
-a own -b $dmac -t "$proto" -q "${mz_args[@]}" &
sleep 1
}

start_traffic_pktsize()
{
local pktsize=$1; shift
local h_in=$1; shift
local sip=$1; shift
local dip=$1; shift
local dmac=$1; shift
local -a mz_args=("$@")

__start_traffic $pktsize udp "$@"
__start_traffic $pktsize udp "$h_in" "$sip" "$dip" "$dmac" \
"${mz_args[@]}"
}

start_tcp_traffic_pktsize()
{
local pktsize=$1; shift
local h_in=$1; shift
local sip=$1; shift
local dip=$1; shift
local dmac=$1; shift
local -a mz_args=("$@")

__start_traffic $pktsize tcp "$@"
__start_traffic $pktsize tcp "$h_in" "$sip" "$dip" "$dmac" \
"${mz_args[@]}"
}

start_traffic()
{
start_traffic_pktsize 8000 "$@"
local h_in=$1; shift
local sip=$1; shift
local dip=$1; shift
local dmac=$1; shift
local -a mz_args=("$@")

start_traffic_pktsize 8000 "$h_in" "$sip" "$dip" "$dmac" \
"${mz_args[@]}"
}

start_tcp_traffic()
{
start_tcp_traffic_pktsize 8000 "$@"
local h_in=$1; shift
local sip=$1; shift
local dip=$1; shift
local dmac=$1; shift
local -a mz_args=("$@")

start_tcp_traffic_pktsize 8000 "$h_in" "$sip" "$dip" "$dmac" \
"${mz_args[@]}"
}

stop_traffic()
Expand Down
Loading

0 comments on commit 748e3bb

Please sign in to comment.