Info/Layer2/RuckusAP.pm untested

filter: Statementstmt 0.0% 0 / 220 Branchbran 0.0% 0 / 60 Conditioncond 0.0% 0 / 99 MC/DCmcdc 0.0% 0 / 56 Subroutinesub 0.0% 0 / 34 Podpod 0.0% 0 / 30 totaltotal 0.0% 0 / 499 CC 31 SCAR 28.6
CC
31
Cov
0%
_ruckus_wlan_rows
72.0
os_ver
30.0
i_80211channel
20.0
CRAP 17.5
1 # SNMP::Info::Layer2::RuckusAP - SNMP interface to Ruckus access points
2 #
3 # Copyright (c) 2026 The SNMP::Info Developers
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the copyright holder nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29 #
30  
31 package SNMP::Info::Layer2::RuckusAP;
32  
33 use strict;
34 use warnings;
35 use Exporter;
36 use SNMP::Info::Layer2;
37  
38 our ($VERSION, %GLOBALS, %FUNCS, %MIBS, %MUNGE);
39 $VERSION = '3.985003';
40 @SNMP::Info::Layer2::RuckusAP::ISA = qw(SNMP::Info::Layer2 Exporter);
41 @SNMP::Info::Layer2::RuckusAP::EXPORT_OK = qw//;
42  
43 %MIBS = (
44 %SNMP::Info::Layer2::MIBS,
45 'RUCKUS-HWINFO-MIB' => 'ruckusHwInfoModelNumber',
46 'RUCKUS-SWINFO-MIB' => 'ruckusSwRevision',
47 'RUCKUS-WLAN-MIB' => 'ruckusWLANSSID',
48 );
49  
50 %GLOBALS = (
51 %SNMP::Info::Layer2::GLOBALS,
52 'ruckus_model' => 'ruckusHwInfoModelNumber',
53 'ruckus_serial' => 'ruckusHwInfoSerialNumber',
54 );
55  
56 %FUNCS = (
57 %SNMP::Info::Layer2::FUNCS,
58 'ruckus_sw_rev' => 'ruckusSwRevision',
59 'ruckus_sw_rev_status' => 'ruckusSwRevStatus',
60 'ruckus_wlan_ssid' => 'ruckusWLANSSID',
61 'ruckus_wlan_bssid' => 'ruckusWLANBSSID',
62 'ruckus_wlan_channel' => 'ruckusWLANChannel',
63 'ruckus_wlan_admin_status' => 'ruckusWLANAdminStatus',
64 'ruckus_wlan_bcast_disabled' => 'ruckusWLANSSIDBcastDisable',
65 'ruckus_wlan_ifindex' => 'ruckusWLANIfIndex',
66 'ruckus_wlan_name' => 'ruckusWLANName',
67 'ruckus_wlan_vlan' => 'ruckusWLANVlanID',
68 'ruckus_station_mac' => 'ruckusWLANStaAddr',
69 'ruckus_station_rates' => 'ruckusWLANStaRates',
70 'ruckus_station_stats_mac' => 'ruckusWLANStaStatsMacAddr',
71 'ruckus_station_stats_ssid' => 'ruckusWLANStaStatsSSID',
72 'ruckus_station_stats_rxpkt' => 'ruckusWLANStaStatsRxDataFrames',
73 'ruckus_station_stats_rxbyte' => 'ruckusWLANStaStatsRxBytes',
74 'ruckus_station_stats_txpkt' => 'ruckusWLANStaStatsTxDataFrames',
75 'ruckus_station_stats_txbyte' => 'ruckusWLANStaStatsTxBytes',
76 'ruckus_station_stats_rssi' => 'ruckusWLANStaStatsRSSI',
77 'ruckus_station_rks_txrate' => 'ruckusWLANStaRksTxRate',
78 );
79  
80 %MUNGE = (
81 %SNMP::Info::Layer2::MUNGE,
82 );
83  
84 # Ruckus APs do not implement SNMPv2-MIB::sysServices. They bridge wireless
85 # clients onto their WLAN interfaces, so report layer 2 for layer-aware
86 # discovery and MAC collection.
87 sub layers {
88 return '00000010';
89 }
90  
91 # The WLAN table is indexed by WLAN number, and ruckusWLANIfIndex repeats
92 # it rather than giving an IF-MIB ifIndex. No column names a WLAN's radio:
93 # the AP numbers WLANs 0-31 on wifi0 and 32-63 on wifi1, as every walk
94 # shows and Ruckus community posts describe (snmp-info#672). A WLAN with
95 # no such radio stays on its own interface, matched by name. Returns, per
96 # active row, its port and its own WLAN interface.
97 sub _ruckus_wlan_rows {
98 my $self = shift;
99 my $status = $self->ruckus_wlan_admin_status() || {};
100 my $names = $self->ruckus_wlan_name() || {};
101 my $i_descr = $self->i_description() || {};
102  
103 my ( %radio, %ifindexes_named );
104 foreach my $iid ( keys %$i_descr ) {
105 my $descr = $i_descr->{$iid};
106 next unless defined $descr;
107 $radio{$1} = $iid if $descr =~ /^wifi(\d+)$/;
108 push @{ $ifindexes_named{$descr} }, $iid;
109 }
110  
111 my %rows;
112 foreach my $row ( keys %$status ) {
113 my $state = $status->{$row};
114 next unless defined $state;
115 next unless $state eq q{1} or lc($state) eq q{up};
116 next unless $row =~ /^\d+$/;
117 my $named = $ifindexes_named{ $names->{$row} // '' } || [];
118 my $wlan_if = @$named == 1 ? $named->[0] : undef;
119 my $port = $radio{ int( $row / 32 ) } // $wlan_if;
120 $rows{$row} = [ $port, $wlan_if ] if defined $port;
121 }
122 return \%rows;
123 }
124  
125 sub _ruckus_wlan_values_by_port {
126 my ( $self, $method, $partial ) = @_;
127 my $values = $self->$method() || {};
128 my $rows = _ruckus_wlan_rows($self);
129 my %result;
130  
131 foreach my $row ( keys %$rows ) {
132 my $port = $rows->{$row}[0];
133 next if defined $partial and $partial ne $port;
134 next unless defined $values->{$row};
135 $result{"$port.$row"} = $values->{$row};
136 }
137  
138 return \%result;
139 }
140  
141 # Station tables are indexed <WLAN number>.6.<client MAC>.
142 sub _ruckus_station_ports {
143 my $self = shift;
144 my $macs = $self->ruckus_station_mac() || {};
145 my $rows = _ruckus_wlan_rows($self);
146 my %ports;
147  
148 foreach my $idx ( keys %$macs ) {
149 next unless $idx =~ /^(\d+)\.6\.\d+(?:\.\d+){5}$/;
150 next unless exists $rows->{$1};
151 $ports{$idx} = [ $rows->{$1}[0], $1, $macs->{$idx} ];
152 }
153 return \%ports;
154 }
155  
156 sub interfaces {
157 my ( $self, $partial ) = @_;
158 my $interfaces = $self->SUPER::interfaces($partial) || {};
159 my $rows = _ruckus_wlan_rows($self);
160  
161 foreach my $row ( values %$rows ) {
162 my ( $port, $wlan_if ) = @$row;
163 delete $interfaces->{$wlan_if}
164 if defined $wlan_if and $wlan_if ne $port;
165 }
166 return $interfaces;
167 }
168  
169 sub i_ssidlist {
170 my ( $self, $partial ) = @_;
171 my $ssids = _ruckus_wlan_values_by_port( $self, 'ruckus_wlan_ssid',
172 $partial );
173 return { map { $_ => $ssids->{$_} } grep { $ssids->{$_} =~ /\S/ }
174 keys %$ssids };
175 }
176  
177 sub i_ssidmac {
178 my ( $self, $partial ) = @_;
179 my $values = _ruckus_wlan_values_by_port(
180 $self, 'ruckus_wlan_bssid', $partial
181 );
182 foreach my $key ( keys %$values ) {
183 $values->{$key} = SNMP::Info::munge_mac( $values->{$key} );
184 }
185 return $values;
186 }
187  
188 sub i_ssidbcast {
189 my ( $self, $partial ) = @_;
190 my $disabled = _ruckus_wlan_values_by_port(
191 $self, 'ruckus_wlan_bcast_disabled', $partial
192 );
193 my %broadcast;
194 foreach my $key ( keys %$disabled ) {
195 my $value = $disabled->{$key};
196 $broadcast{$key} = ( $value eq '1' or lc($value) eq 'true' ) ? 0 : 1;
197 }
198 return \%broadcast;
199 }
200  
201 sub i_80211channel {
202 my ( $self, $partial ) = @_;
203 my $channels = $self->ruckus_wlan_channel() || {};
204 my $rows = _ruckus_wlan_rows($self);
205 my %result;
206  
207 # Every WLAN on a radio repeats its channel; ruckusRadioChannel reads 0.
208 foreach my $row ( sort { $a <=> $b } keys %$rows ) {
209 my $port = $rows->{$row}[0];
210 next if defined $partial and $partial ne $port;
211 next unless defined $channels->{$row};
212 $result{$port} = $channels->{$row} unless exists $result{$port};
213 }
214  
215 return \%result;
216 }
217  
218 sub i_vlan_membership {
219 my ( $self, $partial ) = @_;
220 my $vlans = _ruckus_wlan_values_by_port( $self, 'ruckus_wlan_vlan',
221 $partial );
222 my %members;
223  
224 foreach my $key ( keys %$vlans ) {
225 my $vlan = $vlans->{$key};
226 next unless $vlan;
227 ( my $port = $key ) =~ s/\.\d+$//;
228 $members{$port}{$vlan} = 1;
229 }
230 return { map { $_ => [ sort { $a <=> $b } keys %{ $members{$_} } ] }
231 keys %members };
232 }
233  
234 sub fw_mac {
235 my $self = shift;
236 my $standard = $self->SUPER::fw_mac() || {};
237 my $stations = _ruckus_station_ports($self);
238 my %result = %$standard;
239  
240 foreach my $idx ( keys %$stations ) {
241 $result{$idx} = SNMP::Info::munge_mac( $stations->{$idx}[2] );
242 }
243 return \%result;
244 }
245  
246 sub fw_port {
247 my $self = shift;
248 my $standard = $self->SUPER::fw_port() || {};
249 my $stations = _ruckus_station_ports($self);
250 my %result = %$standard;
251  
252 $result{$_} = $stations->{$_}[0] foreach keys %$stations;
253 return \%result;
254 }
255  
256 sub fw_ssid {
257 my $self = shift;
258 my $ssids = $self->ruckus_wlan_ssid() || {};
259 my $stations = _ruckus_station_ports($self);
260 my %result;
261  
262 foreach my $idx ( keys %$stations ) {
263 my $ssid = $ssids->{ $stations->{$idx}[1] };
264 $result{$idx} = $ssid if defined $ssid and $ssid =~ /\S/;
265 }
266 return \%result;
267 }
268  
269 # No station table has a VLAN column, so a client takes the VLAN its WLAN
270 # is configured with. A VLAN assigned per client (dynamic VLAN) is not seen.
271 sub qb_fw_vlan {
272 my $self = shift;
273 my $standard = $self->SUPER::qb_fw_vlan() || {};
274 my $vlans = $self->ruckus_wlan_vlan() || {};
275 my $stations = _ruckus_station_ports($self);
276 my %result = %$standard;
277  
278 foreach my $idx ( keys %$stations ) {
279 my $vlan = $vlans->{ $stations->{$idx}[1] };
280 $result{$idx} = $vlan if $vlan;
281 }
282 return \%result;
283 }
284  
285 sub _ruckus_stats_index {
286 my ($idx) = @_;
287 return $idx if $idx =~ /^\d+\.6(?:\.\d+){6}$/;
288 return "$1.6.$2" if $idx =~ /^(\d+)\.(\d+(?:\.\d+){5})$/;
289 return;
290 }
291  
292 sub cd11_mac {
293 my $self = shift;
294 my $macs = $self->ruckus_station_stats_mac() || {};
295 return { map { $_ => SNMP::Info::munge_mac( $macs->{$_} ) } keys %$macs };
296 }
297  
298 sub cd11_ssid {
299 my $self = shift;
300 return $self->ruckus_station_stats_ssid() || {};
301 }
302  
303 sub cd11_txrate {
304 my $self = shift;
305 my $rates = $self->ruckus_station_rks_txrate() || {};
306 my %result;
307 foreach my $idx ( keys %$rates ) {
308 my $stats_idx = _ruckus_stats_index($idx);
309 next unless defined $stats_idx and defined $rates->{$idx};
310 # Agents report this PHY rate in Kbps; cd11_txrate is in Mbps.
311 $result{$stats_idx} = [ $rates->{$idx} / 1000 ];
312 }
313 return \%result;
314 }
315  
316 sub cd11_rateset {
317 my $self = shift;
318 my $raw_rates = $self->ruckus_station_rates() || {};
319 my %result;
320 foreach my $idx ( keys %$raw_rates ) {
321 my $raw = $raw_rates->{$idx};
322 next unless defined $raw and length $raw;
323 my $number = qr/\d+(?:\.\d+)?/;
324 my @rates
325 = ( $raw =~ /^\s*$number(?:[\s,]+$number)*\s*$/ )
326 ? map { 0 + $_ } grep {length} split /[\s,]+/, $raw
327 : map { ( ( $_ & 0x7f ) / 2 ) } unpack 'C*', $raw;
328 $result{$idx} = \@rates if @rates;
329 }
330 return \%result;
331 }
332  
333 sub cd11_sigstrength {
334 my $self = shift;
335 return $self->ruckus_station_stats_rssi() || {};
336 }
337  
338 sub cd11_rxpkt {
339 my $self = shift;
340 return $self->ruckus_station_stats_rxpkt() || {};
341 }
342  
343 sub cd11_txpkt {
344 my $self = shift;
345 return $self->ruckus_station_stats_txpkt() || {};
346 }
347  
348 sub cd11_rxbyte {
349 my $self = shift;
350 return $self->ruckus_station_stats_rxbyte() || {};
351 }
352  
353 sub cd11_txbyte {
354 my $self = shift;
355 return $self->ruckus_station_stats_txbyte() || {};
356 }
357  
358 # No Ruckus AP seen serves BRIDGE-MIB, and fw_port returns the radio's
359 # ifIndex, so each interface is its own bridge port.
360 sub bp_index {
361 my $self = shift;
362 my $ifindexes = $self->i_index() || {};
363 return { map { $_ => $_ } keys %$ifindexes };
364 }
365  
366 sub model {
367 my $self = shift;
368 my $description = $self->description() || '';
369 my ($unleashed_model)
370 = $description =~ /^Ruckus Wireless ([A-Z]\d{3}\w*)/;
371 return $self->ruckus_model() || $unleashed_model || $self->SUPER::model();
372 }
373  
374 sub vendor { return 'ruckus'; }
375 sub os { return 'ruckus'; }
376 sub os_ver {
377 my $self = shift;
378 my $revisions = $self->ruckus_sw_rev() || {};
379 my $statuses = $self->ruckus_sw_rev_status() || {};
380  
381 foreach my $index ( sort { $a <=> $b } keys %$revisions ) {
382 my $status = $statuses->{$index};
383 my $revision = $revisions->{$index};
384 next unless defined $status;
385 next unless defined $revision and $revision =~ /\S/;
386 return $revision
387 if $status =~ /^(?:active|2)$/i;
388 }
389  
390 # Some firmware (R500 on 9.13) answers ruckusSwRevision with no status.
391 my ($first_revision) = grep { defined and /\S/ }
392 @$revisions{ sort { $a <=> $b } keys %$revisions };
393 return $first_revision if !%$statuses and defined $first_revision;
394  
395 return $self->SUPER::os_ver();
396 }
397 sub serial {
398 my $self = shift;
399 my $serial = $self->ruckus_serial();
400 return $serial if defined $serial and $serial !~ /^\s*$/;
401 return $self->SUPER::serial();
402 }
403  
404 1;
405  
406 __END__