2 # SPDX-License-Identifier: GPL-2.0
4 # Test devlink-trap policer functionality over mlxsw.
6 # +---------------------------------+
11 # | | default via 192.0.2.2 |
12 # +----|----------------------------+
14 # +----|----------------------------------------------------------------------+
22 # +----|----------------------------------------------------------------------+
24 # +----|----------------------------+
25 # | | default via 198.51.100.2 |
27 # | | 198.51.100.1/24 |
30 # +---------------------------------+
32 lib_dir
=$
(dirname $0)/..
/..
/..
/net
/forwarding
41 source $lib_dir/tc_common.sh
42 source $lib_dir/lib.sh
43 source $lib_dir/devlink_lib.sh
47 simple_if_init
$h1 192.0.2.1/24
50 ip
-4 route add default vrf v
$h1 nexthop via
192.0.2.2
55 ip
-4 route del default vrf v
$h1 nexthop via
192.0.2.2
58 simple_if_fini
$h1 192.0.2.1/24
63 simple_if_init
$h2 198.51.100.1/24
66 ip
-4 route add default vrf v
$h2 nexthop via
198.51.100.2
71 ip
-4 route del default vrf v
$h2 nexthop via
198.51.100.2
74 simple_if_fini
$h2 198.51.100.1/24
79 ip link
set dev
$rp1 up
80 ip link
set dev
$rp2 up
82 __addr_add_del
$rp1 add
192.0.2.2/24
83 __addr_add_del
$rp2 add
198.51.100.2/24
87 ip
-4 route add blackhole
198.51.100.100
89 devlink
trap set $DEVLINK_DEV trap blackhole_route action
trap
94 devlink
trap set $DEVLINK_DEV trap blackhole_route action drop
96 ip
-4 route del blackhole
198.51.100.100
100 __addr_add_del
$rp2 del
198.51.100.2/24
101 __addr_add_del
$rp1 del
192.0.2.2/24
103 ip link
set dev
$rp2 down
104 ip link
set dev
$rp1 down
115 rp1_mac
=$
(mac_get
$rp1)
136 # Reload to ensure devlink-trap settings are back to default.
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"
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"
155 log_test
"Trap policer rate limits"
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"
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"
177 log_test
"Trap policer burst size limits"
184 t0
=$
(devlink_trap_rx_packets_get blackhole_route
)
186 t1
=$
(devlink_trap_rx_packets_get blackhole_route
)
188 echo $
(((t1
- t0
) / 10))
191 policer_drop_rate_get
()
196 t0
=$
(devlink_trap_policer_rx_dropped_get
$id)
198 t1
=$
(devlink_trap_policer_rx_dropped_get
$id)
200 echo $
(((t1
- t0
) / 10))
205 local rate pct drop_rate
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
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 ==="
217 start_traffic
$h1 192.0.2.1 198.51.100.100 $rp1_mac
219 sleep 5 # Take measurements when rate is stable
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"
227 drop_rate
=$
(policer_drop_rate_get
$id)
229 check_err $?
"Expected non-zero policer drop rate, got 0"
230 log_info
"Measured policer drop rate of $drop_rate pps"
234 # Send packets at a rate of 1000 pps and make sure they are not dropped
236 log_info
"=== Tx rate: 1000 pps, Policer rate: 1000 pps ==="
238 start_traffic
$h1 192.0.2.1 198.51.100.100 $rp1_mac -d 1msec
240 sleep 5 # Take measurements when rate is stable
242 drop_rate
=$
(policer_drop_rate_get
$id)
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"
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 ==="
254 devlink
trap group
set $DEVLINK_DEV group l3_drops nopolicer
256 start_traffic
$h1 192.0.2.1 198.51.100.100 $rp1_mac
258 rate
=$
(trap_rate_get
)
260 check_err $?
"Expected rate higher than 1000 pps, got $rate pps"
261 log_info
"Measured rate $rate pps"
263 drop_rate
=$
(policer_drop_rate_get
$id)
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"
270 log_test
"Trap policer rate"
277 for id
in $
(devlink_trap_policer_ids_get
); do
279 log_info
"Running rate test for policer $id"
286 local t0_rx t0_drop t1_rx t1_drop rx drop
291 devlink
trap policer
set $DEVLINK_DEV policer
$id rate
1000 burst
512
292 devlink
trap group
set $DEVLINK_DEV group l3_drops policer
$id
294 # Send a burst of 16 packets and make sure that 16 are received
295 # and that none are dropped by the policer
296 log_info
"=== Tx burst size: 16, Policer burst size: 512 ==="
298 t0_rx
=$
(devlink_trap_rx_packets_get blackhole_route
)
299 t0_drop
=$
(devlink_trap_policer_rx_dropped_get
$id)
301 start_traffic
$h1 192.0.2.1 198.51.100.100 $rp1_mac -c 16
303 t1_rx
=$
(devlink_trap_rx_packets_get blackhole_route
)
304 t1_drop
=$
(devlink_trap_policer_rx_dropped_get
$id)
306 rx
=$
((t1_rx
- t0_rx
))
308 check_err $?
"Expected burst size of 16 packets, got $rx packets"
309 log_info
"Expected burst size of 16 packets, measured burst size of $rx packets"
311 drop
=$
((t1_drop
- t0_drop
))
313 check_err $?
"Expected zero policer drops, got $drop"
314 log_info
"Measured policer drops of $drop packets"
316 # Unbind the policer and send a burst of 64 packets. Make sure that
317 # 64 packets are received and that none are dropped by the policer
318 log_info
"=== Tx burst size: 64, Policer burst size: No policer ==="
320 devlink
trap group
set $DEVLINK_DEV group l3_drops nopolicer
322 t0_rx
=$
(devlink_trap_rx_packets_get blackhole_route
)
323 t0_drop
=$
(devlink_trap_policer_rx_dropped_get
$id)
325 start_traffic
$h1 192.0.2.1 198.51.100.100 $rp1_mac -c 64
327 t1_rx
=$
(devlink_trap_rx_packets_get blackhole_route
)
328 t1_drop
=$
(devlink_trap_policer_rx_dropped_get
$id)
330 rx
=$
((t1_rx
- t0_rx
))
332 check_err $?
"Expected burst size of 64 packets, got $rx packets"
333 log_info
"Expected burst size of 64 packets, measured burst size of $rx packets"
335 drop
=$
((t1_drop
- t0_drop
))
337 check_err $?
"Expected zero policer drops, got $drop"
338 log_info
"Measured policer drops of $drop packets"
340 log_test
"Trap policer burst size"
347 for id
in $
(devlink_trap_policer_ids_get
); do
349 log_info
"Running burst size test for policer $id"