Oliver Gorwits > SNMP-Info-2.11 > SNMP::Info::CDP



Annotate this POD


New  3
Open  0
View/Report Bugs
Module Version: 2.11   Source   Latest Release: SNMP-Info-3.28


SNMP::Info::CDP - SNMP Interface to Cisco Discovery Protocol (CDP) using SNMP


Max Baker


 my $cdp = new SNMP::Info ( 
                             AutoSpecify => 1,
                             Debug       => 1,
                             DestHost    => 'router', 
                             Community   => 'public',
                             Version     => 2

 my $class = $cdp->class();
 print " Using device sub class : $class\n";

 $hascdp   = $cdp->hasCDP() ? 'yes' : 'no';

 # Print out a map of device ports with CDP neighbors:
 my $interfaces = $cdp->interfaces();
 my $c_if       = $cdp->c_if();
 my $c_ip       = $cdp->c_ip();
 my $c_port     = $cdp->c_port();

 foreach my $cdp_key (keys %$c_ip){
    my $iid           = $c_if->{$cdp_key};
    my $port          = $interfaces->{$iid};
    my $neighbor      = $c_ip->{$cdp_key};
    my $neighbor_port = $c_port->{$cdp_key};
    print "Port : $port connected to $neighbor / $neighbor_port\n";


SNMP::Info::CDP is a subclass of SNMP::Info that provides an object oriented interface to CDP information through SNMP.

CDP is a Layer 2 protocol that supplies topology information of devices that also speak CDP, mostly switches and routers. CDP is implemented in Cisco and some HP devices.

Create or use a device subclass that inherits this class. Do not use directly.

Each device implements a subset of the global and cache entries. Check the return value to see if that data is held by the device.

Inherited Classes


Required MIBs


MIBs can be found at ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz


These are methods that return scalar values from SNMP


Is CDP is active in this device?

Accounts for SNMP version 1 devices which may have CDP but not cdp_run()


Is CDP enabled on this device? Note that a lot of Cisco devices that implement CDP don't implement this value. @#%$!



Interval in seconds at which CDP messages are generated.



Time in seconds that CDP messages are kept.



Returns CDP device ID.

This is the device id broadcast via CDP to other devices, and is what is retrieved from remote devices with $cdp->id().



These are methods that return tables of information in the form of a reference to a hash.



Returns Device Functional Capabilities. Results are munged into an ascii binary string, 7 digits long, MSB. Each digit represents a bit from the table below.

From http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#18843:

(Bit) - Description

(0x40) - Provides level 1 functionality.
(0x20) - The bridge or switch does not forward IGMP Report packets on non router ports.
(0x10) - Sends and receives packets for at least one network layer protocol. If the device is routing the protocol, this bit should not be set.
(0x08) - Performs level 2 switching. The difference between this bit and bit 0x02 is that a switch does not run the Spanning-Tree Protocol. This device is assumed to be deployed in a physical loop-free topology.
(0x04) - Performs level 2 source-route bridging. A source-route bridge would set both this bit and bit 0x02.
(0x02) - Performs level 2 transparent bridging.
(0x01) - Performs level 3 routing for at least one network layer protocol.

Thanks to Martin Lorensen martin -at- lorensen.dk for a pointer to this information.



Returns remote VTP Management Domain as defined in CISCO-VTP-MIB::managementDomainName



Returns the port duplex status from remote devices.



Returns remote device id string



Returns the mapping to the SNMP Interface Table.

Note that a lot devices don't implement $cdp->c_index(), So if it isn't around, we fake it.

In order to map the cdp table entry back to the interfaces() entry, we truncate the last number off of it :

  # it exists, yay.
  my $c_index     = $device->c_index();
  return $c_index if defined $c_index;

  # if not, let's fake it
  my $c_ip       = $device->c_ip();
  my %c_if
  foreach my $key (keys %$c_ip){
      $iid = $key;
      ## Truncate off .1 from cdp response
      $iid =~ s/\.\d+$//;
      $c_if{$key} = $iid;
  return \%c_if;

Returns the mapping to the SNMP2 Interface table for CDP Cache Entries.

Most devices don't implement this, so you probably want to use $cdp->c_if() instead.

See c_if() entry.



If $cdp->c_proto() is supported, returns remote IPV4 address only. Otherwise it will return all addresses.



Returns remote address



Returns remote platform id



Returns remote port ID



Returns remote address type received. Usually IP.



Returns remote hardware version



Returns the remote interface native VLAN.



Returns the amount of power consumed by remote device in milliwatts munged for decimal placement.


Data Munging Callback Subroutines ^


Inserts a decimal at the proper location.

syntax highlighting: