Skip to content

Commit 057ced0

Browse files
[bgpcfgd]: Split one bgp mega-template to chunks. (#4143)
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
1 parent 9129378 commit 057ced0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1463
-850
lines changed

dockers/docker-fpm-frr/Dockerfile.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ RUN apt-get clean -y && \
3939
apt-get autoremove -y && \
4040
rm -rf /debs ~/.cache
4141

42+
COPY ["frr", "/usr/share/sonic/templates"]
4243
COPY ["bgpcfgd", "start.sh", "/usr/bin/"]
43-
COPY ["*.j2", "/usr/share/sonic/templates/"]
4444
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
4545
COPY ["snmp.conf", "/etc/snmp/frr.conf"]
4646
COPY ["TSA", "/usr/bin/TSA"]

dockers/docker-fpm-frr/TSA

+30-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
#!/bin/bash
22

3-
c=0
4-
config=$(vtysh -c "show run")
5-
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
6-
c=$((c+$?))
7-
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
8-
c=$((c+$?))
9-
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
10-
c=$((c+$?))
11-
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
12-
c=$((c+$?))
3+
function check_not_installed()
4+
{
5+
c=0
6+
config=$(vtysh -c "show run")
7+
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
8+
do
9+
echo "$config" | grep -q "route-map $route_map_name permit 2"
10+
c=$((c+$?))
11+
echo "$config" | grep -q "route-map $route_map_name deny 3"
12+
c=$((c+$?))
13+
done
14+
return $c
15+
}
1316

14-
if [[ $c -eq 4 ]];
17+
check_not_installed
18+
not_installed=$?
19+
if [[ $not_installed -ne 0 ]];
1520
then
1621
TSA_FILE=$(mktemp)
17-
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.tsa.isolate.conf.j2 > "$TSA_FILE"
18-
vtysh -f "$TSA_FILE"
19-
rm -f "$TSA_FILE"
22+
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
23+
do
24+
case "$route_map_name" in
25+
*V4*)
26+
ip_version=V4
27+
;;
28+
*V6*)
29+
ip_version=V6
30+
;;
31+
esac
32+
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"
33+
vtysh -f "$TSA_FILE"
34+
rm -f "$TSA_FILE"
35+
done
2036
echo "System Mode: Normal -> Maintenance"
2137
else
2238
echo "System is already in Maintenance mode"

dockers/docker-fpm-frr/TSB

+25-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
11
#!/bin/bash
22

3-
c=0
4-
config=$(vtysh -c "show run")
5-
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
6-
c=$((c+$?))
7-
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
8-
c=$((c+$?))
9-
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
10-
c=$((c+$?))
11-
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
12-
c=$((c+$?))
3+
function check_installed()
4+
{
5+
c=0
6+
e=0
7+
config=$(vtysh -c "show run")
8+
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
9+
do
10+
echo "$config" | grep -q "route-map $route_map_name permit 2"
11+
c=$((c+$?))
12+
e=$((e+1))
13+
echo "$config" | grep -q "route-map $route_map_name deny 3"
14+
c=$((c+$?))
15+
e=$((e+1))
16+
done
17+
return $((e-c))
18+
}
1319

14-
if [[ $c -eq 0 ]];
20+
check_installed
21+
installed=$?
22+
if [[ $installed -ne 0 ]];
1523
then
1624
TSB_FILE=$(mktemp)
17-
sonic-cfggen -d -y /etc/sonic/constants.yml -t /usr/share/sonic/templates/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE"
18-
vtysh -f "$TSB_FILE"
19-
rm -f "$TSB_FILE"
25+
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
26+
do
27+
sonic-cfggen -d -a "{\"route_map_name\":\"$route_map_name\"}" -t /usr/share/sonic/templates/bgpd/tsa/bgpd.tsa.unisolate.conf.j2 > "$TSB_FILE"
28+
vtysh -f "$TSB_FILE"
29+
rm -f "$TSB_FILE"
30+
done
2031
echo "System Mode: Maintenance -> Normal"
2132
else
2233
echo "System is already in Normal mode"

dockers/docker-fpm-frr/TSC

+39-12
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,48 @@
11
#!/bin/bash
22

3+
function check_not_installed()
4+
{
5+
c=0
6+
config=$(vtysh -c "show run")
7+
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
8+
do
9+
echo "$config" | grep -q "route-map $route_map_name permit 2"
10+
c=$((c+$?))
11+
echo "$config" | grep -q "route-map $route_map_name deny 3"
12+
c=$((c+$?))
13+
done
14+
return $c
15+
}
16+
17+
function check_installed()
18+
{
19+
c=0
20+
e=0
21+
config=$(vtysh -c "show run")
22+
for route_map_name in $(echo "$config" | sed -ne 's/ neighbor \S* route-map \(\S*\) out/\1/p');
23+
do
24+
echo "$config" | grep -q "route-map $route_map_name permit 2"
25+
c=$((c+$?))
26+
e=$((e+1))
27+
echo "$config" | grep -q "route-map $route_map_name deny 3"
28+
c=$((c+$?))
29+
e=$((e+1))
30+
done
31+
return $((e-c))
32+
}
33+
334
echo "Traffic Shift Check:"
4-
c=0
5-
config=$(vtysh -c "show run")
6-
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 permit 2"
7-
c=$((c+$?))
8-
echo "$config" | grep -q "route-map TO_BGP_PEER_V4 deny 3"
9-
c=$((c+$?))
10-
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 permit 2"
11-
c=$((c+$?))
12-
echo "$config" | grep -q "route-map TO_BGP_PEER_V6 deny 3"
13-
c=$((c+$?))
1435

15-
if [[ $c -eq 4 ]];
36+
check_not_installed
37+
not_installed=$?
38+
39+
check_installed
40+
installed=$?
41+
42+
if [[ $installed -eq 0 ]];
1643
then
1744
echo "System Mode: Normal"
18-
elif [[ $c -eq 0 ]];
45+
elif [[ $not_installed -eq 0 ]];
1946
then
2047
echo "System Mode: Maintenance"
2148
else

0 commit comments

Comments
 (0)