Skip to content

Commit 4a859f3

Browse files
oleksandrivantsivKAVITHA RAMALINGAM
authored andcommitted
[Mellanox] Extend Nvidia Bluefield DPU chassis implementation (sonic-net#20620)
- Why I did it Implement the interface required to run DPU chassisd on the Nvidia Smart Switch. Implement get_dpu_id API that deducts the DPU ID based on the midplane interface IP address. - How I did it Implement platform API - How to verify it The implementation is covered by the UT.
1 parent dabd189 commit 4a859f3

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

device/nvidia-bluefield/arm64-nvda_bf-bf3comdpu/pmon_daemon_control.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"skip_ledd": true,
33
"skip_psud": true,
44
"skip_fancontrol": true,
5-
"skip_chassisd": true,
5+
"skip_chassisd": false,
66
"skip_ycabled": true
77
}

platform/nvidia-bluefield/platform-api/sonic_platform/chassis.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import os
2323
from functools import reduce
2424
from time import sleep
25+
import psutil
26+
import ipaddress
27+
import socket
2528

2629
from . import utils
2730
from .device_data import DeviceDataManager
@@ -53,8 +56,25 @@ def __init__(self):
5356
self.sfp_event = None
5457
self._eeprom = Eeprom()
5558
self._watchdog = Watchdog()
59+
5660
logger.log_info("Chassis loaded successfully")
5761

62+
def _get_dpu_id(self):
63+
ip = None
64+
midplane_inft = psutil.net_if_addrs().get('eth0-midplane', [])
65+
66+
for address in midplane_inft:
67+
if address.family == socket.AF_INET:
68+
ip = ipaddress.IPv4Address(address.address)
69+
break
70+
71+
if not ip:
72+
raise RuntimeError("Midplane interface IP address is not available")
73+
74+
last_byte = int(str(ip).split('.')[-1])
75+
76+
return last_byte - 1
77+
5878
def _initialize_sfp(self):
5979
self._sfp_list = []
6080

@@ -272,3 +292,36 @@ def get_reboot_cause(self):
272292
to pass a description of the reboot cause.
273293
"""
274294
return "N/A", "N/A"
295+
296+
##############################################
297+
# SmartSwitch methods
298+
##############################################
299+
300+
def get_dpu_id(self, **kwargs):
301+
"""
302+
For the smart switch DPU retrieves the ID of the DPU.
303+
Returns None for non-smartswitch chassis.
304+
305+
Returns:
306+
An integer, indicating the DPU ID Ex: name:DPU0 return value 0,
307+
name:DPU1 return value 1, name:DPUX return value X
308+
"""
309+
return self._get_dpu_id()
310+
311+
def is_smartswitch(self):
312+
"""
313+
Retrieves whether the sonic instance is part of smartswitch
314+
315+
Returns:
316+
Returns:True for SmartSwitch and False for other platforms
317+
"""
318+
return True
319+
320+
def is_dpu(self):
321+
"""
322+
Retrieves whether the SONiC instance runs on the DPU
323+
324+
Returns:
325+
True if the SONiC instance runs on the DPU else False
326+
"""
327+
return True

platform/nvidia-bluefield/platform-api/tests/test_chassis.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import os
1919
import sys
20+
import socket
21+
from collections import namedtuple
2022

2123
from unittest.mock import patch
2224
from unittest.mock import mock_open
@@ -83,3 +85,11 @@ def test_sfp(self, *args):
8385
assert len(sfp_list) == 2
8486
assert id(sfp1) == id(sfp_list[0])
8587
assert id(sfp2) == id(sfp_list[1])
88+
89+
90+
@patch('psutil.net_if_addrs', return_value={
91+
'eth0-midplane': [namedtuple('snicaddr', ['family', 'address'])(family=socket.AF_INET, address='169.254.200.1')]})
92+
def test_get_dpu_id(self, *args):
93+
chassis = Chassis()
94+
95+
assert chassis.get_dpu_id() == 0

0 commit comments

Comments
 (0)