Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Test for DSCP prioritization and rewrite. Packets ingress $swp1 with a DSCP
0005 # tag and are prioritized according to the map at $swp1. They egress $swp2 and
0006 # the DSCP value is updated to match the map at that interface. The updated DSCP
0007 # tag is verified at $h2.
0008 #
0009 # ICMP responses are produced with the same DSCP tag that arrived at $h2. They
0010 # go through prioritization at $swp2 and DSCP retagging at $swp1. The tag is
0011 # verified at $h1--it should match the original tag.
0012 #
0013 # +----------------------+                             +----------------------+
0014 # | H1                   |                             |                   H2 |
0015 # |    + $h1             |                             |            $h2 +     |
0016 # |    | 192.0.2.1/28    |                             |   192.0.2.2/28 |     |
0017 # +----|-----------------+                             +----------------|-----+
0018 #      |                                                                |
0019 # +----|----------------------------------------------------------------|-----+
0020 # | SW |                                                                |     |
0021 # |  +-|----------------------------------------------------------------|-+   |
0022 # |  | + $swp1                       BR                           $swp2 + |   |
0023 # |  |   APP=0,5,10 .. 7,5,17                      APP=0,5,20 .. 7,5,27   |   |
0024 # |  +--------------------------------------------------------------------+   |
0025 # +---------------------------------------------------------------------------+
0026 
0027 ALL_TESTS="
0028         ping_ipv4
0029         test_dscp
0030 "
0031 
0032 lib_dir=$(dirname $0)/../../../net/forwarding
0033 
0034 NUM_NETIFS=4
0035 source $lib_dir/lib.sh
0036 
0037 h1_create()
0038 {
0039         simple_if_init $h1 192.0.2.1/28
0040         tc qdisc add dev $h1 clsact
0041         dscp_capture_install $h1 10
0042 }
0043 
0044 h1_destroy()
0045 {
0046         dscp_capture_uninstall $h1 10
0047         tc qdisc del dev $h1 clsact
0048         simple_if_fini $h1 192.0.2.1/28
0049 }
0050 
0051 h2_create()
0052 {
0053         simple_if_init $h2 192.0.2.2/28
0054         tc qdisc add dev $h2 clsact
0055         dscp_capture_install $h2 20
0056 }
0057 
0058 h2_destroy()
0059 {
0060         dscp_capture_uninstall $h2 20
0061         tc qdisc del dev $h2 clsact
0062         simple_if_fini $h2 192.0.2.2/28
0063 }
0064 
0065 dscp_map()
0066 {
0067         local base=$1; shift
0068         local prio
0069 
0070         for prio in {0..7}; do
0071                 echo app=$prio,5,$((base + prio))
0072         done
0073 }
0074 
0075 switch_create()
0076 {
0077         ip link add name br1 type bridge vlan_filtering 1
0078         ip link set dev br1 up
0079         ip link set dev $swp1 master br1
0080         ip link set dev $swp1 up
0081         ip link set dev $swp2 master br1
0082         ip link set dev $swp2 up
0083 
0084         lldptool -T -i $swp1 -V APP $(dscp_map 10) >/dev/null
0085         lldptool -T -i $swp2 -V APP $(dscp_map 20) >/dev/null
0086         lldpad_app_wait_set $swp1
0087         lldpad_app_wait_set $swp2
0088 }
0089 
0090 switch_destroy()
0091 {
0092         lldptool -T -i $swp2 -V APP -d $(dscp_map 20) >/dev/null
0093         lldptool -T -i $swp1 -V APP -d $(dscp_map 10) >/dev/null
0094         lldpad_app_wait_del
0095 
0096         ip link set dev $swp2 down
0097         ip link set dev $swp2 nomaster
0098         ip link set dev $swp1 down
0099         ip link set dev $swp1 nomaster
0100         ip link del dev br1
0101 }
0102 
0103 setup_prepare()
0104 {
0105         h1=${NETIFS[p1]}
0106         swp1=${NETIFS[p2]}
0107 
0108         swp2=${NETIFS[p3]}
0109         h2=${NETIFS[p4]}
0110 
0111         vrf_prepare
0112 
0113         h1_create
0114         h2_create
0115         switch_create
0116 }
0117 
0118 cleanup()
0119 {
0120         pre_cleanup
0121 
0122         switch_destroy
0123         h2_destroy
0124         h1_destroy
0125 
0126         vrf_cleanup
0127 }
0128 
0129 ping_ipv4()
0130 {
0131         ping_test $h1 192.0.2.2
0132 }
0133 
0134 dscp_ping_test()
0135 {
0136         local vrf_name=$1; shift
0137         local sip=$1; shift
0138         local dip=$1; shift
0139         local prio=$1; shift
0140         local dev_10=$1; shift
0141         local dev_20=$1; shift
0142         local key
0143 
0144         local dscp_10=$(((prio + 10) << 2))
0145         local dscp_20=$(((prio + 20) << 2))
0146 
0147         RET=0
0148 
0149         local -A t0s
0150         eval "t0s=($(dscp_fetch_stats $dev_10 10)
0151                    $(dscp_fetch_stats $dev_20 20))"
0152 
0153         local ping_timeout=$((PING_TIMEOUT * 5))
0154         ip vrf exec $vrf_name \
0155            ${PING} -Q $dscp_10 ${sip:+-I $sip} $dip \
0156                    -c 10 -i 0.5 -w $ping_timeout &> /dev/null
0157 
0158         local -A t1s
0159         eval "t1s=($(dscp_fetch_stats $dev_10 10)
0160                    $(dscp_fetch_stats $dev_20 20))"
0161 
0162         for key in ${!t0s[@]}; do
0163                 local expect
0164                 if ((key == prio+10 || key == prio+20)); then
0165                         expect=10
0166                 else
0167                         expect=0
0168                 fi
0169 
0170                 local delta=$((t1s[$key] - t0s[$key]))
0171                 ((expect == delta))
0172                 check_err $? "DSCP $key: Expected to capture $expect packets, got $delta."
0173         done
0174 
0175         log_test "DSCP rewrite: $dscp_10-(prio $prio)-$dscp_20"
0176 }
0177 
0178 test_dscp()
0179 {
0180         local prio
0181 
0182         for prio in {0..7}; do
0183                 dscp_ping_test v$h1 192.0.2.1 192.0.2.2 $prio $h1 $h2
0184         done
0185 }
0186 
0187 trap cleanup EXIT
0188 
0189 setup_prepare
0190 setup_wait
0191 
0192 tests_run
0193 
0194 exit $EXIT_STATUS