Info/Layer3/ArubaInstant.pm untested

filter: Statementstmt 0.0% 0 / 323 Branchbran 0.0% 0 / 96 Conditioncond 0.0% 0 / 142 MC/DCmcdc 0.0% 0 / 80 Subroutinesub 0.0% 0 / 50 Podpod 0.0% 0 / 46 totaltotal 0.0% 0 / 737 CC 49 SCAR 34.7
CC
49
Cov
0%
_augment
156.0
_wlan_radios
72.0
serial
30.0
CRAP 32.2
1 # SNMP::Info::Layer3::ArubaInstant
2 #
3 # Copyright (c) 2013 Eric Miller
4 # Copyright (c) 2026 Muris
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # * Redistributions of source code must retain the above copyright notice,
11 # this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # * Neither the name of the University of California, Santa Cruz nor the
16 # names of its contributors may be used to endorse or promote products
17 # derived from this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30  
31 package SNMP::Info::Layer3::ArubaInstant;
32  
33 use strict;
34 use warnings;
35 use SNMP::Info::Layer3::Aruba;
36  
37 our @ISA = qw/SNMP::Info::Layer3::Aruba/;
38 our ($VERSION, %MIBS, %GLOBALS, %FUNCS, %MUNGE);
39 $VERSION = '3.985005';
40  
41 %MIBS = (%SNMP::Info::Layer3::Aruba::MIBS,
42 'AI-AP-MIB' => 'aiWlanESSID');
43 %GLOBALS = (%SNMP::Info::Layer3::Aruba::GLOBALS,
44 'instant_vc_name' => 'aiVirtualControllerName',
45 'instant_vc_version' => 'aiVirtualControllerVersion',
46 'instant_conductor_ip' => 'aiConductorIPAddress',
47 'instant_master_ip' => 'aiMasterIPAddress',
48 );
49 %FUNCS = (%SNMP::Info::Layer3::Aruba::FUNCS,
50 'instant_radio_channel' => 'aiRadioChannel',
51 'instant_radio_power' => 'aiRadioTransmitPower',
52 'instant_radio_mac' => 'aiRadioMACAddress',
53 'instant_radio_status' => 'aiRadioStatus',
54 'instant_wlan_ssid' => 'aiWlanESSID',
55 'instant_wlan_mac' => 'aiWlanMACAddress',
56 'instant_ap_name' => 'aiAPName',
57 'instant_ap_status' => 'aiAPStatus',
58 'instant_ap_ip' => 'aiAPIPAddress',
59 'instant_ap_serial' => 'aiAPSerialNum',
60 'instant_ap_model' => 'aiAPModelName',
61 'instant_ap_type' => 'aiAPModel',
62 'instant_ssid' => 'aiSSID',
63 'instant_ssid_hide' => 'aiSSIDHide',
64 'instant_client_mac' => 'aiClientMACAddress',
65 'instant_client_bssid'=> 'aiClientWlanMACAddress',
66 'instant_client_snr' => 'aiClientSNR',
67 'instant_client_txrate' => 'aiClientTxRate',
68 'instant_client_uptime' => 'aiClientUptime',
69 'instant_client_txbytes' => 'aiClientTxDataBytes',
70 'instant_client_rxbytes' => 'aiClientRxDataBytes',
71 'instant_client_txframes' => 'aiClientTxDataFrames',
72 'instant_client_rxframes' => 'aiClientRxDataFrames',
73 );
74 %MUNGE = (%SNMP::Info::Layer3::Aruba::MUNGE,
75 'instant_radio_mac' => \&SNMP::Info::munge_mac,
76 'instant_wlan_mac' => \&SNMP::Info::munge_mac,
77 'instant_client_mac' => \&SNMP::Info::munge_mac,
78 'instant_client_bssid' => \&SNMP::Info::munge_mac,
79 'instant_wlan_ssid' => \&SNMP::Info::munge_null,
80 'instant_ssid' => \&SNMP::Info::munge_null,
81 );
82  
83 # WLANs with a usable BSSID. They are not ports: each is mapped to the radio
84 # that serves it (_wlan_radios).
85 sub _wlans {
86 my ($self, $partial) = @_;
87 my $macs = $self->instant_wlan_mac($partial) || {};
88 my %wlans;
89 foreach my $iid (keys %$macs) {
90 next unless $iid =~ /^(\d+(?:\.\d+){5})\.(\d+)$/;
91 my ($ap, $number) = ($1, $2);
92 my $mac = $macs->{$iid};
93 next unless defined $mac && $mac =~ /^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/i;
94 next if $mac eq '00:00:00:00:00:00';
95 $wlans{$iid} = {ap => $ap, number => $number, mac => lc $mac};
96 }
97 return \%wlans;
98 }
99  
100 # One port per radio. The trailing .0 keeps the keys radio ports had when
101 # WLANs were ports too, and leaves room for the WLAN number in i_ssidlist.
102 sub _radios {
103 my ($self, $partial) = @_;
104 my $channels = $self->instant_radio_channel() || {};
105 my $macs = $self->instant_radio_mac() || {};
106 my %radios;
107 # A radio missing from one column (a failed walk) keeps its port.
108 foreach my $iid (keys %{ {%$channels, %$macs} }) {
109 next unless $iid =~ /^(\d+(?:\.\d+){5})\.(\d+)$/;
110 my ($ap, $number) = ($1, $2);
111 my $mac = $macs->{$iid};
112 $mac = undef unless defined $mac && $mac =~ /^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/i;
113 my $logical = "$iid.0";
114 next if defined $partial && length $partial
115 && $logical ne $partial && index($logical, "$partial.") != 0;
116 $radios{$logical} = {ap => $ap, number => $number,
117 source => $iid, kind => 'radio', mac => $mac};
118 }
119 return \%radios;
120 }
121  
122 # BSSIDs count up from their radio's MAC (16 per radio on current APs, 8
123 # on older ones), so each radio owns the addresses from its MAC up to the
124 # next radio's MAC on the same AP. The highest radio owns a range as wide
125 # as the gap below it, or 16 on a single-radio AP. A WLAN no range holds is
126 # left out, not guessed. A radio with no MAC may sit inside any other
127 # radio's range, so on its AP each radio keeps only the 8 addresses no
128 # other radio can start within.
129 sub _wlan_radios {
130 my $self = shift;
131 my $wlans = $self->_wlans();
132 my $radios = $self->_radios();
133 my (%by_ap, %unbounded);
134 foreach my $iid (keys %$radios) {
135 my $radio = $radios->{$iid};
136 $unbounded{ $radio->{ap} } = 1 unless defined $radio->{mac};
137 next unless defined $radio->{mac};
138 push @{ $by_ap{ $radio->{ap} } }, [_mac_number($radio->{mac}), $iid];
139 }
140 my %ranges;
141 foreach my $ap (keys %by_ap) {
142 my @sorted = sort { $a->[0] <=> $b->[0] || $a->[1] cmp $b->[1] }
143 @{ $by_ap{$ap} };
144 foreach my $i (0 .. $#sorted) {
145 my ($start, $iid) = @{ $sorted[$i] };
146 my $gap = $i > 0 ? $start - $sorted[$i - 1][0] : 0;
147 my $end = $i < $#sorted ? $sorted[$i + 1][0]
148 : $start + ($gap > 0 ? $gap : 16);
149 $end = $start + 8 if $unbounded{$ap} && $end > $start + 8;
150 push @{ $ranges{$ap} }, [$start, $end, $iid];
151 }
152 }
153 my %radio_of;
154 foreach my $iid (keys %$wlans) {
155 my $bssid = _mac_number($wlans->{$iid}{mac});
156 my ($range) = grep { $_->[0] <= $bssid && $bssid < $_->[1] }
157 @{ $ranges{ $wlans->{$iid}{ap} } || [] };
158 $radio_of{$iid} = $range->[2] if $range;
159 }
160 return \%radio_of;
161 }
162  
163 sub _mac_number {
164 (my $mac = shift) =~ s/://g;
165 no warnings 'portable';
166 return hex $mac;
167 }
168  
169 sub _in_partial {
170 my ($key, $partial) = @_;
171 return 1 unless defined $partial && length $partial;
172 return $key eq $partial || index($key, "$partial.") == 0;
173 }
174  
175 sub _augment {
176 my ($self, $physical, $field, $partial) = @_;
177 my %result = %{ $physical || {} };
178 my $radios = $self->_radios($partial);
179 my $radio_status = $self->instant_radio_status() || {};
180 my $channels = $self->instant_radio_channel() || {};
181 my $names = $self->instant_ap_name() || {};
182 foreach my $iid (keys %$radios) {
183 my $radio = $radios->{$iid};
184 my $ap_mac = join ':', map {sprintf '%02x', $_} split /\./, $radio->{ap};
185 my $name = "$ap_mac.radio$radio->{number}";
186 my $ap_label = $names->{$radio->{ap}} || $ap_mac;
187 if ($field eq 'index') { $result{$iid} = $name }
188 elsif ($field eq 'name') { $result{$iid} = $name }
189 elsif ($field eq 'label') {
190 $result{$iid} = "$ap_label radio$radio->{number}";
191 }
192 elsif ($field eq 'description') {
193 $result{$iid} = join ': ', $ap_label,
194 "Radio $radio->{number} (channel "
195 . ($channels->{$radio->{source}} // '') . ')';
196 }
197 elsif ($field eq 'type') { $result{$iid} = 'ieee80211' }
198 elsif ($field eq 'mac') {
199 if (defined $radio->{mac}) { $result{$iid} = $radio->{mac} }
200 else { delete $result{$iid} }
201 }
202 elsif ($field eq 'up') {
203 my $value = $radio_status->{$radio->{source}};
204 $result{$iid} = ($value eq '1' ? 'up' : $value eq '2' ? 'down' : $value)
205 if defined $value;
206 }
207 }
208 return \%result;
209 }
210  
211 sub i_index {
212 my ($self, $partial) = @_;
213 return $self->_augment($self->SUPER::i_index($partial), 'index', $partial);
214 }
215  
216 sub interfaces {
217 my ($self, $partial) = @_;
218 return $self->_augment($self->SUPER::interfaces($partial), 'name', $partial);
219 }
220  
221 sub i_name {
222 my ($self, $partial) = @_;
223 return $self->_augment($self->SUPER::i_name($partial), 'label', $partial);
224 }
225  
226 # The virtual controller's ifTable lists one radioMAC interface per BSSID
227 # of its own AP only; radios of every AP are the ports instead.
228 sub i_ignore {
229 my ($self, $partial) = @_;
230 my $interfaces = $self->interfaces($partial) || {};
231 my $types = $self->i_type($partial) || {};
232 my %ignore;
233 foreach my $iid (keys %$interfaces) {
234 next unless ($types->{$iid} // '') eq 'radioMAC';
235 next unless $interfaces->{$iid} =~ /^radio\d+_ssid_id\d+$/;
236 $ignore{$iid} = 1;
237 }
238 return \%ignore;
239 }
240  
241 sub i_description {
242 my ($self, $partial) = @_;
243 return $self->_augment($self->SUPER::i_description($partial), 'description', $partial);
244 }
245  
246 sub i_type {
247 my ($self, $partial) = @_;
248 return $self->_augment($self->SUPER::i_type($partial), 'type', $partial);
249 }
250  
251 sub i_mac {
252 my ($self, $partial) = @_;
253 return $self->_augment($self->SUPER::i_mac($partial), 'mac', $partial);
254 }
255  
256 sub i_up {
257 my ($self, $partial) = @_;
258 return $self->_augment($self->SUPER::i_up($partial), 'up', $partial);
259 }
260  
261 sub i_up_admin {
262 my ($self, $partial) = @_;
263 return $self->_augment($self->SUPER::i_up_admin($partial), 'up', $partial);
264 }
265  
266 # Keyed radio port, then WLAN number: callers drop the last component to
267 # find the port, so every SSID a radio serves lands on that radio.
268 sub _ssid_rows {
269 my ($self, $partial) = @_;
270 my $wlans = $self->_wlans();
271 my $radio_of = $self->_wlan_radios();
272 my %rows;
273 foreach my $iid (keys %$radio_of) {
274 my $key = "$radio_of->{$iid}.$wlans->{$iid}{number}";
275 $rows{$key} = $iid if _in_partial($key, $partial);
276 }
277 return \%rows;
278 }
279  
280 sub i_ssidlist {
281 my ($self, $partial) = @_;
282 my $ssids = $self->instant_wlan_ssid() || {};
283 my $rows = $self->_ssid_rows($partial);
284 return {map { ($_ => $ssids->{ $rows->{$_} }) }
285 grep {defined $ssids->{ $rows->{$_} }} keys %$rows};
286 }
287  
288 sub i_ssidmac {
289 my ($self, $partial) = @_;
290 my $wlans = $self->_wlans();
291 my $rows = $self->_ssid_rows($partial);
292 return {map { ($_ => $wlans->{ $rows->{$_} }{mac}) } keys %$rows};
293 }
294  
295 sub i_ssidbcast {
296 my ($self, $partial) = @_;
297 my $ssids = $self->instant_ssid() || {};
298 my $hide = $self->instant_ssid_hide() || {};
299 my %broadcast;
300 foreach my $idx (keys %$ssids) {
301 next unless defined $ssids->{$idx} && defined $hide->{$idx};
302 next unless $hide->{$idx} =~ /^(?:enable|disable|0|1)$/;
303 $broadcast{$ssids->{$idx}} = ($hide->{$idx} eq 'enable' || $hide->{$idx} eq '1') ? 0 : 1;
304 }
305 my $wlans = $self->i_ssidlist($partial);
306 return {map { ($_ => $broadcast{$wlans->{$_}}) }
307 grep {exists $broadcast{$wlans->{$_}}} keys %$wlans};
308 }
309  
310 sub i_80211channel {
311 my ($self, $partial) = @_;
312 my $channels = $self->instant_radio_channel() || {};
313 my $radios = $self->_radios($partial);
314 my %result;
315 foreach my $iid (keys %$radios) {
316 my $value = $channels->{$radios->{$iid}{source}};
317 next unless defined $value && $value =~ /^(\d+)(?:[+-]|[ES])?$/i;
318 $result{$iid} = 0 + $1 if $1 > 0;
319 }
320 return \%result;
321 }
322  
323 sub dot11_cur_tx_pwr_mw {
324 my ($self, $partial) = @_;
325 my $power = $self->instant_radio_power() || {};
326 my $radios = $self->_radios($partial);
327 my %result;
328 foreach my $iid (keys %$radios) {
329 my $value = $power->{$radios->{$iid}{source}};
330 next unless defined $value && $value =~ /^-?\d+$/;
331 # AI-AP-MIB power is treated as dBm by LibreNMS's Aruba Instant
332 # implementation. Netdisco stores integer milliwatts.
333 $result{$iid} = int(10 ** ($value / 10) + 0.5);
334 }
335 return \%result;
336 }
337  
338 sub bp_index {
339 my ($self, $partial) = @_;
340 my %index = %{ $self->SUPER::bp_index($partial) || {} };
341 my $wlans = $self->_wlans();
342 my $radio_of = $self->_wlan_radios();
343 foreach my $iid (keys %$radio_of) {
344 $index{ $wlans->{$iid}{mac} } = $radio_of->{$iid};
345 }
346 return \%index;
347 }
348  
349 # aiClientTable is indexed by the client MAC, so the MAC comes from the
350 # index of the BSSID column rather than a second walk of aiClientMACAddress.
351 sub _clients {
352 my ($self, $partial) = @_;
353 my $bssids = $self->instant_client_bssid($partial) || {};
354 my $wlans = $self->_wlans();
355 my %known = map { ($wlans->{$_}{mac} => 1) } keys %{ $self->_wlan_radios() };
356 my %clients;
357 foreach my $iid (keys %$bssids) {
358 my @octets = split /\./, $iid;
359 next unless @octets == 6 && !grep { !/^\d+$/ || $_ > 255 } @octets;
360 my $bssid = $bssids->{$iid};
361 next unless defined $bssid && $known{lc $bssid};
362 $clients{$iid} = {mac => join(':', map { sprintf '%02x', $_ } @octets),
363 bssid => lc $bssid};
364 }
365 return \%clients;
366 }
367  
368 sub fw_mac {
369 my ($self, $partial) = @_;
370 my %macs = %{ $self->SUPER::fw_mac($partial) || {} };
371 my $clients = $self->_clients($partial);
372 $macs{"instant.$_"} = $clients->{$_}{mac} foreach keys %$clients;
373 return \%macs;
374 }
375  
376 sub fw_port {
377 my ($self, $partial) = @_;
378 my %ports = %{ $self->SUPER::fw_port($partial) || {} };
379 my $clients = $self->_clients($partial);
380 $ports{"instant.$_"} = $clients->{$_}{bssid} foreach keys %$clients;
381 return \%ports;
382 }
383  
384 # One aiClientTable column for the clients _clients places on a radio.
385 sub _client_column {
386 my ($self, $method) = @_;
387 my $clients = $self->_clients();
388 my $values = $self->$method() || {};
389 return {map { ($_ => $values->{$_}) }
390 grep {defined $values->{$_}} keys %$clients};
391 }
392  
393 sub cd11_mac {
394 my $self = shift;
395 my $clients = $self->_clients();
396 return {map { ($_ => $clients->{$_}{mac}) } keys %$clients};
397 }
398  
399 sub cd11_ssid {
400 my $self = shift;
401 my $clients = $self->_clients();
402 my $wlans = $self->_wlans();
403 my $ssids = $self->instant_wlan_ssid() || {};
404 my %ssid_of = map { ($wlans->{$_}{mac} => $ssids->{$_}) }
405 grep {defined $ssids->{$_}} keys %{ $self->_wlan_radios() };
406 return {map { ($_ => $ssid_of{ $clients->{$_}{bssid} }) }
407 grep {defined $ssid_of{ $clients->{$_}{bssid} }} keys %$clients};
408 }
409  
410 sub cd11_txrate {
411 my $self = shift;
412 my $rates = $self->_client_column('instant_client_txrate');
413 return {map { ($_ => [$rates->{$_}]) } keys %$rates};
414 }
415  
416 sub cd11_sigqual { return shift->_client_column('instant_client_snr') }
417  
418 # AI-AP-MIB reports no RSSI; the inherited leaf is a controller table.
419 sub cd11_sigstrength { return {} }
420  
421 sub cd11_uptime { return shift->_client_column('instant_client_uptime') }
422 sub cd11_txbyte { return shift->_client_column('instant_client_txbytes') }
423 sub cd11_rxbyte { return shift->_client_column('instant_client_rxbytes') }
424 sub cd11_txpkt { return shift->_client_column('instant_client_txframes') }
425 sub cd11_rxpkt { return shift->_client_column('instant_client_rxframes') }
426  
427 # The cluster's serial is its conductor's, the AP at aiConductorIPAddress.
428 # aiMasterIPAddress, the MIB's older name for that AP, is only a fallback. A
429 # member AP walked directly lists only itself.
430 sub serial {
431 my $instant = shift;
432  
433 my $serials = $instant->instant_ap_serial() || {};
434 my $ap_ips = $instant->instant_ap_ip() || {};
435 foreach my $conductor ( $instant->instant_conductor_ip(),
436 $instant->instant_master_ip() )
437 {
438 next unless defined $conductor and $conductor ne '0.0.0.0';
439 foreach my $iid ( keys %$ap_ips ) {
440 next unless ( $ap_ips->{$iid} // '' ) eq $conductor;
441 return $serials->{$iid} if defined $serials->{$iid};
442 }
443 }
444 my @aps = keys %$serials;
445 return $serials->{ $aps[0] } if @aps == 1;
446 return $instant->SUPER::serial();
447 }
448  
449 # APs are entities under the virtual controller, indexed as Layer3::Aruba
450 # indexes controller APs: the last three octets of the AP MAC.
451 sub e_index {
452 my $instant = shift;
453  
454 my $names = $instant->instant_ap_name() || {};
455 my $serials = $instant->instant_ap_serial() || {};
456  
457 my %e_index = ( 0 => 1 );
458 foreach my $iid ( keys %$names, keys %$serials ) {
459 next unless $iid =~ /(\d+\.\d+\.\d+)$/;
460 $e_index{$iid} = int( join '', map { sprintf '%03d', $_ } split /\./, $1 );
461 }
462 return \%e_index;
463 }
464  
465 # The AP name goes in e_name, as on the radio ports; the controller classes
466 # put a generic "AP" there and the name in the description.
467 sub e_name {
468 my $instant = shift;
469  
470 my $e_index = $instant->e_index() || {};
471 my $names = $instant->instant_ap_name() || {};
472  
473 my %e_name;
474 foreach my $iid ( keys %$e_index ) {
475 if ( $iid eq '0' ) {
476 $e_name{$iid} = 'WLAN Controller';
477 next;
478 }
479 my $name = $names->{$iid};
480 $e_name{$iid} = ( defined $name and length $name ) ? $name : 'AP';
481 }
482 return \%e_name;
483 }
484  
485 sub e_descr {
486 my $instant = shift;
487  
488 my $e_index = $instant->e_index() || {};
489 my $models = $instant->instant_ap_model() || {};
490  
491 my %e_descr;
492 foreach my $iid ( keys %$e_index ) {
493 $e_descr{$iid}
494 = $iid eq '0'
495 ? ( $instant->instant_vc_name() || $instant->model() )
496 : ( $models->{$iid} || 'AP' );
497 }
498 return \%e_descr;
499 }
500  
501 sub e_model {
502 my $instant = shift;
503  
504 my $models = $instant->instant_ap_model() || {};
505 my %e_model = ( 0 => $instant->model() );
506 foreach my $iid ( keys %$models ) {
507 $e_model{$iid} = $models->{$iid} if defined $models->{$iid};
508 }
509 return \%e_model;
510 }
511  
512 sub e_type {
513 my $instant = shift;
514 return $instant->instant_ap_type() || {};
515 }
516  
517 sub e_serial {
518 my $instant = shift;
519  
520 my $serials = $instant->instant_ap_serial() || {};
521 my %e_serial = ( 0 => $instant->serial() // '' );
522 foreach my $iid ( keys %$serials ) {
523 $e_serial{$iid} = $serials->{$iid} if defined $serials->{$iid};
524 }
525 return \%e_serial;
526 }
527  
528 # AI-AP-MIB has no hardware or per-AP software version; the inherited
529 # methods would walk controller tables an Instant cluster does not serve.
530 sub e_hwver { return {} }
531  
532 sub e_swver {
533 my $instant = shift;
534  
535 my $version = $instant->instant_vc_version();
536 return {} unless defined $version and length $version;
537 return { 0 => $version };
538 }
539  
540 sub e_fru {
541 my $instant = shift;
542  
543 my $e_index = $instant->e_index() || {};
544 my %e_fru = map { $_ => ( $_ eq '0' ? 'false' : 'true' ) } keys %$e_index;
545 return \%e_fru;
546 }
547  
548 1;
549 __END__