Skip to content

Commit

Permalink
[SmartSwitch] Add a new API for the DPU chassis to query dataplane an…
Browse files Browse the repository at this point in the history
…d midplane states
  • Loading branch information
oleksandrivantsiv committed Oct 22, 2024
1 parent f07a6aa commit 94a1b5e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
52 changes: 45 additions & 7 deletions sonic_platform_base/chassis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,64 @@ def get_module_index(self, module_name):
# SmartSwitch methods
##############################################

def get_dpu_id(self, name):
def get_dpu_id(self, **kwargs):
"""
Retrieves the DPU ID for the given dpu-module name.
Returns None for non-smartswitch chassis.
Retrieves the DPU ID for the specified DPU module on a Smart Switch chassis.
When run on the Smart Switch chassis, it fetches the ID corresponding to provided DPU module name.
When run on the Smart Switch DPU chassis, returns the ID of the DPU.
This method is relevant only for Smart Switch chassis.
Args:
name (str, optional): The name of the DPU module (e.g., "DPU0", "DPU1").
Returns:
An integer, indicating the DPU ID Ex: name:DPU0 return value 0,
name:DPU1 return value 1, name:DPUX return value X
int: The DPU ID associated with the given module name.
For example, for name "DPU0", returns 0; for "DPU1", returns 1, and so on.
"""
raise NotImplementedError

def is_smartswitch(self):
"""
Retrieves whether the sonic instance is part of smartswitch
Checks whether the current SONiC instance is part of a Smart Switch platform.
Returns:
bool: True if the instance is part of a Smart Switch, False otherwise.
"""
return False

def is_dpu(self):
"""
Checks whether the current SONiC instance is running on a DPU.
Returns:
Returns:True for SmartSwitch and False for other platforms
bool: True if the instance is running on a DPU, False otherwise.
"""
return False

def get_dpu_dataplane_state(self):
"""
Retrieves the status of the DPU dataplane.
This method is applicable only on Smart Switch DPUs.
Returns:
bool: True if the dataplane is UP, False if it is down.
"""
raise NotImplementedError

def get_dpu_controlplane_state(self):
"""
Retrieves the status of the DPU control plane.
This method is applicable only on Smart Switch DPUs.
Returns:
bool: True if the control plane is UP, False if it is down.
"""
raise NotImplementedError


##############################################
# Fan methods
##############################################
Expand Down
11 changes: 6 additions & 5 deletions tests/chassis_base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@ def test_reboot_cause(self):
def test_chassis_base(self):
chassis = ChassisBase()
not_implemented_methods = [
[chassis.get_uid_led],
[chassis.set_uid_led, "COLOR"],
[chassis.get_dpu_id, "DPU0"],
[chassis.get_uid_led, [], {}],
[chassis.set_uid_led, ["COLOR"], {}],
[chassis.get_dpu_id, [], {"name": "DPU0"}],
]

for method in not_implemented_methods:
exception_raised = False
try:
func = method[0]
args = method[1:]
func(*args)
args = method[1]
kwargs = method[2]
func(*args, **kwargs)
except NotImplementedError:
exception_raised = True

Expand Down

0 comments on commit 94a1b5e

Please sign in to comment.