The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Device::Cisco::NXAPI - Interact with the NX-API (Nexus 9K Switches)

VERSION

Version 0.01

SYNOPSIS

This module provides methods to make API calls and extract information from devices that support the NX-API. This is predominantly the Nexus 9K range of switches in NXOS mode (not in ACI mode).

    use Device::Cisco::NXAPI;

    my $switch_api = Device::Cisco::NXAPI->new(uri => "https://192.168.1.1:8080", username => "admin", password => "admin");

    my @route_info = $switch_api->routes(vrf => "CustVRF");
    my %version_info = $switch_api->version();

CONSTRUCTOR

This method constructs a new Device::Cisco::NXAPI object.

    my $switch_api = Device::Cisco::NXAPI->new(
                                    # Mandatory parameters:
                                    uri => '',                  # URI of the switch to connect to.
                                    username => '',             # Username to logon to the switch
                                    password => '',             # Password to logon to the switch

                                    # Optional Parameters
                                    debug => (0 | 1),           # Output debugging information to stderr
                                );

METHODS

tester()

Returns a Device::Cisco::NXAPI::Test object for the switch. This object can be used to run test cases against the switch.

version()

    my %version_info = $switch->version()

Returns a hash consisting of system information. There are no arguments to this method.

The structure returned is as follows:

    (
      'kern_uptm_secs' => 17,
      'kickstart_ver_str' => '7.0(3)I2(2b)',
      'kick_file_name' => 'bootflash:///nxos.7.0.3.I2.2b.bin',
      'rr_ctime' => ' Mon Dec 19 04:57:51 2016',
      'kern_uptm_days' => 0,
      'kick_tmstmp' => '02/29/2016 05:21:45',
      'host_name' => 'switch',
      'cpu_name' => 'Intel(R) Core(TM) i3- CPU @ 2.50GHz',
      'kern_uptm_hrs' => 0,
      'manufacturer' => 'Cisco Systems, Inc.',
      'rr_sys_ver' => '11.3(2h)',
      'mem_type' => 'kB',
      'bootflash_size' => 7906304,
      'kern_uptm_mins' => 5,
      'bios_cmpl_time' => '10/12/2015',
      'bios_ver_str' => '07.41',
      'proc_board_id' => 'SAL1911BCSU',
      'kick_cmpl_time' => ' 2/28/2016 21:00:00',
      'header_str' => 'Cisco Nexus Operating System (NX-OS) Software',
      'rr_reason' => 'Reset Requested by CLI command reload',
      'memory' => 16401952,
      'chassis_id' => 'Nexus9000 C9372PX chassis',
      'rr_usecs' => 832622,
      'rr_service' => 'PolicyElem Ch reload'
    );

routes( %options )

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

        my $first_route = $routes[0]->{prefix};

Returns a list of HASHREFs with information on the routes present in the a VRFs routing table. The 'vrf =>' argument determines the VRF, and if not specified the global routing table is used. The 'vrf => all' will return routes from all routing tables on the switch.

The structure returned is as follows:

    (
      {
        'prefix' => '1.1.1.0/24'                            # The prefix of the route
        'vrf' => 'other_vrf',                               # VRF the route is in.
        'paths' => [                                                # Paths to next-hop (multiple paths in the case of ECMP)
                     {
                       'clientname' => 'direct',                # Protocol (e.g. direct, local, static, ospf)
                       'uptime' => 'P28DT19H43M28S',    # Time the route has been in the routing table
                       'ipnexthop' => '2.2.2.1',                # Next hop IP for the path
                       'ifname' => 'Eth1/1'                             # Egress interface for the path
                     }
                   ],
      },
    )

arp( %options )

    my @arp_table = $switch->arp(
        vrf => '',
    );

Returns a list of HASREFs containing the ARP table information. The vrf argument specifies the VRF to retrieve the ARP entries from. If no argument is specified the global routing table is used. If all is specified as the VRF, ARP entries from all routing tables are returned.

The structure returned is as follows:

    (
     {
       'ifname' => 'mgmt0',                 # Egress interface
       'vrf' => 'management',           # VRF
       'mac' => '0009.0fe9.9b39',       # MAC address
       'ip' => '10.47.64.4',            # IP address
       'time-stamp' => '00:01:20'       # Entry timeout
     }
    )

vlans()

    my @vlan_info = $switch->vlans();

Returns a list of HASHREFs containing information on the current layer 2 VLANs configured on the device. This method has no arguments.

The data structure returned is as follows:

    (
      {
        'id' => '1',
        'utf_id' => '1',
        'name' => 'default',
        'admin_state' => 'noshutdown',
        'vlan_state' => 'active'
        'interfaces' => [
          'Ethernet1/3-22',
          'Ethernet1/26-44',
          'Ethernet1/47-54'
        ],
      },
    )

physical_interfaces()

    my @interface_info = $switch->physical_interfaces(); 

Returns a list of HASHREFs containing information on the physical interfacee state.

The structure returned is as follows:

    (
     {
       'name' => 'Ethernet1/5',
       'mac' => '84b8.020f.15d4',
       'speed' => 'auto-speed',
       'admin_state' => 'up',           
       'op_state' => 'down',    
       'fps_in' => '0',         
       'fps_out' => '0',
       'bps_in' => '0',
       'bps_out' => '0',
       'bytes_in' => 0,                         
       'bytes_out' => 0,                
       'packets_in' => 0,       
       'packets_out' => 0,
       'last_link_flap' => 'never'      
       'errors' => {
         'ignored_frames' => '0',       
         'bad_protocol' => '0',
         'runts' => 0,
         'crc_errors' => '0',
         'no_carrier' => '0',
         'in_errors' => '0',
         'collisions' => '0',
         'lost_carrier' => '0',
         'dribbles' => '0',
         'overruns' => '0',
         'bad_frames' => '0',
         'no_buffer' => 0,
         'late_collisions' => '0',
         'underruns' => '0',
         'out_errors' => '0',
         'babbles' => '0',
         'out_discards' => '0',
         'in_discards' => '0'
       },
     }
    )

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 vrf is not specified, the peer info relating to the default routing table is retrieved. If 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' }, )

bgp_rib( %options )

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

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

If 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'
      },
    )

cdp_neighbours()

Returns a list of HASHREFs containing the current CDP information visible on the switch.

The structure returned is as follows:

    (
      {
        'platform_id' => 'cisco WS-C2960X-24TD-L',
        'intf_id' => 'mgmt0',
        'port_id' => 'GigabitEthernet1/0/3',
        'ifindex' => 83886080,
        'ttl' => 179,
        'device_id' => 'hostname',
        'capability' => 'IGMP_cnd_filtering'
      }
    )

AUTHOR

Greg Foletta, <greg at foletta.org>

BUGS

Please report any bugs or feature requests to bug-switch-nxapi at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Switch-NXAPI. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Device::Cisco::NXAPI

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2016 Greg Foletta.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at:

http://www.perlfoundation.org/artistic_license_2_0

Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license.

If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license.

This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder.

This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed.

Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.