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 <[email protected]>
---
 ryu/tests/switch/tester.py |   39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/ryu/tests/switch/tester.py b/ryu/tests/switch/tester.py
index 73a7bfb..b6826e5 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)
 
-- 
1.7.10.4


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to