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
57 tc qdisc replace dev $h1 root handle 1: tbf \
58 rate 10Mbit burst 10K limit 1M
63 tc qdisc del dev $h1 root
65 simple_if_fini $h1 192.0.2.1/28
70 simple_if_init $h2 192.0.2.2/28
77 simple_if_fini $h2 192.0.2.2/28
82 simple_if_init $h3 192.0.2.3/28
89 simple_if_fini $h3 192.0.2.3/28
94 ip link add dev br up type bridge
95 ip link set dev $swp1 up master br
96 ip link set dev $swp2 up master br
97 ip link set dev $swp3 up master br
103 tc qdisc replace dev $swp3 root handle 1: tbf \
104 rate 10Mbit burst 10K limit 1M
105 ip link add name _drop_test up type dummy
110 ip link del dev _drop_test
111 tc qdisc del dev $swp3 root
117 ip link set dev $swp3 down nomaster
118 ip link set dev $swp2 down nomaster
119 ip link set dev $swp1 down nomaster
134 h3_mac=$(mac_get $h3)
158 ping_test $h1 192.0.2.3 " from host 1"
159 ping_test $h2 192.0.2.3 " from host 2"
164 qdisc_stats_get $swp3 11: .backlog
169 qdisc_stats_get $swp3 11: .marked
174 qdisc_stats_get $swp3 11: .packets
179 link_stats_get _drop_test tx packets
184 local proto=$1; shift
187 $MZ $h2 -p $PKTSZ -a own -b $h3_mac -A 192.0.2.2 -B 192.0.2.3 -t $proto -q -c $pkts "$@"
190 # This sends traffic in an attempt to build a backlog of $size. Returns 0 on
191 # success. After 10 failed attempts it bails out and returns 1. It dumps the
192 # backlog size to stdout.
196 local proto=$1; shift
201 local cur=$(get_qdisc_backlog)
202 local diff=$((size - cur))
203 local pkts=$(((diff + PKTSZ - 1) / PKTSZ))
205 if ((cur >= size)); then
208 elif ((i++ > 10)); then
213 send_packets $proto $pkts "$@"
222 local npackets_0=$(get_qdisc_npackets)
223 local nmarked_0=$(get_nmarked)
225 local npackets_1=$(get_qdisc_npackets)
226 local nmarked_1=$(get_nmarked)
228 local nmarked_d=$((nmarked_1 - nmarked_0))
229 local npackets_d=$((npackets_1 - npackets_0))
230 local pct=$((100 * nmarked_d / npackets_d))
240 local npackets_0=$(get_qdisc_npackets)
241 local nmirrored_0=$(get_nmirrored)
243 local npackets_1=$(get_qdisc_npackets)
244 local nmirrored_1=$(get_nmirrored)
246 local nmirrored_d=$((nmirrored_1 - nmirrored_0))
247 local npackets_d=$((npackets_1 - npackets_0))
248 local pct=$((100 * nmirrored_d / npackets_d))
257 local limit=$1; shift
261 # Build the below-the-limit backlog using UDP. We could use TCP just
262 # fine, but this way we get a proof that UDP is accepted when queue
263 # length is below the limit. The main stream is using TCP, and if the
264 # limit is misconfigured, we would see this traffic being ECN marked.
266 backlog=$(build_backlog $((2 * limit / 3)) udp)
267 check_err $? "Could not build the requested backlog"
268 pct=$(check_marking "== 0")
269 check_err $? "backlog $backlog / $limit Got $pct% marked packets, expected == 0."
270 log_test "$name backlog < limit"
272 # Now push TCP, because non-TCP traffic would be early-dropped after the
273 # backlog crosses the limit, and we want to make sure that the backlog
274 # is above the limit.
276 backlog=$(build_backlog $((3 * limit / 2)) tcp tos=0x01)
277 check_err $? "Could not build the requested backlog"
278 pct=$(check_marking ">= 95")
279 check_err $? "backlog $backlog / $limit Got $pct% marked packets, expected >= 95."
280 log_test "$name backlog > limit"
285 local limit=$1; shift
288 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
289 -a own -b $h3_mac -t tcp -q tos=0x01 &
292 ecn_test_common "$name" $limit
294 # Up there we saw that UDP gets accepted when backlog is below the
295 # limit. Now that it is above, it should all get dropped, and backlog
296 # building should fail.
298 build_backlog $((2 * limit)) udp >/dev/null
299 check_fail $? "UDP traffic went into backlog instead of being early-dropped"
300 log_test "$name backlog > limit: UDP early-dropped"
308 local limit=$1; shift
309 local name="ECN nodrop"
311 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
312 -a own -b $h3_mac -t tcp -q tos=0x01 &
315 ecn_test_common "$name" $limit
317 # Up there we saw that UDP gets accepted when backlog is below the
318 # limit. Now that it is above, in nodrop mode, make sure it goes to
321 build_backlog $((2 * limit)) udp >/dev/null
322 check_err $? "UDP traffic was early-dropped instead of getting into backlog"
323 log_test "$name backlog > limit: UDP not dropped"
331 local limit=$1; shift
335 # Use ECN-capable TCP to verify there's no marking even though the queue
337 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
338 -a own -b $h3_mac -t tcp -q tos=0x01 &
340 # Pushing below the queue limit should work.
342 backlog=$(build_backlog $((2 * limit / 3)) tcp tos=0x01)
343 check_err $? "Could not build the requested backlog"
344 pct=$(check_marking "== 0")
345 check_err $? "backlog $backlog / $limit Got $pct% marked packets, expected == 0."
346 log_test "RED backlog < limit"
348 # Pushing above should not.
350 backlog=$(build_backlog $((3 * limit / 2)) tcp tos=0x01)
351 check_fail $? "Traffic went into backlog instead of being early-dropped"
352 pct=$(check_marking "== 0")
353 check_err $? "backlog $backlog / $limit Got $pct% marked packets, expected == 0."
354 log_test "RED backlog > limit"
362 local limit=$1; shift
370 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
371 -a own -b $h3_mac -t udp -q &
374 tc filter add block 10 pref 1234 handle 102 matchall skip_hw \
375 action mirred egress mirror dev _drop_test
377 # Push to the queue until it's at the limit. The configured limit is
378 # rounded by the qdisc, so this is the best we can do to get to the real
380 build_backlog $((3 * limit / 2)) udp >/dev/null
382 base=$(get_nmirrored)
386 ((now >= base + 100))
387 check_err $? "Dropped packets not observed: 100 expected, $((now - base)) seen"
389 tc filter del block 10 pref 1234 handle 102 matchall
391 base=$(get_nmirrored)
396 check_err $? "Dropped packets still observed: 0 expected, $((now - base)) seen"
398 log_test "RED early_dropped packets mirrored"
406 local limit=$1; shift
411 $MZ $h1 -p $PKTSZ -A 192.0.2.1 -B 192.0.2.3 -c 0 \
412 -a own -b $h3_mac -t tcp -q tos=0x01 &
415 tc filter add block 10 pref 1234 handle 102 matchall skip_hw \
416 action mirred egress mirror dev _drop_test
418 backlog=$(build_backlog $((2 * limit / 3)) tcp tos=0x01)
419 check_err $? "Could not build the requested backlog"
420 pct=$(check_mirroring "== 0")
421 check_err $? "backlog $backlog / $limit Got $pct% mirrored packets, expected == 0."
423 backlog=$(build_backlog $((3 * limit / 2)) tcp tos=0x01)
424 check_err $? "Could not build the requested backlog"
425 pct=$(check_mirroring ">= 95")
426 check_err $? "backlog $backlog / $limit Got $pct% mirrored packets, expected >= 95."
428 tc filter del block 10 pref 1234 handle 102 matchall
430 log_test "ECN marked packets mirrored"
440 tc qdisc replace dev $swp3 parent 1:1 handle 11: red \
441 limit 1M avpkt $PKTSZ probability 1 \
442 min $BACKLOG max $((BACKLOG + 1)) burst 38 "${args[@]}"
448 tc qdisc del dev $swp3 parent 1:1
460 install_qdisc ecn nodrop
461 do_ecn_nodrop_test $BACKLOG
474 install_qdisc qevent early_drop block 10
475 do_red_qevent_test $BACKLOG
481 install_qdisc ecn qevent mark block 10
482 do_ecn_qevent_test $BACKLOG