ofp-msgs: Move most OpenFlow header definitions here.
[cascardo/ovs.git] / include / openflow / nicira-ext.h
index b1885b2..a209e6a 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 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
@@ -287,6 +283,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 +306,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,21 +468,6 @@ 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))
-
 /* Number of registers allocated NXM field IDs. */
 #define NXM_NX_MAX_REGS 16
 
@@ -489,22 +475,8 @@ OFP_ASSERT(sizeof(struct nx_async_config) == 24);
 #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? */
 
-/* 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)
-
+/* Bits in the value of NXM_NX_TUN_FLAGS. */
+#define NX_TUN_FLAG_OAM  (1 << 0) /* Is this an OAM packet? */
 
 /* ## --------------------- ## */
 /* ## Requests and replies. ## */
@@ -927,4 +899,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 */