Skip to content

Commit

Permalink
selftests: netdevsim: Test route offload failure notifications
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Amit Cohen authored and David S. Miller committed Feb 9, 2021
1 parent a4cb1c0 commit 9ee53e3
Showing 1 changed file with 132 additions and 2 deletions.
134 changes: 132 additions & 2 deletions tools/testing/selftests/drivers/net/netdevsim/fib_notifications.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,38 @@ 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/
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
Expand All @@ -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
}

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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"
}

Expand Down Expand Up @@ -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
Expand All @@ -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"
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9ee53e3

Please sign in to comment.