netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, kuba@kernel.org,
	edumazet@google.com, pabeni@redhat.com, dsahern@kernel.org,
	horms@kernel.org, idosch@nvidia.com, kuniyu@amazon.com,
	Willem de Bruijn <willemb@google.com>
Subject: Re: [PATCH net-next 3/3] selftests/net: test tcp connection load balancing
Date: Wed, 23 Apr 2025 12:05:46 +0300	[thread overview]
Message-ID: <aAitarcdcgq9x6uL@shredder> (raw)
In-Reply-To: <20250420180537.2973960-4-willemdebruijn.kernel@gmail.com>

On Sun, Apr 20, 2025 at 02:04:31PM -0400, Willem de Bruijn wrote:
> From: Willem de Bruijn <willemb@google.com>
> 
> Verify that TCP connections use both routes when connecting multiple
> times to a remote service over a two nexthop multipath route.
> 
> Use netcat to create the connections. Use tc prio + tc filter to
> count routes taken, counting SYN packets across the two egress
> devices.
> 
> To avoid flaky tests when testing inherently randomized behavior,
> set a low bar and pass if even a single SYN is observed on both
> devices.
> 
> Signed-off-by: Willem de Bruijn <willemb@google.com>
> 
> ---
> 
> Integrated into fib_nexthops.sh as it covers multipath nexthop
> routing and can reuse all of its setup(), but technically the test
> does not use nexthop *objects* as is, so I can also move into a
> separate file and move common setup code to lib.sh if preferred.

No strong preference, but fib_nexthops.sh explicitly tests nexthop
objects, so including here a test that doesn't use them is a bit weird.
Did you consider putting this in fib_tests.sh instead?

> ---
>  tools/testing/selftests/net/fib_nexthops.sh | 83 +++++++++++++++++++++
>  1 file changed, 83 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh
> index b39f748c2572..93d19e92bd5b 100755
> --- a/tools/testing/selftests/net/fib_nexthops.sh
> +++ b/tools/testing/selftests/net/fib_nexthops.sh
> @@ -31,6 +31,7 @@ IPV4_TESTS="
>  	ipv4_compat_mode
>  	ipv4_fdb_grp_fcnal
>  	ipv4_mpath_select
> +	ipv4_mpath_balance
>  	ipv4_torture
>  	ipv4_res_torture
>  "
> @@ -45,6 +46,7 @@ IPV6_TESTS="
>  	ipv6_compat_mode
>  	ipv6_fdb_grp_fcnal
>  	ipv6_mpath_select
> +	ipv6_mpath_balance
>  	ipv6_torture
>  	ipv6_res_torture
>  "
> @@ -2110,6 +2112,87 @@ ipv4_res_torture()
>  	log_test 0 0 "IPv4 resilient nexthop group torture test"
>  }
>  
> +# Install a prio qdisc with separate bands counting IPv4 and IPv6 SYNs
> +tc_add_syn_counter() {
> +	local -r dev=$1
> +
> +	# qdisc with band 1 for no-match, band 2 for ipv4, band 3 for ipv6
> +	ip netns exec $me tc qdisc add dev $dev root handle 1: prio bands 3 \
> +		priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> +	ip netns exec $me tc qdisc add dev $dev parent 1:1 handle 2: pfifo
> +	ip netns exec $me tc qdisc add dev $dev parent 1:2 handle 4: pfifo
> +	ip netns exec $me tc qdisc add dev $dev parent 1:3 handle 6: pfifo
> +
> +	# ipv4 filter on SYN flag set: band 2
> +	ip netns exec $me tc filter add dev $dev parent 1: protocol ip u32 \
> +		match ip protocol 6 0xff \
> +		match ip dport 8000 0xffff \
> +		match u8 0x02 0xff at 33 \
> +		flowid 1:2
> +
> +	# ipv6 filter on SYN flag set: band 3
> +	ip netns exec $me tc filter add dev $dev parent 1: protocol ipv6 u32 \
> +		match ip6 protocol 6 0xff \
> +		match ip6 dport 8000 0xffff \
> +		match u8 0x02 0xff at 53 \
> +		flowid 1:3
> +}
> +
> +tc_get_syn_counter() {
> +	ip netns exec $me tc -j -s qdisc show dev $1 handle $2 | jq .[0].packets
> +}
> +
> +ip_mpath_balance() {
> +	local -r ipver="-$1"
> +	local -r daddr=$2
> +	local -r handle="$1:"
> +	local -r num_conn=20
> +
> +	tc_add_syn_counter veth1
> +	tc_add_syn_counter veth3
> +
> +	for i in $(seq 1 $num_conn); do
> +		ip netns exec $remote nc $ipver -l -p 8000 >/dev/null &
> +		echo -n a | ip netns exec $me nc $ipver -q 0 $daddr 8000

I don't have the '-q' option in Fedora:

# ./fib_nexthops.sh -t ipv4_mpath_balance
nc: invalid option -- 'q'
[...]
Tests passed:   0
Tests failed:   1
Tests skipped:  0

We had multiple problems in the past with 'nc' because of different
distributions using different versions. See for example:

ba6fbd383c12dfe6833968e3555ada422720a76f
5e8670610b93158ffacc3241f835454ff26a3469

Maybe use 'socat' instead?

> +	done
> +
> +	local -r syn0="$(tc_get_syn_counter veth1 $handle)"
> +	local -r syn1="$(tc_get_syn_counter veth3 $handle)"
> +	local -r syns=$((syn0+syn1))
> +
> +	[ "$VERBOSE" = "1" ] && echo "multipath: syns seen: ($syn0,$syn1)"
> +
> +	[[ $syns -ge $num_conn ]] && [[ $syn0 -gt 0 ]] && [[ $syn1 -gt 0 ]]

IIUC, this only tests that connections to the same destination address
and destination port are load balanced across all the paths (patch #2),
but it doesn't test that each connection uses the source address of the
egress interface (patch #1). Any reason not to test both? I'm asking
because I expect the current test to pass even without both patches.

I noticed that you are using tc-u32 for the matching, but with tc-flower
you can easily match on both 'src_ip' and 'tcp_flags'.

> +}
> +
> +ipv4_mpath_balance()
> +{
> +	$IP route add 172.16.101.1 \
> +		nexthop via 172.16.1.2 \
> +		nexthop via 172.16.2.2
> +
> +	ip netns exec $me \
> +		sysctl -q -w net.ipv4.fib_multipath_hash_policy=1
> +
> +	ip_mpath_balance 4 172.16.101.1
> +
> +	log_test $? 0 "Multipath loadbalance"
> +}
> +
> +ipv6_mpath_balance()
> +{
> +	$IP route add 2001:db8:101::1\
> +		nexthop via 2001:db8:91::2 \
> +		nexthop via 2001:db8:92::2
> +
> +	ip netns exec $me \
> +		sysctl -q -w net.ipv6.fib_multipath_hash_policy=1
> +
> +	ip_mpath_balance 6 2001:db8:101::1
> +
> +	log_test $? 0 "Multipath loadbalance"
> +}
> +
>  basic()
>  {
>  	echo
> -- 
> 2.49.0.805.g082f7c87e0-goog
> 
> 

  reply	other threads:[~2025-04-23  9:05 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-20 18:04 [PATCH net-next 0/3] ip: improve tcp sock multipath routing Willem de Bruijn
2025-04-20 18:04 ` [PATCH net-next 1/3] ipv4: prefer multipath nexthop that matches source address Willem de Bruijn
2025-04-22 16:06   ` David Ahern
2025-04-20 18:04 ` [PATCH net-next 2/3] ip: load balance tcp connections to single dst addr and port Willem de Bruijn
2025-04-21 13:54   ` Willem de Bruijn
2025-04-22 16:41   ` David Ahern
2025-04-22 18:07     ` Willem de Bruijn
2025-04-20 18:04 ` [PATCH net-next 3/3] selftests/net: test tcp connection load balancing Willem de Bruijn
2025-04-23  9:05   ` Ido Schimmel [this message]
2025-04-23 14:18     ` Willem de Bruijn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aAitarcdcgq9x6uL@shredder \
    --to=idosch@idosch.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    --cc=willemdebruijn.kernel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).