Info/Layer3/Arista.pm untested

filter: Statementstmt 0.0% 0 / 98 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 17 totaltotal 0.0% 0 / 225 CC 12 SCAR 21.5
CC
12
Cov
0%
_vrf_vendor_instances
30.0
os_ver
12.0
_snmp_context
12.0
CRAP 8.6
1 # SNMP::Info::Layer3::Arista
2 #
3 # Copyright (c) 2008 Arista Networks, Inc.
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 Arista Networks, Inc. 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::Arista;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer3;
36 use SNMP::Info::MAU;
37 use SNMP::Info::Aggregate 'agg_ports_ifstack';
38  
39 @SNMP::Info::Layer3::Arista::ISA = qw/
40 SNMP::Info::Aggregate
41 SNMP::Info::MAU
42 SNMP::Info::Layer3
43 Exporter
44 /;
45 @SNMP::Info::Layer3::Arista::EXPORT_OK = qw//;
46  
47 our ($VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE);
48  
49 $VERSION = '3.985003';
50  
51 %MIBS = (
52 %SNMP::Info::Layer3::MIBS,
53 %SNMP::Info::MAU::MIBS,
54 %SNMP::Info::Aggregate::MIBS,
55 'ARISTA-PRODUCTS-MIB' => 'aristaDCS7124S',
56 'ARISTA-VRF-MIB' => 'aristaVrfState',
57 );
58  
59 %GLOBALS = (
60 %SNMP::Info::Layer3::GLOBALS,
61 %SNMP::Info::MAU::GLOBALS,
62 );
63  
64 %FUNCS = (
65 %SNMP::Info::Layer3::FUNCS,
66 %SNMP::Info::MAU::FUNCS,
67  
68 # ARISTA-VRF-MIB::aristaVrfTable and aristaVrfIfTable
69 'vrf_arista_rd' => 'aristaVrfRouteDistinguisher',
70 'vrf_arista_state' => 'aristaVrfState',
71 'vrf_arista_if' => 'aristaVrfIfMembership',
72 );
73  
74 %MUNGE = (
75 %SNMP::Info::Layer3::MUNGE,
76 %SNMP::Info::MAU::MUNGE,
77 );
78  
79 # use MAU-MIB for admin. duplex and admin. speed
80 *SNMP::Info::Layer3::Arista::i_duplex_admin
81 = \&SNMP::Info::MAU::mau_i_duplex_admin;
82 *SNMP::Info::Layer3::Arista::i_speed_admin
83 = \&SNMP::Info::MAU::mau_i_speed_admin;
84  
85 sub vendor {
86 return 'arista';
87 }
88  
89 sub os {
90 return 'EOS';
91 }
92  
93 sub os_ver {
94 my $arista = shift;
95 my $descr = $arista->description();
96  
97 if (defined ($descr)) {
98 my $os_ver = undef;
99 $os_ver = $1 if ($descr =~ /\s+EOS\s+version\s+(\S+)\s+/);
100 return $os_ver;
101 }
102 return;
103 }
104  
105 sub model {
106 my $arista = shift;
107 my $id = $arista->id();
108  
109 my $model = &SNMP::translateObj($id);
110 return $id unless defined $model;
111  
112 $model =~ s/^arista//;
113 return $model;
114 }
115  
116 # The LLDP MIB leaves it up in the air what the index means.
117 # On EOS, it's a dot1d port.
118 sub lldp_if {
119 my $arista = shift;
120 my $partial = shift;
121  
122 # We pick a column that someone else is likely to want,
123 # so that the cache means that hopefully this doesn't
124 # cause any more SNMP transactions in total.
125 my $desc = $arista->lldp_rem_desc($partial) || {};
126 my $bp_index = $arista->bp_index() || {};
127  
128 my $lldp_if = {};
129 foreach my $key ( keys %$desc ) {
130 my @aOID = split( '\.', $key );
131 my $port = $aOID[1];
132 $lldp_if->{$key} = $bp_index->{$port};
133 }
134 return $lldp_if;
135 }
136  
137 sub set_i_vlan {
138 my ($arista, $vlan, $iid) = @_;
139 return $arista->set_qb_i_vlan($vlan, $iid);
140 }
141  
142 sub agg_ports { return agg_ports_ifstack(@_) }
143  
144 sub _agg_ports_walked { return qw/ifStackStatus ifType/ }
145  
146 sub _context_kinds {
147 my ( $arista, $feature ) = @_;
148  
149 return ['vrf'] if ( $feature // '' ) eq 'vrf';
150 return;
151 }
152  
153 # A VRF is a context named like it; the v2c community is community@VRF
154 sub _snmp_context {
155 my ( $arista, $kind, $id ) = @_;
156  
157 return unless ( $kind // '' ) eq 'vrf';
158 return if !defined $id or $id eq q() or $id eq 'default';
159 return { kind => 'vrf', id => $id, v2c => "%s\@$id", v3 => $id };
160 }
161  
162 # Each VRF reads in its own context. The default context serves only the
163 # default instance's rows, but its aristaVrfIfTable names every VRF port.
164 sub _vrf_context_filters { return 1; }
165  
166 sub _vrf_default_context_members { return 1; }
167  
168 # A VRF context, named for its VRF, serves no aristaVrfTable row
169 sub _vrf_context_is_instance_name { return 1; }
170  
171 # aristaVrfTable is indexed by the length-prefixed VRF name. INVALID is no
172 # route distinguisher. aristaVrfState is not read into oper: see the POD.
173 # The table has no row for the default VRF, so a whole walk of it lists
174 # default even with no row.
175 sub _vrf_vendor_instances {
176 my $arista = shift;
177  
178 my $rd = $arista->vrf_arista_rd() || {};
179 my $state = $arista->vrf_arista_state() || {};
180 my %iids = map { $_ => 1 } keys %$rd, keys %$state;
181  
182 my %instances;
183 foreach my $iid ( keys %iids ) {
184 my ($name) = $arista->_vrf_decode_name($iid);
185 next if !defined $name or !length $name or $name eq 'default';
186  
187 my $record = SNMP::Info::VRF::_vrf_record( $name, 'vrf', 'device' );
188 my $served = $rd->{$iid};
189 $record->{rd} = $arista->_vrf_rd($served)
190 if defined $served and $served ne 'INVALID';
191 $record->{sources}{list} = 'ARISTA-VRF-MIB';
192 $record->{sources}{rd} = 'ARISTA-VRF-MIB' if defined $record->{rd};
193 $instances{$name} = $record;
194 }
195 $arista->_vrf_list_default( \%instances, 'ARISTA-VRF-MIB' )
196 if %iids or $arista->_arista_vrf_table_answered();
197 return \%instances;
198 }
199  
200 # True when both aristaVrfTable walks were recorded complete. An absent
201 # outcome is a poller MIB problem, not an answer from the device.
202 sub _arista_vrf_table_answered {
203 my $arista = shift;
204  
205 foreach my $method (qw/vrf_arista_rd vrf_arista_state/) {
206 my $status = $arista->walk_status($method) or return 0;
207 return 0 if !$status->{complete} or defined $status->{reason};
208 }
209 return 1;
210 }
211  
212 sub _vrf_vendor_list_methods {
213 return qw/vrf_arista_rd vrf_arista_state vrf_arista_if/;
214 }
215  
216 # aristaVrfIfMembership is indexed by ifIndex and holds the VRF name
217 sub _vrf_vendor_membership {
218 my $arista = shift;
219  
220 my $rows = $arista->vrf_arista_if() || {};
221 return {
222 map { $_ => $rows->{$_} }
223 grep { length( $rows->{$_} // q() ) and $rows->{$_} ne 'default' }
224 keys %$rows
225 };
226 }
227  
228 1;
229 __END__