Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3#
4# This test sends many small packets (size is less than cell size) through the
5# switch. A shaper is used in $swp2, so the traffic is limited there. Packets
6# are queued till they will be sent.
7#
8# The idea is to verify that the switch can handle at least 85% of maximum
9# supported descrpitors by hardware. Then, we verify that the driver configures
10# firmware to allow infinite size of egress descriptor pool, and does not use a
11# lower limitation. Increase the size of the relevant pools such that the pool's
12# size does not limit the traffic.
13
14# +-----------------------+
15# | H1 |
16# | + $h1.111 |
17# | | 192.0.2.33/28 |
18# | | |
19# | + $h1 |
20# +---|-------------------+
21# |
22# +---|-----------------------------+
23# | + $swp1 |
24# | | iPOOL1 |
25# | | |
26# | +-|------------------------+ |
27# | | + $swp1.111 | |
28# | | | |
29# | | BR1 | |
30# | | | |
31# | | + $swp2.111 | |
32# | +-|------------------------+ |
33# | | |
34# | + $swp2 |
35# | | ePOOL6 |
36# | | 1mbit |
37# +---+-----------------------------+
38# |
39# +---|-------------------+
40# | + $h2 H2 |
41# | | |
42# | + $h2.111 |
43# | 192.0.2.34/28 |
44# +-----------------------+
45#
46
47ALL_TESTS="
48 ping_ipv4
49 max_descriptors
50"
51
52lib_dir=$(dirname $0)/../../../net/forwarding
53
54NUM_NETIFS=4
55source $lib_dir/lib.sh
56source $lib_dir/devlink_lib.sh
57source mlxsw_lib.sh
58
59MAX_POOL_SIZE=$(devlink_pool_size_get)
60SHAPER_RATE=1mbit
61
62# The current TBF qdisc interface does not allow us to configure the shaper to
63# flat zero. The ASIC shaper is guaranteed to work with a granularity of
64# 200Mbps. On Spectrum-2, writing a value close to zero instead of zero works
65# well, but the performance on Spectrum-1 is unpredictable. Thus, do not run the
66# test on Spectrum-1.
67mlxsw_only_on_spectrum 2+ || exit
68
69h1_create()
70{
71 adf_simple_if_init $h1
72
73 vlan_create $h1 111 v$h1 192.0.2.33/28
74 defer vlan_destroy $h1 111
75 ip link set dev $h1.111 type vlan egress-qos-map 0:1
76}
77
78h2_create()
79{
80 adf_simple_if_init $h2
81
82 vlan_create $h2 111 v$h2 192.0.2.34/28
83 defer vlan_destroy $h2 111
84}
85
86switch_create()
87{
88 # pools
89 # -----
90 # devlink_pool_size_thtype_restore needs to be done first so that we can
91 # reset the various limits to values that are only valid for the
92 # original static / dynamic setting.
93
94 devlink_pool_size_thtype_save 1
95 devlink_pool_size_thtype_set 1 dynamic $MAX_POOL_SIZE
96 defer_prio devlink_pool_size_thtype_restore 1
97
98 devlink_pool_size_thtype_save 6
99 devlink_pool_size_thtype_set 6 static $MAX_POOL_SIZE
100 defer_prio devlink_pool_size_thtype_restore 6
101
102 # $swp1
103 # -----
104
105 ip link set dev $swp1 up
106 defer ip link set dev $swp1 down
107
108 vlan_create $swp1 111
109 defer vlan_destroy $swp1 111
110 ip link set dev $swp1.111 type vlan ingress-qos-map 0:0 1:1
111
112 devlink_port_pool_th_save $swp1 1
113 devlink_port_pool_th_set $swp1 1 16
114 defer devlink_tc_bind_pool_th_restore $swp1 1 ingress
115
116 devlink_tc_bind_pool_th_save $swp1 1 ingress
117 devlink_tc_bind_pool_th_set $swp1 1 ingress 1 16
118 defer devlink_port_pool_th_restore $swp1 1
119
120 tc qdisc replace dev $swp1 root handle 1: \
121 ets bands 8 strict 8 priomap 7 6
122 defer tc qdisc del dev $swp1 root
123
124 dcb buffer set dev $swp1 prio-buffer all:0 1:1
125 defer dcb buffer set dev $swp1 prio-buffer all:0
126
127 # $swp2
128 # -----
129
130 ip link set dev $swp2 up
131 defer ip link set dev $swp2 down
132
133 vlan_create $swp2 111
134 defer vlan_destroy $swp2 111
135 ip link set dev $swp2.111 type vlan egress-qos-map 0:0 1:1
136
137 devlink_port_pool_th_save $swp2 6
138 devlink_port_pool_th_set $swp2 6 $MAX_POOL_SIZE
139 defer devlink_tc_bind_pool_th_restore $swp2 1 egress
140
141 devlink_tc_bind_pool_th_save $swp2 1 egress
142 devlink_tc_bind_pool_th_set $swp2 1 egress 6 $MAX_POOL_SIZE
143 defer devlink_port_pool_th_restore $swp2 6
144
145 tc qdisc replace dev $swp2 root handle 1: tbf rate $SHAPER_RATE \
146 burst 128K limit 500M
147 defer tc qdisc del dev $swp2 root
148
149 tc qdisc replace dev $swp2 parent 1:1 handle 11: \
150 ets bands 8 strict 8 priomap 7 6
151 defer tc qdisc del dev $swp2 parent 1:1 handle 11:
152
153 # bridge
154 # ------
155
156 ip link add name br1 type bridge vlan_filtering 0
157 defer ip link del dev br1
158
159 ip link set dev $swp1.111 master br1
160 defer ip link set dev $swp1.111 nomaster
161
162 ip link set dev br1 up
163 defer ip link set dev br1 down
164
165 ip link set dev $swp2.111 master br1
166 defer ip link set dev $swp2.111 nomaster
167}
168
169setup_prepare()
170{
171 h1=${NETIFS[p1]}
172 swp1=${NETIFS[p2]}
173
174 swp2=${NETIFS[p3]}
175 h2=${NETIFS[p4]}
176
177 h2mac=$(mac_get $h2)
178
179 adf_vrf_prepare
180
181 h1_create
182 h2_create
183 switch_create
184}
185
186ping_ipv4()
187{
188 ping_test $h1 192.0.2.34 " h1->h2"
189}
190
191percentage_used()
192{
193 local num_packets=$1; shift
194 local max_packets=$1; shift
195
196 bc <<< "
197 scale=2
198 100 * $num_packets / $max_packets
199 "
200}
201
202max_descriptors()
203{
204 local cell_size=$(devlink_cell_size_get)
205 local exp_perc_used=85
206 local max_descriptors
207 local pktsize=30
208
209 RET=0
210
211 max_descriptors=$(mlxsw_max_descriptors_get) || exit 1
212
213 local d0=$(ethtool_stats_get $swp2 tc_no_buffer_discard_uc_tc_1)
214
215 log_info "Send many small packets, packet size = $pktsize bytes"
216 start_traffic_pktsize $pktsize $h1.111 192.0.2.33 192.0.2.34 $h2mac
217 defer stop_traffic $!
218
219 # Sleep to wait for congestion.
220 sleep 5
221
222 local d1=$(ethtool_stats_get $swp2 tc_no_buffer_discard_uc_tc_1)
223 ((d1 == d0))
224 check_err $? "Drops seen on egress port: $d0 -> $d1 ($((d1 - d0)))"
225
226 # Check how many packets the switch can handle, the limitation is
227 # maximum descriptors.
228 local pkts_bytes=$(ethtool_stats_get $swp2 tc_transmit_queue_tc_1)
229 local pkts_num=$((pkts_bytes / cell_size))
230 local perc_used=$(percentage_used $pkts_num $max_descriptors)
231
232 check_err $(bc <<< "$perc_used < $exp_perc_used") \
233 "Expected > $exp_perc_used% of descriptors, handle $perc_used%"
234
235 log_test "Maximum descriptors usage. The percentage used is $perc_used%"
236}
237
238trap cleanup EXIT
239setup_prepare
240setup_wait
241tests_run
242
243exit $EXIT_STATUS