def measure_network(nidb): import autonetkit.measure as measure log.info("Measuring network") remote_hosts = [node.tap.ip for node in nidb.nodes("is_router")] dest_node = random.choice([n for n in nidb.nodes("is_l3device")]) log.info("Tracing to randomly selected node: %s" % dest_node) dest_ip = dest_node.interfaces[0].ipv4_address # choose random interface on this node command = "traceroute -n -a -U -w 0.5 %s" % dest_ip measure.send(nidb, command, remote_hosts, threads = 10) # abort after 10 fails, proceed on any success, 0.1 second timeout (quite aggressive) #command = 'vtysh -c "show ip route"' #measure.send(nidb, command, remote_hosts, threads = 5) remote_hosts = [node.tap.ip for node in nidb.nodes( "is_router") if node.bgp.ebgp_neighbors] command = "cat /var/log/zebra/bgpd.log"
def collect_sh_ip_route(anm, nidb, start_node = None): if not start_node: start_node = random.choice([n for n in nidb.nodes("is_router")]) #TODO: move this to another module, eg measure import autonetkit.measure as measure import autonetkit.verify as verify import autonetkit command = 'vtysh -c "show ip route"' #TODO: make auto take tap ip if netkit platform node #TODO: auto make put into list if isinstance(remote_hosts, nidb_node) remote_hosts = [start_node.tap.ip] result = measure.send(nidb, command, remote_hosts) processed = [] for line in result: processed.append([anm['ipv4'].node(n) for n in line]) #TODO: move this into verify module verification_results = verify.igp_routes(anm, processed) processed_with_results = [] for line in processed: prefix = str(line[-1].subnet) try: result = verification_results[prefix] except KeyError: result = False # couldn't find prefix processed_with_results.append({ 'path': line, 'verified': result, }) autonetkit.update_http(anm, nidb) ank_messaging.highlight([], [], processed_with_results)
def collect_sh_ip_route(anm, nidb, start_node=None): if not start_node: start_node = random.choice([n for n in nidb.nodes("is_router")]) #TODO: move this to another module, eg measure import autonetkit.measure as measure import autonetkit.verify as verify import autonetkit command = 'vtysh -c "show ip route"' #TODO: make auto take tap ip if netkit platform node #TODO: auto make put into list if isinstance(remote_hosts, nidb_node) remote_hosts = [start_node.tap.ip] result = measure.send(nidb, command, remote_hosts) processed = [] for line in result: processed.append([anm['ipv4'].node(n) for n in line]) #TODO: move this into verify module verification_results = verify.igp_routes(anm, processed) processed_with_results = [] for line in processed: prefix = str(line[-1].subnet) try: result = verification_results[prefix] except KeyError: result = False # couldn't find prefix processed_with_results.append({ 'path': line, 'verified': result, }) autonetkit.update_http(anm, nidb) ank_messaging.highlight([], [], processed_with_results)
def apply_difference(nidb_a, nidb_diff): #TODO: batch node updates try: modified_nodes = nidb_diff['nodes']['m'] except KeyError: print "no nodes modified" modified_nodes = {} ank_messaging.highlight(modified_nodes, [], []) for node_id, node_data in modified_nodes.items(): nidb_node = nidb_a.node(node_id) #print nidb_node.tap.ip if "_interfaces" in node_data: for interface_id, interface_data in node_data['_interfaces'].items(): interface = nidb_node.interface(interface_id) if 'ospf_cost' in interface_data: cost_1 = interface_data['ospf_cost'][1] cost_2 = interface_data['ospf_cost'][2] #print "%s (%s) ospf_cost %s -> %s" % (interface.id, interface.description, #cost_1, cost_2) # TODO: use a template for this (even inline would be an improvement) #TODO: can vtysh take \n delimeted data? command = "\n".join([ "conf t", "interface %s" % interface.id, "ip ospf cost %s " % cost_2]) command = 'vtysh -c "%s"' % command remote_hosts = [nidb_node.tap.ip] measure.send(nidb_a, command, remote_hosts) command = "show ip ospf interface %s" % interface.id command = 'vtysh -c "%s"' % command measure.send(nidb_a, command, remote_hosts)
def measure_network(anm, nidb): import autonetkit.measure as measure log.info("Measuring network") if 1: remote_hosts = [node.tap.ip for node in nidb.nodes("is_router")] dest_node = random.choice([n for n in nidb.nodes("is_l3device")]) log.info("Tracing to randomly selected node: %s" % dest_node) dest_ip = dest_node.interfaces[ 0].ipv4_address # choose random interface on this node command = "traceroute -n -a -U -w 0.5 %s" % dest_ip measure.send(nidb, command, remote_hosts, threads=10) # abort after 10 fails, proceed on any success, 0.1 second timeout (quite aggressive) if 0: collect_sh_ip_route(anm, nidb) if 0: #measure.send(nidb, command, remote_hosts, threads = 5) remote_hosts = [ node.tap.ip for node in nidb.nodes("is_router") if node.bgp.ebgp_neighbors ] command = "cat /var/log/zebra/bgpd.log"
def main(): import argparse usage = "ank_measure_client" parser = argparse.ArgumentParser(description=usage) parser.add_argument('filename', default=None, help="Input topology") parser.add_argument('--deploy', action="store_true", default=False, help="Deploy") parser.add_argument('--measure', action="store_true", default=False, help="Measure") arguments = parser.parse_args() if arguments.filename: import build # grabs build.py from example anm = build.build_overlays(arguments.filename) anm.save() import compile # grabs compile.py from example nidb = build.build_nidb(anm) nidb.save() messaging = ank_messaging.AnkMessaging() messaging.publish_anm(anm, nidb) host = "localhost" nk_compiler = compile.NetkitCompiler(nidb, anm, host) nk_compiler.compile() render.render(nidb) else: log.info( "No input file specified, attempting to load previously compiled network" ) # loading anm = autonetkit.anm.AbstractNetworkModel() anm.restore_latest() nidb = autonetkit.nidb.NIDB() nidb.restore_latest() username = "******" host = "192.168.255.129" if arguments.deploy: import autonetkit.deploy.netkit as nk_deploy dst_folder = nidb.topology['localhost'].render_dst_folder nk_deploy.deploy(host, username, dst_folder) if arguments.measure: """ Some notes on measurement: NOTE: Measure requires a remote host to be setup, and rabbitmq running, (by default ank will look on localhost) http://www.rabbitmq.com/install-debian.html or for OS X: http://superuser.com/questions/464311/open-port-5672-tcp-for-access-to-rabbitmq-on-mac and pip install pika pip install https://github.com/knipknap/exscript/tarball/master note this needs paramiko... which needs to compile. if you don't have python headers, eg in ubuntu: sudo apt-get install python-dev wget https://raw.github.com/sk2/autonetkit/master/autonetkit/measure_client.py sk2@ubuntu:~$ python measure_client.py --server 192.168.255.1 where --server specifies the rabbitmq server can also use through ANK package: install ank through github, then install Exscript can then do: ank_measure_client --server 192.168.255.1 """ import autonetkit.measure as measure log.info("Measuring network") remote_hosts = [node.tap.ip for node in nidb.routers()] #remote_hosts = remote_hosts[:3] # truncate for testing dest_node = random.choice(list(nidb.routers())) log.info("Tracing to randomly selected node: %s" % dest_node) dest_ip = dest_node.interfaces[ 0].ipv4_address # choose random interface on this node command = "traceroute -n -a -U -w 0.5 %s" % dest_ip #command = 'vtysh -c "show ip route"' measure.send(nidb, command, remote_hosts, threads=20) # abort after 10 fails, proceed on any success, 0.1 second timeout (quite aggressive) #command = 'vtysh -c "show ip route"' remote_hosts = [ node.tap.ip for node in nidb.routers() if node.bgp.ebgp_neighbors ] command = "cat /var/log/zebra/bgpd.log"
def main(): import argparse usage = "ank_measure_client" parser = argparse.ArgumentParser(description = usage) parser.add_argument('filename', default= None, help="Input topology") parser.add_argument('--deploy', action="store_true", default= False, help="Deploy") parser.add_argument('--measure', action="store_true", default= False, help="Measure") arguments = parser.parse_args() if arguments.filename: import build # grabs build.py from example anm = build.build_overlays(arguments.filename) anm.save() import compile # grabs compile.py from example nidb = build.build_nidb(anm) nidb.save() messaging = ank_messaging.AnkMessaging() messaging.publish_anm(anm, nidb) host = "localhost" nk_compiler = compile.NetkitCompiler(nidb, anm, host) nk_compiler.compile() render.render(nidb) else: log.info("No input file specified, attempting to load previously compiled network") # loading anm = autonetkit.anm.AbstractNetworkModel() anm.restore_latest() nidb = autonetkit.nidb.NIDB() nidb.restore_latest() username = "******" host = "192.168.255.129" if arguments.deploy: import autonetkit.deploy.netkit as nk_deploy dst_folder = nidb.topology['localhost'].render_dst_folder nk_deploy.deploy(host, username, dst_folder) if arguments.measure: """ Some notes on measurement: NOTE: Measure requires a remote host to be setup, and rabbitmq running, (by default ank will look on localhost) http://www.rabbitmq.com/install-debian.html or for OS X: http://superuser.com/questions/464311/open-port-5672-tcp-for-access-to-rabbitmq-on-mac and pip install pika pip install https://github.com/knipknap/exscript/tarball/master note this needs paramiko... which needs to compile. if you don't have python headers, eg in ubuntu: sudo apt-get install python-dev wget https://raw.github.com/sk2/autonetkit/master/autonetkit/measure_client.py sk2@ubuntu:~$ python measure_client.py --server 192.168.255.1 where --server specifies the rabbitmq server can also use through ANK package: install ank through github, then install Exscript can then do: ank_measure_client --server 192.168.255.1 """ import autonetkit.measure as measure log.info("Measuring network") remote_hosts = [node.tap.ip for node in nidb.routers() ] #remote_hosts = remote_hosts[:3] # truncate for testing dest_node = random.choice(list(nidb.routers())) log.info("Tracing to randomly selected node: %s" % dest_node) dest_ip = dest_node.interfaces[0].ipv4_address # choose random interface on this node command = "traceroute -n -a -U -w 0.5 %s" % dest_ip #command = 'vtysh -c "show ip route"' measure.send(nidb, command, remote_hosts, threads = 20) # abort after 10 fails, proceed on any success, 0.1 second timeout (quite aggressive) #command = 'vtysh -c "show ip route"' remote_hosts = [node.tap.ip for node in nidb.routers() if node.bgp.ebgp_neighbors] command = "cat /var/log/zebra/bgpd.log"