On Fri, 8 Jun 2012 11:32:57 +0900
Simon Horman <[email protected]> wrote:

> Sorry for not noticing this earlier. It has no bearing on the correctness
> or performance of the code, but I think there is a typo.
> 
> s/find_/fin_/

Oops, thanks.

I fixed the typo and added some constants about NXAST_LEARN. The
following patch was applied.

-
>From 32e9fe1a2a09add788b87281dcf261abb025b107 Mon Sep 17 00:00:00 2001
From: FUJITA Tomonori <[email protected]>
Date: Fri, 8 Jun 2012 13:41:03 +0900
Subject: [PATCH] add Nicira Extension NXAST_LEARN support

Signed-off-by: FUJITA Tomonori <[email protected]>
---
 ryu/ofproto/ofproto_v1_0.py        |   16 ++++++++++++++
 ryu/ofproto/ofproto_v1_0_parser.py |   39 ++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py
index 9892c2c..e6d1150 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 fdf7c36..a0b15f4 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()
 
 
[email protected]_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):
-- 
1.7.2.5


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to