Skip to content

Commit c57f727

Browse files
authored
[Mellanox][Smartswitch] Platform API for Smartswtich (sonic-net#20944)
[Mellanox][Smartswitch] Platform API for Smartswtich
1 parent 8dbec05 commit c57f727

File tree

6 files changed

+772
-18
lines changed

6 files changed

+772
-18
lines changed

platform/mellanox/mlnx-platform-api/sonic_platform/chassis.py

+152
Original file line numberDiff line numberDiff line change
@@ -1198,3 +1198,155 @@ def get_sfp(self, index):
11981198
return None
11991199

12001200
return module.get_sfp(sfp_index - 1)
1201+
1202+
class SmartSwitchChassis(Chassis):
1203+
def __init__(self):
1204+
super(SmartSwitchChassis, self).__init__()
1205+
self.module_initialized_count = 0
1206+
self.module_name_index_map = {}
1207+
self.initialize_modules()
1208+
1209+
def is_modular_chassis(self):
1210+
"""
1211+
Retrieves whether the sonic instance is part of modular chassis
1212+
1213+
Returns:
1214+
A bool value, should return False by default or for fixed-platforms.
1215+
Should return True for supervisor-cards, line-cards etc running as part
1216+
of modular-chassis.
1217+
For SmartSwitch platforms this should return True even if they are
1218+
fixed-platforms, as they are treated like a modular chassis as the
1219+
DPU cards are treated like line-cards of a modular-chassis.
1220+
"""
1221+
return False
1222+
1223+
##############################################
1224+
# Module methods
1225+
##############################################
1226+
def initialize_single_module(self, index):
1227+
count = self.get_num_modules()
1228+
if index < 0:
1229+
raise RuntimeError(f"Invalid index = {index} for module initialization with total module count = {count}")
1230+
if index >= count:
1231+
return
1232+
if not self._module_list:
1233+
self._module_list = [None] * count
1234+
if not self._module_list[index]:
1235+
from .module import DpuModule
1236+
module = DpuModule(index)
1237+
self._module_list[index] = module
1238+
self.module_name_index_map[module.get_name()] = index
1239+
self.module_initialized_count += 1
1240+
1241+
def initialize_modules(self):
1242+
count = self.get_num_modules()
1243+
for index in range(count):
1244+
self.initialize_single_module(index=index)
1245+
1246+
def get_num_modules(self):
1247+
"""
1248+
Retrieves the number of modules available on this chassis
1249+
On a SmarSwitch chassis this includes the number of DPUs.
1250+
1251+
Returns:
1252+
An integer, the number of modules available on this chassis
1253+
"""
1254+
return DeviceDataManager.get_dpu_count()
1255+
1256+
def get_all_modules(self):
1257+
"""
1258+
Retrieves all modules available on this chassis. On a SmarSwitch
1259+
chassis this includes the number of DPUs.
1260+
1261+
Returns:
1262+
A list of objects derived from ModuleBase representing all
1263+
modules available on this chassis
1264+
"""
1265+
self.initialize_modules()
1266+
return self._module_list
1267+
1268+
def get_module(self, index):
1269+
"""
1270+
Retrieves module represented by (0-based) index <index>
1271+
On a SmartSwitch index:0 will fetch switch, index:1 will fetch
1272+
DPU0 and so on
1273+
1274+
Args:
1275+
index: An integer, the index (0-based) of the module to
1276+
retrieve
1277+
1278+
Returns:
1279+
An object dervied from ModuleBase representing the specified
1280+
module
1281+
"""
1282+
self.initialize_single_module(index)
1283+
return super(SmartSwitchChassis, self).get_module(index)
1284+
1285+
def get_module_index(self, module_name):
1286+
"""
1287+
Retrieves module index from the module name
1288+
1289+
Args:
1290+
module_name: A string, prefixed by SUPERVISOR, LINE-CARD or FABRIC-CARD
1291+
Ex. SUPERVISOR0, LINE-CARD1, FABRIC-CARD5
1292+
SmartSwitch Example: SWITCH, DPU1, DPU2 ... DPUX
1293+
1294+
Returns:
1295+
An integer, the index of the ModuleBase object in the module_list
1296+
"""
1297+
return self.module_name_index_map[module_name.upper()]
1298+
1299+
##############################################
1300+
# SmartSwitch methods
1301+
##############################################
1302+
1303+
def get_dpu_id(self, name):
1304+
"""
1305+
Retrieves the DPU ID for the given dpu-module name.
1306+
Returns None for non-smartswitch chassis.
1307+
Returns:
1308+
An integer, indicating the DPU ID Ex: name:DPU0 return value 1,
1309+
name:DPU1 return value 2, name:DPUX return value X+1
1310+
"""
1311+
module = self.get_module(self.get_module_index(name))
1312+
return module.get_dpu_id()
1313+
1314+
def is_smartswitch(self):
1315+
"""
1316+
Retrieves whether the sonic instance is part of smartswitch
1317+
Returns:
1318+
Returns:True for SmartSwitch and False for other platforms
1319+
"""
1320+
return True
1321+
1322+
def init_midplane_switch(self):
1323+
"""
1324+
Initializes the midplane functionality of the modular chassis. For
1325+
example, any validation of midplane, populating any lookup tables etc
1326+
can be done here. The expectation is that the required kernel modules,
1327+
ip-address assignment etc are done before the pmon, database dockers
1328+
are up.
1329+
1330+
Returns:
1331+
A bool value, should return True if the midplane initialized
1332+
successfully.
1333+
"""
1334+
return True
1335+
1336+
def get_module_dpu_data_port(self, index):
1337+
"""
1338+
Retrieves the DPU data port NPU-DPU association represented for
1339+
the DPU index. Platforms that need to overwrite the platform.json
1340+
file will use this API. This is valid only on the Switch and not on DPUs
1341+
Args:
1342+
index: An integer, the index of the module to retrieve
1343+
Returns:
1344+
A string giving the NPU-DPU port association:
1345+
Ex: For index: 1 will return the dup0 port association which is
1346+
"Ethernet-BP0: Ethernet0" where the string left of ":" (Ethernet-BP0)
1347+
is the NPU port and the string right of ":" (Ethernet0) is the DPU port
1348+
"""
1349+
platform_dpus_data = DeviceDataManager.get_platform_dpus_data()
1350+
module = self._module_list[index]
1351+
module_name = module.get_name()
1352+
return platform_dpus_data[module_name.lower()]["interface"]

0 commit comments

Comments
 (0)