From 12d6584bee4aca4a5bf2e93e3b8eca43cae76d0d Mon Sep 17 00:00:00 2001 From: Victor Orlikowski Date: Tue, 2 Aug 2016 11:02:31 +0900 Subject: [PATCH] Ensure that send() and send_msg() in controller return status to calling applications When a Datapath disconnects, an application may not know about it until it attempts to send a message to that Datapath. Ryu's core will detect the failure to send, and will close the Datapath object - but has no way of letting the application know that it did so. With this patch, send_msg() returns True or False, depending on whether the message that the application was trying to send was able to be enqueued to send via a given Datapath object. If the Datapath.send_msg() returns False, the calling application can thereby determine that the Datapath is no longer valid, and should clean up any references it has to it. Existing applications may choose to ignore the return value, and nothing breaks. I have patched one utility method that uses send_msg(), since it was not marked as deprecated. All utility methods marked as deprecated, I have not altered. Signed-off-by: Victor J. Orlikowski Signed-off-by: FUJITA Tomonori --- ryu/controller/controller.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py index 54fb1c95..cf9deb99 100644 --- a/ryu/controller/controller.py +++ b/ryu/controller/controller.py @@ -319,6 +319,7 @@ class Datapath(ofproto_protocol.ProtocolDesc): if not msg_enqueued: LOG.debug('Datapath in process of terminating; send() to %s discarded.', self.address) + return msg_enqueued def set_xid(self, msg): self.xid += 1 @@ -332,7 +333,7 @@ class Datapath(ofproto_protocol.ProtocolDesc): self.set_xid(msg) msg.serialize() # LOG.debug('send_msg %s', msg) - self.send(msg.buf) + return self.send(msg.buf) def _echo_request_loop(self): if not self.max_unreplied_echo_requests: @@ -418,7 +419,7 @@ class Datapath(ofproto_protocol.ProtocolDesc): def send_barrier(self): barrier_request = self.ofproto_parser.OFPBarrierRequest(self) - self.send_msg(barrier_request) + return self.send_msg(barrier_request) def send_nxt_set_flow_format(self, flow_format): assert (flow_format == ofproto_v1_0.NXFF_OPENFLOW10 or