Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the device type and bgp session status for multi NPU platforms #4600

Merged
merged 5 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,21 @@ def filter_acl_table_bindings(acls, neighbors, port_channels, sub_role):

return filter_acls

def enable_internal_bgp_session(bgp_sessions, filename, asic_name):
'''
In Multi-NPU session the internal sessions will always be up.
So adding the admin-status 'up' configuration to bgp sessions
BGP session between FrontEnd and BackEnd Asics are internal bgp sessions
'''
local_sub_role = parse_asic_sub_role(filename, asic_name)

for peer_ip in bgp_sessions.keys():
peer_name = bgp_sessions[peer_ip]['name']
peer_sub_role = parse_asic_sub_role(filename, peer_name)
if ((local_sub_role == FRONTEND_ASIC_SUB_ROLE and peer_sub_role == BACKEND_ASIC_SUB_ROLE) or
(local_sub_role == BACKEND_ASIC_SUB_ROLE and peer_sub_role == FRONTEND_ASIC_SUB_ROLE)):
bgp_sessions[peer_ip].update({'admin_status': 'up'})

###############################################################################
#
# Main functions
Expand Down Expand Up @@ -842,6 +857,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
(intfs, lo_intfs, mvrf, mgmt_intf, vlans, vlan_members, pcs, pc_members, acls, vni) = parse_dpg(child, asic_name)
elif child.tag == str(QName(ns, "CpgDec")):
(bgp_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, asic_name)
enable_internal_bgp_session(bgp_sessions, filename, asic_name)
elif child.tag == str(QName(ns, "PngDec")):
(neighbors, devices, port_speed_png) = parse_asic_png(child, asic_name, hostname)
elif child.tag == str(QName(ns, "MetadataDeclaration")):
Expand All @@ -851,6 +867,8 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
elif child.tag == str(QName(ns, "DeviceInfos")):
(port_speeds_default, port_descriptions) = parse_deviceinfo(child, hwsku)

# set the host device type in asic metadata also
device_type = [devices[key]['type'] for key in devices if key.lower() == hostname.lower()][0]
if asic_name is None:
current_device = [devices[key] for key in devices if key.lower() == hostname.lower()][0]
else:
Expand All @@ -864,7 +882,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None):
'docker_routing_config_mode': docker_routing_config_mode,
'hostname': hostname,
'hwsku': hwsku,
'type': current_device['type']
'type': device_type
}
}
# for this hostname, if sub_role is defined, add sub_role in
Expand Down
12 changes: 6 additions & 6 deletions src/sonic-config-engine/tests/test_multinpu_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ASIC_SKU = 'multi-npu-asic'
NUM_ASIC = 4
HOSTNAME = 'multi_npu_platform_01'

DEVICE_TYPE = 'LeafRouter'

class TestMultiNpuCfgGen(TestCase):

Expand Down Expand Up @@ -197,16 +197,16 @@ def test_frontend_bgp_neighbor(self):
output = json.loads(self.run_script(argument))
self.assertDictEqual(output, \
{'10.0.0.1': {'rrclient': 0, 'name': '01T2', 'local_addr': '10.0.0.0', 'nhopself': 0, 'holdtime': '10', 'asn': '65200', 'keepalive': '3'},
'10.1.0.0': {'rrclient': 0, 'name': 'ASIC2', 'local_addr': '10.1.0.1', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'},
'10.1.0.0': {'rrclient': 0, 'name': 'ASIC2', 'local_addr': '10.1.0.1', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0', 'admin_status': 'up'},
'fc00::2': {'rrclient': 0, 'name': '01T2', 'local_addr': 'fc00::1', 'nhopself': 0, 'holdtime': '10', 'asn': '65200', 'keepalive': '3'},
'10.1.0.2': {'rrclient': 0, 'name': 'ASIC3', 'local_addr': '10.1.0.3', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'}})
'10.1.0.2': {'rrclient': 0, 'name': 'ASIC3', 'local_addr': '10.1.0.3', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0', 'admin_status': 'up'}})

def test_backend_asic_bgp_neighbor(self):
argument = "-m {} -p {} -n asic3 --var-json \"BGP_NEIGHBOR\"".format(self.sample_graph, self.port_config[3])
output = json.loads(self.run_script(argument))
self.assertDictEqual(output, \
{'10.1.0.7': {'rrclient': 0, 'name': 'ASIC1', 'local_addr': '10.1.0.6', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'},
'10.1.0.3': {'rrclient': 0, 'name': 'ASIC0', 'local_addr': '10.1.0.2', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'}})
{'10.1.0.7': {'rrclient': 0, 'name': 'ASIC1', 'local_addr': '10.1.0.6', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0', 'admin_status': 'up'},
'10.1.0.3': {'rrclient': 0, 'name': 'ASIC0', 'local_addr': '10.1.0.2', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0', 'admin_status': 'up'}})

def test_device_asic_metadata(self):
argument = "-m {} --var-json DEVICE_METADATA".format(self.sample_graph)
Expand All @@ -215,7 +215,7 @@ def test_device_asic_metadata(self):
asic_name = "asic{}".format(asic)
self.assertEqual(output['localhost']['hostname'], 'multi_npu_platform_01')
self.assertEqual(output['localhost']['asic_name'], asic_name)
self.assertEqual(output['localhost']['type'], 'Asic')
self.assertEqual(output['localhost']['type'], DEVICE_TYPE)
if asic == 0 or asic == 1:
self.assertEqual(output['localhost']['sub_role'], 'FrontEnd')
else:
Expand Down