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