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>
This commit is contained in:
parent
85bb012896
commit
9e542b8851
@ -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).
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user