diff options
author | IWAMOTO Toshihiro <iwamoto@valinux.co.jp> | 2016-02-03 18:02:19 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-02-10 14:47:44 +0900 |
commit | 8830f61cafc162903f1065ca8bb6851c048c19ed (patch) | |
tree | 183071eb3340daf4eceb5af451079a107292f1cf | |
parent | efc859eebf28128c7b4450ff75355d5e2ad83610 (diff) |
Implement NXActionRegLoad
The OpenStack Neutron's of_interface code generates flows with
NXActionRegLoad. It's not required but better to be able to
parse them.
Signed-off-by: IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/nx_actions.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/ryu/ofproto/nx_actions.py b/ryu/ofproto/nx_actions.py index f729bdf9..9d32df6b 100644 --- a/ryu/ofproto/nx_actions.py +++ b/ryu/ofproto/nx_actions.py @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +import six + import struct from ryu import utils @@ -203,6 +205,52 @@ def generate(ofp_name, ofpp_name): super(NXActionUnknown, self).serialize(buf, offset) buf += data + class NXActionRegLoad(NXAction): + _subtype = nicira_ext.NXAST_REG_LOAD + _fmt_str = '!HIQ' # ofs_nbits, dst, value + _TYPE = { + 'ascii': [ + 'dst', + ] + } + + def __init__(self, ofs, nbits, dst, value, + type_=None, len_=None, experimenter=None, subtype=None): + super(NXActionRegLoad, self).__init__() + self.ofs = ofs + self.nbits = nbits + self.dst = dst + self.value = value + + @classmethod + def parse(cls, buf): + (ofs_nbits, dst, value,) = struct.unpack_from( + NXActionRegLoad._fmt_str, buf, 0) + ofs = ofs_nbits >> 6 + nbits = (ofs_nbits & ((1 << 6) - 1)) + 1 + # Right-shift instead of using oxm_parse_header for simplicity... + dst_name = ofp.oxm_to_user_header(dst >> 9) + return cls(ofs, nbits, dst_name, value) + + def serialize(self, buf, offset): + hdr_data = bytearray() + n = ofp.oxm_from_user_header(self.dst) + ofp.oxm_serialize_header(n, hdr_data, 0) + (dst_num,) = struct.unpack_from('!I', six.binary_type(hdr_data), 0) + + ofs_nbits = (self.ofs << 6) + self.nbits - 1 + data = bytearray() + msg_pack_into(NXActionRegLoad._fmt_str, data, 0, + ofs_nbits, dst_num, self.value) + payload_offset = ( + ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE + + struct.calcsize(NXAction._fmt_str) + ) + self.len = utils.round_up(payload_offset + len(data), 8) + super(NXActionRegLoad, self).serialize(buf, offset) + msg_pack_into('!%ds' % len(data), buf, offset + payload_offset, + bytes(data)) + class NXActionRegMove(NXAction): _subtype = nicira_ext.NXAST_REG_MOVE _fmt_str = '!HHH' # n_bits, src_ofs, dst_ofs @@ -596,6 +644,7 @@ def generate(ofp_name, ofpp_name): add_attr('NXActionUnknown', NXActionUnknown) classes = [ + 'NXActionRegLoad', 'NXActionRegMove', 'NXActionLearn', 'NXActionConjunction', |