Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 port #3

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions README

This file was deleted.

48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# POX

POX is a networking software platform written in Python.

POX started life as an OpenFlow controller, but can now also function as an OpenFlow switch, and can be useful for writing networking software in general.

This POX version requires Python 3+, 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 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.

## Running POX

pox.py 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.

There are two ways to start pox.py:
```sh
# You can manually run the script via the interpreter of your choice (e.g. python3):
# Note that python2/python2.6/python2.7 are not supported anymore
python3 pox.py [pox-options..] [modules..] [module-options..]

# Otherwise, you can let POX select the Python interpreter to use (trying, in order: pypy, python3 or python)
# This might *not* work properly depending on your machine
./pox.py [pox-options..] [modules..] [module-options..]
```

### POX options
pox.py supports a few command line options of its own which should be given before specifying the modules:
- `--verbose` print stack traces for initialization exceptions
- `--no-openflow` don't start the openflow module automatically


### Modules
Modules are looked for everywhere that Python normally looks, plus the "pox" and "ext" directories. Thus, you can do the following:

```sh
python3 pox.py 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()` function.
For example, to set the address or port of the controller, invoke as follows:

```sh
python3 pox.py openflow.of_01 --address=10.1.1.1 --port=6634
```


16 changes: 3 additions & 13 deletions pox.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
# 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 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
Expand All @@ -33,16 +31,8 @@
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

if type python2.6 > /dev/null 2> /dev/null; then
exec python2.6 $OPT "$0" $FLG "$@"
fi

if type python2 > /dev/null 2> /dev/null; then
exec python2 $OPT "$0" $FLG "$@"
if type python3 > /dev/null 2> /dev/null; then
exec python3 $OPT "$0" $FLG "$@"
fi

exec python $OPT "$0" $FLG "$@"
Expand Down
21 changes: 9 additions & 12 deletions pox/boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
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
import logging.config
Expand Down Expand Up @@ -214,7 +211,7 @@ def _do_launch (argv, skip_startup=False):

if getattr(f, '_pox_eval_args', False):
import ast
for k,v in params.items():
for k,v in list(params.items()):
if isinstance(v, str):
try:
params[k] = ast.literal_eval(v)
Expand Down Expand Up @@ -272,7 +269,7 @@ def _do_launch (argv, skip_startup=False):
code = f.__code__
argcount = code.co_argcount
argnames = code.co_varnames[:argcount]
defaults = list((f.func_defaults) or [])
defaults = list((f.__defaults__) or [])
defaults = [EMPTY] * (argcount - len(defaults)) + defaults
args = {}
for n, a in enumerate(argnames):
Expand All @@ -290,7 +287,7 @@ def _do_launch (argv, skip_startup=False):
doc = f.__doc__.split("\n")
#TODO: only strip the same leading space as was on the first
# line
doc = map(str.strip, doc)
doc = list(map(str.strip, doc))
print('',("\n ".join(doc)).strip())

#print(params)
Expand All @@ -304,15 +301,15 @@ def _do_launch (argv, skip_startup=False):
"Active"))
print(" {0:25} {0:25} {0:25}".format("-" * 15))

for k,v in args.iteritems():
for k,v in args.items():
print(" {0:25} {1:25} {2:25}".format(k,str(v[0]),
str(v[1] if v[1] is not EMPTY else v[0])))

if len(params):
print("This component does not have a parameter named "
+ "'{0}'.".format(params.keys()[0]))
+ "'{0}'.".format(list(params.keys())[0]))
return False
missing = [k for k,x in args.iteritems()
missing = [k for k,x in args.items()
if x[1] is EMPTY and x[0] is EMPTY]
if len(missing):
print("You must specify a value for the '{0}' "
Expand All @@ -323,7 +320,7 @@ def _do_launch (argv, skip_startup=False):
else:
# Error is inside the function
raise
elif len(params) > 0 or launch is not "launch":
elif len(params) > 0 or launch != "launch":
print("Module %s has no %s(), but it was specified or passed " \
"arguments" % (name, launch))
return False
Expand Down Expand Up @@ -354,7 +351,7 @@ def set (self, given_name, value):
return True

def process_options (self, options):
for k,v in options.iteritems():
for k,v in options.items():
if self.set(k, v) is False:
# Bad option!
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pox/config/gvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
gvariables = {}

def launch (__INSTANCE__=None, **kw):
for k,v in kw.items():
for k,v in list(kw.items()):
gvariables[k] = v
2 changes: 1 addition & 1 deletion pox/config/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
variables = {}

def launch (__INSTANCE__=None, **kw):
for k,v in kw.items():
for k,v in list(kw.items()):
variables[k] = v
13 changes: 6 additions & 7 deletions pox/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class (an instance of which is available as pox.core.core).
(up and down events), etc.
"""

from __future__ import print_function


# Set up initial log state
import logging
Expand Down Expand Up @@ -371,12 +371,11 @@ def goUp (self):
vers = '.'.join(platform.python_version().split(".")[:2])
except:
vers = 'an unknown version'
if vers != "2.7":
if float(vers) >= 3:
l = logging.getLogger("version")
if not l.isEnabledFor(logging.WARNING):
l.setLevel(logging.WARNING)
l.warn("POX requires Python 2.7. You're running %s.", vers)
l.warn("If you run into problems, try using Python 2.7 or PyPy.")
l.warn("Support for Python 3 is experimental.")

self.starting_up = False
self.raiseEvent(GoingUpEvent())
Expand Down Expand Up @@ -483,7 +482,7 @@ def call_when_ready (self, callback, components=[], name=None, args=(),
if callback is None:
callback = lambda:None
callback.__name__ = "<None>"
if isinstance(components, basestring):
if isinstance(components, str):
components = [components]
elif isinstance(components, set):
components = list(components)
Expand Down Expand Up @@ -577,7 +576,7 @@ def _handle_topology_SwitchJoin (self, ...):
"""
if components is None:
components = set()
elif isinstance(components, basestring):
elif isinstance(components, str):
components = set([components])
else:
components = set(components)
Expand All @@ -591,7 +590,7 @@ def _handle_topology_SwitchJoin (self, ...):
if None in listen_args:
# This means add it to all...
args = listen_args.pop(None)
for k,v in args.iteritems():
for k,v in args.items():
for c in components:
if c not in listen_args:
listen_args[c] = {}
Expand Down
2 changes: 1 addition & 1 deletion pox/datapaths/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""

from pox.core import core
from Queue import Queue
from queue import Queue
import pox.lib.packet as pkt
from pox.lib.interfaceio import PCapInterface

Expand Down
Loading