Пример #1
0
def build_anm(topology_name):
    print "Building anm for %s" % topology_name
    dirname, filename = os.path.split(os.path.abspath(__file__))
    input_filename = os.path.join(dirname, "%s.graphml" % topology_name)

    anm = autonetkit.ANM()
    input_graph = graphml.load_graphml(input_filename)

    import autonetkit.build_network as build_network
    anm = build_network.initialise(input_graph)
    anm = build_network.apply_design_rules(anm)
    return anm
Пример #2
0
def build_anm(topology_name):
    print "Building anm for %s" % topology_name
    dirname, filename = os.path.split(os.path.abspath(__file__))
    input_filename = os.path.join(dirname, "%s.graphml" % topology_name)

    anm =  autonetkit.ANM()
    input_graph = graphml.load_graphml(input_filename)

    import autonetkit.build_network as build_network
    anm = build_network.initialise(input_graph)
    anm = build_network.apply_design_rules(anm)
    return anm
Пример #3
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")
Пример #4
0
import autonetkit.load.graphml as graphml
import shutil

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.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)
Пример #5
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()
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)

    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()

    import autonetkit.render
    autonetkit.render.render(nidb)

    import os
    dst_folder = nidb.topology['localhost'].render_dst_folder

    # test folder structure
    dir_structure = {}
    for path, dirs, files in os.walk(dst_folder):
        dir_structure[path] = list(files)

    # record folder structure
    structure_filename = os.path.join(dirname, "dir_structure_expected.tar.gz")
    json_to_gzip(dir_structure, structure_filename)
    dir_structure_expected = gzip_to_json(structure_filename)
    assert dir_structure == dir_structure_expected

    routernames = ["as1r1", "as20r3"]
    config_files = ["bgpd.conf", "ospfd.conf", "zebra.conf"]

    for routername in routernames:
        router = nidb.node(routername)
        zebra_dir = os.path.join(router.render.base_dst_folder, "etc", "zebra")

        for conf_file in config_files:
            expected_filename = os.path.join(dirname, "%s_%s" % (routername, conf_file))
            with open(expected_filename, "r") as fh:
                expected_result = fh.read()

            actual_filename = os.path.join(zebra_dir, conf_file)
            with open(actual_filename, "r") as fh:
                actual_result = fh.read()

            if expected_result != actual_result:
                if automated:
                    #TODO: use difflib
                    print "Expected"
                    print expected_result
                    print "Actual"
                    print actual_result
                    raise AssertionError("Invalid result")
                else:
                    cmd = ["ksdiff", expected_filename, actual_filename]
                    child = subprocess.Popen(cmd)
                    answer = raw_input("Merge (answer yes to merge): ")
                    if answer == "yes":
                        print "Replacing expected with output"
                        shutil.move(actual_filename, expected_filename)