def main(device_ip, peer_ip): config = ConfigDictionary() username = config.username() password = config.password() print(device_ip + " logging in as " + username) jdev = Device(user=username, host=device_ip, password=password) jdev.open(gather_facts=False) jdev.timeout = 6000 try: resultxml = jdev.rpc.get_route_information(table='inet.0', protocol='bgp', peer=peer_ip, extensive=True) except Exception as err: print "CMD:" etree.dump(err.cmd) print "RSP:" etree.dump(err.rsp) for routexml in resultxml.findall('.//rt'): route = RouteData(routexml) print "destination: " + route.prefix() + "as-path: " + route.aspath() jdev.close()
def main(device_ip, peer_ip): config = ConfigDictionary() username = config.username() password = config.password() print (device_ip + " logging in as " + username) jdev = Device(user=username, host=device_ip, password=password) jdev.open(gather_facts=False) jdev.timeout=6000 try: resultxml = jdev.rpc.get_route_information(table='inet.0',protocol='bgp',peer=peer_ip,extensive=True) except Exception as err: print "CMD:" etree.dump(err.cmd) print "RSP:" etree.dump(err.rsp) for routexml in resultxml.findall('.//rt'): route = RouteData(routexml) print "destination: " + route.prefix() + "as-path: " + route.aspath() jdev.close()
def main(peer_asn, output): config = ConfigDictionary() username = config.username() password = config.password() local_preferences = config.get_list_of_localpref() for router in config.get_list_of_router_names(): jdev = Device(user=username, host=config.get_router_ip(router), password=password) jdev.open(gather_facts=False) jdev.timeout = 600 regex_asn = ".* " + peer_asn try: resultxml = jdev.rpc.get_route_information(table='inet.0', aspath_regex=regex_asn, extensive=True) except Exception as err: print "CMD:" etree.dump(err.cmd) print "RSP:" etree.dump(err.rsp) jdev.close() sorted_routes = {} sorted_routes["peer"] = [] sorted_routes["peer-indirect"] = [] sorted_routes["peer-routeserver"] = [] sorted_routes["transit"] = [] sorted_routes["customer"] = [] sorted_routes["outofrange"] = [] for routexml in resultxml.findall('.//rt'): route = RouteData(routexml) full_prefix = route.prefix() session_type = route.get_adjacency_type(local_preferences) sorted_routes[session_type].append(full_prefix) if output == 'machine': print json.dumps(sorted_routes) else: print "For " + router + " in " + config.get_router_location(router) + " Routes: " + str(len(sorted_routes["peer"])) + " via bilateral peering, " + str(len(sorted_routes["peer-routeserver"])) + " via peering at mlp, " + str(len(sorted_routes["peer-indirect"])) + " via peering in other cities " + str(len(sorted_routes["customer"])) + " via customer, and " + str(len(sorted_routes["transit"])) + " via transit."
def main(device_ip, peer_asn, output): config = ConfigDictionary() username = config.username() password = config.password() jdev = Device(user=username, host=device_ip, password=password) jdev.open(gather_facts=False) jdev.timeout = 600 regex_asn = ".* " + peer_asn try: resultxml = jdev.rpc.get_route_information(table='inet.0', aspath_regex=regex_asn, extensive=True) except Exception as err: print "CMD:" etree.dump(err.cmd) print "RSP:" etree.dump(err.rsp) jdev.close() sorted_routes = {} sorted_routes["peer"] = [] sorted_routes["transit"] = [] sorted_routes["customer"] = [] sorted_routes["outofrange"] = [] for routexml in resultxml.findall('.//rt'): route = RouteData(routexml) full_prefix = route.prefix() session_type = config.get_type_from_localpref(route.activelocalpref()) sorted_routes[session_type].append(full_prefix) if output == 'machine': print json.dumps(sorted_routes) else: print "Number of routes: " + str(len( sorted_routes["peer"])) + " via peering, " + str( len(sorted_routes["customer"])) + " via customer, and " + str( len(sorted_routes["transit"]) ) + " via transit. (use -m for full output and breakdown)"
def main(device_ip, peer_asn, output): config = ConfigDictionary() username = config.username() password = config.password() jdev = Device(user=username, host=device_ip, password=password) jdev.open(gather_facts=False) jdev.timeout = 600 regex_asn = ".* " + peer_asn try: resultxml = jdev.rpc.get_route_information(table='inet.0', aspath_regex=regex_asn, extensive=True) except Exception as err: print "CMD:" etree.dump(err.cmd) print "RSP:" etree.dump(err.rsp) jdev.close() sorted_routes = {} sorted_routes["peer"] = [] sorted_routes["transit"] = [] sorted_routes["customer"] = [] sorted_routes["outofrange"] = [] for routexml in resultxml.findall('.//rt'): route = RouteData(routexml) full_prefix = route.prefix() session_type = config.get_type_from_localpref(route.activelocalpref()) sorted_routes[session_type].append(full_prefix) if output == 'machine': print json.dumps(sorted_routes) else: print "Number of routes: " + str(len(sorted_routes["peer"])) + " via peering, " + str(len(sorted_routes["customer"])) + " via customer, and " + str(len(sorted_routes["transit"])) + " via transit. (use -m for full output and breakdown)"
def test_can_obtain_clean_aspath_for_route(self): resultxml = etree.fromstring( open('./tests/test_data/bgp_route.xml').read()) route = RouteData(resultxml.find('.//rt')) self.assertTrue(route.aspath() == '6939 6461 12536')
def test_can_get_localpref_for_active_prefix(self): resultxml = etree.fromstring( open('./tests/test_data/bgp_route.xml').read()) route = RouteData(resultxml.find('.//rt')) self.assertTrue(route.activelocalpref() == 1000)
def test_can_read_prefix_from_route_object(self): resultxml = etree.fromstring( open('./tests/test_data/bgp_route.xml').read()) route = RouteData(resultxml.find('.//rt')) self.assertTrue(route.prefix() == '199.87.242.0/24')
def test_can_identify_route_as_peering(self): config = ConfigDictionary('./etc/example.ini') resultxml = etree.fromstring(open('./tests/test_data/bgp_route.xml').read()) route = RouteData(resultxml.find('.//rt')) self.assertTrue(route.get_adjacency_type(config.get_list_of_localpref()) == "transit")
def test_can_obtain_clean_aspath_for_route(self): resultxml = etree.fromstring(open('./tests/test_data/bgp_route.xml').read()) route = RouteData(resultxml.find('.//rt')) self.assertTrue(route.aspath() == '6939 6461 12536')
def test_can_get_localpref_for_active_prefix(self): resultxml = etree.fromstring(open('./tests/test_data/bgp_route.xml').read()) route = RouteData(resultxml.find('.//rt')) self.assertTrue(route.activelocalpref() == 1000)
def test_can_read_prefix_from_route_object(self): resultxml = etree.fromstring(open('./tests/test_data/bgp_route.xml').read()) route = RouteData(resultxml.find('.//rt')) self.assertTrue(route.prefix() == '199.87.242.0/24')