Skip to content

Commit

Permalink
[Bug Fix] Route map for BGP profile FROM_SDN_APPLIANCE_ROUTES (sonic-…
Browse files Browse the repository at this point in the history
…net#19871)

Why I did it
This is a bug fix and this change should go into 202305 brranch and onwards.
Added Route map support for BGP profile FROM_SDN_APPLIANCE_ROUTES
With this change the following route map should be added if the BGP profile is added

route-map FROM_SDN_APPLIANCE_ROUTES_RM permit 100
set as-path prepend <Prepend value of FROM_SDN_SLB_DEPLOYMENT_ID>
set community <community id>
set origin incomplete
Work item tracking
Microsoft ADO (number only):
28896695
How I did it
How to verify it
Added test to verify the rotue map creation.
  • Loading branch information
siqbal1986 authored and mssonicbld committed Aug 31, 2024
1 parent 652b388 commit 45add9d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/sonic-bgpcfgd/bgpcfgd/managers_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from swsscommon import swsscommon
from .log import log_err, log_debug

ROUTE_MAPS = ["FROM_SDN_SLB_ROUTES"]
ROUTE_MAPS = ["FROM_SDN_SLB_ROUTES", "FROM_SDN_APPLIANCE_ROUTES"]
FROM_SDN_SLB_DEPLOYMENT_ID = '2'

class RouteMapMgr(Manager):
Expand Down Expand Up @@ -83,7 +83,7 @@ def __read_asn(self):

def __update_rm(self, rm, data):
cmds = []
if rm == "FROM_SDN_SLB_ROUTES":
if rm in ROUTE_MAPS :
cmds.append("route-map %s permit 100" % ("%s_RM" % rm))
bgp_asn = self.__read_asn()
if bgp_asn is None or bgp_asn is '':
Expand Down
79 changes: 73 additions & 6 deletions src/sonic-bgpcfgd/tests/test_rm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def constructor():
mgr = RouteMapMgr(common_objs, "APPL_DB", "BGP_PROFILE_TABLE")
return mgr

def set_del_test(mgr, op, args, expected_ret, expected_cmds):
def set_del_test(mgr, op, cfg_args, expected_ret, expected_cmds):
set_del_test.push_list_called = False
def push_list(cmds):
set_del_test.push_list_called = True
Expand All @@ -34,10 +34,12 @@ def push_list(cmds):
mgr.cfg_mgr.push_list = push_list

if op == "SET":
ret = mgr.set_handler(*args)
assert ret == expected_ret
for i in range(0, len(cfg_args)):
ret = mgr.set_handler(cfg_args[i][0], cfg_args[i][1])
assert ret == expected_ret
elif op == "DEL":
mgr.del_handler(*args)
for i in range(0, len(cfg_args)):
mgr.del_handler(cfg_args[i])
else:
assert False, "Wrong operation"

Expand All @@ -51,9 +53,9 @@ def test_set_del():
set_del_test(
mgr,
"SET",
("FROM_SDN_SLB_ROUTES", {
[("FROM_SDN_SLB_ROUTES", {
"community_id": "1234:1234"
}),
})],
True,
[
["route-map FROM_SDN_SLB_ROUTES_RM permit 100",
Expand All @@ -72,3 +74,68 @@ def test_set_del():
["no route-map FROM_SDN_SLB_ROUTES_RM permit 100"]
]
)

def test_set_del_com_sdn_apl():
mgr = constructor()
set_del_test(
mgr,
"SET",
[("FROM_SDN_APPLIANCE_ROUTES", {
"community_id": "1235:1235"
})],
True,
[
["route-map FROM_SDN_APPLIANCE_ROUTES_RM permit 100",
" set as-path prepend 12346 12346",
" set community 1235:1235",
" set origin incomplete"]
]
)

set_del_test(
mgr,
"DEL",
("FROM_SDN_APPLIANCE_ROUTES",),
True,
[
["no route-map FROM_SDN_APPLIANCE_ROUTES_RM permit 100"]
]
)

def test_set_del_com_sdn_apl_and_slb():
mgr = constructor()
set_del_test(
mgr,
"SET",
[("FROM_SDN_APPLIANCE_ROUTES", {
"community_id": "1235:1235"
}),
("FROM_SDN_SLB_ROUTES", {
"community_id": "1234:1234"
}
)],
True,
[
["route-map FROM_SDN_APPLIANCE_ROUTES_RM permit 100",
" set as-path prepend 12346 12346",
" set community 1235:1235",
" set origin incomplete"],
["route-map FROM_SDN_SLB_ROUTES_RM permit 100",
" set as-path prepend 12346 12346",
" set community 1234:1234",
" set origin incomplete"]

]
)

set_del_test(
mgr,
"DEL",
("FROM_SDN_APPLIANCE_ROUTES", "FROM_SDN_SLB_ROUTES",),
True,
[
["no route-map FROM_SDN_APPLIANCE_ROUTES_RM permit 100"],
["no route-map FROM_SDN_SLB_ROUTES_RM permit 100"]
]
)

0 comments on commit 45add9d

Please sign in to comment.