* set origin and as-path prepend for routes from SLB Co-authored-by: jcaiMR <111116206+jcaiMR@users.noreply.github.com>
This commit is contained in:
parent
ae67185253
commit
7dfe240ef4
@ -1,8 +1,9 @@
|
|||||||
from .manager import Manager
|
from .manager import Manager
|
||||||
|
from swsscommon import swsscommon
|
||||||
from .log import log_err, log_debug
|
from .log import log_err, log_debug
|
||||||
|
|
||||||
ROUTE_MAPS = ["FROM_SDN_SLB_ROUTES"]
|
ROUTE_MAPS = ["FROM_SDN_SLB_ROUTES"]
|
||||||
|
FROM_SDN_SLB_DEPLOYMENT_ID = '2'
|
||||||
|
|
||||||
class RouteMapMgr(Manager):
|
class RouteMapMgr(Manager):
|
||||||
"""This class add route-map when BGP_PROFILE_TABLE in APPL_DB is updated"""
|
"""This class add route-map when BGP_PROFILE_TABLE in APPL_DB is updated"""
|
||||||
@ -71,8 +72,28 @@ class RouteMapMgr(Manager):
|
|||||||
return False
|
return False
|
||||||
return True
|
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):
|
def __update_rm(self, rm, data):
|
||||||
cmds = ["route-map %s permit 100" % ("%s_RM" % rm), " set community %s" % data["community_id"]]
|
cmds = []
|
||||||
log_debug("BGPRouteMapMgr:: update route-map %s community %s" % ("%s_RM" % rm, data["community_id"]))
|
if rm == "FROM_SDN_SLB_ROUTES":
|
||||||
self.cfg_mgr.push_list(cmds)
|
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")
|
log_debug("BGPRouteMapMgr::Done")
|
||||||
|
@ -3,13 +3,23 @@ from bgpcfgd.directory import Directory
|
|||||||
from bgpcfgd.managers_rm import RouteMapMgr
|
from bgpcfgd.managers_rm import RouteMapMgr
|
||||||
from swsscommon import swsscommon
|
from swsscommon import swsscommon
|
||||||
|
|
||||||
|
|
||||||
|
test_rm_constants = {
|
||||||
|
"deployment_id_asn_map": {
|
||||||
|
"1": 12345,
|
||||||
|
"2": 12346,
|
||||||
|
"3": 12347,
|
||||||
|
"4": 12348,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def constructor():
|
def constructor():
|
||||||
cfg_mgr = MagicMock()
|
cfg_mgr = MagicMock()
|
||||||
|
|
||||||
common_objs = {
|
common_objs = {
|
||||||
'directory': Directory(),
|
'directory': Directory(),
|
||||||
'cfg_mgr': cfg_mgr,
|
'cfg_mgr': cfg_mgr,
|
||||||
'constants': {},
|
'constants': test_rm_constants,
|
||||||
}
|
}
|
||||||
|
|
||||||
mgr = RouteMapMgr(common_objs, "APPL_DB", "BGP_PROFILE_TABLE")
|
mgr = RouteMapMgr(common_objs, "APPL_DB", "BGP_PROFILE_TABLE")
|
||||||
@ -47,7 +57,9 @@ def test_set_del():
|
|||||||
True,
|
True,
|
||||||
[
|
[
|
||||||
["route-map FROM_SDN_SLB_ROUTES_RM permit 100",
|
["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"]
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user