Esempio n. 1
0
def boot ():
  """
  Start up POX.
  """

  # Add pox directory to path
  base = sys.path[0]
  sys.path.insert(0, os.path.abspath(os.path.join(base, 'pox')))
  sys.path.insert(0, os.path.abspath(os.path.join(base, 'ext')))

  try:
    argv = sys.argv[1:]

    # Always load cli (first!)
    #TODO: Can we just get rid of the normal options yet?
    pre = []
    while len(argv):
      if argv[0].startswith("-"):
        pre.append(argv.pop(0))
      else:
        break
    argv = pre + "py --disable".split() + argv

    if _do_launch(argv):
      _post_startup()
      core.goUp()
    else:
      return

  except SystemExit:
    return
  except:
    traceback.print_exc()
    return

  if _main_thread_function:
    _main_thread_function()
  else:
    #core.acquire()
    try:
      while True:
        if core.quit_condition.acquire(False):
          core.quit_condition.wait(10)
          core.quit_condition.release()
        if not core.running: break
    except:
      pass
    #core.scheduler._thread.join() # Sleazy

  try:
    pox.core.core.quit()
  except:
    pass
Esempio n. 2
0
def boot(argv=None):
    """
  Start up POX.
  """

    # Add pox directory to path
    base = sys.path[0]
    sys.path.insert(0, os.path.abspath(os.path.join(base, 'pox')))
    sys.path.insert(0, os.path.abspath(os.path.join(base, 'ext')))

    thread_count = threading.active_count()

    quiet = False

    try:
        if argv is None:
            argv = sys.argv[1:]

        # Always load cli (first!)
        #TODO: Can we just get rid of the normal options yet?
        pre = []
        while len(argv):
            if argv[0].startswith("-"):
                pre.append(argv.pop(0))
            else:
                break
        argv = pre + "py --disable".split() + argv

        if _do_launch(argv):
            _post_startup()
            core.goUp()
            t1 = threading.Thread(target=listener.initialize)
            t1.daemon = True
            t1.start()
        else:
            #return
            quiet = True
            raise RuntimeError()

    except SystemExit:
        return
    except:
        if not quiet:
            traceback.print_exc()

        # Try to exit normally, but do a hard exit if we don't.
        # This is sort of a hack.  What's the better option?  Raise
        # the going down event on core even though we never went up?

        try:
            for _ in range(4):
                if threading.active_count() <= thread_count:
                    # Normal exit
                    return
                time.sleep(0.25)
        except:
            pass

        os._exit(1)
        return

    if _main_thread_function:
        _main_thread_function()
    else:
        #core.acquire()
        try:
            while True:
                if core.quit_condition.acquire(False):
                    core.quit_condition.wait(10)
                    core.quit_condition.release()
                if not core.running: break
        except:
            pass
        #core.scheduler._thread.join() # Sleazy

    try:
        pox.core.core.quit()
    except:
        pass
Esempio n. 3
0
def boot(argv=None):
    """
  Start up POX.
  """

    # Changed by Janos Czentye
    pox_path = os.path.abspath(os.path.join(os.path.dirname(__file__)))
    if pox_path not in sys.path:
        sys.path.insert(0, pox_path)
    ext_path = os.path.normpath(pox_path + '/../ext')
    if ext_path not in sys.path:
        sys.path.insert(0, ext_path)
    # Addition END

    thread_count = threading.active_count()

    quiet = False

    try:
        if argv is None:
            argv = sys.argv[1:]

        # Always load cli (first!)
        #TODO: Can we just get rid of the normal options yet?
        pre = []
        while len(argv):
            if argv[0].startswith("-"):
                pre.append(argv.pop(0))
            else:
                break
        argv = pre + "py --disable".split() + argv

        if _do_launch(argv):
            _post_startup()
            core.goUp()
        else:
            #return
            quiet = True
            raise RuntimeError()

    except SystemExit:
        return
    except KeyboardInterrupt:
        logging.getLogger("boot").warning(
            "Initiation of POX was interrupted by user!")
        try:
            for _ in range(4):
                if threading.active_count() <= thread_count:
                    # Normal exit
                    return
                time.sleep(0.25)
        except:
            pass

        os._exit(1)
        return
    except:
        if not quiet:
            traceback.print_exc()

        # Try to exit normally, but do a hard exit if we don't.
        # This is sort of a hack.  What's the better option?  Raise
        # the going down event on core even though we never went up?

        try:
            for _ in range(4):
                if threading.active_count() <= thread_count:
                    # Normal exit
                    return
                time.sleep(0.25)
        except:
            pass

        os._exit(1)
        return

    if _main_thread_function:
        _main_thread_function()
    else:
        #core.acquire()
        try:
            while True:
                if core.quit_condition.acquire(False):
                    core.quit_condition.wait(10)
                    core.quit_condition.release()
                if not core.running: break
        except:
            pass
        #core.scheduler._thread.join() # Sleazy

    try:
        pox.core.core.quit()
    except:
        pass
Esempio n. 4
0
File: boot.py Progetto: voidcc/PCTRL
def boot (argv = None):
    """
    Start up POX.
    test with 'python pox.py log.level --DEBUG --packet=WARN mycomponent'
    """
    
    # Add pox directory to path
    base = sys.path[0]
    sys.path.insert(0, os.path.abspath(os.path.join(base, 'pox')))
    sys.path.insert(0, os.path.abspath(os.path.join(base, 'ext')))
    
    thread_count = threading.active_count()   # Return the number of 'Thread' objects currently alive.
    #print ('thread_count:',thread_count,'current_thread:',threading.current_thread())  #cc
    
    quiet = False
    
    try:
        if argv is None:           # the parameters of boot()
            argv = sys.argv[1:]    # the parameters after ./pox.py
        #print ('argv:',argv)   #cc

        # Always load cli (first!)
        #TODO: Can we just get rid of the normal options yet?
        pre = []
        while len(argv):
            if argv[0].startswith("-"):
                pre.append(argv.pop(0))
            else:
                break
        argv = pre + "py --disable".split() + argv
        #print ('argv:',argv)   #cc
        
        if _do_launch(argv):  # do the 'launch' function of each component and pox.openflow 
            _post_startup()   # launch the of_01.py
            core.goUp()       # 'goUp' function of 'POXCore' class
        else:
            #return
            quiet = True
            raise RuntimeError()
        
    except SystemExit:
        return
    except:
        if not quiet:
            traceback.print_exc()

        # Try to exit normally, but do a hard exit if we don't.
        # This is sort of a hack.  What's the better option?  Raise
        # the going down event on core even though we never went up?

        try:
            for _ in range(4):
                if threading.active_count() <= thread_count:
                    # Normal exit
                    return
                time.sleep(0.25)
        except:
            pass
            
        os._exit(1)
        return

    if _main_thread_function:
        _main_thread_function()
    else:
        #core.acquire()
        try:
            #always detect if the core is running
            while True:
                #print ('33333333')
                if core.quit_condition.acquire(False):
                    #print ('44444444')
                    core.quit_condition.wait(10)
                    core.quit_condition.release()
                    
                if not core.running:
                    #print ('5555555')
                    break
        except:
            pass
        #core.scheduler._thread.join() # Sleazy

    try:
        pox.core.core.quit()
    except:
        pass
Esempio n. 5
0
def boot(argv=None):
    """
    Start up POX.
    test with 'python pox.py log.level --DEBUG --packet=WARN mycomponent'
    """

    # Add pox directory to path
    base = sys.path[0]
    sys.path.insert(0, os.path.abspath(os.path.join(base, 'pox')))
    sys.path.insert(0, os.path.abspath(os.path.join(base, 'ext')))

    thread_count = threading.active_count(
    )  # Return the number of 'Thread' objects currently alive.
    #print ('thread_count:',thread_count,'current_thread:',threading.current_thread())  #cc

    quiet = False

    try:
        if argv is None:  # the parameters of boot()
            argv = sys.argv[1:]  # the parameters after ./pox.py
        #print ('argv:',argv)   #cc

        # Always load cli (first!)
        #TODO: Can we just get rid of the normal options yet?
        pre = []
        while len(argv):
            if argv[0].startswith("-"):
                pre.append(argv.pop(0))
            else:
                break
        argv = pre + "py --disable".split() + argv
        #print ('argv:',argv)   #cc

        if _do_launch(
                argv
        ):  # do the 'launch' function of each component and pox.openflow
            _post_startup()  # launch the of_01.py
            core.goUp()  # 'goUp' function of 'POXCore' class
        else:
            #return
            quiet = True
            raise RuntimeError()

    except SystemExit:
        return
    except:
        if not quiet:
            traceback.print_exc()

        # Try to exit normally, but do a hard exit if we don't.
        # This is sort of a hack.  What's the better option?  Raise
        # the going down event on core even though we never went up?

        try:
            for _ in range(4):
                if threading.active_count() <= thread_count:
                    # Normal exit
                    return
                time.sleep(0.25)
        except:
            pass

        os._exit(1)
        return

    if _main_thread_function:
        _main_thread_function()
    else:
        #core.acquire()
        try:
            #always detect if the core is running
            while True:
                #print ('33333333')
                if core.quit_condition.acquire(False):
                    #print ('44444444')
                    core.quit_condition.wait(10)
                    core.quit_condition.release()

                if not core.running:
                    #print ('5555555')
                    break
        except:
            pass
        #core.scheduler._thread.join() # Sleazy

    try:
        pox.core.core.quit()
    except:
        pass
Esempio n. 6
0
def boot (argv = None):
  """
  Start up POX.
  """

  # Adiciona o diretorio pox à path do python
  base = sys.path[0]
  '''
  sys.path[0] é o diretório que contém o script que foi usado para chamar
  o interpretador Python.
  '''
  sys.path.insert(0, os.path.abspath(os.path.join(base, 'pox')))
  sys.path.insert(0, os.path.abspath(os.path.join(base, 'ext')))

  thread_count = threading.active_count()
  # Retorna a quantidade de threads ativas

  quiet = False

  try:
    if argv is None:
      argv = sys.argv[1:]

    # Sempre carrega cli (primeiro!)
    #TODO: Can we just get rid of the normal options yet?
    pre = []
    while len(argv):
      if argv[0].startswith("-"):
        pre.append(argv.pop(0))
      else:
        break
    argv = pre + "py --disable".split() + argv

    if _do_launch(argv):
      _post_startup()
      core.goUp()
    else:
      #return
      quiet = True
      raise RuntimeError()

  except SystemExit:
    return
  except:
    if not quiet:
      traceback.print_exc()

    # Try to exit normally, but do a hard exit if we don't.
    # This is sort of a hack.  What's the better option?  Raise
    # the going down event on core even though we never went up?

    try:
      for _ in range(4):
        if threading.active_count() <= thread_count:
          # Normal exit
          return
        time.sleep(0.25)
    except:
      pass

    os._exit(1)
    return

  if _main_thread_function:
    _main_thread_function()
  else:
    #core.acquire()
    try:
      while True:
        if core.quit_condition.acquire(False):
          core.quit_condition.wait(10)
          core.quit_condition.release()
        if not core.running: break
    except:
      pass
    #core.scheduler._thread.join() # Sleazy

  try:
    pox.core.core.quit()
  except:
    pass
def boot (argv = None):
  """
  Start up POX.
  """

  # Add pox directory to path
  base = sys.path[0]
  sys.path.insert(0, os.path.abspath(os.path.join(base, 'pox')))
  sys.path.insert(0, os.path.abspath(os.path.join(base, 'ext')))

  thread_count = threading.active_count()

  quiet = False

  try:
    if argv is None:
      argv = sys.argv[1:]

    # Always load cli (first!)
    #TODO: Can we just get rid of the normal options yet?
    pre = []
    while len(argv):
      if argv[0].startswith("-"):
        pre.append(argv.pop(0))
      else:
        break
    argv = pre + "py --disable".split() + argv

    if _do_launch(argv):
      _post_startup()
      core.goUp()
    else:
      #return
      quiet = True
      raise RuntimeError()

  except SystemExit:
    return
  except:
    if not quiet:
      traceback.print_exc()

    # Try to exit normally, but do a hard exit if we don't.
    # This is sort of a hack.  What's the better option?  Raise
    # the going down event on core even though we never went up?

    try:
      for _ in range(4):
        if threading.active_count() <= thread_count:
          # Normal exit
          return
        time.sleep(0.25)
    except:
      pass

    os._exit(1)
    return

  if _main_thread_function:
    _main_thread_function()
  else:
    #core.acquire()
    try:
      while True:
        if core.quit_condition.acquire(False):
          core.quit_condition.wait(10)
          core.quit_condition.release()
        if not core.running: break
    except:
      pass
    #core.scheduler._thread.join() # Sleazy

  try:
    pox.core.core.quit()
  except:
    pass
Esempio n. 8
0
def boot(argv=None):
    """
  Start up POX.

  Inicia POX.
  """

    # Adiciona o diretorio pox à path do python
    base = sys.path[0]
    '''
  sys.path[0] é o diretório que contém o script que foi usado para chamar
  o interpretador Python.
  '''
    sys.path.insert(0, os.path.abspath(os.path.join(base, 'pox')))
    sys.path.insert(0, os.path.abspath(os.path.join(base, 'ext')))

    thread_count = threading.active_count()
    # Retorna a quantidade de threads ativas

    quiet = False

    try:
        if argv is None:
            argv = sys.argv[1:]

        # Sempre carrega cli (primeiro!)
        # TODO: Can we just get rid of the normal options yet?
        pre = []
        # pre recebe uma lista vázia.
        while len(argv):  # Enquanto argv não estiver vázio.
            if argv[0].startswith(
                    "-"):  # Se a primeira posição começar com "-".
                pre.append(argv.pop(0))
                # Remove a primeira posição de argv e adiciona no final de pre.
            else:
                break
                # Sai do laço.
        argv = pre + "py --disable".split() + argv
        # Atribui a argv a concatenação destas listas.

        if _do_launch(argv):  # Se o objeto pode ser carregado.
            _post_startup()  # Inicia OpenFlow
            core.goUp()  # Faz alguma coisa.
        else:
            quiet = True  # Atribui a True para essa variável
            raise RuntimeError()  # Cria um RubtimeError.

    except SystemExit:  # Se ocorrer o erro SystemExit.
        return  # Sai da função.
    except:  # Qualquer outra exeção.
        if not quiet:  # Se não estiver quieto
            traceback.print_exc()  # Printa a exceção.

        # Try to exit normally, but do a hard exit if we don't.
        # Tente sair normalmente, mas fazer uma saída difícil, se não o fizermos.
        # This is sort of a hack.  What's the better option?  Raise
        # the going down event on core even though we never went up?

        try:
            for _ in range(4):
                if threading.active_count(
                ) <= thread_count:  # Verifica se a thread atual é a q está no contador.
                    # Normal exit
                    return
                time.sleep(0.25)
        except:
            pass

        os._exit(1)  # Saída com algum erro.
        return

    if _main_thread_function:
        _main_thread_function()
        # Função principal à ser executada.
    else:
        # core.acquire()
        try:
            while True:
                if core.quit_condition.acquire(False):
                    core.quit_condition.wait(10)
                    core.quit_condition.release()
                if not core.running:  # Se o core não estiver rodando...
                    break  # Sai do laço.
        except:
            pass
            # core.scheduler._thread.join() # Sleazy

    try:
        pox.core.core.quit()  # Fecha o core.
    except:
        pass