Device-Cisco-NXAPI

 view release on metacpan or  search on metacpan

lib/Device/Cisco/NXAPI.pm  view on Meta::CPAN

            ['eth_inrate1_pkts', 'fps_in'],
            ['eth_bia_addr', 'mac'],
            ['eth_speed', 'speed'],
            ['eth_link_flapped', 'last_link_flap'],
        );

        my @eth_err_keys = (
            ['eth_bad_eth', 'bad_frames'],
            ['eth_overrun', 'overruns'],
            ['eth_runts', 'runts'],
            ['eth_nobuf', 'no_buffer'],
            ['eth_lostcarrier', 'lost_carrier'],
            ['eth_ignored', 'ignored_frames'],
            ['eth_coll', 'collisions'],
            ['eth_crc', 'crc_errors'],
            ['eth_nocarrier', 'no_carrier'],
            ['eth_outerr', 'out_errors'],
            ['eth_inerr', 'in_errors'],
            ['eth_indiscard', 'in_discards'],
            ['eth_outdiscard', 'out_discards'],
            ['eth_babbles', 'babbles'],
            ['eth_latecoll', 'late_collisions'],
            ['eth_underrun', 'underruns'],
            ['eth_dribble', 'dribbles'],
            ['eth_bad_proto', 'bad_protocol'],
        );

        # We extract out the relevant keys and translate them to better names
        # We also move the interface errors to a sub-tree
        my %renamed_info = map { $_->[1] => $interface->{$_->[0] // ''} } @eth_info_keys;
        my %renamed_errors = map { $_->[1] => $interface->{$_->[0]} } @eth_err_keys;
        $renamed_info{errors} = \%renamed_errors;
    
        push @ret_interfaces, \%renamed_info;
    }

    return @ret_interfaces;
}

=head2 bgp_peers( %options )

    my @bgp_peers = $switch->bgp_peers(
        vrf => '',
        af => 'ipv4 | ipv6'
    );

This function retrieves information on the BGP peers configured on the device. If B<vrf> is not specified,
the peer info relating to the default routing table is retrieved. If B<vrf> is specified as 'all', peer info
from all VRFs (including the global routing table) is returned.

The structure returned is as follows:

    (
      {
        'capabilitiessent' => '0',
        'state' => 'Idle',
        'updatesrecvd' => '0',
        'up' => 'false',
        'index' => '1',
        'updatessent' => '0',
        'keepaliverecvd' => '0',
        'holdtime' => '180',
        'resettime' => 'never',
        'neighbor' => '1.1.1.1',
        'lastread' => 'never',
        'opensrecvd' => '0',
        'peerresettime' => 'never',
        'bytesrecvd' => '0',
        'notificationsrcvd' => '0',
        'msgrecvd' => '0',
        'rtrefreshrecvd' => '0',
        'rtrefreshsent' => '0',
        'version' => '4',
        'firstkeepalive' => 'false',
        'remoteas' => '65001',
        'keepalivesent' => '0',
        'notificationssent' => '0',
        'bytessent' => '0',
        'remote-id' => '0.0.0.0',
        'keepalivetime' => '60',
        'peerresetreason' => 'No error',
        'restarttime' => '00:00:01',
        'lastwrite' => 'never',
        'connsestablished' => '0',
        'connsdropped' => '0',
        'resetreason' => 'No error',
        'recvbufbytes' => '0',
        'connattempts' => '0',
        'elapsedtime' => '00:05:24',
        'sentbytesoutstanding' => '0',
        'msgsent' => '0',
        'openssent' => '0'
      },
    )

=cut

sub bgp_peers {
    my $self = shift;
    my %args = validate(@_, 
        {
            vrf => { default => 'default', type => SCALAR | UNDEF },
            af => { default => 'ipv4', type => SCALAR | UNDEF, regex => qr{(ipv4|ipv6)} }
        }
    );
   
    my $user_args = "vrf $args{vrf} $args{af}";

    my $ret = $self->_send_cmd("show bgp $user_args neighbors");
    _fixup_returned_structure($ret);
    return _modify_returned_bgp_peer_structure($ret);
}

sub _modify_returned_bgp_peer_structure {
    my $bgp_peer_structure = shift;
    my @ret_bgp_peers;

    for my $bgp_peer (@{ $bgp_peer_structure->{neighbor} }) {
        my @extracted_keys = (
      		'up',
      		'state',
      		'resettime',
      		'resetreason',
      		'peerresetreason',
      		'neighbor',
      		'remoteas',
      		'remote-id',
      		'version',
      		'holdtime',
      		'keepalivetime',
      		'connsdropped',
      		'connsestablished',
      		'restarttime',
      		'firstkeepalive',
      		'sentbytesoutstanding',
      		'msgsent',
      		'msgrecvd',
      		'bytessent',
      		'bytesrecvd',
      		'updatessent',
      		'updatesrecvd',
      		'openssent',
      		'opensrecvd',
      		'notificationssent',
      		'notificationsrcvd',
      		'rtrefreshsent',
      		'keepaliverecvd',
      		'connattempts',
      		'lastread',
      		'rtrefreshrecvd',
      		'index',
      		'peerresettime',
      		'recvbufbytes',
      		'capabilitiessent',
      		'elapsedtime',
      		'lastwrite',
      		'keepalivesent',
        );

        my %peer_info = %{ $bgp_peer }{ @extracted_keys };
        push @ret_bgp_peers, \%peer_info;
    }
    return @ret_bgp_peers;
}


=head2 bgp_rib( %options )

    my $bgp_rib_ref = $switch->bgp_rib(
        vrf => '',
        af => 'ipv4 | ipv6'
    );

Returns information on the BGP Routinng Information Base (RIB). If B<vrf =>> is not specified, the global routing table is returned.
If B<vrf =>> is set to 'all', the RIB for all VRFs, including the global routing table, is returned.

If B<af =>> is not specied, the RIB for the IPv4 address family is returned.

The structure returned is as follows:

    (
      {
        'prefix' => '1.2.3.0/24',
        'paths' => [
          {
            'pathnr' => '0',
            'ipnexthop' => '0.0.0.0',
            'weight' => '32768',
            'best' => '>',
            'metric' => '',
            'origin' => 'i',
            'aspath' => '',
            'localpref' => '100',
            'type' => 'l',
            'status' => '*'
          }
        ],
        'vrf' => 'default'
      },
    )


=cut
sub bgp_rib {
    my $self = shift;
    my %args = validate(@_, 
        {
            vrf => { default => 'default', type => SCALAR | UNDEF },
            af => { default => 'ipv4', type => SCALAR | UNDEF, regex => qr{(ipv4|ipv6)} }
        }
    );

    my ($vrf, $addr_family); 

    my %address_families = (
                            ipv4 => "ip unicast",
                            ipv6 => "ipv6 unicast",



( run in 1.166 second using v1.01-cache-2.11-cpan-39bf76dae61 )