All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: David Wei <dw@davidwei.uk>
Cc: Jiri Pirko <jiri@resnulli.us>,
	Sabrina Dubroca <sd@queasysnail.net>,
	netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>
Subject: Re: [PATCH net-next v2 3/3] netdevsim: add selftest for forwarding skb between connected ports
Date: Tue, 12 Dec 2023 12:29:35 -0800	[thread overview]
Message-ID: <20231212122935.4e23dd08@kernel.org> (raw)
In-Reply-To: <20231210010448.816126-4-dw@davidwei.uk>

On Sat,  9 Dec 2023 17:04:48 -0800 David Wei wrote:
> From: David Wei <davidhwei@meta.com>
> 
> Connect two netdevsim ports in different namespaces together, then send
> packets between them using socat.
> 
> Signed-off-by: David Wei <dw@davidwei.uk>
> ---
>  .../selftests/drivers/net/netdevsim/peer.sh   | 111 ++++++++++++++++++
>  1 file changed, 111 insertions(+)
>  create mode 100755 tools/testing/selftests/drivers/net/netdevsim/peer.sh

You need to include this script in the Makefile so it gets run

> diff --git a/tools/testing/selftests/drivers/net/netdevsim/peer.sh b/tools/testing/selftests/drivers/net/netdevsim/peer.sh
> new file mode 100755
> index 000000000000..d1d59a932174
> --- /dev/null
> +++ b/tools/testing/selftests/drivers/net/netdevsim/peer.sh
> @@ -0,0 +1,111 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +NSIM_DEV_SYS=/sys/bus/netdevsim
> +NSIM_DEV_DFS=/sys/kernel/debug/netdevsim/netdevsim
> +
> +socat_check()
> +{
> +	if [ ! -x "$(command -v socat)" ]; then
> +		echo "socat command not found. Skipping test"
> +		return 1
> +	fi
> +
> +	return 0
> +}
> +
> +setup_ns()
> +{
> +	set -e
> +	ip netns add nssv
> +	ip netns add nscl
> +
> +	ip link set eni1np1 netns nssv
> +	ip link set eni2np1 netns nscl

This assumes you have systemd renaming interfaces.
I can find out what the netdev is called from sysfs.
After you create the nsim device in its sysfs dir
there will be a dir "net" and in it you'll have
a subdir with the same name as the netdev.

> +	ip netns exec nssv ip addr add '192.168.1.1/24' dev eni1np1
> +	ip netns exec nscl ip addr add '192.168.1.2/24' dev eni2np1
> +
> +	ip netns exec nssv ip link set dev eni1np1 up
> +	ip netns exec nscl ip link set dev eni2np1 up
> +	set +e
> +}
> +
> +cleanup_ns()
> +{
> +	ip netns del nscl
> +	ip netns del nssv
> +}
> +
> +###
> +### Code start
> +###
> +
> +modprobe netdevsim
> +
> +# linking
> +
> +echo 1 > ${NSIM_DEV_SYS}/new_device

Use $RANDOM to generate a random device ID.

> +echo "2 0" > ${NSIM_DEV_DFS}1/ports/0/peer 2>/dev/null
> +if [ $? -eq 0 ]; then
> +	echo "linking with non-existent netdevsim should fail"
> +	exit 1
> +fi
> +
> +echo 2 > /sys/bus/netdevsim/new_device
> +
> +echo "2 0" > ${NSIM_DEV_DFS}1/ports/0/peer
> +if [ $? -ne 0 ]; then
> +	echo "linking netdevsim1 port0 with netdevsim2 port0 should succeed"
> +	exit 1
> +fi
> +
> +# argument error checking
> +
> +echo "2 1" > ${NSIM_DEV_DFS}1/ports/0/peer 2>/dev/null
> +if [ $? -eq 0 ]; then
> +	echo "linking with non-existent port in a netdevsim should fail"
> +	exit 1
> +fi
> +
> +echo "1 0" > ${NSIM_DEV_DFS}1/ports/0/peer 2>/dev/null
> +if [ $? -eq 0 ]; then
> +	echo "linking with self should fail"
> +	exit 1
> +fi
> +
> +echo "2 a" > ${NSIM_DEV_DFS}1/ports/0/peer 2>/dev/null
> +if [ $? -eq 0 ]; then
> +	echo "invalid arg should fail"
> +	exit 1
> +fi
> +
> +# send/recv packets
> +
> +socat_check || exit 1

There's a magic return value for skipping kselftests, 1 means fail.
-- 
pw-bot: cr

  reply	other threads:[~2023-12-12 20:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-10  1:04 [PATCH net-next v2 0/3] netdevsim: link and forward skbs between ports David Wei
2023-12-10  1:04 ` [PATCH net-next v2 1/3] netdevsim: allow two netdevsim ports to be connected David Wei
2023-12-12 20:24   ` Jakub Kicinski
2023-12-13  0:37     ` David Wei
2023-12-10  1:04 ` [PATCH net-next v2 2/3] netdevsim: forward skbs from one connected port to another David Wei
2023-12-10  1:04 ` [PATCH net-next v2 3/3] netdevsim: add selftest for forwarding skb between connected ports David Wei
2023-12-12 20:29   ` Jakub Kicinski [this message]
2023-12-13  0:38     ` David Wei

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=20231212122935.4e23dd08@kernel.org \
    --to=kuba@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dw@davidwei.uk \
    --cc=edumazet@google.com \
    --cc=jiri@resnulli.us \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.