selftests: netdevsim: Test route offload failure notifications
authorAmit Cohen <amcohen@nvidia.com>
Sun, 7 Feb 2021 08:22:58 +0000 (10:22 +0200)
committerDavid S. Miller <davem@davemloft.net>
Tue, 9 Feb 2021 00:47:03 +0000 (16:47 -0800)
Add cases to verify that when debugfs variable "fail_route_offload" is
set, notification with "rt_offload_failed" flag is received.

Extend the existing cases to verify that when sysctl
"fib_notify_on_flag_change" is set to 2, the kernel emits notifications
only for failed route installation.

$ ./fib_notifications.sh
TEST: IPv4 route addition [ OK ]
TEST: IPv4 route deletion [ OK ]
TEST: IPv4 route replacement [ OK ]
TEST: IPv4 route offload failed [ OK ]
TEST: IPv6 route addition [ OK ]
TEST: IPv6 route deletion [ OK ]
TEST: IPv6 route replacement [ OK ]
TEST: IPv6 route offload failed [ OK ]

Signed-off-by: Amit Cohen <amcohen@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh

index 16a9dd4..8d91191 100755 (executable)
@@ -7,9 +7,11 @@ ALL_TESTS="
        ipv4_route_addition_test
        ipv4_route_deletion_test
        ipv4_route_replacement_test
+       ipv4_route_offload_failed_test
        ipv6_route_addition_test
        ipv6_route_deletion_test
        ipv6_route_replacement_test
+       ipv6_route_offload_failed_test
 "
 
 NETDEVSIM_PATH=/sys/bus/netdevsim/
@@ -17,9 +19,26 @@ DEV_ADDR=1337
 DEV=netdevsim${DEV_ADDR}
 DEVLINK_DEV=netdevsim/${DEV}
 SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV/net/
+DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV/
 NUM_NETIFS=0
 source $lib_dir/lib.sh
 
+check_rt_offload_failed()
+{
+       local outfile=$1; shift
+       local line
+
+       # Make sure that the first notification was emitted without
+       # RTM_F_OFFLOAD_FAILED flag and the second with RTM_F_OFFLOAD_FAILED
+       # flag
+       head -n 1 $outfile | grep -q "rt_offload_failed"
+       if [[ $? -eq 0 ]]; then
+               return 1
+       fi
+
+       head -n 2 $outfile | tail -n 1 | grep -q "rt_offload_failed"
+}
+
 check_rt_trap()
 {
        local outfile=$1; shift
@@ -39,15 +58,23 @@ route_notify_check()
 {
        local outfile=$1; shift
        local expected_num_lines=$1; shift
+       local offload_failed=${1:-0}; shift
 
        # check the monitor results
        lines=`wc -l $outfile | cut "-d " -f1`
        test $lines -eq $expected_num_lines
        check_err $? "$expected_num_lines notifications were expected but $lines were received"
 
-       if [[ $expected_num_lines -eq 2 ]]; then
+       if [[ $expected_num_lines -eq 1 ]]; then
+               return
+       fi
+
+       if [[ $offload_failed -eq 0 ]]; then
                check_rt_trap $outfile
                check_err $? "Wrong RTM_F_TRAP flags in notifications"
+       else
+               check_rt_offload_failed $outfile
+               check_err $? "Wrong RTM_F_OFFLOAD_FAILED flags in notifications"
        fi
 }
 
@@ -57,6 +84,7 @@ route_addition_check()
        local notify=$1; shift
        local route=$1; shift
        local expected_num_notifications=$1; shift
+       local offload_failed=${1:-0}; shift
 
        ip netns exec testns1 sysctl -qw net.$ip.fib_notify_on_flag_change=$notify
 
@@ -68,7 +96,7 @@ route_addition_check()
        sleep 1
        kill %% && wait %% &> /dev/null
 
-       route_notify_check $outfile $expected_num_notifications
+       route_notify_check $outfile $expected_num_notifications $offload_failed
        rm -f $outfile
 
        $IP route del $route dev dummy1
@@ -93,6 +121,13 @@ ipv4_route_addition_test()
        expected_num_notifications=2
        route_addition_check $ip $notify $route $expected_num_notifications
 
+       # notify=2 means emit notifications only for failed route installation,
+       # make sure a single notification will be emitted for the programmed
+       # route.
+       notify=2
+       expected_num_notifications=1
+       route_addition_check $ip $notify $route $expected_num_notifications
+
        log_test "IPv4 route addition"
 }
 
@@ -185,11 +220,55 @@ ipv4_route_replacement_test()
        expected_num_notifications=2
        route_replacement_check $ip $notify $route $expected_num_notifications
 
+       # notify=2 means emit notifications only for failed route installation,
+       # make sure a single notification will be emitted for the new route.
+       notify=2
+       expected_num_notifications=1
+       route_replacement_check $ip $notify $route $expected_num_notifications
+
        $IP link del name dummy2
 
        log_test "IPv4 route replacement"
 }
 
+ipv4_route_offload_failed_test()
+{
+
+       RET=0
+
+       local ip="ipv4"
+       local route=192.0.2.0/24
+       local offload_failed=1
+
+       echo "y"> $DEBUGFS_DIR/fib/fail_route_offload
+       check_err $? "Failed to setup route offload to fail"
+
+       # Make sure a single notification will be emitted for the programmed
+       # route.
+       local notify=0
+       local expected_num_notifications=1
+       route_addition_check $ip $notify $route $expected_num_notifications \
+               $offload_failed
+
+       # Make sure two notifications will be emitted for the new route.
+       notify=1
+       expected_num_notifications=2
+       route_addition_check $ip $notify $route $expected_num_notifications \
+               $offload_failed
+
+       # notify=2 means emit notifications only for failed route installation,
+       # make sure two notifications will be emitted for the new route.
+       notify=2
+       expected_num_notifications=2
+       route_addition_check $ip $notify $route $expected_num_notifications \
+               $offload_failed
+
+       echo "n"> $DEBUGFS_DIR/fib/fail_route_offload
+       check_err $? "Failed to setup route offload not to fail"
+
+       log_test "IPv4 route offload failed"
+}
+
 ipv6_route_addition_test()
 {
        RET=0
@@ -208,6 +287,13 @@ ipv6_route_addition_test()
        expected_num_notifications=2
        route_addition_check $ip $notify $route $expected_num_notifications
 
+       # notify=2 means emit notifications only for failed route installation,
+       # make sure a single notification will be emitted for the programmed
+       # route.
+       notify=2
+       expected_num_notifications=1
+       route_addition_check $ip $notify $route $expected_num_notifications
+
        log_test "IPv6 route addition"
 }
 
@@ -250,11 +336,55 @@ ipv6_route_replacement_test()
        expected_num_notifications=2
        route_replacement_check $ip $notify $route $expected_num_notifications
 
+       # notify=2 means emit notifications only for failed route installation,
+       # make sure a single notification will be emitted for the new route.
+       notify=2
+       expected_num_notifications=1
+       route_replacement_check $ip $notify $route $expected_num_notifications
+
        $IP link del name dummy2
 
        log_test "IPv6 route replacement"
 }
 
+ipv6_route_offload_failed_test()
+{
+
+       RET=0
+
+       local ip="ipv6"
+       local route=2001:db8:1::/64
+       local offload_failed=1
+
+       echo "y"> $DEBUGFS_DIR/fib/fail_route_offload
+       check_err $? "Failed to setup route offload to fail"
+
+       # Make sure a single notification will be emitted for the programmed
+       # route.
+       local notify=0
+       local expected_num_notifications=1
+       route_addition_check $ip $notify $route $expected_num_notifications \
+               $offload_failed
+
+       # Make sure two notifications will be emitted for the new route.
+       notify=1
+       expected_num_notifications=2
+       route_addition_check $ip $notify $route $expected_num_notifications \
+               $offload_failed
+
+       # notify=2 means emit notifications only for failed route installation,
+       # make sure two notifications will be emitted for the new route.
+       notify=2
+       expected_num_notifications=2
+       route_addition_check $ip $notify $route $expected_num_notifications \
+               $offload_failed
+
+       echo "n"> $DEBUGFS_DIR/fib/fail_route_offload
+       check_err $? "Failed to setup route offload not to fail"
+
+       log_test "IPv6 route offload failed"
+}
+
 setup_prepare()
 {
        modprobe netdevsim &> /dev/null