From 812814f7ccee7b53b9c8d459fd28a457c1ab9a0c Mon Sep 17 00:00:00 2001 From: Jostar Yang Date: Fri, 25 Jun 2021 17:29:58 +0800 Subject: [PATCH 1/2] [PDDF] Add get_sfp() to chassis to handle port idx Signed-off-by: Jostar Yang --- .../as7326-56x/sonic_platform/chassis.py | 24 ++++++++++++++++++ .../as7726-32x/sonic_platform/chassis.py | 25 +++++++++++++++++++ .../as7816-64x/sonic_platform/chassis.py | 25 +++++++++++++++++++ .../as9716-32d/sonic_platform/chassis.py | 25 +++++++++++++++++++ 4 files changed, 99 insertions(+) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py index 99fb3b569a2c..8bd0f93b40b2 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py @@ -7,6 +7,7 @@ ############################################################################# try: + import sys import time from sonic_platform_pddf_base.pddf_chassis import PddfChassis except ImportError as e: @@ -59,3 +60,26 @@ def get_change_event(self, timeout=2000): return True, change_dict else: return True, change_dict + + def get_sfp(self, index): + """ + Retrieves sfp represented by (1-based) index + + Args: + index: An integer, the index (1-based) of the sfp to retrieve. + The index should be the sequence of a physical port in a chassis, + starting from 1. + For example, 1 for Ethernet0, 2 for Ethernet4 and so on. + + Returns: + An object derived from SfpBase representing the specified sfp + """ + sfp = None + + try: + # The index will start from 1 + sfp = self._sfp_list[index-1] + except IndexError: + sys.stderr.write("SFP index {} out of range (1-{})\n".format( + index, len(self._sfp_list))) + return sfp diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py index 713cf6831ac0..0bb30e5203aa 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py @@ -7,6 +7,7 @@ ############################################################################# try: + import sys import time from sonic_platform_pddf_base.pddf_chassis import PddfChassis except ImportError as e: @@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000): return True, change_dict else: return True, change_dict + + + def get_sfp(self, index): + """ + Retrieves sfp represented by (1-based) index + + Args: + index: An integer, the index (1-based) of the sfp to retrieve. + The index should be the sequence of a physical port in a chassis, + starting from 1. + For example, 1 for Ethernet0, 2 for Ethernet4 and so on. + + Returns: + An object derived from SfpBase representing the specified sfp + """ + sfp = None + + try: + # The index will start from 1 + sfp = self._sfp_list[index-1] + except IndexError: + sys.stderr.write("SFP index {} out of range (1-{})\n".format( + index, len(self._sfp_list))) + return sfp diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py index 12c7dbacb16b..67e449b2bdcd 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py @@ -7,6 +7,7 @@ ############################################################################# try: + import sys import time from sonic_platform_pddf_base.pddf_chassis import PddfChassis except ImportError as e: @@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000): return True, change_dict else: return True, change_dict + + + def get_sfp(self, index): + """ + Retrieves sfp represented by (1-based) index + + Args: + index: An integer, the index (1-based) of the sfp to retrieve. + The index should be the sequence of a physical port in a chassis, + starting from 1. + For example, 1 for Ethernet0, 2 for Ethernet4 and so on. + + Returns: + An object derived from SfpBase representing the specified sfp + """ + sfp = None + + try: + # The index will start from 1 + sfp = self._sfp_list[index-1] + except IndexError: + sys.stderr.write("SFP index {} out of range (1-{})\n".format( + index, len(self._sfp_list))) + return sfp diff --git a/platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py index 713cf6831ac0..0bb30e5203aa 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py @@ -7,6 +7,7 @@ ############################################################################# try: + import sys import time from sonic_platform_pddf_base.pddf_chassis import PddfChassis except ImportError as e: @@ -59,3 +60,27 @@ def get_change_event(self, timeout=2000): return True, change_dict else: return True, change_dict + + + def get_sfp(self, index): + """ + Retrieves sfp represented by (1-based) index + + Args: + index: An integer, the index (1-based) of the sfp to retrieve. + The index should be the sequence of a physical port in a chassis, + starting from 1. + For example, 1 for Ethernet0, 2 for Ethernet4 and so on. + + Returns: + An object derived from SfpBase representing the specified sfp + """ + sfp = None + + try: + # The index will start from 1 + sfp = self._sfp_list[index-1] + except IndexError: + sys.stderr.write("SFP index {} out of range (1-{})\n".format( + index, len(self._sfp_list))) + return sfp From a6e35e9cab910009f8606548b50880d39b1561d6 Mon Sep 17 00:00:00 2001 From: Jostar Yang Date: Fri, 9 Jul 2021 16:42:32 +0800 Subject: [PATCH 2/2] Modify index start from 1 in in get_change_event() --- .../as7326-56x/sonic_platform/chassis.py | 2 +- .../as7726-32x/sonic_platform/chassis.py | 2 +- .../as7816-64x/sonic_platform/chassis.py | 2 +- .../as9716-32d/sonic_platform/chassis.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py index 8bd0f93b40b2..feb1fbdb5620 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7326-56x/sonic_platform/chassis.py @@ -39,7 +39,7 @@ def get_change_event(self, timeout=2000): bitmap = 0 for i in range(58): - modpres = self.get_sfp(i).get_presence() + modpres = self.get_sfp(i+1).get_presence() if modpres: bitmap = bitmap | (1 << i) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py index 0bb30e5203aa..8ff20a760562 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7726-32x/sonic_platform/chassis.py @@ -39,7 +39,7 @@ def get_change_event(self, timeout=2000): bitmap = 0 for i in range(34): - modpres = self.get_sfp(i).get_presence() + modpres = self.get_sfp(i+1).get_presence() if modpres: bitmap = bitmap | (1 << i) diff --git a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py index 67e449b2bdcd..c597c0d8bb1c 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as7816-64x/sonic_platform/chassis.py @@ -39,7 +39,7 @@ def get_change_event(self, timeout=2000): bitmap = 0 for i in range(64): - modpres = self.get_sfp(i).get_presence() + modpres = self.get_sfp(i+1).get_presence() if modpres: bitmap = bitmap | (1 << i) diff --git a/platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py b/platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py index 0bb30e5203aa..8ff20a760562 100644 --- a/platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py +++ b/platform/broadcom/sonic-platform-modules-accton/as9716-32d/sonic_platform/chassis.py @@ -39,7 +39,7 @@ def get_change_event(self, timeout=2000): bitmap = 0 for i in range(34): - modpres = self.get_sfp(i).get_presence() + modpres = self.get_sfp(i+1).get_presence() if modpres: bitmap = bitmap | (1 << i)