cmp() func was introduced for Python 3 compatibility before,
but this implementation is not enough, because a MAC address
can not be compared with a Bridge ID (integer value) by com() func.

This patch fixes to convert the MAC address into an integer value
before comparing with Bridge ID and fixes this problem.

Signed-off-by: Shinpei Muraoka <shinpei.mura...@gmail.com>
---
 ryu/lib/mac.py    | 9 +++++++++
 ryu/lib/stplib.py | 6 ++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/ryu/lib/mac.py b/ryu/lib/mac.py
index 88ab336..4ebac00 100644
--- a/ryu/lib/mac.py
+++ b/ryu/lib/mac.py
@@ -49,6 +49,15 @@ def haddr_to_str(addr):
         raise AssertionError
 
 
+def haddr_to_int(addr):
+    """Convert mac address string in human readable format into
+    integer value"""
+    try:
+        return int(addr.replace(':', ''), 16)
+    except:
+        raise ValueError
+
+
 def haddr_to_bin(string):
     """Parse mac address string in human readable format into
     internal representation"""
diff --git a/ryu/lib/stplib.py b/ryu/lib/stplib.py
index bb5bd6f..ff28d9e 100644
--- a/ryu/lib/stplib.py
+++ b/ryu/lib/stplib.py
@@ -25,6 +25,7 @@ from ryu.controller.handler import set_ev_cls
 from ryu.exception import RyuException
 from ryu.exception import OFPUnknownVersion
 from ryu.lib import hub
+from ryu.lib import mac
 from ryu.lib.dpid import dpid_to_str
 from ryu.lib.packet import bpdu
 from ryu.lib.packet import ethernet
@@ -351,7 +352,8 @@ class Stp(app_manager.RyuApp):
                 if not result:
                     result1 = Stp._cmp_value(
                         rcv_priority.designated_bridge_id.value,
-                        my_priority.designated_bridge_id.mac_addr)
+                        mac.haddr_to_int(
+                            my_priority.designated_bridge_id.mac_addr))
                     result2 = Stp._cmp_value(
                         rcv_priority.designated_port_id.value,
                         my_priority.designated_port_id.port_no)
@@ -363,7 +365,7 @@ class Stp(app_manager.RyuApp):
 
     @staticmethod
     def _cmp_value(value1, value2):
-        result = cmp(str(value1), str(value2))
+        result = cmp(value1, value2)
         if result < 0:
             return SUPERIOR
         elif result == 0:
-- 
2.7.4


------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to