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>
This commit is contained in:
IWASE Yusuke 2018-03-06 15:52:23 +09:00 committed by FUJITA Tomonori
parent 3003d475d2
commit 4e10ba4438
6 changed files with 16 additions and 5 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)