[Ryu-devel] [PATCH] app/ofctl: Enable to send single BarrierRequest
Brought to you by:
nz_gizmoguy
|
From: Satoshi F. <sat...@gm...> - 2017-10-17 01:25:18
|
Currently, with ryu.app.ofctl.api.send_msg(),
a BarrierRequest will send with every messages.
So, using send_msg() with a BarrierRequest will
cause duplex transmission of BarrierRequests.
This commit enables to send a single BarrierRequest
if send_msg() is used with a BarrierRequest
by avoiding sending an additional BarrierRequest.
Signed-off-by: Satoshi Fujimoto <sat...@gm...>
---
ryu/app/ofctl/service.py | 46 ++++++++++++++++++++++++++++------------------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/ryu/app/ofctl/service.py b/ryu/app/ofctl/service.py
index 19aebd4..ad943a2 100644
--- a/ryu/app/ofctl/service.py
+++ b/ryu/app/ofctl/service.py
@@ -113,6 +113,7 @@ class OfctlService(app_manager.RyuApp):
def _handle_send_msg(self, req):
msg = req.msg
datapath = msg.datapath
+ parser = datapath.ofproto_parser
try:
si = self._switches[datapath.id]
@@ -123,28 +124,34 @@ class OfctlService(app_manager.RyuApp):
self.reply_to_request(req, rep)
return
- if req.reply_cls is not None:
- self._observe_msg(req.reply_cls)
-
- datapath.set_xid(msg)
- xid = msg.xid
- barrier = datapath.ofproto_parser.OFPBarrierRequest(datapath)
- datapath.set_xid(barrier)
- barrier_xid = barrier.xid
- assert xid not in si.results
- assert xid not in si.xids
- assert barrier_xid not in si.barriers
- si.results[xid] = []
- si.xids[xid] = req
- si.barriers[barrier_xid] = xid
-
- datapath.send_msg(msg)
+ def _store_xid(xid, barrier_xid):
+ assert xid not in si.results
+ assert xid not in si.xids
+ assert barrier_xid not in si.barriers
+ si.results[xid] = []
+ si.xids[xid] = req
+ si.barriers[barrier_xid] = xid
+
+ if isinstance(req.msg, parser.OFPBarrierRequest):
+ barrier = msg
+ datapath.set_xid(barrier)
+ _store_xid(barrier.xid, barrier.xid)
+ else:
+ if req.reply_cls is not None:
+ self._observe_msg(req.reply_cls)
+ datapath.set_xid(msg)
+ barrier = datapath.ofproto_parser.OFPBarrierRequest(datapath)
+ datapath.set_xid(barrier)
+ _store_xid(msg.xid, barrier.xid)
+ datapath.send_msg(msg)
+
datapath.send_msg(barrier)
@set_ev_cls(ofp_event.EventOFPBarrierReply, MAIN_DISPATCHER)
def _handle_barrier(self, ev):
msg = ev.msg
datapath = msg.datapath
+ parser = datapath.ofproto_parser
try:
si = self._switches[datapath.id]
except KeyError:
@@ -157,9 +164,12 @@ class OfctlService(app_manager.RyuApp):
return
result = si.results.pop(xid)
req = si.xids.pop(xid)
- if req.reply_cls is not None:
+ is_barrier = isinstance(req.msg, parser.OFPBarrierRequest)
+ if req.reply_cls is not None and not is_barrier:
self._unobserve_msg(req.reply_cls)
- if any(self._is_error(r) for r in result):
+ if is_barrier and req.reply_cls == parser.OFPBarrierReply:
+ rep = event.Reply(result=ev.msg)
+ elif any(self._is_error(r) for r in result):
rep = event.Reply(exception=exception.OFError(result=result))
elif req.reply_multi:
rep = event.Reply(result=result)
--
2.7.4
|