Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # This test sends traffic from H1 to H2. Either on ingress of $swp1, or on
0005 # egress of $swp2, the traffic is acted upon by an action skbedit priority. The
0006 # new priority should be taken into account when classifying traffic on the PRIO
0007 # qdisc at $swp2. The test verifies that for different priority values, the
0008 # traffic ends up in expected PRIO band.
0009 #
0010 # +----------------------+                             +----------------------+
0011 # | H1                   |                             |                   H2 |
0012 # |    + $h1             |                             |            $h2 +     |
0013 # |    | 192.0.2.1/28    |                             |   192.0.2.2/28 |     |
0014 # +----|-----------------+                             +----------------|-----+
0015 #      |                                                                |
0016 # +----|----------------------------------------------------------------|-----+
0017 # | SW |                                                                |     |
0018 # |  +-|----------------------------------------------------------------|-+   |
0019 # |  | + $swp1                       BR                           $swp2 + |   |
0020 # |  |                                                             PRIO   |   |
0021 # |  +--------------------------------------------------------------------+   |
0022 # +---------------------------------------------------------------------------+
0023 
0024 ALL_TESTS="
0025         ping_ipv4
0026         test_ingress
0027         test_egress
0028 "
0029 
0030 NUM_NETIFS=4
0031 source lib.sh
0032 
0033 : ${HIT_TIMEOUT:=2000} # ms
0034 
0035 h1_create()
0036 {
0037         simple_if_init $h1 192.0.2.1/28
0038 }
0039 
0040 h1_destroy()
0041 {
0042         simple_if_fini $h1 192.0.2.1/28
0043 }
0044 
0045 h2_create()
0046 {
0047         simple_if_init $h2 192.0.2.2/28
0048 }
0049 
0050 h2_destroy()
0051 {
0052         simple_if_fini $h2 192.0.2.2/28
0053 }
0054 
0055 switch_create()
0056 {
0057         ip link add name br1 up type bridge vlan_filtering 1
0058         ip link set dev $swp1 master br1
0059         ip link set dev $swp1 up
0060         ip link set dev $swp2 master br1
0061         ip link set dev $swp2 up
0062 
0063         tc qdisc add dev $swp1 clsact
0064         tc qdisc add dev $swp2 clsact
0065         tc qdisc add dev $swp2 root handle 10: \
0066            prio bands 8 priomap 7 6 5 4 3 2 1 0
0067 }
0068 
0069 switch_destroy()
0070 {
0071         tc qdisc del dev $swp2 root
0072         tc qdisc del dev $swp2 clsact
0073         tc qdisc del dev $swp1 clsact
0074 
0075         ip link set dev $swp2 down
0076         ip link set dev $swp2 nomaster
0077         ip link set dev $swp1 down
0078         ip link set dev $swp1 nomaster
0079         ip link del dev br1
0080 }
0081 
0082 setup_prepare()
0083 {
0084         h1=${NETIFS[p1]}
0085         swp1=${NETIFS[p2]}
0086 
0087         swp2=${NETIFS[p3]}
0088         h2=${NETIFS[p4]}
0089 
0090         h2mac=$(mac_get $h2)
0091 
0092         vrf_prepare
0093         h1_create
0094         h2_create
0095         switch_create
0096 }
0097 
0098 cleanup()
0099 {
0100         pre_cleanup
0101 
0102         switch_destroy
0103         h2_destroy
0104         h1_destroy
0105         vrf_cleanup
0106 }
0107 
0108 ping_ipv4()
0109 {
0110         ping_test $h1 192.0.2.2
0111 }
0112 
0113 test_skbedit_priority_one()
0114 {
0115         local locus=$1; shift
0116         local prio=$1; shift
0117         local classid=$1; shift
0118 
0119         RET=0
0120 
0121         tc filter add $locus handle 101 pref 1 \
0122            flower action skbedit priority $prio
0123 
0124         local pkt0=$(qdisc_parent_stats_get $swp2 $classid .packets)
0125         local pkt2=$(tc_rule_handle_stats_get "$locus" 101)
0126         $MZ $h1 -t udp "sp=54321,dp=12345" -c 10 -d 20msec -p 100 \
0127             -a own -b $h2mac -A 192.0.2.1 -B 192.0.2.2 -q
0128 
0129         local pkt1
0130         pkt1=$(busywait "$HIT_TIMEOUT" until_counter_is ">= $((pkt0 + 10))" \
0131                         qdisc_parent_stats_get $swp2 $classid .packets)
0132         check_err $? "Expected to get 10 packets on class $classid, but got $((pkt1 - pkt0))."
0133 
0134         local pkt3=$(tc_rule_handle_stats_get "$locus" 101)
0135         ((pkt3 >= pkt2 + 10))
0136         check_err $? "Expected to get 10 packets on skbedit rule but got $((pkt3 - pkt2))."
0137 
0138         log_test "$locus skbedit priority $prio -> classid $classid"
0139 
0140         tc filter del $locus pref 1
0141 }
0142 
0143 test_ingress()
0144 {
0145         local prio
0146 
0147         for prio in {0..7}; do
0148                 test_skbedit_priority_one "dev $swp1 ingress" \
0149                                           $prio 10:$((8 - prio))
0150         done
0151 }
0152 
0153 test_egress()
0154 {
0155         local prio
0156 
0157         for prio in {0..7}; do
0158                 test_skbedit_priority_one "dev $swp2 egress" \
0159                                           $prio 10:$((8 - prio))
0160         done
0161 }
0162 
0163 trap cleanup EXIT
0164 
0165 setup_prepare
0166 setup_wait
0167 
0168 tests_run
0169 
0170 exit $EXIT_STATUS