]> git.proxmox.com Git - ovs.git/blame - include/openflow/nicira-ext.h
openflow: New Nicira Extended PACKET_IN format.
[ovs.git] / include / openflow / nicira-ext.h
CommitLineData
064af421 1/*
6eb59a8f 2 * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks
a14bc59f
BP
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.
064af421
BP
15 */
16
17#ifndef OPENFLOW_NICIRA_EXT_H
18#define OPENFLOW_NICIRA_EXT_H 1
19
20#include "openflow/openflow.h"
26c112c2 21#include "openvswitch/types.h"
064af421 22
064af421 23/* The following vendor extensions, proposed by Nicira Networks, are not yet
26c112c2
BP
24 * standardized, so they are not included in openflow.h. Some of them may be
25 * suitable for standardization; others we never expect to standardize. */
064af421
BP
26
27#define NX_VENDOR_ID 0x00002320
26c112c2
BP
28\f
29/* Nicira vendor-specific error messages extension.
30 *
31 * OpenFlow 1.0 has a set of predefined error types (OFPET_*) and codes (which
32 * are specific to each type). It does not have any provision for
33 * vendor-specific error codes, and it does not even provide "generic" error
34 * codes that can apply to problems not anticipated by the OpenFlow
35 * specification authors.
36 *
37 * This extension attempts to address the problem by adding a generic "error
38 * vendor extension". The extension works as follows: use NXET_VENDOR as type
6eb59a8f 39 * and NXVC_VENDOR_ERROR as code, followed by struct nx_vendor_error with
26c112c2
BP
40 * vendor-specific details, followed by at least 64 bytes of the failed
41 * request.
42 *
a23aab1f 43 * It would be better to have a type-specific vendor extension, e.g. so that
26c112c2
BP
44 * OFPET_BAD_ACTION could be used with vendor-specific code values. But
45 * OFPET_BAD_ACTION and most other standardized types already specify that
46 * their 'data' values are (the start of) the OpenFlow message being replied
47 * to, so there is no room to insert a vendor ID.
48 *
49 * Currently this extension is only implemented by Open vSwitch, but it seems
50 * like a reasonable candidate for future standardization.
51 */
52
53/* This is a random number to avoid accidental collision with any other
54 * vendor's extension. */
55#define NXET_VENDOR 0xb0c2
56
57/* ofp_error msg 'code' values for NXET_VENDOR. */
58enum nx_vendor_code {
59 NXVC_VENDOR_ERROR /* 'data' contains struct nx_vendor_error. */
60};
61
62/* 'data' for 'type' == NXET_VENDOR, 'code' == NXVC_VENDOR_ERROR. */
63struct nx_vendor_error {
64 ovs_be32 vendor; /* Vendor ID as in struct ofp_vendor_header. */
65 ovs_be16 type; /* Vendor-defined type. */
66 ovs_be16 code; /* Vendor-defined subtype. */
67 /* Followed by at least the first 64 bytes of the failed request. */
68};
69\f
422bb884
BP
70/* Specific Nicira extension error numbers.
71 *
72 * These are the "code" values used in nx_vendor_error. So far, the "type"
73 * values in nx_vendor_error are the same as those in ofp_error_msg. That is,
74 * at Nicira so far we've only needed additional vendor-specific 'code' values,
75 * so we're using the existing 'type' values to avoid having to invent new ones
76 * that duplicate the current ones' meanings. */
77
09246b99 78/* Additional "code" values for OFPET_BAD_REQUEST. */
dc4762ed 79enum nx_bad_request_code {
09246b99
BP
80/* Nicira Extended Match (NXM) errors. */
81
82 /* Generic error code used when there is an error in an NXM sent to the
83 * switch. The switch may use one of the more specific error codes below,
84 * if there is an appropriate one, to simplify debugging, but it is not
85 * required to do so. */
86 NXBRC_NXM_INVALID = 0x100,
87
88 /* The nxm_type, or nxm_type taken in combination with nxm_hasmask or
89 * nxm_length or both, is invalid or not implemented. */
90 NXBRC_NXM_BAD_TYPE = 0x101,
91
92 /* Invalid nxm_value. */
93 NXBRC_NXM_BAD_VALUE = 0x102,
94
95 /* Invalid nxm_mask. */
96 NXBRC_NXM_BAD_MASK = 0x103,
97
98 /* A prerequisite was not met. */
99 NXBRC_NXM_BAD_PREREQ = 0x104,
100
101 /* A given nxm_type was specified more than once. */
48266274
BP
102 NXBRC_NXM_DUP_TYPE = 0x105,
103
104/* Other errors. */
105
106 /* A request specified a nonexistent table ID. (But NXFMFC_BAD_TABLE_ID is
107 * used instead, when it is appropriate, because that is such a special
108 * case.) */
109 NXBRC_BAD_TABLE_ID = 0x200,
68f36edf
BP
110
111 /* NXT_ROLE_REQUEST specified an invalid role. */
112 NXBRC_BAD_ROLE = 0x201,
e1154f71
BP
113
114 /* The in_port in an ofp_packet_out request is invalid. */
115 NXBRC_BAD_IN_PORT = 0x202
09246b99
BP
116};
117
422bb884 118/* Additional "code" values for OFPET_FLOW_MOD_FAILED. */
dc4762ed 119enum nx_flow_mod_failed_code {
422bb884
BP
120 /* Generic hardware error. */
121 NXFMFC_HARDWARE = 0x100,
122
123 /* A nonexistent table ID was specified in the "command" field of struct
6c1491fb 124 * ofp_flow_mod, when the nxt_flow_mod_table_id extension is enabled. */
09246b99 125 NXFMFC_BAD_TABLE_ID = 0x101
422bb884
BP
126};
127\f
26c112c2 128/* Nicira vendor requests and replies. */
064af421 129
09246b99
BP
130/* Header for Nicira vendor requests and replies. */
131struct nicira_header {
132 struct ofp_header header;
133 ovs_be32 vendor; /* NX_VENDOR_ID. */
134 ovs_be32 subtype; /* One of NXT_* below. */
135};
136OFP_ASSERT(sizeof(struct nicira_header) == 16);
137
138/* Values for the 'subtype' member of struct nicira_header. */
064af421 139enum nicira_type {
898b7f8d 140 /* No longer used. */
241e8267
BP
141 NXT_STATUS_REQUEST__OBSOLETE = 0,
142 NXT_STATUS_REPLY__OBSOLETE = 1,
143 NXT_ACT_SET_CONFIG__OBSOLETE = 2,
144 NXT_ACT_GET_CONFIG__OBSOLETE = 3,
145 NXT_COMMAND_REQUEST__OBSOLETE = 4,
146 NXT_COMMAND_REPLY__OBSOLETE = 5,
147 NXT_FLOW_END_CONFIG__OBSOLETE = 6,
148 NXT_FLOW_END__OBSOLETE = 7,
149 NXT_MGMT__OBSOLETE = 8,
150 NXT_TUN_ID_FROM_COOKIE__OBSOLETE = 9,
9deba63b
BP
151
152 /* Controller role support. The request body is struct nx_role_request.
153 * The reply echos the request. */
241e8267
BP
154 NXT_ROLE_REQUEST = 10,
155 NXT_ROLE_REPLY = 11,
09246b99
BP
156
157 /* Flexible flow specification (aka NXM = Nicira Extended Match). */
241e8267
BP
158 NXT_SET_FLOW_FORMAT = 12, /* Set flow format. */
159 NXT_FLOW_MOD = 13, /* Analogous to OFPT_FLOW_MOD. */
160 NXT_FLOW_REMOVED = 14, /* Analogous to OFPT_FLOW_REMOVED. */
d1e9b9bf
BP
161
162 /* Use the upper 8 bits of the 'command' member in struct ofp_flow_mod to
163 * designate the table to which a flow is to be added? See the big comment
164 * on struct nxt_flow_mod_table_id for more information. */
54834960
EJ
165 NXT_FLOW_MOD_TABLE_ID = 15,
166
167 /* Alternative PACKET_IN message formats. */
168 NXT_SET_PACKET_IN_FORMAT = 16, /* Set Packet In format. */
169 NXT_PACKET_IN = 17 /* Nicira Packet In. */
064af421
BP
170};
171
09246b99
BP
172/* Header for Nicira vendor stats request and reply messages. */
173struct nicira_stats_msg {
63f2140a 174 struct ofp_vendor_stats_msg vsm; /* Vendor NX_VENDOR_ID. */
09246b99
BP
175 ovs_be32 subtype; /* One of NXST_* below. */
176 uint8_t pad[4]; /* Align to 64-bits. */
064af421 177};
09246b99 178OFP_ASSERT(sizeof(struct nicira_stats_msg) == 24);
064af421 179
09246b99
BP
180/* Values for the 'subtype' member of struct nicira_stats_msg. */
181enum nicira_stats_type {
182 /* Flexible flow specification (aka NXM = Nicira Extended Match). */
183 NXST_FLOW, /* Analogous to OFPST_FLOW. */
184 NXST_AGGREGATE /* Analogous to OFPST_AGGREGATE. */
f9bfea14
BP
185};
186
520e9a2a
EJ
187/* Fields to use when hashing flows. */
188enum nx_hash_fields {
189 /* Ethernet source address (NXM_OF_ETH_SRC) only. */
190 NX_HASH_FIELDS_ETH_SRC,
191
192 /* L2 through L4, symmetric across src/dst. Specifically, each of the
193 * following fields, if present, is hashed (slashes separate symmetric
194 * pairs):
195 *
196 * - NXM_OF_ETH_DST / NXM_OF_ETH_SRC
197 * - NXM_OF_ETH_TYPE
198 * - The VID bits from NXM_OF_VLAN_TCI, ignoring PCP and CFI.
199 * - NXM_OF_IP_PROTO
200 * - NXM_OF_IP_SRC / NXM_OF_IP_DST
201 * - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
202 */
203 NX_HASH_FIELDS_SYMMETRIC_L4
204};
205
6c1491fb
BP
206/* This command enables or disables an Open vSwitch extension that allows a
207 * controller to specify the OpenFlow table to which a flow should be added,
208 * instead of having the switch decide which table is most appropriate as
209 * required by OpenFlow 1.0. By default, the extension is disabled.
210 *
211 * When this feature is enabled, Open vSwitch treats struct ofp_flow_mod's
212 * 16-bit 'command' member as two separate fields. The upper 8 bits are used
213 * as the table ID, the lower 8 bits specify the command as usual. A table ID
214 * of 0xff is treated like a wildcarded table ID.
215 *
216 * The specific treatment of the table ID depends on the type of flow mod:
217 *
218 * - OFPFC_ADD: Given a specific table ID, the flow is always placed in that
219 * table. If an identical flow already exists in that table only, then it
220 * is replaced. If the flow cannot be placed in the specified table,
221 * either because the table is full or because the table cannot support
222 * flows of the given type, the switch replies with an
223 * OFPFMFC_ALL_TABLES_FULL error. (A controller can distinguish these
224 * cases by comparing the current and maximum number of entries reported
225 * in ofp_table_stats.)
226 *
227 * If the table ID is wildcarded, the switch picks an appropriate table
228 * itself. If an identical flow already exist in the selected flow table,
229 * then it is replaced. The choice of table might depend on the flows
230 * that are already in the switch; for example, if one table fills up then
231 * the switch might fall back to another one.
232 *
233 * - OFPFC_MODIFY, OFPFC_DELETE: Given a specific table ID, only flows
234 * within that table are matched and modified or deleted. If the table ID
235 * is wildcarded, flows within any table may be matched and modified or
236 * deleted.
237 *
238 * - OFPFC_MODIFY_STRICT, OFPFC_DELETE_STRICT: Given a specific table ID,
239 * only a flow within that table may be matched and modified or deleted.
240 * If the table ID is wildcarded and exactly one flow within any table
241 * matches, then it is modified or deleted; if flows in more than one
242 * table match, then none is modified or deleted.
243 */
244struct nxt_flow_mod_table_id {
245 struct ofp_header header;
246 uint32_t vendor; /* NX_VENDOR_ID. */
247 uint32_t subtype; /* NXT_FLOW_MOD_TABLE_ID. */
248 uint8_t set; /* Nonzero to enable, zero to disable. */
249 uint8_t pad[7];
250};
251OFP_ASSERT(sizeof(struct nxt_flow_mod_table_id) == 24);
252
54834960
EJ
253enum nx_packet_in_format {
254 NXPIF_OPENFLOW10 = 0, /* Standard OpenFlow 1.0 compatible. */
255 NXPIF_NXM = 1 /* Nicira Extended. */
256};
257
258/* NXT_SET_PACKET_IN_FORMAT request. */
259struct nxt_set_packet_in_format {
260 struct nicira_header nxh;
261 ovs_be32 format; /* One of NXPIF_*. */
262};
263OFP_ASSERT(sizeof(struct nxt_set_packet_in_format) == 20);
264
265/* NXT_PACKET_IN (analogous to OFPT_PACKET_IN).
266 *
267 * The NXT_PACKET_IN format is intended to model the OpenFlow-1.2 PACKET_IN
268 * with some minor tweaks. Most notably NXT_PACKET_IN includes the cookie of
269 * the rule which triggered the NXT_PACKET_IN message, and the match fields are
270 * in NXM format.
271 *
272 * The match fields in the NXT_PACKET_IN are intended to contain flow
273 * processing metadata collected at the time the NXT_PACKET_IN message was
274 * triggered. It is minimally required to contain the NXM_OF_IN_PORT of the
275 * packet, but may include other NXM headers such as flow registers. The match
276 * fields are allowed to contain non-metadata (e.g. NXM_OF_ETH_SRC etc).
277 * However, this information can typically be found in the packet directly, so
278 * it may be redundant.
279 *
280 * Whereas in most cases a controller can expect to only get back NXM fields
281 * that it set up itself (e.g. flow dumps will ordinarily report only NXM
282 * fields from flows that the controller added), NXT_PACKET_IN messages might
283 * contain fields that the controller does not understand, because the switch
284 * might support fields (new registers, new protocols, etc.) that the
285 * controller does not.  The controller must prepared to tolerate these.
286 *
287 * The 'cookie' and 'table_id' fields have no meaning when 'reason' is
288 * OFPR_NO_MATCH. In this case they should be set to 0. */
289struct nxt_packet_in {
290 struct nicira_header nxh;
291 ovs_be32 buffer_id; /* ID assigned by datapath. */
292 ovs_be16 total_len; /* Full length of frame. */
293 uint8_t reason; /* Reason packet is sent (one of OFPR_*). */
294 uint8_t table_id; /* ID of the table that was looked up. */
295 ovs_be64 cookie; /* Cookie of the rule that was looked up. */
296 ovs_be16 match_len; /* Size of nx_match. */
297 uint8_t pad[6]; /* Align to 64-bits. */
298 /* Followed by:
299 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
300 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
301 * all-zero bytes, then
302 * - Exactly 2 all-zero padding bytes, then
303 * - An Ethernet frame whose length is inferred from nxh.header.length.
304 *
305 * The padding bytes preceding the Ethernet frame ensure that the IP
306 * header (if any) following the Ethernet header is 32-bit aligned. */
307
308 /* uint8_t nxm_fields[...]; */ /* Match. */
309 /* uint8_t pad[2]; */ /* Align to 64 bit + 16 bit. */
310 /* uint8_t data[0]; */ /* Ethernet frame. */
311};
312OFP_ASSERT(sizeof(struct nxt_packet_in) == 40);
313
9deba63b
BP
314/* Configures the "role" of the sending controller. The default role is:
315 *
316 * - Other (NX_ROLE_OTHER), which allows the controller access to all
317 * OpenFlow features.
318 *
319 * The other possible roles are a related pair:
320 *
321 * - Master (NX_ROLE_MASTER) is equivalent to Other, except that there may
322 * be at most one Master controller at a time: when a controller
323 * configures itself as Master, any existing Master is demoted to the
324 * Slave role.
325 *
326 * - Slave (NX_ROLE_SLAVE) allows the controller read-only access to
327 * OpenFlow features. In particular attempts to modify the flow table
328 * will be rejected with an OFPBRC_EPERM error.
329 *
197a992f
BP
330 * Slave controllers do not receive OFPT_PACKET_IN or OFPT_FLOW_REMOVED
331 * messages, but they do receive OFPT_PORT_STATUS messages.
9deba63b
BP
332 */
333struct nx_role_request {
334 struct nicira_header nxh;
459749fe 335 ovs_be32 role; /* One of NX_ROLE_*. */
9deba63b
BP
336};
337
338enum nx_role {
339 NX_ROLE_OTHER, /* Default role, full access. */
340 NX_ROLE_MASTER, /* Full access, at most one. */
341 NX_ROLE_SLAVE /* Read-only access. */
342};
26c112c2
BP
343\f
344/* Nicira vendor flow actions. */
9deba63b 345
064af421 346enum nx_action_subtype {
39b72738
BP
347 NXAST_SNAT__OBSOLETE, /* No longer used. */
348 NXAST_RESUBMIT, /* struct nx_action_resubmit */
349 NXAST_SET_TUNNEL, /* struct nx_action_set_tunnel */
6c222e55 350 NXAST_DROP_SPOOFED_ARP__OBSOLETE,
39b72738 351 NXAST_SET_QUEUE, /* struct nx_action_set_queue */
b6c9e612
BP
352 NXAST_POP_QUEUE, /* struct nx_action_pop_queue */
353 NXAST_REG_MOVE, /* struct nx_action_reg_move */
354 NXAST_REG_LOAD, /* struct nx_action_reg_load */
b9298d3f
BP
355 NXAST_NOTE, /* struct nx_action_note */
356 NXAST_SET_TUNNEL64, /* struct nx_action_set_tunnel64 */
3b6a2571 357 NXAST_MULTIPATH, /* struct nx_action_multipath */
daff3353 358 NXAST_AUTOPATH, /* struct nx_action_autopath */
a368bb53 359 NXAST_BUNDLE, /* struct nx_action_bundle */
29901626 360 NXAST_BUNDLE_LOAD, /* struct nx_action_bundle */
f694937d 361 NXAST_RESUBMIT_TABLE, /* struct nx_action_resubmit */
75a75043 362 NXAST_OUTPUT_REG, /* struct nx_action_output_reg */
848e8809
EJ
363 NXAST_LEARN, /* struct nx_action_learn */
364 NXAST_EXIT /* struct nx_action_header */
39b72738 365};
eedc0097 366
39b72738
BP
367/* Header for Nicira-defined actions. */
368struct nx_action_header {
459749fe
BP
369 ovs_be16 type; /* OFPAT_VENDOR. */
370 ovs_be16 len; /* Length is 16. */
371 ovs_be32 vendor; /* NX_VENDOR_ID. */
372 ovs_be16 subtype; /* NXAST_*. */
39b72738 373 uint8_t pad[6];
064af421 374};
39b72738 375OFP_ASSERT(sizeof(struct nx_action_header) == 16);
064af421 376
29901626 377/* Action structures for NXAST_RESUBMIT and NXAST_RESUBMIT_TABLE.
39b72738 378 *
29901626 379 * These actions search one of the switch's flow tables:
39b72738 380 *
29901626
BP
381 * - For NXAST_RESUBMIT_TABLE only, if the 'table' member is not 255, then
382 * it specifies the table to search.
39b72738 383 *
29901626
BP
384 * - Otherwise (for NXAST_RESUBMIT_TABLE with a 'table' of 255, or for
385 * NXAST_RESUBMIT regardless of 'table'), it searches the current flow
386 * table, that is, the OpenFlow flow table that contains the flow from
387 * which this action was obtained. If this action did not come from a
388 * flow table (e.g. it came from an OFPT_PACKET_OUT message), then table 0
389 * is the current table.
390 *
391 * The flow table lookup uses a flow that may be slightly modified from the
392 * original lookup:
393 *
394 * - For NXAST_RESUBMIT, the 'in_port' member of struct nx_action_resubmit
395 * is used as the flow's in_port.
396 *
397 * - For NXAST_RESUBMIT_TABLE, if the 'in_port' member is not OFPP_IN_PORT,
398 * then its value is used as the flow's in_port. Otherwise, the original
399 * in_port is used.
400 *
401 * - If actions that modify the flow (e.g. OFPAT_SET_VLAN_VID) precede the
402 * resubmit action, then the flow is updated with the new values.
39b72738
BP
403 *
404 * Following the lookup, the original in_port is restored.
405 *
406 * If the modified flow matched in the flow table, then the corresponding
29901626 407 * actions are executed. Afterward, actions following the resubmit in the
39b72738
BP
408 * original set of actions, if any, are executed; any changes made to the
409 * packet (e.g. changes to VLAN) by secondary actions persist when those
410 * actions are executed, although the original in_port is restored.
411 *
29901626
BP
412 * Resubmit actions may be used any number of times within a set of actions.
413 *
414 * Resubmit actions may nest to an implementation-defined depth. Beyond this
415 * implementation-defined depth, further resubmit actions are simply ignored.
416 *
417 * NXAST_RESUBMIT ignores 'table' and 'pad'. NXAST_RESUBMIT_TABLE requires
418 * 'pad' to be all-bits-zero.
39b72738 419 *
29901626
BP
420 * Open vSwitch 1.0.1 and earlier did not support recursion. Open vSwitch
421 * before 1.2.90 did not support NXAST_RESUBMIT_TABLE.
39b72738 422 */
064af421 423struct nx_action_resubmit {
459749fe
BP
424 ovs_be16 type; /* OFPAT_VENDOR. */
425 ovs_be16 len; /* Length is 16. */
426 ovs_be32 vendor; /* NX_VENDOR_ID. */
427 ovs_be16 subtype; /* NXAST_RESUBMIT. */
428 ovs_be16 in_port; /* New in_port for checking flow table. */
29901626
BP
429 uint8_t table; /* NXAST_RESUBMIT_TABLE: table to use. */
430 uint8_t pad[3];
064af421
BP
431};
432OFP_ASSERT(sizeof(struct nx_action_resubmit) == 16);
433
39b72738
BP
434/* Action structure for NXAST_SET_TUNNEL.
435 *
b9298d3f
BP
436 * Sets the encapsulating tunnel ID to a 32-bit value. The most-significant 32
437 * bits of the tunnel ID are set to 0. */
659586ef 438struct nx_action_set_tunnel {
459749fe
BP
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_SET_TUNNEL. */
659586ef 443 uint8_t pad[2];
459749fe 444 ovs_be32 tun_id; /* Tunnel ID. */
659586ef
JG
445};
446OFP_ASSERT(sizeof(struct nx_action_set_tunnel) == 16);
447
b9298d3f
BP
448/* Action structure for NXAST_SET_TUNNEL64.
449 *
450 * Sets the encapsulating tunnel ID to a 64-bit value. */
451struct nx_action_set_tunnel64 {
452 ovs_be16 type; /* OFPAT_VENDOR. */
453 ovs_be16 len; /* Length is 16. */
454 ovs_be32 vendor; /* NX_VENDOR_ID. */
455 ovs_be16 subtype; /* NXAST_SET_TUNNEL64. */
456 uint8_t pad[6];
457 ovs_be64 tun_id; /* Tunnel ID. */
458};
459OFP_ASSERT(sizeof(struct nx_action_set_tunnel64) == 24);
460
39b72738
BP
461/* Action structure for NXAST_SET_QUEUE.
462 *
463 * Set the queue that should be used when packets are output. This is similar
464 * to the OpenFlow OFPAT_ENQUEUE action, but does not take the output port as
465 * an argument. This allows the queue to be defined before the port is
466 * known. */
eedc0097 467struct nx_action_set_queue {
459749fe
BP
468 ovs_be16 type; /* OFPAT_VENDOR. */
469 ovs_be16 len; /* Length is 16. */
470 ovs_be32 vendor; /* NX_VENDOR_ID. */
471 ovs_be16 subtype; /* NXAST_SET_QUEUE. */
eedc0097 472 uint8_t pad[2];
459749fe 473 ovs_be32 queue_id; /* Where to enqueue packets. */
eedc0097
JP
474};
475OFP_ASSERT(sizeof(struct nx_action_set_queue) == 16);
476
39b72738
BP
477/* Action structure for NXAST_POP_QUEUE.
478 *
479 * Restores the queue to the value it was before any NXAST_SET_QUEUE actions
480 * were used. Only the original queue can be restored this way; no stack is
481 * maintained. */
482struct nx_action_pop_queue {
459749fe
BP
483 ovs_be16 type; /* OFPAT_VENDOR. */
484 ovs_be16 len; /* Length is 16. */
485 ovs_be32 vendor; /* NX_VENDOR_ID. */
486 ovs_be16 subtype; /* NXAST_POP_QUEUE. */
064af421
BP
487 uint8_t pad[6];
488};
39b72738 489OFP_ASSERT(sizeof(struct nx_action_pop_queue) == 16);
064af421 490
b6c9e612
BP
491/* Action structure for NXAST_REG_MOVE.
492 *
493 * Copies src[src_ofs:src_ofs+n_bits] to dst[dst_ofs:dst_ofs+n_bits], where
494 * a[b:c] denotes the bits within 'a' numbered 'b' through 'c' (not including
495 * bit 'c'). Bit numbering starts at 0 for the least-significant bit, 1 for
496 * the next most significant bit, and so on.
497 *
60d5e0d8
BP
498 * 'src' and 'dst' are nxm_header values with nxm_hasmask=0. (It doesn't make
499 * sense to use nxm_hasmask=1 because the action does not do any kind of
500 * matching; it uses the actual value of a field.)
501 *
502 * The following nxm_header values are potentially acceptable as 'src':
b6c9e612
BP
503 *
504 * - NXM_OF_IN_PORT
505 * - NXM_OF_ETH_DST
506 * - NXM_OF_ETH_SRC
507 * - NXM_OF_ETH_TYPE
508 * - NXM_OF_VLAN_TCI
509 * - NXM_OF_IP_TOS
510 * - NXM_OF_IP_PROTO
511 * - NXM_OF_IP_SRC
512 * - NXM_OF_IP_DST
513 * - NXM_OF_TCP_SRC
514 * - NXM_OF_TCP_DST
515 * - NXM_OF_UDP_SRC
516 * - NXM_OF_UDP_DST
517 * - NXM_OF_ICMP_TYPE
518 * - NXM_OF_ICMP_CODE
519 * - NXM_OF_ARP_OP
520 * - NXM_OF_ARP_SPA
521 * - NXM_OF_ARP_TPA
522 * - NXM_NX_TUN_ID
bad68a99
JP
523 * - NXM_NX_ARP_SHA
524 * - NXM_NX_ARP_THA
d31f1109
JP
525 * - NXM_NX_ICMPV6_TYPE
526 * - NXM_NX_ICMPV6_CODE
685a51a5
JP
527 * - NXM_NX_ND_SLL
528 * - NXM_NX_ND_TLL
b6c9e612
BP
529 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
530 *
531 * The following nxm_header values are potentially acceptable as 'dst':
532 *
54d54726
BP
533 * - NXM_OF_ETH_DST
534 * - NXM_OF_ETH_SRC
535 * - NXM_OF_IP_TOS
536 * - NXM_OF_IP_SRC
537 * - NXM_OF_IP_DST
538 * - NXM_OF_TCP_SRC
539 * - NXM_OF_TCP_DST
540 * - NXM_OF_UDP_SRC
541 * - NXM_OF_UDP_DST
542 * Modifying any of the above fields changes the corresponding packet
543 * header.
544 *
b6c9e612
BP
545 * - NXM_NX_REG(idx) for idx in the switch's accepted range.
546 *
547 * - NXM_OF_VLAN_TCI. Modifying this field's value has side effects on the
548 * packet's 802.1Q header. Setting a value with CFI=0 removes the 802.1Q
549 * header (if any), ignoring the other bits. Setting a value with CFI=1
550 * adds or modifies the 802.1Q header appropriately, setting the TCI field
551 * to the field's new value (with the CFI bit masked out).
552 *
553 * - NXM_NX_TUN_ID. Modifying this value modifies the tunnel ID used for the
554 * packet's next tunnel encapsulation.
555 *
556 * A given nxm_header value may be used as 'src' or 'dst' only on a flow whose
557 * nx_match satisfies its prerequisites. For example, NXM_OF_IP_TOS may be
558 * used only if the flow's nx_match includes an nxm_entry that specifies
559 * nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0, and nxm_value=0x0800.
560 *
561 * The switch will reject actions for which src_ofs+n_bits is greater than the
562 * width of 'src' or dst_ofs+n_bits is greater than the width of 'dst' with
563 * error type OFPET_BAD_ACTION, code OFPBAC_BAD_ARGUMENT.
564 */
565struct nx_action_reg_move {
566 ovs_be16 type; /* OFPAT_VENDOR. */
567 ovs_be16 len; /* Length is 16. */
568 ovs_be32 vendor; /* NX_VENDOR_ID. */
569 ovs_be16 subtype; /* NXAST_REG_MOVE. */
570 ovs_be16 n_bits; /* Number of bits. */
571 ovs_be16 src_ofs; /* Starting bit offset in source. */
572 ovs_be16 dst_ofs; /* Starting bit offset in destination. */
573 ovs_be32 src; /* Source register. */
574 ovs_be32 dst; /* Destination register. */
575};
576OFP_ASSERT(sizeof(struct nx_action_reg_move) == 24);
577
578/* Action structure for NXAST_REG_LOAD.
579 *
580 * Copies value[0:n_bits] to dst[ofs:ofs+n_bits], where a[b:c] denotes the bits
581 * within 'a' numbered 'b' through 'c' (not including bit 'c'). Bit numbering
582 * starts at 0 for the least-significant bit, 1 for the next most significant
583 * bit, and so on.
584 *
7b064a79
BP
585 * 'dst' is an nxm_header with nxm_hasmask=0. See the documentation for
586 * NXAST_REG_MOVE, above, for the permitted fields and for the side effects of
587 * loading them.
b6c9e612
BP
588 *
589 * The 'ofs' and 'n_bits' fields are combined into a single 'ofs_nbits' field
590 * to avoid enlarging the structure by another 8 bytes. To allow 'n_bits' to
591 * take a value between 1 and 64 (inclusive) while taking up only 6 bits, it is
592 * also stored as one less than its true value:
593 *
594 * 15 6 5 0
595 * +------------------------------+------------------+
596 * | ofs | n_bits - 1 |
597 * +------------------------------+------------------+
598 *
599 * The switch will reject actions for which ofs+n_bits is greater than the
600 * width of 'dst', or in which any bits in 'value' with value 2**n_bits or
601 * greater are set to 1, with error type OFPET_BAD_ACTION, code
602 * OFPBAC_BAD_ARGUMENT.
603 */
604struct nx_action_reg_load {
605 ovs_be16 type; /* OFPAT_VENDOR. */
606 ovs_be16 len; /* Length is 16. */
607 ovs_be32 vendor; /* NX_VENDOR_ID. */
608 ovs_be16 subtype; /* NXAST_REG_LOAD. */
609 ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */
610 ovs_be32 dst; /* Destination register. */
611 ovs_be64 value; /* Immediate value. */
612};
613OFP_ASSERT(sizeof(struct nx_action_reg_load) == 24);
614
96fc46e8
BP
615/* Action structure for NXAST_NOTE.
616 *
617 * This action has no effect. It is variable length. The switch does not
618 * attempt to interpret the user-defined 'note' data in any way. A controller
619 * can use this action to attach arbitrary metadata to a flow.
620 *
621 * This action might go away in the future.
622 */
623struct nx_action_note {
459749fe
BP
624 ovs_be16 type; /* OFPAT_VENDOR. */
625 ovs_be16 len; /* A multiple of 8, but at least 16. */
626 ovs_be32 vendor; /* NX_VENDOR_ID. */
627 ovs_be16 subtype; /* NXAST_NOTE. */
96fc46e8
BP
628 uint8_t note[6]; /* Start of user-defined data. */
629 /* Possibly followed by additional user-defined data. */
630};
631OFP_ASSERT(sizeof(struct nx_action_note) == 16);
632
53ddd40a
BP
633/* Action structure for NXAST_MULTIPATH.
634 *
635 * This action performs the following steps in sequence:
636 *
520e9a2a 637 * 1. Hashes the fields designated by 'fields', one of NX_HASH_FIELDS_*.
53ddd40a
BP
638 * Refer to the definition of "enum nx_mp_fields" for details.
639 *
640 * The 'basis' value is used as a universal hash parameter, that is,
641 * different values of 'basis' yield different hash functions. The
642 * particular universal hash function used is implementation-defined.
643 *
644 * The hashed fields' values are drawn from the current state of the
645 * flow, including all modifications that have been made by actions up to
646 * this point.
647 *
648 * 2. Applies the multipath link choice algorithm specified by 'algorithm',
649 * one of NX_MP_ALG_*. Refer to the definition of "enum nx_mp_algorithm"
650 * for details.
651 *
652 * The output of the algorithm is 'link', an unsigned integer less than
653 * or equal to 'max_link'.
654 *
655 * Some algorithms use 'arg' as an additional argument.
656 *
657 * 3. Stores 'link' in dst[ofs:ofs+n_bits]. The format and semantics of
338bd6a0 658 * 'dst' and 'ofs_nbits' are similar to those for the NXAST_REG_LOAD
43edca57 659 * action.
53ddd40a
BP
660 *
661 * The switch will reject actions that have an unknown 'fields', or an unknown
662 * 'algorithm', or in which ofs+n_bits is greater than the width of 'dst', or
663 * in which 'max_link' is greater than or equal to 2**n_bits, with error type
664 * OFPET_BAD_ACTION, code OFPBAC_BAD_ARGUMENT.
665 */
666struct nx_action_multipath {
667 ovs_be16 type; /* OFPAT_VENDOR. */
668 ovs_be16 len; /* Length is 32. */
669 ovs_be32 vendor; /* NX_VENDOR_ID. */
670 ovs_be16 subtype; /* NXAST_MULTIPATH. */
671
672 /* What fields to hash and how. */
520e9a2a 673 ovs_be16 fields; /* One of NX_HASH_FIELDS_*. */
53ddd40a
BP
674 ovs_be16 basis; /* Universal hash parameter. */
675 ovs_be16 pad0;
676
677 /* Multipath link choice algorithm to apply to hash value. */
678 ovs_be16 algorithm; /* One of NX_MP_ALG_*. */
679 ovs_be16 max_link; /* Number of output links, minus 1. */
680 ovs_be32 arg; /* Algorithm-specific argument. */
681 ovs_be16 pad1;
682
683 /* Where to store the result. */
684 ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */
43edca57 685 ovs_be32 dst; /* Destination. */
53ddd40a
BP
686};
687OFP_ASSERT(sizeof(struct nx_action_multipath) == 32);
688
53ddd40a
BP
689/* NXAST_MULTIPATH: Multipath link choice algorithm to apply.
690 *
691 * In the descriptions below, 'n_links' is max_link + 1. */
692enum nx_mp_algorithm {
693 /* link = hash(flow) % n_links.
694 *
695 * Redistributes all traffic when n_links changes. O(1) performance. See
696 * RFC 2992.
697 *
698 * Use UINT16_MAX for max_link to get a raw hash value. */
699 NX_MP_ALG_MODULO_N,
700
701 /* link = hash(flow) / (MAX_HASH / n_links).
702 *
703 * Redistributes between one-quarter and one-half of traffic when n_links
704 * changes. O(1) performance. See RFC 2992.
705 */
706 NX_MP_ALG_HASH_THRESHOLD,
707
708 /* for i in [0,n_links):
709 * weights[i] = hash(flow, i)
710 * link = { i such that weights[i] >= weights[j] for all j != i }
711 *
712 * Redistributes 1/n_links of traffic when n_links changes. O(n_links)
713 * performance. If n_links is greater than a threshold (currently 64, but
714 * subject to change), Open vSwitch will substitute another algorithm
715 * automatically. See RFC 2992. */
716 NX_MP_ALG_HRW, /* Highest Random Weight. */
717
718 /* i = 0
719 * repeat:
720 * i = i + 1
721 * link = hash(flow, i) % arg
722 * while link > max_link
723 *
724 * Redistributes 1/n_links of traffic when n_links changes. O(1)
725 * performance when arg/max_link is bounded by a constant.
726 *
727 * Redistributes all traffic when arg changes.
728 *
729 * arg must be greater than max_link and for best performance should be no
730 * more than approximately max_link * 2. If arg is outside the acceptable
731 * range, Open vSwitch will automatically substitute the least power of 2
732 * greater than max_link.
733 *
734 * This algorithm is specific to Open vSwitch.
735 */
736 NX_MP_ALG_ITER_HASH /* Iterative Hash. */
737};
09246b99 738\f
75a75043
BP
739/* Action structure for NXAST_LEARN.
740 *
741 * This action adds or modifies a flow in an OpenFlow table, similar to
742 * OFPT_FLOW_MOD with OFPFC_MODIFY_STRICT as 'command'. The new flow has the
743 * specified idle timeout, hard timeout, priority, cookie, and flags. The new
744 * flow's match criteria and actions are built by applying each of the series
745 * of flow_mod_spec elements included as part of the action.
746 *
747 * A flow_mod_spec starts with a 16-bit header. A header that is all-bits-0 is
748 * a no-op used for padding the action as a whole to a multiple of 8 bytes in
749 * length. Otherwise, the flow_mod_spec can be thought of as copying 'n_bits'
750 * bits from a source to a destination. In this case, the header contains
751 * multiple fields:
752 *
753 * 15 14 13 12 11 10 0
754 * +------+---+------+---------------------------------+
755 * | 0 |src| dst | n_bits |
756 * +------+---+------+---------------------------------+
757 *
758 * The meaning and format of a flow_mod_spec depends on 'src' and 'dst'. The
759 * following table summarizes the meaning of each possible combination.
760 * Details follow the table:
761 *
762 * src dst meaning
763 * --- --- ----------------------------------------------------------
764 * 0 0 Add match criteria based on value in a field.
765 * 1 0 Add match criteria based on an immediate value.
766 * 0 1 Add NXAST_REG_LOAD action to copy field into a different field.
767 * 1 1 Add NXAST_REG_LOAD action to load immediate value into a field.
768 * 0 2 Add OFPAT_OUTPUT action to output to port from specified field.
769 * All other combinations are undefined and not allowed.
770 *
771 * The flow_mod_spec header is followed by a source specification and a
772 * destination specification. The format and meaning of the source
773 * specification depends on 'src':
774 *
775 * - If 'src' is 0, the source bits are taken from a field in the flow to
776 * which this action is attached. (This should be a wildcarded field. If
777 * its value is fully specified then the source bits being copied have
778 * constant values.)
779 *
780 * The source specification is an ovs_be32 'field' and an ovs_be16 'ofs'.
781 * 'field' is an nxm_header with nxm_hasmask=0, and 'ofs' the starting bit
782 * offset within that field. The source bits are field[ofs:ofs+n_bits-1].
783 * 'field' and 'ofs' are subject to the same restrictions as the source
784 * field in NXAST_REG_MOVE.
785 *
786 * - If 'src' is 1, the source bits are a constant value. The source
787 * specification is (n_bits+15)/16*2 bytes long. Taking those bytes as a
788 * number in network order, the source bits are the 'n_bits'
789 * least-significant bits. The switch will report an error if other bits
790 * in the constant are nonzero.
791 *
792 * The flow_mod_spec destination specification, for 'dst' of 0 or 1, is an
793 * ovs_be32 'field' and an ovs_be16 'ofs'. 'field' is an nxm_header with
794 * nxm_hasmask=0 and 'ofs' is a starting bit offset within that field. The
795 * meaning of the flow_mod_spec depends on 'dst':
796 *
797 * - If 'dst' is 0, the flow_mod_spec specifies match criteria for the new
798 * flow. The new flow matches only if bits field[ofs:ofs+n_bits-1] in a
799 * packet equal the source bits. 'field' may be any nxm_header with
800 * nxm_hasmask=0 that is allowed in NXT_FLOW_MOD.
801 *
802 * Order is significant. Earlier flow_mod_specs must satisfy any
803 * prerequisites for matching fields specified later, by copying constant
804 * values into prerequisite fields.
805 *
806 * The switch will reject flow_mod_specs that do not satisfy NXM masking
807 * restrictions.
808 *
809 * - If 'dst' is 1, the flow_mod_spec specifies an NXAST_REG_LOAD action for
810 * the new flow. The new flow copies the source bits into
811 * field[ofs:ofs+n_bits-1]. Actions are executed in the same order as the
812 * flow_mod_specs.
813 *
814 * The flow_mod_spec destination spec for 'dst' of 2 (when 'src' is 0) is
815 * empty. It has the following meaning:
816 *
817 * - The flow_mod_spec specifies an OFPAT_OUTPUT action for the new flow.
818 * The new flow outputs to the OpenFlow port specified by the source field.
819 * Of the special output ports with value OFPP_MAX or larger, OFPP_IN_PORT,
820 * OFPP_FLOOD, OFPP_LOCAL, and OFPP_ALL are supported. Other special ports
821 * may not be used.
822 *
823 * Resource Management
824 * -------------------
825 *
826 * A switch has a finite amount of flow table space available for learning.
827 * When this space is exhausted, no new learning table entries will be learned
828 * until some existing flow table entries expire. The controller should be
829 * prepared to handle this by flooding (which can be implemented as a
830 * low-priority flow).
831 *
832 * Examples
833 * --------
834 *
835 * The following examples give a prose description of the flow_mod_specs along
836 * with informal notation for how those would be represented and a hex dump of
837 * the bytes that would be required.
838 *
839 * These examples could work with various nx_action_learn parameters. Typical
840 * values would be idle_timeout=OFP_FLOW_PERMANENT, hard_timeout=60,
841 * priority=OFP_DEFAULT_PRIORITY, flags=0, table_id=10.
842 *
843 * 1. Learn input port based on the source MAC, with lookup into
844 * NXM_NX_REG1[16:31] by resubmit to in_port=99:
845 *
846 * Match on in_port=99:
847 * ovs_be16(src=1, dst=0, n_bits=16), 20 10
848 * ovs_be16(99), 00 63
849 * ovs_be32(NXM_OF_IN_PORT), ovs_be16(0) 00 00 00 02 00 00
850 *
851 * Match Ethernet destination on Ethernet source from packet:
852 * ovs_be16(src=0, dst=0, n_bits=48), 00 30
853 * ovs_be32(NXM_OF_ETH_SRC), ovs_be16(0) 00 00 04 06 00 00
854 * ovs_be32(NXM_OF_ETH_DST), ovs_be16(0) 00 00 02 06 00 00
855 *
856 * Set NXM_NX_REG1[16:31] to the packet's input port:
857 * ovs_be16(src=0, dst=1, n_bits=16), 08 10
858 * ovs_be32(NXM_OF_IN_PORT), ovs_be16(0) 00 00 00 02 00 00
859 * ovs_be32(NXM_NX_REG1), ovs_be16(16) 00 01 02 04 00 10
860 *
861 * Given a packet that arrived on port A with Ethernet source address B,
862 * this would set up the flow "in_port=99, dl_dst=B,
863 * actions=load:A->NXM_NX_REG1[16..31]".
864 *
865 * In syntax accepted by ovs-ofctl, this action is: learn(in_port=99,
eddfcba7
BP
866 * NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],
867 * load:NXM_OF_IN_PORT[]->NXM_NX_REG1[16..31])
75a75043
BP
868 *
869 * 2. Output to input port based on the source MAC and VLAN VID, with lookup
870 * into NXM_NX_REG1[16:31]:
871 *
872 * Match on same VLAN ID as packet:
873 * ovs_be16(src=0, dst=0, n_bits=12), 00 0c
874 * ovs_be32(NXM_OF_VLAN_TCI), ovs_be16(0) 00 00 08 02 00 00
875 * ovs_be32(NXM_OF_VLAN_TCI), ovs_be16(0) 00 00 08 02 00 00
876 *
877 * Match Ethernet destination on Ethernet source from packet:
878 * ovs_be16(src=0, dst=0, n_bits=48), 00 30
879 * ovs_be32(NXM_OF_ETH_SRC), ovs_be16(0) 00 00 04 06 00 00
880 * ovs_be32(NXM_OF_ETH_DST), ovs_be16(0) 00 00 02 06 00 00
881 *
882 * Output to the packet's input port:
883 * ovs_be16(src=0, dst=2, n_bits=16), 10 10
884 * ovs_be32(NXM_OF_IN_PORT), ovs_be16(0) 00 00 00 02 00 00
885 *
886 * Given a packet that arrived on port A with Ethernet source address B in
887 * VLAN C, this would set up the flow "dl_dst=B, vlan_vid=C,
888 * actions=output:A".
889 *
890 * In syntax accepted by ovs-ofctl, this action is:
891 * learn(NXM_OF_VLAN_TCI[0..11], NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[],
892 * output:NXM_OF_IN_PORT[])
893 *
894 * 3. Here's a recipe for a very simple-minded MAC learning switch. It uses a
895 * 10-second MAC expiration time to make it easier to see what's going on
896 *
897 * ovs-vsctl del-controller br0
898 * ovs-ofctl del-flows br0
899 * ovs-ofctl add-flow br0 "table=0 actions=learn(table=1, \
900 hard_timeout=10, NXM_OF_VLAN_TCI[0..11], \
901 NXM_OF_ETH_DST[]=NXM_OF_ETH_SRC[], \
902 output:NXM_OF_IN_PORT[]), resubmit(,1)"
903 * ovs-ofctl add-flow br0 "table=1 priority=0 actions=flood"
904 *
905 * You can then dump the MAC learning table with:
906 *
907 * ovs-ofctl dump-flows br0 table=1
908 *
909 * Usage Advice
910 * ------------
911 *
912 * For best performance, segregate learned flows into a table that is not used
913 * for any other flows except possibly for a lowest-priority "catch-all" flow
914 * (a flow with no match criteria). If different learning actions specify
915 * different match criteria, use different tables for the learned flows.
916 *
917 * The meaning of 'hard_timeout' and 'idle_timeout' can be counterintuitive.
918 * These timeouts apply to the flow that is added, which means that a flow with
919 * an idle timeout will expire when no traffic has been sent *to* the learned
920 * address. This is not usually the intent in MAC learning; instead, we want
921 * the MAC learn entry to expire when no traffic has been sent *from* the
922 * learned address. Use a hard timeout for that.
923 */
924struct nx_action_learn {
925 ovs_be16 type; /* OFPAT_VENDOR. */
926 ovs_be16 len; /* At least 24. */
927 ovs_be32 vendor; /* NX_VENDOR_ID. */
928 ovs_be16 subtype; /* NXAST_LEARN. */
929 ovs_be16 idle_timeout; /* Idle time before discarding (seconds). */
930 ovs_be16 hard_timeout; /* Max time before discarding (seconds). */
931 ovs_be16 priority; /* Priority level of flow entry. */
932 ovs_be64 cookie; /* Cookie for new flow. */
933 ovs_be16 flags; /* Either 0 or OFPFF_SEND_FLOW_REM. */
934 uint8_t table_id; /* Table to insert flow entry. */
935 uint8_t pad[5]; /* Must be zero. */
936 /* Followed by a sequence of flow_mod_spec elements, as described above,
937 * until the end of the action is reached. */
938};
939OFP_ASSERT(sizeof(struct nx_action_learn) == 32);
940
941#define NX_LEARN_N_BITS_MASK 0x3ff
942
943#define NX_LEARN_SRC_FIELD (0 << 13) /* Copy from field. */
944#define NX_LEARN_SRC_IMMEDIATE (1 << 13) /* Copy from immediate value. */
945#define NX_LEARN_SRC_MASK (1 << 13)
946
947#define NX_LEARN_DST_MATCH (0 << 11) /* Add match criterion. */
948#define NX_LEARN_DST_LOAD (1 << 11) /* Add NXAST_REG_LOAD action. */
949#define NX_LEARN_DST_OUTPUT (2 << 11) /* Add OFPAT_OUTPUT action. */
950#define NX_LEARN_DST_RESERVED (3 << 11) /* Not yet defined. */
951#define NX_LEARN_DST_MASK (3 << 11)
952\f
3b6a2571
EJ
953/* Action structure for NXAST_AUTOPATH.
954 *
955 * This action performs the following steps in sequence:
956 *
957 * 1. Hashes the flow using an implementation-defined hash function.
958 *
959 * The hashed fields' values are drawn from the current state of the
960 * flow, including all modifications that have been made by actions up to
961 * this point.
962 *
963 * 2. Selects an OpenFlow 'port'.
964 *
965 * 'port' is selected in an implementation-defined manner, taking into
966 * account 'id' and the hash value calculated in step 1.
967 *
968 * Generally a switch will have been configured with a set of ports that
969 * may be chosen given 'id'. The switch may take into account any number
970 * of factors when choosing 'port' from its configured set. Factors may
971 * include carrier, load, and the results of configuration protocols such
972 * as LACP.
973 *
974 * 3. Stores 'port' in dst[ofs:ofs+n_bits].
975 *
976 * The format and semantics of 'dst' and 'ofs_nbits' are similar to those
43edca57 977 * for the NXAST_REG_LOAD action.
3b6a2571
EJ
978 *
979 * The switch will reject actions in which ofs+n_bits is greater than the width
980 * of 'dst', with error type OFPET_BAD_ACTION, code OFPBAC_BAD_ARGUMENT.
981 */
982struct nx_action_autopath {
983 ovs_be16 type; /* OFPAT_VENDOR. */
984 ovs_be16 len; /* Length is 20. */
985 ovs_be32 vendor; /* NX_VENDOR_ID. */
eac7014f 986 ovs_be16 subtype; /* NXAST_AUTOPATH. */
3b6a2571
EJ
987
988 /* Where to store the result. */
989 ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */
43edca57 990 ovs_be32 dst; /* Destination. */
3b6a2571
EJ
991
992 ovs_be32 id; /* Autopath ID. */
993 ovs_be32 pad;
994};
995OFP_ASSERT(sizeof(struct nx_action_autopath) == 24);
996\f
a368bb53 997/* Action structure for NXAST_BUNDLE and NXAST_BUNDLE_LOAD.
daff3353 998 *
a368bb53
EJ
999 * The bundle actions choose a slave from a supplied list of options.
1000 * NXAST_BUNDLE outputs to its selection. NXAST_BUNDLE_LOAD writes its
1001 * selection to a register.
daff3353
EJ
1002 *
1003 * The list of possible slaves follows the nx_action_bundle structure. The size
1004 * of each slave is governed by its type as indicated by the 'slave_type'
1005 * parameter. The list of slaves should be padded at its end with zeros to make
1006 * the total length of the action a multiple of 8.
1007 *
1008 * Switches infer from the 'slave_type' parameter the size of each slave. All
1009 * implementations must support the NXM_OF_IN_PORT 'slave_type' which indicates
1010 * that the slaves are OpenFlow port numbers with NXM_LENGTH(NXM_OF_IN_PORT) ==
1011 * 2 byte width. Switches should reject actions which indicate unknown or
1012 * unsupported slave types.
1013 *
1014 * Switches use a strategy dictated by the 'algorithm' parameter to choose a
1015 * slave. If the switch does not support the specified 'algorithm' parameter,
1016 * it should reject the action.
1017 *
439e4d8c
EJ
1018 * Several algorithms take into account liveness when selecting slaves. The
1019 * liveness of a slave is implementation defined (with one exception), but will
1020 * generally take into account things like its carrier status and the results
1021 * of any link monitoring protocols which happen to be running on it. In order
1022 * to give controllers a place-holder value, the OFPP_NONE port is always
1023 * considered live.
1024 *
daff3353
EJ
1025 * Some slave selection strategies require the use of a hash function, in which
1026 * case the 'fields' and 'basis' parameters should be populated. The 'fields'
1027 * parameter (one of NX_HASH_FIELDS_*) designates which parts of the flow to
1028 * hash. Refer to the definition of "enum nx_hash_fields" for details. The
1029 * 'basis' parameter is used as a universal hash parameter. Different values
1030 * of 'basis' yield different hash results.
1031 *
1032 * The 'zero' parameter at the end of the action structure is reserved for
1033 * future use. Switches are required to reject actions which have nonzero
a368bb53
EJ
1034 * bytes in the 'zero' field.
1035 *
1036 * NXAST_BUNDLE actions should have 'ofs_nbits' and 'dst' zeroed. Switches
1037 * should reject actions which have nonzero bytes in either of these fields.
1038 *
1039 * NXAST_BUNDLE_LOAD stores the OpenFlow port number of the selected slave in
1040 * dst[ofs:ofs+n_bits]. The format and semantics of 'dst' and 'ofs_nbits' are
1041 * similar to those for the NXAST_REG_LOAD action. */
daff3353
EJ
1042struct nx_action_bundle {
1043 ovs_be16 type; /* OFPAT_VENDOR. */
1044 ovs_be16 len; /* Length including slaves. */
1045 ovs_be32 vendor; /* NX_VENDOR_ID. */
799d2bfa 1046 ovs_be16 subtype; /* NXAST_BUNDLE or NXAST_BUNDLE_LOAD. */
daff3353
EJ
1047
1048 /* Slave choice algorithm to apply to hash value. */
1049 ovs_be16 algorithm; /* One of NX_BD_ALG_*. */
1050
1051 /* What fields to hash and how. */
735bc64a 1052 ovs_be16 fields; /* One of NX_HASH_FIELDS_*. */
daff3353
EJ
1053 ovs_be16 basis; /* Universal hash parameter. */
1054
1055 ovs_be32 slave_type; /* NXM_OF_IN_PORT. */
1056 ovs_be16 n_slaves; /* Number of slaves. */
1057
a368bb53
EJ
1058 ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */
1059 ovs_be32 dst; /* Destination. */
1060
1061 uint8_t zero[4]; /* Reserved. Must be zero. */
daff3353
EJ
1062};
1063OFP_ASSERT(sizeof(struct nx_action_bundle) == 32);
1064
1065/* NXAST_BUNDLE: Bundle slave choice algorithm to apply.
1066 *
1067 * In the descriptions below, 'slaves' is the list of possible slaves in the
1068 * order they appear in the OpenFlow action. */
1069enum nx_bd_algorithm {
1070 /* Chooses the first live slave listed in the bundle.
1071 *
1072 * O(n_slaves) performance. */
1073 NX_BD_ALG_ACTIVE_BACKUP,
1074
1075 /* for i in [0,n_slaves):
1076 * weights[i] = hash(flow, i)
1077 * slave = { slaves[i] such that weights[i] >= weights[j] for all j != i }
1078 *
1079 * Redistributes 1/n_slaves of traffic when a slave's liveness changes.
1080 * O(n_slaves) performance.
1081 *
1082 * Uses the 'fields' and 'basis' parameters. */
1083 NX_BD_ALG_HRW /* Highest Random Weight. */
1084};
1085\f
f694937d
EJ
1086/* Action structure for NXAST_OUTPUT_REG.
1087 *
1088 * Outputs to the OpenFlow port number written to src[ofs:ofs+nbits].
1089 *
1090 * The format and semantics of 'src' and 'ofs_nbits' are similar to those for
1091 * the NXAST_REG_LOAD action.
1092 *
1093 * The acceptable nxm_header values for 'src' are the same as the acceptable
1094 * nxm_header values for the 'src' field of NXAST_REG_MOVE.
1095 *
1096 * The 'max_len' field indicates the number of bytes to send when the chosen
1097 * port is OFPP_CONTROLLER. Its semantics are equivalent to the 'max_len'
1098 * field of OFPAT_OUTPUT.
1099 *
1100 * The 'zero' field is required to be zeroed for forward compatibility. */
1101struct nx_action_output_reg {
1102 ovs_be16 type; /* OFPAT_VENDOR. */
1103 ovs_be16 len; /* 24. */
1104 ovs_be32 vendor; /* NX_VENDOR_ID. */
1105 ovs_be16 subtype; /* NXAST_OUTPUT_REG. */
1106
1107 ovs_be16 ofs_nbits; /* (ofs << 6) | (n_bits - 1). */
1108 ovs_be32 src; /* Source. */
1109
1110 ovs_be16 max_len; /* Max length to send to controller. */
1111
1112 uint8_t zero[6]; /* Reserved, must be zero. */
1113};
1114OFP_ASSERT(sizeof(struct nx_action_output_reg) == 24);
1115\f
848e8809
EJ
1116/* NXAST_EXIT
1117 *
1118 * Discontinues action processing.
1119 *
1120 * The NXAST_EXIT action causes the switch to immediately halt processing
1121 * actions for the flow. Any actions which have already been processed are
1122 * executed by the switch. However, any further actions, including those which
1123 * may be in different tables, or different levels of the NXAST_RESUBMIT
1124 * hierarchy, will be ignored.
1125 *
1126 * Uses the nx_action_header structure. */
1127\f
09246b99
BP
1128/* Flexible flow specifications (aka NXM = Nicira Extended Match).
1129 *
1130 * OpenFlow 1.0 has "struct ofp_match" for specifying flow matches. This
1131 * structure is fixed-length and hence difficult to extend. This section
1132 * describes a more flexible, variable-length flow match, called "nx_match" for
1133 * short, that is also supported by Open vSwitch. This section also defines a
1134 * replacement for each OpenFlow message that includes struct ofp_match.
1135 *
1136 *
1137 * Format
1138 * ======
1139 *
1140 * An nx_match is a sequence of zero or more "nxm_entry"s, which are
1141 * type-length-value (TLV) entries, each 5 to 259 (inclusive) bytes long.
1142 * "nxm_entry"s are not aligned on or padded to any multibyte boundary. The
1143 * first 4 bytes of an nxm_entry are its "header", followed by the entry's
1144 * "body".
1145 *
1146 * An nxm_entry's header is interpreted as a 32-bit word in network byte order:
1147 *
1148 * |<-------------------- nxm_type ------------------>|
1149 * | |
1150 * |31 16 15 9| 8 7 0
1151 * +----------------------------------+---------------+--+------------------+
1152 * | nxm_vendor | nxm_field |hm| nxm_length |
1153 * +----------------------------------+---------------+--+------------------+
1154 *
1155 * The most-significant 23 bits of the header are collectively "nxm_type".
1156 * Bits 16...31 are "nxm_vendor", one of the NXM_VENDOR_* values below. Bits
1157 * 9...15 are "nxm_field", which is a vendor-specific value. nxm_type normally
1158 * designates a protocol header, such as the Ethernet type, but it can also
1159 * refer to packet metadata, such as the switch port on which a packet arrived.
1160 *
1161 * Bit 8 is "nxm_hasmask" (labeled "hm" above for space reasons). The meaning
1162 * of this bit is explained later.
1163 *
1164 * The least-significant 8 bits are "nxm_length", a positive integer. The
1165 * length of the nxm_entry, including the header, is exactly 4 + nxm_length
1166 * bytes.
1167 *
1168 * For a given nxm_vendor, nxm_field, and nxm_hasmask value, nxm_length is a
1169 * constant. It is included only to allow software to minimally parse
1170 * "nxm_entry"s of unknown types. (Similarly, for a given nxm_vendor,
1171 * nxm_field, and nxm_length, nxm_hasmask is a constant.)
1172 *
1173 *
1174 * Semantics
1175 * =========
1176 *
1177 * A zero-length nx_match (one with no "nxm_entry"s) matches every packet.
1178 *
1179 * An nxm_entry places a constraint on the packets matched by the nx_match:
1180 *
1181 * - If nxm_hasmask is 0, the nxm_entry's body contains a value for the
1182 * field, called "nxm_value". The nx_match matches only packets in which
1183 * the field equals nxm_value.
1184 *
1185 * - If nxm_hasmask is 1, then the nxm_entry's body contains a value for the
1186 * field (nxm_value), followed by a bitmask of the same length as the
1187 * value, called "nxm_mask". For each 1-bit in position J in nxm_mask, the
1188 * nx_match matches only packets for which bit J in the given field's value
1189 * matches bit J in nxm_value. A 0-bit in nxm_mask causes the
1190 * corresponding bits in nxm_value and the field's value to be ignored.
1191 * (The sense of the nxm_mask bits is the opposite of that used by the
1192 * "wildcards" member of struct ofp_match.)
1193 *
1194 * When nxm_hasmask is 1, nxm_length is always even.
1195 *
1196 * An all-zero-bits nxm_mask is equivalent to omitting the nxm_entry
1197 * entirely. An all-one-bits nxm_mask is equivalent to specifying 0 for
1198 * nxm_hasmask.
1199 *
1200 * When there are multiple "nxm_entry"s, all of the constraints must be met.
1201 *
1202 *
1203 * Mask Restrictions
1204 * =================
1205 *
1206 * Masks may be restricted:
1207 *
1208 * - Some nxm_types may not support masked wildcards, that is, nxm_hasmask
1209 * must always be 0 when these fields are specified. For example, the
1210 * field that identifies the port on which a packet was received may not be
1211 * masked.
1212 *
1213 * - Some nxm_types that do support masked wildcards may only support certain
1214 * nxm_mask patterns. For example, fields that have IPv4 address values
1215 * may be restricted to CIDR masks.
1216 *
1217 * These restrictions should be noted in specifications for individual fields.
1218 * A switch may accept an nxm_hasmask or nxm_mask value that the specification
1219 * disallows, if the switch correctly implements support for that nxm_hasmask
1220 * or nxm_mask value. A switch must reject an attempt to set up a flow that
1221 * contains a nxm_hasmask or nxm_mask value that it does not support.
1222 *
1223 *
1224 * Prerequisite Restrictions
1225 * =========================
1226 *
1227 * The presence of an nxm_entry with a given nxm_type may be restricted based
1228 * on the presence of or values of other "nxm_entry"s. For example:
1229 *
1230 * - An nxm_entry for nxm_type=NXM_OF_IP_TOS is allowed only if it is
1231 * preceded by another entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0,
1232 * and nxm_value=0x0800. That is, matching on the IP source address is
1233 * allowed only if the Ethernet type is explicitly set to IP.
1234 *
e51df1a0
BP
1235 * - An nxm_entry for nxm_type=NXM_OF_TCP_SRC is allowed only if it is
1236 * preceded by an entry with nxm_type=NXM_OF_ETH_TYPE, nxm_hasmask=0, and
1237 * nxm_value either 0x0800 or 0x86dd, and another with
1238 * nxm_type=NXM_OF_IP_PROTO, nxm_hasmask=0, nxm_value=6, in that order.
1239 * That is, matching on the TCP source port is allowed only if the Ethernet
1240 * type is IP or IPv6 and the IP protocol is TCP.
09246b99
BP
1241 *
1242 * These restrictions should be noted in specifications for individual fields.
1243 * A switch may implement relaxed versions of these restrictions. A switch
1244 * must reject an attempt to set up a flow that violates its restrictions.
1245 *
1246 *
1247 * Ordering Restrictions
1248 * =====================
1249 *
1250 * An nxm_entry that has prerequisite restrictions must appear after the
1251 * "nxm_entry"s for its prerequisites. Ordering of "nxm_entry"s within an
1252 * nx_match is not otherwise constrained.
1253 *
1254 * Any given nxm_type may appear in an nx_match at most once.
1255 *
1256 *
1257 * nxm_entry Examples
1258 * ==================
1259 *
1260 * These examples show the format of a single nxm_entry with particular
1261 * nxm_hasmask and nxm_length values. The diagrams are labeled with field
1262 * numbers and byte indexes.
1263 *
1264 *
be86ea7a 1265 * 8-bit nxm_value, nxm_hasmask=1, nxm_length=2:
09246b99
BP
1266 *
1267 * 0 3 4 5
1268 * +------------+---+---+
1269 * | header | v | m |
1270 * +------------+---+---+
1271 *
1272 *
1273 * 16-bit nxm_value, nxm_hasmask=0, nxm_length=2:
1274 *
1275 * 0 3 4 5
1276 * +------------+------+
1277 * | header | value|
1278 * +------------+------+
1279 *
1280 *
1281 * 32-bit nxm_value, nxm_hasmask=0, nxm_length=4:
1282 *
1283 * 0 3 4 7
1284 * +------------+-------------+
1285 * | header | nxm_value |
1286 * +------------+-------------+
1287 *
1288 *
1289 * 48-bit nxm_value, nxm_hasmask=0, nxm_length=6:
1290 *
1291 * 0 3 4 9
1292 * +------------+------------------+
1293 * | header | nxm_value |
1294 * +------------+------------------+
1295 *
1296 *
1297 * 48-bit nxm_value, nxm_hasmask=1, nxm_length=12:
1298 *
1299 * 0 3 4 9 10 15
1300 * +------------+------------------+------------------+
1301 * | header | nxm_value | nxm_mask |
1302 * +------------+------------------+------------------+
1303 *
1304 *
1305 * Error Reporting
1306 * ===============
1307 *
1308 * A switch should report an error in an nx_match using error type
1309 * OFPET_BAD_REQUEST and one of the NXBRC_NXM_* codes. Ideally the switch
1310 * should report a specific error code, if one is assigned for the particular
1311 * problem, but NXBRC_NXM_INVALID is also available to report a generic
1312 * nx_match error.
1313 */
1314
1315#define NXM_HEADER__(VENDOR, FIELD, HASMASK, LENGTH) \
1316 (((VENDOR) << 16) | ((FIELD) << 9) | ((HASMASK) << 8) | (LENGTH))
1317#define NXM_HEADER(VENDOR, FIELD, LENGTH) \
1318 NXM_HEADER__(VENDOR, FIELD, 0, LENGTH)
1319#define NXM_HEADER_W(VENDOR, FIELD, LENGTH) \
1320 NXM_HEADER__(VENDOR, FIELD, 1, (LENGTH) * 2)
1321#define NXM_VENDOR(HEADER) ((HEADER) >> 16)
1322#define NXM_FIELD(HEADER) (((HEADER) >> 9) & 0x7f)
1323#define NXM_TYPE(HEADER) (((HEADER) >> 9) & 0x7fffff)
1324#define NXM_HASMASK(HEADER) (((HEADER) >> 8) & 1)
1325#define NXM_LENGTH(HEADER) ((HEADER) & 0xff)
1326
1327#define NXM_MAKE_WILD_HEADER(HEADER) \
1328 NXM_HEADER_W(NXM_VENDOR(HEADER), NXM_FIELD(HEADER), NXM_LENGTH(HEADER))
1329
1330/* ## ------------------------------- ## */
1331/* ## OpenFlow 1.0-compatible fields. ## */
1332/* ## ------------------------------- ## */
1333
1334/* Physical or virtual port on which the packet was received.
1335 *
1336 * Prereqs: None.
1337 *
1338 * Format: 16-bit integer in network byte order.
1339 *
1340 * Masking: Not maskable. */
1341#define NXM_OF_IN_PORT NXM_HEADER (0x0000, 0, 2)
1342
1343/* Source or destination address in Ethernet header.
1344 *
1345 * Prereqs: None.
1346 *
1347 * Format: 48-bit Ethernet MAC address.
1348 *
1e37a2d7
BP
1349 * Masking: The nxm_mask patterns 01:00:00:00:00:00 and FE:FF:FF:FF:FF:FF must
1350 * be supported for NXM_OF_ETH_DST_W (as well as the trivial patterns that
1351 * are all-0-bits or all-1-bits). Support for other patterns and for masking
1352 * of NXM_OF_ETH_SRC is optional. */
09246b99 1353#define NXM_OF_ETH_DST NXM_HEADER (0x0000, 1, 6)
1e37a2d7 1354#define NXM_OF_ETH_DST_W NXM_HEADER_W(0x0000, 1, 6)
09246b99
BP
1355#define NXM_OF_ETH_SRC NXM_HEADER (0x0000, 2, 6)
1356
1357/* Packet's Ethernet type.
1358 *
1359 * For an Ethernet II packet this is taken from the Ethernet header. For an
1360 * 802.2 LLC+SNAP header with OUI 00-00-00 this is taken from the SNAP header.
1361 * A packet that has neither format has value 0x05ff
1362 * (OFP_DL_TYPE_NOT_ETH_TYPE).
1363 *
1364 * For a packet with an 802.1Q header, this is the type of the encapsulated
1365 * frame.
1366 *
1367 * Prereqs: None.
1368 *
1369 * Format: 16-bit integer in network byte order.
1370 *
1371 * Masking: Not maskable. */
1372#define NXM_OF_ETH_TYPE NXM_HEADER (0x0000, 3, 2)
1373
1374/* 802.1Q TCI.
1375 *
1376 * For a packet with an 802.1Q header, this is the Tag Control Information
1377 * (TCI) field, with the CFI bit forced to 1. For a packet with no 802.1Q
1378 * header, this has value 0.
1379 *
1380 * Prereqs: None.
1381 *
1382 * Format: 16-bit integer in network byte order.
1383 *
1384 * Masking: Arbitrary masks.
1385 *
1386 * This field can be used in various ways:
1387 *
1388 * - If it is not constrained at all, the nx_match matches packets without
1389 * an 802.1Q header or with an 802.1Q header that has any TCI value.
1390 *
1391 * - Testing for an exact match with 0 matches only packets without an
1392 * 802.1Q header.
1393 *
1394 * - Testing for an exact match with a TCI value with CFI=1 matches packets
1395 * that have an 802.1Q header with a specified VID and PCP.
1396 *
1397 * - Testing for an exact match with a nonzero TCI value with CFI=0 does
1398 * not make sense. The switch may reject this combination.
1399 *
1400 * - Testing with a specific VID and CFI=1, with nxm_mask=0x1fff, matches
1401 * packets that have an 802.1Q header with that VID (and any PCP).
1402 *
1403 * - Testing with a specific PCP and CFI=1, with nxm_mask=0xf000, matches
1404 * packets that have an 802.1Q header with that PCP (and any VID).
1405 *
8ca67760 1406 * - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no 802.1Q
09246b99 1407 * header or with an 802.1Q header with a VID of 0.
8ca67760
BP
1408 *
1409 * - Testing with nxm_value=0, nxm_mask=0xe000 matches packets with no 802.1Q
1410 * header or with an 802.1Q header with a PCP of 0.
1411 *
1412 * - Testing with nxm_value=0, nxm_mask=0xefff matches packets with no 802.1Q
1413 * header or with an 802.1Q header with both VID and PCP of 0.
09246b99
BP
1414 */
1415#define NXM_OF_VLAN_TCI NXM_HEADER (0x0000, 4, 2)
1416#define NXM_OF_VLAN_TCI_W NXM_HEADER_W(0x0000, 4, 2)
1417
1418/* The "type of service" byte of the IP header, with the ECN bits forced to 0.
1419 *
d31f1109 1420 * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
09246b99
BP
1421 *
1422 * Format: 8-bit integer with 2 least-significant bits forced to 0.
1423 *
1424 * Masking: Not maskable. */
1425#define NXM_OF_IP_TOS NXM_HEADER (0x0000, 5, 1)
1426
1427/* The "protocol" byte in the IP header.
1428 *
d31f1109 1429 * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
09246b99
BP
1430 *
1431 * Format: 8-bit integer.
1432 *
1433 * Masking: Not maskable. */
1434#define NXM_OF_IP_PROTO NXM_HEADER (0x0000, 6, 1)
1435
1436/* The source or destination address in the IP header.
1437 *
1438 * Prereqs: NXM_OF_ETH_TYPE must match 0x0800 exactly.
1439 *
1440 * Format: 32-bit integer in network byte order.
1441 *
1442 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
1443 * high-order bits set to 1 and the other 32-N bits set to 0. */
1444#define NXM_OF_IP_SRC NXM_HEADER (0x0000, 7, 4)
1445#define NXM_OF_IP_SRC_W NXM_HEADER_W(0x0000, 7, 4)
1446#define NXM_OF_IP_DST NXM_HEADER (0x0000, 8, 4)
1447#define NXM_OF_IP_DST_W NXM_HEADER_W(0x0000, 8, 4)
1448
1449/* The source or destination port in the TCP header.
1450 *
1451 * Prereqs:
d31f1109 1452 * NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
09246b99
BP
1453 * NXM_OF_IP_PROTO must match 6 exactly.
1454 *
1455 * Format: 16-bit integer in network byte order.
1456 *
1457 * Masking: Not maskable. */
1458#define NXM_OF_TCP_SRC NXM_HEADER (0x0000, 9, 2)
1459#define NXM_OF_TCP_DST NXM_HEADER (0x0000, 10, 2)
1460
1461/* The source or destination port in the UDP header.
1462 *
1463 * Prereqs:
d31f1109 1464 * NXM_OF_ETH_TYPE must match either 0x0800 or 0x86dd.
09246b99
BP
1465 * NXM_OF_IP_PROTO must match 17 exactly.
1466 *
1467 * Format: 16-bit integer in network byte order.
1468 *
1469 * Masking: Not maskable. */
1470#define NXM_OF_UDP_SRC NXM_HEADER (0x0000, 11, 2)
1471#define NXM_OF_UDP_DST NXM_HEADER (0x0000, 12, 2)
1472
1473/* The type or code in the ICMP header.
1474 *
1475 * Prereqs:
1476 * NXM_OF_ETH_TYPE must match 0x0800 exactly.
1477 * NXM_OF_IP_PROTO must match 1 exactly.
1478 *
1479 * Format: 8-bit integer.
1480 *
1481 * Masking: Not maskable. */
1482#define NXM_OF_ICMP_TYPE NXM_HEADER (0x0000, 13, 1)
1483#define NXM_OF_ICMP_CODE NXM_HEADER (0x0000, 14, 1)
1484
1485/* ARP opcode.
1486 *
1487 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
1488 * otherwise. Only ARP opcodes between 1 and 255 should be specified for
1489 * matching.
1490 *
1491 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
1492 *
1493 * Format: 16-bit integer in network byte order.
1494 *
1495 * Masking: Not maskable. */
1496#define NXM_OF_ARP_OP NXM_HEADER (0x0000, 15, 2)
1497
1498/* For an Ethernet+IP ARP packet, the source or target protocol address
1499 * in the ARP header. Always 0 otherwise.
1500 *
1501 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
1502 *
1503 * Format: 32-bit integer in network byte order.
1504 *
1505 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
1506 * high-order bits set to 1 and the other 32-N bits set to 0. */
1507#define NXM_OF_ARP_SPA NXM_HEADER (0x0000, 16, 4)
1508#define NXM_OF_ARP_SPA_W NXM_HEADER_W(0x0000, 16, 4)
1509#define NXM_OF_ARP_TPA NXM_HEADER (0x0000, 17, 4)
1510#define NXM_OF_ARP_TPA_W NXM_HEADER_W(0x0000, 17, 4)
1511
1512/* ## ------------------------ ## */
1513/* ## Nicira match extensions. ## */
1514/* ## ------------------------ ## */
1515
b6c9e612
BP
1516/* Metadata registers.
1517 *
1518 * Registers initially have value 0. Actions allow register values to be
1519 * manipulated.
1520 *
1521 * Prereqs: None.
1522 *
1523 * Format: Array of 32-bit integer registers. Space is reserved for up to
1524 * NXM_NX_MAX_REGS registers, but switches may implement fewer.
1525 *
1526 * Masking: Arbitrary masks. */
1527#define NXM_NX_MAX_REGS 16
1528#define NXM_NX_REG(IDX) NXM_HEADER (0x0001, IDX, 4)
1529#define NXM_NX_REG_W(IDX) NXM_HEADER_W(0x0001, IDX, 4)
1530#define NXM_NX_REG_IDX(HEADER) NXM_FIELD(HEADER)
19e7439c
BP
1531#define NXM_IS_NX_REG(HEADER) (!((((HEADER) ^ NXM_NX_REG0)) & 0xffffe1ff))
1532#define NXM_IS_NX_REG_W(HEADER) (!((((HEADER) ^ NXM_NX_REG0_W)) & 0xffffe1ff))
b6c9e612
BP
1533#define NXM_NX_REG0 NXM_HEADER (0x0001, 0, 4)
1534#define NXM_NX_REG0_W NXM_HEADER_W(0x0001, 0, 4)
1535#define NXM_NX_REG1 NXM_HEADER (0x0001, 1, 4)
1536#define NXM_NX_REG1_W NXM_HEADER_W(0x0001, 1, 4)
1537#define NXM_NX_REG2 NXM_HEADER (0x0001, 2, 4)
1538#define NXM_NX_REG2_W NXM_HEADER_W(0x0001, 2, 4)
1539#define NXM_NX_REG3 NXM_HEADER (0x0001, 3, 4)
1540#define NXM_NX_REG3_W NXM_HEADER_W(0x0001, 3, 4)
d2c0fed9
JP
1541#define NXM_NX_REG4 NXM_HEADER (0x0001, 4, 4)
1542#define NXM_NX_REG4_W NXM_HEADER_W(0x0001, 4, 4)
b6c9e612 1543
09246b99
BP
1544/* Tunnel ID.
1545 *
1546 * For a packet received via GRE tunnel including a (32-bit) key, the key is
1547 * stored in the low 32-bits and the high bits are zeroed. For other packets,
1548 * the value is 0.
1549 *
1550 * Prereqs: None.
1551 *
1552 * Format: 64-bit integer in network byte order.
1553 *
1554 * Masking: Arbitrary masks. */
1555#define NXM_NX_TUN_ID NXM_HEADER (0x0001, 16, 8)
1556#define NXM_NX_TUN_ID_W NXM_HEADER_W(0x0001, 16, 8)
1557
bad68a99
JP
1558/* For an Ethernet+IP ARP packet, the source or target hardware address
1559 * in the ARP header. Always 0 otherwise.
1560 *
1561 * Prereqs: NXM_OF_ETH_TYPE must match 0x0806 exactly.
1562 *
1563 * Format: 48-bit Ethernet MAC address.
1564 *
1565 * Masking: Not maskable. */
1566#define NXM_NX_ARP_SHA NXM_HEADER (0x0001, 17, 6)
1567#define NXM_NX_ARP_THA NXM_HEADER (0x0001, 18, 6)
1568
d31f1109
JP
1569/* The source or destination address in the IPv6 header.
1570 *
1571 * Prereqs: NXM_OF_ETH_TYPE must match 0x86dd exactly.
1572 *
1573 * Format: 128-bit IPv6 address.
1574 *
1575 * Masking: Only CIDR masks are allowed, that is, masks that consist of N
1576 * high-order bits set to 1 and the other 128-N bits set to 0. */
1577#define NXM_NX_IPV6_SRC NXM_HEADER (0x0001, 19, 16)
1578#define NXM_NX_IPV6_SRC_W NXM_HEADER_W(0x0001, 19, 16)
1579#define NXM_NX_IPV6_DST NXM_HEADER (0x0001, 20, 16)
1580#define NXM_NX_IPV6_DST_W NXM_HEADER_W(0x0001, 20, 16)
1581
1582/* The type or code in the ICMPv6 header.
1583 *
1584 * Prereqs:
1585 * NXM_OF_ETH_TYPE must match 0x86dd exactly.
1586 * NXM_OF_IP_PROTO must match 58 exactly.
1587 *
1588 * Format: 8-bit integer.
1589 *
1590 * Masking: Not maskable. */
1591#define NXM_NX_ICMPV6_TYPE NXM_HEADER (0x0001, 21, 1)
1592#define NXM_NX_ICMPV6_CODE NXM_HEADER (0x0001, 22, 1)
1593
685a51a5
JP
1594/* The target address in an IPv6 Neighbor Discovery message.
1595 *
1596 * Prereqs:
1597 * NXM_OF_ETH_TYPE must match 0x86dd exactly.
1598 * NXM_OF_IP_PROTO must match 58 exactly.
1599 * NXM_OF_ICMPV6_TYPE must be either 135 or 136.
1600 *
1601 * Format: 128-bit IPv6 address.
1602 *
1603 * Masking: Not maskable. */
1604#define NXM_NX_ND_TARGET NXM_HEADER (0x0001, 23, 16)
1605
1606/* The source link-layer address option in an IPv6 Neighbor Discovery
1607 * message.
1608 *
1609 * Prereqs:
1610 * NXM_OF_ETH_TYPE must match 0x86dd exactly.
1611 * NXM_OF_IP_PROTO must match 58 exactly.
1612 * NXM_OF_ICMPV6_TYPE must be exactly 135.
1613 *
1614 * Format: 48-bit Ethernet MAC address.
1615 *
1616 * Masking: Not maskable. */
1617#define NXM_NX_ND_SLL NXM_HEADER (0x0001, 24, 6)
1618
1619/* The target link-layer address option in an IPv6 Neighbor Discovery
1620 * message.
1621 *
1622 * Prereqs:
1623 * NXM_OF_ETH_TYPE must match 0x86dd exactly.
1624 * NXM_OF_IP_PROTO must match 58 exactly.
1625 * NXM_OF_ICMPV6_TYPE must be exactly 136.
1626 *
1627 * Format: 48-bit Ethernet MAC address.
1628 *
1629 * Masking: Not maskable. */
1630#define NXM_NX_ND_TLL NXM_HEADER (0x0001, 25, 6)
1631
7257b535
BP
1632/* IP fragment information.
1633 *
1634 * Prereqs:
1635 * NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
1636 *
1637 * Format: 8-bit value with one of the values 0, 1, or 3, as described below.
1638 *
1639 * Masking: Fully maskable.
1640 *
1641 * This field has three possible values:
1642 *
1643 * - A packet that is not an IP fragment has value 0.
1644 *
1645 * - A packet that is an IP fragment with offset 0 (the first fragment) has
1646 * bit 0 set and thus value 1.
1647 *
1648 * - A packet that is an IP fragment with nonzero offset has bits 0 and 1 set
1649 * and thus value 3.
1650 *
1651 * NX_IP_FRAG_ANY and NX_IP_FRAG_LATER are declared to symbolically represent
1652 * the meanings of bits 0 and 1.
1653 *
1654 * The switch may reject matches against values that can never appear.
1655 *
1656 * It is important to understand how this field interacts with the OpenFlow IP
1657 * fragment handling mode:
1658 *
1659 * - In OFPC_FRAG_DROP mode, the OpenFlow switch drops all IP fragments
1660 * before they reach the flow table, so every packet that is available for
1661 * matching will have value 0 in this field.
1662 *
1663 * - Open vSwitch does not implement OFPC_FRAG_REASM mode, but if it did then
1664 * IP fragments would be reassembled before they reached the flow table and
1665 * again every packet available for matching would always have value 0.
1666 *
1667 * - In OFPC_FRAG_NORMAL mode, all three values are possible, but OpenFlow
1668 * 1.0 says that fragments' transport ports are always 0, even for the
1669 * first fragment, so this does not provide much extra information.
1670 *
1671 * - In OFPC_FRAG_NX_MATCH mode, all three values are possible. For
1672 * fragments with offset 0, Open vSwitch makes L4 header information
1673 * available.
1674 */
1675#define NXM_NX_IP_FRAG NXM_HEADER (0x0001, 26, 1)
1676#define NXM_NX_IP_FRAG_W NXM_HEADER_W(0x0001, 26, 1)
1677
1678/* Bits in the value of NXM_NX_IP_FRAG. */
1679#define NX_IP_FRAG_ANY (1 << 0) /* Is this a fragment? */
1680#define NX_IP_FRAG_LATER (1 << 1) /* Is this a fragment with nonzero offset? */
d31f1109 1681
fa8223b7
JP
1682/* The flow label in the IPv6 header.
1683 *
1684 * Prereqs: NXM_OF_ETH_TYPE must match 0x86dd exactly.
1685 *
1686 * Format: 20-bit IPv6 flow label in least-significant bits.
1687 *
1688 * Masking: Not maskable. */
1689#define NXM_NX_IPV6_LABEL NXM_HEADER (0x0001, 27, 4)
1690
530180fd
JP
1691/* The ECN of the IP header.
1692 *
1693 * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
1694 *
1695 * Format: ECN in the low-order 2 bits.
1696 *
1697 * Masking: Not maskable. */
1698#define NXM_NX_IP_ECN NXM_HEADER (0x0001, 28, 1)
1699
a61680c6
JP
1700/* The time-to-live/hop limit of the IP header.
1701 *
1702 * Prereqs: NXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
1703 *
1704 * Format: 8-bit integer.
1705 *
1706 * Masking: Not maskable. */
1707#define NXM_NX_IP_TTL NXM_HEADER (0x0001, 29, 1)
1708
e729e793
JP
1709/* Flow cookie.
1710 *
1711 * This may be used to gain the OpenFlow 1.1-like ability to restrict
1712 * certain NXM-based Flow Mod and Flow Stats Request messages to flows
1713 * with specific cookies. See the "nx_flow_mod" and "nx_flow_stats_request"
1714 * structure definitions for more details. This match is otherwise not
1715 * allowed.
1716 *
1717 * Prereqs: None.
1718 *
1719 * Format: 64-bit integer in network byte order.
1720 *
1721 * Masking: Arbitrary masks. */
1722#define NXM_NX_COOKIE NXM_HEADER (0x0001, 30, 8)
1723#define NXM_NX_COOKIE_W NXM_HEADER_W(0x0001, 30, 8)
1724
09246b99
BP
1725/* ## --------------------- ## */
1726/* ## Requests and replies. ## */
1727/* ## --------------------- ## */
1728
492f7572 1729enum nx_flow_format {
09246b99 1730 NXFF_OPENFLOW10 = 0, /* Standard OpenFlow 1.0 compatible. */
09246b99
BP
1731 NXFF_NXM = 2 /* Nicira extended match. */
1732};
1733
1734/* NXT_SET_FLOW_FORMAT request. */
1735struct nxt_set_flow_format {
1736 struct ofp_header header;
1737 ovs_be32 vendor; /* NX_VENDOR_ID. */
1738 ovs_be32 subtype; /* NXT_SET_FLOW_FORMAT. */
1739 ovs_be32 format; /* One of NXFF_*. */
1740};
1741OFP_ASSERT(sizeof(struct nxt_set_flow_format) == 20);
1742
e729e793
JP
1743/* NXT_FLOW_MOD (analogous to OFPT_FLOW_MOD).
1744 *
1745 * It is possible to limit flow deletions and modifications to certain
1746 * cookies by using the NXM_NX_COOKIE and NXM_NX_COOKIE_W matches. For
1747 * these commands, the "cookie" field is always ignored. Flow additions
1748 * make use of the "cookie" field and ignore any NXM_NX_COOKIE*
1749 * definitions.
1750 */
09246b99
BP
1751struct nx_flow_mod {
1752 struct nicira_header nxh;
1753 ovs_be64 cookie; /* Opaque controller-issued identifier. */
1754 ovs_be16 command; /* One of OFPFC_*. */
1755 ovs_be16 idle_timeout; /* Idle time before discarding (seconds). */
1756 ovs_be16 hard_timeout; /* Max time before discarding (seconds). */
1757 ovs_be16 priority; /* Priority level of flow entry. */
1758 ovs_be32 buffer_id; /* Buffered packet to apply to (or -1).
1759 Not meaningful for OFPFC_DELETE*. */
1760 ovs_be16 out_port; /* For OFPFC_DELETE* commands, require
1761 matching entries to include this as an
1762 output port. A value of OFPP_NONE
1763 indicates no restriction. */
1764 ovs_be16 flags; /* One of OFPFF_*. */
1765 ovs_be16 match_len; /* Size of nx_match. */
1766 uint8_t pad[6]; /* Align to 64-bits. */
1767 /* Followed by:
1768 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1769 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1770 * all-zero bytes, then
1771 * - Actions to fill out the remainder of the message length (always a
1772 * multiple of 8).
1773 */
1774};
1775OFP_ASSERT(sizeof(struct nx_flow_mod) == 48);
1776
1777/* NXT_FLOW_REMOVED (analogous to OFPT_FLOW_REMOVED). */
1778struct nx_flow_removed {
1779 struct nicira_header nxh;
1780 ovs_be64 cookie; /* Opaque controller-issued identifier. */
1781 ovs_be16 priority; /* Priority level of flow entry. */
1782 uint8_t reason; /* One of OFPRR_*. */
1783 uint8_t pad[1]; /* Align to 32-bits. */
1784 ovs_be32 duration_sec; /* Time flow was alive in seconds. */
1785 ovs_be32 duration_nsec; /* Time flow was alive in nanoseconds beyond
1786 duration_sec. */
1787 ovs_be16 idle_timeout; /* Idle timeout from original flow mod. */
1788 ovs_be16 match_len; /* Size of nx_match. */
1789 ovs_be64 packet_count;
1790 ovs_be64 byte_count;
1791 /* Followed by:
1792 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1793 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1794 * all-zero bytes. */
1795};
1796OFP_ASSERT(sizeof(struct nx_flow_removed) == 56);
1797
1798/* Nicira vendor stats request of type NXST_FLOW (analogous to OFPST_FLOW
e729e793
JP
1799 * request).
1800 *
1801 * It is possible to limit matches to certain cookies by using the
1802 * NXM_NX_COOKIE and NXM_NX_COOKIE_W matches.
1803 */
09246b99
BP
1804struct nx_flow_stats_request {
1805 struct nicira_stats_msg nsm;
1806 ovs_be16 out_port; /* Require matching entries to include this
1807 as an output port. A value of OFPP_NONE
1808 indicates no restriction. */
1809 ovs_be16 match_len; /* Length of nx_match. */
1810 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
1811 or 0xff for all tables. */
1812 uint8_t pad[3]; /* Align to 64 bits. */
1813 /* Followed by:
1814 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1815 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1816 * all-zero bytes, which must also exactly fill out the length of the
1817 * message.
1818 */
1819};
1820OFP_ASSERT(sizeof(struct nx_flow_stats_request) == 32);
1821
1822/* Body for Nicira vendor stats reply of type NXST_FLOW (analogous to
1823 * OFPST_FLOW reply). */
1824struct nx_flow_stats {
1825 ovs_be16 length; /* Length of this entry. */
1826 uint8_t table_id; /* ID of table flow came from. */
1827 uint8_t pad;
1828 ovs_be32 duration_sec; /* Time flow has been alive in seconds. */
1829 ovs_be32 duration_nsec; /* Time flow has been alive in nanoseconds
1830 beyond duration_sec. */
1831 ovs_be16 priority; /* Priority of the entry. Only meaningful
1832 when this is not an exact-match entry. */
1833 ovs_be16 idle_timeout; /* Number of seconds idle before expiration. */
1834 ovs_be16 hard_timeout; /* Number of seconds before expiration. */
1835 ovs_be16 match_len; /* Length of nx_match. */
1836 uint8_t pad2[4]; /* Align to 64 bits. */
1837 ovs_be64 cookie; /* Opaque controller-issued identifier. */
5e9d0469
BP
1838 ovs_be64 packet_count; /* Number of packets, UINT64_MAX if unknown. */
1839 ovs_be64 byte_count; /* Number of bytes, UINT64_MAX if unknown. */
09246b99
BP
1840 /* Followed by:
1841 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1842 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1843 * all-zero bytes, then
1844 * - Actions to fill out the remainder 'length' bytes (always a multiple
1845 * of 8).
1846 */
1847};
1848OFP_ASSERT(sizeof(struct nx_flow_stats) == 48);
1849
1850/* Nicira vendor stats request of type NXST_AGGREGATE (analogous to
1851 * OFPST_AGGREGATE request). */
1852struct nx_aggregate_stats_request {
1853 struct nicira_stats_msg nsm;
1854 ovs_be16 out_port; /* Require matching entries to include this
1855 as an output port. A value of OFPP_NONE
1856 indicates no restriction. */
1857 ovs_be16 match_len; /* Length of nx_match. */
1858 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
1859 or 0xff for all tables. */
1860 uint8_t pad[3]; /* Align to 64 bits. */
1861 /* Followed by:
1862 * - Exactly match_len (possibly 0) bytes containing the nx_match, then
1863 * - Exactly (match_len + 7)/8*8 - match_len (between 0 and 7) bytes of
1864 * all-zero bytes, which must also exactly fill out the length of the
1865 * message.
1866 */
1867};
1868OFP_ASSERT(sizeof(struct nx_aggregate_stats_request) == 32);
1869
1870/* Body for nicira_stats_msg reply of type NXST_AGGREGATE (analogous to
675baf0c 1871 * OFPST_AGGREGATE reply). */
09246b99
BP
1872struct nx_aggregate_stats_reply {
1873 struct nicira_stats_msg nsm;
5e9d0469
BP
1874 ovs_be64 packet_count; /* Number of packets, UINT64_MAX if unknown. */
1875 ovs_be64 byte_count; /* Number of bytes, UINT64_MAX if unknown. */
1876 ovs_be32 flow_count; /* Number of flows. */
1877 uint8_t pad[4]; /* Align to 64 bits. */
09246b99
BP
1878};
1879OFP_ASSERT(sizeof(struct nx_aggregate_stats_reply) == 48);
659586ef 1880
064af421 1881#endif /* openflow/nicira-ext.h */