Info/Layer3/Tachyon.pm untested

filter: Statementstmt 0.0% 0 / 153 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 82 MC/DCmcdc 0.0% 0 / 46 Subroutinesub 0.0% 0 / 26 Podpod 0.0% 0 / 22 totaltotal 0.0% 0 / 391 CC 32 SCAR 26.0
CC
32
Cov
0%
i_up
30.0
i_up_admin
30.0
_tachyon_munge_mac
20.0
CRAP 13.4
1 # SNMP::Info::Layer3::Tachyon - SNMP interface to Tachyon Networks TNA devices
2 #
3 # Copyright (c) 2026 by SNMP::Info Developers.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are met:
7 #
8 # * Redistributions of source code must retain the above copyright notice,
9 # this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
13 # * Neither the name of the University of California, Santa Cruz nor the
14 # names of its contributors may be used to endorse or promote products
15 # derived from this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
28  
29 package SNMP::Info::Layer3::Tachyon;
30  
31 use strict;
32 use warnings;
33 use Exporter;
34 use SNMP::Info::Layer3;
35  
36 @SNMP::Info::Layer3::Tachyon::ISA = qw/SNMP::Info::Layer3 Exporter/;
37 @SNMP::Info::Layer3::Tachyon::EXPORT_OK = qw//;
38  
39 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE);
40  
41 $VERSION = '3.985003';
42  
43 # TACHYON-MIB is not in a netdisco-mibs release yet (netdisco-mibs#310), so
44 # its objects are read by numeric OID. Switch to the names once it ships.
45 %MIBS = (%SNMP::Info::Layer3::MIBS);
46 %FUNCS = (
47 %SNMP::Info::Layer3::FUNCS,
48  
49 # wirelessPeersTable: wirelessPeerMac, wirelessPeerVapIfIndex
50 'tachyon_peer_mac' => '.1.3.6.1.4.1.57344.1.2.6.1.1',
51 'tachyon_peer_ifindex' => '.1.3.6.1.4.1.57344.1.2.6.1.3',
52  
53 # ethernetTable: ethernetIfaceName, ethernetLink, ethernetDuplex,
54 # ethernetEnabled
55 'tachyon_ethernet_ifname' => '.1.3.6.1.4.1.57344.1.1.3.1.2',
56 'tachyon_ethernet_link' => '.1.3.6.1.4.1.57344.1.1.3.1.5',
57 'tachyon_ethernet_duplex' => '.1.3.6.1.4.1.57344.1.1.3.1.8',
58 'tachyon_ethernet_admin' => '.1.3.6.1.4.1.57344.1.1.3.1.10',
59 );
60  
61 %GLOBALS = (
62 %SNMP::Info::Layer3::GLOBALS,
63  
64 # deviceModel, deviceSerialNo, firmwareVersion, deviceDescription
65 'tachyon_device_model' => '.1.3.6.1.4.1.57344.1.3.1.0',
66 'tachyon_serial' => '.1.3.6.1.4.1.57344.1.3.2.0',
67 'tachyon_firmware' => '.1.3.6.1.4.1.57344.1.3.4.0',
68 'tachyon_description' => '.1.3.6.1.4.1.57344.1.3.9.0',
69 );
70  
71 %MUNGE = (%SNMP::Info::Layer3::MUNGE);
72  
73 sub vendor { return 'tachyon'; }
74  
75 # The radio may serve no sysServices; peers in the forwarding table make it a
76 # layer 2 device whatever it reports.
77 sub layers {
78 my $self = shift;
79  
80 my $layers = $self->SUPER::layers() || '00000100';
81 my $macs = $self->fw_mac() || {};
82 substr( $layers, 6, 1, '1' ) if keys %$macs;
83 return $layers;
84 }
85  
86 sub os { return 'tachyon'; }
87  
88 sub model {
89 my $self = shift;
90 my $model = $self->tachyon_device_model();
91 return $model if defined $model and $model =~ /\S/;
92 return $self->SUPER::model();
93 }
94  
95 sub os_ver {
96 my $self = shift;
97 my $version = $self->tachyon_firmware();
98 return $version if defined $version and $version =~ /\S/;
99 return $self->SUPER::os_ver();
100 }
101  
102 sub serial {
103 my $self = shift;
104 my $serial = $self->tachyon_serial();
105 return $serial if defined $serial and $serial =~ /\S/;
106 return $self->SUPER::serial();
107 }
108  
109 # deviceDescription is user-entered, so sysDescr comes first
110 sub description {
111 my $self = shift;
112 my $description = $self->SUPER::description();
113 return $description if defined $description and $description =~ /\S/;
114 return $self->tachyon_description();
115 }
116  
117 sub _tachyon_munge_mac {
118 my $mac = shift;
119 return unless defined $mac;
120 return SNMP::Info::munge_mac($mac) if length($mac) == 6;
121  
122 $mac =~ s/[^0-9A-Fa-f]//g;
123 return unless length($mac) == 12;
124 return join ':', map { lc substr( $mac, $_, 2 ) } ( 0, 2, 4, 6, 8, 10 );
125 }
126  
127 sub fw_mac {
128 my $self = shift;
129 my $macs = $self->tachyon_peer_mac() || {};
130 my %fw_mac;
131 foreach my $index ( keys %$macs ) {
132 my $mac = _tachyon_munge_mac( $macs->{$index} );
133 $fw_mac{$index} = $mac if defined $mac;
134 }
135 return \%fw_mac;
136 }
137  
138 sub fw_port {
139 my $self = shift;
140 return $self->tachyon_peer_ifindex() || {};
141 }
142  
143 # The peer table lists active wireless associations, so they have learned
144 # forwarding status. Its port value is already an ifIndex rather than a
145 # dot1d bridge port number.
146 sub fw_status {
147 my $self = shift;
148 my $macs = $self->fw_mac() || {};
149 return { map { $_ => 3 } keys %$macs };
150 }
151  
152 # Some agents serve no ifIndex column, so map every interface and every
153 # peer port to itself
154 sub bp_index {
155 my $self = shift;
156 my $interfaces = $self->interfaces() || {};
157 my $ports = $self->fw_port() || {};
158 return { map { $_ => $_ } keys %$interfaces,
159 grep {defined} values %$ports };
160 }
161  
162 sub _tachyon_ethernet_ifindexes {
163 my $self = shift;
164 my $ifnames = $self->tachyon_ethernet_ifname() || {};
165 my $if_descriptions = $self->i_description() || {};
166 my %ifindex_for_name = map { $if_descriptions->{$_} => $_ }
167 grep { defined $if_descriptions->{$_} } keys %$if_descriptions;
168 my %ifindex_for_row;
169  
170 foreach my $row ( keys %$ifnames ) {
171 my $ifindex = $ifindex_for_name{ $ifnames->{$row} };
172 $ifindex_for_row{$row} = $ifindex if defined $ifindex;
173 }
174  
175 return \%ifindex_for_row;
176 }
177  
178 # IF-MIB remains the primary source; these vendor columns fill missing
179 # Ethernet values on firmware that omits them from IF-MIB.
180 sub i_up {
181 my ( $self, $partial ) = @_;
182 my $up = $self->SUPER::i_up($partial) || {};
183 my $ifindex_for_row = _tachyon_ethernet_ifindexes($self);
184 my $link = $self->tachyon_ethernet_link() || {};
185  
186 foreach my $row ( keys %$link ) {
187 my $ifindex = $ifindex_for_row->{$row};
188 next unless defined $ifindex;
189 next if defined $partial and $partial ne $ifindex;
190 $up->{$ifindex} = $link->{$row} ? 'up' : 'down'
191 unless exists $up->{$ifindex};
192 }
193  
194 return $up;
195 }
196  
197 sub i_up_admin {
198 my ( $self, $partial ) = @_;
199 my $admin = $self->SUPER::i_up_admin($partial) || {};
200 my $ifindex_for_row = _tachyon_ethernet_ifindexes($self);
201 my $enabled = $self->tachyon_ethernet_admin() || {};
202  
203 foreach my $row ( keys %$enabled ) {
204 my $ifindex = $ifindex_for_row->{$row};
205 next unless defined $ifindex;
206 next if defined $partial and $partial ne $ifindex;
207 $admin->{$ifindex} = $enabled->{$row} ? 'up' : 'down'
208 unless exists $admin->{$ifindex};
209 }
210  
211 return $admin;
212 }
213  
214 sub i_duplex {
215 my ( $self, $partial ) = @_;
216 my $duplex = $self->SUPER::i_duplex($partial) || {};
217 my $ifindex_for_row = _tachyon_ethernet_ifindexes($self);
218 my $ethernet_duplex = $self->tachyon_ethernet_duplex() || {};
219  
220 foreach my $row ( keys %$ethernet_duplex ) {
221 my $ifindex = $ifindex_for_row->{$row};
222 next unless defined $ifindex;
223 next if defined $partial and $partial ne $ifindex;
224 my $value = lc( $ethernet_duplex->{$row} || '' );
225 $duplex->{$ifindex} = $value
226 if $value =~ /^(?:full|half)$/ and not exists $duplex->{$ifindex};
227 }
228  
229 return $duplex;
230 }
231  
232 sub i_type {
233 my ( $self, $partial ) = @_;
234 my $type = $self->SUPER::i_type($partial) || {};
235 my $ifindex_for_row = _tachyon_ethernet_ifindexes($self);
236  
237 foreach my $ifindex ( values %$ifindex_for_row ) {
238 next if defined $partial and $partial ne $ifindex;
239 $type->{$ifindex} = 'ethernetCsmacd' unless exists $type->{$ifindex};
240 }
241  
242 return $type;
243 }
244  
245 sub _tachyon_vlan_ifindexes {
246 my $self = shift;
247 my $names = $self->i_name() || {};
248 my $descriptions = $self->i_description() || {};
249 my %vlans;
250  
251 foreach my $ifindex ( keys %$names, keys %$descriptions ) {
252 my $name = $names->{$ifindex} || $descriptions->{$ifindex} || '';
253 my $vlan;
254 $vlan = $1 if $name =~ /\.(\d{1,4})$/;
255 $vlan = $1 if !defined($vlan) && $name =~ /^br[^.]*?(\d{1,4})$/i;
256 next unless defined $vlan and $vlan >= 1 and $vlan <= 4094;
257 $vlans{$ifindex} = 0 + $vlan;
258 }
259  
260 return \%vlans;
261 }
262  
263 sub i_vlan {
264 my ( $self, $partial ) = @_;
265 my $vlans = _tachyon_vlan_ifindexes($self);
266 return $vlans unless defined $partial;
267 return exists $vlans->{$partial} ? { $partial => $vlans->{$partial} } : {};
268 }
269  
270 sub v_name {
271 my ( $self, $partial ) = @_;
272 my $vlans = _tachyon_vlan_ifindexes($self);
273 my %names = map { $vlans->{$_} => "$vlans->{$_}" } keys %$vlans;
274 return \%names unless defined $partial;
275 return exists $names{$partial} ? { $partial => $names{$partial} } : {};
276 }
277  
278 sub i_vlan_membership {
279 my ( $self, $partial ) = @_;
280 my $vlans = _tachyon_vlan_ifindexes($self);
281 my %membership;
282 foreach my $ifindex ( keys %$vlans ) {
283 next if defined $partial and $ifindex ne $partial;
284 $membership{$ifindex} = [ $vlans->{$ifindex} ];
285 }
286 return \%membership;
287 }
288  
289 sub i_vlan_membership_untagged { return {}; }
290  
291 =head1 NAME
292  
293 SNMP::Info::Layer3::Tachyon - SNMP support for Tachyon TNA devices
294  
295 =head1 AUTHOR
296  
297 SNMP::Info Developers
298  
299 =head1 SYNOPSIS
300  
301 use SNMP::Info;
302  
303 my $info = SNMP::Info->new(
304 AutoSpecify => 1,
305 DestHost => 'mydevice',
306 Community => 'public',
307 Version => 2,
308 );
309  
310 =head1 DESCRIPTION
311  
312 Supports Tachyon TNA-300 series devices using the Tachyon private MIB. Reads
313 model, serial number, and firmware version from the system extension group,
314 learns wireless peers from the peer table, and identifies VLAN interfaces by
315 their reported interface names. Tachyon's TNS switches are not handled by
316 this class.
317  
318 =head2 Inherited Classes
319  
320 =over
321  
322 =item SNMP::Info::Layer3
323  
324 =back
325  
326 =head2 Required MIBs
327  
328 None. C<TACHYON-MIB> objects are read by numeric OID until the MIB is in a
329 netdisco-mibs release.
330  
331 =head2 Inherited MIBs
332  
333 See L<SNMP::Info::Layer3/Required MIBs> for inherited MIB requirements.
334  
335 =head1 GLOBALS
336  
337 These methods return scalar values from the device.
338  
339 =over
340  
341 =item $info->vendor()
342  
343 Returns C<'tachyon'>.
344  
345 =item $info->os()
346  
347 Returns C<'tachyon'>.
348  
349 =item $info->layers()
350  
351 Returns the served C<sysServices> layers, or layer 3 where none are served,
352 with layer 2 added whenever the peer table lists a peer.
353  
354 =item $info->model()
355  
356 Returns the device model from C<deviceModel>.
357  
358 =item $info->os_ver()
359  
360 Returns the firmware version from C<firmwareVersion>.
361  
362 =item $info->serial()
363  
364 Returns the serial number from C<deviceSerialNo>.
365  
366 =item $info->description()
367  
368 Returns C<sysDescr>, or the user-entered C<deviceDescription> where
369 C<sysDescr> is empty.
370  
371 =back
372  
373 =head1 TABLE METHODS
374  
375 These methods return tables as references to hashes.
376  
377 =over
378  
379 =item $info->fw_mac()
380  
381 Returns wireless peer MAC addresses keyed by the peer table index.
382  
383 =item $info->fw_port()
384  
385 Returns the interface index associated with each wireless peer.
386  
387 =item $info->fw_status()
388  
389 Returns forwarding status C<3> for each active wireless peer.
390  
391 =item $info->bp_index()
392  
393 Maps each interface and each peer port to itself, since C<fw_port()> returns
394 interface indexes.
395  
396 =item $info->i_up()
397  
398 Returns interface operational status, including Tachyon Ethernet port state.
399  
400 =item $info->i_up_admin()
401  
402 Returns interface administrative status, including Tachyon Ethernet port
403 state.
404  
405 =item $info->i_duplex()
406  
407 Returns duplex mode for Tachyon Ethernet interfaces.
408  
409 =item $info->i_type()
410  
411 Reports Tachyon Ethernet interfaces as C<ethernetCsmacd>.
412  
413 =item $info->i_vlan()
414  
415 Maps VLAN interfaces to VLAN IDs using their interface names.
416  
417 =item $info->v_name()
418  
419 Maps VLAN IDs to names derived from the device's VLAN interface names.
420  
421 =item $info->i_vlan_membership()
422  
423 Returns VLAN membership for the logical VLAN interfaces reported by the
424 device.
425  
426 =item $info->i_vlan_membership_untagged()
427  
428 Returns an empty table because untagged VLAN membership is not available from
429 the device's SNMP data.
430  
431 =back
432  
433 =head2 Table Methods imported from SNMP::Info::Layer3
434  
435 See documentation in L<SNMP::Info::Layer3> for details.
436  
437 =cut
438  
439 1;