Info/Layer3/Tasman.pm untested

filter: Statementstmt 0.0% 0 / 130 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 35 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 14 totaltotal 0.0% 0 / 244 CC 15 SCAR 22.6
CC
15
Cov
0%
e_descr
20.0
e_parent
20.0
os_ver
12.0
CRAP 9.6
1 # SNMP::Info::Layer3::Tasman
2 #
3 # Copyright (c) 2012 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::Layer3::Tasman;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35  
36 use SNMP::Info::Layer3;
37 use SNMP::Info::MAU;
38  
39 @SNMP::Info::Layer3::Tasman::ISA = qw/SNMP::Info::MAU
40 SNMP::Info::Layer3 Exporter/;
41 @SNMP::Info::Layer3::Tasman::EXPORT_OK = qw//;
42  
43 our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE);
44  
45 $VERSION = '3.985003';
46  
47 %MIBS = (
48 %SNMP::Info::Layer3::MIBS,
49 %SNMP::Info::MAU::MIBS,
50 'NT-ENTERPRISE-DATA-MIB' => 'ntEnterpriseRouters',
51 'SYSTEM-MIB' => 'nnsysVersion',
52 'CHASSIS-MIB' => 'nnchassisModel',
53 'ENVIRONMENT-MIB' => 'nnenvPwrsupStatus',
54 );
55  
56 %GLOBALS = (
57 %SNMP::Info::Layer3::GLOBALS,
58 %SNMP::Info::MAU::GLOBALS,
59 'ps1_type' => 'nnenvPwrsupType.1',
60 'ps1_status' => 'nnenvPwrsupStatus.1',
61 'ps2_type' => 'nnenvPwrsupType.2',
62 'ps2_status' => 'nnenvPwrsupStatus.2',
63 'nn_sys_ver' => 'nnsysVersion',
64 'nn_ch_model' => 'nnchassisModel',
65 'nn_ch_op_stat' => 'nnchassisOperStatus',
66 'nn_ch_serial' => 'nnchassisSerialNumber',
67 );
68  
69 %FUNCS = ( %SNMP::Info::Layer3::FUNCS, %SNMP::Info::MAU::FUNCS, );
70  
71 %MUNGE = ( %SNMP::Info::Layer3::MUNGE, %SNMP::Info::MAU::MUNGE, );
72  
73 # use MAU-MIB for admin. duplex and admin. speed
74 *SNMP::Info::Layer3::Tasman::i_duplex_admin
75 = \&SNMP::Info::MAU::mau_i_duplex_admin;
76 *SNMP::Info::Layer3::Tasman::i_speed_admin
77 = \&SNMP::Info::MAU::mau_i_speed_admin;
78  
79 my $module_map = {
80 ADSL_ANX_A => '1-port ADSL2+ Annex A',
81 ADSL_ANX_B => '1-port ADSL2+ Annex B',
82 BRI_2ST => '2-port ST-interface ISDN BRI for both TDM and Packet',
83 FXO_2M => 'Voice Interface card - 2 port FXO',
84 FXO_4M => 'Voice Interface card - 4 port FXO',
85 FXS_2M => 'Voice Interface card - 2 port FXS',
86 FXS_4M => 'Voice Interface card - 4 port FXS',
87 HSSI_1 => '1-port High Speed Serial',
88 LMF_24 => '24-port 10/100 Fast Ethernet Layer2/3 switch',
89 LMG_10 =>
90 '10-port non-blocking 10/100/1000 Gigabit Ethernet Layer2/3 switch',
91 LMG_44 => '44-port 10/100/1000 Gigabit Ethernet Layer 2/3 switch',
92 LMP_24 => '24-port 10/100 fast Ethernet Layer2/3 PoE switch',
93 PVIM_A => 'Packetized Voice Module (PVIM)',
94 SCIM_A => 'Ipsec VPN Encryption Module',
95 SERV_MOD => 'Secure Router 4134 Server Module',
96 VCM_A =>
97 'Medium Carrier module supports up to 4 FXO or FXS Small Modules',
98 VOIP_A => 'Packetized Voice Module (PVM)',
99 VPN_A => 'High Performance IPsec VPN Encryption Module',
100 WDS3_1C => '1-port Clear Channel DS3',
101 WT3_1C => '1-port Channelized T3',
102 DS3_1C => '1-port Channelized T3',
103 WTE_1 => '1-port T1/E1 w DS0 and DS1 support for both TDM and Packet',
104 WTE_2S => '2-port Sync and Async Serial',
105 WTE_8 => '8-port T1/E1',
106 };
107  
108 sub vendor {
109 return 'avaya';
110 }
111  
112 sub os {
113 return 'tasman';
114 }
115  
116 sub os_ver {
117 my $tasman = shift;
118 my $version = $tasman->nn_sys_ver() || "";
119 my $descr = $tasman->description() || "";
120  
121 # Newer versions
122 return $1 if ( $version =~ /^SW:\s+(.+?)\s+/ );
123  
124 # Older versions
125 return $1 if ( $descr =~ /Software Version\s+=\s+[r]*(.+),/ );
126  
127 # Can't find
128 return;
129 }
130  
131 sub model {
132 my $tasman = shift;
133  
134 my $id = $tasman->id();
135 my $ch_model = $tasman->nn_ch_model();
136  
137 return $ch_model if $ch_model;
138  
139 my $model = &SNMP::translateObj($id);
140 return $id unless defined $model;
141  
142 $model =~ s/^ntSecureRouter/SR/;
143 return $model;
144 }
145  
146 sub serial {
147 my $tasman = shift;
148  
149 # Newer versions of the software redefined the MIB in a non-backwards
150 # compatible manner. Try the old OID first.
151 my $serial = $tasman->nn_ch_op_stat();
152  
153 # Newer versions populate status, serial should contain some letters
154 # while a status is an integer
155 return $serial if ( $serial !~ /^\D+$/ );
156  
157 # Unfortunately newer versions don't seem to populate the newer OID.
158 # so check modules for a chassis
159 my $e_parent = $tasman->e_parent();
160  
161 foreach my $iid ( keys %$e_parent ) {
162 my $parent = $e_parent->{$iid};
163 if ( $parent eq '0' ) {
164 my $ser = $tasman->e_serial($iid);
165 return $ser->{$iid};
166 }
167 }
168  
169 # If everything else failed just return what is supposed to hold the
170 # serial although it probably doesn't
171 return $tasman->nn_ch_serial();
172 }
173  
174 # Slots 1–4 are Small Module slots. Slots 5–7 are Medium Module slots.
175 # A Large Module spans slots 6 and 7. It will be identified as slot 6.
176  
177 sub e_index {
178 my $tasman = shift;
179  
180 my $index = $tasman->nnchassisInfoSlotSubSlotString() || {};
181  
182 # In some cases the modules are duplicated, remove duplicates
183 my %seen;
184 my %e_index;
185 foreach my $key ( keys %$index ) {
186 my $string = $index->{$key};
187 $string =~ s/\D//;
188 unless ( $seen{$string} ) {
189 $seen{$string}++;
190 $e_index{$key} = $string + 1;
191 }
192 }
193  
194 return \%e_index;
195 }
196  
197 sub e_class {
198 my $tasman = shift;
199  
200 my $e_index = $tasman->e_index() || {};
201  
202 my %e_class;
203 foreach my $iid ( keys %$e_index ) {
204  
205 my $index = $e_index->{$iid};
206  
207 if ( $index == 1 ) {
208 $e_class{$iid} = 'chassis';
209 }
210 else {
211 $e_class{$iid} = 'module';
212 }
213 }
214 return \%e_class;
215 }
216  
217 sub e_descr {
218 my $tasman = shift;
219  
220 my $e_index = $tasman->e_index() || {};
221 my $types = $tasman->nnchassisInfoCardType || {};
222  
223 my %e_descr;
224 foreach my $iid ( keys %$e_index ) {
225 my $type = $types->{$iid};
226 next unless $type;
227  
228 if ( $type =~ /^MPU/ ) {
229 $e_descr{$iid} = $tasman->model();
230 }
231 elsif ( defined $module_map->{$type} ) {
232 $e_descr{$iid} = $module_map->{$type};
233 }
234 else {
235 next;
236 }
237 }
238 return \%e_descr;
239 }
240  
241 sub e_serial {
242 my $tasman = shift;
243  
244 my $e_index = $tasman->e_index() || {};
245 my $serials = $tasman->nnchassisInfoSerialNumber() || {};
246  
247 my %e_serial;
248 foreach my $iid ( keys %$e_index ) {
249 $e_serial{$iid} = $serials->{$iid} || '';
250 }
251 return \%e_serial;
252 }
253  
254 sub e_fru {
255 my $tasman = shift;
256  
257 my $e_index = $tasman->e_index() || {};
258  
259 my %e_fru;
260 foreach my $iid ( keys %$e_index ) {
261 $e_fru{$iid} = "true";
262 }
263 return \%e_fru;
264 }
265  
266 sub e_type {
267 my $tasman = shift;
268  
269 my $e_index = $tasman->e_index() || {};
270 my $types = $tasman->nnchassisInfoCardType || {};
271  
272 my %e_type;
273 foreach my $iid ( keys %$e_index ) {
274 $e_type{$iid} = $types->{$iid} || '';
275 }
276  
277 return \%e_type;
278 }
279  
280 sub e_vendor {
281 my $tasman = shift;
282  
283 my $e_idx = $tasman->e_index() || {};
284  
285 my %e_vendor;
286 foreach my $iid ( keys %$e_idx ) {
287 $e_vendor{$iid} = 'avaya';
288 }
289 return \%e_vendor;
290 }
291  
292 sub e_pos {
293 my $tasman = shift;
294  
295 return $tasman->e_index();
296 }
297  
298 sub e_parent {
299 my $tasman = shift;
300  
301 my $e_idx = $tasman->e_index() || {};
302 my $e_classes = $tasman->e_class() || {};
303  
304 my $cha_idx = 0;
305 foreach my $i ( keys %$e_classes ) {
306 my $class = $e_classes->{$i};
307 my $pos = $e_idx->{$i};
308 if ( $class && $class eq 'chassis' ) {
309 $cha_idx = $pos;
310 }
311 }
312  
313 my %e_parent;
314 foreach my $iid ( keys %$e_idx ) {
315 my $idx = $e_idx->{$iid};
316  
317 if ( $idx == 1 ) {
318 $e_parent{$iid} = 0;
319 }
320 elsif ( $idx =~ /^(\d)\d$/ ) {
321 $e_parent{$iid} = $1;
322 }
323 else {
324 $e_parent{$iid} = $cha_idx;
325 }
326 }
327 return \%e_parent;
328 }
329  
330 1;
331 __END__