Ejemplo n.º 1
0
def build_network(input_filename):
    anm = AbstractNetworkModel()
    input_graph = ank.load_graphml(input_filename)

    G_in = anm.add_overlay("input", input_graph)
    ank.set_node_default(G_in, G_in, platform="netkit")
    ank.set_node_default(G_in, G_in, host="nectar1")

    graph_product.expand(G_in)
    
    if len(ank.unique_attr(G_in, "asn")) > 1:
        # Multiple ASNs set, use label format device.asn 
        anm.set_node_label(".as",  ['label', 'pop', 'asn'])

# set syntax for routers according to platform
    G_in.update(G_in.nodes("is_router", platform = "junosphere"), syntax="junos")
    G_in.update(G_in.nodes("is_router", platform = "dynagen"), syntax="ios")
    G_in.update(G_in.nodes("is_router", platform = "netkit"), syntax="quagga")

    G_graphics = anm.add_overlay("graphics") # plotting data
    G_graphics.add_nodes_from(G_in, retain=['x', 'y', 'device_type', 'device_subtype', 'asn'])

    build_phy(anm)
    build_ip(anm)
    build_ospf(anm)
    build_bgp(anm)

    return anm
Ejemplo n.º 2
0
def build_network(input_filename):
    anm = AbstractNetworkModel()
    input_graph = ank.load_graphml(input_filename)

    G_in = anm.add_overlay("input", input_graph)
    ank.set_node_default(G_in, G_in, platform="netkit")
    ank.set_node_default(G_in, G_in, host="nectar1")

    if len(ank.unique_attr(G_in, "asn")) > 1:
        # Multiple ASNs set, use label format device.asn
        anm.set_node_label(".as", ['label', 'asn'])


# set syntax for routers according to platform
    G_in.update(G_in.nodes("is_router", platform="junosphere"), syntax="junos")
    G_in.update(G_in.nodes("is_router", platform="dynagen"), syntax="ios")
    G_in.update(G_in.nodes("is_router", platform="netkit"), syntax="quagga")

    G_graphics = anm.add_overlay("graphics")  # plotting data
    G_graphics.add_nodes_from(G_in, retain=['x', 'y', 'device_type', 'asn'])

    build_phy(anm)
    build_ip(anm)
    build_ospf(anm)
    build_bgp(anm)

    return anm
Ejemplo n.º 3
0
def main():
    ank_version = pkg_resources.get_distribution("AutoNetkit").version
    log.info("AutoNetkit %s" % ank_version)

    import optparse
    opt = optparse.OptionParser()
    opt.add_option('--file', '-f', default= None, help="Load topology from FILE")        
    opt.add_option('--monitor', '-m',  action="store_true", default= False, help="Monitor input file for changes")        
    opt.add_option('--debug',  action="store_true", default= False, help="Debug mode")        
    opt.add_option('--compile',  action="store_true", default= False, help="Compile")        
    opt.add_option('--deploy',  action="store_true", default= False, help="Deploy")        
    opt.add_option('--measure',  action="store_true", default= False, help="Measure")        
    options, arguments = opt.parse_args()

    input_filename = options.file
    if not options.file:
        input_filename = "ank.graphml"

    if options.debug:
        #TODO: fix this
        import logging
        logger = logging.getLogger("ANK")
        logger.setLevel(logging.DEBUG)

    if options.compile:
        anm = build_network(input_filename)
        anm.save()
        nidb = compile_network(anm)
        nidb.save()
        render.remove_dirs(["rendered/nectar1/nklab/"])
        render.render(nidb)
    else:
        anm = AbstractNetworkModel()
        anm.restore_latest()
        nidb = NIDB()
        nidb.restore_latest()

    if options.deploy:
        deploy_network(nidb)
    if options.measure:
        measure_network(nidb)

    if options.monitor:
        try:
            log.info("Monitoring for updates...")
            while True:
                time.sleep(0.2)
                if change_monitor.check_for_change(input_filename, anm):
                    try:
                        log.info("Input graph updated, recompiling network")
                        if options.compile:
                            nidb = compile_network(anm)
                            render.remove_dirs(["rendered/nectar1/nklab/"])
                            render.render(nidb)
                        if options.deploy:
                            deploy_network(nidb)
                        if options.measure:
                            measure_network(nidb)
                        log.info("Monitoring for updates...")
                    except:
                        # TODO: remove this, add proper warning
                        log.warn("Unable to build network")
                        pass
        except KeyboardInterrupt:
            log.info("Exiting")