Set 'origin' and 'AS Path' for T1 SLB routes (#13613)

* set origin and as-path prepend for routes from SLB
This commit is contained in:
jcaiMR 2023-02-09 05:40:05 +08:00 committed by Qi Luo
parent 4e70a2bfbc
commit 936679ee47
2 changed files with 39 additions and 6 deletions

View File

@ -1,8 +1,9 @@
from .manager import Manager
from swsscommon import swsscommon
from .log import log_err, log_debug
ROUTE_MAPS = ["FROM_SDN_SLB_ROUTES"]
FROM_SDN_SLB_DEPLOYMENT_ID = '2'
class RouteMapMgr(Manager):
"""This class add route-map when BGP_PROFILE_TABLE in APPL_DB is updated"""
@ -71,8 +72,28 @@ class RouteMapMgr(Manager):
return False
return True
def __read_asn(self):
if not 'deployment_id_asn_map' in self.constants:
log_err("BGPRouteMapMgr:: 'deployment_id_asn_map' key is not found in constants")
return None
if FROM_SDN_SLB_DEPLOYMENT_ID in self.constants['deployment_id_asn_map']:
return self.constants['deployment_id_asn_map'][FROM_SDN_SLB_DEPLOYMENT_ID]
log_err("BGPRouteMapMgr:: deployment id %s is not found in constants" % (FROM_SDN_SLB_DEPLOYMENT_ID))
return None
def __update_rm(self, rm, data):
cmds = ["route-map %s permit 100" % ("%s_RM" % rm), " set community %s" % data["community_id"]]
log_debug("BGPRouteMapMgr:: update route-map %s community %s" % ("%s_RM" % rm, data["community_id"]))
self.cfg_mgr.push_list(cmds)
cmds = []
if rm == "FROM_SDN_SLB_ROUTES":
cmds.append("route-map %s permit 100" % ("%s_RM" % rm))
bgp_asn = self.__read_asn()
if bgp_asn is None or bgp_asn is '':
log_debug("BGPRouteMapMgr:: update route-map %s, but asn is not found in constants" % ("%s_RM" % rm))
return
cmds.append(" set as-path prepend %s %s" % (bgp_asn, bgp_asn))
cmds.append(" set community %s" % data["community_id"])
cmds.append(" set origin incomplete")
log_debug("BGPRouteMapMgr:: update route-map %s community %s origin incomplete as-path prepend %s %s" % \
("%s_RM" % rm, data["community_id"], bgp_asn, bgp_asn))
if cmds:
self.cfg_mgr.push_list(cmds)
log_debug("BGPRouteMapMgr::Done")

View File

@ -3,13 +3,23 @@ from bgpcfgd.directory import Directory
from bgpcfgd.managers_rm import RouteMapMgr
from swsscommon import swsscommon
test_rm_constants = {
"deployment_id_asn_map": {
"1": 12345,
"2": 12346,
"3": 12347,
"4": 12348,
}
}
def constructor():
cfg_mgr = MagicMock()
common_objs = {
'directory': Directory(),
'cfg_mgr': cfg_mgr,
'constants': {},
'constants': test_rm_constants,
}
mgr = RouteMapMgr(common_objs, "APPL_DB", "BGP_PROFILE_TABLE")
@ -47,7 +57,9 @@ def test_set_del():
True,
[
["route-map FROM_SDN_SLB_ROUTES_RM permit 100",
" set community 1234:1234"]
" set as-path prepend 12346 12346",
" set community 1234:1234",
" set origin incomplete"]
]
)