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>
This commit is contained in:
Satoshi Fujimoto 2017-10-17 10:24:53 +09:00 committed by FUJITA Tomonori
parent 66bdeaa7b5
commit 92730dc7e9

View File

@ -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)
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
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
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(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)