From 435bb7dbe27034d1ad0bc4c39cccf747968076c2 Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Sun, 25 Nov 2012 21:45:56 -0500 Subject: [PATCH] No longer emulate CDP methods in other discovery protocol classes, use the class name as base (sonmp, fdp) rather than cdp. --- Info/FDP.pm | 73 +++++++++++++++++++---------------------- Info/SONMP.pm | 90 ++++++++++++++++++++++++++------------------------- 2 files changed, 79 insertions(+), 84 deletions(-) diff --git a/Info/FDP.pm b/Info/FDP.pm index 88bc870d..7e0c5402 100644 --- a/Info/FDP.pm +++ b/Info/FDP.pm @@ -47,13 +47,6 @@ $VERSION = '2.08'; %MIBS = ( 'FOUNDRY-SN-SWITCH-GROUP-MIB' => 'snFdpGlobalRun' ); %GLOBALS = ( - - # CDP-Compatibility - 'cdp_interval' => 'snFdpGlobalMessageInterval', - 'cdp_holdtime' => 'snFdpGlobalHoldTime', - 'cdp_id' => 'snFdpGlobalDeviceId', - - # 'fdp_run' => 'snFdpGlobalRun', 'fdp_interval' => 'snFdpGlobalMessageInterval', 'fdp_holdtime' => 'snFdpGlobalHoldTime', @@ -61,27 +54,27 @@ $VERSION = '2.08'; ); %FUNCS = ( - 'c_index' => 'snFdpCacheIfIndex', - 'c_proto' => 'snFdpCacheAddressType', - 'c_ip' => 'snFdpCacheAddress', - 'c_ver' => 'snFdpCacheVersion', - 'c_id' => 'snFdpCacheDeviceId', - 'c_port' => 'snFdpCacheDevicePort', - 'c_platform' => 'snFdpCachePlatform', - 'c_capabilities' => 'snFdpCacheCapabilities', - 'c_domain' => 'snFdpCacheVTPMgmtDomain', - 'c_vlan' => 'snFdpCacheNativeVLAN', - 'c_duplex' => 'snFdpCacheDuplex', + 'fdp_index' => 'snFdpCacheIfIndex', + 'fdp_proto' => 'snFdpCacheAddressType', + 'fdp_ip' => 'snFdpCacheAddress', + 'fdp_ver' => 'snFdpCacheVersion', + 'fdp_id' => 'snFdpCacheDeviceId', + 'fdp_port' => 'snFdpCacheDevicePort', + 'fdp_platform' => 'snFdpCachePlatform', + 'fdp_capabilities' => 'snFdpCacheCapabilities', + 'fdp_domain' => 'snFdpCacheVTPMgmtDomain', + 'fdp_vlan' => 'snFdpCacheNativeVLAN', + 'fdp_duplex' => 'snFdpCacheDuplex', ); %MUNGE = ( - 'c_capabilities' => \&SNMP::Info::munge_caps, - 'c_ip' => \&SNMP::Info::munge_ip + 'fdp_capabilities' => \&SNMP::Info::munge_caps, + 'fdp_ip' => \&SNMP::Info::munge_ip ); -sub cdp_run { +sub fdp_run { my $fdp = shift; - my $fdp_run = $fdp->fdp_run(); + my $fdp_run = $fdp->orig_fdp_run(); # if fdp_run isn't implemented on device, assume FDP is on return $fdp_run if defined $fdp_run; @@ -107,7 +100,7 @@ sub hasFDP { return $fdp->fdp_run(); } -sub c_if { +sub fdp_if { my $fdp = shift; # See if by some miracle Cisco implemented the fdpCacheIfIndex entry @@ -115,7 +108,7 @@ sub c_if { return $fdp_index if defined $fdp_index; # Nope, didn't think so. Now we fake it. - my $fdp_ip = $fdp->c_ip(); + my $fdp_ip = $fdp->fdp_ip(); unless ( defined $fdp_ip ) { $fdp->error_throw( "SNMP::Info::FDP:fdp_if() - Device doesn't have fdp_ip() data. Can't fake fdp_index()" @@ -256,19 +249,19 @@ CDP compatibility =over -=item $fdp->c_interval() +=item $fdp->fdp_interval() Interval in seconds at which FDP messages are generated. (C) -=item $fdp->c_holdtime() +=item $fdp->fdp_holdtime() Time in seconds that FDP messages are kept. (C) -=item $fdp->c_id() +=item $fdp->fdp_id() Returns FDP device ID. @@ -277,7 +270,7 @@ retrieved from remote devices with $fdp->id(). (C) -=item $cdp->cdp_run() +=item $fdp->fdp_run() Is FDP enabled on this device? @@ -294,7 +287,7 @@ CDP compatibility =over -=item $fdp->c_capabilities() +=item $fdp->fdp_capabilities() Returns Device Functional Capabilities. Results are munged into an ascii binary string, 7 digits long, MSB. Each digit represents a bit from the @@ -333,26 +326,26 @@ this information. (C) -=item $fdp->c_domain() +=item $fdp->fdp_domain() The CDP version of this returns remote VTP Management Domain as defined in C (C) -=item $fdp->c_duplex() +=item $fdp->fdp_duplex() Returns the port duplex status from remote devices. (C) -=item $fdp->c_id() +=item $fdp->fdp_id() Returns remote device id string (C) -=item $fdp->c_if() +=item $fdp->fdp_if() Returns the mapping to the SNMP Interface Table. @@ -380,7 +373,7 @@ truncate the last number off of it : return \%fdp_if; -=item $fdp->c_index() +=item $fdp->fdp_index() Returns the mapping to the SNMP2 Interface table for FDP Cache Entries. @@ -391,37 +384,37 @@ See fdp_if() entry. (C) -=item $fdp->c_ip() +=item $fdp->fdp_ip() Returns remote IP address (C) -=item $fdp->c_platform() +=item $fdp->fdp_platform() Returns remote platform id (C) -=item $fdp->c_port() +=item $fdp->fdp_port() Returns remote port ID (C) -=item $fdp->c_proto() +=item $fdp->fdp_proto() Returns remote address type received. Usually IP. (C) -=item $fdp->c_ver() +=item $fdp->fdp_ver() Returns remote hardware version (C) -=item $fdp->c_vlan() +=item $fdp->fdp_vlan() Returns the remote interface native VLAN. diff --git a/Info/SONMP.pm b/Info/SONMP.pm index b2c113e7..0322de50 100644 --- a/Info/SONMP.pm +++ b/Info/SONMP.pm @@ -1,7 +1,6 @@ # SNMP::Info::SONMP -# $Id$ # -# Copyright (c) 2008 Eric Miller +# Copyright (c) 2012 Eric Miller # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -30,6 +29,7 @@ package SNMP::Info::SONMP; +use warnings; use strict; use Exporter; use SNMP::Info; @@ -47,8 +47,8 @@ $VERSION = '2.08'; ); %GLOBALS = ( - 'cdp_id' => 's5EnMsTopIpAddr', - 'cdp_run' => 's5EnMsTopStatus', + 'sonmp_id' => 's5EnMsTopIpAddr', + 'sonmp_run' => 's5EnMsTopStatus', ); %FUNCS = ( @@ -77,12 +77,14 @@ sub port_offset { return 0; } -sub hasCDP { +sub hasSONMP { my $sonmp = shift; - return $sonmp->cdp_run(); + + return 1 if defined $sonmp->sonmp_run(); + return; } -sub c_if { +sub sonmp_if { my $sonmp = shift; my $partial = shift; @@ -93,7 +95,7 @@ sub c_if { my $port_offset = $sonmp->port_offset(); my $model = $sonmp->model(); - my %c_if; + my %sonmp_if; foreach my $entry ( keys %$sonmp_topo_port ) { my $port = $sonmp_topo_port->{$entry}; next unless defined $port; @@ -118,31 +120,31 @@ sub c_if { my $index = ( ( $slot - $slot_offset ) * $index_factor ) + ( $port - $port_offset ); - $c_if{$entry} = $index; + $sonmp_if{$entry} = $index; } - return \%c_if; + return \%sonmp_if; } -sub c_ip { +sub sonmp_ip { my $sonmp = shift; my $partial = shift; my $sonmp_topo_port = $sonmp->sonmp_topo_port($partial) || {}; my $sonmp_topo_ip = $sonmp->sonmp_topo_ip($partial) || {}; - my %c_ip; + my %sonmp_ip; foreach my $entry ( keys %$sonmp_topo_ip ) { my $port = $sonmp_topo_port->{$entry}; next unless defined $port; next if $port == 0; my $ip = $sonmp_topo_ip->{$entry}; - $c_ip{$entry} = $ip; + $sonmp_ip{$entry} = $ip; } - return \%c_ip; + return \%sonmp_ip; } -sub c_port { +sub sonmp_port { my $sonmp = shift; my $partial = shift; @@ -150,7 +152,7 @@ sub c_port { my $sonmp_topo_seg = $sonmp->sonmp_topo_seg($partial) || {}; my $sonmp_topo_platform = $sonmp->sonmp_topo_platform($partial) || {}; - my %c_port; + my %sonmp_port; foreach my $entry ( keys %$sonmp_topo_seg ) { my $port = $sonmp_topo_port->{$entry}; next unless defined $port; @@ -161,12 +163,12 @@ sub c_port { # AP-222x Series does not adhere to port numbering if ( $platform =~ /AccessPoint/i ) { - $c_port{$entry} = 'dp0'; + $sonmp_port{$entry} = 'dp0'; } # BayHubs send the lower three bytes of the MAC not the slot/port elsif ( $seg > 4000 ) { - $c_port{$entry} = 'unknown'; + $sonmp_port{$entry} = 'unknown'; } else { @@ -174,20 +176,20 @@ sub c_port { my $remote_port = $seg % 256; my $remote_slot = int( $seg / 256 ); - $c_port{$entry} = "$remote_slot.$remote_port"; + $sonmp_port{$entry} = "$remote_slot.$remote_port"; } } - return \%c_port; + return \%sonmp_port; } -sub c_platform { +sub sonmp_platform { my $sonmp = shift; my $partial = shift; my $sonmp_topo_port = $sonmp->sonmp_topo_port($partial) || {}; my $sonmp_topo_platform = $sonmp->sonmp_topo_platform($partial) || {}; - my %c_platform; + my %sonmp_platform; foreach my $entry ( keys %$sonmp_topo_platform ) { my $port = $sonmp_topo_port->{$entry}; next unless defined $port; @@ -195,9 +197,9 @@ sub c_platform { my $platform = $sonmp_topo_platform->{$entry}; - $c_platform{$entry} = $platform; + $sonmp_platform{$entry} = $platform; } - return \%c_platform; + return \%sonmp_platform; } sub mac { @@ -242,19 +244,19 @@ Eric Miller my $class = $sonmp->class(); print " Using device sub class : $class\n"; - $hascdp = $sonmp->hasCDP() ? 'yes' : 'no'; + $hassonmp = $sonmp->hasSONMP() ? 'yes' : 'no'; # Print out a map of device ports with CDP neighbors: my $interfaces = $sonmp->interfaces(); - my $c_if = $sonmp->c_if(); - my $c_ip = $sonmp->c_ip(); - my $c_port = $sonmp->c_port(); + my $sonmp_if = $sonmp->sonmp_if(); + my $sonmp_ip = $sonmp->sonmp_ip(); + my $sonmp_port = $sonmp->sonmp_port(); - foreach my $cdp_key (keys %$c_ip){ - my $iid = $c_if->{$cdp_key}; + foreach my $sonmp_key (keys %$sonmp_ip){ + my $iid = $sonmp_if->{$sonmp_key}; my $port = $interfaces->{$iid}; - my $neighbor = $c_ip->{$cdp_key}; - my $neighbor_port = $c_port->{$cdp_key}; + my $neighbor = $sonmp_ip->{$sonmp_key}; + my $neighbor_port = $sonmp_port->{$sonmp_key}; print "Port : $port connected to $neighbor / $neighbor_port\n"; } @@ -266,8 +268,8 @@ through SNMP. SONMP is a Layer 2 protocol that supplies topology information of devices that also speak SONMP, mostly switches and hubs. SONMP is implemented in -SynOptics, Bay, and Nortel devices. SONMP has been rebranded by Bay then -Nortel and is know by several different names, most recently Nortel +SynOptics, Bay, Nortel, and Avaya devices. SONMP has been rebranded by Bay +then Nortel and may be referred to by several different names, including Nortel Discovery Protocol (NDP). Create or use a device subclass that inherits this class. Do not use @@ -309,17 +311,17 @@ Returns the offset if slot numbering does not start at 0. Defaults to 1. Returns the offset if port numbering does not start at 0. Defaults to 0. -=item $cdp->hasCDP() +=item $sonmp->hasSONMP() Is SONMP is active in this device? -=item $sonmp->cdp_id() +=item $sonmp->sonmp_id() Returns the IP that the device is sending out for its Nmm topology info. (C) -=item $sonmp->cdp_run() +=item $sonmp->sonmp_run() Returns true if SONMP is on for this device. @@ -386,31 +388,31 @@ bay_topo_seg() is local. =back -=head2 Pseudo CDP information +=head2 Common topology information All entries with port=0 are local and ignored. =over -=item $sonmp->c_if() +=item $sonmp->sonmp_if() Returns reference to hash. Key: IID, Value: Local port (interfaces) -=item $sonmp->c_ip() +=item $sonmp->sonmp_ip() Returns reference to hash. Key: IID, Value: Remote IP address -If multiple entries exist with the same local port, c_if(), with different -IPv4 addresses, c_ip(), there is either a non SONMP device in between two or +If multiple entries exist with the same local port, sonmp_if(), with different +IPv4 addresses, sonmp_ip(), there is either a non SONMP device in between two or more devices or multiple devices which are not directly connected. Use the data from the Layer2 Topology Table below to dig deeper. -=item $sonmp->c_port() +=item $sonmp->sonmp_port() Returns reference to hash. Key: IID, Value: Remote port (interfaces) -=item $sonmp->c_platform() +=item $sonmp->sonmp_platform() Returns reference to hash. Key: IID, Value: Remote device type