Skip to content

Commit 06869f2

Browse files
committed
General route-maps and prefix_list manager fix
Signed-off-by: Mukul Chodhary <70460358+Muckthebuck@users.noreply.github.com>
1 parent fd26d87 commit 06869f2

File tree

4 files changed

+64
-13
lines changed

4 files changed

+64
-13
lines changed

dockers/docker-fpm-frr/frr/bgpd/templates/general/peer-group.conf.j2

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
neighbor PEER_V6 soft-reconfiguration inbound
2727
neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in
2828
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out
29+
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'SpineRouter' %}
30+
table-map SELECTIVE_ROUTE_DOWNLOAD_V4
31+
table-map SELECTIVE_ROUTE_DOWNLOAD_V6
32+
{% endif %}
2933
exit-address-family
3034
!
3135
! end of template: bgpd/templates/general/peer-group.conf.j2

dockers/docker-fpm-frr/frr/bgpd/templates/general/policies.conf.j2

+39
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,44 @@ route-map TO_BGP_PEER_V6 permit 100
9797
!
9898
route-map CHECK_IDF_ISOLATION permit 10
9999
!
100+
!
101+
!
102+
{% if CONFIG_DB__DEVICE_METADATA and 'localhost' in CONFIG_DB__DEVICE_METADATA and 'type' in CONFIG_DB__DEVICE_METADATA['localhost'] and 'subtype' in CONFIG_DB__DEVICE_METADATA['localhost'] %}
103+
{% if CONFIG_DB__DEVICE_METADATA['localhost']['type'] == 'SpineRouter' and CONFIG_DB__DEVICE_METADATA['localhost']['subtype'] == 'UpstreamLC' %}
104+
bgp community-list standard ANCHOR_ROUTE_COMMUNITY permit {{ constants.bgp.anchor_route_community }}
105+
bgp community-list standard LOCAL_ANCHOR_ROUTE_COMMUNITY permit {{ constants.bgp.local_anchor_route_community }}
106+
bgp community-list standard ANCHOR_CONTRIBUTING_ROUTE_COMMUNITY permit {{ constants.bgp.anchor_contributing_route_community }}
107+
!
108+
route-map SELECTIVE_ROUTE_DOWNLOAD_V4 deny 10
109+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
110+
!
111+
route-map SELECTIVE_ROUTE_DOWNLOAD_V4 permit 1000
112+
!
113+
route-map SELECTIVE_ROUTE_DOWNLOAD_V6 deny 10
114+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
115+
!
116+
route-map SELECTIVE_ROUTE_DOWNLOAD_V6 permit 1000
117+
!
118+
route-map TAG_ANCHOR_COMMUNITY permit 10
119+
set community {{ constants.bgp.local_anchor_route_community }} {{ constants.bgp.anchor_route_community }} additive
120+
!
121+
route-map TO_BGP_PEER_V6 permit 30
122+
match ipv6 address prefix-list ANCHOR_CONTRIBUTING_ROUTES
123+
set community {{ constants.bgp.anchor_contributing_route_community }} additive
124+
on-match next
125+
!
126+
route-map TO_BGP_PEER_V6 permit 40
127+
set comm-list LOCAL_ANCHOR_ROUTE_COMMUNITY delete
128+
!
129+
route-map TO_BGP_PEER_V4 permit 30
130+
match ipv6 address prefix-list ANCHOR_CONTRIBUTING_ROUTES
131+
set community {{ constants.bgp.anchor_contributing_route_community }} additive
132+
on-match next
133+
!
134+
route-map TO_BGP_PEER_V4 permit 40
135+
set comm-list LOCAL_ANCHOR_ROUTE_COMMUNITY delete
136+
!
137+
{% endif %}
138+
{% endif %}
100139
! end of template: bgpd/templates/general/policies.conf.j2
101140
!

files/image_config/constants/constants.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ constants:
99
sentinel_community: 12345:12346
1010
internal_community_match_tag: 201
1111
local_anchor_route_community: 12345:555
12+
anchor_route_community: 12345:666
13+
anchor_contributing_route_community: 12345:777
1214
route_do_not_send_appdb_tag: 202
1315
route_eligible_for_fallback_to_default_tag: 203
1416
families:

src/sonic-bgpcfgd/bgpcfgd/managers_prefix_list.py

+19-13
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ def generate_prefix_list_config(self, data, add):
3535
"""
3636
cmd = "\n"
3737
metadata = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]
38-
bgp_asn = metadata["bgp_asn"]
39-
localhost_type = metadata["type"]
40-
subtype = metadata["subtype"]
38+
try:
39+
bgp_asn = metadata["bgp_asn"]
40+
localhost_type = metadata["type"]
41+
subtype = metadata["subtype"]
42+
except KeyError as e:
43+
log_warn(f"PrefixListMgr:: Missing metadata key: {e}")
44+
return False
4145

4246
if data["prefix_list_name"] != "ANCHOR_PREFIX":
4347
log_warn("PrefixListMgr:: Prefix list %s is not supported" % data["prefix_list_name"])
44-
return
48+
return False
4549
if localhost_type != "SpineRouter" or subtype != "UpstreamLC":
4650
log_warn("PrefixListMgr:: Prefix list %s is only supported on UpstreamLC of SpineRouter" % data["prefix_list_name"])
47-
return
51+
return False
4852

4953
# Add the anchor prefix to the radian configuration
5054
data["bgp_asn"] = bgp_asn
@@ -56,6 +60,7 @@ def generate_prefix_list_config(self, data, add):
5660
cmd += self.templates["del_radian"].render(data=data)
5761
log_debug("PrefixListMgr:: Anchor prefix %s removed from radian configuration" % data["prefix"])
5862
self.cfg_mgr.push(cmd)
63+
return True
5964

6065

6166

@@ -72,11 +77,11 @@ def set_handler(self, key, data):
7277
data["prefix"] = str(prefix.cidr)
7378
data["ipv"] = self.get_ip_type(prefix)
7479
# Generate the prefix list configuration
75-
self.generate_prefix_list_config(data, add=True)
76-
log_info("PrefixListMgr:: %s %s configuration generated" % (prefix_list_name, data["prefix"]))
80+
if self.generate_prefix_list_config(data, add=True):
81+
log_info("PrefixListMgr:: %s %s configuration generated" % (prefix_list_name, data["prefix"]))
7782

78-
self.directory.put(self.db_name, self.table_name, key, data)
79-
log_info("PrefixListMgr:: set %s" % key)
83+
self.directory.put(self.db_name, self.table_name, key, data)
84+
log_info("PrefixListMgr:: set %s" % key)
8085
return True
8186

8287
def del_handler(self, key):
@@ -92,10 +97,11 @@ def del_handler(self, key):
9297
data["prefix_list_name"] = prefix_list_name
9398
data["prefix"] = str(prefix.cidr)
9499
data["ipv"] = self.get_ip_type(prefix)
95-
self.generate_prefix_list_config(data, add=False)
96-
log_info("PrefixListMgr:: %s %s configuration deleted" % (prefix_list_name, data["prefix"]))
97-
self.directory.remove(self.db_name, self.table_name, key)
98-
log_info("PrefixListMgr:: deleted %s" % key)
100+
# remove the prefix list configuration
101+
if self.generate_prefix_list_config(data, add=False):
102+
log_info("PrefixListMgr:: %s %s configuration deleted" % (prefix_list_name, data["prefix"]))
103+
self.directory.remove(self.db_name, self.table_name, key)
104+
log_info("PrefixListMgr:: deleted %s" % key)
99105
# Implement deletion logic if necessary
100106
return True
101107

0 commit comments

Comments
 (0)