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 a pedit action. An ingress
0006 # filter installed on $h2 verifies that the packet looks like expected.
0007 #
0008 # +----------------------+                             +----------------------+
0009 # | H1                   |                             |                   H2 |
0010 # |    + $h1             |                             |            $h2 +     |
0011 # |    | 192.0.2.1/28    |                             |   192.0.2.2/28 |     |
0012 # +----|-----------------+                             +----------------|-----+
0013 #      |                                                                |
0014 # +----|----------------------------------------------------------------|-----+
0015 # | SW |                                                                |     |
0016 # |  +-|----------------------------------------------------------------|-+   |
0017 # |  | + $swp1                       BR                           $swp2 + |   |
0018 # |  +--------------------------------------------------------------------+   |
0019 # +---------------------------------------------------------------------------+
0020 
0021 ALL_TESTS="
0022         ping_ipv4
0023         ping_ipv6
0024         test_ip4_src
0025         test_ip4_dst
0026         test_ip6_src
0027         test_ip6_dst
0028 "
0029 
0030 NUM_NETIFS=4
0031 source lib.sh
0032 source tc_common.sh
0033 
0034 h1_create()
0035 {
0036         simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
0037 }
0038 
0039 h1_destroy()
0040 {
0041         simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/64
0042 }
0043 
0044 h2_create()
0045 {
0046         simple_if_init $h2 192.0.2.2/28 2001:db8:1::2/64
0047         tc qdisc add dev $h2 clsact
0048 }
0049 
0050 h2_destroy()
0051 {
0052         tc qdisc del dev $h2 clsact
0053         simple_if_fini $h2 192.0.2.2/28 2001:db8:1::2/64
0054 }
0055 
0056 switch_create()
0057 {
0058         ip link add name br1 up type bridge vlan_filtering 1
0059         ip link set dev $swp1 master br1
0060         ip link set dev $swp1 up
0061         ip link set dev $swp2 master br1
0062         ip link set dev $swp2 up
0063 
0064         tc qdisc add dev $swp1 clsact
0065         tc qdisc add dev $swp2 clsact
0066 }
0067 
0068 switch_destroy()
0069 {
0070         tc qdisc del dev $swp2 clsact
0071         tc qdisc del dev $swp1 clsact
0072 
0073         ip link set dev $swp2 down
0074         ip link set dev $swp2 nomaster
0075         ip link set dev $swp1 down
0076         ip link set dev $swp1 nomaster
0077         ip link del dev br1
0078 }
0079 
0080 setup_prepare()
0081 {
0082         h1=${NETIFS[p1]}
0083         swp1=${NETIFS[p2]}
0084 
0085         swp2=${NETIFS[p3]}
0086         h2=${NETIFS[p4]}
0087 
0088         h2mac=$(mac_get $h2)
0089 
0090         vrf_prepare
0091         h1_create
0092         h2_create
0093         switch_create
0094 }
0095 
0096 cleanup()
0097 {
0098         pre_cleanup
0099 
0100         switch_destroy
0101         h2_destroy
0102         h1_destroy
0103         vrf_cleanup
0104 }
0105 
0106 ping_ipv4()
0107 {
0108         ping_test $h1 192.0.2.2
0109 }
0110 
0111 ping_ipv6()
0112 {
0113         ping6_test $h1 2001:db8:1::2
0114 }
0115 
0116 do_test_pedit_ip()
0117 {
0118         local pedit_locus=$1; shift
0119         local pedit_action=$1; shift
0120         local match_prot=$1; shift
0121         local match_flower=$1; shift
0122         local mz_flags=$1; shift
0123 
0124         tc filter add $pedit_locus handle 101 pref 1 \
0125            flower action pedit ex munge $pedit_action
0126         tc filter add dev $h2 ingress handle 101 pref 1 prot $match_prot \
0127            flower skip_hw $match_flower action pass
0128 
0129         RET=0
0130 
0131         $MZ $mz_flags $h1 -c 10 -d 20msec -p 100 -a own -b $h2mac -q -t ip
0132 
0133         local pkts
0134         pkts=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= 10" \
0135                         tc_rule_handle_stats_get "dev $h2 ingress" 101)
0136         check_err $? "Expected to get 10 packets, but got $pkts."
0137 
0138         pkts=$(tc_rule_handle_stats_get "$pedit_locus" 101)
0139         ((pkts >= 10))
0140         check_err $? "Expected to get 10 packets on pedit rule, but got $pkts."
0141 
0142         log_test "$pedit_locus pedit $pedit_action"
0143 
0144         tc filter del dev $h2 ingress pref 1
0145         tc filter del $pedit_locus pref 1
0146 }
0147 
0148 do_test_pedit_ip6()
0149 {
0150         local locus=$1; shift
0151         local pedit_addr=$1; shift
0152         local flower_addr=$1; shift
0153 
0154         do_test_pedit_ip "$locus" "$pedit_addr set 2001:db8:2::1" ipv6  \
0155                          "$flower_addr 2001:db8:2::1"                   \
0156                          "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
0157 }
0158 
0159 do_test_pedit_ip4()
0160 {
0161         local locus=$1; shift
0162         local pedit_addr=$1; shift
0163         local flower_addr=$1; shift
0164 
0165         do_test_pedit_ip "$locus" "$pedit_addr set 198.51.100.1" ip     \
0166                          "$flower_addr 198.51.100.1"                    \
0167                          "-A 192.0.2.1 -B 192.0.2.2"
0168 }
0169 
0170 test_ip4_src()
0171 {
0172         do_test_pedit_ip4 "dev $swp1 ingress" "ip src" src_ip
0173         do_test_pedit_ip4 "dev $swp2 egress"  "ip src" src_ip
0174 }
0175 
0176 test_ip4_dst()
0177 {
0178         do_test_pedit_ip4 "dev $swp1 ingress" "ip dst" dst_ip
0179         do_test_pedit_ip4 "dev $swp2 egress"  "ip dst" dst_ip
0180 }
0181 
0182 test_ip6_src()
0183 {
0184         do_test_pedit_ip6 "dev $swp1 ingress" "ip6 src" src_ip
0185         do_test_pedit_ip6 "dev $swp2 egress"  "ip6 src" src_ip
0186 }
0187 
0188 test_ip6_dst()
0189 {
0190         do_test_pedit_ip6 "dev $swp1 ingress" "ip6 dst" dst_ip
0191         do_test_pedit_ip6 "dev $swp2 egress"  "ip6 dst" dst_ip
0192 }
0193 
0194 trap cleanup EXIT
0195 
0196 setup_prepare
0197 setup_wait
0198 
0199 tests_run
0200 
0201 exit $EXIT_STATUS