Skip to content

Commit

Permalink
[minigraph]: Adding new secondary field to VLAN_INTERFACE table (#16827)
Browse files Browse the repository at this point in the history
This is change taken as part of the HLD: sonic-net/SONiC#1470.
In this PR we add the logic to parse the SecondarySubnets field in the minigraph and add a flag in "secondary" in the vlan_interface table of the config db.

Microsoft ADO (number only): 16784946

How I did it
Made changes in the minigraph.py to parse the xml entry and add the parsed value to the config db

How to verify it
Added python tests in the sonic-config-engine folder to test the config db entries.
  • Loading branch information
shbalaku-microsoft authored and yxieca committed Dec 4, 2023
1 parent c0963db commit fad1081
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,17 @@ def parse_dpg(dpg, hname):
if vlanmac is not None and vlanmac.text is not None:
vlan_attributes['mac'] = vlanmac.text

vintf_node = vintf.find(str(QName(ns, "SecondarySubnets")))
if vintf_node is not None and vintf_node.text is not None:
subnets = vintf_node.text.split(';')
for subnet in subnets:
if sys.version_info >= (3, 0):
network_def = ipaddress.ip_network(subnet, strict=False)
else:
network_def = ipaddress.ip_network(unicode(subnet), strict=False)
prefix = str(network_def[1]) + "/" + str(network_def.prefixlen)
intfs[(vintfname, prefix)]["secondary"] = "true"

sonic_vlan_name = "Vlan%s" % vlanid
if sonic_vlan_name != vintfname:
vlan_attributes['alias'] = vintfname
Expand Down Expand Up @@ -1729,6 +1740,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
if intf[0][0:4] == 'Vlan':
vlan_intfs[intf] = {}

if "secondary" in intfs[intf]:
vlan_intfs[intf]["secondary"] = "true"

if bool(results['PEER_SWITCH']):
vlan_intfs[intf[0]] = {
'proxy_arp': 'enabled',
Expand All @@ -1739,6 +1753,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
elif intf[0] in vlan_invert_mapping:
vlan_intfs[(vlan_invert_mapping[intf[0]], intf[1])] = {}

if "secondary" in intfs[intf]:
vlan_intfs[(vlan_invert_mapping[intf[0]], intf[1])]["secondary"] = "true"

if bool(results['PEER_SWITCH']):
vlan_intfs[vlan_invert_mapping[intf[0]]] = {
'proxy_arp': 'enabled',
Expand Down
6 changes: 6 additions & 0 deletions src/sonic-config-engine/tests/simple-sample-graph-case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<VlanID>1000</VlanID>
<Tag>1000</Tag>
<Subnets>192.168.0.0/27</Subnets>
<SecondarySubnets>192.168.1.0/27</SecondarySubnets>
<MacAddress>00:aa:bb:cc:dd:ee</MacAddress>
</VlanInterface>
<VlanInterface>
Expand Down Expand Up @@ -176,6 +177,11 @@
<AttachTo>ab1</AttachTo>
<Prefix>192.168.0.1/27</Prefix>
</IPInterface>
<IPInterface>
<Name i:nil="true"/>
<AttachTo>ab1</AttachTo>
<Prefix>192.168.1.1/27</Prefix>
</IPInterface>
</IPInterfaces>
<DataAcls/>
<AclInterfaces>
Expand Down
8 changes: 7 additions & 1 deletion src/sonic-config-engine/tests/test_minigraph_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ def test_minigraph_vlan_members(self):
def test_minigraph_vlan_interfaces_keys(self):
argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', "VLAN_INTERFACE.keys()|list"]
output = self.run_script(argument)
self.assertEqual(output.strip(), "[('Vlan1000', '192.168.0.1/27'), 'Vlan1000']")
expected_list_dict = {
'list': ['Vlan1000', 'Vlan1000|192.168.0.1/27', 'Vlan1000|192.168.1.1/27']
}
self.assertEqual(utils.liststr_to_dict(output.strip()), expected_list_dict)

def test_minigraph_vlan_interfaces(self):
argument = ['-m', self.sample_graph, '-p', self.port_config, '-v', "VLAN_INTERFACE"]
Expand All @@ -149,6 +152,9 @@ def test_minigraph_vlan_interfaces(self):
'Vlan1000': {
'proxy_arp': 'enabled',
'grat_arp': 'enabled'
},
'Vlan1000|192.168.1.1/27': {
'secondary': 'true'
}
}
self.assertEqual(utils.to_dict(output.strip()), expected_table)
Expand Down
5 changes: 5 additions & 0 deletions src/sonic-yang-models/yang-models/sonic-vlan.yang
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ module sonic-vlan {
(contains(../ip-prefix, '.') and current()='IPv4')";
type stypes:ip-family;
}

leaf secondary {
description "Optional field to specify if the prefix is secondary subnet";
type boolean;
}
}
/* end of VLAN_INTERFACE_LIST */
}
Expand Down

0 comments on commit fad1081

Please sign in to comment.