This commit is contained in:
Mati Alfaro 2024-03-25 13:31:07 -07:00 committed by GitHub
commit 43fb0deda9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 325 additions and 33 deletions

View File

@ -142,7 +142,7 @@
</VlanInterface> </VlanInterface>
<VlanInterface> <VlanInterface>
<Name>ab2</Name> <Name>ab2</Name>
<AttachTo>fortyGigE0/4</AttachTo> <AttachTo>PortChannel01</AttachTo>
<DhcpRelays>192.0.0.1</DhcpRelays> <DhcpRelays>192.0.0.1</DhcpRelays>
<Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays> <Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays>
<VlanID>2000</VlanID> <VlanID>2000</VlanID>

View File

@ -142,7 +142,7 @@
</VlanInterface> </VlanInterface>
<VlanInterface> <VlanInterface>
<Name>ab2</Name> <Name>ab2</Name>
<AttachTo>fortyGigE0/4</AttachTo> <AttachTo>PortChannel01</AttachTo>
<DhcpRelays>192.0.0.1</DhcpRelays> <DhcpRelays>192.0.0.1</DhcpRelays>
<Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays> <Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays>
<VlanID>2000</VlanID> <VlanID>2000</VlanID>

View File

@ -142,7 +142,7 @@
</VlanInterface> </VlanInterface>
<VlanInterface> <VlanInterface>
<Name>ab2</Name> <Name>ab2</Name>
<AttachTo>fortyGigE0/4</AttachTo> <AttachTo>PortChannel01</AttachTo>
<DhcpRelays>192.0.0.1</DhcpRelays> <DhcpRelays>192.0.0.1</DhcpRelays>
<Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays> <Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays>
<VlanID>2000</VlanID> <VlanID>2000</VlanID>

View File

@ -143,7 +143,7 @@
</VlanInterface> </VlanInterface>
<VlanInterface> <VlanInterface>
<Name>ab2</Name> <Name>ab2</Name>
<AttachTo>fortyGigE0/4</AttachTo> <AttachTo>PortChannel01</AttachTo>
<DhcpRelays>192.0.0.1</DhcpRelays> <DhcpRelays>192.0.0.1</DhcpRelays>
<Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays> <Dhcpv6Relays>fc02:2000::3;fc02:2000::4</Dhcpv6Relays>
<VlanID>2000</VlanID> <VlanID>2000</VlanID>

View File

@ -281,7 +281,7 @@
</VlanInterface> </VlanInterface>
<VlanInterface> <VlanInterface>
<Name>Vlan2000</Name> <Name>Vlan2000</Name>
<AttachTo>fortyGigE0/112;fortyGigE0/116;fortyGigE0/120</AttachTo> <AttachTo>PortChannel01;PortChannel02;PortChannel03</AttachTo>
<NoDhcpRelay>False</NoDhcpRelay> <NoDhcpRelay>False</NoDhcpRelay>
<StaticDHCPRelay>0.0.0.0/0</StaticDHCPRelay> <StaticDHCPRelay>0.0.0.0/0</StaticDHCPRelay>
<FhrpProtoType i:nil="true"/> <FhrpProtoType i:nil="true"/>

View File

@ -265,7 +265,7 @@
</VlanInterface> </VlanInterface>
<VlanInterface> <VlanInterface>
<Name>Vlan2000</Name> <Name>Vlan2000</Name>
<AttachTo>fortyGigE0/112;fortyGigE0/116;fortyGigE0/120</AttachTo> <AttachTo>PortChannel01;PortChannel02;PortChannel03</AttachTo>
<NoDhcpRelay>False</NoDhcpRelay> <NoDhcpRelay>False</NoDhcpRelay>
<StaticDHCPRelay>0.0.0.0/0</StaticDHCPRelay> <StaticDHCPRelay>0.0.0.0/0</StaticDHCPRelay>
<FhrpProtoType i:nil="true"/> <FhrpProtoType i:nil="true"/>

View File

@ -129,7 +129,7 @@ class TestCfgGenCaseInsensitive(TestCase):
output = self.run_script(argument) output = self.run_script(argument)
expected = { expected = {
'Vlan1000|Ethernet8': {'tagging_mode': 'untagged'}, 'Vlan1000|Ethernet8': {'tagging_mode': 'untagged'},
'Vlan2000|Ethernet4': {'tagging_mode': 'untagged'} 'Vlan2000|PortChannel01': {'tagging_mode': 'untagged'}
} }
self.assertEqual( self.assertEqual(
utils.to_dict(output.strip()), utils.to_dict(output.strip()),

View File

@ -1185,10 +1185,7 @@
"Vlan111|Ethernet0": { "Vlan111|Ethernet0": {
"tagging_mode": "untagged" "tagging_mode": "untagged"
}, },
"Vlan111|Ethernet1": { "Vlan111|PortChannel0004": {
"tagging_mode": "untagged"
},
"Vlan111|Ethernet2": {
"tagging_mode": "untagged" "tagging_mode": "untagged"
}, },
"Vlan111|Ethernet3": { "Vlan111|Ethernet3": {
@ -2262,7 +2259,7 @@
"span": { "span": {
"direction": "RX", "direction": "RX",
"type": "SPAN", "type": "SPAN",
"dst_port": "Ethernet2", "dst_port": "Ethernet7",
"src_port": "Ethernet3,Ethernet4" "src_port": "Ethernet3,Ethernet4"
} }
}, },

View File

@ -234,8 +234,8 @@ class Test_yang_models:
desc = self.SpecialTests[test]['desc'] desc = self.SpecialTests[test]['desc']
self.logStartTest(desc) self.logStartTest(desc)
jInput = json.loads(self.readJsonInput(test)) jInput = json.loads(self.readJsonInput(test))
# check all Vlan from 1 to 4094 # check all Vlan from 2 to 4094
for i in range(4095): for i in range(2,4095):
vlan = 'Vlan'+str(i) vlan = 'Vlan'+str(i)
jInput["sonic-vlan:sonic-vlan"]["sonic-vlan:VLAN"]["VLAN_LIST"]\ jInput["sonic-vlan:sonic-vlan"]["sonic-vlan:VLAN"]["VLAN_LIST"]\
[0]["name"] = vlan [0]["name"] = vlan

View File

@ -86,5 +86,33 @@
"VLAN_INTERFACE_INVALID_ENABLE_IPV6_LINK_LOCAL": { "VLAN_INTERFACE_INVALID_ENABLE_IPV6_LINK_LOCAL": {
"desc": "Enable the ipv6 link-local as true.", "desc": "Enable the ipv6 link-local as true.",
"eStr": "Invalid value \"true\" in \"ipv6_use_link_local_only\" element." "eStr": "Invalid value \"true\" in \"ipv6_use_link_local_only\" element."
},
"VLAN_MEMBERS_WITHOUT_CREATING_VLAN":{
"desc": "Vlan members without Creating Vlan",
"eStrKey": "LeafRef"
},
"VLAN_CREATE_VLAN_WITH_MISSMATCHING_NAME": {
"desc": "Create Vlan so that name doesn't match id",
"eStr": "The vlanid must correspond to the VLAN name"
},
"IP_PREFIX_WITHOUT_CREATNG_VLAN": {
"desc": "Create IP on not created Vlan",
"eStrKey": "LeafRef"
},
"MIRROR_SESSION_ON_VLAN_MEMBER_PORT": {
"desc": "Set mirror dst port to a Vlan member",
"eStr": "Port is used as a destination port in a mirror session"
},
"VLAN_ADD_PORT_CHANNEL_MEMBER": {
"desc": "Add port channel member to Vlan",
"eStr": "Port is a member of a port channel"
},
"VLAN_ADD_PORT_THAT_IS_UNTAGGED": {
"desc": "Add port that is already untagged",
"eStr": "Port can be untagged in at most one VLAN"
},
"VLAN_ADD_PORT_THAT_IS_ROUTER_INTERFACE": {
"desc": "Add to Vlan port that is router interface",
"eStr": "Port is a router interface"
} }
} }

View File

@ -719,5 +719,248 @@
] ]
} }
} }
},
"VLAN_MEMBERS_WITHOUT_CREATING_VLAN": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"admin_status": "up",
"name": "Ethernet0"
}
]
}
},
"sonic-vlan:sonic-vlan": {
"sonic-vlan:VLAN_MEMBER": {
"VLAN_MEMBER_LIST": [
{
"port": "Ethernet0",
"tagging_mode": "tagged",
"name": "Vlan100"
}
]
}
}
},
"VLAN_CREATE_VLAN_WITH_MISSMATCHING_NAME": {
"sonic-vlan:sonic-vlan": {
"sonic-vlan:VLAN": {
"VLAN_LIST": [
{
"name": "Vlan10",
"vlanid":11
}
]
}
}
},
"IP_PREFIX_WITHOUT_CREATNG_VLAN": {
"sonic-vlan:sonic-vlan": {
"sonic-vlan:VLAN": {
"VLAN_LIST": [
{
"description": "server_vlan",
"name": "Vlan10"
}
]
},
"sonic-vlan:VLAN_INTERFACE": {
"VLAN_INTERFACE_IPPREFIX_LIST": [
{
"family": "IPv4",
"ip-prefix": "20.0.0.1/24",
"scope": "global",
"name": "Vlan100"
}
],
"VLAN_INTERFACE_LIST": [
{
"name": "Vlan100"
}
]
}
}
},
"MIRROR_SESSION_ON_VLAN_MEMBER_PORT": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [
{
"admin_status": "up",
"name": "Ethernet1",
"speed": 25000,
"lanes": "1"
},
{
"admin_status": "up",
"name": "Ethernet2",
"speed": 25000,
"lanes": "1"
}
]
}
},
"sonic-vlan:sonic-vlan": {
"sonic-vlan:VLAN": {
"VLAN_LIST": [
{
"name": "Vlan10"
}
]
},
"sonic-vlan:VLAN_MEMBER": {
"VLAN_MEMBER_LIST": [
{
"port": "Ethernet2",
"tagging_mode": "tagged",
"name": "Vlan10"
}
]
}
},
"sonic-mirror-session:sonic-mirror-session": {
"sonic-mirror-session:MIRROR_SESSION": {
"MIRROR_SESSION_LIST": [ {
"name":"mirror_session_dscp",
"type": "SPAN",
"src_port": "Ethernet1",
"dst_port": "Ethernet2"
}]
}
}
},
"VLAN_ADD_PORT_CHANNEL_MEMBER": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [{
"admin_status": "up",
"name": "Ethernet1",
"speed": 25000,
"lanes": "1"
}]
}
},
"sonic-portchannel:sonic-portchannel": {
"sonic-portchannel:PORTCHANNEL": {
"PORTCHANNEL_LIST": [
{
"admin_status": "up",
"min_links": "1",
"mtu": "9100",
"tpid": "0x8100",
"lacp_key": "auto",
"name": "PortChannel0001",
"fast_rate": "false",
"fallback" : "false",
"mode" : "routed"
}
]
},
"sonic-portchannel:PORTCHANNEL_MEMBER": {
"PORTCHANNEL_MEMBER_LIST": [
{
"name": "PortChannel0001",
"port": "Ethernet1"
}
]
}
},
"sonic-vlan:sonic-vlan": {
"sonic-vlan:VLAN": {
"VLAN_LIST": [
{
"name": "Vlan10"
}
]
},
"sonic-vlan:VLAN_MEMBER": {
"VLAN_MEMBER_LIST": [
{
"port": "Ethernet1",
"tagging_mode": "tagged",
"name": "Vlan10"
}
]
}
}
},
"VLAN_ADD_PORT_THAT_IS_UNTAGGED": {
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [{
"admin_status": "up",
"name": "Ethernet1",
"speed": 25000,
"lanes": "1"
}]
}
},
"sonic-vlan:sonic-vlan": {
"sonic-vlan:VLAN": {
"VLAN_LIST": [
{
"name": "Vlan10"
},
{
"name": "Vlan11"
}
]
},
"sonic-vlan:VLAN_MEMBER": {
"VLAN_MEMBER_LIST": [
{
"port": "Ethernet1",
"tagging_mode": "untagged",
"name": "Vlan10"
},
{
"port": "Ethernet1",
"tagging_mode": "untagged",
"name": "Vlan11"
}
]
}
}
},
"VLAN_ADD_PORT_THAT_IS_ROUTER_INTERFACE": {
"sonic-interface:sonic-interface": {
"sonic-interface:INTERFACE": {
"INTERFACE_LIST": [
{
"name": "Ethernet1"
}
]
}
},
"sonic-port:sonic-port": {
"sonic-port:PORT": {
"PORT_LIST": [{
"admin_status": "up",
"name": "Ethernet1",
"speed": 25000,
"lanes": "1"
}]
}
},
"sonic-vlan:sonic-vlan": {
"sonic-vlan:VLAN": {
"VLAN_LIST": [
{
"name": "Vlan10"
}
]
},
"sonic-vlan:VLAN_MEMBER": {
"VLAN_MEMBER_LIST": [
{
"port": "Ethernet1",
"tagging_mode": "untagged",
"name": "Vlan10"
}
]
}
}
} }
} }

View File

@ -34,8 +34,19 @@ module sonic-vlan {
prefix vrf; prefix vrf;
} }
import sonic-mirror-session {
prefix sms;
}
import sonic-interface {
prefix intf;
}
description "VLAN yang Module for SONiC OS"; description "VLAN yang Module for SONiC OS";
revision 2024-03-07 {
description "Add Constraints that are implemented in CLI";
}
revision 2021-04-22 { revision 2021-04-22 {
description "Modify Vlan Member to include PortChannel along with Port"; description "Modify Vlan Member to include PortChannel along with Port";
} }
@ -62,7 +73,7 @@ module sonic-vlan {
leaf name { leaf name {
type leafref { type leafref {
path /vlan:sonic-vlan/vlan:VLAN/vlan:VLAN_LIST/vlan:name; path "/vlan:sonic-vlan/vlan:VLAN/vlan:VLAN_LIST/vlan:name";
} }
} }
@ -164,7 +175,7 @@ module sonic-vlan {
type boolean; type boolean;
} }
} }
/* end of VLAN_INTERFACE_LIST */ /* end of VLAN_INTERFACE_IPPREFIX_LIST */
} }
/* end of VLAN_INTERFACE container */ /* end of VLAN_INTERFACE container */
@ -178,13 +189,15 @@ module sonic-vlan {
leaf name { leaf name {
type string { type string {
pattern 'Vlan([0-9]{1,3}|[1-3][0-9]{3}|[4][0][0-8][0-9]|[4][0][9][0-4])'; pattern 'Vlan(409[0-5]|40[0-8][0-9]|[1-3][0-9]{3}|[1-9][0-9]{2}|[1-9][0-9]|[2-9])';
} }
} }
leaf vlanid { leaf vlanid {
type uint16 { type uint16 {
range 1..4094; range 2..4094;
}
must "substring-after(../name, 'Vlan') = current()"{
error-message "The vlanid must correspond to the VLAN name";
} }
} }
@ -239,7 +252,6 @@ module sonic-vlan {
path "/vlan:sonic-vlan/vlan:VLAN/vlan:VLAN_LIST/vlan:name"; path "/vlan:sonic-vlan/vlan:VLAN/vlan:VLAN_LIST/vlan:name";
} }
} }
leaf port { leaf port {
/* key elements are mandatory by default */ /* key elements are mandatory by default */
type union { type union {
@ -250,8 +262,20 @@ module sonic-vlan {
path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name"; path "/lag:sonic-portchannel/lag:PORTCHANNEL/lag:PORTCHANNEL_LIST/lag:name";
} }
} }
must "not(/sms:sonic-mirror-session/sms:MIRROR_SESSION/sms:MIRROR_SESSION_LIST[sms:dst_port=current()])"
{
error-message "Port is used as a destination port in a mirror session.";
}
must "not(/lag:sonic-portchannel/lag:PORTCHANNEL_MEMBER/lag:PORTCHANNEL_MEMBER_LIST[lag:port=current()]/lag:name)" {
error-message "Port is a member of a port channel.";
}
must "not(/intf:sonic-interface/intf:INTERFACE/intf:INTERFACE_LIST[intf:name=current()])" {
error-message "Port is a router interface.";
}
must "count(../../vlan:VLAN_MEMBER_LIST[vlan:port=current() and vlan:tagging_mode='untagged']) <= 1" {
error-message "Port can be untagged in at most one VLAN.";
}
} }
leaf tagging_mode { leaf tagging_mode {
mandatory true; mandatory true;
type stypes:vlan_tagging_mode; type stypes:vlan_tagging_mode;