diff options
author | Isaku Yamahata <yamahata@valinux.co.jp> | 2012-01-27 17:47:08 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-01-29 03:30:41 +0900 |
commit | 5ef02dfc55e816e0fa758b2386aab5fd66b2ae29 (patch) | |
tree | d4ac29cd1be062330d7b5dc751755a787ca73e30 | |
parent | 18cbaad5ad490fbb3a4e9b188dd419d789f45ccb (diff) |
ofproto_v1_0_parser: allows 0 as dl_{src, dst} for OFPMatch
When 0 is passed for dl_{src, dst}, it is converted to '\x00' * 6
So when creating OFPMatch with wildcarded dl_{src, dst},
the argument can be simplified to 0 instead of '\x00' * 6.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_0_parser.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py index cb1983a3..d8664947 100644 --- a/ryu/ofproto/ofproto_v1_0_parser.py +++ b/ryu/ofproto/ofproto_v1_0_parser.py @@ -17,6 +17,7 @@ import collections import struct from ofproto_parser import MsgBase +from ryu.lib import mac from . import ofproto_parser from . import ofproto_v1_0 @@ -91,6 +92,18 @@ class OFPMatch(collections.namedtuple('OFPMatchBase', ( 'dl_vlan_pcp', 'dl_type', 'nw_tos', 'nw_proto', 'nw_src', 'nw_dst', 'tp_src', 'tp_dst'))): + def __new__(cls, *args): + # for convenience when dl_src/dl_dst are wildcard + if args[2] != 0 and args[3] != 0: + return super(cls, OFPMatch).__new__(cls, *args) + + tmp = list(args) + if tmp[2] == 0: + tmp[2] = mac.DONTCARE + if tmp[3] == 0: + tmp[3] = mac.DONTCARE + return super(cls, OFPMatch).__new__(cls, *tmp) + def serialize(self, buf, offset): _pack_into(ofproto_v1_0.OFP_MATCH_PACK_STR, buf, offset, *self) |