Info/Layer3/ArubaCX.pm untested

filter: Statementstmt 0.0% 0 / 407 Branchbran 0.0% 0 / 152 Conditioncond 0.0% 0 / 255 MC/DCmcdc 0.0% 0 / 143 Subroutinesub 0.0% 0 / 72 Podpod 0.0% 0 / 64 totaltotal 0.0% 0 / 1093 CC 77 SCAR 31.9
CC
77
Cov
0%
_cipt_clients
132.0
_aoscx_stp_protocol
72.0
_munge_vsx_addr
42.0
CRAP 24.4
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.985005';
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 # The VSX system ID is a MAC in text; the keepalive peer is an InetAddress
142 # that AOS-CX can serve as text. Accept text or raw octets for both, and
143 # format a text address as its octets would be, so both forms compare equal
144 sub _munge_vsx_mac {
145 my $value = shift;
146 return unless defined $value;
147 if ( $value =~ /^[[:xdigit:]]{2}(?:[:-][[:xdigit:]]{2}){5}$/ ) {
148 ( my $mac = lc $value ) =~ tr/-/:/;
149 return $mac;
150 }
151 return SNMP::Info::munge_mac($value) if length $value == 6;
152 return;
153 }
154  
155 sub _munge_vsx_addr {
156 my $value = shift;
157 return unless defined $value and length $value;
158 my $octets = Socket::inet_pton( Socket::AF_INET(), $value )
159 // Socket::inet_pton( Socket::AF_INET6(), $value );
160 unless ( defined $octets ) {
161 return unless length $value == 4 or length $value == 16;
162 $octets = $value;
163 }
164 my $addr = SNMP::Info::munge_inetaddress($octets);
165 return unless defined $addr;
166 return if $addr =~ /^[0:.]+$/;
167 return $addr;
168 }
169  
170 # Product codes reported by ENTITY-MIB or the product OID.
171 %MODEL_MAP = ( 'JL719C' => '8360-48Y6C v2', );
172  
173 sub _at_pbb_one {
174 my $in = shift // {};
175 my $ret = {};
176 foreach my $key ( keys %$in ) {
177 if ( $key =~ /^1\.(\d+)$/ ) {
178 $ret->{$1} = $in->{$key};
179 }
180 }
181 return unless %$ret;
182 return $ret;
183 }
184  
185 sub fan {
186 my $cx = shift;
187 my $names = $cx->fan_names() || {};
188 my $states = $cx->fan_states() || {};
189 my @ary = ();
190 foreach my $idx ( sort keys %$names ) {
191 my $name = $names->{$idx} // 'n/a';
192 my $state = $states->{$idx} // 'n/a';
193 push @ary, sprintf( "%s: %s", $name, $state );
194 }
195 return join( ', ', @ary );
196 }
197  
198 sub vendor {
199 my $cx = shift;
200 my $mfg = $cx->entPhysicalMfgName(1) || {};
201 my $vendor = $mfg->{1} || "aruba";
202 return lc($vendor);
203 }
204  
205 sub mac {
206 my $cx = shift;
207 my $b_mac = $cx->b_mac();
208 return $b_mac if defined $b_mac and $b_mac !~ /^[0:]+$/;
209 return $cx->orig_mac();
210 }
211  
212 sub stack_info {
213 my $cx = shift;
214 my $vsf_topo = $cx->vsf_topology();
215 if ( defined $vsf_topo and $vsf_topo ne 'standalone' ) {
216 my $member_prod_names = $cx->vsf_prod_names() || {};
217 my $num_members = scalar keys %$member_prod_names;
218 my $fullname = ( values %$member_prod_names )[0];
219 my $modelname = '';
220 if ( $fullname =~ /^(\S+)/ ) {
221 $modelname = $1;
222 }
223 return sprintf( "%s (stack of %d)", $modelname, $num_members );
224 }
225 else {
226 return;
227 }
228 }
229  
230 sub model {
231 my $cx = shift;
232 my $model = $cx->entPhysicalModelName(1) || {};
233 my $id = $cx->id();
234 my $translated_id = &SNMP::translateObj($id) || $id;
235 $translated_id =~ s/arubaWiredSwitch//i;
236 my $name = $cx->stack_info() || $model->{1} || $translated_id;
237 return defined $MODEL_MAP{$name} ? $MODEL_MAP{$name} : $name;
238 }
239  
240 # Keep client tracking rows separate from the standard neighbour-table
241 # indexes.
242 # InetAddress is an OCTET STRING; check its length against the address type.
243 sub _cipt_clients {
244 my ( $cx, $family, $partial ) = @_;
245 my $types = $cx->cipt_addr_type() || {};
246 my $addrs = $cx->cipt_addr() || {};
247 my $ports = $cx->cipt_ifindex() || {};
248 my %clients;
249 foreach my $idx ( keys %$types ) {
250 my $type = $types->{$idx};
251 next unless defined $type;
252 next
253 unless ( $family == 1 && ( $type eq '1' || $type eq 'ipv4' ) )
254 || ( $family == 2 && ( $type eq '2' || $type eq 'ipv6' ) );
255 next unless $idx =~ /^6\.((?:\d+\.){5}\d+)\.(\d+)\.(\d+)$/;
256 my ( $mac_index, $vlan, $ip_index ) = ( $1, $2, $3 );
257 my @mac = split /\./, $mac_index;
258 next if grep { $_ > 255 } @mac;
259 next if ( $mac[0] & 1 ) || !grep {$_} @mac;
260 next unless $vlan >= 1 && $vlan <= 4094 && $ip_index > 0;
261 my $addr = $addrs->{$idx};
262 next
263 unless defined $addr
264 && length($addr) == ( $family == 1 ? 4 : 16 );
265 my $port = $ports->{$idx};
266 next unless defined $port && $port =~ /^\d+$/ && $port > 0;
267 my $row = "cipt.$idx";
268 next if defined $partial && $row !~ /^\Q$partial\E(?:\.|$)/;
269 $clients{$row} = {
270 mac => join( ':', map { sprintf '%02x', $_ } @mac ),
271 addr => SNMP::Info::munge_inetaddress($addr),
272 port => $port,
273 };
274 }
275 return \%clients;
276 }
277  
278 sub _cipt_merge {
279 my ( $cx, $base, $family, $field, $partial ) = @_;
280 my %result = %{ $base || {} };
281 my $clients = $cx->_cipt_clients( $family, $partial );
282 $result{$_} = $clients->{$_}{$field} for keys %$clients;
283 return \%result;
284 }
285  
286 sub at_paddr {
287 my ( $cx, $partial ) = @_;
288 return $cx->_cipt_merge( $cx->SUPER::at_paddr($partial), 1, 'mac',
289 $partial );
290 }
291  
292 sub at_netaddr {
293 my ( $cx, $partial ) = @_;
294 return $cx->_cipt_merge( $cx->SUPER::at_netaddr($partial),
295 1, 'addr', $partial );
296 }
297  
298 sub ipv6_n2p_mac {
299 my ( $cx, $partial ) = @_;
300 return $cx->_cipt_merge( $cx->SUPER::ipv6_n2p_mac(), 2, 'mac', $partial );
301 }
302  
303 sub ipv6_n2p_addr {
304 my ( $cx, $partial ) = @_;
305 return $cx->_cipt_merge( $cx->SUPER::ipv6_n2p_addr(), 2, 'addr',
306 $partial );
307 }
308  
309 sub ipv6_n2p_if {
310 my ( $cx, $partial ) = @_;
311 return $cx->_cipt_merge( $cx->SUPER::ipv6_n2p_if(), 2, 'port', $partial );
312 }
313  
314 # Transceivers are absent from ENTITY-MIB; add one module row per
315 # arubaWiredPmXcvrTable row, indexed above any real entPhysicalIndex.
316 my $XCVR_BASE = 1_000_000_000;
317  
318 sub _xcvr_entities {
319 my $cx = shift;
320 my $descr = $cx->pm_xcvr_descr() || {};
321 return {} unless %$descr;
322 my $real = $cx->SUPER::e_index() || {};
323 my $class = $cx->SUPER::e_class() || {};
324 my $name = $cx->SUPER::e_name() || {};
325 my $port = $cx->pm_xcvr_port() || {};
326 my $product = $cx->pm_xcvr_product() || {};
327 my $serial = $cx->pm_xcvr_serial() || {};
328 my $type = $cx->pm_xcvr_type() || {};
329 my ($chassis) = sort { $a <=> $b }
330 grep { ( $class->{$_} // '' ) eq 'chassis' } keys %$class;
331 my %port_entity = map { $name->{$_} => $_ }
332 grep { ( $class->{$_} // '' ) eq 'port' && defined $name->{$_} }
333 keys %$class;
334 my %rows;
335  
336 foreach my $ifindex ( grep {/^\d+$/} keys %$descr ) {
337 my $idx = $XCVR_BASE + $ifindex;
338 next if exists $real->{$idx};
339 my $port_name = $port->{$ifindex} // $ifindex;
340 $rows{$idx} = {
341 e_index => $idx,
342 e_class => 'module',
343 e_descr => $descr->{$ifindex},
344 e_name => "Transceiver $port_name",
345 e_model => $product->{$ifindex},
346 e_serial => $serial->{$ifindex},
347 e_type => $type->{$ifindex},
348 e_fru => 'true',
349 e_parent => $port_entity{$port_name} // $chassis // 0,
350 };
351 }
352 return \%rows;
353 }
354  
355 sub _xcvr_merge {
356 my ( $cx, $method, $partial ) = @_;
357 my $super = "SUPER::$method";
358 return $cx->$super($partial) if defined $partial;
359 my $rows = $cx->_xcvr_entities();
360 return $cx->$super() unless %$rows;
361 my $base = $cx->$super();
362 my %result = %{ $base || {} };
363 $result{$_} = $rows->{$_}{$method} for keys %$rows;
364 return \%result;
365 }
366  
367 sub e_index { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_index', $p ) }
368 sub e_class { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_class', $p ) }
369 sub e_descr { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_descr', $p ) }
370 sub e_name { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_name', $p ) }
371 sub e_model { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_model', $p ) }
372  
373 sub e_serial {
374 my ( $cx, $p ) = @_;
375 return $cx->_xcvr_merge( 'e_serial', $p );
376 }
377 sub e_type { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_type', $p ) }
378 sub e_fru { my ( $cx, $p ) = @_; return $cx->_xcvr_merge( 'e_fru', $p ) }
379  
380 sub e_parent {
381 my ( $cx, $p ) = @_;
382 return $cx->_xcvr_merge( 'e_parent', $p );
383 }
384  
385 sub os {
386 return "arubaos-cx";
387 }
388  
389 sub os_ver {
390 my $cx = shift;
391 my $ver_release = $cx->entPhysicalSoftwareRev(1) || {};
392 return $ver_release->{1};
393 }
394  
395 # agg_ports should return a hash with
396 # ifindex of member -> ifindex of aggregation
397 #
398 # arabuaos-cx has a broken implementation of
399 # dot3adAggPortListPorts / 1.2.840.10006.300.43.1.1.2.1.1
400 # it return a comma seperated String with interface names
401 # (rfc states a PortList / bitmask of member ports)
402 #
403 # fetch value, split at comma, reverse search the interface hash
404 # for the interface index
405  
406 sub agg_ports {
407 my $cx = shift;
408 my $ret = {};
409 my $ports = $cx->raw_ad_lag_ports();
410 my $interfaces = $cx->interfaces();
411 foreach my $m ( keys %$ports ) {
412 my $idx = $m;
413 my $portlist = $ports->{$m};
414 next unless $portlist;
415  
416 foreach my $ifname ( split( /,/, $portlist ) ) {
417 foreach my $ifindex ( keys %$interfaces ) {
418 if ( $interfaces->{$ifindex} eq $ifname ) {
419 $ret->{$ifindex} = $idx;
420 }
421 }
422 }
423 }
424 return $ret;
425 }
426  
427 sub _agg_ports_walked { return qw/raw_ad_lag_ports/ }
428  
429 # Overrides for VLAN & forwarding table methods
430 sub v_name {
431 my $cx = shift;
432 return _at_pbb_one( $cx->iqb_v_name() ) || $cx->SUPER::v_name();
433 }
434  
435 sub qb_i_vlan {
436 my $cx = shift;
437 return _at_pbb_one( $cx->iqb_i_vlan() ) || $cx->SUPER::qb_i_vlan();
438 }
439  
440 # AOS-CX serves PVID 0, which Q-BRIDGE-MIB forbids, on ports with no native
441 # VLAN in effect; leave those ports out, as for a port with no PVID row
442 sub i_vlan {
443 my ( $cx, $partial ) = @_;
444 my $i_vlan = $cx->SUPER::i_vlan($partial) or return;
445 my %native = map { $_ => $i_vlan->{$_} }
446 grep { ( $i_vlan->{$_} // '0' ) ne '0' } keys %$i_vlan;
447 return \%native;
448 }
449  
450 sub i_untagged { goto &i_vlan }
451  
452 sub i_vlan_type {
453 my $cx = shift;
454 return _at_pbb_one( $cx->iqb_i_vlan_type() )
455 || $cx->SUPER::qb_i_vlan_type();
456 }
457  
458 sub qb_v_egress {
459 my $cx = shift;
460 return $cx->iqb_v_egress() || $cx->SUPER::qb_v_egress();
461 }
462  
463 sub qb_cv_egress {
464 my $cx = shift;
465 return $cx->iqb_cv_egress() || $cx->SUPER::qb_cv_egress();
466 }
467  
468 sub qb_v_untagged {
469 my $cx = shift;
470 return $cx->iqb_v_untagged() || $cx->SUPER::qb_v_untagged();
471 }
472  
473 sub qb_cv_untagged {
474 my $cx = shift;
475 return $cx->iqb_cv_untagged() || $cx->SUPER::qb_cv_untagged();
476 }
477  
478 # AOS-CX 10.16 serves ieee8021SpanningTreeVersion 3 (mstp) in both of its
479 # modes. It reports CIST port role 6, outside the MIB's enum, on every port
480 # while running RPVST, and on link-down ports while running MSTP; it never
481 # reports a defined role under RPVST. So in the lowest component a defined
482 # role is MSTP, and role 6 on every row is RPVST when one of those ports is
483 # up. A switch that serves no CIST port role is read as BRIDGE-MIB alone
484 # (dot1d); any other case is unknown.
485 sub _aoscx_stp_protocol {
486 my $cx = shift;
487  
488 return $cx->{_aoscx_stp_protocol} if $cx->{_aoscx_stp_protocol};
489  
490 my $component = $cx->_ieee_stp_component();
491 return $cx->{_aoscx_stp_protocol} = 'dot1d' unless defined $component;
492 my $rows = $cx->mstp_cist_p_role() || {};
493 my %roles = map { ( split /\./ )[1] => $rows->{$_} }
494 grep { ( split /\./ )[0] == $component } keys %$rows;
495 return $cx->{_aoscx_stp_protocol} = 'dot1d' unless %roles;
496  
497 my @roles = values %roles;
498 my $protocol;
499 if ( grep { defined and /^(?:root|alternate|designated|backup)$/ }
500 @roles )
501 {
502 $protocol = 'mstp';
503 }
504 elsif ( @roles == grep { defined and $_ eq '6' } @roles ) {
505 $protocol = 'rapid-pvst'
506 if $cx->_aoscx_any_port_up( [ keys %roles ] );
507 }
508 return unless defined $protocol;
509 return $cx->{_aoscx_stp_protocol} = $protocol;
510 }
511  
512 # Whether any of these bridge ports maps to an ifIndex that is up, or to
513 # a link aggregation with a member that is up. AOS-CX 10.16 reports a link
514 # aggregation's ifOperStatus as down while its members are up.
515 sub _aoscx_any_port_up {
516 my ( $cx, $ports ) = @_;
517  
518 my $bp_index = $cx->bp_index() || {};
519 my $up = $cx->i_up() || {};
520 my $lag_of = $cx->agg_ports() || {};
521 my %iids = map { $_ => 1 } grep {defined} @{$bp_index}{@$ports};
522  
523 foreach my $iid ( keys %$up ) {
524 next unless ( $up->{$iid} // '' ) eq 'up';
525 my $lag = $lag_of->{$iid};
526 return 1 if $iids{$iid} or ( defined $lag and $iids{$lag} );
527 }
528 return 0;
529 }
530  
531 # MSTP is read from the IEEE MIBs, and dot1d from BRIDGE-MIB, both by the
532 # inherited methods
533 sub _aoscx_inherits_stp {
534 my $cx = shift;
535 my $protocol = $cx->_aoscx_stp_protocol() // '';
536 return $protocol eq 'mstp' || $protocol eq 'dot1d';
537 }
538  
539 sub _ieee_stp_protocol {
540 my $cx = shift;
541 return ( $cx->_aoscx_stp_protocol() || '' ) eq 'mstp' ? 'mstp' : undef;
542 }
543  
544 sub _ieee_stp_measured { return 1; }
545  
546 sub hasRapidPVST {
547 my $cx = shift;
548 return ( $cx->_aoscx_stp_protocol() || '' ) eq 'rapid-pvst' ? 1 : 0;
549 }
550  
551 sub stp_protocols {
552 my $cx = shift;
553  
554 return $cx->SUPER::stp_protocols() if $cx->_aoscx_inherits_stp();
555 my $protocol = $cx->_aoscx_stp_protocol();
556 return unless defined $protocol;
557 return $cx->_aoscx_rpvst_protocols();
558 }
559  
560 sub stp_trees {
561 my $cx = shift;
562  
563 return unless $cx->_stp_default_context_ok();
564 return $cx->SUPER::stp_trees() if $cx->_aoscx_inherits_stp();
565 my $protocol = $cx->_aoscx_stp_protocol();
566 return {} unless defined $protocol;
567 return $cx->_aoscx_rpvst_trees();
568 }
569  
570 sub stp_trees_complete {
571 my $cx = shift;
572  
573 return $cx->SUPER::stp_trees_complete() if $cx->_aoscx_inherits_stp();
574 my $protocol = $cx->_aoscx_stp_protocol();
575 return 0 unless defined $protocol;
576 return $cx->_aoscx_rpvst_trees_complete();
577 }
578  
579 sub stp_vlan_map {
580 my $cx = shift;
581  
582 return $cx->SUPER::stp_vlan_map() if $cx->_aoscx_inherits_stp();
583 my $protocol = $cx->_aoscx_stp_protocol();
584 return unless defined $protocol;
585 return $cx->_aoscx_rpvst_vlan_map();
586 }
587  
588 sub stp_tree_ports {
589 my ( $cx, $tree_key ) = @_;
590  
591 return $cx->SUPER::stp_tree_ports($tree_key)
592 if $cx->_aoscx_inherits_stp();
593 $cx->_stp_tree_for_key($tree_key) or return;
594 return $cx->_aoscx_rpvst_tree_ports($tree_key);
595 }
596  
597 # dot1dStpPortState keeps MSTP's last values while AOS-CX runs RPVST
598 sub i_stp_state {
599 my ( $cx, $partial ) = @_;
600  
601 return {} if ( $cx->_aoscx_stp_protocol() || '' ) eq 'rapid-pvst';
602 return $cx->SUPER::i_stp_state($partial);
603 }
604  
605 # RPVST keeps the operational edge flag per VLAN; the port's native VLAN is
606 # the row that describes the port
607 sub i_edgeport_oper {
608 my ( $cx, $partial ) = @_;
609  
610 return $cx->SUPER::i_edgeport_oper($partial)
611 if $cx->_aoscx_inherits_stp();
612 $cx->_aoscx_stp_protocol() or return {};
613  
614 my $native = $cx->i_vlan($partial) || {};
615 my $edge = $cx->rpvst_pv_edge_oper() || {};
616 my %i_edgeport;
617 foreach my $iid ( keys %$native ) {
618 next unless defined $native->{$iid};
619 my $enabled = SNMP::Info::Bridge::_stp_enabled(
620 $edge->{"$native->{$iid}.$iid"} );
621 $i_edgeport{$iid} = $enabled if defined $enabled;
622 }
623 return \%i_edgeport;
624 }
625  
626 # MAC part of this switch's CIST bridge ID, which RPVST also uses as the
627 # bridge MAC; on a VSX pair it is the VSX system MAC
628 sub _aoscx_bridge_mac {
629 my $cx = shift;
630  
631 my $component = $cx->_ieee_stp_component();
632 return unless defined $component;
633 my $id = ( $cx->mstp_cist_bridge() || {} )->{$component};
634 my $parts = SNMP::Info::Bridge::_stp_decode_bridge_id($id) or return;
635 return $parts->{mac};
636 }
637  
638 sub _aoscx_rpvst_protocols { return ['rapid-pvst']; }
639  
640 # One tree per RPVST-enabled VLAN. No 8-octet bridge ID is served, so IDs
641 # are built from parts; sys_id_ext is the VLAN only where the bridge is
642 # this switch and ExtendedSystemID is on.
643 sub _aoscx_rpvst_trees {
644 my $cx = shift;
645  
646 return $cx->{_stp_trees} if $cx->{_stp_trees};
647  
648 my $admin = $cx->rpvst_v_admin() || {};
649 my $priority = $cx->rpvst_v_priority() || {};
650 my $root_prio = $cx->rpvst_v_root_priority() || {};
651 my $root_mac = $cx->rpvst_v_root_mac() || {};
652 my $own_mac = $cx->_aoscx_bridge_mac();
653 my $ext_on = SNMP::Info::Bridge::_stp_enabled( $cx->rpvst_ext_sysid() );
654  
655 my %trees;
656 foreach my $vlan ( keys %$admin ) {
657 next unless SNMP::Info::Bridge::_stp_enabled( $admin->{$vlan} );
658 my $ext = $ext_on ? $vlan + 0 : undef;
659 my $root_is_own
660 = defined $own_mac
661 && defined $root_mac->{$vlan}
662 && $root_mac->{$vlan} eq $own_mac;
663 $trees{"vlan.$vlan"} = {
664 type => 'vlan',
665 id => $vlan + 0,
666 vlan => $vlan + 0,
667 protocol => 'rapid-pvst',
668 measured => 1,
669 ports_complete => 1,
670 contexts => [ { kind => 'none' } ],
671 bridge => scalar SNMP::Info::Bridge::_stp_bridge_id_parts(
672 $priority->{$vlan}, $ext, $own_mac
673 ),
674 root => scalar SNMP::Info::Bridge::_stp_bridge_id_parts(
675 $root_prio->{$vlan}, $root_is_own ? $ext : undef,
676 $root_mac->{$vlan}
677 ),
678 };
679 }
680 $cx->{_stp_trees} = \%trees if keys %trees;
681 return \%trees;
682 }
683  
684 sub _aoscx_rpvst_trees_complete {
685 my $cx = shift;
686  
687 my $trees = $cx->stp_trees() || {};
688 return 0 unless keys %$trees;
689 return 0 if $cx->_stp_walk_incomplete('rpvst_v_admin');
690 return 1;
691 }
692  
693 sub _aoscx_rpvst_vlan_map {
694 my $cx = shift;
695  
696 my $trees = $cx->stp_trees() || {};
697 return unless keys %$trees;
698 my %map = map { $_->{vlan} => "vlan.$_->{vlan}" } values %$trees;
699 return \%map;
700 }
701  
702 # Rows indexed <VLAN>.<ifIndex>; the designated bridge column serves only a
703 # MAC, so its priority comes from the root or this switch when it matches
704 sub _aoscx_rpvst_tree_ports {
705 my ( $cx, $tree_key ) = @_;
706  
707 my $tree = ( $cx->stp_trees() || {} )->{$tree_key} or return;
708 my $vlan = $tree->{vlan};
709 my $states = $cx->rpvst_pv_state() || {};
710 my $roles = $cx->rpvst_pv_role() || {};
711 my $d_bridge = $cx->rpvst_pv_bridge() || {};
712  
713 my %rows;
714 foreach my $index ( keys %{ +{ %$states, %$roles, %$d_bridge } } ) {
715 my ( $row_vlan, $iid ) = split /\./, $index, 2;
716 next unless $row_vlan == $vlan;
717 $rows{$iid} = {
718 tree_type => $tree->{type},
719 tree_id => $tree->{id},
720 state => $states->{$index},
721 role => scalar _aoscx_rpvst_known_role( $roles->{$index} ),
722 role_raw => $roles->{$index},
723 enabled => undef,
724 designated_bridge =>
725 scalar _aoscx_rpvst_designated( $tree, $d_bridge->{$index} ),
726 designated_port => undef,
727 };
728 }
729 return \%rows;
730 }
731  
732 sub _aoscx_rpvst_known_role {
733 my $role = shift;
734 return unless defined $role;
735 return $role
736 if $role =~ /^(?:root|alternate|designated|backup|master|disabled)$/;
737 return;
738 }
739  
740 # Priority and sys_id_ext from the root or this switch when the MAC is
741 # theirs, else undef
742 sub _aoscx_rpvst_designated {
743 my ( $tree, $mac ) = @_;
744 return unless defined $mac;
745  
746 foreach my $known ( $tree->{root}, $tree->{bridge} ) {
747 next unless $known and defined $known->{mac};
748 next unless $known->{mac} eq $mac;
749 return SNMP::Info::Bridge::_stp_bridge_id_parts( $known->{priority},
750 $known->{sys_id_ext}, $mac );
751 }
752 return SNMP::Info::Bridge::_stp_bridge_id_parts( undef, undef, $mac );
753 }
754  
755 # The ISL is served by interface name; "0" or empty means none is configured
756 sub _vsx_isl_ifindex {
757 my $cx = shift;
758 my $name = $cx->vsx_isl_port();
759 return unless defined $name and length $name and $name ne '0';
760 my $interfaces = $cx->interfaces() || {};
761 my ($ifindex) = grep { ( $interfaces->{$_} // '' ) eq $name }
762 sort { $a <=> $b } keys %$interfaces;
763 return $ifindex;
764 }
765  
766 # One VSX domain per switch, from scalars, as VOSS reports its virtual IST
767 sub _lag_vendor_domains {
768 my $cx = shift;
769  
770 my $role = $cx->vsx_role() // '';
771 my $peer_link = $cx->_vsx_isl_ifindex();
772 return {}
773 unless $role eq 'primary'
774 or $role eq 'secondary'
775 or defined $peer_link;
776  
777 my %value_of = (
778 system_mac => scalar $cx->vsx_system_mac(),
779 role => scalar $cx->vsx_role(),
780 peer => scalar $cx->vsx_keepalive_peer(),
781 status => scalar $cx->vsx_isl_state(),
782 peer_link => $peer_link,
783 );
784 my %leaf_of = (
785 system_mac => 'arubaWiredVsxDeviceOperSystemID',
786 role => 'arubaWiredVsxDeviceRole',
787 peer => 'arubaWiredVsxKeepAlivePeerIPAddr',
788 status => 'arubaWiredVsxIslOperState',
789 peer_link => 'arubaWiredVsxIslPort',
790 );
791 my $domain = { kind => 'vsx', sources => {} };
792 foreach my $field ( grep { defined $value_of{$_} } keys %value_of ) {
793 $domain->{$field} = $value_of{$field};
794 $domain->{sources}{$field} = "ARUBAWIRED-VSX-MIB::$leaf_of{$field}";
795 }
796 return { vsx => $domain };
797 }
798  
799 sub _lag_vendor_walked { return qw/vsx_agg_type/ }
800  
801 # Multi-chassis LAGs get mc only while the VSX domain is served, as VOSS
802 # does for split MLTs; a LAG the standard table does not list gets a record
803 sub _lag_vendor_groups {
804 my ( $cx, $groups ) = @_;
805  
806 return unless %{ $cx->_lag_vendor_domains() };
807 my $types = $cx->vsx_agg_type() || {};
808 my $interfaces = $cx->interfaces() || {};
809 foreach my $ifindex ( keys %$types ) {
810 next unless ( $types->{$ifindex} // '' ) eq 'multiChassis';
811 my $name = $interfaces->{$ifindex} // $ifindex;
812 my $record = $groups->{$ifindex}
813 ||= SNMP::Info::IEEE802dot3ad::_lag_new_record();
814 $record->{mc} = {
815 kind => 'vsx',
816 group => $name =~ /^lag(\d+)$/ ? $1 + 0 : $name,
817 domain => 'vsx',
818 state => undef,
819 };
820 $record->{sources}{mc}
821 = 'ARUBAWIRED-VSX-MIB::arubaWiredVsxAggregatorType';
822 }
823 my $isl = $cx->_vsx_isl_ifindex();
824 return unless defined $isl;
825 my $record = $groups->{$isl}
826 ||= SNMP::Info::IEEE802dot3ad::_lag_new_record();
827 $record->{peer_link} = 1;
828 $record->{sources}{peer_link}
829 = 'ARUBAWIRED-VSX-MIB::arubaWiredVsxIslPort';
830 return;
831 }
832  
833 1;
834 __END__