Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / router_mpath_nh_lib.sh
blob507b2852dabeaf04aa0654e061cff426c5754288
1 # SPDX-License-Identifier: GPL-2.0
3 nh_stats_do_test()
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="$@"
12 local dp
14 RET=0
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)
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
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)
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))
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"
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
48 log_test "NH stats test $what"
51 nh_stats_test_dispatch_swhw()
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="$@"
59 nh_stats_do_test "$what" "$nh1_id" "$nh2_id" "$group_id" \
60 nh_stats_get "${mz[@]}"
62 xfail_on_veth $rp11 \
63 nh_stats_do_test "HW $what" "$nh1_id" "$nh2_id" "$group_id" \
64 nh_stats_get_hw "${mz[@]}"
67 nh_stats_test_dispatch()
69 local nhgtype=$1; shift
70 local what=$1; shift
71 local nh1_id=$1; shift
72 local nh2_id=$1; shift
73 local group_id=$1; shift
74 local mz="$@"
76 local enabled
78 if ! ip nexthop help 2>&1 | grep -q hw_stats; then
79 log_test_skip "NH stats test: ip doesn't support HW stats"
80 return
83 ip nexthop replace id $group_id group $nh1_id/$nh2_id \
84 hw_stats on type $nhgtype
85 enabled=$(ip -s -j -d nexthop show id $group_id |
86 jq '.[].hw_stats.enabled')
87 if [[ $enabled == true ]]; then
88 nh_stats_test_dispatch_swhw "$what" "$nh1_id" "$nh2_id" \
89 "$group_id" "${mz[@]}"
90 elif [[ $enabled == false ]]; then
91 check_err 1 "HW stats still disabled after enabling"
92 log_test "NH stats test"
93 else
94 log_test_skip "NH stats test: ip doesn't report hw_stats info"
97 ip nexthop replace id $group_id group $nh1_id/$nh2_id \
98 hw_stats off type $nhgtype
101 __nh_stats_test_v4()
103 local nhgtype=$1; shift
105 sysctl_set net.ipv4.fib_multipath_hash_policy 1
106 nh_stats_test_dispatch $nhgtype "IPv4" 101 102 103 \
107 $MZ $h1 -A 192.0.2.2 -B 198.51.100.2
108 sysctl_restore net.ipv4.fib_multipath_hash_policy
111 __nh_stats_test_v6()
113 local nhgtype=$1; shift
115 sysctl_set net.ipv6.fib_multipath_hash_policy 1
116 nh_stats_test_dispatch $nhgtype "IPv6" 104 105 106 \
117 $MZ -6 $h1 -A 2001:db8:1::2 -B 2001:db8:2::2
118 sysctl_restore net.ipv6.fib_multipath_hash_policy
121 check_nhgw16()
123 local nhid=$1; shift
125 ip nexthop replace id 9999 group "$nhid,65535" &>/dev/null
126 if (( $? )); then
127 log_test_skip "16-bit multipath tests" \
128 "iproute2 or the kernel do not support 16-bit next hop weights"
129 return 1
131 ip nexthop del id 9999 ||: