SNMP::Info::CDP - Perl5 Interface to Cisco Discovery Protocol (CDP) using SNMP
Max Baker (max@warped.org)
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.
None.
MIBs can be found at ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz
These are methods that return scalar values from SNMP
hasCDP()Accounts for SNMP version 1 devices which may have CDP but not cdp_run()
cdp_run()(cdpGlobalRun)
cdp_interval()(cdpGlobalMessageInterval)
cdp_holdtime()(cdpGlobalHoldTime)
cdp_id()This is the device id broadcast via CDP to other devices, and is what is retrieved from remote devices with $cdp->id().
(cdpGlobalDeviceId)
These are methods that return tables of information in the form of a reference to a hash.
c_capabilities()From http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#18843:
(Bit) - Description
Thanks to Martin Lorensen martin -at- lorensen.dk for a pointer to this information.
(cdpCacheCapabilities)
c_domain()(cdpCacheVTPMgmtDomain)
c_duplex()(cdpCacheDuplex)
c_id()(cdpCacheDeviceId)
c_if()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;
c_index()Most devices don't implement this, so you probably want to use $cdp->c_if() instead.
See c_if() entry.
(cdpCacheIfIndex)
c_ip()(cdpCacheAddress)
c_platform()(cdpCachePlatform)
c_port()(cdpDevicePort)
c_proto()(cdpCacheAddressType)
c_ver()(cdpCacheVersion)
c_vlan()(cdpCacheNativeVLAN)