2 * Copyright (c) 2008, 2009, 2010 Nicira Networks
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 #define NICIRA_OUI_STR "002320"
25 /* The following vendor extensions, proposed by Nicira Networks, are not yet
26 * standardized, so they are not included in openflow.h. Some of them may be
27 * suitable for standardization; others we never expect to standardize. */
29 #define NX_VENDOR_ID 0x00002320
31 /* Nicira vendor-specific error messages extension.
33 * OpenFlow 1.0 has a set of predefined error types (OFPET_*) and codes (which
34 * are specific to each type). It does not have any provision for
35 * vendor-specific error codes, and it does not even provide "generic" error
36 * codes that can apply to problems not anticipated by the OpenFlow
37 * specification authors.
39 * This extension attempts to address the problem by adding a generic "error
40 * vendor extension". The extension works as follows: use NXET_VENDOR as type
41 * and NXVC_VENDOR_CODE as code, followed by struct nx_vendor_error with
42 * vendor-specific details, followed by at least 64 bytes of the failed
45 * It would be better to have a type-specific vendor extension, e.g. so that
46 * OFPET_BAD_ACTION could be used with vendor-specific code values. But
47 * OFPET_BAD_ACTION and most other standardized types already specify that
48 * their 'data' values are (the start of) the OpenFlow message being replied
49 * to, so there is no room to insert a vendor ID.
51 * Currently this extension is only implemented by Open vSwitch, but it seems
52 * like a reasonable candidate for future standardization.
55 /* This is a random number to avoid accidental collision with any other
56 * vendor's extension. */
57 #define NXET_VENDOR 0xb0c2
59 /* ofp_error msg 'code' values for NXET_VENDOR. */
61 NXVC_VENDOR_ERROR /* 'data' contains struct nx_vendor_error. */
64 /* 'data' for 'type' == NXET_VENDOR, 'code' == NXVC_VENDOR_ERROR. */
65 struct nx_vendor_error {
66 ovs_be32 vendor; /* Vendor ID as in struct ofp_vendor_header. */
67 ovs_be16 type; /* Vendor-defined type. */
68 ovs_be16 code; /* Vendor-defined subtype. */
69 /* Followed by at least the first 64 bytes of the failed request. */
72 /* Specific Nicira extension error numbers.
74 * These are the "code" values used in nx_vendor_error. So far, the "type"
75 * values in nx_vendor_error are the same as those in ofp_error_msg. That is,
76 * at Nicira so far we've only needed additional vendor-specific 'code' values,
77 * so we're using the existing 'type' values to avoid having to invent new ones
78 * that duplicate the current ones' meanings. */
80 /* Additional "code" values for OFPET_BAD_REQUEST. */
82 /* Nicira Extended Match (NXM) errors. */
84 /* Generic error code used when there is an error in an NXM sent to the
85 * switch. The switch may use one of the more specific error codes below,
86 * if there is an appropriate one, to simplify debugging, but it is not
87 * required to do so. */
88 NXBRC_NXM_INVALID = 0x100,
90 /* The nxm_type, or nxm_type taken in combination with nxm_hasmask or
91 * nxm_length or both, is invalid or not implemented. */
92 NXBRC_NXM_BAD_TYPE = 0x101,
94 /* Invalid nxm_value. */
95 NXBRC_NXM_BAD_VALUE = 0x102,
97 /* Invalid nxm_mask. */
98 NXBRC_NXM_BAD_MASK = 0x103,
100 /* A prerequisite was not met. */
101 NXBRC_NXM_BAD_PREREQ = 0x104,
103 /* A given nxm_type was specified more than once. */
104 NXBRC_NXM_DUP_TYPE = 0x105
107 /* Additional "code" values for OFPET_FLOW_MOD_FAILED. */
109 /* Generic hardware error. */
110 NXFMFC_HARDWARE = 0x100,
112 /* A nonexistent table ID was specified in the "command" field of struct
113 * ofp_flow_mod, when the nxt_flow_mod_table_id extension is enabled.
114 * (This extension is not yet implemented on this branch of Open
116 NXFMFC_BAD_TABLE_ID = 0x101
119 /* Nicira vendor requests and replies. */
121 /* Header for Nicira vendor requests and replies. */
122 struct nicira_header {
123 struct ofp_header header;
124 ovs_be32 vendor; /* NX_VENDOR_ID. */
125 ovs_be32 subtype; /* One of NXT_* below. */
127 OFP_ASSERT(sizeof(struct nicira_header) == 16);
129 /* Values for the 'subtype' member of struct nicira_header. */
131 /* Switch status request. The request body is an ASCII string that
132 * specifies a prefix of the key names to include in the output; if it is
133 * the null string, then all key-value pairs are included. */
136 /* Switch status reply. The reply body is an ASCII string of key-value
137 * pairs in the form "key=value\n". */
140 /* No longer used. */
141 NXT_ACT_SET_CONFIG__OBSOLETE,
142 NXT_ACT_GET_CONFIG__OBSOLETE,
143 NXT_COMMAND_REQUEST__OBSOLETE,
144 NXT_COMMAND_REPLY__OBSOLETE,
145 NXT_FLOW_END_CONFIG__OBSOLETE,
146 NXT_FLOW_END__OBSOLETE,
149 /* Use the high 32 bits of the cookie field as the tunnel ID in the flow
151 NXT_TUN_ID_FROM_COOKIE,
153 /* Controller role support. The request body is struct nx_role_request.
154 * The reply echos the request. */
158 /* Flexible flow specification (aka NXM = Nicira Extended Match). */
159 NXT_SET_FLOW_FORMAT, /* Set flow format. */
160 NXT_FLOW_MOD, /* Analogous to OFPT_FLOW_MOD. */
161 NXT_FLOW_REMOVED /* Analogous to OFPT_FLOW_REMOVED. */
164 /* Header for Nicira vendor stats request and reply messages. */
165 struct nicira_stats_msg {
166 struct ofp_header header; /* OFPT_STATS_REQUEST or OFPT_STATS_REPLY. */
167 ovs_be16 type; /* OFPST_VENDOR. */
168 ovs_be16 flags; /* OFPSF_{REQ,REPLY}_*. */
169 ovs_be32 vendor; /* NX_VENDOR_ID. */
170 ovs_be32 subtype; /* One of NXST_* below. */
171 uint8_t pad[4]; /* Align to 64-bits. */
173 OFP_ASSERT(sizeof(struct nicira_stats_msg) == 24);
175 /* Values for the 'subtype' member of struct nicira_stats_msg. */
176 enum nicira_stats_type {
177 /* Flexible flow specification (aka NXM = Nicira Extended Match). */
178 NXST_FLOW, /* Analogous to OFPST_FLOW. */
179 NXST_AGGREGATE /* Analogous to OFPST_AGGREGATE. */
182 /* NXT_TUN_ID_FROM_COOKIE request. */
183 struct nxt_tun_id_cookie {
184 struct ofp_header header;
185 uint32_t vendor; /* NX_VENDOR_ID. */
186 uint32_t subtype; /* NXT_TUN_ID_FROM_COOKIE */
187 uint8_t set; /* Nonzero to enable, zero to disable. */
190 OFP_ASSERT(sizeof(struct nxt_tun_id_cookie) == 24);
192 /* Configures the "role" of the sending controller. The default role is:
194 * - Other (NX_ROLE_OTHER), which allows the controller access to all
197 * The other possible roles are a related pair:
199 * - Master (NX_ROLE_MASTER) is equivalent to Other, except that there may
200 * be at most one Master controller at a time: when a controller
201 * configures itself as Master, any existing Master is demoted to the
204 * - Slave (NX_ROLE_SLAVE) allows the controller read-only access to
205 * OpenFlow features. In particular attempts to modify the flow table
206 * will be rejected with an OFPBRC_EPERM error.
208 * Slave controllers do not receive OFPT_PACKET_IN or OFPT_FLOW_REMOVED
209 * messages, but they do receive OFPT_PORT_STATUS messages.
211 struct nx_role_request {
212 struct nicira_header nxh;
213 uint32_t role; /* One of NX_ROLE_*. */
217 NX_ROLE_OTHER, /* Default role, full access. */
218 NX_ROLE_MASTER, /* Full access, at most one. */
219 NX_ROLE_SLAVE /* Read-only access. */
222 /* Nicira vendor flow actions. */
224 enum nx_action_subtype {
225 NXAST_SNAT__OBSOLETE, /* No longer used. */
226 NXAST_RESUBMIT, /* struct nx_action_resubmit */
227 NXAST_SET_TUNNEL, /* struct nx_action_set_tunnel */
228 NXAST_DROP_SPOOFED_ARP, /* struct nx_action_drop_spoofed_arp */
229 NXAST_SET_QUEUE, /* struct nx_action_set_queue */
230 NXAST_POP_QUEUE, /* struct nx_action_pop_queue */
231 NXAST_REG_MOVE, /* struct nx_action_reg_move */
232 NXAST_REG_LOAD, /* struct nx_action_reg_load */
233 NXAST_NOTE /* struct nx_action_note */
236 /* Header for Nicira-defined actions. */
237 struct nx_action_header {
238 uint16_t type; /* OFPAT_VENDOR. */
239 uint16_t len; /* Length is 16. */
240 uint32_t vendor; /* NX_VENDOR_ID. */
241 uint16_t subtype; /* NXAST_*. */
244 OFP_ASSERT(sizeof(struct nx_action_header) == 16);
246 /* Action structure for NXAST_RESUBMIT.
248 * NXAST_RESUBMIT searches the flow table again, using a flow that is slightly
249 * modified from the original lookup:
251 * - The 'in_port' member of struct nx_action_resubmit is used as the flow's
254 * - If NXAST_RESUBMIT is preceded by actions that affect the flow
255 * (e.g. OFPAT_SET_VLAN_VID), then the flow is updated with the new
258 * Following the lookup, the original in_port is restored.
260 * If the modified flow matched in the flow table, then the corresponding
261 * actions are executed. Afterward, actions following NXAST_RESUBMIT in the
262 * original set of actions, if any, are executed; any changes made to the
263 * packet (e.g. changes to VLAN) by secondary actions persist when those
264 * actions are executed, although the original in_port is restored.
266 * NXAST_RESUBMIT may be used any number of times within a set of actions.
268 * NXAST_RESUBMIT may nest to an implementation-defined depth. Beyond this
269 * implementation-defined depth, further NXAST_RESUBMIT actions are simply
270 * ignored. (Open vSwitch 1.0.1 and earlier did not support recursion.)
272 struct nx_action_resubmit {
273 uint16_t type; /* OFPAT_VENDOR. */
274 uint16_t len; /* Length is 16. */
275 uint32_t vendor; /* NX_VENDOR_ID. */
276 uint16_t subtype; /* NXAST_RESUBMIT. */
277 uint16_t in_port; /* New in_port for checking flow table. */
280 OFP_ASSERT(sizeof(struct nx_action_resubmit) == 16);
282 /* Action structure for NXAST_SET_TUNNEL.
284 * Sets the encapsulating tunnel ID. */
285 struct nx_action_set_tunnel {
286 uint16_t type; /* OFPAT_VENDOR. */
287 uint16_t len; /* Length is 16. */
288 uint32_t vendor; /* NX_VENDOR_ID. */
289 uint16_t subtype; /* NXAST_SET_TUNNEL. */
291 uint32_t tun_id; /* Tunnel ID. */
293 OFP_ASSERT(sizeof(struct nx_action_set_tunnel) == 16);
295 /* Action structure for NXAST_DROP_SPOOFED_ARP.
297 * Stops processing further actions, if the packet being processed is an
298 * Ethernet+IPv4 ARP packet for which the source Ethernet address inside the
299 * ARP packet differs from the source Ethernet address in the Ethernet header.
301 * This is useful because OpenFlow does not provide a way to match on the
302 * Ethernet addresses inside ARP packets, so there is no other way to drop
303 * spoofed ARPs other than sending every ARP packet to a controller. */
304 struct nx_action_drop_spoofed_arp {
305 uint16_t type; /* OFPAT_VENDOR. */
306 uint16_t len; /* Length is 16. */
307 uint32_t vendor; /* NX_VENDOR_ID. */
308 uint16_t subtype; /* NXAST_DROP_SPOOFED_ARP. */
311 OFP_ASSERT(sizeof(struct nx_action_drop_spoofed_arp) == 16);
313 /* Action structure for NXAST_SET_QUEUE.
315 * Set the queue that should be used when packets are output. This is similar
316 * to the OpenFlow OFPAT_ENQUEUE action, but does not take the output port as
317 * an argument. This allows the queue to be defined before the port is
319 struct nx_action_set_queue {
320 uint16_t type; /* OFPAT_VENDOR. */
321 uint16_t len; /* Length is 16. */
322 uint32_t vendor; /* NX_VENDOR_ID. */
323 uint16_t subtype; /* NXAST_SET_QUEUE. */
325 uint32_t queue_id; /* Where to enqueue packets. */
327 OFP_ASSERT(sizeof(struct nx_action_set_queue) == 16);
329 /* Action structure for NXAST_POP_QUEUE.
331 * Restores the queue to the value it was before any NXAST_SET_QUEUE actions
332 * were used. Only the original queue can be restored this way; no stack is
334 struct nx_action_pop_queue {
335 uint16_t type; /* OFPAT_VENDOR. */
336 uint16_t len; /* Length is 16. */
337 uint32_t vendor; /* NX_VENDOR_ID. */
338 uint16_t subtype; /* NXAST_POP_QUEUE. */
341 OFP_ASSERT(sizeof(struct nx_action_pop_queue) == 16);
343 /* Action structure for NXAST_REG_MOVE.
345 * Copies src[src_ofs:src_ofs+n_bits] to dst[dst_ofs:dst_ofs+n_bits], where
346 * a[b:c] denotes the bits within 'a' numbered 'b' through 'c' (not including
347 * bit 'c'). Bit numbering starts at 0 for the least-significant bit, 1 for
348 * the next most significant bit, and so on.
350 * 'src' and 'dst' are nxm_header values with nxm_hasmask=0. (It doesn't make
351 * sense to use nxm_hasmask=1 because the action does not do any kind of
352 * matching; it uses the actual value of a field.)
354 * The following nxm_header values are potentially acceptable as 'src':
375 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
377 * The following nxm_header values are potentially acceptable as 'dst':
379 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
381 * - NXM_OF_VLAN_TCI. Modifying this field's value has side effects on the
382 * packet's 802.1Q header. Setting a value with CFI=0 removes the 802.1Q
383 * header (if any), ignoring the other bits. Setting a value with CFI=1
384 * adds or modifies the 802.1Q header appropriately, setting the TCI field
385 * to the field's new value (with the CFI bit masked out).
387 * - NXM_NX_TUN_ID. Modifying this value modifies the tunnel ID used for the
388 * packet's next tunnel encapsulation.
390 * A given nxm_header value may be used as 'src' or 'dst' only on a flow whose
391 * nx_match satisfies its prerequisites. For example, NXM_OF_IP_TOS may be
392 * used only if the flow's nx_match includes an nxm_entry that specifies
393 * nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0, and nxm_value=0x0800.
395 * The switch will reject actions for which src_ofs+n_bits is greater than the
396 * width of 'src' or dst_ofs+n_bits is greater than the width of 'dst' with
397 * error type OFPET_BAD_ACTION, code OFPBAC_BAD_ARGUMENT.
399 struct nx_action_reg_move {
400 ovs_be16 type; /* OFPAT_VENDOR. */
401 ovs_be16 len; /* Length is 16. */
402 ovs_be32 vendor; /* NX_VENDOR_ID. */
403 ovs_be16 subtype; /* NXAST_REG_MOVE. */
404 ovs_be16 n_bits; /* Number of bits. */
405 ovs_be16 src_ofs; /* Starting bit offset in source. */
406 ovs_be16 dst_ofs; /* Starting bit offset in destination. */
407 ovs_be32 src; /* Source register. */
408 ovs_be32 dst; /* Destination register. */
410 OFP_ASSERT(sizeof(struct nx_action_reg_move) == 24);
412 /* Action structure for NXAST_REG_LOAD.
414 * Copies value[0:n_bits] to dst[ofs:ofs+n_bits], where a[b:c] denotes the bits
415 * within 'a' numbered 'b' through 'c' (not including bit 'c'). Bit numbering
416 * starts at 0 for the least-significant bit, 1 for the next most significant
419 * 'dst' is an nxm_header with nxm_hasmask=0. It must be one of the following:
421 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
423 * The 'ofs' and 'n_bits' fields are combined into a single 'ofs_nbits' field
424 * to avoid enlarging the structure by another 8 bytes. To allow 'n_bits' to
425 * take a value between 1 and 64 (inclusive) while taking up only 6 bits, it is
426 * also stored as one less than its true value:
429 * +------------------------------+------------------+
430 * | ofs | n_bits - 1 |
431 * +------------------------------+------------------+
433 * The switch will reject actions for which ofs+n_bits is greater than the
434 * width of 'dst', or in which any bits in 'value' with value 2**n_bits or
435 * greater are set to 1, with error type OFPET_BAD_ACTION, code
436 * OFPBAC_BAD_ARGUMENT.
438 struct nx_action_reg_load {
439 ovs_be16 type; /* OFPAT_VENDOR. */
440 ovs_be16 len; /* Length is 16. */
441 ovs_be32 vendor; /* NX_VENDOR_ID. */
442 ovs_be16 subtype; /* NXAST_REG_LOAD. */
443 ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */
444 ovs_be32 dst; /* Destination register. */
445 ovs_be64 value; /* Immediate value. */
447 OFP_ASSERT(sizeof(struct nx_action_reg_load) == 24);
449 /* Action structure for NXAST_NOTE.
451 * This action has no effect. It is variable length. The switch does not
452 * attempt to interpret the user-defined 'note' data in any way. A controller
453 * can use this action to attach arbitrary metadata to a flow.
455 * This action might go away in the future.
457 struct nx_action_note {
458 uint16_t type; /* OFPAT_VENDOR. */
459 uint16_t len; /* A multiple of 8, but at least 16. */
460 uint32_t vendor; /* NX_VENDOR_ID. */
461 uint16_t subtype; /* NXAST_NOTE. */
462 uint8_t note[6]; /* Start of user-defined data. */
463 /* Possibly followed by additional user-defined data. */
465 OFP_ASSERT(sizeof(struct nx_action_note) == 16);
467 /* Wildcard for tunnel ID. */
468 #define NXFW_TUN_ID (1 << 25)
470 #define NXFW_ALL NXFW_TUN_ID
471 #define OVSFW_ALL (OFPFW_ALL | NXFW_ALL)
473 /* Flexible flow specifications (aka NXM = Nicira Extended Match).
475 * OpenFlow 1.0 has "struct ofp_match" for specifying flow matches. This
476 * structure is fixed-length and hence difficult to extend. This section
477 * describes a more flexible, variable-length flow match, called "nx_match" for
478 * short, that is also supported by Open vSwitch. This section also defines a
479 * replacement for each OpenFlow message that includes struct ofp_match.
485 * An nx_match is a sequence of zero or more "nxm_entry"s, which are
486 * type-length-value (TLV) entries, each 5 to 259 (inclusive) bytes long.
487 * "nxm_entry"s are not aligned on or padded to any multibyte boundary. The
488 * first 4 bytes of an nxm_entry are its "header", followed by the entry's
491 * An nxm_entry's header is interpreted as a 32-bit word in network byte order:
493 * |<-------------------- nxm_type ------------------>|
496 * +----------------------------------+---------------+--+------------------+
497 * | nxm_vendor | nxm_field |hm| nxm_length |
498 * +----------------------------------+---------------+--+------------------+
500 * The most-significant 23 bits of the header are collectively "nxm_type".
501 * Bits 16...31 are "nxm_vendor", one of the NXM_VENDOR_* values below. Bits
502 * 9...15 are "nxm_field", which is a vendor-specific value. nxm_type normally
503 * designates a protocol header, such as the Ethernet type, but it can also
504 * refer to packet metadata, such as the switch port on which a packet arrived.
506 * Bit 8 is "nxm_hasmask" (labeled "hm" above for space reasons). The meaning
507 * of this bit is explained later.
509 * The least-significant 8 bits are "nxm_length", a positive integer. The
510 * length of the nxm_entry, including the header, is exactly 4 + nxm_length
513 * For a given nxm_vendor, nxm_field, and nxm_hasmask value, nxm_length is a
514 * constant. It is included only to allow software to minimally parse
515 * "nxm_entry"s of unknown types. (Similarly, for a given nxm_vendor,
516 * nxm_field, and nxm_length, nxm_hasmask is a constant.)
522 * A zero-length nx_match (one with no "nxm_entry"s) matches every packet.
524 * An nxm_entry places a constraint on the packets matched by the nx_match:
526 * - If nxm_hasmask is 0, the nxm_entry's body contains a value for the
527 * field, called "nxm_value". The nx_match matches only packets in which
528 * the field equals nxm_value.
530 * - If nxm_hasmask is 1, then the nxm_entry's body contains a value for the
531 * field (nxm_value), followed by a bitmask of the same length as the
532 * value, called "nxm_mask". For each 1-bit in position J in nxm_mask, the
533 * nx_match matches only packets for which bit J in the given field's value
534 * matches bit J in nxm_value. A 0-bit in nxm_mask causes the
535 * corresponding bits in nxm_value and the field's value to be ignored.
536 * (The sense of the nxm_mask bits is the opposite of that used by the
537 * "wildcards" member of struct ofp_match.)
539 * When nxm_hasmask is 1, nxm_length is always even.
541 * An all-zero-bits nxm_mask is equivalent to omitting the nxm_entry
542 * entirely. An all-one-bits nxm_mask is equivalent to specifying 0 for
545 * When there are multiple "nxm_entry"s, all of the constraints must be met.
551 * Masks may be restricted:
553 * - Some nxm_types may not support masked wildcards, that is, nxm_hasmask
554 * must always be 0 when these fields are specified. For example, the
555 * field that identifies the port on which a packet was received may not be
558 * - Some nxm_types that do support masked wildcards may only support certain
559 * nxm_mask patterns. For example, fields that have IPv4 address values
560 * may be restricted to CIDR masks.
562 * These restrictions should be noted in specifications for individual fields.
563 * A switch may accept an nxm_hasmask or nxm_mask value that the specification
564 * disallows, if the switch correctly implements support for that nxm_hasmask
565 * or nxm_mask value. A switch must reject an attempt to set up a flow that
566 * contains a nxm_hasmask or nxm_mask value that it does not support.
569 * Prerequisite Restrictions
570 * =========================
572 * The presence of an nxm_entry with a given nxm_type may be restricted based
573 * on the presence of or values of other "nxm_entry"s. For example:
575 * - An nxm_entry for nxm_type=NXM_OF_IP_TOS is allowed only if it is
576 * preceded by another entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
577 * and nxm_value=0x0800. That is, matching on the IP source address is
578 * allowed only if the Ethernet type is explicitly set to IP.
580 * - An nxm_entry for nxm_type=NXM_OF_TCP_SRC is allowed only if it is preced
581 * by an entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
582 * nxm_value=0x0800 and another with nxm_type=NXM_OF_IP_PROTO,
583 * nxm_hasmask=0, nxm_value=6, in that order. That is, matching on the TCP
584 * source port is allowed only if the Ethernet type is IP and the IP
587 * These restrictions should be noted in specifications for individual fields.
588 * A switch may implement relaxed versions of these restrictions. A switch
589 * must reject an attempt to set up a flow that violates its restrictions.
592 * Ordering Restrictions
593 * =====================
595 * An nxm_entry that has prerequisite restrictions must appear after the
596 * "nxm_entry"s for its prerequisites. Ordering of "nxm_entry"s within an
597 * nx_match is not otherwise constrained.
599 * Any given nxm_type may appear in an nx_match at most once.
605 * These examples show the format of a single nxm_entry with particular
606 * nxm_hasmask and nxm_length values. The diagrams are labeled with field
607 * numbers and byte indexes.
610 * 8-bit nxm_value, nxm_hasmask=1, nxm_length=1:
613 * +------------+---+---+
615 * +------------+---+---+
618 * 16-bit nxm_value, nxm_hasmask=0, nxm_length=2:
621 * +------------+------+
623 * +------------+------+
626 * 32-bit nxm_value, nxm_hasmask=0, nxm_length=4:
629 * +------------+-------------+
630 * | header | nxm_value |
631 * +------------+-------------+
634 * 48-bit nxm_value, nxm_hasmask=0, nxm_length=6:
637 * +------------+------------------+
638 * | header | nxm_value |
639 * +------------+------------------+
642 * 48-bit nxm_value, nxm_hasmask=1, nxm_length=12:
645 * +------------+------------------+------------------+
646 * | header | nxm_value | nxm_mask |
647 * +------------+------------------+------------------+
653 * A switch should report an error in an nx_match using error type
654 * OFPET_BAD_REQUEST and one of the NXBRC_NXM_* codes. Ideally the switch
655 * should report a specific error code, if one is assigned for the particular
656 * problem, but NXBRC_NXM_INVALID is also available to report a generic
660 #define NXM_HEADER__(VENDOR, FIELD, HASMASK, LENGTH) \
661 (((VENDOR) << 16) | ((FIELD) << 9) | ((HASMASK) << 8) | (LENGTH))
662 #define NXM_HEADER(VENDOR, FIELD, LENGTH) \
663 NXM_HEADER__(VENDOR, FIELD, 0, LENGTH)
664 #define NXM_HEADER_W(VENDOR, FIELD, LENGTH) \
665 NXM_HEADER__(VENDOR, FIELD, 1, (LENGTH) * 2)
666 #define NXM_VENDOR(HEADER) ((HEADER) >> 16)
667 #define NXM_FIELD(HEADER) (((HEADER) >> 9) & 0x7f)
668 #define NXM_TYPE(HEADER) (((HEADER) >> 9) & 0x7fffff)
669 #define NXM_HASMASK(HEADER) (((HEADER) >> 8) & 1)
670 #define NXM_LENGTH(HEADER) ((HEADER) & 0xff)
672 #define NXM_MAKE_WILD_HEADER(HEADER) \
673 NXM_HEADER_W(NXM_VENDOR(HEADER), NXM_FIELD(HEADER), NXM_LENGTH(HEADER))
675 /* ## ------------------------------- ## */
676 /* ## OpenFlow 1.0-compatible fields. ## */
677 /* ## ------------------------------- ## */
679 /* Physical or virtual port on which the packet was received.
683 * Format: 16-bit integer in network byte order.
685 * Masking: Not maskable. */
686 #define NXM_OF_IN_PORT NXM_HEADER (0x0000, 0, 2)
688 /* Source or destination address in Ethernet header.
692 * Format: 48-bit Ethernet MAC address.
694 * Masking: The nxm_mask patterns 01:00:00:00:00:00 and FE:FF:FF:FF:FF:FF must
695 * be supported for NXM_OF_ETH_DST_W (as well as the trivial patterns that
696 * are all-0-bits or all-1-bits). Support for other patterns and for masking
697 * of NXM_OF_ETH_SRC is optional. */
698 #define NXM_OF_ETH_DST NXM_HEADER (0x0000, 1, 6)
699 #define NXM_OF_ETH_DST_W NXM_HEADER_W(0x0000, 1, 6)
700 #define NXM_OF_ETH_SRC NXM_HEADER (0x0000, 2, 6)
702 /* Packet's Ethernet type.
704 * For an Ethernet II packet this is taken from the Ethernet header. For an
705 * 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP header.
706 * A packet that has neither format has value 0x05ff
707 * (OFP_DL_TYPE_NOT_ETH_TYPE).
709 * For a packet with an 802.1Q header, this is the type of the encapsulated
714 * Format: 16-bit integer in network byte order.
716 * Masking: Not maskable. */
717 #define NXM_OF_ETH_TYPE NXM_HEADER (0x0000, 3, 2)
721 * For a packet with an 802.1Q header, this is the Tag Control Information
722 * (TCI) field, with the CFI bit forced to 1. For a packet with no 802.1Q
723 * header, this has value 0.
727 * Format: 16-bit integer in network byte order.
729 * Masking: Arbitrary masks.
731 * This field can be used in various ways:
733 * - If it is not constrained at all, the nx_match matches packets without
734 * an 802.1Q header or with an 802.1Q header that has any TCI value.
736 * - Testing for an exact match with 0 matches only packets without an
739 * - Testing for an exact match with a TCI value with CFI=1 matches packets
740 * that have an 802.1Q header with a specified VID and PCP.
742 * - Testing for an exact match with a nonzero TCI value with CFI=0 does
743 * not make sense. The switch may reject this combination.
745 * - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
746 * packets that have an 802.1Q header with that VID (and any PCP).
748 * - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
749 * packets that have an 802.1Q header with that PCP (and any VID).
751 * - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no 802.1Q
752 * header or with an 802.1Q header with a VID of 0.
754 #define NXM_OF_VLAN_TCI NXM_HEADER (0x0000, 4, 2)
755 #define NXM_OF_VLAN_TCI_W NXM_HEADER_W(0x0000, 4, 2)
757 /* The "type of service" byte of the IP header, with the ECN bits forced to 0.
759 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
761 * Format: 8-bit integer with 2 least-significant bits forced to 0.
763 * Masking: Not maskable. */
764 #define NXM_OF_IP_TOS NXM_HEADER (0x0000, 5, 1)
766 /* The "protocol" byte in the IP header.
768 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
770 * Format: 8-bit integer.
772 * Masking: Not maskable. */
773 #define NXM_OF_IP_PROTO NXM_HEADER (0x0000, 6, 1)
775 /* The source or destination address in the IP header.
777 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
779 * Format: 32-bit integer in network byte order.
781 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
782 * high-order bits set to 1 and the other 32-N bits set to 0. */
783 #define NXM_OF_IP_SRC NXM_HEADER (0x0000, 7, 4)
784 #define NXM_OF_IP_SRC_W NXM_HEADER_W(0x0000, 7, 4)
785 #define NXM_OF_IP_DST NXM_HEADER (0x0000, 8, 4)
786 #define NXM_OF_IP_DST_W NXM_HEADER_W(0x0000, 8, 4)
788 /* The source or destination port in the TCP header.
791 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
792 * NXM_OF_IP_PROTO must match 6 exactly.
794 * Format: 16-bit integer in network byte order.
796 * Masking: Not maskable. */
797 #define NXM_OF_TCP_SRC NXM_HEADER (0x0000, 9, 2)
798 #define NXM_OF_TCP_DST NXM_HEADER (0x0000, 10, 2)
800 /* The source or destination port in the UDP header.
803 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
804 * NXM_OF_IP_PROTO must match 17 exactly.
806 * Format: 16-bit integer in network byte order.
808 * Masking: Not maskable. */
809 #define NXM_OF_UDP_SRC NXM_HEADER (0x0000, 11, 2)
810 #define NXM_OF_UDP_DST NXM_HEADER (0x0000, 12, 2)
812 /* The type or code in the ICMP header.
815 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
816 * NXM_OF_IP_PROTO must match 1 exactly.
818 * Format: 8-bit integer.
820 * Masking: Not maskable. */
821 #define NXM_OF_ICMP_TYPE NXM_HEADER (0x0000, 13, 1)
822 #define NXM_OF_ICMP_CODE NXM_HEADER (0x0000, 14, 1)
826 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
827 * otherwise. Only ARP opcodes between 1 and 255 should be specified for
830 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
832 * Format: 16-bit integer in network byte order.
834 * Masking: Not maskable. */
835 #define NXM_OF_ARP_OP NXM_HEADER (0x0000, 15, 2)
837 /* For an Ethernet+IP ARP packet, the source or target protocol address
838 * in the ARP header. Always 0 otherwise.
840 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
842 * Format: 32-bit integer in network byte order.
844 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
845 * high-order bits set to 1 and the other 32-N bits set to 0. */
846 #define NXM_OF_ARP_SPA NXM_HEADER (0x0000, 16, 4)
847 #define NXM_OF_ARP_SPA_W NXM_HEADER_W(0x0000, 16, 4)
848 #define NXM_OF_ARP_TPA NXM_HEADER (0x0000, 17, 4)
849 #define NXM_OF_ARP_TPA_W NXM_HEADER_W(0x0000, 17, 4)
851 /* ## ------------------------ ## */
852 /* ## Nicira match extensions. ## */
853 /* ## ------------------------ ## */
855 /* Metadata registers.
857 * Registers initially have value 0. Actions allow register values to be
862 * Format: Array of 32-bit integer registers. Space is reserved for up to
863 * NXM_NX_MAX_REGS registers, but switches may implement fewer.
865 * Masking: Arbitrary masks. */
866 #define NXM_NX_MAX_REGS 16
867 #define NXM_NX_REG(IDX) NXM_HEADER (0x0001, IDX, 4)
868 #define NXM_NX_REG_W(IDX) NXM_HEADER_W(0x0001, IDX, 4)
869 #define NXM_NX_REG_IDX(HEADER) NXM_FIELD(HEADER)
870 #define NXM_IS_NX_REG(HEADER) (!((((HEADER) ^ NXM_NX_REG0)) & 0xffffe1ff))
871 #define NXM_IS_NX_REG_W(HEADER) (!((((HEADER) ^ NXM_NX_REG0_W)) & 0xffffe1ff))
872 #define NXM_NX_REG0 NXM_HEADER (0x0001, 0, 4)
873 #define NXM_NX_REG0_W NXM_HEADER_W(0x0001, 0, 4)
874 #define NXM_NX_REG1 NXM_HEADER (0x0001, 1, 4)
875 #define NXM_NX_REG1_W NXM_HEADER_W(0x0001, 1, 4)
876 #define NXM_NX_REG2 NXM_HEADER (0x0001, 2, 4)
877 #define NXM_NX_REG2_W NXM_HEADER_W(0x0001, 2, 4)
878 #define NXM_NX_REG3 NXM_HEADER (0x0001, 3, 4)
879 #define NXM_NX_REG3_W NXM_HEADER_W(0x0001, 3, 4)
883 * For a packet received via GRE tunnel including a (32-bit) key, the key is
884 * stored in the low 32-bits and the high bits are zeroed. For other packets,
889 * Format: 64-bit integer in network byte order.
891 * Masking: Arbitrary masks. */
892 #define NXM_NX_TUN_ID NXM_HEADER (0x0001, 16, 8)
893 #define NXM_NX_TUN_ID_W NXM_HEADER_W(0x0001, 16, 8)
895 /* ## --------------------- ## */
896 /* ## Requests and replies. ## */
897 /* ## --------------------- ## */
899 enum nx_flow_format {
900 NXFF_OPENFLOW10 = 0, /* Standard OpenFlow 1.0 compatible. */
901 NXFF_TUN_ID_FROM_COOKIE = 1, /* OpenFlow 1.0, plus obtain tunnel ID from
903 NXFF_NXM = 2 /* Nicira extended match. */
906 /* NXT_SET_FLOW_FORMAT request. */
907 struct nxt_set_flow_format {
908 struct ofp_header header;
909 ovs_be32 vendor; /* NX_VENDOR_ID. */
910 ovs_be32 subtype; /* NXT_SET_FLOW_FORMAT. */
911 ovs_be32 format; /* One of NXFF_*. */
913 OFP_ASSERT(sizeof(struct nxt_set_flow_format) == 20);
915 /* NXT_FLOW_MOD (analogous to OFPT_FLOW_MOD). */
917 struct nicira_header nxh;
918 ovs_be64 cookie; /* Opaque controller-issued identifier. */
919 ovs_be16 command; /* One of OFPFC_*. */
920 ovs_be16 idle_timeout; /* Idle time before discarding (seconds). */
921 ovs_be16 hard_timeout; /* Max time before discarding (seconds). */
922 ovs_be16 priority; /* Priority level of flow entry. */
923 ovs_be32 buffer_id; /* Buffered packet to apply to (or -1).
924 Not meaningful for OFPFC_DELETE*. */
925 ovs_be16 out_port; /* For OFPFC_DELETE* commands, require
926 matching entries to include this as an
927 output port. A value of OFPP_NONE
928 indicates no restriction. */
929 ovs_be16 flags; /* One of OFPFF_*. */
930 ovs_be16 match_len; /* Size of nx_match. */
931 uint8_t pad[6]; /* Align to 64-bits. */
933 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
934 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
935 * all-zero bytes, then
936 * - Actions to fill out the remainder of the message length (always a
940 OFP_ASSERT(sizeof(struct nx_flow_mod) == 48);
942 /* NXT_FLOW_REMOVED (analogous to OFPT_FLOW_REMOVED). */
943 struct nx_flow_removed {
944 struct nicira_header nxh;
945 ovs_be64 cookie; /* Opaque controller-issued identifier. */
946 ovs_be16 priority; /* Priority level of flow entry. */
947 uint8_t reason; /* One of OFPRR_*. */
948 uint8_t pad[1]; /* Align to 32-bits. */
949 ovs_be32 duration_sec; /* Time flow was alive in seconds. */
950 ovs_be32 duration_nsec; /* Time flow was alive in nanoseconds beyond
952 ovs_be16 idle_timeout; /* Idle timeout from original flow mod. */
953 ovs_be16 match_len; /* Size of nx_match. */
954 ovs_be64 packet_count;
957 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
958 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
961 OFP_ASSERT(sizeof(struct nx_flow_removed) == 56);
963 /* Nicira vendor stats request of type NXST_FLOW (analogous to OFPST_FLOW
965 struct nx_flow_stats_request {
966 struct nicira_stats_msg nsm;
967 ovs_be16 out_port; /* Require matching entries to include this
968 as an output port. A value of OFPP_NONE
969 indicates no restriction. */
970 ovs_be16 match_len; /* Length of nx_match. */
971 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
972 or 0xff for all tables. */
973 uint8_t pad[3]; /* Align to 64 bits. */
975 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
976 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
977 * all-zero bytes, which must also exactly fill out the length of the
981 OFP_ASSERT(sizeof(struct nx_flow_stats_request) == 32);
983 /* Body for Nicira vendor stats reply of type NXST_FLOW (analogous to
984 * OFPST_FLOW reply). */
985 struct nx_flow_stats {
986 ovs_be16 length; /* Length of this entry. */
987 uint8_t table_id; /* ID of table flow came from. */
989 ovs_be32 duration_sec; /* Time flow has been alive in seconds. */
990 ovs_be32 duration_nsec; /* Time flow has been alive in nanoseconds
991 beyond duration_sec. */
992 ovs_be16 priority; /* Priority of the entry. Only meaningful
993 when this is not an exact-match entry. */
994 ovs_be16 idle_timeout; /* Number of seconds idle before expiration. */
995 ovs_be16 hard_timeout; /* Number of seconds before expiration. */
996 ovs_be16 match_len; /* Length of nx_match. */
997 uint8_t pad2[4]; /* Align to 64 bits. */
998 ovs_be64 cookie; /* Opaque controller-issued identifier. */
999 ovs_be64 packet_count; /* Number of packets in flow. */
1000 ovs_be64 byte_count; /* Number of bytes in flow. */
1002 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1003 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1004 * all-zero bytes, then
1005 * - Actions to fill out the remainder 'length' bytes (always a multiple
1009 OFP_ASSERT(sizeof(struct nx_flow_stats) == 48);
1011 /* Nicira vendor stats request of type NXST_AGGREGATE (analogous to
1012 * OFPST_AGGREGATE request). */
1013 struct nx_aggregate_stats_request {
1014 struct nicira_stats_msg nsm;
1015 ovs_be16 out_port; /* Require matching entries to include this
1016 as an output port. A value of OFPP_NONE
1017 indicates no restriction. */
1018 ovs_be16 match_len; /* Length of nx_match. */
1019 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
1020 or 0xff for all tables. */
1021 uint8_t pad[3]; /* Align to 64 bits. */
1023 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1024 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1025 * all-zero bytes, which must also exactly fill out the length of the
1029 OFP_ASSERT(sizeof(struct nx_aggregate_stats_request) == 32);
1031 /* Body for nicira_stats_msg reply of type NXST_AGGREGATE (analogous to
1032 * OFPST_AGGREGATE reply).
1034 * ofp_aggregate_stats_reply does not contain an ofp_match structure, so we
1035 * reuse it entirely. (It would be very odd to use OFPST_AGGREGATE to reply to
1036 * an NXST_AGGREGATE request, so we don't do that.) */
1037 struct nx_aggregate_stats_reply {
1038 struct nicira_stats_msg nsm;
1039 struct ofp_aggregate_stats_reply asr;
1041 OFP_ASSERT(sizeof(struct nx_aggregate_stats_reply) == 48);
1043 #endif /* openflow/nicira-ext.h */