--- a/pvl/snmp/bridge.py Tue Mar 18 21:24:18 2014 +0200
+++ b/pvl/snmp/bridge.py Tue Mar 18 21:24:35 2014 +0200
@@ -10,6 +10,8 @@
SNMP:
BRIDGE-MIB::dot1dTpFdbTable
+ Q-BRIDGE-MIB::dot1qTpFdbTable
+ Q-BRIDGE-MIB::dot1qVlanCurrentTable
"""
@@ -23,6 +25,10 @@
DOT1D_TP_AGING_TIME = pysnmp.MibVariable('BRIDGE-MIB', 'dot1dTpAgingTime', 0)
DOT1D_TP_FDB_PORT = pysnmp.MibVariable('BRIDGE-MIB', 'dot1dTpFdbPort')
+DOT1Q_VLAN_FDB_ID = pysnmp.MibVariable('Q-BRIDGE-MIB', 'dot1qVlanFdbId') # [dot1qVlanIndex]
+
+DOT1Q_TP_FDB_PORT = pysnmp.MibVariable('Q-BRIDGE-MIB', 'dot1qTpFdbPort') # [dot1qFdbId, dot1qTpFdbAddress]
+
def macaddr (value) :
"""
Excepts a MAC address from an SNMP OctetString.
@@ -45,13 +51,48 @@
return True
- def fdb (self) :
+ def fdb_ports (self) :
+ """
+ Map hosts in the brige FDB to specific ports.
+ """
+
for idx, data in self.table(DOT1D_TP_FDB_PORT) :
addr, = idx
port = data[DOT1D_TP_FDB_PORT]
yield macaddr(addr), int(port)
+ def vlan_fdb (self) :
+ """
+ Get FDB id -> vlan mappings.
+
+ (fdb, vlan)
+ """
+
+ for idx, data in self.table(DOT1Q_VLAN_FDB_ID) :
+ time, vlan = idx
+ fdb = int(data[DOT1Q_VLAN_FDB_ID])
+
+ yield fdb, vlan
+
+ def vlan_fdb_ports (self) :
+ """
+ Get per-vlan host -> port mappings.
+
+ (macaddr, port, vlan)
+ """
+
+ fdb_to_vlan = dict(self.vlan_fdb())
+
+ for idx, data in self.table(DOT1Q_TP_FDB_PORT) :
+ fdb, addr = idx
+ port = data[DOT1Q_TP_FDB_PORT]
+
+ vlan = fdb_to_vlan.get(fdb)
+
+ yield macaddr(addr), int(port), vlan
+
+
if __name__ == '__main__':
import doctest
doctest.testmod()