Esempio n. 1
0
    def __init__(self):

        # The following tables should go to Topology later
        self.entryByMAC = {}
        self._t = Timer(timeoutSec['timerInterval'],
                        self._check_timeouts,
                        recurring=True)
        self.listenTo(core)
        log.info("host_tracker ready")
 def addInData(self, data):
   """
   This adds data to the inData packet searcher.  It also resets the timer
   used to determine when to write the data out to file.
   """
   
   if self.writeTimer != None:
     self.writeTimer.cancel()
     
   self.inData.addData(data)    
   self.writeTimer = Timer(self.timeout, self.writeOutput)    
Esempio n. 3
0
    def __init__(self):
        self._dps = set()
        self.adjacency = {}  # From Link to time.time() stamp
        self._sender = LLDPSender()
        Timer(TIMEOUT_CHECK_PERIOD, self._expireLinks, recurring=True)

        if core.hasComponent("openflow"):
            self.listenTo(core.openflow)
        else:
            # We'll wait for openflow to come up
            self.listenTo(core)
Esempio n. 4
0
    def setup_connection(self, connection, packet):
        """
        1. Takes a connection and a packet

        2. Inits self.connection_data, which is a dict {<connection_tuple>: <connection_info_dict>}

        """

        if connection in self.connection_data:
            log.debug("Connection %s is already setup" % (str(connection)))
            return

        now = time.time()

        # create timer
        try:
            timer = Timer(30,
                          self.delete_idle_connection,
                          args=[connection],
                          recurring=True)
        except Exception, e:
            log.debug("----ERROR-----: %s" % (str(e)))
Esempio n. 5
0
        Event.__init__(self)
        self.packet = packet
        self.connection = connection
        self.sig = connection.sig
        self.action = connection.action
        self.opaque = connection.opaque
        self.reverse = self.packet.next.srcip == self.connection.sig.dst
        self.send = connection.send

    def _invoke(self, handler, *args, **kw):
        r = handler(self, self.sig, self.packet)
        self.connection.opaque = self.opaque
        return r


stray_timer = Timer(90, roll_strays, recurring=True)


class EE122Gateway(EventMixin):
    _eventMixin_events = set([
        DeferredConnectionIn,
        ConnectionIn,
        MonitorData,
    ])

    def __init__(self, switch, ports):
        global INSIDE_PORT, OUTSIDE_PORT, INTERNAL_PORT
        for p in ports:
            if p.name == OUTSIDE_PORT:
                OUTSIDE_PORT = p.port_no
            if isinstance(INSIDE_PORT, list) and p.name in INSIDE_PORT:
class Monitored:
  """
  Monitored is used to keep track of a monitored IP address.  Most of the
  work of Monitored is done by two PacketDataSearchers, one for data
  send from us and one for data sent to us.  Monitored also contains data
  needed to write out the results of the two PacketDataSearchers to file.
  This data is written after no new data is seen in self.timeout seconds.
  After data is written to file, a flag is set so that clean up functions
  in firewall know when to delete Monitored objects.
  """

  def __init__(self):

    self.outData = PacketDataSearcher()
    self.inData = PacketDataSearcher()    
    self.portNumber = ""
    self.ipAdd = ""
    self.outputFileName = ""    
    self.timeout = 0
    self.writeTimer = None
    self.isDataWritten = False    
    self.writeDataToDebug = True    

  
  def addSearchString(self, string):
    """ Adds the string to both PacketDataSearchers. """
    self.outData.addSearchString(string)
    self.inData.addSearchString(string)


  def setPort(self, port):
    """ Sets the port number. """
    self.portNumber = str(port)

    
  def setIP(self, ip):
    """ Sets the IP address. """
    self.ipAdd = str(ip)


  def setTimeout(self, t):
    """
    Sets the time out time which tells Monitored when to write the data out
    to file.
    """
    self.timeout = t


  def setOutputFile(self, filename):
    """ Sets the name of the file to write data out to. """
    self.outputFileName = filename


  def addOutData(self, data):
    """
    This adds data to the outData packet searcher.  It also resets the timer
    used to determine when to write the data out to file.
    """

    if self.writeTimer != None:
      self.writeTimer.cancel()
      
    self.outData.addData(data)    
    self.writeTimer = Timer(self.timeout, self.writeOutput)


  def addInData(self, data):
    """
    This adds data to the inData packet searcher.  It also resets the timer
    used to determine when to write the data out to file.
    """
    
    if self.writeTimer != None:
      self.writeTimer.cancel()
      
    self.inData.addData(data)    
    self.writeTimer = Timer(self.timeout, self.writeOutput)    
  

  def getResults(self):
    """
    Returns a comma separated value string containing the current
    results.
    """

    inResults = self.inData.getResults()
    outResults = self.outData.getResults()
    results = ""

    for string in inResults:
      results = results + self.ipAdd + "," + self.portNumber + "," + string +\
                ","+ str(inResults[string]+outResults[string]) + "\n"
     
    return results


  def writeOutput(self):
    """
    This is called when the writeTimer goes off.  It writes the current search
    string totals and other appropriate information to file.
    """
    
    if self.writeDataToDebug:      
      log.debug("Results: \n" + self.getResults())
      log.debug("In Stats:  " + self.inData.getStats())
      log.debug("Out Stats: " + self.outData.getStats())      
    
    try:
      outFile = open(self.outputFileName, "a")
      outFile.write(self.getResults())
      outFile.close()      
      self.isDataWritten = True
      log.debug("Data written to: " + self.outputFileName)
          
    except Exception:           
      sys.exc_clear()       
      log.debug("Error writing results to file: " + self.outputFileName)      

    log.debug("_______________________________________________________________") 


  def isWrittenToFile(self):
    """
    Returns True if the search string totals have been written to file.
    Else False.
    """

    return self.isDataWritten
Esempio n. 7
0
 def __init__(self):
     self._session_key_salt = str(time.time()) + "POX"
     self._connections = {}
     #self._t = Timer(5, self._check_timeouts, recurring=True)
     self._t = Timer(60 * 2, self._check_timeouts, recurring=True)