[minigraph] Support tagged VlanInterface if attached to multiple vlans (#6833)
It is possible that one interface attaches multiple vlans. The VlanInterface should be in tagged mode. Signed-off-by: Qi Luo <qiluo-msft@users.noreply.github.com>
This commit is contained in:
parent
5aba5cc68b
commit
c8ed3676ab
@ -526,6 +526,13 @@ def parse_dpg(dpg, hname):
|
||||
vlans = {}
|
||||
vlan_members = {}
|
||||
vlantype_name = ""
|
||||
intf_vlan_mbr = defaultdict(list)
|
||||
for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))):
|
||||
vlanid = vintf.find(str(QName(ns, "VlanID"))).text
|
||||
vintfmbr = vintf.find(str(QName(ns, "AttachTo"))).text
|
||||
vmbr_list = vintfmbr.split(';')
|
||||
for i, member in enumerate(vmbr_list):
|
||||
intf_vlan_mbr[member].append(vlanid)
|
||||
for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))):
|
||||
vintfname = vintf.find(str(QName(ns, "Name"))).text
|
||||
vlanid = vintf.find(str(QName(ns, "VlanID"))).text
|
||||
@ -539,6 +546,8 @@ def parse_dpg(dpg, hname):
|
||||
sonic_vlan_member_name = "Vlan%s" % (vlanid)
|
||||
if vlantype_name == "Tagged":
|
||||
vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'tagged'}
|
||||
elif len(intf_vlan_mbr[member]) > 1:
|
||||
vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'tagged'}
|
||||
else:
|
||||
vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'untagged'}
|
||||
|
||||
|
@ -173,6 +173,22 @@
|
||||
<Type>Tagged</Type>
|
||||
<Subnets>192.168.0.0/28</Subnets>
|
||||
</VlanInterface>
|
||||
<VlanInterface>
|
||||
<Name>ab2</Name>
|
||||
<AttachTo>fortyGigE0/12</AttachTo>
|
||||
<DhcpRelays>192.0.0.1;192.0.0.2</DhcpRelays>
|
||||
<VlanID>2000</VlanID>
|
||||
<Tag>2000</Tag>
|
||||
<Subnets>192.168.0.240/27</Subnets>
|
||||
</VlanInterface>
|
||||
<VlanInterface>
|
||||
<Name>ab3</Name>
|
||||
<AttachTo>fortyGigE0/12</AttachTo>
|
||||
<DhcpRelays>192.0.0.1;192.0.0.2</DhcpRelays>
|
||||
<VlanID>2001</VlanID>
|
||||
<Tag>2001</Tag>
|
||||
<Subnets>192.168.0.240/27</Subnets>
|
||||
</VlanInterface>
|
||||
</VlanInterfaces>
|
||||
<IPInterfaces>
|
||||
<IPInterface>
|
||||
|
@ -121,6 +121,8 @@ class TestCfgGen(TestCase):
|
||||
utils.to_dict(output.strip()),
|
||||
utils.to_dict(
|
||||
'{\n "Vlan1000|Ethernet8": {\n "tagging_mode": "untagged"\n },'
|
||||
' \n "Vlan2000|Ethernet12": {\n "tagging_mode": "tagged"\n },'
|
||||
' \n "Vlan2001|Ethernet12": {\n "tagging_mode": "tagged"\n },'
|
||||
' \n "Vlan2020|Ethernet12": {\n "tagging_mode": "tagged"\n }\n}'
|
||||
)
|
||||
)
|
||||
@ -206,6 +208,8 @@ class TestCfgGen(TestCase):
|
||||
utils.to_dict(output.strip()),
|
||||
utils.to_dict(
|
||||
"{'Vlan1000': {'alias': 'ab1', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '1000'}, "
|
||||
"'Vlan2001': {'alias': 'ab3', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '2001'},"
|
||||
"'Vlan2000': {'alias': 'ab2', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '2000'},"
|
||||
"'Vlan2020': {'alias': 'kk1', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '2020'}}"
|
||||
)
|
||||
)
|
||||
@ -214,9 +218,13 @@ class TestCfgGen(TestCase):
|
||||
argument = '-m "' + self.sample_graph_simple + '" -p "' + self.port_config + '" -v VLAN_MEMBER'
|
||||
output = self.run_script(argument)
|
||||
self.assertEqual(
|
||||
output.strip(),
|
||||
"{('Vlan1000', 'Ethernet8'): {'tagging_mode': 'untagged'}, "
|
||||
"('Vlan2020', 'Ethernet12'): {'tagging_mode': 'tagged'}}"
|
||||
utils.to_dict(output.strip()),
|
||||
utils.to_dict(
|
||||
"{('Vlan2000', 'Ethernet12'): {'tagging_mode': 'tagged'}, "
|
||||
"('Vlan1000', 'Ethernet8'): {'tagging_mode': 'untagged'}, "
|
||||
"('Vlan2020', 'Ethernet12'): {'tagging_mode': 'tagged'}, "
|
||||
"('Vlan2001', 'Ethernet12'): {'tagging_mode': 'tagged'}}"
|
||||
)
|
||||
)
|
||||
|
||||
def test_minigraph_vlan_interfaces(self):
|
||||
|
Loading…
Reference in New Issue
Block a user