1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ALL_TESTS="
5	ping_ipv4
6	ecn_test
7	ecn_nodrop_test
8	red_test
9	mc_backlog_test
10	red_mirror_test
11"
12: ${QDISC:=ets}
13source sch_red_core.sh
14
15# do_ecn_test first build 2/3 of the requested backlog and expects no marking,
16# and then builds 3/2 of it and does expect marking. The values of $BACKLOG1 and
17# $BACKLOG2 are far enough not to overlap, so that we can assume that if we do
18# see (do not see) marking, it is actually due to the configuration of that one
19# TC, and not due to configuration of the other TC leaking over.
20BACKLOG1=200000
21BACKLOG2=500000
22
23install_qdisc()
24{
25	local -a args=("$@")
26
27	tc qdisc add dev $swp3 root handle 10: $QDISC \
28	   bands 8 priomap 7 6 5 4 3 2 1 0
29	tc qdisc add dev $swp3 parent 10:8 handle 108: red \
30	   limit 1000000 min $BACKLOG1 max $((BACKLOG1 + 1)) \
31	   probability 1.0 avpkt 8000 burst 38 "${args[@]}"
32	tc qdisc add dev $swp3 parent 10:7 handle 107: red \
33	   limit 1000000 min $BACKLOG2 max $((BACKLOG2 + 1)) \
34	   probability 1.0 avpkt 8000 burst 63 "${args[@]}"
35	sleep 1
36}
37
38uninstall_qdisc()
39{
40	tc qdisc del dev $swp3 parent 10:7
41	tc qdisc del dev $swp3 parent 10:8
42	tc qdisc del dev $swp3 root
43}
44
45ecn_test()
46{
47	install_qdisc ecn
48
49	do_ecn_test 10 $BACKLOG1
50	do_ecn_test 11 $BACKLOG2
51
52	uninstall_qdisc
53}
54
55ecn_nodrop_test()
56{
57	install_qdisc ecn nodrop
58
59	do_ecn_nodrop_test 10 $BACKLOG1
60	do_ecn_nodrop_test 11 $BACKLOG2
61
62	uninstall_qdisc
63}
64
65red_test()
66{
67	install_qdisc
68
69	do_red_test 10 $BACKLOG1
70	do_red_test 11 $BACKLOG2
71
72	uninstall_qdisc
73}
74
75mc_backlog_test()
76{
77	install_qdisc
78
79	# Note that the backlog numbers here do not correspond to RED
80	# configuration, but are arbitrary.
81	do_mc_backlog_test 10 $BACKLOG1
82	do_mc_backlog_test 11 $BACKLOG2
83
84	uninstall_qdisc
85}
86
87red_mirror_test()
88{
89	install_qdisc qevent early_drop block 10
90
91	do_drop_mirror_test 10 $BACKLOG1 early_drop
92	do_drop_mirror_test 11 $BACKLOG2 early_drop
93
94	uninstall_qdisc
95}
96
97trap cleanup EXIT
98
99setup_prepare
100setup_wait
101
102bail_on_lldpad
103tests_run
104
105exit $EXIT_STATUS
106