]> git.proxmox.com Git - ovs.git/blob - include/openflow/nicira-ext.h
nicira-ext: Clarify and fix macros to check for NXM metadata registers.
[ovs.git] / include / openflow / nicira-ext.h
1 /*
2 * Copyright (c) 2008, 2009, 2010 Nicira Networks
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef OPENFLOW_NICIRA_EXT_H
18 #define OPENFLOW_NICIRA_EXT_H 1
19
20 #include "openflow/openflow.h"
21 #include "openvswitch/types.h"
22
23 #define NICIRA_OUI_STR "002320"
24
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. */
28
29 #define NX_VENDOR_ID 0x00002320
30 \f
31 /* Nicira vendor-specific error messages extension.
32 *
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.
38 *
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
43 * request.
44 *
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.
50 *
51 * Currently this extension is only implemented by Open vSwitch, but it seems
52 * like a reasonable candidate for future standardization.
53 */
54
55 /* This is a random number to avoid accidental collision with any other
56 * vendor's extension. */
57 #define NXET_VENDOR 0xb0c2
58
59 /* ofp_error msg 'code' values for NXET_VENDOR. */
60 enum nx_vendor_code {
61 NXVC_VENDOR_ERROR /* 'data' contains struct nx_vendor_error. */
62 };
63
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. */
70 };
71 \f
72 /* Specific Nicira extension error numbers.
73 *
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. */
79
80 /* Additional "code" values for OFPET_BAD_REQUEST. */
81 enum {
82 /* Nicira Extended Match (NXM) errors. */
83
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,
89
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,
93
94 /* Invalid nxm_value. */
95 NXBRC_NXM_BAD_VALUE = 0x102,
96
97 /* Invalid nxm_mask. */
98 NXBRC_NXM_BAD_MASK = 0x103,
99
100 /* A prerequisite was not met. */
101 NXBRC_NXM_BAD_PREREQ = 0x104,
102
103 /* A given nxm_type was specified more than once. */
104 NXBRC_NXM_DUP_TYPE = 0x105
105 };
106
107 /* Additional "code" values for OFPET_FLOW_MOD_FAILED. */
108 enum {
109 /* Generic hardware error. */
110 NXFMFC_HARDWARE = 0x100,
111
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
115 * vSwitch.) */
116 NXFMFC_BAD_TABLE_ID = 0x101
117 };
118 \f
119 /* Nicira vendor requests and replies. */
120
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. */
126 };
127 OFP_ASSERT(sizeof(struct nicira_header) == 16);
128
129 /* Values for the 'subtype' member of struct nicira_header. */
130 enum nicira_type {
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. */
134 NXT_STATUS_REQUEST,
135
136 /* Switch status reply. The reply body is an ASCII string of key-value
137 * pairs in the form "key=value\n". */
138 NXT_STATUS_REPLY,
139
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,
147 NXT_MGMT__OBSOLETE,
148
149 /* Use the high 32 bits of the cookie field as the tunnel ID in the flow
150 * match. */
151 NXT_TUN_ID_FROM_COOKIE,
152
153 /* Controller role support. The request body is struct nx_role_request.
154 * The reply echos the request. */
155 NXT_ROLE_REQUEST,
156 NXT_ROLE_REPLY,
157
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. */
162 };
163
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. */
172 };
173 OFP_ASSERT(sizeof(struct nicira_stats_msg) == 24);
174
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. */
180 };
181
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. */
188 uint8_t pad[7];
189 };
190 OFP_ASSERT(sizeof(struct nxt_tun_id_cookie) == 24);
191
192 /* Configures the "role" of the sending controller. The default role is:
193 *
194 * - Other (NX_ROLE_OTHER), which allows the controller access to all
195 * OpenFlow features.
196 *
197 * The other possible roles are a related pair:
198 *
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
202 * Slave role.
203 *
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.
207 *
208 * Slave controllers do not receive OFPT_PACKET_IN or OFPT_FLOW_REMOVED
209 * messages, but they do receive OFPT_PORT_STATUS messages.
210 */
211 struct nx_role_request {
212 struct nicira_header nxh;
213 uint32_t role; /* One of NX_ROLE_*. */
214 };
215
216 enum 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. */
220 };
221 \f
222 /* Nicira vendor flow actions. */
223
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 */
234 };
235
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_*. */
242 uint8_t pad[6];
243 };
244 OFP_ASSERT(sizeof(struct nx_action_header) == 16);
245
246 /* Action structure for NXAST_RESUBMIT.
247 *
248 * NXAST_RESUBMIT searches the flow table again, using a flow that is slightly
249 * modified from the original lookup:
250 *
251 * - The 'in_port' member of struct nx_action_resubmit is used as the flow's
252 * in_port.
253 *
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
256 * values.
257 *
258 * Following the lookup, the original in_port is restored.
259 *
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.
265 *
266 * NXAST_RESUBMIT may be used any number of times within a set of actions.
267 *
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.)
271 */
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. */
278 uint8_t pad[4];
279 };
280 OFP_ASSERT(sizeof(struct nx_action_resubmit) == 16);
281
282 /* Action structure for NXAST_SET_TUNNEL.
283 *
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. */
290 uint8_t pad[2];
291 uint32_t tun_id; /* Tunnel ID. */
292 };
293 OFP_ASSERT(sizeof(struct nx_action_set_tunnel) == 16);
294
295 /* Action structure for NXAST_DROP_SPOOFED_ARP.
296 *
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.
300 *
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. */
309 uint8_t pad[6];
310 };
311 OFP_ASSERT(sizeof(struct nx_action_drop_spoofed_arp) == 16);
312
313 /* Action structure for NXAST_SET_QUEUE.
314 *
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
318 * known. */
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. */
324 uint8_t pad[2];
325 uint32_t queue_id; /* Where to enqueue packets. */
326 };
327 OFP_ASSERT(sizeof(struct nx_action_set_queue) == 16);
328
329 /* Action structure for NXAST_POP_QUEUE.
330 *
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
333 * maintained. */
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. */
339 uint8_t pad[6];
340 };
341 OFP_ASSERT(sizeof(struct nx_action_pop_queue) == 16);
342
343 /* Action structure for NXAST_REG_MOVE.
344 *
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.
349 *
350 * 'src' and 'dst' are nxm_header values with nxm_hasmask=0. The following
351 * nxm_header values are potentially acceptable as 'src':
352 *
353 * - NXM_OF_IN_PORT
354 * - NXM_OF_ETH_DST
355 * - NXM_OF_ETH_SRC
356 * - NXM_OF_ETH_TYPE
357 * - NXM_OF_VLAN_TCI
358 * - NXM_OF_IP_TOS
359 * - NXM_OF_IP_PROTO
360 * - NXM_OF_IP_SRC
361 * - NXM_OF_IP_DST
362 * - NXM_OF_TCP_SRC
363 * - NXM_OF_TCP_DST
364 * - NXM_OF_UDP_SRC
365 * - NXM_OF_UDP_DST
366 * - NXM_OF_ICMP_TYPE
367 * - NXM_OF_ICMP_CODE
368 * - NXM_OF_ARP_OP
369 * - NXM_OF_ARP_SPA
370 * - NXM_OF_ARP_TPA
371 * - NXM_NX_TUN_ID
372 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
373 *
374 * The following nxm_header values are potentially acceptable as 'dst':
375 *
376 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
377 *
378 * - NXM_OF_VLAN_TCI. Modifying this field's value has side effects on the
379 * packet's 802.1Q header. Setting a value with CFI=0 removes the 802.1Q
380 * header (if any), ignoring the other bits. Setting a value with CFI=1
381 * adds or modifies the 802.1Q header appropriately, setting the TCI field
382 * to the field's new value (with the CFI bit masked out).
383 *
384 * - NXM_NX_TUN_ID. Modifying this value modifies the tunnel ID used for the
385 * packet's next tunnel encapsulation.
386 *
387 * A given nxm_header value may be used as 'src' or 'dst' only on a flow whose
388 * nx_match satisfies its prerequisites. For example, NXM_OF_IP_TOS may be
389 * used only if the flow's nx_match includes an nxm_entry that specifies
390 * nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0, and nxm_value=0x0800.
391 *
392 * The switch will reject actions for which src_ofs+n_bits is greater than the
393 * width of 'src' or dst_ofs+n_bits is greater than the width of 'dst' with
394 * error type OFPET_BAD_ACTION, code OFPBAC_BAD_ARGUMENT.
395 */
396 struct nx_action_reg_move {
397 ovs_be16 type; /* OFPAT_VENDOR. */
398 ovs_be16 len; /* Length is 16. */
399 ovs_be32 vendor; /* NX_VENDOR_ID. */
400 ovs_be16 subtype; /* NXAST_REG_MOVE. */
401 ovs_be16 n_bits; /* Number of bits. */
402 ovs_be16 src_ofs; /* Starting bit offset in source. */
403 ovs_be16 dst_ofs; /* Starting bit offset in destination. */
404 ovs_be32 src; /* Source register. */
405 ovs_be32 dst; /* Destination register. */
406 };
407 OFP_ASSERT(sizeof(struct nx_action_reg_move) == 24);
408
409 /* Action structure for NXAST_REG_LOAD.
410 *
411 * Copies value[0:n_bits] to dst[ofs:ofs+n_bits], where a[b:c] denotes the bits
412 * within 'a' numbered 'b' through 'c' (not including bit 'c'). Bit numbering
413 * starts at 0 for the least-significant bit, 1 for the next most significant
414 * bit, and so on.
415 *
416 * 'dst' must be one of the following:
417 *
418 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
419 *
420 * The 'ofs' and 'n_bits' fields are combined into a single 'ofs_nbits' field
421 * to avoid enlarging the structure by another 8 bytes. To allow 'n_bits' to
422 * take a value between 1 and 64 (inclusive) while taking up only 6 bits, it is
423 * also stored as one less than its true value:
424 *
425 * 15 6 5 0
426 * +------------------------------+------------------+
427 * | ofs | n_bits - 1 |
428 * +------------------------------+------------------+
429 *
430 * The switch will reject actions for which ofs+n_bits is greater than the
431 * width of 'dst', or in which any bits in 'value' with value 2**n_bits or
432 * greater are set to 1, with error type OFPET_BAD_ACTION, code
433 * OFPBAC_BAD_ARGUMENT.
434 */
435 struct nx_action_reg_load {
436 ovs_be16 type; /* OFPAT_VENDOR. */
437 ovs_be16 len; /* Length is 16. */
438 ovs_be32 vendor; /* NX_VENDOR_ID. */
439 ovs_be16 subtype; /* NXAST_REG_LOAD. */
440 ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */
441 ovs_be32 dst; /* Destination register. */
442 ovs_be64 value; /* Immediate value. */
443 };
444 OFP_ASSERT(sizeof(struct nx_action_reg_load) == 24);
445
446 /* Action structure for NXAST_NOTE.
447 *
448 * This action has no effect. It is variable length. The switch does not
449 * attempt to interpret the user-defined 'note' data in any way. A controller
450 * can use this action to attach arbitrary metadata to a flow.
451 *
452 * This action might go away in the future.
453 */
454 struct nx_action_note {
455 uint16_t type; /* OFPAT_VENDOR. */
456 uint16_t len; /* A multiple of 8, but at least 16. */
457 uint32_t vendor; /* NX_VENDOR_ID. */
458 uint16_t subtype; /* NXAST_NOTE. */
459 uint8_t note[6]; /* Start of user-defined data. */
460 /* Possibly followed by additional user-defined data. */
461 };
462 OFP_ASSERT(sizeof(struct nx_action_note) == 16);
463
464 /* Wildcard for tunnel ID. */
465 #define NXFW_TUN_ID (1 << 25)
466
467 #define NXFW_ALL NXFW_TUN_ID
468 #define OVSFW_ALL (OFPFW_ALL | NXFW_ALL)
469 \f
470 /* Flexible flow specifications (aka NXM = Nicira Extended Match).
471 *
472 * OpenFlow 1.0 has "struct ofp_match" for specifying flow matches. This
473 * structure is fixed-length and hence difficult to extend. This section
474 * describes a more flexible, variable-length flow match, called "nx_match" for
475 * short, that is also supported by Open vSwitch. This section also defines a
476 * replacement for each OpenFlow message that includes struct ofp_match.
477 *
478 *
479 * Format
480 * ======
481 *
482 * An nx_match is a sequence of zero or more "nxm_entry"s, which are
483 * type-length-value (TLV) entries, each 5 to 259 (inclusive) bytes long.
484 * "nxm_entry"s are not aligned on or padded to any multibyte boundary. The
485 * first 4 bytes of an nxm_entry are its "header", followed by the entry's
486 * "body".
487 *
488 * An nxm_entry's header is interpreted as a 32-bit word in network byte order:
489 *
490 * |<-------------------- nxm_type ------------------>|
491 * | |
492 * |31 16 15 9| 8 7 0
493 * +----------------------------------+---------------+--+------------------+
494 * | nxm_vendor | nxm_field |hm| nxm_length |
495 * +----------------------------------+---------------+--+------------------+
496 *
497 * The most-significant 23 bits of the header are collectively "nxm_type".
498 * Bits 16...31 are "nxm_vendor", one of the NXM_VENDOR_* values below. Bits
499 * 9...15 are "nxm_field", which is a vendor-specific value. nxm_type normally
500 * designates a protocol header, such as the Ethernet type, but it can also
501 * refer to packet metadata, such as the switch port on which a packet arrived.
502 *
503 * Bit 8 is "nxm_hasmask" (labeled "hm" above for space reasons). The meaning
504 * of this bit is explained later.
505 *
506 * The least-significant 8 bits are "nxm_length", a positive integer. The
507 * length of the nxm_entry, including the header, is exactly 4 + nxm_length
508 * bytes.
509 *
510 * For a given nxm_vendor, nxm_field, and nxm_hasmask value, nxm_length is a
511 * constant. It is included only to allow software to minimally parse
512 * "nxm_entry"s of unknown types. (Similarly, for a given nxm_vendor,
513 * nxm_field, and nxm_length, nxm_hasmask is a constant.)
514 *
515 *
516 * Semantics
517 * =========
518 *
519 * A zero-length nx_match (one with no "nxm_entry"s) matches every packet.
520 *
521 * An nxm_entry places a constraint on the packets matched by the nx_match:
522 *
523 * - If nxm_hasmask is 0, the nxm_entry's body contains a value for the
524 * field, called "nxm_value". The nx_match matches only packets in which
525 * the field equals nxm_value.
526 *
527 * - If nxm_hasmask is 1, then the nxm_entry's body contains a value for the
528 * field (nxm_value), followed by a bitmask of the same length as the
529 * value, called "nxm_mask". For each 1-bit in position J in nxm_mask, the
530 * nx_match matches only packets for which bit J in the given field's value
531 * matches bit J in nxm_value. A 0-bit in nxm_mask causes the
532 * corresponding bits in nxm_value and the field's value to be ignored.
533 * (The sense of the nxm_mask bits is the opposite of that used by the
534 * "wildcards" member of struct ofp_match.)
535 *
536 * When nxm_hasmask is 1, nxm_length is always even.
537 *
538 * An all-zero-bits nxm_mask is equivalent to omitting the nxm_entry
539 * entirely. An all-one-bits nxm_mask is equivalent to specifying 0 for
540 * nxm_hasmask.
541 *
542 * When there are multiple "nxm_entry"s, all of the constraints must be met.
543 *
544 *
545 * Mask Restrictions
546 * =================
547 *
548 * Masks may be restricted:
549 *
550 * - Some nxm_types may not support masked wildcards, that is, nxm_hasmask
551 * must always be 0 when these fields are specified. For example, the
552 * field that identifies the port on which a packet was received may not be
553 * masked.
554 *
555 * - Some nxm_types that do support masked wildcards may only support certain
556 * nxm_mask patterns. For example, fields that have IPv4 address values
557 * may be restricted to CIDR masks.
558 *
559 * These restrictions should be noted in specifications for individual fields.
560 * A switch may accept an nxm_hasmask or nxm_mask value that the specification
561 * disallows, if the switch correctly implements support for that nxm_hasmask
562 * or nxm_mask value. A switch must reject an attempt to set up a flow that
563 * contains a nxm_hasmask or nxm_mask value that it does not support.
564 *
565 *
566 * Prerequisite Restrictions
567 * =========================
568 *
569 * The presence of an nxm_entry with a given nxm_type may be restricted based
570 * on the presence of or values of other "nxm_entry"s. For example:
571 *
572 * - An nxm_entry for nxm_type=NXM_OF_IP_TOS is allowed only if it is
573 * preceded by another entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
574 * and nxm_value=0x0800. That is, matching on the IP source address is
575 * allowed only if the Ethernet type is explicitly set to IP.
576 *
577 * - An nxm_entry for nxm_type=NXM_OF_TCP_SRC is allowed only if it is preced
578 * by an entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
579 * nxm_value=0x0800 and another with nxm_type=NXM_OF_IP_PROTO,
580 * nxm_hasmask=0, nxm_value=6, in that order. That is, matching on the TCP
581 * source port is allowed only if the Ethernet type is IP and the IP
582 * protocol is TCP.
583 *
584 * These restrictions should be noted in specifications for individual fields.
585 * A switch may implement relaxed versions of these restrictions. A switch
586 * must reject an attempt to set up a flow that violates its restrictions.
587 *
588 *
589 * Ordering Restrictions
590 * =====================
591 *
592 * An nxm_entry that has prerequisite restrictions must appear after the
593 * "nxm_entry"s for its prerequisites. Ordering of "nxm_entry"s within an
594 * nx_match is not otherwise constrained.
595 *
596 * Any given nxm_type may appear in an nx_match at most once.
597 *
598 *
599 * nxm_entry Examples
600 * ==================
601 *
602 * These examples show the format of a single nxm_entry with particular
603 * nxm_hasmask and nxm_length values. The diagrams are labeled with field
604 * numbers and byte indexes.
605 *
606 *
607 * 8-bit nxm_value, nxm_hasmask=1, nxm_length=1:
608 *
609 * 0 3 4 5
610 * +------------+---+---+
611 * | header | v | m |
612 * +------------+---+---+
613 *
614 *
615 * 16-bit nxm_value, nxm_hasmask=0, nxm_length=2:
616 *
617 * 0 3 4 5
618 * +------------+------+
619 * | header | value|
620 * +------------+------+
621 *
622 *
623 * 32-bit nxm_value, nxm_hasmask=0, nxm_length=4:
624 *
625 * 0 3 4 7
626 * +------------+-------------+
627 * | header | nxm_value |
628 * +------------+-------------+
629 *
630 *
631 * 48-bit nxm_value, nxm_hasmask=0, nxm_length=6:
632 *
633 * 0 3 4 9
634 * +------------+------------------+
635 * | header | nxm_value |
636 * +------------+------------------+
637 *
638 *
639 * 48-bit nxm_value, nxm_hasmask=1, nxm_length=12:
640 *
641 * 0 3 4 9 10 15
642 * +------------+------------------+------------------+
643 * | header | nxm_value | nxm_mask |
644 * +------------+------------------+------------------+
645 *
646 *
647 * Error Reporting
648 * ===============
649 *
650 * A switch should report an error in an nx_match using error type
651 * OFPET_BAD_REQUEST and one of the NXBRC_NXM_* codes. Ideally the switch
652 * should report a specific error code, if one is assigned for the particular
653 * problem, but NXBRC_NXM_INVALID is also available to report a generic
654 * nx_match error.
655 */
656
657 #define NXM_HEADER__(VENDOR, FIELD, HASMASK, LENGTH) \
658 (((VENDOR) << 16) | ((FIELD) << 9) | ((HASMASK) << 8) | (LENGTH))
659 #define NXM_HEADER(VENDOR, FIELD, LENGTH) \
660 NXM_HEADER__(VENDOR, FIELD, 0, LENGTH)
661 #define NXM_HEADER_W(VENDOR, FIELD, LENGTH) \
662 NXM_HEADER__(VENDOR, FIELD, 1, (LENGTH) * 2)
663 #define NXM_VENDOR(HEADER) ((HEADER) >> 16)
664 #define NXM_FIELD(HEADER) (((HEADER) >> 9) & 0x7f)
665 #define NXM_TYPE(HEADER) (((HEADER) >> 9) & 0x7fffff)
666 #define NXM_HASMASK(HEADER) (((HEADER) >> 8) & 1)
667 #define NXM_LENGTH(HEADER) ((HEADER) & 0xff)
668
669 #define NXM_MAKE_WILD_HEADER(HEADER) \
670 NXM_HEADER_W(NXM_VENDOR(HEADER), NXM_FIELD(HEADER), NXM_LENGTH(HEADER))
671
672 /* ## ------------------------------- ## */
673 /* ## OpenFlow 1.0-compatible fields. ## */
674 /* ## ------------------------------- ## */
675
676 /* Physical or virtual port on which the packet was received.
677 *
678 * Prereqs: None.
679 *
680 * Format: 16-bit integer in network byte order.
681 *
682 * Masking: Not maskable. */
683 #define NXM_OF_IN_PORT NXM_HEADER (0x0000, 0, 2)
684
685 /* Source or destination address in Ethernet header.
686 *
687 * Prereqs: None.
688 *
689 * Format: 48-bit Ethernet MAC address.
690 *
691 * Masking: The nxm_mask patterns 01:00:00:00:00:00 and FE:FF:FF:FF:FF:FF must
692 * be supported for NXM_OF_ETH_DST_W (as well as the trivial patterns that
693 * are all-0-bits or all-1-bits). Support for other patterns and for masking
694 * of NXM_OF_ETH_SRC is optional. */
695 #define NXM_OF_ETH_DST NXM_HEADER (0x0000, 1, 6)
696 #define NXM_OF_ETH_DST_W NXM_HEADER_W(0x0000, 1, 6)
697 #define NXM_OF_ETH_SRC NXM_HEADER (0x0000, 2, 6)
698
699 /* Packet's Ethernet type.
700 *
701 * For an Ethernet II packet this is taken from the Ethernet header. For an
702 * 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP header.
703 * A packet that has neither format has value 0x05ff
704 * (OFP_DL_TYPE_NOT_ETH_TYPE).
705 *
706 * For a packet with an 802.1Q header, this is the type of the encapsulated
707 * frame.
708 *
709 * Prereqs: None.
710 *
711 * Format: 16-bit integer in network byte order.
712 *
713 * Masking: Not maskable. */
714 #define NXM_OF_ETH_TYPE NXM_HEADER (0x0000, 3, 2)
715
716 /* 802.1Q TCI.
717 *
718 * For a packet with an 802.1Q header, this is the Tag Control Information
719 * (TCI) field, with the CFI bit forced to 1. For a packet with no 802.1Q
720 * header, this has value 0.
721 *
722 * Prereqs: None.
723 *
724 * Format: 16-bit integer in network byte order.
725 *
726 * Masking: Arbitrary masks.
727 *
728 * This field can be used in various ways:
729 *
730 * - If it is not constrained at all, the nx_match matches packets without
731 * an 802.1Q header or with an 802.1Q header that has any TCI value.
732 *
733 * - Testing for an exact match with 0 matches only packets without an
734 * 802.1Q header.
735 *
736 * - Testing for an exact match with a TCI value with CFI=1 matches packets
737 * that have an 802.1Q header with a specified VID and PCP.
738 *
739 * - Testing for an exact match with a nonzero TCI value with CFI=0 does
740 * not make sense. The switch may reject this combination.
741 *
742 * - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
743 * packets that have an 802.1Q header with that VID (and any PCP).
744 *
745 * - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
746 * packets that have an 802.1Q header with that PCP (and any VID).
747 *
748 * - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no 802.1Q
749 * header or with an 802.1Q header with a VID of 0.
750 */
751 #define NXM_OF_VLAN_TCI NXM_HEADER (0x0000, 4, 2)
752 #define NXM_OF_VLAN_TCI_W NXM_HEADER_W(0x0000, 4, 2)
753
754 /* The "type of service" byte of the IP header, with the ECN bits forced to 0.
755 *
756 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
757 *
758 * Format: 8-bit integer with 2 least-significant bits forced to 0.
759 *
760 * Masking: Not maskable. */
761 #define NXM_OF_IP_TOS NXM_HEADER (0x0000, 5, 1)
762
763 /* The "protocol" byte in the IP header.
764 *
765 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
766 *
767 * Format: 8-bit integer.
768 *
769 * Masking: Not maskable. */
770 #define NXM_OF_IP_PROTO NXM_HEADER (0x0000, 6, 1)
771
772 /* The source or destination address in the IP header.
773 *
774 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
775 *
776 * Format: 32-bit integer in network byte order.
777 *
778 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
779 * high-order bits set to 1 and the other 32-N bits set to 0. */
780 #define NXM_OF_IP_SRC NXM_HEADER (0x0000, 7, 4)
781 #define NXM_OF_IP_SRC_W NXM_HEADER_W(0x0000, 7, 4)
782 #define NXM_OF_IP_DST NXM_HEADER (0x0000, 8, 4)
783 #define NXM_OF_IP_DST_W NXM_HEADER_W(0x0000, 8, 4)
784
785 /* The source or destination port in the TCP header.
786 *
787 * Prereqs:
788 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
789 * NXM_OF_IP_PROTO must match 6 exactly.
790 *
791 * Format: 16-bit integer in network byte order.
792 *
793 * Masking: Not maskable. */
794 #define NXM_OF_TCP_SRC NXM_HEADER (0x0000, 9, 2)
795 #define NXM_OF_TCP_DST NXM_HEADER (0x0000, 10, 2)
796
797 /* The source or destination port in the UDP header.
798 *
799 * Prereqs:
800 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
801 * NXM_OF_IP_PROTO must match 17 exactly.
802 *
803 * Format: 16-bit integer in network byte order.
804 *
805 * Masking: Not maskable. */
806 #define NXM_OF_UDP_SRC NXM_HEADER (0x0000, 11, 2)
807 #define NXM_OF_UDP_DST NXM_HEADER (0x0000, 12, 2)
808
809 /* The type or code in the ICMP header.
810 *
811 * Prereqs:
812 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
813 * NXM_OF_IP_PROTO must match 1 exactly.
814 *
815 * Format: 8-bit integer.
816 *
817 * Masking: Not maskable. */
818 #define NXM_OF_ICMP_TYPE NXM_HEADER (0x0000, 13, 1)
819 #define NXM_OF_ICMP_CODE NXM_HEADER (0x0000, 14, 1)
820
821 /* ARP opcode.
822 *
823 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
824 * otherwise. Only ARP opcodes between 1 and 255 should be specified for
825 * matching.
826 *
827 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
828 *
829 * Format: 16-bit integer in network byte order.
830 *
831 * Masking: Not maskable. */
832 #define NXM_OF_ARP_OP NXM_HEADER (0x0000, 15, 2)
833
834 /* For an Ethernet+IP ARP packet, the source or target protocol address
835 * in the ARP header. Always 0 otherwise.
836 *
837 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
838 *
839 * Format: 32-bit integer in network byte order.
840 *
841 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
842 * high-order bits set to 1 and the other 32-N bits set to 0. */
843 #define NXM_OF_ARP_SPA NXM_HEADER (0x0000, 16, 4)
844 #define NXM_OF_ARP_SPA_W NXM_HEADER_W(0x0000, 16, 4)
845 #define NXM_OF_ARP_TPA NXM_HEADER (0x0000, 17, 4)
846 #define NXM_OF_ARP_TPA_W NXM_HEADER_W(0x0000, 17, 4)
847
848 /* ## ------------------------ ## */
849 /* ## Nicira match extensions. ## */
850 /* ## ------------------------ ## */
851
852 /* Metadata registers.
853 *
854 * Registers initially have value 0. Actions allow register values to be
855 * manipulated.
856 *
857 * Prereqs: None.
858 *
859 * Format: Array of 32-bit integer registers. Space is reserved for up to
860 * NXM_NX_MAX_REGS registers, but switches may implement fewer.
861 *
862 * Masking: Arbitrary masks. */
863 #define NXM_NX_MAX_REGS 16
864 #define NXM_NX_REG(IDX) NXM_HEADER (0x0001, IDX, 4)
865 #define NXM_NX_REG_W(IDX) NXM_HEADER_W(0x0001, IDX, 4)
866 #define NXM_NX_REG_IDX(HEADER) NXM_FIELD(HEADER)
867 #define NXM_IS_NX_REG(HEADER) (!((((HEADER) ^ NXM_NX_REG0)) & 0xffffe1ff))
868 #define NXM_IS_NX_REG_W(HEADER) (!((((HEADER) ^ NXM_NX_REG0_W)) & 0xffffe1ff))
869 #define NXM_NX_REG0 NXM_HEADER (0x0001, 0, 4)
870 #define NXM_NX_REG0_W NXM_HEADER_W(0x0001, 0, 4)
871 #define NXM_NX_REG1 NXM_HEADER (0x0001, 1, 4)
872 #define NXM_NX_REG1_W NXM_HEADER_W(0x0001, 1, 4)
873 #define NXM_NX_REG2 NXM_HEADER (0x0001, 2, 4)
874 #define NXM_NX_REG2_W NXM_HEADER_W(0x0001, 2, 4)
875 #define NXM_NX_REG3 NXM_HEADER (0x0001, 3, 4)
876 #define NXM_NX_REG3_W NXM_HEADER_W(0x0001, 3, 4)
877
878 /* Tunnel ID.
879 *
880 * For a packet received via GRE tunnel including a (32-bit) key, the key is
881 * stored in the low 32-bits and the high bits are zeroed. For other packets,
882 * the value is 0.
883 *
884 * Prereqs: None.
885 *
886 * Format: 64-bit integer in network byte order.
887 *
888 * Masking: Arbitrary masks. */
889 #define NXM_NX_TUN_ID NXM_HEADER (0x0001, 16, 8)
890 #define NXM_NX_TUN_ID_W NXM_HEADER_W(0x0001, 16, 8)
891
892 /* ## --------------------- ## */
893 /* ## Requests and replies. ## */
894 /* ## --------------------- ## */
895
896 enum nx_flow_format {
897 NXFF_OPENFLOW10 = 0, /* Standard OpenFlow 1.0 compatible. */
898 NXFF_TUN_ID_FROM_COOKIE = 1, /* OpenFlow 1.0, plus obtain tunnel ID from
899 * cookie. */
900 NXFF_NXM = 2 /* Nicira extended match. */
901 };
902
903 /* NXT_SET_FLOW_FORMAT request. */
904 struct nxt_set_flow_format {
905 struct ofp_header header;
906 ovs_be32 vendor; /* NX_VENDOR_ID. */
907 ovs_be32 subtype; /* NXT_SET_FLOW_FORMAT. */
908 ovs_be32 format; /* One of NXFF_*. */
909 };
910 OFP_ASSERT(sizeof(struct nxt_set_flow_format) == 20);
911
912 /* NXT_FLOW_MOD (analogous to OFPT_FLOW_MOD). */
913 struct nx_flow_mod {
914 struct nicira_header nxh;
915 ovs_be64 cookie; /* Opaque controller-issued identifier. */
916 ovs_be16 command; /* One of OFPFC_*. */
917 ovs_be16 idle_timeout; /* Idle time before discarding (seconds). */
918 ovs_be16 hard_timeout; /* Max time before discarding (seconds). */
919 ovs_be16 priority; /* Priority level of flow entry. */
920 ovs_be32 buffer_id; /* Buffered packet to apply to (or -1).
921 Not meaningful for OFPFC_DELETE*. */
922 ovs_be16 out_port; /* For OFPFC_DELETE* commands, require
923 matching entries to include this as an
924 output port. A value of OFPP_NONE
925 indicates no restriction. */
926 ovs_be16 flags; /* One of OFPFF_*. */
927 ovs_be16 match_len; /* Size of nx_match. */
928 uint8_t pad[6]; /* Align to 64-bits. */
929 /* Followed by:
930 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
931 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
932 * all-zero bytes, then
933 * - Actions to fill out the remainder of the message length (always a
934 * multiple of 8).
935 */
936 };
937 OFP_ASSERT(sizeof(struct nx_flow_mod) == 48);
938
939 /* NXT_FLOW_REMOVED (analogous to OFPT_FLOW_REMOVED). */
940 struct nx_flow_removed {
941 struct nicira_header nxh;
942 ovs_be64 cookie; /* Opaque controller-issued identifier. */
943 ovs_be16 priority; /* Priority level of flow entry. */
944 uint8_t reason; /* One of OFPRR_*. */
945 uint8_t pad[1]; /* Align to 32-bits. */
946 ovs_be32 duration_sec; /* Time flow was alive in seconds. */
947 ovs_be32 duration_nsec; /* Time flow was alive in nanoseconds beyond
948 duration_sec. */
949 ovs_be16 idle_timeout; /* Idle timeout from original flow mod. */
950 ovs_be16 match_len; /* Size of nx_match. */
951 ovs_be64 packet_count;
952 ovs_be64 byte_count;
953 /* Followed by:
954 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
955 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
956 * all-zero bytes. */
957 };
958 OFP_ASSERT(sizeof(struct nx_flow_removed) == 56);
959
960 /* Nicira vendor stats request of type NXST_FLOW (analogous to OFPST_FLOW
961 * request). */
962 struct nx_flow_stats_request {
963 struct nicira_stats_msg nsm;
964 ovs_be16 out_port; /* Require matching entries to include this
965 as an output port. A value of OFPP_NONE
966 indicates no restriction. */
967 ovs_be16 match_len; /* Length of nx_match. */
968 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
969 or 0xff for all tables. */
970 uint8_t pad[3]; /* Align to 64 bits. */
971 /* Followed by:
972 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
973 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
974 * all-zero bytes, which must also exactly fill out the length of the
975 * message.
976 */
977 };
978 OFP_ASSERT(sizeof(struct nx_flow_stats_request) == 32);
979
980 /* Body for Nicira vendor stats reply of type NXST_FLOW (analogous to
981 * OFPST_FLOW reply). */
982 struct nx_flow_stats {
983 ovs_be16 length; /* Length of this entry. */
984 uint8_t table_id; /* ID of table flow came from. */
985 uint8_t pad;
986 ovs_be32 duration_sec; /* Time flow has been alive in seconds. */
987 ovs_be32 duration_nsec; /* Time flow has been alive in nanoseconds
988 beyond duration_sec. */
989 ovs_be16 priority; /* Priority of the entry. Only meaningful
990 when this is not an exact-match entry. */
991 ovs_be16 idle_timeout; /* Number of seconds idle before expiration. */
992 ovs_be16 hard_timeout; /* Number of seconds before expiration. */
993 ovs_be16 match_len; /* Length of nx_match. */
994 uint8_t pad2[4]; /* Align to 64 bits. */
995 ovs_be64 cookie; /* Opaque controller-issued identifier. */
996 ovs_be64 packet_count; /* Number of packets in flow. */
997 ovs_be64 byte_count; /* Number of bytes in flow. */
998 /* Followed by:
999 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1000 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1001 * all-zero bytes, then
1002 * - Actions to fill out the remainder 'length' bytes (always a multiple
1003 * of 8).
1004 */
1005 };
1006 OFP_ASSERT(sizeof(struct nx_flow_stats) == 48);
1007
1008 /* Nicira vendor stats request of type NXST_AGGREGATE (analogous to
1009 * OFPST_AGGREGATE request). */
1010 struct nx_aggregate_stats_request {
1011 struct nicira_stats_msg nsm;
1012 ovs_be16 out_port; /* Require matching entries to include this
1013 as an output port. A value of OFPP_NONE
1014 indicates no restriction. */
1015 ovs_be16 match_len; /* Length of nx_match. */
1016 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
1017 or 0xff for all tables. */
1018 uint8_t pad[3]; /* Align to 64 bits. */
1019 /* Followed by:
1020 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1021 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1022 * all-zero bytes, which must also exactly fill out the length of the
1023 * message.
1024 */
1025 };
1026 OFP_ASSERT(sizeof(struct nx_aggregate_stats_request) == 32);
1027
1028 /* Body for nicira_stats_msg reply of type NXST_AGGREGATE (analogous to
1029 * OFPST_AGGREGATE reply).
1030 *
1031 * ofp_aggregate_stats_reply does not contain an ofp_match structure, so we
1032 * reuse it entirely. (It would be very odd to use OFPST_AGGREGATE to reply to
1033 * an NXST_AGGREGATE request, so we don't do that.) */
1034 struct nx_aggregate_stats_reply {
1035 struct nicira_stats_msg nsm;
1036 struct ofp_aggregate_stats_reply asr;
1037 };
1038 OFP_ASSERT(sizeof(struct nx_aggregate_stats_reply) == 48);
1039
1040 #endif /* openflow/nicira-ext.h */