summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-10-17 10:24:53 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-11-01 23:22:37 +0900
commit92730dc7e9906649d761bb1ee4cc1a354d4ef96c (patch)
tree9378a9a6ece7bdbfcc0244a0aeabb8d8e4387e2d
parent66bdeaa7b5071d9b4f073924c64017a6f4d7882f (diff)
app/ofctl: Enable to send single BarrierRequest
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 <satoshi.fujimoto7@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/app/ofctl/service.py46
1 files changed, 28 insertions, 18 deletions
diff --git a/ryu/app/ofctl/service.py b/ryu/app/ofctl/service.py
index 19aebd4b..ad943a2f 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)