Info/Layer2/NAP222x.pm untested

filter: Statementstmt 0.0% 0 / 186 Branchbran 0.0% 0 / 78 Conditioncond 0.0% 0 / 44 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 365 CC 40 SCAR 32.8
CC
40
Cov
0%
i_duplex_admin
56.0
i_80211channel
56.0
i_duplex
42.0
CRAP 26.5
1 # SNMP::Info::Layer2::NAP222x
2 #
3 # Copyright (c) 2008 Eric Miller
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 University of California, Santa Cruz nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from 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 package SNMP::Info::Layer2::NAP222x;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::SONMP;
36 use SNMP::Info::IEEE802dot11;
37 use SNMP::Info::Layer2;
38  
39 @SNMP::Info::Layer2::NAP222x::ISA
40 = qw/SNMP::Info::SONMP SNMP::Info::IEEE802dot11 SNMP::Info::Layer2 Exporter/;
41 @SNMP::Info::Layer2::NAP222x::EXPORT_OK = qw//;
42  
43 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE);
44  
45 $VERSION = '3.985003';
46  
47 %MIBS = (
48 %SNMP::Info::Layer2::MIBS, %SNMP::Info::IEEE802dot11::MIBS,
49 %SNMP::Info::SONMP::MIBS, 'NORTEL-WLAN-AP-MIB' => 'ntWlanSwHardwareVer',
50 );
51  
52 %GLOBALS = (
53 %SNMP::Info::Layer2::GLOBALS,
54 %SNMP::Info::IEEE802dot11::GLOBALS,
55 %SNMP::Info::SONMP::GLOBALS,
56 'nt_hw_ver' => 'ntWlanSwHardwareVer',
57 'nt_fw_ver' => 'ntWlanSwBootRomVer',
58 'nt_sw_ver' => 'ntWlanSwOpCodeVer',
59 'nt_cc' => 'ntWlanSwCountryCode',
60 'tftp_action' => 'ntWlanTransferStart',
61 'tftp_host' => 'ntWlanFileServer',
62 'tftp_file' => 'ntWlanDestFile',
63 'tftp_type' => 'ntWlanFileType',
64 'tftp_result' => 'ntWlanFileTransferStatus',
65 'tftp_xtype' => 'ntWlanTransferType',
66 'tftp_src_file' => 'ntWlanSrcFile',
67 'ftp_user' => 'ntWlanUserName',
68 'ftp_pass' => 'ntWlanPassword',
69 );
70  
71 %FUNCS = (
72 %SNMP::Info::Layer2::FUNCS,
73 %SNMP::Info::IEEE802dot11::FUNCS,
74 %SNMP::Info::SONMP::FUNCS,
75  
76 # From ntWlanPortTable
77 'nt_prt_name' => 'ntWlanPortName',
78 'nt_dpx_admin' => 'ntWlanPortCapabilities',
79 'nt_auto' => 'ntWlanPortAutonegotiation',
80 'nt_dpx' => 'ntWlanPortSpeedDpxStatus',
81  
82 # From ntWlanDot11PhyOperationTable
83 'nt_i_broadcast' => 'ntWlanDot11ClosedSystem',
84  
85 # From ntWlanApVlanTable
86 'nt_i_vlan' => 'ntWlanApVlanDefaultVid',
87 );
88  
89 %MUNGE = (
90 %SNMP::Info::Layer2::MUNGE, %SNMP::Info::IEEE802dot11::MUNGE,
91 %SNMP::Info::SONMP::MUNGE,
92 );
93  
94 sub os {
95 return 'nortel';
96 }
97  
98 sub os_bin {
99 my $nap222x = shift;
100 my $bin = $nap222x->nt_fw_ver();
101 return unless defined $bin;
102  
103 if ( $bin =~ m/(\d+\.\d+\.\d+)/ ) {
104 return $1;
105 }
106 return;
107 }
108  
109 sub model {
110 my $nap222x = shift;
111 my $descr = $nap222x->description();
112 return unless defined $descr;
113  
114 return 'AP-2220' if ( $descr =~ /2220/ );
115 return 'AP-2221' if ( $descr =~ /2221/ );
116 return;
117 }
118  
119 sub mac {
120 my $nap222x = shift;
121 my $i_mac = $nap222x->i_mac();
122  
123 # Return Interface MAC
124 foreach my $entry ( keys %$i_mac ) {
125 my $sn = $i_mac->{$entry};
126 next unless $sn;
127 return $sn;
128 }
129 return;
130 }
131  
132 sub serial {
133 my $nap222x = shift;
134 my $i_mac = $nap222x->i_mac();
135  
136 # Return Interface MAC
137 foreach my $entry ( keys %$i_mac ) {
138 my $sn = $i_mac->{$entry};
139 next unless $sn;
140 return $sn;
141 }
142 return;
143 }
144  
145 sub interfaces {
146 my $nap222x = shift;
147 my $partial = shift;
148  
149 my $interfaces = $nap222x->i_index($partial) || {};
150 my $description = $nap222x->i_description($partial) || {};
151  
152 my %interfaces = ();
153 foreach my $iid ( keys %$interfaces ) {
154 my $desc = $description->{$iid};
155 next unless defined $desc;
156 next if $desc =~ /lo/i;
157  
158 $interfaces{$iid} = $desc;
159 }
160 return \%interfaces;
161 }
162  
163 sub i_duplex {
164 my $nap222x = shift;
165 my $partial = shift;
166  
167 my $mode = $nap222x->nt_dpx($partial) || {};
168 my $port_name = $nap222x->nt_prt_name($partial) || {};
169 my $interfaces = $nap222x->interfaces($partial) || {};
170  
171 my %i_duplex;
172 foreach my $if ( keys %$interfaces ) {
173 my $port = $interfaces->{$if};
174 next unless $port =~ /dp/i;
175 foreach my $idx ( keys %$mode ) {
176 my $name = $port_name->{$idx} || 'unknown';
177 next unless $name eq $port;
178 my $duplex = $mode->{$idx};
179  
180 $duplex = 'other' unless defined $duplex;
181 $duplex = 'half' if $duplex =~ /half/i;
182 $duplex = 'full' if $duplex =~ /full/i;
183  
184 $i_duplex{$if} = $duplex;
185 }
186 }
187 return \%i_duplex;
188 }
189  
190 sub i_duplex_admin {
191 my $nap222x = shift;
192 my $partial = shift;
193  
194 my $dpx_admin = $nap222x->nt_dpx_admin($partial) || {};
195 my $nt_auto = $nap222x->nt_auto($partial) || {};
196 my $interfaces = $nap222x->interfaces($partial) || {};
197 my $port_name = $nap222x->nt_prt_name($partial) || {};
198  
199 my %i_duplex_admin;
200 foreach my $if ( keys %$interfaces ) {
201 my $port = $interfaces->{$if};
202 next unless $port =~ /dp/i;
203 foreach my $idx ( keys %$dpx_admin ) {
204 my $name = $port_name->{$idx} || 'unknown';
205 next unless $name eq $port;
206 my $duplex = $dpx_admin->{$idx};
207 my $auto = $nt_auto->{$idx};
208  
209 $duplex = 'other' unless defined $duplex;
210 $duplex = 'half'
211 if ( $duplex =~ /half/i and $auto =~ /disabled/i );
212 $duplex = 'full'
213 if ( $duplex =~ /full/i and $auto =~ /disabled/i );
214 $duplex = 'auto' if $auto =~ /enabled/i;
215  
216 $i_duplex_admin{$if} = $duplex;
217 }
218 }
219 return \%i_duplex_admin;
220 }
221  
222 sub i_name {
223 my $nap222x = shift;
224 my $partial = shift;
225  
226 my $interfaces = $nap222x->interfaces($partial) || {};
227  
228 my %i_name;
229 foreach my $if ( keys %$interfaces ) {
230 my $desc = $interfaces->{$if};
231 next unless defined $desc;
232  
233 my $name = 'unknown';
234 $name = 'Ethernet Interface' if $desc =~ /dp/i;
235 $name = 'Wireless Interface B' if $desc =~ /ndc/i;
236 $name = 'Wireless Interface A' if $desc =~ /ar/i;
237  
238 $i_name{$if} = $name;
239 }
240 return \%i_name;
241 }
242  
243 # dot1dBasePortTable does not exist and dot1dTpFdbPort does not map to ifIndex
244 sub bp_index {
245 my $nap222x = shift;
246 my $partial = shift;
247  
248 my $interfaces = $nap222x->interfaces($partial) || {};
249  
250 my %bp_index;
251 foreach my $iid ( keys %$interfaces ) {
252 my $desc = $interfaces->{$iid};
253 next unless defined $desc;
254 next unless $desc =~ /(ndc|ar)/i;
255  
256 my $port = 1;
257 $port = 2 if $desc =~ /ndc/i;
258  
259 $bp_index{$port} = $iid;
260 }
261 return \%bp_index;
262 }
263  
264 # Indicies don't match anywhere in these devices! Need to override to match
265 # IfIndex.
266 sub i_ssidlist {
267 my $nap222x = shift;
268 my $partial = shift;
269  
270 # modify partial to match index
271 if ( defined $partial ) {
272 $partial = $partial - 2;
273 }
274 my $ssids = $nap222x->orig_i_ssidlist($partial) || {};
275  
276 my %i_ssidlist;
277 foreach my $iid ( keys %$ssids ) {
278 my $port = $iid + 2;
279 my $ssid = $ssids->{$iid};
280 next unless defined $ssid;
281  
282 $i_ssidlist{$port} = $ssid;
283 }
284 return \%i_ssidlist;
285 }
286  
287 sub i_ssidbcast {
288 my $nap222x = shift;
289 my $partial = shift;
290  
291 # modify partial to match index
292 if ( defined $partial ) {
293 $partial = $partial - 2;
294 }
295 my $bcast = $nap222x->nt_i_broadcast($partial) || {};
296  
297 my %i_ssidbcast;
298 foreach my $iid ( keys %$bcast ) {
299 my $port = $iid + 2;
300 my $bc = $bcast->{$iid};
301 next unless defined $bc;
302  
303 $i_ssidbcast{$port} = $bc;
304 }
305 return \%i_ssidbcast;
306 }
307  
308 sub i_80211channel {
309 my $nap222x = shift;
310 my $partial = shift;
311  
312 # modify partial to match index
313 if ( defined $partial ) {
314 $partial = $partial - 2;
315 }
316 my $phy_type = $nap222x->dot11_phy_type($partial) || {};
317 my $cur_freq = $nap222x->dot11_cur_freq() || {};
318 my $cur_ch = $nap222x->dot11_cur_ch() || {};
319  
320 my %i_80211channel;
321 foreach my $iid ( keys %$phy_type ) {
322 my $port = $iid + 2;
323 my $type = $phy_type->{$iid};
324 next unless defined $type;
325 if ( $type =~ /dsss/ ) {
326 my $ch = $cur_ch->{1};
327 next unless defined $ch;
328 $i_80211channel{$port} = $ch;
329 }
330 elsif ( $type =~ /ofdm/ ) {
331 my $ch = $cur_freq->{0};
332 next unless defined $ch;
333 $i_80211channel{$port} = $ch;
334 }
335 else {
336 next;
337 }
338 }
339  
340 return \%i_80211channel;
341 }
342  
343 sub i_vlan {
344 my $nap222x = shift;
345 my $partial = shift;
346  
347 # modify partial to match index
348 if ( defined $partial ) {
349 $partial = $partial - 2;
350 }
351 my $vlans = $nap222x->nt_i_vlan($partial) || {};
352  
353 my %i_vlan;
354 foreach my $iid ( keys %$vlans ) {
355 my $port = $iid + 2;
356 my $vlan = $vlans->{$iid};
357 next unless defined $vlan;
358  
359 $i_vlan{$port} = $vlan;
360 }
361 return \%i_vlan;
362 }
363  
364 1;
365 __END__