Commit 748e3bbf authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'net-selftests-mirroring-cleanup' into main



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: default avatarDavid S. Miller <davem@davemloft.net>
parents c977ac49 098ba97d
Loading
Loading
Loading
Loading
+28 −43
Original line number Diff line number Diff line
@@ -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 \
@@ -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()
@@ -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"
}
@@ -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
+2 −16
Original line number Diff line number Diff line
@@ -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
@@ -107,7 +107,7 @@ mirror_gre_tunnels_destroy()
	done
}

__mirror_gre_test()
mirror_gre_test()
{
	local count=$1; shift
	local should_fail=$1; shift
@@ -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]}
+56 −27
Original line number Diff line number Diff line
@@ -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
@@ -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()
@@ -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()
@@ -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()
+13 −32
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ test_span_gre_mac()

	RET=0

	mirror_install $swp1 $direction $tundev "matchall $tcflags"
	mirror_install $swp1 $direction $tundev "matchall"
	icmp_capture_install h3-${tundev} "src_mac $src_mac dst_mac $dst_mac"

	mirror_test v$h1 192.0.2.1 192.0.2.2 h3-${tundev} 100 10
@@ -82,29 +82,29 @@ test_span_gre_mac()
	icmp_capture_uninstall h3-${tundev}
	mirror_uninstall $swp1 $direction

	log_test "$direction $what: envelope MAC ($tcflags)"
	log_test "$direction $what: envelope MAC"
}

test_two_spans()
{
	RET=0

	mirror_install $swp1 ingress gt4 "matchall $tcflags"
	mirror_install $swp1 egress gt6 "matchall $tcflags"
	quick_test_span_gre_dir gt4 ingress
	quick_test_span_gre_dir gt6 egress
	mirror_install $swp1 ingress gt4 "matchall"
	mirror_install $swp1 egress gt6 "matchall"
	quick_test_span_gre_dir gt4 8 0
	quick_test_span_gre_dir gt6 0 8

	mirror_uninstall $swp1 ingress
	fail_test_span_gre_dir gt4 ingress
	quick_test_span_gre_dir gt6 egress
	fail_test_span_gre_dir gt4 8 0
	quick_test_span_gre_dir gt6 0 8

	mirror_install $swp1 ingress gt4 "matchall $tcflags"
	mirror_install $swp1 ingress gt4 "matchall"
	mirror_uninstall $swp1 egress
	quick_test_span_gre_dir gt4 ingress
	fail_test_span_gre_dir gt6 egress
	quick_test_span_gre_dir gt4 8 0
	fail_test_span_gre_dir gt6 0 8

	mirror_uninstall $swp1 ingress
	log_test "two simultaneously configured mirrors ($tcflags)"
	log_test "two simultaneously configured mirrors"
}

test_gretap()
@@ -131,30 +131,11 @@ test_ip6gretap_mac()
	test_span_gre_mac gt6 egress "mirror to ip6gretap"
}

test_all()
{
	slow_path_trap_install $swp1 ingress
	slow_path_trap_install $swp1 egress

	tests_run

	slow_path_trap_uninstall $swp1 egress
	slow_path_trap_uninstall $swp1 ingress
}

trap cleanup EXIT

setup_prepare
setup_wait

tcflags="skip_hw"
test_all

if ! tc_offload_check; then
	echo "WARN: Could not test offloaded functionality"
else
	tcflags="skip_sw"
	test_all
fi
tests_run

exit $EXIT_STATUS
+1 −22
Original line number Diff line number Diff line
@@ -196,32 +196,11 @@ test_ip6gretap()
	full_test_span_gre_dir gt6 egress  0 8 "mirror to ip6gretap w/ UL"
}

test_all()
{
	RET=0

	slow_path_trap_install $swp1 ingress
	slow_path_trap_install $swp1 egress

	tests_run

	slow_path_trap_uninstall $swp1 egress
	slow_path_trap_uninstall $swp1 ingress
}

trap cleanup EXIT

setup_prepare
setup_wait

tcflags="skip_hw"
test_all

if ! tc_offload_check; then
	echo "WARN: Could not test offloaded functionality"
else
	tcflags="skip_sw"
	test_all
fi
tests_run

exit $EXIT_STATUS
Loading