forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Inventec][D6356] Update Inventec 6356 (sonic-net#3839)
* [Inventec][D6356] Update Inventec 6356 1.[Platform API] Add get_change_event implementation for Chassis class 2.[Platforn monitor] skip ledd to avoid pmon init failure
- Loading branch information
Showing
5 changed files
with
170 additions
and
20 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
4 changes: 4 additions & 0 deletions
4
device/inventec/x86_64-inventec_d6356-r0/pmon_daemon_control.json
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,4 @@ | ||
{ | ||
"skip_ledd": true | ||
} | ||
|
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
116 changes: 116 additions & 0 deletions
116
platform/broadcom/sonic-platform-modules-inventec/d6356/sonic_platform/transceiver_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,116 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Name: transceiver_event.py, version: 1.0 | ||
# | ||
|
||
try: | ||
import time | ||
import socket | ||
import re | ||
import os | ||
from collections import OrderedDict | ||
except ImportError as e: | ||
raise ImportError("%s - required module not found" % str(e)) | ||
|
||
|
||
class NetlinkEventMonitor(object): | ||
__instance = None | ||
|
||
def __new__(cls, *args, **kwargs): | ||
if not cls.__instance: | ||
# print(cls) | ||
cls.__instance = super(NetlinkEventMonitor, cls).__new__(cls) | ||
cls.__instance.__recieved_events = OrderedDict() | ||
return cls.__instance | ||
|
||
def __init__(self, timeout): | ||
# print('__init__', self) | ||
NETLINK_KOBJECT_UEVENT = 15 | ||
self.__socket = socket.socket(socket.AF_NETLINK, socket.SOCK_DGRAM, NETLINK_KOBJECT_UEVENT) | ||
self.__timeout = timeout | ||
|
||
def start(self): | ||
# print('start', self.__timeout) | ||
self.__socket.bind((os.getpid(), -1)) | ||
if 0 == self.__timeout: | ||
self.__socket.settimeout(None) | ||
else: | ||
self.__socket.settimeout(self.__timeout/1000.0) | ||
|
||
def stop(self): | ||
self.__socket.close() | ||
|
||
def __enter__(self): | ||
# print('__enter__', self) | ||
self.start() | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
# print('__exit__', self) | ||
self.stop() | ||
|
||
def __iter__(self): | ||
# print('__iter__', self) | ||
while True: | ||
for item in self.next_events(): | ||
yield item | ||
|
||
def next_events(self): | ||
try: | ||
data = self.__socket.recv(16384) | ||
event = {} | ||
for item in data.split(b'\x00'): | ||
if not item: | ||
# check if we have an event and if we already received it | ||
if event and 'SEQNUM' in event: | ||
event_seqnum = event['SEQNUM'] | ||
if event_seqnum in self.__recieved_events: | ||
pass | ||
else: | ||
# print("=", event_seqnum) | ||
self.__recieved_events[event_seqnum] = event | ||
length = len(self.__recieved_events) | ||
# print("=", length) | ||
if (length > 100): | ||
self.__recieved_events.popitem(last=False) | ||
yield event | ||
event = {} | ||
else: | ||
try: | ||
k, v = item.split(b'=', 1) | ||
event[k.decode('ascii')] = v.decode('ascii') | ||
# print("=",k,v) | ||
except ValueError: | ||
pass | ||
except Exception: | ||
yield {} | ||
|
||
class TransceiverEvent(object): | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def get_transceiver_change_event(self, timeout=0): | ||
port_dict = {} | ||
with NetlinkEventMonitor(timeout) as netlink_monitor: | ||
for event in netlink_monitor: | ||
if event and 'SUBSYSTEM' in event: | ||
if event['SUBSYSTEM'] == 'swps': | ||
#print('SWPS event. From %s, ACTION %s, IF_TYPE %s, IF_LANE %s' % (event['DEVPATH'], event['ACTION'], event['IF_TYPE'], event['IF_LANE'])) | ||
portname = event['DEVPATH'].split("/")[-1] | ||
rc = re.match(r"port(?P<num>\d+)",portname) | ||
if rc is not None: | ||
if event['ACTION'] == "remove": | ||
remove_num = int(rc.group("num")) | ||
port_dict[remove_num] = "0" | ||
elif event['ACTION'] == "add": | ||
add_num = int(rc.group("num")) | ||
port_dict[add_num] = "1" | ||
return True, port_dict | ||
else: | ||
return False, {} | ||
else: | ||
pass | ||
else: | ||
return True, {} | ||
|
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