Info/Layer3/ArubaCX.pm untested

filter: Statementstmt 0.0% 0 / 416 Branchbran 0.0% 0 / 156 Conditioncond 0.0% 0 / 258 MC/DCmcdc 0.0% 0 / 145 Subroutinesub 0.0% 0 / 73 Podpod 0.0% 0 / 65 totaltotal 0.0% 0 / 1113 CC 79 SCAR 32.1
CC
79
Cov
0%
_cipt_clients
132.0
_aoscx_stp_protocol
72.0
_munge_vsx_addr
42.0
CRAP 24.7
1 # SNMP::Info::Layer3::ArubaCX
2 #
3 # Copyright (c) 2026 SNMP::Info Developers
4 # Copyright (c) 2021 Jeroen van Ingen
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are met:
9 #
10 # * Redistributions of source code must retain the above copyright notice,
11 # this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # * Neither the name of the University of California, Santa Cruz nor the
16 # names of its contributors may be used to endorse or promote products
17 # derived from this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 # POSSIBILITY OF SUCH DAMAGE.
30  
31 package SNMP::Info::Layer3::ArubaCX;
32  
33 use strict;
34 use warnings;
35 use Exporter;
36 use SNMP::Info::IEEE802dot3ad;
37 use SNMP::Info::IEEE802_STP;
38 use SNMP::Info::Layer3;
39 use SNMP::Info::IEEE802_Bridge;
40 use Socket ();
41  
42 @SNMP::Info::Layer3::ArubaCX::ISA = qw/
43 SNMP::Info::IEEE802dot3ad
44 SNMP::Info::IEEE802_STP
45 SNMP::Info::Layer3
46 SNMP::Info::IEEE802_Bridge
47 Exporter
48 /;
49 @SNMP::Info::Layer3::ArubaCX::EXPORT_OK = qw/
50 agg_ports
51 /;
52  
53 our ( $VERSION, %GLOBALS, %MIBS, %FUNCS, %MODEL_MAP, %MUNGE );
54  
55 $VERSION = '3.985007';
56  
57 %MIBS = (
58 %SNMP::Info::Layer3::MIBS,
59 %SNMP::Info::IEEE802_STP::MIBS,
60 %SNMP::Info::IEEE802dot3ad::MIBS,
61 %SNMP::Info::IEEE802_Bridge::MIBS,
62 'ARUBAWIRED-CIPT-MIB' => 'arubaWiredCiptClientIpAddress',
63 'ARUBAWIRED-FAN-MIB' => 'arubaWiredFanName',
64 'ARUBAWIRED-VSF-MIB' => 'arubaWiredVsfTrapEnable',
65 'ARUBAWIRED-POE-MIB' => 'arubaWiredPoePethPsePortAveragePower',
66 'ARUBAWIRED-POWERSUPPLY-MIB' => 'arubaWiredPSUName',
67 'ARUBAWIRED-PM-MIB' => 'arubaWiredPmXcvrDescription',
68 'ARUBAWIRED-RPVST-MIB' => 'arubaWiredRpvstExtendedSystemID',
69 'ARUBAWIRED-VSX-MIB' => 'arubaWiredVsxDeviceRole',
70 );
71  
72 %GLOBALS = (
73 %SNMP::Info::Layer3::GLOBALS,
74 %SNMP::Info::IEEE802_STP::GLOBALS,
75 %SNMP::Info::IEEE802_Bridge::GLOBALS,
76 'ps1_type' => 'arubaWiredPSUProductName.1.1',
77 'ps2_type' => 'arubaWiredPSUProductName.1.2',
78 'ps1_status' => 'arubaWiredPSUState.1.1',
79 'ps2_status' => 'arubaWiredPSUState.1.2',
80 'vsf_topology' => 'arubaWiredVsfTopology',
81 'rpvst_ext_sysid' => 'arubaWiredRpvstExtendedSystemID',
82  
83 # ARUBAWIRED-VSX-MIB
84 'vsx_role' => 'arubaWiredVsxDeviceRole',
85 'vsx_system_mac' => 'arubaWiredVsxDeviceOperSystemID',
86 'vsx_isl_port' => 'arubaWiredVsxIslPort',
87 'vsx_isl_state' => 'arubaWiredVsxIslOperState',
88 'vsx_keepalive_peer' => 'arubaWiredVsxKeepAlivePeerIPAddr',
89 'vsx_keepalive_state' => 'arubaWiredVsxKeepAliveOperState',
90 );
91  
92 %FUNCS = (
93 %SNMP::Info::Layer3::FUNCS,
94 %SNMP::Info::IEEE802_STP::FUNCS,
95 %SNMP::Info::IEEE802dot3ad::FUNCS,
96 %SNMP::Info::IEEE802_Bridge::FUNCS,
97 'peth_port_power' => 'arubaWiredPoePethPsePortAveragePower',
98 'fan_names' => 'arubaWiredFanName',
99 'fan_states' => 'arubaWiredFanState',
100 'psu_names' => 'arubaWiredPSUName',
101 'psu_types' => 'arubaWiredPSUProductName',
102 'psu_states' => 'arubaWiredPSUState',
103 'vsf_prod_names' => 'arubaWiredVsfMemberProductName',
104 'cipt_addr_type' => 'arubaWiredCiptClientIpAddrType',
105 'cipt_addr' => 'arubaWiredCiptClientIpAddress',
106 'cipt_ifindex' => 'arubaWiredCiptClientPortIfIndex',
107 'raw_ad_lag_ports' => 'dot3adAggPortListPorts', # unmunged raw data
108 'pm_xcvr_port' => 'arubaWiredPmXcvrPortDesc',
109 'pm_xcvr_descr' => 'arubaWiredPmXcvrDescription',
110 'pm_xcvr_product' => 'arubaWiredPmXcvrProductNum',
111 'pm_xcvr_serial' => 'arubaWiredPmXcvrSerialNum',
112 'pm_xcvr_type' => 'arubaWiredPmXcvrType',
113  
114 # ARUBAWIRED-RPVST-MIB::arubaWiredRpvstVlanTable
115 'rpvst_v_admin' => 'arubaWiredRpvstVlanRpvstAdminStatus',
116 'rpvst_v_priority' => 'arubaWiredRpvstVlanPriority',
117 'rpvst_v_root_priority' => 'arubaWiredRpvstVlanRootPriority',
118 'rpvst_v_root_mac' => 'arubaWiredRpvstVlanRootMacAddress',
119  
120 # ARUBAWIRED-RPVST-MIB::arubaWiredRpvstPortVlanTable
121 'rpvst_pv_state' => 'arubaWiredRpvstPortVlanState',
122 'rpvst_pv_role' => 'arubaWiredRpvstPortVlanRole',
123 'rpvst_pv_bridge' => 'arubaWiredRpvstPortVlanDesigBridge',
124 'rpvst_pv_edge_oper' => 'arubaWiredRpvstPortVlanOperEdge',
125  
126 # ARUBAWIRED-VSX-MIB::arubaWiredVsxAggregatorTable
127 'vsx_agg_type' => 'arubaWiredVsxAggregatorType',
128 );
129  
130 %MUNGE = (
131 %SNMP::Info::Layer3::MUNGE,
132 %SNMP::Info::IEEE802_STP::MUNGE,
133 %SNMP::Info::IEEE802dot3ad::MUNGE,
134 %SNMP::Info::IEEE802_Bridge::MUNGE,
135 'rpvst_v_root_mac' => \&SNMP::Info::munge_mac,
136 'rpvst_pv_bridge' => \&SNMP::Info::munge_mac,
137 'vsx_system_mac' => \&_munge_vsx_mac,
138 'vsx_keepalive_peer' => \&_munge_vsx_addr,
139 );
140  
141 # Cleans text as interfaces() cleans ifDescr: no control characters and no
142 # surrounding spaces
143 sub _vsx_text {
144 my $value = shift;
145 return unless defined $value;
146 ( my $text = $value ) =~ s/[[:cntrl:]]//g;
147 $text =~ s/^\s+|\s+$//g;
148 return $text;
149 }
150  
151 # The VSX system ID is a MAC in text; the keepalive peer is an InetAddress
152 # that AOS-CX can serve as text. Accept text or raw octets for both, and
153 # format a text address as its octets would be, so both forms compare equal
154 sub _munge_vsx_mac {
155 my $value = shift;
156 return unless defined $value;
157 my $text = _vsx_text($value);
158 if ( $text =~ /^[[:xdigit:]]{2}(?:[:-][[:xdigit:]]{2}){5}$/ ) {
159 ( my $mac = lc $text ) =~ tr/-/:/;
160 return $mac;
161 }
162 return SNMP::Info::munge_mac($value) if length $value == 6;
163 return;
164 }
165  
166 sub _munge_vsx_addr {
167 my $value = shift;
168 return unless defined $value and length $value;
169 my $text = _vsx_text($value);
170 my $octets = Socket::inet_pton( Socket::AF_INET(), $text )
171 // Socket::inet_pton( Socket::AF_INET6(), $text );
172 unless ( defined $octets ) {
173 return unless length $value == 4 or length $value == 16;
174 $octets = $value;
175 }
176 my $addr = SNMP::Info::munge_inetaddress($octets);
177 return unless defined $addr;
178 return if $addr =~ /^[0:.]+$/;
179 return $addr;
180 }
181  
182 # Product codes reported by ENTITY-MIB or the product OID.
183 # CX 6000/6100 names follow ARUBAWIRED-NETWORKING-OID descriptions.
184 %MODEL_MAP = (
185 'JL675A' => '6100 48G Class4 PoE 4SFP+ 370W',
186 'JL676A' => '6100 48G 4SFP+',
187 'JL677A' => '6100 24G Class4 PoE 4SFP+ 370W',
188 'JL678A' => '6100 24G 4SFP+',
189 'JL679A' => '6100 12G Class4 PoE 2G/2SFP+ 139W',
190 'JL719C' => '8360-48Y6C v2',
191 'R8N85A' => '6000 48G Class4 PoE 4SFP 370W',
192 'R8N85B' => '6000 48G Class4 PoE 4SFP 370W',
193 'R8N86A' => '6000 48G 4SFP',
194 'R8N86B' => '6000 48G 4SFP',
195 'R8N87A' => '6000 24G Class4 PoE 4SFP 370W',
196 'R8N87B' => '6000 24G Class4 PoE 4SFP 370W',
197 'R8N88A' => '6000 24G 4SFP',
198 'R8N88B' => '6000 24G 4SFP',
199 'R8N89A' => '6000 12G Class4 PoE 2G/2SFP 139W',
200 'R8N89B' => '6000 12G Class4 PoE 2G/2SFP 139W',
201 'R9Y03A' => '6000 48G Class4 PoE 4SFP 740W',
202 'R9Y03B' => '6000 48G Class4 PoE 4SFP 740W',
203 'R9Y04A' => '6100 48G Class4 PoE 4SFP+ 740W',
204 );
205  
206 sub _at_pbb_one {
207 my $in = shift // {};
208 my $ret = {};
209 foreach my $key ( keys %$in ) {
210 if ( $key =~ /^1\.(\d+)$/ ) {
211 $ret->{$1} = $in->{$key};
212 }
213 }
214 return unless %$ret;
215 return $ret;
216 }
217  
218 sub fan {
219 my $cx = shift;
220 my $names = $cx->fan_names() || {};
221 my $states = $cx->fan_states() || {};
222 my @ary = ();
223 foreach my $idx ( sort keys %$names ) {
224 my $name = $names->{$idx} // 'n/a';
225 my $state = $states->{$idx} // 'n/a';
226 push @ary, sprintf( "%s: %s", $name, $state );
227 }
228 return join( ', ', @ary );
229 }
230  
231 sub vendor {
232 my $cx = shift;
233 my $mfg = $cx->entPhysicalMfgName(1) || {};
234 my $vendor = $mfg->{1} || "aruba";
235 return lc($vendor);
236 }
237  
238 sub mac {
239 my $cx = shift;
240 my $b_mac = $cx->b_mac();
241 return $b_mac if defined $b_mac and $b_mac !~ /^[0:]+$/;
242 return $cx->orig_mac();
243 }
244  
245 sub stack_info {
246 my $cx = shift;
247 my $vsf_topo = $cx->vsf_topology();
248 if ( defined $vsf_topo and $vsf_topo ne 'standalone' ) {
249 my $member_prod_names = $cx->vsf_prod_names() || {};
250 my $num_members = scalar keys %$member_prod_names;
251 my $fullname = ( values %$member_prod_names )[0];
252 my $modelname = '';
253 if ( $fullname =~ /^(\S+)/ ) {
254 $modelname = $1;
255 }
256 return sprintf( "%s (stack of %d)", $modelname, $num_members );
257 }
258 else {
259 return;
260 }
261 }
262  
263 sub model {
264 my $cx = shift;
265 my $model = $cx->entPhysicalModelName(1) || {};
266 my $id = $cx->id();
267 my $translated_id = &SNMP::translateObj($id) || $id;
268 $translated_id =~ s/arubaWiredSwitch//i;
269 my $name = $cx->stack_info() || $model->{1} || $translated_id;
270 return defined $MODEL_MAP{$name} ? $MODEL_MAP{$name} : $name;
271 }
272  
273 # Keep client tracking rows separate from the standard neighbour-table
274 # indexes.
275 # InetAddress is an OCTET STRING; check its length against the address type.
276 sub _cipt_clients {
277 my ( $cx, $family, $partial ) = @_;
278 my $types = $cx->cipt_addr_type() || {};
279 my $addrs = $cx->cipt_addr() || {};
280 my $ports = $cx->cipt_ifindex() || {};
281 my %clients;
282 foreach my $idx ( keys %$types ) {
283 my $type = $types->{$idx};
284 next unless defined $type;
285 next
286 unless ( $family == 1 && ( $type eq '1' || $type eq 'ipv4' ) )
287 || ( $family == 2 && ( $type eq '2' || $type eq 'ipv6' ) );
288 next unless $idx =~ /^6\.((?:\d+\.){5}\d+)\.(\d+)\.(\d+)$/;
289 my ( $mac_index, $vlan, $ip_index ) = ( $1, $2, $3 );
290 my @mac = split /\./, $mac_index;
291 next if grep { $_ > 255 } @mac;
292 next if ( $mac[0] & 1 ) || !grep {$_} @mac;
293 next unless $vlan >= 1 && $vlan <= 4094 && $ip_index > 0;
294 my $addr = $addrs->{$idx};
295 next
296 unless defined $addr
297 && length($addr) == ( $family == 1 ? 4 : 16 );
298 my $port = $ports->{$idx};
299 next unless defined $port && $port =~ /^\d+$/ && $port > 0;
300 my $row = "cipt.$idx";
301 next if defined $partial && $row !~ /^\Q$partial\E(?:\.|$)/;
302 $clients{$row} = {
303 mac => join( ':', map { sprintf '%02x', $_ } @mac ),
304 addr => SNMP::Info::munge_inetaddress($addr),
305 port => $port,
306 };
307 }
308 return \%clients;
309 }
310  
311 sub _cipt_merge {
312 my ( $cx, $base, $family, $field, $partial ) = @_;
313 my %result = %{ $base || {} };
314 my $clients = $cx->_cipt_clients( $family, $partial );
315 $result{$_} = $clients->{$_}{$field} for keys %$clients;
316 return \%result;
317 }
318  
319 sub at_paddr {
320 my ( $cx, $partial ) = @_;
321 return $cx->_cipt_merge( $cx->SUPER::at_paddr($partial), 1, 'mac',
322 $partial );
323 }
324  
325 sub at_netaddr {
326 my ( $cx, $partial ) = @_;
327 return $cx->_cipt_merge( $cx->SUPER::at_netaddr($partial),
328 1, 'addr', $partial );
329 }
330  
331 sub ipv6_n2p_mac {
332 my ( $cx, $partial ) = @_;
333 return $cx->_cipt_merge( $cx->SUPER::ipv6_n2p_mac(), 2, 'mac', $partial );
334 }
335  
336 sub ipv6_n2p_addr {
337 my ( $cx, $partial ) = @_;
338 return $cx->_cipt_merge( $cx->SUPER::ipv6_n2p_addr(), 2, 'addr',
339 $partial );
340 }
341  
342 sub ipv6_n2p_if {
343 my ( $cx, $partial ) = @_;
344 return $cx->_cipt_merge( $cx->SUPER::ipv6_n2p_if(), 2, 'port', $partial );
345 }
346  
347 # Transceivers are absent from ENTITY-MIB; add one module row per
348 # arubaWiredPmXcvrTable row, indexed above any real entPhysicalIndex.
349 my $XCVR_BASE = 1_000_000_000;
350  
351 sub _xcvr_entities {
352 my $cx = shift;
353 my $descr = $cx->pm_xcvr_descr() || {};
354 return {} unless %$descr;
355 my $real = $cx->SUPER::e_index() || {};
356 my $class = $cx->SUPER::e_class() || {};
357 my $name = $cx->SUPER::e_name() || {};
358 my $port = $cx->pm_xcvr_port() || {};
359 my $product = $cx->pm_xcvr_product() || {};
360 my $serial = $cx->pm_xcvr_serial() || {};
361 my $type = $cx->pm_xcvr_type() || {};
362 my ($chassis) = sort { $a <=> $b }
363 grep { ( $class->{$_} // '' ) eq 'chassis' } keys %$class;
364 my %port_entity = map { $name->{$_} => $_ }
365 grep { ( $class->{$_} // '' ) eq 'port' && defined $name->{$_} }
366 keys %$class;
367 my %rows;
368  
369 foreach my $ifindex ( grep {/^\d+$/} keys %$descr ) {
370 my $idx = $XCVR_BASE + $ifindex;
371 next if exists $real->{$idx};
372 my $port_name = $port->{$ifindex} // $ifindex;
373 $rows{$idx} = {
374 e_index => $idx,
375 e_class => 'module',
376 e_descr => $descr->{$ifindex},
377 e_name => "Transceiver $port_name",
378 e_model => $product->{$ifindex},
379 e_serial => $serial->{$ifindex},
380 e_type => $type->{$ifindex},
381 e_fru => 'true',
382 e_parent => $port_entity{$port_name} // $chassis // 0,
383 };
384 }
385 return \%rows;
386 }
387  
388 sub _xcvr_merge {
389 my ( $cx, $method, $partial ) = @_;
390 my $super = "SUPER::$method";
391 return $cx->$super($partial) if defined $partial;
392 my $rows = $cx->_xcvr_entities();
393 return $cx->$super() unless %$rows;
394 my $base = $cx->$super();
395 my %result = %{ $base || {} };
396 $result{$_} = $rows->{$_}{$method} for keys %$rows;
397 return \%result;
398 }
399  
400 sub e_index { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_index', $p ) }
401 sub e_class { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_class', $p ) }
402 sub e_descr { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_descr', $p ) }
403 sub e_name { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_name', $p ) }
404 sub e_model { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_model', $p ) }
405  
406 sub e_serial {
407 my ( $cx, $p ) = @_;
408 return $cx->_xcvr_merge( 'e_serial', $p );
409 }
410 sub e_type { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_type', $p ) }
411 sub e_fru { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_fru', $p ) }
412  
413 sub e_parent {
414 my ( $cx, $p ) = @_;
415 return $cx->_xcvr_merge( 'e_parent', $p );
416 }
417  
418 sub os {
419 return "arubaos-cx";
420 }
421  
422 sub os_ver {
423 my $cx = shift;
424 my $ver_release = $cx->entPhysicalSoftwareRev(1) || {};
425 return $ver_release->{1};
426 }
427  
428 # agg_ports should return a hash with
429 # ifindex of member -> ifindex of aggregation
430 #
431 # arabuaos-cx has a broken implementation of
432 # dot3adAggPortListPorts / 1.2.840.10006.300.43.1.1.2.1.1
433 # it return a comma seperated String with interface names
434 # (rfc states a PortList / bitmask of member ports)
435 #
436 # fetch value, split at comma, reverse search the interface hash
437 # for the interface index
438  
439 sub agg_ports {
440 my $cx = shift;
441 my $ret = {};
442 my $ports = $cx->raw_ad_lag_ports();
443 my $interfaces = $cx->interfaces();
444 foreach my $m ( keys %$ports ) {
445 my $idx = $m;
446 my $portlist = $ports->{$m};
447 next unless $portlist;
448  
449 foreach my $ifname ( split( /,/, $portlist ) ) {
450 foreach my $ifindex ( keys %$interfaces ) {
451 if ( $interfaces->{$ifindex} eq $ifname ) {
452 $ret->{$ifindex} = $idx;
453 }
454 }
455 }
456 }
457 return $ret;
458 }
459  
460 sub _agg_ports_walked { return qw/raw_ad_lag_ports/ }
461  
462 # Overrides for VLAN & forwarding table methods
463 sub v_name {
464 my $cx = shift;
465 return _at_pbb_one( $cx->iqb_v_name() ) || $cx->SUPER::v_name();
466 }
467  
468 sub qb_i_vlan {
469 my $cx = shift;
470 return _at_pbb_one( $cx->iqb_i_vlan() ) || $cx->SUPER::qb_i_vlan();
471 }
472  
473 # AOS-CX serves PVID 0, which Q-BRIDGE-MIB forbids, on ports with no native
474 # VLAN in effect; leave those ports out, as for a port with no PVID row
475 sub i_vlan {
476 my ( $cx, $partial ) = @_;
477 my $i_vlan = $cx->SUPER::i_vlan($partial) or return;
478 my %native = map { $_ => $i_vlan->{$_} }
479 grep { ( $i_vlan->{$_} // '0' ) ne '0' } keys %$i_vlan;
480 return \%native;
481 }
482  
483 sub i_untagged { goto &i_vlan }
484  
485 sub i_vlan_type {
486 my $cx = shift;
487 return _at_pbb_one( $cx->iqb_i_vlan_type() )
488 || $cx->SUPER::qb_i_vlan_type();
489 }
490  
491 sub qb_v_egress {
492 my $cx = shift;
493 return $cx->iqb_v_egress() || $cx->SUPER::qb_v_egress();
494 }
495  
496 sub qb_cv_egress {
497 my $cx = shift;
498 return $cx->iqb_cv_egress() || $cx->SUPER::qb_cv_egress();
499 }
500  
501 sub qb_v_untagged {
502 my $cx = shift;
503 return $cx->iqb_v_untagged() || $cx->SUPER::qb_v_untagged();
504 }
505  
506 sub qb_cv_untagged {
507 my $cx = shift;
508 return $cx->iqb_cv_untagged() || $cx->SUPER::qb_cv_untagged();
509 }
510  
511 # AOS-CX 10.16 serves ieee8021SpanningTreeVersion 3 (mstp) in both of its
512 # modes. It reports CIST port role 6, outside the MIB's enum, on every port
513 # while running RPVST, and on link-down ports while running MSTP; it never
514 # reports a defined role under RPVST. So in the lowest component a defined
515 # role is MSTP, and role 6 on every row is RPVST when one of those ports is
516 # up. A switch that serves no CIST port role is read as BRIDGE-MIB alone
517 # (dot1d); any other case is unknown.
518 sub _aoscx_stp_protocol {
519 my $cx = shift;
520  
521 return $cx->{_aoscx_stp_protocol} if $cx->{_aoscx_stp_protocol};
522  
523 my $component = $cx->_ieee_stp_component();
524 return $cx->{_aoscx_stp_protocol} = 'dot1d' unless defined $component;
525 my $rows = $cx->mstp_cist_p_role() || {};
526 my %roles = map { ( split /\./ )[1] => $rows->{$_} }
527 grep { ( split /\./ )[0] == $component } keys %$rows;
528 return $cx->{_aoscx_stp_protocol} = 'dot1d' unless %roles;
529  
530 my @roles = values %roles;
531 my $protocol;
532 if ( grep { defined and /^(?:root|alternate|designated|backup)$/ }
533 @roles )
534 {
535 $protocol = 'mstp';
536 }
537 elsif ( @roles == grep { defined and $_ eq '6' } @roles ) {
538 $protocol = 'rapid-pvst'
539 if $cx->_aoscx_any_port_up( [ keys %roles ] );
540 }
541 return unless defined $protocol;
542 return $cx->{_aoscx_stp_protocol} = $protocol;
543 }
544  
545 # Whether any of these bridge ports maps to an ifIndex that is up, or to
546 # a link aggregation with a member that is up. AOS-CX 10.16 reports a link
547 # aggregation's ifOperStatus as down while its members are up.
548 sub _aoscx_any_port_up {
549 my ( $cx, $ports ) = @_;
550  
551 my $bp_index = $cx->bp_index() || {};
552 my $up = $cx->i_up() || {};
553 my $lag_of = $cx->agg_ports() || {};
554 my %iids = map { $_ => 1 } grep {defined} @{$bp_index}{@$ports};
555  
556 foreach my $iid ( keys %$up ) {
557 next unless ( $up->{$iid} // '' ) eq 'up';
558 my $lag = $lag_of->{$iid};
559 return 1 if $iids{$iid} or ( defined $lag and $iids{$lag} );
560 }
561 return 0;
562 }
563  
564 # MSTP is read from the IEEE MIBs, and dot1d from BRIDGE-MIB, both by the
565 # inherited methods
566 sub _aoscx_inherits_stp {
567 my $cx = shift;
568 my $protocol = $cx->_aoscx_stp_protocol() // '';
569 return $protocol eq 'mstp' || $protocol eq 'dot1d';
570 }
571  
572 sub _ieee_stp_protocol {
573 my $cx = shift;
574 return ( $cx->_aoscx_stp_protocol() || '' ) eq 'mstp' ? 'mstp' : undef;
575 }
576  
577 sub _ieee_stp_measured { return 1; }
578  
579 sub hasRapidPVST {
580 my $cx = shift;
581 return ( $cx->_aoscx_stp_protocol() || '' ) eq 'rapid-pvst' ? 1 : 0;
582 }
583  
584 sub stp_protocols {
585 my $cx = shift;
586  
587 return $cx->SUPER::stp_protocols() if $cx->_aoscx_inherits_stp();
588 my $protocol = $cx->_aoscx_stp_protocol();
589 return unless defined $protocol;
590 return $cx->_aoscx_rpvst_protocols();
591 }
592  
593 sub stp_trees {
594 my $cx = shift;
595  
596 return unless $cx->_stp_default_context_ok();
597 return $cx->SUPER::stp_trees() if $cx->_aoscx_inherits_stp();
598 my $protocol = $cx->_aoscx_stp_protocol();
599 return {} unless defined $protocol;
600 return $cx->_aoscx_rpvst_trees();
601 }
602  
603 sub stp_trees_complete {
604 my $cx = shift;
605  
606 return $cx->SUPER::stp_trees_complete() if $cx->_aoscx_inherits_stp();
607 my $protocol = $cx->_aoscx_stp_protocol();
608 return 0 unless defined $protocol;
609 return $cx->_aoscx_rpvst_trees_complete();
610 }
611  
612 sub stp_vlan_map {
613 my $cx = shift;
614  
615 return $cx->SUPER::stp_vlan_map() if $cx->_aoscx_inherits_stp();
616 my $protocol = $cx->_aoscx_stp_protocol();
617 return unless defined $protocol;
618 return $cx->_aoscx_rpvst_vlan_map();
619 }
620  
621 sub stp_tree_ports {
622 my ( $cx, $tree_key ) = @_;
623  
624 return $cx->SUPER::stp_tree_ports($tree_key)
625 if $cx->_aoscx_inherits_stp();
626 $cx->_stp_tree_for_key($tree_key) or return;
627 return $cx->_aoscx_rpvst_tree_ports($tree_key);
628 }
629  
630 # dot1dStpPortState keeps MSTP's last values while AOS-CX runs RPVST
631 sub i_stp_state {
632 my ( $cx, $partial ) = @_;
633  
634 return {} if ( $cx->_aoscx_stp_protocol() || '' ) eq 'rapid-pvst';
635 return $cx->SUPER::i_stp_state($partial);
636 }
637  
638 # RPVST keeps the operational edge flag per VLAN; the port's native VLAN is
639 # the row that describes the port
640 sub i_edgeport_oper {
641 my ( $cx, $partial ) = @_;
642  
643 return $cx->SUPER::i_edgeport_oper($partial)
644 if $cx->_aoscx_inherits_stp();
645 $cx->_aoscx_stp_protocol() or return {};
646  
647 my $native = $cx->i_vlan($partial) || {};
648 my $edge = $cx->rpvst_pv_edge_oper() || {};
649 my %i_edgeport;
650 foreach my $iid ( keys %$native ) {
651 next unless defined $native->{$iid};
652 my $enabled = SNMP::Info::Bridge::_stp_enabled(
653 $edge->{"$native->{$iid}.$iid"} );
654 $i_edgeport{$iid} = $enabled if defined $enabled;
655 }
656 return \%i_edgeport;
657 }
658  
659 # MAC part of this switch's CIST bridge ID, which RPVST also uses as the
660 # bridge MAC; on a VSX pair it is the VSX system MAC
661 sub _aoscx_bridge_mac {
662 my $cx = shift;
663  
664 my $component = $cx->_ieee_stp_component();
665 return unless defined $component;
666 my $id = ( $cx->mstp_cist_bridge() || {} )->{$component};
667 my $parts = SNMP::Info::Bridge::_stp_decode_bridge_id($id) or return;
668 return $parts->{mac};
669 }
670  
671 sub _aoscx_rpvst_protocols { return ['rapid-pvst']; }
672  
673 # One tree per RPVST-enabled VLAN. No 8-octet bridge ID is served, so IDs
674 # are built from parts; sys_id_ext is the VLAN only where the bridge is
675 # this switch and ExtendedSystemID is on.
676 sub _aoscx_rpvst_trees {
677 my $cx = shift;
678  
679 return $cx->{_stp_trees} if $cx->{_stp_trees};
680  
681 my $admin = $cx->rpvst_v_admin() || {};
682 my $priority = $cx->rpvst_v_priority() || {};
683 my $root_prio = $cx->rpvst_v_root_priority() || {};
684 my $root_mac = $cx->rpvst_v_root_mac() || {};
685 my $own_mac = $cx->_aoscx_bridge_mac();
686 my $ext_on = SNMP::Info::Bridge::_stp_enabled( $cx->rpvst_ext_sysid() );
687  
688 my %trees;
689 foreach my $vlan ( keys %$admin ) {
690 next unless SNMP::Info::Bridge::_stp_enabled( $admin->{$vlan} );
691 my $ext = $ext_on ? $vlan + 0 : undef;
692 my $root_is_own
693 = defined $own_mac
694 && defined $root_mac->{$vlan}
695 && $root_mac->{$vlan} eq $own_mac;
696 $trees{"vlan.$vlan"} = {
697 type => 'vlan',
698 id => $vlan + 0,
699 vlan => $vlan + 0,
700 protocol => 'rapid-pvst',
701 measured => 1,
702 ports_complete => 1,
703 contexts => [ { kind => 'none' } ],
704 bridge => scalar SNMP::Info::Bridge::_stp_bridge_id_parts(
705 $priority->{$vlan}, $ext, $own_mac
706 ),
707 root => scalar SNMP::Info::Bridge::_stp_bridge_id_parts(
708 $root_prio->{$vlan}, $root_is_own ? $ext : undef,
709 $root_mac->{$vlan}
710 ),
711 };
712 }
713 $cx->{_stp_trees} = \%trees if keys %trees;
714 return \%trees;
715 }
716  
717 sub _aoscx_rpvst_trees_complete {
718 my $cx = shift;
719  
720 my $trees = $cx->stp_trees() || {};
721 return 0 unless keys %$trees;
722 return 0 if $cx->_stp_walk_incomplete('rpvst_v_admin');
723 return 1;
724 }
725  
726 sub _aoscx_rpvst_vlan_map {
727 my $cx = shift;
728  
729 my $trees = $cx->stp_trees() || {};
730 return unless keys %$trees;
731 my %map = map { $_->{vlan} => "vlan.$_->{vlan}" } values %$trees;
732 return \%map;
733 }
734  
735 # Rows indexed <VLAN>.<ifIndex>; the designated bridge column serves only a
736 # MAC, so its priority comes from the root or this switch when it matches
737 sub _aoscx_rpvst_tree_ports {
738 my ( $cx, $tree_key ) = @_;
739  
740 my $tree = ( $cx->stp_trees() || {} )->{$tree_key} or return;
741 my $vlan = $tree->{vlan};
742 my $states = $cx->rpvst_pv_state() || {};
743 my $roles = $cx->rpvst_pv_role() || {};
744 my $d_bridge = $cx->rpvst_pv_bridge() || {};
745  
746 my %rows;
747 foreach my $index ( keys %{ +{ %$states, %$roles, %$d_bridge } } ) {
748 my ( $row_vlan, $iid ) = split /\./, $index, 2;
749 next unless $row_vlan == $vlan;
750 $rows{$iid} = {
751 tree_type => $tree->{type},
752 tree_id => $tree->{id},
753 state => $states->{$index},
754 role => scalar _aoscx_rpvst_known_role( $roles->{$index} ),
755 role_raw => $roles->{$index},
756 enabled => undef,
757 designated_bridge =>
758 scalar _aoscx_rpvst_designated( $tree, $d_bridge->{$index} ),
759 designated_port => undef,
760 };
761 }
762 return \%rows;
763 }
764  
765 sub _aoscx_rpvst_known_role {
766 my $role = shift;
767 return unless defined $role;
768 return $role
769 if $role =~ /^(?:root|alternate|designated|backup|master|disabled)$/;
770 return;
771 }
772  
773 # Priority and sys_id_ext from the root or this switch when the MAC is
774 # theirs, else undef
775 sub _aoscx_rpvst_designated {
776 my ( $tree, $mac ) = @_;
777 return unless defined $mac;
778  
779 foreach my $known ( $tree->{root}, $tree->{bridge} ) {
780 next unless $known and defined $known->{mac};
781 next unless $known->{mac} eq $mac;
782 return SNMP::Info::Bridge::_stp_bridge_id_parts( $known->{priority},
783 $known->{sys_id_ext}, $mac );
784 }
785 return SNMP::Info::Bridge::_stp_bridge_id_parts( undef, undef, $mac );
786 }
787  
788 # The ISL is served by interface name; "0" or empty means none is
789 # configured. interfaces() suffixes a repeated ifDescr with its ifIndex, so
790 # a name two interfaces share matches neither
791 sub _vsx_isl_ifindex {
792 my $cx = shift;
793 my $name = _vsx_text( scalar $cx->vsx_isl_port() );
794 return unless defined $name and length $name and $name ne '0';
795 my $interfaces = $cx->interfaces() || {};
796 my ($ifindex) = grep { ( $interfaces->{$_} // '' ) eq $name }
797 sort { $a <=> $b } keys %$interfaces;
798 return $ifindex;
799 }
800  
801 # One VSX domain per switch, from scalars, as VOSS reports its virtual IST
802 sub _lag_vendor_domains {
803 my $cx = shift;
804  
805 my $role = $cx->vsx_role() // '';
806 my $peer_link = $cx->_vsx_isl_ifindex();
807 return {}
808 unless $role eq 'primary'
809 or $role eq 'secondary'
810 or defined $peer_link;
811  
812 my %value_of = (
813 system_mac => scalar $cx->vsx_system_mac(),
814 role => scalar $cx->vsx_role(),
815 peer => scalar $cx->vsx_keepalive_peer(),
816 status => scalar $cx->vsx_isl_state(),
817 peer_link => $peer_link,
818 );
819 my %leaf_of = (
820 system_mac => 'arubaWiredVsxDeviceOperSystemID',
821 role => 'arubaWiredVsxDeviceRole',
822 peer => 'arubaWiredVsxKeepAlivePeerIPAddr',
823 status => 'arubaWiredVsxIslOperState',
824 peer_link => 'arubaWiredVsxIslPort',
825 );
826 my $domain = { kind => 'vsx', sources => {} };
827 foreach my $field ( grep { defined $value_of{$_} } keys %value_of ) {
828 $domain->{$field} = $value_of{$field};
829 $domain->{sources}{$field} = "ARUBAWIRED-VSX-MIB::$leaf_of{$field}";
830 }
831 return { vsx => $domain };
832 }
833  
834 sub _lag_vendor_walked { return qw/vsx_agg_type/ }
835  
836 # Multi-chassis LAGs get mc only while the VSX domain is served, as VOSS
837 # does for split MLTs; a LAG the standard table does not list gets a record
838 sub _lag_vendor_groups {
839 my ( $cx, $groups ) = @_;
840  
841 return unless %{ $cx->_lag_vendor_domains() };
842 my $types = $cx->vsx_agg_type() || {};
843 my $interfaces = $cx->interfaces() || {};
844 my $isl = $cx->_vsx_isl_ifindex();
845 foreach my $ifindex ( keys %$types ) {
846 next unless ( $types->{$ifindex} // '' ) eq 'multiChassis';
847 next if defined $isl and $ifindex == $isl;
848 my $name = $interfaces->{$ifindex} // $ifindex;
849 my $record = $groups->{$ifindex}
850 ||= SNMP::Info::IEEE802dot3ad::_lag_new_record();
851 $record->{mc} = {
852 kind => 'vsx',
853 group => $name =~ /^lag(\d+)$/ ? $1 + 0 : $name,
854 domain => 'vsx',
855 state => undef,
856 };
857 $record->{sources}{mc}
858 = 'ARUBAWIRED-VSX-MIB::arubaWiredVsxAggregatorType';
859 }
860 return unless defined $isl;
861 my $record = $groups->{$isl}
862 ||= SNMP::Info::IEEE802dot3ad::_lag_new_record();
863 $record->{peer_link} = 1;
864 $record->{sources}{peer_link}
865 = 'ARUBAWIRED-VSX-MIB::arubaWiredVsxIslPort';
866 return;
867 }
868  
869 1;
870 __END__