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()
Esempio n. 2
0
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()
Esempio n. 3
0
 def test_can_login_parse_serial(self):
 	config = ConfigDictionary('./etc/example.ini')
 	jdev = Device(user=config.username(), host=config.get_router_ip('rtr1'), password=config.password())
 	jdev.open(gather_facts=False)
 	inv = jdev.rpc.get_chassis_inventory()
 	print "model: %s" % inv.findtext('.//chassis/description')
 	jdev.close()
 	assert inv.findtext('.//chassis/description') == 'VMX'
def main(peer_asn):
    list_peering_ips_of_target_asn = []

    config = ConfigDictionary("/home/andy/etc/pypeer.ini")
    username = config.username()
    password = config.password()

    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

        try:
            resultxml = jdev.rpc.get_bgp_summary_information()
        except Exception as err:
            print "CMD:"
            etree.dump(err.cmd)
            print "RSP:"
            etree.dump(err.rsp)

        bgpsum = BgpData(resultxml)
        for thispeeringip in bgpsum.get_list_ipaddr_from_asn(peer_asn):
            list_peering_ips_of_target_asn.append(thispeeringip)

    exchange = Exchange()
    list_sessions_configured_peeringdbid_exchanges_of_target_asn = []
    for peering_ip in list_peering_ips_of_target_asn:
        if not is_valid_ipv4_address(peering_ip):
            next
        else:
            peeringdb_id = exchange.get_exchange_from_peerip(peering_ip)['peeringdbid']
            list_sessions_configured_peeringdbid_exchanges_of_target_asn.append(peeringdb_id)

    # todo: pull this from config file
    list_my_exchanges = [26, 806, 87, 59, 33, 31, 804, 1, 255, 5, 359, 48, 387,
                         435, 583, 745, 18, 777, 53, 297, 35, 70, 64, 60, 325,
                         587]

    peeringdb = PeeringDBClient()
    list_their_exchanges = peeringdb.get_list_connected_ixp(peer_asn)

    mutual_exchanges = set(list_my_exchanges).intersection(list_their_exchanges)
    missing_exchanges = set(mutual_exchanges).difference(list_sessions_configured_peeringdbid_exchanges_of_target_asn)

    print "Missing exchanges are:" + str(missing_exchanges)

    for pdbid in missing_exchanges:
        print str(pdbid) + ": " + peeringdb.get_name_of_ixp_from_pdbid(pdbid)
Esempio n. 5
0
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)"
Esempio n. 6
0
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():
    list_peeringdbid_of_connected_exchanges = []

    config = ConfigDictionary("/home/andy/etc/pypeer.ini")
    username = config.username()
    password = config.password()
    exchange = Exchange()
    peeringdb = PeeringDBClient()

    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

        try:
            resultxml = jdev.rpc.get_bgp_summary_information()
        except Exception as err:
            print "CMD:"
            etree.dump(err.cmd)
            print "RSP:"
            etree.dump(err.rsp)

        bgpsum = BgpData(resultxml)
        for thispeeringip in bgpsum.get_list_peering_ips():
            if not is_valid_ipv4_address(thispeeringip):
                next
            else:
                peeringdb_id = exchange.get_exchange_from_peerip(thispeeringip)['peeringdbid']
                if peeringdb_id==0:
                    next 
                elif peeringdb_id in list_peeringdbid_of_connected_exchanges:
                    next
                else:
                    list_peeringdbid_of_connected_exchanges.append(peeringdb_id)
                    ixpjson      = peeringdb.ixlan(peeringdb_id)
                    ixpparser    = PeeringDBParser(ixpjson)
                    print "%s: %s   # %s" % (peeringdb_id, router, ixpparser.get_name_of_ixorg_from_ixlan())
def main(peer_asn):
    list_peering_ips_of_target_asn = []

    config = ConfigDictionary()
    username = config.username()
    password = config.password()

    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

        try:
            resultxml = jdev.rpc.get_bgp_summary_information()
        except Exception as err:
            print "CMD:"
            etree.dump(err.cmd)
            print "RSP:"
            etree.dump(err.rsp)

        bgpsum = BgpData(resultxml)
        for thispeeringip in bgpsum.get_list_ipaddr_from_asn(peer_asn):
            list_peering_ips_of_target_asn.append(thispeeringip)

    print "all peering ips : " + str(list_peering_ips_of_target_asn)

    exchange = Exchange()
    list_sessions_configured_peeringdbid_exchanges_of_target_asn = []
    for peering_ip in list_peering_ips_of_target_asn:
        if not is_valid_ipv4_address(peering_ip):
            next
        else:
            peeringdb_id = exchange.get_exchange_from_peerip(
                peering_ip)['peeringdbid']
            list_sessions_configured_peeringdbid_exchanges_of_target_asn.append(
                peeringdb_id)

    # todo: pull this from config file
    list_my_exchanges = [
        26, 806, 87, 59, 33, 31, 804, 1, 255, 5, 359, 48, 387, 435, 583, 745,
        18, 777, 53, 297, 35, 70, 64, 60, 325, 587
    ]

    peeringdb = PeeringDBClient()
    list_their_exchanges = peeringdb.get_list_connected_ixp(peer_asn)

    mutual_exchanges = set(list_my_exchanges).intersection(
        list_their_exchanges)
    missing_exchanges = set(mutual_exchanges).difference(
        list_sessions_configured_peeringdbid_exchanges_of_target_asn)

    print "Missing exchanges are:" + str(missing_exchanges)
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(peer_asn):
    list_peering_ips_of_target_asn = []

    config = ConfigDictionary("etc/pypeer.ini")
    username = config.username()
    password = config.password()

    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

        try:
            resultxml = jdev.rpc.get_bgp_summary_information()
        except Exception as err:
            print "CMD:"
            etree.dump(err.cmd)
            print "RSP:"
            etree.dump(err.rsp)

        bgpsum = BgpData(resultxml)
        for thispeeringip in bgpsum.get_list_ipaddr_from_asn(peer_asn):
            list_peering_ips_of_target_asn.append(thispeeringip)

    exchange = Exchange()
    list_sessions_configured_peeringdbid_exchanges_of_target_asn = []
    for peering_ip in list_peering_ips_of_target_asn:
        if not is_valid_ipv4_address(peering_ip):
            next
        else:
            peeringdb_id = exchange.get_exchange_from_peerip(peering_ip)['peeringdbid']
            list_sessions_configured_peeringdbid_exchanges_of_target_asn.append(peeringdb_id)

    peeringdb = PeeringDBClient()
    peeringjson = PeeringDBParser(peeringdb.asn(peer_asn))
    list_their_exchanges = peeringjson.get_list_of_asn_exchanges()

    mutual_exchanges = set(config.get_list_of_connected_exchanges()).intersection(list_their_exchanges)
    missing_exchanges = set(mutual_exchanges).difference(list_sessions_configured_peeringdbid_exchanges_of_target_asn)

    print "Missing exchanges are:" + str(missing_exchanges)

    for pdbid in missing_exchanges:
        ixpparser    = PeeringDBParser(peeringdb.ixlan(pdbid))
        print str(pdbid) + ": " + ixpparser.get_name_of_ixorg_from_ixlan()
Esempio n. 11
0
 def test_can_get_list_of_my_connected_exchanges(self):
     config = ConfigDictionary('./etc/example.ini')
     self.assertTrue(18 in config.get_list_of_connected_exchanges())
Esempio n. 12
0
 def test_can_parse_peering_localpref_range(self):
     config = ConfigDictionary('./etc/example.ini')
     self.assertTrue(config.get_type_from_localpref(2500) == "peer")
Esempio n. 13
0
 def test_username(self):
     config = ConfigDictionary('./etc/example.ini')
     thisusername = config.username()
     self.assertTrue(thisusername == 'exampleuser')
Esempio n. 14
0
 def test_can_find_rtr1_ipaddr(self):
     config = ConfigDictionary('./etc/example.ini')
     self.assertTrue(config.get_router_ip('rtr1') == '91.194.69.4')
Esempio n. 15
0
 def test_can_see_rtr2_in_list_of_routers(self):
     config = ConfigDictionary('./etc/example.ini')
     self.assertTrue("rtr2" in config.get_list_of_router_names())
Esempio n. 16
0
 def test_can_see_rtr1_in_ams_location(self):
     config = ConfigDictionary('./etc/example.ini')
     self.assertTrue(config.get_router_location('rtr1') == 'ams')
Esempio n. 17
0
 def test_can_parse_peering_localpref_range(self):
     config = ConfigDictionary('./etc/example.ini')
     self.assertTrue(config.get_type_from_localpref(2500) == "peer")
Esempio n. 18
0
 def test_can_see_rtr2_in_list_of_routers(self):
     config = ConfigDictionary('./etc/example.ini')
     self.assertTrue("rtr2" in config.get_list_of_router_names())
Esempio n. 19
0
 def test_can_find_rtr1_ipaddr(self):
     config = ConfigDictionary('./etc/example.ini')
     self.assertTrue(config.get_router_ip('rtr1') == '91.194.69.4')
Esempio n. 20
0
 def test_username(self):
     config = ConfigDictionary('./etc/example.ini')
     thisusername = config.username()
     self.assertTrue(thisusername == 'exampleuser')
Esempio n. 21
0
 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")