-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[minigraph] Add support for ipv4 dhcp_server in minigraph parser #16313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
yaqiangz
wants to merge
3
commits into
sonic-net:master
from
yaqiangz:azure-master_dhcp_server_ipv4_parser
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,10 @@ | |
|
|
||
| FRONTEND_ASIC_SUB_ROLE = 'FrontEnd' | ||
| BACKEND_ASIC_SUB_ROLE = 'BackEnd' | ||
| DEFAULT_DHCP_SERVER_LEASE_TIME = 900 | ||
| DEFAULT_DHCP_SERVER_MODE = "PORT" | ||
| RACK_MGMT_MAP = "rack_mgmt_map" | ||
| DHCP_SERVER_IP = "240.127.1.2" | ||
|
|
||
| dualtor_cable_types = ["active-active", "active-standby"] | ||
|
|
||
|
|
@@ -219,6 +223,7 @@ def parse_png(png, hname, dpg_ecmp_content = None): | |
| mux_cable_ports = {} | ||
| port_device_map = {} | ||
| png_ecmp_content = {} | ||
| link_ports = {} | ||
| FG_NHG_MEMBER = {} | ||
| FG_NHG = {} | ||
| NEIGH = {} | ||
|
|
@@ -262,6 +267,11 @@ def parse_png(png, hname, dpg_ecmp_content = None): | |
| startport = link.find(str(QName(ns, "StartPort"))).text | ||
| bandwidth_node = link.find(str(QName(ns, "Bandwidth"))) | ||
| bandwidth = bandwidth_node.text if bandwidth_node is not None else None | ||
| if linktype == "DeviceMgmtLink": | ||
| # To get port - device map | ||
| link_device = enddevice if startdevice.lower() == hname.lower() else startdevice | ||
| link_port = startport if startdevice.lower() == hname.lower() else endport | ||
| link_ports[link_port] = link_device | ||
| if enddevice.lower() == hname.lower(): | ||
| if endport in port_alias_map: | ||
| endport = port_alias_map[endport] | ||
|
|
@@ -338,7 +348,7 @@ def parse_png(png, hname, dpg_ecmp_content = None): | |
|
|
||
| png_ecmp_content = {"FG_NHG_MEMBER": FG_NHG_MEMBER, "FG_NHG": FG_NHG, "NEIGH": NEIGH} | ||
|
|
||
| return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds, console_ports, mux_cable_ports, png_ecmp_content) | ||
| return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds, console_ports, mux_cable_ports, png_ecmp_content, link_ports) | ||
|
|
||
|
|
||
| def parse_asic_external_link(link, asic_name, hostname): | ||
|
|
@@ -1441,6 +1451,63 @@ def select_mmu_profiles(profile, platform, hwsku): | |
| base_file = os.path.join(path, file_item) | ||
| exec_cmd(["sudo", "cp", file_in_dir, base_file]) | ||
|
|
||
|
|
||
| def generate_ipv4_dhcp_server_config(devices, link_ports, port_alias_map, vlan_intfs, vlan_members, rack_mgmt_map): | ||
| """ | ||
| Generate IPv4 DHCP Server related config | ||
| """ | ||
| dhcp_server_ipv4 = {} | ||
| dhcp_server_ipv4_port = {} | ||
| dhcp_server_ipv4_customized_options = {} | ||
|
|
||
| # Use option 223 in DHCP packet to send rack_mgmt_map | ||
| if rack_mgmt_map is not None: | ||
| dhcp_server_ipv4_customized_options = { | ||
| RACK_MGMT_MAP: { | ||
| "id": 223, | ||
| "type": "text", | ||
| "value": rack_mgmt_map | ||
| } | ||
| } | ||
|
|
||
| alias_port_map = dict((v, k) for k, v in port_alias_map.items()) | ||
| # Generate DHCP_SERVER_IPV4 part | ||
| for vlan_intf in list(vlan_intfs.keys()): | ||
| if not isinstance(vlan_intf, tuple): | ||
| continue | ||
|
|
||
| vlan_name = vlan_intf[0] | ||
| vlan_intf_str = vlan_intf[1] | ||
| vlan_network = ipaddress.ip_network(UNICODE_TYPE(vlan_intf_str), False) | ||
| if vlan_network.version != 4: | ||
| continue | ||
| dhcp_server_ipv4[vlan_name] = { | ||
| "gateway": vlan_intf_str.split("/")[0], | ||
| "lease_time": DEFAULT_DHCP_SERVER_LEASE_TIME, | ||
| "mode": DEFAULT_DHCP_SERVER_MODE, | ||
| "netmask": str(vlan_network.netmask), | ||
| "state": "enabled" | ||
| } | ||
| if rack_mgmt_map is not None: | ||
| dhcp_server_ipv4[vlan_name]["customized_options"] = [RACK_MGMT_MAP] | ||
|
|
||
| # Generate DHCP_SERVER_IPV4_PORT part | ||
| for vlan_member in list(vlan_members.keys()): | ||
| interface = vlan_member[1] | ||
| if interface not in alias_port_map or alias_port_map[interface] not in link_ports: | ||
| continue | ||
| neighbor_device = link_ports[alias_port_map[interface]] | ||
| if not neighbor_device.endswith("BMC"): | ||
| continue | ||
| mgmt_ip_str = devices[neighbor_device]["mgmt_addr"] | ||
| dhcp_server_ipv4_port[vlan_member] = { | ||
| "ips": [ | ||
| mgmt_ip_str.split("/")[0] | ||
| ] | ||
| } | ||
| return dhcp_server_ipv4, dhcp_server_ipv4_port, dhcp_server_ipv4_customized_options | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # | ||
| # Main functions | ||
|
|
@@ -1521,6 +1588,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw | |
| redundancy_type = None | ||
| qos_profile = None | ||
| rack_mgmt_map = None | ||
| dhcp_server_ipv4 = None | ||
| dhcp_server_ipv4_port = None | ||
| dhcp_server_ipv4_customized_options = None | ||
|
|
||
| hwsku_qn = QName(ns, "HwSku") | ||
| hostname_qn = QName(ns, "Hostname") | ||
|
|
@@ -1549,9 +1619,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw | |
| elif child.tag == str(QName(ns, "CpgDec")): | ||
| (bgp_sessions, bgp_internal_sessions, bgp_voq_chassis_sessions, bgp_asn, bgp_peers_with_range, bgp_monitors, bgp_sentinel_sessions) = parse_cpg(child, hostname) | ||
| elif child.tag == str(QName(ns, "PngDec")): | ||
| (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports, mux_cable_ports, png_ecmp_content) = parse_png(child, hostname, dpg_ecmp_content) | ||
| (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports, mux_cable_ports, png_ecmp_content, link_ports) = parse_png(child, hostname, dpg_ecmp_content) | ||
| elif child.tag == str(QName(ns, "UngDec")): | ||
| (u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname, None) | ||
| (u_neighbors, u_devices, _, _, _, _, _, _, _) = parse_png(child, hostname, None) | ||
| elif child.tag == str(QName(ns, "MetadataDeclaration")): | ||
| (syslog_servers, dhcp_servers, dhcpv6_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id, region, cloudtype, resource_type, downstream_subrole, switch_id, switch_type, max_cores, kube_data, macsec_profile, downstream_redundancy_types, redundancy_type, qos_profile, rack_mgmt_map) = parse_meta(child, hostname) | ||
| elif child.tag == str(QName(ns, "LinkMetadataDeclaration")): | ||
|
|
@@ -2010,7 +2080,9 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw | |
| else: | ||
| 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) | ||
| # For BmcMgmtToRRouter, treat docker ip as new dhcp_server | ||
| results['DHCP_SERVER'] = dict((item, {}) for item in dhcp_servers) \ | ||
| if devices[hostname]["type"] != "BmcMgmtToRRouter" else {DHCP_SERVER_IP: {}} | ||
| results['DHCP_RELAY'] = dhcp_relay_table | ||
| results['NTP_SERVER'] = dict((item, {}) for item in ntp_servers) | ||
| # Set default DNS nameserver from dns.j2 | ||
|
|
@@ -2068,6 +2140,18 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw | |
| 'client_crt_cname': 'client.restapi.sonic' | ||
| } | ||
| } | ||
| if devices[hostname]["type"] == "BmcMgmtToRRouter": | ||
| dhcp_server_ipv4, dhcp_server_ipv4_port, dhcp_server_ipv4_customized_options = \ | ||
| generate_ipv4_dhcp_server_config(devices, link_ports, port_alias_map, vlan_intfs, vlan_members, | ||
| rack_mgmt_map) | ||
| for vlan_name, _ in results["VLAN"].items(): | ||
| # For BmcMgmtToRRouter, treat docker ip as new dhcp_server | ||
| results["VLAN"][vlan_name]["dhcp_servers"] = [DHCP_SERVER_IP] | ||
| if dhcp_server_ipv4 is not None: | ||
| results['DHCP_SERVER_IPV4'] = dhcp_server_ipv4 | ||
| if dhcp_server_ipv4_customized_options: | ||
| results['DHCP_SERVER_IPV4_CUSTOMIZED_OPTIONS'] = dhcp_server_ipv4_customized_options | ||
| results['DHCP_SERVER_IPV4_PORT'] = dhcp_server_ipv4_port | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a new table in ConfigDB. Please onboard it with golden config generation pipeline. We are blocking new tables coming into minigraph parser. |
||
|
|
||
| if len(png_ecmp_content): | ||
| results['FG_NHG_MEMBER'] = png_ecmp_content['FG_NHG_MEMBER'] | ||
|
|
||
53 changes: 53 additions & 0 deletions
53
src/sonic-config-engine/tests/sample-nokia-7215-port-config.ini
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # name lanes alias | ||
| Ethernet0 1 etp1 | ||
| Ethernet1 2 etp2 | ||
| Ethernet2 3 etp3 | ||
| Ethernet3 4 etp4 | ||
| Ethernet4 5 etp5 | ||
| Ethernet5 6 etp6 | ||
| Ethernet6 7 etp7 | ||
| Ethernet7 8 etp8 | ||
| Ethernet8 9 etp9 | ||
| Ethernet9 10 etp10 | ||
| Ethernet10 11 etp11 | ||
| Ethernet11 12 etp12 | ||
| Ethernet12 13 etp13 | ||
| Ethernet13 14 etp14 | ||
| Ethernet14 15 etp15 | ||
| Ethernet15 16 etp16 | ||
| Ethernet16 17 etp17 | ||
| Ethernet17 18 etp18 | ||
| Ethernet18 19 etp19 | ||
| Ethernet19 20 etp20 | ||
| Ethernet20 21 etp21 | ||
| Ethernet21 22 etp22 | ||
| Ethernet22 23 etp23 | ||
| Ethernet23 24 etp24 | ||
| Ethernet24 25 etp25 | ||
| Ethernet25 26 etp26 | ||
| Ethernet26 27 etp27 | ||
| Ethernet27 28 etp28 | ||
| Ethernet28 29 etp29 | ||
| Ethernet29 30 etp30 | ||
| Ethernet30 31 etp31 | ||
| Ethernet31 32 etp32 | ||
| Ethernet32 33 etp33 | ||
| Ethernet33 34 etp34 | ||
| Ethernet34 35 etp35 | ||
| Ethernet35 36 etp36 | ||
| Ethernet36 37 etp37 | ||
| Ethernet37 38 etp38 | ||
| Ethernet38 39 etp39 | ||
| Ethernet39 40 etp40 | ||
| Ethernet40 41 etp41 | ||
| Ethernet41 42 etp42 | ||
| Ethernet42 43 etp43 | ||
| Ethernet43 44 etp44 | ||
| Ethernet44 45 etp45 | ||
| Ethernet45 46 etp46 | ||
| Ethernet46 47 etp47 | ||
| Ethernet47 48 etp48 | ||
| Ethernet48 49 etp49 | ||
| Ethernet49 50 etp50 | ||
| Ethernet50 51 etp51 | ||
| Ethernet51 52 etp52 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why generate_ipv4_dhcp_server_config() is needed. It just manipulated existing ConfigDB, does not parse minigraph at all, no extra info added into ConfigDB. Seems like everything you needed is already in ConfigDB or as default values.