1 # SPDX-License-Identifier: GPL-2.0
3 # This test sends one stream of traffic from H1 through a TBF shaper, to a RED
4 # within TBF shaper on $swp3. The two shapers have the same configuration, and
5 # thus the resulting stream should fill all available bandwidth on the latter
6 # shaper. A second stream is sent from H2 also via $swp3, and used to inject
7 # additional traffic. Since all available bandwidth is taken, this traffic has
10 # +--------------------------+ +--------------------------+
13 # | | 192.0.2.1/28 | | | 192.0.2.2/28 |
14 # | | TBF 10Mbps | | | |
15 # +-----|--------------------+ +-----|--------------------+
17 # +-----|------------------------------------------------|--------------------+
19 # | +--|------------------------------------------------|----------------+ |
20 # | | + $swp1 + $swp2 | |
24 # | | | TBF 10Mbps / RED | |
25 # | +--------------------------------|-----------------------------------+ |
27 # +-----------------------------------|---------------------------------------+
29 # +-----|--------------------+
34 # +--------------------------+
54 simple_if_init
$h1 192.0.2.1/28
56 tc qdisc replace dev
$h1 root handle
1: tbf \
57 rate
10Mbit burst
10K limit
1M
62 tc qdisc del dev
$h1 root
64 simple_if_fini
$h1 192.0.2.1/28
69 simple_if_init
$h2 192.0.2.2/28
76 simple_if_fini
$h2 192.0.2.2/28
81 simple_if_init
$h3 192.0.2.3/28
88 simple_if_fini
$h3 192.0.2.3/28
93 ip link add dev br up
type bridge
94 ip link
set dev
$swp1 up master br
95 ip link
set dev
$swp2 up master br
96 ip link
set dev
$swp3 up master br
102 tc qdisc replace dev
$swp3 root handle
1: tbf \
103 rate
10Mbit burst
10K limit
1M
104 ip link add name _drop_test up
type dummy
109 ip link del dev _drop_test
110 tc qdisc del dev
$swp3 root
116 ip link
set dev
$swp3 down nomaster
117 ip link
set dev
$swp2 down nomaster
118 ip link
set dev
$swp1 down nomaster
133 h3_mac
=$
(mac_get
$h3)
157 ping_test
$h1 192.0.2.3 " from host 1"
158 ping_test
$h2 192.0.2.3 " from host 2"
163 qdisc_stats_get
$swp3 11: .backlog
168 qdisc_stats_get
$swp3 11: .marked
173 qdisc_stats_get
$swp3 11: .packets
178 link_stats_get _drop_test tx packets
183 local proto
=$1; shift
186 $MZ $h2 -p $PKTSZ -a own
-b $h3_mac -A 192.0.2.2 -B 192.0.2.3 -t $proto -q -c $pkts "$@"
189 # This sends traffic in an attempt to build a backlog of $size. Returns 0 on
190 # success. After 10 failed attempts it bails out and returns 1. It dumps the
191 # backlog size to stdout.
195 local proto
=$1; shift
200 local cur
=$
(get_qdisc_backlog
)
201 local diff=$
((size
- cur
))
202 local pkts
=$
(((diff + PKTSZ
- 1) / PKTSZ
))
204 if ((cur
>= size
)); then
207 elif ((i
++ > 10)); then
212 send_packets
$proto $pkts "$@"
221 local npackets_0
=$
(get_qdisc_npackets
)
222 local nmarked_0
=$
(get_nmarked
)
224 local npackets_1
=$
(get_qdisc_npackets
)
225 local nmarked_1
=$
(get_nmarked
)
227 local nmarked_d
=$
((nmarked_1
- nmarked_0
))
228 local npackets_d
=$
((npackets_1
- npackets_0
))
229 local pct
=$
((100 * nmarked_d
/ npackets_d
))
239 local npackets_0
=$
(get_qdisc_npackets
)
240 local nmirrored_0
=$
(get_nmirrored
)
242 local npackets_1
=$
(get_qdisc_npackets
)
243 local nmirrored_1
=$
(get_nmirrored
)
245 local nmirrored_d
=$
((nmirrored_1
- nmirrored_0
))
246 local npackets_d
=$
((npackets_1
- npackets_0
))
247 local pct
=$
((100 * nmirrored_d
/ npackets_d
))
256 local limit
=$1; shift
260 # Build the below-the-limit backlog using UDP. We could use TCP just
261 # fine, but this way we get a proof that UDP is accepted when queue
262 # length is below the limit. The main stream is using TCP, and if the
263 # limit is misconfigured, we would see this traffic being ECN marked.
265 backlog
=$
(build_backlog $
((2 * limit
/ 3)) udp
)
266 check_err $?
"Could not build the requested backlog"
267 pct
=$
(check_marking
"== 0")
268 check_err $?
"backlog $backlog / $limit Got $pct% marked packets, expected == 0."
269 log_test
"$name backlog < limit"
271 # Now push TCP, because non-TCP traffic would be early-dropped after the
272 # backlog crosses the limit, and we want to make sure that the backlog
273 # is above the limit.
275 backlog
=$
(build_backlog $
((3 * limit
/ 2)) tcp tos
=0x01)
276 check_err $?
"Could not build the requested backlog"
277 pct
=$
(check_marking
">= 95")
278 check_err $?
"backlog $backlog / $limit Got $pct% marked packets, expected >= 95."
279 log_test
"$name backlog > limit"
284 local limit
=$1; shift
287 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
288 -a own
-b $h3_mac -t tcp
-q tos
=0x01 &
291 ecn_test_common
"$name" $limit
293 # Up there we saw that UDP gets accepted when backlog is below the
294 # limit. Now that it is above, it should all get dropped, and backlog
295 # building should fail.
297 build_backlog $
((2 * limit
)) udp
>/dev
/null
298 check_fail $?
"UDP traffic went into backlog instead of being early-dropped"
299 log_test
"$name backlog > limit: UDP early-dropped"
307 local limit
=$1; shift
308 local name
="ECN nodrop"
310 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
311 -a own
-b $h3_mac -t tcp
-q tos
=0x01 &
314 ecn_test_common
"$name" $limit
316 # Up there we saw that UDP gets accepted when backlog is below the
317 # limit. Now that it is above, in nodrop mode, make sure it goes to
320 build_backlog $
((2 * limit
)) udp
>/dev
/null
321 check_err $?
"UDP traffic was early-dropped instead of getting into backlog"
322 log_test
"$name backlog > limit: UDP not dropped"
330 local limit
=$1; shift
334 # Use ECN-capable TCP to verify there's no marking even though the queue
336 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
337 -a own
-b $h3_mac -t tcp
-q tos
=0x01 &
339 # Pushing below the queue limit should work.
341 backlog
=$
(build_backlog $
((2 * limit
/ 3)) tcp tos
=0x01)
342 check_err $?
"Could not build the requested backlog"
343 pct
=$
(check_marking
"== 0")
344 check_err $?
"backlog $backlog / $limit Got $pct% marked packets, expected == 0."
345 log_test
"RED backlog < limit"
347 # Pushing above should not.
349 backlog
=$
(build_backlog $
((3 * limit
/ 2)) tcp tos
=0x01)
350 check_fail $?
"Traffic went into backlog instead of being early-dropped"
351 pct
=$
(check_marking
"== 0")
352 check_err $?
"backlog $backlog / $limit Got $pct% marked packets, expected == 0."
353 log_test
"RED backlog > limit"
361 local limit
=$1; shift
369 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
370 -a own
-b $h3_mac -t udp
-q &
373 tc filter add block
10 pref
1234 handle
102 matchall skip_hw \
374 action mirred egress mirror dev _drop_test
376 # Push to the queue until it's at the limit. The configured limit is
377 # rounded by the qdisc, so this is the best we can do to get to the real
379 build_backlog $
((3 * limit
/ 2)) udp
>/dev
/null
381 base
=$
(get_nmirrored
)
385 ((now
>= base
+ 100))
386 check_err $?
"Dropped packets not observed: 100 expected, $((now - base)) seen"
388 tc filter del block
10 pref
1234 handle
102 matchall
390 base
=$
(get_nmirrored
)
395 check_err $?
"Dropped packets still observed: 0 expected, $((now - base)) seen"
397 log_test
"RED early_dropped packets mirrored"
405 local limit
=$1; shift
410 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
411 -a own
-b $h3_mac -t tcp
-q tos
=0x01 &
414 tc filter add block
10 pref
1234 handle
102 matchall skip_hw \
415 action mirred egress mirror dev _drop_test
417 backlog
=$
(build_backlog $
((2 * limit
/ 3)) tcp tos
=0x01)
418 check_err $?
"Could not build the requested backlog"
419 pct
=$
(check_mirroring
"== 0")
420 check_err $?
"backlog $backlog / $limit Got $pct% mirrored packets, expected == 0."
422 backlog
=$
(build_backlog $
((3 * limit
/ 2)) tcp tos
=0x01)
423 check_err $?
"Could not build the requested backlog"
424 pct
=$
(check_mirroring
">= 95")
425 check_err $?
"backlog $backlog / $limit Got $pct% mirrored packets, expected >= 95."
427 tc filter del block
10 pref
1234 handle
102 matchall
429 log_test
"ECN marked packets mirrored"
439 tc qdisc replace dev
$swp3 parent
1:1 handle
11: red \
440 limit
1M avpkt
$PKTSZ probability
1 \
441 min
$BACKLOG max $
((BACKLOG
+ 1)) burst
38 "${args[@]}"
447 tc qdisc del dev
$swp3 parent
1:1
459 install_qdisc ecn nodrop
460 do_ecn_nodrop_test
$BACKLOG
473 install_qdisc qevent early_drop block
10
474 do_red_qevent_test
$BACKLOG
480 install_qdisc ecn qevent mark block
10
481 do_ecn_qevent_test
$BACKLOG