SNMP::Info::CDP(3pm)

SNMP::Info::CDP πŸ’– (that's the SNMP::Info::CDP(3pm) page, bestie)

Okay so real talk: this is a User Contributed Perl Documentation page, and it's the one that lets you peek at Cisco Discovery Protocol stuff over SNMP. Let's get into it, it's giving network-topology-gossip. ✨


AUTHOR πŸ‘‘

Max Baker


SYNOPSIS πŸŽ€

Here's the vibe, copy-paste ready, no edits from me:

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";
}

So cute, so functional. πŸ’…


DESCRIPTION πŸ¦‹

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

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. (Not just Cisco, bestie, other vendors too, don't come for me.) 🌸

Important: Create or use a device subclass that inherits this class. Do not use directly. Like, genuinely, don't.

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. Some devices are overachievers, some are lowkey doing the bare minimum. πŸ™ˆ

Inherited Classes

None. It's an only child. πŸ’€

Required MIBs

  • CISCO-CDP-MIB

GLOBALS ⭐

These are methods that return scalar values from SNMP. Scalar = single lil value, no table drama.

  • $cdp->hasCDP() β€” Is CDP is active in this device? It accounts for SNMP version 1 devices which may have CDP but not cdp_run(). (Yes, it works around the flaky ones. Iconic behaviour, honestly.)
  • $cdp->cdp_run() β€” Is CDP enabled on this device? Note that a lot of Cisco devices that implement CDP don't implement this value. @#%$! (their words, and honestly? valid frustration.)

("cdpGlobalRun")

  • $cdp->cdp_interval() β€” Interval in seconds at which CDP messages are generated.

("cdpGlobalMessageInterval")

  • $cdp->cdp_holdtime() β€” Time in seconds that CDP messages are kept. Like a message that sticks around, refusing to leave the group chat. πŸ’œ

("cdpGlobalHoldTime")

  • $cdp->cdp_gid() β€” 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().

("cdpGlobalDeviceId")


TABLE METHODS πŸ”₯

These are methods that return tables of information in the form of a reference to a hash. A hash ref, bestie. A whole table of tea. πŸ“

CDP CACHE ENTRIES 🌈

(Bit) - Description

  • (0x400) - Two-Port MAC Relay.
  • (0x200) - CAST Phone Port / CVTA / Supports-STP-Dispute depending upon platform.
  • (0x100) - Remotely-Managed Device.
  • (0x80) - VoIP Phone.
  • (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 for a pointer to the original information and CPAN user Alex for updates. 🫢 Shoutout to the contributors, we love a credited legend.

("cdpCacheCapabilities")

  • $cdp->cdp_domain() β€” Returns remote VTP Management Domain as defined in "CISCO-VTP-MIB::managementDomainName"

("cdpCacheVTPMgmtDomain")

  • $cdp->cdp_duplex() β€” Returns the port duplex status from remote devices.

("cdpCacheDuplex")

  • $cdp->cdp_id() β€” Returns remote device id string

("cdpCacheDeviceId")

  • $cdp->cdp_if() β€” Returns the mapping to the SNMP Interface Table.

Note that a lot devices don't implement $cdp->cdp_index(), So if it isn't around, we fake it. (Fraud! But the helpful kind. The iconic kind.)

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;
  • $cdp->cdp_index() β€” 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->cdp_if() instead. See cdp_if() entry.

("cdpCacheIfIndex")

  • $cdp->cdp_ip() β€” If $cdp->cdp_proto() is supported, returns remote IPV4 address only. Otherwise it will return all addresses.

("cdpCacheAddress")

  • $cdp->cdp_addr() β€” Returns remote address

("cdpCacheAddress")

  • $cdp->cdp_platform() β€” Returns remote platform id

("cdpCachePlatform")

  • $cdp->cdp_port() β€” Returns remote Port-ID. Most of the time this is a string with the port name, but this is not guaranteed to be so. No promises, bestie. πŸ™ˆ

("cdpCacheDevicePort")

  • $cdp->cdp_proto() β€” Returns remote address type received. Usually IP.

("cdpCacheAddressType")

  • $cdp->cdp_ver() β€” Returns remote hardware version

("cdpCacheVersion")

  • $cdp->cdp_vlan() β€” Returns the remote interface native VLAN.

("cdpCacheNativeVLAN")

  • $cdp->cdp_power() β€” Returns the amount of power consumed by remote device in milliwatts munged for decimal placement. Wattage but make it decimal-correct. ⚑

("cdpCachePowerConsumption")

  • $cdp->cdp_cap() β€” Returns hash of arrays with each array containing the system capabilities supported by the remote system. Possible elements in the array are "Router", "Trans-Bridge", "Source-Route-Bridge", "Switch", "Host", "IGMP", "Repeater", "VoIP-Phone", "Remotely-Managed-Device", "Supports-STP-Dispute", and "Two-port Mac Relay".

Data Munging Callback Subroutines 🧚

  • $cdp->munge_power() β€” Inserts a decimal at the proper location. That's it, that's the whole job, and it does it flawlessly. πŸ’…

And that's the page!! Go map some neighbors, you absolute main character. πŸ‘‘

This was perl v5.40.1, dated 2026-02-28, from the SNMP::Info::CDP(3pm) manual. Bye bestie, ily, go read your MIBs. πŸŽ€βœ¨

πŸ“¦ where this page comes from