14cec8529SPetr Machata#!/bin/bash 24cec8529SPetr Machata# SPDX-License-Identifier: GPL-2.0 34cec8529SPetr Machata 44cec8529SPetr Machata# +-----------------------+ +------------------------+ 54cec8529SPetr Machata# | H1 (vrf) | | H2 (vrf) | 64cec8529SPetr Machata# | + $h1.10 | | + $h2.10 | 74cec8529SPetr Machata# | | 192.0.2.1/28 | | | 192.0.2.2/28 | 84cec8529SPetr Machata# | | | | | | 94cec8529SPetr Machata# | | + $h1.20 | | | + $h2.20 | 104cec8529SPetr Machata# | \ | 198.51.100.1/24 | | \ | 198.51.100.2/24 | 114cec8529SPetr Machata# | \| | | \| | 124cec8529SPetr Machata# | + $h1 | | + $h2 | 134cec8529SPetr Machata# +----|------------------+ +----|-------------------+ 144cec8529SPetr Machata# | | 154cec8529SPetr Machata# +----|--------------------------------------------------|-------------------+ 164cec8529SPetr Machata# | SW | | | 174cec8529SPetr Machata# | +--|--------------------------------------------------|-----------------+ | 184cec8529SPetr Machata# | | + $swp1 BR1 (802.1ad) + $swp2 | | 194cec8529SPetr Machata# | | vid 100 pvid untagged vid 100 pvid | | 204cec8529SPetr Machata# | | untagged | | 214cec8529SPetr Machata# | | + vx100 (vxlan) | | 224cec8529SPetr Machata# | | local 192.0.2.17 | | 234cec8529SPetr Machata# | | remote 192.0.2.34 192.0.2.50 | | 244cec8529SPetr Machata# | | id 1000 dstport $VXPORT | | 254cec8529SPetr Machata# | | vid 100 pvid untagged | | 264cec8529SPetr Machata# | +-----------------------------------------------------------------------+ | 274cec8529SPetr Machata# | | 284cec8529SPetr Machata# | 192.0.2.32/28 via 192.0.2.18 | 294cec8529SPetr Machata# | 192.0.2.48/28 via 192.0.2.18 | 304cec8529SPetr Machata# | | 314cec8529SPetr Machata# | + $rp1 | 324cec8529SPetr Machata# | | 192.0.2.17/28 | 334cec8529SPetr Machata# +----|----------------------------------------------------------------------+ 344cec8529SPetr Machata# | 354cec8529SPetr Machata# +----|--------------------------------------------------------+ 364cec8529SPetr Machata# | | VRP2 (vrf) | 374cec8529SPetr Machata# | + $rp2 | 384cec8529SPetr Machata# | 192.0.2.18/28 | 394cec8529SPetr Machata# | | (maybe) HW 404cec8529SPetr Machata# ============================================================================= 414cec8529SPetr Machata# | | (likely) SW 424cec8529SPetr Machata# | + v1 (veth) + v3 (veth) | 434cec8529SPetr Machata# | | 192.0.2.33/28 | 192.0.2.49/28 | 444cec8529SPetr Machata# +----|---------------------------------------|----------------+ 454cec8529SPetr Machata# | | 464cec8529SPetr Machata# +----|------------------------------+ +----|------------------------------+ 474cec8529SPetr Machata# | + v2 (veth) NS1 (netns) | | + v4 (veth) NS2 (netns) | 484cec8529SPetr Machata# | 192.0.2.34/28 | | 192.0.2.50/28 | 494cec8529SPetr Machata# | | | | 504cec8529SPetr Machata# | 192.0.2.16/28 via 192.0.2.33 | | 192.0.2.16/28 via 192.0.2.49 | 514cec8529SPetr Machata# | 192.0.2.50/32 via 192.0.2.33 | | 192.0.2.34/32 via 192.0.2.49 | 524cec8529SPetr Machata# | | | | 534cec8529SPetr Machata# | +-------------------------------+ | | +-------------------------------+ | 544cec8529SPetr Machata# | | BR2 (802.1ad) | | | | BR2 (802.1ad) | | 554cec8529SPetr Machata# | | + vx100 (vxlan) | | | | + vx100 (vxlan) | | 564cec8529SPetr Machata# | | local 192.0.2.34 | | | | local 192.0.2.50 | | 574cec8529SPetr Machata# | | remote 192.0.2.17 | | | | remote 192.0.2.17 | | 584cec8529SPetr Machata# | | remote 192.0.2.50 | | | | remote 192.0.2.34 | | 594cec8529SPetr Machata# | | id 1000 dstport $VXPORT | | | | id 1000 dstport $VXPORT | | 604cec8529SPetr Machata# | | vid 100 pvid untagged | | | | vid 100 pvid untagged | | 614cec8529SPetr Machata# | | | | | | | | 624cec8529SPetr Machata# | | + w1 (veth) | | | | + w1 (veth) | | 634cec8529SPetr Machata# | | | vid 100 pvid untagged | | | | | vid 100 pvid untagged | | 644cec8529SPetr Machata# | +--|----------------------------+ | | +--|----------------------------+ | 654cec8529SPetr Machata# | | | | | | 664cec8529SPetr Machata# | +--|----------------------------+ | | +--|----------------------------+ | 674cec8529SPetr Machata# | | | VW2 (vrf) | | | | | VW2 (vrf) | | 684cec8529SPetr Machata# | | + w2 (veth) | | | | + w2 (veth) | | 694cec8529SPetr Machata# | | |\ | | | | |\ | | 704cec8529SPetr Machata# | | | + w2.10 | | | | | + w2.10 | | 714cec8529SPetr Machata# | | | 192.0.2.3/28 | | | | | 192.0.2.4/28 | | 724cec8529SPetr Machata# | | | | | | | | | | 734cec8529SPetr Machata# | | + w2.20 | | | | + w2.20 | | 744cec8529SPetr Machata# | | 198.51.100.3/24 | | | | 198.51.100.4/24 | | 754cec8529SPetr Machata# | +-------------------------------+ | | +-------------------------------+ | 764cec8529SPetr Machata# +-----------------------------------+ +-----------------------------------+ 774cec8529SPetr Machata 784cec8529SPetr Machata: ${VXPORT:=4789} 794cec8529SPetr Machataexport VXPORT 804cec8529SPetr Machata 814cec8529SPetr Machata: ${ALL_TESTS:=" 824cec8529SPetr Machata ping_ipv4 834cec8529SPetr Machata "} 844cec8529SPetr Machata 854cec8529SPetr MachataNUM_NETIFS=6 864cec8529SPetr Machatasource lib.sh 874cec8529SPetr Machata 884cec8529SPetr Machatah1_create() 894cec8529SPetr Machata{ 904cec8529SPetr Machata simple_if_init $h1 914cec8529SPetr Machata tc qdisc add dev $h1 clsact 924cec8529SPetr Machata vlan_create $h1 10 v$h1 192.0.2.1/28 934cec8529SPetr Machata vlan_create $h1 20 v$h1 198.51.100.1/24 944cec8529SPetr Machata} 954cec8529SPetr Machata 964cec8529SPetr Machatah1_destroy() 974cec8529SPetr Machata{ 984cec8529SPetr Machata vlan_destroy $h1 20 994cec8529SPetr Machata vlan_destroy $h1 10 1004cec8529SPetr Machata tc qdisc del dev $h1 clsact 1014cec8529SPetr Machata simple_if_fini $h1 1024cec8529SPetr Machata} 1034cec8529SPetr Machata 1044cec8529SPetr Machatah2_create() 1054cec8529SPetr Machata{ 1064cec8529SPetr Machata simple_if_init $h2 1074cec8529SPetr Machata tc qdisc add dev $h2 clsact 1084cec8529SPetr Machata vlan_create $h2 10 v$h2 192.0.2.2/28 1094cec8529SPetr Machata vlan_create $h2 20 v$h2 198.51.100.2/24 1104cec8529SPetr Machata} 1114cec8529SPetr Machata 1124cec8529SPetr Machatah2_destroy() 1134cec8529SPetr Machata{ 1144cec8529SPetr Machata vlan_destroy $h2 20 1154cec8529SPetr Machata vlan_destroy $h2 10 1164cec8529SPetr Machata tc qdisc del dev $h2 clsact 1174cec8529SPetr Machata simple_if_fini $h2 1184cec8529SPetr Machata} 1194cec8529SPetr Machata 1204cec8529SPetr Machatarp1_set_addr() 1214cec8529SPetr Machata{ 1224cec8529SPetr Machata ip address add dev $rp1 192.0.2.17/28 1234cec8529SPetr Machata 1244cec8529SPetr Machata ip route add 192.0.2.32/28 nexthop via 192.0.2.18 1254cec8529SPetr Machata ip route add 192.0.2.48/28 nexthop via 192.0.2.18 1264cec8529SPetr Machata} 1274cec8529SPetr Machata 1284cec8529SPetr Machatarp1_unset_addr() 1294cec8529SPetr Machata{ 1304cec8529SPetr Machata ip route del 192.0.2.48/28 nexthop via 192.0.2.18 1314cec8529SPetr Machata ip route del 192.0.2.32/28 nexthop via 192.0.2.18 1324cec8529SPetr Machata 1334cec8529SPetr Machata ip address del dev $rp1 192.0.2.17/28 1344cec8529SPetr Machata} 1354cec8529SPetr Machata 1364cec8529SPetr Machataswitch_create() 1374cec8529SPetr Machata{ 1384cec8529SPetr Machata ip link add name br1 type bridge vlan_filtering 1 vlan_protocol 802.1ad \ 1394cec8529SPetr Machata vlan_default_pvid 0 mcast_snooping 0 140*8c3736ceSPetr Machata ip link set dev br1 addrgenmode none 1414cec8529SPetr Machata # Make sure the bridge uses the MAC address of the local port and not 1424cec8529SPetr Machata # that of the VxLAN's device. 1434cec8529SPetr Machata ip link set dev br1 address $(mac_get $swp1) 1444cec8529SPetr Machata ip link set dev br1 up 1454cec8529SPetr Machata 1464cec8529SPetr Machata ip link set dev $rp1 up 1474cec8529SPetr Machata rp1_set_addr 1484cec8529SPetr Machata 1494cec8529SPetr Machata ip link add name vx100 type vxlan id 1000 \ 1504cec8529SPetr Machata local 192.0.2.17 dstport "$VXPORT" \ 1514cec8529SPetr Machata nolearning noudpcsum tos inherit ttl 100 1524cec8529SPetr Machata ip link set dev vx100 up 1534cec8529SPetr Machata 1544cec8529SPetr Machata ip link set dev vx100 master br1 1554cec8529SPetr Machata bridge vlan add vid 100 dev vx100 pvid untagged 1564cec8529SPetr Machata 1574cec8529SPetr Machata ip link set dev $swp1 master br1 1584cec8529SPetr Machata ip link set dev $swp1 up 1594cec8529SPetr Machata bridge vlan add vid 100 dev $swp1 pvid untagged 1604cec8529SPetr Machata 1614cec8529SPetr Machata ip link set dev $swp2 master br1 1624cec8529SPetr Machata ip link set dev $swp2 up 1634cec8529SPetr Machata bridge vlan add vid 100 dev $swp2 pvid untagged 1644cec8529SPetr Machata 1654cec8529SPetr Machata bridge fdb append dev vx100 00:00:00:00:00:00 dst 192.0.2.34 self 1664cec8529SPetr Machata bridge fdb append dev vx100 00:00:00:00:00:00 dst 192.0.2.50 self 1674cec8529SPetr Machata} 1684cec8529SPetr Machata 1694cec8529SPetr Machataswitch_destroy() 1704cec8529SPetr Machata{ 1714cec8529SPetr Machata bridge fdb del dev vx100 00:00:00:00:00:00 dst 192.0.2.50 self 1724cec8529SPetr Machata bridge fdb del dev vx100 00:00:00:00:00:00 dst 192.0.2.34 self 1734cec8529SPetr Machata 1744cec8529SPetr Machata bridge vlan del vid 100 dev $swp2 1754cec8529SPetr Machata ip link set dev $swp2 down 1764cec8529SPetr Machata ip link set dev $swp2 nomaster 1774cec8529SPetr Machata 1784cec8529SPetr Machata bridge vlan del vid 100 dev $swp1 1794cec8529SPetr Machata ip link set dev $swp1 down 1804cec8529SPetr Machata ip link set dev $swp1 nomaster 1814cec8529SPetr Machata 1824cec8529SPetr Machata ip link set dev vx100 nomaster 1834cec8529SPetr Machata ip link set dev vx100 down 1844cec8529SPetr Machata ip link del dev vx100 1854cec8529SPetr Machata 1864cec8529SPetr Machata rp1_unset_addr 1874cec8529SPetr Machata ip link set dev $rp1 down 1884cec8529SPetr Machata 1894cec8529SPetr Machata ip link set dev br1 down 1904cec8529SPetr Machata ip link del dev br1 1914cec8529SPetr Machata} 1924cec8529SPetr Machata 1934cec8529SPetr Machatavrp2_create() 1944cec8529SPetr Machata{ 1954cec8529SPetr Machata simple_if_init $rp2 192.0.2.18/28 1964cec8529SPetr Machata __simple_if_init v1 v$rp2 192.0.2.33/28 1974cec8529SPetr Machata __simple_if_init v3 v$rp2 192.0.2.49/28 1984cec8529SPetr Machata tc qdisc add dev v1 clsact 1994cec8529SPetr Machata} 2004cec8529SPetr Machata 2014cec8529SPetr Machatavrp2_destroy() 2024cec8529SPetr Machata{ 2034cec8529SPetr Machata tc qdisc del dev v1 clsact 2044cec8529SPetr Machata __simple_if_fini v3 192.0.2.49/28 2054cec8529SPetr Machata __simple_if_fini v1 192.0.2.33/28 2064cec8529SPetr Machata simple_if_fini $rp2 192.0.2.18/28 2074cec8529SPetr Machata} 2084cec8529SPetr Machata 2094cec8529SPetr Machatans_init_common() 2104cec8529SPetr Machata{ 2114cec8529SPetr Machata local in_if=$1; shift 2124cec8529SPetr Machata local in_addr=$1; shift 2134cec8529SPetr Machata local other_in_addr=$1; shift 2144cec8529SPetr Machata local nh_addr=$1; shift 2154cec8529SPetr Machata local host_addr1=$1; shift 2164cec8529SPetr Machata local host_addr2=$1; shift 2174cec8529SPetr Machata 2184cec8529SPetr Machata ip link set dev $in_if up 2194cec8529SPetr Machata ip address add dev $in_if $in_addr/28 2204cec8529SPetr Machata tc qdisc add dev $in_if clsact 2214cec8529SPetr Machata 2224cec8529SPetr Machata ip link add name br2 type bridge vlan_filtering 1 vlan_protocol 802.1ad \ 2234cec8529SPetr Machata vlan_default_pvid 0 2244cec8529SPetr Machata ip link set dev br2 up 2254cec8529SPetr Machata 2264cec8529SPetr Machata ip link add name w1 type veth peer name w2 2274cec8529SPetr Machata 2284cec8529SPetr Machata ip link set dev w1 master br2 2294cec8529SPetr Machata ip link set dev w1 up 2304cec8529SPetr Machata bridge vlan add vid 100 dev w1 pvid untagged 2314cec8529SPetr Machata 2324cec8529SPetr Machata ip link add name vx100 type vxlan id 1000 local $in_addr \ 2334cec8529SPetr Machata dstport "$VXPORT" 2344cec8529SPetr Machata ip link set dev vx100 up 2354cec8529SPetr Machata bridge fdb append dev vx100 00:00:00:00:00:00 dst 192.0.2.17 self 2364cec8529SPetr Machata bridge fdb append dev vx100 00:00:00:00:00:00 dst $other_in_addr self 2374cec8529SPetr Machata 2384cec8529SPetr Machata ip link set dev vx100 master br2 2394cec8529SPetr Machata tc qdisc add dev vx100 clsact 2404cec8529SPetr Machata 2414cec8529SPetr Machata bridge vlan add vid 100 dev vx100 pvid untagged 2424cec8529SPetr Machata 2434cec8529SPetr Machata simple_if_init w2 2444cec8529SPetr Machata vlan_create w2 10 vw2 $host_addr1/28 2454cec8529SPetr Machata vlan_create w2 20 vw2 $host_addr2/24 2464cec8529SPetr Machata 2474cec8529SPetr Machata ip route add 192.0.2.16/28 nexthop via $nh_addr 2484cec8529SPetr Machata ip route add $other_in_addr/32 nexthop via $nh_addr 2494cec8529SPetr Machata} 2504cec8529SPetr Machataexport -f ns_init_common 2514cec8529SPetr Machata 2524cec8529SPetr Machatans1_create() 2534cec8529SPetr Machata{ 2544cec8529SPetr Machata ip netns add ns1 2554cec8529SPetr Machata ip link set dev v2 netns ns1 2564cec8529SPetr Machata in_ns ns1 \ 2574cec8529SPetr Machata ns_init_common v2 192.0.2.34 192.0.2.50 192.0.2.33 \ 2584cec8529SPetr Machata 192.0.2.3 198.51.100.3 2594cec8529SPetr Machata} 2604cec8529SPetr Machata 2614cec8529SPetr Machatans1_destroy() 2624cec8529SPetr Machata{ 2634cec8529SPetr Machata ip netns exec ns1 ip link set dev v2 netns 1 2644cec8529SPetr Machata ip netns del ns1 2654cec8529SPetr Machata} 2664cec8529SPetr Machata 2674cec8529SPetr Machatans2_create() 2684cec8529SPetr Machata{ 2694cec8529SPetr Machata ip netns add ns2 2704cec8529SPetr Machata ip link set dev v4 netns ns2 2714cec8529SPetr Machata in_ns ns2 \ 2724cec8529SPetr Machata ns_init_common v4 192.0.2.50 192.0.2.34 192.0.2.49 \ 2734cec8529SPetr Machata 192.0.2.4 198.51.100.4 2744cec8529SPetr Machata} 2754cec8529SPetr Machata 2764cec8529SPetr Machatans2_destroy() 2774cec8529SPetr Machata{ 2784cec8529SPetr Machata ip netns exec ns2 ip link set dev v4 netns 1 2794cec8529SPetr Machata ip netns del ns2 2804cec8529SPetr Machata} 2814cec8529SPetr Machata 2824cec8529SPetr Machatasetup_prepare() 2834cec8529SPetr Machata{ 2844cec8529SPetr Machata h1=${NETIFS[p1]} 2854cec8529SPetr Machata swp1=${NETIFS[p2]} 2864cec8529SPetr Machata 2874cec8529SPetr Machata swp2=${NETIFS[p3]} 2884cec8529SPetr Machata h2=${NETIFS[p4]} 2894cec8529SPetr Machata 2904cec8529SPetr Machata rp1=${NETIFS[p5]} 2914cec8529SPetr Machata rp2=${NETIFS[p6]} 2924cec8529SPetr Machata 2934cec8529SPetr Machata vrf_prepare 2944cec8529SPetr Machata forwarding_enable 2954cec8529SPetr Machata 2964cec8529SPetr Machata h1_create 2974cec8529SPetr Machata h2_create 2984cec8529SPetr Machata switch_create 2994cec8529SPetr Machata 3004cec8529SPetr Machata ip link add name v1 type veth peer name v2 3014cec8529SPetr Machata ip link add name v3 type veth peer name v4 3024cec8529SPetr Machata vrp2_create 3034cec8529SPetr Machata ns1_create 3044cec8529SPetr Machata ns2_create 3054cec8529SPetr Machata 3064cec8529SPetr Machata r1_mac=$(in_ns ns1 mac_get w2) 3074cec8529SPetr Machata r2_mac=$(in_ns ns2 mac_get w2) 3084cec8529SPetr Machata h2_mac=$(mac_get $h2) 3094cec8529SPetr Machata} 3104cec8529SPetr Machata 3114cec8529SPetr Machatacleanup() 3124cec8529SPetr Machata{ 3134cec8529SPetr Machata pre_cleanup 3144cec8529SPetr Machata 3154cec8529SPetr Machata ns2_destroy 3164cec8529SPetr Machata ns1_destroy 3174cec8529SPetr Machata vrp2_destroy 3184cec8529SPetr Machata ip link del dev v3 3194cec8529SPetr Machata ip link del dev v1 3204cec8529SPetr Machata 3214cec8529SPetr Machata switch_destroy 3224cec8529SPetr Machata h2_destroy 3234cec8529SPetr Machata h1_destroy 3244cec8529SPetr Machata 3254cec8529SPetr Machata forwarding_restore 3264cec8529SPetr Machata vrf_cleanup 3274cec8529SPetr Machata} 3284cec8529SPetr Machata 3294cec8529SPetr Machataping_ipv4() 3304cec8529SPetr Machata{ 3314cec8529SPetr Machata ping_test $h1 192.0.2.2 ": local->local" 3324cec8529SPetr Machata ping_test $h1 192.0.2.3 ": local->remote 1" 3334cec8529SPetr Machata ping_test $h1 192.0.2.4 ": local->remote 2" 3344cec8529SPetr Machata} 3354cec8529SPetr Machata 3364cec8529SPetr Machatatest_all() 3374cec8529SPetr Machata{ 3384cec8529SPetr Machata echo "Running tests with UDP port $VXPORT" 3394cec8529SPetr Machata tests_run 3404cec8529SPetr Machata} 3414cec8529SPetr Machata 3424cec8529SPetr Machatatrap cleanup EXIT 3434cec8529SPetr Machata 3444cec8529SPetr Machatasetup_prepare 3454cec8529SPetr Machatasetup_wait 3464cec8529SPetr Machatatest_all 3474cec8529SPetr Machata 3484cec8529SPetr Machataexit $EXIT_STATUS 349