From 29b2d4435d96f78bb6d9e9288d457b574f46d1bb Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Wed, 8 Jul 2020 23:33:43 -0700 Subject: [PATCH 1/5] Sfputil base and helper class changes for multi-ASIC --- sonic_platform_base/sonic_sfp/sfputilbase.py | 44 ++++++++++++++++--- .../sonic_sfp/sfputilhelper.py | 43 +++++++++++++++--- 2 files changed, 76 insertions(+), 11 deletions(-) diff --git a/sonic_platform_base/sonic_sfp/sfputilbase.py b/sonic_platform_base/sonic_sfp/sfputilbase.py index 56845c579..2706dc0ab 100644 --- a/sonic_platform_base/sonic_sfp/sfputilbase.py +++ b/sonic_platform_base/sonic_sfp/sfputilbase.py @@ -31,6 +31,9 @@ PLATFORM_JSON = 'platform.json' PORT_CONFIG_INI = 'port_config.ini' +# TODO, to move this definition to a common place +INTERNAL_INTERFACE_PREFIX = "Ethernet-BP" + # definitions of the offset and width for values in XCVR info eeprom XCVR_INTFACE_BULK_OFFSET = 0 XCVR_INTFACE_BULK_WIDTH_QSFP = 20 @@ -157,6 +160,9 @@ class SfpUtilBase(object): """ ["swp1", "swp5", "swp6", "swp7", "swp8" ...] """ logical = [] + # Mapping of logical port names available on a system to ASIC num + logical_to_asic = {} + # dicts for easier conversions between logical, physical and bcm ports logical_to_bcm = {} logical_to_physical = {} @@ -371,7 +377,7 @@ def _is_valid_port(self, port_num): return False - def read_porttab_mappings(self, porttabfile): + def read_porttab_mappings(self, porttabfile, asic_inst = 0): logical = [] logical_to_bcm = {} logical_to_physical = {} @@ -455,12 +461,16 @@ def read_porttab_mappings(self, porttabfile): # so we use the port's position in the file (zero-based) as bcm_port portname = line.split()[0] + # Ignore if this is an internal backplane interface + if portname.startswith(INTERNAL_INTERFACE_PREFIX): + continue + bcm_port = str(port_pos_in_file) if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - elif len(line.split()) >= 4: + elif "asic_port_name" not in title and len(line.split()) >= 4: fp_port_index = int(line.split()[3]) else: fp_port_index = portname.split("Ethernet").pop() @@ -483,6 +493,9 @@ def read_porttab_mappings(self, porttabfile): logical.append(portname) + # Mapping of logical port names available on a system to ASIC instance + self.logical_to_asic[portname] = asic_inst + logical_to_bcm[portname] = "xe" + bcm_port logical_to_physical[portname] = [fp_port_index] if physical_to_logical.get(fp_port_index) is None: @@ -495,10 +508,10 @@ def read_porttab_mappings(self, porttabfile): port_pos_in_file += 1 - self.logical = logical - self.logical_to_bcm = logical_to_bcm - self.logical_to_physical = logical_to_physical - self.physical_to_logical = physical_to_logical + self.logical.extend(logical) + self.logical_to_bcm.update(logical_to_bcm) + self.logical_to_physical.update(logical_to_physical) + self.physical_to_logical.update(physical_to_logical) """ print("logical: " + self.logical) @@ -506,6 +519,18 @@ def read_porttab_mappings(self, porttabfile): print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical) """ + + def read_all_porttab_mappings(self, platform_dir, num_asic_inst): + # In multi asic scenario, get all the port_config files for different asics + for inst in range(num_asic_inst): + port_map_dir = os.path.join(platform_dir, str(inst)) + port_map_file = os.path.join(port_map_dir, PORT_CONFIG_INI) + if os.path.exists(port_map_file): + self.read_porttab_mappings(port_map_file, inst) + else: + port_json_file = os.path.join(port_map_dir, PLATFORM_JSON) + self.read_porttab_mappings(port_json_file, inst) + def read_phytab_mappings(self, phytabfile): logical = [] phytab_mappings = {} @@ -615,6 +640,13 @@ def is_logical_port(self, port): else: return 0 + def get_asicId_for_logical_port(self, logical_port): + """Returns the asic_id list of physical ports for the given logical port""" + if logical_port in self.logical_to_asic.keys(): + return self.logical_to_asic[logical_port] + else: + return None + def is_logical_port_ganged_40_by_4(self, logical_port): physical_port_list = self.logical_to_physical[logical_port] if len(physical_port_list) > 1: diff --git a/sonic_platform_base/sonic_sfp/sfputilhelper.py b/sonic_platform_base/sonic_sfp/sfputilhelper.py index 5d17132ec..f9716b24b 100644 --- a/sonic_platform_base/sonic_sfp/sfputilhelper.py +++ b/sonic_platform_base/sonic_sfp/sfputilhelper.py @@ -23,6 +23,9 @@ PLATFORM_JSON = 'platform.json' PORT_CONFIG_INI = 'port_config.ini' +# TODO, to move this definition to a common place +INTERNAL_INTERFACE_PREFIX = "Ethernet-BP" + class SfpUtilHelper(object): # List to specify filter for sfp_ports # Needed by platforms like dni-6448 which @@ -33,6 +36,9 @@ class SfpUtilHelper(object): """ ["swp1", "swp5", "swp6", "swp7", "swp8" ...] """ logical = [] + # Mapping of logical port names available on a system to ASIC num + logical_to_asic = {} + # dicts for easier conversions between logical, physical and bcm ports logical_to_physical = {} @@ -42,7 +48,7 @@ class SfpUtilHelper(object): def __init__(self): pass - def read_porttab_mappings(self, porttabfile): + def read_porttab_mappings(self, porttabfile, asic_inst = 0): logical = [] logical_to_physical = {} physical_to_logical = {} @@ -122,12 +128,16 @@ def read_porttab_mappings(self, porttabfile): # so we use the port's position in the file (zero-based) as bcm_port portname = line.split()[0] + # Ignore if this is an internal backplane interface + if portname.startswith(INTERNAL_INTERFACE_PREFIX): + continue + bcm_port = str(port_pos_in_file) if "index" in title: fp_port_index = int(line.split()[title.index("index")]) # Leave the old code for backward compatibility - elif len(line.split()) >= 4: + elif "asic_port_name" not in title and len(line.split()) >= 4: fp_port_index = int(line.split()[3]) else: fp_port_index = portname.split("Ethernet").pop() @@ -150,6 +160,9 @@ def read_porttab_mappings(self, porttabfile): logical.append(portname) + # Mapping of logical port names available on a system to ASIC instance + self.logical_to_asic[portname] = asic_inst + logical_to_physical[portname] = [fp_port_index] if physical_to_logical.get(fp_port_index) is None: physical_to_logical[fp_port_index] = [portname] @@ -161,15 +174,28 @@ def read_porttab_mappings(self, porttabfile): port_pos_in_file += 1 - self.logical = logical - self.logical_to_physical = logical_to_physical - self.physical_to_logical = physical_to_logical + self.logical.extend(logical) + self.logical_to_physical.update(logical_to_physical) + self.physical_to_logical.update(physical_to_logical) """ print("logical: " + self.logical) print("logical to physical: " + self.logical_to_physical) print("physical to logical: " + self.physical_to_logical) """ + + def read_all_porttab_mappings(self, platform_dir, num_asic_inst): + # In multi asic scenario, get all the port_config files for different asics + + for inst in range(num_asic_inst): + port_map_dir = os.path.join(platform_dir, str(inst), '/') + port_map_file = os.path.join(port_map_dir, str(inst), PORT_CONFIG_INI) + if os.path.exists(port_map_file): + self.read_porttab_mappings(port_map_file, inst) + else: + port_json_file = os.path.join(port_map_dir, str(inst), PLATFORM_JSON) + self.read_porttab_mappings(port_json_file, inst) + def get_physical_to_logical(self, port_num): """Returns list of logical ports for the given physical port""" @@ -185,3 +211,10 @@ def is_logical_port(self, port): return 1 else: return 0 + + def get_asicId_for_logical_port(self, logical_port): + """Returns the asic_id list of physical ports for the given logical port""" + if logical_port in self.logical_to_asic.keys(): + return self.logical_to_asic[logical_port] + else: + return None From 4a8927ffe0900d66ce5f1cb8778c4906184db4c4 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Thu, 9 Jul 2020 18:39:06 -0700 Subject: [PATCH 2/5] Updates to initial commit --- sonic_platform_base/sonic_sfp/sfputilbase.py | 8 +++----- sonic_platform_base/sonic_sfp/sfputilhelper.py | 15 ++++++--------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/sonic_platform_base/sonic_sfp/sfputilbase.py b/sonic_platform_base/sonic_sfp/sfputilbase.py index 2706dc0ab..28a3888a2 100644 --- a/sonic_platform_base/sonic_sfp/sfputilbase.py +++ b/sonic_platform_base/sonic_sfp/sfputilbase.py @@ -31,9 +31,6 @@ PLATFORM_JSON = 'platform.json' PORT_CONFIG_INI = 'port_config.ini' -# TODO, to move this definition to a common place -INTERNAL_INTERFACE_PREFIX = "Ethernet-BP" - # definitions of the offset and width for values in XCVR info eeprom XCVR_INTFACE_BULK_OFFSET = 0 XCVR_INTFACE_BULK_WIDTH_QSFP = 20 @@ -462,7 +459,7 @@ def read_porttab_mappings(self, porttabfile, asic_inst = 0): portname = line.split()[0] # Ignore if this is an internal backplane interface - if portname.startswith(INTERNAL_INTERFACE_PREFIX): + if portname.startswith(daemon_base.get_internal_interface_prefix()): continue bcm_port = str(port_pos_in_file) @@ -529,7 +526,8 @@ def read_all_porttab_mappings(self, platform_dir, num_asic_inst): self.read_porttab_mappings(port_map_file, inst) else: port_json_file = os.path.join(port_map_dir, PLATFORM_JSON) - self.read_porttab_mappings(port_json_file, inst) + if os.path.exists(port_json_file): + self.read_porttab_mappings(port_json_file, inst) def read_phytab_mappings(self, phytabfile): logical = [] diff --git a/sonic_platform_base/sonic_sfp/sfputilhelper.py b/sonic_platform_base/sonic_sfp/sfputilhelper.py index f9716b24b..ba31d5bcc 100644 --- a/sonic_platform_base/sonic_sfp/sfputilhelper.py +++ b/sonic_platform_base/sonic_sfp/sfputilhelper.py @@ -23,9 +23,6 @@ PLATFORM_JSON = 'platform.json' PORT_CONFIG_INI = 'port_config.ini' -# TODO, to move this definition to a common place -INTERNAL_INTERFACE_PREFIX = "Ethernet-BP" - class SfpUtilHelper(object): # List to specify filter for sfp_ports # Needed by platforms like dni-6448 which @@ -129,7 +126,7 @@ def read_porttab_mappings(self, porttabfile, asic_inst = 0): portname = line.split()[0] # Ignore if this is an internal backplane interface - if portname.startswith(INTERNAL_INTERFACE_PREFIX): + if portname.startswith(daemon_base.get_internal_interface_prefix()): continue bcm_port = str(port_pos_in_file) @@ -186,15 +183,15 @@ def read_porttab_mappings(self, porttabfile, asic_inst = 0): def read_all_porttab_mappings(self, platform_dir, num_asic_inst): # In multi asic scenario, get all the port_config files for different asics - for inst in range(num_asic_inst): - port_map_dir = os.path.join(platform_dir, str(inst), '/') - port_map_file = os.path.join(port_map_dir, str(inst), PORT_CONFIG_INI) + port_map_dir = os.path.join(platform_dir, str(inst)) + port_map_file = os.path.join(port_map_dir, PORT_CONFIG_INI) if os.path.exists(port_map_file): self.read_porttab_mappings(port_map_file, inst) else: - port_json_file = os.path.join(port_map_dir, str(inst), PLATFORM_JSON) - self.read_porttab_mappings(port_json_file, inst) + port_json_file = os.path.join(port_map_dir, PLATFORM_JSON) + if os.path.exists(port_json_file): + self.read_porttab_mappings(port_json_file, inst) def get_physical_to_logical(self, port_num): """Returns list of logical ports for the given physical port""" From 6419fa186b4c3adf1ae1e5c52872d201ad0ffa4d Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Fri, 10 Jul 2020 23:40:11 -0700 Subject: [PATCH 3/5] Updates for comments --- sonic_platform_base/sonic_sfp/sfputilbase.py | 4 ++-- sonic_platform_base/sonic_sfp/sfputilhelper.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sonic_platform_base/sonic_sfp/sfputilbase.py b/sonic_platform_base/sonic_sfp/sfputilbase.py index 28a3888a2..966b44c0e 100644 --- a/sonic_platform_base/sonic_sfp/sfputilbase.py +++ b/sonic_platform_base/sonic_sfp/sfputilbase.py @@ -374,7 +374,7 @@ def _is_valid_port(self, port_num): return False - def read_porttab_mappings(self, porttabfile, asic_inst = 0): + def read_porttab_mappings(self, porttabfile, asic_inst=0): logical = [] logical_to_bcm = {} logical_to_physical = {} @@ -638,7 +638,7 @@ def is_logical_port(self, port): else: return 0 - def get_asicId_for_logical_port(self, logical_port): + def get_asic_id_for_logical_port(self, logical_port): """Returns the asic_id list of physical ports for the given logical port""" if logical_port in self.logical_to_asic.keys(): return self.logical_to_asic[logical_port] diff --git a/sonic_platform_base/sonic_sfp/sfputilhelper.py b/sonic_platform_base/sonic_sfp/sfputilhelper.py index ba31d5bcc..b6ed51588 100644 --- a/sonic_platform_base/sonic_sfp/sfputilhelper.py +++ b/sonic_platform_base/sonic_sfp/sfputilhelper.py @@ -209,7 +209,7 @@ def is_logical_port(self, port): else: return 0 - def get_asicId_for_logical_port(self, logical_port): + def get_asic_id_for_logical_port(self, logical_port): """Returns the asic_id list of physical ports for the given logical port""" if logical_port in self.logical_to_asic.keys(): return self.logical_to_asic[logical_port] From a3614b03ec77799f9e5394e9d8774fddead856d4 Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Mon, 13 Jul 2020 16:50:21 -0700 Subject: [PATCH 4/5] Updated the missed comment earlier --- sonic_platform_base/sonic_sfp/sfputilhelper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sonic_platform_base/sonic_sfp/sfputilhelper.py b/sonic_platform_base/sonic_sfp/sfputilhelper.py index b6ed51588..208781238 100644 --- a/sonic_platform_base/sonic_sfp/sfputilhelper.py +++ b/sonic_platform_base/sonic_sfp/sfputilhelper.py @@ -45,7 +45,7 @@ class SfpUtilHelper(object): def __init__(self): pass - def read_porttab_mappings(self, porttabfile, asic_inst = 0): + def read_porttab_mappings(self, porttabfile, asic_inst=0): logical = [] logical_to_physical = {} physical_to_logical = {} From f5a10e4d647331d08603d0ac384bef9b4e1a935c Mon Sep 17 00:00:00 2001 From: Judy Joseph Date: Sun, 9 Aug 2020 15:37:57 -0700 Subject: [PATCH 5/5] Updated based on sonic-py-common --- sonic_platform_base/sonic_sfp/sfputilbase.py | 8 +++----- sonic_platform_base/sonic_sfp/sfputilhelper.py | 9 ++++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/sonic_platform_base/sonic_sfp/sfputilbase.py b/sonic_platform_base/sonic_sfp/sfputilbase.py index 966b44c0e..1f3d2470a 100644 --- a/sonic_platform_base/sonic_sfp/sfputilbase.py +++ b/sonic_platform_base/sonic_sfp/sfputilbase.py @@ -16,6 +16,7 @@ from natsort import natsorted from portconfig import get_port_config from sonic_py_common import device_info + from sonic_py_common.interface import backplane_prefix from . import bcmshell # Dot module supports both Python 2 and Python 3 using explicit relative import methods from sonic_eeprom import eeprom_dts @@ -459,7 +460,7 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0): portname = line.split()[0] # Ignore if this is an internal backplane interface - if portname.startswith(daemon_base.get_internal_interface_prefix()): + if portname.startswith(backplane_prefix()): continue bcm_port = str(port_pos_in_file) @@ -640,10 +641,7 @@ def is_logical_port(self, port): def get_asic_id_for_logical_port(self, logical_port): """Returns the asic_id list of physical ports for the given logical port""" - if logical_port in self.logical_to_asic.keys(): - return self.logical_to_asic[logical_port] - else: - return None + return self.logical_to_asic.get(logical_port) def is_logical_port_ganged_40_by_4(self, logical_port): physical_port_list = self.logical_to_physical[logical_port] diff --git a/sonic_platform_base/sonic_sfp/sfputilhelper.py b/sonic_platform_base/sonic_sfp/sfputilhelper.py index 208781238..eed5396d5 100644 --- a/sonic_platform_base/sonic_sfp/sfputilhelper.py +++ b/sonic_platform_base/sonic_sfp/sfputilhelper.py @@ -16,6 +16,8 @@ from natsort import natsorted from portconfig import get_port_config from sonic_py_common import device_info + from sonic_py_common.interface import backplane_prefix + except ImportError as e: raise ImportError("%s - required module not found" % str(e)) @@ -126,7 +128,7 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0): portname = line.split()[0] # Ignore if this is an internal backplane interface - if portname.startswith(daemon_base.get_internal_interface_prefix()): + if portname.startswith(backplane_prefix()): continue bcm_port = str(port_pos_in_file) @@ -211,7 +213,4 @@ def is_logical_port(self, port): def get_asic_id_for_logical_port(self, logical_port): """Returns the asic_id list of physical ports for the given logical port""" - if logical_port in self.logical_to_asic.keys(): - return self.logical_to_asic[logical_port] - else: - return None + return self.logical_to_asic.get(logical_port)