On Tue,  8 May 2012 08:31:02 +0900
FUJITA Tomonori <[email protected]> wrote:

> Only NXActionSetTunell is supported for now

I've applied the following updated patch. I added parsers of all the
NXAction that we support.

=
>From c401f4d9bf12b9378dde4cc9c3e6fd53c3f4a494 Mon Sep 17 00:00:00 2001
From: FUJITA Tomonori <[email protected]>
Date: Tue, 8 May 2012 10:51:03 +0900
Subject: [PATCH] Add NXAction parser support

Signed-off-by: FUJITA Tomonori <[email protected]>
---
 ryu/ofproto/ofproto_v1_0.py        |    5 +-
 ryu/ofproto/ofproto_v1_0_parser.py |   80 ++++++++++++++++++++++++++++++++++-
 2 files changed, 79 insertions(+), 6 deletions(-)

diff --git a/ryu/ofproto/ofproto_v1_0.py b/ryu/ofproto/ofproto_v1_0.py
index 43e4116..2f5f649 100644
--- a/ryu/ofproto/ofproto_v1_0.py
+++ b/ryu/ofproto/ofproto_v1_0.py
@@ -254,10 +254,9 @@ NX_ACTION_MULTIPATH_PACK_STR = '!HHIHHH2xHHI2xHI'
 NX_ACTION_MULTIPATH_SIZE = 32
 assert calcsize(NX_ACTION_MULTIPATH_PACK_STR) == NX_ACTION_MULTIPATH_SIZE
 
-NX_ACTION_HEADER_PACK_STR = '!H'
+NX_ACTION_HEADER_PACK_STR = '!HHIH'
 NX_ACTION_HEADER_SIZE = 10
-assert (OFP_ACTION_VENDOR_HEADER_SIZE +
-        calcsize(NX_ACTION_HEADER_PACK_STR)) == NX_ACTION_HEADER_SIZE
+assert calcsize(NX_ACTION_HEADER_PACK_STR) == NX_ACTION_HEADER_SIZE
 
 OFP_PACKET_OUT_PACK_STR = '!IHH'
 OFP_PACKET_OUT_SIZE = 16
diff --git a/ryu/ofproto/ofproto_v1_0_parser.py 
b/ryu/ofproto/ofproto_v1_0_parser.py
index f6ea77d..ea164bd 100644
--- a/ryu/ofproto/ofproto_v1_0_parser.py
+++ b/ryu/ofproto/ofproto_v1_0_parser.py
@@ -367,12 +367,43 @@ class OFPActionEnqueue(OFPAction):
                       self.type, self.len, self.port, self.queue_id)
 
 
-# TODO:XXX OFPActionVendor
-# NXAction* is a partial implementatoin, only handling serilalisation
-# of a subset of Nicira vendor actions
[email protected]_action_type(ofproto_v1_0.OFPAT_VENDOR, 0)
+class OFPActionVendor(OFPAction):
+    _ACTION_VENDORS = {}
 
+    @staticmethod
+    def register_action_vendor(vendor):
+        def _register_action_vendor(cls):
+            cls.cls_vendor = vendor
+            OFPActionVendor._ACTION_VENDORS[cls.cls_vendor] = cls
+            return cls
+        return _register_action_vendor
+
+    def __init__(self, vendor):
+        super(OFPActionVendor, self).__init__()
+        self.vendor = vendor
+
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, vendor = struct.unpack_from(
+            ofproto_v1_0.OFP_ACTION_VENDOR_HEADER_PACK_STR, buf, offset)
+        cls_ = cls._ACTION_VENDORS.get(vendor)
+        return cls_.parser(buf, offset)
 
+
[email protected]_action_vendor(ofproto_v1_0.NX_VENDOR_ID)
 class NXActionHeader(object):
+    _NX_ACTION_SUBTYPES = {}
+
+    @staticmethod
+    def register_nx_action_subtype(subtype):
+        def _register_nx_action_subtype(cls):
+            cls.cls_subtype = subtype
+            NXActionHeader._NX_ACTION_SUBTYPES[cls.cls_subtype] = cls
+            return cls
+        return _register_nx_action_subtype
+
+
     def __init__(self, subtype_, len_):
         self.type = ofproto_v1_0.OFPAT_VENDOR
         self.len = len_
@@ -383,6 +414,12 @@ class NXActionHeader(object):
         msg_pack_into(ofproto_v1_0.OFP_ACTION_HEADER_PACK_STR,
                       buf, offset, self.type, self.len)
 
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, vendor, subtype = struct.unpack_from(
+            ofproto_v1_0.NX_ACTION_HEADER_PACK_STR, buf, offset)
+        cls_ = cls._NX_ACTION_SUBTYPES.get(subtype)
+        return cls_.parser(buf, offset)
 
 class NXActionResubmitBase(NXActionHeader):
     def __init__(self, subtype, in_port, table):
@@ -399,18 +436,33 @@ class NXActionResubmitBase(NXActionHeader):
                       self.in_port, self.table)
 
 
[email protected]_nx_action_subtype(ofproto_v1_0.NXAST_RESUBMIT)
 class NXActionResubmit(NXActionResubmitBase):
     def __init__(self, in_port=ofproto_v1_0.OFPP_IN_PORT):
         super(NXActionResubmit, self).__init__(
             ofproto_v1_0.NXAST_RESUBMIT, in_port, 0)
 
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, vendor, subtype, in_port, table = struct.unpack_from(
+            ofproto_v1_0.NX_ACTION_RESUBMIT_PACK_STR, buf, offset)
+        return cls(in_port)
+
 
[email protected]_nx_action_subtype(ofproto_v1_0.NXAST_RESUBMIT_TABLE)
 class NXActionResubmitTable(NXActionResubmitBase):
     def __init__(self, in_port=ofproto_v1_0.OFPP_IN_PORT, table=0xff):
         super(NXActionResubmitTable, self).__init__(
             ofproto_v1_0.NXAST_RESUBMIT_TABLE, in_port, table)
 
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, vendor, subtype, in_port, table = struct.unpack_from(
+            ofproto_v1_0.NX_ACTION_RESUBMIT_PACK_STR, buf, offset)
+        return cls(in_port, table)
 
+
[email protected]_nx_action_subtype(ofproto_v1_0.NXAST_SET_TUNNEL)
 class NXActionSetTunnel(NXActionHeader):
     def __init__(self, tun_id_):
         self.tun_id = tun_id_
@@ -423,7 +475,14 @@ class NXActionSetTunnel(NXActionHeader):
                       offset, self.type, self.len, self.vendor, self.subtype,
                       self.tun_id)
 
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, vendor, subtype, tun_id = struct.unpack_from(
+            ofproto_v1_0.NX_ACTION_SET_TUNNEL_PACK_STR, buf, offset)
+        return cls(tun_id)
+
 
[email protected]_nx_action_subtype(ofproto_v1_0.NXAST_SET_TUNNEL64)
 class NXActionSetTunnel64(NXActionHeader):
     def __init__(self, tun_id_):
         self.tun_id = tun_id_
@@ -436,7 +495,14 @@ class NXActionSetTunnel64(NXActionHeader):
                       offset, self.type, self.len, self.vendor, self.subtype,
                       self.tun_id)
         
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, vendor, subtype, in_port, table = struct.unpack_from(
+            ofproto_v1_0.NX_ACTION_TUNNE64_PACK_STR, buf, offset)
+        return cls(in_port)
 
+
[email protected]_nx_action_subtype(ofproto_v1_0.NXAST_MULTIPATH)
 class NXActionMultipath(NXActionHeader):
     def __init__(self, fields, basis, algorithm, max_link, arg,
                  ofs_nbits, dst):
@@ -457,6 +523,14 @@ class NXActionMultipath(NXActionHeader):
                       self.fields, self.basis, self.algorithm, self.max_link,
                       self.arg, self.ofs_nbits, self.dst)
 
+    @classmethod
+    def parser(cls, buf, offset):
+        type_, len_, vendor, subtype, fields, basis, algorithm,
+        max_link, arg, ofs_nbits, dst = struct.unpack_from(
+            ofproto_v1_0.NX_ACTION_MULTIPATH_PACK_STR, buf, offset)
+        return cls(fields, basis, algorithm, max_link, arg, ofs_nbits,
+                   dst)
+
 
 class OFPDescStats(collections.namedtuple('OFPDescStats',
         ('mfr_desc', 'hw_desc', 'sw_desc', 'serial_num', 'dp_desc'))):
-- 
1.7.4.4


------------------------------------------------------------------------------
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