diff options
author | Yusuke Iwase <iwase.yusuke0@gmail.com> | 2015-10-06 16:49:27 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-11 21:51:38 +0900 |
commit | 9e542b885110404fd5ac8bfd25f5c4c97adc933a (patch) | |
tree | 4572f009ff90b2cfad5fb160a3d0941178db33a1 | |
parent | 85bb0128962398150e85ae4d0549147b0c2112c9 (diff) |
of10: Add __contains__ method into OFPMatch
To support query whether a match instance contains a specific field,
This patch adds __contains__ method into OFPMatch.
Example:
>>> if 'nw_src' in match:
... print match['nw_src']
...
'192.168.0.1'
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_0.py | 2 | ||||
-rw-r--r-- | ryu/ofproto/ofproto_v1_0_parser.py | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py index 4cac2626..c6cd9736 100644 --- a/ryu/ofproto/ofproto_v1_0.py +++ b/ryu/ofproto/ofproto_v1_0.py @@ -265,10 +265,12 @@ OFPFW_TP_DST = 1 << 7 # TCP/UDP destination port. OFPFW_NW_SRC_SHIFT = 8 OFPFW_NW_SRC_BITS = 6 OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT +OFPFW_NW_SRC = OFPFW_NW_SRC_MASK # IP source address (not in OF Spec). OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT OFPFW_NW_DST_SHIFT = 14 OFPFW_NW_DST_BITS = 6 OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT +OFPFW_NW_DST = OFPFW_NW_DST_MASK # IP destination address (not in OF Spec). OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT OFPFW_DL_VLAN_PCP = 1 << 20 # VLAN priority. OFPFW_NW_TOS = 1 << 21 # IP ToS (DSCP field, 6 bits). diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py index 73d3409b..fd2687d4 100644 --- a/ryu/ofproto/ofproto_v1_0_parser.py +++ b/ryu/ofproto/ofproto_v1_0_parser.py @@ -241,6 +241,10 @@ class OFPMatch(StringifyMixin): else: raise KeyError(name) + def __contains__(self, name): + wc = getattr(ofproto, 'OFPFW_' + name.upper(), 0) + return ~self.wildcards & wc + def serialize(self, buf, offset): msg_pack_into(ofproto.OFP_MATCH_PACK_STR, buf, offset, self.wildcards, self.in_port, self.dl_src, |