Skip to content

Conversation

@longhuan-cisco
Copy link
Contributor

@longhuan-cisco longhuan-cisco commented Jul 14, 2025

sonic-swss side change: sonic-net/sonic-swss#3764

Description

Add support for custom serdes attrs SAI_PORT_SERDES_ATTR_CUSTOM_COLLECTION

In media_settings.json, custom attributes can be defined by using CUSTOM: as prefix, and existing parsing logic/format will be reused.

Example media_settings.json snippet

                    "CUSTOM:ABC": {
                        "lane0": "0x1",
                        "lane1": "0x1",
                        "lane2": "0x1",
                        "lane3": "0x1",
                        "lane4": "0x1",
                        "lane5": "0x1",
                        "lane6": "0x1",
                        "lane7": "0x1"
                    },
                    "CUSTOM:XYZ": {
                        "lane0": "0x10",
                        "lane1": "0x10",
                        "lane2": "0x10",
                        "lane3": "0x10",
                        "lane4": "0x10",
                        "lane5": "0x10",
                        "lane6": "0x10",
                        "lane7": "0x10"
                    },
                    "CUSTOM:XXX": {
                        "lane0": "0x7",
                        "lane1": "0x7",
                        "lane2": "0x7",
                        "lane3": "0x7",
                        "lane4": "0x7",
                        "lane5": "0x7",
                        "lane6": "0x7",
                        "lane7": "0x7"
                    },

Motivation and Context

How Has This Been Tested?

Tested end-to-end xcvrd->OA->SAI/SDK on 8-hostlanes optics with both non-breakout and breakout modes.

Additional Information (Optional)

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@longhuan-cisco
Copy link
Contributor Author

@prgeor @mihirpat1 could you please review, thanks

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mihirpat1 mihirpat1 requested a review from Copilot October 15, 2025 02:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for custom SerDes attributes in the media settings parser, allowing custom attributes to be defined in media_settings.json with a CUSTOM: prefix and converted to JSON format for consumption by the SAI layer.

  • Introduces parsing logic for custom SerDes attributes prefixed with CUSTOM:
  • Adds conversion functions to handle hex/int string values and convert them to signed integers
  • Implements JSON serialization of custom attributes for database storage

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
sonic-xcvrd/xcvrd/xcvrd_utilities/media_settings_parser.py Adds custom SerDes attribute parsing logic, helper functions for string-to-int conversion, and integration into the media setting notification flow
sonic-xcvrd/tests/test_xcvrd.py Adds unit tests for the custom SerDes attribute handling functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

prsunny pushed a commit to sonic-net/sonic-swss that referenced this pull request Nov 26, 2025
sonic-platform-daemon side change: sonic-net/sonic-platform-daemons#643

What I did
Support SAI_PORT_SERDES_ATTR_CUSTOM_COLLECTION (i.e. custom serdes attributes represented in JSON based string format)

Use boost::variant for the serdes_attr map value to support both std::vector<uint32_t> and std::string in a type-safe way, with easy extensibility to add more types later.
@longhuan-cisco
Copy link
Contributor Author

@prgeor kindly reminder, thanks

return port_speed, lane_count, subport_num


def convert_to_int32(value):
Copy link
Collaborator

Choose a reason for hiding this comment

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

@longhuan-cisco I am not sure why custom values need this conversion compared to existing SI values

Copy link
Contributor Author

@longhuan-cisco longhuan-cisco Dec 6, 2025

Choose a reason for hiding this comment

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

@prgeor Agree, changed it to take custom attr values as-is from media_settings.json
It's up to the vendor/platform to use whatever types of values.

@prgeor
Copy link
Collaborator

prgeor commented Nov 27, 2025

@longhuan-cisco can we have an HLD describing this ? We have similar for GLOBAL_MEDIA_SETTINGS , PORT_MEDIA_SETTINGS here. ?

We can have CUSTOM_MEDIA_SETTINGS

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@longhuan-cisco
Copy link
Contributor Author

@longhuan-cisco can we have an HLD describing this ? We have similar for GLOBAL_MEDIA_SETTINGS , PORT_MEDIA_SETTINGS here. ?

@prgeor
Sure will update HLD https://github.com/sonic-net/SONiC/blob/master/doc/media-settings/Media-based-Port-settings.md

We can have CUSTOM_MEDIA_SETTINGS

Were you suggesting to put custom attributes in a new CUSTOM_MEDIA_SETTINGS section of media_settings.json? I'm not sure about the advantage of doing so.
Instead, by putting all the custom attributes in existing GLOBAL_MEDIA_SETTINGS and PORT_MEDIA_SETTINGS in the same way as traditional attributes (only difference is the CUSTOM: prefix), both traditional and custom attributes are able to share the same parsing logic (without touching the existing main parsing logic), custom attributes automatically obtain all the existing good stuff of today's parser (range ports support, DEFAULT_KEY, vendor+PN matching, regex key matching, media_lane_speed_key, etc) and inherit any potential future enhancement for free.

if GLOBAL_MEDIA_SETTINGS_KEY in g_dict:
for keys in g_dict[GLOBAL_MEDIA_SETTINGS_KEY]:
if COMMA_SEPARATOR in keys:
port_list = keys.split(COMMA_SEPARATOR)
for port in port_list:
if RANGE_SEPARATOR in port:
if common.check_port_in_range(port, physical_port):
media_dict = g_dict[GLOBAL_MEDIA_SETTINGS_KEY][keys]
break
elif str(physical_port) == port:
media_dict = g_dict[GLOBAL_MEDIA_SETTINGS_KEY][keys]
break
elif RANGE_SEPARATOR in keys:
if common.check_port_in_range(keys, physical_port):
media_dict = g_dict[GLOBAL_MEDIA_SETTINGS_KEY][keys]
# If there is a match in the global profile for a media type,
# fetch those values
media_settings = get_media_settings(key, media_dict)
if media_settings is not None:
return media_settings
# Try to match 'default' key if it does not match any keys
elif DEFAULT_KEY in media_dict:
default_dict = get_media_settings_for_speed(media_dict[DEFAULT_KEY], lane_speed_key)
media_dict = {}
if PORT_MEDIA_SETTINGS_KEY in g_dict:
for keys in g_dict[PORT_MEDIA_SETTINGS_KEY]:
if int(keys) == physical_port:
media_dict = g_dict[PORT_MEDIA_SETTINGS_KEY][keys]
break
if len(media_dict) == 0:
if len(default_dict) != 0:
return default_dict
else:
helper_logger.log_notice("No values for physical port '{}'".format(physical_port))
return {}
media_settings = get_media_settings(key, media_dict)
if media_settings is not None:
return media_settings
# Try to match 'default' key if it does not match any keys
elif DEFAULT_KEY in media_dict:
return get_media_settings_for_speed(media_dict[DEFAULT_KEY], lane_speed_key)
elif len(default_dict) != 0:
return default_dict
else:
if len(default_dict) != 0:
return default_dict

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@longhuan-cisco longhuan-cisco requested a review from prgeor December 6, 2025 01:19
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.

4 participants