brintos

brintos / linux-shallow public Read only

0
0
Text · 11.4 KiB · 0f0f4f0 Raw
418 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# This test injects a 10-MB burst of traffic with VLAN tag and 802.1p priority5# of 1. This stream is consistently prioritized as priority 1, is put to PG6# buffer 1, and scheduled at TC 1.7#8# - the stream first ingresses through $swp1, where it is forwarded to $swp39#10# - then it ingresses through $swp4. Here it is put to a lossless buffer and put11#   to a small pool ("PFC pool"). The traffic is forwarded to $swp2, which is12#   shaped, and thus the PFC pool eventually fills, therefore the headroom13#   fills, and $swp3 is paused.14#15# - since $swp3 now can't send traffic, the traffic ingressing $swp1 is kept at16#   a pool ("overflow pool"). The overflow pool needs to be large enough to17#   contain the whole burst.18#19# - eventually the PFC pool gets some traffic out, headroom therefore gets some20#   traffic to the pool, and $swp3 is unpaused again. This way the traffic is21#   gradually forwarded from the overflow pool, through the PFC pool, out of22#   $swp2, and eventually to $h2.23#24# - if PFC works, all lossless flow packets that ingress through $swp1 should25#   also be seen ingressing $h2. If it doesn't, there will be drops due to26#   discrepancy between the speeds of $swp1 and $h2.27#28# - it should all play out relatively quickly, so that SLL and HLL will not29#   cause drops.30#31# +-----------------------+32# | H1                    |33# |   + $h1.111           |34# |   | 192.0.2.33/28     |35# |   |                   |36# |   + $h1               |37# +---|-------------------+  +--------------------+38#     |                      |                    |39# +---|----------------------|--------------------|---------------------------+40# |   + $swp1          $swp3 +                    + $swp4                     |41# |   | iPOOL1        iPOOL0 |                    | iPOOL2                    |42# |   | ePOOL4        ePOOL5 |                    | ePOOL4                    |43# |   |        PFC:enabled=1 |                    | PFC:enabled=1             |44# | +-|----------------------|-+                +-|------------------------+  |45# | | + $swp1.111  $swp3.111 + |                | + $swp4.111              |  |46# | |                          |                |                          |  |47# | | BR1                      |                | BR2                      |  |48# | |                          |                |                          |  |49# | |                          |                |         + $swp2.111      |  |50# | +--------------------------+                +---------|----------------+  |51# |                                                       |                   |52# | iPOOL0: 500KB dynamic                                 |                   |53# | iPOOL1: 10MB static                                   |                   |54# | iPOOL2: 1MB static                                    + $swp2             |55# | ePOOL4: 500KB dynamic                                 | iPOOL0            |56# | ePOOL5: 10MB static                                   | ePOOL6            |57# | ePOOL6: "infinite" static                             | 200Mbps shaper    |58# +-------------------------------------------------------|-------------------+59#                                                         |60#                                                     +---|-------------------+61#                                                     |   + $h2            H2 |62#                                                     |   |                   |63#                                                     |   + $h2.111           |64#                                                     |     192.0.2.34/28     |65#                                                     +-----------------------+66#67# iPOOL0+ePOOL4 is a helper pool for control traffic etc.68# iPOOL1+ePOOL5 are overflow pools.69# iPOOL2+ePOOL6 are PFC pools.70 71ALL_TESTS="72	ping_ipv473	test_qos_pfc74"75 76lib_dir=$(dirname $0)/../../../net/forwarding77 78NUM_NETIFS=679source $lib_dir/lib.sh80source $lib_dir/devlink_lib.sh81 82_1KB=100083_100KB=$((100 * _1KB))84_500KB=$((500 * _1KB))85_1MB=$((1000 * _1KB))86_10MB=$((10 * _1MB))87 88h1_create()89{90	simple_if_init $h191	mtu_set $h1 1000092 93	vlan_create $h1 111 v$h1 192.0.2.33/2894}95 96h1_destroy()97{98	vlan_destroy $h1 11199 100	mtu_restore $h1101	simple_if_fini $h1102}103 104h2_create()105{106	simple_if_init $h2107	mtu_set $h2 10000108 109	vlan_create $h2 111 v$h2 192.0.2.34/28110}111 112h2_destroy()113{114	vlan_destroy $h2 111115 116	mtu_restore $h2117	simple_if_fini $h2118}119 120switch_create()121{122	local lanes_swp4123	local pg1_size124 125	# pools126	# -----127 128	devlink_pool_size_thtype_save 0129	devlink_pool_size_thtype_save 4130	devlink_pool_size_thtype_save 1131	devlink_pool_size_thtype_save 5132	devlink_pool_size_thtype_save 2133	devlink_pool_size_thtype_save 6134 135	devlink_port_pool_th_save $swp1 1136	devlink_port_pool_th_save $swp2 6137	devlink_port_pool_th_save $swp3 5138	devlink_port_pool_th_save $swp4 2139 140	devlink_tc_bind_pool_th_save $swp1 1 ingress141	devlink_tc_bind_pool_th_save $swp2 1 egress142	devlink_tc_bind_pool_th_save $swp3 1 egress143	devlink_tc_bind_pool_th_save $swp4 1 ingress144 145	# Control traffic pools. Just reduce the size. Keep them dynamic so that146	# we don't need to change all the uninteresting quotas.147	devlink_pool_size_thtype_set 0 dynamic $_500KB148	devlink_pool_size_thtype_set 4 dynamic $_500KB149 150	# Overflow pools.151	devlink_pool_size_thtype_set 1 static $_10MB152	devlink_pool_size_thtype_set 5 static $_10MB153 154	# PFC pools. As per the writ, the size of egress PFC pool should be155	# infinice, but actually it just needs to be large enough to not matter156	# in practice, so reuse the 10MB limit.157	devlink_pool_size_thtype_set 2 static $_1MB158	devlink_pool_size_thtype_set 6 static $_10MB159 160	# $swp1161	# -----162 163	ip link set dev $swp1 up164	mtu_set $swp1 10000165	vlan_create $swp1 111166	ip link set dev $swp1.111 type vlan ingress-qos-map 0:0 1:1167 168	devlink_port_pool_th_set $swp1 1 $_10MB169	devlink_tc_bind_pool_th_set $swp1 1 ingress 1 $_10MB170 171	# Configure qdisc so that we can configure PG and therefore pool172	# assignment.173	tc qdisc replace dev $swp1 root handle 1: \174	   ets bands 8 strict 8 priomap 7 6175	dcb buffer set dev $swp1 prio-buffer all:0 1:1176 177	# $swp2178	# -----179 180	ip link set dev $swp2 up181	mtu_set $swp2 10000182	vlan_create $swp2 111183	ip link set dev $swp2.111 type vlan egress-qos-map 0:0 1:1184 185	devlink_port_pool_th_set $swp2 6 $_10MB186	devlink_tc_bind_pool_th_set $swp2 1 egress 6 $_10MB187 188	# prio 0->TC0 (band 7), 1->TC1 (band 6). TC1 is shaped.189	tc qdisc replace dev $swp2 root handle 1: \190	   ets bands 8 strict 8 priomap 7 6191	tc qdisc replace dev $swp2 parent 1:7 handle 17: \192	   tbf rate 200Mbit burst 131072 limit 1M193 194	# $swp3195	# -----196 197	ip link set dev $swp3 up198	mtu_set $swp3 10000199	vlan_create $swp3 111200	ip link set dev $swp3.111 type vlan egress-qos-map 0:0 1:1201 202	devlink_port_pool_th_set $swp3 5 $_10MB203	devlink_tc_bind_pool_th_set $swp3 1 egress 5 $_10MB204 205	# prio 0->TC0 (band 7), 1->TC1 (band 6)206	tc qdisc replace dev $swp3 root handle 1: \207	   ets bands 8 strict 8 priomap 7 6208 209	# Need to enable PFC so that PAUSE takes effect. Therefore need to put210	# the lossless prio into a buffer of its own. Don't bother with buffer211	# sizes though, there is not going to be any pressure in the "backward"212	# direction.213	dcb buffer set dev $swp3 prio-buffer all:0 1:1214	dcb pfc set dev $swp3 prio-pfc all:off 1:on215 216	# $swp4217	# -----218 219	ip link set dev $swp4 up220	mtu_set $swp4 10000221	vlan_create $swp4 111222	ip link set dev $swp4.111 type vlan ingress-qos-map 0:0 1:1223 224	devlink_port_pool_th_set $swp4 2 $_1MB225	devlink_tc_bind_pool_th_set $swp4 1 ingress 2 $_1MB226 227	# Configure qdisc so that we can hand-tune headroom.228	tc qdisc replace dev $swp4 root handle 1: \229	   ets bands 8 strict 8 priomap 7 6230	dcb buffer set dev $swp4 prio-buffer all:0 1:1231	dcb pfc set dev $swp4 prio-pfc all:off 1:on232	# PG0 will get autoconfigured to Xoff, give PG1 arbitrarily 100K, which233	# is (-2*MTU) about 80K of delay provision.234	pg1_size=$_100KB235 236	setup_wait_dev_with_timeout $swp4237 238	lanes_swp4=$(ethtool $swp4 | grep 'Lanes:')239	lanes_swp4=${lanes_swp4#*"Lanes: "}240 241	# 8-lane ports use two buffers among which the configured buffer242	# is split, so double the size to get twice (20K + 80K).243	if [[ $lanes_swp4 -eq 8 ]]; then244		pg1_size=$((pg1_size * 2))245	fi246 247	dcb buffer set dev $swp4 buffer-size all:0 1:$pg1_size248 249	# bridges250	# -------251 252	ip link add name br1 type bridge vlan_filtering 0253	ip link set dev $swp1.111 master br1254	ip link set dev $swp3.111 master br1255	ip link set dev br1 up256 257	ip link add name br2 type bridge vlan_filtering 0258	ip link set dev $swp2.111 master br2259	ip link set dev $swp4.111 master br2260	ip link set dev br2 up261}262 263switch_destroy()264{265	# Do this first so that we can reset the limits to values that are only266	# valid for the original static / dynamic setting.267	devlink_pool_size_thtype_restore 6268	devlink_pool_size_thtype_restore 5269	devlink_pool_size_thtype_restore 4270	devlink_pool_size_thtype_restore 2271	devlink_pool_size_thtype_restore 1272	devlink_pool_size_thtype_restore 0273 274	# bridges275	# -------276 277	ip link set dev br2 down278	ip link set dev $swp4.111 nomaster279	ip link set dev $swp2.111 nomaster280	ip link del dev br2281 282	ip link set dev br1 down283	ip link set dev $swp3.111 nomaster284	ip link set dev $swp1.111 nomaster285	ip link del dev br1286 287	# $swp4288	# -----289 290	dcb buffer set dev $swp4 buffer-size all:0291	dcb pfc set dev $swp4 prio-pfc all:off292	dcb buffer set dev $swp4 prio-buffer all:0293	tc qdisc del dev $swp4 root294 295	devlink_tc_bind_pool_th_restore $swp4 1 ingress296	devlink_port_pool_th_restore $swp4 2297 298	vlan_destroy $swp4 111299	mtu_restore $swp4300	ip link set dev $swp4 down301 302	# $swp3303	# -----304 305	dcb pfc set dev $swp3 prio-pfc all:off306	dcb buffer set dev $swp3 prio-buffer all:0307	tc qdisc del dev $swp3 root308 309	devlink_tc_bind_pool_th_restore $swp3 1 egress310	devlink_port_pool_th_restore $swp3 5311 312	vlan_destroy $swp3 111313	mtu_restore $swp3314	ip link set dev $swp3 down315 316	# $swp2317	# -----318 319	tc qdisc del dev $swp2 parent 1:7320	tc qdisc del dev $swp2 root321 322	devlink_tc_bind_pool_th_restore $swp2 1 egress323	devlink_port_pool_th_restore $swp2 6324 325	vlan_destroy $swp2 111326	mtu_restore $swp2327	ip link set dev $swp2 down328 329	# $swp1330	# -----331 332	dcb buffer set dev $swp1 prio-buffer all:0333	tc qdisc del dev $swp1 root334 335	devlink_tc_bind_pool_th_restore $swp1 1 ingress336	devlink_port_pool_th_restore $swp1 1337 338	vlan_destroy $swp1 111339	mtu_restore $swp1340	ip link set dev $swp1 down341}342 343setup_prepare()344{345	h1=${NETIFS[p1]}346	swp1=${NETIFS[p2]}347 348	swp2=${NETIFS[p3]}349	h2=${NETIFS[p4]}350 351	swp3=${NETIFS[p5]}352	swp4=${NETIFS[p6]}353 354	h2mac=$(mac_get $h2)355 356	vrf_prepare357 358	h1_create359	h2_create360	switch_create361}362 363cleanup()364{365	pre_cleanup366 367	switch_destroy368	h2_destroy369	h1_destroy370 371	vrf_cleanup372}373 374ping_ipv4()375{376	ping_test $h1 192.0.2.34377}378 379test_qos_pfc()380{381	RET=0382 383	# 10M pool, each packet is 8K of payload + headers384	local pkts=$((_10MB / 8050))385	local size=$((pkts * 8050))386	local in0=$(ethtool_stats_get $swp1 rx_octets_prio_1)387	local out0=$(ethtool_stats_get $swp2 tx_octets_prio_1)388 389	$MZ $h1 -p 8000 -Q 1:111 -A 192.0.2.33 -B 192.0.2.34 \390		-a own -b $h2mac -c $pkts -t udp -q391	sleep 2392 393	local in1=$(ethtool_stats_get $swp1 rx_octets_prio_1)394	local out1=$(ethtool_stats_get $swp2 tx_octets_prio_1)395 396	local din=$((in1 - in0))397	local dout=$((out1 - out0))398 399	local pct_in=$((din * 100 / size))400 401	((pct_in > 95 && pct_in < 105))402	check_err $? "Relative ingress out of expected bounds, $pct_in% should be 100%"403 404	((dout == din))405	check_err $? "$((din - dout)) bytes out of $din ingressed got lost"406 407	log_test "PFC"408}409 410bail_on_lldpad "configure DCB" "configure Qdiscs"411 412trap cleanup EXIT413setup_prepare414setup_wait415tests_run416 417exit $EXIT_STATUS418