Implement serializing the state of packet traversal in "continuations".
[cascardo/ovs.git] / include / openflow / nicira-ext.h
index bbf3388..8950335 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,8 +17,8 @@
 #ifndef OPENFLOW_NICIRA_EXT_H
 #define OPENFLOW_NICIRA_EXT_H 1
 
-#include "openflow/openflow.h"
-#include "openvswitch/types.h"
+#include <openflow/openflow.h>
+#include <openvswitch/types.h>
 
 /* The following vendor extensions, proposed by Nicira, are not yet
  * standardized, so they are not included in openflow.h.  Some of them may be
@@ -68,31 +68,6 @@ struct nx_vendor_error {
 \f
 /* Nicira vendor requests and replies. */
 
-/* Header for Nicira vendor requests and replies. */
-struct nicira_header {
-    struct ofp_header header;
-    ovs_be32 vendor;            /* NX_VENDOR_ID. */
-    ovs_be32 subtype;           /* See the NXT numbers in ofp-msgs.h. */
-};
-OFP_ASSERT(sizeof(struct nicira_header) == 16);
-
-/* Header for Nicira vendor stats request and reply messages in OpenFlow
- * 1.0. */
-struct nicira10_stats_msg {
-    struct ofp10_vendor_stats_msg vsm; /* Vendor NX_VENDOR_ID. */
-    ovs_be32 subtype;           /* One of NXST_* below. */
-    uint8_t pad[4];             /* Align to 64-bits. */
-};
-OFP_ASSERT(sizeof(struct nicira10_stats_msg) == 24);
-
-/* Header for Nicira vendor stats request and reply messages in OpenFlow
- * 1.1. */
-struct nicira11_stats_msg {
-    struct ofp11_vendor_stats_msg vsm; /* Vendor NX_VENDOR_ID. */
-    ovs_be32 subtype;           /* One of NXST_* below. */
-};
-OFP_ASSERT(sizeof(struct nicira11_stats_msg) == 24);
-
 /* Fields to use when hashing flows. */
 enum nx_hash_fields {
     /* Ethernet source address (NXM_OF_ETH_SRC) only. */
@@ -109,7 +84,28 @@ enum nx_hash_fields {
      *  - NXM_OF_IP_SRC / NXM_OF_IP_DST
      *  - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
      */
-    NX_HASH_FIELDS_SYMMETRIC_L4
+    NX_HASH_FIELDS_SYMMETRIC_L4,
+
+    /* L3+L4 only, including the following fields:
+     *
+     *  - NXM_OF_IP_PROTO
+     *  - NXM_OF_IP_SRC / NXM_OF_IP_DST
+     *  - NXM_OF_SCTP_SRC / NXM_OF_SCTP_DST
+     *  - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
+     */
+    NX_HASH_FIELDS_SYMMETRIC_L3L4,
+
+    /* L3+L4 only with UDP ports, including the following fields:
+     *
+     *  - NXM_OF_IP_PROTO
+     *  - NXM_OF_IP_SRC / NXM_OF_IP_DST
+     *  - NXM_OF_SCTP_SRC / NXM_OF_SCTP_DST
+     *  - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
+     *  - NXM_OF_UDP_SRC / NXM_OF_UDP_DST
+     */
+    NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP
+
+
 };
 
 /* This command enables or disables an Open vSwitch extension that allows a
@@ -158,11 +154,25 @@ struct nx_flow_mod_table_id {
 OFP_ASSERT(sizeof(struct nx_flow_mod_table_id) == 8);
 
 enum nx_packet_in_format {
-    NXPIF_OPENFLOW10 = 0,       /* Standard OpenFlow 1.0 compatible. */
-    NXPIF_NXM = 1               /* Nicira Extended. */
+    NXPIF_STANDARD = 0,         /* OFPT_PACKET_IN for this OpenFlow version. */
+    NXPIF_NXT_PACKET_IN = 1,    /* NXT_PACKET_IN (since OVS v1.1). */
+    NXPIF_NXT_PACKET_IN2 = 2,   /* NXT_PACKET_IN2 (since OVS v2.6). */
 };
 
-/* NXT_SET_PACKET_IN_FORMAT request. */
+/* NXT_SET_PACKET_IN_FORMAT request.
+ *
+ * For any given OpenFlow version, Open vSwitch supports multiple formats for
+ * "packet-in" messages.  The default is always the standard format for the
+ * OpenFlow version in question, but NXT_SET_PACKET_IN_FORMAT can be used to
+ * set an alternative format.
+ *
+ * From OVS v1.1 to OVS v2.5, this request was only honored for OpenFlow 1.0.
+ * Requests to set format NXPIF_NXT_PACKET_IN were accepted for OF1.1+ but they
+ * had no effect.  (Requests to set formats other than NXPIF_STANDARD or
+ * NXPIF_NXT_PACKET_IN were rejected with OFPBRC_EPERM.)
+ *
+ * From OVS v2.6 onward, this request is honored for all OpenFlow versions.
+ */
 struct nx_set_packet_in_format {
     ovs_be32 format;            /* One of NXPIF_*. */
 };
@@ -225,6 +235,123 @@ struct nx_packet_in {
 };
 OFP_ASSERT(sizeof(struct nx_packet_in) == 24);
 
+/* NXT_PACKET_IN2
+ * ==============
+ *
+ * NXT_PACKET_IN2 is conceptually similar to OFPT_PACKET_IN but it is expressed
+ * as an extensible set of properties instead of using a fixed structure.
+ *
+ * Added in Open vSwitch 2.6
+ *
+ *
+ * Continuations
+ * -------------
+ *
+ * When a "controller" action specifies the "pause" flag, the controller action
+ * freezes the packet's trip through Open vSwitch flow tables and serializes
+ * that state into the packet-in message as a "continuation".  The controller
+ * can later send the continuation back to the switch, which will restart the
+ * packet's traversal from the point where it was interrupted.  This permits an
+ * OpenFlow controller to interpose on a packet midway through processing in
+ * Open vSwitch.
+ *
+ * Continuations fit into packet processing this way:
+ *
+ * 1. A packet ingresses into Open vSwitch, which runs it through the OpenFlow
+ *    tables.
+ *
+ * 2. An OpenFlow flow executes a "controller" action that includes the "pause"
+ *    flag.  Open vSwitch serializes the packet processing state and sends it,
+ *    as an NXT_PACKET_IN2 that includes an additional NXPINT_CONTINUATION
+ *    property (the continuation), to the OpenFlow controller.
+ *
+ *    (The controller must use NXAST_CONTROLLER2 to generate the packet-in,
+ *    because only this form of the "controller" action has a "pause" flag.
+ *    Similarly, the controller must use NXT_SET_PACKET_IN_FORMAT to select
+ *    NXT_PACKET_IN2 as the packet-in format, because this is the only format
+ *    that supports continuation passing.)
+ *
+ * 3. The controller receives the NXT_PACKET_IN2 and processes it.  The
+ *    controller can interpret and, if desired, modify some of the contents of
+ *    the packet-in, such as the packet and the metadata being processed.
+ *
+ * 4. The controller sends the continuation back to the switch, using an
+ *    NXT_RESUME message.  Packet processing resumes where it left off.
+ *
+ * The controller might change the pipeline configuration concurrently with
+ * steps 2 through 4.  For example, it might add or remove OpenFlow flows.  If
+ * that happens, then the packet will experience a mix of processing from the
+ * two configurations, that is, the initial processing (before
+ * NXAST_CONTROLLER2) uses the initial flow table, and the later processing
+ * (after NXT_RESUME) uses the later flow table.  This means that the
+ * controller needs to take care to avoid incompatible pipeline changes while
+ * processing continuations.
+ *
+ * External side effects (e.g. "output") of OpenFlow actions processed before
+ * NXAST_CONTROLLER2 is encountered might be executed during step 2 or step 4,
+ * and the details may vary among Open vSwitch features and versions.  Thus, a
+ * controller that wants to make sure that side effects are executed must pass
+ * the continuation back to the switch, that is, must not skip step 4.
+ *
+ * Architecturally, continuations may be "stateful" or "stateless", that is,
+ * they may or may not refer to buffered state maintained in Open vSwitch.
+ * This means that a controller should not attempt to resume a given
+ * continuations more than once (because the switch might have discarded the
+ * buffered state after the first use).  For the same reason, continuations
+ * might become "stale" if the controller takes too long to resume them
+ * (because the switch might have discarded old buffered state).  Taken
+ * together with the previous note, this means that a controller should resume
+ * each continuation exactly once (and promptly).
+ *
+ * Without the information in NXPINT_CONTINUATION, the controller can (with
+ * careful design, and help from the flow cookie) determine where the packet is
+ * in the pipeline, but in the general case it can't determine what nested
+ * "resubmit"s that may be in progress, or what data is on the stack maintained
+ * by NXAST_STACK_PUSH and NXAST_STACK_POP actions, what is in the OpenFlow
+ * action set, etc.
+ *
+ * Continuations are expensive because they require a round trip between the
+ * switch and the controller.  Thus, they should not be used to implement
+ * processing that needs to happen at "line rate".
+ *
+ * The contents of NXPINT_CONTINUATION are private to the switch, may change
+ * unpredictably from one version of Open vSwitch to another, and are not
+ * documented here.  The contents are also tied to a given Open vSwitch process
+ * and bridge, so that restarting Open vSwitch or deleting and recreating a
+ * bridge will cause the corresponding NXT_RESUME to be rejected.
+ *
+ * In the current implementation, Open vSwitch forks the packet processing
+ * pipeline across patch ports.  Suppose, for example, that the pipeline for
+ * br0 outputs to a patch port whose peer belongs to br1, and that the pipeline
+ * for br1 executes a controller action with the "pause" flag.  This only
+ * pauses processing within br1, and processing in br0 continues and possibly
+ * completes with visible side effects, such as outputting to ports, before
+ * br1's controller receives or processes the continuation.  This
+ * implementation maintains the independence of separate bridges and, since
+ * processing in br1 cannot affect the behavior of br0 anyway, should not cause
+ * visible behavioral changes.
+ *
+ * A stateless implementation of continuations may ignore the "controller"
+ * action max_len, always sending the whole packet, because the full packet is
+ * required to continue traversal.
+ */
+enum nx_packet_in2_prop_type {
+    /* Packet. */
+    NXPINT_PACKET,              /* Raw packet data. */
+    NXPINT_FULL_LEN,            /* ovs_be32: Full packet len, if truncated. */
+    NXPINT_BUFFER_ID,           /* ovs_be32: Buffer ID, if buffered. */
+
+    /* Information about the flow that triggered the packet-in. */
+    NXPINT_TABLE_ID,            /* uint8_t: Table ID. */
+    NXPINT_COOKIE,              /* ovs_be64: Flow cookie. */
+
+    /* Other. */
+    NXPINT_REASON,              /* uint8_t, one of OFPR_*. */
+    NXPINT_METADATA,            /* NXM or OXM for metadata fields. */
+    NXPINT_USERDATA,            /* From NXAST_CONTROLLER2 userdata. */
+    NXPINT_CONTINUATION,        /* Private data for continuing processing. */
+};
+
 /* Configures the "role" of the sending controller.  The default role is:
  *
  *    - Other (NX_ROLE_OTHER), which allows the controller access to all
@@ -287,6 +414,9 @@ OFP_ASSERT(sizeof(struct nx_async_config) == 24);
  * short, that is also supported by Open vSwitch.  This section also defines a
  * replacement for each OpenFlow message that includes struct ofp10_match.
  *
+ * OpenFlow 1.2+ introduced OpenFlow Extensible Match (OXM), adapting
+ * the design of NXM.  The format of NXM and OXM are compatible.
+ *
  *
  * Format
  * ======
@@ -307,10 +437,12 @@ OFP_ASSERT(sizeof(struct nx_async_config) == 24);
  * +----------------------------------+---------------+--+------------------+
  *
  * The most-significant 23 bits of the header are collectively "nxm_type".
- * Bits 16...31 are "nxm_vendor", one of the NXM_VENDOR_* values below.  Bits
- * 9...15 are "nxm_field", which is a vendor-specific value.  nxm_type normally
- * designates a protocol header, such as the Ethernet type, but it can also
- * refer to packet metadata, such as the switch port on which a packet arrived.
+ * Bits 16...31 are "nxm_vendor", one of OFPXMC12_* values.  In case of
+ * NXM, it's either OFPXMC12_NXM_0 or OFPXMC12_NXM_1.
+ * Bits 9...15 are "nxm_field", which is a vendor-specific value.  nxm_type
+ * normally designates a protocol header, such as the Ethernet type, but it
+ * can also refer to packet metadata, such as the switch port on which a packet
+ * arrived.
  *
  * Bit 8 is "nxm_hasmask" (labeled "hm" above for space reasons).  The meaning
  * of this bit is explained later.
@@ -467,506 +599,15 @@ OFP_ASSERT(sizeof(struct nx_async_config) == 24);
  * nx_match error.
  */
 
-#define NXM_HEADER__(VENDOR, FIELD, HASMASK, LENGTH) \
-    (((VENDOR) << 16) | ((FIELD) << 9) | ((HASMASK) << 8) | (LENGTH))
-#define NXM_HEADER(VENDOR, FIELD, LENGTH) \
-    NXM_HEADER__(VENDOR, FIELD, 0, LENGTH)
-#define NXM_HEADER_W(VENDOR, FIELD, LENGTH) \
-    NXM_HEADER__(VENDOR, FIELD, 1, (LENGTH) * 2)
-#define NXM_VENDOR(HEADER) ((HEADER) >> 16)
-#define NXM_FIELD(HEADER) (((HEADER) >> 9) & 0x7f)
-#define NXM_TYPE(HEADER) (((HEADER) >> 9) & 0x7fffff)
-#define NXM_HASMASK(HEADER) (((HEADER) >> 8) & 1)
-#define NXM_LENGTH(HEADER) ((HEADER) & 0xff)
-
-#define NXM_MAKE_WILD_HEADER(HEADER) \
-        NXM_HEADER_W(NXM_VENDOR(HEADER), NXM_FIELD(HEADER), NXM_LENGTH(HEADER))
-
-/* ## ------------------------------- ## */
-/* ## OpenFlow 1.0-compatible fields. ## */
-/* ## ------------------------------- ## */
-
-/* Physical or virtual port on which the packet was received.
- *
- * Prereqs: None.
- *
- * Format: 16-bit integer in network byte order.
- *
- * Masking: Not maskable. */
-#define NXM_OF_IN_PORT    NXM_HEADER  (0x0000,  0, 2)
-
-/* Source or destination address in Ethernet header.
- *
- * Prereqs: None.
- *
- * Format: 48-bit Ethernet MAC address.
- *
- * Masking: Fully maskable, in versions 1.8 and later. Earlier versions only
- *   supported the following masks for NXM_OF_ETH_DST_W: 00:00:00:00:00:00,
- *   fe:ff:ff:ff:ff:ff, 01:00:00:00:00:00, ff:ff:ff:ff:ff:ff. */
-#define NXM_OF_ETH_DST    NXM_HEADER  (0x0000,  1, 6)
-#define NXM_OF_ETH_DST_W  NXM_HEADER_W(0x0000,  1, 6)
-#define NXM_OF_ETH_SRC    NXM_HEADER  (0x0000,  2, 6)
-#define NXM_OF_ETH_SRC_W  NXM_HEADER_W(0x0000,  2, 6)
-
-/* Packet's Ethernet type.
- *
- * For an Ethernet II packet this is taken from the Ethernet header.  For an
- * 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP header.
- * A packet that has neither format has value 0x05ff
- * (OFP_DL_TYPE_NOT_ETH_TYPE).
- *
- * For a packet with an 802.1Q header, this is the type of the encapsulated
- * frame.
- *
- * Prereqs: None.
- *
- * Format: 16-bit integer in network byte order.
- *
- * Masking: Not maskable. */
-#define NXM_OF_ETH_TYPE   NXM_HEADER  (0x0000,  3, 2)
-
-/* 802.1Q TCI.
- *
- * For a packet with an 802.1Q header, this is the Tag Control Information
- * (TCI) field, with the CFI bit forced to 1.  For a packet with no 802.1Q
- * header, this has value 0.
- *
- * Prereqs: None.
- *
- * Format: 16-bit integer in network byte order.
- *
- * Masking: Arbitrary masks.
- *
- * This field can be used in various ways:
- *
- *   - If it is not constrained at all, the nx_match matches packets without
- *     an 802.1Q header or with an 802.1Q header that has any TCI value.
- *
- *   - Testing for an exact match with 0 matches only packets without an
- *     802.1Q header.
- *
- *   - Testing for an exact match with a TCI value with CFI=1 matches packets
- *     that have an 802.1Q header with a specified VID and PCP.
- *
- *   - Testing for an exact match with a nonzero TCI value with CFI=0 does
- *     not make sense.  The switch may reject this combination.
- *
- *   - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
- *     packets that have an 802.1Q header with that VID (and any PCP).
- *
- *   - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
- *     packets that have an 802.1Q header with that PCP (and any VID).
- *
- *   - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no 802.1Q
- *     header or with an 802.1Q header with a VID of 0.
- *
- *   - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no 802.1Q
- *     header or with an 802.1Q header with a PCP of 0.
- *
- *   - Testing with nxm_value=0, nxm_mask=0xefff matches packets with no 802.1Q
- *     header or with an 802.1Q header with both VID and PCP of 0.
- */
-#define NXM_OF_VLAN_TCI   NXM_HEADER  (0x0000,  4, 2)
-#define NXM_OF_VLAN_TCI_W NXM_HEADER_W(0x0000,  4, 2)
-
-/* The "type of service" byte of the IP header, with the ECN bits forced to 0.
- *
- * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
- *
- * Format: 8-bit integer with 2 least-significant bits forced to 0.
- *
- * Masking: Not maskable. */
-#define NXM_OF_IP_TOS     NXM_HEADER  (0x0000,  5, 1)
-
-/* The "protocol" byte in the IP header.
- *
- * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
- *
- * Format: 8-bit integer.
- *
- * Masking: Not maskable. */
-#define NXM_OF_IP_PROTO   NXM_HEADER  (0x0000,  6, 1)
-
-/* The source or destination address in the IP header.
- *
- * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
- *
- * Format: 32-bit integer in network byte order.
- *
- * Masking: Fully maskable, in Open vSwitch 1.8 and later.  In earlier
- *   versions, only CIDR masks are allowed, that is, masks that consist of N
- *   high-order bits set to 1 and the other 32-N bits set to 0. */
-#define NXM_OF_IP_SRC     NXM_HEADER  (0x0000,  7, 4)
-#define NXM_OF_IP_SRC_W   NXM_HEADER_W(0x0000,  7, 4)
-#define NXM_OF_IP_DST     NXM_HEADER  (0x0000,  8, 4)
-#define NXM_OF_IP_DST_W   NXM_HEADER_W(0x0000,  8, 4)
-
-/* The source or destination port in the TCP header.
- *
- * Prereqs:
- *   NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
- *   NXM_OF_IP_PROTO must match 6 exactly.
- *
- * Format: 16-bit integer in network byte order.
- *
- * Masking: Fully maskable, in Open vSwitch 1.6 and later.  Not maskable, in
- *   earlier versions. */
-#define NXM_OF_TCP_SRC    NXM_HEADER  (0x0000,  9, 2)
-#define NXM_OF_TCP_SRC_W  NXM_HEADER_W(0x0000,  9, 2)
-#define NXM_OF_TCP_DST    NXM_HEADER  (0x0000, 10, 2)
-#define NXM_OF_TCP_DST_W  NXM_HEADER_W(0x0000, 10, 2)
-
-/* The source or destination port in the UDP header.
- *
- * Prereqs:
- *   NXM_OF_ETH_TYPE must match either 0x0800 or 0x86dd.
- *   NXM_OF_IP_PROTO must match 17 exactly.
- *
- * Format: 16-bit integer in network byte order.
- *
- * Masking: Fully maskable, in Open vSwitch 1.6 and later.  Not maskable, in
- *   earlier versions. */
-#define NXM_OF_UDP_SRC    NXM_HEADER  (0x0000, 11, 2)
-#define NXM_OF_UDP_SRC_W  NXM_HEADER_W(0x0000, 11, 2)
-#define NXM_OF_UDP_DST    NXM_HEADER  (0x0000, 12, 2)
-#define NXM_OF_UDP_DST_W  NXM_HEADER_W(0x0000, 12, 2)
-
-/* The type or code in the ICMP header.
- *
- * Prereqs:
- *   NXM_OF_ETH_TYPE must match 0x0800 exactly.
- *   NXM_OF_IP_PROTO must match 1 exactly.
- *
- * Format: 8-bit integer.
- *
- * Masking: Not maskable. */
-#define NXM_OF_ICMP_TYPE  NXM_HEADER  (0x0000, 13, 1)
-#define NXM_OF_ICMP_CODE  NXM_HEADER  (0x0000, 14, 1)
-
-/* ARP opcode.
- *
- * For an Ethernet+IP ARP packet, the opcode in the ARP header.  Always 0
- * otherwise.  Only ARP opcodes between 1 and 255 should be specified for
- * matching.
- *
- * Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.
- *
- * Format: 16-bit integer in network byte order.
- *
- * Masking: Not maskable. */
-#define NXM_OF_ARP_OP     NXM_HEADER  (0x0000, 15, 2)
-
-/* For an Ethernet+IP ARP packet, the source or target protocol address
- * in the ARP header.  Always 0 otherwise.
- *
- * Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.
- *
- * Format: 32-bit integer in network byte order.
- *
- * Masking: Fully maskable, in Open vSwitch 1.8 and later.  In earlier
- *   versions, only CIDR masks are allowed, that is, masks that consist of N
- *   high-order bits set to 1 and the other 32-N bits set to 0. */
-#define NXM_OF_ARP_SPA    NXM_HEADER  (0x0000, 16, 4)
-#define NXM_OF_ARP_SPA_W  NXM_HEADER_W(0x0000, 16, 4)
-#define NXM_OF_ARP_TPA    NXM_HEADER  (0x0000, 17, 4)
-#define NXM_OF_ARP_TPA_W  NXM_HEADER_W(0x0000, 17, 4)
-
-/* ## ------------------------ ## */
-/* ## Nicira match extensions. ## */
-/* ## ------------------------ ## */
-
-/* Metadata registers.
- *
- * Registers initially have value 0.  Actions allow register values to be
- * manipulated.
- *
- * Prereqs: None.
- *
- * Format: Array of 32-bit integer registers.  Space is reserved for up to
- *   NXM_NX_MAX_REGS registers, but switches may implement fewer.
- *
- * Masking: Arbitrary masks. */
+/* Number of registers allocated NXM field IDs. */
 #define NXM_NX_MAX_REGS 16
-#define NXM_NX_REG(IDX)   NXM_HEADER  (0x0001, IDX, 4)
-#define NXM_NX_REG_W(IDX) NXM_HEADER_W(0x0001, IDX, 4)
-#define NXM_NX_REG_IDX(HEADER) NXM_FIELD(HEADER)
-#define NXM_IS_NX_REG(HEADER) (!((((HEADER) ^ NXM_NX_REG0)) & 0xffffe1ff))
-#define NXM_IS_NX_REG_W(HEADER) (!((((HEADER) ^ NXM_NX_REG0_W)) & 0xffffe1ff))
-#define NXM_NX_REG0       NXM_HEADER  (0x0001, 0, 4)
-#define NXM_NX_REG0_W     NXM_HEADER_W(0x0001, 0, 4)
-#define NXM_NX_REG1       NXM_HEADER  (0x0001, 1, 4)
-#define NXM_NX_REG1_W     NXM_HEADER_W(0x0001, 1, 4)
-#define NXM_NX_REG2       NXM_HEADER  (0x0001, 2, 4)
-#define NXM_NX_REG2_W     NXM_HEADER_W(0x0001, 2, 4)
-#define NXM_NX_REG3       NXM_HEADER  (0x0001, 3, 4)
-#define NXM_NX_REG3_W     NXM_HEADER_W(0x0001, 3, 4)
-#define NXM_NX_REG4       NXM_HEADER  (0x0001, 4, 4)
-#define NXM_NX_REG4_W     NXM_HEADER_W(0x0001, 4, 4)
-#define NXM_NX_REG5       NXM_HEADER  (0x0001, 5, 4)
-#define NXM_NX_REG5_W     NXM_HEADER_W(0x0001, 5, 4)
-#define NXM_NX_REG6       NXM_HEADER  (0x0001, 6, 4)
-#define NXM_NX_REG6_W     NXM_HEADER_W(0x0001, 6, 4)
-#define NXM_NX_REG7       NXM_HEADER  (0x0001, 7, 4)
-#define NXM_NX_REG7_W     NXM_HEADER_W(0x0001, 7, 4)
-
-/* Tunnel ID.
- *
- * For a packet received via a Geneve, GRE, VXLAN or LISP tunnel including a
- * key less than 64 bits, the key is stored in the low bits and the high bits
- * are zeroed.  For other packets, the value is 0.
- *
- * All zero bits, for packets not received via a keyed tunnel.
- *
- * Prereqs: None.
- *
- * Format: 64-bit integer in network byte order.
- *
- * Masking: Arbitrary masks. */
-#define NXM_NX_TUN_ID     NXM_HEADER  (0x0001, 16, 8)
-#define NXM_NX_TUN_ID_W   NXM_HEADER_W(0x0001, 16, 8)
-
-/* For an Ethernet+IP ARP packet, the source or target hardware address
- * in the ARP header.  Always 0 otherwise.
- *
- * Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.
- *
- * Format: 48-bit Ethernet MAC address.
- *
- * Masking: Not maskable. */
-#define NXM_NX_ARP_SHA    NXM_HEADER  (0x0001, 17, 6)
-#define NXM_NX_ARP_THA    NXM_HEADER  (0x0001, 18, 6)
-
-/* The source or destination address in the IPv6 header.
- *
- * Prereqs: NXM_OF_ETH_TYPE must match 0x86dd exactly.
- *
- * Format: 128-bit IPv6 address.
- *
- * Masking: Fully maskable, in Open vSwitch 1.8 and later.  In previous
- *   versions, only CIDR masks are allowed, that is, masks that consist of N
- *   high-order bits set to 1 and the other 128-N bits set to 0. */
-#define NXM_NX_IPV6_SRC    NXM_HEADER  (0x0001, 19, 16)
-#define NXM_NX_IPV6_SRC_W  NXM_HEADER_W(0x0001, 19, 16)
-#define NXM_NX_IPV6_DST    NXM_HEADER  (0x0001, 20, 16)
-#define NXM_NX_IPV6_DST_W  NXM_HEADER_W(0x0001, 20, 16)
-
-/* The type or code in the ICMPv6 header.
- *
- * Prereqs:
- *   NXM_OF_ETH_TYPE must match 0x86dd exactly.
- *   NXM_OF_IP_PROTO must match 58 exactly.
- *
- * Format: 8-bit integer.
- *
- * Masking: Not maskable. */
-#define NXM_NX_ICMPV6_TYPE NXM_HEADER  (0x0001, 21, 1)
-#define NXM_NX_ICMPV6_CODE NXM_HEADER  (0x0001, 22, 1)
-
-/* The target address in an IPv6 Neighbor Discovery message.
- *
- * Prereqs:
- *   NXM_OF_ETH_TYPE must match 0x86dd exactly.
- *   NXM_OF_IP_PROTO must match 58 exactly.
- *   NXM_OF_ICMPV6_TYPE must be either 135 or 136.
- *
- * Format: 128-bit IPv6 address.
- *
- * Masking: Fully maskable, in Open vSwitch 1.8 and later.  In previous
- *   versions, only CIDR masks are allowed, that is, masks that consist of N
- *   high-order bits set to 1 and the other 128-N bits set to 0. */
-#define NXM_NX_ND_TARGET     NXM_HEADER    (0x0001, 23, 16)
-#define NXM_NX_ND_TARGET_W   NXM_HEADER_W  (0x0001, 23, 16)
-
-/* The source link-layer address option in an IPv6 Neighbor Discovery
- * message.
- *
- * Prereqs:
- *   NXM_OF_ETH_TYPE must match 0x86dd exactly.
- *   NXM_OF_IP_PROTO must match 58 exactly.
- *   NXM_OF_ICMPV6_TYPE must be exactly 135.
- *
- * Format: 48-bit Ethernet MAC address.
- *
- * Masking: Not maskable. */
-#define NXM_NX_ND_SLL      NXM_HEADER  (0x0001, 24, 6)
-
-/* The target link-layer address option in an IPv6 Neighbor Discovery
- * message.
- *
- * Prereqs:
- *   NXM_OF_ETH_TYPE must match 0x86dd exactly.
- *   NXM_OF_IP_PROTO must match 58 exactly.
- *   NXM_OF_ICMPV6_TYPE must be exactly 136.
- *
- * Format: 48-bit Ethernet MAC address.
- *
- * Masking: Not maskable. */
-#define NXM_NX_ND_TLL      NXM_HEADER  (0x0001, 25, 6)
-
-/* IP fragment information.
- *
- * Prereqs:
- *   NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
- *
- * Format: 8-bit value with one of the values 0, 1, or 3, as described below.
- *
- * Masking: Fully maskable.
- *
- * This field has three possible values:
- *
- *   - A packet that is not an IP fragment has value 0.
- *
- *   - A packet that is an IP fragment with offset 0 (the first fragment) has
- *     bit 0 set and thus value 1.
- *
- *   - A packet that is an IP fragment with nonzero offset has bits 0 and 1 set
- *     and thus value 3.
- *
- * NX_IP_FRAG_ANY and NX_IP_FRAG_LATER are declared to symbolically represent
- * the meanings of bits 0 and 1.
- *
- * The switch may reject matches against values that can never appear.
- *
- * It is important to understand how this field interacts with the OpenFlow IP
- * fragment handling mode:
- *
- *   - In OFPC_FRAG_DROP mode, the OpenFlow switch drops all IP fragments
- *     before they reach the flow table, so every packet that is available for
- *     matching will have value 0 in this field.
- *
- *   - Open vSwitch does not implement OFPC_FRAG_REASM mode, but if it did then
- *     IP fragments would be reassembled before they reached the flow table and
- *     again every packet available for matching would always have value 0.
- *
- *   - In OFPC_FRAG_NORMAL mode, all three values are possible, but OpenFlow
- *     1.0 says that fragments' transport ports are always 0, even for the
- *     first fragment, so this does not provide much extra information.
- *
- *   - In OFPC_FRAG_NX_MATCH mode, all three values are possible.  For
- *     fragments with offset 0, Open vSwitch makes L4 header information
- *     available.
- */
-#define NXM_NX_IP_FRAG     NXM_HEADER  (0x0001, 26, 1)
-#define NXM_NX_IP_FRAG_W   NXM_HEADER_W(0x0001, 26, 1)
 
 /* Bits in the value of NXM_NX_IP_FRAG. */
 #define NX_IP_FRAG_ANY   (1 << 0) /* Is this a fragment? */
 #define NX_IP_FRAG_LATER (1 << 1) /* Is this a fragment with nonzero offset? */
 
-/* The flow label in the IPv6 header.
- *
- * Prereqs: NXM_OF_ETH_TYPE must match 0x86dd exactly.
- *
- * Format: 20-bit IPv6 flow label in least-significant bits.
- *
- * Masking: Fully maskable. */
-#define NXM_NX_IPV6_LABEL   NXM_HEADER  (0x0001, 27, 4)
-#define NXM_NX_IPV6_LABEL_W NXM_HEADER_W(0x0001, 27, 4)
-
-/* The ECN of the IP header.
- *
- * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
- *
- * Format: ECN in the low-order 2 bits.
- *
- * Masking: Not maskable. */
-#define NXM_NX_IP_ECN      NXM_HEADER  (0x0001, 28, 1)
-
-/* The time-to-live/hop limit of the IP header.
- *
- * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
- *
- * Format: 8-bit integer.
- *
- * Masking: Not maskable. */
-#define NXM_NX_IP_TTL      NXM_HEADER  (0x0001, 29, 1)
-
-/* Flow cookie.
- *
- * This may be used to gain the OpenFlow 1.1-like ability to restrict
- * certain NXM-based Flow Mod and Flow Stats Request messages to flows
- * with specific cookies.  See the "nx_flow_mod" and "nx_flow_stats_request"
- * structure definitions for more details.  This match is otherwise not
- * allowed.
- *
- * Prereqs: None.
- *
- * Format: 64-bit integer in network byte order.
- *
- * Masking: Arbitrary masks. */
-#define NXM_NX_COOKIE     NXM_HEADER  (0x0001, 30, 8)
-#define NXM_NX_COOKIE_W   NXM_HEADER_W(0x0001, 30, 8)
-
-/* The source or destination address in the outer IP header of a tunneled
- * packet.
- *
- * For non-tunneled packets, the value is 0.
- *
- * Prereqs: None.
- *
- * Format: 32-bit integer in network byte order.
- *
- * Masking: Fully maskable. */
-#define NXM_NX_TUN_IPV4_SRC   NXM_HEADER  (0x0001, 31, 4)
-#define NXM_NX_TUN_IPV4_SRC_W NXM_HEADER_W(0x0001, 31, 4)
-#define NXM_NX_TUN_IPV4_DST   NXM_HEADER  (0x0001, 32, 4)
-#define NXM_NX_TUN_IPV4_DST_W NXM_HEADER_W(0x0001, 32, 4)
-
-/* Metadata marked onto the packet in a system-dependent manner.
- *
- * The packet mark may be used to carry contextual information
- * to other parts of the system outside of Open vSwitch. As a
- * result, the semantics depend on system in use.
- *
- * Prereqs: None.
- *
- * Format: 32-bit integer in network byte order.
- *
- * Masking: Fully maskable. */
-#define NXM_NX_PKT_MARK   NXM_HEADER  (0x0001, 33, 4)
-#define NXM_NX_PKT_MARK_W NXM_HEADER_W(0x0001, 33, 4)
-
-/* The flags in the TCP header.
-*
-* Prereqs:
-*   NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
-*   NXM_OF_IP_PROTO must match 6 exactly.
-*
-* Format: 16-bit integer with 4 most-significant bits forced to 0.
-*
-* Masking: Bits 0-11 fully maskable. */
-#define NXM_NX_TCP_FLAGS   NXM_HEADER  (0x0001, 34, 2)
-#define NXM_NX_TCP_FLAGS_W NXM_HEADER_W(0x0001, 34, 2)
-
-/* Metadata dp_hash.
- *
- * Internal use only, not programable from controller.
- *
- * The dp_hash is used to carry the flow hash computed in the
- * datapath.
- *
- * Prereqs: None.
- *
- * Format: 32-bit integer in network byte order.
- *
- * Masking: Fully maskable. */
-#define NXM_NX_DP_HASH   NXM_HEADER  (0x0001, 35, 4)
-#define NXM_NX_DP_HASH_W NXM_HEADER_W(0x0001, 35, 4)
-
-/* Metadata recirc_id.
- *
- * Internal use only, not programable from controller.
- *
- * The recirc_id used for recirculation. 0 is reserved
- * for initially received packet.
- *
- * Prereqs: None.
- *
- * Format: 32-bit integer in network byte order.
- *
- * Masking: not maskable. */
-#define NXM_NX_RECIRC_ID   NXM_HEADER  (0x0001, 36, 4)
+/* Bits in the value of NXM_NX_TUN_FLAGS. */
+#define NX_TUN_FLAG_OAM  (1 << 0) /* Is this an OAM packet? */
 
 /* ## --------------------- ## */
 /* ## Requests and replies. ## */
@@ -1389,4 +1030,86 @@ struct nx_flow_monitor_cancel {
 };
 OFP_ASSERT(sizeof(struct nx_flow_monitor_cancel) == 4);
 
+/* Variable-length option TLV table maintenance commands.
+ *
+ * The option in Type-Length-Value format is widely used in tunnel options,
+ * e.g., the base Geneve header is followed by zero or more options in TLV
+ * format. Each option consists of a four byte option header and a variable
+ * amount of option data interpreted according to the type. The generic TLV
+ * format in tunnel options is as following:
+ *
+ * 0                   1                   2                   3
+ * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |          Option Class         |      Type     |R|R|R| Length  |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |                      Variable Option Data                     |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * In order to work with this variable-length options in TLV format in
+ * tunnel options, we need to maintain a mapping table between an option
+ * TLV (defined by <class, type, length>) and an NXM field that can be
+ * operated on for the purposes of matches, actions, etc. This mapping
+ * must be explicitly specified by the user.
+ *
+ * There are two primary groups of OpenFlow messages that are introduced
+ * as Nicira extensions: modification commands (add, delete, clear mappings)
+ * and table status request/reply to dump the current table along with switch
+ * information.
+ *
+ * Note that mappings should not be changed while they are in active use by
+ * a flow. The result of doing so is undefined. */
+
+/* TLV table commands */
+enum nx_tlv_table_mod_command {
+    NXTTMC_ADD,          /* New mappings (fails if an option is already
+                            mapped). */
+    NXTTMC_DELETE,       /* Delete mappings, identified by index
+                          * (unmapped options are ignored). */
+    NXTTMC_CLEAR,        /* Clear all mappings. Additional information
+                            in this command is ignored. */
+};
+
+/* Map between an option TLV and an NXM field. */
+struct nx_tlv_map {
+    ovs_be16 option_class; /* TLV class. */
+    uint8_t  option_type;  /* TLV type. */
+    uint8_t  option_len;   /* TLV length (multiple of 4). */
+    ovs_be16 index;        /* NXM_NX_TUN_METADATA<n> index */
+    uint8_t  pad[2];
+};
+OFP_ASSERT(sizeof(struct nx_tlv_map) == 8);
+
+/* NXT_TLV_TABLE_MOD.
+ *
+ * Use to configure a mapping between option TLVs (class, type, length)
+ * and NXM fields (NXM_NX_TUN_METADATA<n> where 'index' is <n>).
+ *
+ * This command is atomic: all operations on different options will
+ * either succeed or fail. */
+struct nx_tlv_table_mod {
+    ovs_be16 command;           /* One of NTTTMC_* */
+    uint8_t pad[6];
+    /* struct nx_tlv_map[0]; Array of maps between indicies and option
+                                TLVs. The number of elements is inferred
+                                from the length field in the header. */
+};
+OFP_ASSERT(sizeof(struct nx_tlv_table_mod) == 8);
+
+/* NXT_TLV_TABLE_REPLY.
+ *
+ * Issued in reponse to an NXT_TLV_TABLE_REQUEST to give information
+ * about the current status of the TLV table in the switch. Provides
+ * both static information about the switch's capabilities as well as
+ * the configured TLV table. */
+struct nx_tlv_table_reply {
+    ovs_be32 max_option_space; /* Maximum total of option sizes supported. */
+    ovs_be16 max_fields;       /* Maximum number of match fields supported. */
+    uint8_t reserved[10];
+    /* struct nx_tlv_map[0]; Array of maps between indicies and option
+                                TLVs. The number of elements is inferred
+                                from the length field in the header. */
+};
+OFP_ASSERT(sizeof(struct nx_tlv_table_reply) == 16);
+
 #endif /* openflow/nicira-ext.h */