1SNMP::Info::CDP(3) User Contributed Perl Documentation SNMP::Info::CDP(3)
2
3
4
6 SNMP::Info::CDP - SNMP Interface to Cisco Discovery Protocol (CDP)
7 using SNMP
8
10 Max Baker
11
13 my $cdp = new SNMP::Info (
14 AutoSpecify => 1,
15 Debug => 1,
16 DestHost => 'router',
17 Community => 'public',
18 Version => 2
19 );
20
21 my $class = $cdp->class();
22 print " Using device sub class : $class\n";
23
24 $hascdp = $cdp->hasCDP() ? 'yes' : 'no';
25
26 # Print out a map of device ports with CDP neighbors:
27 my $interfaces = $cdp->interfaces();
28 my $cdp_if = $cdp->cdp_if();
29 my $cdp_ip = $cdp->cdp_ip();
30 my $cdp_port = $cdp->cdp_port();
31
32 foreach my $cdp_key (keys %$cdp_ip){
33 my $iid = $cdp_if->{$cdp_key};
34 my $port = $interfaces->{$iid};
35 my $neighbor = $cdp_ip->{$cdp_key};
36 my $neighbor_port = $cdp_port->{$cdp_key};
37 print "Port : $port connected to $neighbor / $neighbor_port\n";
38 }
39
41 SNMP::Info::CDP is a subclass of SNMP::Info that provides an object
42 oriented interface to CDP information through SNMP.
43
44 CDP is a Layer 2 protocol that supplies topology information of devices
45 that also speak CDP, mostly switches and routers. CDP is implemented
46 in Cisco and some HP devices.
47
48 Create or use a device subclass that inherits this class. Do not use
49 directly.
50
51 Each device implements a subset of the global and cache entries. Check
52 the return value to see if that data is held by the device.
53
54 Inherited Classes
55 None.
56
57 Required MIBs
58 CISCO-CDP-MIB
59
60 MIBs can be found at ftp://ftp.cisco.com/pub/mibs/v2/v2.tar.gz
61
63 These are methods that return scalar values from SNMP
64
65 $cdp->hasCDP()
66 Is CDP is active in this device?
67
68 Accounts for SNMP version 1 devices which may have CDP but not
69 cdp_run()
70
71 $cdp->cdp_run()
72 Is CDP enabled on this device? Note that a lot of Cisco devices
73 that implement CDP don't implement this value. @#%$!
74
75 ("cdpGlobalRun")
76
77 $cdp->cdp_interval()
78 Interval in seconds at which CDP messages are generated.
79
80 ("cdpGlobalMessageInterval")
81
82 $cdp->cdp_holdtime()
83 Time in seconds that CDP messages are kept.
84
85 ("cdpGlobalHoldTime")
86
87 $cdp->cdp_gid()
88 Returns CDP device ID.
89
90 This is the device id broadcast via CDP to other devices, and is
91 what is retrieved from remote devices with $cdp->id().
92
93 ("cdpGlobalDeviceId")
94
96 These are methods that return tables of information in the form of a
97 reference to a hash.
98
99 CDP CACHE ENTRIES
100 $cdp->cdp_capabilities()
101 Returns Device Functional Capabilities. Results are munged into an
102 ascii binary string, MSB. Each digit represents a bit from the
103 table below from the CDP Capabilities Mapping to Smartport Type
104 table within the Cisco Small Business 200 Series Smart Switch
105 Administration Guide,
106 <http://www.cisco.com/c/en/us/support/switches/small-business-200-series-smart-switches/products-maintenance-guides-list.html>:
107
108 (Bit) - Description
109
110 (0x400) - Two-Port MAC Relay.
111 (0x200) - CAST Phone Port / CVTA / Supports-STP-Dispute depending
112 upon platform.
113 (0x100) - Remotely-Managed Device.
114 (0x80) - VoIP Phone.
115 (0x40) - Provides level 1 functionality.
116 (0x20) - The bridge or switch does not forward IGMP Report packets
117 on non router ports.
118 (0x10) - Sends and receives packets for at least one network layer
119 protocol. If the device is routing the protocol, this bit should
120 not be set.
121 (0x08) - Performs level 2 switching. The difference between this
122 bit and bit 0x02 is that a switch does not run the Spanning-Tree
123 Protocol. This device is assumed to be deployed in a physical loop-
124 free topology.
125 (0x04) - Performs level 2 source-route bridging. A source-route
126 bridge would set both this bit and bit 0x02.
127 (0x02) - Performs level 2 transparent bridging.
128 (0x01) - Performs level 3 routing for at least one network layer
129 protocol.
130
131 Thanks to Martin Lorensen for a pointer to the original information
132 and CPAN user Alex for updates.
133
134 ("cdpCacheCapabilities")
135
136 $cdp->cdp_domain()
137 Returns remote VTP Management Domain as defined in
138 "CISCO-VTP-MIB::managementDomainName"
139
140 ("cdpCacheVTPMgmtDomain")
141
142 $cdp->cdp_duplex()
143 Returns the port duplex status from remote devices.
144
145 ("cdpCacheDuplex")
146
147 $cdp->cdp_id()
148 Returns remote device id string
149
150 ("cdpCacheDeviceId")
151
152 $cdp->cdp_if()
153 Returns the mapping to the SNMP Interface Table.
154
155 Note that a lot devices don't implement $cdp->cdp_index(), So if
156 it isn't around, we fake it.
157
158 In order to map the cdp table entry back to the interfaces() entry,
159 we truncate the last number off of it :
160
161 # it exists, yay.
162 my $cdp_index = $device->cdp_index();
163 return $cdp_index if defined $cdp_index;
164
165 # if not, let's fake it
166 my $cdp_ip = $device->cdp_ip();
167
168 my %cdp_if
169 foreach my $key (keys %$cdp_ip){
170 $iid = $key;
171 ## Truncate off .1 from cdp response
172 $iid =~ s/\.\d+$//;
173 $cdp_if{$key} = $iid;
174 }
175
176 return \%cdp_if;
177
178 $cdp->cdp_index()
179 Returns the mapping to the SNMP2 Interface table for CDP Cache
180 Entries.
181
182 Most devices don't implement this, so you probably want to use
183 $cdp->cdp_if() instead.
184
185 See cdp_if() entry.
186
187 ("cdpCacheIfIndex")
188
189 $cdp->cdp_ip()
190 If $cdp->cdp_proto() is supported, returns remote IPV4 address
191 only. Otherwise it will return all addresses.
192
193 ("cdpCacheAddress")
194
195 $cdp->cdp_addr()
196 Returns remote address
197
198 ("cdpCacheAddress")
199
200 $cdp->cdp_platform()
201 Returns remote platform id
202
203 ("cdpCachePlatform")
204
205 $cdp->cdp_port()
206 Returns remote port ID
207
208 ("cdpDevicePort")
209
210 $cdp->cdp_proto()
211 Returns remote address type received. Usually IP.
212
213 ("cdpCacheAddressType")
214
215 $cdp->cdp_ver()
216 Returns remote hardware version
217
218 ("cdpCacheVersion")
219
220 $cdp->cdp_vlan()
221 Returns the remote interface native VLAN.
222
223 ("cdpCacheNativeVLAN")
224
225 $cdp->cdp_power()
226 Returns the amount of power consumed by remote device in milliwatts
227 munged for decimal placement.
228
229 ("cdpCachePowerConsumption")
230
231 $cdp->cdp_cap()
232 Returns hash of arrays with each array containing the system
233 capabilities supported by the remote system. Possible elements in
234 the array are "Router", "Trans-Bridge", "Source-Route-Bridge",
235 "Switch", "Host", "IGMP", "Repeater", "VoIP-Phone",
236 "Remotely-Managed-Device", "Supports-STP-Dispute", and "Two-port
237 Mac Relay".
238
240 $cdp->munge_power()
241 Inserts a decimal at the proper location.
242
243
244
245perl v5.28.1 2019-04-04 SNMP::Info::CDP(3)