Skip to content

Orchagent validates mirror session queue parameter against maximum value from SAI#1957

Merged
prsunny merged 3 commits intosonic-net:masterfrom
raphaelt-nvidia:mirror_queue_check
Oct 18, 2021
Merged

Orchagent validates mirror session queue parameter against maximum value from SAI#1957
prsunny merged 3 commits intosonic-net:masterfrom
raphaelt-nvidia:mirror_queue_check

Conversation

@raphaelt-nvidia
Copy link
Contributor

Signed-off-by: Raphael Tryster raphaelt@nvidia.com

What I did

On initialization, orchagent queries SAI for the maximum value of the queue parameter in mirroring sessions. When the user configures a session, if the value requested by the user is invalid, it writes an error in the log and does not pass the request to SAI/SDK.

Why I did it

Fixes https://github.com/Azure/sonic-buildimage/issues/8189[mirroring] Missing per-vendor validation of mirror session queue parameter. Without this change, orchagent passes the invalid data to SAI/SDK which returns failure, causing orchagent to exit, effectively a system crash.

How I verified it

Manual and unit test: Create 3 mirror sessions with queue = 0, maximum valid value, lowest invalid value. First two cases, sessions are created. For last case, session not created in state DB and error in log.

Details if related

…lue from SAI

Signed-off-by: Raphael Tryster <raphaelt@nvidia.com>
… if vendor SAI does not specify limit

Signed-off-by: Raphael Tryster <raphaelt@nvidia.com>

// 15 is a typical value, but if vendor's SAI does not supply the maximum value,
// allow all 8-bit numbers, effectively cancelling validation by orchagent.
#define MIRROR_SESSION_DEFAULT_NUM_TC 255
Copy link
Collaborator

Choose a reason for hiding this comment

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

if 15 is the typical value, I would suggest having 15 as the default limit. By having 255 and if user supply a value like 100, this still can fail in SAI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The failure of some automatic tests has shown me that the question is more complex than that. Firstly, let me describe our internal discussions. My first inclination was to use 15 as a typical default, but our architect pointed out that if some vendor supports a higher number and does not implement SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES, then a user configuring that higher number will be prevented from doing so. On the other hand, if we set the default high, then a smart user of that vendor's switch could go up to its maximum, and only a dumb user would enter a value that is too high and crash the switch. So I changed it to 255, which would allow all values up to 254. Of course, you may take the position that if a vendor wants to allow use of higher numbered queues, that vendor must implement SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES.

Now I would like to consult about another aspect. Changing to 255 exposed a bug in the test which I missed because internally I ran the wrong test version, but the failed tests in github show it. The vs test uses setReadOnlyAttr to simulate a value of 15 for SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES, expects passing 14 to succeed and 15 to fail. This worked as long as the default in orchagent was 15. But after I changed it to 255, creating a session with queue=15 succeeded, and the test failed. I believe the reason is that for efficiency, orchagent only queries SAI once for SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES, caches the value, and compares against the cached value whenever a session is created. You can see that code in this PR. But that probably means that when the test tries to set the limit with setReadOnlyAttr, it has no effect, because orchagent already completed its initialization, found no implementation of SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES in the vs environment, and set the limit to the default of 255. This theory is supported by additional tests I did today, where 254 succeeds and 255 fails. That means that the test cannot simulate its own limit, and must assume the same default as orchagent.

To sum up:

  1. In the light of the discussion above, do you still think I should change the default back to 15?
  2. Do you agree that I should get rid of setReadOnlyAttr in the test, and align with whatever default orchagent sets for testing the limit?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for explaining. Approving from my side. Lets wait for @bingwang-ms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I gather you answer to #1 is No. What about #2? Unless I change something in the test, it will continue to fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

The clarification in #1 makes sense to me. Regarding #2, I think updating the test code is better.

@prsunny prsunny requested a review from bingwang-ms October 13, 2021 21:44
prsunny
prsunny previously approved these changes Oct 14, 2021

// 15 is a typical value, but if vendor's SAI does not supply the maximum value,
// allow all 8-bit numbers, effectively cancelling validation by orchagent.
#define MIRROR_SESSION_DEFAULT_NUM_TC 255
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for explaining. Approving from my side. Lets wait for @bingwang-ms

Signed-off-by: Raphael Tryster <raphaelt@nvidia.com>
@prsunny prsunny merged commit 6b15584 into sonic-net:master Oct 18, 2021
volodymyrsamotiy pushed a commit to volodymyrsamotiy/sonic-swss that referenced this pull request Oct 20, 2021
…eter against maximum value from SAI (sonic-net#1957)

Signed-off-by: Raphael Tryster <raphaelt@nvidia.com>
judyjoseph pushed a commit that referenced this pull request Oct 21, 2021
…lue from SAI (#1957)

* Orchagent validates mirror session queue parameter against maximum value from SAI
Signed-off-by: Raphael Tryster <raphaelt@nvidia.com>
prsunny pushed a commit that referenced this pull request Jul 1, 2025
…#3712)

The PR is intended to provide a fix for the change #1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES attribute implementation in VS lib.

Due to the circular dependency, in order to have clean sonic-sairedis CI,
the current change should be merged first.
mssonicbld added a commit to mssonicbld/sonic-swss.msft that referenced this pull request Jul 12, 2025
<!--
Please make sure you have read and understood the contribution guildlines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

1. Make sure your commit includes a signature generted with `git commit -s`
2. Make sure your commit title follows the correct format: [component]: description
3. Make sure your commit message contains enough details about the change and related tests
4. Make sure your pull request adds related reviewers, asignees, labels

Please also provide the following information in this pull request:
-->

The PR is intended to provide a fix for the change sonic-net/sonic-swss#1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the `SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES` attribute implementation in VS lib.

Due to the circular dependency, in order to have clean `sonic-sairedis` CI,
the current change should be merged first.

**DEPENDS:**
1. sonic-net/sonic-sairedis#1610

**What I did**
* Updated mirror VS test

**Why I did it**
* To align the behaviour with a new VS lib implementation

**How I verified it**
1. Run VS test
```
root@sonic: tests# pytest --dvsname=vs --log-cli-level=info -vvv test_mirror_port_span.py
======================================================================== test session starts =========================================================================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /root/work/debug/trim/asym/sonic-swss/tests
plugins: flaky-3.7.0
collected 10 items

test_mirror_port_span.py::TestMirror::test_PortMirrorQueue PASSED                                                                                              [ 10%]
test_mirror_port_span.py::TestMirror::test_PortMirrorAddRemove PASSED                                                                                          [ 20%]
test_mirror_port_span.py::TestMirror::test_PortMirrorMultiSpanAddRemove PASSED                                                                                 [ 30%]
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerAddRemove PASSED                                                                                   [ 40%]
test_mirror_port_span.py::TestMirror::test_PortMultiMirrorPolicerAddRemove PASSED                                                                              [ 50%]
test_mirror_port_span.py::TestMirror::test_LAGMirrorSpanAddRemove PASSED                                                                                       [ 60%]
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerWithAcl PASSED                                                                                     [ 70%]
test_mirror_port_span.py::TestMirror::test_PortMirrorLAGPortSpanAddRemove PASSED                                                                               [ 80%]
test_mirror_port_span.py::TestMirror::test_PortLAGMirrorUpdateLAG PASSED                                                                                       [ 90%]
test_mirror_port_span.py::test_nonflaky_dummy PASSED                                                                                                           [100%]
```

**Details if related**
* N/A

#### A picture of a cute animal (not mandatory but encouraged)
```
      .---.        .-----------
     /     \  __  /    ------
    / /     \(  )/    -----
   //////   ' \/ `   ---
  //// / // :    : ---
 // /   /  /`    '--
//          //..\\
       ====UU====UU====
           '//||\\`
             ''``
```
mssonicbld added a commit to Azure/sonic-swss.msft that referenced this pull request Jul 12, 2025
…#103)

<!--
Please make sure you have read and understood the contribution guildlines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

1. Make sure your commit includes a signature generted with `git commit -s`
2. Make sure your commit title follows the correct format: [component]: description
3. Make sure your commit message contains enough details about the change and related tests
4. Make sure your pull request adds related reviewers, asignees, labels

Please also provide the following information in this pull request:
-->

The PR is intended to provide a fix for the change sonic-net/sonic-swss#1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the `SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES` attribute implementation in VS lib.

Due to the circular dependency, in order to have clean `sonic-sairedis` CI,
the current change should be merged first.

**DEPENDS:**
1. sonic-net/sonic-sairedis#1610

**What I did**
* Updated mirror VS test

**Why I did it**
* To align the behaviour with a new VS lib implementation

**How I verified it**
1. Run VS test
```
root@sonic: tests# pytest --dvsname=vs --log-cli-level=info -vvv test_mirror_port_span.py
======================================================================== test session starts =========================================================================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /root/work/debug/trim/asym/sonic-swss/tests
plugins: flaky-3.7.0
collected 10 items

test_mirror_port_span.py::TestMirror::test_PortMirrorQueue PASSED [ 10%]
test_mirror_port_span.py::TestMirror::test_PortMirrorAddRemove PASSED [ 20%]
test_mirror_port_span.py::TestMirror::test_PortMirrorMultiSpanAddRemove PASSED [ 30%]
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerAddRemove PASSED [ 40%]
test_mirror_port_span.py::TestMirror::test_PortMultiMirrorPolicerAddRemove PASSED [ 50%]
test_mirror_port_span.py::TestMirror::test_LAGMirrorSpanAddRemove PASSED [ 60%]
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerWithAcl PASSED [ 70%]
test_mirror_port_span.py::TestMirror::test_PortMirrorLAGPortSpanAddRemove PASSED [ 80%]
test_mirror_port_span.py::TestMirror::test_PortLAGMirrorUpdateLAG PASSED [ 90%]
test_mirror_port_span.py::test_nonflaky_dummy PASSED [100%]
```

**Details if related**
* N/A

#### A picture of a cute animal (not mandatory but encouraged)
```
 .---. .-----------
 / \ __ / ------
 / / \( )/ -----
 ////// ' \/ ` ---
 //// / // : : ---
 // / / /` '--
// //..\\
 ====UU====UU====
 '//||\\`
 ''``
```
mssonicbld added a commit to mssonicbld/sonic-swss that referenced this pull request Jul 14, 2025
<!--
Please make sure you have read and understood the contribution guildlines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

1. Make sure your commit includes a signature generted with `git commit -s`
2. Make sure your commit title follows the correct format: [component]: description
3. Make sure your commit message contains enough details about the change and related tests
4. Make sure your pull request adds related reviewers, asignees, labels

Please also provide the following information in this pull request:
-->

The PR is intended to provide a fix for the change sonic-net#1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the `SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES` attribute implementation in VS lib.

Due to the circular dependency, in order to have clean `sonic-sairedis` CI,
the current change should be merged first.

**DEPENDS:**
1. sonic-net/sonic-sairedis#1610

**What I did**
* Updated mirror VS test

**Why I did it**
* To align the behaviour with a new VS lib implementation

**How I verified it**
1. Run VS test
```
root@sonic: tests# pytest --dvsname=vs --log-cli-level=info -vvv test_mirror_port_span.py
======================================================================== test session starts =========================================================================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /root/work/debug/trim/asym/sonic-swss/tests
plugins: flaky-3.7.0
collected 10 items

test_mirror_port_span.py::TestMirror::test_PortMirrorQueue PASSED                                                                                              [ 10%]
test_mirror_port_span.py::TestMirror::test_PortMirrorAddRemove PASSED                                                                                          [ 20%]
test_mirror_port_span.py::TestMirror::test_PortMirrorMultiSpanAddRemove PASSED                                                                                 [ 30%]
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerAddRemove PASSED                                                                                   [ 40%]
test_mirror_port_span.py::TestMirror::test_PortMultiMirrorPolicerAddRemove PASSED                                                                              [ 50%]
test_mirror_port_span.py::TestMirror::test_LAGMirrorSpanAddRemove PASSED                                                                                       [ 60%]
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerWithAcl PASSED                                                                                     [ 70%]
test_mirror_port_span.py::TestMirror::test_PortMirrorLAGPortSpanAddRemove PASSED                                                                               [ 80%]
test_mirror_port_span.py::TestMirror::test_PortLAGMirrorUpdateLAG PASSED                                                                                       [ 90%]
test_mirror_port_span.py::test_nonflaky_dummy PASSED                                                                                                           [100%]
```

**Details if related**
* N/A

#### A picture of a cute animal (not mandatory but encouraged)
```
      .---.        .-----------
     /     \  __  /    ------
    / /     \(  )/    -----
   //////   ' \/ `   ---
  //// / // :    : ---
 // /   /  /`    '--
//          //..\\
       ====UU====UU====
           '//||\\`
             ''``
```
stepanblyschak pushed a commit to stepanblyschak/sonic-swss that referenced this pull request Jul 31, 2025
<!--
Please make sure you have read and understood the contribution guildlines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md

1. Make sure your commit includes a signature generted with `git commit -s`
2. Make sure your commit title follows the correct format: [component]: description
3. Make sure your commit message contains enough details about the change and related tests
4. Make sure your pull request adds related reviewers, asignees, labels

Please also provide the following information in this pull request:
-->

The PR is intended to provide a fix for the change sonic-net#1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the `SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES` attribute implementation in VS lib.

Due to the circular dependency, in order to have clean `sonic-sairedis` CI,
the current change should be merged first.

**DEPENDS:**
1. sonic-net/sonic-sairedis#1610

**What I did**
* Updated mirror VS test

**Why I did it**
* To align the behaviour with a new VS lib implementation

**How I verified it**
1. Run VS test
```
root@sonic: tests# pytest --dvsname=vs --log-cli-level=info -vvv test_mirror_port_span.py
======================================================================== test session starts =========================================================================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-0.13.1 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /root/work/debug/trim/asym/sonic-swss/tests
plugins: flaky-3.7.0
collected 10 items

test_mirror_port_span.py::TestMirror::test_PortMirrorQueue PASSED                                                                                              [ 10%]
test_mirror_port_span.py::TestMirror::test_PortMirrorAddRemove PASSED                                                                                          [ 20%]
test_mirror_port_span.py::TestMirror::test_PortMirrorMultiSpanAddRemove PASSED                                                                                 [ 30%]
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerAddRemove PASSED                                                                                   [ 40%]
test_mirror_port_span.py::TestMirror::test_PortMultiMirrorPolicerAddRemove PASSED                                                                              [ 50%]
test_mirror_port_span.py::TestMirror::test_LAGMirrorSpanAddRemove PASSED                                                                                       [ 60%]
test_mirror_port_span.py::TestMirror::test_PortMirrorPolicerWithAcl PASSED                                                                                     [ 70%]
test_mirror_port_span.py::TestMirror::test_PortMirrorLAGPortSpanAddRemove PASSED                                                                               [ 80%]
test_mirror_port_span.py::TestMirror::test_PortLAGMirrorUpdateLAG PASSED                                                                                       [ 90%]
test_mirror_port_span.py::test_nonflaky_dummy PASSED                                                                                                           [100%]
```

**Details if related**
* N/A

#### A picture of a cute animal (not mandatory but encouraged)
```
      .---.        .-----------
     /     \  __  /    ------
    / /     \(  )/    -----
   //////   ' \/ `   ---
  //// / // :    : ---
 // /   /  /`    '--
//          //..\\
       ====UU====UU====
           '//||\\`
             ''``
```
Janetxxx pushed a commit to Janetxxx/sonic-swss that referenced this pull request Nov 10, 2025
…lue from SAI (sonic-net#1957)

* Orchagent validates mirror session queue parameter against maximum value from SAI
Signed-off-by: Raphael Tryster <raphaelt@nvidia.com>
Janetxxx pushed a commit to Janetxxx/sonic-swss that referenced this pull request Nov 10, 2025
…sonic-net#3712)

The PR is intended to provide a fix for the change sonic-net#1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES attribute implementation in VS lib.

Due to the circular dependency, in order to have clean sonic-sairedis CI,
the current change should be merged first.
balanokia pushed a commit to balanokia/sonic-swss that referenced this pull request Nov 17, 2025
…sonic-net#3712)

The PR is intended to provide a fix for the change sonic-net#1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES attribute implementation in VS lib.

Due to the circular dependency, in order to have clean sonic-sairedis CI,
the current change should be merged first.
theasianpianist pushed a commit to theasianpianist/sonic-swss that referenced this pull request Feb 4, 2026
…sonic-net#3712)

The PR is intended to provide a fix for the change sonic-net#1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES attribute implementation in VS lib.

Due to the circular dependency, in order to have clean sonic-sairedis CI,
the current change should be merged first.

Signed-off-by: Lawrence Lee <lawlee@microsoft.com>
baorliu pushed a commit to baorliu/sonic-swss that referenced this pull request Feb 23, 2026
…sonic-net#3712)

The PR is intended to provide a fix for the change sonic-net#1957

The old test behavior relies on a hardcoded max TC value of 255. Now it needs to be updated following the SAI_SWITCH_ATTR_QOS_MAX_NUMBER_OF_TRAFFIC_CLASSES attribute implementation in VS lib.

Due to the circular dependency, in order to have clean sonic-sairedis CI,
the current change should be merged first.

Signed-off-by: Baorong Liu <96146196+baorliu@users.noreply.github.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.

[mirroring] Missing per-vendor validation of mirror session queue parameter

5 participants