-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jostar Yang
committed
Oct 18, 2021
1 parent
2cb56ba
commit 9f0352b
Showing
3 changed files
with
67 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
platform/broadcom/sonic-platform-modules-accton/as5835-54x/sonic_platform/event.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters