Skip to content

Commit be00853

Browse files
pmachatadavem330
authored andcommitted
selftests: mlxsw: Add a RIF counter scale test
This tests creates as many RIFs as possible, ideally more than there can be RIF counters (though that is currently only possible on Spectrum-1). It then tries to enable L3 HW stats on each of the RIFs. It also contains the traffic test, which tries to run traffic through a log2 of those counters and checks that the traffic is shown in the counter values. Like with tc_flower traffic test, take a log2 subset of rules. The logic behind picking log2 rules is that then every bit of the instantiated item's number is exercised. This should catch issues whether they happen at the high end, low end, or somewhere in between. Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Amit Cohen <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent dd5d20e commit be00853

File tree

5 files changed

+162
-2
lines changed

5 files changed

+162
-2
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
RIF_COUNTER_NUM_NETIFS=2
4+
5+
rif_counter_addr4()
6+
{
7+
local i=$1; shift
8+
local p=$1; shift
9+
10+
printf 192.0.%d.%d $((i / 64)) $(((4 * i % 256) + p))
11+
}
12+
13+
rif_counter_addr4pfx()
14+
{
15+
rif_counter_addr4 $@
16+
printf /30
17+
}
18+
19+
rif_counter_h1_create()
20+
{
21+
simple_if_init $h1
22+
}
23+
24+
rif_counter_h1_destroy()
25+
{
26+
simple_if_fini $h1
27+
}
28+
29+
rif_counter_h2_create()
30+
{
31+
simple_if_init $h2
32+
}
33+
34+
rif_counter_h2_destroy()
35+
{
36+
simple_if_fini $h2
37+
}
38+
39+
rif_counter_setup_prepare()
40+
{
41+
h1=${NETIFS[p1]}
42+
h2=${NETIFS[p2]}
43+
44+
vrf_prepare
45+
46+
rif_counter_h1_create
47+
rif_counter_h2_create
48+
}
49+
50+
rif_counter_cleanup()
51+
{
52+
local count=$1; shift
53+
54+
pre_cleanup
55+
56+
for ((i = 1; i <= count; i++)); do
57+
vlan_destroy $h2 $i
58+
done
59+
60+
rif_counter_h2_destroy
61+
rif_counter_h1_destroy
62+
63+
vrf_cleanup
64+
65+
if [[ -v RIF_COUNTER_BATCH_FILE ]]; then
66+
rm -f $RIF_COUNTER_BATCH_FILE
67+
fi
68+
}
69+
70+
71+
rif_counter_test()
72+
{
73+
local count=$1; shift
74+
local should_fail=$1; shift
75+
76+
RIF_COUNTER_BATCH_FILE="$(mktemp)"
77+
78+
for ((i = 1; i <= count; i++)); do
79+
vlan_create $h2 $i v$h2 $(rif_counter_addr4pfx $i 2)
80+
done
81+
for ((i = 1; i <= count; i++)); do
82+
cat >> $RIF_COUNTER_BATCH_FILE <<-EOF
83+
stats set dev $h2.$i l3_stats on
84+
EOF
85+
done
86+
87+
ip -b $RIF_COUNTER_BATCH_FILE
88+
check_err_fail $should_fail $? "RIF counter enablement"
89+
}
90+
91+
rif_counter_traffic_test()
92+
{
93+
local count=$1; shift
94+
local i;
95+
96+
for ((i = count; i > 0; i /= 2)); do
97+
$MZ $h1 -Q $i -c 1 -d 20msec -p 100 -a own -b $(mac_get $h2) \
98+
-A $(rif_counter_addr4 $i 1) \
99+
-B $(rif_counter_addr4 $i 2) \
100+
-q -t udp sp=54321,dp=12345
101+
done
102+
for ((i = count; i > 0; i /= 2)); do
103+
busywait "$TC_HIT_TIMEOUT" until_counter_is "== 1" \
104+
hw_stats_get l3_stats $h2.$i rx packets > /dev/null
105+
check_err $? "Traffic not seen at RIF $h2.$i"
106+
done
107+
}

tools/testing/selftests/drivers/net/mlxsw/spectrum-2/resource_scale.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ cleanup()
2525

2626
trap cleanup EXIT
2727

28-
ALL_TESTS="router tc_flower mirror_gre tc_police port rif_mac_profile"
28+
ALL_TESTS="
29+
router
30+
tc_flower
31+
mirror_gre
32+
tc_police
33+
port
34+
rif_mac_profile
35+
rif_counter
36+
"
37+
2938
for current_test in ${TESTS:-$ALL_TESTS}; do
3039
RET_FIN=0
3140
source ${current_test}_scale.sh
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../spectrum/rif_counter_scale.sh

tools/testing/selftests/drivers/net/mlxsw/spectrum/resource_scale.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ cleanup()
2222
devlink_sp_read_kvd_defaults
2323
trap cleanup EXIT
2424

25-
ALL_TESTS="router tc_flower mirror_gre tc_police port rif_mac_profile"
25+
ALL_TESTS="
26+
router
27+
tc_flower
28+
mirror_gre
29+
tc_police
30+
port
31+
rif_mac_profile
32+
rif_counter
33+
"
34+
2635
for current_test in ${TESTS:-$ALL_TESTS}; do
2736
RET_FIN=0
2837
source ${current_test}_scale.sh
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
source ../rif_counter_scale.sh
3+
4+
rif_counter_get_target()
5+
{
6+
local should_fail=$1; shift
7+
local max_cnts
8+
local max_rifs
9+
local target
10+
11+
max_rifs=$(devlink_resource_size_get rifs)
12+
max_cnts=$(devlink_resource_size_get counters rif)
13+
14+
# Remove already allocated RIFs.
15+
((max_rifs -= $(devlink_resource_occ_get rifs)))
16+
17+
# 10 KVD slots per counter, ingress+egress counters per RIF
18+
((max_cnts /= 20))
19+
20+
# Pointless to run the overflow test if we don't have enough RIFs to
21+
# host all the counters.
22+
if ((max_cnts > max_rifs && should_fail)); then
23+
echo 0
24+
return
25+
fi
26+
27+
target=$((max_rifs < max_cnts ? max_rifs : max_cnts))
28+
29+
if ((! should_fail)); then
30+
echo $target
31+
else
32+
echo $((target + 1))
33+
fi
34+
}

0 commit comments

Comments
 (0)