5
5
6
6
try :
7
7
import time
8
+ import datetime
8
9
from sonic_sfp .sfputilbase import SfpUtilBase
9
10
except ImportError as e :
10
11
raise ImportError ("%s - required module not found" % str (e ))
@@ -20,6 +21,7 @@ class SfpUtil(SfpUtilBase):
20
21
EEPROM_OFFSET = 20
21
22
22
23
_port_to_eeprom_mapping = {}
24
+ port_dict = {}
23
25
24
26
@property
25
27
def port_start (self ):
@@ -37,12 +39,33 @@ def qsfp_ports(self):
37
39
def port_to_eeprom_mapping (self ):
38
40
return self ._port_to_eeprom_mapping
39
41
42
+ @property
43
+ def get_transceiver_status (self ):
44
+
45
+ try :
46
+ reg_file = open ("/sys/devices/platform/dell-s6000-cpld.0/qsfp_modprs" )
47
+
48
+ except IOError as e :
49
+ print "Error: unable to open file: %s" % str (e )
50
+ return False
51
+
52
+ content = reg_file .readline ().rstrip ()
53
+
54
+ reg_file .close ()
55
+
56
+ return int (content , 16 )
57
+
58
+
40
59
def __init__ (self ):
60
+
41
61
eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom"
42
62
43
63
for x in range (0 , self .port_end + 1 ):
44
64
self ._port_to_eeprom_mapping [x ] = eeprom_path .format (x + self .EEPROM_OFFSET )
45
65
66
+ # Get Transceiver status
67
+ self .modprs_register = self .get_transceiver_status
68
+
46
69
SfpUtilBase .__init__ (self )
47
70
48
71
def get_presence (self , port_num ):
@@ -174,10 +197,60 @@ def reset(self, port_num):
174
197
175
198
return True
176
199
177
- def get_transceiver_change_event (self ):
178
- """
179
- TODO: This function need to be implemented
180
- when decide to support monitoring SFP(Xcvrd)
181
- on this platform.
182
- """
183
- raise NotImplementedError
200
+ def get_transceiver_change_event (self , timeout = 0 ):
201
+
202
+ start_time = time .time ()
203
+ port_dict = {}
204
+ port = self .port_start
205
+ forever = False
206
+
207
+ if timeout == 0 :
208
+ forever = True
209
+ elif timeout > 0 :
210
+ timeout = timeout / float (1000 ) # Convert to secs
211
+ else :
212
+ print "get_transceiver_change_event:Invalid timeout value" , timeout
213
+ return False , {}
214
+
215
+ end_time = start_time + timeout
216
+ if start_time > end_time :
217
+ print 'get_transceiver_change_event:' \
218
+ 'time wrap / invalid timeout value' , timeout
219
+
220
+ return False , {} # Time wrap or possibly incorrect timeout
221
+
222
+ while timeout >= 0 :
223
+ # Check for OIR events and return updated port_dict
224
+ reg_value = self .get_transceiver_status
225
+ if reg_value != self .modprs_register :
226
+ changed_ports = self .modprs_register ^ reg_value
227
+ while port >= self .port_start and port <= self .port_end :
228
+
229
+ # Mask off the bit corresponding to our port
230
+ mask = (1 << port )
231
+
232
+ if changed_ports & mask :
233
+ # ModPrsL is active low
234
+ if reg_value & mask == 0 :
235
+ port_dict [port ] = '1'
236
+ else :
237
+ port_dict [port ] = '0'
238
+
239
+ port += 1
240
+
241
+ # Update reg value
242
+ self .modprs_register = reg_value
243
+ return True , port_dict
244
+
245
+ if forever :
246
+ time .sleep (1 )
247
+ else :
248
+ timeout = end_time - time .time ()
249
+ if timeout >= 1 :
250
+ time .sleep (1 ) # We poll at 1 second granularity
251
+ else :
252
+ if timeout > 0 :
253
+ time .sleep (timeout )
254
+ return True , {}
255
+ print "get_transceiver_change_event: Should not reach here."
256
+ return False , {}
0 commit comments