Skip to content

Commit

Permalink
[bgpcfgd]: Split one bgp mega-template to chunks. (#4143)
Browse files Browse the repository at this point in the history
The one big bgp configuration template was splitted into chunks.

Currently we have three types of bgp neighbor peers:

general bgp peers. They are represented by CONFIG_DB::BGP_NEIGHBOR table entries
dynamic bgp peers. They are represented by CONFIG_DB::BGP_PEER_RANGE table entries
monitors bgp peers. They are represented by CONFIG_DB::BGP_MONITORS table entries
This PR introduces three templates for each peer type:

bgp policies: represent policieas that will be applied to the bgp peer-group (ip prefix-lists, route-maps, etc)
bgp peer-group: represent bgp peer group which has common configuration for the bgp peer type and uses bgp routing policy from the previous item
bgp peer-group instance: represent bgp configuration, which will be used to instatiate a bgp peer-group for the bgp peer-type. Usually this one is simple, consist of the referral to the bgp peer-group, bgp peer description and bgp peer ip address.
This PR redefined constant.yml file. Now this file has a setting for to use or don't use bgp_neighbor metadata. This file has more parameters for now, which are not used. They will be used in the next iteration of bgpcfgd.

Currently all tests have been disabled. I'm going to create next PR with the tests right after this PR is merged.

I'm going to introduce better bgpcfgd in a short time. It will include support of dynamic changes for the templates.

FIX:: #4231
  • Loading branch information
pavel-shirshov authored Apr 23, 2020
1 parent 9129378 commit 057ced0
Show file tree
Hide file tree
Showing 47 changed files with 1,463 additions and 850 deletions.
2 changes: 1 addition & 1 deletion dockers/docker-fpm-frr/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ RUN apt-get clean -y && \
apt-get autoremove -y && \
rm -rf /debs ~/.cache

COPY ["frr", "/usr/share/sonic/templates"]
COPY ["bgpcfgd", "start.sh", "/usr/bin/"]
COPY ["*.j2", "/usr/share/sonic/templates/"]
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["snmp.conf", "/etc/snmp/frr.conf"]
COPY ["TSA", "/usr/bin/TSA"]
Expand Down
44 changes: 30 additions & 14 deletions dockers/docker-fpm-frr/TSA
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
#!/bin/bash

c=0
config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$((c+$?))
function check_not_installed()
{
c=0
config=$(vtysh -c "show run")
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
echo "$config" | grep -q "route-map $route_map_name permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map $route_map_name deny 3"
c=$((c+$?))
done
return $c
}

if [[ $c -eq 4 ]];
check_not_installed
not_installed=$?
if [[ $not_installed -ne 0 ]];
then
TSA_FILE=$(mktemp)
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE"
vtysh -f "$TSA_FILE"
rm -f "$TSA_FILE"
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
case "$route_map_name" in
*V4*)
ip_version=V4
;;
*V6*)
ip_version=V6
;;
esac
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\", \"ip_version\": \"$ip_version\"}" -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE"
vtysh -f "$TSA_FILE"
rm -f "$TSA_FILE"
done
echo "System Mode: Normal -> Maintenance"
else
echo "System is already in Maintenance mode"
Expand Down
39 changes: 25 additions & 14 deletions dockers/docker-fpm-frr/TSB
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
#!/bin/bash

c=0
config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$((c+$?))
function check_installed()
{
c=0
e=0
config=$(vtysh -c "show run")
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
echo "$config" | grep -q "route-map $route_map_name permit 2"
c=$((c+$?))
e=$((e+1))
echo "$config" | grep -q "route-map $route_map_name deny 3"
c=$((c+$?))
e=$((e+1))
done
return $((e-c))
}

if [[ $c -eq 0 ]];
check_installed
installed=$?
if [[ $installed -ne 0 ]];
then
TSB_FILE=$(mktemp)
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE"
vtysh -f "$TSB_FILE"
rm -f "$TSB_FILE"
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\"}" -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE"
vtysh -f "$TSB_FILE"
rm -f "$TSB_FILE"
done
echo "System Mode: Maintenance -> Normal"
else
echo "System is already in Normal mode"
Expand Down
51 changes: 39 additions & 12 deletions dockers/docker-fpm-frr/TSC
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
#!/bin/bash

function check_not_installed()
{
c=0
config=$(vtysh -c "show run")
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
echo "$config" | grep -q "route-map $route_map_name permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map $route_map_name deny 3"
c=$((c+$?))
done
return $c
}

function check_installed()
{
c=0
e=0
config=$(vtysh -c "show run")
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
do
echo "$config" | grep -q "route-map $route_map_name permit 2"
c=$((c+$?))
e=$((e+1))
echo "$config" | grep -q "route-map $route_map_name deny 3"
c=$((c+$?))
e=$((e+1))
done
return $((e-c))
}

echo "Traffic Shift Check:"
c=0
config=$(vtysh -c "show run")
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
c=$((c+$?))
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
c=$((c+$?))

if [[ $c -eq 4 ]];
check_not_installed
not_installed=$?

check_installed
installed=$?

if [[ $installed -eq 0 ]];
then
echo "System Mode: Normal"
elif [[ $c -eq 0 ]];
elif [[ $not_installed -eq 0 ]];
then
echo "System Mode: Maintenance"
else
Expand Down
Loading

0 comments on commit 057ced0

Please sign in to comment.