summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorShinpei Muraoka <shinpei.muraoka@gmail.com>2016-09-27 12:01:04 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-10-01 20:46:28 +0900
commitd23c07054e6f33b392f49f6fceacbdb891be3d87 (patch)
tree31a9e19c855b9393be32bdb51762cba470243996
parent29d1a97139535a07c4f87923d4401175a584c183 (diff)
stplib: Fix to compare MAC address and Bridge ID
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.muraoka@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/lib/mac.py9
-rw-r--r--ryu/lib/stplib.py6
2 files changed, 13 insertions, 2 deletions
diff --git a/ryu/lib/mac.py b/ryu/lib/mac.py
index 88ab3363..4ebac00a 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 bb5bd6f0..ff28d9ec 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: