File Index
Files and directories
Sign in
FILE

sch_ets_core.sh

File preview with syntax highlighting.

linux-6.19.14/tools/testing/selftests/net/forwarding/sch_ets_core.sh BASH
  1# SPDX-License-Identifier: GPL-2.0
  2
  3# This is a template for ETS Qdisc test.
  4#
  5# This test sends from H1 several traffic streams with 802.1p-tagged packets.
  6# The tags are used at $swp1 to prioritize the traffic. Each stream is then
  7# queued at a different ETS band according to the assigned priority. After
  8# runnig for a while, counters at H2 are consulted to determine whether the
  9# traffic scheduling was according to the ETS configuration.
 10#
 11# This template is supposed to be embedded by a test driver, which implements
 12# statistics collection, any HW-specific stuff, and prominently configures the
 13# system to assure that there is overcommitment at $swp2. That is necessary so
 14# that the ETS traffic selection algorithm kicks in and has to schedule some
 15# traffic at the expense of other.
 16#
 17# A driver for veth-based testing is in sch_ets.sh, an example of a driver for
 18# an offloaded data path is in selftests/drivers/net/mlxsw/sch_ets.sh.
 19#
 20# +---------------------------------------------------------------------+
 21# | H1                                                                  |
 22# |     + $h1.10              + $h1.11              + $h1.12            |
 23# |     | 192.0.2.1/28        | 192.0.2.17/28       | 192.0.2.33/28     |
 24# |     | egress-qos-map      | egress-qos-map      | egress-qos-map    |
 25# |     |  0:0                |  0:1                |  0:2              |
 26# |     \____________________ | ____________________/                   |
 27# |                          \|/                                        |
 28# |                           + $h1                                     |
 29# +---------------------------|-----------------------------------------+
 30#                             |
 31# +---------------------------|-----------------------------------------+
 32# | SW                        + $swp1                                   |
 33# |                           | >1Gbps                                  |
 34# |      ____________________/|\____________________                    |
 35# |     /                     |                     \                   |
 36# |  +--|----------------+ +--|----------------+ +--|----------------+  |
 37# |  |  + $swp1.10       | |  + $swp1.11       | |  + $swp1.12       |  |
 38# |  |    ingress-qos-map| |    ingress-qos-map| |    ingress-qos-map|  |
 39# |  |     0:0 1:1 2:2   | |     0:0 1:1 2:2   | |     0:0 1:1 2:2   |  |
 40# |  |                   | |                   | |                   |  |
 41# |  |    BR10           | |    BR11           | |    BR12           |  |
 42# |  |                   | |                   | |                   |  |
 43# |  |  + $swp2.10       | |  + $swp2.11       | |  + $swp2.12       |  |
 44# |  +--|----------------+ +--|----------------+ +--|----------------+  |
 45# |     \____________________ | ____________________/                   |
 46# |                          \|/                                        |
 47# |                           + $swp2                                   |
 48# |                           | 1Gbps (ethtool or HTB qdisc)            |
 49# |                           | qdisc ets quanta $W0 $W1 $W2            |
 50# |                           |           priomap 0 1 2                 |
 51# +---------------------------|-----------------------------------------+
 52#                             |
 53# +---------------------------|-----------------------------------------+
 54# | H2                        + $h2                                     |
 55# |      ____________________/|\____________________                    |
 56# |     /                     |                     \                   |
 57# |     + $h2.10              + $h2.11              + $h2.12            |
 58# |       192.0.2.2/28          192.0.2.18/28         192.0.2.34/28     |
 59# +---------------------------------------------------------------------+
 60
 61NUM_NETIFS=4
 62CHECK_TC=yes
 63source $lib_dir/lib.sh
 64source $lib_dir/sch_ets_tests.sh
 65
 66PARENT=root
 67QDISC_DEV=
 68
 69sip()
 70{
 71	echo 192.0.2.$((16 * $1 + 1))
 72}
 73
 74dip()
 75{
 76	echo 192.0.2.$((16 * $1 + 2))
 77}
 78
 79# Callback from sch_ets_tests.sh
 80ets_start_traffic()
 81{
 82	local dst_mac=$(mac_get $h2)
 83	local i=$1; shift
 84
 85	start_traffic $h1.1$i $(sip $i) $(dip $i) $dst_mac
 86}
 87
 88ETS_CHANGE_QDISC=
 89
 90priomap_mode()
 91{
 92	echo "Running in priomap mode"
 93	ets_delete_qdisc
 94	ETS_CHANGE_QDISC=ets_change_qdisc_priomap
 95}
 96
 97classifier_mode()
 98{
 99	echo "Running in classifier mode"
100	ets_delete_qdisc
101	ETS_CHANGE_QDISC=ets_change_qdisc_classifier
102}
103
104ets_change_qdisc_priomap()
105{
106	local dev=$1; shift
107	local nstrict=$1; shift
108	local priomap=$1; shift
109	local quanta=("${@}")
110
111	local op=$(if [[ -n $QDISC_DEV ]]; then echo change; else echo add; fi)
112
113	tc qdisc $op dev $dev $PARENT handle 10: ets			       \
114		$(if ((nstrict)); then echo strict $nstrict; fi)	       \
115		$(if ((${#quanta[@]})); then echo quanta ${quanta[@]}; fi)     \
116		priomap $priomap
117	QDISC_DEV=$dev
118}
119
120ets_change_qdisc_classifier()
121{
122	local dev=$1; shift
123	local nstrict=$1; shift
124	local priomap=$1; shift
125	local quanta=("${@}")
126
127	local op=$(if [[ -n $QDISC_DEV ]]; then echo change; else echo add; fi)
128
129	tc qdisc $op dev $dev $PARENT handle 10: ets			       \
130		$(if ((nstrict)); then echo strict $nstrict; fi)	       \
131		$(if ((${#quanta[@]})); then echo quanta ${quanta[@]}; fi)
132
133	if [[ $op == add ]]; then
134		local prio=0
135		local band
136
137		for band in $priomap; do
138			tc filter add dev $dev parent 10: basic \
139				match "meta(priority eq $prio)" \
140				flowid 10:$((band + 1))
141			((prio++))
142		done
143	fi
144	QDISC_DEV=$dev
145}
146
147# Callback from sch_ets_tests.sh
148ets_change_qdisc()
149{
150	if [[ -z "$ETS_CHANGE_QDISC" ]]; then
151		exit 1
152	fi
153	$ETS_CHANGE_QDISC "$@"
154}
155
156ets_delete_qdisc()
157{
158	if [[ -n $QDISC_DEV ]]; then
159		tc qdisc del dev $QDISC_DEV $PARENT
160		QDISC_DEV=
161	fi
162}
163
164h1_create()
165{
166	local i;
167
168	adf_simple_if_init $h1
169
170	mtu_set $h1 9900
171	defer mtu_restore $h1
172
173	for i in {0..2}; do
174		vlan_create $h1 1$i v$h1 $(sip $i)/28
175		defer vlan_destroy $h1 1$i
176		ip link set dev $h1.1$i type vlan egress 0:$i
177	done
178}
179
180h2_create()
181{
182	local i
183
184	adf_simple_if_init $h2
185
186	mtu_set $h2 9900
187	defer mtu_restore $h2
188
189	for i in {0..2}; do
190		vlan_create $h2 1$i v$h2 $(dip $i)/28
191		defer vlan_destroy $h2 1$i
192	done
193}
194
195ets_switch_create()
196{
197	local i
198
199	ip link set dev $swp1 up
200	defer ip link set dev $swp1 down
201
202	mtu_set $swp1 9900
203	defer mtu_restore $swp1
204
205	ip link set dev $swp2 up
206	defer ip link set dev $swp2 down
207
208	mtu_set $swp2 9900
209	defer mtu_restore $swp2
210
211	for i in {0..2}; do
212		vlan_create $swp1 1$i
213		defer vlan_destroy $swp1 1$i
214		ip link set dev $swp1.1$i type vlan ingress 0:0 1:1 2:2
215
216		vlan_create $swp2 1$i
217		defer vlan_destroy $swp2 1$i
218
219		ip link add dev br1$i type bridge
220		defer ip link del dev br1$i
221
222		ip link set dev $swp1.1$i master br1$i
223		defer ip link set dev $swp1.1$i nomaster
224
225		ip link set dev $swp2.1$i master br1$i
226		defer ip link set dev $swp2.1$i nomaster
227
228		ip link set dev br1$i up
229		defer ip link set dev br1$i down
230
231		ip link set dev $swp1.1$i up
232		defer ip link set dev $swp1.1$i down
233
234		ip link set dev $swp2.1$i up
235		defer ip link set dev $swp2.1$i down
236	done
237
238	defer ets_delete_qdisc
239}
240
241setup_prepare()
242{
243	h1=${NETIFS[p1]}
244	swp1=${NETIFS[p2]}
245
246	swp2=${NETIFS[p3]}
247	h2=${NETIFS[p4]}
248
249	put=$swp2
250	hut=$h2
251
252	adf_vrf_prepare
253
254	h1_create
255	h2_create
256	switch_create
257}
258
259ping_ipv4()
260{
261	ping_test $h1.10 $(dip 0) " vlan 10"
262	ping_test $h1.11 $(dip 1) " vlan 11"
263	ping_test $h1.12 $(dip 2) " vlan 12"
264}
265
266ets_run()
267{
268	trap cleanup EXIT
269
270	setup_prepare
271	setup_wait
272
273	tests_run
274
275	exit $EXIT_STATUS
276}
~/ Read-only file preview.