diff mbox series

[net,v4,3/3] selftests: fib_tests: Add multipath list receive tests

Message ID 20230830091341.17273-4-sriram.yagnaraman@est.tech (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Avoid TCP resets when using ECMP for load-balancing between multiple servers. | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns WARNING: line length of 83 exceeds 80 columns WARNING: line length of 86 exceeds 80 columns WARNING: line length of 92 exceeds 80 columns WARNING: line length of 95 exceeds 80 columns WARNING: line length of 97 exceeds 80 columns WARNING: line length of 98 exceeds 80 columns WARNING: line length of 99 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Sriram Yagnaraman Aug. 30, 2023, 9:13 a.m. UTC
The test uses perf stat to count the number of fib:fib_table_lookup
tracepoint hits for IPv4 and the number of fib6:fib6_table_lookup for
IPv6. The measured count is checked to be within 5% of the total number
of packets sent via veth1.

Signed-off-by: Sriram Yagnaraman <sriram.yagnaraman@est.tech>
---
 tools/testing/selftests/net/fib_tests.sh | 158 ++++++++++++++++++++++-
 1 file changed, 157 insertions(+), 1 deletion(-)

Comments

Ido Schimmel Aug. 30, 2023, 3:48 p.m. UTC | #1
On Wed, Aug 30, 2023 at 11:13:41AM +0200, Sriram Yagnaraman wrote:
> +link_stats_get()
> +{
> +	local ns=$1; shift
> +        local dev=$1; shift
> +        local dir=$1; shift
> +        local stat=$1; shift

Indentation is off...

> +
> +        ip -n $ns -j -s link show dev $dev \
> +                | jq '.[]["stats64"]["'$dir'"]["'$stat'"]'
> +}
> +
> +list_rcv_eval()
> +{
> +	local name=$1; shift
> +	local file=$1; shift
> +	local expected=$1; shift
> +	local exp=$1; shift

Nit: You can drop the first and last arguments since they don't change
between both invocations.

> +
> +

Unnecessary blank line


> +	local count=$(tail -n 1 $file | jq '.["counter-value"] | tonumber | floor')
> +	local ratio=$(echo "scale=2; $count / $expected" | bc -l)
> +	local res=$(echo "$ratio $exp" | bc)
> +	[[ $res -eq 1 ]]
> +	log_test $? 0 "$name route hit ratio ($ratio)"
> +}
> +
> +ipv4_mpath_list_test()
> +{
> +	echo
> +	echo "IPv4 multipath list receive tests"
> +
> +	mpath_dep_check || return 1
> +
> +	route_setup
> +
> +	set -e
> +	run_cmd "ip netns exec ns1 ethtool -K veth1 tcp-segmentation-offload off"
> +
> +	run_cmd "ip netns exec ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\""
> +	run_cmd "ip netns exec ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\""
> +	run_cmd "ip netns exec ns2 ethtool -K veth2 generic-receive-offload on"
> +	run_cmd "ip -n ns2 link add name nh1 up type dummy"
> +	run_cmd "ip -n ns2 link add name nh2 up type dummy"
> +	run_cmd "ip -n ns2 address add 172.16.201.1/24 dev nh1"
> +	run_cmd "ip -n ns2 address add 172.16.202.1/24 dev nh2"
> +	run_cmd "ip -n ns2 neigh add 172.16.201.2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
> +	run_cmd "ip -n ns2 neigh add 172.16.202.2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
> +	run_cmd "ip -n ns2 route add 203.0.113.0/24
> +		nexthop via 172.16.201.2 nexthop via 172.16.202.2"
> +	run_cmd "ip netns exec ns2 sysctl -qw net.ipv4.fib_multipath_hash_policy=1"
> +	set +e
> +
> +	local dmac=$(ip -n ns2 -j link show dev veth2 | jq -r '.[]["address"]')
> +	local tmp_file=$(mktemp)
> +	local cmd="ip netns exec ns1 mausezahn veth1 -a own -b $dmac
> +		-A 172.16.101.1 -B 203.0.113.1 -t udp 'sp=12345,dp=0-65535' -q"
> +
> +	# Packets forwarded in a list using a multipath route must not reuse a
> +	# cached result so that a flow always hits the same nexthop. In other
> +	# words, the FIB lookup tracepoint needs to be triggered for every
> +	# packet.
> +	local t0_rx_pkts=$(link_stats_get ns2 veth2 rx packets)
> +	run_cmd "perf stat -e fib:fib_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd"
> +	local t1_rx_pkts=$(link_stats_get ns2 veth2 rx packets)
> +	local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
> +	list_rcv_eval "Multipath" $tmp_file $diff ">= 0.95"
> +
> +	rm $tmp_file
> +	route_cleanup
> +}
> +
> +ipv6_mpath_list_test()
> +{
> +	echo
> +	echo "IPv6 multipath list receive tests"
> +
> +	mpath_dep_check || return 1
> +
> +	route_setup
> +
> +	set -e
> +	run_cmd "ip netns exec ns1 ethtool -K veth1 tcp-segmentation-offload off"
> +
> +	run_cmd "ip netns exec ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\""
> +	run_cmd "ip netns exec ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\""
> +	run_cmd "ip netns exec ns2 ethtool -K veth2 generic-receive-offload on"
> +	run_cmd "ip -n ns2 link add name nh1 up type dummy"
> +	run_cmd "ip -n ns2 link add name nh2 up type dummy"
> +	run_cmd "ip -n ns2 -6 address add 2001:db8:201::1/64 dev nh1"
> +	run_cmd "ip -n ns2 -6 address add 2001:db8:202::1/64 dev nh2"
> +	run_cmd "ip -n ns2 -6 neigh add 2001:db8:201::2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
> +	run_cmd "ip -n ns2 -6 neigh add 2001:db8:202::2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
> +	run_cmd "ip -n ns2 -6 route add 2001:db8:301::/64
> +		nexthop via 2001:db8:201::2 nexthop via 2001:db8:202::2"
> +	run_cmd "ip netns exec ns2 sysctl -qw net.ipv6.fib_multipath_hash_policy=1"
> +	set +e
> +
> +	local dmac=$(ip -n ns2 -j link show dev veth2 | jq -r '.[]["address"]')
> +	local tmp_file=$(mktemp)
> +	local cmd="ip netns exec ns1 mausezahn -6 veth1 -a own -b $dmac
> +		-A 2001:db8:101::1 -B 2001:db8:301::1 -t udp 'sp=12345,dp=0-65535' -q"
> +
> +	# Packets forwarded in a list using a multipath route must not reuse a
> +	# cached result so that a flow always hits the same nexthop. In other
> +	# words, the FIB lookup tracepoint needs to be triggered for every
> +	# packet.
> +	local t0_rx_pkts=$(link_stats_get ns2 veth2 rx packets)
> +	run_cmd "perf stat -e fib6:fib6_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd"
> +	local t1_rx_pkts=$(link_stats_get ns2 veth2 rx packets)
> +	local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
> +	list_rcv_eval "Multipath" $tmp_file $diff ">= 0.95"
> +
> +	rm $tmp_file
> +	route_cleanup
> +}
> +
>  ################################################################################
>  # usage
>  
> @@ -2433,6 +2587,8 @@ do
>  	ipv6_mangle)			ipv6_mangle_test;;
>  	ipv4_bcast_neigh)		ipv4_bcast_neigh_test;;
>  	fib6_gc_test|ipv6_gc)		fib6_gc_test;;
> +	ipv4_mpath_list)		ipv4_mpath_list_test;;
> +	ipv6_mpath_list)		ipv6_mpath_list_test;;
>  
>  	help) echo "Test names: $TESTS"; exit 0;;
>  	esac
> -- 
> 2.34.1
> 
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index d328af4a149c..42f49fa48c26 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -12,7 +12,8 @@  ksft_skip=4
 TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
        ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics \
        ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr \
-       ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"
+       ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test \
+       ipv4_mpath_list ipv6_mpath_list"
 
 VERBOSE=0
 PAUSE_ON_FAIL=no
@@ -2352,6 +2353,159 @@  ipv4_bcast_neigh_test()
 	cleanup
 }
 
+mpath_dep_check()
+{
+	if [ ! -x "$(command -v mausezahn)" ]; then
+		echo "mausezahn command not found. Skipping test"
+		return 1
+	fi
+
+	if [ ! -x "$(command -v jq)" ]; then
+		echo "jq command not found. Skipping test"
+		return 1
+	fi
+
+	if [ ! -x "$(command -v bc)" ]; then
+		echo "bc command not found. Skipping test"
+		return 1
+	fi
+
+	if [ ! -x "$(command -v perf)" ]; then
+		echo "perf command not found. Skipping test"
+		return 1
+	fi
+
+	perf list fib:* | grep -q fib_table_lookup
+	if [ $? -ne 0 ]; then
+		echo "IPv4 FIB tracepoint not found. Skipping test"
+		return 1
+	fi
+
+	perf list fib6:* | grep -q fib6_table_lookup
+	if [ $? -ne 0 ]; then
+		echo "IPv6 FIB tracepoint not found. Skipping test"
+		return 1
+	fi
+
+	return 0
+}
+
+link_stats_get()
+{
+	local ns=$1; shift
+        local dev=$1; shift
+        local dir=$1; shift
+        local stat=$1; shift
+
+        ip -n $ns -j -s link show dev $dev \
+                | jq '.[]["stats64"]["'$dir'"]["'$stat'"]'
+}
+
+list_rcv_eval()
+{
+	local name=$1; shift
+	local file=$1; shift
+	local expected=$1; shift
+	local exp=$1; shift
+
+
+	local count=$(tail -n 1 $file | jq '.["counter-value"] | tonumber | floor')
+	local ratio=$(echo "scale=2; $count / $expected" | bc -l)
+	local res=$(echo "$ratio $exp" | bc)
+	[[ $res -eq 1 ]]
+	log_test $? 0 "$name route hit ratio ($ratio)"
+}
+
+ipv4_mpath_list_test()
+{
+	echo
+	echo "IPv4 multipath list receive tests"
+
+	mpath_dep_check || return 1
+
+	route_setup
+
+	set -e
+	run_cmd "ip netns exec ns1 ethtool -K veth1 tcp-segmentation-offload off"
+
+	run_cmd "ip netns exec ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\""
+	run_cmd "ip netns exec ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\""
+	run_cmd "ip netns exec ns2 ethtool -K veth2 generic-receive-offload on"
+	run_cmd "ip -n ns2 link add name nh1 up type dummy"
+	run_cmd "ip -n ns2 link add name nh2 up type dummy"
+	run_cmd "ip -n ns2 address add 172.16.201.1/24 dev nh1"
+	run_cmd "ip -n ns2 address add 172.16.202.1/24 dev nh2"
+	run_cmd "ip -n ns2 neigh add 172.16.201.2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
+	run_cmd "ip -n ns2 neigh add 172.16.202.2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
+	run_cmd "ip -n ns2 route add 203.0.113.0/24
+		nexthop via 172.16.201.2 nexthop via 172.16.202.2"
+	run_cmd "ip netns exec ns2 sysctl -qw net.ipv4.fib_multipath_hash_policy=1"
+	set +e
+
+	local dmac=$(ip -n ns2 -j link show dev veth2 | jq -r '.[]["address"]')
+	local tmp_file=$(mktemp)
+	local cmd="ip netns exec ns1 mausezahn veth1 -a own -b $dmac
+		-A 172.16.101.1 -B 203.0.113.1 -t udp 'sp=12345,dp=0-65535' -q"
+
+	# Packets forwarded in a list using a multipath route must not reuse a
+	# cached result so that a flow always hits the same nexthop. In other
+	# words, the FIB lookup tracepoint needs to be triggered for every
+	# packet.
+	local t0_rx_pkts=$(link_stats_get ns2 veth2 rx packets)
+	run_cmd "perf stat -e fib:fib_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd"
+	local t1_rx_pkts=$(link_stats_get ns2 veth2 rx packets)
+	local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
+	list_rcv_eval "Multipath" $tmp_file $diff ">= 0.95"
+
+	rm $tmp_file
+	route_cleanup
+}
+
+ipv6_mpath_list_test()
+{
+	echo
+	echo "IPv6 multipath list receive tests"
+
+	mpath_dep_check || return 1
+
+	route_setup
+
+	set -e
+	run_cmd "ip netns exec ns1 ethtool -K veth1 tcp-segmentation-offload off"
+
+	run_cmd "ip netns exec ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\""
+	run_cmd "ip netns exec ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\""
+	run_cmd "ip netns exec ns2 ethtool -K veth2 generic-receive-offload on"
+	run_cmd "ip -n ns2 link add name nh1 up type dummy"
+	run_cmd "ip -n ns2 link add name nh2 up type dummy"
+	run_cmd "ip -n ns2 -6 address add 2001:db8:201::1/64 dev nh1"
+	run_cmd "ip -n ns2 -6 address add 2001:db8:202::1/64 dev nh2"
+	run_cmd "ip -n ns2 -6 neigh add 2001:db8:201::2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
+	run_cmd "ip -n ns2 -6 neigh add 2001:db8:202::2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
+	run_cmd "ip -n ns2 -6 route add 2001:db8:301::/64
+		nexthop via 2001:db8:201::2 nexthop via 2001:db8:202::2"
+	run_cmd "ip netns exec ns2 sysctl -qw net.ipv6.fib_multipath_hash_policy=1"
+	set +e
+
+	local dmac=$(ip -n ns2 -j link show dev veth2 | jq -r '.[]["address"]')
+	local tmp_file=$(mktemp)
+	local cmd="ip netns exec ns1 mausezahn -6 veth1 -a own -b $dmac
+		-A 2001:db8:101::1 -B 2001:db8:301::1 -t udp 'sp=12345,dp=0-65535' -q"
+
+	# Packets forwarded in a list using a multipath route must not reuse a
+	# cached result so that a flow always hits the same nexthop. In other
+	# words, the FIB lookup tracepoint needs to be triggered for every
+	# packet.
+	local t0_rx_pkts=$(link_stats_get ns2 veth2 rx packets)
+	run_cmd "perf stat -e fib6:fib6_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd"
+	local t1_rx_pkts=$(link_stats_get ns2 veth2 rx packets)
+	local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
+	list_rcv_eval "Multipath" $tmp_file $diff ">= 0.95"
+
+	rm $tmp_file
+	route_cleanup
+}
+
 ################################################################################
 # usage
 
@@ -2433,6 +2587,8 @@  do
 	ipv6_mangle)			ipv6_mangle_test;;
 	ipv4_bcast_neigh)		ipv4_bcast_neigh_test;;
 	fib6_gc_test|ipv6_gc)		fib6_gc_test;;
+	ipv4_mpath_list)		ipv4_mpath_list_test;;
+	ipv6_mpath_list)		ipv6_mpath_list_test;;
 
 	help) echo "Test names: $TESTS"; exit 0;;
 	esac