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_inited = False
115
116
self ._RJ45_port_list = None
@@ -121,9 +122,8 @@ def __del__(self):
121
122
self .sfp_event .deinitialize ()
122
123
123
124
if self ._sfp_list :
124
- from .sfp import SFP , deinitialize_sdk_handle
125
- if SFP .shared_sdk_handle :
126
- deinitialize_sdk_handle (SFP .shared_sdk_handle )
125
+ if self .sfp_module .SFP .shared_sdk_handle :
126
+ self .sfp_module .deinitialize_sdk_handle (sfp_module .SFP .shared_sdk_handle )
127
127
128
128
@property
129
129
def RJ45_port_list (self ):
@@ -249,39 +249,45 @@ def get_fan_drawer(self, index):
249
249
# SFP methods
250
250
##############################################
251
251
252
+ def _import_sfp_module (self ):
253
+ if not self .sfp_module :
254
+ from . import sfp as sfp_module
255
+ self .sfp_module = sfp_module
256
+ return self .sfp_module
257
+
252
258
def initialize_single_sfp (self , index ):
253
259
sfp_count = self .get_num_sfps ()
254
260
if index < sfp_count :
255
261
if not self ._sfp_list :
256
262
self ._sfp_list = [None ] * sfp_count
257
263
258
264
if not self ._sfp_list [index ]:
259
- from . sfp import SFP
265
+ sfp_module = self . _import_sfp_module ()
260
266
if self .RJ45_port_list and index in self .RJ45_port_list :
261
- self ._sfp_list [index ] = RJ45Port (index )
267
+ self ._sfp_list [index ] = sfp_module . RJ45Port (index )
262
268
else :
263
- self ._sfp_list [index ] = SFP (index )
269
+ self ._sfp_list [index ] = sfp_module . SFP (index )
264
270
self .sfp_initialized_count += 1
265
271
266
272
def initialize_sfp (self ):
267
273
if not self ._sfp_list :
268
- from . sfp import SFP
274
+ sfp_module = self . _import_sfp_module ()
269
275
sfp_count = self .get_num_sfps ()
270
276
for index in range (sfp_count ):
271
277
if self .RJ45_port_list and index in self .RJ45_port_list :
272
- sfp_module = RJ45Port (index )
278
+ sfp_object = sfp_module . RJ45Port (index )
273
279
else :
274
- sfp_module = SFP (index )
275
- self ._sfp_list .append (sfp_module )
280
+ sfp_object = sfp_module . SFP (index )
281
+ self ._sfp_list .append (sfp_object )
276
282
self .sfp_initialized_count = sfp_count
277
283
elif self .sfp_initialized_count != len (self ._sfp_list ):
278
- from . sfp import SFP
284
+ sfp_module = self . _import_sfp_module ()
279
285
for index in range (len (self ._sfp_list )):
280
286
if self ._sfp_list [index ] is None :
281
287
if self .RJ45_port_list and index in self .RJ45_port_list :
282
- self ._sfp_list [index ] = RJ45Port (index )
288
+ self ._sfp_list [index ] = sfp_module . RJ45Port (index )
283
289
else :
284
- self ._sfp_list [index ] = SFP (index )
290
+ self ._sfp_list [index ] = sfp_module . SFP (index )
285
291
self .sfp_initialized_count = len (self ._sfp_list )
286
292
287
293
def get_num_sfps (self ):
@@ -321,6 +327,30 @@ def get_sfp(self, index):
321
327
self .initialize_single_sfp (index )
322
328
return super (Chassis , self ).get_sfp (index )
323
329
330
+ def get_port_or_cage_type (self , index ):
331
+ """
332
+ Retrieves sfp port or cage type corresponding to physical port <index>
333
+
334
+ Args:
335
+ index: An integer (>=0), the index of the sfp to retrieve.
336
+ The index should correspond to the physical port in a chassis.
337
+ For example:-
338
+ 1 for Ethernet0, 2 for Ethernet4 and so on for one platform.
339
+ 0 for Ethernet0, 1 for Ethernet4 and so on for another platform.
340
+
341
+ Returns:
342
+ The masks of all types of port or cage that can be supported on the port
343
+ Types are defined in sfp_base.py
344
+ Eg.
345
+ Both SFP and SFP+ are supported on the port, the return value should be 0x0a
346
+ which is 0x02 | 0x08
347
+ """
348
+ index = index - 1
349
+ if self .RJ45_port_list and index in self .RJ45_port_list :
350
+ from sonic_platform_base .sfp_base import SfpBase
351
+ return SfpBase .SFP_PORT_TYPE_BIT_RJ45
352
+ raise NotImplementedError
353
+
324
354
def get_change_event (self , timeout = 0 ):
325
355
"""
326
356
Returns a nested dictionary containing all devices which have
0 commit comments