diff mbox series

[net-next,v6,5/5] selftests/net: Adding test cases of replacing routes and route advertisements.

Message ID 20240208220653.374773-6-thinker.li@gmail.com (mailing list archive)
State Accepted
Commit 3407df8dc2de07d6b80f28d1a19a5c24a835f69b
Delegated to: Netdev Maintainers
Headers show
Series Remove expired routes with a separated list of routes. | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: shuah@kernel.org linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: line length of 81 exceeds 80 columns
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-10--12-00 (tests: 1262)

Commit Message

Kui-Feng Lee Feb. 8, 2024, 10:06 p.m. UTC
From: Kui-Feng Lee <thinker.li@gmail.com>

Add tests of changing permanent routes to temporary routes and the reversed
case to make sure GC working correctly in these cases.  Add tests for the
temporary routes from RA.

The existing device will be deleted between tests to remove all routes
associated with it, so that the earlier tests don't mess up the later ones.

Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Tested-by: Hangbin Liu <liuhangbin@gmail.com>
Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com>
---
 tools/testing/selftests/net/fib_tests.sh | 151 +++++++++++++++++++----
 1 file changed, 129 insertions(+), 22 deletions(-)

Comments

Jakub Kicinski Feb. 23, 2024, 3:52 a.m. UTC | #1
On Thu,  8 Feb 2024 14:06:53 -0800 thinker.li@gmail.com wrote:
>  	# Permanent routes
> -	for i in $(seq 1 5000); do
> +	for i in $(seq 1 5); do
>  	    $IP -6 route add 2001:30::$i \
>  		via 2001:10::2 dev dummy_10
>  	done
>  	# Temporary routes
> -	for i in $(seq 1 1000); do
> +	for i in $(seq 1 5); do
>  	    # Expire route after $EXPIRE seconds
>  	    $IP -6 route add 2001:20::$i \
>  		via 2001:10::2 dev dummy_10 expires $EXPIRE
>  	done
> -	sleep $(($EXPIRE * 2))
> -	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
> -	if [ $N_EXP_SLEEP -ne 0 ]; then
> -	    echo "FAIL: expected 0 routes with expires," \
> -		 "got $N_EXP_SLEEP (5000 permanent routes)"
> -	    ret=1
> -	else
> -	    ret=0
> +	sleep $(($EXPIRE * 2 + 1))
> +	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
> +	log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"

Looks like fib_tests.sh have gotten flaky since this got merged :(

https://netdev.bots.linux.dev/contest.html?test=fib-tests-sh&executor=vmksft-net&pass=0

# Fib6 garbage collection test
#     TEST: ipv6 route garbage collection                                 [ OK ]
# FAIL: Expected 0 routes, got 1
#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]
https://netdev-3.bots.linux.dev/vmksft-net/results/477081/6-fib-tests-sh/stdout

# Fib6 garbage collection test
#     TEST: ipv6 route garbage collection                                 [ OK ]
# FAIL: Expected 0 routes, got 3
#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]
https://netdev-3.bots.linux.dev/vmksft-net/results/467181/6-fib-tests-sh/stdout

# Fib6 garbage collection test
#     TEST: ipv6 route garbage collection                                 [ OK ]
# FAIL: Expected 0 routes, got 3
#     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
#     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
#     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]
https://netdev-3.bots.linux.dev/vmksft-net/results/466641/18-fib-tests-sh/stdout

Could you take a look?
Kui-Feng Lee Feb. 23, 2024, 4:53 a.m. UTC | #2
On 2/22/24 19:52, Jakub Kicinski wrote:
> On Thu,  8 Feb 2024 14:06:53 -0800 thinker.li@gmail.com wrote:
>>   	# Permanent routes
>> -	for i in $(seq 1 5000); do
>> +	for i in $(seq 1 5); do
>>   	    $IP -6 route add 2001:30::$i \
>>   		via 2001:10::2 dev dummy_10
>>   	done
>>   	# Temporary routes
>> -	for i in $(seq 1 1000); do
>> +	for i in $(seq 1 5); do
>>   	    # Expire route after $EXPIRE seconds
>>   	    $IP -6 route add 2001:20::$i \
>>   		via 2001:10::2 dev dummy_10 expires $EXPIRE
>>   	done
>> -	sleep $(($EXPIRE * 2))
>> -	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
>> -	if [ $N_EXP_SLEEP -ne 0 ]; then
>> -	    echo "FAIL: expected 0 routes with expires," \
>> -		 "got $N_EXP_SLEEP (5000 permanent routes)"
>> -	    ret=1
>> -	else
>> -	    ret=0
>> +	sleep $(($EXPIRE * 2 + 1))
>> +	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
>> +	log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"
> 
> Looks like fib_tests.sh have gotten flaky since this got merged :(

Sure! I am looking into it.

> 
> https://netdev.bots.linux.dev/contest.html?test=fib-tests-sh&executor=vmksft-net&pass=0
> 
> # Fib6 garbage collection test
> #     TEST: ipv6 route garbage collection                                 [ OK ]
> # FAIL: Expected 0 routes, got 1
> #     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
> #     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
> #     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]
> https://netdev-3.bots.linux.dev/vmksft-net/results/477081/6-fib-tests-sh/stdout
> 
> # Fib6 garbage collection test
> #     TEST: ipv6 route garbage collection                                 [ OK ]
> # FAIL: Expected 0 routes, got 3
> #     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
> #     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
> #     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]
> https://netdev-3.bots.linux.dev/vmksft-net/results/467181/6-fib-tests-sh/stdout
> 
> # Fib6 garbage collection test
> #     TEST: ipv6 route garbage collection                                 [ OK ]
> # FAIL: Expected 0 routes, got 3
> #     TEST: ipv6 route garbage collection (with permanent routes)         [FAIL]
> #     TEST: ipv6 route garbage collection (replace with expires)          [ OK ]
> #     TEST: ipv6 route garbage collection (replace with permanent)        [ OK ]
> https://netdev-3.bots.linux.dev/vmksft-net/results/466641/18-fib-tests-sh/stdout
> 
> Could you take a look?
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index b3ecccbbfcd2..3ec1050e47a2 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -743,6 +743,43 @@  fib_notify_test()
 	cleanup &> /dev/null
 }
 
+# Create a new dummy_10 to remove all associated routes.
+reset_dummy_10()
+{
+	$IP link del dev dummy_10
+
+	$IP link add dummy_10 type dummy
+	$IP link set dev dummy_10 up
+	$IP -6 address add 2001:10::1/64 dev dummy_10
+}
+
+check_rt_num()
+{
+    local expected=$1
+    local num=$2
+
+    if [ $num -ne $expected ]; then
+	echo "FAIL: Expected $expected routes, got $num"
+	ret=1
+    else
+	ret=0
+    fi
+}
+
+check_rt_num_clean()
+{
+    local expected=$1
+    local num=$2
+
+    if [ $num -ne $expected ]; then
+	log_test 1 0 "expected $expected routes, got $num"
+	set +e
+	cleanup &> /dev/null
+	return 1
+    fi
+    return 0
+}
+
 fib6_gc_test()
 {
 	setup
@@ -751,7 +788,7 @@  fib6_gc_test()
 	echo "Fib6 garbage collection test"
 	set -e
 
-	EXPIRE=3
+	EXPIRE=5
 
 	# Check expiration of routes every $EXPIRE seconds (GC)
 	$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=$EXPIRE
@@ -763,44 +800,114 @@  fib6_gc_test()
 	$NS_EXEC sysctl -wq net.ipv6.route.flush=1
 
 	# Temporary routes
-	for i in $(seq 1 1000); do
+	for i in $(seq 1 5); do
 	    # Expire route after $EXPIRE seconds
 	    $IP -6 route add 2001:20::$i \
 		via 2001:10::2 dev dummy_10 expires $EXPIRE
 	done
-	sleep $(($EXPIRE * 2))
-	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
-	if [ $N_EXP_SLEEP -ne 0 ]; then
-	    echo "FAIL: expected 0 routes with expires, got $N_EXP_SLEEP"
-	    ret=1
-	else
-	    ret=0
-	fi
+	sleep $(($EXPIRE * 2 + 1))
+	$NS_EXEC sysctl -wq net.ipv6.route.flush=1
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection"
+
+	reset_dummy_10
 
 	# Permanent routes
-	for i in $(seq 1 5000); do
+	for i in $(seq 1 5); do
 	    $IP -6 route add 2001:30::$i \
 		via 2001:10::2 dev dummy_10
 	done
 	# Temporary routes
-	for i in $(seq 1 1000); do
+	for i in $(seq 1 5); do
 	    # Expire route after $EXPIRE seconds
 	    $IP -6 route add 2001:20::$i \
 		via 2001:10::2 dev dummy_10 expires $EXPIRE
 	done
-	sleep $(($EXPIRE * 2))
-	N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
-	if [ $N_EXP_SLEEP -ne 0 ]; then
-	    echo "FAIL: expected 0 routes with expires," \
-		 "got $N_EXP_SLEEP (5000 permanent routes)"
-	    ret=1
-	else
-	    ret=0
+	sleep $(($EXPIRE * 2 + 1))
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"
+
+	reset_dummy_10
+
+	# Permanent routes
+	for i in $(seq 1 5); do
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10
+	done
+	# Replace with temporary routes
+	for i in $(seq 1 5); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done
+	check_rt_num_clean 5 $($IP -6 route list |grep expires|wc -l) || return
+	# Wait for GC
+	sleep $(($EXPIRE * 2 + 1))
+	$NS_EXEC sysctl -wq net.ipv6.route.flush=1
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (replace with expires)"
+
+	reset_dummy_10
+
+	# Temporary routes
+	for i in $(seq 1 5); do
+	    # Expire route after $EXPIRE seconds
+	    $IP -6 route add 2001:20::$i \
+		via 2001:10::2 dev dummy_10 expires $EXPIRE
+	done
+	# Replace with permanent routes
+	for i in $(seq 1 5); do
+	    $IP -6 route replace 2001:20::$i \
+		via 2001:10::2 dev dummy_10
+	done
+	check_rt_num_clean 0 $($IP -6 route list |grep expires|wc -l) || return
+
+	# Wait for GC
+	sleep $(($EXPIRE * 2 + 1))
+
+	check_rt_num 5 $($IP -6 route list |grep -v expires|grep 2001:20::|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (replace with permanent)"
+
+	# ra6 is required for the next test. (ipv6toolkit)
+	if [ ! -x "$(command -v ra6)" ]; then
+	    echo "SKIP: ra6 not found."
+	    set +e
+	    cleanup &> /dev/null
+	    return
 	fi
 
-	set +e
+	# Delete dummy_10 and remove all routes
+	$IP link del dev dummy_10
 
-	log_test $ret 0 "ipv6 route garbage collection"
+	# Create a pair of veth devices to send a RA message from one
+	# device to another.
+	$IP link add veth1 type veth peer name veth2
+	$IP link set dev veth1 up
+	$IP link set dev veth2 up
+	$IP -6 address add 2001:10::1/64 dev veth1 nodad
+	$IP -6 address add 2001:10::2/64 dev veth2 nodad
+
+	# Make veth1 ready to receive RA messages.
+	$NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra=2
+
+	# Send a RA message with a route from veth2 to veth1.
+	$NS_EXEC ra6 -i veth2 -d 2001:10::1 -t $EXPIRE
+
+	# Wait for the RA message.
+	sleep 1
+
+	# systemd may mess up the test.  You syould make sure that
+	# systemd-networkd.service and systemd-networkd.socket are stopped.
+	check_rt_num_clean 1 $($IP -6 route list|grep expires|wc -l) || return
+
+	# Wait for GC
+	sleep $(($EXPIRE * 2 + 1))
+
+	$NS_EXEC sysctl -wq net.ipv6.route.flush=1
+	check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
+	log_test $ret 0 "ipv6 route garbage collection (RA message)"
+
+	set +e
 
 	cleanup &> /dev/null
 }