From e104247950a1c38fa11d555c514a5c74e748b82c Mon Sep 17 00:00:00 2001 From: Vadym Hlushko <62022266+vadymhlushko-mlnx@users.noreply.github.com> Date: Thu, 3 Mar 2022 15:58:17 +0200 Subject: [PATCH] [nvgre] Added YANG model and tests (#10095) - Why I did it NVGRE Tunnel feature extends the Config DB with new tables. These tables require a new YANG model. - How I did it Added a new YANG model sonic-nvgre-tunnel.yang - How to verify it Added YANG test cases. Signed-off-by: Vadym Hlushko --- src/sonic-yang-models/setup.py | 2 + .../tests/files/sample_config_db.json | 21 ++- .../tests/yang_model_tests/tests/nvgre.json | 25 ++++ .../yang_model_tests/tests_config/nvgre.json | 125 ++++++++++++++++++ .../yang-models/sonic-nvgre-tunnel.yang | 109 +++++++++++++++ 5 files changed, 280 insertions(+), 2 deletions(-) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/nvgre.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/nvgre.json create mode 100644 src/sonic-yang-models/yang-models/sonic-nvgre-tunnel.yang diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index e0bacac194..d8b9a0d0c4 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -109,6 +109,7 @@ setup( './yang-models/sonic-mirror-session.yang', './yang-models/sonic-ntp.yang', './yang-models/sonic-nat.yang', + './yang-models/sonic-nvgre-tunnel.yang', './yang-models/sonic-pbh.yang', './yang-models/sonic-port.yang', './yang-models/sonic-policer.yang', @@ -167,6 +168,7 @@ setup( './cvlyang-models/sonic-mgmt_vrf.yang', './cvlyang-models/sonic-ntp.yang', './cvlyang-models/sonic-nat.yang', + './cvlyang-models/sonic-nvgre-tunnel.yang', './cvlyang-models/sonic-pbh.yang', './cvlyang-models/sonic-policer.yang', './cvlyang-models/sonic-port.yang', diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index 3a88898666..89a915e72b 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1562,7 +1562,7 @@ } }, - + "MCLAG_DOMAIN": { "123": { "source_ip": "12.1.1.1", @@ -1606,6 +1606,8 @@ } }, + + "POLICER": { "everflow_static_policer": { "meter_type": "bytes", @@ -1614,8 +1616,23 @@ "cbs": "12500000", "color": "aware", "red_packet_action": "drop" - } + } + }, + + + "NVGRE_TUNNEL": { + "tunnel_1": { + "src_ip": "10.0.0.1" + } + }, + "NVGRE_TUNNEL_MAP": { + "tunnel_1|Vlan111": { + "vlan_id": "111", + "vsid": "5000" + } } + + }, "SAMPLE_CONFIG_DB_UNKNOWN": { "UNKNOWN_TABLE": { diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/nvgre.json b/src/sonic-yang-models/tests/yang_model_tests/tests/nvgre.json new file mode 100644 index 0000000000..e776b0d906 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/nvgre.json @@ -0,0 +1,25 @@ +{ + "NVGRE_TUNNEL_AND_TUNNEL_MAP": { + "desc": "NVGRE_TUNNEL with NVGRE_TUNNEL_MAP" + }, + + "NVGRE_TUNNEL_INVALID_SRC_IP": { + "desc": "INVALID src_ip value for NVGRE_TUNNEL", + "eStrKey": "InvalidValue" + }, + + "NVGRE_TUNNEL_MAP_UNEXISTING_NVGRE_TUNNEL_NAME": { + "desc": "Unexisting NVGRE_TUNNEL", + "eStrKey": "LeafRef" + }, + + "NVGRE_TUNNEL_MAP_INVALID_VLAN_ID": { + "desc": "Invalid VLAN ID", + "eStrKey": "Pattern" + }, + + "NVGRE_TUNNEL_MAP_INVALID_VSID": { + "desc": "INVALID VSID value for NVGRE_TUNNEL_MAP", + "eStrKey": "Pattern" + } +} \ No newline at end of file diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/nvgre.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/nvgre.json new file mode 100644 index 0000000000..8c2588fa7d --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/nvgre.json @@ -0,0 +1,125 @@ +{ + "NVGRE_TUNNEL_AND_TUNNEL_MAP": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "name": "Vlan200" + } + ] + } + }, + "sonic-nvgre-tunnel:sonic-nvgre-tunnel": { + "sonic-nvgre-tunnel:NVGRE_TUNNEL": { + "NVGRE_TUNNEL_LIST": [ + { + "tunnel_name": "tunnel_1", + "src_ip": "10.0.0.1" + } + ] + }, + "sonic-nvgre-tunnel:NVGRE_TUNNEL_MAP": { + "NVGRE_TUNNEL_MAP_LIST": [ + { + "tunnel_name": "tunnel_1", + "tunnel_map_name": "Vlan200", + "vlan_id": 200, + "vsid": 5000 + } + ] + } + } + }, + + "NVGRE_TUNNEL_INVALID_SRC_IP": { + "sonic-nvgre-tunnel:sonic-nvgre-tunnel": { + "sonic-nvgre-tunnel:NVGRE_TUNNEL": { + "NVGRE_TUNNEL_LIST": [ + { + "tunnel_name": "tunnel_1", + "src_ip": "INVALID" + } + ] + } + } + }, + + "NVGRE_TUNNEL_MAP_UNEXISTING_NVGRE_TUNNEL_NAME": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "name": "Vlan200" + } + ] + } + }, + "sonic-nvgre-tunnel:sonic-nvgre-tunnel": { + "sonic-nvgre-tunnel:NVGRE_TUNNEL_MAP": { + "NVGRE_TUNNEL_MAP_LIST": [ + { + "tunnel_name": "INVALID", + "tunnel_map_name": "Vlan200", + "vlan_id": 200, + "vsid": 5000 + } + ] + } + } + }, + + "NVGRE_TUNNEL_MAP_INVALID_VLAN_ID": { + "sonic-nvgre-tunnel:sonic-nvgre-tunnel": { + "sonic-nvgre-tunnel:NVGRE_TUNNEL": { + "NVGRE_TUNNEL_LIST": [ + { + "tunnel_name": "tunnel_1", + "src_ip": "10.0.0.1" + } + ] + }, + "sonic-nvgre-tunnel:NVGRE_TUNNEL_MAP": { + "NVGRE_TUNNEL_MAP_LIST": [ + { + "tunnel_name": "tunnel_1", + "tunnel_map_name": "Vlan200", + "vlan_id": 5000, + "vsid": 5000 + } + ] + } + } + }, + + "NVGRE_TUNNEL_MAP_INVALID_VSID": { + "sonic-vlan:sonic-vlan": { + "sonic-vlan:VLAN": { + "VLAN_LIST": [ + { + "name": "Vlan200" + } + ] + } + }, + "sonic-nvgre-tunnel:sonic-nvgre-tunnel": { + "sonic-nvgre-tunnel:NVGRE_TUNNEL": { + "NVGRE_TUNNEL_LIST": [ + { + "tunnel_name": "tunnel_1", + "src_ip": "10.0.0.1" + } + ] + }, + "sonic-nvgre-tunnel:NVGRE_TUNNEL_MAP": { + "NVGRE_TUNNEL_MAP_LIST": [ + { + "tunnel_name": "tunnel_1", + "tunnel_map_name": "Vlan200", + "vlan_id": 200, + "vsid": 999999999 + } + ] + } + } + } +} \ No newline at end of file diff --git a/src/sonic-yang-models/yang-models/sonic-nvgre-tunnel.yang b/src/sonic-yang-models/yang-models/sonic-nvgre-tunnel.yang new file mode 100644 index 0000000000..b10c35d940 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-nvgre-tunnel.yang @@ -0,0 +1,109 @@ +module sonic-nvgre-tunnel { + + yang-version 1.1; + + namespace "http://github.com/Azure/sonic-nvgre-tunnel"; + prefix nvgre; + + import ietf-inet-types { + prefix inet; + } + + organization + "SONiC"; + + contact + "SONiC"; + + description + "NVGRE Tunnel YANG Module for SONiC OS"; + + revision 2021-10-31 { + description + "First Revision"; + } + + container sonic-nvgre-tunnel { + + container NVGRE_TUNNEL { + + description "NVGRE_TUNNEL part of config_db.json"; + + list NVGRE_TUNNEL_LIST { + + key "tunnel_name"; + + leaf tunnel_name { + description "NVGRE Tunnel name"; + + type string { + length 1..255; + } + } + + leaf src_ip { + description "Source IP address"; + + mandatory true; + type inet:ip-address; + } + + } + /* end of NVGRE_TUNNEL_LIST */ + + } + /* end of container NVGRE_TUNNEL */ + + container NVGRE_TUNNEL_MAP { + + description "NVGRE_TUNNEL_MAP part of config_db.json"; + + list NVGRE_TUNNEL_MAP_LIST { + + key "tunnel_name tunnel_map_name"; + + leaf tunnel_name { + description "NVGRE Tunnel name"; + + type leafref { + path /nvgre:sonic-nvgre-tunnel/nvgre:NVGRE_TUNNEL/nvgre:NVGRE_TUNNEL_LIST/nvgre:tunnel_name; + } + } + + leaf tunnel_map_name { + description "NVGRE Tunnel map name"; + + type string { + length 1..255; + } + } + + leaf vlan_id { + description "VLAN identifier"; + + mandatory true; + type uint16 { + range 1..4094; + } + } + + leaf vsid { + description "Virtual Subnet Identifier"; + + mandatory true; + type uint32 { + range 0..16777214; + } + } + + } + /* end of NVGRE_TUNNEL_MAP_LIST */ + + } + /* end of container NVGRE_TUNNEL_MAP */ + + } + /* end of container sonic-nvgre-tunnel */ + +} +/* end of module sonic-nvgre-tunnel */