Info/Layer1/S3000.pm untested

filter: Statementstmt 0.0% 0 / 172 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 63 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 0.0% 0 / 21 Podpod 0.0% 0 / 17 totaltotal 0.0% 0 / 358 CC 26 SCAR 26.6
CC
26
Cov
0%
i_up
42.0
model
20.0
i_up_admin
20.0
CRAP 14.3
1 # SNMP::Info::Layer1::S3000
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::Layer1::S3000;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer2;
36  
37 @SNMP::Info::Layer1::S3000::ISA = qw/SNMP::Info::Layer2 Exporter/;
38 @SNMP::Info::Layer1::S3000::EXPORT_OK = qw//;
39  
40 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = (
45 %SNMP::Info::Layer2::MIBS,
46 'SYNOPTICS-ETHERNET-MIB' => 's3EnetPortTable',
47 'SYNOPTICS-COMMON-MIB' => 's3AgentType',
48 );
49  
50 %GLOBALS = (
51 %SNMP::Info::Layer2::GLOBALS,
52  
53 # From SYNOPTICS-COMMON-MIB
54 'os_bin' => 's3AgentFwVer',
55 's3000_major_ver' => 's3AgentSwMajorVer',
56 's3000_minor_ver' => 's3AgentSwMinorVer',
57 's3000_maint_ver' => 's3AgentSwMaintVer',
58 );
59  
60 %FUNCS = (
61 %SNMP::Info::Layer2::FUNCS,
62  
63 # SYNOPTICS-ETHERNET-MIB::s3EnetPortTable
64 's3000_pb_index' => 's3EnetPortBoardIndex',
65 's3000_pp_index' => 's3EnetPortIndex',
66 's3000_up_admin' => 's3EnetPortPartStatus',
67 's3000_up' => 's3EnetPortLinkStatus',
68  
69 # SYNOPTICS-ETHERNET-MIB::s3EnetShowNodesTable
70 's3000_nb_index' => 's3EnetShowNodesSlotIndex',
71 's3000_np_index' => 's3EnetShowNodesPortIndex',
72 'fw_mac' => 's3EnetShowNodesMacAddress',
73  
74 # SYNOPTICS-ETHERNET-MIB::s3EnetTopNmmTable
75 's3000_topo_port' => 's3EnetTopNmmPort',
76 's3000_topo_mac' => 's3EnetTopNmmMacAddr',
77 );
78  
79 %MUNGE = (
80 %SNMP::Info::Layer2::MUNGE, 's3000_topo_mac' => \&SNMP::Info::munge_mac
81 );
82  
83 sub layers {
84 return '00000011';
85 }
86  
87 sub os {
88 return 'synoptics';
89 }
90  
91 sub vendor {
92 return 'nortel';
93 }
94  
95 sub model {
96 my $s3000 = shift;
97 my $id = $s3000->id();
98 return unless defined $id;
99 my $model = &SNMP::translateObj($id);
100 return $id unless defined $model;
101 $model =~ s/^s3reg-//i;
102  
103 return $1 if ( $model =~ /((\d+){3}[\dX])/ );
104 return $model;
105 }
106  
107 sub os_ver {
108 my $s3000 = shift;
109 my $major_ver = $s3000->s3000_major_ver() || 0;
110 my $minor_ver = $s3000->s3000_minor_ver() || 0;
111 my $maint_ver = $s3000->s3000_maint_ver() || 0;
112  
113 my $ver = "$major_ver.$minor_ver.$maint_ver";
114 return $ver;
115 }
116  
117 sub mac {
118 my $s3000 = shift;
119 my $topo_port = $s3000->s3000_topo_port();
120 my $topo_mac = $s3000->s3000_topo_mac();
121  
122 foreach my $entry ( keys %$topo_port ) {
123 my $port = $topo_port->{$entry};
124 next unless $port == 0;
125 my $mac = $topo_mac->{$entry};
126 return $mac;
127 }
128  
129 # Topology turned off, not supported.
130 return;
131 }
132  
133 # Hubs do not support ifMIB requirements for get MAC
134 # and port status
135  
136 sub i_index {
137 my $s3000 = shift;
138 my $partial = shift;
139  
140 my $b_index = $s3000->s3000_pb_index($partial) || {};
141 my $p_index = $s3000->s3000_pp_index($partial) || {};
142  
143 my %i_index;
144 foreach my $iid ( keys %$b_index ) {
145 my $board = $b_index->{$iid};
146 next unless defined $board;
147 my $port = $p_index->{$iid} || 0;
148  
149 # We need to make up an index for multiple board instances.
150 my $index = ( $board * 256 ) + $port;
151  
152 $i_index{$iid} = $index;
153 }
154 return \%i_index;
155 }
156  
157 # Partials don't really help in this class, but implemented
158 # for consistency
159  
160 sub interfaces {
161 my $s3000 = shift;
162 my $partial = shift;
163  
164 my $i_index = $s3000->i_index() || {};
165  
166 my %if;
167 foreach my $iid ( keys %$i_index ) {
168 my $index = $i_index->{$iid};
169 next unless defined $index;
170 next if ( defined $partial and $index !~ /^$partial$/ );
171  
172 # Index numbers are deterministic slot * 256 + port - see i_index()
173 my $port = $index % 256;
174 my $slot = int( $index / 256 );
175  
176 my $slotport = "$slot.$port";
177  
178 $if{$index} = $slotport;
179 }
180  
181 return \%if;
182 }
183  
184 sub i_duplex {
185 my $s3000 = shift;
186 my $partial = shift;
187  
188 my $port_index = $s3000->i_index() || {};
189  
190 my %i_duplex;
191 foreach my $iid ( keys %$port_index ) {
192 my $index = $port_index->{$iid};
193 next unless defined $index;
194 next if ( defined $partial and $index !~ /^$partial$/ );
195  
196 # Hubs only function half duplex
197 my $duplex = 'half';
198 $i_duplex{$index} = $duplex;
199 }
200 return \%i_duplex;
201 }
202  
203 sub i_duplex_admin {
204 my $s3000 = shift;
205 my $partial = shift;
206  
207 my $port_index = $s3000->i_index() || {};
208  
209 my %i_duplex_admin;
210 foreach my $iid ( keys %$port_index ) {
211 my $index = $port_index->{$iid};
212 next unless defined $index;
213 next if ( defined $partial and $index !~ /^$partial$/ );
214  
215 # Hubs only function half duplex
216 my $duplex = 'half';
217 $i_duplex_admin{$index} = $duplex;
218 }
219 return \%i_duplex_admin;
220 }
221  
222 sub i_speed {
223 my $s3000 = shift;
224 my $partial = shift;
225  
226 my $port_index = $s3000->i_index() || {};
227  
228 my %i_speed;
229 foreach my $iid ( keys %$port_index ) {
230 my $index = $port_index->{$iid};
231 next unless defined $index;
232 next if ( defined $partial and $index !~ /^$partial$/ );
233  
234 # These hubs only support 10 Mbs
235 my $speed = '10000000';
236 $i_speed{$index} = $speed;
237 }
238 return \%i_speed;
239 }
240  
241 sub i_up {
242 my $s3000 = shift;
243 my $partial = shift;
244  
245 my $port_index = $s3000->i_index() || {};
246 my $link_stat = $s3000->s3000_up() || {};
247  
248 my %i_up;
249 foreach my $iid ( keys %$port_index ) {
250 my $index = $port_index->{$iid};
251 next unless defined $index;
252 next if ( defined $partial and $index !~ /^$partial$/ );
253 my $link_stat = $link_stat->{$iid};
254 next unless defined $link_stat;
255  
256 $link_stat = 'up' if $link_stat =~ /on/i;
257 $link_stat = 'down' if $link_stat =~ /off/i;
258  
259 $i_up{$index} = $link_stat;
260 }
261 return \%i_up;
262 }
263  
264 sub i_up_admin {
265 my $s3000 = shift;
266 my $partial = shift;
267  
268 my $i_index = $s3000->i_index() || {};
269 my $link_stat = $s3000->s3000_up_admin() || {};
270  
271 my %i_up_admin;
272 foreach my $iid ( keys %$i_index ) {
273 my $index = $i_index->{$iid};
274 next unless defined $index;
275 next if ( defined $partial and $index !~ /^$partial$/ );
276 my $link_stat = $link_stat->{$iid};
277 next unless defined $link_stat;
278  
279 $i_up_admin{$index} = $link_stat;
280 }
281 return \%i_up_admin;
282 }
283  
284 sub set_i_up_admin {
285  
286 # map setting to those the hub will understand
287 my %setting = qw/up 2 down 3/;
288  
289 my $s3000 = shift;
290 my ( $setting, $iid ) = @_;
291  
292 my $i_index = $s3000->i_index() || {};
293 my %reverse_i_index = reverse %$i_index;
294  
295 $setting = lc($setting);
296  
297 return 0 unless defined $setting{$setting};
298  
299 $iid = $reverse_i_index{$iid};
300  
301 return $s3000->set_s3000_up_admin( $setting{$setting}, $iid );
302 }
303  
304 # Hubs do not support the standard Bridge MIB
305 sub bp_index {
306 my $s3000 = shift;
307 my $partial = shift;
308  
309 my $b_index = $s3000->s3000_nb_index() || {};
310 my $p_index = $s3000->s3000_np_index() || {};
311 my $model = $s3000->model();
312  
313 my %bp_index;
314 foreach my $iid ( keys %$b_index ) {
315 my $board = $b_index->{$iid};
316 next unless defined $board;
317 my $port = $p_index->{$iid} || 0;
318  
319 my $index = ( $board * 256 ) + $port;
320 next if ( defined $partial and $index !~ /^$partial$/ );
321  
322 $bp_index{$index} = $index;
323 }
324 return \%bp_index;
325 }
326  
327 sub fw_mac {
328 my $s3000 = shift;
329 my $partial = shift;
330  
331 return $s3000->SUPER::fw_mac($partial);
332 }
333  
334 sub fw_port {
335 my $s3000 = shift;
336 my $partial = shift;
337  
338 my $b_index = $s3000->s3000_nb_index($partial) || {};
339 my $p_index = $s3000->s3000_np_index($partial) || {};
340 my $model = $s3000->model();
341  
342 my %fw_port;
343 foreach my $iid ( keys %$b_index ) {
344 my $board = $b_index->{$iid};
345 next unless defined $board;
346 my $port = $p_index->{$iid} || 0;
347  
348 my $index = ( $board * 256 ) + $port;
349  
350 $fw_port{$iid} = $index;
351 }
352 return \%fw_port;
353 }
354  
355 1;
356 __END__