Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Test traffic distribution when there are multiple routes between an IPv4
0005 # GRE tunnel. The tunnel carries IPv4 traffic between multiple hosts.
0006 # Multiple routes are in the underlay network. With the default multipath
0007 # policy, SW2 will only look at the outer IP addresses, hence only a single
0008 # route would be used.
0009 #
0010 # +-------------------------+
0011 # | H1                      |
0012 # |               $h1 +     |
0013 # | 192.0.3.{2-62}/24 |     |
0014 # +-------------------|-----+
0015 #                     |
0016 # +-------------------|------------------------+
0017 # | SW1               |                        |
0018 # |              $ol1 +                        |
0019 # |      192.0.3.1/24                          |
0020 # |                                            |
0021 # |  + g1 (gre)                                |
0022 # |    loc=192.0.2.65                          |
0023 # |    rem=192.0.2.66 --.                      |
0024 # |    tos=inherit      |                      |
0025 # |                     v                      |
0026 # |                     + $ul1                 |
0027 # |                     | 192.0.2.129/28       |
0028 # +---------------------|----------------------+
0029 #                       |
0030 # +---------------------|----------------------+
0031 # | SW2                 |                      |
0032 # |               $ul21 +                      |
0033 # |      192.0.2.130/28                        |
0034 # |                   |                        |
0035 # !   ________________|_____                   |
0036 # |  /                      \                  |
0037 # |  |                      |                  |
0038 # |  + $ul22.111 (vlan)     + $ul22.222 (vlan) |
0039 # |  | 192.0.2.145/28       | 192.0.2.161/28   |
0040 # |  |                      |                  |
0041 # +--|----------------------|------------------+
0042 #    |                      |
0043 # +--|----------------------|------------------+
0044 # |  |                      |                  |
0045 # |  + $ul32.111 (vlan)     + $ul32.222 (vlan) |
0046 # |  | 192.0.2.146/28       | 192.0.2.162/28   |
0047 # |  |                      |                  |
0048 # |  \______________________/                  |
0049 # |                   |                        |
0050 # |                   |                        |
0051 # |               $ul31 +                      |
0052 # |      192.0.2.177/28 |                  SW3 |
0053 # +---------------------|----------------------+
0054 #                       |
0055 # +---------------------|----------------------+
0056 # |                     + $ul4                 |
0057 # |                     ^ 192.0.2.178/28       |
0058 # |                     |                      |
0059 # |  + g2 (gre)         |                      |
0060 # |    loc=192.0.2.66   |                      |
0061 # |    rem=192.0.2.65 --'                      |
0062 # |    tos=inherit                             |
0063 # |                                            |
0064 # |               $ol4 +                       |
0065 # |       192.0.4.1/24 |                   SW4 |
0066 # +--------------------|-----------------------+
0067 #                      |
0068 # +--------------------|---------+
0069 # |                    |         |
0070 # |                $h2 +         |
0071 # |  192.0.4.{2-62}/24        H2 |
0072 # +------------------------------+
0073 
0074 ALL_TESTS="
0075         ping_ipv4
0076         multipath_ipv4
0077 "
0078 
0079 NUM_NETIFS=10
0080 source lib.sh
0081 
0082 h1_create()
0083 {
0084         simple_if_init $h1 192.0.3.2/24
0085         ip route add vrf v$h1 192.0.4.0/24 via 192.0.3.1
0086 }
0087 
0088 h1_destroy()
0089 {
0090         ip route del vrf v$h1 192.0.4.0/24 via 192.0.3.1
0091         simple_if_fini $h1 192.0.3.2/24
0092 }
0093 
0094 sw1_create()
0095 {
0096         simple_if_init $ol1 192.0.3.1/24
0097         __simple_if_init $ul1 v$ol1 192.0.2.129/28
0098 
0099         tunnel_create g1 gre 192.0.2.65 192.0.2.66 tos inherit dev v$ol1
0100         __simple_if_init g1 v$ol1 192.0.2.65/32
0101         ip route add vrf v$ol1 192.0.2.66/32 via 192.0.2.130
0102 
0103         ip route add vrf v$ol1 192.0.4.0/24 nexthop dev g1
0104 }
0105 
0106 sw1_destroy()
0107 {
0108         ip route del vrf v$ol1 192.0.4.0/24
0109 
0110         ip route del vrf v$ol1 192.0.2.66/32
0111         __simple_if_fini g1 192.0.2.65/32
0112         tunnel_destroy g1
0113 
0114         __simple_if_fini $ul1 192.0.2.129/28
0115         simple_if_fini $ol1 192.0.3.1/24
0116 }
0117 
0118 sw2_create()
0119 {
0120         simple_if_init $ul21 192.0.2.130/28
0121         __simple_if_init $ul22 v$ul21
0122         vlan_create $ul22 111 v$ul21 192.0.2.145/28
0123         vlan_create $ul22 222 v$ul21 192.0.2.161/28
0124 
0125         ip route add vrf v$ul21 192.0.2.65/32 via 192.0.2.129
0126         ip route add vrf v$ul21 192.0.2.66/32 \
0127            nexthop via 192.0.2.146 \
0128            nexthop via 192.0.2.162
0129 }
0130 
0131 sw2_destroy()
0132 {
0133         ip route del vrf v$ul21 192.0.2.66/32
0134         ip route del vrf v$ul21 192.0.2.65/32
0135 
0136         vlan_destroy $ul22 222
0137         vlan_destroy $ul22 111
0138         __simple_if_fini $ul22
0139         simple_if_fini $ul21 192.0.2.130/28
0140 }
0141 
0142 sw3_create()
0143 {
0144         simple_if_init $ul31 192.0.2.177/28
0145         __simple_if_init $ul32 v$ul31
0146         vlan_create $ul32 111 v$ul31 192.0.2.146/28
0147         vlan_create $ul32 222 v$ul31 192.0.2.162/28
0148 
0149         ip route add vrf v$ul31 192.0.2.66/32 via 192.0.2.178
0150         ip route add vrf v$ul31 192.0.2.65/32 \
0151            nexthop via 192.0.2.145 \
0152            nexthop via 192.0.2.161
0153 
0154         tc qdisc add dev $ul32 clsact
0155         tc filter add dev $ul32 ingress pref 111 prot 802.1Q \
0156            flower vlan_id 111 action pass
0157         tc filter add dev $ul32 ingress pref 222 prot 802.1Q \
0158            flower vlan_id 222 action pass
0159 }
0160 
0161 sw3_destroy()
0162 {
0163         tc qdisc del dev $ul32 clsact
0164 
0165         ip route del vrf v$ul31 192.0.2.65/32
0166         ip route del vrf v$ul31 192.0.2.66/32
0167 
0168         vlan_destroy $ul32 222
0169         vlan_destroy $ul32 111
0170         __simple_if_fini $ul32
0171         simple_if_fini $ul31 192.0.2.177/28
0172 }
0173 
0174 sw4_create()
0175 {
0176         simple_if_init $ol4 192.0.4.1/24
0177         __simple_if_init $ul4 v$ol4 192.0.2.178/28
0178 
0179         tunnel_create g2 gre 192.0.2.66 192.0.2.65 tos inherit dev v$ol4
0180         __simple_if_init g2 v$ol4 192.0.2.66/32
0181         ip route add vrf v$ol4 192.0.2.65/32 via 192.0.2.177
0182 
0183         ip route add vrf v$ol4 192.0.3.0/24 nexthop dev g2
0184 }
0185 
0186 sw4_destroy()
0187 {
0188         ip route del vrf v$ol4 192.0.3.0/24
0189 
0190         ip route del vrf v$ol4 192.0.2.65/32
0191         __simple_if_fini g2 192.0.2.66/32
0192         tunnel_destroy g2
0193 
0194         __simple_if_fini $ul4 192.0.2.178/28
0195         simple_if_fini $ol4 192.0.4.1/24
0196 }
0197 
0198 h2_create()
0199 {
0200         simple_if_init $h2 192.0.4.2/24
0201         ip route add vrf v$h2 192.0.3.0/24 via 192.0.4.1
0202 }
0203 
0204 h2_destroy()
0205 {
0206         ip route del vrf v$h2 192.0.3.0/24 via 192.0.4.1
0207         simple_if_fini $h2 192.0.4.2/24
0208 }
0209 
0210 setup_prepare()
0211 {
0212         h1=${NETIFS[p1]}
0213 
0214         ol1=${NETIFS[p2]}
0215         ul1=${NETIFS[p3]}
0216 
0217         ul21=${NETIFS[p4]}
0218         ul22=${NETIFS[p5]}
0219 
0220         ul32=${NETIFS[p6]}
0221         ul31=${NETIFS[p7]}
0222 
0223         ul4=${NETIFS[p8]}
0224         ol4=${NETIFS[p9]}
0225 
0226         h2=${NETIFS[p10]}
0227 
0228         vrf_prepare
0229         h1_create
0230         sw1_create
0231         sw2_create
0232         sw3_create
0233         sw4_create
0234         h2_create
0235 
0236         forwarding_enable
0237 }
0238 
0239 cleanup()
0240 {
0241         pre_cleanup
0242 
0243         forwarding_restore
0244 
0245         h2_destroy
0246         sw4_destroy
0247         sw3_destroy
0248         sw2_destroy
0249         sw1_destroy
0250         h1_destroy
0251         vrf_cleanup
0252 }
0253 
0254 multipath4_test()
0255 {
0256         local what=$1; shift
0257         local weight1=$1; shift
0258         local weight2=$1; shift
0259 
0260         sysctl_set net.ipv4.fib_multipath_hash_policy 2
0261         ip route replace vrf v$ul21 192.0.2.66/32 \
0262            nexthop via 192.0.2.146 weight $weight1 \
0263            nexthop via 192.0.2.162 weight $weight2
0264 
0265         local t0_111=$(tc_rule_stats_get $ul32 111 ingress)
0266         local t0_222=$(tc_rule_stats_get $ul32 222 ingress)
0267 
0268         ip vrf exec v$h1 \
0269            $MZ $h1 -q -p 64 -A "192.0.3.2-192.0.3.62" -B "192.0.4.2-192.0.4.62" \
0270                -d 1msec -c 50 -t udp "sp=1024,dp=1024"
0271         sleep 1
0272 
0273         local t1_111=$(tc_rule_stats_get $ul32 111 ingress)
0274         local t1_222=$(tc_rule_stats_get $ul32 222 ingress)
0275 
0276         local d111=$((t1_111 - t0_111))
0277         local d222=$((t1_222 - t0_222))
0278         multipath_eval "$what" $weight1 $weight2 $d111 $d222
0279 
0280         ip route replace vrf v$ul21 192.0.2.66/32 \
0281            nexthop via 192.0.2.146 \
0282            nexthop via 192.0.2.162
0283         sysctl_restore net.ipv4.fib_multipath_hash_policy
0284 }
0285 
0286 ping_ipv4()
0287 {
0288         ping_test $h1 192.0.4.2
0289 }
0290 
0291 multipath_ipv4()
0292 {
0293         log_info "Running IPv4 over GRE over IPv4 multipath tests"
0294         multipath4_test "ECMP" 1 1
0295         multipath4_test "Weighted MP 2:1" 2 1
0296         multipath4_test "Weighted MP 11:45" 11 45
0297 }
0298 
0299 trap cleanup EXIT
0300 
0301 setup_prepare
0302 setup_wait
0303 tests_run
0304 
0305 exit $EXIT_STATUS