From ecb1d556073511c5113bae752bd6d9cfffab0685 Mon Sep 17 00:00:00 2001 From: Yusuke Iwase Date: Wed, 22 Jul 2015 13:50:30 +0900 Subject: [PATCH] ofproto_v1_5_parser: Add OFPActionCopyField support 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 Signed-off-by: FUJITA Tomonori --- 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 3a33ecfd..6775cbff 100644 --- a/ryu/ofproto/ofproto_v1_5_parser.py +++ b/ryu/ofproto/ofproto_v1_5_parser.py @@ -5588,6 +5588,58 @@ class OFPActionPopPbb(OFPAction): return cls() +@OFPAction.register_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):