ofproto_v1_0_parser: Add __getitem__ method into OFPMatch
Currently, ofproto_v1_0_parser does not support query with a match field name like ofproto_v1_[2345]_parser support. This patch adds __getitem__ method in order to get the match value witch a match field name. 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:
committed by
FUJITA Tomonori
parent
5cda019b3c
commit
388adf152c
@@ -205,6 +205,27 @@ class OFPMatch(StringifyMixin):
|
||||
else:
|
||||
self.wildcards = wildcards
|
||||
|
||||
def __getitem__(self, name):
|
||||
if not isinstance(name, str):
|
||||
raise KeyError(name)
|
||||
elif name == 'nw_src_mask':
|
||||
_m = 32 - ((self.wildcards & ofproto.OFPFW_NW_SRC_MASK) >>
|
||||
ofproto.OFPFW_NW_SRC_SHIFT)
|
||||
return 0 if _m < 0 else _m
|
||||
elif name == 'nw_dst_mask':
|
||||
_m = 32 - ((self.wildcards & ofproto.OFPFW_NW_DST_MASK) >>
|
||||
ofproto.OFPFW_NW_DST_SHIFT)
|
||||
return 0 if _m < 0 else _m
|
||||
elif name == 'wildcards':
|
||||
return self.wildcards
|
||||
|
||||
wc_name = 'OFPFW_' + name.upper()
|
||||
wc = getattr(ofproto, wc_name, ofproto.OFPFW_ALL)
|
||||
if self.wildcards & ~wc:
|
||||
return getattr(self, name)
|
||||
else:
|
||||
raise KeyError(name)
|
||||
|
||||
def serialize(self, buf, offset):
|
||||
msg_pack_into(ofproto.OFP_MATCH_PACK_STR, buf, offset,
|
||||
self.wildcards, self.in_port, self.dl_src,
|
||||
|
||||
Reference in New Issue
Block a user