Skip to content

Commit

Permalink
[mlnx-sfp-plugin] enhancement to support transceiver sensor monitoring (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
keboliu authored and lguohan committed Aug 2, 2018
1 parent 8e74230 commit a215bcd
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 12 deletions.
43 changes: 41 additions & 2 deletions device/mellanox/x86_64-mlnx_lssn2700-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
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
Expand All @@ -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
Expand All @@ -39,7 +48,7 @@ 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/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)
Expand Down Expand Up @@ -149,3 +158,33 @@ def reset(self, port_num):
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

43 changes: 41 additions & 2 deletions device/mellanox/x86_64-mlnx_msn2100-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
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
Expand All @@ -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
Expand All @@ -39,7 +48,7 @@ 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/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)
Expand Down Expand Up @@ -149,3 +158,33 @@ def reset(self, port_num):
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

48 changes: 44 additions & 4 deletions device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,27 @@
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
Expand All @@ -32,20 +41,21 @@ def port_end(self):

@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:
Expand Down Expand Up @@ -149,3 +159,33 @@ def reset(self, port_num):
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

43 changes: 41 additions & 2 deletions device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
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
Expand All @@ -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
Expand All @@ -39,7 +48,7 @@ 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/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)
Expand Down Expand Up @@ -149,3 +158,33 @@ def reset(self, port_num):
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

43 changes: 41 additions & 2 deletions device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
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
Expand All @@ -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
Expand All @@ -39,7 +48,7 @@ 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)
Expand Down Expand Up @@ -149,3 +158,33 @@ def reset(self, port_num):
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

0 comments on commit a215bcd

Please sign in to comment.