Commit 8464dcc4 authored by Simon Redman's avatar Simon Redman

Move ULA_map construction to helper method

parent cba8b3ee
......@@ -113,6 +113,26 @@ def parse_local_interface_addresses(netgraph):
return interface_map
def construct_ULAs(ipv6_link_local_map, ipv4_map):
"""
Combine the per-host, per-interface IPv6 and IPv4 information into per-host, per-interface Unique Local Addresses
:param ipv6_link_local_map: per-host per-interface IPv6 link local address map as built by parse_local_interface_addresses
:param ipv4_map: per-host per-interface IPv4 address map as built by parse_ipv4_networks
:return: mapping of hosts to interfaces to ULAs
"""
ULA_map = {}
for host in ipv6_link_local_map:
ULA_map[host] = {}
for interface in ipv6_link_local_map[host]:
link_local_addr = ipv6_link_local_map[host][interface]
ipv4_addr = ipv4_map[host][interface]
ULA_map[host][interface] = convert_link_local_addr_to_ULA(link_local_addr, ipv4_addr)
return ULA_map
def convert_link_local_addr_to_ULA(link_local_interface, ipv4_interface):
"""
Combine a link's ipv4 address and ipv6 interface ID to form an ipv6 Unique Local Address
......@@ -185,13 +205,8 @@ if __name__ == "__main__":
netgraph.graph._node[hostnames[host_idx]]['session'] = sessions[host_idx]
link_local_map = parse_local_interface_addresses(netgraph)
ipv4_map = parse_ipv4_networks(netgraph)
ULA_map = {}
for host in link_local_map:
ULA_map[host] = {}
for interface in link_local_map[host]:
link_local_addr = link_local_map[host][interface]
ipv4_addr = ipv4_map[host][interface]
ULA_map[host][interface] = convert_link_local_addr_to_ULA(link_local_addr, ipv4_addr)
ULA_map = construct_ULAs(link_local_map, ipv4_map)
add_ULAs_to_hosts(netgraph.graph, ULA_map)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment