Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # This test is for checking VXLAN underlay in a non-default VRF.
0005 #
0006 # It simulates two hypervisors running a VM each using four network namespaces:
0007 # two for the HVs, two for the VMs.
0008 # A small VXLAN tunnel is made between the two hypervisors to have the two vms
0009 # in the same virtual L2:
0010 #
0011 # +-------------------+                                    +-------------------+
0012 # |                   |                                    |                   |
0013 # |    vm-1 netns     |                                    |    vm-2 netns     |
0014 # |                   |                                    |                   |
0015 # |  +-------------+  |                                    |  +-------------+  |
0016 # |  |   veth-hv   |  |                                    |  |   veth-hv   |  |
0017 # |  | 10.0.0.1/24 |  |                                    |  | 10.0.0.2/24 |  |
0018 # |  +-------------+  |                                    |  +-------------+  |
0019 # |        .          |                                    |         .         |
0020 # +-------------------+                                    +-------------------+
0021 #          .                                                         .
0022 #          .                                                         .
0023 #          .                                                         .
0024 # +-----------------------------------+   +------------------------------------+
0025 # |        .                          |   |                          .         |
0026 # |  +----------+                     |   |                     +----------+   |
0027 # |  | veth-tap |                     |   |                     | veth-tap |   |
0028 # |  +----+-----+                     |   |                     +----+-----+   |
0029 # |       |                           |   |                          |         |
0030 # |    +--+--+      +--------------+  |   |  +--------------+     +--+--+      |
0031 # |    | br0 |      | vrf-underlay |  |   |  | vrf-underlay |     | br0 |      |
0032 # |    +--+--+      +-------+------+  |   |  +------+-------+     +--+--+      |
0033 # |       |                 |         |   |         |                |         |
0034 # |   +---+----+    +-------+-------+ |   | +-------+-------+    +---+----+    |
0035 # |   | vxlan0 |....|     veth0     |.|...|.|     veth0     |....| vxlan0 |    |
0036 # |   +--------+    | 172.16.0.1/24 | |   | | 172.16.0.2/24 |    +--------+    |
0037 # |                 +---------------+ |   | +---------------+                  |
0038 # |                                   |   |                                    |
0039 # |             hv-1 netns            |   |           hv-2 netns               |
0040 # |                                   |   |                                    |
0041 # +-----------------------------------+   +------------------------------------+
0042 #
0043 # This tests both the connectivity between vm-1 and vm-2, and that the underlay
0044 # can be moved in and out of the vrf by unsetting and setting veth0's master.
0045 
0046 set -e
0047 
0048 cleanup() {
0049     ip link del veth-hv-1 2>/dev/null || true
0050     ip link del veth-tap 2>/dev/null || true
0051 
0052     for ns in hv-1 hv-2 vm-1 vm-2; do
0053         ip netns del $ns 2>/dev/null || true
0054     done
0055 }
0056 
0057 # Clean start
0058 cleanup &> /dev/null
0059 
0060 [[ $1 == "clean" ]] && exit 0
0061 
0062 trap cleanup EXIT
0063 
0064 # Setup "Hypervisors" simulated with netns
0065 ip link add veth-hv-1 type veth peer name veth-hv-2
0066 setup-hv-networking() {
0067     hv=$1
0068 
0069     ip netns add hv-$hv
0070     ip link set veth-hv-$hv netns hv-$hv
0071     ip -netns hv-$hv link set veth-hv-$hv name veth0
0072 
0073     ip -netns hv-$hv link add vrf-underlay type vrf table 1
0074     ip -netns hv-$hv link set vrf-underlay up
0075     ip -netns hv-$hv addr add 172.16.0.$hv/24 dev veth0
0076     ip -netns hv-$hv link set veth0 up
0077 
0078     ip -netns hv-$hv link add br0 type bridge
0079     ip -netns hv-$hv link set br0 up
0080 
0081     ip -netns hv-$hv link add vxlan0 type vxlan id 10 local 172.16.0.$hv dev veth0 dstport 4789
0082     ip -netns hv-$hv link set vxlan0 master br0
0083     ip -netns hv-$hv link set vxlan0 up
0084 }
0085 setup-hv-networking 1
0086 setup-hv-networking 2
0087 
0088 # Check connectivity between HVs by pinging hv-2 from hv-1
0089 echo -n "Checking HV connectivity                                           "
0090 ip netns exec hv-1 ping -c 1 -W 1 172.16.0.2 &> /dev/null || (echo "[FAIL]"; false)
0091 echo "[ OK ]"
0092 
0093 # Setups a "VM" simulated by a netns an a veth pair
0094 setup-vm() {
0095     id=$1
0096 
0097     ip netns add vm-$id
0098     ip link add veth-tap type veth peer name veth-hv
0099 
0100     ip link set veth-tap netns hv-$id
0101     ip -netns hv-$id link set veth-tap master br0
0102     ip -netns hv-$id link set veth-tap up
0103 
0104     ip link set veth-hv address 02:1d:8d:dd:0c:6$id
0105 
0106     ip link set veth-hv netns vm-$id
0107     ip -netns vm-$id addr add 10.0.0.$id/24 dev veth-hv
0108     ip -netns vm-$id link set veth-hv up
0109 }
0110 setup-vm 1
0111 setup-vm 2
0112 
0113 # Setup VTEP routes to make ARP work
0114 bridge -netns hv-1 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.2 self permanent
0115 bridge -netns hv-2 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.1 self permanent
0116 
0117 echo -n "Check VM connectivity through VXLAN (underlay in the default VRF)  "
0118 ip netns exec vm-1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false)
0119 echo "[ OK ]"
0120 
0121 # Move the underlay to a non-default VRF
0122 ip -netns hv-1 link set veth0 vrf vrf-underlay
0123 ip -netns hv-1 link set vxlan0 down
0124 ip -netns hv-1 link set vxlan0 up
0125 ip -netns hv-2 link set veth0 vrf vrf-underlay
0126 ip -netns hv-2 link set vxlan0 down
0127 ip -netns hv-2 link set vxlan0 up
0128 
0129 echo -n "Check VM connectivity through VXLAN (underlay in a VRF)            "
0130 ip netns exec vm-1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false)
0131 echo "[ OK ]"