Skip to content

Commit

Permalink
allow new hardware versions (#519)
Browse files Browse the repository at this point in the history
* start to add support for new models, regex is incorrect atm, tests fail because of that. todo also: remove ghost interfaces, ahXIfTable should be main reference

* get rid of ghost interfaces by referencing ahifname

* return ahDeviceMode as is, fall back to old code when not supported

* return ahDeviceMode as is, fall back to old code when not supported

* recognize newer models
  • Loading branch information
inphobia committed Mar 11, 2024
1 parent d293fa7 commit e20cab9
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 25 deletions.
55 changes: 42 additions & 13 deletions lib/SNMP/Info/Layer2/Aerohive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ $VERSION = '3.970001';
%SNMP::Info::Layer2::GLOBALS,

# AH-SYSTEM-MIB
'serial' => 'ahSystemSerial',
'os_bin' => 'ahFirmwareVersion',
'ah_serial' => 'ahSystemSerial',
'os_bin' => 'ahFirmwareVersion',
'ah_devmode' => 'ahDeviceMode',
# not documented in the most recent mib,
# but this is the base mac for the device
'ah_mac' => '.1.3.6.1.4.1.26928.1.3.2.0',
'ah_mac' => '.1.3.6.1.4.1.26928.1.3.2.0',
);

%FUNCS = (
Expand All @@ -67,6 +68,7 @@ $VERSION = '3.970001';

# AH-INTERFACE-MIB::ahXIfTable
'ah_i_ssidlist' => 'ahSSIDName',
'ah_i_name' => 'ahIfName',

# AH-INTERFACE-MIB::ahAssociationTable
'cd11_txrate' => 'ahClientLastTxRate',
Expand Down Expand Up @@ -100,14 +102,18 @@ sub os {
sub serial {
my $aerohive = shift;

return $aerohive->ahSystemSerial()
return $aerohive->ah_serial()
|| $aerohive->SUPER::serial();
}

sub os_ver {
my $aerohive = shift;
my $ah_ver = $aerohive->os_bin();
my $descr = $aerohive->description();

if ( defined ($ah_ver) && $ah_ver =~ m/\bHiveOS\s(\d+\.\w+)\b/ix ) {
return $1;
}
if ( defined ($descr) && $descr =~ m/\bHiveOS\s(\d+\.\w+)\b/ix ) {
return $1;
}
Expand Down Expand Up @@ -138,15 +144,34 @@ sub mac {
}

sub model {
my $aerohive = shift;
my $descr = $aerohive->description();
my $aerohive = shift;
my $descr = $aerohive->description();
my $ahdevmode = $aerohive->ah_devmode();

if ( defined ($ahdevmode) and length $ahdevmode ) {
return $ahdevmode;
}
if ( defined ($descr) && $descr =~ m/\b(?:Hive|)(AP\d+)\b/ix ) {
return $1;
}
return;
}

sub interfaces {
my $aerohive = shift;
my $interfaces = $aerohive->i_index();
my $i_descr = $aerohive->ah_i_name();

my %if;
foreach my $iid ( keys %$interfaces ) {
my $descr = $i_descr->{$iid};
next unless defined $descr;
$if{$iid} = $descr if ( defined $descr and length $descr );
}

return \%if
}

sub i_ssidlist {
my $aerohive = shift;
my $partial = shift;
Expand Down Expand Up @@ -383,15 +408,13 @@ Returns 'hiveos'.
=item $aerohive->serial()
Returns the serial number extracted from C<ahSystemSerial>.
Returns the serial number extracted from C<ahSystemSerial> or defer
to imported modules.
=item $aerohive->os_ver()
Returns the OS version extracted from C<sysDescr>.
=item $aerohive->os_bin()
Returns the firmware version extracted from C<ahFirmwareVersion>.
Returns the OS version extracted from C<ahFirmwareVersion> or
C<sysDescr> as fallback.
=item $aerohive->mac()
Expand All @@ -401,7 +424,8 @@ return the lowest numbered mac address.
=item $aerohive->model()
Returns the model extracted from C<sysDescr>.
Returns C<ahDeviceMode>, if that's not available the model
is extracted from C<sysDescr>.
=back
Expand Down Expand Up @@ -463,6 +487,11 @@ Returns client radio interface MAC addresses.
=over
=item $aerohive->interfaces()
Only return interfaces which have an entry in ahIfName as well. This halts
the creation of ghost interfaces.
=item $aerohive->bp_index()
Simulates bridge MIB by returning reference to a hash mapping i_index() to
Expand Down
50 changes: 38 additions & 12 deletions xt/lib/Test/SNMP/Info/Layer2/Aerohive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,26 @@ sub setup : Tests(setup) {
# Example walk had no sysServices returned
#'_layers' => 1,
'_description' => 'HiveAP121, HiveOS 6.2r1 release build1924',
'_ahSystemSerial' => '02511610111621',
'_os_bin' => 'HiveOS 10.6r6 build-8f57188',
'_ah_serial' => '02511610111621',
'_ah_devmode' => 'AP305C-1',
# not documented, oid '.1.3.6.1.4.1.26928.1.3.2.0'
'_ah_mac' => '4018:b13a:4c40',
'_ah_mac' => '4018:b13a:4c40',

# AH-SMI-MIB::ahProduct
'_id' => '.1.3.6.1.4.1.26928.1',
'_i_index' => 1,
'_i_description' => 1,
'_i_mac' => 1,
'_ah_i_ssidlist' => 1,
'_ah_i_name' => 1,
'_cd11_txrate' => 1,
'_ah_c_vlan' => 1,
'_ah_c_ip' => 1,
'store' => {
'i_index' => {4 => 4, 6 => 6, 7 => 7, 9 => 9, 15 => 15, 16 => 16, 20 => 20},
'i_index' => {10 => 10, 6 => 6, 7 => 7, 33 => 33, 15 => 15, 16 => 16, 20 => 20},
'i_description' =>
{4 => 'eth0', 6 => 'wifi0', 7 => 'wifi1', 9 => 'mgt0', 15 => 'wifi0.1', 16 => 'wifi0.2', 20 => 'wifi1.1'},
{10 => 'eth0', 6 => 'wifi0', 7 => 'wifi1', 33 => 'mgt0', 15 => 'wifi0.1', 16 => 'wifi0.2', 20 => 'wifi1.1'},
'i_mac' => {
# mgt0 always has lowest mac, most of the time shared with eth0
# wifi0 shares it's mac with wifi0.1 (same goes for wifi1/wifi1.1)
Expand All @@ -74,7 +77,9 @@ sub setup : Tests(setup) {
20 => pack("H*", '4018B13A4C64')
},
'ah_i_ssidlist' =>
{4 => 'N/A', 6 => 'N/A', 7 => 'N/A', 9 => 'N/A', 15 => 'MyGuest', 16 => 'MyPrivate', 20 => 'MyGuest'},
{10 => 'N/A', 6 => 'N/A', 7 => 'N/A', 33 => 'N/A', 15 => 'MyGuest', 16 => 'MyPrivate', 20 => 'MyGuest'},
'ah_i_name' =>
{10 => 'eth0', 6 => 'wifi0', 7 => 'wifi1', 33 => 'mgt0', 15 => 'wifi0.1', 16 => 'wifi0.2', 20 => 'wifi1.1'},
'cd11_txrate' => {
'15.6.128.150.177.92.153.130' => 6000,
'20.6.40.106.186.61.150.231' => 58500,
Expand Down Expand Up @@ -116,10 +121,13 @@ sub os : Tests(2) {
is($test->{info}->os(), 'hiveos', q(OS returns 'hiveos'));
}

sub os_ver : Tests(4) {
sub os_ver : Tests(5) {
my $test = shift;

can_ok($test->{info}, 'os_ver');
is($test->{info}->os_ver(), '10.6r6', q(OS version from ahFirmwareVersion is expected value));

delete $test->{info}{_os_bin};
is($test->{info}->os_ver(), '6.2r1', q(OS version is expected value));

$test->{info}{_description} = 'AP250, HiveOS 10.0r8 build-236132';
Expand Down Expand Up @@ -148,16 +156,20 @@ sub mac : Tests(4) {
is($test->{info}->mac(), undef, q(No mac returns undef mac));
}

sub model : Tests(4) {
sub model : Tests(5) {
my $test = shift;

can_ok($test->{info}, 'model');
is($test->{info}->model(),
'AP121', q(Model with 'Hive' in description is expected value));
'AP305C-1', q(Model from ah_devmode is expected value));

delete $test->{info}{_ah_devmode};
is($test->{info}->model(),
'AP121', q(Model with 'Hive' in description with no ah_devmode is expected value));

$test->{info}{_description} = 'AP250, HiveOS 8.3r2 build-191018';
is($test->{info}->model(),
'AP250', q(Model without 'Hive' in description is expected value));
'AP250', q(Model without 'Hive' in description with no ah_devmode is expected value));

$test->{info}->clear_cache();
is($test->{info}->model(), undef, q(No description returns undef model));
Expand All @@ -174,6 +186,20 @@ sub serial : Tests(3) {
q(No serial returns undef));
}

sub interfaces : Tests(3) {
my $test = shift;

can_ok($test->{info}, 'interfaces');

my $expected = {6 => 'wifi0', 7 => 'wifi1', 10 => 'eth0', 15 => 'wifi0.1', 16 => 'wifi0.2', 20 => 'wifi1.1', 33 => 'mgt0'};

cmp_deeply($test->{info}->interfaces(),
$expected, q(interfaces return expected values));

$test->{info}->clear_cache();
cmp_deeply($test->{info}->interfaces(), {}, q(No data returns empty hash));
}

sub i_ssidlist : Tests(3) {
my $test = shift;

Expand Down Expand Up @@ -251,13 +277,13 @@ sub bp_index : Tests(3) {
# mock up the needed snmp data.
my $data
= {'IF-MIB::ifIndex' =>
{4 => 4, 6 => 6, 7 => 7, 9 => 9, 15 => 15, 16 => 16, 20 => 20},
{10 => 10, 6 => 6, 7 => 7, 33 => 33, 15 => 15, 16 => 16, 20 => 20},
'RFC1213-MIB::ifIndex' =>
{4 => 4, 6 => 6, 7 => 7, 9 => 9, 15 => 15, 16 => 16, 20 => 20},
{10 => 10, 6 => 6, 7 => 7, 33 => 33, 15 => 15, 16 => 16, 20 => 20},
};
$test->{info}{sess}{Data} = $data;

my $expected = {4 => 4, 6 => 6, 7 => 7, 9 => 9, 15 => 15, 16 => 16, 20 => 20};
my $expected = {10 => 10, 6 => 6, 7 => 7, 33 => 33, 15 => 15, 16 => 16, 20 => 20};

cmp_deeply($test->{info}->bp_index(),
$expected, q(Bridge interface mapping has expected values));
Expand Down

0 comments on commit e20cab9

Please sign in to comment.