A class for performing SNMP V2 queries on Cisco devices

copyright Copyright (c) 2012, Open Source Solutions Limited, Dublin, Ireland
author Barry O'Donovan

 Methods

An extension of `collapseLAGs()` to work with `crawl()` and `linkTopology()`.

collapseDevicesLAGs(array $devices) : array
Rather than taking the input from `neighbours()`, it takes input from `crawl()` or `linkTopology()` and processes all neighbours.
see

Parameters

$devices

array

The result of a call to crawl() or linkTopology()

Returns

arrayProcessed CDP neighbours with LAG ports collapsed

Utility function to process the output from neighbours() and remove individual trunk ports leaving only single LAG links.

collapseLAGs(array $neighbours) : array
For example, here's a sample return for a switch with a neighbour connected with a LAG / PortChannel: array(2) { ["cr-sw01.example.ie"] => array(2) { [0] => array(11) { ["localPortId"] => int(10111) ["localPortName"] => string(8) "Gi1/0/11" ["localPort"] => string(21) "GigabitEthernet1/0/11" ["isLAG"] => bool(true) ["lagPortId"] => int(5048) ["lagPortName"] => string(4) "Po48" ["remotePort"] => string(21) "GigabitEthernet1/0/11" ["remotePortId"] => int(10111) ["remotePortName"] => string(8) "Gi1/0/11" ["remoteLagPortId"] => int(5048) ["remoteLagPortName"] => string(4) "Po48" } [1] => array(11) { ["localPortId"] => int(10112) ["localPortName"] => string(8) "Gi1/0/12" ["localPort"] => string(21) "GigabitEthernet1/0/12" ["isLAG"] => bool(true) ["lagPortId"] => int(5048) ["lagPortName"] => string(4) "Po48" ["remotePort"] => string(21) "GigabitEthernet1/0/12" ["remotePortId"] => int(10112) ["remotePortName"] => string(8) "Gi1/0/12" ["remoteLagPortId"] => int(5048) ["remoteLagPortName"] => string(4) "Po48" } } ... } The result of this function would be: array(2) { ["cr-sw01.example.ie"] => array(1) { [0] => array(11) { ["localPortId"] => int(5048) ["localPortName"] => string(8) "Po48" ["localPort"] => string(21) "Po48" ["isLAG"] => bool(true) ["lagPortId"] => int(5048) ["lagPortName"] => string(4) "Po48" ["remotePort"] => string(21) "Po48" ["remotePortId"] => int(5048) ["remotePortName"] => string(8) "Po48" ["remoteLagPortId"] => int(5048) ["remoteLagPortName"] => string(4) "Po48" } } ... }
see

Parameters

$neighbours

array

The result of a call to neighbours()

Returns

arrayProcessed CDP neighbours with LAG ports collapsed

Recursivily crawls all CDP neighbours to build up a flat array of all devices indexed by the CDP device id.

crawl(array $devices = array(), string $device = null, array $ignore = array()) : array
Array form is same as that returned by neighbours()
see

Parameters

$devices

array

Unless you're doing something funky, just pass an empty array. This is where the result will be found.

$device

string

CDP device ID of next host to crawl. On first pass, set to null - used internally when recursing

$ignore

array

An array of CDP device IDs to ignore. I.e. to not include in recursive crawling

Returns

arrayThe resultant array of all crawled devices (same as that passed in the @param $devices parameter)

Get the SNMP instance

getSNMP() : \OSS_SNMP\SNMP

Returns

\OSS_SNMP\SNMPInstance of the SNMP object

Get the time for the receiving device holds CDP message

globalHoldTime() : int
> The time for the receiving device holds CDP message. > The default value is 180 seconds."

Returns

intThe time for the receiving device holds CDP message

The time when the cache table was last changed

globalLastChange() : int
> Indicates the time when the cache table was last changed. It > is the most recent time at which any row was last created, > modified or deleted.

Returns

intThe time (timeticks) when the cache table was last changed

Get the interval at which CDP messages are to be generated

globalMessageInterval() : int
> The interval at which CDP messages are to be generated. > The default value is 60 seconds.

Returns

intThe interval at which CDP messages are to be generated

Get the device's global CDP (Cisco Discovery Protocol) run status

globalRun() : boolean
> An indication of whether the Cisco Discovery Protocol is currently > running. Entries in cdpCacheTable are deleted when CDP is disabled.

Returns

booleanTrue if enabled globally, else false

Get the device's CDP (Cisco Discovery Protocol) ID

id() : string

Returns

stringThe device's CDP (Cisco Discovery Protocol) ID

Get the device's interfaces CDP enabled status

interfaceEnabled() : array
Applies the TruthValue post processor to turn SNMP values into true / false.
see

Returns

arrayThe device's interfaces CDP enabled status' (as boolean true / false)

Get the device's interface names as seen in CDP

interfaceNames() : array
> The name of the local interface as advertised by CDP in the Port-ID TLV

Returns

arrayThe device's interface names as seen in CDP

Find the layer 2 topology as an array with no link mentioned more than once.

linkTopology(array $devices = null) : array
Huh? This function: * takes the result of crawl() (or calls crawl()) to get the CDP topology; * foreach device, builds an array of device to device links; * SO LONG as that link has already not been accounted for in the other direction. I.e. if a link is found A -> B, then the same B -> A link will not be included. The primary differences to the return value of this and crawl() are: * links only appear once (unidirectional) rather than twice (bidirectional) * the links are indexed by the localPortName rather than an integer index: [cr-sw04.degkcp.example.ie] => Array ( [cd-sw02.degkcp.example.ie] => Array ( [GigabitEthernet1/0/3] => Array ( [remotePort] => FastEthernet0/1 [isLAG] => false ........ ) ) All port information is copied over from the supplied / called `crawl()` array
see

Parameters

$devices

array

The result of crawl() (if null, this function performs a crawl())

Returns

arrayL2 topology as described above.

Get the CDP neighbours' address type indexed by the current device's port ID

neighbourAddressTypes(boolean $translate = false) : array
> An indication of the type of address contained in the corresponding instance of cdpCacheAddress

Parameters

$translate

boolean

If true, return the string representation via self::$VTP_VLAN_TYPES

Returns

arrayThe CDP neighbours' address type indexed by the current device's port ID

Get the device's CDP neighbour addresses indexed by the current device's port ID

neighbourAddresses() : array
> The (first) network-layer address of the device > as reported in the Address TLV of the most recently received > CDP message. For example, if the corresponding instance of > cacheAddressType had the value 'ip(1)', then this object > would be an IPv4-address. If the neighbor device is > SNMP-manageable, it is supposed to generate its CDP messages > such that this address is one at which it will receive SNMP > messages. Use cdpCtAddressTable to extract the remaining > addresses from the Address TLV received most recently."

Returns

arrayThe device's CDP neighbour addresses indexed by the current device's port ID

Get an array of individual capabilities of a given neighbour (by connected port ID)

neighbourCapabilities(int $portId, int $translate = false) : array
Example: print_r( $host->useCisco_CDP()->neighbourCapabilities( 10111 ) ) [0] => 8 // self::CDP_CACHE_NEIGHBOUR_CAPABILITY_SWITCH [1] => 32 // self::CDP_CACHE_NEIGHBOUR_CAPABILITY_IGMP_CAPABLE print_r( $host->useCisco_CDP()->neighbourCapabilities( 10111, true ) ) [0] => "Switch" // self::CDP_CACHE_NEIGHBOUR_CAPABILITY_SWITCH [1] => "IGMP Capable" // self::CDP_CACHE_NEIGHBOUR_CAPABILITY_IGMP_CAPABLE

Parameters

$portId

int

The CDP neighbour by connected local port ID

$translate

int

Set to true to return descriptions rather than integers

Returns

arrayIndividual capabilities of a given neighbour

Get the device's CDP neighbour capabilities (as a decimal integer) indexed by the current device's port ID

neighbourCapability() : array
> The Device's Functional Capabilities as reported in the most > recent CDP message. For latest set of specific values, see > the latest version of the CDP specification. The zero-length > string indicates no Capabilities field (TLV) was reported in > the most recent CDP message."
see "Cisco Discovery Protocol Specification, 10/19/94."
see
see

Returns

arrayThe device's CDP neighbour capabilities (as a decimal integer) indexed by the current device's port ID

Get the remote device's interface's duplex mode (indexed by local portId)

neighbourDuplexMode(boolean $translate = false) : array
> he remote device's interface's duplex mode, as reported in the > most recent CDP message. The value unknown(1) indicates > no duplex mode field (TLV) was reported in the most > recent CDP message."

Parameters

$translate

boolean

If true, return the string representation via self::$VTP_VLAN_TYPES

Returns

arrayThe remote device's interface's duplex mode (indexed by local portId)

Query if a given neighbour (by connected port ID) has the given capability

neighbourHasCapability(int $portId, int $capability) : boolean
Example: if( $host->useCisco_CDP()->neighbourHasCapability( $portId, \OSS_SNMP\SNMP\MIBS\Cisco\CDP::CDP_CACHE_NEIGHBOUR_CAPABILITY_SWITCH ) echo "Host is a switch!!";

Parameters

$portId

int

The CDP neighbour by connected local port ID

$capability

int

The capability to query for (defined by self::CDP_CACHE_NEIGHBOUR_CAPABILITY_XXX constants)

Returns

booleanTrue if the neighbour has the given capability

Get the device's CDP neighbours (by their CDP ID) indexed by the current device's port ID

neighbourId() : array
> The Device-ID string as reported in the most recent CDP > message. The zero-length string indicates no Device-ID > field (TLV) was reported in the most recent CDP message."

Returns

arrayThe device's CDP neighbours (by their CDP ID) indexed by the current device's port ID

Get the remote device's last change time (indexed by local portId)

neighbourLastChange() : array
> Indicates the time when this cache entry was last changed. > This object is initialised to the current time when the entry > gets created and updated to the current time whenever the value > of any (other) object instance in the corresponding row is > modified."

Returns

arrayThe remote device's last change time(indexed by local portId)

Get the remote device's interface's native VLAN (indexed by local portId)

neighbourNativeVLAN() : array
> The remote device's interface's native VLAN, as reported in the > most recent CDP message. The value 0 indicates > no native VLAN field (TLV) was reported in the most > recent CDP message.

Returns

arrayThe remote device's interface's native VLAN (indexed by local portId)

Get the device's CDP neighbour platforms indexed by the current device's port ID

neighbourPlatforms() : array
> The Device's Hardware Platform as reported in the most recent CDP > message. The zero-length string indicates that no Platform field > (TLV) was reported in the most recent CDP message.

Returns

arrayThe device's CDP neighbour platforms indexed by the current device's port ID

Get the device's CDP neighbours connected port description indexed by the current device's port ID

neighbourPort() : array
E.g. a sample call may return: Array ( [10101] => GigabitEthernet0/1 [10102] => FastEthernet0/2 [10103] => GigabitEthernet1/0/24 [10105] => GigabitEthernet1/0/2 ) meaning, for example, that our local port with ID `10101` is connected to port `GigabitEthernet0/1` on the neighbour connected to that local port. You can discover the neighbour ID via `neighbourId()`. > The Port-ID string as reported in the most recent CDP > message. This will typically be the value of the ifName > object (e.g., 'Ethernet0'). The zero-length string > indicates no Port-ID field (TLV) was reported in the > most recent CDP message.
see

Returns

arrayThe device's CDP neighbours connected port *description* indexed by the current device's port ID

Get the device's CDP neighbours' VTP management domain indexed by the current device's port ID

neighbourVTPMgmtDomain() : array
> The VTP Management Domain for the remote device's interface, > as reported in the most recently received CDP message. This > object is not instantiated if no VTP Management Domain field > (TLV) was reported in the most recently received CDP message.
see "managementDomainName in CISCO-VTP-MIB"

Returns

arrayThe device's CDP neighbours' VTP management domain indexed by the current device's port ID

Get the device's CDP neighbour version indexed by the current device's port ID

neighbourVersions() : array
> The Version string as reported in the most recent CDP > message. The zero-length string indicates no Version > field (TLV) was reported in the most recent CDP message."

Returns

arrayThe device's CDP neighbour version indexed by the current device's port ID

CDP utility function to get all CDP neighbours and their connected ports.

neighbours(boolean $inverse = false, array $skipHostIds = null) : array
Returns an array of neighbours indexed by the neighbour CDP ID with a lot of details. For example, here's a sample return for a switch with two neighbours where one neighbour is connected with a LAG / PortChannel and `$inverse` was set to true. array(2) { ["cr-sw07.example.ie"] => array(1) { [0] => array(7) { ["localPortId"] => int(10103) ["localPortName"] => string(7) "Gi1/0/3" ["localPort"] => string(20) "GigabitEthernet1/0/3" ["isLAG"] => bool(false) ["remotePort"] => string(21) "GigabitEthernet1/0/24" ["remotePortId"] => int(10124) ["remotePortName"] => string(8) "Gi1/0/24" } } ["cr-sw01.example.ie"] => array(2) { [0] => array(11) { ["localPortId"] => int(10111) ["localPortName"] => string(8) "Gi1/0/11" ["localPort"] => string(21) "GigabitEthernet1/0/11" ["isLAG"] => bool(true) ["lagPortId"] => int(5048) ["lagPortName"] => string(4) "Po48" ["remotePort"] => string(21) "GigabitEthernet1/0/11" ["remotePortId"] => int(10111) ["remotePortName"] => string(8) "Gi1/0/11" ["remoteLagPortId"] => int(5048) ["remoteLagPortName"] => string(4) "Po48" } [1] => array(11) { ["localPortId"] => int(10112) ["localPortName"] => string(8) "Gi1/0/12" ["localPort"] => string(21) "GigabitEthernet1/0/12" ["isLAG"] => bool(true) ["lagPortId"] => int(5048) ["lagPortName"] => string(4) "Po48" ["remotePort"] => string(21) "GigabitEthernet1/0/12" ["remotePortId"] => int(10112) ["remotePortName"] => string(8) "Gi1/0/12" ["remoteLagPortId"] => int(5048) ["remoteLagPortName"] => string(4) "Po48" } }
see
see
see

Parameters

$inverse

boolean

If true, all remoteXXX params will be discovered (only remotePort is returned otherwise)

$skipHostIds

array

If using $inverse, pass an array of CDP IDs of neighbours that should not be 'inverse' discovered.

Returns

arrayCDP neighbours and their connected ports

Set the SNMP instance

setSNMP(\OSS_SNMP\SNMP $snmp) : \OSS_SNMP\MIB

Parameters

$snmp

\OSS_SNMP\SNMP

the SNMP instance

Returns

\OSS_SNMP\MIBAn instance of this class for fluent interfaces

 Properties

 

Text representation of CDP neighbour address type

$CDP_CACHE_NEIGHBOUR_ADDRESS_TYPES : array

Default

array(self::CDP_CACHE_NEIGHBOUR_ADDRESS_TYPE_IP => 'ip')
Static
see
 

Text representation of CDP capabilities

$CDP_CACHE_NEIGHBOUR_CAPABILITIES : array

Default

array(self::CDP_CACHE_NEIGHBOUR_CAPABILITY_ROUTER => 'Router', self::CDP_CACHE_NEIGHBOUR_CAPABILITY_TRANSPARENT_BRIDGE => 'Transparent Bridge', self::CDP_CACHE_NEIGHBOUR_CAPABILITY_SOURCE_ROUTE_BRIDGE => 'Source Route Bridge', self::CDP_CACHE_NEIGHBOUR_CAPABILITY_SWITCH => 'Switch', self::CDP_CACHE_NEIGHBOUR_CAPABILITY_HOST => 'Host', self::CDP_CACHE_NEIGHBOUR_CAPABILITY_IGMP_CAPABLE => 'IGMP Capable', self::CDP_CACHE_NEIGHBOUR_CAPABILITY_REPEATER => 'Repeater')
Static
see
 

Text representation of CDP capabilities

$CDP_CACHE_NEIGHBOUR_DUPLEXES : array

Default

array(self::CDP_CACHE_NEIGHBOUR_DUPLEX_UNKNOWN => 'unknown', self::CDP_CACHE_NEIGHBOUR_DUPLEX_HALF => 'half-duplex', self::CDP_CACHE_NEIGHBOUR_DUPLEX_FULL => 'full-duplex')
Static
see
 

Instance for the SNMP object

$_snmp 

Default

null

 Constants

 

Constant for possible value of CDP neighbour address type

CDP_CACHE_NEIGHBOUR_ADDRESS_TYPE_IP = 1 
see
 

Constant for possible value of CDP neighbour capability

CDP_CACHE_NEIGHBOUR_CAPABILITY_HOST = 16 
see
 

Constant for possible value of CDP neighbour capability

CDP_CACHE_NEIGHBOUR_CAPABILITY_IGMP_CAPABLE = 32 
see
 

Constant for possible value of CDP neighbour capability

CDP_CACHE_NEIGHBOUR_CAPABILITY_REPEATER = 64 
see
 

Constant for possible value of CDP neighbour capability

CDP_CACHE_NEIGHBOUR_CAPABILITY_ROUTER = 1 
see
 

Constant for possible value of CDP neighbour capability

CDP_CACHE_NEIGHBOUR_CAPABILITY_SOURCE_ROUTE_BRIDGE = 4 
see
 

Constant for possible value of CDP neighbour capability

CDP_CACHE_NEIGHBOUR_CAPABILITY_SWITCH = 8 
see
 

Constant for possible value of CDP neighbour capability

CDP_CACHE_NEIGHBOUR_CAPABILITY_TRANSPARENT_BRIDGE = 2 
see
 

Constant for possible value of CDP neighbour duplex

CDP_CACHE_NEIGHBOUR_DUPLEX_FULL = 3 
see
 

Constant for possible value of CDP neighbour duplex

CDP_CACHE_NEIGHBOUR_DUPLEX_HALF = 2 
see
 

Constant for possible value of CDP neighbour duplex

CDP_CACHE_NEIGHBOUR_DUPLEX_UNKNOWN = 1 
see
 

OID_CDP_CACHE_NEIGHBOUR_ADDRESS

OID_CDP_CACHE_NEIGHBOUR_ADDRESS = '.1.3.6.1.4.1.9.9.23.1.2.1.1.4' 
 

OID_CDP_CACHE_NEIGHBOUR_ADDRESS_TYPE

OID_CDP_CACHE_NEIGHBOUR_ADDRESS_TYPE = '.1.3.6.1.4.1.9.9.23.1.2.1.1.3' 
 

OID_CDP_CACHE_NEIGHBOUR_CAPABILITY

OID_CDP_CACHE_NEIGHBOUR_CAPABILITY = '.1.3.6.1.4.1.9.9.23.1.2.1.1.9' 
 

OID_CDP_CACHE_NEIGHBOUR_DUPLEX

OID_CDP_CACHE_NEIGHBOUR_DUPLEX = '.1.3.6.1.4.1.9.9.23.1.2.1.1.12' 
 

OID_CDP_CACHE_NEIGHBOUR_ID

OID_CDP_CACHE_NEIGHBOUR_ID = '.1.3.6.1.4.1.9.9.23.1.2.1.1.6' 
 

OID_CDP_CACHE_NEIGHBOUR_LAST_CHANGE

OID_CDP_CACHE_NEIGHBOUR_LAST_CHANGE = '.1.3.6.1.4.1.9.9.23.1.2.1.1.24' 
 

OID_CDP_CACHE_NEIGHBOUR_NATIVE_VLAN

OID_CDP_CACHE_NEIGHBOUR_NATIVE_VLAN = '.1.3.6.1.4.1.9.9.23.1.2.1.1.11' 
 

OID_CDP_CACHE_NEIGHBOUR_PLATFORM

OID_CDP_CACHE_NEIGHBOUR_PLATFORM = '.1.3.6.1.4.1.9.9.23.1.2.1.1.8' 
 

OID_CDP_CACHE_NEIGHBOUR_PORT

OID_CDP_CACHE_NEIGHBOUR_PORT = '.1.3.6.1.4.1.9.9.23.1.2.1.1.7' 
 

OID_CDP_CACHE_NEIGHBOUR_VERSION

OID_CDP_CACHE_NEIGHBOUR_VERSION = '.1.3.6.1.4.1.9.9.23.1.2.1.1.5' 
 

OID_CDP_CACHE_NEIGHBOUR_VTP_MGMT_DOMAIN

OID_CDP_CACHE_NEIGHBOUR_VTP_MGMT_DOMAIN = '.1.3.6.1.4.1.9.9.23.1.2.1.1.10' 
 

OID_CDP_GLOBAL_DEVICE_ID

OID_CDP_GLOBAL_DEVICE_ID = '.1.3.6.1.4.1.9.9.23.1.3.4.0' 
 

OID_CDP_GLOBAL_HOLDTIME

OID_CDP_GLOBAL_HOLDTIME = '.1.3.6.1.4.1.9.9.23.1.3.3.0' 
 

OID_CDP_GLOBAL_LAST_CHANGE

OID_CDP_GLOBAL_LAST_CHANGE = '.1.3.6.1.4.1.9.9.23.1.3.5.0' 
 

OID_CDP_GLOBAL_MESSAGE_INTERVAL

OID_CDP_GLOBAL_MESSAGE_INTERVAL = '.1.3.6.1.4.1.9.9.23.1.3.2.0' 
 

OID_CDP_GLOBAL_RUN

OID_CDP_GLOBAL_RUN = '.1.3.6.1.4.1.9.9.23.1.3.1.0' 
 

OID_CDP_INTERFACE_ENABLED

OID_CDP_INTERFACE_ENABLED = '.1.3.6.1.4.1.9.9.23.1.1.1.1.2' 
 

OID_CDP_INTERFACE_NAME

OID_CDP_INTERFACE_NAME = '.1.3.6.1.4.1.9.9.23.1.1.1.1.6'