From 59da77306ce5b0b83a84dd96561dca66e577cdeb Mon Sep 17 00:00:00 2001 From: Jason Kölker Date: Wed, 12 Aug 2015 00:00:31 +0000 Subject: Allow specifing match fields in ClsRule.__init__ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jason Kölker Signed-off-by: FUJITA Tomonori --- ryu/ofproto/nx_match.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/ryu/ofproto/nx_match.py b/ryu/ofproto/nx_match.py index 2364780b..dae24b6d 100644 --- a/ryu/ofproto/nx_match.py +++ b/ryu/ofproto/nx_match.py @@ -118,10 +118,26 @@ class FlowWildcards(ofproto_parser.StringifyMixin): class ClsRule(ofproto_parser.StringifyMixin): """describe a matching rule for OF 1.0 OFPMatch (and NX). """ - def __init__(self): + def __init__(self, **kwargs): self.wc = FlowWildcards() self.flow = Flow() + for key, value in kwargs.items(): + if key[:3] == 'reg': + register = int(key[3:] or -1) + self.set_reg(register, value) + continue + + setter = getattr(self, 'set_' + key, None) + if not setter: + LOG.error('Invalid kwarg specified to ClsRule (%s)', key) + continue + + if not isinstance(value, (tuple, list)): + value = (value, ) + + setter(*value) + def set_in_port(self, port): self.wc.wildcards &= ~FWW_IN_PORT self.flow.in_port = port -- cgit v1.2.3