def getFullMACTable(self): """\brief Gets the full learned mac table from the switch, returning a list of MACTableEntry objects. \return (\c list) A list of MACTableEntry objects with the results. """ portsTable = self.snmp.walk(OID.dot1dTpFdbPort) learnedTypeTable = self.snmp.walk(OID.dot1dTpFdbStatus) result = [] for learnedTypeTableRow in learnedTypeTable: for learnedname, learnedval in learnedTypeTableRow: if learnedval == rfc1902.Integer32('3'): learnedname = rfc1902.ObjectName((learnedname.prettyPrint()).replace(OID.dot1dTpFdbStatus.prettyPrint(),OID.dot1dTpFdbPort.prettyPrint())) for portTableRow in portsTable: for portname, portval in portTableRow: if learnedname == portname: result.append(MACTableEntry(("%02x:%02x:%02x:%02x:%02x:%02x" % (int(learnedname[11]),int(learnedname[12]),int(learnedname[13]),int(learnedname[14]),int(learnedname[15]),int(learnedname[16]))).replace("0x","").upper(),portval,'3',self.__switchName)) return result for key in learnedTypeTable.keys(): if (learnedTypeTable[key] == str(3)): mac = MACTableEntry((macAddressesTable[key]).replace(' ',':',5).upper(),portsTable[key],learnedTypeTable[key]) mac.setSwitch(self.getSwitchID()) result.append(mac)
def __getFDBTable(self, result): portsTable = self.snmp.walk(OID.dot1dTpFdbPort) learnedTypeTable = self.snmp.walk(OID.dot1dTpFdbStatus) for learnedTypeTableRow in learnedTypeTable: for learnedname, learnedval in learnedTypeTableRow: if learnedval == rfc1902.Integer32('3'): learnedname = rfc1902.ObjectName( (learnedname.prettyPrint()).replace( OID.dot1dTpFdbStatus.prettyPrint(), OID.dot1dTpFdbPort.prettyPrint())) for portTableRow in portsTable: for portname, portval in portTableRow: if learnedname == portname: result.append( MACTableEntry( ("%02x:%02x:%02x:%02x:%02x:%02x" % (int(learnedname[11]), int(learnedname[12]), int(learnedname[13]), int(learnedname[14]), int(learnedname[15]), int(learnedname[16]))).replace( "0x", "").upper(), portval, '3', self.getSwitchName())) #return result return for key in learnedTypeTable.keys(): if (learnedTypeTable[key] == str(3)): mac = MACTableEntry( (macAddressesTable[key]).replace(' ', ':', 5).upper(), portsTable[key], learnedTypeTable[key]) mac.setSwitch(self.getSwitchID()) result.append(mac)
def __getFullMACTable(self): """\brief Gets the full learned mac table from the switch, returning a list of MACTableEntry objects. \return (\c list) A list of MACTableEntry objects with the results. """ portsTable = self.getDot1qTpFdbPort(True) learnedTypeTable = self.getDot1qTpFdbStatus(True) result = [] for learnedTypeTableRow in learnedTypeTable: for learnedname, learnedval in learnedTypeTableRow: if learnedval == rfc1902.Integer32('3'): learnedname = rfc1902.ObjectName( (learnedname.prettyPrint()).replace( OID.dot1qTpFdbStatus.prettyPrint(), OID.dot1qTpFdbPort.prettyPrint())) for portTableRow in portsTable: for portname, portval in portTableRow: if learnedname == portname: result.append( MACTableEntry( ("%02x:%02x:%02x:%02x:%02x:%02x" % (int(learnedname[14]), int(learnedname[15]), int(learnedname[16]), int(learnedname[17]), int(learnedname[18]), int(learnedname[19]))).replace( "0x", "").upper(), portval, '3', self.getSwitchName())) return result
def __getFDBTable(self,result): portsTable = self.snmp.walk(OID.dot1dTpFdbPort) learnedTypeTable = self.snmp.walk(OID.dot1dTpFdbStatus) for learnedTypeTableRow in learnedTypeTable: for learnedname, learnedval in learnedTypeTableRow: if learnedval == rfc1902.Integer32('3'): learnedname = rfc1902.ObjectName((learnedname.prettyPrint()).replace(OID.dot1dTpFdbStatus.prettyPrint(),OID.dot1dTpFdbPort.prettyPrint())) for portTableRow in portsTable: for portname, portval in portTableRow: if learnedname == portname: result.append(MACTableEntry(("%02x:%02x:%02x:%02x:%02x:%02x" % (int(learnedname[11]),int(learnedname[12]),int(learnedname[13]),int(learnedname[14]),int(learnedname[15]),int(learnedname[16]))).replace("0x","").upper(),portval,'3',self.getSwitchName())) #return result return for key in learnedTypeTable.keys(): if (learnedTypeTable[key] == str(3)): mac = MACTableEntry((macAddressesTable[key]).replace(' ',':',5).upper(),portsTable[key],learnedTypeTable[key]) mac.setSwitch(self.getSwitchID()) result.append(mac)
def DELETEgetFullMACTable(self): """\brief Returns a list of MACTableEntry objects representing the full mac table of the switch (the switch's database). \return (\c list) A list of MACTableEntry objects """ originalCmd = self.getCommunity() table = [] # Get the VLAN ids vlanIDs = CiscoSwitch.getVLANGlobalIDs(self) for vlanID in vlanIDs: newcmd = str(originalCmd) + "@" + vlanID self.setCommunity(newcmd) # Get the MAC Address Table cmd = self.getSNMPwalkCommand() + SWITCH_DB_ADDRESSES_TABLE macTableMAC = self.getSNMPResultTable(cmd) # Get the port numbers cmd = self.getSNMPwalkCommand() + SWITCH_DB_PORTS_TABLE macTablePort = self.getSNMPResultTable(cmd) # Get the status (e.g. 3 = learned) cmd = self.getSNMPwalkCommand() + SWITCH_DB_STATUS_TABLE macTableStatus = self.getSNMPResultTable(cmd) # Get the IfIndexcorresponding port number cmd = self.getSNMPwalkCommand() + PORT_IDS_TABLE macTableIfIndex = self.getSNMPResultTable(cmd) # Get the ifName (e.g. Fa0/2) cmd = self.getSNMPwalkCommand() + IFNAME_TABLE macTableIfName = self.getSNMPResultTable(cmd) # Should be correct?: len(macTableMAC) == len(macTablePort) == len (macTableStatus) for key in macTableMAC.keys(): if (macTableStatus[key] == str(3)): ifIndex = int(macTableIfIndex[macTablePort[key]]) # We could map to the name as well, uncomment to get name #for name in macTableIfName.keys(): # if (int(name) == ifIndex): # ifName = macTableIfName[name] # We now decrement the ifIndex by 1 to get the correct port # TODO: Is this always correct? ifIndex = ifIndex - 1 mac = MACTableEntry( (macTableMAC[key]).replace(' ', ':', 5).upper(), ifIndex, macTableStatus[key]) table.append(mac) self.setCommunity(originalCmd) return table