diff --git a/README b/README index ee77184eb..6b19bb5d8 100644 --- a/README +++ b/README @@ -8,29 +8,29 @@ POX officially requires Python 2.7 (though much of it will work fine fine with Python 2.6), and should run under Linux, Mac OS, and Windows. (And just about anywhere else -- we've run it on Android phones, under FreeBSD, Haiku, and elsewhere. All you need is Python!) -You can place a pypy distribution alongside pox.py (in a directory +You can place a pypy distribution alongside pox (in a directory named "pypy"), and POX will run with pypy (this can be a significant performance boost!). POX currently communicates with OpenFlow 1.0 switches and includes special support for the Open vSwitch/Nicira extensions. -pox.py boots up POX. It takes a list of module names on the command line, +pox boots up POX. It takes a list of module names on the command line, locates the modules, calls their launch() function (if it exists), and then transitions to the "up" state. Modules are looked for everywhere that Python normally looks, plus the "pox" and "ext" directories. Thus, you can do the following: - ./pox.py forwarding.l2_learning + ./pox forwarding.l2_learning You can pass options to the modules by specifying options after the module name. These are passed to the module's launch() funcion. For example, to set the address or port of the controller, invoke as follows: - ./pox.py openflow.of_01 --address=10.1.1.1 --port=6634 + ./pox openflow.of_01 --address=10.1.1.1 --port=6634 -pox.py also supports a few command line options of its own which should +pox also supports a few command line options of its own which should be given first: --verbose print stack traces for initialization exceptions --no-openflow don't start the openflow module automatically diff --git a/debug-pox.py b/debug-pox.py deleted file mode 120000 index dac916991..000000000 --- a/debug-pox.py +++ /dev/null @@ -1 +0,0 @@ -pox.py \ No newline at end of file diff --git a/ext/skeleton.py b/ext/skeleton.py index 015e622cd..2478849c0 100644 --- a/ext/skeleton.py +++ b/ext/skeleton.py @@ -20,14 +20,14 @@ don't want to release under Apache (but consider doing so!). Rename this file to whatever you like, .e.g., mycomponent.py. You can -then invoke it with "./pox.py mycomponent" if you leave it in the +then invoke it with "pox mycomponent" if you leave it in the ext/ directory. Implement a launch() function (as shown below) which accepts commandline arguments and starts off your component (e.g., by listening to events). Edit this docstring and your launch function's docstring. These will -show up when used with the help component ("./pox.py help --mycomponent"). +show up when used with the help component ("pox help --mycomponent"). """ # Import some POX stuff @@ -63,7 +63,7 @@ def launch (foo, bar = False): # specify a keyword arguments catch-all (e.g., **kwargs). # For example, you can execute this component as: - # ./pox.py skeleton --foo=3 --bar=4 + # pox skeleton --foo=3 --bar=4 # Note that arguments passed from the commandline are ordinarily # always strings, and it's up to you to validate and convert them. @@ -95,7 +95,7 @@ def breakfast (): # You can invoke other functions from the commandline too. We call # these multiple or alternative launch functions. To execute this # one, you'd do: - # ./pox.py skeleton:breakfast + # pox skeleton:breakfast import random items = "egg,bacon,sausage,baked beans,tomato".split(',') diff --git a/pox.py b/pox.py deleted file mode 100755 index ab4832d36..000000000 --- a/pox.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh - - -# Copyright 2011-2012 James McCauley -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at: -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# 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__': - boot() diff --git a/pox/boot.py b/pox/boot.py old mode 100755 new mode 100644 index 026a9add5..d9665b89d --- a/pox/boot.py +++ b/pox/boot.py @@ -1,5 +1,3 @@ -#!/bin/sh - - # Copyright 2011,2012,2013 James McCauley # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -# If you have PyPy 1.6+ in a directory called pypy alongside pox.py, we +# If you have PyPy 1.6+ in a directory called pypy alongside pox, 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. @@ -22,24 +20,6 @@ #TODO: Make runnable by itself (paths need adjusting, etc.). -''''true -export OPT="-u -O" -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; then - exec python2.7 $OPT "$0" $FLG "$@" -fi -exec python $OPT "$0" $FLG "$@" -''' - from __future__ import print_function import logging @@ -353,7 +333,7 @@ def process_options (self, options): POX is a Software Defined Networking controller framework. The commandline of POX is like: -pox.py [POX options] [C1 [C1 options]] [C2 [C2 options]] ... +pox [POX options] [C1 [C1 options]] [C2 [C2 options]] ... Notable POX options include: --verbose Print more debugging information (especially useful for @@ -366,10 +346,10 @@ def process_options (self, options): support are up to the module. As an example, you can load a learning switch app that listens on a non-standard port number by specifying an option to the of_01 component, and loading the l2_learning component like: - ./pox.py --verbose openflow.of_01 --port=6634 forwarding.l2_learning + pox --verbose openflow.of_01 --port=6634 forwarding.l2_learning The 'help' component can give help for other components. Start with: - ./pox.py help --help + pox help --help """.strip() @@ -506,10 +486,10 @@ 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'))) + # Add pox library to path and the current $PWD/ext + curdir = os.path.join(os.path.abspath(''), 'ext') + sys.path.insert(0, curdir) + sys.path.insert(0, core.library) thread_count = threading.active_count() diff --git a/pox/core.py b/pox/core.py index b41133d94..f22b13650 100644 --- a/pox/core.py +++ b/pox/core.py @@ -594,6 +594,12 @@ def __getattr__ (self, name): raise AttributeError("'%s' not registered" % (name,)) + @property + def library(self): + version = ".".join(map(str, core.version)) + pox_dir = "pox-{0}".format(version) + return os.path.join(os.path.sep, 'var', 'lib', pox_dir) + core = None def initialize (threaded_selecthub=True, epoll_selecthub=False, diff --git a/pox/datapaths/__init__.py b/pox/datapaths/__init__.py index bdd8538aa..acb8d048f 100644 --- a/pox/datapaths/__init__.py +++ b/pox/datapaths/__init__.py @@ -16,7 +16,7 @@ Lets you start a default instance of the datapath, for what it's worth. Example: -./pox.py --no-openflow datapaths:softwareswitch --address=localhost +pox --no-openflow datapaths:softwareswitch --address=localhost """ from pox.lib.ioworker.workers import BackoffWorker diff --git a/pox/datapaths/pcap_switch.py b/pox/datapaths/pcap_switch.py index 85837ddfc..6198f3cc4 100644 --- a/pox/datapaths/pcap_switch.py +++ b/pox/datapaths/pcap_switch.py @@ -16,7 +16,7 @@ Software switch with PCap ports Example: -./pox.py --no-openflow datapaths.pcap_switch --address=localhost +pox --no-openflow datapaths.pcap_switch --address=localhost """ from pox.core import core diff --git a/pox/forwarding/l2_nx.py b/pox/forwarding/l2_nx.py index c3489a94e..31f32876c 100644 --- a/pox/forwarding/l2_nx.py +++ b/pox/forwarding/l2_nx.py @@ -17,7 +17,7 @@ This learning switch requires Nicira extensions as found in Open vSwitch. Furthermore, you must enable packet-in conversion. Run with something like: - ./pox.py openflow.nicira --convert-packet-in forwarding.l2_nx + pox openflow.nicira --convert-packet-in forwarding.l2_nx This forwards based on ethernet source and destination addresses. Where l2_pairs installs rules for each pair of source and destination address, diff --git a/pox/forwarding/l2_nx_self_learning.py b/pox/forwarding/l2_nx_self_learning.py index 83b567bb2..89d3d40e6 100644 --- a/pox/forwarding/l2_nx_self_learning.py +++ b/pox/forwarding/l2_nx_self_learning.py @@ -18,7 +18,7 @@ This uses the "learn" action so that switches become learning switches *with no controller involvement*. - ./pox.py openflow.nicira forwarding.l2_nx_self_learning + pox openflow.nicira forwarding.l2_nx_self_learning """ from pox.core import core diff --git a/pox/info/debug_deadlock.py b/pox/info/debug_deadlock.py index 64395b5ce..82b04aca2 100644 --- a/pox/info/debug_deadlock.py +++ b/pox/info/debug_deadlock.py @@ -18,7 +18,7 @@ (Might be more useful if it only printed stack frames that were not changing, sort of like recoco_spy.) -This was initially factored out from a pox.py modification by +This was initially factored out from a pox modification by Colin or Andi. """ diff --git a/pox/log/__init__.py b/pox/log/__init__.py index a456155c8..5da93ec69 100644 --- a/pox/log/__init__.py +++ b/pox/log/__init__.py @@ -45,8 +45,8 @@ def launch (__INSTANCE__ = None, **kw): Allows you to configure log handlers from the commandline. Examples: - ./pox.py log --file=pox.log,w --syslog --no-default - ./pox.py log --*TimedRotatingFile=filename=foo.log,when=D,backupCount=5 + pox log --file=pox.log,w --syslog --no-default + pox log --*TimedRotatingFile=filename=foo.log,when=D,backupCount=5 The handlers are most of the ones described in Python's logging.handlers, and the special one --no-default, which turns off the default logging to diff --git a/pox/log/level.py b/pox/log/level.py index 5bb091f94..ecd8c3287 100644 --- a/pox/log/level.py +++ b/pox/log/level.py @@ -21,7 +21,7 @@ def launch (__INSTANCE__=None, **kw): Allows configuring log levels from the commandline. For example, to turn off the verbose web logging, try: - pox.py web.webcore log.level --web.webcore=INFO + pox web.webcore log.level --web.webcore=INFO """ for k,v in kw.iteritems(): if v is True: diff --git a/pox/misc/gephi_topo.py b/pox/misc/gephi_topo.py index d2a56b89e..a10ad11c5 100644 --- a/pox/misc/gephi_topo.py +++ b/pox/misc/gephi_topo.py @@ -23,7 +23,7 @@ Based on POXDesk's tinytopo module. Requires discovery. host_tracker is optional. -pox.py openflow.discovery misc.gephi_topo host_tracker forwarding.l2_learning +pox openflow.discovery misc.gephi_topo host_tracker forwarding.l2_learning """ from pox.core import core diff --git a/pox/openflow/__init__.py b/pox/openflow/__init__.py index 001f3972e..da5a9c42a 100644 --- a/pox/openflow/__init__.py +++ b/pox/openflow/__init__.py @@ -30,7 +30,7 @@ generally just want to listen to the aggregate stats events which take care of this for you and are only fired when all data is available. -NOTE: This module is usually automatically loaded by pox.py +NOTE: This module is usually automatically loaded by pox """ from pox.lib.revent import * diff --git a/pox/topology/topology.py b/pox/topology/topology.py index 543f7d528..40d3e536f 100644 --- a/pox/topology/topology.py +++ b/pox/topology/topology.py @@ -19,7 +19,7 @@ with OpenFlow switches. Note that this means that you often want to invoke something like: - $ ./pox.py topology openflow.discovery openflow.topology + $ pox topology openflow.discovery openflow.topology """ from pox.lib.revent import * diff --git a/pox/web/webcore.py b/pox/web/webcore.py index 8633862f2..cb3e328dd 100644 --- a/pox/web/webcore.py +++ b/pox/web/webcore.py @@ -26,8 +26,8 @@ core.WebServer.set_handler("/foo", wrapRequestHandler(CHRH)) .. now URLs under the /foo/ directory will let you browse through the -filesystem next to pox.py. If you create a cgi-bin directory next to -pox.py, you'll be able to run executables in it. +filesystem next to pox. If you create a cgi-bin directory next to +pox, you'll be able to run executables in it. For this specific purpose, there's actually a SplitCGIRequestHandler which demonstrates wrapping a normal request handler while also diff --git a/setup.py b/setup.py new file mode 100644 index 000000000..6deaa491e --- /dev/null +++ b/setup.py @@ -0,0 +1,38 @@ +import glob +import os + +import pox.core +from setuptools import setup +from setuptools import find_packages + + +NAME="pox" +DESCRIPTION="POX is a networking software platform." + + +core = pox.core.initialize() +VERSION=".".join(map(str,core.version)) + +tools=glob.glob("tools/*") +exts=glob.glob("ext/*.py") +docs=['LICENSE', 'README', 'NOTICE'] +pox_dir="pox-{0}".format(VERSION) +shares=os.path.join("usr", "share", pox_dir) + +setup(name=NAME, + version=VERSION, + description=DESCRIPTION, + author="Murphy McCauley", + url="http://www.noxrepo.org/", + packages=find_packages(exclude=["tests", "tests.*"]), + data_files=[ + (os.path.join(shares, 'tools'), tools), + (os.path.join(core.library, 'ext'), exts), + (os.path.join(shares, "doc"), docs), + ], + entry_points={ + 'console_scripts': [ + 'pox = pox.boot:boot', + ], + }, +)