Skip to content

Updated the YANG model for ERSPAN mirror sessions#22882

Merged
qiluo-msft merged 6 commits intosonic-net:masterfrom
mramezani95:mramezani/update_mirror_session_yang_model
Jul 3, 2025
Merged

Updated the YANG model for ERSPAN mirror sessions#22882
qiluo-msft merged 6 commits intosonic-net:masterfrom
mramezani95:mramezani/update_mirror_session_yang_model

Conversation

@mramezani95
Copy link
Contributor

@mramezani95 mramezani95 commented Jun 7, 2025

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

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…ion. Also added a test in which src_ip and dst_ip are both IPv6 addresses.

Signed-off-by: Mahdi Ramezani <[email protected]>
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Signed-off-by: Mahdi Ramezani <[email protected]>
@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mramezani95 mramezani95 changed the title Updated the YANG model for mirror sessions Updated the YANG model for ERSPAN mirror sessions Jun 25, 2025
@mramezani95 mramezani95 marked this pull request as ready for review June 25, 2025 07:12
@mramezani95 mramezani95 requested a review from qiluo-msft as a code owner June 25, 2025 07:12
@mramezani95
Copy link
Contributor Author

/azpw ms_conflict

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@wen587 wen587 left a comment

Choose a reason for hiding this comment

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

lgtm

@qiluo-msft qiluo-msft merged commit 1da5d5a into sonic-net:master Jul 3, 2025
19 of 20 checks passed
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202505: #23310

@mssonicbld
Copy link
Collaborator

Cherry-pick PR to msft-202412: Azure/sonic-buildimage-msft#1682

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.

7 participants