1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4# +--------------------------------------------+ 5# | H1 (vrf) | 6# | | 7# | + LAG1.100 + LAG1.200 | 8# | | 192.0.2.1/28 | 192.0.2.17/28 | 9# | | 2001:db8:1::1/64 | 2001:db8:3:1/64 | 10# | \___________ _______/ | 11# | v | 12# | + LAG1 (team) | 13# | | | 14# | ____^____ | 15# | / \ | 16# | + $h1 + $h4 | 17# | | | | 18# +----------|-----------|---------------------+ 19# | | 20# +----------|-----------|---------------------+ 21# | SW | | | 22# | + $swp1 + $swp4 | 23# | \____ ____/ | 24# | v | 25# | LAG2 (team) + | 26# | | | 27# | _______^______________ | 28# | / \ | 29# | +------|------------+ +-------|----------+ | 30# | | + LAG2.100 | | + LAG2.200 | | 31# | | | | | | 32# | | BR1 (802.1d) | | BR2 (802.1d) | | 33# | | 192.0.2.2/28 | | 192.0.2.18/28 | | 34# | | 2001:db8:1::2/64 | | 2001:db8:3:2/64 | | 35# | | | | | | 36# | +-------------------+ +------------------+ | 37# | | 38# | + LAG3.100 + LAG3.200 | 39# | | 192.0.2.129/28 | 192.0.2.145/28 | 40# | | 2001:db8:2::1/64 | 2001:db8:4::1/64 | 41# | | | | 42# | \_________ ___________/ | 43# | v | 44# | + LAG3 (team) | 45# | ____|____ | 46# | / \ | 47# | + $swp2 + $swp3 | 48# | | | | 49# +-------|---------|--------------------------+ 50# | | 51# +-------|---------|--------------------------+ 52# | | | | 53# | + $h2 + $h3 | 54# | \____ ___/ | 55# | | | 56# | + LAG4 (team) | 57# | | | 58# | __________^__________ | 59# | / \ | 60# | | | | 61# | + LAG4.100 + LAG4.200 | 62# | 192.0.2.130/28 192.0.2.146/28 | 63# | 2001:db8:2::2/64 2001:db8:4::2/64 | 64# | | 65# | H2 (vrf) | 66# +--------------------------------------------+ 67 68ALL_TESTS=" 69 ping_ipv4 70 ping_ipv6 71 72 $(: exercise remastering of LAG2 slaves ) 73 config_deslave_swp4 74 config_wait 75 ping_ipv4 76 ping_ipv6 77 config_enslave_swp4 78 config_deslave_swp1 79 config_wait 80 ping_ipv4 81 ping_ipv6 82 config_deslave_swp4 83 config_enslave_swp1 84 config_enslave_swp4 85 config_wait 86 ping_ipv4 87 ping_ipv6 88 89 $(: exercise remastering of LAG2 itself ) 90 config_remaster_lag2 91 config_wait 92 ping_ipv4 93 ping_ipv6 94 95 $(: exercise remastering of LAG3 slaves ) 96 config_deslave_swp2 97 config_wait 98 ping_ipv4 99 ping_ipv6 100 config_enslave_swp2 101 config_deslave_swp3 102 config_wait 103 ping_ipv4 104 ping_ipv6 105 config_deslave_swp2 106 config_enslave_swp3 107 config_enslave_swp2 108 config_wait 109 ping_ipv4 110 ping_ipv6 111" 112NUM_NETIFS=8 113source lib.sh 114 115h1_create() 116{ 117 team_create lag1 lacp 118 ip link set dev lag1 addrgenmode none 119 ip link set dev lag1 address $(mac_get $h1) 120 ip link set dev $h1 master lag1 121 ip link set dev $h4 master lag1 122 simple_if_init lag1 123 ip link set dev $h1 up 124 ip link set dev $h4 up 125 126 vlan_create lag1 100 vlag1 192.0.2.1/28 2001:db8:1::1/64 127 vlan_create lag1 200 vlag1 192.0.2.17/28 2001:db8:3::1/64 128 129 ip -4 route add 192.0.2.128/28 vrf vlag1 nexthop via 192.0.2.2 130 ip -6 route add 2001:db8:2::/64 vrf vlag1 nexthop via 2001:db8:1::2 131 132 ip -4 route add 192.0.2.144/28 vrf vlag1 nexthop via 192.0.2.18 133 ip -6 route add 2001:db8:4::/64 vrf vlag1 nexthop via 2001:db8:3::2 134} 135 136h1_destroy() 137{ 138 ip -6 route del 2001:db8:4::/64 vrf vlag1 139 ip -4 route del 192.0.2.144/28 vrf vlag1 140 141 ip -6 route del 2001:db8:2::/64 vrf vlag1 142 ip -4 route del 192.0.2.128/28 vrf vlag1 143 144 vlan_destroy lag1 200 145 vlan_destroy lag1 100 146 147 ip link set dev $h4 down 148 ip link set dev $h1 down 149 simple_if_fini lag1 150 ip link set dev $h4 nomaster 151 ip link set dev $h1 nomaster 152 team_destroy lag1 153} 154 155h2_create() 156{ 157 team_create lag4 lacp 158 ip link set dev lag4 addrgenmode none 159 ip link set dev lag4 address $(mac_get $h2) 160 ip link set dev $h2 master lag4 161 ip link set dev $h3 master lag4 162 simple_if_init lag4 163 ip link set dev $h2 up 164 ip link set dev $h3 up 165 166 vlan_create lag4 100 vlag4 192.0.2.130/28 2001:db8:2::2/64 167 vlan_create lag4 200 vlag4 192.0.2.146/28 2001:db8:4::2/64 168 169 ip -4 route add 192.0.2.0/28 vrf vlag4 nexthop via 192.0.2.129 170 ip -6 route add 2001:db8:1::/64 vrf vlag4 nexthop via 2001:db8:2::1 171 172 ip -4 route add 192.0.2.16/28 vrf vlag4 nexthop via 192.0.2.145 173 ip -6 route add 2001:db8:3::/64 vrf vlag4 nexthop via 2001:db8:4::1 174} 175 176h2_destroy() 177{ 178 ip -6 route del 2001:db8:3::/64 vrf vlag4 179 ip -4 route del 192.0.2.16/28 vrf vlag4 180 181 ip -6 route del 2001:db8:1::/64 vrf vlag4 182 ip -4 route del 192.0.2.0/28 vrf vlag4 183 184 vlan_destroy lag4 200 185 vlan_destroy lag4 100 186 187 ip link set dev $h3 down 188 ip link set dev $h2 down 189 simple_if_fini lag4 190 ip link set dev $h3 nomaster 191 ip link set dev $h2 nomaster 192 team_destroy lag4 193} 194 195router_create() 196{ 197 team_create lag2 lacp 198 ip link set dev lag2 addrgenmode none 199 ip link set dev lag2 address $(mac_get $swp1) 200 ip link set dev $swp1 master lag2 201 ip link set dev $swp4 master lag2 202 203 vlan_create lag2 100 204 vlan_create lag2 200 205 206 ip link add name br1 type bridge vlan_filtering 0 207 ip link set dev br1 address $(mac_get lag2.100) 208 ip link set dev lag2.100 master br1 209 210 ip link add name br2 type bridge vlan_filtering 0 211 ip link set dev br2 address $(mac_get lag2.200) 212 ip link set dev lag2.200 master br2 213 214 ip link set dev $swp1 up 215 ip link set dev $swp4 up 216 ip link set dev br1 up 217 ip link set dev br2 up 218 219 __addr_add_del br1 add 192.0.2.2/28 2001:db8:1::2/64 220 __addr_add_del br2 add 192.0.2.18/28 2001:db8:3::2/64 221 222 team_create lag3 lacp 223 ip link set dev lag3 addrgenmode none 224 ip link set dev lag3 address $(mac_get $swp2) 225 ip link set dev $swp2 master lag3 226 ip link set dev $swp3 master lag3 227 ip link set dev $swp2 up 228 ip link set dev $swp3 up 229 230 vlan_create lag3 100 231 vlan_create lag3 200 232 233 __addr_add_del lag3.100 add 192.0.2.129/28 2001:db8:2::1/64 234 __addr_add_del lag3.200 add 192.0.2.145/28 2001:db8:4::1/64 235} 236 237router_destroy() 238{ 239 __addr_add_del lag3.200 del 192.0.2.145/28 2001:db8:4::1/64 240 __addr_add_del lag3.100 del 192.0.2.129/28 2001:db8:2::1/64 241 242 vlan_destroy lag3 200 243 vlan_destroy lag3 100 244 245 ip link set dev $swp3 down 246 ip link set dev $swp2 down 247 ip link set dev $swp3 nomaster 248 ip link set dev $swp2 nomaster 249 team_destroy lag3 250 251 __addr_add_del br2 del 192.0.2.18/28 2001:db8:3::2/64 252 __addr_add_del br1 del 192.0.2.2/28 2001:db8:1::2/64 253 254 ip link set dev br2 down 255 ip link set dev br1 down 256 ip link set dev $swp4 down 257 ip link set dev $swp1 down 258 259 ip link set dev lag2.200 nomaster 260 ip link del dev br2 261 262 ip link set dev lag2.100 nomaster 263 ip link del dev br1 264 265 vlan_destroy lag2 200 266 vlan_destroy lag2 100 267 268 ip link set dev $swp4 nomaster 269 ip link set dev $swp1 nomaster 270 team_destroy lag2 271} 272 273config_remaster_lag2() 274{ 275 log_info "Remaster bridge slaves" 276 277 ip link set dev lag2.200 nomaster 278 ip link set dev lag2.100 nomaster 279 sleep 2 280 ip link set dev lag2.100 master br1 281 ip link set dev lag2.200 master br2 282} 283 284config_deslave() 285{ 286 local netdev=$1; shift 287 288 log_info "Deslave $netdev" 289 ip link set dev $netdev down 290 ip link set dev $netdev nomaster 291 ip link set dev $netdev up 292} 293 294config_deslave_swp1() 295{ 296 config_deslave $swp1 297} 298 299config_deslave_swp2() 300{ 301 config_deslave $swp2 302} 303 304config_deslave_swp3() 305{ 306 config_deslave $swp3 307} 308 309config_deslave_swp4() 310{ 311 config_deslave $swp4 312} 313 314config_enslave() 315{ 316 local netdev=$1; shift 317 local master=$1; shift 318 319 log_info "Enslave $netdev to $master" 320 ip link set dev $netdev down 321 ip link set dev $netdev master $master 322 ip link set dev $netdev up 323} 324 325config_enslave_swp1() 326{ 327 config_enslave $swp1 lag2 328} 329 330config_enslave_swp2() 331{ 332 config_enslave $swp2 lag3 333} 334 335config_enslave_swp3() 336{ 337 config_enslave $swp3 lag3 338} 339 340config_enslave_swp4() 341{ 342 config_enslave $swp4 lag2 343} 344 345config_wait() 346{ 347 setup_wait_dev lag2 348 setup_wait_dev lag3 349} 350 351setup_prepare() 352{ 353 h1=${NETIFS[p1]} 354 swp1=${NETIFS[p2]} 355 356 swp2=${NETIFS[p3]} 357 h2=${NETIFS[p4]} 358 359 swp3=${NETIFS[p5]} 360 h3=${NETIFS[p6]} 361 362 h4=${NETIFS[p7]} 363 swp4=${NETIFS[p8]} 364 365 vrf_prepare 366 367 h1_create 368 h2_create 369 370 router_create 371 372 forwarding_enable 373} 374 375cleanup() 376{ 377 pre_cleanup 378 379 forwarding_restore 380 381 router_destroy 382 383 h2_destroy 384 h1_destroy 385 386 vrf_cleanup 387} 388 389ping_ipv4() 390{ 391 ping_test lag1.100 192.0.2.130 ": via 100" 392 ping_test lag1.200 192.0.2.146 ": via 200" 393} 394 395ping_ipv6() 396{ 397 ping6_test lag1.100 2001:db8:2::2 ": via 100" 398 ping6_test lag1.200 2001:db8:4::2 ": via 200" 399} 400 401trap cleanup EXIT 402 403setup_prepare 404setup_wait 405 406tests_run 407 408exit $EXIT_STATUS 409