Skip to content

Commit

Permalink
Allow CRC to learn routes through BGP
Browse files Browse the repository at this point in the history
This is a sample to allow learning routes from a given range belonging
to OpenStack cluster. It can be modified to learn other ranges or to
learn everything
  • Loading branch information
luis5tb committed Nov 3, 2023
1 parent c0a3767 commit d8724da
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ NEUTRON_KUTTL_NAMESPACE ?= neutron-kuttl-tests
# BGP
NETWORK_BGP ?= false
BGP_ASN ?= 64999
BGP_PEER_ASN ?= 64999
BGP_LEAF_1 ?= 100.65.4.1
BGP_LEAF_2 ?= 100.64.4.1
BGP_SOURCE_IP ?= 172.30.4.2
BGP_SOURCE_IP6 ?= f00d:f00d:f00d:f00d:f00d:f00d:f00d:42
NNCP_BGP_1_INTERFACE ?= enp7s0
NNCP_BGP_2_INTERFACE ?= enp8s0
NNCP_BGP_1_IP_ADDRESS ?= 100.65.4.2
Expand Down Expand Up @@ -1852,6 +1855,8 @@ nncp: export INTERFACE_BGP_1=${NNCP_BGP_1_INTERFACE}
nncp: export INTERFACE_BGP_2=${NNCP_BGP_2_INTERFACE}
nncp: export BGP_1_IP_ADDRESS=${NNCP_BGP_1_IP_ADDRESS}
nncp: export BGP_2_IP_ADDRESS=${NNCP_BGP_2_IP_ADDRESS}
nncp: export LO_IP_ADDRESS=${BGP_SOURCE_IP}
nncp: export LO_IP6_ADDRESS=${BGP_SOURCE_IP6}
endif
nncp: export CTLPLANE_IP_ADDRESS_PREFIX=${NNCP_CTLPLANE_IP_ADDRESS_PREFIX}
nncp: export CTLPLANE_IP_ADDRESS_SUFFIX=${NNCP_CTLPLANE_IP_ADDRESS_SUFFIX}
Expand Down Expand Up @@ -1902,8 +1907,11 @@ netattach_cleanup: ## Deletes the network-attachment-definitions
metallb: export NAMESPACE=metallb-system
metallb: export INTERFACE=${NNCP_INTERFACE}
metallb: export ASN=${BGP_ASN}
metallb: export PEER_ASN=${BGP_PEER_ASN}
metallb: export LEAF_1=${BGP_LEAF_1}
metallb: export LEAF_2=${BGP_LEAF_2}
metallb: export SOURCE_IP=${BGP_SOURCE_IP}
metallb: export SOURCE_IP6=${BGP_SOURCE_IP6}
metallb: ## installs metallb operator in the metallb-system namespace
$(eval $(call vars,$@,metallb))
bash scripts/gen-namespace.sh
Expand All @@ -1924,8 +1932,11 @@ metallb_config: export NAMESPACE=metallb-system
metallb_config: export CTLPLANE_METALLB_POOL=${METALLB_POOL}
metallb_config: export INTERFACE=${NNCP_INTERFACE}
metallb_config: export ASN=${BGP_ASN}
metallb_config: export PEER_ASN=${BGP_PEER_ASN}
metallb_config: export LEAF_1=${BGP_LEAF_1}
metallb_config: export LEAF_2=${BGP_LEAF_2}
metallb_config: export SOURCE_IP=${BGP_SOURCE_IP}
metallb_config: export SOURCE_IP6=${BGP_SOURCE_IP6}
metallb_config: metallb_config_cleanup ## creates the IPAddressPools and l2advertisement resources
$(eval $(call vars,$@,metallb))
bash scripts/gen-olm-metallb.sh
Expand All @@ -1934,6 +1945,7 @@ metallb_config: metallb_config_cleanup ## creates the IPAddressPools and l2adver
ifeq ($(NETWORK_BGP), true)
oc apply -f ${DEPLOY_DIR}/bgppeers.yaml
oc apply -f ${DEPLOY_DIR}/bgpadvertisement.yaml
oc apply -f ${DEPLOY_DIR}/bgpextras.yaml
endif

.PHONY: metallb_config_cleanup
Expand All @@ -1944,7 +1956,8 @@ metallb_config_cleanup: ## deletes the IPAddressPools and l2advertisement resour
oc delete --ignore-not-found=true -f ${DEPLOY_DIR}/l2advertisement.yaml
oc delete --ignore-not-found=true -f ${DEPLOY_DIR}/bgppeers.yaml
oc delete --ignore-not-found=true -f ${DEPLOY_DIR}/bgpadvertisement.yaml
${CLEANUP_DIR_CMD} ${DEPLOY_DIR}/ipaddresspools.yaml ${DEPLOY_DIR}/l2advertisement.yaml ${DEPLOY_DIR}/bgppeers.yaml ${DEPLOY_DIR}/bgpadvertisement.yaml
oc delete --ignore-not-found=true -f ${DEPLOY_DIR}/bgpextras.yaml
${CLEANUP_DIR_CMD} ${DEPLOY_DIR}/ipaddresspools.yaml ${DEPLOY_DIR}/l2advertisement.yaml ${DEPLOY_DIR}/bgppeers.yaml ${DEPLOY_DIR}/bgpadvertisement.yaml ${DEPLOY_DIR}/bgpextras.yaml

##@ MANILA
.PHONY: manila_prep
Expand Down
16 changes: 16 additions & 0 deletions scripts/gen-nncp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ if [ -n "$BGP" ]; then
name: ${INTERFACE_BGP_2}
state: up
type: ethernet
- description: Configuring lo
ipv4:
address:
- ip: ${LO_IP_ADDRESS}
prefix-length: 32
enabled: true
dhcp: false
ipv6:
address:
- ip: ${LO_IP6_ADDRESS}
prefix-length: 128
enabled: true
dhcp: false
name: lo
mtu: 65536
state: unknown
EOF_CAT
fi
cat >> ${DEPLOY_DIR}/${WORKER}_nncp.yaml <<EOF_CAT
Expand Down
44 changes: 42 additions & 2 deletions scripts/gen-olm-metallb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ if [ -z "${ASN}" ]; then
echo "Please set ASN"; exit 1
fi

if [ -z "${PEER_ASN}" ]; then
echo "Please set PEER_ASN"; exit 1
fi

if [ -z "${LEAF_1}" ]; then
echo "Please set LEAF_1"; exit 1
fi
Expand All @@ -47,6 +51,10 @@ if [ -z "${LEAF_2}" ]; then
echo "Please set LEAF_2"; exit 1
fi

if [ -z "${SOURCE_IP}" ]; then
echo "Please set SOURCE_IP"; exit 1
fi

echo OPERATOR_DIR ${OPERATOR_DIR}
echo DEPLOY_DIR ${DEPLOY_DIR}
echo INTERFACE ${INTERFACE}
Expand Down Expand Up @@ -178,9 +186,10 @@ metadata:
namespace: metallb-system
spec:
myASN: ${ASN}
peerASN: ${ASN}
peerASN: ${PEER_ASN}
peerAddress: ${LEAF_1}
password: f00barZ
routerID: ${SOURCE_IP}
---
apiVersion: metallb.io/v1beta2
kind: BGPPeer
Expand All @@ -189,9 +198,10 @@ metadata:
namespace: metallb-system
spec:
myASN: ${ASN}
peerASN: ${ASN}
peerASN: ${PEER_ASN}
peerAddress: ${LEAF_2}
password: f00barZ
routerID: ${SOURCE_IP}
EOF_CAT
cat > ${DEPLOY_DIR}/bgpadvertisement.yaml <<EOF_CAT
---
Expand All @@ -210,3 +220,33 @@ spec:
- bgp-peer
- bgp-peer-2
EOF_CAT
cat > ${DEPLOY_DIR}/bgpextras.yaml << EOF_CAT
---
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: bgpextras
data:
extras: |
router bgp ${ASN}
network ${SOURCE_IP}/32
neighbor ${LEAF_1} allowas-in origin
neighbor ${LEAF_2} allowas-in origin
! ip prefix-list osp permit 172.16.0.0/16 le 32
route-map ${LEAF_1}-in permit 20
! match ip address prefix-list osp
set src ${SOURCE_IP}
route-map ${LEAF_2}-in permit 20
! match ip address prefix-list osp
set src ${SOURCE_IP}
ip protocol bgp route-map ${LEAF_1}-in
ip protocol bgp route-map ${LEAF_2}-in
ip prefix-list ocp-lo permit ${SOURCE_IP}/32
route-map ${LEAF_1}-out permit 1
match ip address prefix-list ocp-lo
route-map ${LEAF_2}-out permit 1
match ip address prefix-list ocp-lo
EOF_CAT

0 comments on commit d8724da

Please sign in to comment.