-
Notifications
You must be signed in to change notification settings - Fork 658
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
[sfputil] Configure the debug loopback mode only on the relevant lanes of the logical port #3485
Conversation
cc4e0ca
to
99f5c92
Compare
…s of the logical port Signed-off-by: xinyu <xinyu0123@gmail.com>
99f5c92
to
0de47b2
Compare
sfputil/main.py
Outdated
@@ -1991,11 +1991,44 @@ def loopback(port_name, loopback_mode): | |||
click.echo("{}: This functionality is not implemented".format(port_name)) | |||
sys.exit(ERROR_NOT_IMPLEMENTED) | |||
|
|||
namespaces = multi_asic.get_front_end_namespaces() | |||
for namespace in namespaces: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xinyulin Instead of using the for loop to traverse over all possible namespaces, you can directly get the namespace of the port by calling multi_asic.get_namespace_for_port(port_name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihirpat1 Thanks for the example, I have modified it.
sfputil/main.py
Outdated
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace) | ||
if config_db is not None: | ||
config_db.connect() | ||
subport = int(config_db.get(config_db.CONFIG_DB, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xinyulin Please handle case wherein subport field is not defined in CONFIG_DB. You can assume subport to be 0 in such case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihirpat1 Could we simply assign the subport to 1 if the subport is not defined in the CONFIG_DB (subport is None) or is mistakenly set to 0?
if subport is None or subport == 0: subport = 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xinyulin Yes, this should be fine as well
fb3e74b
to
b922081
Compare
Signed-off-by: xinyu <xinyu0123@gmail.com>
b922081
to
33bd87c
Compare
sfputil/main.py
Outdated
subport = int(config_db.get(config_db.CONFIG_DB, | ||
'PORT|{}'.format(port_name), 'subport')) | ||
|
||
# If it is not defined (None) or if it is set to 0, assign a default value of 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# If it is not defined (None) or if it is set to 0, assign a default value of 1 | |
# If subport is not defined (None) or set to 0, assign a default value of 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihirpat1 Thank you for correcting the wording. I also added more loopback_mode options to allow users to individually clear each mode in the latest commit.
@click.argument('loopback_mode', required=True, default="none",
type=click.Choice(["none", "host-side-input", "host-side-output",
"media-side-input", "media-side-output",
"host-side-input-none", "host-side-output-none",
"host-side-input-none", "host-side-output-none"]))
I’ve kept none
as a valid loopback_mode option. Do you think it’s useful for users who want to completely clear all loopback modes on the physical port at once? Or should we remove this none
option and require users to disable the loopback mode individually?
33bd87c
to
1f7112b
Compare
Signed-off-by: xinyu <xinyu0123@gmail.com>
1f7112b
to
4d85d22
Compare
sfputil/main.py
Outdated
click.echo("Failed to connect to STATE_DB") | ||
sys.exit(EXIT_FAIL) | ||
|
||
if loopback_mode in ("host-side-input", "host-side-output", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replace this block with something similar to the below?
lane_mask = 0
if "host-side" in loopback_mode:
lane_mask = ((1 << host_lane_count) - 1) << ((subport - 1) * host_lane_count)
elif "media-side" in loopback_mode:
lane_mask = ((1 << media_lane_count) - 1) << ((subport - 1) * media_lane_count)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It looks compact and clean!
sfputil/main.py
Outdated
@@ -1469,10 +1469,10 @@ def is_fw_switch_done(port_name): | |||
status = -1 # Abnormal status. | |||
elif (ImageARunning == 1) and (ImageACommitted == 0): # ImageA is running, but not committed. | |||
click.echo("FW images switch successful : ImageA is running") | |||
status = 1 # run_firmware is done. | |||
status = 1 # run_firmware is done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xinyulin Can you please revert this line
sfputil/main.py
Outdated
elif (ImageBRunning == 1) and (ImageBCommitted == 0): # ImageB is running, but not committed. | ||
click.echo("FW images switch successful : ImageB is running") | ||
status = 1 # run_firmware is done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xinyulin Can you please revert this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops! My editor automatically trimmed the trailing whitespace. Let me revert it and disable that feature.
sfputil/main.py
Outdated
state_db = SonicV2Connector(use_unix_socket_path=False, namespace=namespace) | ||
if state_db is not None: | ||
state_db.connect(state_db.STATE_DB) | ||
host_lane_count = int(state_db.get(state_db.STATE_DB, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xinyulin Wondering if we should handle ValueError exception and return error to handle case wherein subport
, host_lane_count
or media_lane_count
are not present in the DB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihirpat1 It is helpful for the user to know about the incorrect configuration. The newly added commit catches the TypeError
when the variable is not present in the DB.
try:
subport = int(config_db.get(config_db.CONFIG_DB, f'PORT|{port_name}', 'subport'))
except TypeError:
click.echo(f"{port_name}: subport is not present in CONFIG_DB")
sys.exit(EXIT_FAIL)
From the formula, the lane_mask
will automatically be set to 0 when the host or media lane count is zero.
if 'host-side' in loopback_mode:
lane_mask = ((1 << host_lane_count) - 1) << ((subport - 1) * host_lane_count)
elif 'media-side' in loopback_mode:
lane_mask = ((1 << media_lane_count) - 1) << ((subport - 1) * media_lane_count)
… clean Signed-off-by: xinyu <xinyu0123@gmail.com>
2e69024
to
22d2634
Compare
… host_lane_count, or media_lane_count is not present Signed-off-by: xinyu <xinyu0123@gmail.com>
22d2634
to
e1c7aa1
Compare
52ebfb3
to
b78f125
Compare
aff5a53
to
9f8ae79
Compare
…lane count Signed-off-by: xinyu <xinyu0123@gmail.com>
9f8ae79
to
2aaf92f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@xinyulin Approving with a minor comment
doc/Command-Reference.md
Outdated
@@ -3106,19 +3106,19 @@ This command is the standard CMIS diagnostic control used for troubleshooting li | |||
|
|||
- Usage: | |||
``` | |||
sfputil debug loopback PORT_NAME LOOPBACK_MODE | |||
sfputil debug loopback PORT_NAME LOOPBACK_MODE <enable/disable> | |||
|
|||
Set the loopback mode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set the loopback mode | |
Valid values for LOOPBACK_MODE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mihirpat1 Thanks! It has been revised.
…ove clarity Signed-off-by: xinyu <xinyu0123@gmail.com>
@bingwang-ms can you cherry pick to 202405? Its a new CLI for debugging. |
@yxieca Can you please help to cherry pick this to 202311? |
…s of the logical port (sonic-net#3485) * [sfputil] Configure the debug loopback mode only on the relevant lanes of the logical port Signed-off-by: xinyu <xinyu0123@gmail.com>
Cherry-pick PR to 202311: #3543 |
…s of the logical port (#3485) * [sfputil] Configure the debug loopback mode only on the relevant lanes of the logical port Signed-off-by: xinyu <xinyu0123@gmail.com>
…s of the logical port (sonic-net#3485) * [sfputil] Configure the debug loopback mode only on the relevant lanes of the logical port Signed-off-by: xinyu <xinyu0123@gmail.com>
Cherry-pick PR to 202405: #3552 |
…s of the logical port (#3485) * [sfputil] Configure the debug loopback mode only on the relevant lanes of the logical port Signed-off-by: xinyu <xinyu0123@gmail.com>
What I did
This update enhances the loopback command functionality to support configuring the loopback mode for specific logical ports, instead of applying the configuration to the entire physical port.
How I did it
By calculating the lane mask according to the port's configuration and state data, the loopback mode can now be accurately set for the specified port, ensuring that other unrelated logical ports are not affected during diagnostic operations.
How to verify it
Tested under Cisco8111 with Credo C1 cable.
The sfputil debug loopback command will now only affect the relevant lanes of the logical port.
Set host input loopback mode on logical port Ethernet80, the expected value of page 0x13, byte 0xB7= 0x0F
Set media input loopback mode on logical port Ethernet84, the expected value of page 0x13, byte 0xB5= 0xF0
Previous command output (if the output of a command-line utility has changed)
New command output (if the output of a command-line utility has changed)