Skip to content

Commit

Permalink
Set 'origin' and 'AS Path' for T1 SLB routes (sonic-net#13613)
Browse files Browse the repository at this point in the history
* set origin and as-path prepend for routes from SLB
  • Loading branch information
jcaiMR authored Feb 8, 2023
1 parent 39cbd28 commit c8cf20c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
29 changes: 25 additions & 4 deletions src/sonic-bgpcfgd/bgpcfgd/managers_rm.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down Expand Up @@ -71,8 +72,28 @@ def __del_handler_validate(self, key):
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")
16 changes: 14 additions & 2 deletions src/sonic-bgpcfgd/tests/test_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@
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")
Expand Down Expand Up @@ -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"]
]
)

Expand Down

0 comments on commit c8cf20c

Please sign in to comment.