349 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# Handles creation and destruction of IP-in-IP or GRE tunnels over the given5# topology. Supports both flat and hierarchical models.6#7# Flat Model:8# Overlay and underlay share the same VRF.9# SW1 uses default VRF so tunnel has no bound dev.10# SW2 uses non-default VRF tunnel has a bound dev.11# +-------------------------+12# | H1 |13# | $h1 + |14# | 192.0.2.1/28 | |15# +-------------------|-----+16# |17# +-------------------|-----+18# | SW1 | |19# | $ol1 + |20# | 192.0.2.2/28 |21# | |22# | + g1a (gre) |23# | loc=192.0.2.65 |24# | rem=192.0.2.66 --. |25# | tos=inherit | |26# | .------------------' |27# | | |28# | v |29# | + $ul1.111 (vlan) |30# | | 192.0.2.129/28 |31# | \ |32# | \_______ |33# | | |34# |VRF default + $ul1 |35# +------------|------------+36# |37# +------------|------------+38# | SW2 + $ul2 |39# | _______| |40# | / |41# | / |42# | + $ul2.111 (vlan) |43# | ^ 192.0.2.130/28 |44# | | |45# | | |46# | '------------------. |47# | + g2a (gre) | |48# | loc=192.0.2.66 | |49# | rem=192.0.2.65 --' |50# | tos=inherit |51# | |52# | $ol2 + |53# | 192.0.2.17/28 | |54# | VRF v$ol2 | |55# +-------------------|-----+56# |57# +-------------------|-----+58# | H2 | |59# | $h2 + |60# | 192.0.2.18/28 |61# +-------------------------+62#63# Hierarchical model:64# The tunnel is bound to a device in a different VRF65#66# +---------------------------+67# | H1 |68# | $h1 + |69# | 192.0.2.1/28 | |70# +-------------------|-------+71# |72# +-------------------|-------+73# | SW1 | |74# | +-----------------|-----+ |75# | | $ol1 + | |76# | | 192.0.2.2/28 | |77# | | | |78# | | + g1a (gre) | |79# | | rem=192.0.2.66 | |80# | | tos=inherit | |81# | | loc=192.0.2.65 | |82# | | ^ | |83# | | VRF v$ol1 | | |84# | +-----------|-----------+ |85# | | |86# | +-----------|-----------+ |87# | | VRF v$ul1 | | |88# | | | | |89# | | | | |90# | | v | |91# | | dummy1 + | |92# | | 192.0.2.65 | |93# | | .-------' | |94# | | | | |95# | | v | |96# | | + $ul1.111 (vlan) | |97# | | | 192.0.2.129/28 | |98# | | \ | |99# | | \_____ | |100# | | | | |101# | | + $ul1 | |102# | +----------|------------+ |103# +------------|--------------+104# |105# +------------|--------------+106# | SW2 | |107# | +----------|------------+ |108# | | + $ul2 | |109# | | _____| | |110# | | / | |111# | | / | |112# | | | $ul2.111 (vlan) | |113# | | + 192.0.2.130/28 | |114# | | ^ | |115# | | | | |116# | | '-------. | |117# | | dummy2 + | |118# | | 192.0.2.66 | |119# | | ^ | |120# | | | | |121# | | | | |122# | | VRF v$ul2 | | |123# | +-----------|-----------+ |124# | | |125# | +-----------|-----------+ |126# | | VRF v$ol2 | | |127# | | | | |128# | | v | |129# | | g2a (gre)+ | |130# | | loc=192.0.2.66 | |131# | | rem=192.0.2.65 | |132# | | tos=inherit | |133# | | | |134# | | $ol2 + | |135# | | 192.0.2.17/28 | | |136# | +-----------------|-----+ |137# +-------------------|-------+138# |139# +-------------------|-------+140# | H2 | |141# | $h2 + |142# | 192.0.2.18/28 |143# +---------------------------+144 145h1_create()146{147 simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/64148 ip route add vrf v$h1 192.0.2.16/28 via 192.0.2.2149}150 151h1_destroy()152{153 ip route del vrf v$h1 192.0.2.16/28 via 192.0.2.2154 simple_if_fini $h1 192.0.2.1/28155}156 157h2_create()158{159 simple_if_init $h2 192.0.2.18/28160 ip route add vrf v$h2 192.0.2.0/28 via 192.0.2.17161}162 163h2_destroy()164{165 ip route del vrf v$h2 192.0.2.0/28 via 192.0.2.17166 simple_if_fini $h2 192.0.2.18/28167}168 169sw1_flat_create()170{171 local type=$1; shift172 local ol1=$1; shift173 local ul1=$1; shift174 175 ip link set dev $ol1 up176 __addr_add_del $ol1 add "192.0.2.2/28"177 178 ip link set dev $ul1 up179 vlan_create $ul1 111 "" 192.0.2.129/28180 181 tunnel_create g1a $type 192.0.2.65 192.0.2.66 tos inherit "$@"182 ip link set dev g1a up183 __addr_add_del g1a add "192.0.2.65/32"184 185 ip route add 192.0.2.66/32 via 192.0.2.130186 187 ip route add 192.0.2.16/28 nexthop dev g1a188}189 190sw1_flat_destroy()191{192 local ol1=$1; shift193 local ul1=$1; shift194 195 ip route del 192.0.2.16/28196 197 ip route del 192.0.2.66/32 via 192.0.2.130198 __simple_if_fini g1a 192.0.2.65/32199 tunnel_destroy g1a200 201 vlan_destroy $ul1 111202 __simple_if_fini $ul1203 __simple_if_fini $ol1 192.0.2.2/28204}205 206sw2_flat_create()207{208 local type=$1; shift209 local ol2=$1; shift210 local ul2=$1; shift211 212 simple_if_init $ol2 192.0.2.17/28213 __simple_if_init $ul2 v$ol2214 vlan_create $ul2 111 v$ol2 192.0.2.130/28215 216 tunnel_create g2a $type 192.0.2.66 192.0.2.65 tos inherit dev v$ol2 \217 "$@"218 __simple_if_init g2a v$ol2 192.0.2.66/32219 220 ip route add vrf v$ol2 192.0.2.65/32 via 192.0.2.129221 ip route add vrf v$ol2 192.0.2.0/28 nexthop dev g2a222}223 224sw2_flat_destroy()225{226 local ol2=$1; shift227 local ul2=$1; shift228 229 ip route del vrf v$ol2 192.0.2.0/28230 231 ip route del vrf v$ol2 192.0.2.65/32 via 192.0.2.129232 __simple_if_fini g2a 192.0.2.66/32233 tunnel_destroy g2a234 235 vlan_destroy $ul2 111236 __simple_if_fini $ul2237 simple_if_fini $ol2 192.0.2.17/28238}239 240sw1_hierarchical_create()241{242 local type=$1; shift243 local ol1=$1; shift244 local ul1=$1; shift245 246 simple_if_init $ol1 192.0.2.2/28247 simple_if_init $ul1248 ip link add name dummy1 type dummy249 __simple_if_init dummy1 v$ul1 192.0.2.65/32250 251 vlan_create $ul1 111 v$ul1 192.0.2.129/28252 tunnel_create g1a $type 192.0.2.65 192.0.2.66 tos inherit dev dummy1 \253 "$@"254 ip link set dev g1a master v$ol1255 256 ip route add vrf v$ul1 192.0.2.66/32 via 192.0.2.130257 ip route add vrf v$ol1 192.0.2.16/28 nexthop dev g1a258}259 260sw1_hierarchical_destroy()261{262 local ol1=$1; shift263 local ul1=$1; shift264 265 ip route del vrf v$ol1 192.0.2.16/28266 ip route del vrf v$ul1 192.0.2.66/32267 268 tunnel_destroy g1a269 vlan_destroy $ul1 111270 271 __simple_if_fini dummy1 192.0.2.65/32272 ip link del dev dummy1273 274 simple_if_fini $ul1275 simple_if_fini $ol1 192.0.2.2/28276}277 278sw2_hierarchical_create()279{280 local type=$1; shift281 local ol2=$1; shift282 local ul2=$1; shift283 284 simple_if_init $ol2 192.0.2.17/28285 simple_if_init $ul2286 287 ip link add name dummy2 type dummy288 __simple_if_init dummy2 v$ul2 192.0.2.66/32289 290 vlan_create $ul2 111 v$ul2 192.0.2.130/28291 tunnel_create g2a $type 192.0.2.66 192.0.2.65 tos inherit dev dummy2 \292 "$@"293 ip link set dev g2a master v$ol2294 295 ip route add vrf v$ul2 192.0.2.65/32 via 192.0.2.129296 ip route add vrf v$ol2 192.0.2.0/28 nexthop dev g2a297}298 299sw2_hierarchical_destroy()300{301 local ol2=$1; shift302 local ul2=$1; shift303 304 ip route del vrf v$ol2 192.0.2.0/28305 ip route del vrf v$ul2 192.0.2.65/32306 307 tunnel_destroy g2a308 vlan_destroy $ul2 111309 310 __simple_if_fini dummy2 192.0.2.66/32311 ip link del dev dummy2312 313 simple_if_fini $ul2314 simple_if_fini $ol2 192.0.2.17/28315}316 317topo_mtu_change()318{319 local mtu=$1320 321 ip link set mtu $mtu dev $h1322 ip link set mtu $mtu dev $ol1323 ip link set mtu $mtu dev g1a324 ip link set mtu $mtu dev $ul1325 ip link set mtu $mtu dev $ul1.111326 ip link set mtu $mtu dev $h2327 ip link set mtu $mtu dev $ol2328 ip link set mtu $mtu dev g2a329 ip link set mtu $mtu dev $ul2330 ip link set mtu $mtu dev $ul2.111331}332 333test_mtu_change()334{335 local encap=$1; shift336 337 RET=0338 339 ping_do $h1 192.0.2.18 "-s 1800 -w 3"340 check_fail $? "ping $encap should not pass with size 1800"341 342 RET=0343 344 topo_mtu_change 2000345 ping_do $h1 192.0.2.18 "-s 1800 -w 3"346 check_err $?347 log_test "ping $encap packet size 1800 after MTU change"348}349