def start(components): from pox.boot import boot out_log = os.path.join(logs['log_dir'], 'pox.out') err_log = os.path.join(logs['log_dir'], 'pox.err') #sys.stdout = open(out_log, 'w') sys.stderr = open(err_log, 'w') boot({'components':components})
# If you have PyPy 1.6+ in a directory called pypy alongside pox.py, we # use it. # Otherwise, we try to use a Python interpreter called python2.7, which # is a good idea if you're using Python from MacPorts, for example. # We fall back to just "python" and hope that works. ''''true #export OPT="-u -O" export OPT="-u" export FLG="" if [ "$(basename $0)" = "debug-pox.py" ]; then export OPT="" export FLG="--debug" fi if [ -x pypy/bin/pypy ]; then exec pypy/bin/pypy $OPT "$0" $FLG "$@" fi if type python2.7 > /dev/null 2> /dev/null; then exec python2.7 $OPT "$0" $FLG "$@" fi exec python $OPT "$0" $FLG "$@" ''' from pox.boot import boot if __name__ == '__main__': print(" ---------------------- MAIN ------------------------ ") boot()
def main(): # Implement parser options parser = argparse.ArgumentParser( description="ESCAPEv2: Extensible Service ChAin Prototyping Environment " "using Mininet, Click, NETCONF and POX", add_help=True, version=get_escape_version(), prefix_chars="-+") # Add optional arguments escape = parser.add_argument_group("ESCAPEv2 arguments") escape.add_argument( "-a", "--agent", action="store_true", default=False, help="run in AGENT mode: start the infrastructure layer " "with the ROS REST-API (without the Service " "sublayer (SAS))") escape.add_argument( "-b", "--bypassapi", action="store_true", default=False, help="start the REST-API to bypass embedding and access " "to the DoV directly") escape.add_argument("-c", "--config", metavar="path", type=str, help="use external config file to extend the default " "configuration") escape.add_argument("-d", "--debug", action="count", default=0, help="run the ESCAPE in debug mode (can use multiple " "times for more verbose logging)") escape.add_argument("-e", "--environment", action="store_true", default=False, help="run ESCAPEv2 in the pre-defined virtualenv") escape.add_argument("-f", "--full", action="store_true", default=False, help="run the infrastructure layer also") escape.add_argument( "-g", "--gui", action="store_true", default=False, help="(OBSOLETE) initiate the graph-viewer GUI app which " "automatically connects to the ROS REST-API") escape.add_argument("-i", "--interactive", action="store_true", default=False, help="run an interactive shell for observing internal " "states") escape.add_argument("-l", "--log", metavar="file", type=str, help="define log file path explicitly " "(default: log/escape.log)") escape.add_argument( "--log_folder", metavar="path", type=str, help="define log folder path explicitly (default: log/)") escape.add_argument("-m", "--mininet", metavar="file", type=str, help="read the Mininet topology from the given file") escape.add_argument("-n", "--nosignal", action="store_true", default=False, help="run ESCAPE in a sub-shell that prevents " "propagation of received SIGNALs") escape.add_argument("-o", "--openflow", action="store", type=int, nargs="?", const=6633, metavar="port", help="initiate internal OpenFlow module with given " "listening port (default: 6633)") escape.add_argument("-q", "--quit", action="store_true", default=False, help="quit right after the first service request has " "processed") escape.add_argument("+q", "++quit", action="store_false", default=False, help="explicitly disable quit mode") escape.add_argument("-r", "--rosapi", action="store_true", default=False, help="start REST-API for the Resource Orchestration " "sublayer (ROS)") escape.add_argument("-s", "--service", metavar="file", type=str, help="skip the SAS REST-API initiation and read the " "service request from the given file") escape.add_argument("-t", "--test", action="store_true", default=False, help="run in test mode") escape.add_argument( "-x", "--clean", action="store_true", default=False, help="run the cleanup task standalone and kill remained " "programs, interfaces, veth parts and junk files") escape.add_argument("-V", "--visualization", action="store_true", default=False, help="run the visualization module to send data to a " "remote server") # Add remaining POX modules escape.add_argument("modules", metavar="...", nargs=argparse.REMAINDER, help="optional POX modules") # Parsing arguments args = parser.parse_args() if args.clean: return clean() # Construct POX init command according to argument basic command cmd = [os.path.join(PROJECT_ROOT, "pox/pox.py"), MAIN_CONTAINER_LAYER_NAME] # Run ESCAPE in VERBOSE logging level if it is needed if args.debug == 1: # Set logging level to DEBUG cmd.append("--loglevel=DEBUG") elif args.debug > 1: # Setup logging level to specific VERBOSE cmd.append("--loglevel=VERBOSE") else: # Use default loglevel: INFO pass # Run the Infrastructure Layer with the required root privilege if args.full: cmd.insert(0, "sudo") cmd.append("--full") if args.test: cmd.append("--test") if args.log: cmd.append("--log=%s" % args.log) if args.log_folder: cmd.append("--log_folder=%s" % args.log_folder) if args.quit: cmd.append("--quit") # Initiate the rudimentary GUI if args.gui: cmd.append("--gui") # Read the service request NFFG from a file and start the mapping process if args.service: cmd.append("--sg_file=%s" % os.path.abspath(args.service)) # Override optional external config file if args.config: cmd.append("--config=%s" % os.path.abspath(args.config)) # Skip the Service Layer initiation and start the ROS agent REST-API if args.agent: cmd.append("--agent") # AGENT mode is only useful with --full -> initiate infrastructure if needed if not args.full: cmd.insert(0, "sudo") cmd.append("--full") # Start the REST-API for the ROS layer if args.rosapi or args.gui: cmd.append("--rosapi") # Start an REST-API for the Adaptation Layer if args.bypassapi: cmd.append("--dovapi") # Enable Visualization if args.visualization: cmd.append("--visualization") # Add topology file if --full is set if args.mininet: if args.full or args.agent: cmd.append("--mininet=%s" % os.path.abspath(args.mininet)) else: parser.error( message= "-m/--mininet can be used only with Infrastructure layer! " "(with -f/--full or -a/--agent flag)") # Add the interactive shell if needed if args.interactive: cmd.append("py") cmd.append("--completion") if args.openflow: cmd.extend(("openflow.of_01", "--port=%s" % args.openflow)) # Add optional POX modules cmd.extend(args.modules) def __activate_virtualenv(): """ Activate virtualenv based on activate script under bin/ :return: None """ try: activate_this = PROJECT_ROOT + '/bin/activate_this.py' execfile(activate_this, dict(__file__=activate_this)) except IOError as e: print "Virtualenv is not set properly:\n%s" % e print "Remove the '.set_virtualenv' file or configure the virtualenv!" exit(os.EX_DATAERR) # Activate virtual environment if necessary if args.environment: __activate_virtualenv() else: for entry in os.listdir(PROJECT_ROOT): if entry.upper().startswith(".USE_VIRTUALENV"): __activate_virtualenv() break # Starting ESCAPEv2 (as a POX module) print "Starting %s..." % parser.description if args.nosignal: # Create command cmd = " ".join(cmd) if args.debug: print "Command: %s" % cmd try: return os.system(cmd) except KeyboardInterrupt: # Catch KeyboardInterrupt generated by own SIGINT signal pass else: # sys.path[0] = pox_base pox_params = cmd[2:] if cmd[0] == "sudo" else cmd[1:] if args.debug: print "POX parameters: %s" % pox_params # Start POX from pox.boot import boot return boot(argv=pox_params)
def main(): sys.argv.append('forwarding.IntelligentRoutingFramework') boot.boot()
def main(): # Implement parser options parser = argparse.ArgumentParser( description="ESCAPEv2: Extensible Service ChAin Prototyping Environment " "using Mininet, Click, NETCONF and POX", add_help=True, version="2.0.0") # Add optional arguments escape = parser.add_argument_group("ESCAPEv2 arguments") escape.add_argument( "-a", "--agent", action="store_true", default=False, help="run in AGENT mode: start the infrastructure layer " "with the ROS REST-API (without the Service " "sublayer (SAS))") escape.add_argument( "-c", "--config", metavar="path", type=str, # default="pox/escape.config", help="override default config filename") escape.add_argument("-d", "--debug", action="count", default=0, help="run the ESCAPE in debug mode (can use multiple " "times for more verbose logging)") escape.add_argument("-e", "--environment", action="store_true", default=False, help="run ESCAPEv2 in the pre-defined virtualenv") escape.add_argument("-f", "--full", action="store_true", default=False, help="run the infrastructure layer also") escape.add_argument("-g", "--gui", action="store_true", default=False, help="initiate the graph-viewer GUI app which " "automatically connects to the ROS REST-API") escape.add_argument("-i", "--interactive", action="store_true", default=False, help="run an interactive shell for observing internal " "states") escape.add_argument("-p", "--POXlike", action="store_true", default=False, help="start ESCAPEv2 in the actual interpreter using " "./pox as working directory instead of using a " "separate shell process with POX's own PYTHON env") escape.add_argument( "-r", "--rosapi", action="store_true", default=False, help="start the REST-API for the Resource Orchestration " "sublayer (ROS)") escape.add_argument("-s", "--service", metavar="file", type=str, help="skip the SAS REST-API initiation and read the " "service request from the given file") escape.add_argument( "-t", "--topo", metavar="file", type=str, help="read the topology from the given file explicitly") escape.add_argument( "-x", "--clean", action="store_true", default=False, help="run the cleanup task standalone and kill remained " "programs, interfaces, veth parts and junk files") escape.add_argument("-V", "--visualization", action="store_true", default=False, help="run the visualization module to send data to a " "remote server") escape.add_argument("-4", "--cfor", action="store_true", default=False, help="start the REST-API for the Cf-Or interface") # Add remaining POX modules escape.add_argument("modules", metavar="...", nargs=argparse.REMAINDER, help="optional POX modules") # Parsing arguments args = parser.parse_args() if args.clean: # Tailor Python path for importing mics functions without initialize # escape or util packages. import sys mn = os.path.abspath(os.path.dirname(__file__) + "/mininet") # Import misc directly from util/ to avoid standard ESCAPE init steps misc = os.path.abspath( os.path.dirname(__file__) + "/escape/escape/util") sys.path.insert(0, mn) sys.path.insert(0, misc) if os.geteuid() != 0: print "Cleanup process requires root privilege!" return else: print "Run cleaning process..." from misc import remove_junks remove_junks() print "Cleaned." return # Get base dir of this script base_dir = os.path.abspath(os.path.dirname(__file__)) # Create absolute path for the pox.py initial script # Construct POX init command according to argument # basic command cmd = [os.path.join(base_dir, "pox/pox.py"), "unify"] # Run ESCAPE in VERBOSE logging level if it is needed if args.debug == 1: # Set logging level to DEBUG cmd.append("--loglevel=DEBUG") elif args.debug > 1: # Setup logging level to specific VERBOSE cmd.append("--loglevel=VERBOSE") else: # Use default loglevel: INFO pass # Run the Infrastructure Layer with the required root privilege if args.full: cmd.insert(0, "sudo") cmd.append("--full") # Initiate the rudimentary GUI if args.gui: cmd.append("--gui") # Read the service request NFFG from a file and start the mapping process if args.service: cmd.append("--sg_file=%s" % os.path.abspath(args.service)) # Override optional external config file if args.config: cmd.append("--config=%s" % os.path.abspath(args.config)) # Skip the Service Layer initiation and start the ROS agent REST-API if args.agent: cmd.append("--agent") # AGENT mode is only useful with --full -> initiate infrastructure if needed if not args.full: cmd.insert(0, "sudo") cmd.append("--full") # Start the REST-API for the ROS layer if args.rosapi or args.gui: cmd.append("--rosapi") # Start an REST-API for the Cf-Or interface if args.cfor: cmd.append("--cfor") # Enable Visualization if args.visualization: cmd.append("--visualization") # Add topology file if --full is set if args.topo: if args.full or args.agent: cmd.append("--topo=%s" % os.path.abspath(args.topo)) else: parser.error( message="-t/--topo can be used only with infrastructure layer! " "(with -f/--full or -a/--agent flag)") # Add the interactive shell if needed if args.interactive: cmd.append("py") cmd.append("--completion") # Add optional POX modules cmd.extend(args.modules) def __activate_virtualenv(): """ Activate virtualenv based on activate script under bin/ :return: None """ try: activate_this = os.path.join(base_dir, 'bin/activate_this.py') execfile(activate_this, dict(__file__=activate_this)) except IOError as e: print "Virtualenv is not set properly:\n%s" % e print "Remove the '.set_virtualenv' file or configure the virtualenv!" os._exit(1) # Activate virtual environment if necessary if args.environment: __activate_virtualenv() else: for entry in os.listdir(base_dir): if entry.upper().startswith(".USE_VIRTUALENV"): __activate_virtualenv() break # Starting ESCAPEv2 (as a POX module) print "Starting %s..." % parser.description if args.POXlike: pox_base = os.path.realpath((os.path.dirname(__file__) + "/pox")) # Change working directory os.chdir(pox_base) # Override first path element # POX use the first element of path to add pox directories to PYTHONPATH import sys sys.path[0] = pox_base pox_params = cmd[2:] if cmd[0] == "sudo" else cmd[1:] if args.debug: print "POX base: %s" % pox_base print "POX parameters: %s" % pox_params from pox.boot import boot boot(argv=pox_params) else: # Create command cmd = " ".join(cmd) if args.debug: print "Command: %s" % cmd os.system(cmd)
def __init__(self): boot()