diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2016-12-16 15:17:41 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-12-29 22:58:43 +0900 |
commit | 27b253d06e42e5a79ce00508d8bdade6f53724d4 (patch) | |
tree | 97e6eabe93f348071122f131b868e1c46ad70ff8 | |
parent | f1edc9fbd08f7b25d341eec37934fd39206cecf9 (diff) |
BGPSpeaker/net_ctrl: Move _send_*_response() function
This patch moves _send_*_response() function into RpcSession class
to use socket wrapper methods for maintaining the connection state
safely.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/services/protocols/bgp/net_ctrl.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/ryu/services/protocols/bgp/net_ctrl.py b/ryu/services/protocols/bgp/net_ctrl.py index 342e2efe..400032c8 100644 --- a/ryu/services/protocols/bgp/net_ctrl.py +++ b/ryu/services/protocols/bgp/net_ctrl.py @@ -156,6 +156,16 @@ class RpcSession(Activity): for msg in self._unpacker: return msg + def _send_error_response(self, request, err_msg): + rpc_msg = self.create_error_response(request[RPC_IDX_MSG_ID], + str(err_msg)) + return self._sendall(rpc_msg) + + def _send_success_response(self, request, result): + rpc_msg = self.create_success_response(request[RPC_IDX_MSG_ID], + result) + return self._sendall(rpc_msg) + def send_notification(self, method, params): rpc_msg = self.create_notification(method, params) return self._sendall(rpc_msg) @@ -177,10 +187,9 @@ class RpcSession(Activity): if msg[0] == RPC_MSG_REQUEST: try: result = _handle_request(msg) - _send_success_response(self, self._socket, msg, result) + self._send_success_response(msg, result) except BGPSException as e: - _send_error_response(self, self._socket, msg, - e.message) + self._send_error_response(msg, e.message) elif msg[0] == RPC_MSG_RESPONSE: _handle_response(msg) elif msg[0] == RPC_MSG_NOTIFY: @@ -384,17 +393,5 @@ def _handle_request(request): raise ApiException(desc='Invalid type for RPC parameter.') -def _send_success_response(rpc_session, sock, request, result): - response = rpc_session.create_success_response(request[RPC_IDX_MSG_ID], - result) - sock.sendall(response) - - -def _send_error_response(rpc_session, sock, request, emsg): - response = rpc_session.create_error_response(request[RPC_IDX_MSG_ID], - str(emsg)) - sock.sendall(response) - - # Network controller singleton NET_CONTROLLER = _NetworkController() |