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	do_red_test 10 $BACKLOG1
71	do_red_test 11 $BACKLOG2
72
73	uninstall_qdisc
74}
75
76mc_backlog_test()
77{
78	install_qdisc
79
80	# Note that the backlog numbers here do not correspond to RED
81	# configuration, but are arbitrary.
82	do_mc_backlog_test 10 $BACKLOG1
83	do_mc_backlog_test 11 $BACKLOG2
84
85	uninstall_qdisc
86}
87
88red_mirror_test()
89{
90	install_qdisc qevent early_drop block 10
91
92	do_drop_mirror_test 10 $BACKLOG1 early_drop
93	do_drop_mirror_test 11 $BACKLOG2 early_drop
94
95	uninstall_qdisc
96}
97
98red_trap_test()
99{
100	install_qdisc qevent early_drop block 10
101
102	do_drop_trap_test 10 $BACKLOG1 early_drop
103	do_drop_trap_test 11 $BACKLOG2 early_drop
104
105	uninstall_qdisc
106}
107
108trap cleanup EXIT
109
110setup_prepare
111setup_wait
112
113bail_on_lldpad
114tests_run
115
116exit $EXIT_STATUS
117