blib/lib/Net/SNMP/Mixin/Dot1abLldp.pm

filter: Statementstmt 18.0% 27 / 150 Branchbran 1.5% 1 / 64 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 42.1% 8 / 19 Podpod 100% 4 / 4 totaltotal 15.6% 40 / 256 CC 41 SCAR 33.7
CC
41
Cov
12%
_init
56.0
get_lldp_rem_table
42.0
_fetch_lldp_local_system_data
42.0
CRAP 29.0
↑ Summary
1 package Net::SNMP::Mixin::Dot1abLldp;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #
7 # store this package name in a handy variable,
8 # used for unambiguous prefix of mixin attributes
9 # storage in object hash
10 #
11 4 my $prefix = __PACKAGE__;
12  
13 #
14 # this module import config
15 #
16 4 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Net::SNMP::Mixin::Util qw/normalize_mac idx2val push_error get_init_slot/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #
20 # this module export config
21 #
22 4 my @mixin_methods;
23  
24 4 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 @mixin_methods = (
26 qw/
27 get_lldp_local_system_data
28 get_lldp_loc_port_table
29 get_lldp_rem_table
30 map_lldp_loc_portid2portnum
31 /
32 );
33 }
34  
35 4 ▶use Sub::Exporter -setup => {
Subroutine BEGIN: called CC=1 SCAR=0.0
36 exports => [@mixin_methods],
37 groups => { default => [@mixin_methods], },
38 4 };
39  
40 #
41 # SNMP oid constants used in this module
42 #
43 # from lldpMIB
44 4 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
45 4 LLDP_LOCAL_SYSTEM_DATA => '1.0.8802.1.1.2.1.3',
46 LLDP_LOCAL_CHASSIS_ID_SUBTYPE => '1.0.8802.1.1.2.1.3.1.0',
47 LLDP_LOCAL_CHASSIS_ID => '1.0.8802.1.1.2.1.3.2.0',
48 LLDP_LOCAL_SYS_NAME => '1.0.8802.1.1.2.1.3.3.0',
49 LLDP_LOCAL_SYS_DESC => '1.0.8802.1.1.2.1.3.4.0',
50 LLDP_LOCAL_SYS_CAPA_SUP => '1.0.8802.1.1.2.1.3.5.0',
51 LLDP_LOCAL_SYS_CAPA_ENA => '1.0.8802.1.1.2.1.3.6.0',
52  
53 LLDP_LOC_PORT_TABLE => '1.0.8802.1.1.2.1.3.7',
54 LLDP_LOC_PORT_NUM => '1.0.8802.1.1.2.1.3.7.1.1',
55 LLDP_LOC_PORT_ID_SUBTYPE => '1.0.8802.1.1.2.1.3.7.1.2',
56 LLDP_LOC_PORT_ID => '1.0.8802.1.1.2.1.3.7.1.3',
57 LLDP_LOC_PORT_DESC => '1.0.8802.1.1.2.1.3.7.1.4',
58  
59 LLDP_REM_TABLE => '1.0.8802.1.1.2.1.4.1',
60 LLDP_REM_LOCAL_PORT_NUM => '1.0.8802.1.1.2.1.4.1.1.2',
61 LLDP_REM_CHASSIS_ID_SUBTYPE => '1.0.8802.1.1.2.1.4.1.1.4',
62 LLDP_REM_CHASSIS_ID => '1.0.8802.1.1.2.1.4.1.1.5',
63 LLDP_REM_PORT_ID_SUBTYPE => '1.0.8802.1.1.2.1.4.1.1.6',
64 LLDP_REM_PORT_ID => '1.0.8802.1.1.2.1.4.1.1.7',
65 LLDP_REM_PORT_DESC => '1.0.8802.1.1.2.1.4.1.1.8',
66 LLDP_REM_SYS_NAME => '1.0.8802.1.1.2.1.4.1.1.9',
67 LLDP_REM_SYS_DESC => '1.0.8802.1.1.2.1.4.1.1.10',
68 LLDP_REM_SYS_CAPA_SUP => '1.0.8802.1.1.2.1.4.1.1.11',
69 LLDP_REM_SYS_CAPA_ENA => '1.0.8802.1.1.2.1.4.1.1.12',
70 4 };
71  
72 =head1 NAME
73  
74 Net::SNMP::Mixin::Dot1abLldp - mixin class for the Link Layer Discovery Protocol
75  
76 =cut
77  
78 4 our $VERSION = '0.18';
79  
80 =head1 SYNOPSIS
81  
82 A Net::SNMP mixin class for LLDP (Link Layer Discovery Protocol) based info.
83  
84 use Net::SNMP;
85 use Net::SNMP::Mixin;
86  
87 #...
88  
89 my $session = Net::SNMP->session( -hostname => 'foo.bar.com' );
90  
91 $session->mixer('Net::SNMP::Mixin::Dot1abLldp');
92 $session->init_mixins;
93 snmp_dispatcher();
94 $session->init_ok();
95 die $session->errors if $session->errors;
96  
97 printf "Local ChassisID: %s\n",
98 $session->get_lldp_local_system_data->{lldpLocChassisId};
99  
100 $lldp_loc_port_tbl = $session->get_lldp_loc_port_table;
101 $lldp_rem_tbl = $session->get_lldp_rem_table;
102  
103 foreach $lport ( keys %$lldp_rem_tbl ) {
104 foreach $idx ( keys %{ $lldp_rem_tbl->{$lport} } ) {
105 my $lldpRemSysName = $lldp_rem_tbl->{$lport}{$idx}{lldpRemSysName};
106 my $lldpRemPortId = $lldp_rem_tbl->{$lport}{$idx}{lldpRemPortId};
107 my $lldpRemPortDesc = $lldp_rem_tbl->{$lport}{$idx}{lldpRemPortDesc};
108 my $lldpRemChassisId = $lldp_rem_tbl->{$lport}{$idx}{lldpRemChassisId};
109 my $ldesc = $lldp_loc_port_tbl->{$lport}{lldpLocPortDesc};
110  
111 printf "$lport:$ldesc => $lldpRemSysName:$lldpRemPortId:$lldpRemPortDesc:$lldpRemChassisId\n";
112 }
113 }
114  
115 =cut
116  
117 =head1 DESCRIPTION
118  
119 With this mixin it's simple to explore the Layer-2 topologie of the network.
120  
121 The LLDP (Link Layer Discovery Protocol) is an IEEE (Draft?) standard for vendor-independent Layer-2 discovery, similar to the proprietary CDP (Cisco Discovery Protocol) from Cisco. It's defined in the IEEE 802.1AB documents, therefore the name of this module.
122  
123 This mixin reads data from the B<< lldpLocalSystemData >>, B<< lldpLocPortTable >> and the B<< lldpRemTable >> out of the LLDP-MIB. At least these values are in the mandatory set of the LLDP-MIB.
124  
125 =head1 MIXIN METHODS
126  
127 =head2 B<< OBJ->get_lldp_local_system_data() >>
128  
129 Returns the LLDP lldpLocalSystemData group as a hash reference:
130  
131 {
132 lldpLocChassisIdSubtype => Integer,
133 lldpLocChassisId => OCTET_STRING,
134 lldpLocSysName => OCTET_STRING,
135 lldpLocSysDesc => OCTET_STRING,
136 lldpLocSysCapSupported => BITS,
137 lldpLocSysCapEnabled => BITS,
138 }
139  
140 =cut
141  
142 0 ▶sub get_lldp_local_system_data {
Subroutine get_lldp_local_system_data: not called CC=4 SCAR=30.0
Pod documented
143 0 my $session = shift;
144 0 my $agent = $session->hostname;
145  
146 0 ▶ Carp::croak "$agent: '$prefix' not initialized,"
Branch: 1 branch
BranchTrueFalseTotal
unless $session->init_ok($prefix) 0 0 0
147 unless $session->init_ok($prefix);
148  
149 # just a shallow copy for shallow values
150 0 my $result = { %{ $session->{$prefix}{locSysData} } };
151  
152 # if the chassisIdSubtype has the enumeration 'macAddress(4)'
153 # we normalize the MacAddress
154 $result->{lldpLocChassisId} = normalize_mac( $result->{lldpLocChassisId} )
155 0 ▶ if defined $result->{lldpLocChassisIdSubtype} && $result->{lldpLocChassisIdSubtype} == 4;
Branch: 1 branch
BranchTrueFalseTotal
if defined $result->{"lldpLocChassisIdSubtype"} and $result->{"lldpLocChassisIdSubtype"} == 4 0 0 0
Condition0%0/3
defined $result->{"lldpLocChassisIdSubtype"} and $result->{"lldpLocChassisIdSubtype"} == 4
!ll&&!rl&&r
000
MC/DC0%0/2
defined $result->{"lldpLocChassisIdSubtype"} and $result->{"lldpLocChassisIdSubtype"} == 4
defined $result->{"lldpLocChassisIdSubtype"} $result->{"lldpLocChassisIdSubtype"} == 4
Truth table0%0/3
A and B
A= defined $result->{"lldpLocChassisIdSubtype"}B= $result->{"lldpLocChassisIdSubtype"} == 4
ABresult
0X0
100
111
156  
157 0 return $result;
158 }
159  
160 =head2 B<< OBJ->get_lldp_loc_port_table() >>
161  
162 Returns the LLDP lldp_loc_port_table as a hash reference. The table is indexed by the LLDP local port numbers:
163  
164 {
165 lldpLocPortNum => {
166 lldpLocPortIdSubtype => INTEGER,
167 lldpLocPortId => OCTET_STRING,
168 lldpLocPortDesc => OCTET_STRING,
169 }
170 }
171  
172 The LLDP portnumber isn't necessarily the ifIndex of the switch. See the TEXTUAL-CONVENTION from the LLDP-MIB:
173  
174 "A port number has no mandatory relationship to an
175 InterfaceIndex object (of the interfaces MIB, IETF RFC 2863).
176 If the LLDP agent is a IEEE 802.1D, IEEE 802.1Q bridge, the
177 LldpPortNumber will have the same value as the dot1dBasePort
178 object (defined in IETF RFC 1493) associated corresponding
179 bridge port. If the system hosting LLDP agent is not an
180 IEEE 802.1D or an IEEE 802.1Q bridge, the LldpPortNumber
181 will have the same value as the corresponding interface's
182 InterfaceIndex object."
183  
184 See also the L<< Net::SNMP::Mixin::Dot1dBase >> for a mixin to get the mapping between the ifIndexes and the dot1dBasePorts if needed.
185  
186 =cut
187  
188 0 ▶sub get_lldp_loc_port_table {
Subroutine get_lldp_loc_port_table: not called CC=4 SCAR=30.0
Pod documented
189 0 my $session = shift;
190 0 my $agent = $session->hostname;
191  
192 0 ▶ Carp::croak "$agent: '$prefix' not initialized,"
Branch: 1 branch
BranchTrueFalseTotal
unless $session->init_ok($prefix) 0 0 0
193 unless $session->init_ok($prefix);
194  
195 # stash for return values
196 0 my $result = {};
197  
198 #
199 # the MIB tables are stored in {column}{row}{value} order
200 # but we return {row}{column}{value}
201 #
202 # grab all rows from one choosen column
203 0 my @rows = keys %{ $session->{$prefix}{lldpLocPortTbl}{lldpLocPortId} };
204  
205 0 foreach my $row (@rows) {
206  
207 # loop over all columns
208 0 foreach my $column ( keys %{ $session->{$prefix}{lldpLocPortTbl} } ) {
209  
210 # rebuild in reverse order: result(row,column) = stash(column,row)
211 # side effect: make a shallow copy for shallow values
212  
213 $result->{$row}{$column} =
214 0 $session->{$prefix}{lldpLocPortTbl}{$column}{$row};
215 }
216  
217 }
218  
219 0 return $result;
220 }
221  
222 =head2 B<< OBJ->map_lldp_loc_portid2portnum() >>
223  
224 Returns a hash reference with local portIds to local portNums:
225  
226 {
227 ...
228 Te5/32 => 234,
229 ...
230 }
231  
232 =cut
233  
234 0 ▶sub map_lldp_loc_portid2portnum {
Subroutine map_lldp_loc_portid2portnum: not called CC=3 SCAR=24.8
Pod documented
235 0 my $session = shift;
236 0 my $agent = $session->hostname;
237  
238 0 ▶ Carp::croak "$agent: '$prefix' not initialized,"
Branch: 1 branch
BranchTrueFalseTotal
unless $session->init_ok($prefix) 0 0 0
239 unless $session->init_ok($prefix);
240  
241 # stash for return values
242 0 my $result = {};
243  
244 0 foreach my $portNum ( keys %{ $session->{$prefix}{lldpLocPortTbl}{lldpLocPortId} } ) {
245 0 my $portId = $session->{$prefix}{lldpLocPortTbl}{lldpLocPortId}{$portNum};
246 0 $result->{$portId} = $portNum;
247 }
248  
249 0 return $result;
250 }
251  
252 =head2 B<< OBJ->get_lldp_rem_table() >>
253  
254 Returns the LLDP lldp_rem_table as a hash reference. The table is indexed by the LLDP local port numbers on which the remote system information is received and an index for multiple neighbors on one port:
255  
256 {
257 lldpRemLocalPortNum => {
258 lldpRemIndex => {
259 lldpRemChassisIdSubtype => INTEGER,
260 lldpRemChassisId => OCTET_STRING,
261 lldpRemPortIdSubtype => INTEGER,
262 lldpRemPortId => OCTET_STRING,
263 lldpRemPortDesc => OCTET_STRING,
264 lldpRemSysName => OCTET_STRING,
265 lldpRemSysDesc => OCTET_STRING,
266 lldpRemSysCapSupported => BITS,
267 lldpRemSysCapEnabled => BITS,
268 }
269 }
270 }
271  
272 =cut
273  
274 0 ▶sub get_lldp_rem_table {
Subroutine get_lldp_rem_table: not called CC=6 SCAR=37.4
Pod documented
275 0 my $session = shift;
276 0 my $agent = $session->hostname;
277  
278 0 ▶ Carp::croak "$agent: '$prefix' not initialized,"
Branch: 1 branch
BranchTrueFalseTotal
unless $session->init_ok($prefix) 0 0 0
279 unless $session->init_ok($prefix);
280  
281 # stash for return values
282 0 my $result = {};
283  
284 # the MIB tables are stored in {column}{row}{value} order
285 # but we return {row}{column}{value}
286 #
287 # grab all rows from one random choosen column
288 0 my @rows = keys %{ $session->{$prefix}{lldpRemTbl}{lldpRemPortId} };
289  
290 0 foreach my $row (@rows) {
291  
292 # the rows are the concatenation of 'lldpRemLocalPortNum.lldpRemIndex'
293 # split them into separate values
294 0 my ( $lldpRemLocalPortNum, $lldpRemIndex ) = split /\./, $row;
295  
296 # loop over all columns
297 0 foreach my $column ( keys %{ $session->{$prefix}{lldpRemTbl} } ) {
298  
299 # rebuild in reverse order: result(row,column) = stash(column,row)
300 # side effect: make a shallow copy for shallow values
301 # side effect: entangle the row 'lldpRemLocalPortNum.lldpRemIndex'
302  
303 $result->{$lldpRemLocalPortNum}{$lldpRemIndex}{$column} =
304 0 $session->{$prefix}{lldpRemTbl}{$column}{$row};
305 }
306  
307 # if the chassisIdSubtype has the enumeration 'macAddress(4)'
308 # we normalize the MacAddress
309 my $chassisIdSubtype =
310 0 $result->{$lldpRemLocalPortNum}{$lldpRemIndex}{lldpRemChassisIdSubtype};
311  
312 0 ▶ if ( defined $chassisIdSubtype && $chassisIdSubtype == 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $chassisIdSubtype and $chassisIdSubtype == 4) 0 0 0
Condition0%0/3
defined $chassisIdSubtype and $chassisIdSubtype == 4
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chassisIdSubtype and $chassisIdSubtype == 4
defined $chassisIdSubtype $chassisIdSubtype == 4
Truth table0%0/3
A and B
A= defined $chassisIdSubtypeB= $chassisIdSubtype == 4
ABresult
0X0
100
111
313 $result->{$lldpRemLocalPortNum}{$lldpRemIndex}{lldpRemChassisId} =
314 0 normalize_mac( $result->{$lldpRemLocalPortNum}{$lldpRemIndex}{lldpRemChassisId} );
315 }
316  
317 }
318  
319 0 return $result;
320 }
321  
322 =head1 INITIALIZATION
323  
324 =head2 B<< OBJ->_init($reload) >>
325  
326 Fetch the LLDP related snmp values from the host. Don't call this method direct!
327  
328 =cut
329  
330 #
331 # due to the asynchron nature, we don't know what init job is really the last, we decrement
332 # the value after each callback
333 #
334 4 ▶use constant THIS_INIT_JOBS => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
335  
336 0 ▶sub _init {
Subroutine _init: not called CC=7 SCAR=40.3
337 0 my ( $session, $reload ) = @_;
338 0 my $agent = $session->hostname;
339  
340 die "$agent: $prefix already initialized and reload not forced.\n"
341 if exists get_init_slot($session)->{$prefix}
342 0 ▶ && get_init_slot($session)->{$prefix} == 0
Branch: 1 branch
BranchTrueFalseTotal
if exists get_init_slot($session)->{$prefix} and get_init_slot($session)->{$prefix} == 0 and not $reload 0 0 0
Condition0%0/6
exists get_init_slot($session)->{$prefix} and get_init_slot($session)->{$prefix} == 0 and not $reload
!ll&&!rl&&r
000
exists get_init_slot($session)->{$prefix} and get_init_slot($session)->{$prefix} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
exists get_init_slot($session)->{$prefix} and get_init_slot($session)->{$prefix} == 0 and not $reload
exists get_init_slot($session)->{$prefix} get_init_slot($session)->{$prefix} == 0 not $reload
Truth table0%0/4
A and B and not(C)
A= exists get_init_slot($session)->{$prefix}B= get_init_slot($session)->{$prefix} == 0C= not $reload
ABCresult
0XX0
10X0
1100
1111
343 && not $reload;
344  
345 # set number of async init jobs for proper initialization
346 0 get_init_slot($session)->{$prefix} = THIS_INIT_JOBS;
347  
348 # populate the object with needed mib values
349 #
350 # initialize the object for LLDP infos
351 0 _fetch_lldp_local_system_data($session);
352 0 ▶ return if $session->error;
Branch: 1 branch
BranchTrueFalseTotal
if $session->error 0 0 0
353  
354 0 _fetch_lldp_loc_port_tbl($session);
355 0 ▶ return if $session->error;
Branch: 1 branch
BranchTrueFalseTotal
if $session->error 0 0 0
356  
357 0 _fetch_lldp_rem_tbl($session);
358 0 ▶ return if $session->error;
Branch: 1 branch
BranchTrueFalseTotal
if $session->error 0 0 0
359  
360 0 return 1;
361 }
362  
363 =head1 PRIVATE METHODS
364  
365 Only for developers or maintainers.
366  
367 =head2 B<< _fetch_lldp_local_system_data($session) >>
368  
369 Fetch the local system data from the lldpMIB once during object initialization.
370  
371 =cut
372  
373 0 ▶sub _fetch_lldp_local_system_data {
Subroutine _fetch_lldp_local_system_data: not called CC=6 SCAR=37.4
374 0 my $session = shift;
375 0 my $result;
376  
377 # use get_entries instead of get_request since the
378 # result will be true in case of missing values
379 # the values are just noSuchObject
380 # with get_entries() we get error messages for free
381  
382 0 ▶ $result = $session->get_entries(
Branch: 2 branches
BranchTrueFalseTotal
$session->version != 0 ? : 0 0 0
$session->nonblocking ? : 0 0 0
383 -columns => [ LLDP_LOCAL_SYSTEM_DATA, ],
384 -endindex => '6.0', # LLDP_LOCAL_SYS_CAPA_ENA
385 ( $session->version != 0 ? ( -maxrepetitions => 10 ) : () ),
386  
387 # define callback if in nonblocking mode
388 $session->nonblocking ? ( -callback => \&_lldp_local_system_data_cb ) : (),
389  
390 );
391  
392 0 ▶ unless ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 0 0
393 0 ▶ if ( my $err_msg = $session->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err_msg = $session->error) 0 0 0
394 0 push_error( $session, "$prefix: $err_msg" );
395 }
396 0 return;
397 }
398  
399 # in nonblocking mode the callback will be called asynchronously
400 0 ▶ return 1 if $session->nonblocking;
Branch: 1 branch
BranchTrueFalseTotal
if $session->nonblocking 0 0 0
401  
402 # ok we are in synchronous mode, call the result mangling function
403 # by hand
404 0 _lldp_local_system_data_cb($session);
405 }
406  
407 =head2 B<< _lldp_local_system_data_cb($session) >>
408  
409 The callback for _fetch_lldp_local_system_data.
410  
411 =cut
412  
413 0 ▶sub _lldp_local_system_data_cb {
Subroutine _lldp_local_system_data_cb: not called CC=3 SCAR=24.8
414 0 my $session = shift;
415 0 my $vbl = $session->var_bind_list;
416  
417 0 ▶ unless ( defined $vbl ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $vbl) 0 0 0
418 0 ▶ if ( my $err_msg = $session->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err_msg = $session->error) 0 0 0
419 0 push_error( $session, "$prefix: $err_msg" );
420 }
421 0 return;
422 }
423  
424 $session->{$prefix}{locSysData}{lldpLocChassisIdSubtype} =
425 0 $vbl->{ LLDP_LOCAL_CHASSIS_ID_SUBTYPE() };
426  
427 $session->{$prefix}{locSysData}{lldpLocChassisId} =
428 0 $vbl->{ LLDP_LOCAL_CHASSIS_ID() };
429  
430 $session->{$prefix}{locSysData}{lldpLocSysName} =
431 0 $vbl->{ LLDP_LOCAL_SYS_NAME() };
432  
433 $session->{$prefix}{locSysData}{lldpLocSysDesc} =
434 0 $vbl->{ LLDP_LOCAL_SYS_DESC() };
435  
436 $session->{$prefix}{locSysData}{lldpLocSysCapSupported} =
437 0 $vbl->{ LLDP_LOCAL_SYS_CAPA_SUP() };
438  
439 $session->{$prefix}{locSysData}{lldpLocSysCapEnabled} =
440 0 $vbl->{ LLDP_LOCAL_SYS_CAPA_ENA() };
441  
442 # this init job is finished
443 0 get_init_slot($session)->{$prefix}--;
444  
445 0 return 1;
446 }
447  
448 =head2 B<< _fetch_lldp_loc_port_tbl($session) >>
449  
450 Fetch the lldpLocPortTable once during object initialization.
451  
452 =cut
453  
454 0 ▶sub _fetch_lldp_loc_port_tbl {
Subroutine _fetch_lldp_loc_port_tbl: not called CC=6 SCAR=37.4
455 0 my $session = shift;
456 0 my $result;
457  
458 # fetch the lldpLocPortTable
459 0 ▶ $result = $session->get_table(
Branch: 2 branches
BranchTrueFalseTotal
$session->version != 0 ? : 0 0 0
$session->nonblocking ? : 0 0 0
460 -baseoid => LLDP_LOC_PORT_TABLE,
461 ( $session->version != 0 ? ( -maxrepetitions => 10 ) : () ),
462  
463 # define callback if in nonblocking mode
464 $session->nonblocking ? ( -callback => \&_lldp_loc_port_tbl_cb ) : (),
465 );
466  
467 0 ▶ unless ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 0 0
468 0 ▶ if ( my $err_msg = $session->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err_msg = $session->error) 0 0 0
469 0 push_error( $session, "$prefix: $err_msg" );
470 }
471 0 return;
472 }
473  
474 # in nonblocking mode the callback will be called asynchronously
475 0 ▶ return 1 if $session->nonblocking;
Branch: 1 branch
BranchTrueFalseTotal
if $session->nonblocking 0 0 0
476  
477 # ok we are in synchronous mode, call the result mangling function
478 # by hand
479 0 _lldp_loc_port_tbl_cb($session);
480  
481 }
482  
483 =head2 B<< _lldp_loc_port_tbl_cb($session) >>
484  
485 The callback for _fetch_lldp_loc_port_tbl_cb().
486  
487 =cut
488  
489 0 ▶sub _lldp_loc_port_tbl_cb {
Subroutine _lldp_loc_port_tbl_cb: not called CC=3 SCAR=24.8
490 0 my $session = shift;
491 0 my $vbl = $session->var_bind_list;
492  
493 0 ▶ unless ( defined $vbl ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $vbl) 0 0 0
494 0 ▶ if ( my $err_msg = $session->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err_msg = $session->error) 0 0 0
495 0 push_error( $session, "$prefix: $err_msg" );
496 }
497 0 return;
498 }
499  
500 # mangle result table to get plain idx->value
501  
502 $session->{$prefix}{lldpLocPortTbl}{lldpLocPortIdSubtype} =
503 0 idx2val( $vbl, LLDP_LOC_PORT_ID_SUBTYPE );
504  
505 $session->{$prefix}{lldpLocPortTbl}{lldpLocPortId} =
506 0 idx2val( $vbl, LLDP_LOC_PORT_ID );
507  
508 $session->{$prefix}{lldpLocPortTbl}{lldpLocPortDesc} =
509 0 idx2val( $vbl, LLDP_LOC_PORT_DESC );
510  
511 # this init job is finished
512 0 get_init_slot($session)->{$prefix}--;
513  
514 0 return 1;
515 }
516  
517 =head2 B<< _fetch_lldp_rem_tbl($session) >>
518  
519 Fetch the lldpRemTable once during object initialization.
520  
521 =cut
522  
523 0 ▶sub _fetch_lldp_rem_tbl {
Subroutine _fetch_lldp_rem_tbl: not called CC=6 SCAR=37.4
524 0 my $session = shift;
525 0 my $result;
526  
527 # fetch the lldpRemTable
528 0 ▶ $result = $session->get_table(
Branch: 2 branches
BranchTrueFalseTotal
$session->version != 0 ? : 0 0 0
$session->nonblocking ? : 0 0 0
529 -baseoid => LLDP_REM_TABLE,
530 ( $session->version != 0 ? ( -maxrepetitions => 10 ) : () ),
531  
532 # define callback if in nonblocking mode
533 $session->nonblocking ? ( -callback => \&_lldp_rem_tbl_cb ) : (),
534 );
535  
536 0 ▶ unless ( defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $result) 0 0 0
537 0 ▶ if ( my $err_msg = $session->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err_msg = $session->error) 0 0 0
538 0 push_error( $session, "$prefix: $err_msg" );
539 }
540 0 return;
541 }
542  
543 # in nonblocking mode the callback will be called asynchronously
544 0 ▶ return 1 if $session->nonblocking;
Branch: 1 branch
BranchTrueFalseTotal
if $session->nonblocking 0 0 0
545  
546 # ok we are in synchronous mode, call the result mangling function
547 # by hand
548 0 _lldp_rem_tbl_cb($session);
549  
550 }
551  
552 =head2 B<< _lldp_rem_tbl_cb($session) >>
553  
554 The callback for _fetch_lldp_rem_tbl_cb().
555  
556 =cut
557  
558 0 ▶sub _lldp_rem_tbl_cb {
Subroutine _lldp_rem_tbl_cb: not called CC=3 SCAR=24.8
559 0 my $session = shift;
560 0 my $vbl = $session->var_bind_list;
561  
562 0 ▶ unless ( defined $vbl ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $vbl) 0 0 0
563 0 ▶ if ( my $err_msg = $session->error ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err_msg = $session->error) 0 0 0
564 0 push_error( $session, "$prefix: $err_msg" );
565 }
566 0 return;
567 }
568  
569 # mangle result table to get plain idx->value
570 #---------------------------------------------------------------
571 # the tableIndex is a little bit tricky, please see the LLDP-MIB
572 #---------------------------------------------------------------
573 #
574 # .1.0.8802.1.1.2.1.4.1.1.11[.0.20.1]
575 # ^ ^ ^
576 # | | |
577 # lldpRemTimeMark---/ | |
578 # | |
579 # lldpRemLocalPortNum--/ |
580 # |
581 # lldpRemIndex-----------/
582 #
583 #---------------------------------------------------------------
584 # lldpRemEntry OBJECT-TYPE
585 # SYNTAX LldpRemEntry
586 # MAX-ACCESS not-accessible
587 # STATUS current
588 # DESCRIPTION
589 # "Information about a particular physical network connection.
590 # Entries may be created and deleted in this table by the agent,
591 # if a physical topology discovery process is active."
592 # INDEX {
593 # lldpRemTimeMark,
594 # lldpRemLocalPortNum,
595 # lldpRemIndex
596 # }
597 # ::= { lldpRemTable 1 }
598 # -----------------------------------------------
599  
600 # mangle result table to get plain idx->value
601 # cut off the variable lldpRemTimeMark as pre
602 #
603 # result hashes: lldpRemLocalPortNum.lldpRemIndex => values
604 #
605  
606 $session->{$prefix}{lldpRemTbl}{lldpRemChassisIdSubtype} =
607 0 idx2val( $vbl, LLDP_REM_CHASSIS_ID_SUBTYPE, 1, undef, );
608  
609 $session->{$prefix}{lldpRemTbl}{lldpRemChassisId} =
610 0 idx2val( $vbl, LLDP_REM_CHASSIS_ID, 1, undef, );
611  
612 $session->{$prefix}{lldpRemTbl}{lldpRemPortIdSubtype} =
613 0 idx2val( $vbl, LLDP_REM_PORT_ID_SUBTYPE, 1, undef, );
614  
615 $session->{$prefix}{lldpRemTbl}{lldpRemPortId} =
616 0 idx2val( $vbl, LLDP_REM_PORT_ID, 1, undef, );
617  
618 $session->{$prefix}{lldpRemTbl}{lldpRemPortDesc} =
619 0 idx2val( $vbl, LLDP_REM_PORT_DESC, 1, undef, );
620  
621 $session->{$prefix}{lldpRemTbl}{lldpRemSysName} =
622 0 idx2val( $vbl, LLDP_REM_SYS_NAME, 1, undef, );
623  
624 $session->{$prefix}{lldpRemTbl}{lldpRemSysDesc} =
625 0 idx2val( $vbl, LLDP_REM_SYS_DESC, 1, undef, );
626  
627 $session->{$prefix}{lldpRemTbl}{lldpRemSysCapSupported} =
628 0 idx2val( $vbl, LLDP_REM_SYS_CAPA_SUP, 1, undef, );
629  
630 $session->{$prefix}{lldpRemTbl}{lldpRemSysCapEnabled} =
631 0 idx2val( $vbl, LLDP_REM_SYS_CAPA_ENA, 1, undef, );
632  
633 # this init job is finished
634 0 get_init_slot($session)->{$prefix}--;
635  
636 0 return 1;
637 }
638  
639 4 ▶unless ( caller() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller()) 0 4 4
640 0 print "$prefix compiles and initializes successful.\n";
641 }
642  
643 =head1 SEE ALSO
644  
645 L<< Net::SNMP::Mixin::Dot1dBase >>
646  
647 =head1 REQUIREMENTS
648  
649 L<< Net::SNMP >>, L<< Net::SNMP::Mixin >>
650  
651 =head1 BUGS, PATCHES & FIXES
652  
653 There are no known bugs at the time of this release. However, if you spot a bug or are experiencing difficulties that are not explained within the POD documentation, please submit a bug to the RT system (see link below). However, it would help greatly if you are able to pinpoint problems or even supply a patch.
654  
655 Fixes are dependant upon their severity and my availablity. Should a fix not be forthcoming, please feel free to (politely) remind me by sending an email to gaissmai@cpan.org .
656  
657 RT: http://rt.cpan.org/Public/Dist/Display.html?Name=Net-SNMP-Mixin-Dot1abLldp
658  
659  
660 =head1 AUTHOR
661  
662 Karl Gaissmaier <karl.gaissmaier at uni-ulm.de>
663  
664 =head1 COPYRIGHT & LICENSE
665  
666 Copyright 2008-2021 Karl Gaissmaier, all rights reserved.
667  
668 This program is free software; you can redistribute it and/or modify it
669 under the same terms as Perl itself.
670  
671 =cut
672  
673 4 1;
674  
675 # vim: sw=2
↑ Summary