From 32d3a9f4991650af15f3e93740a78d6a10edf764 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Fri, 8 Jun 2012 13:41:03 +0900 Subject: [PATCH] Add Nicira Extension NXAST_LEARN support Signed-off-by: FUJITA Tomonori --- ryu/ofproto/ofproto_v1_0.py | 16 ++++++++++++ ryu/ofproto/ofproto_v1_0_parser.py | 39 ++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py index 9892c2ca..e6d1150d 100644 --- a/ryu/ofproto/ofproto_v1_0.py +++ b/ryu/ofproto/ofproto_v1_0.py @@ -246,6 +246,7 @@ NXAST_BUNDLE = 12 NXAST_BUNDLE_LOAD = 13 NXAST_RESUBMIT_TABLE = 14 NXAST_OUTPUT_REG = 15 +NXAST_LEARN = 16 NXAST_EXIT = 17 NXAST_DEC_TTL = 18 NXAST_FIN_TIMEOUT = 19 @@ -299,6 +300,10 @@ NX_ACTION_OUTPUT_REG_PACK_STR = '!HHIHHIH6x' NX_ACTION_OUTPUT_REG_SIZE = 24 assert calcsize(NX_ACTION_OUTPUT_REG_PACK_STR) == NX_ACTION_OUTPUT_REG_SIZE +NX_ACTION_LEARN_PACK_STR = '!HHIHHHHQHBxHH' +NX_ACTION_LEARN_SIZE = 32 +assert calcsize(NX_ACTION_LEARN_PACK_STR) == NX_ACTION_LEARN_SIZE + NX_ACTION_CONTROLLER_PACK_STR = '!HHIHHHBB' NX_ACTION_CONTROLLER_SIZE = 16 assert calcsize(NX_ACTION_CONTROLLER_PACK_STR) == NX_ACTION_CONTROLLER_SIZE @@ -732,3 +737,14 @@ NX_MP_ALG_ITER_HASH = 3 # enum nx_bd_algorithm NX_BD_ALG_ACTIVE_BACKUP = 0 NX_BD_ALG_HRW = 1 + +# nx_learn constants +NX_LEARN_N_BITS_MASK = 0x3ff +NX_LEARN_SRC_FIELD = 0 << 13 # Copy from field. +NX_LEARN_SRC_IMMEDIATE = 1 << 13 # Copy from immediate value. +NX_LEARN_SRC_MASK = 1 << 13 +NX_LEARN_DST_MATCH = 0 << 11 # Add match criterion. +NX_LEARN_DST_LOAD = 1 << 11 # Add NXAST_REG_LOAD action +NX_LEARN_DST_OUTPUT = 2 << 11 # Add OFPAT_OUTPUT action. +NX_LEARN_DST_RESERVED = 3 << 11 # Not yet defined. +NX_LEARN_DST_MASK = 3 << 11 diff --git a/ryu/ofproto/ofproto_v1_0_parser.py b/ryu/ofproto/ofproto_v1_0_parser.py index fdf7c363..a0b15f4f 100644 --- a/ryu/ofproto/ofproto_v1_0_parser.py +++ b/ryu/ofproto/ofproto_v1_0_parser.py @@ -824,6 +824,45 @@ class NXActionDecTtl(NXActionHeader): return cls() +@NXActionHeader.register_nx_action_subtype(ofproto_v1_0.NXAST_LEARN) +class NXActionLearn(NXActionHeader): + def __init__(self, idle_timeout, hard_timeout, priority, cookie, flags, + table_id, fin_idle_timeout, fin_hard_timeout, spec): + len_ = len(spec) + ofproto_v1_0.NX_ACTION_LEARN_SIZE + pad_len = 8 - (len_ % 8) + + super(NXActionLearn, self).__init__( + ofproto_v1_0.NXAST_LEARN, len_ + pad_len) + 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.spec = spec + bytearray('\x00' * pad_len) + + def serialize(self, buf, offset): + msg_pack_into(ofproto_v1_0.NX_ACTION_LEARN_PACK_STR, buf, offset, + self.type, self.len, self.vendor, self.subtype, + self.idle_timeout, self.hard_timeout, self.priority, + self.cookie, self.flags, self.table_id, + self.fin_idle_timeout, self.fin_hard_timeout) + buf += self.spec + + @classmethod + def parser(cls, buf, offset): + (type_, len_, vendor, subtype, idle_timeout, hard_timeout, priority, + cookie, flags, table_id, fin_idle_timeout, + fin_hard_timeout) = struct.unpack_from( + ofproto_v1_0.NX_ACTION_LEARN_PACK_STR, buf, offset) + spec = buf[offset + ofproto_v1_0.NX_ACTION_LEARN_SIZE:] + return cls(idle_timeout, hard_timeout, priority, + cookie, flags, table_id, fin_idle_timeout, + fin_hard_timeout, spec) + + @NXActionHeader.register_nx_action_subtype(ofproto_v1_0.NXAST_CONTROLLER) class NXActionController(NXActionHeader): def __init__(self, max_len, controller_id, reason):