Ejemplo n.º 1
0
def build_ip(anm):
    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")
    #TODO: add function to update edge properties: can overload node update?

    #TODO: abstract this better
    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.overlay.graphics.x = ank.neigh_average(G_ip, node, "x",
                                                    G_graphics)
        node.overlay.graphics.y = ank.neigh_average(G_ip, node, "y",
                                                    G_graphics)
        node.overlay.graphics.asn = math.floor(
            ank.neigh_average(G_ip, node, "asn", G_phy))  # arbitrary choice

    switch_nodes = G_ip.nodes("is_switch")  # regenerate due to aggregated
    G_ip.update(switch_nodes,
                collision_domain=True)  # switches are part of collision domain
    G_ip.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.neigh_equal(G_ip, node, "host", G_phy):
            node.host = ank.neigh_attr(G_ip, node, "host",
                                       G_phy).next()  # first attribute


# set collision domain IPs
    collision_domain_id = (i for i in itertools.count(0))
    for node in G_ip.nodes("collision_domain"):
        graphics_node = G_graphics.node(node)
        graphics_node.device_type = "collision_domain"
        cd_id = collision_domain_id.next()
        node.cd_id = cd_id
        #TODO: Use this label
        if not node.is_switch:
            label = "_".join(sorted(ank.neigh_attr(G_ip, 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

    ip.allocate_ips(G_ip)
    ank.save(G_ip)
Ejemplo n.º 2
0
def build_ospf(anm):
    G_in = anm['input']
    G_ospf = anm.add_overlay("ospf")
    G_ospf.add_nodes_from(G_in.nodes("is_router"), retain=['asn'])
    G_ospf.add_nodes_from(G_in.nodes("is_switch"), retain=['asn'])
    G_ospf.add_edges_from(G_in.edges(), retain = ['edge_id', 'ospf_cost'])
#TODO: trim out non same asn edges
    ank.aggregate_nodes(G_ospf, G_ospf.nodes("is_switch"), retain = "edge_id")
    ank.explode_nodes(G_ospf, G_ospf.nodes("is_switch"))
    for link in G_ospf.edges():
           link.cost = 1
           link.area = 0

    non_same_asn_edges = [link for link in G_ospf.edges() if link.src.asn != link.dst.asn]
    G_ospf.remove_edges_from(non_same_asn_edges)
Ejemplo n.º 3
0
def build_ospf(anm):
    G_in = anm['input']
    G_ospf = anm.add_overlay("ospf")
    G_ospf.add_nodes_from(G_in.nodes("is_router"), retain=['asn'])
    G_ospf.add_nodes_from(G_in.nodes("is_switch"), retain=['asn'])
    G_ospf.add_edges_from(G_in.edges(), retain=['edge_id', 'ospf_cost'])
    #TODO: trim out non same asn edges
    ank.aggregate_nodes(G_ospf, G_ospf.nodes("is_switch"), retain="edge_id")
    ank.explode_nodes(G_ospf, G_ospf.nodes("is_switch"))
    for link in G_ospf.edges():
        link.cost = 1
        link.area = 0

    non_same_asn_edges = [
        link for link in G_ospf.edges() if link.src.asn != link.dst.asn
    ]
    G_ospf.remove_edges_from(non_same_asn_edges)
Ejemplo n.º 4
0
def build_ip(anm):
    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")
#TODO: add function to update edge properties: can overload node update?

#TODO: abstract this better
    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.overlay.graphics.x = ank.neigh_average(G_ip, node, "x", G_graphics)
        node.overlay.graphics.y = ank.neigh_average(G_ip, node, "y", G_graphics)
        node.overlay.graphics.asn = math.floor(ank.neigh_average(G_ip, node, "asn", G_phy)) # arbitrary choice

    switch_nodes = G_ip.nodes("is_switch")# regenerate due to aggregated
    G_ip.update(switch_nodes, collision_domain=True) # switches are part of collision domain
    G_ip.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.neigh_equal(G_ip, node, "host", G_phy):
            node.host = ank.neigh_attr(G_ip, node, "host", G_phy).next() # first attribute

# set collision domain IPs
    collision_domain_id = (i for i in itertools.count(0))
    for node in G_ip.nodes("collision_domain"):
        graphics_node = G_graphics.node(node)
        graphics_node.device_type = "collision_domain"
        cd_id = collision_domain_id.next()
        node.cd_id = cd_id
#TODO: Use this label
        if not node.is_switch:
            label = "_".join(sorted(ank.neigh_attr(G_ip, 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

    ip.allocate_ips(G_ip)
    ank.save(G_ip)