| SNMP::Info::CDP(3pm) | User Contributed Perl Documentation | SNMP::Info::CDP(3pm) |
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 $cdp_if = $cdp->cdp_if();
my $cdp_ip = $cdp->cdp_ip();
my $cdp_port = $cdp->cdp_port();
foreach my $cdp_key (keys %$cdp_ip){
my $iid = $cdp_if->{$cdp_key};
my $port = $interfaces->{$iid};
my $neighbor = $cdp_ip->{$cdp_key};
my $neighbor_port = $cdp_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 by Cisco and several other vendors.
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.
These are methods that return scalar values from SNMP
Accounts for SNMP version 1 devices which may have CDP but not cdp_run()
("cdpGlobalRun")
("cdpGlobalMessageInterval")
("cdpGlobalHoldTime")
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.
(Bit) - Description
Thanks to Martin Lorensen for a pointer to the original information and CPAN user Alex for updates.
("cdpCacheCapabilities")
("cdpCacheVTPMgmtDomain")
("cdpCacheDuplex")
("cdpCacheDeviceId")
Note that a lot devices don't implement $cdp->cdp_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 $cdp_index = $device->cdp_index();
return $cdp_index if defined $cdp_index;
# if not, let's fake it
my $cdp_ip = $device->cdp_ip();
my %cdp_if
foreach my $key (keys %$cdp_ip){
$iid = $key;
## Truncate off .1 from cdp response
$iid =~ s/\.\d+$//;
$cdp_if{$key} = $iid;
}
return \%cdp_if;
Most devices don't implement this, so you probably want to use $cdp->cdp_if() instead.
See cdp_if() entry.
("cdpCacheIfIndex")
("cdpCacheAddress")
("cdpCacheAddress")
("cdpCachePlatform")
("cdpCacheDevicePort")
("cdpCacheAddressType")
("cdpCacheVersion")
("cdpCacheNativeVLAN")
("cdpCachePowerConsumption")
| 2023-09-30 | perl v5.36.0 |