Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Handles creation and destruction of IP-in-IP or GRE tunnels over the given
0005 # topology. Supports both flat and hierarchical models.
0006 #
0007 # Flat Model:
0008 # Overlay and underlay share the same VRF.
0009 # SW1 uses default VRF so tunnel has no bound dev.
0010 # SW2 uses non-default VRF tunnel has a bound dev.
0011 # +-------------------------+
0012 # | H1                      |
0013 # |               $h1 +     |
0014 # |      192.0.2.1/28 |     |
0015 # +-------------------|-----+
0016 #                     |
0017 # +-------------------|-----+
0018 # | SW1               |     |
0019 # |              $ol1 +     |
0020 # |      192.0.2.2/28       |
0021 # |                         |
0022 # |  + g1a (gre)            |
0023 # |    loc=192.0.2.65       |
0024 # |    rem=192.0.2.66 --.   |
0025 # |    tos=inherit      |   |
0026 # |  .------------------'   |
0027 # |  |                      |
0028 # |  v                      |
0029 # |  + $ul1.111 (vlan)      |
0030 # |  | 192.0.2.129/28       |
0031 # |   \                     |
0032 # |    \_______             |
0033 # |            |            |
0034 # |VRF default + $ul1       |
0035 # +------------|------------+
0036 #              |
0037 # +------------|------------+
0038 # | SW2        + $ul2       |
0039 # |     _______|            |
0040 # |    /                    |
0041 # |   /                     |
0042 # |  + $ul2.111 (vlan)      |
0043 # |  ^ 192.0.2.130/28       |
0044 # |  |                      |
0045 # |  |                      |
0046 # |  '------------------.   |
0047 # |  + g2a (gre)        |   |
0048 # |    loc=192.0.2.66   |   |
0049 # |    rem=192.0.2.65 --'   |
0050 # |    tos=inherit          |
0051 # |                         |
0052 # |              $ol2 +     |
0053 # |     192.0.2.17/28 |     |
0054 # | VRF v$ol2         |     |
0055 # +-------------------|-----+
0056 #                     |
0057 # +-------------------|-----+
0058 # | H2                |     |
0059 # |               $h2 +     |
0060 # |     192.0.2.18/28       |
0061 # +-------------------------+
0062 #
0063 # Hierarchical model:
0064 # The tunnel is bound to a device in a different VRF
0065 #
0066 # +---------------------------+
0067 # | H1                        |
0068 # |               $h1 +       |
0069 # |      192.0.2.1/28 |       |
0070 # +-------------------|-------+
0071 #                     |
0072 # +-------------------|-------+
0073 # | SW1               |       |
0074 # | +-----------------|-----+ |
0075 # | |            $ol1 +     | |
0076 # | |     192.0.2.2/28      | |
0077 # | |                       | |
0078 # | |    + g1a (gre)        | |
0079 # | |    rem=192.0.2.66     | |
0080 # | |    tos=inherit        | |
0081 # | |    loc=192.0.2.65     | |
0082 # | |           ^           | |
0083 # | | VRF v$ol1 |           | |
0084 # | +-----------|-----------+ |
0085 # |             |             |
0086 # | +-----------|-----------+ |
0087 # | | VRF v$ul1 |           | |
0088 # | |           |           | |
0089 # | |           |           | |
0090 # | |           v           | |
0091 # | |    dummy1 +           | |
0092 # | |   192.0.2.65          | |
0093 # | |   .-------'           | |
0094 # | |   |                   | |
0095 # | |   v                   | |
0096 # | |   + $ul1.111 (vlan)   | |
0097 # | |   | 192.0.2.129/28    | |
0098 # | |   \                   | |
0099 # | |    \_____             | |
0100 # | |          |            | |
0101 # | |          + $ul1       | |
0102 # | +----------|------------+ |
0103 # +------------|--------------+
0104 #              |
0105 # +------------|--------------+
0106 # | SW2        |              |
0107 # | +----------|------------+ |
0108 # | |          + $ul2       | |
0109 # | |     _____|            | |
0110 # | |    /                  | |
0111 # | |   /                   | |
0112 # | |   | $ul2.111 (vlan)   | |
0113 # | |   + 192.0.2.130/28    | |
0114 # | |   ^                   | |
0115 # | |   |                   | |
0116 # | |   '-------.           | |
0117 # | |    dummy2 +           | |
0118 # | |    192.0.2.66         | |
0119 # | |           ^           | |
0120 # | |           |           | |
0121 # | |           |           | |
0122 # | | VRF v$ul2 |           | |
0123 # | +-----------|-----------+ |
0124 # |             |             |
0125 # | +-----------|-----------+ |
0126 # | | VRF v$ol2 |           | |
0127 # | |           |           | |
0128 # | |           v           | |
0129 # | |  g2a (gre)+           | |
0130 # | |  loc=192.0.2.66       | |
0131 # | |  rem=192.0.2.65       | |
0132 # | |  tos=inherit          | |
0133 # | |                       | |
0134 # | |            $ol2 +     | |
0135 # | |   192.0.2.17/28 |     | |
0136 # | +-----------------|-----+ |
0137 # +-------------------|-------+
0138 #                     |
0139 # +-------------------|-------+
0140 # | H2                |       |
0141 # |               $h2 +       |
0142 # |     192.0.2.18/28         |
0143 # +---------------------------+
0144 source lib.sh
0145 
0146 h1_create()
0147 {
0148         simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64
0149         ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2
0150 }
0151 
0152 h1_destroy()
0153 {
0154         ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2
0155         simple_if_fini $h1 192.0.2.1/28
0156 }
0157 
0158 h2_create()
0159 {
0160         simple_if_init $h2 192.0.2.18/28
0161         ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17
0162 }
0163 
0164 h2_destroy()
0165 {
0166         ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17
0167         simple_if_fini $h2 192.0.2.18/28
0168 }
0169 
0170 sw1_flat_create()
0171 {
0172         local type=$1; shift
0173         local ol1=$1; shift
0174         local ul1=$1; shift
0175 
0176         ip link set dev $ol1 up
0177         __addr_add_del $ol1 add "192.0.2.2/28"
0178 
0179         ip link set dev $ul1 up
0180         vlan_create $ul1 111 "" 192.0.2.129/28
0181 
0182         tunnel_create g1a $type 192.0.2.65 192.0.2.66 tos inherit "$@"
0183         ip link set dev g1a up
0184         __addr_add_del g1a add "192.0.2.65/32"
0185 
0186         ip route add 192.0.2.66/32 via 192.0.2.130
0187 
0188         ip route add 192.0.2.16/28 nexthop dev g1a
0189 }
0190 
0191 sw1_flat_destroy()
0192 {
0193         local ol1=$1; shift
0194         local ul1=$1; shift
0195 
0196         ip route del 192.0.2.16/28
0197 
0198         ip route del 192.0.2.66/32 via 192.0.2.130
0199         __simple_if_fini g1a 192.0.2.65/32
0200         tunnel_destroy g1a
0201 
0202         vlan_destroy $ul1 111
0203         __simple_if_fini $ul1
0204         __simple_if_fini $ol1 192.0.2.2/28
0205 }
0206 
0207 sw2_flat_create()
0208 {
0209         local type=$1; shift
0210         local ol2=$1; shift
0211         local ul2=$1; shift
0212 
0213         simple_if_init $ol2 192.0.2.17/28
0214         __simple_if_init $ul2 v$ol2
0215         vlan_create $ul2 111 v$ol2 192.0.2.130/28
0216 
0217         tunnel_create g2a $type 192.0.2.66 192.0.2.65 tos inherit dev v$ol2 \
0218                 "$@"
0219         __simple_if_init g2a v$ol2 192.0.2.66/32
0220 
0221         ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129
0222         ip route add vrf v$ol2 192.0.2.0/28 nexthop dev g2a
0223 }
0224 
0225 sw2_flat_destroy()
0226 {
0227         local ol2=$1; shift
0228         local ul2=$1; shift
0229 
0230         ip route del vrf v$ol2 192.0.2.0/28
0231 
0232         ip route del vrf v$ol2 192.0.2.65/32 via 192.0.2.129
0233         __simple_if_fini g2a 192.0.2.66/32
0234         tunnel_destroy g2a
0235 
0236         vlan_destroy $ul2 111
0237         __simple_if_fini $ul2
0238         simple_if_fini $ol2 192.0.2.17/28
0239 }
0240 
0241 sw1_hierarchical_create()
0242 {
0243         local type=$1; shift
0244         local ol1=$1; shift
0245         local ul1=$1; shift
0246 
0247         simple_if_init $ol1 192.0.2.2/28
0248         simple_if_init $ul1
0249         ip link add name dummy1 type dummy
0250         __simple_if_init dummy1 v$ul1 192.0.2.65/32
0251 
0252         vlan_create $ul1 111 v$ul1 192.0.2.129/28
0253         tunnel_create g1a $type 192.0.2.65 192.0.2.66 tos inherit dev dummy1 \
0254                 "$@"
0255         ip link set dev g1a master v$ol1
0256 
0257         ip route add vrf v$ul1 192.0.2.66/32 via 192.0.2.130
0258         ip route add vrf v$ol1 192.0.2.16/28 nexthop dev g1a
0259 }
0260 
0261 sw1_hierarchical_destroy()
0262 {
0263         local ol1=$1; shift
0264         local ul1=$1; shift
0265 
0266         ip route del vrf v$ol1 192.0.2.16/28
0267         ip route del vrf v$ul1 192.0.2.66/32
0268 
0269         tunnel_destroy g1a
0270         vlan_destroy $ul1 111
0271 
0272         __simple_if_fini dummy1 192.0.2.65/32
0273         ip link del dev dummy1
0274 
0275         simple_if_fini $ul1
0276         simple_if_fini $ol1 192.0.2.2/28
0277 }
0278 
0279 sw2_hierarchical_create()
0280 {
0281         local type=$1; shift
0282         local ol2=$1; shift
0283         local ul2=$1; shift
0284 
0285         simple_if_init $ol2 192.0.2.17/28
0286         simple_if_init $ul2
0287 
0288         ip link add name dummy2 type dummy
0289         __simple_if_init dummy2 v$ul2 192.0.2.66/32
0290 
0291         vlan_create $ul2 111 v$ul2 192.0.2.130/28
0292         tunnel_create g2a $type 192.0.2.66 192.0.2.65 tos inherit dev dummy2 \
0293                 "$@"
0294         ip link set dev g2a master v$ol2
0295 
0296         ip route add vrf v$ul2 192.0.2.65/32 via 192.0.2.129
0297         ip route add vrf v$ol2 192.0.2.0/28 nexthop dev g2a
0298 }
0299 
0300 sw2_hierarchical_destroy()
0301 {
0302         local ol2=$1; shift
0303         local ul2=$1; shift
0304 
0305         ip route del vrf v$ol2 192.0.2.0/28
0306         ip route del vrf v$ul2 192.0.2.65/32
0307 
0308         tunnel_destroy g2a
0309         vlan_destroy $ul2 111
0310 
0311         __simple_if_fini dummy2 192.0.2.66/32
0312         ip link del dev dummy2
0313 
0314         simple_if_fini $ul2
0315         simple_if_fini $ol2 192.0.2.17/28
0316 }
0317 
0318 topo_mtu_change()
0319 {
0320         local mtu=$1
0321 
0322         ip link set mtu $mtu dev $h1
0323         ip link set mtu $mtu dev $ol1
0324         ip link set mtu $mtu dev g1a
0325         ip link set mtu $mtu dev $ul1
0326         ip link set mtu $mtu dev $ul1.111
0327         ip link set mtu $mtu dev $h2
0328         ip link set mtu $mtu dev $ol2
0329         ip link set mtu $mtu dev g2a
0330         ip link set mtu $mtu dev $ul2
0331         ip link set mtu $mtu dev $ul2.111
0332 }
0333 
0334 test_mtu_change()
0335 {
0336         local encap=$1; shift
0337 
0338         RET=0
0339 
0340         ping_do $h1 192.0.2.18 "-s 1800 -w 3"
0341         check_fail $? "ping $encap should not pass with size 1800"
0342 
0343         RET=0
0344 
0345         topo_mtu_change 2000
0346         ping_do $h1 192.0.2.18 "-s 1800 -w 3"
0347         check_err $?
0348         log_test "ping $encap packet size 1800 after MTU change"
0349 }