diff options
author | YAMAMOTO Takashi <yamamoto@valinux.co.jp> | 2015-01-23 11:16:22 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-01-25 21:50:37 +0900 |
commit | 306a500ee6bdfaebf0886804348aeb17b77befb2 (patch) | |
tree | a56d27372416a8809e2be4c1c8275f89c8a4dd65 | |
parent | 181d2fa3a2bb408ca716d0d753762c8528fe3dd4 (diff) |
nx_actions: Implement nx_action_learn
This is planned to be used for upcoming Neutron OVS agent changes.
(https://blueprints.launchpad.net/neutron/+spec/ovs-ofctl-to-python)
Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/nx_actions.py | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/ryu/ofproto/nx_actions.py b/ryu/ofproto/nx_actions.py index a9b1e528..2431dd1c 100644 --- a/ryu/ofproto/nx_actions.py +++ b/ryu/ofproto/nx_actions.py @@ -247,6 +247,88 @@ def generate(ofp_name, ofpp_name): msg_pack_into('!%ds' % len(data), buf, offset + payload_offset, bytes(data)) + class NXActionLearn(NXAction): + subtype = nicira_ext.NXAST_LEARN + + # idle_timeout, hard_timeout, priority, cookie, flags, + # table_id, pad, fin_idle_timeout, fin_hard_timeout + _fmt_str = '!HHHQHBxHH' + # Followed by flow_mod_specs + + def __init__(self, + table_id, + specs, + idle_timeout=0, + hard_timeout=0, + priority=ofp.OFP_DEFAULT_PRIORITY, + cookie=0, + flags=0, + fin_idle_timeout=0, + fin_hard_timeout=0, + type_=None, len_=None, experimenter=None, subtype=None): + super(NXActionLearn, self).__init__() + self.idle_timeout = idle_timeout + self.hard_timeout = hard_timeout + self.priority = priority + self.cookie = cookie + self.flags = flags + self.table_id = table_id + self.fin_idle_timeout = fin_idle_timeout + self.fin_hard_timeout = fin_hard_timeout + self.specs = specs + + @classmethod + def parse(cls, buf): + (idle_timeout, + hard_timeout, + priority, + cookie, + flags, + table_id, + fin_idle_timeout, + fin_hard_timeout,) = struct.unpack_from( + NXActionLearn._fmt_str, buf, 0) + rest = buf[struct.calcsize(NXActionLearn._fmt_str):] + # specs + specs = [] + while len(rest) > 0: + spec, rest = _NXFlowSpec.parse(rest) + if spec is None: + continue + specs.append(spec) + return cls(idle_timeout=idle_timeout, + hard_timeout=hard_timeout, + priority=priority, + cookie=cookie, + flags=flags, + table_id=table_id, + fin_idle_timeout=fin_idle_timeout, + fin_hard_timeout=fin_hard_timeout, + specs=specs) + + def serialize(self, buf, offset): + # fixup + data = bytearray() + msg_pack_into(NXActionLearn._fmt_str, data, 0, + self.idle_timeout, + self.hard_timeout, + self.priority, + self.cookie, + self.flags, + self.table_id, + self.fin_idle_timeout, + self.fin_hard_timeout) + for spec in self.specs: + data += spec.serialize() + payload_offset = ( + ofp.OFP_ACTION_EXPERIMENTER_HEADER_SIZE + + struct.calcsize(NXAction._fmt_str) + ) + self.len = utils.round_up(payload_offset + len(data), 8) + super(NXActionLearn, self).serialize(buf, offset) + msg_pack_into('!%ds' % len(data), buf, offset + payload_offset, + bytes(data)) + def add_attr(k, v): setattr(ofpp, k, v) @@ -255,6 +337,7 @@ def generate(ofp_name, ofpp_name): classes = [ 'NXActionRegMove', + 'NXActionLearn', '_NXFlowSpec', # exported for testing 'NXFlowSpecMatch', 'NXFlowSpecLoad', |