Skip to content

Fetch capability of mirror before configuring it#4089

Merged
qiluo-msft merged 6 commits intosonic-net:masterfrom
stephenxs:mirror_capability_check
Nov 17, 2025
Merged

Fetch capability of mirror before configuring it#4089
qiluo-msft merged 6 commits intosonic-net:masterfrom
stephenxs:mirror_capability_check

Conversation

@stephenxs
Copy link
Copy Markdown
Collaborator

@stephenxs stephenxs commented Oct 11, 2025

What I did

Fetch capability of ingress/egress mirror before configuring it and avoid configuring ingress/egress mirror on a platform that does not support it.

How I did it

Check the capability in PORT_INGRESS_MIRROR_CAPABLE and PORT_EGRESS_MIRROR_CAPABLE in STATE_DB table SWITCH_CAPABILITY.
The capability of ingress/egress mirror is inserted to STATE_DB by orchagent during initialization.

How to verify it

Manual test and unit test

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)

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Stephen Sun <[email protected]>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@stephenxs
Copy link
Copy Markdown
Collaborator Author

Failure is caused by rebasing the commit to the latest master. Investigating.

@stephenxs
Copy link
Copy Markdown
Collaborator Author

Failure is caused by rebasing the commit to the latest master. Investigating.

Depends on sonic-net/sonic-swss#3934

Signed-off-by: Stephen Sun <[email protected]>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@stephenxs stephenxs changed the title Fetch capability of mirror before configuring it. Fetch capability of mirror before configuring it Oct 20, 2025
@stephenxs stephenxs marked this pull request as ready for review October 23, 2025 06:03
@stephenxs stephenxs requested a review from bingwang-ms October 24, 2025 06:07
bingwang-ms
bingwang-ms previously approved these changes Nov 4, 2025
@bingwang-ms
Copy link
Copy Markdown
Contributor

Depends on sonic-net/sonic-swss#3934

@bingwang-ms
Copy link
Copy Markdown
Contributor

@qiluo-msft Can you help review this change? Thanks

config/main.py Outdated
def is_port_mirror_capability_supported(direction, namespace=None):
""" Check if port mirror capability is supported for the given direction """
try:
state_db = SonicV2Connector(host='127.0.0.1')
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Nov 4, 2025

Choose a reason for hiding this comment

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

Could you use unix socket which has better performance? #Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

config/main.py Outdated
return False

return True
except Exception:
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Nov 4, 2025

Choose a reason for hiding this comment

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

Could you use more specific exception type? #Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed as we do not expect any exception here.

@qiluo-msft qiluo-msft requested a review from Copilot November 4, 2025 01:08
Copy link
Copy Markdown
Contributor

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 ASIC capability checking for port mirror direction support before allowing mirror session configuration. The change prevents users from configuring mirror sessions with directions (rx/tx/both) that are not supported by the underlying ASIC hardware.

  • Added is_port_mirror_capability_supported() function to query STATE_DB for ASIC capabilities
  • Integrated capability validation into validate_mirror_session_config()
  • Added comprehensive test coverage for capability checking functionality

Reviewed Changes

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

File Description
config/main.py Added capability checking function and validation logic to prevent unsupported mirror directions
tests/config_mirror_session_test.py Added test cases for capability checking and removed trailing whitespace

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@stephenxs stephenxs requested a review from qiluo-msft November 4, 2025 07:20
@stephenxs
Copy link
Copy Markdown
Collaborator Author

It's weird that pretest passed locally but failed in the github

stephens@675ff3c81f2e:/sonic/src/sonic-utilities/config$ git commit -s
[INFO] Initializing environment for https://github.com/PyCQA/flake8.
[INFO] Installing environment for https://github.com/PyCQA/flake8.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
flake8...................................................................Passed
[detached HEAD 8bf2b0d7] Fix community review comments
 1 file changed, 19 insertions(+), 23 deletions(-)
stephens@675ff3c81f2e:/sonic/src/sonic-utilities/config$ git log

@qiluo-msft qiluo-msft merged commit ad0a3d3 into sonic-net:master Nov 17, 2025
7 checks passed
@stephenxs stephenxs deleted the mirror_capability_check branch November 18, 2025 01:08
gordon-nexthop pushed a commit to nexthop-ai/sonic-utilities that referenced this pull request Nov 25, 2025
What I did
Fetch capability of ingress/egress mirror before configuring it and avoid configuring ingress/egress mirror on a platform that does not support it.

How I did it
Check the capability in PORT_INGRESS_MIRROR_CAPABLE and PORT_EGRESS_MIRROR_CAPABLE in STATE_DB table SWITCH_CAPABILITY.
The capability of ingress/egress mirror is inserted to STATE_DB by orchagent during initialization.

How to verify it
Manual test and unit test
yxieca added a commit to yxieca/sonic-utilities that referenced this pull request Dec 13, 2025
yxieca added a commit that referenced this pull request Dec 14, 2025
@yxieca
Copy link
Copy Markdown
Contributor

yxieca commented Dec 14, 2025

@stephenxs this change causes test failure when advancing sonic-utilities submodule. We need to revert to move forward.

@yxieca
Copy link
Copy Markdown
Contributor

yxieca commented Dec 14, 2025

@stephenxs this change is causing show_techsupport/test_techsupport.py to fail at multi-asic deployment. But this is a good change to have. I will see if that is the only failure. if it is, then I am leaning towards file an issue to xfail it and let you work on a fix. Please stay tuned.

@stephenxs
Copy link
Copy Markdown
Collaborator Author

@stephenxs this change is causing show_techsupport/test_techsupport.py to fail at multi-asic deployment. But this is a good change to have. I will see if that is the only failure. if it is, then I am leaning towards file an issue to xfail it and let you work on a fix. Please stay tuned.

Could you please share the test link? Thanks

@yxieca
Copy link
Copy Markdown
Contributor

yxieca commented Dec 14, 2025

Issue: sonic-net/sonic-mgmt#21690

Test failure: https://elastictest.org/scheduler/testplan/693d87a8be086527515c111d

@stephenxs
Copy link
Copy Markdown
Collaborator Author

YairRaviv pushed a commit to YairRaviv/sonic-utilities that referenced this pull request Jan 12, 2026
What I did
Fetch capability of ingress/egress mirror before configuring it and avoid configuring ingress/egress mirror on a platform that does not support it.

How I did it
Check the capability in PORT_INGRESS_MIRROR_CAPABLE and PORT_EGRESS_MIRROR_CAPABLE in STATE_DB table SWITCH_CAPABILITY.
The capability of ingress/egress mirror is inserted to STATE_DB by orchagent during initialization.

How to verify it
Manual test and unit test
@mssonicbld
Copy link
Copy Markdown
Collaborator

Cherry-pick PR to 202511: #4204

yxieca added a commit to yxieca/sonic-utilities that referenced this pull request Feb 28, 2026
The legacy 'config mirror_session add' command calls add_erspan()
with direction=None and src_port=None. After PR sonic-net#4089 added port
mirror capability checking, validate_mirror_session_config() checks
PORT_INGRESS_MIRROR_CAPABLE and PORT_EGRESS_MIRROR_CAPABLE in
STATE_DB when direction is None. On platforms where orchagent does
not populate these keys, this causes the legacy command to fail
with 'Port mirror direction both is not supported by the ASIC'.

The fix skips the capability check when src_port is not specified,
since legacy ERSPAN sessions don't use port-based mirroring and
should not be subject to the port mirror capability check.

Fixes: sonic-net#4318
Signed-off-by: Ying Xie <[email protected]>
mssonicbld added a commit to mssonicbld/sonic-utilities that referenced this pull request Mar 18, 2026
…sessions

## What I did

Fixed is_port_mirror_capability_supported() so that ERSPAN sessions (direction=None) are not blocked by the PORT_INGRESS_MIRROR_CAPABLE / PORT_EGRESS_MIRROR_CAPABLE capability check.

## Root cause

PR sonic-net#4089 added a capability check that reads PORT_INGRESS_MIRROR_CAPABLE and PORT_EGRESS_MIRROR_CAPABLE from STATE_DB SWITCH_CAPABILITY|switch. For ERSPAN sessions, direction=None was treated as 'check both', but:
1. These capability flags only apply to SPAN (port mirror) sessions, not ERSPAN (which uses source/destination IPs, not ports)
2. Platforms that don't populate these STATE_DB keys return None, which != 'true', so the function incorrectly returns False (unsupported)

PR sonic-net#4159 partially addressed the multi-ASIC namespace issue but did not fix the fundamental problem for ERSPAN sessions with no src/dst port specified.

## How I fixed it

- **For ERSPAN (direction=None)**: Return True immediately. PORT_INGRESS/EGRESS_MIRROR_CAPABLE does not apply to ERSPAN sessions.
- **For SPAN (direction != None)**: Treat absent STATE_DB key (None value) as 'supported' for backward compatibility with platforms that don't populate SWITCH_CAPABILITY table entries.

## How to verify it

Unit tests updated in 	ests/config_mirror_session_test.py:
- Added Test 4 to verify behavior when STATE_DB keys are absent (all return True)
- Updated Test 2 and Test 3 assertions for direction=None to expect True

Fixes: sonic-net/sonic-mgmt#21690
Signed-off-by: Sonic Build Admin <[email protected]>
bingwang-ms pushed a commit that referenced this pull request Mar 18, 2026
…sessions (#4368)

## What I did

Fixed is_port_mirror_capability_supported() so that ERSPAN sessions (direction=None) are not blocked by the PORT_INGRESS_MIRROR_CAPABLE / PORT_EGRESS_MIRROR_CAPABLE capability check.

## Root cause

PR #4089 added a capability check that reads PORT_INGRESS_MIRROR_CAPABLE and PORT_EGRESS_MIRROR_CAPABLE from STATE_DB SWITCH_CAPABILITY|switch. For ERSPAN sessions, direction=None was treated as 'check both', but:
1. These capability flags only apply to SPAN (port mirror) sessions, not ERSPAN (which uses source/destination IPs, not ports)
2. Platforms that don't populate these STATE_DB keys return None, which != 'true', so the function incorrectly returns False (unsupported)

PR #4159 partially addressed the multi-ASIC namespace issue but did not fix the fundamental problem for ERSPAN sessions with no src/dst port specified.

## How I fixed it

- **For ERSPAN (direction=None)**: Return True immediately. PORT_INGRESS/EGRESS_MIRROR_CAPABLE does not apply to ERSPAN sessions.
- **For SPAN (direction != None)**: Treat absent STATE_DB key (None value) as 'supported' for backward compatibility with platforms that don't populate SWITCH_CAPABILITY table entries.

## How to verify it

Unit tests updated in 	ests/config_mirror_session_test.py:
- Added Test 4 to verify behavior when STATE_DB keys are absent (all return True)
- Updated Test 2 and Test 3 assertions for direction=None to expect True

Fixes: sonic-net/sonic-mgmt#21690

Signed-off-by: Sonic Build Admin <[email protected]>
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.

10 participants