1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# This test injects a 10-MB burst of traffic with VLAN tag and 802.1p priority 5# of 1. This stream is consistently prioritized as priority 1, is put to PG 6# buffer 1, and scheduled at TC 1. 7# 8# - the stream first ingresses through $swp1, where it is forwarded to $swp3 9# 10# - then it ingresses through $swp4. Here it is put to a lossless buffer and put 11# to a small pool ("PFC pool"). The traffic is forwarded to $swp2, which is 12# shaped, and thus the PFC pool eventually fills, therefore the headroom 13# fills, and $swp3 is paused. 14# 15# - since $swp3 now can't send traffic, the traffic ingressing $swp1 is kept at 16# a pool ("overflow pool"). The overflow pool needs to be large enough to 17# contain the whole burst. 18# 19# - eventually the PFC pool gets some traffic out, headroom therefore gets some 20# traffic to the pool, and $swp3 is unpaused again. This way the traffic is 21# gradually forwarded from the overflow pool, through the PFC pool, out of 22# $swp2, and eventually to $h2. 23# 24# - if PFC works, all lossless flow packets that ingress through $swp1 should 25# also be seen ingressing $h2. If it doesn't, there will be drops due to 26# discrepancy between the speeds of $swp1 and $h2. 27# 28# - it should all play out relatively quickly, so that SLL and HLL will not 29# 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# | | 1Gbps | | 1Gbps | 44# | | PFC:enabled=1 | | PFC:enabled=1 | 45# | +-|----------------------|-+ +-|------------------------+ | 46# | | + $swp1.111 $swp3.111 + | | + $swp4.111 | | 47# | | | | | | 48# | | BR1 | | BR2 | | 49# | | | | | | 50# | | | | + $swp2.111 | | 51# | +--------------------------+ +---------|----------------+ | 52# | | | 53# | iPOOL0: 500KB dynamic | | 54# | iPOOL1: 10MB static | | 55# | iPOOL2: 1MB static + $swp2 | 56# | ePOOL4: 500KB dynamic | iPOOL0 | 57# | ePOOL5: 10MB static | ePOOL6 | 58# | ePOOL6: "infinite" static | 200Mbps shaper | 59# +-------------------------------------------------------|-------------------+ 60# | 61# +---|-------------------+ 62# | + $h2 H2 | 63# | | | 64# | + $h2.111 | 65# | 192.0.2.34/28 | 66# +-----------------------+ 67# 68# iPOOL0+ePOOL4 is a helper pool for control traffic etc. 69# iPOOL1+ePOOL5 are overflow pools. 70# iPOOL2+ePOOL6 are PFC pools. 71 72ALL_TESTS=" 73 ping_ipv4 74 test_qos_pfc 75" 76 77lib_dir=$(dirname $0)/../../../net/forwarding 78 79NUM_NETIFS=6 80source $lib_dir/lib.sh 81source $lib_dir/devlink_lib.sh 82source qos_lib.sh 83 84_1KB=1000 85_100KB=$((100 * _1KB)) 86_500KB=$((500 * _1KB)) 87_1MB=$((1000 * _1KB)) 88_10MB=$((10 * _1MB)) 89 90h1_create() 91{ 92 simple_if_init $h1 93 mtu_set $h1 10000 94 95 vlan_create $h1 111 v$h1 192.0.2.33/28 96} 97 98h1_destroy() 99{ 100 vlan_destroy $h1 111 101 102 mtu_restore $h1 103 simple_if_fini $h1 104} 105 106h2_create() 107{ 108 simple_if_init $h2 109 mtu_set $h2 10000 110 111 vlan_create $h2 111 v$h2 192.0.2.34/28 112} 113 114h2_destroy() 115{ 116 vlan_destroy $h2 111 117 118 mtu_restore $h2 119 simple_if_fini $h2 120} 121 122switch_create() 123{ 124 local lanes_swp4 125 local pg1_size 126 127 # pools 128 # ----- 129 130 devlink_pool_size_thtype_save 0 131 devlink_pool_size_thtype_save 4 132 devlink_pool_size_thtype_save 1 133 devlink_pool_size_thtype_save 5 134 devlink_pool_size_thtype_save 2 135 devlink_pool_size_thtype_save 6 136 137 devlink_port_pool_th_save $swp1 1 138 devlink_port_pool_th_save $swp2 6 139 devlink_port_pool_th_save $swp3 5 140 devlink_port_pool_th_save $swp4 2 141 142 devlink_tc_bind_pool_th_save $swp1 1 ingress 143 devlink_tc_bind_pool_th_save $swp2 1 egress 144 devlink_tc_bind_pool_th_save $swp3 1 egress 145 devlink_tc_bind_pool_th_save $swp4 1 ingress 146 147 # Control traffic pools. Just reduce the size. Keep them dynamic so that 148 # we don't need to change all the uninteresting quotas. 149 devlink_pool_size_thtype_set 0 dynamic $_500KB 150 devlink_pool_size_thtype_set 4 dynamic $_500KB 151 152 # Overflow pools. 153 devlink_pool_size_thtype_set 1 static $_10MB 154 devlink_pool_size_thtype_set 5 static $_10MB 155 156 # PFC pools. As per the writ, the size of egress PFC pool should be 157 # infinice, but actually it just needs to be large enough to not matter 158 # in practice, so reuse the 10MB limit. 159 devlink_pool_size_thtype_set 2 static $_1MB 160 devlink_pool_size_thtype_set 6 static $_10MB 161 162 # $swp1 163 # ----- 164 165 ip link set dev $swp1 up 166 mtu_set $swp1 10000 167 vlan_create $swp1 111 168 ip link set dev $swp1.111 type vlan ingress-qos-map 0:0 1:1 169 170 devlink_port_pool_th_set $swp1 1 $_10MB 171 devlink_tc_bind_pool_th_set $swp1 1 ingress 1 $_10MB 172 173 # Configure qdisc so that we can configure PG and therefore pool 174 # assignment. 175 tc qdisc replace dev $swp1 root handle 1: \ 176 ets bands 8 strict 8 priomap 7 6 177 dcb buffer set dev $swp1 prio-buffer all:0 1:1 178 179 # $swp2 180 # ----- 181 182 ip link set dev $swp2 up 183 mtu_set $swp2 10000 184 vlan_create $swp2 111 185 ip link set dev $swp2.111 type vlan egress-qos-map 0:0 1:1 186 187 devlink_port_pool_th_set $swp2 6 $_10MB 188 devlink_tc_bind_pool_th_set $swp2 1 egress 6 $_10MB 189 190 # prio 0->TC0 (band 7), 1->TC1 (band 6). TC1 is shaped. 191 tc qdisc replace dev $swp2 root handle 1: \ 192 ets bands 8 strict 8 priomap 7 6 193 tc qdisc replace dev $swp2 parent 1:7 handle 17: \ 194 tbf rate 200Mbit burst 131072 limit 1M 195 196 # $swp3 197 # ----- 198 199 ip link set dev $swp3 up 200 mtu_set $swp3 10000 201 vlan_create $swp3 111 202 ip link set dev $swp3.111 type vlan egress-qos-map 0:0 1:1 203 204 devlink_port_pool_th_set $swp3 5 $_10MB 205 devlink_tc_bind_pool_th_set $swp3 1 egress 5 $_10MB 206 207 # prio 0->TC0 (band 7), 1->TC1 (band 6) 208 tc qdisc replace dev $swp3 root handle 1: \ 209 ets bands 8 strict 8 priomap 7 6 210 211 # Need to enable PFC so that PAUSE takes effect. Therefore need to put 212 # the lossless prio into a buffer of its own. Don't bother with buffer 213 # sizes though, there is not going to be any pressure in the "backward" 214 # direction. 215 dcb buffer set dev $swp3 prio-buffer all:0 1:1 216 dcb pfc set dev $swp3 prio-pfc all:off 1:on 217 218 # $swp4 219 # ----- 220 221 ip link set dev $swp4 up 222 mtu_set $swp4 10000 223 vlan_create $swp4 111 224 ip link set dev $swp4.111 type vlan ingress-qos-map 0:0 1:1 225 226 devlink_port_pool_th_set $swp4 2 $_1MB 227 devlink_tc_bind_pool_th_set $swp4 1 ingress 2 $_1MB 228 229 # Configure qdisc so that we can hand-tune headroom. 230 tc qdisc replace dev $swp4 root handle 1: \ 231 ets bands 8 strict 8 priomap 7 6 232 dcb buffer set dev $swp4 prio-buffer all:0 1:1 233 dcb pfc set dev $swp4 prio-pfc all:off 1:on 234 # PG0 will get autoconfigured to Xoff, give PG1 arbitrarily 100K, which 235 # is (-2*MTU) about 80K of delay provision. 236 pg1_size=$_100KB 237 238 setup_wait_dev_with_timeout $swp4 239 240 lanes_swp4=$(ethtool $swp4 | grep 'Lanes:') 241 lanes_swp4=${lanes_swp4#*"Lanes: "} 242 243 # 8-lane ports use two buffers among which the configured buffer 244 # is split, so double the size to get twice (20K + 80K). 245 if [[ $lanes_swp4 -eq 8 ]]; then 246 pg1_size=$((pg1_size * 2)) 247 fi 248 249 dcb buffer set dev $swp4 buffer-size all:0 1:$pg1_size 250 251 # bridges 252 # ------- 253 254 ip link add name br1 type bridge vlan_filtering 0 255 ip link set dev $swp1.111 master br1 256 ip link set dev $swp3.111 master br1 257 ip link set dev br1 up 258 259 ip link add name br2 type bridge vlan_filtering 0 260 ip link set dev $swp2.111 master br2 261 ip link set dev $swp4.111 master br2 262 ip link set dev br2 up 263} 264 265switch_destroy() 266{ 267 # Do this first so that we can reset the limits to values that are only 268 # valid for the original static / dynamic setting. 269 devlink_pool_size_thtype_restore 6 270 devlink_pool_size_thtype_restore 5 271 devlink_pool_size_thtype_restore 4 272 devlink_pool_size_thtype_restore 2 273 devlink_pool_size_thtype_restore 1 274 devlink_pool_size_thtype_restore 0 275 276 # bridges 277 # ------- 278 279 ip link set dev br2 down 280 ip link set dev $swp4.111 nomaster 281 ip link set dev $swp2.111 nomaster 282 ip link del dev br2 283 284 ip link set dev br1 down 285 ip link set dev $swp3.111 nomaster 286 ip link set dev $swp1.111 nomaster 287 ip link del dev br1 288 289 # $swp4 290 # ----- 291 292 dcb buffer set dev $swp4 buffer-size all:0 293 dcb pfc set dev $swp4 prio-pfc all:off 294 dcb buffer set dev $swp4 prio-buffer all:0 295 tc qdisc del dev $swp4 root 296 297 devlink_tc_bind_pool_th_restore $swp4 1 ingress 298 devlink_port_pool_th_restore $swp4 2 299 300 vlan_destroy $swp4 111 301 mtu_restore $swp4 302 ip link set dev $swp4 down 303 304 # $swp3 305 # ----- 306 307 dcb pfc set dev $swp3 prio-pfc all:off 308 dcb buffer set dev $swp3 prio-buffer all:0 309 tc qdisc del dev $swp3 root 310 311 devlink_tc_bind_pool_th_restore $swp3 1 egress 312 devlink_port_pool_th_restore $swp3 5 313 314 vlan_destroy $swp3 111 315 mtu_restore $swp3 316 ip link set dev $swp3 down 317 318 # $swp2 319 # ----- 320 321 tc qdisc del dev $swp2 parent 1:7 322 tc qdisc del dev $swp2 root 323 324 devlink_tc_bind_pool_th_restore $swp2 1 egress 325 devlink_port_pool_th_restore $swp2 6 326 327 vlan_destroy $swp2 111 328 mtu_restore $swp2 329 ip link set dev $swp2 down 330 331 # $swp1 332 # ----- 333 334 dcb buffer set dev $swp1 prio-buffer all:0 335 tc qdisc del dev $swp1 root 336 337 devlink_tc_bind_pool_th_restore $swp1 1 ingress 338 devlink_port_pool_th_restore $swp1 1 339 340 vlan_destroy $swp1 111 341 mtu_restore $swp1 342 ip link set dev $swp1 down 343} 344 345setup_prepare() 346{ 347 h1=${NETIFS[p1]} 348 swp1=${NETIFS[p2]} 349 350 swp2=${NETIFS[p3]} 351 h2=${NETIFS[p4]} 352 353 swp3=${NETIFS[p5]} 354 swp4=${NETIFS[p6]} 355 356 h2mac=$(mac_get $h2) 357 358 vrf_prepare 359 360 h1_create 361 h2_create 362 switch_create 363} 364 365cleanup() 366{ 367 pre_cleanup 368 369 switch_destroy 370 h2_destroy 371 h1_destroy 372 373 vrf_cleanup 374} 375 376ping_ipv4() 377{ 378 ping_test $h1 192.0.2.34 379} 380 381test_qos_pfc() 382{ 383 RET=0 384 385 # 10M pool, each packet is 8K of payload + headers 386 local pkts=$((_10MB / 8050)) 387 local size=$((pkts * 8050)) 388 local in0=$(ethtool_stats_get $swp1 rx_octets_prio_1) 389 local out0=$(ethtool_stats_get $swp2 tx_octets_prio_1) 390 391 $MZ $h1 -p 8000 -Q 1:111 -A 192.0.2.33 -B 192.0.2.34 \ 392 -a own -b $h2mac -c $pkts -t udp -q 393 sleep 2 394 395 local in1=$(ethtool_stats_get $swp1 rx_octets_prio_1) 396 local out1=$(ethtool_stats_get $swp2 tx_octets_prio_1) 397 398 local din=$((in1 - in0)) 399 local dout=$((out1 - out0)) 400 401 local pct_in=$((din * 100 / size)) 402 403 ((pct_in > 95 && pct_in < 105)) 404 check_err $? "Relative ingress out of expected bounds, $pct_in% should be 100%" 405 406 ((dout == din)) 407 check_err $? "$((din - dout)) bytes out of $din ingressed got lost" 408 409 log_test "PFC" 410} 411 412trap cleanup EXIT 413 414bail_on_lldpad 415setup_prepare 416setup_wait 417tests_run 418 419exit $EXIT_STATUS 420