[action] [PR:22882] Updated the YANG model for ERSPAN mirror sessions#1682
Merged
mssonicbld merged 1 commit intoAzure:202412from Oct 2, 2025
Merged
Conversation
<!--
Please make sure you've read and understood our contributing guidelines:
https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md
** Make sure all your commits include a signature generated with `git commit -s` **
If this is a bug fix, make sure your description includes "fixes #xxxx", or
"closes #xxxx" or "resolves #xxxx"
Please provide the following information:
-->
#### Why I did it
[PR 3317](sonic-net/sonic-swss#3317) in sonic-swss enables configuration of IPv6 mirror sessions (in which both `src_ip` and `dst_ip` are IPv6 addresses). This PR updates the YANG model for ERSPAN mirror sessions so that IPv6 mirror sessions can be configured using the `config apply-patch` command.
##### Work item tracking
- Microsoft ADO **(number only)**: 33501400
#### How I did it
1. Changed the type of `src_ip` and `dst_ip` for ERSPAN mirror sessions to `ip-address` so that IPv6 addresses are also accepted.
2. Added a condition to ensure that both `src_ip` and `dst_ip` have the same IP version.
3. Added a test to verify that a mirror session with IPv6 `src_ip` and `dst_ip` can be successfully configured.
#### How to verify it
Use `config apply-patch` to configure an ERSPAN mirror session with IPv6 `src_ip` and `dst_ip` addresses. For example:
```
$ cat ./mirror_session.patch
[
{
"op": "add",
"path": "/MIRROR_SESSION",
"value": {
"test_session": {
"type": "ERSPAN",
"src_ip": "1001::1",
"dst_ip": "2002::2",
"gre_type": "0x8949",
"dscp": "8",
"ttl": "64",
"queue": "0",
"direction": "RX"
}
}
}
]
$ sudo config apply-patch ./mirror_session.patch
Patch Applier: localhost: Patch application starting.
Patch Applier: localhost: Patch: [{"op": "add", "path": "/MIRROR_SESSION", "value": {"test_session": {"type": "ERSPAN", "src_ip": "1001::1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX"}}}]
Patch Applier: localhost getting current config db.
Patch Applier: localhost: simulating the target full config after applying the patch.
Patch Applier: localhost: validating all JsonPatch operations are permitted on the specified fields
Patch Applier: localhost: validating target config does not have empty tables,
since they do not show up in ConfigDb.
Patch Applier: localhost: sorting patch updates.
Patch Applier: The localhost patch was converted into 1 change:
Patch Applier: localhost: applying 1 change in order:
Patch Applier: * [{"op": "add", "path": "/MIRROR_SESSION", "value": {"test_session": {"type": "ERSPAN", "src_ip": "1001::1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX"}}}]
Patch Applier: localhost: verifying patch updates are reflected on ConfigDB.
Patch Applier: localhost patch application completed.
Patch applied successfully.
$ show mirror_session
ERSPAN Sessions
Name Status SRC IP DST IP GRE DSCP TTL Queue Policer Monitor Port SRC Port Direction
------------ -------- -------- -------- ------ ------ ----- ------- --------- -------------- ---------- -----------
test_session active 1001::1 2002::2 0x8949 8 64 0 Ethernet104 rx
```
If `src_ip` and `dst_ip` have different IP versions, the `apply-patch` command should fail:
```
$ cat ./mirror_session.patch
[
{
"op": "add",
"path": "/MIRROR_SESSION",
"value": {
"invalid_session": {
"type": "ERSPAN",
"src_ip": "1.1.1.1",
"dst_ip": "2002::2",
"gre_type": "0x8949",
"dscp": "8",
"ttl": "64",
"queue": "0",
"direction": "RX"
}
}
}
]
$ sudo config apply-patch ./mirror_session.patch
libyang[0]: Must condition "(contains(current(), ':') and contains(../dst_ip, ':')) or (contains(current(), '.') and contains(../dst_ip, '.'))" not satisfied. (path: /sonic-mirror-session:sonic-mirror-session/MIRROR_SESSION/MIRROR_SESSION_LIST[name='invalid_session']/src_ip)
libyang[0]: src_ip and dst_ip must have the same IP version. (path: /sonic-mirror-session:sonic-mirror-session/MIRROR_SESSION/MIRROR_SESSION_LIST[name='invalid_session']/src_ip)
sonic_yang(3):Data Loading Failed:src_ip and dst_ip must have the same IP version.
Failed to apply patch due to: Validate json patch: [{"op": "add", "path": "/MIRROR_SESSION", "value": {"invalid_session": {"type": "ERSPAN", "src_ip": "1.1.1.1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX"}}}] failed due to:Data Loading Failed
src_ip and dst_ip must have the same IP version.
Usage: config apply-patch [OPTIONS] PATCH_FILE_PATH
Try "config apply-patch -h" for help.
Error: Validate json patch: [{"op": "add", "path": "/MIRROR_SESSION", "value": {"invalid_session": {"type": "ERSPAN", "src_ip": "1.1.1.1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX"}}}] failed due to:Data Loading Failed
src_ip and dst_ip must have the same IP version.
```
<!--
If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012.
-->
#### Which release branch to backport (provide reason below if selected)
<!--
- Note we only backport fixes to a release branch, *not* features!
- Please also provide a reason for the backporting below.
- e.g.
- [x] 202006
-->
- [ ] 202205
- [ ] 202211
- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
#### Tested branch (Please provide the tested image version)
<!--
- Please provide tested image version
- e.g.
- [x] 20201231.100
-->
- [x] 20250625.014807
#### Description for the changelog
<!--
Write a short (one line) summary that describes the changes in this
pull request for inclusion in the changelog:
-->
<!--
Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
-->
Updated the YANG model for ERSPAN mirror sessions to support IPv6 source and destination addresses.
#### Link to config_db schema for YANG module changes
<!--
Provide a link to config_db schema for the table for which YANG model
is defined
Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md
-->
https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#acl-and-mirroring
Collaborator
Author
|
Original PR: sonic-net/sonic-buildimage#22882 |
Collaborator
Author
|
/azp run |
8 tasks
|
Azure Pipelines successfully started running 1 pipeline(s). |
r12f
pushed a commit
that referenced
this pull request
Oct 26, 2025
…#1682) <!-- Please make sure you've read and understood our contributing guidelines: https://github.com/Azure/SONiC/blob/gh-pages/CONTRIBUTING.md failure_prs.log skip_prs.log Make sure all your commits include a signature generated with `git commit -s` ** If this is a bug fix, make sure your description includes "fixes #xxxx", or "closes #xxxx" or "resolves #xxxx" Please provide the following information: --> #### Why I did it [PR 3317](sonic-net/sonic-swss#3317) in sonic-swss enables configuration of IPv6 mirror sessions (in which both `src_ip` and `dst_ip` are IPv6 addresses). This PR updates the YANG model for ERSPAN mirror sessions so that IPv6 mirror sessions can be configured using the `config apply-patch` command. ##### Work item tracking - Microsoft ADO **(number only)**: 33501400 #### How I did it 1. Changed the type of `src_ip` and `dst_ip` for ERSPAN mirror sessions to `ip-address` so that IPv6 addresses are also accepted. 2. Added a condition to ensure that both `src_ip` and `dst_ip` have the same IP version. 3. Added a test to verify that a mirror session with IPv6 `src_ip` and `dst_ip` can be successfully configured. #### How to verify it Use `config apply-patch` to configure an ERSPAN mirror session with IPv6 `src_ip` and `dst_ip` addresses. For example: ``` $ cat ./mirror_session.patch [ { "op": "add", "path": "/MIRROR_SESSION", "value": { "test_session": { "type": "ERSPAN", "src_ip": "1001::1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX" } } } ] $ sudo config apply-patch ./mirror_session.patch Patch Applier: localhost: Patch application starting. Patch Applier: localhost: Patch: [{"op": "add", "path": "/MIRROR_SESSION", "value": {"test_session": {"type": "ERSPAN", "src_ip": "1001::1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX"}}}] Patch Applier: localhost getting current config db. Patch Applier: localhost: simulating the target full config after applying the patch. Patch Applier: localhost: validating all JsonPatch operations are permitted on the specified fields Patch Applier: localhost: validating target config does not have empty tables, since they do not show up in ConfigDb. Patch Applier: localhost: sorting patch updates. Patch Applier: The localhost patch was converted into 1 change: Patch Applier: localhost: applying 1 change in order: Patch Applier: failure_prs.log skip_prs.log [{"op": "add", "path": "/MIRROR_SESSION", "value": {"test_session": {"type": "ERSPAN", "src_ip": "1001::1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX"}}}] Patch Applier: localhost: verifying patch updates are reflected on ConfigDB. Patch Applier: localhost patch application completed. Patch applied successfully. $ show mirror_session ERSPAN Sessions Name Status SRC IP DST IP GRE DSCP TTL Queue Policer Monitor Port SRC Port Direction ------------ -------- -------- -------- ------ ------ ----- ------- --------- -------------- ---------- ----------- test_session active 1001::1 2002::2 0x8949 8 64 0 Ethernet104 rx ``` If `src_ip` and `dst_ip` have different IP versions, the `apply-patch` command should fail: ``` $ cat ./mirror_session.patch [ { "op": "add", "path": "/MIRROR_SESSION", "value": { "invalid_session": { "type": "ERSPAN", "src_ip": "1.1.1.1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX" } } } ] $ sudo config apply-patch ./mirror_session.patch libyang[0]: Must condition "(contains(current(), ':') and contains(../dst_ip, ':')) or (contains(current(), '.') and contains(../dst_ip, '.'))" not satisfied. (path: /sonic-mirror-session:sonic-mirror-session/MIRROR_SESSION/MIRROR_SESSION_LIST[name='invalid_session']/src_ip) libyang[0]: src_ip and dst_ip must have the same IP version. (path: /sonic-mirror-session:sonic-mirror-session/MIRROR_SESSION/MIRROR_SESSION_LIST[name='invalid_session']/src_ip) sonic_yang(3):Data Loading Failed:src_ip and dst_ip must have the same IP version. Failed to apply patch due to: Validate json patch: [{"op": "add", "path": "/MIRROR_SESSION", "value": {"invalid_session": {"type": "ERSPAN", "src_ip": "1.1.1.1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX"}}}] failed due to:Data Loading Failed src_ip and dst_ip must have the same IP version. Usage: config apply-patch [OPTIONS] PATCH_FILE_PATH Try "config apply-patch -h" for help. Error: Validate json patch: [{"op": "add", "path": "/MIRROR_SESSION", "value": {"invalid_session": {"type": "ERSPAN", "src_ip": "1.1.1.1", "dst_ip": "2002::2", "gre_type": "0x8949", "dscp": "8", "ttl": "64", "queue": "0", "direction": "RX"}}}] failed due to:Data Loading Failed src_ip and dst_ip must have the same IP version. ``` <!-- If PR needs to be backported, then the PR must be tested against the base branch and the earliest backport release branch and provide tested image version on these two branches. For example, if the PR is requested for master, 202211 and 202012, then the requester needs to provide test results on master and 202012. --> #### Which release branch to backport (provide reason below if selected) <!-- - Note we only backport fixes to a release branch, *not* features! - Please also provide a reason for the backporting below. - e.g. - [x] 202006 --> - [ ] 202205 - [ ] 202211 - [ ] 202305 - [ ] 202311 - [ ] 202405 - [ ] 202411 - [ ] 202505 #### Tested branch (Please provide the tested image version) <!-- - Please provide tested image version - e.g. - [x] 20201231.100 --> - [x] 20250625.014807 #### Description for the changelog <!-- Write a short (one line) summary that describes the changes in this pull request for inclusion in the changelog: --> <!-- Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU. --> Updated the YANG model for ERSPAN mirror sessions to support IPv6 source and destination addresses. #### Link to config_db schema for YANG module changes <!-- Provide a link to config_db schema for the table for which YANG model is defined Link should point to correct section on https://github.com/Azure/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md --> https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#acl-and-mirroring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why I did it
PR 3317 in sonic-swss enables configuration of IPv6 mirror sessions (in which both
src_ipanddst_ipare IPv6 addresses). This PR updates the YANG model for ERSPAN mirror sessions so that IPv6 mirror sessions can be configured using theconfig apply-patchcommand.Work item tracking
How I did it
src_ipanddst_ipfor ERSPAN mirror sessions toip-addressso that IPv6 addresses are also accepted.src_ipanddst_iphave the same IP version.src_ipanddst_ipcan be successfully configured.How to verify it
Use
config apply-patchto configure an ERSPAN mirror session with IPv6src_ipanddst_ipaddresses. For example:If
src_ipanddst_iphave different IP versions, theapply-patchcommand should fail:Which release branch to backport (provide reason below if selected)
Tested branch (Please provide the tested image version)
Description for the changelog
Updated the YANG model for ERSPAN mirror sessions to support IPv6 source and destination addresses.
Link to config_db schema for YANG module changes
https://github.com/sonic-net/sonic-buildimage/blob/master/src/sonic-yang-models/doc/Configuration.md#acl-and-mirroring