tunneling: Allow matching and setting tunnel 'OAM' flag.
[cascardo/ovs.git] / include / openflow / nicira-ext.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef OPENFLOW_NICIRA_EXT_H
18 #define OPENFLOW_NICIRA_EXT_H 1
19
20 #include <openflow/openflow.h>
21 #include <openvswitch/types.h>
22
23 /* The following vendor extensions, proposed by Nicira, are not yet
24  * standardized, so they are not included in openflow.h.  Some of them may be
25  * suitable for standardization; others we never expect to standardize. */
26
27 \f
28 /* Nicira vendor-specific error messages extension.
29  *
30  * OpenFlow 1.0 has a set of predefined error types (OFPET_*) and codes (which
31  * are specific to each type).  It does not have any provision for
32  * vendor-specific error codes, and it does not even provide "generic" error
33  * codes that can apply to problems not anticipated by the OpenFlow
34  * specification authors.
35  *
36  * This extension attempts to address the problem by adding a generic "error
37  * vendor extension".  The extension works as follows: use NXET_VENDOR as type
38  * and NXVC_VENDOR_ERROR as code, followed by struct nx_vendor_error with
39  * vendor-specific details, followed by at least 64 bytes of the failed
40  * request.
41  *
42  * It would be better to have a type-specific vendor extension, e.g. so that
43  * OFPET_BAD_ACTION could be used with vendor-specific code values.  But
44  * OFPET_BAD_ACTION and most other standardized types already specify that
45  * their 'data' values are (the start of) the OpenFlow message being replied
46  * to, so there is no room to insert a vendor ID.
47  *
48  * Currently this extension is only implemented by Open vSwitch, but it seems
49  * like a reasonable candidate for future standardization.
50  */
51
52 /* This is a random number to avoid accidental collision with any other
53  * vendor's extension. */
54 #define NXET_VENDOR 0xb0c2
55
56 /* ofp_error msg 'code' values for NXET_VENDOR. */
57 enum nx_vendor_code {
58     NXVC_VENDOR_ERROR           /* 'data' contains struct nx_vendor_error. */
59 };
60
61 /* 'data' for 'type' == NXET_VENDOR, 'code' == NXVC_VENDOR_ERROR. */
62 struct nx_vendor_error {
63     ovs_be32 vendor;            /* Vendor ID as in struct ofp_vendor_header. */
64     ovs_be16 type;              /* Vendor-defined type. */
65     ovs_be16 code;              /* Vendor-defined subtype. */
66     /* Followed by at least the first 64 bytes of the failed request. */
67 };
68 \f
69 /* Nicira vendor requests and replies. */
70
71 /* Header for Nicira vendor requests and replies. */
72 struct nicira_header {
73     struct ofp_header header;
74     ovs_be32 vendor;            /* NX_VENDOR_ID. */
75     ovs_be32 subtype;           /* See the NXT numbers in ofp-msgs.h. */
76 };
77 OFP_ASSERT(sizeof(struct nicira_header) == 16);
78
79 /* Header for Nicira vendor stats request and reply messages in OpenFlow
80  * 1.0. */
81 struct nicira10_stats_msg {
82     struct ofp10_vendor_stats_msg vsm; /* Vendor NX_VENDOR_ID. */
83     ovs_be32 subtype;           /* One of NXST_* below. */
84     uint8_t pad[4];             /* Align to 64-bits. */
85 };
86 OFP_ASSERT(sizeof(struct nicira10_stats_msg) == 24);
87
88 /* Header for Nicira vendor stats request and reply messages in OpenFlow
89  * 1.1. */
90 struct nicira11_stats_msg {
91     struct ofp11_vendor_stats_msg vsm; /* Vendor NX_VENDOR_ID. */
92     ovs_be32 subtype;           /* One of NXST_* below. */
93 };
94 OFP_ASSERT(sizeof(struct nicira11_stats_msg) == 24);
95
96 /* Fields to use when hashing flows. */
97 enum nx_hash_fields {
98     /* Ethernet source address (NXM_OF_ETH_SRC) only. */
99     NX_HASH_FIELDS_ETH_SRC,
100
101     /* L2 through L4, symmetric across src/dst.  Specifically, each of the
102      * following fields, if present, is hashed (slashes separate symmetric
103      * pairs):
104      *
105      *  - NXM_OF_ETH_DST / NXM_OF_ETH_SRC
106      *  - NXM_OF_ETH_TYPE
107      *  - The VID bits from NXM_OF_VLAN_TCI, ignoring PCP and CFI.
108      *  - NXM_OF_IP_PROTO
109      *  - NXM_OF_IP_SRC / NXM_OF_IP_DST
110      *  - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
111      */
112     NX_HASH_FIELDS_SYMMETRIC_L4,
113
114     /* L3+L4 only, including the following fields:
115      *
116      *  - NXM_OF_IP_PROTO
117      *  - NXM_OF_IP_SRC / NXM_OF_IP_DST
118      *  - NXM_OF_SCTP_SRC / NXM_OF_SCTP_DST
119      *  - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
120      */
121     NX_HASH_FIELDS_SYMMETRIC_L3L4,
122
123     /* L3+L4 only with UDP ports, including the following fields:
124      *
125      *  - NXM_OF_IP_PROTO
126      *  - NXM_OF_IP_SRC / NXM_OF_IP_DST
127      *  - NXM_OF_SCTP_SRC / NXM_OF_SCTP_DST
128      *  - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
129      *  - NXM_OF_UDP_SRC / NXM_OF_UDP_DST
130      */
131     NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP
132
133
134 };
135
136 /* This command enables or disables an Open vSwitch extension that allows a
137  * controller to specify the OpenFlow table to which a flow should be added,
138  * instead of having the switch decide which table is most appropriate as
139  * required by OpenFlow 1.0.  Because NXM was designed as an extension to
140  * OpenFlow 1.0, the extension applies equally to ofp10_flow_mod and
141  * nx_flow_mod.  By default, the extension is disabled.
142  *
143  * When this feature is enabled, Open vSwitch treats struct ofp10_flow_mod's
144  * and struct nx_flow_mod's 16-bit 'command' member as two separate fields.
145  * The upper 8 bits are used as the table ID, the lower 8 bits specify the
146  * command as usual.  A table ID of 0xff is treated like a wildcarded table ID.
147  *
148  * The specific treatment of the table ID depends on the type of flow mod:
149  *
150  *    - OFPFC_ADD: Given a specific table ID, the flow is always placed in that
151  *      table.  If an identical flow already exists in that table only, then it
152  *      is replaced.  If the flow cannot be placed in the specified table,
153  *      either because the table is full or because the table cannot support
154  *      flows of the given type, the switch replies with an OFPFMFC_TABLE_FULL
155  *      error.  (A controller can distinguish these cases by comparing the
156  *      current and maximum number of entries reported in ofp_table_stats.)
157  *
158  *      If the table ID is wildcarded, the switch picks an appropriate table
159  *      itself.  If an identical flow already exist in the selected flow table,
160  *      then it is replaced.  The choice of table might depend on the flows
161  *      that are already in the switch; for example, if one table fills up then
162  *      the switch might fall back to another one.
163  *
164  *    - OFPFC_MODIFY, OFPFC_DELETE: Given a specific table ID, only flows
165  *      within that table are matched and modified or deleted.  If the table ID
166  *      is wildcarded, flows within any table may be matched and modified or
167  *      deleted.
168  *
169  *    - OFPFC_MODIFY_STRICT, OFPFC_DELETE_STRICT: Given a specific table ID,
170  *      only a flow within that table may be matched and modified or deleted.
171  *      If the table ID is wildcarded and exactly one flow within any table
172  *      matches, then it is modified or deleted; if flows in more than one
173  *      table match, then none is modified or deleted.
174  */
175 struct nx_flow_mod_table_id {
176     uint8_t set;                /* Nonzero to enable, zero to disable. */
177     uint8_t pad[7];
178 };
179 OFP_ASSERT(sizeof(struct nx_flow_mod_table_id) == 8);
180
181 enum nx_packet_in_format {
182     NXPIF_OPENFLOW10 = 0,       /* Standard OpenFlow 1.0 compatible. */
183     NXPIF_NXM = 1               /* Nicira Extended. */
184 };
185
186 /* NXT_SET_PACKET_IN_FORMAT request. */
187 struct nx_set_packet_in_format {
188     ovs_be32 format;            /* One of NXPIF_*. */
189 };
190 OFP_ASSERT(sizeof(struct nx_set_packet_in_format) == 4);
191
192 /* NXT_PACKET_IN (analogous to OFPT_PACKET_IN).
193  *
194  * NXT_PACKET_IN is similar to the OpenFlow 1.2 OFPT_PACKET_IN.  The
195  * differences are:
196  *
197  *     - NXT_PACKET_IN includes the cookie of the rule that triggered the
198  *       message.  (OpenFlow 1.3 OFPT_PACKET_IN also includes the cookie.)
199  *
200  *     - The metadata fields use NXM (instead of OXM) field numbers.
201  *
202  * Open vSwitch 1.9.0 and later omits metadata fields that are zero (as allowed
203  * by OpenFlow 1.2).  Earlier versions included all implemented metadata
204  * fields.
205  *
206  * Open vSwitch does not include non-metadata in the nx_match, because by
207  * definition that information can be found in the packet itself.  The format
208  * and the standards allow this, however, so controllers should be prepared to
209  * tolerate future changes.
210  *
211  * The NXM format is convenient for reporting metadata values, but it is
212  * important not to interpret the format as matching against a flow, because it
213  * does not.  Nothing is being matched; arbitrary metadata masks would not be
214  * meaningful.
215  *
216  * Whereas in most cases a controller can expect to only get back NXM fields
217  * that it set up itself (e.g. flow dumps will ordinarily report only NXM
218  * fields from flows that the controller added), NXT_PACKET_IN messages might
219  * contain fields that the controller does not understand, because the switch
220  * might support fields (new registers, new protocols, etc.) that the
221  * controller does not.  The controller must prepared to tolerate these.
222  *
223  * The 'cookie' field has no meaning when 'reason' is OFPR_NO_MATCH.  In this
224  * case it should be UINT64_MAX. */
225 struct nx_packet_in {
226     ovs_be32 buffer_id;       /* ID assigned by datapath. */
227     ovs_be16 total_len;       /* Full length of frame. */
228     uint8_t reason;           /* Reason packet is sent (one of OFPR_*). */
229     uint8_t table_id;         /* ID of the table that was looked up. */
230     ovs_be64 cookie;          /* Cookie of the rule that was looked up. */
231     ovs_be16 match_len;       /* Size of nx_match. */
232     uint8_t pad[6];           /* Align to 64-bits. */
233     /* Followed by:
234      *   - Exactly match_len (possibly 0) bytes containing the nx_match, then
235      *   - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
236      *     all-zero bytes, then
237      *   - Exactly 2 all-zero padding bytes, then
238      *   - An Ethernet frame whose length is inferred from nxh.header.length.
239      *
240      * The padding bytes preceding the Ethernet frame ensure that the IP
241      * header (if any) following the Ethernet header is 32-bit aligned. */
242
243     /* uint8_t nxm_fields[...]; */ /* NXM headers. */
244     /* uint8_t pad[2]; */          /* Align to 64 bit + 16 bit. */
245     /* uint8_t data[0]; */         /* Ethernet frame. */
246 };
247 OFP_ASSERT(sizeof(struct nx_packet_in) == 24);
248
249 /* Configures the "role" of the sending controller.  The default role is:
250  *
251  *    - Other (NX_ROLE_OTHER), which allows the controller access to all
252  *      OpenFlow features.
253  *
254  * The other possible roles are a related pair:
255  *
256  *    - Master (NX_ROLE_MASTER) is equivalent to Other, except that there may
257  *      be at most one Master controller at a time: when a controller
258  *      configures itself as Master, any existing Master is demoted to the
259  *      Slave role.
260  *
261  *    - Slave (NX_ROLE_SLAVE) allows the controller read-only access to
262  *      OpenFlow features.  In particular attempts to modify the flow table
263  *      will be rejected with an OFPBRC_EPERM error.
264  *
265  *      Slave controllers do not receive OFPT_PACKET_IN or OFPT_FLOW_REMOVED
266  *      messages, but they do receive OFPT_PORT_STATUS messages.
267  */
268 struct nx_role_request {
269     ovs_be32 role;              /* One of NX_ROLE_*. */
270 };
271 OFP_ASSERT(sizeof(struct nx_role_request) == 4);
272
273 enum nx_role {
274     NX_ROLE_OTHER,              /* Default role, full access. */
275     NX_ROLE_MASTER,             /* Full access, at most one. */
276     NX_ROLE_SLAVE               /* Read-only access. */
277 };
278
279 /* NXT_SET_ASYNC_CONFIG.
280  *
281  * Sent by a controller, this message configures the asynchronous messages that
282  * the controller wants to receive.  Element 0 in each array specifies messages
283  * of interest when the controller has an "other" or "master" role; element 1,
284  * when the controller has a "slave" role.
285  *
286  * Each array element is a bitmask in which a 0-bit disables receiving a
287  * particular message and a 1-bit enables receiving it.  Each bit controls the
288  * message whose 'reason' corresponds to the bit index.  For example, the bit
289  * with value 1<<2 == 4 in port_status_mask[1] determines whether the
290  * controller will receive OFPT_PORT_STATUS messages with reason OFPPR_MODIFY
291  * (value 2) when the controller has a "slave" role.
292  *
293  * As a side effect, for service controllers, this message changes the
294  * miss_send_len from default of zero to OFP_DEFAULT_MISS_SEND_LEN (128).
295  */
296 struct nx_async_config {
297     ovs_be32 packet_in_mask[2];    /* Bitmasks of OFPR_* values. */
298     ovs_be32 port_status_mask[2];  /* Bitmasks of OFPRR_* values. */
299     ovs_be32 flow_removed_mask[2]; /* Bitmasks of OFPPR_* values. */
300 };
301 OFP_ASSERT(sizeof(struct nx_async_config) == 24);
302 \f
303 /* Flexible flow specifications (aka NXM = Nicira Extended Match).
304  *
305  * OpenFlow 1.0 has "struct ofp10_match" for specifying flow matches.  This
306  * structure is fixed-length and hence difficult to extend.  This section
307  * describes a more flexible, variable-length flow match, called "nx_match" for
308  * short, that is also supported by Open vSwitch.  This section also defines a
309  * replacement for each OpenFlow message that includes struct ofp10_match.
310  *
311  * OpenFlow 1.2+ introduced OpenFlow Extensible Match (OXM), adapting
312  * the design of NXM.  The format of NXM and OXM are compatible.
313  *
314  *
315  * Format
316  * ======
317  *
318  * An nx_match is a sequence of zero or more "nxm_entry"s, which are
319  * type-length-value (TLV) entries, each 5 to 259 (inclusive) bytes long.
320  * "nxm_entry"s are not aligned on or padded to any multibyte boundary.  The
321  * first 4 bytes of an nxm_entry are its "header", followed by the entry's
322  * "body".
323  *
324  * An nxm_entry's header is interpreted as a 32-bit word in network byte order:
325  *
326  * |<-------------------- nxm_type ------------------>|
327  * |                                                  |
328  * |31                              16 15            9| 8 7                0
329  * +----------------------------------+---------------+--+------------------+
330  * |            nxm_vendor            |   nxm_field   |hm|    nxm_length    |
331  * +----------------------------------+---------------+--+------------------+
332  *
333  * The most-significant 23 bits of the header are collectively "nxm_type".
334  * Bits 16...31 are "nxm_vendor", one of OFPXMC12_* values.  In case of
335  * NXM, it's either OFPXMC12_NXM_0 or OFPXMC12_NXM_1.
336  * Bits 9...15 are "nxm_field", which is a vendor-specific value.  nxm_type
337  * normally designates a protocol header, such as the Ethernet type, but it
338  * can also refer to packet metadata, such as the switch port on which a packet
339  * arrived.
340  *
341  * Bit 8 is "nxm_hasmask" (labeled "hm" above for space reasons).  The meaning
342  * of this bit is explained later.
343  *
344  * The least-significant 8 bits are "nxm_length", a positive integer.  The
345  * length of the nxm_entry, including the header, is exactly 4 + nxm_length
346  * bytes.
347  *
348  * For a given nxm_vendor, nxm_field, and nxm_hasmask value, nxm_length is a
349  * constant.  It is included only to allow software to minimally parse
350  * "nxm_entry"s of unknown types.  (Similarly, for a given nxm_vendor,
351  * nxm_field, and nxm_length, nxm_hasmask is a constant.)
352  *
353  *
354  * Semantics
355  * =========
356  *
357  * A zero-length nx_match (one with no "nxm_entry"s) matches every packet.
358  *
359  * An nxm_entry places a constraint on the packets matched by the nx_match:
360  *
361  *   - If nxm_hasmask is 0, the nxm_entry's body contains a value for the
362  *     field, called "nxm_value".  The nx_match matches only packets in which
363  *     the field equals nxm_value.
364  *
365  *   - If nxm_hasmask is 1, then the nxm_entry's body contains a value for the
366  *     field (nxm_value), followed by a bitmask of the same length as the
367  *     value, called "nxm_mask".  For each 1-bit in position J in nxm_mask, the
368  *     nx_match matches only packets for which bit J in the given field's value
369  *     matches bit J in nxm_value.  A 0-bit in nxm_mask causes the
370  *     corresponding bit in nxm_value is ignored (it should be 0; Open vSwitch
371  *     may enforce this someday), as is the corresponding bit in the field's
372  *     value.  (The sense of the nxm_mask bits is the opposite of that used by
373  *     the "wildcards" member of struct ofp10_match.)
374  *
375  *     When nxm_hasmask is 1, nxm_length is always even.
376  *
377  *     An all-zero-bits nxm_mask is equivalent to omitting the nxm_entry
378  *     entirely.  An all-one-bits nxm_mask is equivalent to specifying 0 for
379  *     nxm_hasmask.
380  *
381  * When there are multiple "nxm_entry"s, all of the constraints must be met.
382  *
383  *
384  * Mask Restrictions
385  * =================
386  *
387  * Masks may be restricted:
388  *
389  *   - Some nxm_types may not support masked wildcards, that is, nxm_hasmask
390  *     must always be 0 when these fields are specified.  For example, the
391  *     field that identifies the port on which a packet was received may not be
392  *     masked.
393  *
394  *   - Some nxm_types that do support masked wildcards may only support certain
395  *     nxm_mask patterns.  For example, fields that have IPv4 address values
396  *     may be restricted to CIDR masks.
397  *
398  * These restrictions should be noted in specifications for individual fields.
399  * A switch may accept an nxm_hasmask or nxm_mask value that the specification
400  * disallows, if the switch correctly implements support for that nxm_hasmask
401  * or nxm_mask value.  A switch must reject an attempt to set up a flow that
402  * contains a nxm_hasmask or nxm_mask value that it does not support.
403  *
404  *
405  * Prerequisite Restrictions
406  * =========================
407  *
408  * The presence of an nxm_entry with a given nxm_type may be restricted based
409  * on the presence of or values of other "nxm_entry"s.  For example:
410  *
411  *   - An nxm_entry for nxm_type=NXM_OF_IP_TOS is allowed only if it is
412  *     preceded by another entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
413  *     and nxm_value=0x0800.  That is, matching on the IP source address is
414  *     allowed only if the Ethernet type is explicitly set to IP.
415  *
416  *   - An nxm_entry for nxm_type=NXM_OF_TCP_SRC is allowed only if it is
417  *     preceded by an entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0, and
418  *     nxm_value either 0x0800 or 0x86dd, and another with
419  *     nxm_type=NXM_OF_IP_PROTO, nxm_hasmask=0, nxm_value=6, in that order.
420  *     That is, matching on the TCP source port is allowed only if the Ethernet
421  *     type is IP or IPv6 and the IP protocol is TCP.
422  *
423  * These restrictions should be noted in specifications for individual fields.
424  * A switch may implement relaxed versions of these restrictions.  A switch
425  * must reject an attempt to set up a flow that violates its restrictions.
426  *
427  *
428  * Ordering Restrictions
429  * =====================
430  *
431  * An nxm_entry that has prerequisite restrictions must appear after the
432  * "nxm_entry"s for its prerequisites.  Ordering of "nxm_entry"s within an
433  * nx_match is not otherwise constrained.
434  *
435  * Any given nxm_type may appear in an nx_match at most once.
436  *
437  *
438  * nxm_entry Examples
439  * ==================
440  *
441  * These examples show the format of a single nxm_entry with particular
442  * nxm_hasmask and nxm_length values.  The diagrams are labeled with field
443  * numbers and byte indexes.
444  *
445  *
446  * 8-bit nxm_value, nxm_hasmask=1, nxm_length=2:
447  *
448  *  0          3  4   5
449  * +------------+---+---+
450  * |   header   | v | m |
451  * +------------+---+---+
452  *
453  *
454  * 16-bit nxm_value, nxm_hasmask=0, nxm_length=2:
455  *
456  *  0          3 4    5
457  * +------------+------+
458  * |   header   | value|
459  * +------------+------+
460  *
461  *
462  * 32-bit nxm_value, nxm_hasmask=0, nxm_length=4:
463  *
464  *  0          3 4           7
465  * +------------+-------------+
466  * |   header   |  nxm_value  |
467  * +------------+-------------+
468  *
469  *
470  * 48-bit nxm_value, nxm_hasmask=0, nxm_length=6:
471  *
472  *  0          3 4                9
473  * +------------+------------------+
474  * |   header   |     nxm_value    |
475  * +------------+------------------+
476  *
477  *
478  * 48-bit nxm_value, nxm_hasmask=1, nxm_length=12:
479  *
480  *  0          3 4                9 10              15
481  * +------------+------------------+------------------+
482  * |   header   |     nxm_value    |      nxm_mask    |
483  * +------------+------------------+------------------+
484  *
485  *
486  * Error Reporting
487  * ===============
488  *
489  * A switch should report an error in an nx_match using error type
490  * OFPET_BAD_REQUEST and one of the NXBRC_NXM_* codes.  Ideally the switch
491  * should report a specific error code, if one is assigned for the particular
492  * problem, but NXBRC_NXM_INVALID is also available to report a generic
493  * nx_match error.
494  */
495
496 /* Number of registers allocated NXM field IDs. */
497 #define NXM_NX_MAX_REGS 16
498
499 /* Bits in the value of NXM_NX_IP_FRAG. */
500 #define NX_IP_FRAG_ANY   (1 << 0) /* Is this a fragment? */
501 #define NX_IP_FRAG_LATER (1 << 1) /* Is this a fragment with nonzero offset? */
502
503 /* Bits in the value of NXM_NX_TUN_FLAGS. */
504 #define NX_TUN_FLAG_OAM  (1 << 0) /* Is this an OAM packet? */
505
506 /* ## --------------------- ## */
507 /* ## Requests and replies. ## */
508 /* ## --------------------- ## */
509
510 enum nx_flow_format {
511     NXFF_OPENFLOW10 = 0,         /* Standard OpenFlow 1.0 compatible. */
512     NXFF_NXM = 2                 /* Nicira extended match. */
513 };
514
515 /* NXT_SET_FLOW_FORMAT request. */
516 struct nx_set_flow_format {
517     ovs_be32 format;            /* One of NXFF_*. */
518 };
519 OFP_ASSERT(sizeof(struct nx_set_flow_format) == 4);
520
521 /* NXT_FLOW_MOD (analogous to OFPT_FLOW_MOD).
522  *
523  * It is possible to limit flow deletions and modifications to certain
524  * cookies by using the NXM_NX_COOKIE(_W) matches.  The "cookie" field
525  * is used only to add or modify flow cookies.
526  */
527 struct nx_flow_mod {
528     ovs_be64 cookie;              /* Opaque controller-issued identifier. */
529     ovs_be16 command;             /* OFPFC_* + possibly a table ID (see comment
530                                    * on struct nx_flow_mod_table_id). */
531     ovs_be16 idle_timeout;        /* Idle time before discarding (seconds). */
532     ovs_be16 hard_timeout;        /* Max time before discarding (seconds). */
533     ovs_be16 priority;            /* Priority level of flow entry. */
534     ovs_be32 buffer_id;           /* Buffered packet to apply to (or -1).
535                                      Not meaningful for OFPFC_DELETE*. */
536     ovs_be16 out_port;            /* For OFPFC_DELETE* commands, require
537                                      matching entries to include this as an
538                                      output port.  A value of OFPP_NONE
539                                      indicates no restriction. */
540     ovs_be16 flags;               /* One of OFPFF_*. */
541     ovs_be16 match_len;           /* Size of nx_match. */
542     uint8_t pad[6];               /* Align to 64-bits. */
543     /* Followed by:
544      *   - Exactly match_len (possibly 0) bytes containing the nx_match, then
545      *   - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
546      *     all-zero bytes, then
547      *   - Actions to fill out the remainder of the message length (always a
548      *     multiple of 8).
549      */
550 };
551 OFP_ASSERT(sizeof(struct nx_flow_mod) == 32);
552
553 /* NXT_FLOW_REMOVED (analogous to OFPT_FLOW_REMOVED).
554  *
555  * 'table_id' is present only in Open vSwitch 1.11 and later.  In earlier
556  * versions of Open vSwitch, this is a padding byte that is always zeroed.
557  * Therefore, a 'table_id' value of 0 indicates that the table ID is not known,
558  * and other values may be interpreted as one more than the flow's former table
559  * ID. */
560 struct nx_flow_removed {
561     ovs_be64 cookie;          /* Opaque controller-issued identifier. */
562     ovs_be16 priority;        /* Priority level of flow entry. */
563     uint8_t reason;           /* One of OFPRR_*. */
564     uint8_t table_id;         /* Flow's former table ID, plus one. */
565     ovs_be32 duration_sec;    /* Time flow was alive in seconds. */
566     ovs_be32 duration_nsec;   /* Time flow was alive in nanoseconds beyond
567                                  duration_sec. */
568     ovs_be16 idle_timeout;    /* Idle timeout from original flow mod. */
569     ovs_be16 match_len;       /* Size of nx_match. */
570     ovs_be64 packet_count;
571     ovs_be64 byte_count;
572     /* Followed by:
573      *   - Exactly match_len (possibly 0) bytes containing the nx_match, then
574      *   - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
575      *     all-zero bytes. */
576 };
577 OFP_ASSERT(sizeof(struct nx_flow_removed) == 40);
578
579 /* Nicira vendor stats request of type NXST_FLOW (analogous to OFPST_FLOW
580  * request).
581  *
582  * It is possible to limit matches to certain cookies by using the
583  * NXM_NX_COOKIE and NXM_NX_COOKIE_W matches.
584  */
585 struct nx_flow_stats_request {
586     ovs_be16 out_port;        /* Require matching entries to include this
587                                  as an output port.  A value of OFPP_NONE
588                                  indicates no restriction. */
589     ovs_be16 match_len;       /* Length of nx_match. */
590     uint8_t table_id;         /* ID of table to read (from ofp_table_stats)
591                                  or 0xff for all tables. */
592     uint8_t pad[3];           /* Align to 64 bits. */
593     /* Followed by:
594      *   - Exactly match_len (possibly 0) bytes containing the nx_match, then
595      *   - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
596      *     all-zero bytes, which must also exactly fill out the length of the
597      *     message.
598      */
599 };
600 OFP_ASSERT(sizeof(struct nx_flow_stats_request) == 8);
601
602 /* Body for Nicira vendor stats reply of type NXST_FLOW (analogous to
603  * OFPST_FLOW reply).
604  *
605  * The values of 'idle_age' and 'hard_age' are only meaningful when talking to
606  * a switch that implements the NXT_FLOW_AGE extension.  Zero means that the
607  * true value is unknown, perhaps because hardware does not track the value.
608  * (Zero is also the value that one should ordinarily expect to see talking to
609  * a switch that does not implement NXT_FLOW_AGE, since those switches zero the
610  * padding bytes that these fields replaced.)  A nonzero value X represents X-1
611  * seconds.  A value of 65535 represents 65534 or more seconds.
612  *
613  * 'idle_age' is the number of seconds that the flow has been idle, that is,
614  * the number of seconds since a packet passed through the flow.  'hard_age' is
615  * the number of seconds since the flow was last modified (e.g. OFPFC_MODIFY or
616  * OFPFC_MODIFY_STRICT).  (The 'duration_*' fields are the elapsed time since
617  * the flow was added, regardless of subsequent modifications.)
618  *
619  * For a flow with an idle or hard timeout, 'idle_age' or 'hard_age',
620  * respectively, will ordinarily be smaller than the timeout, but flow
621  * expiration times are only approximate and so one must be prepared to
622  * tolerate expirations that occur somewhat early or late.
623  */
624 struct nx_flow_stats {
625     ovs_be16 length;          /* Length of this entry. */
626     uint8_t table_id;         /* ID of table flow came from. */
627     uint8_t pad;
628     ovs_be32 duration_sec;    /* Time flow has been alive in seconds. */
629     ovs_be32 duration_nsec;   /* Time flow has been alive in nanoseconds
630                                  beyond duration_sec. */
631     ovs_be16 priority;        /* Priority of the entry. */
632     ovs_be16 idle_timeout;    /* Number of seconds idle before expiration. */
633     ovs_be16 hard_timeout;    /* Number of seconds before expiration. */
634     ovs_be16 match_len;       /* Length of nx_match. */
635     ovs_be16 idle_age;        /* Seconds since last packet, plus one. */
636     ovs_be16 hard_age;        /* Seconds since last modification, plus one. */
637     ovs_be64 cookie;          /* Opaque controller-issued identifier. */
638     ovs_be64 packet_count;    /* Number of packets, UINT64_MAX if unknown. */
639     ovs_be64 byte_count;      /* Number of bytes, UINT64_MAX if unknown. */
640     /* Followed by:
641      *   - Exactly match_len (possibly 0) bytes containing the nx_match, then
642      *   - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
643      *     all-zero bytes, then
644      *   - Actions to fill out the remainder 'length' bytes (always a multiple
645      *     of 8).
646      */
647 };
648 OFP_ASSERT(sizeof(struct nx_flow_stats) == 48);
649
650 /* Nicira vendor stats request of type NXST_AGGREGATE (analogous to
651  * OFPST_AGGREGATE request).
652  *
653  * The reply format is identical to the reply format for OFPST_AGGREGATE,
654  * except for the header. */
655 struct nx_aggregate_stats_request {
656     ovs_be16 out_port;        /* Require matching entries to include this
657                                  as an output port.  A value of OFPP_NONE
658                                  indicates no restriction. */
659     ovs_be16 match_len;       /* Length of nx_match. */
660     uint8_t table_id;         /* ID of table to read (from ofp_table_stats)
661                                  or 0xff for all tables. */
662     uint8_t pad[3];           /* Align to 64 bits. */
663     /* Followed by:
664      *   - Exactly match_len (possibly 0) bytes containing the nx_match, then
665      *   - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
666      *     all-zero bytes, which must also exactly fill out the length of the
667      *     message.
668      */
669 };
670 OFP_ASSERT(sizeof(struct nx_aggregate_stats_request) == 8);
671 \f
672 /* NXT_SET_CONTROLLER_ID.
673  *
674  * Each OpenFlow controller connection has a 16-bit identifier that is
675  * initially 0.  This message changes the connection's ID to 'id'.
676  *
677  * Controller connection IDs need not be unique.
678  *
679  * The NXAST_CONTROLLER action is the only current user of controller
680  * connection IDs. */
681 struct nx_controller_id {
682     uint8_t zero[6];            /* Must be zero. */
683     ovs_be16 controller_id;     /* New controller connection ID. */
684 };
685 OFP_ASSERT(sizeof(struct nx_controller_id) == 8);
686 \f
687 /* Flow Table Monitoring
688  * =====================
689  *
690  * NXST_FLOW_MONITOR allows a controller to keep track of changes to OpenFlow
691  * flow table(s) or subsets of them, with the following workflow:
692  *
693  * 1. The controller sends an NXST_FLOW_MONITOR request to begin monitoring
694  *    flows.  The 'id' in the request must be unique among all monitors that
695  *    the controller has started and not yet canceled on this OpenFlow
696  *    connection.
697  *
698  * 2. The switch responds with an NXST_FLOW_MONITOR reply.  If the request's
699  *    'flags' included NXFMF_INITIAL, the reply includes all the flows that
700  *    matched the request at the time of the request (with event NXFME_ADDED).
701  *    If 'flags' did not include NXFMF_INITIAL, the reply is empty.
702  *
703  *    The reply uses the xid of the request (as do all replies to OpenFlow
704  *    requests).
705  *
706  * 3. Whenever a change to a flow table entry matches some outstanding monitor
707  *    request's criteria and flags, the switch sends a notification to the
708  *    controller as an additional NXST_FLOW_MONITOR reply with xid 0.
709  *
710  *    When multiple outstanding monitors match a single change, only a single
711  *    notification is sent.  This merged notification includes the information
712  *    requested in any of the individual monitors.  That is, if any of the
713  *    matching monitors requests actions (NXFMF_ACTIONS), the notification
714  *    includes actions, and if any of the monitors request full changes for the
715  *    controller's own changes (NXFMF_OWN), the controller's own changes will
716  *    be included in full.
717  *
718  * 4. The controller may cancel a monitor with NXT_FLOW_MONITOR_CANCEL.  No
719  *    further notifications will be sent on the basis of the canceled monitor
720  *    afterward.
721  *
722  *
723  * Buffer Management
724  * =================
725  *
726  * OpenFlow messages for flow monitor notifications can overflow the buffer
727  * space available to the switch, either temporarily (e.g. due to network
728  * conditions slowing OpenFlow traffic) or more permanently (e.g. the sustained
729  * rate of flow table change exceeds the network bandwidth between switch and
730  * controller).
731  *
732  * When Open vSwitch's notification buffer space reaches a limiting threshold,
733  * OVS reacts as follows:
734  *
735  * 1. OVS sends an NXT_FLOW_MONITOR_PAUSED message to the controller, following
736  *    all the already queued notifications.  After it receives this message,
737  *    the controller knows that its view of the flow table, as represented by
738  *    flow monitor notifications, is incomplete.
739  *
740  * 2. As long as the notification buffer is not empty:
741  *
742  *        - NXMFE_ADD and NXFME_MODIFIED notifications will not be sent.
743  *
744  *        - NXFME_DELETED notifications will still be sent, but only for flows
745  *          that existed before OVS sent NXT_FLOW_MONITOR_PAUSED.
746  *
747  *        - NXFME_ABBREV notifications will not be sent.  They are treated as
748  *          the expanded version (and therefore only the NXFME_DELETED
749  *          components, if any, are sent).
750  *
751  * 3. When the notification buffer empties, OVS sends NXFME_ADD notifications
752  *    for flows added since the buffer reached its limit and NXFME_MODIFIED
753  *    notifications for flows that existed before the limit was reached and
754  *    changed after the limit was reached.
755  *
756  * 4. OVS sends an NXT_FLOW_MONITOR_RESUMED message to the controller.  After
757  *    it receives this message, the controller knows that its view of the flow
758  *    table, as represented by flow monitor notifications, is again complete.
759  *
760  * This allows the maximum buffer space requirement for notifications to be
761  * bounded by the limit plus the maximum number of supported flows.
762  *
763  *
764  * "Flow Removed" messages
765  * =======================
766  *
767  * The flow monitor mechanism is independent of OFPT_FLOW_REMOVED and
768  * NXT_FLOW_REMOVED.  Flow monitor updates for deletion are sent if
769  * NXFMF_DELETE is set on a monitor, regardless of whether the
770  * OFPFF_SEND_FLOW_REM flag was set when the flow was added. */
771
772 /* NXST_FLOW_MONITOR request.
773  *
774  * The NXST_FLOW_MONITOR request's body consists of an array of zero or more
775  * instances of this structure.  The request arranges to monitor the flows
776  * that match the specified criteria, which are interpreted in the same way as
777  * for NXST_FLOW.
778  *
779  * 'id' identifies a particular monitor for the purpose of allowing it to be
780  * canceled later with NXT_FLOW_MONITOR_CANCEL.  'id' must be unique among
781  * existing monitors that have not already been canceled.
782  *
783  * The reply includes the initial flow matches for monitors that have the
784  * NXFMF_INITIAL flag set.  No single flow will be included in the reply more
785  * than once, even if more than one requested monitor matches that flow.  The
786  * reply will be empty if none of the monitors has NXFMF_INITIAL set or if none
787  * of the monitors initially matches any flows.
788  *
789  * For NXFMF_ADD, an event will be reported if 'out_port' matches against the
790  * actions of the flow being added or, for a flow that is replacing an existing
791  * flow, if 'out_port' matches against the actions of the flow being replaced.
792  * For NXFMF_DELETE, 'out_port' matches against the actions of a flow being
793  * deleted.  For NXFMF_MODIFY, an event will be reported if 'out_port' matches
794  * either the old or the new actions. */
795 struct nx_flow_monitor_request {
796     ovs_be32 id;                /* Controller-assigned ID for this monitor. */
797     ovs_be16 flags;             /* NXFMF_*. */
798     ovs_be16 out_port;          /* Required output port, if not OFPP_NONE. */
799     ovs_be16 match_len;         /* Length of nx_match. */
800     uint8_t table_id;           /* One table's ID or 0xff for all tables. */
801     uint8_t zeros[5];           /* Align to 64 bits (must be zero). */
802     /* Followed by:
803      *   - Exactly match_len (possibly 0) bytes containing the nx_match, then
804      *   - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
805      *     all-zero bytes. */
806 };
807 OFP_ASSERT(sizeof(struct nx_flow_monitor_request) == 16);
808
809 /* 'flags' bits in struct nx_flow_monitor_request. */
810 enum nx_flow_monitor_flags {
811     /* When to send updates. */
812     NXFMF_INITIAL = 1 << 0,     /* Initially matching flows. */
813     NXFMF_ADD = 1 << 1,         /* New matching flows as they are added. */
814     NXFMF_DELETE = 1 << 2,      /* Old matching flows as they are removed. */
815     NXFMF_MODIFY = 1 << 3,      /* Matching flows as they are changed. */
816
817     /* What to include in updates. */
818     NXFMF_ACTIONS = 1 << 4,     /* If set, actions are included. */
819     NXFMF_OWN = 1 << 5,         /* If set, include own changes in full. */
820 };
821
822 /* NXST_FLOW_MONITOR reply header.
823  *
824  * The body of an NXST_FLOW_MONITOR reply is an array of variable-length
825  * structures, each of which begins with this header.  The 'length' member may
826  * be used to traverse the array, and the 'event' member may be used to
827  * determine the particular structure.
828  *
829  * Every instance is a multiple of 8 bytes long. */
830 struct nx_flow_update_header {
831     ovs_be16 length;            /* Length of this entry. */
832     ovs_be16 event;             /* One of NXFME_*. */
833     /* ...other data depending on 'event'... */
834 };
835 OFP_ASSERT(sizeof(struct nx_flow_update_header) == 4);
836
837 /* 'event' values in struct nx_flow_update_header. */
838 enum nx_flow_update_event {
839     /* struct nx_flow_update_full. */
840     NXFME_ADDED = 0,            /* Flow was added. */
841     NXFME_DELETED = 1,          /* Flow was deleted. */
842     NXFME_MODIFIED = 2,         /* Flow (generally its actions) was changed. */
843
844     /* struct nx_flow_update_abbrev. */
845     NXFME_ABBREV = 3,           /* Abbreviated reply. */
846 };
847
848 /* NXST_FLOW_MONITOR reply for NXFME_ADDED, NXFME_DELETED, and
849  * NXFME_MODIFIED. */
850 struct nx_flow_update_full {
851     ovs_be16 length;            /* Length is 24. */
852     ovs_be16 event;             /* One of NXFME_*. */
853     ovs_be16 reason;            /* OFPRR_* for NXFME_DELETED, else zero. */
854     ovs_be16 priority;          /* Priority of the entry. */
855     ovs_be16 idle_timeout;      /* Number of seconds idle before expiration. */
856     ovs_be16 hard_timeout;      /* Number of seconds before expiration. */
857     ovs_be16 match_len;         /* Length of nx_match. */
858     uint8_t table_id;           /* ID of flow's table. */
859     uint8_t pad;                /* Reserved, currently zeroed. */
860     ovs_be64 cookie;            /* Opaque controller-issued identifier. */
861     /* Followed by:
862      *   - Exactly match_len (possibly 0) bytes containing the nx_match, then
863      *   - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
864      *     all-zero bytes, then
865      *   - Actions to fill out the remainder 'length' bytes (always a multiple
866      *     of 8).  If NXFMF_ACTIONS was not specified, or 'event' is
867      *     NXFME_DELETED, no actions are included.
868      */
869 };
870 OFP_ASSERT(sizeof(struct nx_flow_update_full) == 24);
871
872 /* NXST_FLOW_MONITOR reply for NXFME_ABBREV.
873  *
874  * When the controller does not specify NXFMF_OWN in a monitor request, any
875  * flow tables changes due to the controller's own requests (on the same
876  * OpenFlow channel) will be abbreviated, when possible, to this form, which
877  * simply specifies the 'xid' of the OpenFlow request (e.g. an OFPT_FLOW_MOD or
878  * NXT_FLOW_MOD) that caused the change.
879  *
880  * Some changes cannot be abbreviated and will be sent in full:
881  *
882  *   - Changes that only partially succeed.  This can happen if, for example,
883  *     a flow_mod with type OFPFC_MODIFY affects multiple flows, but only some
884  *     of those modifications succeed (e.g. due to hardware limitations).
885  *
886  *     This cannot occur with the Open vSwitch software datapath.  This also
887  *     cannot occur in Open vSwitch 2.4 and later, because these versions only
888  *     execute any flow modifications if all of them will succeed.
889  *
890  *   - Changes that race with conflicting changes made by other controllers or
891  *     other flow_mods (not separated by barriers) by the same controller.
892  *
893  *     This cannot occur with the current Open vSwitch implementation
894  *     (regardless of datapath) because Open vSwitch internally serializes
895  *     potentially conflicting changes.
896  *
897  *   - Changes that occur when flow notification is paused (see "Buffer
898  *     Management" above).
899  *
900  * A flow_mod that does not change the flow table will not trigger any
901  * notification, even an abbreviated one.  For example, a "modify" or "delete"
902  * flow_mod that does not match any flows will not trigger a notification.
903  * Whether an "add" or "modify" that specifies all the same parameters that a
904  * flow already has triggers a notification is unspecified and subject to
905  * change in future versions of Open vSwitch.
906  *
907  * OVS will always send the notifications for a given flow table change before
908  * the reply to a OFPT_BARRIER_REQUEST request that follows the flow table
909  * change.  Thus, if the controller does not receive an abbreviated (or
910  * unabbreviated) notification for a flow_mod before the next
911  * OFPT_BARRIER_REPLY, it will never receive one. */
912 struct nx_flow_update_abbrev {
913     ovs_be16 length;            /* Length is 8. */
914     ovs_be16 event;             /* NXFME_ABBREV. */
915     ovs_be32 xid;               /* Controller-specified xid from flow_mod. */
916 };
917 OFP_ASSERT(sizeof(struct nx_flow_update_abbrev) == 8);
918
919 /* NXT_FLOW_MONITOR_CANCEL.
920  *
921  * Used by a controller to cancel an outstanding monitor. */
922 struct nx_flow_monitor_cancel {
923     ovs_be32 id;                /* 'id' from nx_flow_monitor_request. */
924 };
925 OFP_ASSERT(sizeof(struct nx_flow_monitor_cancel) == 4);
926
927 /* Geneve option table maintenance commands.
928  *
929  * In order to work with Geneve options, we need to maintain a mapping
930  * table between an option (defined by <class, type, length>) and
931  * an NXM field that can be operated on for the purposes of matches,
932  * actions, etc. This mapping must be explicitly specified by the
933  * user.
934  *
935  * There are two primary groups of OpenFlow messages that are introduced
936  * as Nicira extensions: modification commands (add, delete, clear mappings)
937  * and table status request/reply to dump the current table along with switch
938  * information.
939  *
940  * Note that mappings should not be changed while they are in active use by
941  * a flow. The result of doing so is undefined. */
942
943 /* Geneve table commands */
944 enum nx_geneve_table_mod_command {
945     NXGTMC_ADD,          /* New mappings (fails if an option is already
946                             mapped). */
947     NXGTMC_DELETE,       /* Delete mappings, identified by index
948                           * (unmapped options are ignored). */
949     NXGTMC_CLEAR,        /* Clear all mappings. Additional information
950                             in this command is ignored. */
951 };
952
953 /* Map between a Geneve option and an NXM field. */
954 struct nx_geneve_map {
955     ovs_be16 option_class; /* Geneve option class. */
956     uint8_t  option_type;  /* Geneve option type. */
957     uint8_t  option_len;   /* Geneve option length (multiple of 4). */
958     ovs_be16 index;        /* NXM_NX_TUN_METADATA<n> index */
959     uint8_t  pad[2];
960 };
961 OFP_ASSERT(sizeof(struct nx_geneve_map) == 8);
962
963 /* NXT_GENEVE_TABLE_MOD.
964  *
965  * Use to configure a mapping between Geneve options (class, type, length)
966  * and NXM fields (NXM_NX_TUN_METADATA<n> where 'index' is <n>).
967  *
968  * This command is atomic: all operations on different options will
969  * either succeed or fail. */
970 struct nx_geneve_table_mod {
971     ovs_be16 command;           /* One of NTGTMC_* */
972     uint8_t pad[6];
973     /* struct nx_geneve_map[0]; Array of maps between indicies and Geneve
974                                 options. The number of elements is
975                                 inferred from the length field in the
976                                 header. */
977 };
978 OFP_ASSERT(sizeof(struct nx_geneve_table_mod) == 8);
979
980 /* NXT_GENEVE_TABLE_REPLY.
981  *
982  * Issued in reponse to an NXT_GENEVE_TABLE_REQUEST to give information
983  * about the current status of the Geneve table in the switch. Provides
984  * both static information about the switch's capabilities as well as
985  * the configured Geneve option table. */
986 struct nx_geneve_table_reply {
987     ovs_be32 max_option_space; /* Maximum total of option sizes supported. */
988     ovs_be16 max_fields;       /* Maximum number of match fields supported. */
989     uint8_t pad[2];
990     /* struct nx_geneve_map[0]; Array of maps between indicies and Geneve
991                                 options. The number of elements is
992                                 inferred from the length field in the
993                                 header. */
994 };
995 OFP_ASSERT(sizeof(struct nx_geneve_table_reply) == 8);
996
997 #endif /* openflow/nicira-ext.h */