diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 73d1964c0086..30ba30e4378a 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -577,6 +577,29 @@ def parse_dpg(dpg, hname): vlan_attributes['alias'] = vintfname vlans[sonic_vlan_name] = vlan_attributes + dhcp = child.find(str(QName(ns, "Dhcp"))) + dhcp_table = {} + + if dhcp is not None: + for vintf in dhcp.findall(str(QName(ns, "VlanInterface"))): + vintfname = vintf.find(str(QName(ns, "Name"))).text + + dhcp_attributes = {} + + dhcp_node = vintf.find(str(QName(ns, "Dhcpv6Relays"))) + if dhcp_node is not None and dhcp_node.text is not None: + dhcpservers = dhcp_node.text + vdhcpserver_list = dhcpservers.split(';') + dhcp_attributes['dhcpv6_servers'] = vdhcpserver_list + + option_linklayer_addr = vintf.find(str(QName(ns, "Dhcpv6OptionRfc6939"))) + if option_linklayer_addr is not None and option_linklayer_addr.text == "true": + dhcp_attributes['dhcpv6_option|rfc6939_support'] = "true" + elif option_linklayer_addr is not None and option_linklayer_addr.text == "false": + dhcp_attributes['dhcpv6_option|rfc6939_support'] = "false" + + dhcp_table[vintfname] = dhcp_attributes + acls = {} for aclintf in aclintfs.findall(str(QName(ns, "AclInterface"))): if aclintf.find(str(QName(ns, "InAcl"))) is not None: @@ -691,7 +714,7 @@ def parse_dpg(dpg, hname): if mg_key in mg_tunnel.attrib: tunnelintfs[tunnel_type][tunnel_name][table_key] = mg_tunnel.attrib[mg_key] - return intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, pcs, pc_members, acls, vni, tunnelintfs, dpg_ecmp_content + return intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_table, pcs, pc_members, acls, vni, tunnelintfs, dpg_ecmp_content return None, None, None, None, None, None, None, None, None, None, None, None, None def parse_host_loopback(dpg, hname): @@ -1159,6 +1182,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw tunnel_intfs = None vlans = None vlan_members = None + dhcp_table = None pcs = None mgmt_intf = None voq_inband_intfs = None @@ -1217,7 +1241,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw for child in root: if asic_name is None: if child.tag == str(QName(ns, "DpgDec")): - (intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, pcs, pc_members, acls, vni, tunnel_intfs, dpg_ecmp_content) = parse_dpg(child, hostname) + (intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_table, pcs, pc_members, acls, vni, tunnel_intfs, dpg_ecmp_content) = parse_dpg(child, hostname) elif child.tag == str(QName(ns, "CpgDec")): (bgp_sessions, bgp_internal_sessions, bgp_voq_chassis_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, hostname) elif child.tag == str(QName(ns, "PngDec")): @@ -1232,7 +1256,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw (port_speeds_default, port_descriptions, sys_ports) = parse_deviceinfo(child, hwsku) else: if child.tag == str(QName(ns, "DpgDec")): - (intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, pcs, pc_members, acls, vni, tunnel_intfs, dpg_ecmp_content) = parse_dpg(child, asic_name) + (intfs, lo_intfs, mvrf, mgmt_intf, voq_inband_intfs, vlans, vlan_members, dhcp_table, pcs, pc_members, acls, vni, tunnel_intfs, dpg_ecmp_content) = parse_dpg(child, asic_name) host_lo_intfs = parse_host_loopback(child, hostname) elif child.tag == str(QName(ns, "CpgDec")): (bgp_sessions, bgp_internal_sessions, bgp_voq_chassis_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors) = parse_cpg(child, asic_name, local_devices) @@ -1575,7 +1599,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw results['DEVICE_NEIGHBOR_METADATA'] = { key:devices[key] for key in devices if key in {device['name'] for device in neighbors.values()} } results['SYSLOG_SERVER'] = dict((item, {}) for item in syslog_servers) results['DHCP_SERVER'] = dict((item, {}) for item in dhcp_servers) - results['DHCPv6_SERVER'] = dict((item, {}) for item in dhcpv6_servers) + results['DHCP'] = dhcp_table results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers) results['TACPLUS_SERVER'] = dict((item, {'priority': '1', 'tcp_port': '49'}) for item in tacacs_servers) results['ACL_TABLE'] = filter_acl_table_bindings(acls, neighbors, pcs, sub_role) diff --git a/src/sonic-config-engine/tests/simple-sample-graph-case.xml b/src/sonic-config-engine/tests/simple-sample-graph-case.xml index c1015b6b5362..95398e6913cf 100644 --- a/src/sonic-config-engine/tests/simple-sample-graph-case.xml +++ b/src/sonic-config-engine/tests/simple-sample-graph-case.xml @@ -148,6 +148,18 @@ + + + Vlan1000 + fc02:2000::1;fc02:2000::2 + true + + + Vlan2000 + fc02:2000::3;fc02:2000::4 + false + + diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index eff8324d6fd2..3a64b0a67a5d 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -786,3 +786,16 @@ def test_minigraph_voq_inband_interface(self): 'Vlan3094|1.1.1.1/24': {} } ) + + def test_minigraph_dhcp(self): + argument = '-m "' + self.sample_graph_simple_case + '" -p "' + self.port_config + '" -v DHCP' + output = self.run_script(argument) + self.assertEqual( + utils.to_dict(output.strip()), + utils.to_dict( + "{'Vlan1000': {'dhcpv6_servers': ['fc02:2000::1', 'fc02:2000::2'], 'dhcpv6_option|rfc6939_support': 'true'}, " + "'Vlan2000': {'dhcpv6_servers': ['fc02:2000::3', 'fc02:2000::4'], 'dhcpv6_option|rfc6939_support': 'false'}}" + ) + ) + + \ No newline at end of file diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py index 08bde40af0cf..97c88b2f3271 100644 --- a/src/sonic-config-engine/tests/test_minigraph_case.py +++ b/src/sonic-config-engine/tests/test_minigraph_case.py @@ -357,3 +357,29 @@ def test_minigraph_mux_cable_table(self): utils.to_dict(output.strip()), expected_table ) + + def test_dhcp_table(self): + argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DHCP"' + expected = { + 'Vlan1000': { + 'dhcpv6_servers': [ + "fc02:2000::1", + "fc02:2000::2" + ], + 'dhcpv6_option|rfc6939_support': 'true' + }, + 'Vlan2000': { + 'dhcpv6_servers': [ + "fc02:2000::3", + "fc02:2000::4" + ], + 'dhcpv6_option|rfc6939_support': 'false' + } + } + output = self.run_script(argument) + self.assertEqual( + utils.to_dict(output.strip()), + expected + ) + +