blob: 791cedaad3629afc305091d968ab70c9dbe560fb [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2 * Junior University
3 * Copyright (c) 2011, 2012 Open Networking Foundation
4 *
5 * We are making the OpenFlow specification and associated documentation
6 * (Software) available for public use and benefit with the expectation
7 * that others will use, modify and enhance the Software and contribute
8 * those enhancements back to the community. However, since we would
9 * like to make the Software available for broadest use, with as few
10 * restrictions as possible permission is hereby granted, free of
11 * charge, to any person obtaining a copy of this Software to deal in
12 * the Software under the copyrights without restriction, including
13 * without limitation the rights to use, copy, modify, merge, publish,
14 * distribute, sublicense, and/or sell copies of the Software, and to
15 * permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be
19 * included in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
29 *
30 * The name and trademarks of copyright holder(s) may NOT be used in
31 * advertising or publicity pertaining to the Software or any
32 * derivatives without specific, written prior permission.
33 */
34
35/* OpenFlow: protocol between controller and datapath. */
36
37#ifndef OPENFLOW_OPENFLOW_H
38#define OPENFLOW_OPENFLOW_H 1
39
40#ifdef __KERNEL__
41#include <linux/types.h>
42#else
43#include <stdint.h>
44#endif
45
46#ifdef SWIG
47#define OFP_ASSERT(EXPR) /* SWIG can't handle OFP_ASSERT. */
48#elif !defined(__cplusplus)
49/* Build-time assertion for use in a declaration context. */
50#define OFP_ASSERT(EXPR) \
51 extern int (*build_assert(void))[ sizeof(struct { \
52 unsigned int build_assert_failed : (EXPR) ? 1 : -1; })]
53#else /* __cplusplus */
54#define OFP_ASSERT(_EXPR) typedef int build_assert_failed[(_EXPR) ? 1 : -1]
55#endif /* __cplusplus */
56
57#ifndef SWIG
58#define OFP_PACKED __attribute__((packed))
59#else
60#define OFP_PACKED /* SWIG doesn't understand __attribute. */
61#endif
62
63/* Version number:
64 * Non-experimental versions released: 0x01 = 1.0 ; 0x02 = 1.1 ; 0x03 = 1.2
65 * 0x04 = 1.3
66 * Experimental versions released: 0x81 -- 0x99
67 */
68/* The most significant bit being set in the version field indicates an
69 * experimental OpenFlow version.
70 */
71#define OFP_VERSION 0x04
72
73#define OFP_MAX_TABLE_NAME_LEN 32
74#define OFP_MAX_PORT_NAME_LEN 16
75
76#define OFP_TCP_PORT 6633
77#define OFP_SSL_PORT 6633
78
79#define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
80
81/* Port numbering. Ports are numbered starting from 1. */
82enum ofp_port_no {
83 /* Maximum number of physical and logical switch ports. */
84 OFPP_MAX = 0xffffff00,
85
86 /* Reserved OpenFlow Port (fake output "ports"). */
87 OFPP_IN_PORT = 0xfffffff8, /* Send the packet out the input port. This
88 reserved port must be explicitly used
89 in order to send back out of the input
90 port. */
91 OFPP_TABLE = 0xfffffff9, /* Submit the packet to the first flow table
92 NB: This destination port can only be
93 used in packet-out messages. */
94 OFPP_NORMAL = 0xfffffffa, /* Process with normal L2/L3 switching. */
95 OFPP_FLOOD = 0xfffffffb, /* All physical ports in VLAN, except input
96 port and those blocked or link down. */
97 OFPP_ALL = 0xfffffffc, /* All physical ports except input port. */
98 OFPP_CONTROLLER = 0xfffffffd, /* Send to controller. */
99 OFPP_LOCAL = 0xfffffffe, /* Local openflow "port". */
100 OFPP_ANY = 0xffffffff /* Wildcard port used only for flow mod
101 (delete) and flow stats requests. Selects
102 all flows regardless of output port
103 (including flows with no output port). */
104};
105
106enum ofp_type {
107 /* Immutable messages. */
108 OFPT_HELLO = 0, /* Symmetric message */
109 OFPT_ERROR = 1, /* Symmetric message */
110 OFPT_ECHO_REQUEST = 2, /* Symmetric message */
111 OFPT_ECHO_REPLY = 3, /* Symmetric message */
112 OFPT_EXPERIMENTER = 4, /* Symmetric message */
113
114 /* Switch configuration messages. */
115 OFPT_FEATURES_REQUEST = 5, /* Controller/switch message */
116 OFPT_FEATURES_REPLY = 6, /* Controller/switch message */
117 OFPT_GET_CONFIG_REQUEST = 7, /* Controller/switch message */
118 OFPT_GET_CONFIG_REPLY = 8, /* Controller/switch message */
119 OFPT_SET_CONFIG = 9, /* Controller/switch message */
120
121 /* Asynchronous messages. */
122 OFPT_PACKET_IN = 10, /* Async message */
123 OFPT_FLOW_REMOVED = 11, /* Async message */
124 OFPT_PORT_STATUS = 12, /* Async message */
125
126 /* Controller command messages. */
127 OFPT_PACKET_OUT = 13, /* Controller/switch message */
128 OFPT_FLOW_MOD = 14, /* Controller/switch message */
129 OFPT_GROUP_MOD = 15, /* Controller/switch message */
130 OFPT_PORT_MOD = 16, /* Controller/switch message */
131 OFPT_TABLE_MOD = 17, /* Controller/switch message */
132
133 /* Multipart messages. */
134 OFPT_MULTIPART_REQUEST = 18, /* Controller/switch message */
135 OFPT_MULTIPART_REPLY = 19, /* Controller/switch message */
136
137 /* Barrier messages. */
138 OFPT_BARRIER_REQUEST = 20, /* Controller/switch message */
139 OFPT_BARRIER_REPLY = 21, /* Controller/switch message */
140
141 /* Queue Configuration messages. */
142 OFPT_QUEUE_GET_CONFIG_REQUEST = 22, /* Controller/switch message */
143 OFPT_QUEUE_GET_CONFIG_REPLY = 23, /* Controller/switch message */
144
145 /* Controller role change request messages. */
146 OFPT_ROLE_REQUEST = 24, /* Controller/switch message */
147 OFPT_ROLE_REPLY = 25, /* Controller/switch message */
148
149 /* Asynchronous message configuration. */
150 OFPT_GET_ASYNC_REQUEST = 26, /* Controller/switch message */
151 OFPT_GET_ASYNC_REPLY = 27, /* Controller/switch message */
152 OFPT_SET_ASYNC = 28, /* Controller/switch message */
153
154 /* Meters and rate limiters configuration messages. */
155 OFPT_METER_MOD = 29, /* Controller/switch message */
156};
157
158/* Header on all OpenFlow packets. */
159struct ofp_header {
160 uint8_t version; /* OFP_VERSION. */
161 uint8_t type; /* One of the OFPT_ constants. */
162 uint16_t length; /* Length including this ofp_header. */
163 uint32_t xid; /* Transaction id associated with this packet.
164 Replies use the same id as was in the request
165 to facilitate pairing. */
166};
167OFP_ASSERT(sizeof(struct ofp_header) == 8);
168
169/* Hello elements types.
170 */
171enum ofp_hello_elem_type {
172 OFPHET_VERSIONBITMAP = 1, /* Bitmap of version supported. */
173};
174
175/* Common header for all Hello Elements */
176struct ofp_hello_elem_header {
177 uint16_t type; /* One of OFPHET_*. */
178 uint16_t length; /* Length in bytes of this element. */
179};
180OFP_ASSERT(sizeof(struct ofp_hello_elem_header) == 4);
181
182/* Version bitmap Hello Element */
183struct ofp_hello_elem_versionbitmap {
184 uint16_t type; /* OFPHET_VERSIONBITMAP. */
185 uint16_t length; /* Length in bytes of this element. */
186 /* Followed by:
187 * - Exactly (length - 4) bytes containing the bitmaps, then
188 * - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
189 * bytes of all-zero bytes */
190 uint32_t bitmaps[0]; /* List of bitmaps - supported versions */
191};
192OFP_ASSERT(sizeof(struct ofp_hello_elem_versionbitmap) == 4);
193
194/* OFPT_HELLO. This message includes zero or more hello elements having
195 * variable size. Unknown elements types must be ignored/skipped, to allow
196 * for future extensions. */
197struct ofp_hello {
198 struct ofp_header header;
199
200 /* Hello element list */
201 struct ofp_hello_elem_header elements[0];
202};
203OFP_ASSERT(sizeof(struct ofp_hello) == 8);
204
205#define OFP_DEFAULT_MISS_SEND_LEN 128
206
207enum ofp_config_flags {
208 /* Handling of IP fragments. */
209 OFPC_FRAG_NORMAL = 0, /* No special handling for fragments. */
210 OFPC_FRAG_DROP = 1 << 0, /* Drop fragments. */
211 OFPC_FRAG_REASM = 1 << 1, /* Reassemble (only if OFPC_IP_REASM set). */
212 OFPC_FRAG_MASK = 3,
213};
214
215/* Switch configuration. */
216struct ofp_switch_config {
217 struct ofp_header header;
218 uint16_t flags; /* OFPC_* flags. */
219 uint16_t miss_send_len; /* Max bytes of packet that datapath
220 should send to the controller. See
221 ofp_controller_max_len for valid values.
222 */
223};
224OFP_ASSERT(sizeof(struct ofp_switch_config) == 12);
225
226/* Flags to configure the table. Reserved for future use. */
227enum ofp_table_config {
228 OFPTC_DEPRECATED_MASK = 3, /* Deprecated bits */
229};
230
231/* Table numbering. Tables can use any number up to OFPT_MAX. */
232enum ofp_table {
233 /* Last usable table number. */
234 OFPTT_MAX = 0xfe,
235
236 /* Fake tables. */
237 OFPTT_ALL = 0xff /* Wildcard table used for table config,
238 flow stats and flow deletes. */
239};
240
241
242/* Configure/Modify behavior of a flow table */
243struct ofp_table_mod {
244 struct ofp_header header;
245 uint8_t table_id; /* ID of the table, OFPTT_ALL indicates all tables */
246 uint8_t pad[3]; /* Pad to 32 bits */
247 uint32_t config; /* Bitmap of OFPTC_* flags */
248};
249OFP_ASSERT(sizeof(struct ofp_table_mod) == 16);
250
251/* Capabilities supported by the datapath. */
252enum ofp_capabilities {
253 OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
254 OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
255 OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
256 OFPC_GROUP_STATS = 1 << 3, /* Group statistics. */
257 OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
258 OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */
259 OFPC_PORT_BLOCKED = 1 << 8 /* Switch will block looping ports. */
260};
261
262/* Flags to indicate behavior of the physical port. These flags are
263 * used in ofp_port to describe the current configuration. They are
264 * used in the ofp_port_mod message to configure the port's behavior.
265 */
266enum ofp_port_config {
267 OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
268
269 OFPPC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
270 OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
271 OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
272};
273
274/* Current state of the physical port. These are not configurable from
275 * the controller.
276 */
277enum ofp_port_state {
278 OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
279 OFPPS_BLOCKED = 1 << 1, /* Port is blocked */
280 OFPPS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
281};
282
283/* Features of ports available in a datapath. */
284enum ofp_port_features {
285 OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
286 OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
287 OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
288 OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
289 OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
290 OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
291 OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
292 OFPPF_40GB_FD = 1 << 7, /* 40 Gb full-duplex rate support. */
293 OFPPF_100GB_FD = 1 << 8, /* 100 Gb full-duplex rate support. */
294 OFPPF_1TB_FD = 1 << 9, /* 1 Tb full-duplex rate support. */
295 OFPPF_OTHER = 1 << 10, /* Other rate, not in the list. */
296
297 OFPPF_COPPER = 1 << 11, /* Copper medium. */
298 OFPPF_FIBER = 1 << 12, /* Fiber medium. */
299 OFPPF_AUTONEG = 1 << 13, /* Auto-negotiation. */
300 OFPPF_PAUSE = 1 << 14, /* Pause. */
301 OFPPF_PAUSE_ASYM = 1 << 15 /* Asymmetric pause. */
302};
303
304/* Description of a port */
305struct ofp_port {
306 uint32_t port_no;
307 uint8_t pad[4];
308 uint8_t hw_addr[OFP_ETH_ALEN];
309 uint8_t pad2[2]; /* Align to 64 bits. */
310 char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
311
312 uint32_t config; /* Bitmap of OFPPC_* flags. */
313 uint32_t state; /* Bitmap of OFPPS_* flags. */
314
315 /* Bitmaps of OFPPF_* that describe features. All bits zeroed if
316 * unsupported or unavailable. */
317 uint32_t curr; /* Current features. */
318 uint32_t advertised; /* Features being advertised by the port. */
319 uint32_t supported; /* Features supported by the port. */
320 uint32_t peer; /* Features advertised by peer. */
321
322 uint32_t curr_speed; /* Current port bitrate in kbps. */
323 uint32_t max_speed; /* Max port bitrate in kbps */
324};
325OFP_ASSERT(sizeof(struct ofp_port) == 64);
326
327/* Switch features. */
328struct ofp_switch_features {
329 struct ofp_header header;
330 uint64_t datapath_id; /* Datapath unique ID. The lower 48-bits are for
331 a MAC address, while the upper 16-bits are
332 implementer-defined. */
333
334 uint32_t n_buffers; /* Max packets buffered at once. */
335
336 uint8_t n_tables; /* Number of tables supported by datapath. */
337 uint8_t auxiliary_id; /* Identify auxiliary connections */
338 uint8_t pad[2]; /* Align to 64-bits. */
339
340 /* Features. */
341 uint32_t capabilities; /* Bitmap of support "ofp_capabilities". */
342 uint32_t reserved;
343};
344OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
345
346/* What changed about the physical port */
347enum ofp_port_reason {
348 OFPPR_ADD = 0, /* The port was added. */
349 OFPPR_DELETE = 1, /* The port was removed. */
350 OFPPR_MODIFY = 2, /* Some attribute of the port has changed. */
351};
352
353/* A physical port has changed in the datapath */
354struct ofp_port_status {
355 struct ofp_header header;
356 uint8_t reason; /* One of OFPPR_*. */
357 uint8_t pad[7]; /* Align to 64-bits. */
358 struct ofp_port desc;
359};
360OFP_ASSERT(sizeof(struct ofp_port_status) == 80);
361
362/* Modify behavior of the physical port */
363struct ofp_port_mod {
364 struct ofp_header header;
365 uint32_t port_no;
366 uint8_t pad[4];
367 uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
368 configurable. This is used to
369 sanity-check the request, so it must
370 be the same as returned in an
371 ofp_port struct. */
372 uint8_t pad2[2]; /* Pad to 64 bits. */
373 uint32_t config; /* Bitmap of OFPPC_* flags. */
374 uint32_t mask; /* Bitmap of OFPPC_* flags to be changed. */
375
376 uint32_t advertise; /* Bitmap of OFPPF_*. Zero all bits to prevent
377 any action taking place. */
378 uint8_t pad3[4]; /* Pad to 64 bits. */
379};
380OFP_ASSERT(sizeof(struct ofp_port_mod) == 40);
381
382/* ## -------------------------- ## */
383/* ## OpenFlow Extensible Match. ## */
384/* ## -------------------------- ## */
385
386/* The match type indicates the match structure (set of fields that compose the
387 * match) in use. The match type is placed in the type field at the beginning
388 * of all match structures. The "OpenFlow Extensible Match" type corresponds
389 * to OXM TLV format described below and must be supported by all OpenFlow
390 * switches. Extensions that define other match types may be published on the
391 * ONF wiki. Support for extensions is optional.
392 */
393enum ofp_match_type {
394 OFPMT_STANDARD = 0, /* Deprecated. */
395 OFPMT_OXM = 1, /* OpenFlow Extensible Match */
396};
397
398/* Fields to match against flows */
399struct ofp_match {
400 uint16_t type; /* One of OFPMT_* */
401 uint16_t length; /* Length of ofp_match (excluding padding) */
402 /* Followed by:
403 * - Exactly (length - 4) (possibly 0) bytes containing OXM TLVs, then
404 * - Exactly ((length + 7)/8*8 - length) (between 0 and 7) bytes of
405 * all-zero bytes
406 * In summary, ofp_match is padded as needed, to make its overall size
407 * a multiple of 8, to preserve alignement in structures using it.
408 */
409 uint8_t oxm_fields[4]; /* OXMs start here - Make compiler happy */
410};
411OFP_ASSERT(sizeof(struct ofp_match) == 8);
412
413/* Components of a OXM TLV header. */
414#define OXM_HEADER__(CLASS, FIELD, HASMASK, LENGTH) \
415 (((CLASS) << 16) | ((FIELD) << 9) | ((HASMASK) << 8) | (LENGTH))
416#define OXM_HEADER(CLASS, FIELD, LENGTH) \
417 OXM_HEADER__(CLASS, FIELD, 0, LENGTH)
418#define OXM_HEADER_W(CLASS, FIELD, LENGTH) \
419 OXM_HEADER__(CLASS, FIELD, 1, (LENGTH) * 2)
420#define OXM_CLASS(HEADER) ((HEADER) >> 16)
421#define OXM_FIELD(HEADER) (((HEADER) >> 9) & 0x7f)
422#define OXM_TYPE(HEADER) (((HEADER) >> 9) & 0x7fffff)
423#define OXM_HASMASK(HEADER) (((HEADER) >> 8) & 1)
424#define OXM_LENGTH(HEADER) ((HEADER) & 0xff)
425
426#define OXM_MAKE_WILD_HEADER(HEADER) \
427 OXM_HEADER_W(OXM_CLASS(HEADER), OXM_FIELD(HEADER), OXM_LENGTH(HEADER))
428
429/* OXM Class IDs.
430 * The high order bit differentiate reserved classes from member classes.
431 * Classes 0x0000 to 0x7FFF are member classes, allocated by ONF.
432 * Classes 0x8000 to 0xFFFE are reserved classes, reserved for standardisation.
433 */
434enum ofp_oxm_class {
435 OFPXMC_NXM_0 = 0x0000, /* Backward compatibility with NXM */
436 OFPXMC_NXM_1 = 0x0001, /* Backward compatibility with NXM */
437 OFPXMC_OPENFLOW_BASIC = 0x8000, /* Basic class for OpenFlow */
438 OFPXMC_EXPERIMENTER = 0xFFFF, /* Experimenter class */
439};
440
441/* OXM Flow match field types for OpenFlow basic class. */
442enum oxm_ofb_match_fields {
443 OFPXMT_OFB_IN_PORT = 0, /* Switch input port. */
444 OFPXMT_OFB_IN_PHY_PORT = 1, /* Switch physical input port. */
445 OFPXMT_OFB_METADATA = 2, /* Metadata passed between tables. */
446 OFPXMT_OFB_ETH_DST = 3, /* Ethernet destination address. */
447 OFPXMT_OFB_ETH_SRC = 4, /* Ethernet source address. */
448 OFPXMT_OFB_ETH_TYPE = 5, /* Ethernet frame type. */
449 OFPXMT_OFB_VLAN_VID = 6, /* VLAN id. */
450 OFPXMT_OFB_VLAN_PCP = 7, /* VLAN priority. */
451 OFPXMT_OFB_IP_DSCP = 8, /* IP DSCP (6 bits in ToS field). */
452 OFPXMT_OFB_IP_ECN = 9, /* IP ECN (2 bits in ToS field). */
453 OFPXMT_OFB_IP_PROTO = 10, /* IP protocol. */
454 OFPXMT_OFB_IPV4_SRC = 11, /* IPv4 source address. */
455 OFPXMT_OFB_IPV4_DST = 12, /* IPv4 destination address. */
456 OFPXMT_OFB_TCP_SRC = 13, /* TCP source port. */
457 OFPXMT_OFB_TCP_DST = 14, /* TCP destination port. */
458 OFPXMT_OFB_UDP_SRC = 15, /* UDP source port. */
459 OFPXMT_OFB_UDP_DST = 16, /* UDP destination port. */
460 OFPXMT_OFB_SCTP_SRC = 17, /* SCTP source port. */
461 OFPXMT_OFB_SCTP_DST = 18, /* SCTP destination port. */
462 OFPXMT_OFB_ICMPV4_TYPE = 19, /* ICMP type. */
463 OFPXMT_OFB_ICMPV4_CODE = 20, /* ICMP code. */
464 OFPXMT_OFB_ARP_OP = 21, /* ARP opcode. */
465 OFPXMT_OFB_ARP_SPA = 22, /* ARP source IPv4 address. */
466 OFPXMT_OFB_ARP_TPA = 23, /* ARP target IPv4 address. */
467 OFPXMT_OFB_ARP_SHA = 24, /* ARP source hardware address. */
468 OFPXMT_OFB_ARP_THA = 25, /* ARP target hardware address. */
469 OFPXMT_OFB_IPV6_SRC = 26, /* IPv6 source address. */
470 OFPXMT_OFB_IPV6_DST = 27, /* IPv6 destination address. */
471 OFPXMT_OFB_IPV6_FLABEL = 28, /* IPv6 Flow Label */
472 OFPXMT_OFB_ICMPV6_TYPE = 29, /* ICMPv6 type. */
473 OFPXMT_OFB_ICMPV6_CODE = 30, /* ICMPv6 code. */
474 OFPXMT_OFB_IPV6_ND_TARGET = 31, /* Target address for ND. */
475 OFPXMT_OFB_IPV6_ND_SLL = 32, /* Source link-layer for ND. */
476 OFPXMT_OFB_IPV6_ND_TLL = 33, /* Target link-layer for ND. */
477 OFPXMT_OFB_MPLS_LABEL = 34, /* MPLS label. */
478 OFPXMT_OFB_MPLS_TC = 35, /* MPLS TC. */
479 OFPXMT_OFP_MPLS_BOS = 36, /* MPLS BoS bit. */
480 OFPXMT_OFB_PBB_ISID = 37, /* PBB I-SID. */
481 OFPXMT_OFB_TUNNEL_ID = 38, /* Logical Port Metadata. */
482 OFPXMT_OFB_IPV6_EXTHDR = 39, /* IPv6 Extension Header pseudo-field */
483};
484
485#define OFPXMT_OFB_ALL ((UINT64_C(1) << 40) - 1)
486
487/* OpenFlow port on which the packet was received.
488 * May be a physical port, a logical port, or the reserved port OFPP_LOCAL
489 *
490 * Prereqs: None.
491 *
492 * Format: 32-bit integer in network byte order.
493 *
494 * Masking: Not maskable. */
495#define OXM_OF_IN_PORT OXM_HEADER (0x8000, OFPXMT_OFB_IN_PORT, 4)
496
497/* Physical port on which the packet was received.
498 *
499 * Consider a packet received on a tunnel interface defined over a link
500 * aggregation group (LAG) with two physical port members. If the tunnel
501 * interface is the logical port bound to OpenFlow. In this case,
502 * OFPXMT_OF_IN_PORT is the tunnel's port number and OFPXMT_OF_IN_PHY_PORT is
503 * the physical port number of the LAG on which the tunnel is configured.
504 *
505 * When a packet is received directly on a physical port and not processed by a
506 * logical port, OFPXMT_OF_IN_PORT and OFPXMT_OF_IN_PHY_PORT have the same
507 * value.
508 *
509 * This field is usually not available in a regular match and only available
510 * in ofp_packet_in messages when it's different from OXM_OF_IN_PORT.
511 *
512 * Prereqs: OXM_OF_IN_PORT must be present.
513 *
514 * Format: 32-bit integer in network byte order.
515 *
516 * Masking: Not maskable. */
517#define OXM_OF_IN_PHY_PORT OXM_HEADER (0x8000, OFPXMT_OFB_IN_PHY_PORT, 4)
518
519/* Table metadata.
520 *
521 * Prereqs: None.
522 *
523 * Format: 64-bit integer in network byte order.
524 *
525 * Masking: Arbitrary masks.
526 */
527#define OXM_OF_METADATA OXM_HEADER (0x8000, OFPXMT_OFB_METADATA, 8)
528#define OXM_OF_METADATA_W OXM_HEADER_W(0x8000, OFPXMT_OFB_METADATA, 8)
529
530/* Source or destination address in Ethernet header.
531 *
532 * Prereqs: None.
533 *
534 * Format: 48-bit Ethernet MAC address.
535 *
536 * Masking: Arbitrary masks. */
537#define OXM_OF_ETH_DST OXM_HEADER (0x8000, OFPXMT_OFB_ETH_DST, 6)
538#define OXM_OF_ETH_DST_W OXM_HEADER_W(0x8000, OFPXMT_OFB_ETH_DST, 6)
539#define OXM_OF_ETH_SRC OXM_HEADER (0x8000, OFPXMT_OFB_ETH_SRC, 6)
540#define OXM_OF_ETH_SRC_W OXM_HEADER_W(0x8000, OFPXMT_OFB_ETH_SRC, 6)
541
542/* Packet's Ethernet type.
543 *
544 * Prereqs: None.
545 *
546 * Format: 16-bit integer in network byte order.
547 *
548 * Masking: Not maskable. */
549#define OXM_OF_ETH_TYPE OXM_HEADER (0x8000, OFPXMT_OFB_ETH_TYPE, 2)
550
551/* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
552 * special conditions.
553 */
554enum ofp_vlan_id {
555 OFPVID_PRESENT = 0x1000, /* Bit that indicate that a VLAN id is set */
556 OFPVID_NONE = 0x0000, /* No VLAN id was set. */
557};
558/* Define for compatibility */
559#define OFP_VLAN_NONE OFPVID_NONE
560
561/* 802.1Q VID.
562 *
563 * For a packet with an 802.1Q header, this is the VLAN-ID (VID) from the
564 * outermost tag, with the CFI bit forced to 1. For a packet with no 802.1Q
565 * header, this has value OFPVID_NONE.
566 *
567 * Prereqs: None.
568 *
569 * Format: 16-bit integer in network byte order with bit 13 indicating
570 * presence of VLAN header and 3 most-significant bits forced to 0.
571 * Only the lower 13 bits have meaning.
572 *
573 * Masking: Arbitrary masks.
574 *
575 * This field can be used in various ways:
576 *
577 * - If it is not constrained at all, the nx_match matches packets without
578 * an 802.1Q header or with an 802.1Q header that has any VID value.
579 *
580 * - Testing for an exact match with 0x0 matches only packets without
581 * an 802.1Q header.
582 *
583 * - Testing for an exact match with a VID value with CFI=1 matches packets
584 * that have an 802.1Q header with a specified VID.
585 *
586 * - Testing for an exact match with a nonzero VID value with CFI=0 does
587 * not make sense. The switch may reject this combination.
588 *
589 * - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no 802.1Q
590 * header or with an 802.1Q header with a VID of 0.
591 *
592 * - Testing with nxm_value=0x1000, nxm_mask=0x1000 matches packets with
593 * an 802.1Q header that has any VID value.
594 */
595#define OXM_OF_VLAN_VID OXM_HEADER (0x8000, OFPXMT_OFB_VLAN_VID, 2)
596#define OXM_OF_VLAN_VID_W OXM_HEADER_W(0x8000, OFPXMT_OFB_VLAN_VID, 2)
597
598/* 802.1Q PCP.
599 *
600 * For a packet with an 802.1Q header, this is the VLAN-PCP from the
601 * outermost tag. For a packet with no 802.1Q header, this has value
602 * 0.
603 *
604 * Prereqs: OXM_OF_VLAN_VID must be different from OFPVID_NONE.
605 *
606 * Format: 8-bit integer with 5 most-significant bits forced to 0.
607 * Only the lower 3 bits have meaning.
608 *
609 * Masking: Not maskable.
610 */
611#define OXM_OF_VLAN_PCP OXM_HEADER (0x8000, OFPXMT_OFB_VLAN_PCP, 1)
612
613/* The Diff Serv Code Point (DSCP) bits of the IP header.
614 * Part of the IPv4 ToS field or the IPv6 Traffic Class field.
615 *
616 * Prereqs: OXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
617 *
618 * Format: 8-bit integer with 2 most-significant bits forced to 0.
619 * Only the lower 6 bits have meaning.
620 *
621 * Masking: Not maskable. */
622#define OXM_OF_IP_DSCP OXM_HEADER (0x8000, OFPXMT_OFB_IP_DSCP, 1)
623
624/* The ECN bits of the IP header.
625 * Part of the IPv4 ToS field or the IPv6 Traffic Class field.
626 *
627 * Prereqs: OXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
628 *
629 * Format: 8-bit integer with 6 most-significant bits forced to 0.
630 * Only the lower 2 bits have meaning.
631 *
632 * Masking: Not maskable. */
633#define OXM_OF_IP_ECN OXM_HEADER (0x8000, OFPXMT_OFB_IP_ECN, 1)
634
635/* The "protocol" byte in the IP header.
636 *
637 * Prereqs: OXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
638 *
639 * Format: 8-bit integer.
640 *
641 * Masking: Not maskable. */
642#define OXM_OF_IP_PROTO OXM_HEADER (0x8000, OFPXMT_OFB_IP_PROTO, 1)
643
644/* The source or destination address in the IP header.
645 *
646 * Prereqs: OXM_OF_ETH_TYPE must match 0x0800 exactly.
647 *
648 * Format: 32-bit integer in network byte order.
649 *
650 * Masking: Arbitrary masks.
651 */
652#define OXM_OF_IPV4_SRC OXM_HEADER (0x8000, OFPXMT_OFB_IPV4_SRC, 4)
653#define OXM_OF_IPV4_SRC_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV4_SRC, 4)
654#define OXM_OF_IPV4_DST OXM_HEADER (0x8000, OFPXMT_OFB_IPV4_DST, 4)
655#define OXM_OF_IPV4_DST_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV4_DST, 4)
656
657/* The source or destination port in the TCP header.
658 *
659 * Prereqs:
660 * OXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
661 * OXM_OF_IP_PROTO must match 6 exactly.
662 *
663 * Format: 16-bit integer in network byte order.
664 *
665 * Masking: Not maskable. */
666#define OXM_OF_TCP_SRC OXM_HEADER (0x8000, OFPXMT_OFB_TCP_SRC, 2)
667#define OXM_OF_TCP_DST OXM_HEADER (0x8000, OFPXMT_OFB_TCP_DST, 2)
668
669/* The source or destination port in the UDP header.
670 *
671 * Prereqs:
672 * OXM_OF_ETH_TYPE must match either 0x0800 or 0x86dd.
673 * OXM_OF_IP_PROTO must match 17 exactly.
674 *
675 * Format: 16-bit integer in network byte order.
676 *
677 * Masking: Not maskable. */
678#define OXM_OF_UDP_SRC OXM_HEADER (0x8000, OFPXMT_OFB_UDP_SRC, 2)
679#define OXM_OF_UDP_DST OXM_HEADER (0x8000, OFPXMT_OFB_UDP_DST, 2)
680
681/* The source or destination port in the SCTP header.
682 *
683 * Prereqs:
684 * OXM_OF_ETH_TYPE must match either 0x0800 or 0x86dd.
685 * OXM_OF_IP_PROTO must match 132 exactly.
686 *
687 * Format: 16-bit integer in network byte order.
688 *
689 * Masking: Not maskable. */
690#define OXM_OF_SCTP_SRC OXM_HEADER (0x8000, OFPXMT_OFB_SCTP_SRC, 2)
691#define OXM_OF_SCTP_DST OXM_HEADER (0x8000, OFPXMT_OFB_SCTP_DST, 2)
692
693/* The type or code in the ICMP header.
694 *
695 * Prereqs:
696 * OXM_OF_ETH_TYPE must match 0x0800 exactly.
697 * OXM_OF_IP_PROTO must match 1 exactly.
698 *
699 * Format: 8-bit integer.
700 *
701 * Masking: Not maskable. */
702#define OXM_OF_ICMPV4_TYPE OXM_HEADER (0x8000, OFPXMT_OFB_ICMPV4_TYPE, 1)
703#define OXM_OF_ICMPV4_CODE OXM_HEADER (0x8000, OFPXMT_OFB_ICMPV4_CODE, 1)
704
705/* ARP opcode.
706 *
707 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
708 * otherwise.
709 *
710 * Prereqs: OXM_OF_ETH_TYPE must match 0x0806 exactly.
711 *
712 * Format: 16-bit integer in network byte order.
713 *
714 * Masking: Not maskable. */
715#define OXM_OF_ARP_OP OXM_HEADER (0x8000, OFPXMT_OFB_ARP_OP, 2)
716
717/* For an Ethernet+IP ARP packet, the source or target protocol address
718 * in the ARP header. Always 0 otherwise.
719 *
720 * Prereqs: OXM_OF_ETH_TYPE must match 0x0806 exactly.
721 *
722 * Format: 32-bit integer in network byte order.
723 *
724 * Masking: Arbitrary masks.
725 */
726#define OXM_OF_ARP_SPA OXM_HEADER (0x8000, OFPXMT_OFB_ARP_SPA, 4)
727#define OXM_OF_ARP_SPA_W OXM_HEADER_W(0x8000, OFPXMT_OFB_ARP_SPA, 4)
728#define OXM_OF_ARP_TPA OXM_HEADER (0x8000, OFPXMT_OFB_ARP_TPA, 4)
729#define OXM_OF_ARP_TPA_W OXM_HEADER_W(0x8000, OFPXMT_OFB_ARP_TPA, 4)
730
731/* For an Ethernet+IP ARP packet, the source or target hardware address
732 * in the ARP header. Always 0 otherwise.
733 *
734 * Prereqs: OXM_OF_ETH_TYPE must match 0x0806 exactly.
735 *
736 * Format: 48-bit Ethernet MAC address.
737 *
738 * Masking: Not maskable. */
739#define OXM_OF_ARP_SHA OXM_HEADER (0x8000, OFPXMT_OFB_ARP_SHA, 6)
740#define OXM_OF_ARP_THA OXM_HEADER (0x8000, OFPXMT_OFB_ARP_THA, 6)
741
742/* The source or destination address in the IPv6 header.
743 *
744 * Prereqs: OXM_OF_ETH_TYPE must match 0x86dd exactly.
745 *
746 * Format: 128-bit IPv6 address.
747 *
748 * Masking: Arbitrary masks.
749 */
750#define OXM_OF_IPV6_SRC OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_SRC, 16)
751#define OXM_OF_IPV6_SRC_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV6_SRC, 16)
752#define OXM_OF_IPV6_DST OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_DST, 16)
753#define OXM_OF_IPV6_DST_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV6_DST, 16)
754
755/* The IPv6 Flow Label
756 *
757 * Prereqs:
758 * OXM_OF_ETH_TYPE must match 0x86dd exactly
759 *
760 * Format: 32-bit integer with 12 most-significant bits forced to 0.
761 * Only the lower 20 bits have meaning.
762 *
763 * Masking: Maskable. */
764#define OXM_OF_IPV6_FLABEL OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_FLABEL, 4)
765
766/* The type or code in the ICMPv6 header.
767 *
768 * Prereqs:
769 * OXM_OF_ETH_TYPE must match 0x86dd exactly.
770 * OXM_OF_IP_PROTO must match 58 exactly.
771 *
772 * Format: 8-bit integer.
773 *
774 * Masking: Not maskable. */
775#define OXM_OF_ICMPV6_TYPE OXM_HEADER (0x8000, OFPXMT_OFB_ICMPV6_TYPE, 1)
776#define OXM_OF_ICMPV6_CODE OXM_HEADER (0x8000, OFPXMT_OFB_ICMPV6_CODE, 1)
777
778/* The target address in an IPv6 Neighbor Discovery message.
779 *
780 * Prereqs:
781 * OXM_OF_ETH_TYPE must match 0x86dd exactly.
782 * OXM_OF_IP_PROTO must match 58 exactly.
783 * OXM_OF_ICMPV6_TYPE must be either 135 or 136.
784 *
785 * Format: 128-bit IPv6 address.
786 *
787 * Masking: Not maskable. */
788#define OXM_OF_IPV6_ND_TARGET OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_ND_TARGET, 16)
789
790/* The source link-layer address option in an IPv6 Neighbor Discovery
791 * message.
792 *
793 * Prereqs:
794 * OXM_OF_ETH_TYPE must match 0x86dd exactly.
795 * OXM_OF_IP_PROTO must match 58 exactly.
796 * OXM_OF_ICMPV6_TYPE must be exactly 135.
797 *
798 * Format: 48-bit Ethernet MAC address.
799 *
800 * Masking: Not maskable. */
801#define OXM_OF_IPV6_ND_SLL OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_ND_SLL, 6)
802
803/* The target link-layer address option in an IPv6 Neighbor Discovery
804 * message.
805 *
806 * Prereqs:
807 * OXM_OF_ETH_TYPE must match 0x86dd exactly.
808 * OXM_OF_IP_PROTO must match 58 exactly.
809 * OXM_OF_ICMPV6_TYPE must be exactly 136.
810 *
811 * Format: 48-bit Ethernet MAC address.
812 *
813 * Masking: Not maskable. */
814#define OXM_OF_IPV6_ND_TLL OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_ND_TLL, 6)
815
816/* The LABEL in the first MPLS shim header.
817 *
818 * Prereqs:
819 * OXM_OF_ETH_TYPE must match 0x8847 or 0x8848 exactly.
820 *
821 * Format: 32-bit integer in network byte order with 12 most-significant
822 * bits forced to 0. Only the lower 20 bits have meaning.
823 *
824 * Masking: Not maskable. */
825#define OXM_OF_MPLS_LABEL OXM_HEADER (0x8000, OFPXMT_OFB_MPLS_LABEL, 4)
826
827/* The TC in the first MPLS shim header.
828 *
829 * Prereqs:
830 * OXM_OF_ETH_TYPE must match 0x8847 or 0x8848 exactly.
831 *
832 * Format: 8-bit integer with 5 most-significant bits forced to 0.
833 * Only the lower 3 bits have meaning.
834 *
835 * Masking: Not maskable. */
836#define OXM_OF_MPLS_TC OXM_HEADER (0x8000, OFPXMT_OFB_MPLS_TC, 1)
837
838/* The BoS bit in the first MPLS shim header.
839 *
840 * Prereqs:
841 * OXM_OF_ETH_TYPE must match 0x8847 or 0x8848 exactly.
842 *
843 * Format: 8-bit integer with 7 most-significant bits forced to 0.
844 * Only the lowest bit have a meaning.
845 *
846 * Masking: Not maskable. */
847#define OXM_OF_MPLS_BOS OXM_HEADER (0x8000, OFPXMT_OFB_MPLS_BOS, 1)
848
849/* IEEE 802.1ah I-SID.
850 *
851 * For a packet with a PBB header, this is the I-SID from the
852 * outermost service tag.
853 *
854 * Prereqs:
855 * OXM_OF_ETH_TYPE must match 0x88E7 exactly.
856 *
857 * Format: 24-bit integer in network byte order.
858 *
859 * Masking: Arbitrary masks. */
860#define OXM_OF_PBB_ISID OXM_HEADER (0x8000, OFPXMT_OFB_PBB_ISID, 3)
861#define OXM_OF_PBB_ISID_W OXM_HEADER_W(0x8000, OFPXMT_OFB_PBB_ISID, 3)
862
863/* Logical Port Metadata.
864 *
865 * Metadata associated with a logical port.
866 * If the logical port performs encapsulation and decapsulation, this
867 * is the demultiplexing field from the encapsulation header.
868 * For example, for a packet received via GRE tunnel including a (32-bit) key,
869 * the key is stored in the low 32-bits and the high bits are zeroed.
870 * For a MPLS logical port, the low 20 bits represent the MPLS Label.
871 * For a VxLAN logical port, the low 24 bits represent the VNI.
872 * If the packet is not received through a logical port, the value is 0.
873 *
874 * Prereqs: None.
875 *
876 * Format: 64-bit integer in network byte order.
877 *
878 * Masking: Arbitrary masks. */
879#define OXM_OF_TUNNEL_ID OXM_HEADER (0x8000, OFPXMT_OFB_TUNNEL_ID, 8)
880#define OXM_OF_TUNNEL_ID_W OXM_HEADER_W(0x8000, OFPXMT_OFB_TUNNEL_ID, 8)
881
882/* The IPv6 Extension Header pseudo-field.
883 *
884 * Prereqs:
885 * OXM_OF_ETH_TYPE must match 0x86dd exactly
886 *
887 * Format: 16-bit integer with 7 most-significant bits forced to 0.
888 * Only the lower 9 bits have meaning.
889 *
890 * Masking: Maskable. */
891#define OXM_OF_IPV6_EXTHDR OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_EXTHDR, 2)
892#define OXM_OF_IPV6_EXTHDR_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV6_EXTHDR, 2)
893
894/* Bit definitions for IPv6 Extension Header pseudo-field. */
895enum ofp_ipv6exthdr_flags {
896 OFPIEH_NONEXT = 1 << 0, /* "No next header" encountered. */
897 OFPIEH_ESP = 1 << 1, /* Encrypted Sec Payload header present. */
898 OFPIEH_AUTH = 1 << 2, /* Authentication header present. */
899 OFPIEH_DEST = 1 << 3, /* 1 or 2 dest headers present. */
900 OFPIEH_FRAG = 1 << 4, /* Fragment header present. */
901 OFPIEH_ROUTER = 1 << 5, /* Router header present. */
902 OFPIEH_HOP = 1 << 6, /* Hop-by-hop header present. */
903 OFPIEH_UNREP = 1 << 7, /* Unexpected repeats encountered. */
904 OFPIEH_UNSEQ = 1 << 8, /* Unexpected sequencing encountered. */
905};
906
907/* Header for OXM experimenter match fields. */
908struct ofp_oxm_experimenter_header {
909 uint32_t oxm_header; /* oxm_class = OFPXMC_EXPERIMENTER */
910 uint32_t experimenter; /* Experimenter ID which takes the same
911 form as in struct ofp_experimenter_header. */
912};
913OFP_ASSERT(sizeof(struct ofp_oxm_experimenter_header) == 8);
914
915/* ## ----------------- ## */
916/* ## OpenFlow Actions. ## */
917/* ## ----------------- ## */
918
919enum ofp_action_type {
920 OFPAT_OUTPUT = 0, /* Output to switch port. */
921 OFPAT_COPY_TTL_OUT = 11, /* Copy TTL "outwards" -- from next-to-outermost
922 to outermost */
923 OFPAT_COPY_TTL_IN = 12, /* Copy TTL "inwards" -- from outermost to
924 next-to-outermost */
925 OFPAT_SET_MPLS_TTL = 15, /* MPLS TTL */
926 OFPAT_DEC_MPLS_TTL = 16, /* Decrement MPLS TTL */
927
928 OFPAT_PUSH_VLAN = 17, /* Push a new VLAN tag */
929 OFPAT_POP_VLAN = 18, /* Pop the outer VLAN tag */
930 OFPAT_PUSH_MPLS = 19, /* Push a new MPLS tag */
931 OFPAT_POP_MPLS = 20, /* Pop the outer MPLS tag */
932 OFPAT_SET_QUEUE = 21, /* Set queue id when outputting to a port */
933 OFPAT_GROUP = 22, /* Apply group. */
934 OFPAT_SET_NW_TTL = 23, /* IP TTL. */
935 OFPAT_DEC_NW_TTL = 24, /* Decrement IP TTL. */
936 OFPAT_SET_FIELD = 25, /* Set a header field using OXM TLV format. */
937 OFPAT_PUSH_PBB = 26, /* Push a new PBB service tag (I-TAG) */
938 OFPAT_POP_PBB = 27, /* Pop the outer PBB service tag (I-TAG) */
939 OFPAT_EXPERIMENTER = 0xffff
940};
941
942/* Action header that is common to all actions. The length includes the
943 * header and any padding used to make the action 64-bit aligned.
944 * NB: The length of an action *must* always be a multiple of eight. */
945struct ofp_action_header {
946 uint16_t type; /* One of OFPAT_*. */
947 uint16_t len; /* Length of action, including this
948 header. This is the length of action,
949 including any padding to make it
950 64-bit aligned. */
951 uint8_t pad[4];
952};
953OFP_ASSERT(sizeof(struct ofp_action_header) == 8);
954
955enum ofp_controller_max_len {
956 OFPCML_MAX = 0xffe5, /* maximum max_len value which can be used
957 to request a specific byte length. */
958 OFPCML_NO_BUFFER = 0xffff /* indicates that no buffering should be
959 applied and the whole packet is to be
960 sent to the controller. */
961};
962
963/* Action structure for OFPAT_OUTPUT, which sends packets out 'port'.
964 * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
965 * number of bytes to send. A 'max_len' of zero means no bytes of the
966 * packet should be sent. A 'max_len' of OFPCML_NO_BUFFER means that
967 * the packet is not buffered and the complete packet is to be sent to
968 * the controller. */
969struct ofp_action_output {
970 uint16_t type; /* OFPAT_OUTPUT. */
971 uint16_t len; /* Length is 16. */
972 uint32_t port; /* Output port. */
973 uint16_t max_len; /* Max length to send to controller. */
974 uint8_t pad[6]; /* Pad to 64 bits. */
975};
976OFP_ASSERT(sizeof(struct ofp_action_output) == 16);
977
978/* Action structure for OFPAT_SET_MPLS_TTL. */
979struct ofp_action_mpls_ttl {
980 uint16_t type; /* OFPAT_SET_MPLS_TTL. */
981 uint16_t len; /* Length is 8. */
982 uint8_t mpls_ttl; /* MPLS TTL */
983 uint8_t pad[3];
984};
985OFP_ASSERT(sizeof(struct ofp_action_mpls_ttl) == 8);
986
987/* Action structure for OFPAT_PUSH_VLAN/MPLS/PBB. */
988struct ofp_action_push {
989 uint16_t type; /* OFPAT_PUSH_VLAN/MPLS/PBB. */
990 uint16_t len; /* Length is 8. */
991 uint16_t ethertype; /* Ethertype */
992 uint8_t pad[2];
993};
994OFP_ASSERT(sizeof(struct ofp_action_push) == 8);
995
996/* Action structure for OFPAT_POP_MPLS. */
997struct ofp_action_pop_mpls {
998 uint16_t type; /* OFPAT_POP_MPLS. */
999 uint16_t len; /* Length is 8. */
1000 uint16_t ethertype; /* Ethertype */
1001 uint8_t pad[2];
1002};
1003OFP_ASSERT(sizeof(struct ofp_action_pop_mpls) == 8);
1004
1005/* Action structure for OFPAT_GROUP. */
1006struct ofp_action_group {
1007 uint16_t type; /* OFPAT_GROUP. */
1008 uint16_t len; /* Length is 8. */
1009 uint32_t group_id; /* Group identifier. */
1010};
1011OFP_ASSERT(sizeof(struct ofp_action_group) == 8);
1012
1013/* Action structure for OFPAT_SET_NW_TTL. */
1014struct ofp_action_nw_ttl {
1015 uint16_t type; /* OFPAT_SET_NW_TTL. */
1016 uint16_t len; /* Length is 8. */
1017 uint8_t nw_ttl; /* IP TTL */
1018 uint8_t pad[3];
1019};
1020OFP_ASSERT(sizeof(struct ofp_action_nw_ttl) == 8);
1021
1022/* Action structure for OFPAT_SET_FIELD. */
1023struct ofp_action_set_field {
1024 uint16_t type; /* OFPAT_SET_FIELD. */
1025 uint16_t len; /* Length is padded to 64 bits. */
1026 /* Followed by:
1027 * - Exactly oxm_len bytes containing a single OXM TLV, then
1028 * - Exactly ((oxm_len + 4) + 7)/8*8 - (oxm_len + 4) (between 0 and 7)
1029 * bytes of all-zero bytes
1030 */
1031 uint8_t field[4]; /* OXM TLV - Make compiler happy */
1032};
1033OFP_ASSERT(sizeof(struct ofp_action_set_field) == 8);
1034
1035/* Action header for OFPAT_EXPERIMENTER.
1036 * The rest of the body is experimenter-defined. */
1037struct ofp_action_experimenter_header {
1038 uint16_t type; /* OFPAT_EXPERIMENTER. */
1039 uint16_t len; /* Length is a multiple of 8. */
1040 uint32_t experimenter; /* Experimenter ID which takes the same
1041 form as in struct
1042 ofp_experimenter_header. */
1043};
1044OFP_ASSERT(sizeof(struct ofp_action_experimenter_header) == 8);
1045
1046/* ## ---------------------- ## */
1047/* ## OpenFlow Instructions. ## */
1048/* ## ---------------------- ## */
1049
1050enum ofp_instruction_type {
1051 OFPIT_GOTO_TABLE = 1, /* Setup the next table in the lookup
1052 pipeline */
1053 OFPIT_WRITE_METADATA = 2, /* Setup the metadata field for use later in
1054 pipeline */
1055 OFPIT_WRITE_ACTIONS = 3, /* Write the action(s) onto the datapath action
1056 set */
1057 OFPIT_APPLY_ACTIONS = 4, /* Applies the action(s) immediately */
1058 OFPIT_CLEAR_ACTIONS = 5, /* Clears all actions from the datapath
1059 action set */
1060 OFPIT_METER = 6, /* Apply meter (rate limiter) */
1061
1062 OFPIT_EXPERIMENTER = 0xFFFF /* Experimenter instruction */
1063};
1064
1065/* Instruction header that is common to all instructions. The length includes
1066 * the header and any padding used to make the instruction 64-bit aligned.
1067 * NB: The length of an instruction *must* always be a multiple of eight. */
1068struct ofp_instruction {
1069 uint16_t type; /* Instruction type */
1070 uint16_t len; /* Length of this struct in bytes. */
1071};
1072OFP_ASSERT(sizeof(struct ofp_instruction) == 4);
1073
1074/* Instruction structure for OFPIT_GOTO_TABLE */
1075struct ofp_instruction_goto_table {
1076 uint16_t type; /* OFPIT_GOTO_TABLE */
1077 uint16_t len; /* Length of this struct in bytes. */
1078 uint8_t table_id; /* Set next table in the lookup pipeline */
1079 uint8_t pad[3]; /* Pad to 64 bits. */
1080};
1081OFP_ASSERT(sizeof(struct ofp_instruction_goto_table) == 8);
1082
1083/* Instruction structure for OFPIT_WRITE_METADATA */
1084struct ofp_instruction_write_metadata {
1085 uint16_t type; /* OFPIT_WRITE_METADATA */
1086 uint16_t len; /* Length of this struct in bytes. */
1087 uint8_t pad[4]; /* Align to 64-bits */
1088 uint64_t metadata; /* Metadata value to write */
1089 uint64_t metadata_mask; /* Metadata write bitmask */
1090};
1091OFP_ASSERT(sizeof(struct ofp_instruction_write_metadata) == 24);
1092
1093/* Instruction structure for OFPIT_WRITE/APPLY/CLEAR_ACTIONS */
1094struct ofp_instruction_actions {
1095 uint16_t type; /* One of OFPIT_*_ACTIONS */
1096 uint16_t len; /* Length of this struct in bytes. */
1097 uint8_t pad[4]; /* Align to 64-bits */
1098 struct ofp_action_header actions[0]; /* Actions associated with
1099 OFPIT_WRITE_ACTIONS and
1100 OFPIT_APPLY_ACTIONS */
1101};
1102OFP_ASSERT(sizeof(struct ofp_instruction_actions) == 8);
1103
1104/* Instruction structure for OFPIT_METER */
1105struct ofp_instruction_meter {
1106 uint16_t type; /* OFPIT_METER */
1107 uint16_t len; /* Length is 8. */
1108 uint32_t meter_id; /* Meter instance. */
1109};
1110OFP_ASSERT(sizeof(struct ofp_instruction_meter) == 8);
1111
1112/* Instruction structure for experimental instructions */
1113struct ofp_instruction_experimenter {
1114 uint16_t type; /* OFPIT_EXPERIMENTER */
1115 uint16_t len; /* Length of this struct in bytes */
1116 uint32_t experimenter; /* Experimenter ID which takes the same form
1117 as in struct ofp_experimenter_header. */
1118 /* Experimenter-defined arbitrary additional data. */
1119};
1120OFP_ASSERT(sizeof(struct ofp_instruction_experimenter) == 8);
1121
1122/* ## --------------------------- ## */
1123/* ## OpenFlow Flow Modification. ## */
1124/* ## --------------------------- ## */
1125
1126enum ofp_flow_mod_command {
1127 OFPFC_ADD = 0, /* New flow. */
1128 OFPFC_MODIFY = 1, /* Modify all matching flows. */
1129 OFPFC_MODIFY_STRICT = 2, /* Modify entry strictly matching wildcards and
1130 priority. */
1131 OFPFC_DELETE = 3, /* Delete all matching flows. */
1132 OFPFC_DELETE_STRICT = 4, /* Delete entry strictly matching wildcards and
1133 priority. */
1134};
1135
1136/* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
1137 * is permanent. */
1138#define OFP_FLOW_PERMANENT 0
1139
1140/* By default, choose a priority in the middle. */
1141#define OFP_DEFAULT_PRIORITY 0x8000
1142
1143enum ofp_flow_mod_flags {
1144 OFPFF_SEND_FLOW_REM = 1 << 0, /* Send flow removed message when flow
1145 * expires or is deleted. */
1146 OFPFF_CHECK_OVERLAP = 1 << 1, /* Check for overlapping entries first. */
1147 OFPFF_RESET_COUNTS = 1 << 2, /* Reset flow packet and byte counts. */
1148 OFPFF_NO_PKT_COUNTS = 1 << 3, /* Don't keep track of packet count. */
1149 OFPFF_NO_BYT_COUNTS = 1 << 4, /* Don't keep track of byte count. */
1150};
1151
1152/* Flow setup and teardown (controller -> datapath). */
1153struct ofp_flow_mod {
1154 struct ofp_header header;
1155 uint64_t cookie; /* Opaque controller-issued identifier. */
1156 uint64_t cookie_mask; /* Mask used to restrict the cookie bits
1157 that must match when the command is
1158 OFPFC_MODIFY* or OFPFC_DELETE*. A value
1159 of 0 indicates no restriction. */
1160
1161 /* Flow actions. */
1162 uint8_t table_id; /* ID of the table to put the flow in.
1163 For OFPFC_DELETE_* commands, OFPTT_ALL
1164 can also be used to delete matching
1165 flows from all tables. */
1166 uint8_t command; /* One of OFPFC_*. */
1167 uint16_t idle_timeout; /* Idle time before discarding (seconds). */
1168 uint16_t hard_timeout; /* Max time before discarding (seconds). */
1169 uint16_t priority; /* Priority level of flow entry. */
1170 uint32_t buffer_id; /* Buffered packet to apply to, or
1171 OFP_NO_BUFFER.
1172 Not meaningful for OFPFC_DELETE*. */
1173 uint32_t out_port; /* For OFPFC_DELETE* commands, require
1174 matching entries to include this as an
1175 output port. A value of OFPP_ANY
1176 indicates no restriction. */
1177 uint32_t out_group; /* For OFPFC_DELETE* commands, require
1178 matching entries to include this as an
1179 output group. A value of OFPG_ANY
1180 indicates no restriction. */
1181 uint16_t flags; /* One of OFPFF_*. */
1182 uint8_t pad[2];
1183 struct ofp_match match; /* Fields to match. Variable size. */
1184 //struct ofp_instruction instructions[0]; /* Instruction set */
1185};
1186OFP_ASSERT(sizeof(struct ofp_flow_mod) == 56);
1187
1188/* Group numbering. Groups can use any number up to OFPG_MAX. */
1189enum ofp_group {
1190 /* Last usable group number. */
1191 OFPG_MAX = 0xffffff00,
1192
1193 /* Fake groups. */
1194 OFPG_ALL = 0xfffffffc, /* Represents all groups for group delete
1195 commands. */
1196 OFPG_ANY = 0xffffffff /* Wildcard group used only for flow stats
1197 requests. Selects all flows regardless of
1198 group (including flows with no group).
1199 */
1200};
1201
1202/* Group commands */
1203enum ofp_group_mod_command {
1204 OFPGC_ADD = 0, /* New group. */
1205 OFPGC_MODIFY = 1, /* Modify all matching groups. */
1206 OFPGC_DELETE = 2, /* Delete all matching groups. */
1207};
1208
1209/* Bucket for use in groups. */
1210struct ofp_bucket {
1211 uint16_t len; /* Length the bucket in bytes, including
1212 this header and any padding to make it
1213 64-bit aligned. */
1214 uint16_t weight; /* Relative weight of bucket. Only
1215 defined for select groups. */
1216 uint32_t watch_port; /* Port whose state affects whether this
1217 bucket is live. Only required for fast
1218 failover groups. */
1219 uint32_t watch_group; /* Group whose state affects whether this
1220 bucket is live. Only required for fast
1221 failover groups. */
1222 uint8_t pad[4];
1223 struct ofp_action_header actions[0]; /* The action length is inferred
1224 from the length field in the
1225 header. */
1226};
1227OFP_ASSERT(sizeof(struct ofp_bucket) == 16);
1228
1229/* Group setup and teardown (controller -> datapath). */
1230struct ofp_group_mod {
1231 struct ofp_header header;
1232 uint16_t command; /* One of OFPGC_*. */
1233 uint8_t type; /* One of OFPGT_*. */
1234 uint8_t pad; /* Pad to 64 bits. */
1235 uint32_t group_id; /* Group identifier. */
1236 struct ofp_bucket buckets[0]; /* The length of the bucket array is inferred
1237 from the length field in the header. */
1238};
1239OFP_ASSERT(sizeof(struct ofp_group_mod) == 16);
1240
1241/* Group types. Values in the range [128, 255] are reserved for experimental
1242 * use. */
1243enum ofp_group_type {
1244 OFPGT_ALL = 0, /* All (multicast/broadcast) group. */
1245 OFPGT_SELECT = 1, /* Select group. */
1246 OFPGT_INDIRECT = 2, /* Indirect group. */
1247 OFPGT_FF = 3, /* Fast failover group. */
1248};
1249
1250/* Special buffer-id to indicate 'no buffer' */
1251#define OFP_NO_BUFFER 0xffffffff
1252
1253/* Send packet (controller -> datapath). */
1254struct ofp_packet_out {
1255 struct ofp_header header;
1256 uint32_t buffer_id; /* ID assigned by datapath (OFP_NO_BUFFER
1257 if none). */
1258 uint32_t in_port; /* Packet's input port or OFPP_CONTROLLER. */
1259 uint16_t actions_len; /* Size of action array in bytes. */
1260 uint8_t pad[6];
1261 struct ofp_action_header actions[0]; /* Action list. */
1262 /* uint8_t data[0]; */ /* Packet data. The length is inferred
1263 from the length field in the header.
1264 (Only meaningful if buffer_id == -1.) */
1265};
1266OFP_ASSERT(sizeof(struct ofp_packet_out) == 24);
1267
1268/* Why is this packet being sent to the controller? */
1269enum ofp_packet_in_reason {
1270 OFPR_NO_MATCH = 0, /* No matching flow (table-miss flow entry). */
1271 OFPR_ACTION = 1, /* Action explicitly output to controller. */
1272 OFPR_INVALID_TTL = 2, /* Packet has invalid TTL */
1273};
1274
1275/* Packet received on port (datapath -> controller). */
1276struct ofp_packet_in {
1277 struct ofp_header header;
1278 uint32_t buffer_id; /* ID assigned by datapath. */
1279 uint16_t total_len; /* Full length of frame. */
1280 uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
1281 uint8_t table_id; /* ID of the table that was looked up */
1282 uint64_t cookie; /* Cookie of the flow entry that was looked up. */
1283 struct ofp_match match; /* Packet metadata. Variable size. */
1284 /* Followed by:
1285 * - Exactly 2 all-zero padding bytes, then
1286 * - An Ethernet frame whose length is inferred from header.length.
1287 * The padding bytes preceding the Ethernet frame ensure that the IP
1288 * header (if any) following the Ethernet header is 32-bit aligned.
1289 */
1290 //uint8_t pad[2]; /* Align to 64 bit + 16 bit */
1291 //uint8_t data[0]; /* Ethernet frame */
1292};
1293OFP_ASSERT(sizeof(struct ofp_packet_in) == 32);
1294
1295/* Why was this flow removed? */
1296enum ofp_flow_removed_reason {
1297 OFPRR_IDLE_TIMEOUT = 0, /* Flow idle time exceeded idle_timeout. */
1298 OFPRR_HARD_TIMEOUT = 1, /* Time exceeded hard_timeout. */
1299 OFPRR_DELETE = 2, /* Evicted by a DELETE flow mod. */
1300 OFPRR_GROUP_DELETE = 3, /* Group was removed. */
1301};
1302
1303/* Flow removed (datapath -> controller). */
1304struct ofp_flow_removed {
1305 struct ofp_header header;
1306 uint64_t cookie; /* Opaque controller-issued identifier. */
1307
1308 uint16_t priority; /* Priority level of flow entry. */
1309 uint8_t reason; /* One of OFPRR_*. */
1310 uint8_t table_id; /* ID of the table */
1311
1312 uint32_t duration_sec; /* Time flow was alive in seconds. */
1313 uint32_t duration_nsec; /* Time flow was alive in nanoseconds beyond
1314 duration_sec. */
1315 uint16_t idle_timeout; /* Idle timeout from original flow mod. */
1316 uint16_t hard_timeout; /* Hard timeout from original flow mod. */
1317 uint64_t packet_count;
1318 uint64_t byte_count;
1319 struct ofp_match match; /* Description of fields. Variable size. */
1320};
1321OFP_ASSERT(sizeof(struct ofp_flow_removed) == 56);
1322
1323/* Meter numbering. Flow meters can use any number up to OFPM_MAX. */
1324enum ofp_meter {
1325 /* Last usable meter. */
1326 OFPM_MAX = 0xffff0000,
1327
1328 /* Virtual meters. */
1329 OFPM_SLOWPATH = 0xfffffffd, /* Meter for slow datapath. */
1330 OFPM_CONTROLLER = 0xfffffffe, /* Meter for controller connection. */
1331 OFPM_ALL = 0xffffffff, /* Represents all meters for stat requests
1332 commands. */
1333};
1334
1335/* Meter band types */
1336enum ofp_meter_band_type {
1337 OFPMBT_DROP = 1, /* Drop packet. */
1338 OFPMBT_DSCP_REMARK = 2, /* Remark DSCP in the IP header. */
1339 OFPMBT_EXPERIMENTER = 0xFFFF /* Experimenter meter band. */
1340};
1341
1342/* Common header for all meter bands */
1343struct ofp_meter_band_header {
1344 uint16_t type; /* One of OFPMBT_*. */
1345 uint16_t len; /* Length in bytes of this band. */
1346 uint32_t rate; /* Rate for this band. */
1347 uint32_t burst_size; /* Size of bursts. */
1348};
1349OFP_ASSERT(sizeof(struct ofp_meter_band_header) == 12);
1350
1351/* OFPMBT_DROP band - drop packets */
1352struct ofp_meter_band_drop {
1353 uint16_t type; /* OFPMBT_DROP. */
1354 uint16_t len; /* Length in bytes of this band. */
1355 uint32_t rate; /* Rate for dropping packets. */
1356 uint32_t burst_size; /* Size of bursts. */
1357 uint8_t pad[4];
1358};
1359OFP_ASSERT(sizeof(struct ofp_meter_band_drop) == 16);
1360
1361/* OFPMBT_DSCP_REMARK band - Remark DSCP in the IP header */
1362struct ofp_meter_band_dscp_remark {
1363 uint16_t type; /* OFPMBT_DSCP_REMARK. */
1364 uint16_t len; /* Length in bytes of this band. */
1365 uint32_t rate; /* Rate for remarking packets. */
1366 uint32_t burst_size; /* Size of bursts. */
1367 uint8_t prec_level; /* Number of precendence level to substract. */
1368 uint8_t pad[3];
1369};
1370OFP_ASSERT(sizeof(struct ofp_meter_band_dscp_remark) == 16);
1371
1372/* OFPMBT_EXPERIMENTER band - Write actions in action set */
1373struct ofp_meter_band_experimenter {
1374 uint16_t type; /* One of OFPMBT_*. */
1375 uint16_t len; /* Length in bytes of this band. */
1376 uint32_t rate; /* Rate for this band. */
1377 uint32_t burst_size; /* Size of bursts. */
1378 uint32_t experimenter; /* Experimenter ID which takes the same
1379 form as in struct
1380 ofp_experimenter_header. */
1381};
1382OFP_ASSERT(sizeof(struct ofp_meter_band_experimenter) == 16);
1383
1384/* Meter commands */
1385enum ofp_meter_mod_command {
1386 OFPMC_ADD, /* New meter. */
1387 OFPMC_MODIFY, /* Modify specified meter. */
1388 OFPMC_DELETE, /* Delete specified meter. */
1389};
1390
1391/* Meter configuration flags */
1392enum ofp_meter_flags {
1393 OFPMF_KBPS = 1 << 0, /* Rate value in kb/s (kilo-bit per second). */
1394 OFPMF_PKTPS = 1 << 1, /* Rate value in packet/sec. */
1395 OFPMF_BURST = 1 << 2, /* Do burst size. */
1396 OFPMF_STATS = 1 << 3, /* Collect statistics. */
1397};
1398
1399/* Meter configuration. OFPT_METER_MOD. */
1400struct ofp_meter_mod {
1401 struct ofp_header header;
1402 uint16_t command; /* One of OFPMC_*. */
1403 uint16_t flags; /* One of OFPMF_*. */
1404 uint32_t meter_id; /* Meter instance. */
1405 struct ofp_meter_band_header bands[0]; /* The bands length is
1406 inferred from the length field
1407 in the header. */
1408};
1409OFP_ASSERT(sizeof(struct ofp_meter_mod) == 16);
1410
1411/* Values for 'type' in ofp_error_message. These values are immutable: they
1412 * will not change in future versions of the protocol (although new values may
1413 * be added). */
1414enum ofp_error_type {
1415 OFPET_HELLO_FAILED = 0, /* Hello protocol failed. */
1416 OFPET_BAD_REQUEST = 1, /* Request was not understood. */
1417 OFPET_BAD_ACTION = 2, /* Error in action description. */
1418 OFPET_BAD_INSTRUCTION = 3, /* Error in instruction list. */
1419 OFPET_BAD_MATCH = 4, /* Error in match. */
1420 OFPET_FLOW_MOD_FAILED = 5, /* Problem modifying flow entry. */
1421 OFPET_GROUP_MOD_FAILED = 6, /* Problem modifying group entry. */
1422 OFPET_PORT_MOD_FAILED = 7, /* Port mod request failed. */
1423 OFPET_TABLE_MOD_FAILED = 8, /* Table mod request failed. */
1424 OFPET_QUEUE_OP_FAILED = 9, /* Queue operation failed. */
1425 OFPET_SWITCH_CONFIG_FAILED = 10, /* Switch config request failed. */
1426 OFPET_ROLE_REQUEST_FAILED = 11, /* Controller Role request failed. */
1427 OFPET_METER_MOD_FAILED = 12, /* Error in meter. */
1428 OFPET_TABLE_FEATURES_FAILED = 13, /* Setting table features failed. */
1429 OFPET_EXPERIMENTER = 0xffff /* Experimenter error messages. */
1430};
1431
1432/* ofp_error_msg 'code' values for OFPET_HELLO_FAILED. 'data' contains an
1433 * ASCII text string that may give failure details. */
1434enum ofp_hello_failed_code {
1435 OFPHFC_INCOMPATIBLE = 0, /* No compatible version. */
1436 OFPHFC_EPERM = 1, /* Permissions error. */
1437};
1438
1439/* ofp_error_msg 'code' values for OFPET_BAD_REQUEST. 'data' contains at least
1440 * the first 64 bytes of the failed request. */
1441enum ofp_bad_request_code {
1442 OFPBRC_BAD_VERSION = 0, /* ofp_header.version not supported. */
1443 OFPBRC_BAD_TYPE = 1, /* ofp_header.type not supported. */
1444 OFPBRC_BAD_MULTIPART = 2, /* ofp_multipart_request.type not supported. */
1445 OFPBRC_BAD_EXPERIMENTER = 3, /* Experimenter id not supported
1446 * (in ofp_experimenter_header or
1447 * ofp_multipart_request or
1448 * ofp_multipart_reply). */
1449 OFPBRC_BAD_EXP_TYPE = 4, /* Experimenter type not supported. */
1450 OFPBRC_EPERM = 5, /* Permissions error. */
1451 OFPBRC_BAD_LEN = 6, /* Wrong request length for type. */
1452 OFPBRC_BUFFER_EMPTY = 7, /* Specified buffer has already been used. */
1453 OFPBRC_BUFFER_UNKNOWN = 8, /* Specified buffer does not exist. */
1454 OFPBRC_BAD_TABLE_ID = 9, /* Specified table-id invalid or does not
1455 * exist. */
1456 OFPBRC_IS_SLAVE = 10, /* Denied because controller is slave. */
1457 OFPBRC_BAD_PORT = 11, /* Invalid port. */
1458 OFPBRC_BAD_PACKET = 12, /* Invalid packet in packet-out. */
1459 OFPBRC_MULTIPART_BUFFER_OVERFLOW = 13, /* ofp_multipart_request
1460 overflowed the assigned buffer. */
1461};
1462
1463/* ofp_error_msg 'code' values for OFPET_BAD_ACTION. 'data' contains at least
1464 * the first 64 bytes of the failed request. */
1465enum ofp_bad_action_code {
1466 OFPBAC_BAD_TYPE = 0, /* Unknown action type. */
1467 OFPBAC_BAD_LEN = 1, /* Length problem in actions. */
1468 OFPBAC_BAD_EXPERIMENTER = 2, /* Unknown experimenter id specified. */
1469 OFPBAC_BAD_EXP_TYPE = 3, /* Unknown action for experimenter id. */
1470 OFPBAC_BAD_OUT_PORT = 4, /* Problem validating output port. */
1471 OFPBAC_BAD_ARGUMENT = 5, /* Bad action argument. */
1472 OFPBAC_EPERM = 6, /* Permissions error. */
1473 OFPBAC_TOO_MANY = 7, /* Can't handle this many actions. */
1474 OFPBAC_BAD_QUEUE = 8, /* Problem validating output queue. */
1475 OFPBAC_BAD_OUT_GROUP = 9, /* Invalid group id in forward action. */
1476 OFPBAC_MATCH_INCONSISTENT = 10, /* Action can't apply for this match,
1477 or Set-Field missing prerequisite. */
1478 OFPBAC_UNSUPPORTED_ORDER = 11, /* Action order is unsupported for the
1479 action list in an Apply-Actions instruction */
1480 OFPBAC_BAD_TAG = 12, /* Actions uses an unsupported
1481 tag/encap. */
1482 OFPBAC_BAD_SET_TYPE = 13, /* Unsupported type in SET_FIELD action. */
1483 OFPBAC_BAD_SET_LEN = 14, /* Length problem in SET_FIELD action. */
1484 OFPBAC_BAD_SET_ARGUMENT = 15, /* Bad argument in SET_FIELD action. */
1485};
1486
1487/* ofp_error_msg 'code' values for OFPET_BAD_INSTRUCTION. 'data' contains at least
1488 * the first 64 bytes of the failed request. */
1489enum ofp_bad_instruction_code {
1490 OFPBIC_UNKNOWN_INST = 0, /* Unknown instruction. */
1491 OFPBIC_UNSUP_INST = 1, /* Switch or table does not support the
1492 instruction. */
1493 OFPBIC_BAD_TABLE_ID = 2, /* Invalid Table-ID specified. */
1494 OFPBIC_UNSUP_METADATA = 3, /* Metadata value unsupported by datapath. */
1495 OFPBIC_UNSUP_METADATA_MASK = 4, /* Metadata mask value unsupported by
1496 datapath. */
1497 OFPBIC_BAD_EXPERIMENTER = 5, /* Unknown experimenter id specified. */
1498 OFPBIC_BAD_EXP_TYPE = 6, /* Unknown instruction for experimenter id. */
1499 OFPBIC_BAD_LEN = 7, /* Length problem in instructions. */
1500 OFPBIC_EPERM = 8, /* Permissions error. */
1501};
1502
1503/* ofp_error_msg 'code' values for OFPET_BAD_MATCH. 'data' contains at least
1504 * the first 64 bytes of the failed request. */
1505enum ofp_bad_match_code {
1506 OFPBMC_BAD_TYPE = 0, /* Unsupported match type specified by the
1507 match */
1508 OFPBMC_BAD_LEN = 1, /* Length problem in match. */
1509 OFPBMC_BAD_TAG = 2, /* Match uses an unsupported tag/encap. */
1510 OFPBMC_BAD_DL_ADDR_MASK = 3, /* Unsupported datalink addr mask - switch
1511 does not support arbitrary datalink
1512 address mask. */
1513 OFPBMC_BAD_NW_ADDR_MASK = 4, /* Unsupported network addr mask - switch
1514 does not support arbitrary network
1515 address mask. */
1516 OFPBMC_BAD_WILDCARDS = 5, /* Unsupported combination of fields masked
1517 or omitted in the match. */
1518 OFPBMC_BAD_FIELD = 6, /* Unsupported field type in the match. */
1519 OFPBMC_BAD_VALUE = 7, /* Unsupported value in a match field. */
1520 OFPBMC_BAD_MASK = 8, /* Unsupported mask specified in the match,
1521 field is not dl-address or nw-address. */
1522 OFPBMC_BAD_PREREQ = 9, /* A prerequisite was not met. */
1523 OFPBMC_DUP_FIELD = 10, /* A field type was duplicated. */
1524 OFPBMC_EPERM = 11, /* Permissions error. */
1525};
1526
1527/* ofp_error_msg 'code' values for OFPET_FLOW_MOD_FAILED. 'data' contains
1528 * at least the first 64 bytes of the failed request. */
1529enum ofp_flow_mod_failed_code {
1530 OFPFMFC_UNKNOWN = 0, /* Unspecified error. */
1531 OFPFMFC_TABLE_FULL = 1, /* Flow not added because table was full. */
1532 OFPFMFC_BAD_TABLE_ID = 2, /* Table does not exist */
1533 OFPFMFC_OVERLAP = 3, /* Attempted to add overlapping flow with
1534 CHECK_OVERLAP flag set. */
1535 OFPFMFC_EPERM = 4, /* Permissions error. */
1536 OFPFMFC_BAD_TIMEOUT = 5, /* Flow not added because of unsupported
1537 idle/hard timeout. */
1538 OFPFMFC_BAD_COMMAND = 6, /* Unsupported or unknown command. */
1539 OFPFMFC_BAD_FLAGS = 7, /* Unsupported or unknown flags. */
1540};
1541
1542/* ofp_error_msg 'code' values for OFPET_GROUP_MOD_FAILED. 'data' contains
1543 * at least the first 64 bytes of the failed request. */
1544enum ofp_group_mod_failed_code {
1545 OFPGMFC_GROUP_EXISTS = 0, /* Group not added because a group ADD
1546 attempted to replace an
1547 already-present group. */
1548 OFPGMFC_INVALID_GROUP = 1, /* Group not added because Group
1549 specified is invalid. */
1550 OFPGMFC_WEIGHT_UNSUPPORTED = 2, /* Switch does not support unequal load
1551 sharing with select groups. */
1552 OFPGMFC_OUT_OF_GROUPS = 3, /* The group table is full. */
1553 OFPGMFC_OUT_OF_BUCKETS = 4, /* The maximum number of action buckets
1554 for a group has been exceeded. */
1555 OFPGMFC_CHAINING_UNSUPPORTED = 5, /* Switch does not support groups that
1556 forward to groups. */
1557 OFPGMFC_WATCH_UNSUPPORTED = 6, /* This group cannot watch the watch_port
1558 or watch_group specified. */
1559 OFPGMFC_LOOP = 7, /* Group entry would cause a loop. */
1560 OFPGMFC_UNKNOWN_GROUP = 8, /* Group not modified because a group
1561 MODIFY attempted to modify a
1562 non-existent group. */
1563 OFPGMFC_CHAINED_GROUP = 9, /* Group not deleted because another
1564 group is forwarding to it. */
1565 OFPGMFC_BAD_TYPE = 10, /* Unsupported or unknown group type. */
1566 OFPGMFC_BAD_COMMAND = 11, /* Unsupported or unknown command. */
1567 OFPGMFC_BAD_BUCKET = 12, /* Error in bucket. */
1568 OFPGMFC_BAD_WATCH = 13, /* Error in watch port/group. */
1569 OFPGMFC_EPERM = 14, /* Permissions error. */
1570};
1571
1572/* ofp_error_msg 'code' values for OFPET_PORT_MOD_FAILED. 'data' contains
1573 * at least the first 64 bytes of the failed request. */
1574enum ofp_port_mod_failed_code {
1575 OFPPMFC_BAD_PORT = 0, /* Specified port number does not exist. */
1576 OFPPMFC_BAD_HW_ADDR = 1, /* Specified hardware address does not
1577 * match the port number. */
1578 OFPPMFC_BAD_CONFIG = 2, /* Specified config is invalid. */
1579 OFPPMFC_BAD_ADVERTISE = 3, /* Specified advertise is invalid. */
1580 OFPPMFC_EPERM = 4, /* Permissions error. */
1581};
1582
1583/* ofp_error_msg 'code' values for OFPET_TABLE_MOD_FAILED. 'data' contains
1584 * at least the first 64 bytes of the failed request. */
1585enum ofp_table_mod_failed_code {
1586 OFPTMFC_BAD_TABLE = 0, /* Specified table does not exist. */
1587 OFPTMFC_BAD_CONFIG = 1, /* Specified config is invalid. */
1588 OFPTMFC_EPERM = 2, /* Permissions error. */
1589};
1590
1591/* ofp_error msg 'code' values for OFPET_QUEUE_OP_FAILED. 'data' contains
1592 * at least the first 64 bytes of the failed request */
1593enum ofp_queue_op_failed_code {
1594 OFPQOFC_BAD_PORT = 0, /* Invalid port (or port does not exist). */
1595 OFPQOFC_BAD_QUEUE = 1, /* Queue does not exist. */
1596 OFPQOFC_EPERM = 2, /* Permissions error. */
1597};
1598
1599/* ofp_error_msg 'code' values for OFPET_SWITCH_CONFIG_FAILED. 'data' contains
1600 * at least the first 64 bytes of the failed request. */
1601enum ofp_switch_config_failed_code {
1602 OFPSCFC_BAD_FLAGS = 0, /* Specified flags is invalid. */
1603 OFPSCFC_BAD_LEN = 1, /* Specified len is invalid. */
1604 OFPSCFC_EPERM = 2, /* Permissions error. */
1605};
1606
1607/* ofp_error_msg 'code' values for OFPET_ROLE_REQUEST_FAILED. 'data' contains
1608 * at least the first 64 bytes of the failed request. */
1609enum ofp_role_request_failed_code {
1610 OFPRRFC_STALE = 0, /* Stale Message: old generation_id. */
1611 OFPRRFC_UNSUP = 1, /* Controller role change unsupported. */
1612 OFPRRFC_BAD_ROLE = 2, /* Invalid role. */
1613};
1614
1615/* ofp_error_msg 'code' values for OFPET_METER_MOD_FAILED. 'data' contains
1616 * at least the first 64 bytes of the failed request. */
1617enum ofp_meter_mod_failed_code {
1618 OFPMMFC_UNKNOWN = 0, /* Unspecified error. */
1619 OFPMMFC_METER_EXISTS = 1, /* Meter not added because a Meter ADD
1620 * attempted to replace an existing Meter. */
1621 OFPMMFC_INVALID_METER = 2, /* Meter not added because Meter specified
1622 * is invalid. */
1623 OFPMMFC_UNKNOWN_METER = 3, /* Meter not modified because a Meter
1624 MODIFY attempted to modify a non-existent
1625 Meter. */
1626 OFPMMFC_BAD_COMMAND = 4, /* Unsupported or unknown command. */
1627 OFPMMFC_BAD_FLAGS = 5, /* Flag configuration unsupported. */
1628 OFPMMFC_BAD_RATE = 6, /* Rate unsupported. */
1629 OFPMMFC_BAD_BURST = 7, /* Burst size unsupported. */
1630 OFPMMFC_BAD_BAND = 8, /* Band unsupported. */
1631 OFPMMFC_BAD_BAND_VALUE = 9, /* Band value unsupported. */
1632 OFPMMFC_OUT_OF_METERS = 10, /* No more meters available. */
1633 OFPMMFC_OUT_OF_BANDS = 11, /* The maximum number of properties
1634 * for a meter has been exceeded. */
1635};
1636
1637/* ofp_error_msg 'code' values for OFPET_TABLE_FEATURES_FAILED. 'data' contains
1638 * at least the first 64 bytes of the failed request. */
1639enum ofp_table_features_failed_code {
1640 OFPTFFC_BAD_TABLE = 0, /* Specified table does not exist. */
1641 OFPTFFC_BAD_METADATA = 1, /* Invalid metadata mask. */
1642 OFPTFFC_BAD_TYPE = 2, /* Unknown property type. */
1643 OFPTFFC_BAD_LEN = 3, /* Length problem in properties. */
1644 OFPTFFC_BAD_ARGUMENT = 4, /* Unsupported property value. */
1645 OFPTFFC_EPERM = 5, /* Permissions error. */
1646};
1647
1648/* OFPT_ERROR: Error message (datapath -> controller). */
1649struct ofp_error_msg {
1650 struct ofp_header header;
1651
1652 uint16_t type;
1653 uint16_t code;
1654 uint8_t data[0]; /* Variable-length data. Interpreted based
1655 on the type and code. No padding. */
1656};
1657OFP_ASSERT(sizeof(struct ofp_error_msg) == 12);
1658
1659/* OFPET_EXPERIMENTER: Error message (datapath -> controller). */
1660struct ofp_error_experimenter_msg {
1661 struct ofp_header header;
1662
1663 uint16_t type; /* OFPET_EXPERIMENTER. */
1664 uint16_t exp_type; /* Experimenter defined. */
1665 uint32_t experimenter; /* Experimenter ID which takes the same form
1666 as in struct ofp_experimenter_header. */
1667 uint8_t data[0]; /* Variable-length data. Interpreted based
1668 on the type and code. No padding. */
1669};
1670OFP_ASSERT(sizeof(struct ofp_error_experimenter_msg) == 16);
1671
1672enum ofp_multipart_types {
1673 /* Description of this OpenFlow switch.
1674 * The request body is empty.
1675 * The reply body is struct ofp_desc. */
1676 OFPMP_DESC = 0,
1677
1678 /* Individual flow statistics.
1679 * The request body is struct ofp_flow_stats_request.
1680 * The reply body is an array of struct ofp_flow_stats. */
1681 OFPMP_FLOW = 1,
1682
1683 /* Aggregate flow statistics.
1684 * The request body is struct ofp_aggregate_stats_request.
1685 * The reply body is struct ofp_aggregate_stats_reply. */
1686 OFPMP_AGGREGATE = 2,
1687
1688 /* Flow table statistics.
1689 * The request body is empty.
1690 * The reply body is an array of struct ofp_table_stats. */
1691 OFPMP_TABLE = 3,
1692
1693 /* Port statistics.
1694 * The request body is struct ofp_port_stats_request.
1695 * The reply body is an array of struct ofp_port_stats. */
1696 OFPMP_PORT_STATS = 4,
1697
1698 /* Queue statistics for a port
1699 * The request body is struct ofp_queue_stats_request.
1700 * The reply body is an array of struct ofp_queue_stats */
1701 OFPMP_QUEUE = 5,
1702
1703 /* Group counter statistics.
1704 * The request body is struct ofp_group_stats_request.
1705 * The reply is an array of struct ofp_group_stats. */
1706 OFPMP_GROUP = 6,
1707
1708 /* Group description.
1709 * The request body is empty.
1710 * The reply body is an array of struct ofp_group_desc_stats. */
1711 OFPMP_GROUP_DESC = 7,
1712
1713 /* Group features.
1714 * The request body is empty.
1715 * The reply body is struct ofp_group_features. */
1716 OFPMP_GROUP_FEATURES = 8,
1717
1718 /* Meter statistics.
1719 * The request body is struct ofp_meter_multipart_requests.
1720 * The reply body is an array of struct ofp_meter_stats. */
1721 OFPMP_METER = 9,
1722
1723 /* Meter configuration.
1724 * The request body is struct ofp_meter_multipart_requests.
1725 * The reply body is an array of struct ofp_meter_config. */
1726 OFPMP_METER_CONFIG = 10,
1727
1728 /* Meter features.
1729 * The request body is empty.
1730 * The reply body is struct ofp_meter_features. */
1731 OFPMP_METER_FEATURES = 11,
1732
1733 /* Table features.
1734 * The request body is either empty or contains an array of
1735 * struct ofp_table_features containing the controller's
1736 * desired view of the switch. If the switch is unable to
1737 * set the specified view an error is returned.
1738 * The reply body is an array of struct ofp_table_features. */
1739 OFPMP_TABLE_FEATURES = 12,
1740
1741 /* Port description.
1742 * The request body is empty.
1743 * The reply body is an array of struct ofp_port. */
1744 OFPMP_PORT_DESC = 13,
1745
1746 /* Experimenter extension.
1747 * The request and reply bodies begin with
1748 * struct ofp_experimenter_multipart_header.
1749 * The request and reply bodies are otherwise experimenter-defined. */
1750 OFPMP_EXPERIMENTER = 0xffff
1751};
1752
1753enum ofp_multipart_request_flags {
1754 OFPMPF_REQ_MORE = 1 << 0 /* More requests to follow. */
1755};
1756
1757struct ofp_multipart_request {
1758 struct ofp_header header;
1759 uint16_t type; /* One of the OFPMP_* constants. */
1760 uint16_t flags; /* OFPMPF_REQ_* flags. */
1761 uint8_t pad[4];
1762 uint8_t body[0]; /* Body of the request. */
1763};
1764OFP_ASSERT(sizeof(struct ofp_multipart_request) == 16);
1765
1766enum ofp_multipart_reply_flags {
1767 OFPMPF_REPLY_MORE = 1 << 0 /* More replies to follow. */
1768};
1769
1770struct ofp_multipart_reply {
1771 struct ofp_header header;
1772 uint16_t type; /* One of the OFPMP_* constants. */
1773 uint16_t flags; /* OFPMPF_REPLY_* flags. */
1774 uint8_t pad[4];
1775 uint8_t body[0]; /* Body of the reply. */
1776};
1777OFP_ASSERT(sizeof(struct ofp_multipart_reply) == 16);
1778
1779#define DESC_STR_LEN 256
1780#define SERIAL_NUM_LEN 32
1781/* Body of reply to OFPMP_DESC request. Each entry is a NULL-terminated
1782 * ASCII string. */
1783struct ofp_desc {
1784 char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */
1785 char hw_desc[DESC_STR_LEN]; /* Hardware description. */
1786 char sw_desc[DESC_STR_LEN]; /* Software description. */
1787 char serial_num[SERIAL_NUM_LEN]; /* Serial number. */
1788 char dp_desc[DESC_STR_LEN]; /* Human readable description of datapath. */
1789};
1790OFP_ASSERT(sizeof(struct ofp_desc) == 1056);
1791
1792/* Body for ofp_multipart_request of type OFPMP_FLOW. */
1793struct ofp_flow_stats_request {
1794 uint8_t table_id; /* ID of table to read (from ofp_table_stats),
1795 OFPTT_ALL for all tables. */
1796 uint8_t pad[3]; /* Align to 32 bits. */
1797 uint32_t out_port; /* Require matching entries to include this
1798 as an output port. A value of OFPP_ANY
1799 indicates no restriction. */
1800 uint32_t out_group; /* Require matching entries to include this
1801 as an output group. A value of OFPG_ANY
1802 indicates no restriction. */
1803 uint8_t pad2[4]; /* Align to 64 bits. */
1804 uint64_t cookie; /* Require matching entries to contain this
1805 cookie value */
1806 uint64_t cookie_mask; /* Mask used to restrict the cookie bits that
1807 must match. A value of 0 indicates
1808 no restriction. */
1809 struct ofp_match match; /* Fields to match. Variable size. */
1810};
1811OFP_ASSERT(sizeof(struct ofp_flow_stats_request) == 40);
1812
1813/* Body of reply to OFPMP_FLOW request. */
1814struct ofp_flow_stats {
1815 uint16_t length; /* Length of this entry. */
1816 uint8_t table_id; /* ID of table flow came from. */
1817 uint8_t pad;
1818 uint32_t duration_sec; /* Time flow has been alive in seconds. */
1819 uint32_t duration_nsec; /* Time flow has been alive in nanoseconds beyond
1820 duration_sec. */
1821 uint16_t priority; /* Priority of the entry. */
1822 uint16_t idle_timeout; /* Number of seconds idle before expiration. */
1823 uint16_t hard_timeout; /* Number of seconds before expiration. */
1824 uint16_t flags; /* One of OFPFF_*. */
1825 uint8_t pad2[4]; /* Align to 64-bits. */
1826 uint64_t cookie; /* Opaque controller-issued identifier. */
1827 uint64_t packet_count; /* Number of packets in flow. */
1828 uint64_t byte_count; /* Number of bytes in flow. */
1829 struct ofp_match match; /* Description of fields. Variable size. */
1830 //struct ofp_instruction instructions[0]; /* Instruction set. */
1831};
1832OFP_ASSERT(sizeof(struct ofp_flow_stats) == 56);
1833
1834/* Body for ofp_multipart_request of type OFPMP_AGGREGATE. */
1835struct ofp_aggregate_stats_request {
1836 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
1837 OFPTT_ALL for all tables. */
1838 uint8_t pad[3]; /* Align to 32 bits. */
1839 uint32_t out_port; /* Require matching entries to include this
1840 as an output port. A value of OFPP_ANY
1841 indicates no restriction. */
1842 uint32_t out_group; /* Require matching entries to include this
1843 as an output group. A value of OFPG_ANY
1844 indicates no restriction. */
1845 uint8_t pad2[4]; /* Align to 64 bits. */
1846 uint64_t cookie; /* Require matching entries to contain this
1847 cookie value */
1848 uint64_t cookie_mask; /* Mask used to restrict the cookie bits that
1849 must match. A value of 0 indicates
1850 no restriction. */
1851 struct ofp_match match; /* Fields to match. Variable size. */
1852};
1853OFP_ASSERT(sizeof(struct ofp_aggregate_stats_request) == 40);
1854
1855/* Body of reply to OFPMP_AGGREGATE request. */
1856struct ofp_aggregate_stats_reply {
1857 uint64_t packet_count; /* Number of packets in flows. */
1858 uint64_t byte_count; /* Number of bytes in flows. */
1859 uint32_t flow_count; /* Number of flows. */
1860 uint8_t pad[4]; /* Align to 64 bits. */
1861};
1862OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
1863
1864/* Table Feature property types.
1865 * Low order bit cleared indicates a property for a regular Flow Entry.
1866 * Low order bit set indicates a property for the Table-Miss Flow Entry.
1867 */
1868enum ofp_table_feature_prop_type {
1869 OFPTFPT_INSTRUCTIONS = 0, /* Instructions property. */
1870 OFPTFPT_INSTRUCTIONS_MISS = 1, /* Instructions for table-miss. */
1871 OFPTFPT_NEXT_TABLES = 2, /* Next Table property. */
1872 OFPTFPT_NEXT_TABLES_MISS = 3, /* Next Table for table-miss. */
1873 OFPTFPT_WRITE_ACTIONS = 4, /* Write Actions property. */
1874 OFPTFPT_WRITE_ACTIONS_MISS = 5, /* Write Actions for table-miss. */
1875 OFPTFPT_APPLY_ACTIONS = 6, /* Apply Actions property. */
1876 OFPTFPT_APPLY_ACTIONS_MISS = 7, /* Apply Actions for table-miss. */
1877 OFPTFPT_MATCH = 8, /* Match property. */
1878 OFPTFPT_WILDCARDS = 10, /* Wildcards property. */
1879 OFPTFPT_WRITE_SETFIELD = 12, /* Write Set-Field property. */
1880 OFPTFPT_WRITE_SETFIELD_MISS = 13, /* Write Set-Field for table-miss. */
1881 OFPTFPT_APPLY_SETFIELD = 14, /* Apply Set-Field property. */
1882 OFPTFPT_APPLY_SETFIELD_MISS = 15, /* Apply Set-Field for table-miss. */
1883 OFPTFPT_EXPERIMENTER = 0xFFFE, /* Experimenter property. */
1884 OFPTFPT_EXPERIMENTER_MISS = 0xFFFF, /* Experimenter for table-miss. */
1885};
1886
1887/* Common header for all Table Feature Properties */
1888struct ofp_table_feature_prop_header {
1889 uint16_t type; /* One of OFPTFPT_*. */
1890 uint16_t length; /* Length in bytes of this property. */
1891};
1892OFP_ASSERT(sizeof(struct ofp_table_feature_prop_header) == 4);
1893
1894/* Instructions property */
1895struct ofp_table_feature_prop_instructions {
1896 uint16_t type; /* One of OFPTFPT_INSTRUCTIONS,
1897 OFPTFPT_INSTRUCTIONS_MISS. */
1898 uint16_t length; /* Length in bytes of this property. */
1899 /* Followed by:
1900 * - Exactly (length - 4) bytes containing the instruction ids, then
1901 * - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
1902 * bytes of all-zero bytes */
1903 struct ofp_instruction instruction_ids[0]; /* List of instructions */
1904};
1905OFP_ASSERT(sizeof(struct ofp_table_feature_prop_instructions) == 4);
1906
1907/* Next Tables property */
1908struct ofp_table_feature_prop_next_tables {
1909 uint16_t type; /* One of OFPTFPT_NEXT_TABLES,
1910 OFPTFPT_NEXT_TABLES_MISS. */
1911 uint16_t length; /* Length in bytes of this property. */
1912 /* Followed by:
1913 * - Exactly (length - 4) bytes containing the table_ids, then
1914 * - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
1915 * bytes of all-zero bytes */
1916 uint8_t next_table_ids[0];
1917};
1918OFP_ASSERT(sizeof(struct ofp_table_feature_prop_next_tables) == 4);
1919
1920/* Actions property */
1921struct ofp_table_feature_prop_actions {
1922 uint16_t type; /* One of OFPTFPT_WRITE_ACTIONS,
1923 OFPTFPT_WRITE_ACTIONS_MISS,
1924 OFPTFPT_APPLY_ACTIONS,
1925 OFPTFPT_APPLY_ACTIONS_MISS. */
1926 uint16_t length; /* Length in bytes of this property. */
1927 /* Followed by:
1928 * - Exactly (length - 4) bytes containing the action_ids, then
1929 * - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
1930 * bytes of all-zero bytes */
1931 struct ofp_action_header action_ids[0]; /* List of actions */
1932};
1933OFP_ASSERT(sizeof(struct ofp_table_feature_prop_actions) == 4);
1934
1935/* Match, Wildcard or Set-Field property */
1936struct ofp_table_feature_prop_oxm {
1937 uint16_t type; /* One of OFPTFPT_MATCH,
1938 OFPTFPT_WILDCARDS,
1939 OFPTFPT_WRITE_SETFIELD,
1940 OFPTFPT_WRITE_SETFIELD_MISS,
1941 OFPTFPT_APPLY_SETFIELD,
1942 OFPTFPT_APPLY_SETFIELD_MISS. */
1943 uint16_t length; /* Length in bytes of this property. */
1944 /* Followed by:
1945 * - Exactly (length - 4) bytes containing the oxm_ids, then
1946 * - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
1947 * bytes of all-zero bytes */
1948 uint32_t oxm_ids[0]; /* Array of OXM headers */
1949};
1950OFP_ASSERT(sizeof(struct ofp_table_feature_prop_oxm) == 4);
1951
1952/* Experimenter table feature property */
1953struct ofp_table_feature_prop_experimenter {
1954 uint16_t type; /* One of OFPTFPT_EXPERIMENTER,
1955 OFPTFPT_EXPERIMENTER_MISS. */
1956 uint16_t length; /* Length in bytes of this property. */
1957 uint32_t experimenter; /* Experimenter ID which takes the same
1958 form as in struct
1959 ofp_experimenter_header. */
1960 uint32_t exp_type; /* Experimenter defined. */
1961 /* Followed by:
1962 * - Exactly (length - 12) bytes containing the experimenter data, then
1963 * - Exactly (length + 7)/8*8 - (length) (between 0 and 7)
1964 * bytes of all-zero bytes */
1965 uint32_t experimenter_data[0];
1966};
1967OFP_ASSERT(sizeof(struct ofp_table_feature_prop_experimenter) == 12);
1968
1969/* Body for ofp_multipart_request of type OFPMP_TABLE_FEATURES./
1970 * Body of reply to OFPMP_TABLE_FEATURES request. */
1971struct ofp_table_features {
1972 uint16_t length; /* Length is padded to 64 bits. */
1973 uint8_t table_id; /* Identifier of table. Lower numbered tables
1974 are consulted first. */
1975 uint8_t pad[5]; /* Align to 64-bits. */
1976 char name[OFP_MAX_TABLE_NAME_LEN];
1977 uint64_t metadata_match; /* Bits of metadata table can match. */
1978 uint64_t metadata_write; /* Bits of metadata table can write. */
1979 uint32_t config; /* Bitmap of OFPTC_* values */
1980 uint32_t max_entries; /* Max number of entries supported. */
1981
1982 /* Table Feature Property list */
1983 struct ofp_table_feature_prop_header properties[0];
1984};
1985OFP_ASSERT(sizeof(struct ofp_table_features) == 64);
1986
1987/* Body of reply to OFPMP_TABLE request. */
1988struct ofp_table_stats {
1989 uint8_t table_id; /* Identifier of table. Lower numbered tables
1990 are consulted first. */
1991 uint8_t pad[3]; /* Align to 32-bits. */
1992 uint32_t active_count; /* Number of active entries. */
1993 uint64_t lookup_count; /* Number of packets looked up in table. */
1994 uint64_t matched_count; /* Number of packets that hit table. */
1995};
1996OFP_ASSERT(sizeof(struct ofp_table_stats) == 24);
1997
1998/* Body for ofp_multipart_request of type OFPMP_PORT. */
1999struct ofp_port_stats_request {
2000 uint32_t port_no; /* OFPMP_PORT message must request statistics
2001 * either for a single port (specified in
2002 * port_no) or for all ports (if port_no ==
2003 * OFPP_ANY). */
2004 uint8_t pad[4];
2005};
2006OFP_ASSERT(sizeof(struct ofp_port_stats_request) == 8);
2007
2008/* Body of reply to OFPMP_PORT request. If a counter is unsupported, set
2009 * the field to all ones. */
2010struct ofp_port_stats {
2011 uint32_t port_no;
2012 uint8_t pad[4]; /* Align to 64-bits. */
2013 uint64_t rx_packets; /* Number of received packets. */
2014 uint64_t tx_packets; /* Number of transmitted packets. */
2015 uint64_t rx_bytes; /* Number of received bytes. */
2016 uint64_t tx_bytes; /* Number of transmitted bytes. */
2017 uint64_t rx_dropped; /* Number of packets dropped by RX. */
2018 uint64_t tx_dropped; /* Number of packets dropped by TX. */
2019 uint64_t rx_errors; /* Number of receive errors. This is a super-set
2020 of more specific receive errors and should be
2021 greater than or equal to the sum of all
2022 rx_*_err values. */
2023 uint64_t tx_errors; /* Number of transmit errors. This is a super-set
2024 of more specific transmit errors and should be
2025 greater than or equal to the sum of all
2026 tx_*_err values (none currently defined.) */
2027 uint64_t rx_frame_err; /* Number of frame alignment errors. */
2028 uint64_t rx_over_err; /* Number of packets with RX overrun. */
2029 uint64_t rx_crc_err; /* Number of CRC errors. */
2030 uint64_t collisions; /* Number of collisions. */
2031 uint32_t duration_sec; /* Time port has been alive in seconds. */
2032 uint32_t duration_nsec; /* Time port has been alive in nanoseconds beyond
2033 duration_sec. */
2034};
2035OFP_ASSERT(sizeof(struct ofp_port_stats) == 112);
2036
2037/* Body of OFPMP_GROUP request. */
2038struct ofp_group_stats_request {
2039 uint32_t group_id; /* All groups if OFPG_ALL. */
2040 uint8_t pad[4]; /* Align to 64 bits. */
2041};
2042OFP_ASSERT(sizeof(struct ofp_group_stats_request) == 8);
2043
2044/* Used in group stats replies. */
2045struct ofp_bucket_counter {
2046 uint64_t packet_count; /* Number of packets processed by bucket. */
2047 uint64_t byte_count; /* Number of bytes processed by bucket. */
2048};
2049OFP_ASSERT(sizeof(struct ofp_bucket_counter) == 16);
2050
2051/* Body of reply to OFPMP_GROUP request. */
2052struct ofp_group_stats {
2053 uint16_t length; /* Length of this entry. */
2054 uint8_t pad[2]; /* Align to 64 bits. */
2055 uint32_t group_id; /* Group identifier. */
2056 uint32_t ref_count; /* Number of flows or groups that directly forward
2057 to this group. */
2058 uint8_t pad2[4]; /* Align to 64 bits. */
2059 uint64_t packet_count; /* Number of packets processed by group. */
2060 uint64_t byte_count; /* Number of bytes processed by group. */
2061 uint32_t duration_sec; /* Time group has been alive in seconds. */
2062 uint32_t duration_nsec; /* Time group has been alive in nanoseconds beyond
2063 duration_sec. */
2064 struct ofp_bucket_counter bucket_stats[0];
2065};
2066OFP_ASSERT(sizeof(struct ofp_group_stats) == 40);
2067
2068/* Body of reply to OFPMP_GROUP_DESC request. */
2069struct ofp_group_desc_stats {
2070 uint16_t length; /* Length of this entry. */
2071 uint8_t type; /* One of OFPGT_*. */
2072 uint8_t pad; /* Pad to 64 bits. */
2073 uint32_t group_id; /* Group identifier. */
2074 struct ofp_bucket buckets[0];
2075};
2076OFP_ASSERT(sizeof(struct ofp_group_desc_stats) == 8);
2077
2078/* Group configuration flags */
2079enum ofp_group_capabilities {
2080 OFPGFC_SELECT_WEIGHT = 1 << 0, /* Support weight for select groups */
2081 OFPGFC_SELECT_LIVENESS = 1 << 1, /* Support liveness for select groups */
2082 OFPGFC_CHAINING = 1 << 2, /* Support chaining groups */
2083 OFPGFC_CHAINING_CHECKS = 1 << 3, /* Check chaining for loops and delete */
2084};
2085
2086/* Body of reply to OFPMP_GROUP_FEATURES request. Group features. */
2087struct ofp_group_features {
2088 uint32_t types; /* Bitmap of OFPGT_* values supported. */
2089 uint32_t capabilities; /* Bitmap of OFPGFC_* capability supported. */
2090 uint32_t max_groups[4]; /* Maximum number of groups for each type. */
2091 uint32_t actions[4]; /* Bitmaps of OFPAT_* that are supported. */
2092};
2093OFP_ASSERT(sizeof(struct ofp_group_features) == 40);
2094
2095/* Body of OFPMP_METER and OFPMP_METER_CONFIG requests. */
2096struct ofp_meter_multipart_request {
2097 uint32_t meter_id; /* Meter instance, or OFPM_ALL. */
2098 uint8_t pad[4]; /* Align to 64 bits. */
2099};
2100OFP_ASSERT(sizeof(struct ofp_meter_multipart_request) == 8);
2101
2102/* Statistics for each meter band */
2103struct ofp_meter_band_stats {
2104 uint64_t packet_band_count; /* Number of packets in band. */
2105 uint64_t byte_band_count; /* Number of bytes in band. */
2106};
2107OFP_ASSERT(sizeof(struct ofp_meter_band_stats) == 16);
2108
2109/* Body of reply to OFPMP_METER request. Meter statistics. */
2110struct ofp_meter_stats {
2111 uint32_t meter_id; /* Meter instance. */
2112 uint16_t len; /* Length in bytes of this stats. */
2113 uint8_t pad[6];
2114 uint32_t flow_count; /* Number of flows bound to meter. */
2115 uint64_t packet_in_count; /* Number of packets in input. */
2116 uint64_t byte_in_count; /* Number of bytes in input. */
2117 uint32_t duration_sec; /* Time meter has been alive in seconds. */
2118 uint32_t duration_nsec; /* Time meter has been alive in nanoseconds beyond
2119 duration_sec. */
2120 struct ofp_meter_band_stats band_stats[0]; /* The band_stats length is
2121 inferred from the length field. */
2122};
2123OFP_ASSERT(sizeof(struct ofp_meter_stats) == 40);
2124
2125/* Body of reply to OFPMP_METER_CONFIG request. Meter configuration. */
2126struct ofp_meter_config {
2127 uint16_t length; /* Length of this entry. */
2128 uint16_t flags; /* All OFPMC_* that apply. */
2129 uint32_t meter_id; /* Meter instance. */
2130 struct ofp_meter_band_header bands[0]; /* The bands length is
2131 inferred from the length field. */
2132};
2133OFP_ASSERT(sizeof(struct ofp_meter_config) == 8);
2134
2135/* Body of reply to OFPMP_METER_FEATURES request. Meter features. */
2136struct ofp_meter_features {
2137 uint32_t max_meter; /* Maximum number of meters. */
2138 uint32_t band_types; /* Bitmaps of OFPMBT_* values supported. */
2139 uint32_t capabilities; /* Bitmaps of "ofp_meter_flags". */
2140 uint8_t max_bands; /* Maximum bands per meters */
2141 uint8_t max_color; /* Maximum color value */
2142 uint8_t pad[2];
2143};
2144OFP_ASSERT(sizeof(struct ofp_meter_features) == 16);
2145
2146/* Body for ofp_multipart_request/reply of type OFPMP_EXPERIMENTER. */
2147struct ofp_experimenter_multipart_header {
2148 uint32_t experimenter; /* Experimenter ID which takes the same form
2149 as in struct ofp_experimenter_header. */
2150 uint32_t exp_type; /* Experimenter defined. */
2151 /* Experimenter-defined arbitrary additional data. */
2152};
2153OFP_ASSERT(sizeof(struct ofp_experimenter_multipart_header) == 8);
2154
2155/* Experimenter extension. */
2156struct ofp_experimenter_header {
2157 struct ofp_header header; /* Type OFPT_EXPERIMENTER. */
2158 uint32_t experimenter; /* Experimenter ID:
2159 * - MSB 0: low-order bytes are IEEE OUI.
2160 * - MSB != 0: defined by ONF. */
2161 uint32_t exp_type; /* Experimenter defined. */
2162 /* Experimenter-defined arbitrary additional data. */
2163};
2164OFP_ASSERT(sizeof(struct ofp_experimenter_header) == 16);
2165
2166/* All ones is used to indicate all queues in a port (for stats retrieval). */
2167#define OFPQ_ALL 0xffffffff
2168
2169/* Min rate > 1000 means not configured. */
2170#define OFPQ_MIN_RATE_UNCFG 0xffff
2171
2172/* Max rate > 1000 means not configured. */
2173#define OFPQ_MAX_RATE_UNCFG 0xffff
2174
2175enum ofp_queue_properties {
2176 OFPQT_MIN_RATE = 1, /* Minimum datarate guaranteed. */
2177 OFPQT_MAX_RATE = 2, /* Maximum datarate. */
2178 OFPQT_EXPERIMENTER = 0xffff /* Experimenter defined property. */
2179};
2180
2181/* Common description for a queue. */
2182struct ofp_queue_prop_header {
2183 uint16_t property; /* One of OFPQT_. */
2184 uint16_t len; /* Length of property, including this header. */
2185 uint8_t pad[4]; /* 64-bit alignemnt. */
2186};
2187OFP_ASSERT(sizeof(struct ofp_queue_prop_header) == 8);
2188
2189/* Min-Rate queue property description. */
2190struct ofp_queue_prop_min_rate {
2191 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MIN, len: 16. */
2192 uint16_t rate; /* In 1/10 of a percent; >1000 -> disabled. */
2193 uint8_t pad[6]; /* 64-bit alignment */
2194};
2195OFP_ASSERT(sizeof(struct ofp_queue_prop_min_rate) == 16);
2196
2197/* Max-Rate queue property description. */
2198struct ofp_queue_prop_max_rate {
2199 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MAX, len: 16. */
2200 uint16_t rate; /* In 1/10 of a percent; >1000 -> disabled. */
2201 uint8_t pad[6]; /* 64-bit alignment */
2202};
2203OFP_ASSERT(sizeof(struct ofp_queue_prop_max_rate) == 16);
2204
2205/* Experimenter queue property description. */
2206struct ofp_queue_prop_experimenter {
2207 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_EXPERIMENTER, len: 16. */
2208 uint32_t experimenter; /* Experimenter ID which takes the same
2209 form as in struct
2210 ofp_experimenter_header. */
2211 uint8_t pad[4]; /* 64-bit alignment */
2212 uint8_t data[0]; /* Experimenter defined data. */
2213};
2214OFP_ASSERT(sizeof(struct ofp_queue_prop_experimenter) == 16);
2215
2216/* Full description for a queue. */
2217struct ofp_packet_queue {
2218 uint32_t queue_id; /* id for the specific queue. */
2219 uint32_t port; /* Port this queue is attached to. */
2220 uint16_t len; /* Length in bytes of this queue desc. */
2221 uint8_t pad[6]; /* 64-bit alignment. */
2222 struct ofp_queue_prop_header properties[0]; /* List of properties. */
2223};
2224OFP_ASSERT(sizeof(struct ofp_packet_queue) == 16);
2225
2226/* Query for port queue configuration. */
2227struct ofp_queue_get_config_request {
2228 struct ofp_header header;
2229 uint32_t port; /* Port to be queried. Should refer
2230 to a valid physical port (i.e. < OFPP_MAX),
2231 or OFPP_ANY to request all configured
2232 queues.*/
2233 uint8_t pad[4];
2234};
2235OFP_ASSERT(sizeof(struct ofp_queue_get_config_request) == 16);
2236
2237/* Queue configuration for a given port. */
2238struct ofp_queue_get_config_reply {
2239 struct ofp_header header;
2240 uint32_t port;
2241 uint8_t pad[4];
2242 struct ofp_packet_queue queues[0]; /* List of configured queues. */
2243};
2244OFP_ASSERT(sizeof(struct ofp_queue_get_config_reply) == 16);
2245
2246/* OFPAT_SET_QUEUE action struct: send packets to given queue on port. */
2247struct ofp_action_set_queue {
2248 uint16_t type; /* OFPAT_SET_QUEUE. */
2249 uint16_t len; /* Len is 8. */
2250 uint32_t queue_id; /* Queue id for the packets. */
2251};
2252OFP_ASSERT(sizeof(struct ofp_action_set_queue) == 8);
2253
2254struct ofp_queue_stats_request {
2255 uint32_t port_no; /* All ports if OFPP_ANY. */
2256 uint32_t queue_id; /* All queues if OFPQ_ALL. */
2257};
2258OFP_ASSERT(sizeof(struct ofp_queue_stats_request) == 8);
2259
2260struct ofp_queue_stats {
2261 uint32_t port_no;
2262 uint32_t queue_id; /* Queue i.d */
2263 uint64_t tx_bytes; /* Number of transmitted bytes. */
2264 uint64_t tx_packets; /* Number of transmitted packets. */
2265 uint64_t tx_errors; /* Number of packets dropped due to overrun. */
2266 uint32_t duration_sec; /* Time queue has been alive in seconds. */
2267 uint32_t duration_nsec; /* Time queue has been alive in nanoseconds beyond
2268 duration_sec. */
2269};
2270OFP_ASSERT(sizeof(struct ofp_queue_stats) == 40);
2271
2272/* Configures the "role" of the sending controller. The default role is:
2273 *
2274 * - Equal (NX_ROLE_EQUAL), which allows the controller access to all
2275 * OpenFlow features. All controllers have equal responsibility.
2276 *
2277 * The other possible roles are a related pair:
2278 *
2279 * - Master (NX_ROLE_MASTER) is equivalent to Equal, except that there may
2280 * be at most one Master controller at a time: when a controller
2281 * configures itself as Master, any existing Master is demoted to the
2282 * Slave role.
2283 *
2284 * - Slave (NX_ROLE_SLAVE) allows the controller read-only access to
2285 * OpenFlow features. In particular attempts to modify the flow table
2286 * will be rejected with an OFPBRC_EPERM error.
2287 *
2288 * Slave controllers do not receive OFPT_PACKET_IN or OFPT_FLOW_REMOVED
2289 * messages, but they do receive OFPT_PORT_STATUS messages.
2290 */
2291
2292/* Controller roles. */
2293enum ofp_controller_role {
2294 OFPCR_ROLE_NOCHANGE = 0, /* Don't change current role. */
2295 OFPCR_ROLE_EQUAL = 1, /* Default role, full access. */
2296 OFPCR_ROLE_MASTER = 2, /* Full access, at most one master. */
2297 OFPCR_ROLE_SLAVE = 3, /* Read-only access. */
2298};
2299
2300/* Role request and reply message. */
2301struct ofp_role_request {
2302 struct ofp_header header; /* Type OFPT_ROLE_REQUEST/OFPT_ROLE_REPLY. */
2303 uint32_t role; /* One of NX_ROLE_*. */
2304 uint8_t pad[4]; /* Align to 64 bits. */
2305 uint64_t generation_id; /* Master Election Generation Id */
2306};
2307OFP_ASSERT(sizeof(struct ofp_role_request) == 24);
2308
2309/* Asynchronous message configuration. */
2310struct ofp_async_config {
2311 struct ofp_header header; /* OFPT_GET_ASYNC_REPLY or OFPT_SET_ASYNC. */
2312 uint32_t packet_in_mask[2]; /* Bitmasks of OFPR_* values. */
2313 uint32_t port_status_mask[2]; /* Bitmasks of OFPPR_* values. */
2314 uint32_t flow_removed_mask[2];/* Bitmasks of OFPRR_* values. */
2315};
2316OFP_ASSERT(sizeof(struct ofp_async_config) == 32);
2317
2318#endif /* openflow/openflow.h */