Exemplo n.º 1
0
def build_ip(anm):
    import autonetkit.plugins.ipv4 as ip
    G_ip = anm.add_overlay("ip")
    G_in = anm['input']
    G_graphics = anm['graphics']
    G_phy = anm['phy']

    G_ip.add_nodes_from(G_in)
    G_ip.add_edges_from(G_in.edges(type="physical"))

    ank.aggregate_nodes(G_ip, G_ip.nodes("is_switch"), retain = "edge_id")

    edges_to_split = [edge for edge in G_ip.edges() if edge.attr_both("is_l3device")]
    split_created_nodes = list(ank.split(G_ip, edges_to_split, retain='edge_id'))
    for node in split_created_nodes:
        node['graphics'].x = ank.neigh_average(G_ip, node, "x", G_graphics)
        node['graphics'].y = ank.neigh_average(G_ip, node, "y", G_graphics)

    G_ip.update(split_created_nodes, collision_domain=True)

    for node in G_ip.nodes("collision_domain"):
        graphics_node = G_graphics.node(node)
        node.host = G_phy.node(node.neighbors().next()).host # Set host to be same as one of the neighbors (arbitrary choice)
        asn = ank.neigh_most_frequent(G_ip, node, "asn", G_phy) # arbitrary choice
        node.asn = asn
        graphics_node.asn = asn
        graphics_node.x = ank.neigh_average(G_ip, node, "x", G_graphics)

        graphics_node.device_type = "collision_domain"
        cd_label = "cd_" + "_".join(sorted(ank.neigh_attr(G_ip, node, "label", G_phy)))
        node.label = cd_label 
        graphics_node.label = cd_label

    ip.allocate_ips(G_ip)
Exemplo n.º 2
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""
    g_ipv4 = anm.add_overlay("ipv4")
    g_in = anm['input']
    g_graphics = anm['graphics']
    g_phy = anm['phy']

    g_ipv4.add_nodes_from(g_in)
    g_ipv4.add_edges_from(g_in.edges(type="physical"))

    ank_utils.aggregate_nodes(g_ipv4, g_ipv4.nodes("is_switch"),
                              retain="edge_id")

    edges_to_split = [edge for edge in g_ipv4.edges() if edge.attr_both(
        "is_l3device")]
    split_created_nodes = list(
        ank_utils.split(g_ipv4, edges_to_split, retain='edge_id'))
    for node in split_created_nodes:
        node['graphics'].x = ank_utils.neigh_average(g_ipv4, node, "x",
                                                     g_graphics) + 0.1 # temporary fix for gh-90
        node['graphics'].y = ank_utils.neigh_average(g_ipv4, node, "y",
                                                     g_graphics) + 0.1 # temporary fix for gh-90
        asn = ank_utils.neigh_most_frequent(
            g_ipv4, node, "asn", g_phy)  # arbitrary choice
        node['graphics'].asn = asn
        node.asn = asn # need to use asn in IP overlay for aggregating subnets

    switch_nodes = g_ipv4.nodes("is_switch")  # regenerate due to aggregated
    g_ipv4.update(switch_nodes, collision_domain=True)
                 # switches are part of collision domain
    g_ipv4.update(split_created_nodes, collision_domain=True)
# Assign collision domain to a host if all neighbours from same host
    for node in split_created_nodes:
        if ank_utils.neigh_equal(g_ipv4, node, "host", g_phy):
            node.host = ank_utils.neigh_attr(
                g_ipv4, node, "host", g_phy).next()  # first attribute

# set collision domain IPs
    for node in g_ipv4.nodes("collision_domain"):
        graphics_node = g_graphics.node(node)
        graphics_node.device_type = "collision_domain"
        if not node.is_switch:
            label = "_".join(
                sorted(ank_utils.neigh_attr(g_ipv4, node, "label", g_phy)))
            cd_label = "cd_%s" % label  # switches keep their names
            node.label = cd_label
            node.cd_id = cd_label
            graphics_node.label = cd_label

    #TODO: need to set allocate_ipv4 by default in the readers
    if g_in.data.allocate_ipv4 is False:
        manual_ipv4_allocation(anm)
    else:
        import autonetkit.plugins.ipv4 as ipv4
        ipv4.allocate_ips(g_ipv4, infrastructure)
        ank_utils.save(g_ipv4)
Exemplo n.º 3
0
def build_ip(anm):
    import autonetkit.plugins.ipv4 as ip
    G_ip = anm.add_overlay("ip")
    G_in = anm['input']
    G_graphics = anm['graphics']
    G_phy = anm['phy']

    G_ip.add_nodes_from(G_in)
    G_ip.add_edges_from(G_in.edges(type="physical"))

    ank.aggregate_nodes(G_ip, G_ip.nodes("is_switch"), retain="edge_id")

    edges_to_split = [
        edge for edge in G_ip.edges() if edge.attr_both("is_l3device")
    ]
    split_created_nodes = list(
        ank.split(G_ip, edges_to_split, retain='edge_id'))
    for node in split_created_nodes:
        node['graphics'].x = ank.neigh_average(G_ip, node, "x", G_graphics)
        node['graphics'].y = ank.neigh_average(G_ip, node, "y", G_graphics)

    G_ip.update(split_created_nodes, collision_domain=True)

    for node in G_ip.nodes("collision_domain"):
        graphics_node = G_graphics.node(node)
        node.host = G_phy.node(
            node.neighbors().next()
        ).host  # Set host to be same as one of the neighbors (arbitrary choice)
        asn = ank.neigh_most_frequent(G_ip, node, "asn",
                                      G_phy)  # arbitrary choice
        node.asn = asn
        graphics_node.asn = asn
        graphics_node.x = ank.neigh_average(G_ip, node, "x", G_graphics)

        graphics_node.device_type = "collision_domain"
        cd_label = "cd_" + "_".join(
            sorted(ank.neigh_attr(G_ip, node, "label", G_phy)))
        node.label = cd_label
        graphics_node.label = cd_label

    ip.allocate_ips(G_ip)
Exemplo n.º 4
0
def build_ipv4(anm, infrastructure=True):
    """Builds IPv4 graph"""
    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())
    autonetkit.update_http(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:
        import autonetkit.plugins.ipv4 as ipv4

        ipv4.allocate_ips(g_ipv4, infrastructure=True, loopbacks=False)
        # ank_utils.save(g_ipv4)

    if g_in.data.alloc_ipv4_loopbacks is False:
        manual_ipv4_loopback_allocation(anm)
    else:
        import autonetkit.plugins.ipv4 as ipv4

        ipv4.allocate_ips(g_ipv4, infrastructure=False, loopbacks=True)
        # ank_utils.save(g_ipv4)

    # TODO: need to also support secondary_loopbacks for IPv6
    ipv4.allocate_ips(g_ipv4, infrastructure=False, loopbacks=False, secondary_loopbacks=True)

    autonetkit.update_http(anm)

    # 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

    # TODO: also map loopbacks to loopback interface 0
    autonetkit.update_http(anm)