[mlnx-sfp-plugin] enhancement to support transceiver sensor monitoring (#1839)

* [mlnx-sfpplugin] enhancement to support tranceiver sensor monitoring

* Modify the eeprom folder to make it accessably from pmon container
* implement the get_transceiver_change_event API

file change list

	modified:   device/mellanox/x86_64-mlnx_lssn2700-r0/plugins/sfputil.py
	modified:   device/mellanox/x86_64-mlnx_msn2100-r0/plugins/sfputil.py
	modified:   device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py
	modified:   device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py
	modified:   device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py

signed-off-by Liu Kebo kebol@mellanox.com

* remove commented code

* revise the get_transceiver_change_event implementation and remove unused function

* remove blank
This commit is contained in:
Kebo Liu 2018-08-03 07:53:30 +08:00 committed by lguohan
parent 8e74230e86
commit a215bcd8f1
5 changed files with 208 additions and 12 deletions

View File

@ -10,10 +10,13 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 31
PORTS_IN_BLOCK = 32
@ -22,6 +25,12 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
@property
def port_start(self):
return self.PORT_START
@ -39,7 +48,7 @@ class SfpUtil(SfpUtilBase):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/bsp/qsfp/qsfp{0}"
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon7/qsfp{0}_eeprom"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
@ -149,3 +158,33 @@ class SfpUtil(SfpUtilBase):
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
self.db_sel_object = swsscommon.Select.OBJECT
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict

View File

@ -10,10 +10,13 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 15
PORTS_IN_BLOCK = 16
@ -22,6 +25,12 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
@property
def port_start(self):
return self.PORT_START
@ -39,7 +48,7 @@ class SfpUtil(SfpUtilBase):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/bsp/qsfp/qsfp{0}"
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon4/qsfp{0}_eeprom"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
@ -149,3 +158,33 @@ class SfpUtil(SfpUtilBase):
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
self.db_sel_object = swsscommon.Select.OBJECT
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict

View File

@ -10,18 +10,27 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 55
PORTS_IN_BLOCK = 56
QSFP_PORT_START = 48
EEPROM_OFFSET = 1
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
@property
def port_start(self):
return self.PORT_START
@ -32,20 +41,21 @@ class SfpUtil(SfpUtilBase):
@property
def qsfp_ports(self):
return range(0, self.PORTS_IN_BLOCK + 1)
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
@property
def port_to_eeprom_mapping(self):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/bsp/qsfp/qsfp{0}"
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon6/qsfp{0}_eeprom"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
SfpUtilBase.__init__(self)
def get_presence(self, port_num):
# Check for invalid port_num
if port_num < self.port_start or port_num > self.port_end:
@ -149,3 +159,33 @@ class SfpUtil(SfpUtilBase):
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
self.db_sel_object = swsscommon.Select.OBJECT
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict

View File

@ -10,10 +10,13 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 31
PORTS_IN_BLOCK = 32
@ -22,6 +25,12 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
@property
def port_start(self):
return self.PORT_START
@ -39,7 +48,7 @@ class SfpUtil(SfpUtilBase):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/bsp/qsfp/qsfp{0}"
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon7/qsfp{0}_eeprom"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
@ -149,3 +158,33 @@ class SfpUtil(SfpUtilBase):
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
self.db_sel_object = swsscommon.Select.OBJECT
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict

View File

@ -10,10 +10,13 @@ try:
except ImportError as e:
raise ImportError("%s - required module not found" % str(e))
# parameters for DB connection
REDIS_HOSTNAME = "localhost"
REDIS_PORT = 6379
REDIS_TIMEOUT_USECS = 0
class SfpUtil(SfpUtilBase):
"""Platform-specific SfpUtil class"""
PORT_START = 0
PORT_END = 31
PORTS_IN_BLOCK = 32
@ -22,6 +25,12 @@ class SfpUtil(SfpUtilBase):
_port_to_eeprom_mapping = {}
db_sel = None
db_sel_timeout = None
db_sel_object = None
db_sel_tbl = None
state_db = None
@property
def port_start(self):
return self.PORT_START
@ -39,7 +48,7 @@ class SfpUtil(SfpUtilBase):
return self._port_to_eeprom_mapping
def __init__(self):
eeprom_path = "/bsp/qsfp/qsfp{0}"
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon6/qsfp{0}_eeprom"
for x in range(0, self.port_end + 1):
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
@ -149,3 +158,33 @@ class SfpUtil(SfpUtilBase):
return False
return False
def get_transceiver_change_event(self, timeout=0):
phy_port_dict = {}
status = True
if self.db_sel == None:
from swsscommon import swsscommon
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
REDIS_HOSTNAME,
REDIS_PORT,
REDIS_TIMEOUT_USECS)
# Subscribe to state table for SFP change notifications
self.db_sel = swsscommon.Select()
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
self.db_sel.addSelectable(self.db_sel_tbl)
self.db_sel_timeout = swsscommon.Select.TIMEOUT
self.db_sel_object = swsscommon.Select.OBJECT
(state, c) = self.db_sel.select(timeout)
if state == self.db_sel_timeout:
status = True
elif state != self.db_sel_object:
status = False
else:
(key, op, fvp) = self.db_sel_tbl.pop()
phy_port_dict[key] = op
return status, phy_port_dict