From 03fc34e56cbcb3d5fc31a6af62119c5b05150e16 Mon Sep 17 00:00:00 2001 From: mssonicbld <79238446+mssonicbld@users.noreply.github.com> Date: Mon, 7 Aug 2023 03:48:34 +0800 Subject: [PATCH] [YANG][vlan-sub-interface] Add `vlan` field (#15838) (#16057) --- .../tests/files/sample_config_db.json | 6 ++- .../tests/vlan_sub_interface.json | 4 ++ .../tests_config/vlan_sub_interface.json | 44 +++++++++++++++++-- .../yang-models/sonic-vlan-sub-interface.yang | 14 ++++++ 4 files changed, 62 insertions(+), 6 deletions(-) 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 1374908de8..90c87a4a8b 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1087,12 +1087,14 @@ "Ethernet12.10|10.0.1.56/31": {}, "Ethernet12.10|fc00::1:71/126": {}, "Po0003.10": { - "admin_status": "up" + "admin_status": "up", + "vlan": "10" }, "Po0003.10|10.0.1.58/31": {}, "Po0003.10|fc00::1:75/126": {}, "Eth120.10": { - "admin_status": "up" + "admin_status": "up", + "vlan": "10" }, "Eth120.10|10.0.1.60/31": {}, "Eth120.10|fc00::1:79/126": {} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/vlan_sub_interface.json b/src/sonic-yang-models/tests/yang_model_tests/tests/vlan_sub_interface.json index b91c8a94f3..52b3968d5d 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/vlan_sub_interface.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/vlan_sub_interface.json @@ -55,5 +55,9 @@ "desc": "INCORRECT LOOPBACK ACTION IN VLAN_SUB_INTERFACE TABLE.", "eStrKey" : "Pattern", "eStr": ["drop|forward"] + }, + "VLAN_SUB_INTERFACE_SHORT_NAME_FORMAT_VLAN_CHECK_MUST_CONDITION_FALSE_TEST": { + "desc": "Configure valid short name format vlan sub interface vlan must check condition false.", + "eStrKey": "Must" } } diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan_sub_interface.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan_sub_interface.json index 6f200ef4b7..bb3ba554e4 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan_sub_interface.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/vlan_sub_interface.json @@ -36,7 +36,8 @@ "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { "VLAN_SUB_INTERFACE_LIST": [ { - "name": "Eth8.10" + "name": "Eth8.10", + "vlan": 10 } ], "VLAN_SUB_INTERFACE_IPPREFIX_LIST": [ @@ -132,7 +133,8 @@ "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { "VLAN_SUB_INTERFACE_LIST": [ { - "name": "Eth8.10" + "name": "Eth8.10", + "vlan": 10 } ], "VLAN_SUB_INTERFACE_IPPREFIX_LIST": [ @@ -164,7 +166,8 @@ "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { "VLAN_SUB_INTERFACE_LIST": [ { - "name": "Po0001.10" + "name": "Po0001.10", + "vlan": 10 } ], "VLAN_SUB_INTERFACE_IPPREFIX_LIST": [ @@ -305,7 +308,8 @@ "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { "VLAN_SUB_INTERFACE_LIST": [ { - "name": "Po0002.10" + "name": "Po0002.10", + "vlan": 10 } ], "VLAN_SUB_INTERFACE_IPPREFIX_LIST": [ @@ -533,5 +537,37 @@ ] } } + }, + "VLAN_SUB_INTERFACE_SHORT_NAME_FORMAT_VLAN_CHECK_MUST_CONDITION_FALSE_TEST": { + "sonic-vlan-sub-interface:sonic-vlan-sub-interface": { + "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { + "VLAN_SUB_INTERFACE_LIST": [ + { + "name": "Eth8.10" + } + ], + "VLAN_SUB_INTERFACE_IPPREFIX_LIST": [ + { + "name": "Eth8.10", + "ip-prefix": "10.0.0.1/30" + } + ] + } + }, + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "name": "Ethernet8", + "admin_status": "up", + "alias": "Ethernet8/1", + "description": "Ethernet8", + "lanes": "45,46,47,48", + "mtu": 9000, + "speed": 100000 + } + ] + } + } } } diff --git a/src/sonic-yang-models/yang-models/sonic-vlan-sub-interface.yang b/src/sonic-yang-models/yang-models/sonic-vlan-sub-interface.yang index 5a7f02c751..37e5f47a10 100644 --- a/src/sonic-yang-models/yang-models/sonic-vlan-sub-interface.yang +++ b/src/sonic-yang-models/yang-models/sonic-vlan-sub-interface.yang @@ -37,6 +37,14 @@ module sonic-vlan-sub-interface { description "VLAN_SUB_INTERFACE part of config_db.json with vrf"; + // encap vlan is mandatory for short name subinterfaces + must "(substring-before(name, '.') = /port:sonic-port/port:PORT/port:PORT_LIST/port:name) or " + + "(substring-before(name, '.') = /lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name) or " + + "vlan" + { + error-message "Must condition not satisfied, no encap vlan provided for short-name format vlan sub interface"; + } + key "name"; leaf name { @@ -70,6 +78,12 @@ module sonic-vlan-sub-interface { description "Packet action when a packet ingress and gets routed on the same IP interface"; type stypes:loopback_action; } + + leaf vlan { + type uint16 { + range 1..4094; + } + } } list VLAN_SUB_INTERFACE_IPPREFIX_LIST {