From 92ef0bdbb5bc56d4650a1566424695d41957a0f9 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 26 Mar 2014 13:04:22 +0900 Subject: [PATCH] ryu.app.ofctl: raise exceptions on openflow error messages Signed-off-by: YAMAMOTO Takashi Signed-off-by: FUJITA Tomonori --- ryu/app/ofctl/exception.py | 4 ++++ ryu/app/ofctl/service.py | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ryu/app/ofctl/exception.py b/ryu/app/ofctl/exception.py index 90113aed..c49f33f2 100644 --- a/ryu/app/ofctl/exception.py +++ b/ryu/app/ofctl/exception.py @@ -27,3 +27,7 @@ class _ExceptionBase(exception.RyuException): class UnexpectedMultiReply(_ExceptionBase): message = 'Unexpected Multi replies %(result)s' + + +class OFError(_ExceptionBase): + message = 'OpenFlow errors %(result)s' diff --git a/ryu/app/ofctl/service.py b/ryu/app/ofctl/service.py index e7e181c9..415834ef 100644 --- a/ryu/app/ofctl/service.py +++ b/ryu/app/ofctl/service.py @@ -62,6 +62,11 @@ class OfctlService(app_manager.RyuApp): self.unobserve_event(ev_cls) self.logger.debug('ofctl: stop observing %s' % (ev_cls,)) + @staticmethod + def _is_error(msg): + return (ofp_event.ofp_msg_to_ev_cls(type(msg)) == + ofp_event.EventOFPErrorMsg) + @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER) def _switch_features_handler(self, ev): datapath = ev.msg.datapath @@ -142,7 +147,9 @@ class OfctlService(app_manager.RyuApp): req = si.xids.pop(xid) if not req.reply_cls is None: self._unobserve_msg(req.reply_cls) - if req.reply_multi: + if 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) elif len(result) == 0: rep = event.Reply()