Skip to content

Commit

Permalink
Provide standard install.
Browse files Browse the repository at this point in the history
Resolves noxrepo#145.

- Added a setup.py
- Provide an entry_point to pox.boot.boot() for the cli
- Install /var/lib/pox-<version>
- Now looks for extensions in /var/lib/pox-<version>/ext
- Also looks for extensions in $PWD/ext
- installs tools to /var/lib/pox-<version>/tools
- licenses, readme, etc. installed to /var/lib/pox-<version>/doc
- Removes the debug-config.py alias trick due to pathing issues for cli install
        - now use pox --debug
- Removes the pypy trick.
        - to use pypy, install with pypy via:
                pypy setup.py install
          This will ensure scripts have a #!/usr/bin/pypy shebang.
  • Loading branch information
jameskyle committed Apr 29, 2015
1 parent bab636b commit d3b1b5a
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 96 deletions.
10 changes: 5 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion debug-pox.py

This file was deleted.

8 changes: 4 additions & 4 deletions ext/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(',')
Expand Down
45 changes: 0 additions & 45 deletions pox.py

This file was deleted.

36 changes: 8 additions & 28 deletions pox/boot.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/sh -

# Copyright 2011,2012,2013 James McCauley
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,32 +12,14 @@
# 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.
# We fall back to just "python" and hope that works.

#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
Expand Down Expand Up @@ -345,7 +325,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
Expand All @@ -358,10 +338,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()


Expand Down Expand Up @@ -479,10 +459,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()

Expand Down
6 changes: 6 additions & 0 deletions pox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,12 @@ def __getattr__ (self, name):
return self.components[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 ():
Expand Down
2 changes: 1 addition & 1 deletion pox/datapaths/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pox/datapaths/pcap_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pox/forwarding/l2_nx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pox/forwarding/l2_nx_self_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pox/info/debug_deadlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""

Expand Down
4 changes: 2 additions & 2 deletions pox/log/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pox/log/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pox/misc/gephi_topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pox/openflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
2 changes: 1 addition & 1 deletion pox/topology/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down
4 changes: 2 additions & 2 deletions pox/web/webcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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',
],
},
)

0 comments on commit d3b1b5a

Please sign in to comment.