Esempio n. 1
0
def compile_network(anm):
    nidb = NIDB()
    G_phy = anm.overlay.phy
    G_ip = anm.overlay.ip
    G_graphics = anm.overlay.graphics
    #TODO: build this on a platform by platform basis
    nidb.add_nodes_from(G_phy, retain=['label', 'host', 'platform'])

    nidb.add_nodes_from(G_ip.nodes("collision_domain"),
                        retain=['label', 'host'],
                        collision_domain=True)
    # add edges to switches
    edges_to_add = [
        edge for edge in G_phy.edges()
        if edge.src.is_switch or edge.dst.is_switch
    ]
    edges_to_add += [
        edge for edge in G_ip.edges()
        if edge.src.collision_domain or edge.dst.collision_domain
    ]
    nidb.add_edges_from(edges_to_add, retain='edge_id')

    #TODO: boundaries is still a work in progress...
    for node in nidb:
        graphics_node = G_graphics.node(node)
        node.graphics.x = graphics_node.x
        node.graphics.y = graphics_node.y
        node.graphics.device_type = graphics_node.device_type
        node.device_type = graphics_node.device_type

    host = "nectar1"
    #junosphere_compiler = compiler.JunosphereCompiler(nidb, anm, host)
    #junosphere_compiler.compile()
    netkit_compiler = compiler.NetkitCompiler(nidb, anm, host)
    netkit_compiler.compile()
    #dynagen_compiler = compiler.DynagenCompiler(nidb, anm, host)
    #dynagen_compiler.compile()

    #cisco_compiler = compiler.CiscoCompiler(nidb, anm, host)
    #cisco_compiler.compile()

    return nidb