summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2016-07-25 14:41:06 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-27 14:31:21 +0900
commitf52bb7007ec6c8ec94a90b2d4c4296d23936dd24 (patch)
tree3a538c0233e7a052ad47f892e4299e67f9af6907
parenta909fa3044d1873fd081eee65fec0829ab8b257a (diff)
stplib: Adopt to Python3
In Python3, cmp() method is no longer supported and numerical operations evaluates value type more strictly. So, stplib get some errors in its calculating process. This patch fixes these problems and enable to use stplib on Python3 interpreter. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/packet/bpdu.py2
-rw-r--r--ryu/lib/stplib.py9
2 files changed, 9 insertions, 2 deletions
diff --git a/ryu/lib/packet/bpdu.py b/ryu/lib/packet/bpdu.py
index 8926b2af..da3d9cba 100644
--- a/ryu/lib/packet/bpdu.py
+++ b/ryu/lib/packet/bpdu.py
@@ -379,7 +379,7 @@ class ConfigurationBPDUs(bpdu):
@staticmethod
def _encode_timer(timer):
- return timer * 0x100
+ return int(timer) * 0x100
@bpdu.register_bpdu_type
diff --git a/ryu/lib/stplib.py b/ryu/lib/stplib.py
index fd17b2ae..de3cced8 100644
--- a/ryu/lib/stplib.py
+++ b/ryu/lib/stplib.py
@@ -169,6 +169,13 @@ class EventPacketIn(event.EventBase):
self.msg = msg
+# For Python3 compatibility
+# Note: The following is the official workaround for cmp() in Python2.
+# https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons
+def cmp(a, b):
+ return (a > b) - (a < b)
+
+
class Stp(app_manager.RyuApp):
""" STP(spanning tree) library. """
@@ -351,7 +358,7 @@ class Stp(app_manager.RyuApp):
@staticmethod
def _cmp_value(value1, value2):
- result = cmp(value1, value2)
+ result = cmp(str(value1), str(value2))
if result < 0:
return SUPERIOR
elif result == 0: