2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef OPENFLOW_NICIRA_EXT_H
18 #define OPENFLOW_NICIRA_EXT_H 1
20 #include "openflow/openflow.h"
21 #include "openvswitch/types.h"
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. */
28 /* Nicira vendor-specific error messages extension.
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.
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
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.
48 * Currently this extension is only implemented by Open vSwitch, but it seems
49 * like a reasonable candidate for future standardization.
52 /* This is a random number to avoid accidental collision with any other
53 * vendor's extension. */
54 #define NXET_VENDOR 0xb0c2
56 /* ofp_error msg 'code' values for NXET_VENDOR. */
58 NXVC_VENDOR_ERROR /* 'data' contains struct nx_vendor_error. */
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. */
69 /* Nicira vendor requests and replies. */
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. */
77 OFP_ASSERT(sizeof(struct nicira_header) == 16);
79 /* Header for Nicira vendor stats request and reply messages in OpenFlow
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. */
86 OFP_ASSERT(sizeof(struct nicira10_stats_msg) == 24);
88 /* Header for Nicira vendor stats request and reply messages in OpenFlow
90 struct nicira11_stats_msg {
91 struct ofp11_vendor_stats_msg vsm; /* Vendor NX_VENDOR_ID. */
92 ovs_be32 subtype; /* One of NXST_* below. */
94 OFP_ASSERT(sizeof(struct nicira11_stats_msg) == 24);
96 /* Fields to use when hashing flows. */
98 /* Ethernet source address (NXM_OF_ETH_SRC) only. */
99 NX_HASH_FIELDS_ETH_SRC,
101 /* L2 through L4, symmetric across src/dst. Specifically, each of the
102 * following fields, if present, is hashed (slashes separate symmetric
105 * - NXM_OF_ETH_DST / NXM_OF_ETH_SRC
107 * - The VID bits from NXM_OF_VLAN_TCI, ignoring PCP and CFI.
109 * - NXM_OF_IP_SRC / NXM_OF_IP_DST
110 * - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
112 NX_HASH_FIELDS_SYMMETRIC_L4
115 /* This command enables or disables an Open vSwitch extension that allows a
116 * controller to specify the OpenFlow table to which a flow should be added,
117 * instead of having the switch decide which table is most appropriate as
118 * required by OpenFlow 1.0. Because NXM was designed as an extension to
119 * OpenFlow 1.0, the extension applies equally to ofp10_flow_mod and
120 * nx_flow_mod. By default, the extension is disabled.
122 * When this feature is enabled, Open vSwitch treats struct ofp10_flow_mod's
123 * and struct nx_flow_mod's 16-bit 'command' member as two separate fields.
124 * The upper 8 bits are used as the table ID, the lower 8 bits specify the
125 * command as usual. A table ID of 0xff is treated like a wildcarded table ID.
127 * The specific treatment of the table ID depends on the type of flow mod:
129 * - OFPFC_ADD: Given a specific table ID, the flow is always placed in that
130 * table. If an identical flow already exists in that table only, then it
131 * is replaced. If the flow cannot be placed in the specified table,
132 * either because the table is full or because the table cannot support
133 * flows of the given type, the switch replies with an OFPFMFC_TABLE_FULL
134 * error. (A controller can distinguish these cases by comparing the
135 * current and maximum number of entries reported in ofp_table_stats.)
137 * If the table ID is wildcarded, the switch picks an appropriate table
138 * itself. If an identical flow already exist in the selected flow table,
139 * then it is replaced. The choice of table might depend on the flows
140 * that are already in the switch; for example, if one table fills up then
141 * the switch might fall back to another one.
143 * - OFPFC_MODIFY, OFPFC_DELETE: Given a specific table ID, only flows
144 * within that table are matched and modified or deleted. If the table ID
145 * is wildcarded, flows within any table may be matched and modified or
148 * - OFPFC_MODIFY_STRICT, OFPFC_DELETE_STRICT: Given a specific table ID,
149 * only a flow within that table may be matched and modified or deleted.
150 * If the table ID is wildcarded and exactly one flow within any table
151 * matches, then it is modified or deleted; if flows in more than one
152 * table match, then none is modified or deleted.
154 struct nx_flow_mod_table_id {
155 uint8_t set; /* Nonzero to enable, zero to disable. */
158 OFP_ASSERT(sizeof(struct nx_flow_mod_table_id) == 8);
160 enum nx_packet_in_format {
161 NXPIF_OPENFLOW10 = 0, /* Standard OpenFlow 1.0 compatible. */
162 NXPIF_NXM = 1 /* Nicira Extended. */
165 /* NXT_SET_PACKET_IN_FORMAT request. */
166 struct nx_set_packet_in_format {
167 ovs_be32 format; /* One of NXPIF_*. */
169 OFP_ASSERT(sizeof(struct nx_set_packet_in_format) == 4);
171 /* NXT_PACKET_IN (analogous to OFPT_PACKET_IN).
173 * NXT_PACKET_IN is similar to the OpenFlow 1.2 OFPT_PACKET_IN. The
176 * - NXT_PACKET_IN includes the cookie of the rule that triggered the
177 * message. (OpenFlow 1.3 OFPT_PACKET_IN also includes the cookie.)
179 * - The metadata fields use NXM (instead of OXM) field numbers.
181 * Open vSwitch 1.9.0 and later omits metadata fields that are zero (as allowed
182 * by OpenFlow 1.2). Earlier versions included all implemented metadata
185 * Open vSwitch does not include non-metadata in the nx_match, because by
186 * definition that information can be found in the packet itself. The format
187 * and the standards allow this, however, so controllers should be prepared to
188 * tolerate future changes.
190 * The NXM format is convenient for reporting metadata values, but it is
191 * important not to interpret the format as matching against a flow, because it
192 * does not. Nothing is being matched; arbitrary metadata masks would not be
195 * Whereas in most cases a controller can expect to only get back NXM fields
196 * that it set up itself (e.g. flow dumps will ordinarily report only NXM
197 * fields from flows that the controller added), NXT_PACKET_IN messages might
198 * contain fields that the controller does not understand, because the switch
199 * might support fields (new registers, new protocols, etc.) that the
200 * controller does not. The controller must prepared to tolerate these.
202 * The 'cookie' field has no meaning when 'reason' is OFPR_NO_MATCH. In this
203 * case it should be UINT64_MAX. */
204 struct nx_packet_in {
205 ovs_be32 buffer_id; /* ID assigned by datapath. */
206 ovs_be16 total_len; /* Full length of frame. */
207 uint8_t reason; /* Reason packet is sent (one of OFPR_*). */
208 uint8_t table_id; /* ID of the table that was looked up. */
209 ovs_be64 cookie; /* Cookie of the rule that was looked up. */
210 ovs_be16 match_len; /* Size of nx_match. */
211 uint8_t pad[6]; /* Align to 64-bits. */
213 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
214 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
215 * all-zero bytes, then
216 * - Exactly 2 all-zero padding bytes, then
217 * - An Ethernet frame whose length is inferred from nxh.header.length.
219 * The padding bytes preceding the Ethernet frame ensure that the IP
220 * header (if any) following the Ethernet header is 32-bit aligned. */
222 /* uint8_t nxm_fields[...]; */ /* NXM headers. */
223 /* uint8_t pad[2]; */ /* Align to 64 bit + 16 bit. */
224 /* uint8_t data[0]; */ /* Ethernet frame. */
226 OFP_ASSERT(sizeof(struct nx_packet_in) == 24);
228 /* Configures the "role" of the sending controller. The default role is:
230 * - Other (NX_ROLE_OTHER), which allows the controller access to all
233 * The other possible roles are a related pair:
235 * - Master (NX_ROLE_MASTER) is equivalent to Other, except that there may
236 * be at most one Master controller at a time: when a controller
237 * configures itself as Master, any existing Master is demoted to the
240 * - Slave (NX_ROLE_SLAVE) allows the controller read-only access to
241 * OpenFlow features. In particular attempts to modify the flow table
242 * will be rejected with an OFPBRC_EPERM error.
244 * Slave controllers do not receive OFPT_PACKET_IN or OFPT_FLOW_REMOVED
245 * messages, but they do receive OFPT_PORT_STATUS messages.
247 struct nx_role_request {
248 ovs_be32 role; /* One of NX_ROLE_*. */
250 OFP_ASSERT(sizeof(struct nx_role_request) == 4);
253 NX_ROLE_OTHER, /* Default role, full access. */
254 NX_ROLE_MASTER, /* Full access, at most one. */
255 NX_ROLE_SLAVE /* Read-only access. */
258 /* NXT_SET_ASYNC_CONFIG.
260 * Sent by a controller, this message configures the asynchronous messages that
261 * the controller wants to receive. Element 0 in each array specifies messages
262 * of interest when the controller has an "other" or "master" role; element 1,
263 * when the controller has a "slave" role.
265 * Each array element is a bitmask in which a 0-bit disables receiving a
266 * particular message and a 1-bit enables receiving it. Each bit controls the
267 * message whose 'reason' corresponds to the bit index. For example, the bit
268 * with value 1<<2 == 4 in port_status_mask[1] determines whether the
269 * controller will receive OFPT_PORT_STATUS messages with reason OFPPR_MODIFY
270 * (value 2) when the controller has a "slave" role.
272 * As a side effect, for service controllers, this message changes the
273 * miss_send_len from default of zero to OFP_DEFAULT_MISS_SEND_LEN (128).
275 struct nx_async_config {
276 ovs_be32 packet_in_mask[2]; /* Bitmasks of OFPR_* values. */
277 ovs_be32 port_status_mask[2]; /* Bitmasks of OFPRR_* values. */
278 ovs_be32 flow_removed_mask[2]; /* Bitmasks of OFPPR_* values. */
280 OFP_ASSERT(sizeof(struct nx_async_config) == 24);
282 /* Flexible flow specifications (aka NXM = Nicira Extended Match).
284 * OpenFlow 1.0 has "struct ofp10_match" for specifying flow matches. This
285 * structure is fixed-length and hence difficult to extend. This section
286 * describes a more flexible, variable-length flow match, called "nx_match" for
287 * short, that is also supported by Open vSwitch. This section also defines a
288 * replacement for each OpenFlow message that includes struct ofp10_match.
294 * An nx_match is a sequence of zero or more "nxm_entry"s, which are
295 * type-length-value (TLV) entries, each 5 to 259 (inclusive) bytes long.
296 * "nxm_entry"s are not aligned on or padded to any multibyte boundary. The
297 * first 4 bytes of an nxm_entry are its "header", followed by the entry's
300 * An nxm_entry's header is interpreted as a 32-bit word in network byte order:
302 * |<-------------------- nxm_type ------------------>|
305 * +----------------------------------+---------------+--+------------------+
306 * | nxm_vendor | nxm_field |hm| nxm_length |
307 * +----------------------------------+---------------+--+------------------+
309 * The most-significant 23 bits of the header are collectively "nxm_type".
310 * Bits 16...31 are "nxm_vendor", one of the NXM_VENDOR_* values below. Bits
311 * 9...15 are "nxm_field", which is a vendor-specific value. nxm_type normally
312 * designates a protocol header, such as the Ethernet type, but it can also
313 * refer to packet metadata, such as the switch port on which a packet arrived.
315 * Bit 8 is "nxm_hasmask" (labeled "hm" above for space reasons). The meaning
316 * of this bit is explained later.
318 * The least-significant 8 bits are "nxm_length", a positive integer. The
319 * length of the nxm_entry, including the header, is exactly 4 + nxm_length
322 * For a given nxm_vendor, nxm_field, and nxm_hasmask value, nxm_length is a
323 * constant. It is included only to allow software to minimally parse
324 * "nxm_entry"s of unknown types. (Similarly, for a given nxm_vendor,
325 * nxm_field, and nxm_length, nxm_hasmask is a constant.)
331 * A zero-length nx_match (one with no "nxm_entry"s) matches every packet.
333 * An nxm_entry places a constraint on the packets matched by the nx_match:
335 * - If nxm_hasmask is 0, the nxm_entry's body contains a value for the
336 * field, called "nxm_value". The nx_match matches only packets in which
337 * the field equals nxm_value.
339 * - If nxm_hasmask is 1, then the nxm_entry's body contains a value for the
340 * field (nxm_value), followed by a bitmask of the same length as the
341 * value, called "nxm_mask". For each 1-bit in position J in nxm_mask, the
342 * nx_match matches only packets for which bit J in the given field's value
343 * matches bit J in nxm_value. A 0-bit in nxm_mask causes the
344 * corresponding bit in nxm_value is ignored (it should be 0; Open vSwitch
345 * may enforce this someday), as is the corresponding bit in the field's
346 * value. (The sense of the nxm_mask bits is the opposite of that used by
347 * the "wildcards" member of struct ofp10_match.)
349 * When nxm_hasmask is 1, nxm_length is always even.
351 * An all-zero-bits nxm_mask is equivalent to omitting the nxm_entry
352 * entirely. An all-one-bits nxm_mask is equivalent to specifying 0 for
355 * When there are multiple "nxm_entry"s, all of the constraints must be met.
361 * Masks may be restricted:
363 * - Some nxm_types may not support masked wildcards, that is, nxm_hasmask
364 * must always be 0 when these fields are specified. For example, the
365 * field that identifies the port on which a packet was received may not be
368 * - Some nxm_types that do support masked wildcards may only support certain
369 * nxm_mask patterns. For example, fields that have IPv4 address values
370 * may be restricted to CIDR masks.
372 * These restrictions should be noted in specifications for individual fields.
373 * A switch may accept an nxm_hasmask or nxm_mask value that the specification
374 * disallows, if the switch correctly implements support for that nxm_hasmask
375 * or nxm_mask value. A switch must reject an attempt to set up a flow that
376 * contains a nxm_hasmask or nxm_mask value that it does not support.
379 * Prerequisite Restrictions
380 * =========================
382 * The presence of an nxm_entry with a given nxm_type may be restricted based
383 * on the presence of or values of other "nxm_entry"s. For example:
385 * - An nxm_entry for nxm_type=NXM_OF_IP_TOS is allowed only if it is
386 * preceded by another entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
387 * and nxm_value=0x0800. That is, matching on the IP source address is
388 * allowed only if the Ethernet type is explicitly set to IP.
390 * - An nxm_entry for nxm_type=NXM_OF_TCP_SRC is allowed only if it is
391 * preceded by an entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0, and
392 * nxm_value either 0x0800 or 0x86dd, and another with
393 * nxm_type=NXM_OF_IP_PROTO, nxm_hasmask=0, nxm_value=6, in that order.
394 * That is, matching on the TCP source port is allowed only if the Ethernet
395 * type is IP or IPv6 and the IP protocol is TCP.
397 * These restrictions should be noted in specifications for individual fields.
398 * A switch may implement relaxed versions of these restrictions. A switch
399 * must reject an attempt to set up a flow that violates its restrictions.
402 * Ordering Restrictions
403 * =====================
405 * An nxm_entry that has prerequisite restrictions must appear after the
406 * "nxm_entry"s for its prerequisites. Ordering of "nxm_entry"s within an
407 * nx_match is not otherwise constrained.
409 * Any given nxm_type may appear in an nx_match at most once.
415 * These examples show the format of a single nxm_entry with particular
416 * nxm_hasmask and nxm_length values. The diagrams are labeled with field
417 * numbers and byte indexes.
420 * 8-bit nxm_value, nxm_hasmask=1, nxm_length=2:
423 * +------------+---+---+
425 * +------------+---+---+
428 * 16-bit nxm_value, nxm_hasmask=0, nxm_length=2:
431 * +------------+------+
433 * +------------+------+
436 * 32-bit nxm_value, nxm_hasmask=0, nxm_length=4:
439 * +------------+-------------+
440 * | header | nxm_value |
441 * +------------+-------------+
444 * 48-bit nxm_value, nxm_hasmask=0, nxm_length=6:
447 * +------------+------------------+
448 * | header | nxm_value |
449 * +------------+------------------+
452 * 48-bit nxm_value, nxm_hasmask=1, nxm_length=12:
455 * +------------+------------------+------------------+
456 * | header | nxm_value | nxm_mask |
457 * +------------+------------------+------------------+
463 * A switch should report an error in an nx_match using error type
464 * OFPET_BAD_REQUEST and one of the NXBRC_NXM_* codes. Ideally the switch
465 * should report a specific error code, if one is assigned for the particular
466 * problem, but NXBRC_NXM_INVALID is also available to report a generic
470 #define NXM_HEADER__(VENDOR, FIELD, HASMASK, LENGTH) \
471 (((VENDOR) << 16) | ((FIELD) << 9) | ((HASMASK) << 8) | (LENGTH))
472 #define NXM_HEADER(VENDOR, FIELD, LENGTH) \
473 NXM_HEADER__(VENDOR, FIELD, 0, LENGTH)
474 #define NXM_HEADER_W(VENDOR, FIELD, LENGTH) \
475 NXM_HEADER__(VENDOR, FIELD, 1, (LENGTH) * 2)
476 #define NXM_VENDOR(HEADER) ((HEADER) >> 16)
477 #define NXM_FIELD(HEADER) (((HEADER) >> 9) & 0x7f)
478 #define NXM_TYPE(HEADER) (((HEADER) >> 9) & 0x7fffff)
479 #define NXM_HASMASK(HEADER) (((HEADER) >> 8) & 1)
480 #define NXM_LENGTH(HEADER) ((HEADER) & 0xff)
482 #define NXM_MAKE_WILD_HEADER(HEADER) \
483 NXM_HEADER_W(NXM_VENDOR(HEADER), NXM_FIELD(HEADER), NXM_LENGTH(HEADER))
485 /* ## ------------------------------- ## */
486 /* ## OpenFlow 1.0-compatible fields. ## */
487 /* ## ------------------------------- ## */
489 /* Physical or virtual port on which the packet was received.
493 * Format: 16-bit integer in network byte order.
495 * Masking: Not maskable. */
496 #define NXM_OF_IN_PORT NXM_HEADER (0x0000, 0, 2)
498 /* Source or destination address in Ethernet header.
502 * Format: 48-bit Ethernet MAC address.
504 * Masking: Fully maskable, in versions 1.8 and later. Earlier versions only
505 * supported the following masks for NXM_OF_ETH_DST_W: 00:00:00:00:00:00,
506 * fe:ff:ff:ff:ff:ff, 01:00:00:00:00:00, ff:ff:ff:ff:ff:ff. */
507 #define NXM_OF_ETH_DST NXM_HEADER (0x0000, 1, 6)
508 #define NXM_OF_ETH_DST_W NXM_HEADER_W(0x0000, 1, 6)
509 #define NXM_OF_ETH_SRC NXM_HEADER (0x0000, 2, 6)
510 #define NXM_OF_ETH_SRC_W NXM_HEADER_W(0x0000, 2, 6)
512 /* Packet's Ethernet type.
514 * For an Ethernet II packet this is taken from the Ethernet header. For an
515 * 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP header.
516 * A packet that has neither format has value 0x05ff
517 * (OFP_DL_TYPE_NOT_ETH_TYPE).
519 * For a packet with an 802.1Q header, this is the type of the encapsulated
524 * Format: 16-bit integer in network byte order.
526 * Masking: Not maskable. */
527 #define NXM_OF_ETH_TYPE NXM_HEADER (0x0000, 3, 2)
531 * For a packet with an 802.1Q header, this is the Tag Control Information
532 * (TCI) field, with the CFI bit forced to 1. For a packet with no 802.1Q
533 * header, this has value 0.
537 * Format: 16-bit integer in network byte order.
539 * Masking: Arbitrary masks.
541 * This field can be used in various ways:
543 * - If it is not constrained at all, the nx_match matches packets without
544 * an 802.1Q header or with an 802.1Q header that has any TCI value.
546 * - Testing for an exact match with 0 matches only packets without an
549 * - Testing for an exact match with a TCI value with CFI=1 matches packets
550 * that have an 802.1Q header with a specified VID and PCP.
552 * - Testing for an exact match with a nonzero TCI value with CFI=0 does
553 * not make sense. The switch may reject this combination.
555 * - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
556 * packets that have an 802.1Q header with that VID (and any PCP).
558 * - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
559 * packets that have an 802.1Q header with that PCP (and any VID).
561 * - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no 802.1Q
562 * header or with an 802.1Q header with a VID of 0.
564 * - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no 802.1Q
565 * header or with an 802.1Q header with a PCP of 0.
567 * - Testing with nxm_value=0, nxm_mask=0xefff matches packets with no 802.1Q
568 * header or with an 802.1Q header with both VID and PCP of 0.
570 #define NXM_OF_VLAN_TCI NXM_HEADER (0x0000, 4, 2)
571 #define NXM_OF_VLAN_TCI_W NXM_HEADER_W(0x0000, 4, 2)
573 /* The "type of service" byte of the IP header, with the ECN bits forced to 0.
575 * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
577 * Format: 8-bit integer with 2 least-significant bits forced to 0.
579 * Masking: Not maskable. */
580 #define NXM_OF_IP_TOS NXM_HEADER (0x0000, 5, 1)
582 /* The "protocol" byte in the IP header.
584 * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
586 * Format: 8-bit integer.
588 * Masking: Not maskable. */
589 #define NXM_OF_IP_PROTO NXM_HEADER (0x0000, 6, 1)
591 /* The source or destination address in the IP header.
593 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
595 * Format: 32-bit integer in network byte order.
597 * Masking: Fully maskable, in Open vSwitch 1.8 and later. In earlier
598 * versions, only CIDR masks are allowed, that is, masks that consist of N
599 * high-order bits set to 1 and the other 32-N bits set to 0. */
600 #define NXM_OF_IP_SRC NXM_HEADER (0x0000, 7, 4)
601 #define NXM_OF_IP_SRC_W NXM_HEADER_W(0x0000, 7, 4)
602 #define NXM_OF_IP_DST NXM_HEADER (0x0000, 8, 4)
603 #define NXM_OF_IP_DST_W NXM_HEADER_W(0x0000, 8, 4)
605 /* The source or destination port in the TCP header.
608 * NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
609 * NXM_OF_IP_PROTO must match 6 exactly.
611 * Format: 16-bit integer in network byte order.
613 * Masking: Fully maskable, in Open vSwitch 1.6 and later. Not maskable, in
614 * earlier versions. */
615 #define NXM_OF_TCP_SRC NXM_HEADER (0x0000, 9, 2)
616 #define NXM_OF_TCP_SRC_W NXM_HEADER_W(0x0000, 9, 2)
617 #define NXM_OF_TCP_DST NXM_HEADER (0x0000, 10, 2)
618 #define NXM_OF_TCP_DST_W NXM_HEADER_W(0x0000, 10, 2)
620 /* The source or destination port in the UDP header.
623 * NXM_OF_ETH_TYPE must match either 0x0800 or 0x86dd.
624 * NXM_OF_IP_PROTO must match 17 exactly.
626 * Format: 16-bit integer in network byte order.
628 * Masking: Fully maskable, in Open vSwitch 1.6 and later. Not maskable, in
629 * earlier versions. */
630 #define NXM_OF_UDP_SRC NXM_HEADER (0x0000, 11, 2)
631 #define NXM_OF_UDP_SRC_W NXM_HEADER_W(0x0000, 11, 2)
632 #define NXM_OF_UDP_DST NXM_HEADER (0x0000, 12, 2)
633 #define NXM_OF_UDP_DST_W NXM_HEADER_W(0x0000, 12, 2)
635 /* The type or code in the ICMP header.
638 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
639 * NXM_OF_IP_PROTO must match 1 exactly.
641 * Format: 8-bit integer.
643 * Masking: Not maskable. */
644 #define NXM_OF_ICMP_TYPE NXM_HEADER (0x0000, 13, 1)
645 #define NXM_OF_ICMP_CODE NXM_HEADER (0x0000, 14, 1)
649 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
650 * otherwise. Only ARP opcodes between 1 and 255 should be specified for
653 * Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.
655 * Format: 16-bit integer in network byte order.
657 * Masking: Not maskable. */
658 #define NXM_OF_ARP_OP NXM_HEADER (0x0000, 15, 2)
660 /* For an Ethernet+IP ARP packet, the source or target protocol address
661 * in the ARP header. Always 0 otherwise.
663 * Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.
665 * Format: 32-bit integer in network byte order.
667 * Masking: Fully maskable, in Open vSwitch 1.8 and later. In earlier
668 * versions, only CIDR masks are allowed, that is, masks that consist of N
669 * high-order bits set to 1 and the other 32-N bits set to 0. */
670 #define NXM_OF_ARP_SPA NXM_HEADER (0x0000, 16, 4)
671 #define NXM_OF_ARP_SPA_W NXM_HEADER_W(0x0000, 16, 4)
672 #define NXM_OF_ARP_TPA NXM_HEADER (0x0000, 17, 4)
673 #define NXM_OF_ARP_TPA_W NXM_HEADER_W(0x0000, 17, 4)
675 /* ## ------------------------ ## */
676 /* ## Nicira match extensions. ## */
677 /* ## ------------------------ ## */
679 /* Metadata registers.
681 * Registers initially have value 0. Actions allow register values to be
686 * Format: Array of 32-bit integer registers. Space is reserved for up to
687 * NXM_NX_MAX_REGS registers, but switches may implement fewer.
689 * Masking: Arbitrary masks. */
690 #define NXM_NX_MAX_REGS 16
691 #define NXM_NX_REG(IDX) NXM_HEADER (0x0001, IDX, 4)
692 #define NXM_NX_REG_W(IDX) NXM_HEADER_W(0x0001, IDX, 4)
693 #define NXM_NX_REG_IDX(HEADER) NXM_FIELD(HEADER)
694 #define NXM_IS_NX_REG(HEADER) (!((((HEADER) ^ NXM_NX_REG0)) & 0xffffe1ff))
695 #define NXM_IS_NX_REG_W(HEADER) (!((((HEADER) ^ NXM_NX_REG0_W)) & 0xffffe1ff))
696 #define NXM_NX_REG0 NXM_HEADER (0x0001, 0, 4)
697 #define NXM_NX_REG0_W NXM_HEADER_W(0x0001, 0, 4)
698 #define NXM_NX_REG1 NXM_HEADER (0x0001, 1, 4)
699 #define NXM_NX_REG1_W NXM_HEADER_W(0x0001, 1, 4)
700 #define NXM_NX_REG2 NXM_HEADER (0x0001, 2, 4)
701 #define NXM_NX_REG2_W NXM_HEADER_W(0x0001, 2, 4)
702 #define NXM_NX_REG3 NXM_HEADER (0x0001, 3, 4)
703 #define NXM_NX_REG3_W NXM_HEADER_W(0x0001, 3, 4)
704 #define NXM_NX_REG4 NXM_HEADER (0x0001, 4, 4)
705 #define NXM_NX_REG4_W NXM_HEADER_W(0x0001, 4, 4)
706 #define NXM_NX_REG5 NXM_HEADER (0x0001, 5, 4)
707 #define NXM_NX_REG5_W NXM_HEADER_W(0x0001, 5, 4)
708 #define NXM_NX_REG6 NXM_HEADER (0x0001, 6, 4)
709 #define NXM_NX_REG6_W NXM_HEADER_W(0x0001, 6, 4)
710 #define NXM_NX_REG7 NXM_HEADER (0x0001, 7, 4)
711 #define NXM_NX_REG7_W NXM_HEADER_W(0x0001, 7, 4)
715 * For a packet received via a Geneve, GRE, VXLAN or LISP tunnel including a
716 * key less than 64 bits, the key is stored in the low bits and the high bits
717 * are zeroed. For other packets, the value is 0.
719 * All zero bits, for packets not received via a keyed tunnel.
723 * Format: 64-bit integer in network byte order.
725 * Masking: Arbitrary masks. */
726 #define NXM_NX_TUN_ID NXM_HEADER (0x0001, 16, 8)
727 #define NXM_NX_TUN_ID_W NXM_HEADER_W(0x0001, 16, 8)
729 /* For an Ethernet+IP ARP packet, the source or target hardware address
730 * in the ARP header. Always 0 otherwise.
732 * Prereqs: NXM_OF_ETH_TYPE must match either 0x0806 or 0x8035.
734 * Format: 48-bit Ethernet MAC address.
736 * Masking: Not maskable. */
737 #define NXM_NX_ARP_SHA NXM_HEADER (0x0001, 17, 6)
738 #define NXM_NX_ARP_THA NXM_HEADER (0x0001, 18, 6)
740 /* The source or destination address in the IPv6 header.
742 * Prereqs: NXM_OF_ETH_TYPE must match 0x86dd exactly.
744 * Format: 128-bit IPv6 address.
746 * Masking: Fully maskable, in Open vSwitch 1.8 and later. In previous
747 * versions, only CIDR masks are allowed, that is, masks that consist of N
748 * high-order bits set to 1 and the other 128-N bits set to 0. */
749 #define NXM_NX_IPV6_SRC NXM_HEADER (0x0001, 19, 16)
750 #define NXM_NX_IPV6_SRC_W NXM_HEADER_W(0x0001, 19, 16)
751 #define NXM_NX_IPV6_DST NXM_HEADER (0x0001, 20, 16)
752 #define NXM_NX_IPV6_DST_W NXM_HEADER_W(0x0001, 20, 16)
754 /* The type or code in the ICMPv6 header.
757 * NXM_OF_ETH_TYPE must match 0x86dd exactly.
758 * NXM_OF_IP_PROTO must match 58 exactly.
760 * Format: 8-bit integer.
762 * Masking: Not maskable. */
763 #define NXM_NX_ICMPV6_TYPE NXM_HEADER (0x0001, 21, 1)
764 #define NXM_NX_ICMPV6_CODE NXM_HEADER (0x0001, 22, 1)
766 /* The target address in an IPv6 Neighbor Discovery message.
769 * NXM_OF_ETH_TYPE must match 0x86dd exactly.
770 * NXM_OF_IP_PROTO must match 58 exactly.
771 * NXM_OF_ICMPV6_TYPE must be either 135 or 136.
773 * Format: 128-bit IPv6 address.
775 * Masking: Fully maskable, in Open vSwitch 1.8 and later. In previous
776 * versions, only CIDR masks are allowed, that is, masks that consist of N
777 * high-order bits set to 1 and the other 128-N bits set to 0. */
778 #define NXM_NX_ND_TARGET NXM_HEADER (0x0001, 23, 16)
779 #define NXM_NX_ND_TARGET_W NXM_HEADER_W (0x0001, 23, 16)
781 /* The source link-layer address option in an IPv6 Neighbor Discovery
785 * NXM_OF_ETH_TYPE must match 0x86dd exactly.
786 * NXM_OF_IP_PROTO must match 58 exactly.
787 * NXM_OF_ICMPV6_TYPE must be exactly 135.
789 * Format: 48-bit Ethernet MAC address.
791 * Masking: Not maskable. */
792 #define NXM_NX_ND_SLL NXM_HEADER (0x0001, 24, 6)
794 /* The target link-layer address option in an IPv6 Neighbor Discovery
798 * NXM_OF_ETH_TYPE must match 0x86dd exactly.
799 * NXM_OF_IP_PROTO must match 58 exactly.
800 * NXM_OF_ICMPV6_TYPE must be exactly 136.
802 * Format: 48-bit Ethernet MAC address.
804 * Masking: Not maskable. */
805 #define NXM_NX_ND_TLL NXM_HEADER (0x0001, 25, 6)
807 /* IP fragment information.
810 * NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
812 * Format: 8-bit value with one of the values 0, 1, or 3, as described below.
814 * Masking: Fully maskable.
816 * This field has three possible values:
818 * - A packet that is not an IP fragment has value 0.
820 * - A packet that is an IP fragment with offset 0 (the first fragment) has
821 * bit 0 set and thus value 1.
823 * - A packet that is an IP fragment with nonzero offset has bits 0 and 1 set
826 * NX_IP_FRAG_ANY and NX_IP_FRAG_LATER are declared to symbolically represent
827 * the meanings of bits 0 and 1.
829 * The switch may reject matches against values that can never appear.
831 * It is important to understand how this field interacts with the OpenFlow IP
832 * fragment handling mode:
834 * - In OFPC_FRAG_DROP mode, the OpenFlow switch drops all IP fragments
835 * before they reach the flow table, so every packet that is available for
836 * matching will have value 0 in this field.
838 * - Open vSwitch does not implement OFPC_FRAG_REASM mode, but if it did then
839 * IP fragments would be reassembled before they reached the flow table and
840 * again every packet available for matching would always have value 0.
842 * - In OFPC_FRAG_NORMAL mode, all three values are possible, but OpenFlow
843 * 1.0 says that fragments' transport ports are always 0, even for the
844 * first fragment, so this does not provide much extra information.
846 * - In OFPC_FRAG_NX_MATCH mode, all three values are possible. For
847 * fragments with offset 0, Open vSwitch makes L4 header information
850 #define NXM_NX_IP_FRAG NXM_HEADER (0x0001, 26, 1)
851 #define NXM_NX_IP_FRAG_W NXM_HEADER_W(0x0001, 26, 1)
853 /* Bits in the value of NXM_NX_IP_FRAG. */
854 #define NX_IP_FRAG_ANY (1 << 0) /* Is this a fragment? */
855 #define NX_IP_FRAG_LATER (1 << 1) /* Is this a fragment with nonzero offset? */
857 /* The flow label in the IPv6 header.
859 * Prereqs: NXM_OF_ETH_TYPE must match 0x86dd exactly.
861 * Format: 20-bit IPv6 flow label in least-significant bits.
863 * Masking: Fully maskable. */
864 #define NXM_NX_IPV6_LABEL NXM_HEADER (0x0001, 27, 4)
865 #define NXM_NX_IPV6_LABEL_W NXM_HEADER_W(0x0001, 27, 4)
867 /* The ECN of the IP header.
869 * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
871 * Format: ECN in the low-order 2 bits.
873 * Masking: Not maskable. */
874 #define NXM_NX_IP_ECN NXM_HEADER (0x0001, 28, 1)
876 /* The time-to-live/hop limit of the IP header.
878 * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
880 * Format: 8-bit integer.
882 * Masking: Not maskable. */
883 #define NXM_NX_IP_TTL NXM_HEADER (0x0001, 29, 1)
887 * This may be used to gain the OpenFlow 1.1-like ability to restrict
888 * certain NXM-based Flow Mod and Flow Stats Request messages to flows
889 * with specific cookies. See the "nx_flow_mod" and "nx_flow_stats_request"
890 * structure definitions for more details. This match is otherwise not
895 * Format: 64-bit integer in network byte order.
897 * Masking: Arbitrary masks. */
898 #define NXM_NX_COOKIE NXM_HEADER (0x0001, 30, 8)
899 #define NXM_NX_COOKIE_W NXM_HEADER_W(0x0001, 30, 8)
901 /* The source or destination address in the outer IP header of a tunneled
904 * For non-tunneled packets, the value is 0.
908 * Format: 32-bit integer in network byte order.
910 * Masking: Fully maskable. */
911 #define NXM_NX_TUN_IPV4_SRC NXM_HEADER (0x0001, 31, 4)
912 #define NXM_NX_TUN_IPV4_SRC_W NXM_HEADER_W(0x0001, 31, 4)
913 #define NXM_NX_TUN_IPV4_DST NXM_HEADER (0x0001, 32, 4)
914 #define NXM_NX_TUN_IPV4_DST_W NXM_HEADER_W(0x0001, 32, 4)
916 /* Metadata marked onto the packet in a system-dependent manner.
918 * The packet mark may be used to carry contextual information
919 * to other parts of the system outside of Open vSwitch. As a
920 * result, the semantics depend on system in use.
924 * Format: 32-bit integer in network byte order.
926 * Masking: Fully maskable. */
927 #define NXM_NX_PKT_MARK NXM_HEADER (0x0001, 33, 4)
928 #define NXM_NX_PKT_MARK_W NXM_HEADER_W(0x0001, 33, 4)
930 /* The flags in the TCP header.
933 * NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
934 * NXM_OF_IP_PROTO must match 6 exactly.
936 * Format: 16-bit integer with 4 most-significant bits forced to 0.
938 * Masking: Bits 0-11 fully maskable. */
939 #define NXM_NX_TCP_FLAGS NXM_HEADER (0x0001, 34, 2)
940 #define NXM_NX_TCP_FLAGS_W NXM_HEADER_W(0x0001, 34, 2)
944 * Internal use only, not programable from controller.
946 * The dp_hash is used to carry the flow hash computed in the
951 * Format: 32-bit integer in network byte order.
953 * Masking: Fully maskable. */
954 #define NXM_NX_DP_HASH NXM_HEADER (0x0001, 35, 4)
955 #define NXM_NX_DP_HASH_W NXM_HEADER_W(0x0001, 35, 4)
957 /* Metadata recirc_id.
959 * Internal use only, not programable from controller.
961 * The recirc_id used for recirculation. 0 is reserved
962 * for initially received packet.
966 * Format: 32-bit integer in network byte order.
968 * Masking: not maskable. */
969 #define NXM_NX_RECIRC_ID NXM_HEADER (0x0001, 36, 4)
971 /* ## --------------------- ## */
972 /* ## Requests and replies. ## */
973 /* ## --------------------- ## */
975 enum nx_flow_format {
976 NXFF_OPENFLOW10 = 0, /* Standard OpenFlow 1.0 compatible. */
977 NXFF_NXM = 2 /* Nicira extended match. */
980 /* NXT_SET_FLOW_FORMAT request. */
981 struct nx_set_flow_format {
982 ovs_be32 format; /* One of NXFF_*. */
984 OFP_ASSERT(sizeof(struct nx_set_flow_format) == 4);
986 /* NXT_FLOW_MOD (analogous to OFPT_FLOW_MOD).
988 * It is possible to limit flow deletions and modifications to certain
989 * cookies by using the NXM_NX_COOKIE(_W) matches. The "cookie" field
990 * is used only to add or modify flow cookies.
993 ovs_be64 cookie; /* Opaque controller-issued identifier. */
994 ovs_be16 command; /* OFPFC_* + possibly a table ID (see comment
995 * on struct nx_flow_mod_table_id). */
996 ovs_be16 idle_timeout; /* Idle time before discarding (seconds). */
997 ovs_be16 hard_timeout; /* Max time before discarding (seconds). */
998 ovs_be16 priority; /* Priority level of flow entry. */
999 ovs_be32 buffer_id; /* Buffered packet to apply to (or -1).
1000 Not meaningful for OFPFC_DELETE*. */
1001 ovs_be16 out_port; /* For OFPFC_DELETE* commands, require
1002 matching entries to include this as an
1003 output port. A value of OFPP_NONE
1004 indicates no restriction. */
1005 ovs_be16 flags; /* One of OFPFF_*. */
1006 ovs_be16 match_len; /* Size of nx_match. */
1007 uint8_t pad[6]; /* Align to 64-bits. */
1009 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1010 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1011 * all-zero bytes, then
1012 * - Actions to fill out the remainder of the message length (always a
1016 OFP_ASSERT(sizeof(struct nx_flow_mod) == 32);
1018 /* NXT_FLOW_REMOVED (analogous to OFPT_FLOW_REMOVED).
1020 * 'table_id' is present only in Open vSwitch 1.11 and later. In earlier
1021 * versions of Open vSwitch, this is a padding byte that is always zeroed.
1022 * Therefore, a 'table_id' value of 0 indicates that the table ID is not known,
1023 * and other values may be interpreted as one more than the flow's former table
1025 struct nx_flow_removed {
1026 ovs_be64 cookie; /* Opaque controller-issued identifier. */
1027 ovs_be16 priority; /* Priority level of flow entry. */
1028 uint8_t reason; /* One of OFPRR_*. */
1029 uint8_t table_id; /* Flow's former table ID, plus one. */
1030 ovs_be32 duration_sec; /* Time flow was alive in seconds. */
1031 ovs_be32 duration_nsec; /* Time flow was alive in nanoseconds beyond
1033 ovs_be16 idle_timeout; /* Idle timeout from original flow mod. */
1034 ovs_be16 match_len; /* Size of nx_match. */
1035 ovs_be64 packet_count;
1036 ovs_be64 byte_count;
1038 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1039 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1040 * all-zero bytes. */
1042 OFP_ASSERT(sizeof(struct nx_flow_removed) == 40);
1044 /* Nicira vendor stats request of type NXST_FLOW (analogous to OFPST_FLOW
1047 * It is possible to limit matches to certain cookies by using the
1048 * NXM_NX_COOKIE and NXM_NX_COOKIE_W matches.
1050 struct nx_flow_stats_request {
1051 ovs_be16 out_port; /* Require matching entries to include this
1052 as an output port. A value of OFPP_NONE
1053 indicates no restriction. */
1054 ovs_be16 match_len; /* Length of nx_match. */
1055 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
1056 or 0xff for all tables. */
1057 uint8_t pad[3]; /* Align to 64 bits. */
1059 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1060 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1061 * all-zero bytes, which must also exactly fill out the length of the
1065 OFP_ASSERT(sizeof(struct nx_flow_stats_request) == 8);
1067 /* Body for Nicira vendor stats reply of type NXST_FLOW (analogous to
1068 * OFPST_FLOW reply).
1070 * The values of 'idle_age' and 'hard_age' are only meaningful when talking to
1071 * a switch that implements the NXT_FLOW_AGE extension. Zero means that the
1072 * true value is unknown, perhaps because hardware does not track the value.
1073 * (Zero is also the value that one should ordinarily expect to see talking to
1074 * a switch that does not implement NXT_FLOW_AGE, since those switches zero the
1075 * padding bytes that these fields replaced.) A nonzero value X represents X-1
1076 * seconds. A value of 65535 represents 65534 or more seconds.
1078 * 'idle_age' is the number of seconds that the flow has been idle, that is,
1079 * the number of seconds since a packet passed through the flow. 'hard_age' is
1080 * the number of seconds since the flow was last modified (e.g. OFPFC_MODIFY or
1081 * OFPFC_MODIFY_STRICT). (The 'duration_*' fields are the elapsed time since
1082 * the flow was added, regardless of subsequent modifications.)
1084 * For a flow with an idle or hard timeout, 'idle_age' or 'hard_age',
1085 * respectively, will ordinarily be smaller than the timeout, but flow
1086 * expiration times are only approximate and so one must be prepared to
1087 * tolerate expirations that occur somewhat early or late.
1089 struct nx_flow_stats {
1090 ovs_be16 length; /* Length of this entry. */
1091 uint8_t table_id; /* ID of table flow came from. */
1093 ovs_be32 duration_sec; /* Time flow has been alive in seconds. */
1094 ovs_be32 duration_nsec; /* Time flow has been alive in nanoseconds
1095 beyond duration_sec. */
1096 ovs_be16 priority; /* Priority of the entry. */
1097 ovs_be16 idle_timeout; /* Number of seconds idle before expiration. */
1098 ovs_be16 hard_timeout; /* Number of seconds before expiration. */
1099 ovs_be16 match_len; /* Length of nx_match. */
1100 ovs_be16 idle_age; /* Seconds since last packet, plus one. */
1101 ovs_be16 hard_age; /* Seconds since last modification, plus one. */
1102 ovs_be64 cookie; /* Opaque controller-issued identifier. */
1103 ovs_be64 packet_count; /* Number of packets, UINT64_MAX if unknown. */
1104 ovs_be64 byte_count; /* Number of bytes, UINT64_MAX if unknown. */
1106 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1107 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1108 * all-zero bytes, then
1109 * - Actions to fill out the remainder 'length' bytes (always a multiple
1113 OFP_ASSERT(sizeof(struct nx_flow_stats) == 48);
1115 /* Nicira vendor stats request of type NXST_AGGREGATE (analogous to
1116 * OFPST_AGGREGATE request).
1118 * The reply format is identical to the reply format for OFPST_AGGREGATE,
1119 * except for the header. */
1120 struct nx_aggregate_stats_request {
1121 ovs_be16 out_port; /* Require matching entries to include this
1122 as an output port. A value of OFPP_NONE
1123 indicates no restriction. */
1124 ovs_be16 match_len; /* Length of nx_match. */
1125 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
1126 or 0xff for all tables. */
1127 uint8_t pad[3]; /* Align to 64 bits. */
1129 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1130 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1131 * all-zero bytes, which must also exactly fill out the length of the
1135 OFP_ASSERT(sizeof(struct nx_aggregate_stats_request) == 8);
1137 /* NXT_SET_CONTROLLER_ID.
1139 * Each OpenFlow controller connection has a 16-bit identifier that is
1140 * initially 0. This message changes the connection's ID to 'id'.
1142 * Controller connection IDs need not be unique.
1144 * The NXAST_CONTROLLER action is the only current user of controller
1145 * connection IDs. */
1146 struct nx_controller_id {
1147 uint8_t zero[6]; /* Must be zero. */
1148 ovs_be16 controller_id; /* New controller connection ID. */
1150 OFP_ASSERT(sizeof(struct nx_controller_id) == 8);
1152 /* Flow Table Monitoring
1153 * =====================
1155 * NXST_FLOW_MONITOR allows a controller to keep track of changes to OpenFlow
1156 * flow table(s) or subsets of them, with the following workflow:
1158 * 1. The controller sends an NXST_FLOW_MONITOR request to begin monitoring
1159 * flows. The 'id' in the request must be unique among all monitors that
1160 * the controller has started and not yet canceled on this OpenFlow
1163 * 2. The switch responds with an NXST_FLOW_MONITOR reply. If the request's
1164 * 'flags' included NXFMF_INITIAL, the reply includes all the flows that
1165 * matched the request at the time of the request (with event NXFME_ADDED).
1166 * If 'flags' did not include NXFMF_INITIAL, the reply is empty.
1168 * The reply uses the xid of the request (as do all replies to OpenFlow
1171 * 3. Whenever a change to a flow table entry matches some outstanding monitor
1172 * request's criteria and flags, the switch sends a notification to the
1173 * controller as an additional NXST_FLOW_MONITOR reply with xid 0.
1175 * When multiple outstanding monitors match a single change, only a single
1176 * notification is sent. This merged notification includes the information
1177 * requested in any of the individual monitors. That is, if any of the
1178 * matching monitors requests actions (NXFMF_ACTIONS), the notification
1179 * includes actions, and if any of the monitors request full changes for the
1180 * controller's own changes (NXFMF_OWN), the controller's own changes will
1181 * be included in full.
1183 * 4. The controller may cancel a monitor with NXT_FLOW_MONITOR_CANCEL. No
1184 * further notifications will be sent on the basis of the canceled monitor
1191 * OpenFlow messages for flow monitor notifications can overflow the buffer
1192 * space available to the switch, either temporarily (e.g. due to network
1193 * conditions slowing OpenFlow traffic) or more permanently (e.g. the sustained
1194 * rate of flow table change exceeds the network bandwidth between switch and
1197 * When Open vSwitch's notification buffer space reaches a limiting threshold,
1198 * OVS reacts as follows:
1200 * 1. OVS sends an NXT_FLOW_MONITOR_PAUSED message to the controller, following
1201 * all the already queued notifications. After it receives this message,
1202 * the controller knows that its view of the flow table, as represented by
1203 * flow monitor notifications, is incomplete.
1205 * 2. As long as the notification buffer is not empty:
1207 * - NXMFE_ADD and NXFME_MODIFIED notifications will not be sent.
1209 * - NXFME_DELETED notifications will still be sent, but only for flows
1210 * that existed before OVS sent NXT_FLOW_MONITOR_PAUSED.
1212 * - NXFME_ABBREV notifications will not be sent. They are treated as
1213 * the expanded version (and therefore only the NXFME_DELETED
1214 * components, if any, are sent).
1216 * 3. When the notification buffer empties, OVS sends NXFME_ADD notifications
1217 * for flows added since the buffer reached its limit and NXFME_MODIFIED
1218 * notifications for flows that existed before the limit was reached and
1219 * changed after the limit was reached.
1221 * 4. OVS sends an NXT_FLOW_MONITOR_RESUMED message to the controller. After
1222 * it receives this message, the controller knows that its view of the flow
1223 * table, as represented by flow monitor notifications, is again complete.
1225 * This allows the maximum buffer space requirement for notifications to be
1226 * bounded by the limit plus the maximum number of supported flows.
1229 * "Flow Removed" messages
1230 * =======================
1232 * The flow monitor mechanism is independent of OFPT_FLOW_REMOVED and
1233 * NXT_FLOW_REMOVED. Flow monitor updates for deletion are sent if
1234 * NXFMF_DELETE is set on a monitor, regardless of whether the
1235 * OFPFF_SEND_FLOW_REM flag was set when the flow was added. */
1237 /* NXST_FLOW_MONITOR request.
1239 * The NXST_FLOW_MONITOR request's body consists of an array of zero or more
1240 * instances of this structure. The request arranges to monitor the flows
1241 * that match the specified criteria, which are interpreted in the same way as
1244 * 'id' identifies a particular monitor for the purpose of allowing it to be
1245 * canceled later with NXT_FLOW_MONITOR_CANCEL. 'id' must be unique among
1246 * existing monitors that have not already been canceled.
1248 * The reply includes the initial flow matches for monitors that have the
1249 * NXFMF_INITIAL flag set. No single flow will be included in the reply more
1250 * than once, even if more than one requested monitor matches that flow. The
1251 * reply will be empty if none of the monitors has NXFMF_INITIAL set or if none
1252 * of the monitors initially matches any flows.
1254 * For NXFMF_ADD, an event will be reported if 'out_port' matches against the
1255 * actions of the flow being added or, for a flow that is replacing an existing
1256 * flow, if 'out_port' matches against the actions of the flow being replaced.
1257 * For NXFMF_DELETE, 'out_port' matches against the actions of a flow being
1258 * deleted. For NXFMF_MODIFY, an event will be reported if 'out_port' matches
1259 * either the old or the new actions. */
1260 struct nx_flow_monitor_request {
1261 ovs_be32 id; /* Controller-assigned ID for this monitor. */
1262 ovs_be16 flags; /* NXFMF_*. */
1263 ovs_be16 out_port; /* Required output port, if not OFPP_NONE. */
1264 ovs_be16 match_len; /* Length of nx_match. */
1265 uint8_t table_id; /* One table's ID or 0xff for all tables. */
1266 uint8_t zeros[5]; /* Align to 64 bits (must be zero). */
1268 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1269 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1270 * all-zero bytes. */
1272 OFP_ASSERT(sizeof(struct nx_flow_monitor_request) == 16);
1274 /* 'flags' bits in struct nx_flow_monitor_request. */
1275 enum nx_flow_monitor_flags {
1276 /* When to send updates. */
1277 NXFMF_INITIAL = 1 << 0, /* Initially matching flows. */
1278 NXFMF_ADD = 1 << 1, /* New matching flows as they are added. */
1279 NXFMF_DELETE = 1 << 2, /* Old matching flows as they are removed. */
1280 NXFMF_MODIFY = 1 << 3, /* Matching flows as they are changed. */
1282 /* What to include in updates. */
1283 NXFMF_ACTIONS = 1 << 4, /* If set, actions are included. */
1284 NXFMF_OWN = 1 << 5, /* If set, include own changes in full. */
1287 /* NXST_FLOW_MONITOR reply header.
1289 * The body of an NXST_FLOW_MONITOR reply is an array of variable-length
1290 * structures, each of which begins with this header. The 'length' member may
1291 * be used to traverse the array, and the 'event' member may be used to
1292 * determine the particular structure.
1294 * Every instance is a multiple of 8 bytes long. */
1295 struct nx_flow_update_header {
1296 ovs_be16 length; /* Length of this entry. */
1297 ovs_be16 event; /* One of NXFME_*. */
1298 /* ...other data depending on 'event'... */
1300 OFP_ASSERT(sizeof(struct nx_flow_update_header) == 4);
1302 /* 'event' values in struct nx_flow_update_header. */
1303 enum nx_flow_update_event {
1304 /* struct nx_flow_update_full. */
1305 NXFME_ADDED = 0, /* Flow was added. */
1306 NXFME_DELETED = 1, /* Flow was deleted. */
1307 NXFME_MODIFIED = 2, /* Flow (generally its actions) was changed. */
1309 /* struct nx_flow_update_abbrev. */
1310 NXFME_ABBREV = 3, /* Abbreviated reply. */
1313 /* NXST_FLOW_MONITOR reply for NXFME_ADDED, NXFME_DELETED, and
1314 * NXFME_MODIFIED. */
1315 struct nx_flow_update_full {
1316 ovs_be16 length; /* Length is 24. */
1317 ovs_be16 event; /* One of NXFME_*. */
1318 ovs_be16 reason; /* OFPRR_* for NXFME_DELETED, else zero. */
1319 ovs_be16 priority; /* Priority of the entry. */
1320 ovs_be16 idle_timeout; /* Number of seconds idle before expiration. */
1321 ovs_be16 hard_timeout; /* Number of seconds before expiration. */
1322 ovs_be16 match_len; /* Length of nx_match. */
1323 uint8_t table_id; /* ID of flow's table. */
1324 uint8_t pad; /* Reserved, currently zeroed. */
1325 ovs_be64 cookie; /* Opaque controller-issued identifier. */
1327 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1328 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1329 * all-zero bytes, then
1330 * - Actions to fill out the remainder 'length' bytes (always a multiple
1331 * of 8). If NXFMF_ACTIONS was not specified, or 'event' is
1332 * NXFME_DELETED, no actions are included.
1335 OFP_ASSERT(sizeof(struct nx_flow_update_full) == 24);
1337 /* NXST_FLOW_MONITOR reply for NXFME_ABBREV.
1339 * When the controller does not specify NXFMF_OWN in a monitor request, any
1340 * flow tables changes due to the controller's own requests (on the same
1341 * OpenFlow channel) will be abbreviated, when possible, to this form, which
1342 * simply specifies the 'xid' of the OpenFlow request (e.g. an OFPT_FLOW_MOD or
1343 * NXT_FLOW_MOD) that caused the change.
1345 * Some changes cannot be abbreviated and will be sent in full:
1347 * - Changes that only partially succeed. This can happen if, for example,
1348 * a flow_mod with type OFPFC_MODIFY affects multiple flows, but only some
1349 * of those modifications succeed (e.g. due to hardware limitations).
1351 * This cannot occur with the Open vSwitch software datapath. This also
1352 * cannot occur in Open vSwitch 2.4 and later, because these versions only
1353 * execute any flow modifications if all of them will succeed.
1355 * - Changes that race with conflicting changes made by other controllers or
1356 * other flow_mods (not separated by barriers) by the same controller.
1358 * This cannot occur with the current Open vSwitch implementation
1359 * (regardless of datapath) because Open vSwitch internally serializes
1360 * potentially conflicting changes.
1362 * - Changes that occur when flow notification is paused (see "Buffer
1363 * Management" above).
1365 * A flow_mod that does not change the flow table will not trigger any
1366 * notification, even an abbreviated one. For example, a "modify" or "delete"
1367 * flow_mod that does not match any flows will not trigger a notification.
1368 * Whether an "add" or "modify" that specifies all the same parameters that a
1369 * flow already has triggers a notification is unspecified and subject to
1370 * change in future versions of Open vSwitch.
1372 * OVS will always send the notifications for a given flow table change before
1373 * the reply to a OFPT_BARRIER_REQUEST request that follows the flow table
1374 * change. Thus, if the controller does not receive an abbreviated (or
1375 * unabbreviated) notification for a flow_mod before the next
1376 * OFPT_BARRIER_REPLY, it will never receive one. */
1377 struct nx_flow_update_abbrev {
1378 ovs_be16 length; /* Length is 8. */
1379 ovs_be16 event; /* NXFME_ABBREV. */
1380 ovs_be32 xid; /* Controller-specified xid from flow_mod. */
1382 OFP_ASSERT(sizeof(struct nx_flow_update_abbrev) == 8);
1384 /* NXT_FLOW_MONITOR_CANCEL.
1386 * Used by a controller to cancel an outstanding monitor. */
1387 struct nx_flow_monitor_cancel {
1388 ovs_be32 id; /* 'id' from nx_flow_monitor_request. */
1390 OFP_ASSERT(sizeof(struct nx_flow_monitor_cancel) == 4);
1392 #endif /* openflow/nicira-ext.h */