summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-03-06 15:52:20 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-03-26 22:11:25 +0900
commit7a40d5c2f305d8200566d735619c7605ab778080 (patch)
treef93a434f9258acd69a63cc157ec78aed13c1f75d
parent976914f5e651ace55ef4e7f847381b37a9c386c4 (diff)
controller: Option to close socket after sending Message
Currently, Ryu does not provide the way to close a socket connecting to a switch after sending all enqueued messages, but provides only the way to close the socket immediately regardless of enqueued messages. This patch adds a new option "close_socket" into "Datapath.send_msg()" method and this option enables to close the socket after sending the given message. This patch is convenient to close the socket after sending OFPT_ERROR message to the switch. 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/controller.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
index c0e58659..f46cf009 100644
--- a/ryu/controller/controller.py
+++ b/ryu/controller/controller.py
@@ -362,9 +362,11 @@ class Datapath(ofproto_protocol.ProtocolDesc):
def _send_loop(self):
try:
while self.state != DEAD_DISPATCHER:
- buf = self.send_q.get()
+ buf, close_socket = self.send_q.get()
self._send_q_sem.release()
self.socket.sendall(buf)
+ if close_socket:
+ break
except SocketTimeout:
LOG.debug("Socket timed out while sending data to switch at address %s",
self.address)
@@ -387,11 +389,11 @@ class Datapath(ofproto_protocol.ProtocolDesc):
# Finally, ensure the _recv_loop terminates.
self.close()
- def send(self, buf):
+ def send(self, buf, close_socket=False):
msg_enqueued = False
self._send_q_sem.acquire()
if self.send_q:
- self.send_q.put(buf)
+ self.send_q.put((buf, close_socket))
msg_enqueued = True
else:
self._send_q_sem.release()
@@ -406,13 +408,13 @@ class Datapath(ofproto_protocol.ProtocolDesc):
msg.set_xid(self.xid)
return self.xid
- def send_msg(self, msg):
+ def send_msg(self, msg, close_socket=False):
assert isinstance(msg, self.ofproto_parser.MsgBase)
if msg.xid is None:
self.set_xid(msg)
msg.serialize()
# LOG.debug('send_msg %s', msg)
- return self.send(msg.buf)
+ return self.send(msg.buf, close_socket=close_socket)
def _echo_request_loop(self):
if not self.max_unreplied_echo_requests: