Skip to content

Commit a215bcd

Browse files
keboliulguohan
authored andcommitted
[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 [email protected] * remove commented code * revise the get_transceiver_change_event implementation and remove unused function * remove blank
1 parent 8e74230 commit a215bcd

File tree

5 files changed

+208
-12
lines changed

5 files changed

+208
-12
lines changed

device/mellanox/x86_64-mlnx_lssn2700-r0/plugins/sfputil.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
except ImportError as e:
1111
raise ImportError("%s - required module not found" % str(e))
1212

13+
# parameters for DB connection
14+
REDIS_HOSTNAME = "localhost"
15+
REDIS_PORT = 6379
16+
REDIS_TIMEOUT_USECS = 0
1317

1418
class SfpUtil(SfpUtilBase):
1519
"""Platform-specific SfpUtil class"""
16-
1720
PORT_START = 0
1821
PORT_END = 31
1922
PORTS_IN_BLOCK = 32
@@ -22,6 +25,12 @@ class SfpUtil(SfpUtilBase):
2225

2326
_port_to_eeprom_mapping = {}
2427

28+
db_sel = None
29+
db_sel_timeout = None
30+
db_sel_object = None
31+
db_sel_tbl = None
32+
state_db = None
33+
2534
@property
2635
def port_start(self):
2736
return self.PORT_START
@@ -39,7 +48,7 @@ def port_to_eeprom_mapping(self):
3948
return self._port_to_eeprom_mapping
4049

4150
def __init__(self):
42-
eeprom_path = "/bsp/qsfp/qsfp{0}"
51+
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon7/qsfp{0}_eeprom"
4352

4453
for x in range(0, self.port_end + 1):
4554
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
@@ -149,3 +158,33 @@ def reset(self, port_num):
149158
return False
150159

151160
return False
161+
162+
def get_transceiver_change_event(self, timeout=0):
163+
phy_port_dict = {}
164+
status = True
165+
166+
if self.db_sel == None:
167+
from swsscommon import swsscommon
168+
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
169+
REDIS_HOSTNAME,
170+
REDIS_PORT,
171+
REDIS_TIMEOUT_USECS)
172+
173+
# Subscribe to state table for SFP change notifications
174+
self.db_sel = swsscommon.Select()
175+
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
176+
self.db_sel.addSelectable(self.db_sel_tbl)
177+
self.db_sel_timeout = swsscommon.Select.TIMEOUT
178+
self.db_sel_object = swsscommon.Select.OBJECT
179+
180+
(state, c) = self.db_sel.select(timeout)
181+
if state == self.db_sel_timeout:
182+
status = True
183+
elif state != self.db_sel_object:
184+
status = False
185+
else:
186+
(key, op, fvp) = self.db_sel_tbl.pop()
187+
phy_port_dict[key] = op
188+
189+
return status, phy_port_dict
190+

device/mellanox/x86_64-mlnx_msn2100-r0/plugins/sfputil.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
except ImportError as e:
1111
raise ImportError("%s - required module not found" % str(e))
1212

13+
# parameters for DB connection
14+
REDIS_HOSTNAME = "localhost"
15+
REDIS_PORT = 6379
16+
REDIS_TIMEOUT_USECS = 0
1317

1418
class SfpUtil(SfpUtilBase):
1519
"""Platform-specific SfpUtil class"""
16-
1720
PORT_START = 0
1821
PORT_END = 15
1922
PORTS_IN_BLOCK = 16
@@ -22,6 +25,12 @@ class SfpUtil(SfpUtilBase):
2225

2326
_port_to_eeprom_mapping = {}
2427

28+
db_sel = None
29+
db_sel_timeout = None
30+
db_sel_object = None
31+
db_sel_tbl = None
32+
state_db = None
33+
2534
@property
2635
def port_start(self):
2736
return self.PORT_START
@@ -39,7 +48,7 @@ def port_to_eeprom_mapping(self):
3948
return self._port_to_eeprom_mapping
4049

4150
def __init__(self):
42-
eeprom_path = "/bsp/qsfp/qsfp{0}"
51+
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon4/qsfp{0}_eeprom"
4352

4453
for x in range(0, self.port_end + 1):
4554
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
@@ -149,3 +158,33 @@ def reset(self, port_num):
149158
return False
150159

151160
return False
161+
162+
def get_transceiver_change_event(self, timeout=0):
163+
phy_port_dict = {}
164+
status = True
165+
166+
if self.db_sel == None:
167+
from swsscommon import swsscommon
168+
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
169+
REDIS_HOSTNAME,
170+
REDIS_PORT,
171+
REDIS_TIMEOUT_USECS)
172+
173+
# Subscribe to state table for SFP change notifications
174+
self.db_sel = swsscommon.Select()
175+
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
176+
self.db_sel.addSelectable(self.db_sel_tbl)
177+
self.db_sel_timeout = swsscommon.Select.TIMEOUT
178+
self.db_sel_object = swsscommon.Select.OBJECT
179+
180+
(state, c) = self.db_sel.select(timeout)
181+
if state == self.db_sel_timeout:
182+
status = True
183+
elif state != self.db_sel_object:
184+
status = False
185+
else:
186+
(key, op, fvp) = self.db_sel_tbl.pop()
187+
phy_port_dict[key] = op
188+
189+
return status, phy_port_dict
190+

device/mellanox/x86_64-mlnx_msn2410-r0/plugins/sfputil.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@
1010
except ImportError as e:
1111
raise ImportError("%s - required module not found" % str(e))
1212

13+
# parameters for DB connection
14+
REDIS_HOSTNAME = "localhost"
15+
REDIS_PORT = 6379
16+
REDIS_TIMEOUT_USECS = 0
1317

1418
class SfpUtil(SfpUtilBase):
1519
"""Platform-specific SfpUtil class"""
16-
1720
PORT_START = 0
1821
PORT_END = 55
1922
PORTS_IN_BLOCK = 56
20-
23+
QSFP_PORT_START = 48
2124
EEPROM_OFFSET = 1
2225

2326
_port_to_eeprom_mapping = {}
2427

28+
db_sel = None
29+
db_sel_timeout = None
30+
db_sel_object = None
31+
db_sel_tbl = None
32+
state_db = None
33+
2534
@property
2635
def port_start(self):
2736
return self.PORT_START
@@ -32,20 +41,21 @@ def port_end(self):
3241

3342
@property
3443
def qsfp_ports(self):
35-
return range(0, self.PORTS_IN_BLOCK + 1)
44+
return range(self.QSFP_PORT_START, self.PORTS_IN_BLOCK + 1)
3645

3746
@property
3847
def port_to_eeprom_mapping(self):
3948
return self._port_to_eeprom_mapping
4049

4150
def __init__(self):
42-
eeprom_path = "/bsp/qsfp/qsfp{0}"
51+
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon6/qsfp{0}_eeprom"
4352

4453
for x in range(0, self.port_end + 1):
4554
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
4655

4756
SfpUtilBase.__init__(self)
4857

58+
4959
def get_presence(self, port_num):
5060
# Check for invalid port_num
5161
if port_num < self.port_start or port_num > self.port_end:
@@ -149,3 +159,33 @@ def reset(self, port_num):
149159
return False
150160

151161
return False
162+
163+
def get_transceiver_change_event(self, timeout=0):
164+
phy_port_dict = {}
165+
status = True
166+
167+
if self.db_sel == None:
168+
from swsscommon import swsscommon
169+
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
170+
REDIS_HOSTNAME,
171+
REDIS_PORT,
172+
REDIS_TIMEOUT_USECS)
173+
174+
# Subscribe to state table for SFP change notifications
175+
self.db_sel = swsscommon.Select()
176+
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
177+
self.db_sel.addSelectable(self.db_sel_tbl)
178+
self.db_sel_timeout = swsscommon.Select.TIMEOUT
179+
self.db_sel_object = swsscommon.Select.OBJECT
180+
181+
(state, c) = self.db_sel.select(timeout)
182+
if state == self.db_sel_timeout:
183+
status = True
184+
elif state != self.db_sel_object:
185+
status = False
186+
else:
187+
(key, op, fvp) = self.db_sel_tbl.pop()
188+
phy_port_dict[key] = op
189+
190+
return status, phy_port_dict
191+

device/mellanox/x86_64-mlnx_msn2700-r0/plugins/sfputil.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
except ImportError as e:
1111
raise ImportError("%s - required module not found" % str(e))
1212

13+
# parameters for DB connection
14+
REDIS_HOSTNAME = "localhost"
15+
REDIS_PORT = 6379
16+
REDIS_TIMEOUT_USECS = 0
1317

1418
class SfpUtil(SfpUtilBase):
1519
"""Platform-specific SfpUtil class"""
16-
1720
PORT_START = 0
1821
PORT_END = 31
1922
PORTS_IN_BLOCK = 32
@@ -22,6 +25,12 @@ class SfpUtil(SfpUtilBase):
2225

2326
_port_to_eeprom_mapping = {}
2427

28+
db_sel = None
29+
db_sel_timeout = None
30+
db_sel_object = None
31+
db_sel_tbl = None
32+
state_db = None
33+
2534
@property
2635
def port_start(self):
2736
return self.PORT_START
@@ -39,7 +48,7 @@ def port_to_eeprom_mapping(self):
3948
return self._port_to_eeprom_mapping
4049

4150
def __init__(self):
42-
eeprom_path = "/bsp/qsfp/qsfp{0}"
51+
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon7/qsfp{0}_eeprom"
4352

4453
for x in range(0, self.port_end + 1):
4554
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
@@ -149,3 +158,33 @@ def reset(self, port_num):
149158
return False
150159

151160
return False
161+
162+
def get_transceiver_change_event(self, timeout=0):
163+
phy_port_dict = {}
164+
status = True
165+
166+
if self.db_sel == None:
167+
from swsscommon import swsscommon
168+
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
169+
REDIS_HOSTNAME,
170+
REDIS_PORT,
171+
REDIS_TIMEOUT_USECS)
172+
173+
# Subscribe to state table for SFP change notifications
174+
self.db_sel = swsscommon.Select()
175+
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
176+
self.db_sel.addSelectable(self.db_sel_tbl)
177+
self.db_sel_timeout = swsscommon.Select.TIMEOUT
178+
self.db_sel_object = swsscommon.Select.OBJECT
179+
180+
(state, c) = self.db_sel.select(timeout)
181+
if state == self.db_sel_timeout:
182+
status = True
183+
elif state != self.db_sel_object:
184+
status = False
185+
else:
186+
(key, op, fvp) = self.db_sel_tbl.pop()
187+
phy_port_dict[key] = op
188+
189+
return status, phy_port_dict
190+

device/mellanox/x86_64-mlnx_msn2740-r0/plugins/sfputil.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@
1010
except ImportError as e:
1111
raise ImportError("%s - required module not found" % str(e))
1212

13+
# parameters for DB connection
14+
REDIS_HOSTNAME = "localhost"
15+
REDIS_PORT = 6379
16+
REDIS_TIMEOUT_USECS = 0
1317

1418
class SfpUtil(SfpUtilBase):
1519
"""Platform-specific SfpUtil class"""
16-
1720
PORT_START = 0
1821
PORT_END = 31
1922
PORTS_IN_BLOCK = 32
@@ -22,6 +25,12 @@ class SfpUtil(SfpUtilBase):
2225

2326
_port_to_eeprom_mapping = {}
2427

28+
db_sel = None
29+
db_sel_timeout = None
30+
db_sel_object = None
31+
db_sel_tbl = None
32+
state_db = None
33+
2534
@property
2635
def port_start(self):
2736
return self.PORT_START
@@ -39,7 +48,7 @@ def port_to_eeprom_mapping(self):
3948
return self._port_to_eeprom_mapping
4049

4150
def __init__(self):
42-
eeprom_path = "/bsp/qsfp/qsfp{0}"
51+
eeprom_path = "/sys/class/i2c-adapter/i2c-2/2-0048/hwmon/hwmon6/qsfp{0}_eeprom"
4352

4453
for x in range(0, self.port_end + 1):
4554
self._port_to_eeprom_mapping[x] = eeprom_path.format(x + self.EEPROM_OFFSET)
@@ -149,3 +158,33 @@ def reset(self, port_num):
149158
return False
150159

151160
return False
161+
162+
def get_transceiver_change_event(self, timeout=0):
163+
phy_port_dict = {}
164+
status = True
165+
166+
if self.db_sel == None:
167+
from swsscommon import swsscommon
168+
self.state_db = swsscommon.DBConnector(swsscommon.STATE_DB,
169+
REDIS_HOSTNAME,
170+
REDIS_PORT,
171+
REDIS_TIMEOUT_USECS)
172+
173+
# Subscribe to state table for SFP change notifications
174+
self.db_sel = swsscommon.Select()
175+
self.db_sel_tbl = swsscommon.NotificationConsumer(self.state_db, 'TRANSCEIVER_NOTIFY')
176+
self.db_sel.addSelectable(self.db_sel_tbl)
177+
self.db_sel_timeout = swsscommon.Select.TIMEOUT
178+
self.db_sel_object = swsscommon.Select.OBJECT
179+
180+
(state, c) = self.db_sel.select(timeout)
181+
if state == self.db_sel_timeout:
182+
status = True
183+
elif state != self.db_sel_object:
184+
status = False
185+
else:
186+
(key, op, fvp) = self.db_sel_tbl.pop()
187+
phy_port_dict[key] = op
188+
189+
return status, phy_port_dict
190+

0 commit comments

Comments
 (0)