diff options
author | Yuichi Ito <ito.yuichi0@gmail.com> | 2014-06-23 14:42:57 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-06-23 17:10:25 +0900 |
commit | 2d173ad25c074470284c1cf31e4e64d56ec41e94 (patch) | |
tree | 88a8bc3a169ca1071c9c628ad6026eeab8401089 | |
parent | 1474ec325556e411313e8b7064232428e92e2f11 (diff) |
sw test tool: Modify OFPActionSetField to normalize
This patch is for avoiding the following issues when using ofproto_v1_4_parser:
- OFPActionSetField that is created from JSON keeps unicode strings, instead of usual strings.
- In OFPActionSetField that is created from JSON, IPv6 formats like 'ff::0' or '00ff:0000:0000:0000:0000:0000:0000:0000' are not normalized to 'ff::'.
Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/tests/switch/tester.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ryu/tests/switch/tester.py b/ryu/tests/switch/tester.py index 73a7bfbd..b6826e56 100644 --- a/ryu/tests/switch/tester.py +++ b/ryu/tests/switch/tester.py @@ -1311,6 +1311,15 @@ class Test(stringify.StringifyMixin): fields.append(field_obj) return match.__class__(_ordered_fields=fields) + def __normalize_action(ofproto, action): + action_json = action.to_jsondict() + field = action_json['OFPActionSetField']['field'] + field_obj = ofproto.oxm_from_jsondict(field) + field_obj = ofproto.oxm_normalize_user(*field_obj) + kwargs = {} + kwargs[field_obj[0]] = field_obj[1] + return action.__class__(**kwargs) + # get ofproto modules using user-specified versions (target_ofproto, target_parser) = ofproto_protocol._versions[ OfTester.target_ver] @@ -1345,6 +1354,36 @@ class Test(stringify.StringifyMixin): if isinstance(msg, target_parser.OFPFlowMod): # normalize OFPMatch msg.match = __normalize_match(target_ofproto, msg.match) + # normalize OFPActionSetField + insts = [] + for inst in msg.instructions: + if isinstance(inst, target_parser.OFPInstructionActions): + acts = [] + for act in inst.actions: + if isinstance( + act, target_parser.OFPActionSetField): + act = __normalize_action(target_ofproto, act) + acts.append(act) + inst = target_parser.OFPInstructionActions( + inst.type, actions=acts) + insts.append(inst) + msg.instructions = insts + elif isinstance(msg, target_parser.OFPGroupMod): + # normalize OFPActionSetField + buckets = [] + for bucket in msg.buckets: + acts = [] + for act in bucket.actions: + if isinstance(act, target_parser.OFPActionSetField): + act = __normalize_action(target_ofproto, act) + acts.append(act) + bucket = target_parser.OFPBucket( + weight=bucket.weight, + watch_port=bucket.watch_port, + watch_group=bucket.watch_group, + actions=acts) + buckets.append(bucket) + msg.buckets = buckets msg.serialize() prerequisite.append(msg) |