Skip to content

Commit

Permalink
Updated BBR to use peer group name as prefix. (#6515)
Browse files Browse the repository at this point in the history
To make BBR configured for peer-group if it's name starts with (prefixed) with the string define in constants.yml instead of exact string match.
  • Loading branch information
abdosi authored Jan 22, 2021
1 parent 0464d15 commit 5f39926
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/sonic-bgpcfgd/bgpcfgd/managers_bbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ def __set_prepare_config(self, status):
for af in ["ipv4", "ipv6"]:
cmds.append(" address-family %s" % af)
for pg_name in sorted(self.bbr_enabled_pgs.keys()):
if pg_name in available_peer_groups and af in self.bbr_enabled_pgs[pg_name]:
cmds.append(" %sneighbor %s allowas-in 1" % (prefix_of_commands, pg_name))
peer_groups_to_restart.add(pg_name)
for peer_group_name in available_peer_groups:
if peer_group_name.startswith(pg_name) and af in self.bbr_enabled_pgs[pg_name]:
cmds.append(" %sneighbor %s allowas-in 1" % (prefix_of_commands, peer_group_name))
peer_groups_to_restart.add(peer_group_name)
return cmds, list(peer_groups_to_restart)

def __get_available_peer_groups(self):
Expand Down
40 changes: 37 additions & 3 deletions src/sonic-bgpcfgd/tests/test_bbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test___set_validation_4():
def test___set_validation_5():
__set_validation_common("all", {"status": "disabled"}, None, True)

def __set_prepare_config_common(status, bbr_enabled_pgs, available_pgs, expected_cmds):
def __set_prepare_config_common(status, bbr_enabled_pgs, available_pgs, expected_cmds, bbr_applied_pgs=None):
cfg_mgr = MagicMock()
common_objs = {
'directory': Directory(),
Expand All @@ -269,10 +269,10 @@ def __set_prepare_config_common(status, bbr_enabled_pgs, available_pgs, expected
}
}
m.bbr_enabled_pgs = bbr_enabled_pgs
m._BBRMgr__get_available_peer_groups = MagicMock(return_value = available_pgs)
m._BBRMgr__get_available_peer_groups = MagicMock(return_value = sorted(available_pgs))
cmds, peer_groups = m._BBRMgr__set_prepare_config(status)
assert cmds == expected_cmds
assert set(peer_groups) == available_pgs
assert set(peer_groups) == (available_pgs if not bbr_applied_pgs else bbr_applied_pgs)

def test___set_prepare_config_enabled():
__set_prepare_config_common("enabled", {
Expand Down Expand Up @@ -327,7 +327,41 @@ def test___set_prepare_config_disabled_part():
' no neighbor PEER_V4 allowas-in 1',
' no neighbor PEER_V6 allowas-in 1',
])
def test___set_prepare_config_enabled_multiple_peers():
__set_prepare_config_common("enabled", {
"PEER_V4": ["ipv4"],
"PEER_V6": ["ipv6"],
}, {"PEER_V4", "PEER_V4_DEPLOYMENT_ID_0", "PEER_V4_DEPLOYMENT_ID_1", "PEER_V6", "PEER_V6_DEPLOYMENT_ID_0", "PEER_V6_DEPLOYMENT_ID_1", "PEER_INVALID"},
[
'router bgp 65500',
' address-family ipv4',
' neighbor PEER_V4 allowas-in 1',
' neighbor PEER_V4_DEPLOYMENT_ID_0 allowas-in 1',
' neighbor PEER_V4_DEPLOYMENT_ID_1 allowas-in 1',
' address-family ipv6',
' neighbor PEER_V6 allowas-in 1',
' neighbor PEER_V6_DEPLOYMENT_ID_0 allowas-in 1',
' neighbor PEER_V6_DEPLOYMENT_ID_1 allowas-in 1',
],
{"PEER_V4", "PEER_V4_DEPLOYMENT_ID_0", "PEER_V4_DEPLOYMENT_ID_1", "PEER_V6", "PEER_V6_DEPLOYMENT_ID_0", "PEER_V6_DEPLOYMENT_ID_1"})

def test___set_prepare_config_disabled_multiple_peers():
__set_prepare_config_common("disabled", {
"PEER_V4": ["ipv4"],
"PEER_V6": ["ipv6"],
}, {"PEER_V4", "PEER_V4_DEPLOYMENT_ID_0", "PEER_V4_DEPLOYMENT_ID_1", "PEER_V6", "PEER_V6_DEPLOYMENT_ID_0", "PEER_V6_DEPLOYMENT_ID_1", "PEER_INVALID"},
[
'router bgp 65500',
' address-family ipv4',
' no neighbor PEER_V4 allowas-in 1',
' no neighbor PEER_V4_DEPLOYMENT_ID_0 allowas-in 1',
' no neighbor PEER_V4_DEPLOYMENT_ID_1 allowas-in 1',
' address-family ipv6',
' no neighbor PEER_V6 allowas-in 1',
' no neighbor PEER_V6_DEPLOYMENT_ID_0 allowas-in 1',
' no neighbor PEER_V6_DEPLOYMENT_ID_1 allowas-in 1',
],
{"PEER_V4", "PEER_V4_DEPLOYMENT_ID_0", "PEER_V4_DEPLOYMENT_ID_1", "PEER_V6", "PEER_V6_DEPLOYMENT_ID_0", "PEER_V6_DEPLOYMENT_ID_1"})

def test__get_available_peer_groups():
cfg_mgr = MagicMock()
Expand Down

0 comments on commit 5f39926

Please sign in to comment.