Ejemplo n.º 1
0
def get_prefixes_received_from_neighbor(context,
                                        target,
                                        neighbor,
                                        table='inet.0'):
    '''
    JUNOS: show route receive-protocol bgp <neighbor>

    Returns:
   	A dict of prefixes with its BGP attributes
    '''

    commands = [
        'show route receive-protocol bgp {} table {}'.format(neighbor, table)
    ]

    with context.get_connection('cli') as cli:
        output = cli.execute(commands)

    template = 'bgp_table_junos.tmpl'
    result = helpers.template_parser(template, output[0])
    prefixes = dict()

    for row in result:
        prefixes[row[1]] = {
            'nexthop': row[2],
            'metric': row[3],
            'local_pref': row[4],
            'as_path': row[5],
            'origin': row[6],
            'status_codes': row[0]
        }

    return prefixes
Ejemplo n.º 2
0
def get_bgp_neighbors(context, target):
    '''
    JUNOS: show bgp summary

    Returns:
	A dict of neighbors and neighbor attributes
    '''

    commands = ['show bgp summary']

    with context.get_connection('cli') as cli:
        output = cli.execute(commands)

    template = 'bgp_summary_junos.tmpl'
    result = helpers.template_parser(template, output[0])
    neighbors = dict()

    for row in result:
        neighbors[row[0]] = {
            'asn': row[1],
            'msg_rcvd': row[2],
            'msg_sent': row[3],
            'out_queue': row[4],
            'flaps': row[5],
            'up_down': row[6],
            'state_prefixes': row[7]
        }

    return neighbors
Ejemplo n.º 3
0
def get_prefixes_received_from_neighbor(context, target, neighbor, table=None):
    '''
    IOS/IOS-XE: show ip bgp neighbor <neighbor> received-routes

    Returns:
	A dict of prefixes with its BGP attributes
    '''

    commands = ['show ip bgp neighbor {} received-routes'.format(neighbor)]

    with context.get_connection('cli') as cli:
        output = cli.execute(commands)

    template = 'bgp_table_ios.tmpl'
    result = helpers.template_parser(template, output[0])
    prefixes = dict()

    for row in result:
        prefixes[row[1]] = {
            'nexthop': row[2],
            'metric': row[3],
            'local_pref': row[4],
            'weight': row[5],
            'as_path': row[6],
            'origin': row[7],
            'status_codes': row[0]
        }

    return prefixes
Ejemplo n.º 4
0
def get_bgp_neighbors_state(context, target, neighbors="all"):
    '''
    IOS: show ip bgp neighbors

    Returns:
        A list of dicts of BGP neighbors and state. 
    '''

    commands = list()

    if neighbors == "all":
        commands = ['show ip bgp neighbors']
    else:
        for neighbor in neighbors.split(","):
            commands.append("show ip bgp neighbors {}".format(neighbor))

    with context.get_connection("cli") as cli:
        output = cli.execute(commands)
    data = ("\n").join(output)

    template = 'bgp_neighbors_ios.tmpl'
    neighbors = list()
    result = helpers.template_parser(template, data)

    for elem in result:
        neighbors.append({
            'neighbor': elem[0],
            'remote_asn': elem[1],
            'description': elem[2],
            'state': elem[3],
            'peergroup': elem[4]
        })

    return neighbors
Ejemplo n.º 5
0
def get_ospf_neighbors(context, target):
    '''
    IOS: show ip ospf neighbor 

    Returns:
	A list of dict with OSPF neighbors and state.        
    '''

    commands = ['show ip ospf neighbor']

    with context.get_connection("cli") as cli:
        output = cli.execute(commands)

    template = "ospf_neighbors_ios.tmpl"
    result = helpers.template_parser(template, output[0])

    neighbors = list()

    for elem in result:
        neighbors.append({
            'neighbor': elem[0],
            'priority': elem[1],
            'state': elem[2],
            'neighbor_ip': elem[3],
            'local_intf': elem[4]
        })
    return neighbors
Ejemplo n.º 6
0
def get_ospf_neighbors(context,target):
    '''
    IOS: show ip ospf neighbor 

    Returns:
	A list of dict with OSPF neighbors and state.        
    '''

    commands = ['show ip ospf neighbor']

    with context.get_connection("cli") as cli:
        output = cli.execute(commands)

    template = "ospf_neighbors_ios.tmpl"
    result = helpers.template_parser(template,output[0])

    neighbors = list()

    for elem in result:
        neighbors.append({'neighbor': elem[0],
			  'priority': elem[1],
			  'state': elem[2],
			  'neighbor_ip': elem[3],
			  'local_intf': elem[4]})
    return neighbors
Ejemplo n.º 7
0
def get_mpls_table(context, target):
    '''
    IOS: show mpls forwarding-table 

    Returns:
	A list of dict with MPLS labels and interfaces.        
    '''

    commands = ['show mpls forwarding-table']

    with context.get_connection("cli") as cli:
        output = cli.execute(commands)

    template = "mpls_table_ios.tmpl"
    result = helpers.template_parser(template, output[0])

    labels = list()

    for elem in result:
        labels.append({
            'local_label': elem[0],
            'remote_label': elem[1],
            'prefix': elem[2],
            'interface': helpers.interface_expand(elem[3]),
            'nexthop': elem[4]
        })
    return labels
Ejemplo n.º 8
0
def get_prefixes_received_from_neighbor(context,target,neighbor,table='inet.0'):
    '''
    JUNOS: show route receive-protocol bgp <neighbor>

    Returns:
   	A dict of prefixes with its BGP attributes
    '''

    commands = ['show route receive-protocol bgp {} table {}'.format(neighbor,table)]

    with context.get_connection('cli') as cli:
        output = cli.execute(commands)

    template = 'bgp_table_junos.tmpl'
    result = helpers.template_parser(template, output[0])
    prefixes = dict()

    for row in result:
        prefixes[row[1]] = {'nexthop':row[2],
                            'metric':row[3],
                            'local_pref':row[4],
                            'as_path':row[5],
                            'origin':row[6],
                            'status_codes':row[0]}

    return prefixes
Ejemplo n.º 9
0
def get_prefixes_received_from_neighbor(context,target,neighbor,table=None):
    '''
    IOS/IOS-XE: show ip bgp neighbor <neighbor> received-routes

    Returns:
	A dict of prefixes with its BGP attributes
    '''

    commands = ['show ip bgp neighbor {} received-routes'.format(neighbor)]

    with context.get_connection('cli') as cli:
        output = cli.execute(commands)

    template = 'bgp_table_ios.tmpl'
    result = helpers.template_parser(template,output[0])
    prefixes = dict()

    for row in result:
        prefixes[row[1]] = {'nexthop':row[2],
			    'metric':row[3],
			    'local_pref':row[4],
			    'weight':row[5],
			    'as_path':row[6],
			    'origin':row[7],
			    'status_codes':row[0]}

    return prefixes
Ejemplo n.º 10
0
def get_bgp_neighbors_state(context,target,neighbors="all"):
    '''
    IOS: show ip bgp neighbors

    Returns:
        A list of dicts of BGP neighbors and state. 
    '''

    commands = list()

    if neighbors == "all":
        commands = ['show ip bgp neighbors']
    else:
        for neighbor in neighbors.split(","):
            commands.append("show ip bgp neighbors {}".format(neighbor))

    with context.get_connection("cli") as cli:
        output = cli.execute(commands)
    data = ("\n").join(output)

    template = 'bgp_neighbors_ios.tmpl'
    neighbors = list()
    result = helpers.template_parser(template,data)

    for elem in result:
        neighbors.append({'neighbor':elem[0],
			  'remote_asn':elem[1],
                          'description':elem[2],
                          'state':elem[3],
                          'peergroup':elem[4]})

    return neighbors
Ejemplo n.º 11
0
def get_bgp_neighbors(context,target):
    '''
    JUNOS: show bgp summary

    Returns:
	A dict of neighbors and neighbor attributes
    '''

    commands = ['show bgp summary']

    with context.get_connection('cli') as cli:
        output = cli.execute(commands)

    template = 'bgp_summary_junos.tmpl'
    result = helpers.template_parser(template,output[0])
    neighbors = dict()

    for row in result:
        neighbors[row[0]] = {'asn': row[1],
                             'msg_rcvd':row[2],
                             'msg_sent':row[3],
                             'out_queue':row[4],
                             'flaps':row[5],
                             'up_down':row[6],
                             'state_prefixes':row[7]}

    return neighbors
Ejemplo n.º 12
0
def get_bgp_neighbors(context, target):
    '''
    IOS/IOS-XE: show ip bgp summary

    Returns:
	A list of dicts of neighbors and neighbor attributes
    '''

    commands = ['show ip bgp summary']

    with context.get_connection('cli') as cli:
        output = cli.execute(commands)

    template = 'bgp_summary_ios.tmpl'
    parsed_result = helpers.template_parser(template, output[0])
    neighbors = list()

    HEADER = [
        "neighbor", "version", "peer_asn", "msg_rcvd", "msg_sent",
        "table_version", "in_queue", "out_queue", "up/down", "state/prefixes"
    ]

    for row in parsed_result:
        neighbors.append(dict(zip(HEADER, row)))
        """
        neighbors[row[0]] = {'version':row[1],
                             'asn':row[2],
                             'msg_rcvd':row[3],
                             'msg_sent':row[4],
                             'table_version':row[5],
                             'in_queue':row[6],
                             'out_queue':row[7],
                             'up_down':row[8],
                             'state_prefixes':row[9]}
        """

    return neighbors