- Support partial table fetches on overridden table methods.

-  Use IID as key for hashes, remove unnecessary code.
-  Align with other topology classes, return all data.  c_ip() no longer returns and an array for multiple neighbors on a local port.
This commit is contained in:
Eric Miller
2007-04-06 02:10:58 +00:00
parent 749ad55af1
commit 269d2b7be9

View File

@@ -28,13 +28,12 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package SNMP::Info::SONMP; package SNMP::Info::SONMP;
$VERSION = '1.04'; $VERSION = '1.05';
use strict; use strict;
use Exporter; use Exporter;
use SNMP::Info; use SNMP::Info;
use Carp;
@SNMP::Info::SONMP::ISA = qw/SNMP::Info Exporter/; @SNMP::Info::SONMP::ISA = qw/SNMP::Info Exporter/;
@SNMP::Info::SONMP::EXPORT_OK = qw//; @SNMP::Info::SONMP::EXPORT_OK = qw//;
@@ -83,11 +82,12 @@ sub hasCDP {
return $sonmp->cdp_run(); return $sonmp->cdp_run();
} }
sub c_if { sub c_if {
my $sonmp = shift; my $sonmp = shift;
my $sonmp_topo_port = $sonmp->sonmp_topo_port(); my $partial = shift;
my $sonmp_topo_slot = $sonmp->sonmp_topo_slot();
my $sonmp_topo_port = $sonmp->sonmp_topo_port($partial) || {};
my $sonmp_topo_slot = $sonmp->sonmp_topo_slot($partial) || {};
my $index_factor = $sonmp->index_factor(); my $index_factor = $sonmp->index_factor();
my $slot_offset = $sonmp->slot_offset(); my $slot_offset = $sonmp->slot_offset();
my $port_offset = $sonmp->port_offset(); my $port_offset = $sonmp->port_offset();
@@ -115,117 +115,60 @@ sub c_if {
my $index = (($slot-$slot_offset)*$index_factor) + ($port-$port_offset); my $index = (($slot-$slot_offset)*$index_factor) + ($port-$port_offset);
$c_if{"$index.1"} = $index; $c_if{$entry} = $index;
} }
return \%c_if; return \%c_if;
} }
sub c_ip { sub c_ip {
my $sonmp = shift; my $sonmp = shift;
my $sonmp_topo_ip = $sonmp->sonmp_topo_ip(); my $partial = shift;
my $sonmp_topo_port = $sonmp->sonmp_topo_port();
my $sonmp_topo_slot = $sonmp->sonmp_topo_slot();
my $ip = $sonmp->cdp_id();
my $index_factor = $sonmp->index_factor();
my $slot_offset = $sonmp->slot_offset();
my $port_offset = $sonmp->port_offset();
my $model = $sonmp->model();
my $sonmp_topo_port = $sonmp->sonmp_topo_port($partial) || {};
my $sonmp_topo_ip = $sonmp->sonmp_topo_ip($partial) || {};
# Count the number of devices seen on each port. my %c_ip;
# more than one device seen means connected to a non-sonmp
# device, but other sonmp devices are squawking further away.
my %ip_port;
foreach my $entry (keys %$sonmp_topo_ip){ foreach my $entry (keys %$sonmp_topo_ip){
my $port = $sonmp_topo_port->{$entry}; my $port = $sonmp_topo_port->{$entry};
next unless defined $port; next unless defined $port;
next if ($port =~ /^[\d\.]+$/ and $port == 0); next if $port == 0;
my $slot = $sonmp_topo_slot->{$entry}||0;
if ($model eq 'Baystack Hub') {
my $comidx = $slot;
if (! ($comidx % 5)) {
$slot = ($slot / 5);
} elsif ($comidx =~ /[16]$/) {
$slot = int($slot/5);
$port = 25;
} elsif ($comidx =~ /[27]$/) {
$slot = int($slot/5);
$port = 26;
}
}
my $index = (($slot-$slot_offset)*$index_factor) + ($port-$port_offset);
my $ip = $sonmp_topo_ip->{$entry}; my $ip = $sonmp_topo_ip->{$entry};
push(@{$ip_port{$index}},$ip); $c_ip{$entry} = $ip;
}
my %c_ip;
foreach my $port (keys %ip_port){
my $ips = $ip_port{$port};
if (scalar @$ips == 1) {
$c_ip{"$port.1"} = $ips->[0];
} else {
$c_ip{"$port.1"} = $ips;
}
} }
return \%c_ip; return \%c_ip;
} }
sub c_port { sub c_port {
my $sonmp = shift; my $sonmp = shift;
my $sonmp_topo_port = $sonmp->sonmp_topo_port(); my $partial = shift;
my $sonmp_topo_seg = $sonmp->sonmp_topo_seg();
my $sonmp_topo_slot = $sonmp->sonmp_topo_slot(); my $sonmp_topo_port = $sonmp->sonmp_topo_port($partial) || {};
my $index_factor = $sonmp->index_factor(); my $sonmp_topo_seg = $sonmp->sonmp_topo_seg($partial) || {};
my $slot_offset = $sonmp->slot_offset(); my $sonmp_topo_platform = $sonmp->sonmp_topo_platform($partial) || {};
my $port_offset = $sonmp->port_offset();
my $model = $sonmp->model();
my $sonmp_topo_platform = $sonmp->sonmp_topo_platform();
my %c_port; my %c_port;
foreach my $entry (keys %$sonmp_topo_seg){ foreach my $entry (keys %$sonmp_topo_seg){
my $port = $sonmp_topo_port->{$entry}; my $port = $sonmp_topo_port->{$entry};
next unless defined $port; next unless defined $port;
next if $port == 0; next if $port == 0;
my $slot = $sonmp_topo_slot->{$entry};
$slot = 0 unless defined $slot;
if ($model eq 'Baystack Hub') {
my $comidx = $slot;
if (! ($comidx % 5)) {
$slot = ($slot / 5);
} elsif ($comidx =~ /[16]$/) {
$slot = int($slot/5);
$port = 25;
} elsif ($comidx =~ /[27]$/) {
$slot = int($slot/5);
$port = 26;
}
}
my $index = (($slot-$slot_offset)*$index_factor) + ($port-$port_offset);
# For fake remotes (multiple IPs for a c_ip), use first found
next if defined $c_port{"$index.1"};
my $seg = $sonmp_topo_seg->{$entry}; my $seg = $sonmp_topo_seg->{$entry};
my $platform = $sonmp_topo_platform->{$entry}; my $platform = $sonmp_topo_platform->{$entry};
# AP-222x Series does not adhere to port numbering # AP-222x Series does not adhere to port numbering
if ($platform =~ /AccessPoint/i) { if ($platform =~ /AccessPoint/i) {
$c_port{"$index.1"} = 'dp0'; $c_port{$entry} = 'dp0';
} }
# BayHubs send the lower three bytes of the MAC not the slot/port # BayHubs send the lower three bytes of the MAC not the slot/port
elsif ($seg > 4000) { elsif ($seg > 4000) {
$c_port{"$index.1"} = 'unknown'; $c_port{$entry} = 'unknown';
} }
else { else {
# Segment id is (256 * remote slot_num) + (remote_port) # Segment id is (256 * remote slot_num) + (remote_port)
my $remote_port = $seg % 256; my $remote_port = $seg % 256;
my $remote_slot = int($seg / 256); my $remote_slot = int($seg / 256);
$c_port{"$index.1"} = "$remote_slot.$remote_port"; $c_port{$entry} = "$remote_slot.$remote_port";
} }
} }
return \%c_port; return \%c_port;
@@ -233,48 +176,27 @@ sub c_port {
sub c_platform { sub c_platform {
my $sonmp = shift; my $sonmp = shift;
my $sonmp_topo_port = $sonmp->sonmp_topo_port(); my $partial = shift;
my $sonmp_topo_slot = $sonmp->sonmp_topo_slot();
my $sonmp_topo_platform = $sonmp->sonmp_topo_platform(); my $sonmp_topo_port = $sonmp->sonmp_topo_port($partial) || {};
my $index_factor = $sonmp->index_factor(); my $sonmp_topo_platform = $sonmp->sonmp_topo_platform($partial) || {};
my $slot_offset = $sonmp->slot_offset();
my $port_offset = $sonmp->port_offset();
my $model = $sonmp->model();
my %c_platform; my %c_platform;
foreach my $entry (keys %$sonmp_topo_platform){ foreach my $entry (keys %$sonmp_topo_platform){
my $port = $sonmp_topo_port->{$entry}||0; my $port = $sonmp_topo_port->{$entry};
next unless defined $port;
next if $port == 0; next if $port == 0;
my $slot = $sonmp_topo_slot->{$entry};
$slot = 0 unless defined $slot;
if ($model eq 'Baystack Hub') {
my $comidx = $slot;
if (! ($comidx % 5)) {
$slot = ($slot / 5);
} elsif ($comidx =~ /[16]$/) {
$slot = int($slot/5);
$port = 25;
} elsif ($comidx =~ /[27]$/) {
$slot = int($slot/5);
$port = 26;
}
}
my $index = (($slot-$slot_offset)*$index_factor) + ($port-$port_offset);
# For fake remotes (multiple IPs for a c_ip), use first found
next if defined $c_platform{"$index.1"};
my $platform = $sonmp_topo_platform->{$entry}; my $platform = $sonmp_topo_platform->{$entry};
$c_platform{"$index.1"} = $platform; $c_platform{$entry} = $platform;
} }
return \%c_platform; return \%c_platform;
} }
sub mac { sub mac {
my $sonmp = shift; my $sonmp = shift;
my $sonmp_topo_port = $sonmp->sonmp_topo_port(); my $sonmp_topo_port = $sonmp->sonmp_topo_port();
my $sonmp_topo_mac = $sonmp->sonmp_topo_mac(); my $sonmp_topo_mac = $sonmp->sonmp_topo_mac();
@@ -293,7 +215,7 @@ __END__
=head1 NAME =head1 NAME
SNMP::Info::SONMP - Perl5 Interface to SynOptics Network Management Protocol (SONMP) using SNMP SNMP::Info::SONMP - SNMP Interface to SynOptics Network Management Protocol (SONMP)
=head1 AUTHOR =head1 AUTHOR
@@ -334,10 +256,10 @@ SNMP::Info::SONMP is a subclass of SNMP::Info that provides an object oriented
interface to the SynOptics Network Management Protocol (SONMP) information interface to the SynOptics Network Management Protocol (SONMP) information
through SNMP. through SNMP.
SONMP is a Layer 2 protocol that supplies topology information of devices that also speak SONMP, SONMP is a Layer 2 protocol that supplies topology information of devices that
mostly switches and hubs. SONMP is implemented in SynOptics, Bay, and Nortel Networks devices. also speak SONMP, mostly switches and hubs. SONMP is implemented in SynOptics,
SONMP has been rebranded by Bay then Nortel Networks and is know by several different Bay, and Nortel devices. SONMP has been rebranded by Bay then Nortel and is
names. know by several different names, most recently Nortel Discovery Protocol (NDP).
Create or use a device subclass that inherits this class. Do not use directly. Create or use a device subclass that inherits this class. Do not use directly.
@@ -358,19 +280,6 @@ None.
=back =back
MIBs can be found on the CD that came with your product.
Or, they can be downloaded directly from Nortel Networks regardless of support
contract status.
Go to http://www.nortelnetworks.com Techninal Support, Browse Technical Support,
Select by product, Java Device Manager, Software. Download the latest version.
After installation, all mibs are located under the install directory under mibs
and the repspective product line.
Note: Required version of SYNOPTICS-ROOT-MIB, must be version 199 or higher,
for example synro199.mib.
=head1 GLOBAL METHODS =head1 GLOBAL METHODS
These are methods that return scalar values from SNMP These are methods that return scalar values from SNMP
@@ -392,7 +301,7 @@ Returns the offset if port numbering does not start at 0. Defaults to 0.
=item $cdp->hasCDP() =item $cdp->hasCDP()
Is CDP is active in this device? Is SONMP is active in this device?
=item $sonmp->cdp_id() =item $sonmp->cdp_id()
@@ -402,7 +311,7 @@ Returns the IP that the device is sending out for its Nmm topology info.
=item $sonmp->cdp_run() =item $sonmp->cdp_run()
Returns if the S5-ETH-MULTISEG-TOPOLOGY info is on for this device. Returns true if SONMP is on for this device.
(B<s5EnMsTopStatus>) (B<s5EnMsTopStatus>)
@@ -417,7 +326,7 @@ Returns MAC of the advertised IP address of the device.
These are methods that return tables of information in the form of a reference These are methods that return tables of information in the form of a reference
to a hash. to a hash.
=head2 Layer2 Topology info (s5EnMsTopNmmTable) =head2 Layer2 Topology info (B<s5EnMsTopNmmTable>)
=over =over
@@ -445,7 +354,7 @@ Returns reference to hash. Key: Table entry, Value:Remote Segment ID
(B<s5EnMsTopNmmSegId>) (B<s5EnMsTopNmmSegId>)
=item $sonmp->sonmp_topo_mac =item $sonmp->sonmp_topo_mac()
(B<s5EnMsTopNmmMacAddr>) (B<s5EnMsTopNmmMacAddr>)
@@ -459,7 +368,8 @@ Returns reference to hash. Key: Table entry, Value:Remote Device Type
=item $sonmp->sonmp_topo_localseg =item $sonmp->sonmp_topo_localseg
Returns reference to hash. Key: Table entry, Value:Boolean, if bay_topo_seg() is local Returns reference to hash. Key: Table entry, Value: Boolean, if bay_topo_seg()
is local.
(B<s5EnMsTopNmmLocalSeg>) (B<s5EnMsTopNmmLocalSeg>)
@@ -473,28 +383,25 @@ All entries with port=0 are local and ignored.
=item $sonmp->c_if() =item $sonmp->c_if()
Returns reference to hash. Key: ifIndex.1 Value: port (iid) Returns reference to hash. Key: IID, Value: Local port (interfaces)
=item $sonmp->c_ip() =item $sonmp->c_ip()
Returns referenece to hash. Key: ifIndex.1 Returns reference to hash. Key: IID, Value: Remote IP address
The value of each hash entry can either be a scalar or an array. If multiple entries exist with the same local port, c_if(), with different IPv4
A scalar value is most likely a direct neighbor to that port. addresses, c_ip(), there is either a non-SONMP device in between two or
It is possible that there is a non-SONMP device in between this device and the remote device. more devices or multiple devices which are not directly connected.
An array value represents a list of seen devices. The only time you will get an array
of neighbors, is if there is a non-SONMP device in between two or more devices.
Use the data from the Layer2 Topology Table below to dig deeper. Use the data from the Layer2 Topology Table below to dig deeper.
=item $sonmp->c_port() =item $sonmp->c_port()
Returns reference to hash. Key: ifIndex.1 Value: remote port Returns reference to hash. Key: IID, Value: Remote port (interfaces)
=item $sonmp->c_platform() =item $sonmp->c_platform()
Returns reference to hash. Key: ifIndex.1 Value: Remote Device Type Returns reference to hash. Key: IID, Value: Remote device type
=back =back