Skip to content

Commit

Permalink
Fix as5835-54x xcvrd busy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jostar Yang committed Oct 18, 2021
1 parent 2cb56ba commit 9f0352b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

try:
import sys
import time
from sonic_platform_pddf_base.pddf_chassis import PddfChassis
from .event import SfpEvent
except ImportError as e:
raise ImportError(str(e) + "- required module not found")

Expand All @@ -25,53 +25,17 @@ class Chassis(PddfChassis):
def __init__(self, pddf_data=None, pddf_plugin_data=None):
PddfChassis.__init__(self, pddf_data, pddf_plugin_data)
self.__initialize_components()
self._sfpevent = SfpEvent(self.get_all_sfps())

def __initialize_components(self):
from sonic_platform.component import Component
for index in range(NUM_COMPONENT):
component = Component(index)
self._component_list.append(component)


# Provide the functions/variables below for which implementation is to be overwritten
sfp_change_event_data = {'valid': 0, 'last': 0, 'present': 0}
def get_change_event(self, timeout=2000):
now = time.time()
port_dict = {}
change_dict = {}
change_dict['sfp'] = port_dict

if timeout < 1000:
timeout = 1000
timeout = timeout / float(1000) # Convert to secs

if now < (self.sfp_change_event_data['last'] + timeout) and self.sfp_change_event_data['valid']:
return True, change_dict

bitmap = 0
for i in range(54):
modpres = self.get_sfp(i+1).get_presence()
if modpres:
bitmap = bitmap | (1 << i)

changed_ports = self.sfp_change_event_data['present'] ^ bitmap
if changed_ports:
for i in range(54):
if (changed_ports & (1 << i)):
if (bitmap & (1 << i)) == 0:
port_dict[i+1] = '0'
else:
port_dict[i+1] = '1'


# Update teh cache dict
self.sfp_change_event_data['present'] = bitmap
self.sfp_change_event_data['last'] = now
self.sfp_change_event_data['valid'] = 1
return True, change_dict
else:
return True, change_dict

def get_change_event(self, timeout=0):
return self._sfpevent.get_sfp_event(timeout)

def get_sfp(self, index):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
try:
import time
from sonic_py_common.logger import Logger
except ImportError as e:
raise ImportError(repr(e) + " - required module not found")

POLL_INTERVAL_IN_SEC = 1

class SfpEvent:
''' Listen to insert/remove sfp events '''

def __init__(self, sfp_list):
self._sfp_list = sfp_list
self._logger = Logger()
self._sfp_change_event_data = {'present': 0}

def get_presence_bitmap(self):
bitmap = 0
for sfp in self._sfp_list:
modpres = sfp.get_presence()
i=sfp.get_position_in_parent() - 1
if modpres:
bitmap = bitmap | (1 << i)
return bitmap

def get_sfp_event(self, timeout=2000):
port_dict = {}
change_dict = {}
change_dict['sfp'] = port_dict

if timeout < 1000:
cd_ms = 1000
else:
cd_ms = timeout

while cd_ms > 0:
bitmap = self.get_presence_bitmap()
changed_ports = self._sfp_change_event_data['present'] ^ bitmap
if changed_ports != 0:
break
time.sleep(POLL_INTERVAL_IN_SEC)
# timeout=0 means wait for event forever
if timeout != 0:
cd_ms = cd_ms - POLL_INTERVAL_IN_SEC * 1000

if changed_ports != 0:
for sfp in self._sfp_list:
i=sfp.get_position_in_parent() - 1
if (changed_ports & (1 << i)):
if (bitmap & (1 << i)) == 0:
port_dict[i+1] = '0'
else:
port_dict[i+1] = '1'


# Update the cache dict
self._sfp_change_event_data['present'] = bitmap
return True, change_dict
else:
return True, change_dict
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ def __init__(self, index, pddf_data=None, pddf_plugin_data=None):
PddfSfp.__init__(self, index, pddf_data, pddf_plugin_data)

# Provide the functions/variables below for which implementation is to be overwritten
def get_position_in_parent(self):
"""Retrieves 1-based relative physical position in parent device."""
return self.port_index

0 comments on commit 9f0352b

Please sign in to comment.