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 committed Jan 22, 2021
1 parent beaaf33 commit a87f56c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/sonic-bgpcfgd/bgpcfgd/managers_bbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ 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]:
for peer in available_peers_per_pg[pg_name]:
cmds.append(" %sneighbor %s allowas-in 1" % (prefix_of_commands, peer))
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]:
for peer in available_peers_per_pg[peer_group_name]:
cmds.append(" %sneighbor %s allowas-in 1" % (prefix_of_commands, peer))
peer_groups_to_restart.add(peer_group_name)
return cmds, list(peer_groups_to_restart)

def __get_available_peer_groups(self):
Expand Down Expand Up @@ -150,4 +151,4 @@ def __get_available_peers_per_peer_group(self, available_peer_groups):
pg = m.group(2)
if pg in available_peer_groups:
res[pg].append(peer)
return res
return res
42 changes: 40 additions & 2 deletions src/sonic-bgpcfgd/tests/test_bbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,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, mapping_pgs, expected_cmds):
def __set_prepare_config_common(status, bbr_enabled_pgs, available_pgs, mapping_pgs, expected_cmds, bbr_applied_pgs=None):
cfg_mgr = MagicMock()
common_objs = {
'directory': Directory(),
Expand All @@ -271,7 +271,7 @@ def __set_prepare_config_common(status, bbr_enabled_pgs, available_pgs, mapping_
m._BBRMgr__get_available_peers_per_peer_group = MagicMock(return_value = mapping_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 @@ -330,6 +330,44 @@ def test___set_prepare_config_disabled_part():
' no neighbor 10.0.0.1 allowas-in 1',
' no neighbor fc00::1 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"},
{"PEER_V6": ['fc00::1'],"PEER_V6_DEPLOYMENT_ID_0":['fc00::2'],"PEER_V6_DEPLOYMENT_ID_1":['fc00::3'],
"PEER_V4":['10.0.0.1'],"PEER_V4_DEPLOYMENT_ID_0":['10.0.0.2'],"PEER_V4_DEPLOYMENT_ID_1":['10.0.0.3'], "PEER_INVALID":['10.0.0.4']},[
'router bgp 65500',
' address-family ipv4',
' neighbor 10.0.0.1 allowas-in 1',
' neighbor 10.0.0.3 allowas-in 1',
' neighbor 10.0.0.2 allowas-in 1',
' address-family ipv6',
' neighbor fc00::3 allowas-in 1',
' neighbor fc00::2 allowas-in 1',
' neighbor fc00::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"},
{"PEER_V6": ['fc00::1'],"PEER_V6_DEPLOYMENT_ID_0":['fc00::2'],"PEER_V6_DEPLOYMENT_ID_1":['fc00::3'],
"PEER_V4":['10.0.0.1'],"PEER_V4_DEPLOYMENT_ID_0":['10.0.0.2'],"PEER_V4_DEPLOYMENT_ID_1":['10.0.0.3'], "PEER_INVALID":['10.0.0.4']},[
'router bgp 65500',
' address-family ipv4',
' no neighbor 10.0.0.1 allowas-in 1',
' no neighbor 10.0.0.3 allowas-in 1',
' no neighbor 10.0.0.2 allowas-in 1',
' address-family ipv6',
' no neighbor fc00::3 allowas-in 1',
' no neighbor fc00::2 allowas-in 1',
' no neighbor fc00::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 a87f56c

Please sign in to comment.