2 # SPDX-License-Identifier: GPL-2.0
4 # This test sends one stream of traffic from H1 through a TBF shaper, to a RED
5 # within TBF shaper on $swp3. The two shapers have the same configuration, and
6 # thus the resulting stream should fill all available bandwidth on the latter
7 # shaper. A second stream is sent from H2 also via $swp3, and used to inject
8 # additional traffic. Since all available bandwidth is taken, this traffic has
11 # +--------------------------+ +--------------------------+
14 # | | 192.0.2.1/28 | | | 192.0.2.2/28 |
15 # | | TBF 10Mbps | | | |
16 # +-----|--------------------+ +-----|--------------------+
18 # +-----|------------------------------------------------|--------------------+
20 # | +--|------------------------------------------------|----------------+ |
21 # | | + $swp1 + $swp2 | |
25 # | | | TBF 10Mbps / RED | |
26 # | +--------------------------------|-----------------------------------+ |
28 # +-----------------------------------|---------------------------------------+
30 # +-----|--------------------+
35 # +--------------------------+
55 simple_if_init
$h1 192.0.2.1/28
56 defer simple_if_fini
$h1 192.0.2.1/28
61 tc qdisc replace dev
$h1 root handle
1: tbf \
62 rate
10Mbit burst
10K limit
1M
63 defer tc qdisc del dev
$h1 root
68 simple_if_init
$h2 192.0.2.2/28
69 defer simple_if_fini
$h2 192.0.2.2/28
77 simple_if_init
$h3 192.0.2.3/28
78 defer simple_if_fini
$h3 192.0.2.3/28
86 ip link add dev br up
type bridge
87 defer ip link del dev br
89 ip link
set dev
$swp1 up master br
90 defer ip link
set dev
$swp1 down nomaster
92 ip link
set dev
$swp2 up master br
93 defer ip link
set dev
$swp2 down nomaster
95 ip link
set dev
$swp3 up master br
96 defer ip link
set dev
$swp3 down nomaster
102 defer mtu_restore
$h2
105 defer mtu_restore
$h3
107 tc qdisc replace dev
$swp3 root handle
1: tbf \
108 rate
10Mbit burst
10K limit
1M
109 defer tc qdisc del dev
$swp3 root
111 ip link add name _drop_test up
type dummy
112 defer ip link del dev _drop_test
126 h3_mac
=$
(mac_get
$h3)
139 ping_test
$h1 192.0.2.3 " from host 1"
140 ping_test
$h2 192.0.2.3 " from host 2"
145 qdisc_stats_get
$swp3 11: .backlog
150 qdisc_stats_get
$swp3 11: .marked
155 qdisc_stats_get
$swp3 11: .packets
160 link_stats_get _drop_test tx packets
165 local proto
=$1; shift
168 $MZ $h2 -p $PKTSZ -a own
-b $h3_mac -A 192.0.2.2 -B 192.0.2.3 -t $proto -q -c $pkts "$@"
171 # This sends traffic in an attempt to build a backlog of $size. Returns 0 on
172 # success. After 10 failed attempts it bails out and returns 1. It dumps the
173 # backlog size to stdout.
177 local proto
=$1; shift
182 local cur
=$
(get_qdisc_backlog
)
183 local diff=$
((size
- cur
))
184 local pkts
=$
(((diff + PKTSZ
- 1) / PKTSZ
))
186 if ((cur
>= size
)); then
189 elif ((i
++ > 10)); then
194 send_packets
$proto $pkts "$@"
203 local npackets_0
=$
(get_qdisc_npackets
)
204 local nmarked_0
=$
(get_nmarked
)
206 local npackets_1
=$
(get_qdisc_npackets
)
207 local nmarked_1
=$
(get_nmarked
)
209 local nmarked_d
=$
((nmarked_1
- nmarked_0
))
210 local npackets_d
=$
((npackets_1
- npackets_0
))
211 local pct
=$
((100 * nmarked_d
/ npackets_d
))
221 local npackets_0
=$
(get_qdisc_npackets
)
222 local nmirrored_0
=$
(get_nmirrored
)
224 local npackets_1
=$
(get_qdisc_npackets
)
225 local nmirrored_1
=$
(get_nmirrored
)
227 local nmirrored_d
=$
((nmirrored_1
- nmirrored_0
))
228 local npackets_d
=$
((npackets_1
- npackets_0
))
229 local pct
=$
((100 * nmirrored_d
/ npackets_d
))
238 local limit
=$1; shift
242 # Build the below-the-limit backlog using UDP. We could use TCP just
243 # fine, but this way we get a proof that UDP is accepted when queue
244 # length is below the limit. The main stream is using TCP, and if the
245 # limit is misconfigured, we would see this traffic being ECN marked.
247 backlog
=$
(build_backlog $
((2 * limit
/ 3)) udp
)
248 check_err $?
"Could not build the requested backlog"
249 pct
=$
(check_marking
"== 0")
250 check_err $?
"backlog $backlog / $limit Got $pct% marked packets, expected == 0."
251 log_test
"$name backlog < limit"
253 # Now push TCP, because non-TCP traffic would be early-dropped after the
254 # backlog crosses the limit, and we want to make sure that the backlog
255 # is above the limit.
257 backlog
=$
(build_backlog $
((3 * limit
/ 2)) tcp tos
=0x01)
258 check_err $?
"Could not build the requested backlog"
259 pct
=$
(check_marking
">= 95")
260 check_err $?
"backlog $backlog / $limit Got $pct% marked packets, expected >= 95."
261 log_test
"$name backlog > limit"
266 local limit
=$1; shift
269 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
270 -a own
-b $h3_mac -t tcp
-q tos
=0x01 &
271 defer stop_traffic $
!
274 ecn_test_common
"$name" $limit
276 # Up there we saw that UDP gets accepted when backlog is below the
277 # limit. Now that it is above, it should all get dropped, and backlog
278 # building should fail.
280 build_backlog $
((2 * limit
)) udp
>/dev
/null
281 check_fail $?
"UDP traffic went into backlog instead of being early-dropped"
282 log_test
"$name backlog > limit: UDP early-dropped"
287 local limit
=$1; shift
288 local name
="ECN nodrop"
290 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
291 -a own
-b $h3_mac -t tcp
-q tos
=0x01 &
292 defer stop_traffic $
!
295 ecn_test_common
"$name" $limit
297 # Up there we saw that UDP gets accepted when backlog is below the
298 # limit. Now that it is above, in nodrop mode, make sure it goes to
301 build_backlog $
((2 * limit
)) udp
>/dev
/null
302 check_err $?
"UDP traffic was early-dropped instead of getting into backlog"
303 log_test
"$name backlog > limit: UDP not dropped"
308 local limit
=$1; shift
312 # Use ECN-capable TCP to verify there's no marking even though the queue
314 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
315 -a own
-b $h3_mac -t tcp
-q tos
=0x01 &
316 defer stop_traffic $
!
318 # Pushing below the queue limit should work.
320 backlog
=$
(build_backlog $
((2 * limit
/ 3)) tcp tos
=0x01)
321 check_err $?
"Could not build the requested backlog"
322 pct
=$
(check_marking
"== 0")
323 check_err $?
"backlog $backlog / $limit Got $pct% marked packets, expected == 0."
324 log_test
"RED backlog < limit"
326 # Pushing above should not.
328 backlog
=$
(build_backlog $
((3 * limit
/ 2)) tcp tos
=0x01)
329 check_fail $?
"Traffic went into backlog instead of being early-dropped"
330 pct
=$
(check_marking
"== 0")
331 check_err $?
"backlog $backlog / $limit Got $pct% marked packets, expected == 0."
332 log_test
"RED backlog > limit"
337 local limit
=$1; shift
345 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
346 -a own
-b $h3_mac -t udp
-q &
347 defer stop_traffic $
!
350 tc filter add block
10 pref
1234 handle
102 matchall skip_hw \
351 action mirred egress mirror dev _drop_test
353 # Push to the queue until it's at the limit. The configured limit is
354 # rounded by the qdisc, so this is the best we can do to get to the real
356 build_backlog $
((3 * limit
/ 2)) udp
>/dev
/null
358 base
=$
(get_nmirrored
)
362 ((now
>= base
+ 100))
363 check_err $?
"Dropped packets not observed: 100 expected, $((now - base)) seen"
365 tc filter del block
10 pref
1234 handle
102 matchall
367 base
=$
(get_nmirrored
)
372 check_err $?
"Dropped packets still observed: 0 expected, $((now - base)) seen"
374 log_test
"RED early_dropped packets mirrored"
379 local limit
=$1; shift
384 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
385 -a own
-b $h3_mac -t tcp
-q tos
=0x01 &
386 defer stop_traffic $
!
389 tc filter add block
10 pref
1234 handle
102 matchall skip_hw \
390 action mirred egress mirror dev _drop_test
392 backlog
=$
(build_backlog $
((2 * limit
/ 3)) tcp tos
=0x01)
393 check_err $?
"Could not build the requested backlog"
394 pct
=$
(check_mirroring
"== 0")
395 check_err $?
"backlog $backlog / $limit Got $pct% mirrored packets, expected == 0."
397 backlog
=$
(build_backlog $
((3 * limit
/ 2)) tcp tos
=0x01)
398 check_err $?
"Could not build the requested backlog"
399 pct
=$
(check_mirroring
">= 95")
400 check_err $?
"backlog $backlog / $limit Got $pct% mirrored packets, expected >= 95."
402 tc filter del block
10 pref
1234 handle
102 matchall
404 log_test
"ECN marked packets mirrored"
411 tc qdisc replace dev
$swp3 parent
1:1 handle
11: red \
412 limit
1M avpkt
$PKTSZ probability
1 \
413 min
$BACKLOG max $
((BACKLOG
+ 1)) burst
38 "${args[@]}"
419 tc qdisc del dev
$swp3 parent
1:1
425 defer uninstall_qdisc
426 xfail_on_slow do_ecn_test
$BACKLOG
431 install_qdisc ecn nodrop
432 defer uninstall_qdisc
433 xfail_on_slow do_ecn_nodrop_test
$BACKLOG
439 defer uninstall_qdisc
440 xfail_on_slow do_red_test
$BACKLOG
445 install_qdisc qevent early_drop block
10
446 defer uninstall_qdisc
447 xfail_on_slow do_red_qevent_test
$BACKLOG
452 install_qdisc ecn qevent mark block
10
453 defer uninstall_qdisc
454 xfail_on_slow do_ecn_qevent_test
$BACKLOG