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.fis...@gmail.com>
Signed-off-by: IWASE Yusuke <iwase.yusu...@gmail.com>
---
 ryu/controller/ofp_handler.py      | 11 ++++++-----
 ryu/ofproto/ofproto_v1_0_parser.py |  2 ++
 ryu/ofproto/ofproto_v1_2_parser.py |  2 ++
 ryu/ofproto/ofproto_v1_3_parser.py |  2 ++
 ryu/ofproto/ofproto_v1_4_parser.py |  2 ++
 ryu/ofproto/ofproto_v1_5_parser.py |  2 ++
 6 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/ryu/controller/ofp_handler.py b/ryu/controller/ofp_handler.py
index 6ab02fe..5c4d46d 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 bfc5551..a288964 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 9b4dda4..244126c 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 7730aa1..0324c82 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 fca35f5..470e201 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 0394662..c19a7e8 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)
--
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to