From: Jacob Mandelson <[email protected]>

[[email protected]] Non-trivial up-port to master branch

---

I believe that there is some discussion to be had on if some sort of API
should be provided to allow vendors to register their own extensions (e.g.
at compile time). But as there is currently no such API I would like this
patch considered for merging.
---
 include/openflow/automake.mk    |    7 ++++++
 include/openflow/midokura-ext.h |   20 +++++++++++++++++++
 lib/ofp-util.c                  |   40 +++++++++++++++++++++++++-------------
 lib/ofp-util.h                  |    4 +++
 ofproto/ofproto-dpif.c          |    6 +++++
 ofproto/ofproto.c               |    1 +
 6 files changed, 64 insertions(+), 14 deletions(-)
 create mode 100644 include/openflow/midokura-ext.h

diff --git a/include/openflow/automake.mk b/include/openflow/automake.mk
index 4b370d4..c6b85d4 100644
--- a/include/openflow/automake.mk
+++ b/include/openflow/automake.mk
@@ -1,5 +1,6 @@
 noinst_HEADERS += \
        include/openflow/nicira-ext.h \
+       include/openflow/midokura-ext.h \
        include/openflow/openflow.h
 
 if HAVE_PYTHON
@@ -15,6 +16,12 @@ include/openflow/nicira-ext.h.stamp: 
include/openflow/openflow.h include/openflo
        $(PYTHON) $(srcdir)/build-aux/check-structs 
$(srcdir)/include/openflow/openflow.h $(srcdir)/include/openflow/nicira-ext.h
        touch $@
 DISTCLEANFILES += include/openflow/nicira-ext.h.stamp
+
+ALL_LOCAL += include/openflow/midokura-ext.h.stamp
+include/openflow/midokura-ext.h.stamp: include/openflow/openflow.h 
include/openflow/midokura-ext.h build-aux/check-structs
+       $(PYTHON) $(srcdir)/build-aux/check-structs 
$(srcdir)/include/openflow/openflow.h $(srcdir)/include/openflow/midokura-ext.h
+       touch $@
+DISTCLEANFILES += include/openflow/midokura-ext.h.stamp
 endif
 
 EXTRA_DIST += build-aux/check-structs
diff --git a/include/openflow/midokura-ext.h b/include/openflow/midokura-ext.h
new file mode 100644
index 0000000..145e2b6
--- /dev/null
+++ b/include/openflow/midokura-ext.h
@@ -0,0 +1,20 @@
+#ifndef OPENFLOW_MIDOKURA_EXT_H
+#define OPENFLOW_MIDOKURA_EXT_H 1
+
+#include "openflow.h"
+
+#define MIDO_VENDOR_ID 0x00ACCABA   /* Midokura IEEE OUI */
+
+/* Header for Midokura-defined actions. */
+struct mido_action_header {
+    ovs_be32 vendor;                /* MIDO_VENDOR_ID. */
+    ovs_be16 subtype;               /* MIDO_*. */
+    uint8_t pad[2];
+};
+OFP_ASSERT(sizeof(struct mido_action_header) == 8);
+
+enum mido_action_subtype {
+    MIDO_FIRST_SUBTYPE          /* Replace with the first midokura subtype */
+};
+
+#endif // OPENFLOW_MIDOKURA_EXT_H
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index df3377a..3f9ba21 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -2058,6 +2058,7 @@ validate_actions(const union ofp_action *actions, size_t 
n_actions,
         case OFPUTIL_NXAST_POP_QUEUE:
         case OFPUTIL_NXAST_NOTE:
         case OFPUTIL_NXAST_SET_TUNNEL64:
+        case OFPUTIL_MIDO_FIRST_ACTION:
             break;
         }
 
@@ -2097,13 +2098,13 @@ static const struct ofputil_ofpat_action 
ofpat_actions[] = {
     { OFPUTIL_OFPAT_ENQUEUE,      16 },
 };
 
-struct ofputil_nxast_action {
+struct ofputil_ext_action {
     enum ofputil_action_code code;
     unsigned int min_len;
     unsigned int max_len;
 };
 
-static const struct ofputil_nxast_action nxast_actions[] = {
+static const struct ofputil_ext_action nxast_actions[] = {
     { 0, UINT_MAX, UINT_MAX }, /* NXAST_SNAT__OBSOLETE */
     { OFPUTIL_NXAST_RESUBMIT,     16, 16 },
     { OFPUTIL_NXAST_SET_TUNNEL,   16, 16 },
@@ -2120,6 +2121,10 @@ static const struct ofputil_nxast_action nxast_actions[] 
= {
     { OFPUTIL_NXAST_BUNDLE_LOAD,  32, UINT_MAX },
 };
 
+static const struct ofputil_ext_action mido_actions[] = {
+    { OFPUTIL_MIDO_FIRST_ACTION,  16, 16 },
+};
+
 static int
 ofputil_decode_ofpat_action(const union ofp_action *a)
 {
@@ -2138,7 +2143,8 @@ ofputil_decode_ofpat_action(const union ofp_action *a)
 }
 
 static int
-ofputil_decode_nxast_action(const union ofp_action *a)
+ofputil_decode_ext_action(const union ofp_action *a,
+                          const struct ofputil_ext_action *l, int n)
 {
     unsigned int len = ntohs(a->header.len);
 
@@ -2148,8 +2154,8 @@ ofputil_decode_nxast_action(const union ofp_action *a)
         const struct nx_action_header *nah = (const void *) a;
         int subtype = ntohs(nah->subtype);
 
-        if (subtype <= ARRAY_SIZE(nxast_actions)) {
-            const struct ofputil_nxast_action *ona = &nxast_actions[subtype];
+        if (subtype <= n) {
+            const struct ofputil_ext_action *ona = &l[subtype];
             if (len >= ona->min_len && len <= ona->max_len) {
                 return ona->code;
             } else if (ona->min_len == UINT_MAX) {
@@ -2163,9 +2169,9 @@ ofputil_decode_nxast_action(const union ofp_action *a)
     }
 }
 
-/* Parses 'a' to determine its type.  Returns a nonnegative OFPUTIL_OFPAT_* or
- * OFPUTIL_NXAST_* constant if successful, otherwise a negative OpenFlow error
- * code (as returned by ofp_mkerr()).
+/* Parses 'a' to determine its type.  Returns a nonnegative
+ * OFPUTIL_{OFPAT,NXAST,MIDO}_* constant if successful,
+ * otherwise a negative OpenFlow error code (as returned by ofp_mkerr()).
  *
  * The caller must have already verified that 'a''s length is correct (that is,
  * a->header.len is nonzero and a multiple of sizeof(union ofp_action) and no
@@ -2179,25 +2185,31 @@ ofputil_decode_action(const union ofp_action *a)
     if (a->type != htons(OFPAT_VENDOR)) {
         return ofputil_decode_ofpat_action(a);
     } else if (a->vendor.vendor == htonl(NX_VENDOR_ID)) {
-        return ofputil_decode_nxast_action(a);
+        return ofputil_decode_ext_action(a, nxast_actions,
+                                         ARRAY_SIZE(nxast_actions));
+    } else if (a->vendor.vendor == htonl(MIDO_VENDOR_ID)) {
+        return ofputil_decode_ext_action(a, mido_actions,
+                                         ARRAY_SIZE(mido_actions));
     } else {
         return -ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_BAD_VENDOR);
     }
 }
 
-/* Parses 'a' and returns its type as an OFPUTIL_OFPAT_* or OFPUTIL_NXAST_*
- * constant.  The caller must have already validated that 'a' is a valid action
+/* Parses 'a' and returns its type as an OFPUTIL_{OFPAT,NXAST,MIDO}_* constant.
+ * The caller must have already validated that 'a' is a valid action
  * understood by Open vSwitch (e.g. by a previous successful call to
  * ofputil_decode_action()). */
 enum ofputil_action_code
 ofputil_decode_action_unsafe(const union ofp_action *a)
 {
+    const struct nx_action_header *nah = (const void *) a;
+
     if (a->type != htons(OFPAT_VENDOR)) {
         return ofpat_actions[ntohs(a->type)].code;
-    } else {
-        const struct nx_action_header *nah = (const void *) a;
-
+    } else if (a->vendor.vendor == htonl(NX_VENDOR_ID)) {
         return nxast_actions[ntohs(nah->subtype)].code;
+    } else { /* (a->vendor.vendor == htonl(MIDO_VENDOR_ID) */
+        return mido_actions[ntohs(nah->subtype)].code;
     }
 }
 
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index 7ee3e69..33428ce 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -24,6 +24,7 @@
 #include "classifier.h"
 #include "flow.h"
 #include "openflow/nicira-ext.h"
+#include "openflow/midokura-ext.h"
 #include "openvswitch/types.h"
 
 struct cls_rule;
@@ -304,6 +305,9 @@ enum ofputil_action_code {
     OFPUTIL_NXAST_AUTOPATH,
     OFPUTIL_NXAST_BUNDLE,
     OFPUTIL_NXAST_BUNDLE_LOAD,
+
+    /* MIDO_* actions. */
+    OFPUTIL_MIDO_FIRST_ACTION,
 };
 
 int ofputil_decode_action(const union ofp_action *);
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index cdc21bc..e5d711f 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -3238,6 +3238,12 @@ do_xlate_actions(const union ofp_action *in, size_t n_in,
             bundle_execute_load(nab, &ctx->flow, slave_enabled_cb,
                                 ctx->ofproto);
             break;
+
+        case OFPUTIL_MIDO_FIRST_ACTION:
+            /* Placeholder */
+            VLOG_DBG_RL(&rl, "unimplemented Midokura action type %"PRIu16,
+                        code);
+            break;
         }
     }
 }
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index f40f995..616624e 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -35,6 +35,7 @@
 #include "ofpbuf.h"
 #include "ofproto-provider.h"
 #include "openflow/nicira-ext.h"
+#include "openflow/midokura-ext.h"
 #include "openflow/openflow.h"
 #include "packets.h"
 #include "pinsched.h"
-- 
1.7.5.4

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Reply via email to