Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Test for "tc action mirred egress mirror" when the underlay route points at a
0005 # team device.
0006 #
0007 # +----------------------+                             +----------------------+
0008 # | H1                   |                             |                   H2 |
0009 # |    + $h1.333         |                             |        $h1.555 +     |
0010 # |    | 192.0.2.1/28    |                             |  192.0.2.18/28 |     |
0011 # +----|-----------------+                             +----------------|-----+
0012 #      |                                $h1                             |
0013 #      +---------------------------------+------------------------------+
0014 #                                        |
0015 # +--------------------------------------|------------------------------------+
0016 # | SW                                   o---> mirror                         |
0017 # |                                      |                                    |
0018 # |   +----------------------------------+------------------------------+     |
0019 # |   |                                $swp1                            |     |
0020 # |   + $swp1.333                                             $swp1.555 +     |
0021 # |     192.0.2.2/28                                      192.0.2.17/28       |
0022 # |                                                                           |
0023 # |                                                                           |
0024 # |   + gt4 (gretap)      ,-> + lag1 (team)                                   |
0025 # |     loc=192.0.2.129   |   | 192.0.2.129/28                                |
0026 # |     rem=192.0.2.130 --'   |                                               |
0027 # |     ttl=100               |                                               |
0028 # |     tos=inherit           |                                               |
0029 # |      _____________________|______________________                         |
0030 # |     /                                            \                        |
0031 # |    /                                              \                       |
0032 # |   + $swp3                                          + $swp4                |
0033 # +---|------------------------------------------------|----------------------+
0034 #     |                                                |
0035 # +---|------------------------------------------------|----------------------+
0036 # |   + $h3                                            + $h4               H3 |
0037 # |    \                                              /                       |
0038 # |     \____________________________________________/                        |
0039 # |                           |                                               |
0040 # |                           + lag2 (team)                                   |
0041 # |                             192.0.2.130/28                                |
0042 # |                                                                           |
0043 # +---------------------------------------------------------------------------+
0044 
0045 ALL_TESTS="
0046         test_mirror_gretap_first
0047         test_mirror_gretap_second
0048 "
0049 
0050 NUM_NETIFS=6
0051 source lib.sh
0052 source mirror_lib.sh
0053 source mirror_gre_lib.sh
0054 
0055 require_command $ARPING
0056 
0057 vlan_host_create()
0058 {
0059         local if_name=$1; shift
0060         local vid=$1; shift
0061         local vrf_name=$1; shift
0062         local ips=("${@}")
0063 
0064         vrf_create $vrf_name
0065         ip link set dev $vrf_name up
0066         vlan_create $if_name $vid $vrf_name "${ips[@]}"
0067 }
0068 
0069 vlan_host_destroy()
0070 {
0071         local if_name=$1; shift
0072         local vid=$1; shift
0073         local vrf_name=$1; shift
0074 
0075         vlan_destroy $if_name $vid
0076         ip link set dev $vrf_name down
0077         vrf_destroy $vrf_name
0078 }
0079 
0080 h1_create()
0081 {
0082         vlan_host_create $h1 333 vrf-h1 192.0.2.1/28
0083         ip -4 route add 192.0.2.16/28 vrf vrf-h1 nexthop via 192.0.2.2
0084 }
0085 
0086 h1_destroy()
0087 {
0088         ip -4 route del 192.0.2.16/28 vrf vrf-h1
0089         vlan_host_destroy $h1 333 vrf-h1
0090 }
0091 
0092 h2_create()
0093 {
0094         vlan_host_create $h1 555 vrf-h2 192.0.2.18/28
0095         ip -4 route add 192.0.2.0/28 vrf vrf-h2 nexthop via 192.0.2.17
0096 }
0097 
0098 h2_destroy()
0099 {
0100         ip -4 route del 192.0.2.0/28 vrf vrf-h2
0101         vlan_host_destroy $h1 555 vrf-h2
0102 }
0103 
0104 h3_create_team()
0105 {
0106         team_create lag2 lacp $h3 $h4
0107         __simple_if_init lag2 vrf-h3 192.0.2.130/32
0108         ip -4 route add vrf vrf-h3 192.0.2.129/32 dev lag2
0109 }
0110 
0111 h3_destroy_team()
0112 {
0113         ip -4 route del vrf vrf-h3 192.0.2.129/32 dev lag2
0114         __simple_if_fini lag2 192.0.2.130/32
0115         team_destroy lag2
0116 
0117         ip link set dev $h3 down
0118         ip link set dev $h4 down
0119 }
0120 
0121 h3_create()
0122 {
0123         vrf_create vrf-h3
0124         ip link set dev vrf-h3 up
0125         tc qdisc add dev $h3 clsact
0126         tc qdisc add dev $h4 clsact
0127         h3_create_team
0128 }
0129 
0130 h3_destroy()
0131 {
0132         h3_destroy_team
0133         tc qdisc del dev $h4 clsact
0134         tc qdisc del dev $h3 clsact
0135         ip link set dev vrf-h3 down
0136         vrf_destroy vrf-h3
0137 }
0138 
0139 switch_create()
0140 {
0141         ip link set dev $swp1 up
0142         tc qdisc add dev $swp1 clsact
0143         vlan_create $swp1 333 "" 192.0.2.2/28
0144         vlan_create $swp1 555 "" 192.0.2.17/28
0145 
0146         tunnel_create gt4 gretap 192.0.2.129 192.0.2.130 \
0147                       ttl 100 tos inherit
0148 
0149         ip link set dev $swp3 up
0150         ip link set dev $swp4 up
0151         team_create lag1 lacp $swp3 $swp4
0152         __addr_add_del lag1 add 192.0.2.129/32
0153         ip -4 route add 192.0.2.130/32 dev lag1
0154 }
0155 
0156 switch_destroy()
0157 {
0158         ip -4 route del 192.0.2.130/32 dev lag1
0159         __addr_add_del lag1 del 192.0.2.129/32
0160         team_destroy lag1
0161 
0162         ip link set dev $swp4 down
0163         ip link set dev $swp3 down
0164 
0165         tunnel_destroy gt4
0166 
0167         vlan_destroy $swp1 555
0168         vlan_destroy $swp1 333
0169         tc qdisc del dev $swp1 clsact
0170         ip link set dev $swp1 down
0171 }
0172 
0173 setup_prepare()
0174 {
0175         h1=${NETIFS[p1]}
0176         swp1=${NETIFS[p2]}
0177 
0178         swp3=${NETIFS[p3]}
0179         h3=${NETIFS[p4]}
0180 
0181         swp4=${NETIFS[p5]}
0182         h4=${NETIFS[p6]}
0183 
0184         vrf_prepare
0185 
0186         ip link set dev $h1 up
0187         h1_create
0188         h2_create
0189         h3_create
0190         switch_create
0191 
0192         trap_install $h3 ingress
0193         trap_install $h4 ingress
0194 }
0195 
0196 cleanup()
0197 {
0198         pre_cleanup
0199 
0200         trap_uninstall $h4 ingress
0201         trap_uninstall $h3 ingress
0202 
0203         switch_destroy
0204         h3_destroy
0205         h2_destroy
0206         h1_destroy
0207         ip link set dev $h1 down
0208 
0209         vrf_cleanup
0210 }
0211 
0212 test_lag_slave()
0213 {
0214         local up_dev=$1; shift
0215         local down_dev=$1; shift
0216         local what=$1; shift
0217 
0218         RET=0
0219 
0220         mirror_install $swp1 ingress gt4 \
0221                        "proto 802.1q flower vlan_id 333 $tcflags"
0222 
0223         # Move $down_dev away from the team. That will prompt change in
0224         # txability of the connected device, without changing its upness. The
0225         # driver should notice the txability change and move the traffic to the
0226         # other slave.
0227         ip link set dev $down_dev nomaster
0228         sleep 2
0229         mirror_test vrf-h1 192.0.2.1 192.0.2.18 $up_dev 1 10
0230 
0231         # Test lack of connectivity when neither slave is txable.
0232         ip link set dev $up_dev nomaster
0233         sleep 2
0234         mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h3 1 0
0235         mirror_test vrf-h1 192.0.2.1 192.0.2.18 $h4 1 0
0236         mirror_uninstall $swp1 ingress
0237 
0238         # Recreate H3's team device, because mlxsw, which this test is
0239         # predominantly mean to test, requires a bottom-up construction and
0240         # doesn't allow enslavement to a device that already has an upper.
0241         h3_destroy_team
0242         h3_create_team
0243         # Wait for ${h,swp}{3,4}.
0244         setup_wait
0245 
0246         log_test "$what ($tcflags)"
0247 }
0248 
0249 test_mirror_gretap_first()
0250 {
0251         test_lag_slave $h3 $h4 "mirror to gretap: LAG first slave"
0252 }
0253 
0254 test_mirror_gretap_second()
0255 {
0256         test_lag_slave $h4 $h3 "mirror to gretap: LAG second slave"
0257 }
0258 
0259 test_all()
0260 {
0261         slow_path_trap_install $swp1 ingress
0262         slow_path_trap_install $swp1 egress
0263 
0264         tests_run
0265 
0266         slow_path_trap_uninstall $swp1 egress
0267         slow_path_trap_uninstall $swp1 ingress
0268 }
0269 
0270 trap cleanup EXIT
0271 
0272 setup_prepare
0273 setup_wait
0274 
0275 tcflags="skip_hw"
0276 test_all
0277 
0278 if ! tc_offload_check; then
0279         echo "WARN: Could not test offloaded functionality"
0280 else
0281         tcflags="skip_sw"
0282         test_all
0283 fi
0284 
0285 exit $EXIT_STATUS