Skip to content

Commit

Permalink
sw test tool: Modify OFPActionSetField to normalize
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Yuichi Ito authored and fujita committed Jun 23, 2014
1 parent 1474ec3 commit 2d173ad
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ryu/tests/switch/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,15 @@ def __normalize_match(ofproto, match):
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]
Expand Down Expand Up @@ -1345,6 +1354,36 @@ def __normalize_match(ofproto, match):
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)

Expand Down

0 comments on commit 2d173ad

Please sign in to comment.