Skip to content

[action] [PR:22882] Updated the YANG model for ERSPAN mirror sessions#1682

Merged
mssonicbld merged 1 commit intoAzure:202412from
mssonicbld:cherry/msft-202412/22882
Oct 2, 2025
Merged

[action] [PR:22882] Updated the YANG model for ERSPAN mirror sessions#1682
mssonicbld merged 1 commit intoAzure:202412from
mssonicbld:cherry/msft-202412/22882

Conversation

@mssonicbld
Copy link
Collaborator

Why I did it

PR 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.

Which release branch to backport (provide reason below if selected)

  • 202205
  • 202211
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505

Tested branch (Please provide the tested image version)

  • 20250625.014807

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

<!--
     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
@mssonicbld
Copy link
Collaborator Author

Original PR: sonic-net/sonic-buildimage#22882

@mssonicbld
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld mssonicbld merged commit 3e4e0e9 into Azure:202412 Oct 2, 2025
17 checks passed
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
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.

1 participant