Skip to content

Commit a63e10d

Browse files
ThinkerYzu1davem330
authored andcommitted
selftests: fib_tests: Add a test case for IPv6 garbage collection
Add 1000 IPv6 routes with expiration time (w/ and w/o additional 5000 permanet routes in the background.) Wait for a few seconds to make sure they are removed correctly. The expected output of the test looks like the following example. > Fib6 garbage collection test > TEST: ipv6 route garbage collection [ OK ] Signed-off-by: Kui-Feng Lee <thinker.li@gmail.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3dec89b commit a63e10d

1 file changed

Lines changed: 69 additions & 3 deletions

File tree

tools/testing/selftests/net/fib_tests.sh

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ ret=0
99
ksft_skip=4
1010

1111
# all tests in this script. Can be overridden with -t option
12-
TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh"
12+
TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
13+
ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics \
14+
ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr \
15+
ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test"
1316

1417
VERBOSE=0
1518
PAUSE_ON_FAIL=no
1619
PAUSE=no
17-
IP="ip -netns ns1"
18-
NS_EXEC="ip netns exec ns1"
20+
IP="$(which ip) -netns ns1"
21+
NS_EXEC="$(which ip) netns exec ns1"
1922

2023
which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
2124

@@ -747,6 +750,68 @@ fib_notify_test()
747750
cleanup &> /dev/null
748751
}
749752

753+
fib6_gc_test()
754+
{
755+
setup
756+
757+
echo
758+
echo "Fib6 garbage collection test"
759+
set -e
760+
761+
EXPIRE=3
762+
763+
# Check expiration of routes every $EXPIRE seconds (GC)
764+
$NS_EXEC sysctl -wq net.ipv6.route.gc_interval=$EXPIRE
765+
766+
$IP link add dummy_10 type dummy
767+
$IP link set dev dummy_10 up
768+
$IP -6 address add 2001:10::1/64 dev dummy_10
769+
770+
$NS_EXEC sysctl -wq net.ipv6.route.flush=1
771+
772+
# Temporary routes
773+
for i in $(seq 1 1000); do
774+
# Expire route after $EXPIRE seconds
775+
$IP -6 route add 2001:20::$i \
776+
via 2001:10::2 dev dummy_10 expires $EXPIRE
777+
done
778+
sleep $(($EXPIRE * 2))
779+
N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
780+
if [ $N_EXP_SLEEP -ne 0 ]; then
781+
echo "FAIL: expected 0 routes with expires, got $N_EXP_SLEEP"
782+
ret=1
783+
else
784+
ret=0
785+
fi
786+
787+
# Permanent routes
788+
for i in $(seq 1 5000); do
789+
$IP -6 route add 2001:30::$i \
790+
via 2001:10::2 dev dummy_10
791+
done
792+
# Temporary routes
793+
for i in $(seq 1 1000); do
794+
# Expire route after $EXPIRE seconds
795+
$IP -6 route add 2001:20::$i \
796+
via 2001:10::2 dev dummy_10 expires $EXPIRE
797+
done
798+
sleep $(($EXPIRE * 2))
799+
N_EXP_SLEEP=$($IP -6 route list |grep expires|wc -l)
800+
if [ $N_EXP_SLEEP -ne 0 ]; then
801+
echo "FAIL: expected 0 routes with expires," \
802+
"got $N_EXP_SLEEP (5000 permanent routes)"
803+
ret=1
804+
else
805+
ret=0
806+
fi
807+
808+
set +e
809+
810+
log_test $ret 0 "ipv6 route garbage collection"
811+
812+
cleanup &> /dev/null
813+
}
814+
750815
fib_suppress_test()
751816
{
752817
echo
@@ -2217,6 +2282,7 @@ do
22172282
ipv4_mangle) ipv4_mangle_test;;
22182283
ipv6_mangle) ipv6_mangle_test;;
22192284
ipv4_bcast_neigh) ipv4_bcast_neigh_test;;
2285+
fib6_gc_test|ipv6_gc) fib6_gc_test;;
22202286

22212287
help) echo "Test names: $TESTS"; exit 0;;
22222288
esac

0 commit comments

Comments
 (0)