Esempio n. 1
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""
    import autonetkit.plugins.ipv4 as ipv4
    g_ipv4 = anm.add_overlay("ipv4")
    g_ip = anm['ip']
    g_in = anm['input']
    g_ipv4.add_nodes_from(
        g_ip, retain="collision_domain")  # retain if collision domain or not
    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)
    ank_utils.copy_attr_from(g_ip, g_ipv4, "asn",
        nbunch = g_ipv4.nodes("collision_domain"))
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in
    infra_block, loopback_block, vrf_loopback_block = extract_ipv4_blocks(anm)

    # See if IP addresses specified on each interface
    l3_devices = [d for d in g_in if d.device_type in ("router", "server")]

    manual_alloc_devices = set()
    for device in l3_devices:
        physical_interfaces = list(device.physical_interfaces)
        if all(interface.ipv4_address for interface in physical_interfaces
            if interface.is_bound ):
            manual_alloc_devices.add(device) # add as a manual allocated device

    if manual_alloc_devices == set(l3_devices):
        manual_alloc_ipv4_infrastructure = True
    else:
        manual_alloc_ipv4_infrastructure = False

    #TODO: need to set allocate_ipv4 by default in the readers
    if manual_alloc_ipv4_infrastructure:
        manual_ipv4_infrastructure_allocation(anm)
    else:
        ipv4.allocate_infra(g_ipv4, infra_block)

    if g_in.data.alloc_ipv4_loopbacks is False:
        manual_ipv4_loopback_allocation(anm)
    else:
        ipv4.allocate_loopbacks(g_ipv4, loopback_block)

    #TODO: need to also support secondary_loopbacks for IPv6
    #TODO: only call if secondaries are set
    ipv4.allocate_vrf_loopbacks(g_ipv4, vrf_loopback_block)

    #TODO: replace this with direct allocation to interfaces in ip alloc plugin
    for node in g_ipv4.nodes("is_l3device"):
        node.loopback_zero.ip_address = node.loopback
Esempio n. 2
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""
    import autonetkit.plugins.ipv4 as ipv4
    g_ipv4 = anm.add_overlay("ipv4")
    g_ip = anm['ip']
    g_in = anm['input']
    g_ipv4.add_nodes_from(
        g_ip, retain="collision_domain")  # retain if collision domain or not
    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)
    ank_utils.copy_attr_from(g_ip,
                             g_ipv4,
                             "asn",
                             nbunch=g_ipv4.nodes("collision_domain"))
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in
    infra_block, loopback_block, vrf_loopback_block = extract_ipv4_blocks(anm)

    #TODO: need to set allocate_ipv4 by default in the readers
    if g_in.data.alloc_ipv4_infrastructure is False:
        manual_ipv4_infrastructure_allocation(anm)
    else:
        ipv4.allocate_infra(g_ipv4, infra_block)

    if g_in.data.alloc_ipv4_loopbacks is False:
        manual_ipv4_loopback_allocation(anm)
    else:
        ipv4.allocate_loopbacks(g_ipv4, loopback_block)

    #TODO: need to also support secondary_loopbacks for IPv6
    ipv4.allocate_vrf_loopbacks(g_ipv4, vrf_loopback_block)

    #TODO: replace this with direct allocation to interfaces in ip alloc plugin
    for node in g_ipv4.nodes("is_l3device"):
        node.loopback_zero.ip_address = node.loopback
        for interface in node:
            edges = list(interface.edges())
            if len(edges):
                edge = edges[0]  # first (only) edge
                interface.ip_address = edge.ip_address
                interface.subnet = edge.dst.subnet  # from collision domain
Esempio n. 3
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""
    import autonetkit.plugins.ipv4 as ipv4
    g_ipv4 = anm.add_overlay("ipv4")
    g_ip = anm['ip']
    g_in = anm['input']
    g_ipv4.add_nodes_from(
        g_ip, retain="collision_domain")  # retain if collision domain or not
    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)
    ank_utils.copy_attr_from(g_ip, g_ipv4, "asn", nbunch = g_ipv4.nodes("collision_domain"))
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in
    infra_block, loopback_block, vrf_loopback_block = extract_ipv4_blocks(anm)

    #TODO: need to set allocate_ipv4 by default in the readers
    if g_in.data.alloc_ipv4_infrastructure is False:
        manual_ipv4_infrastructure_allocation(anm)
    else:
        ipv4.allocate_infra(g_ipv4, infra_block)

    if g_in.data.alloc_ipv4_loopbacks is False:
        manual_ipv4_loopback_allocation(anm)
    else:
        ipv4.allocate_loopbacks(g_ipv4, loopback_block)

    #TODO: need to also support secondary_loopbacks for IPv6
    ipv4.allocate_vrf_loopbacks(g_ipv4, vrf_loopback_block)

    #TODO: replace this with direct allocation to interfaces in ip alloc plugin
    for node in g_ipv4.nodes("is_l3device"):
        node.loopback_zero.ip_address = node.loopback
        for interface in node:
            edges = list(interface.edges())
            if len(edges):
                edge = edges[0] # first (only) edge
                interface.ip_address = edge.ip_address
                interface.subnet = edge.dst.subnet # from collision domain
Esempio n. 4
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""

    import autonetkit.plugins.ipv4 as ipv4
    import netaddr
    g_ipv4 = anm.add_overlay('ipv4')
    g_ip = anm['ip']
    g_in = anm['input']
    # retain if collision domain or not
    g_ipv4.add_nodes_from(g_ip, retain=['label', 'allocate',
                                        'broadcast_domain'])

    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)

    ank_utils.copy_attr_from(
        g_ip, g_ipv4, 'asn', nbunch=g_ipv4.nodes('broadcast_domain'))
    # work around until fall-through implemented
    vswitches = [n for n in g_ip.nodes()
                 if n['layer2'].device_type == "switch"
                 and n['layer2'].device_subtype == "virtual"]
    ank_utils.copy_attr_from(g_ip, g_ipv4, 'asn', nbunch=vswitches)
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in

    (infra_block, loopback_block, vrf_loopback_block) = \
        extract_ipv4_blocks(anm)

# TODO: don't present if using manual allocation
    if any(i for n in g_ip.nodes() for i in
           n.loopback_interfaces() if not i.is_loopback_zero):
        block_message = "IPv4 Secondary Loopbacks: %s" % vrf_loopback_block
        log.info(block_message)

    # See if IP addresses specified on each interface

    # do we need this still? in ANM? - differnt because input graph.... but
    # can map back to  self overlay first then phy???
    l3_devices = [d for d in g_in if d.device_type in ('router', 'server')]

    # TODO: need to account for devices whose interfaces are in only e.g. vpns

    manual_alloc_devices = set()
    for device in l3_devices:
        physical_interfaces = list(device.physical_interfaces())
        allocated = list(
            interface.ipv4_address for interface in physical_interfaces
            if interface.is_bound and interface['ipv4'].allocate is not False
            and interface['ipv4'].is_bound)
        if all(interface.ipv4_address for interface in
               physical_interfaces if interface.is_bound
               and interface['ip'].allocate is not False
               and interface['ip'].is_bound):
            # add as a manual allocated device
            manual_alloc_devices.add(device)

    if manual_alloc_devices == set(l3_devices):
        manual_alloc_ipv4_infrastructure = True
    else:
        log.info("Allocating from IPv4 infrastructure block: %s" % infra_block)
        manual_alloc_ipv4_infrastructure = False
        # warn if any set
        allocated = []
        unallocated = []
        for node in l3_devices:
            # TODO: make these inverse sets
            allocated += sorted([i for i in node.physical_interfaces()
                                 if i.is_bound and i.ipv4_address])
            unallocated += sorted([i for i in node.physical_interfaces()
                                   if i.is_bound and not i.ipv4_address
                                   and i['ipv4'].is_bound])

        # TODO: what if IP is set but not a prefix?
        if len(allocated):
            # TODO: if set is > 50% of nodes then list those that are NOT set
            log.warning(
                "Using automatic IPv4 interface allocation. IPv4 interface addresses specified on interfaces %s will be ignored." % allocated)

    # TODO: need to set allocate_ipv4 by default in the readers

    if manual_alloc_ipv4_infrastructure:
        manual_ipv4_infrastructure_allocation(anm)
    else:
        ipv4.allocate_infra(g_ipv4, infra_block)

    if g_in.data.alloc_ipv4_loopbacks is False:
        manual_ipv4_loopback_allocation(anm)
    else:
        log.info("Allocating from IPv4 loopback block: %s" % loopback_block)
        # Check if some nodes are allocated
        allocated = sorted([n for n in g_ip if n['input'].loopback_v4])
        unallocated = sorted([n for n in g_ip if not n['input'].loopback_v4])
        if len(allocated):
            log.warning(
                "Using automatic IPv4 loopback allocation. IPv4 loopback addresses specified on nodes %s will be ignored." % allocated)
            # TODO: if set is > 50% of nodes then list those that are NOT set
        ipv4.allocate_loopbacks(g_ipv4, loopback_block)

    # TODO: need to also support secondary_loopbacks for IPv6
    # TODO: only call if secondaries are set

    ipv4.allocate_secondary_loopbacks(g_ipv4, vrf_loopback_block)

    # TODO: replace this with direct allocation to interfaces in ip alloc plugin
    # TODO: add option for nonzero interfaces on node - ie
    # node.secondary_loopbacks
    for node in g_ipv4:
        node.static_routes = []

    for node in g_ipv4.routers():
        node.loopback_zero.ip_address = node.loopback
        node.loopback_zero.subnet = netaddr.IPNetwork("%s/32" % node.loopback)
        for interface in node.loopback_interfaces():
            if not interface.is_loopback_zero:
                # TODO: fix this inconsistency elsewhere
                interface.ip_address = interface.loopback
Esempio n. 5
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""

    import autonetkit.plugins.ipv4 as ipv4
    import netaddr
    g_ipv4 = anm.add_overlay('ipv4')
    g_ip = anm['ip']
    g_in = anm['input']
    # retain if collision domain or not
    g_ipv4.add_nodes_from(g_ip, retain=['label', 'allocate',
                                        'broadcast_domain'])
    ank_utils.copy_attr_from(g_in, g_ipv4, 'name')
    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)

    ank_utils.copy_attr_from(
        g_ip, g_ipv4, 'asn', nbunch=g_ipv4.nodes('broadcast_domain'))
    # work around until fall-through implemented
    vswitches = [n for n in g_ip.nodes()
                 if n['layer2'].device_type == "switch"
                 and n['layer2'].device_subtype == "virtual"]
    ank_utils.copy_attr_from(g_ip, g_ipv4, 'asn', nbunch=vswitches)
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in

    (infra_block, loopback_block, vrf_loopback_block) = \
        extract_ipv4_blocks(anm)

# TODO: don't present if using manual allocation
    if any(i for n in g_ip.nodes() for i in
           n.loopback_interfaces() if not i.is_loopback_zero):
        block_message = "IPv4 Secondary Loopbacks: %s" % vrf_loopback_block
        log.info(block_message)

    # See if IP addresses specified on each interface

    # do we need this still? in ANM? - differnt because input graph.... but
    # can map back to  self overlay first then phy???
    l3_devices = [d for d in g_in if d.device_type in ('router', 'server')]

    # TODO: need to account for devices whose interfaces are in only e.g. vpns

    manual_alloc_devices = set()
    for device in l3_devices:
        physical_interfaces = list(device.edge_interfaces())
        allocated = list(
            interface.ipv4_address for interface in physical_interfaces
            if interface.is_bound and interface['ipv4'].allocate is not False
            and interface['ipv4'].is_bound)
        if all(interface.ipv4_address for interface in
               physical_interfaces if interface.is_bound
               and interface['ip'].allocate is not False
               and interface['ip'].is_bound):
            # add as a manual allocated device
            manual_alloc_devices.add(device)

    if manual_alloc_devices == set(l3_devices):
        manual_alloc_ipv4_infrastructure = True
    else:
        log.info("Allocating from IPv4 infrastructure block: %s" % infra_block)
        manual_alloc_ipv4_infrastructure = False
        # warn if any set
        allocated = []
        unallocated = []
        for node in l3_devices:
            # TODO: make these inverse sets
            allocated += sorted([i for i in node.edge_interfaces()
                                 if i.is_bound and i.ipv4_address])
            unallocated += sorted([i for i in node.edge_interfaces()
                                   if i.is_bound and not i.ipv4_address
                                   and i['ipv4'].is_bound])

        # TODO: what if IP is set but not a prefix?
        if len(allocated):
            # TODO: if set is > 50% of nodes then list those that are NOT set
            log.warning(
                "Using automatic IPv4 interface allocation. IPv4 interface addresses specified on interfaces %s will be ignored." % allocated)

    # TODO: need to set allocate_ipv4 by default in the readers

    if manual_alloc_ipv4_infrastructure:
        manual_ipv4_infrastructure_allocation(anm)
    else:
        ipv4.allocate_infra(g_ipv4, infra_block)

    if g_in.data.alloc_ipv4_loopbacks is False:
        manual_ipv4_loopback_allocation(anm)
    else:
        log.info("Allocating from IPv4 loopback block: %s" % loopback_block)
        # Check if some nodes are allocated
        allocated = sorted([n for n in g_ip if n['input'].loopback_v4])
        unallocated = sorted([n for n in g_ip if not n['input'].loopback_v4])
        if len(allocated):
            log.warning(
                "Using automatic IPv4 loopback allocation. IPv4 loopback addresses specified on nodes %s will be ignored." % allocated)
            # TODO: if set is > 50% of nodes then list those that are NOT set
        ipv4.allocate_loopbacks(g_ipv4, loopback_block)

    # TODO: need to also support secondary_loopbacks for IPv6
    # TODO: only call if secondaries are set

    ipv4.allocate_secondary_loopbacks(g_ipv4, vrf_loopback_block)

    # TODO: replace this with direct allocation to interfaces in ip alloc plugin
    # TODO: add option for nonzero interfaces on node - ie
    # node.secondary_loopbacks
    for node in g_ipv4:
        node.static_routes = []

    for node in g_ipv4.routers():
        node.loopback_zero.ip_address = node.loopback
        node.loopback_zero.subnet = netaddr.IPNetwork("%s/32" % node.loopback)
        for interface in node.loopback_interfaces():
            if not interface.is_loopback_zero:
                # TODO: fix this inconsistency elsewhere
                interface.ip_address = interface.loopback
Esempio n. 6
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""

    import autonetkit.plugins.ipv4 as ipv4
    import netaddr
    g_ipv4 = anm.add_overlay('ipv4')
    g_ip = anm['ip']
    g_in = anm['input']
    g_ipv4.add_nodes_from(g_ip, retain=['label', 'broadcast_domain'
                                        ])  # retain if collision domain or not

    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)

    ank_utils.copy_attr_from(g_ip,
                             g_ipv4,
                             'asn',
                             nbunch=g_ipv4.nodes('broadcast_domain'))
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in

    (infra_block, loopback_block, vrf_loopback_block) = \
        extract_ipv4_blocks(anm)

    block_message = "IPv4 allocations: Infrastructure: %s, Loopback: %s" % (
        infra_block, loopback_block)
    if any(i for n in g_ip.nodes() for i in n.loopback_interfaces
           if not i.is_loopback_zero):
        block_message += " Secondary Loopbacks: %s" % vrf_loopback_block

    log.info(block_message)

    # See if IP addresses specified on each interface

    # do we need this still? in ANM?
    l3_devices = [d for d in g_in if d.device_type in ('router', 'server')]

    manual_alloc_devices = set()
    for device in l3_devices:
        physical_interfaces = list(device.physical_interfaces)
        allocated = list(interface.ipv4_address
                         for interface in physical_interfaces
                         if interface.is_bound)
        if all(interface.ipv4_address for interface in physical_interfaces
               if interface.is_bound):
            manual_alloc_devices.add(
                device)  # add as a manual allocated device

    if manual_alloc_devices == set(l3_devices):
        manual_alloc_ipv4_infrastructure = True
    else:
        manual_alloc_ipv4_infrastructure = False
        # warn if any set
        allocated = []
        unallocated = []
        for node in l3_devices:
            allocated += sorted([
                i for i in node.physical_interfaces
                if i.is_bound and i.ipv4_address
            ])
            unallocated += sorted([
                i for i in node.physical_interfaces
                if i.is_bound and not i.ipv4_address
            ])

        #TODO: what if IP is set but not a prefix?
        if len(allocated):
            #TODO: if set is > 50% of nodes then list those that are NOT set
            log.warning(
                "Using automatic IPv4 interface allocation. IPv4 interface addresses specified on interfaces %s will be ignored."
                % allocated)

    # TODO: need to set allocate_ipv4 by default in the readers

    if manual_alloc_ipv4_infrastructure:
        manual_ipv4_infrastructure_allocation(anm)
    else:
        ipv4.allocate_infra(g_ipv4, infra_block)

    if g_in.data.alloc_ipv4_loopbacks is False:
        manual_ipv4_loopback_allocation(anm)
    else:
        # Check if some nodes are allocated
        allocated = sorted([n for n in g_ip if n['input'].loopback_v4])
        unallocated = sorted([n for n in g_ip if not n['input'].loopback_v4])
        if len(allocated):
            log.warning(
                "Using automatic IPv4 loopback allocation. IPv4 loopback addresses specified on nodes %s will be ignored."
                % allocated)
            #TODO: if set is > 50% of nodes then list those that are NOT set
        ipv4.allocate_loopbacks(g_ipv4, loopback_block)

    # TODO: need to also support secondary_loopbacks for IPv6
    # TODO: only call if secondaries are set

    ipv4.allocate_vrf_loopbacks(g_ipv4, vrf_loopback_block)

    # TODO: replace this with direct allocation to interfaces in ip alloc plugin
    #TODO: add option for nonzero interfaces on node - ie node.secondary_loopbacks

    for node in g_ipv4.routers():
        node.loopback_zero.ip_address = node.loopback
        node.loopback_zero.subnet = netaddr.IPNetwork("%s/32" % node.loopback)
        for interface in node.loopback_interfaces:
            if not interface.is_loopback_zero:
                interface.ip_address = interface.loopback  #TODO: fix this inconsistency elsewhere
Esempio n. 7
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""

    import autonetkit.plugins.ipv4 as ipv4
    import netaddr

    g_ipv4 = anm.add_overlay("ipv4")
    g_ip = anm["ip"]
    g_in = anm["input"]
    g_ipv4.add_nodes_from(g_ip, retain=["label", "broadcast_domain"])  # retain if collision domain or not

    # Copy ASN attribute chosen for collision domains (used in alloc algorithm)

    ank_utils.copy_attr_from(g_ip, g_ipv4, "asn", nbunch=g_ipv4.nodes("broadcast_domain"))
    g_ipv4.add_edges_from(g_ip.edges())

    # check if ip ranges have been specified on g_in

    (infra_block, loopback_block, vrf_loopback_block) = extract_ipv4_blocks(anm)

    # TODO: don't present if using manual allocation
    block_message = "IPv4 allocations: Infrastructure: %s, Loopback: %s" % (infra_block, loopback_block)
    if any(i for n in g_ip.nodes() for i in n.loopback_interfaces if not i.is_loopback_zero):
        block_message += " Secondary Loopbacks: %s" % vrf_loopback_block

    log.info(block_message)

    # See if IP addresses specified on each interface

    # do we need this still? in ANM? - differnt because input graph.... but can map back to  self overlay first then phy???
    l3_devices = [d for d in g_in if d.device_type in ("router", "server")]

    manual_alloc_devices = set()
    for device in l3_devices:
        physical_interfaces = list(device.physical_interfaces)
        allocated = list(interface.ipv4_address for interface in physical_interfaces if interface.is_bound)
        if all(interface.ipv4_address for interface in physical_interfaces if interface.is_bound):
            manual_alloc_devices.add(device)  # add as a manual allocated device

    if manual_alloc_devices == set(l3_devices):
        manual_alloc_ipv4_infrastructure = True
    else:
        manual_alloc_ipv4_infrastructure = False
        # warn if any set
        allocated = []
        unallocated = []
        for node in l3_devices:
            allocated += sorted([i for i in node.physical_interfaces if i.is_bound and i.ipv4_address])
            unallocated += sorted([i for i in node.physical_interfaces if i.is_bound and not i.ipv4_address])

        # TODO: what if IP is set but not a prefix?
        if len(allocated):
            # TODO: if set is > 50% of nodes then list those that are NOT set
            log.warning(
                "Using automatic IPv4 interface allocation. IPv4 interface addresses specified on interfaces %s will be ignored."
                % allocated
            )

    # TODO: need to set allocate_ipv4 by default in the readers

    if manual_alloc_ipv4_infrastructure:
        manual_ipv4_infrastructure_allocation(anm)
    else:
        ipv4.allocate_infra(g_ipv4, infra_block)

    if g_in.data.alloc_ipv4_loopbacks is False:
        manual_ipv4_loopback_allocation(anm)
    else:
        # Check if some nodes are allocated
        allocated = sorted([n for n in g_ip if n["input"].loopback_v4])
        unallocated = sorted([n for n in g_ip if not n["input"].loopback_v4])
        if len(allocated):
            log.warning(
                "Using automatic IPv4 loopback allocation. IPv4 loopback addresses specified on nodes %s will be ignored."
                % allocated
            )
            # TODO: if set is > 50% of nodes then list those that are NOT set
        ipv4.allocate_loopbacks(g_ipv4, loopback_block)

    # TODO: need to also support secondary_loopbacks for IPv6
    # TODO: only call if secondaries are set

    ipv4.allocate_vrf_loopbacks(g_ipv4, vrf_loopback_block)

    # TODO: replace this with direct allocation to interfaces in ip alloc plugin
    # TODO: add option for nonzero interfaces on node - ie node.secondary_loopbacks

    for node in g_ipv4.routers():
        node.loopback_zero.ip_address = node.loopback
        node.loopback_zero.subnet = netaddr.IPNetwork("%s/32" % node.loopback)
        for interface in node.loopback_interfaces:
            if not interface.is_loopback_zero:
                interface.ip_address = interface.loopback  # TODO: fix this inconsistency elsewhere