Skip to content

[ycabled][active-standby] Ignore transceiver updates for initialized MUX simulator. - #882

Open
harjotsinghpawra wants to merge 1 commit into
sonic-net:masterfrom
harjotsinghpawra:dualtor_as_state_loop
Open

[ycabled][active-standby] Ignore transceiver updates for initialized MUX simulator.#882
harjotsinghpawra wants to merge 1 commit into
sonic-net:masterfrom
harjotsinghpawra:dualtor_as_state_loop

Conversation

@harjotsinghpawra

Copy link
Copy Markdown

Description

TRANSCEIVER_INFO SET notifications contain the complete table row and are
generated for both transceiver insertion and CMIS maintenance updates. After
a simulated Y-cable is initialized, treating every SET as an insertion causes
ycabled to reread the simulator direction and publish stale HW MUX state.

Ignore SET notifications only when the simulator configuration exists and the
port already has a fully initialized simulated Y-cable instance. Continue to
process initial discovery, failed-initialization retries, and DEL notifications.

Add unit tests for initialized, missing, incomplete, and unconfigured simulator
instances and for the corresponding state-update behavior.

Motivation and Context

Problem

xcvrd publishes TRANSCEIVER_INFO SET notifications for CMIS maintenance updates during downlink admin-down. ycabled treats every SET as an SFP insertion. For an active-standby simulated Y-cable this rereads the simulator MUX direction and updates STATE_HW_MUX_CABLE with a direction that may lag linkmgrd's requested state. The stale update can cause active/standby MUX ping-pong and exceed the dual-ToR traffic disruption budget.

Root cause

SubscriberStateTable returns the complete current table row for a SET, not only the changed fields. Consequently, filtering the event based on the fields present in the returned dictionary cannot reliably distinguish insertion from a CMIS-only update.

Fix

For simulator-backed ports, treat a SET as an insertion only until the simulated Y-cable driver is fully initialized. Once the driver instance exists and _initialized is True, ignore subsequent TRANSCEIVER_INFO SET notifications.

The guard is deliberately limited to the MUX simulator by requiring /etc/sonic/mux_simulator.json. Physical Y-cable behavior remains unchanged. DEL notifications remain unchanged and remove the saved driver instance, so a later insertion can initialize again. Missing or partially initialized instances return False, allowing later notifications to retry initialization.

How Has This Been Tested?

  • Initialized simulator suppresses repeated SET processing.
  • Missing simulator instance permits initial discovery.
  • Incomplete simulator instance permits retry.
  • Missing simulator configuration preserves existing behavior.
  • Removal processing remains unchanged through the existing DEL test.

The ycabled wheel build automatically ran the complete component test suite inside the SONiC build container:

platform linux -- Python 3.13.5, pytest-8.3.5
collected 280 items
280 passed, 144 warnings in 6.75s

New tests recorded as passing:

tests/test_y_cable_helper.py::TestYCableScript::test_is_initialized_simulated_y_cable PASSED
tests/test_y_cable_helper.py::TestYCableScript::test_is_initialized_simulated_y_cable_without_instance PASSED
tests/test_y_cable_helper.py::TestYCableScript::test_is_initialized_simulated_y_cable_incomplete_instance PASSED
tests/test_y_cable_helper.py::TestYCableScript::test_is_initialized_simulated_y_cable_without_config PASSED
tests/test_ycable.py::TestYcableScript::test_handle_state_update_task_ignores_update_for_initialized_simulator PASSED
tests/test_ycable.py::TestYcableScript::test_handle_state_update_task_processes_update_for_uninitialized_simulator PASSED
tests/test_ycable.py::TestYcableScript::test_handle_state_update_task_retries_cmis_update_after_failed_simulator_init PASSED

#### Additional Information (Optional)

…MUX simulator.

Signed-off-by: Harjot Singh <harjotpawrawork@gmail.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@azure-pipelines

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

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@harjotsinghpawra

Copy link
Copy Markdown
Author

@lolyu can you please help review this


port_dict = {}
if op == swsscommon.SET_COMMAND:
if y_cable_helper.is_initialized_simulated_y_cable(port):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please make sure the initialized flag will be reset for actual unplug/insert.

Failed or incomplete initialization must return False so a later SET can
retry normal discovery after the simulator configuration becomes available.
"""
if not os.path.exists(MUX_SIMULATOR_CONFIG_FILE):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The fix is applicable to both simulated and physical mux scenario.

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.

3 participants