Skip to content

Commit

Permalink
[201911] Fix tagged VlanInterface if attached to multiple vlan as unt…
Browse files Browse the repository at this point in the history
…agged member (#13534)

Backport #8927
  • Loading branch information
qiluo-msft authored Jan 30, 2023
1 parent bc615c0 commit 9ce9ba4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
22 changes: 18 additions & 4 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,22 +356,36 @@ def parse_dpg(dpg, hname):
vlans = {}
vlan_members = {}
dhcp_relay_table = {}
intf_vlan_mbr = defaultdict(list)
# Dict: vlan member (port/PortChannel) -> set of VlanID, in which the member if an untagged vlan member
untagged_vlan_mbr = defaultdict(set)
for vintf in vlanintfs.findall(str(QName(ns, "VlanInterface"))):
vlanid = vintf.find(str(QName(ns, "VlanID"))).text
vlantype = vintf.find(str(QName(ns, "Type")))
if vlantype is None:
vlantype_name = ""
else:
vlantype_name = vlantype.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)
if vlantype_name != "Tagged":
for member in vmbr_list:
untagged_vlan_mbr[member].add(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
vintfmbr = vintf.find(str(QName(ns, "AttachTo"))).text
vlantype = vintf.find(str(QName(ns, "Type")))
if vlantype is None:
vlantype_name = ""
else:
vlantype_name = vlantype.text
vmbr_list = vintfmbr.split(';')
for i, member in enumerate(vmbr_list):
vmbr_list[i] = port_alias_map.get(member, member)
sonic_vlan_member_name = "Vlan%s" % (vlanid)
if len(intf_vlan_mbr[member]) > 1:
if vlantype_name == "Tagged":
vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'tagged'}
elif len(untagged_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'}
Expand Down
18 changes: 18 additions & 0 deletions src/sonic-config-engine/tests/simple-sample-graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,30 @@
<Tag>1000</Tag>
<Subnets>192.168.0.0/27</Subnets>
</VlanInterface>
<VlanInterface>
<Name>ab4</Name>
<AttachTo>fortyGigE0/8</AttachTo>
<DhcpRelays>192.0.0.1;192.0.0.2</DhcpRelays>
<VlanID>1001</VlanID>
<Tag>1001</Tag>
<Subnets>192.168.0.32/27</Subnets>
</VlanInterface>
<VlanInterface>
<Name>kk1</Name>
<AttachTo>fortyGigE0/12</AttachTo>
<DhcpRelays>192.0.0.1;192.0.0.2</DhcpRelays>
<VlanID>2020</VlanID>
<Tag>2020</Tag>
<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>
<Type>Tagged</Type>
<Subnets>192.168.0.240/27</Subnets>
</VlanInterface>
<VlanInterface>
Expand Down
16 changes: 11 additions & 5 deletions src/sonic-config-engine/tests/test_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ def test_var_json_data(self):
self.assertEqual(
utils.to_dict(output.strip()),
utils.to_dict(
'{\n "Vlan1000|Ethernet8": {\n "tagging_mode": "untagged"\n },'
'{\n "Vlan1000|Ethernet8": {\n "tagging_mode": "tagged"\n },'
' \n "Vlan1001|Ethernet8": {\n "tagging_mode": "tagged"\n },'
' \n "Vlan2000|Ethernet12": {\n "tagging_mode": "tagged"\n },'
' \n "Vlan2001|Ethernet12": {\n "tagging_mode": "tagged"\n }}'
' \n "Vlan2001|Ethernet12": {\n "tagging_mode": "untagged"\n },'
' \n "Vlan2020|Ethernet12": {\n "tagging_mode": "tagged"\n }\n}'
)
)

Expand Down Expand Up @@ -208,8 +210,10 @@ def test_minigraph_vlans(self):
utils.to_dict(output.strip()),
utils.to_dict(
"{'Vlan1000': {'alias': 'ab1', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '1000', 'members': ['Ethernet8']}, "
"'Vlan1001': {'alias': 'ab4', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '1001', 'members': ['Ethernet8']},"
"'Vlan2001': {'alias': 'ab3', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '2001', 'members': ['Ethernet12']},"
"'Vlan2000': {'alias': 'ab2', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '2000', 'members': ['Ethernet12']}}"
"'Vlan2000': {'alias': 'ab2', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '2000', 'members': ['Ethernet12']},"
"'Vlan2020': {'alias': 'kk1', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '2020', 'members': ['Ethernet12']}}"
)
)

Expand All @@ -220,8 +224,10 @@ def test_minigraph_vlan_members(self):
utils.to_dict(output.strip()),
utils.to_dict(
"{('Vlan2000', 'Ethernet12'): {'tagging_mode': 'tagged'}, "
"('Vlan1000', 'Ethernet8'): {'tagging_mode': 'untagged'}, "
"('Vlan2001', 'Ethernet12'): {'tagging_mode': 'tagged'}}"
"('Vlan1000', 'Ethernet8'): {'tagging_mode': 'tagged'}, "
"('Vlan1001', 'Ethernet8'): {'tagging_mode': 'tagged'}, "
"('Vlan2020', 'Ethernet12'): {'tagging_mode': 'tagged'}, "
"('Vlan2001', 'Ethernet12'): {'tagging_mode': 'untagged'}}"
)
)

Expand Down

0 comments on commit 9ce9ba4

Please sign in to comment.