Skip to content

Commit

Permalink
[yang] Update YANG model for mirror session to support decimal value …
Browse files Browse the repository at this point in the history
…for GRE type (sonic-net#10140)

#### Why I did it
PR  sonic-net/sonic-utilities#1825 added validation for the input of `config mirror session add`, and only decimal value is accepted.
An issue sonic-net#10096 was raised to suggest accepting HEX value as well, and the suggestion makes sense to me.

To accept HEX value for GRE type, and keep backward compatibility as well, I updated the YANG model to support both decimal and hexadecimal input for GRE type.

#### How I did it
Update the regex for GRE type.

#### How to verify it
Verified by UT
```
platform linux -- Python 3.9.2, pytest-6.0.2, py-1.10.0, pluggy-0.13.0
rootdir: /sonic/src/sonic-yang-models
plugins: pyfakefs-4.5.4, cov-2.10.1
collected 3 items                                                                                                                                                                                     

tests/test_sonic_yang_models.py ..                                                                                                                                                              [ 66%]
tests/yang_model_tests/test_yang_model.py .                                                                                                                                                     [100%]

========================================================================================== 3 passed in 2.53s ==========================================================================================
```

#### Description for the changelog
Update YANG model for mirror session to support decimal value for GRE type.
  • Loading branch information
bingwang-ms authored and Praveen Chaudhary committed Dec 23, 2022
1 parent 6f478c1 commit ef07f58
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"MIRROR_ERSPAN_ENTRY_WITH_VALID_VALUES": {
"desc": "Configuring ERSPAN entry with valid values."
"MIRROR_ERSPAN_ENTRY_WITH_VALID_HEX_VALUES": {
"desc": "Configuring ERSPAN entry with valid heximal values."
},
"MIRROR_ERSPAN_ENTRY_WITH_VALID_HEX_VALUES_1": {
"desc": "Configuring ERSPAN entry with valid heximal values."
},
"MIRROR_ERSPAN_ENTRY_WITH_VALID_DEC_VALUES": {
"desc": "Configuring ERSPAN entry with valid decimal values."
},
"MIRROR_ERSPAN_ENTRY_WITH_VALID_DEC_VALUES_1": {
"desc": "Configuring ERSPAN entry with valid decimal values."
},
"MIRROR_ERSPAN_ENTRY_WITH_VALID_DEC_VALUES_2": {
"desc": "Configuring ERSPAN entry with valid decimal values."
},
"MIRROR_ERSPAN_ENTRY_WRONG_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid type",
Expand All @@ -26,6 +38,14 @@
"desc": "Configurinng ERSPAN entry with invalid GRE type",
"eStrKey" : "Pattern"
},
"MIRROR_ERSPAN_ENTRY_WRONG_GRE_TYPE_1": {
"desc": "Configuring ERSPAN entry with invalid GRE type",
"eStrKey" : "Pattern"
},
"MIRROR_ERSPAN_ENTRY_WRONG_GRE_TYPE_2": {
"desc": "Configuring ERSPAN entry with invalid GRE type",
"eStrKey" : "Pattern"
},
"MIRROR_ERSPAN_ENTRY_GRE_WRONG_TYPE": {
"desc": "Configurinng ERSPAN entry with invalid GRE type",
"eStrKey" : "When"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"MIRROR_ERSPAN_ENTRY_WITH_VALID_VALUES": {
"MIRROR_ERSPAN_ENTRY_WITH_VALID_HEX_VALUES": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
Expand All @@ -15,6 +15,70 @@
}
}
},
"MIRROR_ERSPAN_ENTRY_WITH_VALID_HEX_VALUES_1": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0x0",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WITH_VALID_DEC_VALUES": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "1234",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WITH_VALID_DEC_VALUES_1": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "65535",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WITH_VALID_DEC_VALUES_2": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_TYPE": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
Expand Down Expand Up @@ -104,7 +168,39 @@
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "0",
"gre_type": "100000",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_GRE_TYPE_1": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "-1",
"dscp": "10"
}
]
}
}
},
"MIRROR_ERSPAN_ENTRY_WRONG_GRE_TYPE_2": {
"sonic-mirror-session:sonic-mirror-session": {
"MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [
{
"name": "erspan",
"type": "ERSPAN",
"dst_ip": "11.1.1.1",
"src_ip": "10.1.1.1",
"gre_type": "65536",
"dscp": "10"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module sonic-mirror-session {
leaf gre_type {
when "current()/../type = 'ERSPAN'";
type string {
pattern "0[xX][0-9a-fA-F]*";
pattern "0[xX][0-9a-fA-F]*|([0-9]|[1-5]?[0-9]{2,4}|6[1-4][0-9]{3}|65[1-4][0-9]{2}|655[1-2][0-9]|6553[0-5])";
length 1..6 {
error-message "Invalid GRE type";
error-app-tag gre-type-invalid;
Expand Down

0 comments on commit ef07f58

Please sign in to comment.