1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# A test for switch behavior under MC overload. An issue in Spectrum chips 5# causes throughput of UC traffic to drop severely when a switch is under heavy 6# MC load. This issue can be overcome by putting the switch to MC-aware mode. 7# This test verifies that UC performance stays intact even as the switch is 8# under MC flood, and therefore that the MC-aware mode is enabled and correctly 9# configured. 10# 11# Because mlxsw throttles CPU port, the traffic can't actually reach userspace 12# at full speed. That makes it impossible to use iperf3 to simply measure the 13# throughput, because many packets (that reach $h3) don't get to the kernel at 14# all even in UDP mode (the situation is even worse in TCP mode, where one can't 15# hope to see more than a couple Mbps). 16# 17# So instead we send traffic with mausezahn and use RX ethtool counters at $h3. 18# Multicast traffic is untagged, unicast traffic is tagged with PCP 1. Therefore 19# each gets a different priority and we can use per-prio ethtool counters to 20# measure the throughput. In order to avoid prioritizing unicast traffic, prio 21# qdisc is installed on $swp3 and maps all priorities to the same band #7 (and 22# thus TC 0). 23# 24# Mausezahn can't actually saturate the links unless it's using large frames. 25# Thus we set MTU to 10K on all involved interfaces. Then both unicast and 26# multicast traffic uses 8K frames. 27# 28# +---------------------------+ +----------------------------------+ 29# | H1 | | H2 | 30# | | | unicast --> + $h2.111 | 31# | multicast | | traffic | 192.0.2.129/28 | 32# | traffic | | | e-qos-map 0:1 | 33# | $h1 + <----- | | | | 34# | 192.0.2.65/28 | | | + $h2 | 35# +---------------|-----------+ +--------------|-------------------+ 36# | | 37# +---------------|---------------------------------------|-------------------+ 38# | $swp1 + + $swp2 | 39# | >1Gbps | | >1Gbps | 40# | +-------------|------+ +----------|----------------+ | 41# | | $swp1.1 + | | + $swp2.111 | | 42# | | BR1 | SW | BR111 | | 43# | | $swp3.1 + | | + $swp3.111 | | 44# | +-------------|------+ +----------|----------------+ | 45# | \_______________________________________/ | 46# | | | 47# | + $swp3 | 48# | | 1Gbps bottleneck | 49# | | prio qdisc: {0..7} -> 7 | 50# +------------------------------------|--------------------------------------+ 51# | 52# +--|-----------------+ 53# | + $h3 H3 | 54# | | 192.0.2.66/28 | 55# | | | 56# | + $h3.111 | 57# | 192.0.2.130/28 | 58# +--------------------+ 59 60ALL_TESTS=" 61 ping_ipv4 62 test_mc_aware 63 test_uc_aware 64" 65 66lib_dir=$(dirname $0)/../../../net/forwarding 67 68NUM_NETIFS=6 69source $lib_dir/lib.sh 70source $lib_dir/devlink_lib.sh 71source qos_lib.sh 72 73h1_create() 74{ 75 simple_if_init $h1 192.0.2.65/28 76 mtu_set $h1 10000 77} 78 79h1_destroy() 80{ 81 mtu_restore $h1 82 simple_if_fini $h1 192.0.2.65/28 83} 84 85h2_create() 86{ 87 simple_if_init $h2 88 mtu_set $h2 10000 89 90 vlan_create $h2 111 v$h2 192.0.2.129/28 91 ip link set dev $h2.111 type vlan egress-qos-map 0:1 92} 93 94h2_destroy() 95{ 96 vlan_destroy $h2 111 97 98 mtu_restore $h2 99 simple_if_fini $h2 100} 101 102h3_create() 103{ 104 simple_if_init $h3 192.0.2.66/28 105 mtu_set $h3 10000 106 107 vlan_create $h3 111 v$h3 192.0.2.130/28 108} 109 110h3_destroy() 111{ 112 vlan_destroy $h3 111 113 114 mtu_restore $h3 115 simple_if_fini $h3 192.0.2.66/28 116} 117 118switch_create() 119{ 120 ip link set dev $swp1 up 121 mtu_set $swp1 10000 122 123 ip link set dev $swp2 up 124 mtu_set $swp2 10000 125 126 ip link set dev $swp3 up 127 mtu_set $swp3 10000 128 129 vlan_create $swp2 111 130 vlan_create $swp3 111 131 132 tc qdisc replace dev $swp3 root handle 3: tbf rate 1gbit \ 133 burst 128K limit 1G 134 tc qdisc replace dev $swp3 parent 3:3 handle 33: \ 135 prio bands 8 priomap 7 7 7 7 7 7 7 7 136 137 ip link add name br1 type bridge vlan_filtering 0 138 ip link set dev br1 up 139 ip link set dev $swp1 master br1 140 ip link set dev $swp3 master br1 141 142 ip link add name br111 type bridge vlan_filtering 0 143 ip link set dev br111 up 144 ip link set dev $swp2.111 master br111 145 ip link set dev $swp3.111 master br111 146 147 # Make sure that ingress quotas are smaller than egress so that there is 148 # room for both streams of traffic to be admitted to shared buffer. 149 devlink_port_pool_th_save $swp1 0 150 devlink_port_pool_th_set $swp1 0 5 151 devlink_tc_bind_pool_th_save $swp1 0 ingress 152 devlink_tc_bind_pool_th_set $swp1 0 ingress 0 5 153 154 devlink_port_pool_th_save $swp2 0 155 devlink_port_pool_th_set $swp2 0 5 156 devlink_tc_bind_pool_th_save $swp2 1 ingress 157 devlink_tc_bind_pool_th_set $swp2 1 ingress 0 5 158 159 devlink_port_pool_th_save $swp3 4 160 devlink_port_pool_th_set $swp3 4 12 161} 162 163switch_destroy() 164{ 165 devlink_port_pool_th_restore $swp3 4 166 167 devlink_tc_bind_pool_th_restore $swp2 1 ingress 168 devlink_port_pool_th_restore $swp2 0 169 170 devlink_tc_bind_pool_th_restore $swp1 0 ingress 171 devlink_port_pool_th_restore $swp1 0 172 173 ip link del dev br111 174 ip link del dev br1 175 176 tc qdisc del dev $swp3 parent 3:3 handle 33: 177 tc qdisc del dev $swp3 root handle 3: 178 179 vlan_destroy $swp3 111 180 vlan_destroy $swp2 111 181 182 mtu_restore $swp3 183 ip link set dev $swp3 down 184 185 mtu_restore $swp2 186 ip link set dev $swp2 down 187 188 mtu_restore $swp1 189 ip link set dev $swp1 down 190} 191 192setup_prepare() 193{ 194 h1=${NETIFS[p1]} 195 swp1=${NETIFS[p2]} 196 197 swp2=${NETIFS[p3]} 198 h2=${NETIFS[p4]} 199 200 swp3=${NETIFS[p5]} 201 h3=${NETIFS[p6]} 202 203 h3mac=$(mac_get $h3) 204 205 vrf_prepare 206 207 h1_create 208 h2_create 209 h3_create 210 switch_create 211} 212 213cleanup() 214{ 215 pre_cleanup 216 217 switch_destroy 218 h3_destroy 219 h2_destroy 220 h1_destroy 221 222 vrf_cleanup 223} 224 225ping_ipv4() 226{ 227 ping_test $h2 192.0.2.130 228} 229 230test_mc_aware() 231{ 232 RET=0 233 234 local -a uc_rate 235 start_traffic $h2.111 192.0.2.129 192.0.2.130 $h3mac 236 uc_rate=($(measure_rate $swp2 $h3 rx_octets_prio_1 "UC-only")) 237 check_err $? "Could not get high enough UC-only ingress rate" 238 stop_traffic 239 local ucth1=${uc_rate[1]} 240 241 start_traffic $h1 192.0.2.65 bc bc 242 243 local d0=$(date +%s) 244 local t0=$(ethtool_stats_get $h3 rx_octets_prio_0) 245 local u0=$(ethtool_stats_get $swp1 rx_octets_prio_0) 246 247 local -a uc_rate_2 248 start_traffic $h2.111 192.0.2.129 192.0.2.130 $h3mac 249 uc_rate_2=($(measure_rate $swp2 $h3 rx_octets_prio_1 "UC+MC")) 250 check_err $? "Could not get high enough UC+MC ingress rate" 251 stop_traffic 252 local ucth2=${uc_rate_2[1]} 253 254 local d1=$(date +%s) 255 local t1=$(ethtool_stats_get $h3 rx_octets_prio_0) 256 local u1=$(ethtool_stats_get $swp1 rx_octets_prio_0) 257 258 local deg=$(bc <<< " 259 scale=2 260 ret = 100 * ($ucth1 - $ucth2) / $ucth1 261 if (ret > 0) { ret } else { 0 } 262 ") 263 264 # Minimum shaper of 200Mbps on MC TCs should cause about 20% of 265 # degradation on 1Gbps link. 266 check_err $(bc <<< "$deg < 15") "Minimum shaper not in effect" 267 check_err $(bc <<< "$deg > 25") "MC traffic degrades UC performance too much" 268 269 local interval=$((d1 - d0)) 270 local mc_ir=$(rate $u0 $u1 $interval) 271 local mc_er=$(rate $t0 $t1 $interval) 272 273 stop_traffic 274 275 log_test "UC performance under MC overload" 276 277 echo "UC-only throughput $(humanize $ucth1)" 278 echo "UC+MC throughput $(humanize $ucth2)" 279 echo "Degradation $deg %" 280 echo 281 echo "Full report:" 282 echo " UC only:" 283 echo " ingress UC throughput $(humanize ${uc_rate[0]})" 284 echo " egress UC throughput $(humanize ${uc_rate[1]})" 285 echo " UC+MC:" 286 echo " ingress UC throughput $(humanize ${uc_rate_2[0]})" 287 echo " egress UC throughput $(humanize ${uc_rate_2[1]})" 288 echo " ingress MC throughput $(humanize $mc_ir)" 289 echo " egress MC throughput $(humanize $mc_er)" 290 echo 291} 292 293test_uc_aware() 294{ 295 RET=0 296 297 start_traffic $h2.111 192.0.2.129 192.0.2.130 $h3mac 298 299 local d0=$(date +%s) 300 local t0=$(ethtool_stats_get $h3 rx_octets_prio_1) 301 local u0=$(ethtool_stats_get $swp2 rx_octets_prio_1) 302 sleep 1 303 304 local attempts=50 305 local passes=0 306 local i 307 308 for ((i = 0; i < attempts; ++i)); do 309 if $ARPING -c 1 -I $h1 -b 192.0.2.66 -q -w 1; then 310 ((passes++)) 311 fi 312 313 sleep 0.1 314 done 315 316 local d1=$(date +%s) 317 local t1=$(ethtool_stats_get $h3 rx_octets_prio_1) 318 local u1=$(ethtool_stats_get $swp2 rx_octets_prio_1) 319 320 local interval=$((d1 - d0)) 321 local uc_ir=$(rate $u0 $u1 $interval) 322 local uc_er=$(rate $t0 $t1 $interval) 323 324 ((attempts == passes)) 325 check_err $? 326 327 stop_traffic 328 329 log_test "MC performance under UC overload" 330 echo " ingress UC throughput $(humanize ${uc_ir})" 331 echo " egress UC throughput $(humanize ${uc_er})" 332 echo " sent $attempts BC ARPs, got $passes responses" 333} 334 335trap cleanup EXIT 336 337setup_prepare 338setup_wait 339 340tests_run 341 342exit $EXIT_STATUS 343