netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aaron Conole <aconole@redhat.com>
To: Ilya Maximets <i.maximets@ovn.org>
Cc: netdev@vger.kernel.org,  "David S. Miller" <davem@davemloft.net>,
	 Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	 Simon Horman <horms@kernel.org>,
	linux-kernel@vger.kernel.org,  linux-kselftest@vger.kernel.org,
	dev@openvswitch.org,  Eelco Chaudron <echaudro@redhat.com>,
	 Shuah Khan <shuah@kernel.org>,
	 Jamal Hadi Salim <jhs@mojatatu.com>,
	 Davide Caratti <dcaratti@redhat.com>
Subject: Re: [PATCH net 2/2] selftests: openvswitch: add a simple test for tunnel metadata
Date: Tue, 09 Sep 2025 10:58:56 -0400	[thread overview]
Message-ID: <f7tqzwfhdu7.fsf@redhat.com> (raw)
In-Reply-To: <20250905133105.3940420-3-i.maximets@ovn.org> (Ilya Maximets's message of "Fri, 5 Sep 2025 15:30:56 +0200")

Ilya Maximets <i.maximets@ovn.org> writes:

> This test ensures that upon receiving decapsulated packets from a
> tunnel interface in openvswitch, the tunnel metadata fields are
> properly populated.  This partially covers interoperability of the
> kernel tunnel ports and openvswitch tunnels (LWT) and parsing and
> formatting of the tunnel metadata fields of the openvswitch netlink
> uAPI.  Doing so, this test also ensures that fields and flags are
> properly extracted during decapsulation by the tunnel core code,
> serving as a regression test for the previously fixed issue with the
> DF bit not being extracted from the outer IP header.
>
> The ovs-dpctl.py script already supports all that is necessary for
> the tunnel ports for this test, so we only need to adjust the
> ovs_add_if() function to pass the '-t' port type argument in order
> to be able to create tunnel ports in the openvswitch datapath.
>
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---

Thanks for the test case - it looks good to me.  One thing I think would
be a useful future enhancement for us is to add json output so that we
can use something like 'jq' to parse the upcall output.  At the moment,
the grep will work, but doesn't let us change anything.  But that is
work for a future patch.

Reviewed-by: Aaron Conole <aconole@redhat.com>

>  .../selftests/net/openvswitch/openvswitch.sh  | 88 +++++++++++++++++--
>  1 file changed, 81 insertions(+), 7 deletions(-)
>
> diff --git a/tools/testing/selftests/net/openvswitch/openvswitch.sh b/tools/testing/selftests/net/openvswitch/openvswitch.sh
> index 3c8d3455d8e7..b327d3061ed5 100755
> --- a/tools/testing/selftests/net/openvswitch/openvswitch.sh
> +++ b/tools/testing/selftests/net/openvswitch/openvswitch.sh
> @@ -25,6 +25,7 @@ tests="
>  	nat_related_v4				ip4-nat-related: ICMP related matches work with SNAT
>  	netlink_checks				ovsnl: validate netlink attrs and settings
>  	upcall_interfaces			ovs: test the upcall interfaces
> +	tunnel_metadata				ovs: test extraction of tunnel metadata
>  	drop_reason				drop: test drop reasons are emitted
>  	psample					psample: Sampling packets with psample"
>  
> @@ -113,13 +114,13 @@ ovs_add_dp () {
>  }
>  
>  ovs_add_if () {
> -	info "Adding IF to DP: br:$2 if:$3"
> -	if [ "$4" != "-u" ]; then
> -		ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-if "$2" "$3" \
> -		    || return 1
> +	info "Adding IF to DP: br:$3 if:$4 ($2)"
> +	if [ "$5" != "-u" ]; then
> +		ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-if \
> +		    -t "$2" "$3" "$4" || return 1
>  	else
>  		python3 $ovs_base/ovs-dpctl.py add-if \
> -		    -u "$2" "$3" >$ovs_dir/$3.out 2>$ovs_dir/$3.err &
> +		    -u -t "$2" "$3" "$4" >$ovs_dir/$4.out 2>$ovs_dir/$4.err &
>  		pid=$!
>  		on_exit "ovs_sbx $1 kill -TERM $pid 2>/dev/null"
>  	fi
> @@ -166,9 +167,9 @@ ovs_add_netns_and_veths () {
>  	fi
>  
>  	if [ "$7" != "-u" ]; then
> -		ovs_add_if "$1" "$2" "$4" || return 1
> +		ovs_add_if "$1" "netdev" "$2" "$4" || return 1
>  	else
> -		ovs_add_if "$1" "$2" "$4" -u || return 1
> +		ovs_add_if "$1" "netdev" "$2" "$4" -u || return 1
>  	fi
>  
>  	if [ $TRACING -eq 1 ]; then
> @@ -756,6 +757,79 @@ test_upcall_interfaces() {
>  	return 0
>  }
>  
> +ovs_add_kernel_tunnel() {
> +	local sbxname=$1; shift
> +	local ns=$1; shift
> +	local tnl_type=$1; shift
> +	local name=$1; shift
> +	local addr=$1; shift
> +
> +	info "setting up kernel ${tnl_type} tunnel ${name}"
> +	ovs_sbx "${sbxname}" ip -netns ${ns} link add dev ${name} type ${tnl_type} $* || return 1
> +	on_exit "ovs_sbx ${sbxname} ip -netns ${ns} link del ${name} >/dev/null 2>&1"
> +	ovs_sbx "${sbxname}" ip -netns ${ns} addr add dev ${name} ${addr} || return 1
> +	ovs_sbx "${sbxname}" ip -netns ${ns} link set dev ${name} mtu 1450 up || return 1
> +}
> +
> +test_tunnel_metadata() {
> +	which arping >/dev/null 2>&1 || return $ksft_skip
> +
> +	sbxname="test_tunnel_metadata"
> +	sbx_add "${sbxname}" || return 1
> +
> +	info "setting up new DP"
> +	ovs_add_dp "${sbxname}" tdp0 -V 2:1 || return 1
> +
> +	ovs_add_netns_and_veths "${sbxname}" tdp0 tns left0 l0 \
> +		172.31.110.1/24 || return 1
> +
> +	info "removing veth interface from openvswitch and setting IP"
> +	ovs_del_if "${sbxname}" tdp0 left0 || return 1
> +	ovs_sbx "${sbxname}" ip addr add 172.31.110.2/24 dev left0 || return 1
> +	ovs_sbx "${sbxname}" ip link set left0 up || return 1
> +
> +	info "setting up tunnel port in openvswitch"
> +	ovs_add_if "${sbxname}" "vxlan" tdp0 ovs-vxlan0 -u || return 1
> +	on_exit "ovs_sbx ${sbxname} ip link del ovs-vxlan0"
> +	ovs_wait ip link show ovs-vxlan0 &>/dev/null || return 1
> +	ovs_sbx "${sbxname}" ip link set ovs-vxlan0 up || return 1
> +
> +	configs=$(echo '
> +	    1 172.31.221.1/24 1155332 32   set   udpcsum flags\(df\|csum\)
> +	    2 172.31.222.1/24 1234567 45   set noudpcsum flags\(df\)
> +	    3 172.31.223.1/24 1020304 23 unset   udpcsum flags\(csum\)
> +	    4 172.31.224.1/24 1357986 15 unset noudpcsum' | sed '/^$/d')
> +
> +	while read -r i addr id ttl df csum flags; do
> +		ovs_add_kernel_tunnel "${sbxname}" tns vxlan vxlan${i} ${addr} \
> +			remote 172.31.110.2 id ${id} dstport 4789 \
> +			ttl ${ttl} df ${df} ${csum} || return 1
> +	done <<< "${configs}"
> +
> +	ovs_wait grep -q 'listening on upcall packet handler' \
> +		${ovs_dir}/ovs-vxlan0.out || return 1
> +
> +	info "sending arping"
> +	for i in 1 2 3 4; do
> +		ovs_sbx "${sbxname}" ip netns exec tns \
> +			arping -I vxlan${i} 172.31.22${i}.2 -c 1 \
> +			>${ovs_dir}/arping.stdout 2>${ovs_dir}/arping.stderr
> +	done
> +
> +	info "checking that received decapsulated packets carry correct metadata"
> +	while read -r i addr id ttl df csum flags; do
> +		arp_hdr="arp\\(sip=172.31.22${i}.1,tip=172.31.22${i}.2,op=1,sha="
> +		addrs="src=172.31.110.1,dst=172.31.110.2"
> +		ports="tp_src=[0-9]*,tp_dst=4789"
> +		tnl_md="tunnel\\(tun_id=${id},${addrs},ttl=${ttl},${ports},${flags}\\)"
> +
> +		ovs_sbx "${sbxname}" grep -qE "MISS upcall.*${tnl_md}.*${arp_hdr}" \
> +			${ovs_dir}/ovs-vxlan0.out || return 1
> +	done <<< "${configs}"
> +
> +	return 0
> +}
> +
>  run_test() {
>  	(
>  	tname="$1"


      reply	other threads:[~2025-09-09 14:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 13:30 [PATCH net 0/2] net: dst_metadata: fix DF flag extraction on tunnel rx Ilya Maximets
2025-09-05 13:30 ` [PATCH net 1/2] net: dst_metadata: fix IP_DF bit not extracted from tunnel headers Ilya Maximets
2025-09-09  8:41   ` Ido Schimmel
2025-09-09  9:27     ` Ilya Maximets
2025-09-05 13:30 ` [PATCH net 2/2] selftests: openvswitch: add a simple test for tunnel metadata Ilya Maximets
2025-09-09 14:58   ` Aaron Conole [this message]

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=f7tqzwfhdu7.fsf@redhat.com \
    --to=aconole@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dcaratti@redhat.com \
    --cc=dev@openvswitch.org \
    --cc=echaudro@redhat.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=i.maximets@ovn.org \
    --cc=jhs@mojatatu.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /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).