Skip to content

Commit

Permalink
[Accton/PDDF] Add get_sfp() to chassis to handle port idx (#7980)
Browse files Browse the repository at this point in the history
* Modify index start from 1 in in get_change_event()

Co-authored-by: Jostar Yang <[email protected]>
  • Loading branch information
jostar-yang and Jostar Yang authored Jul 25, 2021
1 parent 24cc827 commit 5e435e0
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
Expand Down Expand Up @@ -38,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)

Expand All @@ -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 <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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
Expand Down Expand Up @@ -38,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)

Expand All @@ -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 <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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
Expand Down Expand Up @@ -38,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)

Expand All @@ -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 <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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#############################################################################

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
except ImportError as e:
Expand Down Expand Up @@ -38,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)

Expand All @@ -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 <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

0 comments on commit 5e435e0

Please sign in to comment.