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:
parent
3003d475d2
commit
4e10ba4438
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user