Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/net: convert test_vxlan_under_vrf.sh to run it in unique namespace

Here is the test result after conversion.

]# ./test_vxlan_under_vrf.sh
Checking HV connectivity [ OK ]
Check VM connectivity through VXLAN (underlay in the default VRF) [ OK ]
Check VM connectivity through VXLAN (underlay in a VRF) [ OK ]

Acked-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Hangbin Liu and committed by
David S. Miller
d6aab1f6 d79e907b

+36 -34
+36 -34
tools/testing/selftests/net/test_vxlan_under_vrf.sh
··· 43 43 # This tests both the connectivity between vm-1 and vm-2, and that the underlay 44 44 # can be moved in and out of the vrf by unsetting and setting veth0's master. 45 45 46 + source lib.sh 46 47 set -e 47 48 48 49 cleanup() { 49 50 ip link del veth-hv-1 2>/dev/null || true 50 51 ip link del veth-tap 2>/dev/null || true 51 52 52 - for ns in hv-1 hv-2 vm-1 vm-2; do 53 - ip netns del $ns 2>/dev/null || true 54 - done 53 + cleanup_ns $hv_1 $hv_2 $vm_1 $vm_2 55 54 } 56 55 57 56 # Clean start ··· 59 60 [[ $1 == "clean" ]] && exit 0 60 61 61 62 trap cleanup EXIT 63 + setup_ns hv_1 hv_2 vm_1 vm_2 64 + hv[1]=$hv_1 65 + hv[2]=$hv_2 66 + vm[1]=$vm_1 67 + vm[2]=$vm_2 62 68 63 69 # Setup "Hypervisors" simulated with netns 64 70 ip link add veth-hv-1 type veth peer name veth-hv-2 65 71 setup-hv-networking() { 66 - hv=$1 72 + id=$1 67 73 68 - ip netns add hv-$hv 69 - ip link set veth-hv-$hv netns hv-$hv 70 - ip -netns hv-$hv link set veth-hv-$hv name veth0 74 + ip link set veth-hv-$id netns ${hv[$id]} 75 + ip -netns ${hv[$id]} link set veth-hv-$id name veth0 71 76 72 - ip -netns hv-$hv link add vrf-underlay type vrf table 1 73 - ip -netns hv-$hv link set vrf-underlay up 74 - ip -netns hv-$hv addr add 172.16.0.$hv/24 dev veth0 75 - ip -netns hv-$hv link set veth0 up 77 + ip -netns ${hv[$id]} link add vrf-underlay type vrf table 1 78 + ip -netns ${hv[$id]} link set vrf-underlay up 79 + ip -netns ${hv[$id]} addr add 172.16.0.$id/24 dev veth0 80 + ip -netns ${hv[$id]} link set veth0 up 76 81 77 - ip -netns hv-$hv link add br0 type bridge 78 - ip -netns hv-$hv link set br0 up 82 + ip -netns ${hv[$id]} link add br0 type bridge 83 + ip -netns ${hv[$id]} link set br0 up 79 84 80 - ip -netns hv-$hv link add vxlan0 type vxlan id 10 local 172.16.0.$hv dev veth0 dstport 4789 81 - ip -netns hv-$hv link set vxlan0 master br0 82 - ip -netns hv-$hv link set vxlan0 up 85 + ip -netns ${hv[$id]} link add vxlan0 type vxlan id 10 local 172.16.0.$id dev veth0 dstport 4789 86 + ip -netns ${hv[$id]} link set vxlan0 master br0 87 + ip -netns ${hv[$id]} link set vxlan0 up 83 88 } 84 89 setup-hv-networking 1 85 90 setup-hv-networking 2 86 91 87 92 # Check connectivity between HVs by pinging hv-2 from hv-1 88 93 echo -n "Checking HV connectivity " 89 - ip netns exec hv-1 ping -c 1 -W 1 172.16.0.2 &> /dev/null || (echo "[FAIL]"; false) 94 + ip netns exec $hv_1 ping -c 1 -W 1 172.16.0.2 &> /dev/null || (echo "[FAIL]"; false) 90 95 echo "[ OK ]" 91 96 92 97 # Setups a "VM" simulated by a netns an a veth pair 93 98 setup-vm() { 94 99 id=$1 95 100 96 - ip netns add vm-$id 97 101 ip link add veth-tap type veth peer name veth-hv 98 102 99 - ip link set veth-tap netns hv-$id 100 - ip -netns hv-$id link set veth-tap master br0 101 - ip -netns hv-$id link set veth-tap up 103 + ip link set veth-tap netns ${hv[$id]} 104 + ip -netns ${hv[$id]} link set veth-tap master br0 105 + ip -netns ${hv[$id]} link set veth-tap up 102 106 103 107 ip link set veth-hv address 02:1d:8d:dd:0c:6$id 104 108 105 - ip link set veth-hv netns vm-$id 106 - ip -netns vm-$id addr add 10.0.0.$id/24 dev veth-hv 107 - ip -netns vm-$id link set veth-hv up 109 + ip link set veth-hv netns ${vm[$id]} 110 + ip -netns ${vm[$id]} addr add 10.0.0.$id/24 dev veth-hv 111 + ip -netns ${vm[$id]} link set veth-hv up 108 112 } 109 113 setup-vm 1 110 114 setup-vm 2 111 115 112 116 # Setup VTEP routes to make ARP work 113 - bridge -netns hv-1 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.2 self permanent 114 - bridge -netns hv-2 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.1 self permanent 117 + bridge -netns $hv_1 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.2 self permanent 118 + bridge -netns $hv_2 fdb add 00:00:00:00:00:00 dev vxlan0 dst 172.16.0.1 self permanent 115 119 116 120 echo -n "Check VM connectivity through VXLAN (underlay in the default VRF) " 117 - ip netns exec vm-1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false) 121 + ip netns exec $vm_1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false) 118 122 echo "[ OK ]" 119 123 120 124 # Move the underlay to a non-default VRF 121 - ip -netns hv-1 link set veth0 vrf vrf-underlay 122 - ip -netns hv-1 link set vxlan0 down 123 - ip -netns hv-1 link set vxlan0 up 124 - ip -netns hv-2 link set veth0 vrf vrf-underlay 125 - ip -netns hv-2 link set vxlan0 down 126 - ip -netns hv-2 link set vxlan0 up 125 + ip -netns $hv_1 link set veth0 vrf vrf-underlay 126 + ip -netns $hv_1 link set vxlan0 down 127 + ip -netns $hv_1 link set vxlan0 up 128 + ip -netns $hv_2 link set veth0 vrf vrf-underlay 129 + ip -netns $hv_2 link set vxlan0 down 130 + ip -netns $hv_2 link set vxlan0 up 127 131 128 132 echo -n "Check VM connectivity through VXLAN (underlay in a VRF) " 129 - ip netns exec vm-1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false) 133 + ip netns exec $vm_1 ping -c 1 -W 1 10.0.0.2 &> /dev/null || (echo "[FAIL]"; false) 130 134 echo "[ OK ]"