Skip to content

Commit 949ebee

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 949ebee

File tree

8 files changed

+165
-24
lines changed

8 files changed

+165
-24
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

src/sonic-bgpcfgd/tests/data/general/policies.conf/param_all_chassis_pkt.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
"allow_list": {
66
"enabled": true,
77
"drop_community": "12345:12345"
8-
},
9-
"route_eligible_for_fallback_to_default_tag": "203",
10-
"route_do_not_send_appdb_tag" : "202",
11-
"internal_fallback_community": "1111:2222"
8+
},
9+
"route_eligible_for_fallback_to_default_tag": "203",
10+
"route_do_not_send_appdb_tag" : "202",
11+
"internal_fallback_community": "1111:2222",
12+
"local_anchor_route_community": "12345:555",
13+
"anchor_route_community": "12345:666",
14+
"anchor_contributing_route_community": "12345:777"
1215
}
1316
},
1417
"allow_list_default_action": "permit",

src/sonic-bgpcfgd/tests/data/general/policies.conf/param_all_voq.json

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
"allow_list": {
66
"enabled": true,
77
"drop_community": "12345:12345"
8-
},
9-
"route_eligible_for_fallback_to_default_tag": "203",
10-
"route_do_not_send_appdb_tag" : "202",
11-
"internal_fallback_community": "1111:2222"
8+
},
9+
"route_eligible_for_fallback_to_default_tag": "203",
10+
"route_do_not_send_appdb_tag" : "202",
11+
"internal_fallback_community": "1111:2222",
12+
"local_anchor_route_community": "12345:555",
13+
"anchor_route_community": "12345:666",
14+
"anchor_contributing_route_community": "12345:777"
1215
}
1316
},
1417
"allow_list_default_action": "permit",

src/sonic-bgpcfgd/tests/data/general/policies.conf/result_all_chassis_pkt.conf

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
!
22
! template: bgpd/templates/general/policies.conf.j2
33
!
4+
!
45
ip prefix-list DEFAULT_IPV4 permit 0.0.0.0/0
56
ipv6 prefix-list DEFAULT_IPV6 permit ::/0
67
!
8+
!
9+
!
710
! please don't remove. 65535 entries are default rules
811
! which works when allow_list is enabled, but new configuration
912
! is not applied
1013
!
14+
!
1115
route-map ALLOW_LIST_DEPLOYMENT_ID_0_V4 permit 65535
1216
set community 12345:12345 additive
1317
!
@@ -45,13 +49,16 @@ route-map FROM_BGP_PEER_V6 permit 12
4549
!
4650
route-map FROM_BGP_PEER_V6 permit 13
4751
set tag 203
48-
set community 1111:2222 additive
52+
set community 1111:2222 additive !
53+
!
54+
!
4955
!
5056
route-map FROM_BGP_PEER_V4 permit 100
5157
!
5258
route-map TO_BGP_PEER_V4 permit 100
5359
call CHECK_IDF_ISOLATION
5460
!
61+
!
5562
route-map FROM_BGP_PEER_V6 permit 1
5663
on-match next
5764
set ipv6 next-hop prefer-global
@@ -63,5 +70,40 @@ route-map TO_BGP_PEER_V6 permit 100
6370
!
6471
route-map CHECK_IDF_ISOLATION permit 10
6572
!
66-
! end of template: bgpd/templates/general/policies.conf.j2
6773
!
74+
!
75+
bgp community-list standard ANCHOR_ROUTE_COMMUNITY permit 12345:666
76+
bgp community-list standard LOCAL_ANCHOR_ROUTE_COMMUNITY permit 12345:555
77+
bgp community-list standard ANCHOR_CONTRIBUTING_ROUTE_COMMUNITY permit 12345:777
78+
!
79+
route-map SELECTIVE_ROUTE_DOWNLOAD_V4 deny 10
80+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
81+
!
82+
route-map SELECTIVE_ROUTE_DOWNLOAD_V4 permit 1000
83+
!
84+
route-map SELECTIVE_ROUTE_DOWNLOAD_V6 deny 10
85+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
86+
!
87+
route-map SELECTIVE_ROUTE_DOWNLOAD_V6 permit 1000
88+
!
89+
route-map TAG_ANCHOR_COMMUNITY permit 10
90+
set community 12345:555 12345:666 additive
91+
!
92+
route-map TO_BGP_PEER_V6 permit 30
93+
match ipv6 address prefix-list ANCHOR_CONTRIBUTING_ROUTES
94+
set community 12345:777 additive
95+
on-match next
96+
!
97+
route-map TO_BGP_PEER_V6 permit 40
98+
set comm-list LOCAL_ANCHOR_ROUTE_COMMUNITY delete
99+
!
100+
route-map TO_BGP_PEER_V4 permit 30
101+
match ipv6 address prefix-list ANCHOR_CONTRIBUTING_ROUTES
102+
set community 12345:777 additive
103+
on-match next
104+
!
105+
route-map TO_BGP_PEER_V4 permit 40
106+
set comm-list LOCAL_ANCHOR_ROUTE_COMMUNITY delete
107+
!
108+
! end of template: bgpd/templates/general/policies.conf.j2
109+
!

src/sonic-bgpcfgd/tests/data/general/policies.conf/result_all_voq.conf

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
!
22
! template: bgpd/templates/general/policies.conf.j2
33
!
4+
!
45
ip prefix-list DEFAULT_IPV4 permit 0.0.0.0/0
56
ipv6 prefix-list DEFAULT_IPV6 permit ::/0
67
!
8+
!
9+
!
710
! please don't remove. 65535 entries are default rules
811
! which works when allow_list is enabled, but new configuration
912
! is not applied
1013
!
14+
!
1115
route-map ALLOW_LIST_DEPLOYMENT_ID_0_V4 permit 65535
1216
set community 12345:12345 additive
1317
!
@@ -45,13 +49,16 @@ route-map FROM_BGP_PEER_V6 permit 12
4549
!
4650
route-map FROM_BGP_PEER_V6 permit 13
4751
set tag 202
48-
set community 1111:2222 additive
52+
set community 1111:2222 additive !
53+
!
54+
!
4955
!
5056
route-map FROM_BGP_PEER_V4 permit 100
5157
!
5258
route-map TO_BGP_PEER_V4 permit 100
5359
call CHECK_IDF_ISOLATION
5460
!
61+
!
5562
route-map FROM_BGP_PEER_V6 permit 1
5663
on-match next
5764
set ipv6 next-hop prefer-global
@@ -63,5 +70,40 @@ route-map TO_BGP_PEER_V6 permit 100
6370
!
6471
route-map CHECK_IDF_ISOLATION permit 10
6572
!
73+
!
74+
!
75+
bgp community-list standard ANCHOR_ROUTE_COMMUNITY permit 12345:666
76+
bgp community-list standard LOCAL_ANCHOR_ROUTE_COMMUNITY permit 12345:555
77+
bgp community-list standard ANCHOR_CONTRIBUTING_ROUTE_COMMUNITY permit 12345:777
78+
!
79+
route-map SELECTIVE_ROUTE_DOWNLOAD_V4 deny 10
80+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
81+
!
82+
route-map SELECTIVE_ROUTE_DOWNLOAD_V4 permit 1000
83+
!
84+
route-map SELECTIVE_ROUTE_DOWNLOAD_V6 deny 10
85+
match community LOCAL_ANCHOR_ROUTE_COMMUNITY
86+
!
87+
route-map SELECTIVE_ROUTE_DOWNLOAD_V6 permit 1000
88+
!
89+
route-map TAG_ANCHOR_COMMUNITY permit 10
90+
set community 12345:555 12345:666 additive
91+
!
92+
route-map TO_BGP_PEER_V6 permit 30
93+
match ipv6 address prefix-list ANCHOR_CONTRIBUTING_ROUTES
94+
set community 12345:777 additive
95+
on-match next
96+
!
97+
route-map TO_BGP_PEER_V6 permit 40
98+
set comm-list LOCAL_ANCHOR_ROUTE_COMMUNITY delete
99+
!
100+
route-map TO_BGP_PEER_V4 permit 30
101+
match ipv6 address prefix-list ANCHOR_CONTRIBUTING_ROUTES
102+
set community 12345:777 additive
103+
on-match next
104+
!
105+
route-map TO_BGP_PEER_V4 permit 40
106+
set comm-list LOCAL_ANCHOR_ROUTE_COMMUNITY delete
107+
!
66108
! end of template: bgpd/templates/general/policies.conf.j2
67109
!

0 commit comments

Comments
 (0)