1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ALL_TESTS="
5	ping_ipv4
6	ecn_test
7	ecn_test_perband
8	ecn_nodrop_test
9	red_test
10	mc_backlog_test
11	red_mirror_test
12	red_trap_test
13	ecn_mirror_test
14"
15: ${QDISC:=ets}
16source sch_red_core.sh
17
18# do_ecn_test first build 2/3 of the requested backlog and expects no marking,
19# and then builds 3/2 of it and does expect marking. The values of $BACKLOG1 and
20# $BACKLOG2 are far enough not to overlap, so that we can assume that if we do
21# see (do not see) marking, it is actually due to the configuration of that one
22# TC, and not due to configuration of the other TC leaking over.
23BACKLOG1=200000
24BACKLOG2=500000
25
26install_root_qdisc()
27{
28	tc qdisc add dev $swp3 parent 1: handle 10: $QDISC \
29	   bands 8 priomap 7 6 5 4 3 2 1 0
30}
31
32install_qdisc_tc0()
33{
34	local -a args=("$@")
35
36	tc qdisc add dev $swp3 parent 10:8 handle 108: red \
37	   limit 1000000 min $BACKLOG1 max $((BACKLOG1 + 1)) \
38	   probability 1.0 avpkt 8000 burst 38 "${args[@]}"
39}
40
41install_qdisc_tc1()
42{
43	local -a args=("$@")
44
45	tc qdisc add dev $swp3 parent 10:7 handle 107: red \
46	   limit 1000000 min $BACKLOG2 max $((BACKLOG2 + 1)) \
47	   probability 1.0 avpkt 8000 burst 63 "${args[@]}"
48}
49
50install_qdisc()
51{
52	install_root_qdisc
53	install_qdisc_tc0 "$@"
54	install_qdisc_tc1 "$@"
55	sleep 1
56}
57
58uninstall_qdisc_tc0()
59{
60	tc qdisc del dev $swp3 parent 10:8
61}
62
63uninstall_qdisc_tc1()
64{
65	tc qdisc del dev $swp3 parent 10:7
66}
67
68uninstall_root_qdisc()
69{
70	tc qdisc del dev $swp3 parent 1:
71}
72
73uninstall_qdisc()
74{
75	uninstall_qdisc_tc0
76	uninstall_qdisc_tc1
77	uninstall_root_qdisc
78}
79
80ecn_test()
81{
82	install_qdisc ecn
83
84	do_ecn_test 10 $BACKLOG1
85	do_ecn_test 11 $BACKLOG2
86
87	uninstall_qdisc
88}
89
90ecn_test_perband()
91{
92	install_qdisc ecn
93
94	do_ecn_test_perband 10 $BACKLOG1
95	do_ecn_test_perband 11 $BACKLOG2
96
97	uninstall_qdisc
98}
99
100ecn_nodrop_test()
101{
102	install_qdisc ecn nodrop
103
104	do_ecn_nodrop_test 10 $BACKLOG1
105	do_ecn_nodrop_test 11 $BACKLOG2
106
107	uninstall_qdisc
108}
109
110red_test()
111{
112	install_qdisc
113
114	# Make sure that we get the non-zero value if there is any.
115	local cur=$(busywait 1100 until_counter_is "> 0" \
116			    qdisc_stats_get $swp3 10: .backlog)
117	(( cur == 0 ))
118	check_err $? "backlog of $cur observed on non-busy qdisc"
119	log_test "$QDISC backlog properly cleaned"
120
121	do_red_test 10 $BACKLOG1
122	do_red_test 11 $BACKLOG2
123
124	uninstall_qdisc
125}
126
127mc_backlog_test()
128{
129	install_qdisc
130
131	# Note that the backlog numbers here do not correspond to RED
132	# configuration, but are arbitrary.
133	do_mc_backlog_test 10 $BACKLOG1
134	do_mc_backlog_test 11 $BACKLOG2
135
136	uninstall_qdisc
137}
138
139red_mirror_test()
140{
141	install_qdisc qevent early_drop block 10
142
143	do_drop_mirror_test 10 $BACKLOG1 early_drop
144	do_drop_mirror_test 11 $BACKLOG2 early_drop
145
146	uninstall_qdisc
147}
148
149red_trap_test()
150{
151	install_qdisc qevent early_drop block 10
152
153	do_drop_trap_test 10 $BACKLOG1 early_drop
154	do_drop_trap_test 11 $BACKLOG2 early_drop
155
156	uninstall_qdisc
157}
158
159ecn_mirror_test()
160{
161	install_qdisc ecn qevent mark block 10
162
163	do_mark_mirror_test 10 $BACKLOG1
164	do_mark_mirror_test 11 $BACKLOG2
165
166	uninstall_qdisc
167}
168
169bail_on_lldpad
170
171trap cleanup EXIT
172setup_prepare
173setup_wait
174tests_run
175
176exit $EXIT_STATUS
177