Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xcvrd] Modify to support regular expression when parsing the key in media_settings.json #471

Merged
merged 5 commits into from
Jul 5, 2024

Conversation

DennisChiuEC
Copy link
Contributor

Description

Let media_settings.json can use regular expression to match 'vendor key' or 'media key'
when define a set of transceiver to use the same SI value.

Motivation and Context

Make the definition of SI value for a set of vendor or media can be more flexible

How Has This Been Tested?

root@sonic:~# cat /var/log/swss/swss.rec | grep preemphasis
2024-04-17.01:53:10.594465|PORT_TABLE:Ethernet0|SET|preemphasis:0x0c8418,0x0c8418,0x0c8418,0x0c8418
2024-04-17.01:53:11.827324|PORT_TABLE:Ethernet4|SET|preemphasis:0x0c8418,0x0c8418,0x0c8418,0x0c8418

Example of media_settings.json
"GLOBAL_MEDIA_SETTINGS": {
"1-32": {
"VENDOR.*-PN.*": {
"preemphasis": {
"lane0": "0x0c8418",
"lane1": "0x0c8418",
"lane2": "0x0c8418",
"lane3": "0x0c8418",
"lane4": "0x0c8418"
}
}
}

Additional Information (Optional)

@DennisChiuEC DennisChiuEC marked this pull request as draft April 18, 2024 03:06
@DennisChiuEC DennisChiuEC marked this pull request as ready for review April 18, 2024 03:29
@prgeor
Copy link
Collaborator

prgeor commented Apr 21, 2024

@DennisChiuEC Please add unit test

Copy link
Collaborator

@prgeor prgeor left a comment

Choose a reason for hiding this comment

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

@moshemos @tshalvi Please review

@prgeor prgeor requested a review from keboliu April 21, 2024 20:36
@DennisChiuEC
Copy link
Contributor Author

OK, I will add the unit test case.

@keboliu keboliu requested review from noaOrMlnx and removed request for noaOrMlnx April 23, 2024 03:14
@keboliu
Copy link
Collaborator

keboliu commented Apr 30, 2024

@tshalvi would you please review?

@keboliu keboliu removed their request for review May 7, 2024 01:31
if is_si_per_speed_supported(media_dict[key[VENDOR_KEY]]):
if key[LANE_SPEED_KEY] is not None and key[LANE_SPEED_KEY] in media_dict[key[VENDOR_KEY]]: # e.g: 'speed:400GAUI-8'
return media_dict[key[VENDOR_KEY]][key[LANE_SPEED_KEY]]
for dict_key in media_dict.keys():
Copy link
Collaborator

Choose a reason for hiding this comment

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

@DennisChiuEC can you write a function get_media_settings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if is_si_per_speed_supported(media_dict[key[MEDIA_KEY]]):
if key[LANE_SPEED_KEY] is not None and key[LANE_SPEED_KEY] in media_dict[key[MEDIA_KEY]]:
return media_dict[key[MEDIA_KEY]][key[LANE_SPEED_KEY]]
for dict_key in media_dict.keys():
Copy link
Collaborator

Choose a reason for hiding this comment

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

@DennisChiuEC can you write a function get_media_settings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -168,6 +169,19 @@ def get_media_settings_value(physical_port, key):
media_dict = {}
default_dict = {}

def get_media_settings(key, media_dict):
for dict_key in media_dict.keys():
if ( re.match(dict_key, key[VENDOR_KEY]) or re.match(dict_key, key[VENDOR_KEY].split('-')[0]) # e.g: 'AMPHENOL-1234'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ( re.match(dict_key, key[VENDOR_KEY]) or re.match(dict_key, key[VENDOR_KEY].split('-')[0]) # e.g: 'AMPHENOL-1234'
if (re.match(dict_key, key[VENDOR_KEY]) or \
re.match(dict_key, key[VENDOR_KEY].split('-')[0]) # e.g: 'AMPHENOL-1234'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if key[LANE_SPEED_KEY] is not None and key[LANE_SPEED_KEY] in media_dict[dict_key]: # e.g: 'speed:400GAUI-8'
return media_dict[dict_key][key[LANE_SPEED_KEY]]
else:
return {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we returning {} and not None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was added by the previous PR.
I just defined a function to simplify the code.

Copy link
Collaborator

@prgeor prgeor left a comment

Choose a reason for hiding this comment

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

@tshalvi can you please review?

@prgeor prgeor merged commit 74881e1 into sonic-net:master Jul 5, 2024
5 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.

None yet

5 participants