summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/drivers/net/mlxsw/sch_offload.sh
blob: 071a33d10c20b642055ba6ca4584982c87f211ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Test qdisc offload indication


ALL_TESTS="
	test_root
	test_port_tbf
	test_etsprio
	test_etsprio_port_tbf
"
NUM_NETIFS=1
lib_dir=$(dirname $0)/../../../net/forwarding
source $lib_dir/lib.sh

check_not_offloaded()
{
	local handle=$1; shift
	local h
	local offloaded

	h=$(qdisc_stats_get $h1 "$handle" .handle)
	[[ $h == '"'$handle'"' ]]
	check_err $? "Qdisc with handle $handle does not exist"

	offloaded=$(qdisc_stats_get $h1 "$handle" .offloaded)
	[[ $offloaded == true ]]
	check_fail $? "Qdisc with handle $handle offloaded, but should not be"
}

check_all_offloaded()
{
	local handle=$1; shift

	if [[ ! -z $handle ]]; then
		local offloaded=$(qdisc_stats_get $h1 "$handle" .offloaded)
		[[ $offloaded == true ]]
		check_err $? "Qdisc with handle $handle not offloaded"
	fi

	local unoffloaded=$(tc q sh dev $h1 invisible |
				grep -v offloaded |
				sed s/root/parent\ root/ |
				cut -d' ' -f 5)
	[[ -z $unoffloaded ]]
	check_err $? "Qdiscs with following parents not offloaded: $unoffloaded"

	pre_cleanup
}

with_ets()
{
	local handle=$1; shift
	local locus=$1; shift

	tc qdisc add dev $h1 $locus handle $handle \
	   ets bands 8 priomap 7 6 5 4 3 2 1 0
	"$@"
	tc qdisc del dev $h1 $locus
}

with_prio()
{
	local handle=$1; shift
	local locus=$1; shift

	tc qdisc add dev $h1 $locus handle $handle \
	   prio bands 8 priomap 7 6 5 4 3 2 1 0
	"$@"
	tc qdisc del dev $h1 $locus
}

with_red()
{
	local handle=$1; shift
	local locus=$1; shift

	tc qdisc add dev $h1 $locus handle $handle \
	   red limit 1000000 min 200000 max 300000 probability 0.5 avpkt 1500
	"$@"
	tc qdisc del dev $h1 $locus
}

with_tbf()
{
	local handle=$1; shift
	local locus=$1; shift

	tc qdisc add dev $h1 $locus handle $handle \
	   tbf rate 400Mbit burst 128K limit 1M
	"$@"
	tc qdisc del dev $h1 $locus
}

with_pfifo()
{
	local handle=$1; shift
	local locus=$1; shift

	tc qdisc add dev $h1 $locus handle $handle pfifo limit 100K
	"$@"
	tc qdisc del dev $h1 $locus
}

with_bfifo()
{
	local handle=$1; shift
	local locus=$1; shift

	tc qdisc add dev $h1 $locus handle $handle bfifo limit 100K
	"$@"
	tc qdisc del dev $h1 $locus
}

with_drr()
{
	local handle=$1; shift
	local locus=$1; shift

	tc qdisc add dev $h1 $locus handle $handle drr
	"$@"
	tc qdisc del dev $h1 $locus
}

with_qdiscs()
{
	local handle=$1; shift
	local parent=$1; shift
	local kind=$1; shift
	local next_handle=$((handle * 2))
	local locus;

	if [[ $kind == "--" ]]; then
		local cmd=$1; shift
		$cmd $(printf %x: $parent) "$@"
	else
		if ((parent == 0)); then
			locus=root
		else
			locus=$(printf "parent %x:1" $parent)
		fi

		with_$kind $(printf %x: $handle) "$locus" \
			with_qdiscs $next_handle $handle "$@"
	fi
}

get_name()
{
	local parent=$1; shift
	local name=$(echo "" "${@^^}" | tr ' ' -)

	if ((parent != 0)); then
		kind=$(qdisc_stats_get $h1 $parent: .kind)
		kind=${kind%\"}
		kind=${kind#\"}
		name="-${kind^^}$name"
	fi

	echo root$name
}

do_test_offloaded()
{
	local handle=$1; shift
	local parent=$1; shift

	RET=0
	with_qdiscs $handle $parent "$@" -- check_all_offloaded
	log_test $(get_name $parent "$@")" offloaded"
}

do_test_nooffload()
{
	local handle=$1; shift
	local parent=$1; shift

	local name=$(echo "${@^^}" | tr ' ' -)
	local kind

	RET=0
	with_qdiscs $handle $parent "$@" -- check_not_offloaded
	log_test $(get_name $parent "$@")" not offloaded"
}

do_test_combinations()
{
	local handle=$1; shift
	local parent=$1; shift

	local cont
	local leaf
	local fifo

	for cont in "" ets prio; do
		for leaf in "" red tbf "red tbf" "tbf red"; do
			for fifo in "" pfifo bfifo; do
				if [[ -z "$cont$leaf$fifo" ]]; then
					continue
				fi
				do_test_offloaded $handle $parent \
						  $cont $leaf $fifo
			done
		done
	done

	for cont in ets prio; do
		for leaf in red tbf; do
			do_test_nooffload $handle $parent $cont red tbf $leaf
			do_test_nooffload $handle $parent $cont tbf red $leaf
		done
		for leaf in "red red" "tbf tbf"; do
			do_test_nooffload $handle $parent $cont $leaf
		done
	done

	do_test_nooffload $handle $parent drr
}

test_root()
{
	do_test_combinations 1 0
}

test_port_tbf()
{
	with_tbf 1: root \
		do_test_combinations 8 1
}

do_test_etsprio()
{
	local parent=$1; shift
	local tbfpfx=$1; shift
	local cont

	for cont in ets prio; do
		RET=0
		with_$cont 8: "$parent" \
			with_red 11: "parent 8:1" \
			with_red 12: "parent 8:2" \
			with_tbf 13: "parent 8:3" \
			with_tbf 14: "parent 8:4" \
			check_all_offloaded
		log_test "root$tbfpfx-ETS-{RED,TBF} offloaded"

		RET=0
		with_$cont 8: "$parent" \
			with_red 81: "parent 8:1" \
				with_tbf 811: "parent 81:1" \
			with_tbf 84: "parent 8:4" \
				with_red 841: "parent 84:1" \
			check_all_offloaded
		log_test "root$tbfpfx-ETS-{RED-TBF,TBF-RED} offloaded"

		RET=0
		with_$cont 8: "$parent" \
			with_red 81: "parent 8:1" \
				with_tbf 811: "parent 81:1" \
					with_bfifo 8111: "parent 811:1" \
			with_tbf 82: "parent 8:2" \
				with_red 821: "parent 82:1" \
					with_bfifo 8211: "parent 821:1" \
			check_all_offloaded
		log_test "root$tbfpfx-ETS-{RED-TBF-bFIFO,TBF-RED-bFIFO} offloaded"
	done
}

test_etsprio()
{
	do_test_etsprio root ""
}

test_etsprio_port_tbf()
{
	with_tbf 1: root \
		do_test_etsprio "parent 1:1" "-TBF"
}

cleanup()
{
	tc qdisc del dev $h1 root &>/dev/null
}

trap cleanup EXIT
h1=${NETIFS[p1]}
tests_run

exit $EXIT_STATUS