Skip to content

Commit c5147b1

Browse files
committed
Updated the YANG model for ERSPAN mirror sessions
<!-- 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
1 parent c8bd83a commit c5147b1

3 files changed

Lines changed: 32 additions & 4 deletions

File tree

src/sonic-yang-models/tests/yang_model_tests/tests/mirror_session.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,24 @@
1414
"MIRROR_ERSPAN_ENTRY_WITH_VALID_DEC_VALUES_2": {
1515
"desc": "Configuring ERSPAN entry with valid decimal values."
1616
},
17+
"MIRROR_ERSPAN_ENTRY_WITH_VALID_IPV6_SRC_AND_DST_IP": {
18+
"desc": "Configuring ERSPAN entry with valid IPv6 source and destination IPs."
19+
},
1720
"MIRROR_ERSPAN_ENTRY_WRONG_TYPE": {
1821
"desc": "Configuring ERSPAN entry with invalid type",
1922
"eStrKey": "InvalidValue"
2023
},
2124
"MIRROR_ERSPAN_ENTRY_WRONG_DST_IP": {
2225
"desc": "Configuring ERSPAN entry with invalid dst_ip",
23-
"eStrKey" : "Pattern"
26+
"eStr" : "src_ip and dst_ip must have the same IP version."
2427
},
2528
"MIRROR_ERSPAN_ENTRY_WRONG_DST_IP_TYPE": {
2629
"desc": "Configuring ERSPAN entry with invalid dst_ip",
2730
"eStrKey" : "When"
2831
},
2932
"MIRROR_ERSPAN_ENTRY_WRONG_SRC_IP": {
3033
"desc": "Configuring ERSPAN entry with invalid src_ip",
31-
"eStrKey" : "Pattern"
34+
"eStr" : "src_ip and dst_ip must have the same IP version."
3235
},
3336
"MIRROR_ERSPAN_ENTRY_WRONG_SRC_IP_TYPE": {
3437
"desc": "Configuring ERSPAN entry with invalid src_ip",

src/sonic-yang-models/tests/yang_model_tests/tests_config/mirror_session.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,25 @@
7979
}
8080
}
8181
},
82+
"MIRROR_ERSPAN_ENTRY_WITH_VALID_IPV6_SRC_AND_DST_IP": {
83+
"sonic-mirror-session:sonic-mirror-session": {
84+
"MIRROR_SESSION": {
85+
"MIRROR_SESSION_LIST": [
86+
{
87+
"name": "erspan",
88+
"type": "ERSPAN",
89+
"dst_ip": "1001::1",
90+
"src_ip": "2002::2",
91+
"gre_type": "0x1234",
92+
"dscp": "10",
93+
"ttl": "64",
94+
"queue": "0",
95+
"direction": "RX"
96+
}
97+
]
98+
}
99+
}
100+
},
82101
"MIRROR_ERSPAN_ENTRY_WRONG_TYPE": {
83102
"sonic-mirror-session:sonic-mirror-session": {
84103
"MIRROR_SESSION": {

src/sonic-yang-models/yang-models/sonic-mirror-session.yang

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,21 @@ module sonic-mirror-session {
8282

8383
leaf src_ip {
8484
when "current()/../type = 'ERSPAN'";
85-
type inet:ipv4-address;
85+
must "(contains(current(), ':') and contains(../dst_ip, ':')) or (not(contains(current(), ':')) and not(contains(../dst_ip, ':')))" {
86+
error-message "src_ip and dst_ip must have the same IP version.";
87+
}
88+
type inet:ip-address;
8689
description
8790
"ERSPAN source ip. This IP will be set as source ip in
8891
outer header of mirrored frame ";
8992
}
9093

9194
leaf dst_ip {
9295
when "current()/../type = 'ERSPAN'";
93-
type inet:ipv4-address;
96+
must "(contains(current(), ':') and contains(../src_ip, ':')) or (not(contains(current(), ':')) and not(contains(../src_ip, ':')))" {
97+
error-message "src_ip and dst_ip must have the same IP version.";
98+
}
99+
type inet:ip-address;
94100
description
95101
"ERSPAN destination ip. Mirrored frames will be routed to this destination.
96102
This IP will be set as destination ip in outer header of mirrored frame ";

0 commit comments

Comments
 (0)