Skip to content

Commit 4742eb0

Browse files
committed
network: Add BGP+EVPN+VXLAN script to main repository and Agent package
This script can be used to use BGP+EVPN for VXLAN instead of multicast. In order to use the script operators need to manually create a symlink: cd /usr/share ln -s modifyvxlan.sh cloudstack-common/scripts/vm/network/vnet/modifyvxlan-evpn.sh Configuring BGP and EVPN is outside of the scope of CloudStack and is up to the operator to configure. This commit just adds this script to the main repository and does not change any existing functionality.
1 parent bd874ea commit 4742eb0

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
#
20+
# Use BGP+EVPN for VXLAN with CloudStack instead of Multicast
21+
#
22+
# The default 'modifyvxlan.sh' script from CloudStack uses Multicast instead of EVPN for VXLAN
23+
# In order to use this script and thus utilize BGP+EVPN, symlink this file:
24+
#
25+
# ln -s /usr/share/modifyvxlan.sh /usr/share/cloudstack-common/scripts/vm/network/vnet/modifyvxlan-evpn.sh
26+
#
27+
#
28+
# CloudStack will not handle the BGP configuration nor communication, the operator of the hypervisor will
29+
# need to configure the properly.
30+
#
31+
# Frrouting is recommend to be used on the hypervisor to establish BGP sessions with upstream routers and
32+
# exchange BGP+EVPN information.
33+
#
34+
# More information about BGP and EVPN with FRR: https://vincent.bernat.ch/en/blog/2017-vxlan-bgp-evpn
35+
#
36+
37+
DSTPORT=4789
38+
39+
# We bind our VXLAN tunnel IP(v4) on Loopback device 'lo'
40+
DEV="lo"
41+
42+
usage() {
43+
echo "Usage: $0: -o <op>(add | delete) -v <vxlan id> -p <pif> -b <bridge name> (-6)"
44+
}
45+
46+
localAddr() {
47+
local FAMILY=$1
48+
49+
if [[ -z "$FAMILY" || $FAMILY == "inet" ]]; then
50+
ip -4 -o addr show scope global dev ${DEV} | awk 'NR==1 {gsub("/[0-9]+", "") ; print $4}'
51+
fi
52+
53+
if [[ "$FAMILY" == "inet6" ]]; then
54+
ip -6 -o addr show scope global dev ${DEV} | awk 'NR==1 {gsub("/[0-9]+", "") ; print $4}'
55+
fi
56+
}
57+
58+
addVxlan() {
59+
local VNI=$1
60+
local PIF=$2
61+
local VXLAN_BR=$3
62+
local FAMILY=$4
63+
local VXLAN_DEV=vxlan${VNI}
64+
local ADDR=$(localAddr ${FAMILY})
65+
66+
echo "local addr for VNI ${VNI} is ${ADDR}"
67+
68+
if [[ ! -d /sys/class/net/${VXLAN_DEV} ]]; then
69+
ip -f ${FAMILY} link add ${VXLAN_DEV} type vxlan id ${VNI} local ${ADDR} dstport ${DSTPORT} nolearning
70+
ip link set ${VXLAN_DEV} up
71+
sysctl -qw net.ipv6.conf.${VXLAN_DEV}.disable_ipv6=1
72+
fi
73+
74+
if [[ ! -d /sys/class/net/$VXLAN_BR ]]; then
75+
ip link add name ${VXLAN_BR} type bridge
76+
ip link set ${VXLAN_BR} up
77+
sysctl -qw net.ipv6.conf.${VXLAN_BR}.disable_ipv6=1
78+
fi
79+
80+
bridge link show|grep ${VXLAN_BR}|awk '{print $2}'|grep "^${VXLAN_DEV}\$" > /dev/null
81+
if [[ $? -gt 0 ]]; then
82+
ip link set ${VXLAN_DEV} master ${VXLAN_BR}
83+
fi
84+
}
85+
86+
deleteVxlan() {
87+
local VNI=$1
88+
local PIF=$2
89+
local VXLAN_BR=$3
90+
local FAMILY=$4
91+
local VXLAN_DEV=vxlan${VNI}
92+
93+
ip link set ${VXLAN_DEV} nomaster
94+
ip link delete ${VXLAN_DEV}
95+
96+
ip link set ${VXLAN_BR} down
97+
ip link delete ${VXLAN_BR} type bridge
98+
}
99+
100+
OP=
101+
VNI=
102+
FAMILY=inet
103+
option=$@
104+
105+
while getopts 'o:v:p:b:6' OPTION
106+
do
107+
case $OPTION in
108+
o) oflag=1
109+
OP="$OPTARG"
110+
;;
111+
v) vflag=1
112+
VNI="$OPTARG"
113+
;;
114+
p) pflag=1
115+
PIF="$OPTARG"
116+
;;
117+
b) bflag=1
118+
BRNAME="$OPTARG"
119+
;;
120+
6)
121+
FAMILY=inet6
122+
;;
123+
?) usage
124+
exit 2
125+
;;
126+
esac
127+
done
128+
129+
if [[ "$oflag$vflag$pflag$bflag" != "1111" ]]; then
130+
usage
131+
exit 2
132+
fi
133+
134+
lsmod|grep ^vxlan >& /dev/null
135+
if [[ $? -gt 0 ]]; then
136+
modprobe=`modprobe vxlan 2>&1`
137+
if [[ $? -gt 0 ]]; then
138+
echo "Failed to load vxlan kernel module: $modprobe"
139+
exit 1
140+
fi
141+
fi
142+
143+
144+
#
145+
# Add a lockfile to prevent this script from running twice on the same host
146+
# this can cause a race condition
147+
#
148+
149+
LOCKFILE=/var/run/cloud/vxlan.lock
150+
151+
(
152+
flock -x -w 10 200 || exit 1
153+
if [[ "$OP" == "add" ]]; then
154+
addVxlan ${VNI} ${PIF} ${BRNAME} ${FAMILY}
155+
156+
if [[ $? -gt 0 ]]; then
157+
exit 1
158+
fi
159+
elif [[ "$OP" == "delete" ]]; then
160+
deleteVxlan ${VNI} ${PIF} ${BRNAME} ${FAMILY}
161+
fi
162+
) 200>${LOCKFILE}

0 commit comments

Comments
 (0)