[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240131064041.3445212-6-thinker.li@gmail.com>
Date: Tue, 30 Jan 2024 22:40:41 -0800
From: thinker.li@...il.com
To: netdev@...r.kernel.org,
ast@...nel.org,
martin.lau@...ux.dev,
kernel-team@...a.com,
davem@...emloft.net,
dsahern@...nel.org,
edumazet@...gle.com,
kuba@...nel.org,
pabeni@...hat.com,
liuhangbin@...il.com
Cc: sinquersw@...il.com,
kuifeng@...a.com,
Kui-Feng Lee <thinker.li@...il.com>
Subject: [PATCH net-next 5/5] selftests/net: Adding test cases of replacing routes and route advertisements.
From: Kui-Feng Lee <thinker.li@...il.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.
Signed-off-by: Kui-Feng Lee <thinker.li@...il.com>
---
tools/testing/selftests/net/fib_tests.sh | 159 +++++++++++++++++++++--
1 file changed, 148 insertions(+), 11 deletions(-)
diff --git a/tools/testing/selftests/net/fib_tests.sh b/tools/testing/selftests/net/fib_tests.sh
index b3ecccbbfcd2..f69b55304ebb 100755
--- a/tools/testing/selftests/net/fib_tests.sh
+++ b/tools/testing/selftests/net/fib_tests.sh
@@ -743,6 +743,16 @@ 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
+}
+
fib6_gc_test()
{
setup
@@ -768,15 +778,19 @@ fib6_gc_test()
$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"
+ sleep $(($EXPIRE * 2 + 1))
+ N_EXP=$($IP -6 route list |grep expires|wc -l)
+ if [ $N_EXP -ne 0 ]; then
+ echo "FAIL: expected 0 routes with expires, got $N_EXP"
ret=1
else
ret=0
fi
+ log_test $ret 0 "ipv6 route garbage collection"
+
+ reset_dummy_10
+
# Permanent routes
for i in $(seq 1 5000); do
$IP -6 route add 2001:30::$i \
@@ -788,19 +802,142 @@ fib6_gc_test()
$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)"
+ sleep $(($EXPIRE * 2 + 1))
+ N_EXP=$($IP -6 route list |grep expires|wc -l)
+ if [ $N_EXP -ne 0 ]; then
+ echo "FAIL: expected 0 routes with expires, got $N_EXP"
ret=1
else
ret=0
fi
- set +e
+ log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"
- log_test $ret 0 "ipv6 route garbage collection"
+ reset_dummy_10
+
+ # Permanent routes
+ for i in $(seq 1 100); 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 100); do
+ # Expire route after $EXPIRE seconds
+ $IP -6 route replace 2001:20::$i \
+ via 2001:10::2 dev dummy_10 expires $EXPIRE
+ done
+ N_EXP=$($IP -6 route list |grep expires|wc -l)
+ if [ $N_EXP -ne 100 ]; then
+ log_test 1 0 "expected 100 routes with expires, got $N_EXP"
+ set +e
+ cleanup &> /dev/null
+ return
+ fi
+ # Wait for GC
+ sleep $(($EXPIRE * 2 + 1))
+ N_EXP=$($IP -6 route list |grep expires|wc -l)
+ if [ $N_EXP -ne 0 ]; then
+ echo "FAIL: expected 0 routes with expires, got $N_EXP"
+ ret=1
+ else
+ ret=0
+ fi
+
+ log_test $ret 0 "ipv6 route garbage collection (replace with expires)"
+
+ reset_dummy_10
+
+ # Temporary routes
+ for i in $(seq 1 100); 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 100); do
+ $IP -6 route replace 2001:20::$i \
+ via 2001:10::2 dev dummy_10
+ done
+ N_EXP=$($IP -6 route list |grep expires|wc -l)
+ if [ $N_EXP -ne 0 ]; then
+ log_test 1 0 "expected 0 routes with expires, got $N_EXP"
+ set +e
+ cleanup &> /dev/null
+ return
+ fi
+
+ # Wait for GC
+ sleep $(($EXPIRE * 2 + 1))
+
+ N_PERM=$($IP -6 route list |grep -v expires|grep 2001:20::|wc -l)
+ if [ $N_PERM -ne 100 ]; then
+ echo "FAIL: expected 100 permanent routes, got $N_PERM"
+ ret=1
+ else
+ ret=0
+ fi
+
+ 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
+
+ # Delete dummy_10 and remove all routes
+ $IP link del dev dummy_10
+
+ # 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
+
+ # Without stopping these two services, systemd may mess up the test
+ # by intercepting the RA message and adding routes.
+ if [ -x "$(command -v systemctl)" ]; then
+ systemctl stop systemd-networkd.socket
+ systemctl stop systemd-networkd.service
+ fi
+ # Make veth1 ready to receive RA messages.
+ $NS_EXEC sysctl -w net.ipv6.conf.veth1.accept_ra=2 &> /dev/null
+ $NS_EXEC sysctl -w net.ipv6.conf.veth1.accept_ra_rt_info_max_plen=127 &> /dev/null
+
+ # Send a RA message with a route from veth2 to veth1.
+ $NS_EXEC ra6 -i veth2 -d 2001:10::1 -R "2003:10::/64#1#$EXPIRE" -t $EXPIRE
+
+ # Wait for the RA message.
+ sleep 1
+
+ # There are 2 routes with expires. One is a default route and the
+ # other is the route to 2003:10::/64.
+ N_EXP=$($IP -6 route list |grep expires|wc -l)
+ if [ $N_EXP -ne 2 ]; then
+ log_test 1 0 "expected 2 routes with expires, got $N_EXP"
+ set +e
+ cleanup &> /dev/null
+ return
+ fi
+
+ # Wait for GC
+ sleep $(($EXPIRE * 2 + 1))
+
+ N_EXP=$($IP -6 route list |grep expires|wc -l)
+ if [ $N_EXP -ne 0 ]; then
+ echo "FAIL: expected 0 routes with expires, got $N_EXP"
+ ret=1
+ else
+ ret=0
+ fi
+
+ log_test $ret 0 "ipv6 route garbage collection (RA message)"
+
+ set +e
cleanup &> /dev/null
}
--
2.34.1
Powered by blists - more mailing lists