diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py
index 5a2baad87c2a..60a28ed19b3e 100644
--- a/src/sonic-config-engine/minigraph.py
+++ b/src/sonic-config-engine/minigraph.py
@@ -518,28 +518,36 @@ def parse_dpg(dpg, hname):
vlans = {}
vlan_members = {}
dhcp_relay_table = {}
- vlantype_name = ""
- 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 != None:
- vlantype_name = vintf.find(str(QName(ns, "Type"))).text
+ 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 vlantype_name == "Tagged":
vlan_members[(sonic_vlan_member_name, vmbr_list[i])] = {'tagging_mode': 'tagged'}
- elif len(intf_vlan_mbr[member]) > 1:
+ 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'}
diff --git a/src/sonic-config-engine/tests/sample-graph-resource-type.xml b/src/sonic-config-engine/tests/sample-graph-resource-type.xml
index 31f9fc43f2c1..09c2debfbb85 100644
--- a/src/sonic-config-engine/tests/sample-graph-resource-type.xml
+++ b/src/sonic-config-engine/tests/sample-graph-resource-type.xml
@@ -164,6 +164,14 @@
1000
192.168.0.0/27
+
+ ab4
+ fortyGigE0/8
+ 192.0.0.1;192.0.0.2
+ 1001
+ 1001
+ 192.168.0.32/27
+
kk1
fortyGigE0/12
@@ -179,6 +187,7 @@
192.0.0.1;192.0.0.2
2000
2000
+ Tagged
192.168.0.240/27
diff --git a/src/sonic-config-engine/tests/sample-graph-subintf.xml b/src/sonic-config-engine/tests/sample-graph-subintf.xml
index 4a7ffe2f76ed..8940297e7488 100644
--- a/src/sonic-config-engine/tests/sample-graph-subintf.xml
+++ b/src/sonic-config-engine/tests/sample-graph-subintf.xml
@@ -164,6 +164,14 @@
1000
192.168.0.0/27
+
+ ab4
+ fortyGigE0/8
+ 192.0.0.1;192.0.0.2
+ 1001
+ 1001
+ 192.168.0.32/27
+
kk1
fortyGigE0/12
diff --git a/src/sonic-config-engine/tests/simple-sample-graph.xml b/src/sonic-config-engine/tests/simple-sample-graph.xml
index 64d7477fbaf9..196d0b191078 100644
--- a/src/sonic-config-engine/tests/simple-sample-graph.xml
+++ b/src/sonic-config-engine/tests/simple-sample-graph.xml
@@ -164,6 +164,14 @@
1000
192.168.0.0/27
+
+ ab4
+ fortyGigE0/8
+ 192.0.0.1;192.0.0.2
+ 1001
+ 1001
+ 192.168.0.32/27
+
kk1
fortyGigE0/12
@@ -179,6 +187,7 @@
192.0.0.1;192.0.0.2
2000
2000
+ Tagged
192.168.0.240/27
diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py
index b2f8532b7636..79a3fd6fd9ac 100644
--- a/src/sonic-config-engine/tests/test_cfggen.py
+++ b/src/sonic-config-engine/tests/test_cfggen.py
@@ -134,6 +134,7 @@ def test_var_json_data(self, **kwargs):
utils.to_dict(output.strip()),
utils.to_dict(
'{\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 "Vlan2020|Ethernet12": {\n "tagging_mode": "tagged"\n }\n}'
@@ -143,9 +144,10 @@ def test_var_json_data(self, **kwargs):
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}'
)
)
@@ -232,6 +234,7 @@ def test_minigraph_vlans(self, **kwargs):
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']},"
"'Vlan2020': {'alias': 'kk1', 'dhcp_servers': ['192.0.0.1', '192.0.0.2'], 'vlanid': '2020', 'members': ['Ethernet12']}}"
@@ -248,6 +251,7 @@ def test_minigraph_vlan_members(self, **kwargs):
utils.to_dict(output.strip()),
utils.to_dict(
"{('Vlan2000', 'Ethernet12'): {'tagging_mode': 'tagged'}, "
+ "('Vlan1001', 'Ethernet8'): {'tagging_mode': 'tagged'}, "
"('Vlan1000', 'Ethernet8'): {'tagging_mode': 'tagged'}, "
"('Vlan2020', 'Ethernet12'): {'tagging_mode': 'tagged'}, "
"('Vlan2001', 'Ethernet12'): {'tagging_mode': 'tagged'}}"
@@ -258,9 +262,10 @@ def test_minigraph_vlan_members(self, **kwargs):
utils.to_dict(output.strip()),
utils.to_dict(
"{('Vlan2000', 'Ethernet12'): {'tagging_mode': 'tagged'}, "
- "('Vlan1000', 'Ethernet8'): {'tagging_mode': 'untagged'}, "
+ "('Vlan1000', 'Ethernet8'): {'tagging_mode': 'tagged'}, "
+ "('Vlan1001', 'Ethernet8'): {'tagging_mode': 'tagged'}, "
"('Vlan2020', 'Ethernet12'): {'tagging_mode': 'tagged'}, "
- "('Vlan2001', 'Ethernet12'): {'tagging_mode': 'tagged'}}"
+ "('Vlan2001', 'Ethernet12'): {'tagging_mode': 'untagged'}}"
)
)
@@ -626,6 +631,9 @@ def test_minigraph_bgp_mon(self):
def test_minigraph_sub_port_interfaces(self, check_stderr=True):
self.verify_sub_intf(check_stderr=check_stderr)
+ def test_minigraph_sub_port_intf_resource_type_non_backend_tor(self, check_stderr=True):
+ self.verify_sub_intf_non_backend_tor(graph_file=self.sample_resource_graph, check_stderr=check_stderr)
+
def test_minigraph_sub_port_intf_resource_type(self, check_stderr=True):
self.verify_sub_intf(graph_file=self.sample_resource_graph, check_stderr=check_stderr)
@@ -659,6 +667,14 @@ def verify_no_vlan_member(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), "{}")
+ def verify_sub_intf_non_backend_tor(self, **kwargs):
+ graph_file = kwargs.get('graph_file', self.sample_graph_simple)
+
+ # All the other tables stay unchanged
+ self.test_var_json_data(graph_file=graph_file)
+ self.test_minigraph_vlans(graph_file=graph_file)
+ self.test_minigraph_vlan_members(graph_file=graph_file)
+
def verify_sub_intf(self, **kwargs):
graph_file = kwargs.get('graph_file', self.sample_graph_simple)
check_stderr = kwargs.get('check_stderr', True)