# Path: wiremaps/collector/helpers/speed.py
# class SpeedCollector:
#     """Collect speed/duplex/autoneg from 3 OID.
# 
#     Methods C{gotSpeed}, C{gotDuplex} and C{gotAutoneg} should be
#     implemented. c{oidDuplex}, c{oidSpeed} and c{oidAutoneg}
#     attributes should be defined.
#     """
# 
#     def gotSpeed(self, results):
#         raise NotImplementedError
#     def gotAutoneg(self, results):
#         raise NotImplementedError
#     def gotDuplex(self, results):
#         raise NotImplementedError
# 
#     def __init__(self, equipment, proxy, normPort=None):
#         self.proxy = proxy
#         self.equipment = equipment
#         self.normport = normPort
# 
#     def completeEquipment(self):
#         """Complete the equipment with data collected"""
#         for port in self.speed:
#             if self.normport and self.normport(port) is not None:
#                 nport = self.equipment.ports[self.normport(port)]
#             else:
#                 nport = self.equipment.ports[port]
#             nport.speed = self.speed[port]
#             nport.autoneg = self.autoneg.get(port, None)
#             nport.duplex = self.duplex.get(port, None)
# 
#     def collectData(self):
#         print "Collecting port speed/duplex for %s" % self.proxy.ip
#         self.speed = {}
#         self.duplex = {}
#         self.autoneg = {}
#         d = self.proxy.walk(self.oidDuplex)
#         d.addCallback(self.gotDuplex)
#         if hasattr(self, "oidSpeed"):
#             # Sometimes, speed comes with duplex
#             d.addCallback(lambda x: self.proxy.walk(self.oidSpeed))
#             d.addCallback(self.gotSpeed)
#         d.addCallback(lambda x: self.proxy.walk(self.oidAutoneg))
#         d.addCallback(self.gotAutoneg)
#         d.addCallback(lambda _: self.completeEquipment())
#         return d


from twisted.internet import defer
from wiremaps.collector.helpers.speed import SpeedCollector
                        # as represented by its ifIndex value . When a
                        # bit has the value one(1), the corresponding
                        # port is a member of the set. When a bit has
                        # the value zero(0), the corresponding port is
                        # not a member of the set. The encoding is
                        # such that the most significant bit of octet
                        # #1 corresponds to ifIndex 0, while the least
                        # significant bit of octet #88 corresponds to
                        # ifIndex 703."

                        l.append(7-j + 8*i)
            self.mlt[mlt] = l

    def gotIfIndex(self, results):
        for oid in results:
            mlt = int(oid.split(".")[-1])
            index = results[oid]
            self.mltindex[index] = mlt

    def collectData(self, write=True):
        """Collect data from SNMP using rcMltPortMembers
        """
    
        print "Collecting MLT for %s" % self.proxy.ip
        d = self.proxy.walk(self.rcMltPortMembers)
        d.addCallback(self.gotMlt)
        d.addCallback(lambda _: self.proxy.walk(self.rcMltIfIndex))
        d.addCallback(self.gotIfIndex)
        return d


# Path: wiremaps/collector/helpers/speed.py
# class SpeedCollector:
#     """Collect speed/duplex/autoneg from 3 OID.
# 
#     Methods C{gotSpeed}, C{gotDuplex} and C{gotAutoneg} should be
#     implemented. c{oidDuplex}, c{oidSpeed} and c{oidAutoneg}
#     attributes should be defined.
#     """
# 
#     def gotSpeed(self, results):
#         raise NotImplementedError
#     def gotAutoneg(self, results):
#         raise NotImplementedError
#     def gotDuplex(self, results):
#         raise NotImplementedError
# 
#     def __init__(self, equipment, proxy, normPort=None):
#         self.proxy = proxy
#         self.equipment = equipment
#         self.normport = normPort
# 
#     def completeEquipment(self):
#         """Complete the equipment with data collected"""
#         for port in self.speed:
#             if self.normport and self.normport(port) is not None:
#                 nport = self.equipment.ports[self.normport(port)]
#             else:
#                 nport = self.equipment.ports[port]
#             nport.speed = self.speed[port]
#             nport.autoneg = self.autoneg.get(port, None)
#             nport.duplex = self.duplex.get(port, None)
# 
#     def collectData(self):
#         print "Collecting port speed/duplex for %s" % self.proxy.ip
#         self.speed = {}
#         self.duplex = {}
#         self.autoneg = {}
#         d = self.proxy.walk(self.oidDuplex)
#         d.addCallback(self.gotDuplex)
#         if hasattr(self, "oidSpeed"):
#             # Sometimes, speed comes with duplex
#             d.addCallback(lambda x: self.proxy.walk(self.oidSpeed))
#             d.addCallback(self.gotSpeed)
#         d.addCallback(lambda x: self.proxy.walk(self.oidAutoneg))
#         d.addCallback(self.gotAutoneg)
#         d.addCallback(lambda _: self.completeEquipment())
#         return d


# Path: wiremaps/collector/helpers/nortel.py
from twisted.internet import defer
from wiremaps.collector.helpers.speed import SpeedCollector

                        # as represented by its ifIndex value . When a
                        # bit has the value one(1), the corresponding
                        # port is a member of the set. When a bit has
                        # the value zero(0), the corresponding port is
                        # not a member of the set. The encoding is
                        # such that the most significant bit of octet
                        # #1 corresponds to ifIndex 0, while the least
                        # significant bit of octet #88 corresponds to
                        # ifIndex 703."

                        l.append(7-j + 8*i)
            self.mlt[mlt] = l

    def gotIfIndex(self, results):
        for oid in results:
            mlt = int(oid.split(".")[-1])
            index = results[oid]
            self.mltindex[index] = mlt

    def collectData(self, write=True):
        """Collect data from SNMP using rcMltPortMembers
        """
    
        print "Collecting MLT for %s" % self.proxy.ip
        d = self.proxy.walk(self.rcMltPortMembers)
        d.addCallback(self.gotMlt)
        d.addCallback(lambda _: self.proxy.walk(self.rcMltIfIndex))
        d.addCallback(self.gotIfIndex)
        return d


class NortelSpeedCollector(SpeedCollector):