Exemplo n.º 1
0
def compile_network(anm):
    # log.info("Creating base network model")
    nidb = create_nidb(anm)
    g_phy = anm['phy']
    # log.info("Compiling to targets")

    for target_data in config.settings['Compile Targets'].values():
        host = target_data['host']
        platform = target_data['platform']
        if platform == 'netkit':
            import autonetkit.compilers.platform.netkit as pl_netkit
            platform_compiler = pl_netkit.NetkitCompiler(nidb, anm, host)
        elif platform == 'VIRL':
            try:
                import autonetkit_cisco.compilers.platform.cisco as pl_cisco
                platform_compiler = pl_cisco.CiscoCompiler(nidb, anm, host)
            except ImportError:
                log.debug('Unable to load VIRL platform compiler')
        elif platform == 'dynagen':
            import autonetkit.compilers.platform.dynagen as pl_dynagen
            platform_compiler = pl_dynagen.DynagenCompiler(nidb, anm, host)
        elif platform == 'junosphere':
            import autonetkit.compilers.platform.junosphere as pl_junosphere
            platform_compiler = pl_junosphere.JunosphereCompiler(
                nidb, anm, host)

        if any(g_phy.nodes(host=host, platform=platform)):
            # log.info('Compiling configurations for %s on %s'
            # % (platform, host))
            platform_compiler.compile()  # only compile if hosts set
        else:
            log.debug('No devices set for %s on %s' % (platform, host))

    return nidb
Exemplo n.º 2
0
def compile_network(anm):
    nidb = create_nidb(anm)
    g_phy = anm['phy']

    for target_data in config.settings['Compile Targets'].values():
        host = target_data['host']
        platform = target_data['platform']
        if platform == "netkit":
            import autonetkit.compilers.platform.netkit as pl_netkit
            platform_compiler = pl_netkit.NetkitCompiler(nidb, anm, host)
        elif platform == "VIRL":
            try:
                import autonetkit_cisco.compilers.platform.cisco as pl_cisco
                platform_compiler = pl_cisco.CiscoCompiler(nidb, anm, host)
            except ImportError:
                log.debug("Unable to load VIRL platform compiler")
        elif platform == "dynagen":
            import autonetkit.compilers.platform.dynagen as pl_dynagen
            platform_compiler = pl_dynagen.DynagenCompiler(nidb, anm, host)
        elif platform == "junosphere":
            import autonetkit.compilers.platform.junosphere as pl_junosphere
            platform_compiler = pl_junosphere.JunosphereCompiler(
                nidb, anm, host)

        if any(g_phy.nodes(host=host, platform=platform)):
            log.info("Compiling configurations for %s on %s" %
                     (platform, host))
            platform_compiler.compile()  # only compile if hosts set
        else:
            log.debug("No devices set for %s on %s" % (platform, host))

    return nidb
Exemplo n.º 3
0
def compile_network(anm):
    nidb = create_nidb(anm)
    g_phy = anm['phy']

    for target, target_data in config.settings['Compile Targets'].items():
        host = target_data['host']
        platform = target_data['platform']
        if platform == "netkit":
            import autonetkit.compilers.platform.netkit as pl_netkit
            platform_compiler = pl_netkit.NetkitCompiler(nidb, anm, host)
        elif platform == "VIRL":
            try:
                import autonetkit_cisco.compilers.platform.cisco as pl_cisco
                platform_compiler = pl_cisco.CiscoCompiler(nidb, anm, host)
            except ImportError, e:
                print e
                log.warning("Unable to load VIRL platform compiler")
        elif platform == "dynagen":
            import autonetkit.compilers.platform.dynagen as pl_dynagen
            platform_compiler = pl_dynagen.DynagenCompiler(nidb, anm, host)
Exemplo n.º 4
0
def test():


    automated = True # whether to open ksdiff, log to file...
    if __name__ == "__main__":
        automated = False

    dirname, filename = os.path.split(os.path.abspath(__file__))

    anm =  autonetkit.NetworkModel()
    input_file = os.path.join(dirname, "small_internet.graphml")
    input_graph = graphml.load_graphml(input_file)

    import autonetkit.build_network as build_network
    anm = build_network.initialise(input_graph)
    anm = build_network.apply_design_rules(anm)
    anm.save()
    anm_restored =  autonetkit.NetworkModel()
    anm_restored.restore_latest()
    g_phy_original = anm['phy']
    g_phy_restored = anm_restored['phy']
    assert(all(n in g_phy_restored for n in g_phy_original))

    #TODO: do more extensive deep check of parameters

    import autonetkit.workflow as workflow
    render_hostname = "localhost"

    nidb = workflow.create_nidb(anm)
    import autonetkit.compilers.platform.netkit as pl_netkit
    nk_compiler = pl_netkit.NetkitCompiler(nidb, anm, render_hostname)
    nk_compiler.compile()

    nidb.save()
    nidb_restored =  autonetkit.DeviceModel()
    nidb_restored.restore_latest()
    assert(all(n in nidb_restored for n in nidb))

    # cleanup
    shutil.rmtree("versions")
Exemplo n.º 5
0
anm =  autonetkit.ANM()
input_file = os.path.join(dirname, "small_internet.graphml")
input_graph = graphml.load_graphml(input_file)

import autonetkit.build_network as build_network
anm = build_network.initialise(input_graph)
anm = build_network.apply_design_rules(anm)
anm.save()
anm_restored =  autonetkit.ANM()
anm_restored.restore_latest()
g_phy_original = anm['phy']
g_phy_restored = anm_restored['phy']
assert(all(n in g_phy_restored for n in g_phy_original))

#TODO: do more extensive deep check of parameters

import autonetkit.console_script as console_script
render_hostname = "localhost"

nidb = console_script.create_nidb(anm)
import autonetkit.compilers.platform.netkit as pl_netkit
nk_compiler = pl_netkit.NetkitCompiler(nidb, anm, render_hostname)
nk_compiler.compile()

nidb.save()
nidb_restored =  autonetkit.NIDB()
nidb_restored.restore_latest()
assert(all(n in nidb_restored for n in nidb))

# cleanup
shutil.rmtree("versions")
Exemplo n.º 6
0
anm = build_network.apply_design_rules(anm)

render_hostname = "localhost"

g_ospf = anm['ospf']
e1_8 = anm['ospf'].edge('5', '44')
print "before:", e1_8.cost
e1_8.cost = 1001
e1_8.apply_to_interfaces("cost")
print "after:", e1_8.cost

autonetkit.update_http(anm)

#nidb_a = nidb # copy original

nidb_b = console_script.create_nidb(anm)
render_hostname = "localhost"

platform_compiler = pl_netkit.NetkitCompiler(nidb_b, anm, render_hostname)
platform_compiler.compile()

autonetkit.update_http(anm, nidb_b)

import autonetkit.diff
diffs = autonetkit.diff.compare_nidb(nidb, nidb_b)
import pprint
pprint.pprint(diffs)

import autonetkit.push_changes
autonetkit.push_changes.apply_difference(nidb, diffs, emulation_server)
Exemplo n.º 7
0
def test():
	automated = True # whether to open ksdiff, log to file...
	if __name__ == "__main__":
	    automated = False

	dirname, filename = os.path.split(os.path.abspath(__file__))
	parent_dir = os.path.abspath(os.path.join(dirname, os.pardir))

	anm =  autonetkit.NetworkModel()
	input_file = os.path.join(parent_dir, "small_internet.graphml")
	input_graph = graphml.load_graphml(input_file)

	import autonetkit.build_network as build_network
	anm = build_network.initialise(input_graph)
	anm = build_network.apply_design_rules(anm)



	try:
		from websocket import create_connection
	except ImportError:
		print "websocket-client package not installed"
	else:
		autonetkit.update_http(anm)

		ws = create_connection("ws://localhost:8000/ws")
		ws.send("overlay_list")
		result =  ws.recv()
		expected = '{"overlay_list": ["bgp", "ebgp", "ebgp_v4", "ebgp_v6", "eigrp", graphics", "ibgp_v4", "ibgp_v6", "ibgp_vpn_v4", "input", "input_directed", "ip", "ipv4", "ipv6", "isis", "l3_conn", "ospf", "phy", "vrf"]}'
		assert(result == expected)

		overlay_id = "phy"
		ws.send("overlay_id=" + overlay_id)
		result =  ws.recv()
		with open(os.path.join(dirname, "expected_phy.json"), "r") as fh:
			expected = fh.read()

		assert(result == expected)
		ws.close()

		import autonetkit.console_script as console_script
		render_hostname = "localhost"

		nidb = console_script.create_nidb(anm)
		nidb._graph.graph['timestamp'] = "123456"

		import autonetkit.compilers.platform.netkit as pl_netkit
		nk_compiler = pl_netkit.NetkitCompiler(nidb, anm, render_hostname)
		nk_compiler.compile()
		autonetkit.update_http(anm, nidb)

		ws = create_connection("ws://localhost:8000/ws")
		ws.send("overlay_list")
		result =  ws.recv()
		expected = '{"overlay_list": ["bgp", "ebgp", "ebgp_v4", "ebgp_v6", "eigrp", graphics", "ibgp_v4", "ibgp_v6", "ibgp_vpn_v4", "input", "input_directed", "ip", "ipv4", "ipv6", "isis", "l3_conn", "nidb", "ospf", "phy", "vrf"]}'
		assert(result == expected)

		overlay_id = "nidb"
		ws.send("overlay_id=" + overlay_id)
		result =  ws.recv()
		with open(os.path.join(dirname, "expected_nidb.json"), "r") as fh:
			expected = fh.read()

		assert(result == expected)
		ws.close()