1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3# 4# A test for strict prioritization of traffic in the switch. Run two streams of 5# traffic, each through a different ingress port, one tagged with PCP of 1, the 6# other with PCP of 2. Both streams converge at one egress port, where they are 7# assigned TC of, respectively, 1 and 2, with strict priority configured between 8# them. In H3, we expect to see (almost) exclusively the high-priority traffic. 9# 10# Please see qos_mc_aware.sh for an explanation of why we use mausezahn and 11# counters instead of just running iperf3. 12# 13# +---------------------------+ +-----------------------------+ 14# | H1 | | H2 | 15# | $h1.111 + | | + $h2.222 | 16# | 192.0.2.33/28 | | | | 192.0.2.65/28 | 17# | e-qos-map 0:1 | | | | e-qos-map 0:2 | 18# | | | | | | 19# | $h1 + | | + $h2 | 20# +-----------------|---------+ +---------|-------------------+ 21# | | 22# +-----------------|-------------------------------------|-------------------+ 23# | $swp1 + + $swp2 | 24# | >1Gbps | | >1Gbps | 25# | +---------------|-----------+ +----------|----------------+ | 26# | | $swp1.111 + | | + $swp2.222 | | 27# | | BR111 | SW | BR222 | | 28# | | $swp3.111 + | | + $swp3.222 | | 29# | +---------------|-----------+ +----------|----------------+ | 30# | \_____________________________________/ | 31# | | | 32# | + $swp3 | 33# | | 1Gbps bottleneck | 34# | | ETS: (up n->tc n for n in 0..7) | 35# | | strict priority | 36# +------------------------------------|--------------------------------------+ 37# | 38# +--------------------|--------------------+ 39# | + $h3 H3 | 40# | / \ | 41# | / \ | 42# | $h3.111 + + $h3.222 | 43# | 192.0.2.34/28 192.0.2.66/28 | 44# +-----------------------------------------+ 45 46ALL_TESTS=" 47 ping_ipv4 48 test_ets_strict 49" 50 51lib_dir=$(dirname $0)/../../../net/forwarding 52 53NUM_NETIFS=6 54source $lib_dir/lib.sh 55source $lib_dir/devlink_lib.sh 56source qos_lib.sh 57 58h1_create() 59{ 60 simple_if_init $h1 61 mtu_set $h1 10000 62 63 vlan_create $h1 111 v$h1 192.0.2.33/28 64 ip link set dev $h1.111 type vlan egress-qos-map 0:1 65} 66 67h1_destroy() 68{ 69 vlan_destroy $h1 111 70 71 mtu_restore $h1 72 simple_if_fini $h1 73} 74 75h2_create() 76{ 77 simple_if_init $h2 78 mtu_set $h2 10000 79 80 vlan_create $h2 222 v$h2 192.0.2.65/28 81 ip link set dev $h2.222 type vlan egress-qos-map 0:2 82} 83 84h2_destroy() 85{ 86 vlan_destroy $h2 222 87 88 mtu_restore $h2 89 simple_if_fini $h2 90} 91 92h3_create() 93{ 94 simple_if_init $h3 95 mtu_set $h3 10000 96 97 vlan_create $h3 111 v$h3 192.0.2.34/28 98 vlan_create $h3 222 v$h3 192.0.2.66/28 99} 100 101h3_destroy() 102{ 103 vlan_destroy $h3 222 104 vlan_destroy $h3 111 105 106 mtu_restore $h3 107 simple_if_fini $h3 108} 109 110switch_create() 111{ 112 ip link set dev $swp1 up 113 mtu_set $swp1 10000 114 115 ip link set dev $swp2 up 116 mtu_set $swp2 10000 117 118 # prio n -> TC n, strict scheduling 119 lldptool -T -i $swp3 -V ETS-CFG up2tc=0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7 120 lldptool -T -i $swp3 -V ETS-CFG tsa=$( 121 )"0:strict,"$( 122 )"1:strict,"$( 123 )"2:strict,"$( 124 )"3:strict,"$( 125 )"4:strict,"$( 126 )"5:strict,"$( 127 )"6:strict,"$( 128 )"7:strict" 129 sleep 1 130 131 ip link set dev $swp3 up 132 mtu_set $swp3 10000 133 ethtool -s $swp3 speed 1000 autoneg off 134 135 vlan_create $swp1 111 136 vlan_create $swp2 222 137 vlan_create $swp3 111 138 vlan_create $swp3 222 139 140 ip link add name br111 up type bridge vlan_filtering 0 141 ip link set dev $swp1.111 master br111 142 ip link set dev $swp3.111 master br111 143 144 ip link add name br222 up type bridge vlan_filtering 0 145 ip link set dev $swp2.222 master br222 146 ip link set dev $swp3.222 master br222 147 148 # Make sure that ingress quotas are smaller than egress so that there is 149 # room for both streams of traffic to be admitted to shared buffer. 150 devlink_pool_size_thtype_set 0 dynamic 10000000 151 devlink_pool_size_thtype_set 4 dynamic 10000000 152 153 devlink_port_pool_th_set $swp1 0 6 154 devlink_tc_bind_pool_th_set $swp1 1 ingress 0 6 155 156 devlink_port_pool_th_set $swp2 0 6 157 devlink_tc_bind_pool_th_set $swp2 2 ingress 0 6 158 159 devlink_tc_bind_pool_th_set $swp3 1 egress 4 7 160 devlink_tc_bind_pool_th_set $swp3 2 egress 4 7 161 devlink_port_pool_th_set $swp3 4 7 162} 163 164switch_destroy() 165{ 166 devlink_port_pool_th_restore $swp3 4 167 devlink_tc_bind_pool_th_restore $swp3 2 egress 168 devlink_tc_bind_pool_th_restore $swp3 1 egress 169 170 devlink_tc_bind_pool_th_restore $swp2 2 ingress 171 devlink_port_pool_th_restore $swp2 0 172 173 devlink_tc_bind_pool_th_restore $swp1 1 ingress 174 devlink_port_pool_th_restore $swp1 0 175 176 devlink_pool_size_thtype_restore 4 177 devlink_pool_size_thtype_restore 0 178 179 ip link del dev br222 180 ip link del dev br111 181 182 vlan_destroy $swp3 222 183 vlan_destroy $swp3 111 184 vlan_destroy $swp2 222 185 vlan_destroy $swp1 111 186 187 ethtool -s $swp3 autoneg on 188 mtu_restore $swp3 189 ip link set dev $swp3 down 190 lldptool -T -i $swp3 -V ETS-CFG up2tc=0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0 191 192 mtu_restore $swp2 193 ip link set dev $swp2 down 194 195 mtu_restore $swp1 196 ip link set dev $swp1 down 197} 198 199setup_prepare() 200{ 201 h1=${NETIFS[p1]} 202 swp1=${NETIFS[p2]} 203 204 swp2=${NETIFS[p3]} 205 h2=${NETIFS[p4]} 206 207 swp3=${NETIFS[p5]} 208 h3=${NETIFS[p6]} 209 210 h3mac=$(mac_get $h3) 211 212 vrf_prepare 213 214 h1_create 215 h2_create 216 h3_create 217 switch_create 218} 219 220cleanup() 221{ 222 pre_cleanup 223 224 switch_destroy 225 h3_destroy 226 h2_destroy 227 h1_destroy 228 229 vrf_cleanup 230} 231 232ping_ipv4() 233{ 234 ping_test $h1 192.0.2.34 " from H1" 235 ping_test $h2 192.0.2.66 " from H2" 236} 237 238rel() 239{ 240 local old=$1; shift 241 local new=$1; shift 242 243 bc <<< " 244 scale=2 245 ret = 100 * $new / $old 246 if (ret > 0) { ret } else { 0 } 247 " 248} 249 250test_ets_strict() 251{ 252 RET=0 253 254 # Run high-prio traffic on its own. 255 start_traffic $h2.222 192.0.2.65 192.0.2.66 $h3mac 256 local -a rate_2 257 rate_2=($(measure_rate $swp2 $h3 rx_octets_prio_2 "prio 2")) 258 check_err $? "Could not get high enough prio-2 ingress rate" 259 local rate_2_in=${rate_2[0]} 260 local rate_2_eg=${rate_2[1]} 261 stop_traffic # $h2.222 262 263 # Start low-prio stream. 264 start_traffic $h1.111 192.0.2.33 192.0.2.34 $h3mac 265 266 local -a rate_1 267 rate_1=($(measure_rate $swp1 $h3 rx_octets_prio_1 "prio 1")) 268 check_err $? "Could not get high enough prio-1 ingress rate" 269 local rate_1_in=${rate_1[0]} 270 local rate_1_eg=${rate_1[1]} 271 272 # High-prio and low-prio on their own should have about the same 273 # throughput. 274 local rel21=$(rel $rate_1_eg $rate_2_eg) 275 check_err $(bc <<< "$rel21 < 95") 276 check_err $(bc <<< "$rel21 > 105") 277 278 # Start the high-prio stream--now both streams run. 279 start_traffic $h2.222 192.0.2.65 192.0.2.66 $h3mac 280 rate_3=($(measure_rate $swp2 $h3 rx_octets_prio_2 "prio 2 w/ 1")) 281 check_err $? "Could not get high enough prio-2 ingress rate with prio-1" 282 local rate_3_in=${rate_3[0]} 283 local rate_3_eg=${rate_3[1]} 284 stop_traffic # $h2.222 285 286 stop_traffic # $h1.111 287 288 # High-prio should have about the same throughput whether or not 289 # low-prio is in the system. 290 local rel32=$(rel $rate_2_eg $rate_3_eg) 291 check_err $(bc <<< "$rel32 < 95") 292 293 log_test "strict priority" 294 echo "Ingress to switch:" 295 echo " p1 in rate $(humanize $rate_1_in)" 296 echo " p2 in rate $(humanize $rate_2_in)" 297 echo " p2 in rate w/ p1 $(humanize $rate_3_in)" 298 echo "Egress from switch:" 299 echo " p1 eg rate $(humanize $rate_1_eg)" 300 echo " p2 eg rate $(humanize $rate_2_eg) ($rel21% of p1)" 301 echo " p2 eg rate w/ p1 $(humanize $rate_3_eg) ($rel32% of p2)" 302} 303 304trap cleanup EXIT 305 306setup_prepare 307setup_wait 308 309tests_run 310 311exit $EXIT_STATUS 312