Skip to content

[CPO] Extend ChassisBase to support CPO ports - #700

Merged
prgeor merged 11 commits into
sonic-net:masterfrom
nexthop-ai:chassis-cpo
Aug 6, 2026
Merged

[CPO] Extend ChassisBase to support CPO ports#700
prgeor merged 11 commits into
sonic-net:masterfrom
nexthop-ai:chassis-cpo

Conversation

@bgallagher-nexthop

@bgallagher-nexthop bgallagher-nexthop commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

The "Port Mapping for CPO" HLD proposes changes to the Chassis object for CPO hardware platforms, where a function called construct_cpo_devices is called when an cpo.json file is present for the SONiC device. The intent is for vendors to implement construct_cpo_devices and create the CPO platform API objects required for each interface on the vendor's switch.

Example usage, from the HLD:

class VendorCpoChassis(ChassisBase):
  ...
  def construct_cpo_devices(self, cpo_data):
      for interface_name, interface in cpo_data["interfaces"].items():
          associated_devices = interface["associated_devices"]
          assert len(associated_devices) == 2, \
              "We expect 2 devices per interface on this CPO hardware platform"

          # Construct OE/ELSFP objects
          oe = None
          elsfp = None
          for dvc_info in associated_devices:
              device = cpo_data["devices"][dvc_info["device_id"]]
              if device["device_type"] == "optical_engine":
                  oe = VendorOe(hardware_id=self.hw_id, bank=dvc_info["bank"])
              elif device["device_type"] == "external_laser_source":
                  elsfp = VendorElsfp(hardware_id=self.hw_id, bank=dvc_info["bank"])

          # Create a CpoBase-derived object to represent this interface
          assert oe, "No optical engine found for this interface"
          assert elsfp, "No ELSFP found for this interface"
          # VendorCpoSfp would be a subclass of CpoSfpBase here.
          self._sfp_list.append(VendorCpo(hardware_id=self.hw_id, oe=oe, els=elsfp))

This PR adds a construct_cpo_devices stub function for vendors to implement and calls this function when cpo.json is present. It also adds function to store and retrieve CpoBase objects on a Chassis object. Additionally, it changes CPO Platform objects to inherit from DeviceBase so that they adhere to the DeviceBase interface.

Note: this PR requires sonic-net/sonic-buildimage#28077 to be merged first.

Motivation and Context

This change is required to instantiate the required platform API objects (OE, ELSFP, etc) for a Chassis that models CPO hardware.

How Has This Been Tested?

Unit-tests have been added.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@bgallagher-nexthop bgallagher-nexthop changed the title [CPO] Add construct_sfp_list_for_topology hook to ChassisBase [CPO] Extend ChassisBase to support CPO ports Jun 25, 2026
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Comment thread sonic_platform_base/chassis_base.py
Comment thread sonic_platform_base/chassis_base.py Outdated
Comment thread sonic_platform_base/chassis_base.py
Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@bgallagher-nexthop
bgallagher-nexthop marked this pull request as ready for review July 28, 2026 16:56
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread sonic_platform_base/chassis_base.py Outdated
"""
cpo = None
try:
cpo = self._cpo_list[index]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to return an error in case the entry in specific index is "None"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have copied the behaviour of get_sfp here, which is to just log an error and return None if an out-of-bounds index is used.

So for the two scenarios where an incorrect access occurs, we return None in both cases:

  • index is out of bounds -> None returned
  • index is for a non-CPO port -> None returned

from sonic_py_common import device_info
cpo_data = device_info.get_cpo_data()
if cpo_data:
self.construct_cpo_devices(cpo_data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the construct_cpo_devices responsible also to add the "None" for the sfps?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, the intention is that the implementation of this method should add None for any non-CPO ports

Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

micas-net
micas-net previously approved these changes Jul 31, 2026

@micas-net micas-net left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread sonic_platform_base/chassis_base.py
abelamit
abelamit previously approved these changes Aug 4, 2026
prgeor
prgeor previously approved these changes Aug 4, 2026
Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Brian Gallagher <bgallagher@nexthop.ai>
@bgallagher-nexthop
bgallagher-nexthop dismissed stale reviews from prgeor, abelamit, and micas-net via fc51057 August 5, 2026 15:32
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@prgeor

prgeor commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@prgeor
prgeor merged commit 8607c9f into sonic-net:master Aug 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants