summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-03-06 15:52:23 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-03-26 22:11:39 +0900
commit4e10ba44381ca5fa095b5cfc69e7c6fc407642a8 (patch)
tree2eac68307d00fee7ab49acc84b423bc48a5decb6
parent3003d475d268efbff0fa2df56104968e71761ca8 (diff)
ofproto: Encode data field on OFPErrorMsg
Currently, when Ryu failed to negotiate the OpenFlow version with a switch, Ryu will send the OFPT_ERROR message with an error reason on its data field. But on Python 3, error reason string is a str type value and required to be encoded into a bytes type value, otherwise causes an exception when sending the message. This patch fixes to encode the given str value into a bytes type value in OFPErrorMsg.__init__() and solves this problem. Signed-off-by: William Fisher <william.w.fisher@gmail.com> Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/controller/ofp_handler.py11
-rw-r--r--ryu/ofproto/ofproto_v1_0_parser.py2
-rw-r--r--ryu/ofproto/ofproto_v1_2_parser.py2
-rw-r--r--ryu/ofproto/ofproto_v1_3_parser.py2
-rw-r--r--ryu/ofproto/ofproto_v1_4_parser.py2
-rw-r--r--ryu/ofproto/ofproto_v1_5_parser.py2
6 files changed, 16 insertions, 5 deletions
diff --git a/ryu/controller/ofp_handler.py b/ryu/controller/ofp_handler.py
index 6ab02fe8..5c4d46de 100644
--- a/ryu/controller/ofp_handler.py
+++ b/ryu/controller/ofp_handler.py
@@ -60,11 +60,12 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
return hub.spawn(self.controller)
def _hello_failed(self, datapath, error_desc):
- self.logger.error(error_desc)
- error_msg = datapath.ofproto_parser.OFPErrorMsg(datapath)
- error_msg.type = datapath.ofproto.OFPET_HELLO_FAILED
- error_msg.code = datapath.ofproto.OFPHFC_INCOMPATIBLE
- error_msg.data = error_desc
+ self.logger.error('%s on datapath %s', error_desc, datapath.address)
+ error_msg = datapath.ofproto_parser.OFPErrorMsg(
+ datapath=datapath,
+ type_=datapath.ofproto.OFPET_HELLO_FAILED,
+ code=datapath.ofproto.OFPHFC_INCOMPATIBLE,
+ data=error_desc)
datapath.send_msg(error_msg, close_socket=True)
@set_ev_handler(ofp_event.EventOFPHello, HANDSHAKE_DISPATCHER)
diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py
index bfc55512..a288964a 100644
--- a/ryu/ofproto/ofproto_v1_0_parser.py
+++ b/ryu/ofproto/ofproto_v1_0_parser.py
@@ -1258,6 +1258,8 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
+ if isinstance(data, six.string_types):
+ data = data.encode('ascii')
self.data = data
@classmethod
diff --git a/ryu/ofproto/ofproto_v1_2_parser.py b/ryu/ofproto/ofproto_v1_2_parser.py
index 9b4dda4b..244126c3 100644
--- a/ryu/ofproto/ofproto_v1_2_parser.py
+++ b/ryu/ofproto/ofproto_v1_2_parser.py
@@ -141,6 +141,8 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
+ if isinstance(data, six.string_types):
+ data = data.encode('ascii')
self.data = data
if self.type == ofproto.OFPET_EXPERIMENTER:
self.exp_type = kwargs.get('exp_type', None)
diff --git a/ryu/ofproto/ofproto_v1_3_parser.py b/ryu/ofproto/ofproto_v1_3_parser.py
index 7730aa12..0324c82b 100644
--- a/ryu/ofproto/ofproto_v1_3_parser.py
+++ b/ryu/ofproto/ofproto_v1_3_parser.py
@@ -251,6 +251,8 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
+ if isinstance(data, six.string_types):
+ data = data.encode('ascii')
self.data = data
if self.type == ofproto.OFPET_EXPERIMENTER:
self.exp_type = kwargs.get('exp_type', None)
diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py
index fca35f57..470e2013 100644
--- a/ryu/ofproto/ofproto_v1_4_parser.py
+++ b/ryu/ofproto/ofproto_v1_4_parser.py
@@ -262,6 +262,8 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
+ if isinstance(data, six.string_types):
+ data = data.encode('ascii')
self.data = data
if self.type == ofproto.OFPET_EXPERIMENTER:
self.exp_type = kwargs.get('exp_type', None)
diff --git a/ryu/ofproto/ofproto_v1_5_parser.py b/ryu/ofproto/ofproto_v1_5_parser.py
index 03946622..c19a7e8d 100644
--- a/ryu/ofproto/ofproto_v1_5_parser.py
+++ b/ryu/ofproto/ofproto_v1_5_parser.py
@@ -262,6 +262,8 @@ class OFPErrorMsg(MsgBase):
super(OFPErrorMsg, self).__init__(datapath)
self.type = type_
self.code = code
+ if isinstance(data, six.string_types):
+ data = data.encode('ascii')
self.data = data
if self.type == ofproto.OFPET_EXPERIMENTER:
self.exp_type = kwargs.get('exp_type', None)