~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/drivers/net/mlxsw/devlink_trap_policer.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 #
  4 # Test devlink-trap policer functionality over mlxsw.
  5 
  6 # +---------------------------------+
  7 # | H1 (vrf)                        |
  8 # |    + $h1                        |
  9 # |    | 192.0.2.1/24               |
 10 # |    |                            |
 11 # |    |  default via 192.0.2.2     |
 12 # +----|----------------------------+
 13 #      |
 14 # +----|----------------------------------------------------------------------+
 15 # | SW |                                                                      |
 16 # |    + $rp1                                                                 |
 17 # |        192.0.2.2/24                                                       |
 18 # |                                                                           |
 19 # |        198.51.100.2/24                                                    |
 20 # |    + $rp2                                                                 |
 21 # |    |                                                                      |
 22 # +----|----------------------------------------------------------------------+
 23 #      |
 24 # +----|----------------------------+
 25 # |    |  default via 198.51.100.2  |
 26 # |    |                            |
 27 # |    | 198.51.100.1/24            |
 28 # |    + $h2                        |
 29 # | H2 (vrf)                        |
 30 # +---------------------------------+
 31 
 32 lib_dir=$(dirname $0)/../../../net/forwarding
 33 
 34 ALL_TESTS="
 35         rate_limits_test
 36         burst_limits_test
 37         rate_test
 38         burst_test
 39 "
 40 NUM_NETIFS=4
 41 source $lib_dir/tc_common.sh
 42 source $lib_dir/lib.sh
 43 source $lib_dir/devlink_lib.sh
 44 
 45 h1_create()
 46 {
 47         simple_if_init $h1 192.0.2.1/24
 48         mtu_set $h1 10000
 49 
 50         ip -4 route add default vrf v$h1 nexthop via 192.0.2.2
 51 }
 52 
 53 h1_destroy()
 54 {
 55         ip -4 route del default vrf v$h1 nexthop via 192.0.2.2
 56 
 57         mtu_restore $h1
 58         simple_if_fini $h1 192.0.2.1/24
 59 }
 60 
 61 h2_create()
 62 {
 63         simple_if_init $h2 198.51.100.1/24
 64         mtu_set $h2 10000
 65 
 66         ip -4 route add default vrf v$h2 nexthop via 198.51.100.2
 67 }
 68 
 69 h2_destroy()
 70 {
 71         ip -4 route del default vrf v$h2 nexthop via 198.51.100.2
 72 
 73         mtu_restore $h2
 74         simple_if_fini $h2 198.51.100.1/24
 75 }
 76 
 77 router_create()
 78 {
 79         ip link set dev $rp1 up
 80         ip link set dev $rp2 up
 81 
 82         __addr_add_del $rp1 add 192.0.2.2/24
 83         __addr_add_del $rp2 add 198.51.100.2/24
 84         mtu_set $rp1 10000
 85         mtu_set $rp2 10000
 86 
 87         ip -4 route add blackhole 198.51.100.100
 88 
 89         devlink trap set $DEVLINK_DEV trap blackhole_route action trap
 90 }
 91 
 92 router_destroy()
 93 {
 94         devlink trap set $DEVLINK_DEV trap blackhole_route action drop
 95 
 96         ip -4 route del blackhole 198.51.100.100
 97 
 98         mtu_restore $rp2
 99         mtu_restore $rp1
100         __addr_add_del $rp2 del 198.51.100.2/24
101         __addr_add_del $rp1 del 192.0.2.2/24
102 
103         ip link set dev $rp2 down
104         ip link set dev $rp1 down
105 }
106 
107 setup_prepare()
108 {
109         h1=${NETIFS[p1]}
110         rp1=${NETIFS[p2]}
111 
112         rp2=${NETIFS[p3]}
113         h2=${NETIFS[p4]}
114 
115         rp1_mac=$(mac_get $rp1)
116 
117         vrf_prepare
118 
119         h1_create
120         h2_create
121 
122         router_create
123 }
124 
125 cleanup()
126 {
127         pre_cleanup
128 
129         router_destroy
130 
131         h2_destroy
132         h1_destroy
133 
134         vrf_cleanup
135 
136         # Reload to ensure devlink-trap settings are back to default.
137         devlink_reload
138 }
139 
140 rate_limits_test()
141 {
142         RET=0
143 
144         devlink trap policer set $DEVLINK_DEV policer 1 rate 0 &> /dev/null
145         check_fail $? "Policer rate was changed to rate lower than limit"
146         devlink trap policer set $DEVLINK_DEV policer 1 \
147                 rate 2000000001 &> /dev/null
148         check_fail $? "Policer rate was changed to rate higher than limit"
149 
150         devlink trap policer set $DEVLINK_DEV policer 1 rate 1
151         check_err $? "Failed to set policer rate to minimum"
152         devlink trap policer set $DEVLINK_DEV policer 1 rate 2000000000
153         check_err $? "Failed to set policer rate to maximum"
154 
155         log_test "Trap policer rate limits"
156 }
157 
158 burst_limits_test()
159 {
160         RET=0
161 
162         devlink trap policer set $DEVLINK_DEV policer 1 burst 0 &> /dev/null
163         check_fail $? "Policer burst size was changed to 0"
164         devlink trap policer set $DEVLINK_DEV policer 1 burst 17 &> /dev/null
165         check_fail $? "Policer burst size was changed to burst size that is not power of 2"
166         devlink trap policer set $DEVLINK_DEV policer 1 burst 8 &> /dev/null
167         check_fail $? "Policer burst size was changed to burst size lower than limit"
168         devlink trap policer set $DEVLINK_DEV policer 1 \
169                 burst $((2**25)) &> /dev/null
170         check_fail $? "Policer burst size was changed to burst size higher than limit"
171 
172         devlink trap policer set $DEVLINK_DEV policer 1 burst 16
173         check_err $? "Failed to set policer burst size to minimum"
174         devlink trap policer set $DEVLINK_DEV policer 1 burst $((2**24))
175         check_err $? "Failed to set policer burst size to maximum"
176 
177         log_test "Trap policer burst size limits"
178 }
179 
180 trap_rate_get()
181 {
182         local t0 t1
183 
184         t0=$(devlink_trap_rx_packets_get blackhole_route)
185         sleep 10
186         t1=$(devlink_trap_rx_packets_get blackhole_route)
187 
188         echo $(((t1 - t0) / 10))
189 }
190 
191 policer_drop_rate_get()
192 {
193         local id=$1; shift
194         local t0 t1
195 
196         t0=$(devlink_trap_policer_rx_dropped_get $id)
197         sleep 10
198         t1=$(devlink_trap_policer_rx_dropped_get $id)
199 
200         echo $(((t1 - t0) / 10))
201 }
202 
203 __rate_test()
204 {
205         local rate pct drop_rate
206         local id=$1; shift
207 
208         RET=0
209 
210         devlink trap policer set $DEVLINK_DEV policer $id rate 1000 burst 512
211         devlink trap group set $DEVLINK_DEV group l3_drops policer $id
212 
213         # Send packets at highest possible rate and make sure they are dropped
214         # by the policer. Make sure measured received rate is about 1000 pps
215         log_info "=== Tx rate: Highest, Policer rate: 1000 pps ==="
216 
217         start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac
218 
219         sleep 5 # Take measurements when rate is stable
220 
221         rate=$(trap_rate_get)
222         pct=$((100 * (rate - 1000) / 1000))
223         ((-10 <= pct && pct <= 10))
224         check_err $? "Expected rate 1000 pps, got $rate pps, which is $pct% off. Required accuracy is +-10%"
225         log_info "Expected rate 1000 pps, measured rate $rate pps"
226 
227         drop_rate=$(policer_drop_rate_get $id)
228         (( drop_rate > 0 ))
229         check_err $? "Expected non-zero policer drop rate, got 0"
230         log_info "Measured policer drop rate of $drop_rate pps"
231 
232         stop_traffic
233 
234         # Send packets at a rate of 1000 pps and make sure they are not dropped
235         # by the policer
236         log_info "=== Tx rate: 1000 pps, Policer rate: 1000 pps ==="
237 
238         start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac -d 1msec
239 
240         sleep 5 # Take measurements when rate is stable
241 
242         drop_rate=$(policer_drop_rate_get $id)
243         (( drop_rate == 0 ))
244         check_err $? "Expected zero policer drop rate, got a drop rate of $drop_rate pps"
245         log_info "Measured policer drop rate of $drop_rate pps"
246 
247         stop_traffic
248 
249         # Unbind the policer and send packets at highest possible rate. Make
250         # sure they are not dropped by the policer and that the measured
251         # received rate is higher than 1000 pps
252         log_info "=== Tx rate: Highest, Policer rate: No policer ==="
253 
254         devlink trap group set $DEVLINK_DEV group l3_drops nopolicer
255 
256         start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac
257 
258         rate=$(trap_rate_get)
259         (( rate > 1000 ))
260         check_err $? "Expected rate higher than 1000 pps, got $rate pps"
261         log_info "Measured rate $rate pps"
262 
263         drop_rate=$(policer_drop_rate_get $id)
264         (( drop_rate == 0 ))
265         check_err $? "Expected zero policer drop rate, got a drop rate of $drop_rate pps"
266         log_info "Measured policer drop rate of $drop_rate pps"
267 
268         stop_traffic
269 
270         log_test "Trap policer rate"
271 }
272 
273 rate_test()
274 {
275         local last_policer=$(devlink -j -p trap policer show |
276                              jq '[.[]["'$DEVLINK_DEV'"][].policer] | max')
277 
278         log_info "Running rate test for policer 1"
279         __rate_test 1
280 
281         log_info "Running rate test for policer $((last_policer / 2))"
282         __rate_test $((last_policer / 2))
283 
284         log_info "Running rate test for policer $last_policer"
285         __rate_test $last_policer
286 }
287 
288 __burst_test()
289 {
290         local t0_rx t0_drop t1_rx t1_drop rx drop
291         local id=$1; shift
292 
293         RET=0
294 
295         devlink trap policer set $DEVLINK_DEV policer $id rate 1000 burst 512
296         devlink trap group set $DEVLINK_DEV group l3_drops policer $id
297 
298         # Send a burst of 16 packets and make sure that 16 are received
299         # and that none are dropped by the policer
300         log_info "=== Tx burst size: 16, Policer burst size: 512 ==="
301 
302         t0_rx=$(devlink_trap_rx_packets_get blackhole_route)
303         t0_drop=$(devlink_trap_policer_rx_dropped_get $id)
304 
305         start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac -c 16
306 
307         t1_rx=$(devlink_trap_rx_packets_get blackhole_route)
308         t1_drop=$(devlink_trap_policer_rx_dropped_get $id)
309 
310         rx=$((t1_rx - t0_rx))
311         (( rx == 16 ))
312         check_err $? "Expected burst size of 16 packets, got $rx packets"
313         log_info "Expected burst size of 16 packets, measured burst size of $rx packets"
314 
315         drop=$((t1_drop - t0_drop))
316         (( drop == 0 ))
317         check_err $? "Expected zero policer drops, got $drop"
318         log_info "Measured policer drops of $drop packets"
319 
320         # Unbind the policer and send a burst of 64 packets. Make sure that
321         # 64 packets are received and that none are dropped by the policer
322         log_info "=== Tx burst size: 64, Policer burst size: No policer ==="
323 
324         devlink trap group set $DEVLINK_DEV group l3_drops nopolicer
325 
326         t0_rx=$(devlink_trap_rx_packets_get blackhole_route)
327         t0_drop=$(devlink_trap_policer_rx_dropped_get $id)
328 
329         start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac -c 64
330 
331         t1_rx=$(devlink_trap_rx_packets_get blackhole_route)
332         t1_drop=$(devlink_trap_policer_rx_dropped_get $id)
333 
334         rx=$((t1_rx - t0_rx))
335         (( rx == 64 ))
336         check_err $? "Expected burst size of 64 packets, got $rx packets"
337         log_info "Expected burst size of 64 packets, measured burst size of $rx packets"
338 
339         drop=$((t1_drop - t0_drop))
340         (( drop == 0 ))
341         check_err $? "Expected zero policer drops, got $drop"
342         log_info "Measured policer drops of $drop packets"
343 
344         log_test "Trap policer burst size"
345 }
346 
347 burst_test()
348 {
349         local last_policer=$(devlink -j -p trap policer show |
350                              jq '[.[]["'$DEVLINK_DEV'"][].policer] | max')
351 
352         log_info "Running burst test for policer 1"
353         __burst_test 1
354 
355         log_info "Running burst test for policer $((last_policer / 2))"
356         __burst_test $((last_policer / 2))
357 
358         log_info "Running burst test for policer $last_policer"
359         __burst_test $last_policer
360 }
361 
362 trap cleanup EXIT
363 
364 setup_prepare
365 setup_wait
366 
367 tests_run
368 
369 exit $EXIT_STATUS

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php