30
30
from .utils import extract_RJ45_ports_index
31
31
from . import utils
32
32
from .device_data import DeviceDataManager
33
- from .sfp import SFP , RJ45Port , deinitialize_sdk_handle
34
33
except ImportError as e :
35
34
raise ImportError (str (e ) + "- required module not found" )
36
35
@@ -110,6 +109,8 @@ def __init__(self):
110
109
self .sfp_event = None
111
110
self .reboot_cause_initialized = False
112
111
112
+ self .sfp_module = None
113
+
113
114
# Build the RJ45 port list from platform.json and hwsku.json
114
115
self .RJ45_port_list = extract_RJ45_ports_index ()
115
116
@@ -120,9 +121,8 @@ def __del__(self):
120
121
self .sfp_event .deinitialize ()
121
122
122
123
if self ._sfp_list :
123
- from .sfp import SFP , deinitialize_sdk_handle
124
- if SFP .shared_sdk_handle :
125
- deinitialize_sdk_handle (SFP .shared_sdk_handle )
124
+ if self .sfp_module .SFP .shared_sdk_handle :
125
+ self .sfp_module .deinitialize_sdk_handle (sfp_module .SFP .shared_sdk_handle )
126
126
127
127
##############################################
128
128
# PSU methods
@@ -241,39 +241,45 @@ def get_fan_drawer(self, index):
241
241
# SFP methods
242
242
##############################################
243
243
244
+ def _import_sfp_module (self ):
245
+ if not self .sfp_module :
246
+ from . import sfp as sfp_module
247
+ self .sfp_module = sfp_module
248
+ return self .sfp_module
249
+
244
250
def initialize_single_sfp (self , index ):
245
251
sfp_count = self .get_num_sfps ()
246
252
if index < sfp_count :
247
253
if not self ._sfp_list :
248
254
self ._sfp_list = [None ] * sfp_count
249
255
250
256
if not self ._sfp_list [index ]:
251
- from . sfp import SFP
257
+ sfp_module = self . _import_sfp_module ()
252
258
if self .RJ45_port_list and index in self .RJ45_port_list :
253
- self ._sfp_list [index ] = RJ45Port (index )
259
+ self ._sfp_list [index ] = sfp_module . RJ45Port (index )
254
260
else :
255
- self ._sfp_list [index ] = SFP (index )
261
+ self ._sfp_list [index ] = sfp_module . SFP (index )
256
262
self .sfp_initialized_count += 1
257
263
258
264
def initialize_sfp (self ):
259
265
if not self ._sfp_list :
260
- from . sfp import SFP
266
+ sfp_module = self . _import_sfp_module ()
261
267
sfp_count = self .get_num_sfps ()
262
268
for index in range (sfp_count ):
263
269
if self .RJ45_port_list and index in self .RJ45_port_list :
264
- sfp_module = RJ45Port (index )
270
+ sfp_object = sfp_module . RJ45Port (index )
265
271
else :
266
- sfp_module = SFP (index )
267
- self ._sfp_list .append (sfp_module )
272
+ sfp_object = sfp_module . SFP (index )
273
+ self ._sfp_list .append (sfp_object )
268
274
self .sfp_initialized_count = sfp_count
269
275
elif self .sfp_initialized_count != len (self ._sfp_list ):
270
- from . sfp import SFP
276
+ sfp_module = self . _import_sfp_module ()
271
277
for index in range (len (self ._sfp_list )):
272
278
if self ._sfp_list [index ] is None :
273
279
if self .RJ45_port_list and index in self .RJ45_port_list :
274
- self ._sfp_list [index ] = RJ45Port (index )
280
+ self ._sfp_list [index ] = sfp_module . RJ45Port (index )
275
281
else :
276
- self ._sfp_list [index ] = SFP (index )
282
+ self ._sfp_list [index ] = sfp_module . SFP (index )
277
283
self .sfp_initialized_count = len (self ._sfp_list )
278
284
279
285
def get_num_sfps (self ):
@@ -313,6 +319,30 @@ def get_sfp(self, index):
313
319
self .initialize_single_sfp (index )
314
320
return super (Chassis , self ).get_sfp (index )
315
321
322
+ def get_port_or_cage_type (self , index ):
323
+ """
324
+ Retrieves sfp port or cage type corresponding to physical port <index>
325
+
326
+ Args:
327
+ index: An integer (>=0), the index of the sfp to retrieve.
328
+ The index should correspond to the physical port in a chassis.
329
+ For example:-
330
+ 1 for Ethernet0, 2 for Ethernet4 and so on for one platform.
331
+ 0 for Ethernet0, 1 for Ethernet4 and so on for another platform.
332
+
333
+ Returns:
334
+ The masks of all types of port or cage that can be supported on the port
335
+ Types are defined in sfp_base.py
336
+ Eg.
337
+ Both SFP and SFP+ are supported on the port, the return value should be 0x0a
338
+ which is 0x02 | 0x08
339
+ """
340
+ index = index - 1
341
+ if self .RJ45_port_list and index in self .RJ45_port_list :
342
+ from sonic_platform_base .sfp_base import SfpBase
343
+ return SfpBase .SFP_PORT_TYPE_BIT_RJ45
344
+ raise NotImplementedError
345
+
316
346
def get_change_event (self , timeout = 0 ):
317
347
"""
318
348
Returns a nested dictionary containing all devices which have
0 commit comments