Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 #
0004 # A test for strict prioritization of traffic in the switch. Run two streams of
0005 # traffic, each through a different ingress port, one tagged with PCP of 1, the
0006 # other with PCP of 2. Both streams converge at one egress port, where they are
0007 # assigned TC of, respectively, 1 and 2, with strict priority configured between
0008 # them. In H3, we expect to see (almost) exclusively the high-priority traffic.
0009 #
0010 # Please see qos_mc_aware.sh for an explanation of why we use mausezahn and
0011 # counters instead of just running iperf3.
0012 #
0013 # +---------------------------+                 +-----------------------------+
0014 # | H1                        |                 |                          H2 |
0015 # |         $h1.111 +         |                 |         + $h2.222           |
0016 # |   192.0.2.33/28 |         |                 |         | 192.0.2.65/28     |
0017 # |   e-qos-map 0:1 |         |                 |         | e-qos-map 0:2     |
0018 # |                 |         |                 |         |                   |
0019 # |             $h1 +         |                 |         + $h2               |
0020 # +-----------------|---------+                 +---------|-------------------+
0021 #                   |                                     |
0022 # +-----------------|-------------------------------------|-------------------+
0023 # |           $swp1 +                                     + $swp2             |
0024 # |          >1Gbps |                                     | >1Gbps            |
0025 # | +---------------|-----------+              +----------|----------------+  |
0026 # | |     $swp1.111 +           |              |          + $swp2.222      |  |
0027 # | |                     BR111 |       SW     | BR222                     |  |
0028 # | |     $swp3.111 +           |              |          + $swp3.222      |  |
0029 # | +---------------|-----------+              +----------|----------------+  |
0030 # |                 \_____________________________________/                   |
0031 # |                                    |                                      |
0032 # |                                    + $swp3                                |
0033 # |                                    | 1Gbps bottleneck                     |
0034 # |                                    | ETS: (up n->tc n for n in 0..7)      |
0035 # |                                    |      strict priority                 |
0036 # +------------------------------------|--------------------------------------+
0037 #                                      |
0038 #                 +--------------------|--------------------+
0039 #                 |                    + $h3             H3 |
0040 #                 |                   / \                   |
0041 #                 |                  /   \                  |
0042 #                 |         $h3.111 +     + $h3.222         |
0043 #                 |  192.0.2.34/28          192.0.2.66/28   |
0044 #                 +-----------------------------------------+
0045 
0046 ALL_TESTS="
0047         ping_ipv4
0048         test_ets_strict
0049 "
0050 
0051 lib_dir=$(dirname $0)/../../../net/forwarding
0052 
0053 NUM_NETIFS=6
0054 source $lib_dir/lib.sh
0055 source $lib_dir/devlink_lib.sh
0056 source qos_lib.sh
0057 
0058 h1_create()
0059 {
0060         simple_if_init $h1
0061         mtu_set $h1 10000
0062 
0063         vlan_create $h1 111 v$h1 192.0.2.33/28
0064         ip link set dev $h1.111 type vlan egress-qos-map 0:1
0065 }
0066 
0067 h1_destroy()
0068 {
0069         vlan_destroy $h1 111
0070 
0071         mtu_restore $h1
0072         simple_if_fini $h1
0073 }
0074 
0075 h2_create()
0076 {
0077         simple_if_init $h2
0078         mtu_set $h2 10000
0079 
0080         vlan_create $h2 222 v$h2 192.0.2.65/28
0081         ip link set dev $h2.222 type vlan egress-qos-map 0:2
0082 }
0083 
0084 h2_destroy()
0085 {
0086         vlan_destroy $h2 222
0087 
0088         mtu_restore $h2
0089         simple_if_fini $h2
0090 }
0091 
0092 h3_create()
0093 {
0094         simple_if_init $h3
0095         mtu_set $h3 10000
0096 
0097         vlan_create $h3 111 v$h3 192.0.2.34/28
0098         vlan_create $h3 222 v$h3 192.0.2.66/28
0099 }
0100 
0101 h3_destroy()
0102 {
0103         vlan_destroy $h3 222
0104         vlan_destroy $h3 111
0105 
0106         mtu_restore $h3
0107         simple_if_fini $h3
0108 }
0109 
0110 switch_create()
0111 {
0112         ip link set dev $swp1 up
0113         mtu_set $swp1 10000
0114 
0115         ip link set dev $swp2 up
0116         mtu_set $swp2 10000
0117 
0118         # prio n -> TC n, strict scheduling
0119         lldptool -T -i $swp3 -V ETS-CFG up2tc=0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7
0120         lldptool -T -i $swp3 -V ETS-CFG tsa=$(
0121                         )"0:strict,"$(
0122                         )"1:strict,"$(
0123                         )"2:strict,"$(
0124                         )"3:strict,"$(
0125                         )"4:strict,"$(
0126                         )"5:strict,"$(
0127                         )"6:strict,"$(
0128                         )"7:strict"
0129         sleep 1
0130 
0131         ip link set dev $swp3 up
0132         mtu_set $swp3 10000
0133         ethtool -s $swp3 speed 1000 autoneg off
0134 
0135         vlan_create $swp1 111
0136         vlan_create $swp2 222
0137         vlan_create $swp3 111
0138         vlan_create $swp3 222
0139 
0140         ip link add name br111 up type bridge vlan_filtering 0
0141         ip link set dev $swp1.111 master br111
0142         ip link set dev $swp3.111 master br111
0143 
0144         ip link add name br222 up type bridge vlan_filtering 0
0145         ip link set dev $swp2.222 master br222
0146         ip link set dev $swp3.222 master br222
0147 
0148         # Make sure that ingress quotas are smaller than egress so that there is
0149         # room for both streams of traffic to be admitted to shared buffer.
0150         devlink_pool_size_thtype_save 0
0151         devlink_pool_size_thtype_set 0 dynamic 10000000
0152         devlink_pool_size_thtype_save 4
0153         devlink_pool_size_thtype_set 4 dynamic 10000000
0154 
0155         devlink_port_pool_th_save $swp1 0
0156         devlink_port_pool_th_set $swp1 0 6
0157         devlink_tc_bind_pool_th_save $swp1 1 ingress
0158         devlink_tc_bind_pool_th_set $swp1 1 ingress 0 6
0159 
0160         devlink_port_pool_th_save $swp2 0
0161         devlink_port_pool_th_set $swp2 0 6
0162         devlink_tc_bind_pool_th_save $swp2 2 ingress
0163         devlink_tc_bind_pool_th_set $swp2 2 ingress 0 6
0164 
0165         devlink_tc_bind_pool_th_save $swp3 1 egress
0166         devlink_tc_bind_pool_th_set $swp3 1 egress 4 7
0167         devlink_tc_bind_pool_th_save $swp3 2 egress
0168         devlink_tc_bind_pool_th_set $swp3 2 egress 4 7
0169         devlink_port_pool_th_save $swp3 4
0170         devlink_port_pool_th_set $swp3 4 7
0171 }
0172 
0173 switch_destroy()
0174 {
0175         devlink_port_pool_th_restore $swp3 4
0176         devlink_tc_bind_pool_th_restore $swp3 2 egress
0177         devlink_tc_bind_pool_th_restore $swp3 1 egress
0178 
0179         devlink_tc_bind_pool_th_restore $swp2 2 ingress
0180         devlink_port_pool_th_restore $swp2 0
0181 
0182         devlink_tc_bind_pool_th_restore $swp1 1 ingress
0183         devlink_port_pool_th_restore $swp1 0
0184 
0185         devlink_pool_size_thtype_restore 4
0186         devlink_pool_size_thtype_restore 0
0187 
0188         ip link del dev br222
0189         ip link del dev br111
0190 
0191         vlan_destroy $swp3 222
0192         vlan_destroy $swp3 111
0193         vlan_destroy $swp2 222
0194         vlan_destroy $swp1 111
0195 
0196         ethtool -s $swp3 autoneg on
0197         mtu_restore $swp3
0198         ip link set dev $swp3 down
0199         lldptool -T -i $swp3 -V ETS-CFG up2tc=0:0,1:0,2:0,3:0,4:0,5:0,6:0,7:0
0200 
0201         mtu_restore $swp2
0202         ip link set dev $swp2 down
0203 
0204         mtu_restore $swp1
0205         ip link set dev $swp1 down
0206 }
0207 
0208 setup_prepare()
0209 {
0210         h1=${NETIFS[p1]}
0211         swp1=${NETIFS[p2]}
0212 
0213         swp2=${NETIFS[p3]}
0214         h2=${NETIFS[p4]}
0215 
0216         swp3=${NETIFS[p5]}
0217         h3=${NETIFS[p6]}
0218 
0219         h3mac=$(mac_get $h3)
0220 
0221         vrf_prepare
0222 
0223         h1_create
0224         h2_create
0225         h3_create
0226         switch_create
0227 }
0228 
0229 cleanup()
0230 {
0231         pre_cleanup
0232 
0233         switch_destroy
0234         h3_destroy
0235         h2_destroy
0236         h1_destroy
0237 
0238         vrf_cleanup
0239 }
0240 
0241 ping_ipv4()
0242 {
0243         ping_test $h1 192.0.2.34 " from H1"
0244         ping_test $h2 192.0.2.66 " from H2"
0245 }
0246 
0247 rel()
0248 {
0249         local old=$1; shift
0250         local new=$1; shift
0251 
0252         bc <<< "
0253             scale=2
0254             ret = 100 * $new / $old
0255             if (ret > 0) { ret } else { 0 }
0256         "
0257 }
0258 
0259 test_ets_strict()
0260 {
0261         RET=0
0262 
0263         # Run high-prio traffic on its own.
0264         start_traffic $h2.222 192.0.2.65 192.0.2.66 $h3mac
0265         local -a rate_2
0266         rate_2=($(measure_rate $swp2 $h3 rx_octets_prio_2 "prio 2"))
0267         check_err $? "Could not get high enough prio-2 ingress rate"
0268         local rate_2_in=${rate_2[0]}
0269         local rate_2_eg=${rate_2[1]}
0270         stop_traffic # $h2.222
0271 
0272         # Start low-prio stream.
0273         start_traffic $h1.111 192.0.2.33 192.0.2.34 $h3mac
0274 
0275         local -a rate_1
0276         rate_1=($(measure_rate $swp1 $h3 rx_octets_prio_1 "prio 1"))
0277         check_err $? "Could not get high enough prio-1 ingress rate"
0278         local rate_1_in=${rate_1[0]}
0279         local rate_1_eg=${rate_1[1]}
0280 
0281         # High-prio and low-prio on their own should have about the same
0282         # throughput.
0283         local rel21=$(rel $rate_1_eg $rate_2_eg)
0284         check_err $(bc <<< "$rel21 < 95")
0285         check_err $(bc <<< "$rel21 > 105")
0286 
0287         # Start the high-prio stream--now both streams run.
0288         start_traffic $h2.222 192.0.2.65 192.0.2.66 $h3mac
0289         rate_3=($(measure_rate $swp2 $h3 rx_octets_prio_2 "prio 2 w/ 1"))
0290         check_err $? "Could not get high enough prio-2 ingress rate with prio-1"
0291         local rate_3_in=${rate_3[0]}
0292         local rate_3_eg=${rate_3[1]}
0293         stop_traffic # $h2.222
0294 
0295         stop_traffic # $h1.111
0296 
0297         # High-prio should have about the same throughput whether or not
0298         # low-prio is in the system.
0299         local rel32=$(rel $rate_2_eg $rate_3_eg)
0300         check_err $(bc <<< "$rel32 < 95")
0301 
0302         log_test "strict priority"
0303         echo "Ingress to switch:"
0304         echo "  p1 in rate            $(humanize $rate_1_in)"
0305         echo "  p2 in rate            $(humanize $rate_2_in)"
0306         echo "  p2 in rate w/ p1      $(humanize $rate_3_in)"
0307         echo "Egress from switch:"
0308         echo "  p1 eg rate            $(humanize $rate_1_eg)"
0309         echo "  p2 eg rate            $(humanize $rate_2_eg) ($rel21% of p1)"
0310         echo "  p2 eg rate w/ p1      $(humanize $rate_3_eg) ($rel32% of p2)"
0311 }
0312 
0313 trap cleanup EXIT
0314 
0315 setup_prepare
0316 setup_wait
0317 
0318 tests_run
0319 
0320 exit $EXIT_STATUS