1Info::CDP(3) User Contributed Perl Documentation 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 $c_if = $cdp->c_if();
29 my $c_ip = $cdp->c_ip();
30 my $c_port = $cdp->c_port();
31
32 foreach my $cdp_key (keys %$c_ip){
33 my $iid = $c_if->{$cdp_key};
34 my $port = $interfaces->{$iid};
35 my $neighbor = $c_ip->{$cdp_key};
36 my $neighbor_port = $c_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_id()
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->c_capabilities()
101 Returns Device Functional Capabilities. Results are munged into an
102 ascii binary string, 7 digits long, MSB. Each digit represents a
103 bit from the table below.
104
105 From
106 <http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm#18843>:
107
108 (Bit) - Description
109
110 (0x40) - Provides level 1 functionality.
111 (0x20) - The bridge or switch does not forward IGMP Report packets
112 on non router ports.
113 (0x10) - Sends and receives packets for at least one network layer
114 protocol. If the device is routing the protocol, this bit should
115 not be set.
116 (0x08) - Performs level 2 switching. The difference between this
117 bit and bit 0x02 is that a switch does not run the Spanning-Tree
118 Protocol. This device is assumed to be deployed in a physical loop-
119 free topology.
120 (0x04) - Performs level 2 source-route bridging. A source-route
121 bridge would set both this bit and bit 0x02.
122 (0x02) - Performs level 2 transparent bridging.
123 (0x01) - Performs level 3 routing for at least one network layer
124 protocol.
125
126 Thanks to Martin Lorensen "martin -at- lorensen.dk" for a pointer
127 to this information.
128
129 ("cdpCacheCapabilities")
130
131 $cdp->c_domain()
132 Returns remote VTP Management Domain as defined in
133 "CISCO-VTP-MIB::managementDomainName"
134
135 ("cdpCacheVTPMgmtDomain")
136
137 $cdp->c_duplex()
138 Returns the port duplex status from remote devices.
139
140 ("cdpCacheDuplex")
141
142 $cdp->c_id()
143 Returns remote device id string
144
145 ("cdpCacheDeviceId")
146
147 $cdp->c_if()
148 Returns the mapping to the SNMP Interface Table.
149
150 Note that a lot devices don't implement $cdp->c_index(), So if it
151 isn't around, we fake it.
152
153 In order to map the cdp table entry back to the interfaces() entry,
154 we truncate the last number off of it :
155
156 # it exists, yay.
157 my $c_index = $device->c_index();
158 return $c_index if defined $c_index;
159
160 # if not, let's fake it
161 my $c_ip = $device->c_ip();
162
163 my %c_if
164 foreach my $key (keys %$c_ip){
165 $iid = $key;
166 ## Truncate off .1 from cdp response
167 $iid =~ s/\.\d+$//;
168 $c_if{$key} = $iid;
169 }
170
171 return \%c_if;
172
173 $cdp->c_index()
174 Returns the mapping to the SNMP2 Interface table for CDP Cache
175 Entries.
176
177 Most devices don't implement this, so you probably want to use
178 $cdp->c_if() instead.
179
180 See c_if() entry.
181
182 ("cdpCacheIfIndex")
183
184 $cdp->c_ip()
185 If $cdp->c_proto() is supported, returns remote IPV4 address only.
186 Otherwise it will return all addresses.
187
188 ("cdpCacheAddress")
189
190 $cdp->c_addr()
191 Returns remote address
192
193 ("cdpCacheAddress")
194
195 $cdp->c_platform()
196 Returns remote platform id
197
198 ("cdpCachePlatform")
199
200 $cdp->c_port()
201 Returns remote port ID
202
203 ("cdpDevicePort")
204
205 $cdp->c_proto()
206 Returns remote address type received. Usually IP.
207
208 ("cdpCacheAddressType")
209
210 $cdp->c_ver()
211 Returns remote hardware version
212
213 ("cdpCacheVersion")
214
215 $cdp->c_vlan()
216 Returns the remote interface native VLAN.
217
218 ("cdpCacheNativeVLAN")
219
220 $cdp->c_power()
221 Returns the amount of power consumed by remote device in milliwatts
222 munged for decimal placement.
223
224 ("cdpCachePowerConsumption")
225
227 $cdp->munge_power()
228 Inserts a decimal at the proper location.
229
230
231
232perl v5.12.0 2009-06-12 Info::CDP(3)