[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.
This commit is contained in:
Longxiang Lyu 2022-03-31 08:24:13 +08:00 committed by GitHub
parent b31df59c7c
commit 16766c0ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 255 additions and 5 deletions

View File

@ -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": {

View File

@ -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"

View File

@ -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": {

View File

@ -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 <portname>.<vlan_id>