#195 IP address table - IPv4 Address Table will use the IP-MIB::ipAddressTable if the deprecated IP-MIB::ipAddrTable doesn't return results
This commit is contained in:
128
lib/SNMP/Info.pm
128
lib/SNMP/Info.pm
@@ -2560,36 +2560,45 @@ See C<IF-MIB> for full description
|
||||
|
||||
=back
|
||||
|
||||
=head2 IP Address Table
|
||||
=head2 IPv4 Address Table
|
||||
|
||||
Each entry in this table is an IP address in use on this device. Usually
|
||||
this is implemented in Layer3 Devices.
|
||||
Each entry in this table is an IPv4 address in use on this device. Usually
|
||||
this is implemented in Layer3 Devices. These methods try the deprecated IPv4
|
||||
address table C<IP-MIB::ipAddrTable> first due to its prevalence and will try
|
||||
the current C<IP-MIB::ipAddressTable> if it doesn't return any results.
|
||||
C<IP-MIB::ipAddressTable> results are filtered to only return IPv4 unicast
|
||||
addresses and modified to match the return format of the older table for
|
||||
backwards compatibility.
|
||||
|
||||
See documentation in L<SNMP::Info::IPv6> for IPv6 Address Table.
|
||||
|
||||
=over
|
||||
|
||||
=item $info->ip_index()
|
||||
|
||||
Maps the IP Table to the IID
|
||||
Maps the IPv4 addresses to the interface index
|
||||
|
||||
(C<ipAdEntIfIndex>)
|
||||
(C<ipAdEntIfIndex>) or filtered and index modified (C<ipAddressIfIndex>)
|
||||
|
||||
=item $info->ip_table()
|
||||
|
||||
Maps the Table to the IP address
|
||||
Maps the Table to the IPv4 address
|
||||
|
||||
(C<ipAdEntAddr>)
|
||||
(C<ipAdEntAddr>) or address extracted from (C<ipAddressIfIndex>)
|
||||
|
||||
=item $info->ip_netmask()
|
||||
|
||||
Gives netmask setting for IP table entry.
|
||||
Gives netmask setting for IPv4 table entry.
|
||||
|
||||
(C<ipAdEntNetMask>)
|
||||
(C<ipAdEntNetMask>) or netmask calculated from (C<ipAddressPrefix>)
|
||||
|
||||
=item $info->ip_broadcast()
|
||||
|
||||
Gives broadcast address for IP table entry.
|
||||
Gives the value of the least-significant bit in the IPv4 broadcast address
|
||||
either 1 or 0.
|
||||
|
||||
(C<ipAdEntBcastAddr>)
|
||||
(C<ipAdEntBcastAddr>), there is no equivalent from the
|
||||
C<IP-MIB::ipAddressTable>
|
||||
|
||||
=back
|
||||
|
||||
@@ -2770,6 +2779,88 @@ no protocols are supported or running.
|
||||
|
||||
=cut
|
||||
|
||||
sub ip_index {
|
||||
my $self = shift;
|
||||
|
||||
my $o_ip_idx = $self->old_ip_index();
|
||||
return $o_ip_idx
|
||||
if ( ref {} eq ref $o_ip_idx and scalar keys %$o_ip_idx );
|
||||
|
||||
# Since callers may be using the old iid to get the IP, strip protocol
|
||||
# and length from the index
|
||||
my $n_ip_idx = $self->new_ip_index() || {};
|
||||
my $n_ip_type = $self->new_ip_type() || {};
|
||||
|
||||
my %ip_index;
|
||||
foreach my $iid ( keys %$n_ip_idx ) {
|
||||
next unless $n_ip_type->{$iid} and $n_ip_type->{$iid} eq 'unicast';
|
||||
my @parts = split( /\./, $iid );
|
||||
my $type = shift(@parts);
|
||||
my $len = shift(@parts);
|
||||
next unless ( ( $type == 1 ) and ( $len == 4 ) );
|
||||
|
||||
my $new_iid = join( ".", @parts );
|
||||
$ip_index{$new_iid} = $n_ip_idx->{$iid};
|
||||
}
|
||||
return \%ip_index;
|
||||
}
|
||||
|
||||
sub ip_table {
|
||||
my $self = shift;
|
||||
|
||||
my $o_ip_table = $self->old_ip_table();
|
||||
return $o_ip_table
|
||||
if ( ref {} eq ref $o_ip_table and scalar keys %$o_ip_table );
|
||||
|
||||
my $n_ip_idx = $self->new_ip_index() || {};
|
||||
my $n_ip_type = $self->new_ip_type() || {};
|
||||
|
||||
my %ip_table;
|
||||
foreach my $iid ( keys %$n_ip_idx ) {
|
||||
next unless $n_ip_type->{$iid} and $n_ip_type->{$iid} eq 'unicast';
|
||||
my @parts = split( /\./, $iid );
|
||||
my $type = shift(@parts);
|
||||
my $len = shift(@parts);
|
||||
next unless ( ( $type == 1 ) and ( $len == 4 ) );
|
||||
|
||||
my $new_iid = join( ".", @parts );
|
||||
$ip_table{$new_iid} = $new_iid;
|
||||
}
|
||||
return \%ip_table;
|
||||
}
|
||||
|
||||
sub ip_netmask {
|
||||
my $self = shift;
|
||||
|
||||
my $o_ip_mask = $self->old_ip_netmask();
|
||||
return $o_ip_mask
|
||||
if ( ref {} eq ref $o_ip_mask and scalar keys %$o_ip_mask );
|
||||
|
||||
my $n_ip_pfx = $self->new_ip_prefix() || {};
|
||||
my $n_ip_type = $self->new_ip_type() || {};
|
||||
|
||||
my %ip_netmask;
|
||||
foreach my $iid ( keys %$n_ip_pfx ) {
|
||||
next unless $n_ip_type->{$iid} and $n_ip_type->{$iid} eq 'unicast';
|
||||
my @parts = split( /\./, $iid );
|
||||
my $type = shift(@parts);
|
||||
my $len = shift(@parts);
|
||||
next unless ( ( $type == 1 ) and ( $len == 4 ) );
|
||||
|
||||
my $prefix = $n_ip_pfx->{$iid};
|
||||
next if ( !$prefix || $prefix =~ /0\.0$/ );
|
||||
if ( $prefix =~ /\.(\d+)$/ ) {
|
||||
$prefix = $1;
|
||||
}
|
||||
my $new_iid = join( ".", @parts );
|
||||
my $mask = NetAddr::IP::Lite->new( $new_iid . '/' . $prefix )->mask()
|
||||
|| undef;
|
||||
|
||||
$ip_netmask{$new_iid} = $mask;
|
||||
}
|
||||
return \%ip_netmask;
|
||||
}
|
||||
|
||||
sub has_topo {
|
||||
my $self = shift;
|
||||
|
||||
@@ -3182,11 +3273,16 @@ ALTEON-TS-PHYSICAL-MIB::agPortCurCfgPortName.
|
||||
# IF-MIB::IfStackTable
|
||||
'i_stack_status' => 'ifStackStatus',
|
||||
|
||||
# IP::MIB::ipAddrTable (deprecated IPv4 address table)
|
||||
'ip_index' => 'ipAdEntIfIndex',
|
||||
'ip_table' => 'ipAdEntAddr',
|
||||
'ip_netmask' => 'ipAdEntNetMask',
|
||||
'ip_broadcast' => 'ipAdEntBcastAddr',
|
||||
# IP-MIB::ipAddrTable (deprecated IPv4 address table)
|
||||
'old_ip_index' => 'ipAdEntIfIndex',
|
||||
'old_ip_table' => 'ipAdEntAddr',
|
||||
'old_ip_netmask' => 'ipAdEntNetMask',
|
||||
'ip_broadcast' => 'ipAdEntBcastAddr',
|
||||
|
||||
# IP-MIB::ipAddressTable
|
||||
'new_ip_index' => 'ipAddressIfIndex',
|
||||
'new_ip_prefix' => 'ipAddressPrefix',
|
||||
'new_ip_type' => 'ipAddressType',
|
||||
|
||||
# IF-MIB::ifXTable - Extension Table
|
||||
'i_speed_high' => 'ifHighSpeed',
|
||||
|
||||
@@ -508,8 +508,8 @@ sub ip_index {
|
||||
my $airespace = shift;
|
||||
my $partial = shift;
|
||||
|
||||
my $ip_index = $airespace->orig_ip_index($partial) || {};
|
||||
my $if_ip = $airespace->airespace_if_ip() || {};
|
||||
my $ip_index = $airespace->SUPER::ip_index($partial) || {};
|
||||
my $if_ip = $airespace->airespace_if_ip() || {};
|
||||
|
||||
my %ip_index;
|
||||
foreach my $ip ( keys %$ip_index ) {
|
||||
@@ -534,9 +534,9 @@ sub ip_netmask {
|
||||
my $airespace = shift;
|
||||
my $partial = shift;
|
||||
|
||||
my $ip_mask = $airespace->orig_ip_netmask($partial) || {};
|
||||
my $if_ip = $airespace->airespace_if_ip() || {};
|
||||
my $if_mask = $airespace->airespace_if_mask() || {};
|
||||
my $ip_mask = $airespace->SUPER::ip_netmask($partial) || {};
|
||||
my $if_ip = $airespace->airespace_if_ip() || {};
|
||||
my $if_mask = $airespace->airespace_if_mask() || {};
|
||||
|
||||
my %ip_netmask;
|
||||
foreach my $ip ( keys %$ip_mask ) {
|
||||
|
||||
@@ -143,7 +143,7 @@ sub model {
|
||||
# override methods in ipAddrTable
|
||||
sub ip_table {
|
||||
my $nexus = shift;
|
||||
my $orig_ip_table = $nexus->orig_ip_table();
|
||||
my $orig_ip_table = $nexus->SUPER::ip_table();
|
||||
|
||||
my %ip_table;
|
||||
foreach my $iid ( keys %$orig_ip_table ) {
|
||||
@@ -163,8 +163,8 @@ sub ip_table {
|
||||
|
||||
sub ip_index {
|
||||
my $nexus = shift;
|
||||
my $orig_ip_table = $nexus->orig_ip_table();
|
||||
my $orig_ip_index = $nexus->orig_ip_index();
|
||||
my $orig_ip_table = $nexus->SUPER::ip_table();
|
||||
my $orig_ip_index = $nexus->SUPER::ip_index();
|
||||
|
||||
my %ip_index;
|
||||
foreach my $iid ( keys %$orig_ip_table ) {
|
||||
@@ -186,8 +186,8 @@ sub ip_index {
|
||||
|
||||
sub ip_netmask {
|
||||
my $nexus = shift;
|
||||
my $orig_ip_table = $nexus->orig_ip_table();
|
||||
my $orig_ip_netmask = $nexus->orig_ip_netmask();
|
||||
my $orig_ip_table = $nexus->SUPER::ip_table();
|
||||
my $orig_ip_netmask = $nexus->SUPER::ip_netmask();
|
||||
|
||||
my %ip_netmask;
|
||||
foreach my $iid ( keys %$orig_ip_table ) {
|
||||
@@ -209,8 +209,8 @@ sub ip_netmask {
|
||||
|
||||
sub ip_broadcast {
|
||||
my $nexus = shift;
|
||||
my $orig_ip_table = $nexus->orig_ip_table();
|
||||
my $orig_ip_broadcast = $nexus->orig_ip_broadcast();
|
||||
my $orig_ip_table = $nexus->SUPER::ip_table();
|
||||
my $orig_ip_broadcast = $nexus->SUPER::ip_broadcast();
|
||||
|
||||
my %ip_broadcast;
|
||||
foreach my $iid ( keys %$orig_ip_table ) {
|
||||
|
||||
@@ -450,7 +450,7 @@ sub ip_index {
|
||||
my $partial = shift;
|
||||
|
||||
my $model = $passport->model();
|
||||
my $ip_index = $passport->orig_ip_index($partial) || {};
|
||||
my $ip_index = $passport->SUPER::ip_index($partial) || {};
|
||||
|
||||
my %ip_index;
|
||||
foreach my $ip ( keys %$ip_index ) {
|
||||
@@ -492,7 +492,7 @@ sub ip_netmask {
|
||||
my $partial = shift;
|
||||
|
||||
my $model = $passport->model();
|
||||
my $ip_mask = $passport->orig_ip_netmask($partial) || {};
|
||||
my $ip_mask = $passport->SUPER::ip_netmask($partial) || {};
|
||||
|
||||
my %ip_index;
|
||||
foreach my $iid ( keys %$ip_mask ) {
|
||||
|
||||
@@ -55,8 +55,8 @@ $VERSION = '3.60';
|
||||
%FUNCS = (
|
||||
%SNMP::Info::Layer7::FUNCS,
|
||||
# IP Address Table - NS-ROOT-MIB::nsIpAddrTable
|
||||
'ip_index' => 'ipAddr',
|
||||
'ip_netmask' => 'ipNetmask',
|
||||
'ns_ip_index' => 'ipAddr',
|
||||
'ns_ip_netmask' => 'ipNetmask',
|
||||
# TODO VLAN - NS-ROOT-MIB::vlanTable
|
||||
'ns_vid' =>'vlanId',
|
||||
'ns_vlan_mem' => 'vlanMemberInterfaces',
|
||||
@@ -89,13 +89,24 @@ sub model {
|
||||
sub os_ver {
|
||||
my $ns = shift;
|
||||
my $ver = $ns->build_ver() || '';
|
||||
|
||||
|
||||
if ($ver =~ /^.+\bNS(\d+\.\d+)/) {
|
||||
$ver = $1;
|
||||
}
|
||||
return $ver;
|
||||
}
|
||||
|
||||
sub ip_index {
|
||||
my $ns = shift;
|
||||
|
||||
return $ns->ns_ip_index();
|
||||
}
|
||||
|
||||
sub ip_netmask {
|
||||
my $ns = shift;
|
||||
|
||||
return $ns->ns_ip_netmask();
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
|
||||
Reference in New Issue
Block a user