How to properly map switch interfaces to LLDP devices using SNMP

Viewed 219

I'm trying to map devices found using LLDP on a switch to a specific interface on that switch.

If I SSH into the switch, I can tell there is a device on its port 6 (interface 6). enter image description here

If I run snmpwalk looking at the lldpRemEntry, I can see the same device.

snmpwalk -c community -v 2c $IP 1.0.8802.1.1.2.1.4.1.1 | grep 0.6
iso.0.8802.1.1.2.1.4.1.1.4.0.6.32 = INTEGER: 5
iso.0.8802.1.1.2.1.4.1.1.5.0.6.32 = Hex-STRING: 01 0A 63 29 07
iso.0.8802.1.1.2.1.4.1.1.6.0.6.32 = INTEGER: 7
iso.0.8802.1.1.2.1.4.1.1.7.0.6.32 = STRING: "0008303043F4:P1"
iso.0.8802.1.1.2.1.4.1.1.8.0.6.32 = STRING: "SW PORT"
iso.0.8802.1.1.2.1.4.1.1.9.0.6.32 = STRING: "SEP0008303043F4"
iso.0.8802.1.1.2.1.4.1.1.10.0.6.32 = STRING: "Cisco IP Phone 7965G,V11, SCCP45.9-4-2SR4-3S"
iso.0.8802.1.1.2.1.4.1.1.11.0.6.32 = Hex-STRING: 24 00
iso.0.8802.1.1.2.1.4.1.1.12.0.6.32 = Hex-STRING: 24 00

However, when looking at the ifIndex of the same switch, I don't see the same value (I'm expecting 6). Instead, I see these values for the interface id.

snmpwalk -c community -v 2c $IP 1.3.6.1.2.1.2.2.1.1
iso.3.6.1.2.1.2.2.1.1.1 = INTEGER: 1
iso.3.6.1.2.1.2.2.1.1.10 = INTEGER: 10
iso.3.6.1.2.1.2.2.1.1.30 = INTEGER: 30
iso.3.6.1.2.1.2.2.1.1.41 = INTEGER: 41
iso.3.6.1.2.1.2.2.1.1.999 = INTEGER: 999
iso.3.6.1.2.1.2.2.1.1.5179 = INTEGER: 5179
iso.3.6.1.2.1.2.2.1.1.5180 = INTEGER: 5180
iso.3.6.1.2.1.2.2.1.1.5181 = INTEGER: 5181
iso.3.6.1.2.1.2.2.1.1.10101 = INTEGER: 10101
iso.3.6.1.2.1.2.2.1.1.10102 = INTEGER: 10102
iso.3.6.1.2.1.2.2.1.1.10103 = INTEGER: 10103
iso.3.6.1.2.1.2.2.1.1.10104 = INTEGER: 10104
iso.3.6.1.2.1.2.2.1.1.10105 = INTEGER: 10105
iso.3.6.1.2.1.2.2.1.1.10106 = INTEGER: 10106
iso.3.6.1.2.1.2.2.1.1.10107 = INTEGER: 10107
iso.3.6.1.2.1.2.2.1.1.10108 = INTEGER: 10108
iso.3.6.1.2.1.2.2.1.1.10109 = INTEGER: 10109
iso.3.6.1.2.1.2.2.1.1.10110 = INTEGER: 10110
iso.3.6.1.2.1.2.2.1.1.10111 = INTEGER: 10111
iso.3.6.1.2.1.2.2.1.1.10112 = INTEGER: 10112
iso.3.6.1.2.1.2.2.1.1.10113 = INTEGER: 10113
iso.3.6.1.2.1.2.2.1.1.10114 = INTEGER: 10114
iso.3.6.1.2.1.2.2.1.1.10115 = INTEGER: 10115
iso.3.6.1.2.1.2.2.1.1.10116 = INTEGER: 10116
iso.3.6.1.2.1.2.2.1.1.10117 = INTEGER: 10117
iso.3.6.1.2.1.2.2.1.1.10118 = INTEGER: 10118
iso.3.6.1.2.1.2.2.1.1.10119 = INTEGER: 10119
iso.3.6.1.2.1.2.2.1.1.10120 = INTEGER: 10120
iso.3.6.1.2.1.2.2.1.1.10121 = INTEGER: 10121
iso.3.6.1.2.1.2.2.1.1.10122 = INTEGER: 10122
iso.3.6.1.2.1.2.2.1.1.10123 = INTEGER: 10123
iso.3.6.1.2.1.2.2.1.1.10124 = INTEGER: 10124
iso.3.6.1.2.1.2.2.1.1.10125 = INTEGER: 10125
iso.3.6.1.2.1.2.2.1.1.10126 = INTEGER: 10126
iso.3.6.1.2.1.2.2.1.1.10201 = INTEGER: 10201
iso.3.6.1.2.1.2.2.1.1.10202 = INTEGER: 10202
iso.3.6.1.2.1.2.2.1.1.14001 = INTEGER: 14001
iso.3.6.1.2.1.2.2.1.1.14002 = INTEGER: 14002

With these for the names (ifName):

snmpwalk -c community -v 2c $IP 1.3.6.1.2.1.31.1.1.1.1
iso.3.6.1.2.1.31.1.1.1.1.1 = STRING: "Vl1"
iso.3.6.1.2.1.31.1.1.1.1.10 = STRING: "Vl10"
iso.3.6.1.2.1.31.1.1.1.1.30 = STRING: "Vl30"
iso.3.6.1.2.1.31.1.1.1.1.41 = STRING: "Vl41"
iso.3.6.1.2.1.31.1.1.1.1.999 = STRING: "Vl999"
iso.3.6.1.2.1.31.1.1.1.1.5179 = STRING: "StackPort1"
iso.3.6.1.2.1.31.1.1.1.1.5180 = STRING: "StackSub-St1-1"
iso.3.6.1.2.1.31.1.1.1.1.5181 = STRING: "StackSub-St1-2"
iso.3.6.1.2.1.31.1.1.1.1.10101 = STRING: "Gi1/0/1"
iso.3.6.1.2.1.31.1.1.1.1.10102 = STRING: "Gi1/0/2"
iso.3.6.1.2.1.31.1.1.1.1.10103 = STRING: "Gi1/0/3"
iso.3.6.1.2.1.31.1.1.1.1.10104 = STRING: "Gi1/0/4"
iso.3.6.1.2.1.31.1.1.1.1.10105 = STRING: "Gi1/0/5"
iso.3.6.1.2.1.31.1.1.1.1.10106 = STRING: "Gi1/0/6"
iso.3.6.1.2.1.31.1.1.1.1.10107 = STRING: "Gi1/0/7"
iso.3.6.1.2.1.31.1.1.1.1.10108 = STRING: "Gi1/0/8"
iso.3.6.1.2.1.31.1.1.1.1.10109 = STRING: "Gi1/0/9"
iso.3.6.1.2.1.31.1.1.1.1.10110 = STRING: "Gi1/0/10"
iso.3.6.1.2.1.31.1.1.1.1.10111 = STRING: "Gi1/0/11"
iso.3.6.1.2.1.31.1.1.1.1.10112 = STRING: "Gi1/0/12"
iso.3.6.1.2.1.31.1.1.1.1.10113 = STRING: "Gi1/0/13"
iso.3.6.1.2.1.31.1.1.1.1.10114 = STRING: "Gi1/0/14"
iso.3.6.1.2.1.31.1.1.1.1.10115 = STRING: "Gi1/0/15"
iso.3.6.1.2.1.31.1.1.1.1.10116 = STRING: "Gi1/0/16"
iso.3.6.1.2.1.31.1.1.1.1.10117 = STRING: "Gi1/0/17"
iso.3.6.1.2.1.31.1.1.1.1.10118 = STRING: "Gi1/0/18"
iso.3.6.1.2.1.31.1.1.1.1.10119 = STRING: "Gi1/0/19"
iso.3.6.1.2.1.31.1.1.1.1.10120 = STRING: "Gi1/0/20"
iso.3.6.1.2.1.31.1.1.1.1.10121 = STRING: "Gi1/0/21"
iso.3.6.1.2.1.31.1.1.1.1.10122 = STRING: "Gi1/0/22"
iso.3.6.1.2.1.31.1.1.1.1.10123 = STRING: "Gi1/0/23"
iso.3.6.1.2.1.31.1.1.1.1.10124 = STRING: "Gi1/0/24"
iso.3.6.1.2.1.31.1.1.1.1.10125 = STRING: "Gi1/0/25"
iso.3.6.1.2.1.31.1.1.1.1.10126 = STRING: "Gi1/0/26"
iso.3.6.1.2.1.31.1.1.1.1.10201 = STRING: "Te1/0/1"
iso.3.6.1.2.1.31.1.1.1.1.10202 = STRING: "Te1/0/2"
iso.3.6.1.2.1.31.1.1.1.1.14001 = STRING: "Nu0"
iso.3.6.1.2.1.31.1.1.1.1.14002 = STRING: "Fa0"

So I can tell by looking that the index 10106 is the one that has the device on it because it's name matches the local interface name seen when I SSH into the switch. But how do I link these programmatically only using SNMP commands? I tried using the dot1dBasePortIfIndex, but it for some reason doesn't provide all the interfaces to me.

snmpwalk -c community -v 2c $IP 1.3.6.1.2.1.17.1.4.1.2
iso.3.6.1.2.1.17.1.4.1.2.2 = INTEGER: 10102
iso.3.6.1.2.1.17.1.4.1.2.7 = INTEGER: 10107
iso.3.6.1.2.1.17.1.4.1.2.8 = INTEGER: 10108
iso.3.6.1.2.1.17.1.4.1.2.10 = INTEGER: 10110
iso.3.6.1.2.1.17.1.4.1.2.13 = INTEGER: 10113
iso.3.6.1.2.1.17.1.4.1.2.14 = INTEGER: 10114
iso.3.6.1.2.1.17.1.4.1.2.15 = INTEGER: 10115
iso.3.6.1.2.1.17.1.4.1.2.16 = INTEGER: 10116
iso.3.6.1.2.1.17.1.4.1.2.17 = INTEGER: 10117
iso.3.6.1.2.1.17.1.4.1.2.18 = INTEGER: 10118
iso.3.6.1.2.1.17.1.4.1.2.19 = INTEGER: 10119
iso.3.6.1.2.1.17.1.4.1.2.20 = INTEGER: 10120
iso.3.6.1.2.1.17.1.4.1.2.21 = INTEGER: 10121
iso.3.6.1.2.1.17.1.4.1.2.23 = INTEGER: 10123
iso.3.6.1.2.1.17.1.4.1.2.24 = INTEGER: 10124
iso.3.6.1.2.1.17.1.4.1.2.25 = INTEGER: 10125
iso.3.6.1.2.1.17.1.4.1.2.26 = INTEGER: 10126
iso.3.6.1.2.1.17.1.4.1.2.27 = INTEGER: 10201
iso.3.6.1.2.1.17.1.4.1.2.28 = INTEGER: 10202

I'm missing something, but I just don't know what it is. Thanks for the help.

2 Answers

LLDP-MIB contains the following in the description of the LldpPortNumber type:

A port number has no mandatory relationship to an
InterfaceIndex object (of the interfaces MIB, IETF RFC 2863).
If the LLDP agent is a IEEE 802.1D, IEEE 802.1Q bridge, the
LldpPortNumber will have the same value as the dot1dBasePort
object (defined in IETF RFC 1493) associated corresponding
bridge port.  If the system hosting LLDP agent is not an
IEEE 802.1D or an IEEE 802.1Q bridge, the LldpPortNumber
will have the same value as the corresponding interface's
InterfaceIndex object.

It looks like you have discovered this fact, as you mentioned you checked the dot1dBasePortIfIndex. The key thing that you are missing is that Cisco uses something called "community string indexing" for some MIBs, including BRIDGE-MIB. You can find more information at this link if you are interested. In short, you have to incorporate the VLAN number into the community string in order to view the entries for the ports on that VLAN. So if your community string is public and your port is on VLAN 100, then you would need to use public@100 for your community string in order to see the dot1dBasePortIfIndex for that port.

As @TallChuck pointed out, there's no relationship between those indexes. However for at least Cisco IOS devices, including the one you're working on, you can tie that index of 6 using LLDP-MIB::lldpLocPortDesc (or .1.0.8802.1.1.2.1.3.7.1.4). The fields returned are the full names of the interfaces, and match the fields returned from IF-MIB::ifDescr (or .1.3.6.1.2.1.2.2.1.2)

$snmpwalk -v2c -c community 10.10.10.10 LLDP-MIB::lldpLocPortDesc
LLDP-MIB::lldpLocPortDesc.1 = STRING: GigabitEthernet1/0/1
LLDP-MIB::lldpLocPortDesc.2 = STRING: GigabitEthernet1/0/2
...

$snmpwalk -v2c -c community 10.10.10.10 IF-MIB::ifDescr
IF-MIB::ifDescr.10101 = STRING: GigabitEthernet1/0/1
IF-MIB::ifDescr.10102 = STRING: GigabitEthernet1/0/2
...

So in my case, an LLDP neighbor with an index of 2 can be tied to the switch's interface index 10102 via the string GigabitEthernet1/0/2.

One last note, dot1dBasePortIfIndex is a separate indexing system from LLDP, and only indexes layer2 interfaces. This is probably why you didn't see all interfaces listed.

Related