From 16766c0ea4aff78bb8b749d31e6a2135386681f4 Mon Sep 17 00:00:00 2001 From: Longxiang Lyu <35479537+lolyu@users.noreply.github.com> Date: Thu, 31 Mar 2022 08:24:13 +0800 Subject: [PATCH] [YANG ] Support vlan sub intf short naming format (#10160) Why I did it To support vlan sub intf short naming format, like subport Eth8.100 for parent portEthernet8 with vlan id 100. How I did it Add checks to must condition to verify there is a port or portchannel with the index same as the vlan sub intf. How to verify it Run the unttests. --- .../tests/files/sample_config_db.json | 16 +- .../tests/vlan_sub_interface.json | 18 ++ .../tests_config/vlan_sub_interface.json | 214 ++++++++++++++++++ .../yang-models/sonic-vlan-sub-interface.yang | 12 +- 4 files changed, 255 insertions(+), 5 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 6415fb6100..d33cf20e20 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -900,11 +900,21 @@ } }, "VLAN_SUB_INTERFACE": { - "Ethernet120.10": { + "Ethernet12.10": { "admin_status": "up" }, - "Ethernet120.10|10.0.1.56/31": {}, - "Ethernet120.10|fc00::1:71/126": {} + "Ethernet12.10|10.0.1.56/31": {}, + "Ethernet12.10|fc00::1:71/126": {}, + "Po0003.10": { + "admin_status": "up" + }, + "Po0003.10|10.0.1.58/31": {}, + "Po0003.10|fc00::1:75/126": {}, + "Eth120.10": { + "admin_status": "up" + }, + "Eth120.10|10.0.1.60/31": {}, + "Eth120.10|fc00::1:79/126": {} }, "VLAN_MEMBER": { "Vlan111|Ethernet0": { 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 789b7ddd36..e3ffa9dc44 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 @@ -2,10 +2,28 @@ "VLAN_SUB_INTERFACE_MUST_CONDITION_TRUE_TEST": { "desc": "Configure valid vlan sub interface must condition true." }, + "VLAN_SUB_INTERFACE_SHORT_NAME_FORMAT_MUST_CONDITION_TRUE_TEST": { + "desc": "Configure valid short name format vlan sub interface must condition true." + }, "VLAN_SUB_INTERFACE_MUST_CONDITION_FALSE_TEST": { "desc": "Configure vlan sub interface must condition false.", "eStrKey": "Must" }, + "VLAN_SUB_INTERFACE_SHORT_NAME_FORMAT_MUST_CONDITION_FALSE_TEST": { + "desc": "Configure short name format vlan sub interface must condition false.", + "eStrKey": "Must" + }, + "VLAN_SUB_INTERFACE_PO_SHORT_NAME_FORMAT_MUST_CONDITION_TRUE_TEST": { + "desc": "Configure valid portchannel short name format vlan sub interface must condition true." + }, + "VLAN_SUB_INTERFACE_PO_MUST_CONDITION_FALSE_TEST": { + "desc": "Configure portchannel long name format vlan sub interface must condition false.", + "eStrKey": "Must" + }, + "VLAN_SUB_INTERFACE_PO_SHORT_NAME_FORMAT_MUST_CONDITION_FALSE_TEST": { + "desc": "Configure portchannel short name format vlan sub interface must condition false.", + "eStrKey": "Must" + }, "VLAN_SUB_INTERFACE_IP_PREFIX_PORT_NON_EXISTING_LEAF_TEST": { "desc": "Configure ip prefix vlan sub interface with non-existing reference.", "eStrKey": "LeafRef" 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 f95b1af8f0..8adff73e49 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 @@ -31,6 +31,38 @@ } } }, + "VLAN_SUB_INTERFACE_SHORT_NAME_FORMAT_MUST_CONDITION_TRUE_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 + } + ] + } + } + }, "VLAN_SUB_INTERFACE_MUST_CONDITION_FALSE_TEST": { "sonic-vlan-sub-interface:sonic-vlan-sub-interface": { "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { @@ -63,6 +95,188 @@ } } }, + "VLAN_SUB_INTERFACE_SHORT_NAME_FORMAT_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": "Ethernet12", + "admin_status": "up", + "alias": "Ethernet12/1", + "description": "Ethernet12", + "lanes": "49,50,51,52", + "mtu": 9000, + "speed": 100000 + } + ] + } + } + }, + "VLAN_SUB_INTERFACE_PO_SHORT_NAME_FORMAT_MUST_CONDITION_TRUE_TEST": { + "sonic-vlan-sub-interface:sonic-vlan-sub-interface": { + "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { + "VLAN_SUB_INTERFACE_LIST": [ + { + "name": "Po0001.10" + } + ], + "VLAN_SUB_INTERFACE_IPPREFIX_LIST": [ + { + "name": "Po0001.10", + "ip-prefix": "10.0.0.1/30" + } + ] + } + }, + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "tpid": "0x8100", + "speed": 25000 + } + ] + } + }, + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL": { + "PORTCHANNEL_LIST": [ + { + "admin_status": "up", + "members": [ + "Ethernet0" + ], + "min_links": "1", + "mtu": "9100", + "tpid": "0x8100", + "lacp_key": "auto", + "name": "PortChannel0001" + } + ] + } + } + }, + "VLAN_SUB_INTERFACE_PO_MUST_CONDITION_FALSE_TEST": { + "sonic-vlan-sub-interface:sonic-vlan-sub-interface": { + "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { + "VLAN_SUB_INTERFACE_LIST": [ + { + "name": "PortChannel0001.10" + } + ], + "VLAN_SUB_INTERFACE_IPPREFIX_LIST": [ + { + "name": "PortChannel0001.10", + "ip-prefix": "10.0.0.1/30" + } + ] + } + }, + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "tpid": "0x8100", + "speed": 25000 + } + ] + } + }, + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL": { + "PORTCHANNEL_LIST": [ + { + "admin_status": "up", + "members": [ + "Ethernet0" + ], + "min_links": "1", + "mtu": "9100", + "tpid": "0x8100", + "lacp_key": "auto", + "name": "PortChannel0001" + } + ] + } + } + }, + "VLAN_SUB_INTERFACE_PO_SHORT_NAME_FORMAT_MUST_CONDITION_FALSE_TEST": { + "sonic-vlan-sub-interface:sonic-vlan-sub-interface": { + "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { + "VLAN_SUB_INTERFACE_LIST": [ + { + "name": "Po0002.10" + } + ], + "VLAN_SUB_INTERFACE_IPPREFIX_LIST": [ + { + "name": "Po0002.10", + "ip-prefix": "10.0.0.1/30" + } + ] + } + }, + "sonic-port:sonic-port": { + "sonic-port:PORT": { + "PORT_LIST": [ + { + "admin_status": "up", + "alias": "eth0", + "description": "Ethernet0", + "lanes": "65", + "mtu": 9000, + "name": "Ethernet0", + "tpid": "0x8100", + "speed": 25000 + } + ] + } + }, + "sonic-portchannel:sonic-portchannel": { + "sonic-portchannel:PORTCHANNEL": { + "PORTCHANNEL_LIST": [ + { + "admin_status": "up", + "members": [ + "Ethernet0" + ], + "min_links": "1", + "mtu": "9100", + "tpid": "0x8100", + "lacp_key": "auto", + "name": "PortChannel0001" + } + ] + } + } + }, "VLAN_SUB_INTERFACE_IP_PREFIX_PORT_NON_EXISTING_LEAF_TEST": { "sonic-vlan-sub-interface:sonic-vlan-sub-interface": { "sonic-vlan-sub-interface:VLAN_SUB_INTERFACE": { 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 6ce391033a..953aa7e14c 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 @@ -14,6 +14,10 @@ module sonic-vlan-sub-interface { prefix port; } + import sonic-portchannel { + prefix lag; + } + import sonic-vrf { prefix vrf; } @@ -36,9 +40,13 @@ module sonic-vlan-sub-interface { key "name"; leaf name { - must "substring-before(current(), '.') = /port:sonic-port/port:PORT/port:PORT_LIST/port:name" + must "(substring-before(current(), '.') = /port:sonic-port/port:PORT/port:PORT_LIST/port:name) or " + + "(starts-with(substring-before(current(), '.'), 'Eth') and " + + "concat('Ethernet', substring-after(substring-before(current(), '.'), 'Eth')) = /port:sonic-port/port:PORT/port:PORT_LIST/port:name) or " + + "(starts-with(substring-before(current(), '.'), 'Po') and " + + "concat('PortChannel', substring-after(substring-before(current(), '.'), 'Po')) = /lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name)" { - error-message "Must condition not satisfied, Try adding PORT: {}, Example: 'Ethernet0': {}"; + error-message "Must condition not satisfied, please follow vlan sub interface naming convention"; } // check if the vlan sub interface have the form as .