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 also do not receive asynchronous messages
209 * (OFPT_PACKET_IN, OFPT_FLOW_REMOVED, OFPT_PORT_STATUS).
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 */
235 /* Header for Nicira-defined actions. */
236 struct nx_action_header {
237 uint16_t type; /* OFPAT_VENDOR. */
238 uint16_t len; /* Length is 16. */
239 uint32_t vendor; /* NX_VENDOR_ID. */
240 uint16_t subtype; /* NXAST_*. */
243 OFP_ASSERT(sizeof(struct nx_action_header) == 16);
245 /* Action structure for NXAST_RESUBMIT.
247 * NXAST_RESUBMIT searches the flow table again, using a flow that is slightly
248 * modified from the original lookup:
250 * - The 'in_port' member of struct nx_action_resubmit is used as the flow's
253 * - If NXAST_RESUBMIT is preceded by actions that affect the flow
254 * (e.g. OFPAT_SET_VLAN_VID), then the flow is updated with the new
257 * Following the lookup, the original in_port is restored.
259 * If the modified flow matched in the flow table, then the corresponding
260 * actions are executed. Afterward, actions following NXAST_RESUBMIT in the
261 * original set of actions, if any, are executed; any changes made to the
262 * packet (e.g. changes to VLAN) by secondary actions persist when those
263 * actions are executed, although the original in_port is restored.
265 * NXAST_RESUBMIT may be used any number of times within a set of actions.
267 * NXAST_RESUBMIT may nest to an implementation-defined depth. Beyond this
268 * implementation-defined depth, further NXAST_RESUBMIT actions are simply
269 * ignored. (Open vSwitch 1.0.1 and earlier did not support recursion.)
271 struct nx_action_resubmit {
272 uint16_t type; /* OFPAT_VENDOR. */
273 uint16_t len; /* Length is 16. */
274 uint32_t vendor; /* NX_VENDOR_ID. */
275 uint16_t subtype; /* NXAST_RESUBMIT. */
276 uint16_t in_port; /* New in_port for checking flow table. */
279 OFP_ASSERT(sizeof(struct nx_action_resubmit) == 16);
281 /* Action structure for NXAST_SET_TUNNEL.
283 * Sets the encapsulating tunnel ID. */
284 struct nx_action_set_tunnel {
285 uint16_t type; /* OFPAT_VENDOR. */
286 uint16_t len; /* Length is 16. */
287 uint32_t vendor; /* NX_VENDOR_ID. */
288 uint16_t subtype; /* NXAST_SET_TUNNEL. */
290 uint32_t tun_id; /* Tunnel ID. */
292 OFP_ASSERT(sizeof(struct nx_action_set_tunnel) == 16);
294 /* Action structure for NXAST_DROP_SPOOFED_ARP.
296 * Stops processing further actions, if the packet being processed is an
297 * Ethernet+IPv4 ARP packet for which the source Ethernet address inside the
298 * ARP packet differs from the source Ethernet address in the Ethernet header.
300 * This is useful because OpenFlow does not provide a way to match on the
301 * Ethernet addresses inside ARP packets, so there is no other way to drop
302 * spoofed ARPs other than sending every ARP packet to a controller. */
303 struct nx_action_drop_spoofed_arp {
304 uint16_t type; /* OFPAT_VENDOR. */
305 uint16_t len; /* Length is 16. */
306 uint32_t vendor; /* NX_VENDOR_ID. */
307 uint16_t subtype; /* NXAST_DROP_SPOOFED_ARP. */
310 OFP_ASSERT(sizeof(struct nx_action_drop_spoofed_arp) == 16);
312 /* Action structure for NXAST_SET_QUEUE.
314 * Set the queue that should be used when packets are output. This is similar
315 * to the OpenFlow OFPAT_ENQUEUE action, but does not take the output port as
316 * an argument. This allows the queue to be defined before the port is
318 struct nx_action_set_queue {
319 uint16_t type; /* OFPAT_VENDOR. */
320 uint16_t len; /* Length is 16. */
321 uint32_t vendor; /* NX_VENDOR_ID. */
322 uint16_t subtype; /* NXAST_SET_QUEUE. */
324 uint32_t queue_id; /* Where to enqueue packets. */
326 OFP_ASSERT(sizeof(struct nx_action_set_queue) == 16);
328 /* Action structure for NXAST_POP_QUEUE.
330 * Restores the queue to the value it was before any NXAST_SET_QUEUE actions
331 * were used. Only the original queue can be restored this way; no stack is
333 struct nx_action_pop_queue {
334 uint16_t type; /* OFPAT_VENDOR. */
335 uint16_t len; /* Length is 16. */
336 uint32_t vendor; /* NX_VENDOR_ID. */
337 uint16_t subtype; /* NXAST_POP_QUEUE. */
340 OFP_ASSERT(sizeof(struct nx_action_pop_queue) == 16);
342 /* Action structure for NXAST_REG_MOVE.
344 * Copies src[src_ofs:src_ofs+n_bits] to dst[dst_ofs:dst_ofs+n_bits], where
345 * a[b:c] denotes the bits within 'a' numbered 'b' through 'c' (not including
346 * bit 'c'). Bit numbering starts at 0 for the least-significant bit, 1 for
347 * the next most significant bit, and so on.
349 * 'src' and 'dst' are nxm_header values with nxm_hasmask=0. The following
350 * nxm_header values are potentially acceptable as 'src':
371 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
373 * The following nxm_header values are potentially acceptable as 'dst':
375 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
377 * - NXM_OF_VLAN_TCI. Modifying this field's value has side effects on the
378 * packet's 802.1Q header. Setting a value with CFI=0 removes the 802.1Q
379 * header (if any), ignoring the other bits. Setting a value with CFI=1
380 * adds or modifies the 802.1Q header appropriately, setting the TCI field
381 * to the field's new value (with the CFI bit masked out).
383 * - NXM_NX_TUN_ID. Modifying this value modifies the tunnel ID used for the
384 * packet's next tunnel encapsulation.
386 * A given nxm_header value may be used as 'src' or 'dst' only on a flow whose
387 * nx_match satisfies its prerequisites. For example, NXM_OF_IP_TOS may be
388 * used only if the flow's nx_match includes an nxm_entry that specifies
389 * nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0, and nxm_value=0x0800.
391 * The switch will reject actions for which src_ofs+n_bits is greater than the
392 * width of 'src' or dst_ofs+n_bits is greater than the width of 'dst' with
393 * error type OFPET_BAD_ACTION, code OFPBAC_BAD_ARGUMENT.
395 struct nx_action_reg_move {
396 ovs_be16 type; /* OFPAT_VENDOR. */
397 ovs_be16 len; /* Length is 16. */
398 ovs_be32 vendor; /* NX_VENDOR_ID. */
399 ovs_be16 subtype; /* NXAST_REG_MOVE. */
400 ovs_be16 n_bits; /* Number of bits. */
401 ovs_be16 src_ofs; /* Starting bit offset in source. */
402 ovs_be16 dst_ofs; /* Starting bit offset in destination. */
403 ovs_be32 src; /* Source register. */
404 ovs_be32 dst; /* Destination register. */
406 OFP_ASSERT(sizeof(struct nx_action_reg_move) == 24);
408 /* Action structure for NXAST_REG_LOAD.
410 * Copies value[0:n_bits] to dst[ofs:ofs+n_bits], where a[b:c] denotes the bits
411 * within 'a' numbered 'b' through 'c' (not including bit 'c'). Bit numbering
412 * starts at 0 for the least-significant bit, 1 for the next most significant
415 * 'dst' must be one of the following:
417 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
419 * The 'ofs' and 'n_bits' fields are combined into a single 'ofs_nbits' field
420 * to avoid enlarging the structure by another 8 bytes. To allow 'n_bits' to
421 * take a value between 1 and 64 (inclusive) while taking up only 6 bits, it is
422 * also stored as one less than its true value:
425 * +------------------------------+------------------+
426 * | ofs | n_bits - 1 |
427 * +------------------------------+------------------+
429 * The switch will reject actions for which ofs+n_bits is greater than the
430 * width of 'dst', or in which any bits in 'value' with value 2**n_bits or
431 * greater are set to 1, with error type OFPET_BAD_ACTION, code
432 * OFPBAC_BAD_ARGUMENT.
434 struct nx_action_reg_load {
435 ovs_be16 type; /* OFPAT_VENDOR. */
436 ovs_be16 len; /* Length is 16. */
437 ovs_be32 vendor; /* NX_VENDOR_ID. */
438 ovs_be16 subtype; /* NXAST_REG_LOAD. */
439 ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */
440 ovs_be32 dst; /* Destination register. */
441 ovs_be64 value; /* Immediate value. */
443 OFP_ASSERT(sizeof(struct nx_action_reg_load) == 24);
445 /* Wildcard for tunnel ID. */
446 #define NXFW_TUN_ID (1 << 25)
448 #define NXFW_ALL NXFW_TUN_ID
449 #define OVSFW_ALL (OFPFW_ALL | NXFW_ALL)
451 /* Flexible flow specifications (aka NXM = Nicira Extended Match).
453 * OpenFlow 1.0 has "struct ofp_match" for specifying flow matches. This
454 * structure is fixed-length and hence difficult to extend. This section
455 * describes a more flexible, variable-length flow match, called "nx_match" for
456 * short, that is also supported by Open vSwitch. This section also defines a
457 * replacement for each OpenFlow message that includes struct ofp_match.
463 * An nx_match is a sequence of zero or more "nxm_entry"s, which are
464 * type-length-value (TLV) entries, each 5 to 259 (inclusive) bytes long.
465 * "nxm_entry"s are not aligned on or padded to any multibyte boundary. The
466 * first 4 bytes of an nxm_entry are its "header", followed by the entry's
469 * An nxm_entry's header is interpreted as a 32-bit word in network byte order:
471 * |<-------------------- nxm_type ------------------>|
474 * +----------------------------------+---------------+--+------------------+
475 * | nxm_vendor | nxm_field |hm| nxm_length |
476 * +----------------------------------+---------------+--+------------------+
478 * The most-significant 23 bits of the header are collectively "nxm_type".
479 * Bits 16...31 are "nxm_vendor", one of the NXM_VENDOR_* values below. Bits
480 * 9...15 are "nxm_field", which is a vendor-specific value. nxm_type normally
481 * designates a protocol header, such as the Ethernet type, but it can also
482 * refer to packet metadata, such as the switch port on which a packet arrived.
484 * Bit 8 is "nxm_hasmask" (labeled "hm" above for space reasons). The meaning
485 * of this bit is explained later.
487 * The least-significant 8 bits are "nxm_length", a positive integer. The
488 * length of the nxm_entry, including the header, is exactly 4 + nxm_length
491 * For a given nxm_vendor, nxm_field, and nxm_hasmask value, nxm_length is a
492 * constant. It is included only to allow software to minimally parse
493 * "nxm_entry"s of unknown types. (Similarly, for a given nxm_vendor,
494 * nxm_field, and nxm_length, nxm_hasmask is a constant.)
500 * A zero-length nx_match (one with no "nxm_entry"s) matches every packet.
502 * An nxm_entry places a constraint on the packets matched by the nx_match:
504 * - If nxm_hasmask is 0, the nxm_entry's body contains a value for the
505 * field, called "nxm_value". The nx_match matches only packets in which
506 * the field equals nxm_value.
508 * - If nxm_hasmask is 1, then the nxm_entry's body contains a value for the
509 * field (nxm_value), followed by a bitmask of the same length as the
510 * value, called "nxm_mask". For each 1-bit in position J in nxm_mask, the
511 * nx_match matches only packets for which bit J in the given field's value
512 * matches bit J in nxm_value. A 0-bit in nxm_mask causes the
513 * corresponding bits in nxm_value and the field's value to be ignored.
514 * (The sense of the nxm_mask bits is the opposite of that used by the
515 * "wildcards" member of struct ofp_match.)
517 * When nxm_hasmask is 1, nxm_length is always even.
519 * An all-zero-bits nxm_mask is equivalent to omitting the nxm_entry
520 * entirely. An all-one-bits nxm_mask is equivalent to specifying 0 for
523 * When there are multiple "nxm_entry"s, all of the constraints must be met.
529 * Masks may be restricted:
531 * - Some nxm_types may not support masked wildcards, that is, nxm_hasmask
532 * must always be 0 when these fields are specified. For example, the
533 * field that identifies the port on which a packet was received may not be
536 * - Some nxm_types that do support masked wildcards may only support certain
537 * nxm_mask patterns. For example, fields that have IPv4 address values
538 * may be restricted to CIDR masks.
540 * These restrictions should be noted in specifications for individual fields.
541 * A switch may accept an nxm_hasmask or nxm_mask value that the specification
542 * disallows, if the switch correctly implements support for that nxm_hasmask
543 * or nxm_mask value. A switch must reject an attempt to set up a flow that
544 * contains a nxm_hasmask or nxm_mask value that it does not support.
547 * Prerequisite Restrictions
548 * =========================
550 * The presence of an nxm_entry with a given nxm_type may be restricted based
551 * on the presence of or values of other "nxm_entry"s. For example:
553 * - An nxm_entry for nxm_type=NXM_OF_IP_TOS is allowed only if it is
554 * preceded by another entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
555 * and nxm_value=0x0800. That is, matching on the IP source address is
556 * allowed only if the Ethernet type is explicitly set to IP.
558 * - An nxm_entry for nxm_type=NXM_OF_TCP_SRC is allowed only if it is preced
559 * by an entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
560 * nxm_value=0x0800 and another with nxm_type=NXM_OF_IP_PROTO,
561 * nxm_hasmask=0, nxm_value=6, in that order. That is, matching on the TCP
562 * source port is allowed only if the Ethernet type is IP and the IP
565 * These restrictions should be noted in specifications for individual fields.
566 * A switch may implement relaxed versions of these restrictions. A switch
567 * must reject an attempt to set up a flow that violates its restrictions.
570 * Ordering Restrictions
571 * =====================
573 * An nxm_entry that has prerequisite restrictions must appear after the
574 * "nxm_entry"s for its prerequisites. Ordering of "nxm_entry"s within an
575 * nx_match is not otherwise constrained.
577 * Any given nxm_type may appear in an nx_match at most once.
583 * These examples show the format of a single nxm_entry with particular
584 * nxm_hasmask and nxm_length values. The diagrams are labeled with field
585 * numbers and byte indexes.
588 * 8-bit nxm_value, nxm_hasmask=1, nxm_length=1:
591 * +------------+---+---+
593 * +------------+---+---+
596 * 16-bit nxm_value, nxm_hasmask=0, nxm_length=2:
599 * +------------+------+
601 * +------------+------+
604 * 32-bit nxm_value, nxm_hasmask=0, nxm_length=4:
607 * +------------+-------------+
608 * | header | nxm_value |
609 * +------------+-------------+
612 * 48-bit nxm_value, nxm_hasmask=0, nxm_length=6:
615 * +------------+------------------+
616 * | header | nxm_value |
617 * +------------+------------------+
620 * 48-bit nxm_value, nxm_hasmask=1, nxm_length=12:
623 * +------------+------------------+------------------+
624 * | header | nxm_value | nxm_mask |
625 * +------------+------------------+------------------+
631 * A switch should report an error in an nx_match using error type
632 * OFPET_BAD_REQUEST and one of the NXBRC_NXM_* codes. Ideally the switch
633 * should report a specific error code, if one is assigned for the particular
634 * problem, but NXBRC_NXM_INVALID is also available to report a generic
638 #define NXM_HEADER__(VENDOR, FIELD, HASMASK, LENGTH) \
639 (((VENDOR) << 16) | ((FIELD) << 9) | ((HASMASK) << 8) | (LENGTH))
640 #define NXM_HEADER(VENDOR, FIELD, LENGTH) \
641 NXM_HEADER__(VENDOR, FIELD, 0, LENGTH)
642 #define NXM_HEADER_W(VENDOR, FIELD, LENGTH) \
643 NXM_HEADER__(VENDOR, FIELD, 1, (LENGTH) * 2)
644 #define NXM_VENDOR(HEADER) ((HEADER) >> 16)
645 #define NXM_FIELD(HEADER) (((HEADER) >> 9) & 0x7f)
646 #define NXM_TYPE(HEADER) (((HEADER) >> 9) & 0x7fffff)
647 #define NXM_HASMASK(HEADER) (((HEADER) >> 8) & 1)
648 #define NXM_LENGTH(HEADER) ((HEADER) & 0xff)
650 #define NXM_MAKE_WILD_HEADER(HEADER) \
651 NXM_HEADER_W(NXM_VENDOR(HEADER), NXM_FIELD(HEADER), NXM_LENGTH(HEADER))
653 /* ## ------------------------------- ## */
654 /* ## OpenFlow 1.0-compatible fields. ## */
655 /* ## ------------------------------- ## */
657 /* Physical or virtual port on which the packet was received.
661 * Format: 16-bit integer in network byte order.
663 * Masking: Not maskable. */
664 #define NXM_OF_IN_PORT NXM_HEADER (0x0000, 0, 2)
666 /* Source or destination address in Ethernet header.
670 * Format: 48-bit Ethernet MAC address.
672 * Masking: The nxm_mask patterns 01:00:00:00:00:00 and FE:FF:FF:FF:FF:FF must
673 * be supported for NXM_OF_ETH_DST_W (as well as the trivial patterns that
674 * are all-0-bits or all-1-bits). Support for other patterns and for masking
675 * of NXM_OF_ETH_SRC is optional. */
676 #define NXM_OF_ETH_DST NXM_HEADER (0x0000, 1, 6)
677 #define NXM_OF_ETH_DST_W NXM_HEADER_W(0x0000, 1, 6)
678 #define NXM_OF_ETH_SRC NXM_HEADER (0x0000, 2, 6)
680 /* Packet's Ethernet type.
682 * For an Ethernet II packet this is taken from the Ethernet header. For an
683 * 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP header.
684 * A packet that has neither format has value 0x05ff
685 * (OFP_DL_TYPE_NOT_ETH_TYPE).
687 * For a packet with an 802.1Q header, this is the type of the encapsulated
692 * Format: 16-bit integer in network byte order.
694 * Masking: Not maskable. */
695 #define NXM_OF_ETH_TYPE NXM_HEADER (0x0000, 3, 2)
699 * For a packet with an 802.1Q header, this is the Tag Control Information
700 * (TCI) field, with the CFI bit forced to 1. For a packet with no 802.1Q
701 * header, this has value 0.
705 * Format: 16-bit integer in network byte order.
707 * Masking: Arbitrary masks.
709 * This field can be used in various ways:
711 * - If it is not constrained at all, the nx_match matches packets without
712 * an 802.1Q header or with an 802.1Q header that has any TCI value.
714 * - Testing for an exact match with 0 matches only packets without an
717 * - Testing for an exact match with a TCI value with CFI=1 matches packets
718 * that have an 802.1Q header with a specified VID and PCP.
720 * - Testing for an exact match with a nonzero TCI value with CFI=0 does
721 * not make sense. The switch may reject this combination.
723 * - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
724 * packets that have an 802.1Q header with that VID (and any PCP).
726 * - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
727 * packets that have an 802.1Q header with that PCP (and any VID).
729 * - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no 802.1Q
730 * header or with an 802.1Q header with a VID of 0.
732 #define NXM_OF_VLAN_TCI NXM_HEADER (0x0000, 4, 2)
733 #define NXM_OF_VLAN_TCI_W NXM_HEADER_W(0x0000, 4, 2)
735 /* The "type of service" byte of the IP header, with the ECN bits forced to 0.
737 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
739 * Format: 8-bit integer with 2 least-significant bits forced to 0.
741 * Masking: Not maskable. */
742 #define NXM_OF_IP_TOS NXM_HEADER (0x0000, 5, 1)
744 /* The "protocol" byte in the IP header.
746 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
748 * Format: 8-bit integer.
750 * Masking: Not maskable. */
751 #define NXM_OF_IP_PROTO NXM_HEADER (0x0000, 6, 1)
753 /* The source or destination address in the IP header.
755 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
757 * Format: 32-bit integer in network byte order.
759 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
760 * high-order bits set to 1 and the other 32-N bits set to 0. */
761 #define NXM_OF_IP_SRC NXM_HEADER (0x0000, 7, 4)
762 #define NXM_OF_IP_SRC_W NXM_HEADER_W(0x0000, 7, 4)
763 #define NXM_OF_IP_DST NXM_HEADER (0x0000, 8, 4)
764 #define NXM_OF_IP_DST_W NXM_HEADER_W(0x0000, 8, 4)
766 /* The source or destination port in the TCP header.
769 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
770 * NXM_OF_IP_PROTO must match 6 exactly.
772 * Format: 16-bit integer in network byte order.
774 * Masking: Not maskable. */
775 #define NXM_OF_TCP_SRC NXM_HEADER (0x0000, 9, 2)
776 #define NXM_OF_TCP_DST NXM_HEADER (0x0000, 10, 2)
778 /* The source or destination port in the UDP header.
781 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
782 * NXM_OF_IP_PROTO must match 17 exactly.
784 * Format: 16-bit integer in network byte order.
786 * Masking: Not maskable. */
787 #define NXM_OF_UDP_SRC NXM_HEADER (0x0000, 11, 2)
788 #define NXM_OF_UDP_DST NXM_HEADER (0x0000, 12, 2)
790 /* The type or code in the ICMP header.
793 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
794 * NXM_OF_IP_PROTO must match 1 exactly.
796 * Format: 8-bit integer.
798 * Masking: Not maskable. */
799 #define NXM_OF_ICMP_TYPE NXM_HEADER (0x0000, 13, 1)
800 #define NXM_OF_ICMP_CODE NXM_HEADER (0x0000, 14, 1)
804 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
805 * otherwise. Only ARP opcodes between 1 and 255 should be specified for
808 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
810 * Format: 16-bit integer in network byte order.
812 * Masking: Not maskable. */
813 #define NXM_OF_ARP_OP NXM_HEADER (0x0000, 15, 2)
815 /* For an Ethernet+IP ARP packet, the source or target protocol address
816 * in the ARP header. Always 0 otherwise.
818 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
820 * Format: 32-bit integer in network byte order.
822 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
823 * high-order bits set to 1 and the other 32-N bits set to 0. */
824 #define NXM_OF_ARP_SPA NXM_HEADER (0x0000, 16, 4)
825 #define NXM_OF_ARP_SPA_W NXM_HEADER_W(0x0000, 16, 4)
826 #define NXM_OF_ARP_TPA NXM_HEADER (0x0000, 17, 4)
827 #define NXM_OF_ARP_TPA_W NXM_HEADER_W(0x0000, 17, 4)
829 /* ## ------------------------ ## */
830 /* ## Nicira match extensions. ## */
831 /* ## ------------------------ ## */
833 /* Metadata registers.
835 * Registers initially have value 0. Actions allow register values to be
840 * Format: Array of 32-bit integer registers. Space is reserved for up to
841 * NXM_NX_MAX_REGS registers, but switches may implement fewer.
843 * Masking: Arbitrary masks. */
844 #define NXM_NX_MAX_REGS 16
845 #define NXM_NX_REG(IDX) NXM_HEADER (0x0001, IDX, 4)
846 #define NXM_NX_REG_W(IDX) NXM_HEADER_W(0x0001, IDX, 4)
847 #define NXM_NX_REG_IDX(HEADER) NXM_FIELD(HEADER)
848 #define NXM_IS_NX_REG(HEADER) (!((((HEADER) ^ NXM_NX_REG(0))) & 0xffffe0ff))
849 #define NXM_NX_REG0 NXM_HEADER (0x0001, 0, 4)
850 #define NXM_NX_REG0_W NXM_HEADER_W(0x0001, 0, 4)
851 #define NXM_NX_REG1 NXM_HEADER (0x0001, 1, 4)
852 #define NXM_NX_REG1_W NXM_HEADER_W(0x0001, 1, 4)
853 #define NXM_NX_REG2 NXM_HEADER (0x0001, 2, 4)
854 #define NXM_NX_REG2_W NXM_HEADER_W(0x0001, 2, 4)
855 #define NXM_NX_REG3 NXM_HEADER (0x0001, 3, 4)
856 #define NXM_NX_REG3_W NXM_HEADER_W(0x0001, 3, 4)
860 * For a packet received via GRE tunnel including a (32-bit) key, the key is
861 * stored in the low 32-bits and the high bits are zeroed. For other packets,
866 * Format: 64-bit integer in network byte order.
868 * Masking: Arbitrary masks. */
869 #define NXM_NX_TUN_ID NXM_HEADER (0x0001, 16, 8)
870 #define NXM_NX_TUN_ID_W NXM_HEADER_W(0x0001, 16, 8)
872 /* ## --------------------- ## */
873 /* ## Requests and replies. ## */
874 /* ## --------------------- ## */
877 NXFF_OPENFLOW10 = 0, /* Standard OpenFlow 1.0 compatible. */
878 NXFF_TUN_ID_FROM_COOKIE = 1, /* OpenFlow 1.0, plus obtain tunnel ID from
880 NXFF_NXM = 2 /* Nicira extended match. */
883 /* NXT_SET_FLOW_FORMAT request. */
884 struct nxt_set_flow_format {
885 struct ofp_header header;
886 ovs_be32 vendor; /* NX_VENDOR_ID. */
887 ovs_be32 subtype; /* NXT_SET_FLOW_FORMAT. */
888 ovs_be32 format; /* One of NXFF_*. */
890 OFP_ASSERT(sizeof(struct nxt_set_flow_format) == 20);
892 /* NXT_FLOW_MOD (analogous to OFPT_FLOW_MOD). */
894 struct nicira_header nxh;
895 ovs_be64 cookie; /* Opaque controller-issued identifier. */
896 ovs_be16 command; /* One of OFPFC_*. */
897 ovs_be16 idle_timeout; /* Idle time before discarding (seconds). */
898 ovs_be16 hard_timeout; /* Max time before discarding (seconds). */
899 ovs_be16 priority; /* Priority level of flow entry. */
900 ovs_be32 buffer_id; /* Buffered packet to apply to (or -1).
901 Not meaningful for OFPFC_DELETE*. */
902 ovs_be16 out_port; /* For OFPFC_DELETE* commands, require
903 matching entries to include this as an
904 output port. A value of OFPP_NONE
905 indicates no restriction. */
906 ovs_be16 flags; /* One of OFPFF_*. */
907 ovs_be16 match_len; /* Size of nx_match. */
908 uint8_t pad[6]; /* Align to 64-bits. */
910 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
911 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
912 * all-zero bytes, then
913 * - Actions to fill out the remainder of the message length (always a
917 OFP_ASSERT(sizeof(struct nx_flow_mod) == 48);
919 /* NXT_FLOW_REMOVED (analogous to OFPT_FLOW_REMOVED). */
920 struct nx_flow_removed {
921 struct nicira_header nxh;
922 ovs_be64 cookie; /* Opaque controller-issued identifier. */
923 ovs_be16 priority; /* Priority level of flow entry. */
924 uint8_t reason; /* One of OFPRR_*. */
925 uint8_t pad[1]; /* Align to 32-bits. */
926 ovs_be32 duration_sec; /* Time flow was alive in seconds. */
927 ovs_be32 duration_nsec; /* Time flow was alive in nanoseconds beyond
929 ovs_be16 idle_timeout; /* Idle timeout from original flow mod. */
930 ovs_be16 match_len; /* Size of nx_match. */
931 ovs_be64 packet_count;
934 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
935 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
938 OFP_ASSERT(sizeof(struct nx_flow_removed) == 56);
940 /* Nicira vendor stats request of type NXST_FLOW (analogous to OFPST_FLOW
942 struct nx_flow_stats_request {
943 struct nicira_stats_msg nsm;
944 ovs_be16 out_port; /* Require matching entries to include this
945 as an output port. A value of OFPP_NONE
946 indicates no restriction. */
947 ovs_be16 match_len; /* Length of nx_match. */
948 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
949 or 0xff for all tables. */
950 uint8_t pad[3]; /* Align to 64 bits. */
952 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
953 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
954 * all-zero bytes, which must also exactly fill out the length of the
958 OFP_ASSERT(sizeof(struct nx_flow_stats_request) == 32);
960 /* Body for Nicira vendor stats reply of type NXST_FLOW (analogous to
961 * OFPST_FLOW reply). */
962 struct nx_flow_stats {
963 ovs_be16 length; /* Length of this entry. */
964 uint8_t table_id; /* ID of table flow came from. */
966 ovs_be32 duration_sec; /* Time flow has been alive in seconds. */
967 ovs_be32 duration_nsec; /* Time flow has been alive in nanoseconds
968 beyond duration_sec. */
969 ovs_be16 priority; /* Priority of the entry. Only meaningful
970 when this is not an exact-match entry. */
971 ovs_be16 idle_timeout; /* Number of seconds idle before expiration. */
972 ovs_be16 hard_timeout; /* Number of seconds before expiration. */
973 ovs_be16 match_len; /* Length of nx_match. */
974 uint8_t pad2[4]; /* Align to 64 bits. */
975 ovs_be64 cookie; /* Opaque controller-issued identifier. */
976 ovs_be64 packet_count; /* Number of packets in flow. */
977 ovs_be64 byte_count; /* Number of bytes in flow. */
979 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
980 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
981 * all-zero bytes, then
982 * - Actions to fill out the remainder 'length' bytes (always a multiple
986 OFP_ASSERT(sizeof(struct nx_flow_stats) == 48);
988 /* Nicira vendor stats request of type NXST_AGGREGATE (analogous to
989 * OFPST_AGGREGATE request). */
990 struct nx_aggregate_stats_request {
991 struct nicira_stats_msg nsm;
992 ovs_be16 out_port; /* Require matching entries to include this
993 as an output port. A value of OFPP_NONE
994 indicates no restriction. */
995 ovs_be16 match_len; /* Length of nx_match. */
996 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
997 or 0xff for all tables. */
998 uint8_t pad[3]; /* Align to 64 bits. */
1000 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1001 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1002 * all-zero bytes, which must also exactly fill out the length of the
1006 OFP_ASSERT(sizeof(struct nx_aggregate_stats_request) == 32);
1008 /* Body for nicira_stats_msg reply of type NXST_AGGREGATE (analogous to
1009 * OFPST_AGGREGATE reply).
1011 * ofp_aggregate_stats_reply does not contain an ofp_match structure, so we
1012 * reuse it entirely. (It would be very odd to use OFPST_AGGREGATE to reply to
1013 * an NXST_AGGREGATE request, so we don't do that.) */
1014 struct nx_aggregate_stats_reply {
1015 struct nicira_stats_msg nsm;
1016 struct ofp_aggregate_stats_reply asr;
1018 OFP_ASSERT(sizeof(struct nx_aggregate_stats_reply) == 48);
1020 #endif /* openflow/nicira-ext.h */