netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, dsahern@gmail.com, jiri@mellanox.com,
	jakub.kicinski@netronome.com, saeedm@mellanox.com,
	mlxsw@mellanox.com, Ido Schimmel <idosch@mellanox.com>
Subject: [RFC PATCH net-next 15/15] selftests: netdevsim: Add test for route offload API
Date: Wed,  2 Oct 2019 11:41:03 +0300	[thread overview]
Message-ID: <20191002084103.12138-16-idosch@idosch.org> (raw)
In-Reply-To: <20191002084103.12138-1-idosch@idosch.org>

From: Ido Schimmel <idosch@mellanox.com>

Test various aspects of the route offload API on top of the netdevsim
implementation. Both good and error flows are tested.

Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 .../drivers/net/netdevsim/fib_notifier.sh     | 411 ++++++++++++++++++
 1 file changed, 411 insertions(+)
 create mode 100755 tools/testing/selftests/drivers/net/netdevsim/fib_notifier.sh

diff --git a/tools/testing/selftests/drivers/net/netdevsim/fib_notifier.sh b/tools/testing/selftests/drivers/net/netdevsim/fib_notifier.sh
new file mode 100755
index 000000000000..27b0752df67f
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/netdevsim/fib_notifier.sh
@@ -0,0 +1,411 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+#
+# This test is for checking the FIB notification API. It makes use of netdevsim
+# which registers a listener to the FIB notification chain.
+
+lib_dir=$(dirname $0)/../../../net/forwarding
+
+ALL_TESTS="
+	ipv4_identical_routes
+	ipv4_tos
+	ipv4_metric
+	ipv4_replace
+	ipv4_delete
+	ipv4_plen
+	ipv4_replay
+	ipv4_error_path
+	ipv4_flush
+"
+NETDEVSIM_PATH=/sys/bus/netdevsim/
+DEV_ADDR=1337
+DEV=netdevsim${DEV_ADDR}
+DEVLINK_DEV=netdevsim/${DEV}
+NUM_NETIFS=0
+source $lib_dir/lib.sh
+source $lib_dir/devlink_lib.sh
+
+route_in_hw_check()
+{
+	local route=$1; shift
+
+	ip -n testns1 route show $route | grep -q "in_hw"
+}
+
+ipv4_identical_routes()
+{
+	local i
+
+	RET=0
+
+	for i in $(seq 1 3); do
+		ip -n testns1 link add name dummy$i type dummy
+		ip -n testns1 link set dev dummy$i up
+	done
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 tos 0 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 0 metric 1024"
+	check_err $? "Route not in hardware when should"
+
+	ip -n testns1 route append 192.0.2.0/24 dev dummy2 tos 0 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy2 tos 0 metric 1024"
+	check_fail $? "Appended route in hardware when should not"
+
+	ip -n testns1 route prepend 192.0.2.0/24 dev dummy3 tos 0 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy3 tos 0 metric 1024"
+	check_err $? "Prepended route not in hardware when should"
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 0 metric 1024"
+	check_fail $? "Route was not replaced in hardware by prepended one"
+
+	log_test "IPv4 identical routes"
+
+	for i in $(seq 1 3); do
+		ip -n testns1 link del dev dummy$i
+	done
+}
+
+ipv4_tos()
+{
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 tos 0 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 0 metric 1024"
+	check_err $? "Route not in hardware when should"
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 tos 2 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 2 metric 1024"
+	check_err $? "Highest TOS route not in hardware when should"
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 0 metric 1024"
+	check_fail $? "Lowest TOS route still in hardware when should not"
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 tos 1 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 1 metric 1024"
+	check_fail $? "Middle TOS route in hardware when should not"
+
+	log_test "IPv4 routes with TOS"
+
+	ip -n testns1 link del dev dummy1
+}
+
+ipv4_metric()
+{
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1024"
+	check_err $? "Route not in hardware when should"
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric 1022
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1022"
+	check_err $? "Lowest metric route not in hardware when should"
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1024"
+	check_fail $? "Highest metric route still in hardware when should not"
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric 1023
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 1 metric 1023"
+	check_fail $? "Middle metric route in hardware when should not"
+
+	log_test "IPv4 routes with metric"
+
+	ip -n testns1 link del dev dummy1
+}
+
+ipv4_replace()
+{
+	local i
+
+	RET=0
+
+	for i in $(seq 1 2); do
+		ip -n testns1 link add name dummy$i type dummy
+		ip -n testns1 link set dev dummy$i up
+	done
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1024"
+	check_err $? "Route not in hardware when should"
+
+	ip -n testns1 route replace 192.0.2.0/24 dev dummy2 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy2 metric 1024"
+	check_err $? "Replacement route not in hardware when should"
+
+	# Add a route with an higher metric and make sure that replacing it
+	# does not affect the lower metric one.
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric 1025
+	ip -n testns1 route replace 192.0.2.0/24 dev dummy2 metric 1025
+
+	route_in_hw_check "192.0.2.0/24 dev dummy2 metric 1024"
+	check_err $? "Lowest metric route not in hardware when should"
+	route_in_hw_check "192.0.2.0/24 dev dummy2 metric 1025"
+	check_fail $? "Highest metric route in hardware when should not"
+
+	log_test "IPv4 route replace"
+
+	for i in $(seq 1 2); do
+		ip -n testns1 link del dev dummy$i
+	done
+}
+
+ipv4_delete()
+{
+	local metric
+
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	# Insert multiple routes with the same prefix and length and varying
+	# metrics. Make sure that throughout delete operations the lowest
+	# metric route is the one in hardware.
+	for metric in $(seq 1024 1026); do
+		ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric $metric
+	done
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1024"
+	check_err $? "Route not in hardware when should"
+
+	ip -n testns1 route del 192.0.2.0/24 dev dummy1 metric 1024
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1025"
+	check_err $? "Lowest metric route not in hardware when should"
+
+	ip -n testns1 route del 192.0.2.0/24 dev dummy1 metric 1026
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1025"
+	check_err $? "Sole route not in hardware when should"
+
+	log_test "IPv4 route delete"
+
+	ip -n testns1 link del dev dummy1
+}
+
+ipv4_plen()
+{
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	# Add two routes with the same key and different prefix length and
+	# make sure both are in hardware. It can be verfied that both are
+	# sharing the same leaf by checking the /proc/net/fib_trie
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1
+	ip -n testns1 route add 192.0.2.0/25 dev dummy1
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1"
+	check_err $? "/24 not in hardware when should"
+
+	route_in_hw_check "192.0.2.0/25 dev dummy1"
+	check_err $? "/25 not in hardware when should"
+
+	log_test "IPv4 routes with different prefix length"
+
+	ip -n testns1 link del dev dummy1
+}
+
+ipv4_replay_metric()
+{
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric 1024
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric 1025
+
+	devlink -N testns1 dev reload $DEVLINK_DEV
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1024"
+	check_err $? "Lowest metric route not in hardware when should"
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1 metric 1025"
+	check_fail $? "Highest metric route in hardware when should not"
+
+	log_test "IPv4 routes replay - metric"
+
+	ip -n testns1 link del dev dummy1
+}
+
+ipv4_replay_tos()
+{
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 tos 0
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1 tos 1
+
+	devlink -N testns1 dev reload $DEVLINK_DEV
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 1"
+	check_err $? "Highest TOS route not in hardware when should"
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1 tos 0"
+	check_fail $? "Lowest TOS route in hardware when should not"
+
+	log_test "IPv4 routes replay - TOS"
+
+	ip -n testns1 link del dev dummy1
+}
+
+ipv4_replay_plen()
+{
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	ip -n testns1 route add 192.0.2.0/24 dev dummy1
+	ip -n testns1 route add 192.0.2.0/25 dev dummy1
+
+	devlink -N testns1 dev reload $DEVLINK_DEV
+
+	route_in_hw_check "192.0.2.0/24 dev dummy1"
+	check_err $? "/24 not in hardware when should"
+
+	route_in_hw_check "192.0.2.0/25 dev dummy1"
+	check_err $? "/25 not in hardware when should"
+
+	log_test "IPv4 routes replay - prefix length"
+
+	ip -n testns1 link del dev dummy1
+}
+
+ipv4_replay()
+{
+	# Install multiple routes with the same prefix and length and make sure
+	# that after reload only the routes that should be in hardware are
+	# replayed.
+	ipv4_replay_metric
+	ipv4_replay_tos
+	ipv4_replay_plen
+}
+
+ipv4_error_path_add()
+{
+	local lsb
+
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	devlink -N testns1 resource set $DEVLINK_DEV path IPv4/fib size 10
+	devlink -N testns1 dev reload $DEVLINK_DEV
+
+	for lsb in $(seq 1 20); do
+		ip -n testns1 route add 192.0.2.${lsb}/32 dev dummy1 \
+			&> /dev/null
+	done
+
+	log_test "IPv4 error path - add"
+
+	ip -n testns1 link del dev dummy1
+}
+
+ipv4_error_path_replay()
+{
+	local lsb
+
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	devlink -N testns1 resource set $DEVLINK_DEV path IPv4/fib size 100
+	devlink -N testns1 dev reload $DEVLINK_DEV
+
+	for lsb in $(seq 1 20); do
+		ip -n testns1 route add 192.0.2.${lsb}/32 dev dummy1
+	done
+
+	devlink -N testns1 resource set $DEVLINK_DEV path IPv4/fib size 10
+	devlink -N testns1 dev reload $DEVLINK_DEV &> /dev/null
+
+	log_test "IPv4 error path - replay"
+
+	ip -n testns1 link del dev dummy1
+
+	# Successfully reload after deleting all the routes.
+	devlink -N testns1 resource set $DEVLINK_DEV path IPv4/fib size 100
+	devlink -N testns1 dev reload $DEVLINK_DEV
+}
+
+ipv4_error_path()
+{
+	# Test the different error paths of the notifiers by limiting the size
+	# of the "IPv4/fib" resource.
+	ipv4_error_path_add
+	ipv4_error_path_replay
+}
+
+ipv4_flush()
+{
+	local metric
+
+	RET=0
+
+	ip -n testns1 link add name dummy1 type dummy
+	ip -n testns1 link set dev dummy1 up
+
+	# Exercise the routes flushing code paths by inserting various
+	# prefix routes on a netdev and then deleting it.
+	for metric in $(seq 1 20); do
+		ip -n testns1 route add 192.0.2.0/24 dev dummy1 metric $metric
+	done
+
+	ip -n testns1 link del dev dummy1
+
+	log_test "IPv4 routes flushing"
+}
+
+setup_prepare()
+{
+	local netdev
+
+	modprobe netdevsim &> /dev/null
+
+	echo "$DEV_ADDR 0" > ${NETDEVSIM_PATH}/new_device
+
+	if [ ! -d "${NETDEVSIM_PATH}/devices/${DEV}" ]; then
+		echo "Failed to create netdevsim device"
+		exit 1
+	fi
+
+	ip netns add testns1
+	if [ $? -ne 0 ]; then
+		echo "Failed to add netns \"testns1\""
+		exit 1
+	fi
+
+	devlink dev reload $DEVLINK_DEV netns testns1
+	if [ $? -ne 0 ]; then
+		echo "Failed to reload into netns \"testns1\""
+		exit 1
+	fi
+}
+
+cleanup()
+{
+	pre_cleanup
+	ip netns del testns1
+	echo "$DEV_ADDR" > ${NETDEVSIM_PATH}/del_device
+	modprobe -r netdevsim &> /dev/null
+}
+
+trap cleanup EXIT
+
+setup_prepare
+
+tests_run
+
+exit $EXIT_STATUS
-- 
2.21.0


  parent reply	other threads:[~2019-10-02  8:42 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-02  8:40 [RFC PATCH net-next 00/15] Simplify IPv4 route offload API Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 01/15] ipv4: Add temporary events to the FIB notification chain Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 02/15] ipv4: Notify route after insertion to the routing table Ido Schimmel
2019-10-03  1:34   ` David Ahern
2019-10-03  5:16     ` Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 03/15] ipv4: Notify route if replacing currently offloaded one Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 04/15] ipv4: Notify newly added route if should be offloaded Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 05/15] ipv4: Handle route deletion notification Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 06/15] ipv4: Handle route deletion notification during flush Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 07/15] ipv4: Only Replay routes of interest to new listeners Ido Schimmel
2019-10-02 17:44   ` Jiri Pirko
2019-10-03 13:04     ` Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 08/15] mlxsw: spectrum_router: Start using new IPv4 route notifications Ido Schimmel
2019-10-02 17:52   ` Jiri Pirko
2019-10-02 18:01     ` Jiri Pirko
2019-10-03 15:10       ` Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 09/15] ipv4: Remove old route notifications and convert listeners Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 10/15] ipv4: Replace route in list before notifying Ido Schimmel
2019-10-02  8:40 ` [RFC PATCH net-next 11/15] ipv4: Encapsulate function arguments in a struct Ido Schimmel
2019-10-02  8:41 ` [RFC PATCH net-next 12/15] ipv4: Add "in hardware" indication to routes Ido Schimmel
2019-10-02 15:58   ` Roopa Prabhu
2019-10-02 18:21     ` Jiri Pirko
2019-10-03  2:34       ` David Ahern
2019-10-03  5:37         ` Ido Schimmel
2019-10-04  1:55           ` David Ahern
2019-10-04 14:43             ` Ido Schimmel
2019-10-04 16:38               ` David Ahern
2019-10-04 17:43                 ` Roopa Prabhu
2019-10-04 23:20                   ` David Ahern
2019-10-03  5:40         ` Jiri Pirko
2019-10-03 12:59     ` Ido Schimmel
2019-10-04  4:25       ` Roopa Prabhu
2019-10-02  8:41 ` [RFC PATCH net-next 13/15] mlxsw: spectrum_router: Mark routes as "in hardware" Ido Schimmel
2019-10-02 18:27   ` Jiri Pirko
2019-10-03 15:16     ` Ido Schimmel
2019-10-02  8:41 ` [RFC PATCH net-next 14/15] netdevsim: fib: " Ido Schimmel
2019-10-02  8:41 ` Ido Schimmel [this message]
2019-10-02 18:17 ` [RFC PATCH net-next 00/15] Simplify IPv4 route offload API Jiri Pirko
2019-10-03  5:18   ` Ido Schimmel

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=20191002084103.12138-16-idosch@idosch.org \
    --to=idosch@idosch.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=idosch@mellanox.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=jiri@mellanox.com \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.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).