Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 ALL_TESTS="
0005         test_defaults
0006         test_dcb_ets
0007         test_mtu
0008         test_pfc
0009         test_int_buf
0010         test_tc_priomap
0011         test_tc_mtu
0012         test_tc_sizes
0013         test_tc_int_buf
0014 "
0015 
0016 lib_dir=$(dirname $0)/../../../net/forwarding
0017 
0018 NUM_NETIFS=0
0019 source $lib_dir/lib.sh
0020 source $lib_dir/devlink_lib.sh
0021 source qos_lib.sh
0022 
0023 swp=$NETIF_NO_CABLE
0024 
0025 cleanup()
0026 {
0027         pre_cleanup
0028 }
0029 
0030 get_prio_pg()
0031 {
0032         # Produces a string of numbers "<B0> <B1> ... <B7> ", where BX is number
0033         # of buffer that priority X is mapped to.
0034         dcb -j buffer show dev $swp |
0035                 jq -r '[.prio_buffer | .[] | tostring + " "] | add'
0036 }
0037 
0038 get_prio_pfc()
0039 {
0040         # Produces a string of numbers "<P0> <P1> ... <P7> ", where PX denotes
0041         # whether priority X has PFC enabled (the value is 1) or disabled (0).
0042         dcb -j pfc show dev $swp |
0043                 jq -r '[.prio_pfc | .[] | if . then "1 " else "0 " end] | add'
0044 }
0045 
0046 get_prio_tc()
0047 {
0048         # Produces a string of numbers "<T0> <T1> ... <T7> ", where TC is number
0049         # of TC that priority X is mapped to.
0050         dcb -j ets show dev $swp |
0051                 jq -r '[.prio_tc | .[] | tostring + " "] | add'
0052 }
0053 
0054 get_buf_size()
0055 {
0056         local idx=$1; shift
0057 
0058         dcb -j buffer show dev $swp | jq ".buffer_size[$idx]"
0059 }
0060 
0061 get_tot_size()
0062 {
0063         dcb -j buffer show dev $swp | jq '.total_size'
0064 }
0065 
0066 check_prio_pg()
0067 {
0068         local expect=$1; shift
0069 
0070         local current=$(get_prio_pg)
0071         test "$current" = "$expect"
0072         check_err $? "prio2buffer is '$current', expected '$expect'"
0073 }
0074 
0075 check_prio_pfc()
0076 {
0077         local expect=$1; shift
0078 
0079         local current=$(get_prio_pfc)
0080         test "$current" = "$expect"
0081         check_err $? "prio PFC is '$current', expected '$expect'"
0082 }
0083 
0084 check_prio_tc()
0085 {
0086         local expect=$1; shift
0087 
0088         local current=$(get_prio_tc)
0089         test "$current" = "$expect"
0090         check_err $? "prio_tc is '$current', expected '$expect'"
0091 }
0092 
0093 __check_buf_size()
0094 {
0095         local idx=$1; shift
0096         local expr=$1; shift
0097         local what=$1; shift
0098 
0099         local current=$(get_buf_size $idx)
0100         ((current $expr))
0101         check_err $? "${what}buffer $idx size is '$current', expected '$expr'"
0102         echo $current
0103 }
0104 
0105 check_buf_size()
0106 {
0107         __check_buf_size "$@" > /dev/null
0108 }
0109 
0110 test_defaults()
0111 {
0112         RET=0
0113 
0114         check_prio_pg "0 0 0 0 0 0 0 0 "
0115         check_prio_tc "0 0 0 0 0 0 0 0 "
0116         check_prio_pfc "0 0 0 0 0 0 0 0 "
0117 
0118         log_test "Default headroom configuration"
0119 }
0120 
0121 test_dcb_ets()
0122 {
0123         RET=0
0124 
0125         dcb ets set dev $swp prio-tc 0:0 1:2 2:4 3:6 4:1 5:3 6:5 7:7
0126 
0127         check_prio_pg "0 2 4 6 1 3 5 7 "
0128         check_prio_tc "0 2 4 6 1 3 5 7 "
0129         check_prio_pfc "0 0 0 0 0 0 0 0 "
0130 
0131         dcb ets set dev $swp prio-tc all:0
0132 
0133         check_prio_pg "0 0 0 0 0 0 0 0 "
0134         check_prio_tc "0 0 0 0 0 0 0 0 "
0135 
0136         dcb buffer set dev $swp prio-buffer 0:1 1:3 2:5 3:7 4:0 5:2 6:4 7:6 2>/dev/null
0137         check_fail $? "prio2buffer accepted in DCB mode"
0138 
0139         log_test "Configuring headroom through ETS"
0140 }
0141 
0142 test_mtu()
0143 {
0144         local what=$1; shift
0145         local buf0size_2
0146         local buf0size
0147 
0148         RET=0
0149         buf0size=$(__check_buf_size 0 "> 0")
0150 
0151         mtu_set $swp 3000
0152         buf0size_2=$(__check_buf_size 0 "> $buf0size" "MTU 3000: ")
0153         mtu_restore $swp
0154 
0155         mtu_set $swp 6000
0156         check_buf_size 0 "> $buf0size_2" "MTU 6000: "
0157         mtu_restore $swp
0158 
0159         check_buf_size 0 "== $buf0size"
0160 
0161         log_test "${what}MTU impacts buffer size"
0162 }
0163 
0164 test_tc_mtu()
0165 {
0166         # In TC mode, MTU still impacts the threshold below which a buffer is
0167         # not permitted to go.
0168 
0169         tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
0170         test_mtu "TC: "
0171         tc qdisc delete dev $swp root
0172 }
0173 
0174 test_pfc()
0175 {
0176         RET=0
0177 
0178         dcb ets set dev $swp prio-tc all:0 5:1 6:2 7:3
0179 
0180         local buf0size=$(get_buf_size 0)
0181         local buf1size=$(get_buf_size 1)
0182         local buf2size=$(get_buf_size 2)
0183         local buf3size=$(get_buf_size 3)
0184         check_buf_size 0 "> 0"
0185         check_buf_size 1 "> 0"
0186         check_buf_size 2 "> 0"
0187         check_buf_size 3 "> 0"
0188         check_buf_size 4 "== 0"
0189         check_buf_size 5 "== 0"
0190         check_buf_size 6 "== 0"
0191         check_buf_size 7 "== 0"
0192 
0193         log_test "Buffer size sans PFC"
0194 
0195         RET=0
0196 
0197         dcb pfc set dev $swp prio-pfc all:off 5:on 6:on 7:on delay 0
0198 
0199         check_prio_pg "0 0 0 0 0 1 2 3 "
0200         check_prio_pfc "0 0 0 0 0 1 1 1 "
0201         check_buf_size 0 "== $buf0size"
0202         check_buf_size 1 "> $buf1size"
0203         check_buf_size 2 "> $buf2size"
0204         check_buf_size 3 "> $buf3size"
0205 
0206         local buf1size=$(get_buf_size 1)
0207         check_buf_size 2 "== $buf1size"
0208         check_buf_size 3 "== $buf1size"
0209 
0210         log_test "PFC: Cable length 0"
0211 
0212         RET=0
0213 
0214         dcb pfc set dev $swp delay 1000
0215 
0216         check_buf_size 0 "== $buf0size"
0217         check_buf_size 1 "> $buf1size"
0218         check_buf_size 2 "> $buf1size"
0219         check_buf_size 3 "> $buf1size"
0220 
0221         log_test "PFC: Cable length 1000"
0222 
0223         RET=0
0224 
0225         dcb pfc set dev $swp prio-pfc all:off delay 0
0226         dcb ets set dev $swp prio-tc all:0
0227 
0228         check_prio_pg "0 0 0 0 0 0 0 0 "
0229         check_prio_tc "0 0 0 0 0 0 0 0 "
0230         check_buf_size 0 "> 0"
0231         check_buf_size 1 "== 0"
0232         check_buf_size 2 "== 0"
0233         check_buf_size 3 "== 0"
0234         check_buf_size 4 "== 0"
0235         check_buf_size 5 "== 0"
0236         check_buf_size 6 "== 0"
0237         check_buf_size 7 "== 0"
0238 
0239         log_test "PFC: Restore defaults"
0240 }
0241 
0242 test_tc_priomap()
0243 {
0244         RET=0
0245 
0246         dcb ets set dev $swp prio-tc 0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7
0247         check_prio_pg "0 1 2 3 4 5 6 7 "
0248 
0249         tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
0250         check_prio_pg "0 0 0 0 0 0 0 0 "
0251 
0252         dcb buffer set dev $swp prio-buffer 0:1 1:3 2:5 3:7 4:0 5:2 6:4 7:6
0253         check_prio_pg "1 3 5 7 0 2 4 6 "
0254 
0255         tc qdisc delete dev $swp root
0256         check_prio_pg "0 1 2 3 4 5 6 7 "
0257 
0258         # Clean up.
0259         tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
0260         dcb buffer set dev $swp prio-buffer all:0
0261         tc qdisc delete dev $swp root
0262         dcb ets set dev $swp prio-tc all:0
0263 
0264         log_test "TC: priomap"
0265 }
0266 
0267 test_tc_sizes()
0268 {
0269         local cell_size=$(devlink_cell_size_get)
0270         local size=$((cell_size * 1000))
0271 
0272         RET=0
0273 
0274         dcb buffer set dev $swp buffer-size all:0 0:$size 2>/dev/null
0275         check_fail $? "buffer_size should fail before qdisc is added"
0276 
0277         tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
0278 
0279         dcb buffer set dev $swp buffer-size all:0 0:$size
0280         check_err $? "buffer_size should pass after qdisc is added"
0281         check_buf_size 0 "== $size" "set size: "
0282 
0283         mtu_set $swp 6000
0284         check_buf_size 0 "== $size" "set MTU: "
0285         mtu_restore $swp
0286 
0287         dcb buffer set dev $swp buffer-size all:0
0288 
0289         # After replacing the qdisc for the same kind, buffer_size still has to
0290         # work.
0291         tc qdisc replace dev $swp root handle 1: bfifo limit 1M
0292 
0293         dcb buffer set dev $swp buffer-size all:0 0:$size
0294         check_buf_size 0 "== $size" "post replace, set size: "
0295 
0296         dcb buffer set dev $swp buffer-size all:0
0297 
0298         # Likewise after replacing for a different kind.
0299         tc qdisc replace dev $swp root handle 2: prio bands 8
0300 
0301         dcb buffer set dev $swp buffer-size all:0 0:$size
0302         check_buf_size 0 "== $size" "post replace different kind, set size: "
0303 
0304         tc qdisc delete dev $swp root
0305 
0306         dcb buffer set dev $swp buffer-size all:0 0:$size 2>/dev/null
0307         check_fail $? "buffer_size should fail after qdisc is deleted"
0308 
0309         log_test "TC: buffer size"
0310 }
0311 
0312 test_int_buf()
0313 {
0314         local what=$1; shift
0315 
0316         RET=0
0317 
0318         local buf0size=$(get_buf_size 0)
0319         local tot_size=$(get_tot_size)
0320 
0321         # Size of internal buffer and buffer 9.
0322         local dsize=$((tot_size - buf0size))
0323 
0324         tc qdisc add dev $swp clsact
0325         tc filter add dev $swp egress matchall skip_sw action mirred egress mirror dev $swp
0326 
0327         local buf0size_2=$(get_buf_size 0)
0328         local tot_size_2=$(get_tot_size)
0329         local dsize_2=$((tot_size_2 - buf0size_2))
0330 
0331         # Egress SPAN should have added to the "invisible" buffer configuration.
0332         ((dsize_2 > dsize))
0333         check_err $? "Invisible buffers account for '$dsize_2', expected '> $dsize'"
0334 
0335         mtu_set $swp 3000
0336 
0337         local buf0size_3=$(get_buf_size 0)
0338         local tot_size_3=$(get_tot_size)
0339         local dsize_3=$((tot_size_3 - buf0size_3))
0340 
0341         # MTU change might change buffer 0, which will show at total, but the
0342         # hidden buffers should stay the same size.
0343         ((dsize_3 == dsize_2))
0344         check_err $? "MTU change: Invisible buffers account for '$dsize_3', expected '== $dsize_2'"
0345 
0346         mtu_restore $swp
0347         tc qdisc del dev $swp clsact
0348 
0349         # After SPAN removal, hidden buffers should be back to the original sizes.
0350         local buf0size_4=$(get_buf_size 0)
0351         local tot_size_4=$(get_tot_size)
0352         local dsize_4=$((tot_size_4 - buf0size_4))
0353         ((dsize_4 == dsize))
0354         check_err $? "SPAN removed: Invisible buffers account for '$dsize_4', expected '== $dsize'"
0355 
0356         log_test "${what}internal buffer size"
0357 }
0358 
0359 test_tc_int_buf()
0360 {
0361         local cell_size=$(devlink_cell_size_get)
0362         local size=$((cell_size * 1000))
0363 
0364         tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
0365         test_int_buf "TC: "
0366 
0367         dcb buffer set dev $swp buffer-size all:0 0:$size
0368         test_int_buf "TC+buffsize: "
0369 
0370         dcb buffer set dev $swp buffer-size all:0
0371         tc qdisc delete dev $swp root
0372 }
0373 
0374 bail_on_lldpad
0375 
0376 trap cleanup EXIT
0377 setup_wait
0378 tests_run
0379 
0380 exit $EXIT_STATUS