OpenFlow Spec 1.5 introduces Copy-Field action which allows to copy
the value from one header or pipeline field into another header or
pipeline field (EXT-320).

This patch add Copy-Field action support.

Signed-off-by: IWASE Yusuke <[email protected]>
---
 ryu/ofproto/ofproto_v1_5_parser.py | 52 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/ryu/ofproto/ofproto_v1_5_parser.py 
b/ryu/ofproto/ofproto_v1_5_parser.py
index 7d15bc6..e451bc4 100644
--- a/ryu/ofproto/ofproto_v1_5_parser.py
+++ b/ryu/ofproto/ofproto_v1_5_parser.py
@@ -5420,6 +5420,58 @@ class OFPActionPopPbb(OFPAction):
         return cls()
 
 
[email protected]_action_type(ofproto.OFPAT_COPY_FIELD,
+                                ofproto.OFP_ACTION_COPY_FIELD_SIZE)
+class OFPActionCopyField(OFPAction):
+    """
+    Copy Field action
+
+    This action copy value between header and register.
+
+    ================ ======================================================
+    Attribute        Description
+    ================ ======================================================
+    n_bits           Number of bits to copy.
+    src_offset       Starting bit offset in source.
+    dst_offset       Starting bit offset in destination.
+    oxm_ids          List of ``OFPOxmId`` instances.
+                     The first element of this list, src_oxm_id,
+                     identifies the field where the value is copied from.
+                     The second element of this list, dst_oxm_id,
+                     identifies the field where the value is copied to.
+                     The default is [].
+    ================ ======================================================
+    """
+    def __init__(self, n_bits=0, src_offset=0, dst_offset=0, oxm_ids=[],
+                 type_=None, len_=None):
+        super(OFPActionCopyField, self).__init__()
+        self.n_bits = n_bits
+        self.src_offset = src_offset
+        self.dst_offset = dst_offset
+        self.oxm_ids = oxm_ids
+
+    @classmethod
+    def parser(cls, buf, offset):
+        (type_, len_, n_bits, src_offset, dst_offset) = struct.unpack_from(
+            ofproto.OFP_ACTION_COPY_FIELD_PACK_STR, buf, offset)
+        offset += ofproto.OFP_ACTION_COPY_FIELD_SIZE
+
+        rest = buf[offset:offset + len_]
+        oxm_ids = []
+        while rest:
+            i, rest = OFPOxmId.parse(rest)
+            oxm_ids.append(i)
+        return cls(n_bits, src_offset, dst_offset, oxm_ids, type_, len_)
+
+    def serialize(self, buf, offset):
+        msg_pack_into(ofproto.OFP_ACTION_COPY_FIELD_PACK_STR, buf,
+                      offset, self.type, self.len,
+                      self.n_bits, self.src_offset, self.dst_offset)
+
+        for i in self.oxm_ids:
+            buf += i.serialize()
+
+
 @OFPAction.register_action_type(ofproto.OFPAT_METER,
                                 ofproto.OFP_ACTION_METER_SIZE)
 class OFPActionMeter(OFPAction):
-- 
1.9.1


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to