Info/Layer3/ArubaInstant.pm untested

filter: Statementstmt 0.0% 0 / 260 Branchbran 0.0% 0 / 72 Conditioncond 0.0% 0 / 100 MC/DCmcdc 0.0% 0 / 57 Subroutinesub 0.0% 0 / 40 Podpod 0.0% 0 / 36 totaltotal 0.0% 0 / 565 CC 37 SCAR 36.4
CC
37
Cov
0%
_augment
156.0
_wlan_radios
72.0
_wlans
20.0
CRAP 38.0
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.985003';
40  
41 %MIBS = (%SNMP::Info::Layer3::Aruba::MIBS,
42 'AI-AP-MIB' => 'aiWlanESSID');
43 %GLOBALS = (%SNMP::Info::Layer3::Aruba::GLOBALS);
44 %FUNCS = (%SNMP::Info::Layer3::Aruba::FUNCS,
45 'instant_radio_channel' => 'aiRadioChannel',
46 'instant_radio_power' => 'aiRadioTransmitPower',
47 'instant_radio_mac' => 'aiRadioMACAddress',
48 'instant_radio_status' => 'aiRadioStatus',
49 'instant_wlan_ssid' => 'aiWlanESSID',
50 'instant_wlan_mac' => 'aiWlanMACAddress',
51 'instant_ap_name' => 'aiAPName',
52 'instant_ap_status' => 'aiAPStatus',
53 'instant_ssid' => 'aiSSID',
54 'instant_ssid_hide' => 'aiSSIDHide',
55 'instant_client_mac' => 'aiClientMACAddress',
56 'instant_client_bssid'=> 'aiClientWlanMACAddress',
57 'instant_client_snr' => 'aiClientSNR',
58 'instant_client_txrate' => 'aiClientTxRate',
59 'instant_client_uptime' => 'aiClientUptime',
60 'instant_client_txbytes' => 'aiClientTxDataBytes',
61 'instant_client_rxbytes' => 'aiClientRxDataBytes',
62 'instant_client_txframes' => 'aiClientTxDataFrames',
63 'instant_client_rxframes' => 'aiClientRxDataFrames',
64 );
65 %MUNGE = (%SNMP::Info::Layer3::Aruba::MUNGE,
66 'instant_radio_mac' => \&SNMP::Info::munge_mac,
67 'instant_wlan_mac' => \&SNMP::Info::munge_mac,
68 'instant_client_mac' => \&SNMP::Info::munge_mac,
69 'instant_client_bssid' => \&SNMP::Info::munge_mac,
70 'instant_wlan_ssid' => \&SNMP::Info::munge_null,
71 'instant_ssid' => \&SNMP::Info::munge_null,
72 );
73  
74 # WLANs with a usable BSSID. They are not ports: each is mapped to the radio
75 # that serves it (_wlan_radios).
76 sub _wlans {
77 my ($self, $partial) = @_;
78 my $macs = $self->instant_wlan_mac($partial) || {};
79 my %wlans;
80 foreach my $iid (keys %$macs) {
81 next unless $iid =~ /^(\d+(?:\.\d+){5})\.(\d+)$/;
82 my ($ap, $number) = ($1, $2);
83 my $mac = $macs->{$iid};
84 next unless defined $mac && $mac =~ /^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/i;
85 next if $mac eq '00:00:00:00:00:00';
86 $wlans{$iid} = {ap => $ap, number => $number, mac => lc $mac};
87 }
88 return \%wlans;
89 }
90  
91 # One port per radio. The trailing .0 keeps the keys radio ports had when
92 # WLANs were ports too, and leaves room for the WLAN number in i_ssidlist.
93 sub _radios {
94 my ($self, $partial) = @_;
95 my $channels = $self->instant_radio_channel() || {};
96 my $macs = $self->instant_radio_mac() || {};
97 my %radios;
98 # A radio missing from one column (a failed walk) keeps its port.
99 foreach my $iid (keys %{ {%$channels, %$macs} }) {
100 next unless $iid =~ /^(\d+(?:\.\d+){5})\.(\d+)$/;
101 my ($ap, $number) = ($1, $2);
102 my $mac = $macs->{$iid};
103 $mac = undef unless defined $mac && $mac =~ /^(?:[0-9a-f]{2}:){5}[0-9a-f]{2}$/i;
104 my $logical = "$iid.0";
105 next if defined $partial && length $partial
106 && $logical ne $partial && index($logical, "$partial.") != 0;
107 $radios{$logical} = {ap => $ap, number => $number,
108 source => $iid, kind => 'radio', mac => $mac};
109 }
110 return \%radios;
111 }
112  
113 # BSSIDs count up from their radio's MAC (16 per radio on current APs, 8
114 # on older ones), so each radio owns the addresses from its MAC up to the
115 # next radio's MAC on the same AP. The highest radio owns a range as wide
116 # as the gap below it, or 16 on a single-radio AP. A WLAN no range holds is
117 # left out, not guessed. A radio with no MAC may sit inside any other
118 # radio's range, so on its AP each radio keeps only the 8 addresses no
119 # other radio can start within.
120 sub _wlan_radios {
121 my $self = shift;
122 my $wlans = $self->_wlans();
123 my $radios = $self->_radios();
124 my (%by_ap, %unbounded);
125 foreach my $iid (keys %$radios) {
126 my $radio = $radios->{$iid};
127 $unbounded{ $radio->{ap} } = 1 unless defined $radio->{mac};
128 next unless defined $radio->{mac};
129 push @{ $by_ap{ $radio->{ap} } }, [_mac_number($radio->{mac}), $iid];
130 }
131 my %ranges;
132 foreach my $ap (keys %by_ap) {
133 my @sorted = sort { $a->[0] <=> $b->[0] || $a->[1] cmp $b->[1] }
134 @{ $by_ap{$ap} };
135 foreach my $i (0 .. $#sorted) {
136 my ($start, $iid) = @{ $sorted[$i] };
137 my $gap = $i > 0 ? $start - $sorted[$i - 1][0] : 0;
138 my $end = $i < $#sorted ? $sorted[$i + 1][0]
139 : $start + ($gap > 0 ? $gap : 16);
140 $end = $start + 8 if $unbounded{$ap} && $end > $start + 8;
141 push @{ $ranges{$ap} }, [$start, $end, $iid];
142 }
143 }
144 my %radio_of;
145 foreach my $iid (keys %$wlans) {
146 my $bssid = _mac_number($wlans->{$iid}{mac});
147 my ($range) = grep { $_->[0] <= $bssid && $bssid < $_->[1] }
148 @{ $ranges{ $wlans->{$iid}{ap} } || [] };
149 $radio_of{$iid} = $range->[2] if $range;
150 }
151 return \%radio_of;
152 }
153  
154 sub _mac_number {
155 (my $mac = shift) =~ s/://g;
156 no warnings 'portable';
157 return hex $mac;
158 }
159  
160 sub _in_partial {
161 my ($key, $partial) = @_;
162 return 1 unless defined $partial && length $partial;
163 return $key eq $partial || index($key, "$partial.") == 0;
164 }
165  
166 sub _augment {
167 my ($self, $physical, $field, $partial) = @_;
168 my %result = %{ $physical || {} };
169 my $radios = $self->_radios($partial);
170 my $radio_status = $self->instant_radio_status() || {};
171 my $channels = $self->instant_radio_channel() || {};
172 my $names = $self->instant_ap_name() || {};
173 foreach my $iid (keys %$radios) {
174 my $radio = $radios->{$iid};
175 my $ap_mac = join ':', map {sprintf '%02x', $_} split /\./, $radio->{ap};
176 my $name = "$ap_mac.radio$radio->{number}";
177 my $ap_label = $names->{$radio->{ap}} || $ap_mac;
178 if ($field eq 'index') { $result{$iid} = $name }
179 elsif ($field eq 'name') { $result{$iid} = $name }
180 elsif ($field eq 'label') {
181 $result{$iid} = "$ap_label radio$radio->{number}";
182 }
183 elsif ($field eq 'description') {
184 $result{$iid} = join ': ', $ap_label,
185 "Radio $radio->{number} (channel "
186 . ($channels->{$radio->{source}} // '') . ')';
187 }
188 elsif ($field eq 'type') { $result{$iid} = 'ieee80211' }
189 elsif ($field eq 'mac') {
190 if (defined $radio->{mac}) { $result{$iid} = $radio->{mac} }
191 else { delete $result{$iid} }
192 }
193 elsif ($field eq 'up') {
194 my $value = $radio_status->{$radio->{source}};
195 $result{$iid} = ($value eq '1' ? 'up' : $value eq '2' ? 'down' : $value)
196 if defined $value;
197 }
198 }
199 return \%result;
200 }
201  
202 sub i_index {
203 my ($self, $partial) = @_;
204 return $self->_augment($self->SUPER::i_index($partial), 'index', $partial);
205 }
206  
207 sub interfaces {
208 my ($self, $partial) = @_;
209 return $self->_augment($self->SUPER::interfaces($partial), 'name', $partial);
210 }
211  
212 sub i_name {
213 my ($self, $partial) = @_;
214 return $self->_augment($self->SUPER::i_name($partial), 'label', $partial);
215 }
216  
217 # The virtual controller's ifTable lists one radioMAC interface per BSSID
218 # of its own AP only; radios of every AP are the ports instead.
219 sub i_ignore {
220 my ($self, $partial) = @_;
221 my $interfaces = $self->interfaces($partial) || {};
222 my $types = $self->i_type($partial) || {};
223 my %ignore;
224 foreach my $iid (keys %$interfaces) {
225 next unless ($types->{$iid} // '') eq 'radioMAC';
226 next unless $interfaces->{$iid} =~ /^radio\d+_ssid_id\d+$/;
227 $ignore{$iid} = 1;
228 }
229 return \%ignore;
230 }
231  
232 sub i_description {
233 my ($self, $partial) = @_;
234 return $self->_augment($self->SUPER::i_description($partial), 'description', $partial);
235 }
236  
237 sub i_type {
238 my ($self, $partial) = @_;
239 return $self->_augment($self->SUPER::i_type($partial), 'type', $partial);
240 }
241  
242 sub i_mac {
243 my ($self, $partial) = @_;
244 return $self->_augment($self->SUPER::i_mac($partial), 'mac', $partial);
245 }
246  
247 sub i_up {
248 my ($self, $partial) = @_;
249 return $self->_augment($self->SUPER::i_up($partial), 'up', $partial);
250 }
251  
252 sub i_up_admin {
253 my ($self, $partial) = @_;
254 return $self->_augment($self->SUPER::i_up_admin($partial), 'up', $partial);
255 }
256  
257 # Keyed radio port, then WLAN number: callers drop the last component to
258 # find the port, so every SSID a radio serves lands on that radio.
259 sub _ssid_rows {
260 my ($self, $partial) = @_;
261 my $wlans = $self->_wlans();
262 my $radio_of = $self->_wlan_radios();
263 my %rows;
264 foreach my $iid (keys %$radio_of) {
265 my $key = "$radio_of->{$iid}.$wlans->{$iid}{number}";
266 $rows{$key} = $iid if _in_partial($key, $partial);
267 }
268 return \%rows;
269 }
270  
271 sub i_ssidlist {
272 my ($self, $partial) = @_;
273 my $ssids = $self->instant_wlan_ssid() || {};
274 my $rows = $self->_ssid_rows($partial);
275 return {map { ($_ => $ssids->{ $rows->{$_} }) }
276 grep {defined $ssids->{ $rows->{$_} }} keys %$rows};
277 }
278  
279 sub i_ssidmac {
280 my ($self, $partial) = @_;
281 my $wlans = $self->_wlans();
282 my $rows = $self->_ssid_rows($partial);
283 return {map { ($_ => $wlans->{ $rows->{$_} }{mac}) } keys %$rows};
284 }
285  
286 sub i_ssidbcast {
287 my ($self, $partial) = @_;
288 my $ssids = $self->instant_ssid() || {};
289 my $hide = $self->instant_ssid_hide() || {};
290 my %broadcast;
291 foreach my $idx (keys %$ssids) {
292 next unless defined $ssids->{$idx} && defined $hide->{$idx};
293 next unless $hide->{$idx} =~ /^(?:enable|disable|0|1)$/;
294 $broadcast{$ssids->{$idx}} = ($hide->{$idx} eq 'enable' || $hide->{$idx} eq '1') ? 0 : 1;
295 }
296 my $wlans = $self->i_ssidlist($partial);
297 return {map { ($_ => $broadcast{$wlans->{$_}}) }
298 grep {exists $broadcast{$wlans->{$_}}} keys %$wlans};
299 }
300  
301 sub i_80211channel {
302 my ($self, $partial) = @_;
303 my $channels = $self->instant_radio_channel() || {};
304 my $radios = $self->_radios($partial);
305 my %result;
306 foreach my $iid (keys %$radios) {
307 my $value = $channels->{$radios->{$iid}{source}};
308 next unless defined $value && $value =~ /^(\d+)(?:[+-]|[ES])?$/i;
309 $result{$iid} = 0 + $1 if $1 > 0;
310 }
311 return \%result;
312 }
313  
314 sub dot11_cur_tx_pwr_mw {
315 my ($self, $partial) = @_;
316 my $power = $self->instant_radio_power() || {};
317 my $radios = $self->_radios($partial);
318 my %result;
319 foreach my $iid (keys %$radios) {
320 my $value = $power->{$radios->{$iid}{source}};
321 next unless defined $value && $value =~ /^-?\d+$/;
322 # AI-AP-MIB power is treated as dBm by LibreNMS's Aruba Instant
323 # implementation. Netdisco stores integer milliwatts.
324 $result{$iid} = int(10 ** ($value / 10) + 0.5);
325 }
326 return \%result;
327 }
328  
329 sub bp_index {
330 my ($self, $partial) = @_;
331 my %index = %{ $self->SUPER::bp_index($partial) || {} };
332 my $wlans = $self->_wlans();
333 my $radio_of = $self->_wlan_radios();
334 foreach my $iid (keys %$radio_of) {
335 $index{ $wlans->{$iid}{mac} } = $radio_of->{$iid};
336 }
337 return \%index;
338 }
339  
340 # aiClientTable is indexed by the client MAC, so the MAC comes from the
341 # index of the BSSID column rather than a second walk of aiClientMACAddress.
342 sub _clients {
343 my ($self, $partial) = @_;
344 my $bssids = $self->instant_client_bssid($partial) || {};
345 my $wlans = $self->_wlans();
346 my %known = map { ($wlans->{$_}{mac} => 1) } keys %{ $self->_wlan_radios() };
347 my %clients;
348 foreach my $iid (keys %$bssids) {
349 my @octets = split /\./, $iid;
350 next unless @octets == 6 && !grep { !/^\d+$/ || $_ > 255 } @octets;
351 my $bssid = $bssids->{$iid};
352 next unless defined $bssid && $known{lc $bssid};
353 $clients{$iid} = {mac => join(':', map { sprintf '%02x', $_ } @octets),
354 bssid => lc $bssid};
355 }
356 return \%clients;
357 }
358  
359 sub fw_mac {
360 my ($self, $partial) = @_;
361 my %macs = %{ $self->SUPER::fw_mac($partial) || {} };
362 my $clients = $self->_clients($partial);
363 $macs{"instant.$_"} = $clients->{$_}{mac} foreach keys %$clients;
364 return \%macs;
365 }
366  
367 sub fw_port {
368 my ($self, $partial) = @_;
369 my %ports = %{ $self->SUPER::fw_port($partial) || {} };
370 my $clients = $self->_clients($partial);
371 $ports{"instant.$_"} = $clients->{$_}{bssid} foreach keys %$clients;
372 return \%ports;
373 }
374  
375 # One aiClientTable column for the clients _clients places on a radio.
376 sub _client_column {
377 my ($self, $method) = @_;
378 my $clients = $self->_clients();
379 my $values = $self->$method() || {};
380 return {map { ($_ => $values->{$_}) }
381 grep {defined $values->{$_}} keys %$clients};
382 }
383  
384 sub cd11_mac {
385 my $self = shift;
386 my $clients = $self->_clients();
387 return {map { ($_ => $clients->{$_}{mac}) } keys %$clients};
388 }
389  
390 sub cd11_ssid {
391 my $self = shift;
392 my $clients = $self->_clients();
393 my $wlans = $self->_wlans();
394 my $ssids = $self->instant_wlan_ssid() || {};
395 my %ssid_of = map { ($wlans->{$_}{mac} => $ssids->{$_}) }
396 grep {defined $ssids->{$_}} keys %{ $self->_wlan_radios() };
397 return {map { ($_ => $ssid_of{ $clients->{$_}{bssid} }) }
398 grep {defined $ssid_of{ $clients->{$_}{bssid} }} keys %$clients};
399 }
400  
401 sub cd11_txrate {
402 my $self = shift;
403 my $rates = $self->_client_column('instant_client_txrate');
404 return {map { ($_ => [$rates->{$_}]) } keys %$rates};
405 }
406  
407 sub cd11_sigqual { return shift->_client_column('instant_client_snr') }
408  
409 # AI-AP-MIB reports no RSSI; the inherited leaf is a controller table.
410 sub cd11_sigstrength { return {} }
411  
412 sub cd11_uptime { return shift->_client_column('instant_client_uptime') }
413 sub cd11_txbyte { return shift->_client_column('instant_client_txbytes') }
414 sub cd11_rxbyte { return shift->_client_column('instant_client_rxbytes') }
415 sub cd11_txpkt { return shift->_client_column('instant_client_txframes') }
416 sub cd11_rxpkt { return shift->_client_column('instant_client_rxframes') }
417  
418 1;
419 __END__