Info/Layer2/Baystack.pm untested

filter: Statementstmt 0.0% 0 / 196 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 95 MC/DCmcdc 0.0% 0 / 57 Subroutinesub 0.0% 0 / 34 Podpod 0.0% 0 / 26 totaltotal 0.0% 0 / 454 CC 24 SCAR 27.8
CC
24
Cov
0%
model
56.0
os_bin
30.0
index_factor
30.0
CRAP 16.1
1 # SNMP::Info::Layer2::Baystack
2 #
3 # Copyright (c) 2008 Max Baker changes from version 0.8 and beyond.
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::Baystack;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::SONMP;
36 use SNMP::Info::NortelStack;
37 use SNMP::Info::RapidCity;
38 use SNMP::Info::RapidCityLegacy;
39 use SNMP::Info::Layer3;
40  
41 @SNMP::Info::Layer2::Baystack::ISA
42 = qw/SNMP::Info::SONMP SNMP::Info::NortelStack
43 SNMP::Info::RapidCityLegacy SNMP::Info::RapidCity
44 SNMP::Info::Layer3 Exporter/;
45 @SNMP::Info::Layer2::Baystack::EXPORT_OK = qw//;
46  
47 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE);
48  
49 $VERSION = '3.985003';
50  
51 %MIBS = (
52 %SNMP::Info::Layer3::MIBS,
53 %SNMP::Info::RapidCity::MIBS, %SNMP::Info::RapidCityLegacy::MIBS,
54 %SNMP::Info::NortelStack::MIBS,
55 %SNMP::Info::SONMP::MIBS,
56 'BAY-STACK-PETH-EXT-MIB' => 'bspePethPsePortExtMeasuredPower',
57 );
58  
59 %GLOBALS = (
60 %SNMP::Info::Layer3::GLOBALS,
61 %SNMP::Info::RapidCity::GLOBALS, %SNMP::Info::RapidCityLegacy::GLOBALS,
62 %SNMP::Info::NortelStack::GLOBALS,
63 %SNMP::Info::SONMP::GLOBALS,
64 );
65  
66 %FUNCS = (
67 %SNMP::Info::Layer3::FUNCS,
68 %SNMP::Info::RapidCity::FUNCS, %SNMP::Info::RapidCityLegacy::FUNCS,
69 %SNMP::Info::NortelStack::FUNCS,
70 %SNMP::Info::SONMP::FUNCS,
71 'peth_port_power' => 'bspePethPsePortExtMeasuredPower',
72 );
73  
74 # 450's report full duplex as speed = 20mbps?!
75 $SNMP::Info::SPEED_MAP{20_000_000} = '10 Mbps';
76 $SNMP::Info::SPEED_MAP{200_000_000} = '100 Mbps';
77 $SNMP::Info::SPEED_MAP{2_000_000_000} = '1.0 Gbps';
78  
79 %MUNGE = (
80 %SNMP::Info::Layer3::MUNGE,
81 %SNMP::Info::RapidCity::MUNGE, %SNMP::Info::RapidCityLegacy::MUNGE,
82 %SNMP::Info::NortelStack::MUNGE,
83 %SNMP::Info::SONMP::MUNGE,
84 );
85  
86 sub os {
87 my $baystack = shift;
88 my $descr = $baystack->description() || "";
89 my $model = $baystack->model() || "";
90  
91 if ( $descr =~ /Business Ethernet Switch.*SW:v/i ) {
92 return 'bes';
93 }
94 if ( ( ( $model =~ /(420|425|BPS)/ ) and ( $descr =~ m/SW:v[1-2]/i ) )
95 or ( ( $model =~ /(410|450|380)/ ) ) )
96 {
97 return 'baystack';
98 }
99 if ( $model =~ /VSP/ ) {
100 return 'vsp';
101 }
102  
103 return 'boss';
104 }
105  
106 sub os_bin {
107 my $baystack = shift;
108 my $descr = $baystack->description();
109 return unless defined $descr;
110  
111 # 303 / 304
112 if ( $descr =~ m/Rev: \d+\.(\d+\.\d+\.\d+)-\d+\.\d+\.\d+\.\d+/ ) {
113 return $1;
114 }
115  
116 # 450
117 if ( $descr =~ m/FW:V(\d+\.\d+)/ ) {
118 return $1;
119 }
120  
121 if ( $descr =~ m/FW:(\d+\.\d+\.\d+\.\d+)/i ) {
122 return $1;
123 }
124 return;
125 }
126  
127 sub vendor {
128 return 'avaya';
129 }
130  
131 sub model {
132 my $baystack = shift;
133 my $id = $baystack->id();
134 return unless defined $id;
135 my $model = &SNMP::translateObj($id);
136 return $id unless defined $model;
137  
138 my $descr = $baystack->description();
139  
140 # The 303 and 304 share one sysObjectID; other models can carry 303 or
141 # 304 in sysDescr as a software build number
142 if ( $model =~ /BayStack303-304/ and defined $descr ) {
143 return '303' if ( $descr =~ /\D303\D/ );
144 return '304' if ( $descr =~ /\D304\D/ );
145 }
146 return 'BPS' if ( $model =~ /BPS2000/i );
147  
148 # Pull sreg- from all
149 $model =~ s/^sreg-//;
150 # Strip ES/ERS/BayStack etc. from those families
151 $model =~ s/^(E(R)?S|BayStack|Ethernet(Routing)?Switch)-?//;
152 $model =~ s/-ethSwitchNMM//;
153  
154 return $model;
155 }
156  
157 sub interfaces {
158 my $baystack = shift;
159 my $partial = shift;
160  
161 my $i_index = $baystack->i_index($partial) || {};
162 my $index_factor = $baystack->index_factor();
163 my $slot_offset = $baystack->slot_offset();
164  
165 my %if;
166 foreach my $iid ( keys %$i_index ) {
167 my $index = $i_index->{$iid};
168 next unless defined $index;
169  
170 # Ignore cascade ports
171 next if $index > $index_factor * 8;
172  
173 my $port = ( $index % $index_factor );
174 my $slot = ( int( $index / $index_factor ) ) + $slot_offset;
175  
176 my $slotport = "$slot.$port";
177 $if{$iid} = $slotport;
178 }
179 return \%if;
180 }
181  
182 sub i_mac {
183 my $baystack = shift;
184 my $partial = shift;
185  
186 my $i_mac = $baystack->orig_i_mac($partial) || {};
187  
188 my %i_mac;
189  
190 # Baystack 303's with a hw rev < 2.11.4.5 report the mac as all zeros
191 foreach my $iid ( keys %$i_mac ) {
192 my $mac = $i_mac->{$iid};
193 next unless defined $mac;
194 next if $mac eq '00:00:00:00:00:00';
195 $i_mac{$iid} = $mac;
196 }
197 return \%i_mac;
198 }
199  
200 sub i_name {
201 my $baystack = shift;
202 my $partial = shift;
203  
204 my $i_index = $baystack->i_index($partial) || {};
205 my $i_alias = $baystack->i_alias($partial) || {};
206 my $i_name2 = $baystack->orig_i_name($partial) || {};
207  
208 my %i_name;
209 foreach my $iid ( keys %$i_name2 ) {
210 my $name = $i_name2->{$iid};
211 my $alias = $i_alias->{$iid};
212 $i_name{$iid}
213 = ( defined $alias and $alias !~ /^\s*$/ )
214 ? $alias
215 : $name;
216 }
217  
218 return \%i_name;
219 }
220  
221 sub index_factor {
222 my $baystack = shift;
223 my $model = $baystack->model() || "";
224 my $os = $baystack->os();
225 my $os_ver = $baystack->os_ver();
226 my $op_mode = $baystack->ns_op_mode();
227  
228 $op_mode = 'pure' unless defined $op_mode;
229 if ( defined $os_ver and $os_ver =~ m/^(\d+)\./ ) {
230 $os_ver = $1;
231 } else {
232 $os_ver = 1;
233 }
234  
235 my $index_factor = 32;
236 $index_factor = 64
237 if ( ( $model =~ /(470)/ )
238 or ( $os =~ m/(boss|bes)/ ) and ( $op_mode eq 'pure' ) );
239 $index_factor = 128
240 if ( ( $model =~ /(5[569]\d\d)|VSP|4950/ )
241 and ( $os_ver >= 6 ) );
242  
243 return $index_factor;
244 }
245  
246  
247  
248 # Newer devices support ENTITY-MIB, use if available otherwise use proprietary
249 # methods.
250  
251 sub e_index {
252 my $stack = shift;
253 my $partial = shift;
254  
255 return $stack->SUPER::e_index($partial) || $stack->ns_e_index($partial);
256 }
257  
258 sub e_class {
259 my $stack = shift;
260 my $partial = shift;
261  
262 return $stack->SUPER::e_class($partial) || $stack->ns_e_class($partial);
263 }
264  
265 sub e_descr {
266 my $stack = shift;
267 my $partial = shift;
268  
269 return $stack->SUPER::e_descr($partial) || $stack->ns_e_descr($partial);
270 }
271  
272 sub e_name {
273 my $stack = shift;
274 my $partial = shift;
275  
276 return $stack->SUPER::e_name($partial) || $stack->ns_e_name($partial);
277 }
278  
279 sub e_fwver {
280 my $stack = shift;
281 my $partial = shift;
282  
283 return $stack->SUPER::e_fwver($partial) || $stack->ns_e_fwver($partial);
284 }
285  
286 sub e_hwver {
287 my $stack = shift;
288 my $partial = shift;
289  
290 return $stack->SUPER::e_hwver($partial) || $stack->ns_e_hwver($partial);
291 }
292  
293 sub e_parent {
294 my $stack = shift;
295 my $partial = shift;
296  
297 return $stack->SUPER::e_parent($partial) || $stack->ns_e_parent($partial);
298 }
299  
300 sub e_pos {
301 my $stack = shift;
302 my $partial = shift;
303  
304 return $stack->SUPER::e_pos($partial) || $stack->ns_e_pos($partial);
305 }
306  
307 sub e_serial {
308 my $stack = shift;
309 my $partial = shift;
310  
311 return $stack->SUPER::e_serial($partial) || $stack->ns_e_serial($partial);
312 }
313  
314 sub e_swver {
315 my $stack = shift;
316 my $partial = shift;
317  
318 return $stack->SUPER::e_swver($partial) || $stack->ns_e_swver($partial);
319 }
320  
321 sub e_type {
322 my $stack = shift;
323 my $partial = shift;
324  
325 return $stack->SUPER::e_type($partial) || $stack->ns_e_type($partial);
326 }
327  
328 sub e_vendor {
329 my $stack = shift;
330 my $partial = shift;
331  
332 return $stack->SUPER::e_vendor($partial) || $stack->ns_e_vendor($partial);
333 }
334  
335 # fix for stack of switches without POE on module 1
336 # https://sourceforge.net/tracker/?func=detail&aid=3317739&group_id=70362&atid=527529
337 sub peth_port_ifindex {
338 my $stack = shift;
339 my $partial = shift;
340  
341 my %peth_port_ifindex = ();
342 my $poe_port_st = $stack->peth_port_status($partial);
343 my $if_index = $stack->interfaces($partial);
344  
345 foreach my $i (keys %$if_index) {
346 next unless defined $poe_port_st->{$if_index->{$i}};
347 $peth_port_ifindex{$if_index->{$i}} = $i;
348 }
349 return \%peth_port_ifindex;
350 }
351  
352 # Currently only ERS 4800 v5.8+ support the rcBridgeSpbmMacTable
353 # which holds the FDB for a SPBM edge deployment.
354 #
355 # Q-BRIDGE still holds some entries when the rcBridgeSpbmMacTable is in use
356 # so we merge hash entries.
357  
358 sub fw_mac {
359 my $rapidcity = shift;
360  
361 my $qb = $rapidcity->SUPER::fw_mac() || {};
362 my $spbm = $rapidcity->rc_spbm_fw_mac() || {};
363 my $fw_mac = { %$qb, %$spbm };
364  
365 return $fw_mac;
366 }
367  
368 sub fw_port {
369 my $rapidcity = shift;
370  
371 my $qb = $rapidcity->SUPER::fw_port() || {};
372 my $spbm = $rapidcity->rc_spbm_fw_port() || {};
373 my $fw_port = { %$qb, %$spbm };
374  
375 return $fw_port;
376 }
377  
378 sub fw_status {
379 my $rapidcity = shift;
380  
381 my $qb = $rapidcity->SUPER::fw_status() || {};
382 my $spbm = $rapidcity->rc_spbm_fw_status() || {};
383 my $fw_status = { %$qb, %$spbm };
384  
385 return $fw_status;
386 }
387  
388 sub qb_fw_vlan {
389 my $rapidcity = shift;
390  
391 my $qb = $rapidcity->SUPER::qb_fw_vlan() || {};
392 my $spbm = $rapidcity->rc_spbm_fw_vlan() || {};
393 my $qb_fw_vlan = { %$qb, %$spbm };
394  
395 return $qb_fw_vlan;
396 }
397  
398 # Baystack uses S5-AGENT-MIB (loaded in NortelStack) versus RAPID-CITY
399 sub stp_ver {
400 my $rapidcity = shift;
401  
402 return $rapidcity->s5AgSysSpanningTreeOperMode()
403 || $rapidcity->SUPER::stp_ver();
404 }
405  
406 1;
407  
408 __END__