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

[sfputil] Configure the debug loopback mode only on the relevant lanes of the logical port #3485

Merged
merged 9 commits into from
Sep 11, 2024

Conversation

xinyulin
Copy link
Contributor

@xinyulin xinyulin commented Aug 10, 2024

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
image

Set media input loopback mode on logical port Ethernet84, the expected value of page 0x13, byte 0xB5= 0xF0
image

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)

@xinyulin xinyulin force-pushed the sfputil_loopback_lanemask branch 3 times, most recently from cc4e0ca to 99f5c92 Compare August 10, 2024 00:47
…s of the logical port

Signed-off-by: xinyu <xinyu0123@gmail.com>
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:
Copy link
Contributor

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)

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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

sfputil/main.py Outdated Show resolved Hide resolved
Signed-off-by: xinyu <xinyu0123@gmail.com>
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
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 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

Copy link
Contributor Author

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?

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",
Copy link
Contributor

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)

Copy link
Contributor Author

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.
Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Contributor Author

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,
Copy link
Contributor

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.

Copy link
Contributor Author

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>
@xinyulin xinyulin force-pushed the sfputil_loopback_lanemask branch 7 times, most recently from 2e69024 to 22d2634 Compare August 20, 2024 10:12
… host_lane_count, or media_lane_count is not present

Signed-off-by: xinyu <xinyu0123@gmail.com>
@xinyulin xinyulin force-pushed the sfputil_loopback_lanemask branch 3 times, most recently from aff5a53 to 9f8ae79 Compare September 10, 2024 03:47
…lane count

Signed-off-by: xinyu <xinyu0123@gmail.com>
mihirpat1
mihirpat1 previously approved these changes Sep 10, 2024
Copy link
Contributor

@mihirpat1 mihirpat1 left a 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

@@ -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
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
Set the loopback mode
Valid values for LOOPBACK_MODE

Copy link
Contributor Author

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>
@prgeor prgeor merged commit 2cb8cc6 into sonic-net:master Sep 11, 2024
7 checks passed
@prgeor
Copy link
Contributor

prgeor commented Sep 11, 2024

@bingwang-ms can you cherry pick to 202405? Its a new CLI for debugging.

@mihirpat1
Copy link
Contributor

@yxieca Can you please help to cherry pick this to 202311?
MSFT ADO - 29396307

mssonicbld pushed a commit to mssonicbld/sonic-utilities that referenced this pull request Sep 11, 2024
…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>
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202311: #3543

mssonicbld pushed a commit that referenced this pull request Sep 12, 2024
…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>
@xinyulin xinyulin deleted the sfputil_loopback_lanemask branch September 12, 2024 04:26
mssonicbld pushed a commit to mssonicbld/sonic-utilities that referenced this pull request Sep 20, 2024
…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>
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202405: #3552

mssonicbld pushed a commit that referenced this pull request Sep 20, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants