Skip to content

Commit a22b042

Browse files
pmachatakuba-moo
authored andcommitted
selftests: forwarding: Add a test for NH group stats
Add to lib.sh support for fetching NH stats, and a new library, router_mpath_nh_lib.sh, with the common code for testing NH stats. Use the latter from router_mpath_nh.sh and router_mpath_nh_res.sh. The test works by sending traffic through a NH group, and checking that the reported values correspond to what the link that ultimately receives the traffic reports having seen. Signed-off-by: Petr Machata <[email protected]> Link: https://lore.kernel.org/r/2a424c54062a5f1efd13b9ec5b2b0e29c6af2574.1709901020.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 44c2fbe commit a22b042

File tree

5 files changed

+190
-0
lines changed

5 files changed

+190
-0
lines changed

tools/testing/selftests/net/forwarding/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ TEST_FILES := devlink_lib.sh \
123123
mirror_gre_topo_lib.sh \
124124
mirror_lib.sh \
125125
mirror_topo_lib.sh \
126+
router_mpath_nh_lib.sh \
126127
sch_ets_core.sh \
127128
sch_ets_tests.sh \
128129
sch_tbf_core.sh \

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,33 @@ hw_stats_get()
900900
jq ".[0].stats64.$dir.$stat"
901901
}
902902

903+
__nh_stats_get()
904+
{
905+
local key=$1; shift
906+
local group_id=$1; shift
907+
local member_id=$1; shift
908+
909+
ip -j -s -s nexthop show id $group_id |
910+
jq --argjson member_id "$member_id" --arg key "$key" \
911+
'.[].group_stats[] | select(.id == $member_id) | .[$key]'
912+
}
913+
914+
nh_stats_get()
915+
{
916+
local group_id=$1; shift
917+
local member_id=$1; shift
918+
919+
__nh_stats_get packets "$group_id" "$member_id"
920+
}
921+
922+
nh_stats_get_hw()
923+
{
924+
local group_id=$1; shift
925+
local member_id=$1; shift
926+
927+
__nh_stats_get packets_hw "$group_id" "$member_id"
928+
}
929+
903930
humanize()
904931
{
905932
local speed=$1; shift
@@ -2010,3 +2037,10 @@ bail_on_lldpad()
20102037
fi
20112038
fi
20122039
}
2040+
2041+
absval()
2042+
{
2043+
local v=$1; shift
2044+
2045+
echo $((v > 0 ? v : -v))
2046+
}

tools/testing/selftests/net/forwarding/router_mpath_nh.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ ALL_TESTS="
77
multipath_test
88
ping_ipv4_blackhole
99
ping_ipv6_blackhole
10+
nh_stats_test_v4
11+
nh_stats_test_v6
1012
"
1113
NUM_NETIFS=8
1214
source lib.sh
15+
source router_mpath_nh_lib.sh
1316

1417
h1_create()
1518
{
@@ -325,6 +328,16 @@ ping_ipv6_blackhole()
325328
ip -6 nexthop del id 1001
326329
}
327330

331+
nh_stats_test_v4()
332+
{
333+
__nh_stats_test_v4 mpath
334+
}
335+
336+
nh_stats_test_v6()
337+
{
338+
__nh_stats_test_v6 mpath
339+
}
340+
328341
setup_prepare()
329342
{
330343
h1=${NETIFS[p1]}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
nh_stats_do_test()
4+
{
5+
local what=$1; shift
6+
local nh1_id=$1; shift
7+
local nh2_id=$1; shift
8+
local group_id=$1; shift
9+
local stats_get=$1; shift
10+
local mz="$@"
11+
12+
local dp
13+
14+
RET=0
15+
16+
sleep 2
17+
for ((dp=0; dp < 60000; dp += 10000)); do
18+
local dd
19+
local t0_rp12=$(link_stats_tx_packets_get $rp12)
20+
local t0_rp13=$(link_stats_tx_packets_get $rp13)
21+
local t0_nh1=$($stats_get $group_id $nh1_id)
22+
local t0_nh2=$($stats_get $group_id $nh2_id)
23+
24+
ip vrf exec vrf-h1 \
25+
$mz -q -p 64 -d 0 -t udp \
26+
"sp=1024,dp=$((dp))-$((dp + 10000))"
27+
sleep 2
28+
29+
local t1_rp12=$(link_stats_tx_packets_get $rp12)
30+
local t1_rp13=$(link_stats_tx_packets_get $rp13)
31+
local t1_nh1=$($stats_get $group_id $nh1_id)
32+
local t1_nh2=$($stats_get $group_id $nh2_id)
33+
34+
local d_rp12=$((t1_rp12 - t0_rp12))
35+
local d_rp13=$((t1_rp13 - t0_rp13))
36+
local d_nh1=$((t1_nh1 - t0_nh1))
37+
local d_nh2=$((t1_nh2 - t0_nh2))
38+
39+
dd=$(absval $((d_rp12 - d_nh1)))
40+
((dd < 10))
41+
check_err $? "Discrepancy between link and $stats_get: d_rp12=$d_rp12 d_nh1=$d_nh1"
42+
43+
dd=$(absval $((d_rp13 - d_nh2)))
44+
((dd < 10))
45+
check_err $? "Discrepancy between link and $stats_get: d_rp13=$d_rp13 d_nh2=$d_nh2"
46+
done
47+
48+
log_test "NH stats test $what"
49+
}
50+
51+
nh_stats_test_dispatch_swhw()
52+
{
53+
local what=$1; shift
54+
local nh1_id=$1; shift
55+
local nh2_id=$1; shift
56+
local group_id=$1; shift
57+
local mz="$@"
58+
59+
local used
60+
61+
nh_stats_do_test "$what" "$nh1_id" "$nh2_id" "$group_id" \
62+
nh_stats_get "${mz[@]}"
63+
64+
used=$(ip -s -j -d nexthop show id $group_id |
65+
jq '.[].hw_stats.used')
66+
kind=$(ip -j -d link show dev $rp11 |
67+
jq -r '.[].linkinfo.info_kind')
68+
if [[ $used == true ]]; then
69+
nh_stats_do_test "HW $what" "$nh1_id" "$nh2_id" "$group_id" \
70+
nh_stats_get_hw "${mz[@]}"
71+
elif [[ $kind == veth ]]; then
72+
log_test_skip "HW stats not offloaded on veth topology"
73+
fi
74+
}
75+
76+
nh_stats_test_dispatch()
77+
{
78+
local nhgtype=$1; shift
79+
local what=$1; shift
80+
local nh1_id=$1; shift
81+
local nh2_id=$1; shift
82+
local group_id=$1; shift
83+
local mz="$@"
84+
85+
local enabled
86+
local kind
87+
88+
if ! ip nexthop help 2>&1 | grep -q hw_stats; then
89+
log_test_skip "NH stats test: ip doesn't support HW stats"
90+
return
91+
fi
92+
93+
ip nexthop replace id $group_id group $nh1_id/$nh2_id \
94+
hw_stats on type $nhgtype
95+
enabled=$(ip -s -j -d nexthop show id $group_id |
96+
jq '.[].hw_stats.enabled')
97+
if [[ $enabled == true ]]; then
98+
nh_stats_test_dispatch_swhw "$what" "$nh1_id" "$nh2_id" \
99+
"$group_id" "${mz[@]}"
100+
elif [[ $enabled == false ]]; then
101+
check_err 1 "HW stats still disabled after enabling"
102+
log_test "NH stats test"
103+
else
104+
log_test_skip "NH stats test: ip doesn't report hw_stats info"
105+
fi
106+
107+
ip nexthop replace id $group_id group $nh1_id/$nh2_id \
108+
hw_stats off type $nhgtype
109+
}
110+
111+
__nh_stats_test_v4()
112+
{
113+
local nhgtype=$1; shift
114+
115+
sysctl_set net.ipv4.fib_multipath_hash_policy 1
116+
nh_stats_test_dispatch $nhgtype "IPv4" 101 102 103 \
117+
$MZ $h1 -A 192.0.2.2 -B 198.51.100.2
118+
sysctl_restore net.ipv4.fib_multipath_hash_policy
119+
}
120+
121+
__nh_stats_test_v6()
122+
{
123+
local nhgtype=$1; shift
124+
125+
sysctl_set net.ipv6.fib_multipath_hash_policy 1
126+
nh_stats_test_dispatch $nhgtype "IPv6" 104 105 106 \
127+
$MZ -6 $h1 -A 2001:db8:1::2 -B 2001:db8:2::2
128+
sysctl_restore net.ipv6.fib_multipath_hash_policy
129+
}

tools/testing/selftests/net/forwarding/router_mpath_nh_res.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ ALL_TESTS="
55
ping_ipv4
66
ping_ipv6
77
multipath_test
8+
nh_stats_test_v4
9+
nh_stats_test_v6
810
"
911
NUM_NETIFS=8
1012
source lib.sh
13+
source router_mpath_nh_lib.sh
1114

1215
h1_create()
1316
{
@@ -333,6 +336,16 @@ multipath_test()
333336
ip nexthop replace id 106 group 104,1/105,1 type resilient
334337
}
335338

339+
nh_stats_test_v4()
340+
{
341+
__nh_stats_test_v4 resilient
342+
}
343+
344+
nh_stats_test_v6()
345+
{
346+
__nh_stats_test_v6 resilient
347+
}
348+
336349
setup_prepare()
337350
{
338351
h1=${NETIFS[p1]}

0 commit comments

Comments
 (0)