summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason Kölker <jason@koelker.net>2015-08-12 00:00:31 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-20 17:35:27 +0900
commit59da77306ce5b0b83a84dd96561dca66e577cdeb (patch)
tree29b624cec3028247b603ea06205d71c8125b4db9
parent1d30f0987fd5c1b8120a9546d5289c0aabb88a9b (diff)
Allow specifing match fields in ClsRule.__init__
Signed-off-by: Jason Kölker <jason@koelker.net> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/ofproto/nx_match.py18
1 files changed, 17 insertions, 1 deletions
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