Skip to content

Commit e0f34c7

Browse files
committed
selftests: forwarding: Add a test for NH group stats
JIRA: https://issues.redhat.com/browse/RHEL-59118 commit a22b042 Author: Petr Machata <petrm@nvidia.com> Date: Fri Mar 8 13:59:55 2024 +0100 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 <petrm@nvidia.com> Link: https://lore.kernel.org/r/2a424c54062a5f1efd13b9ec5b2b0e29c6af2574.1709901020.git.petrm@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent fe8ebf9 commit e0f34c7

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
@@ -121,6 +121,7 @@ TEST_FILES := devlink_lib.sh \
121121
mirror_gre_topo_lib.sh \
122122
mirror_lib.sh \
123123
mirror_topo_lib.sh \
124+
router_mpath_nh_lib.sh \
124125
sch_ets_core.sh \
125126
sch_ets_tests.sh \
126127
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
@@ -855,6 +855,33 @@ hw_stats_get()
855855
jq ".[0].stats64.$dir.$stat"
856856
}
857857

858+
__nh_stats_get()
859+
{
860+
local key=$1; shift
861+
local group_id=$1; shift
862+
local member_id=$1; shift
863+
864+
ip -j -s -s nexthop show id $group_id |
865+
jq --argjson member_id "$member_id" --arg key "$key" \
866+
'.[].group_stats[] | select(.id == $member_id) | .[$key]'
867+
}
868+
869+
nh_stats_get()
870+
{
871+
local group_id=$1; shift
872+
local member_id=$1; shift
873+
874+
__nh_stats_get packets "$group_id" "$member_id"
875+
}
876+
877+
nh_stats_get_hw()
878+
{
879+
local group_id=$1; shift
880+
local member_id=$1; shift
881+
882+
__nh_stats_get packets_hw "$group_id" "$member_id"
883+
}
884+
858885
humanize()
859886
{
860887
local speed=$1; shift
@@ -1965,3 +1992,10 @@ bail_on_lldpad()
19651992
fi
19661993
fi
19671994
}
1995+
1996+
absval()
1997+
{
1998+
local v=$1; shift
1999+
2000+
echo $((v > 0 ? v : -v))
2001+
}

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
{
@@ -358,6 +361,16 @@ ping_ipv6_blackhole()
358361
ip -6 nexthop del id 1001
359362
}
360363

364+
nh_stats_test_v4()
365+
{
366+
__nh_stats_test_v4 mpath
367+
}
368+
369+
nh_stats_test_v6()
370+
{
371+
__nh_stats_test_v6 mpath
372+
}
373+
361374
setup_prepare()
362375
{
363376
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)