blob: 3e26ea5f5d0abb96094edd860300fffde8a22244 [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 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 * Experimental versions released: 0x81 -- 0x99
66 */
67/* The most significant bit being set in the version field indicates an
68 * experimental OpenFlow version.
69 */
70#define OFP_VERSION 0x03
71
72#define OFP_MAX_TABLE_NAME_LEN 32
73#define OFP_MAX_PORT_NAME_LEN 16
74
75#define OFP_TCP_PORT 6633
76#define OFP_SSL_PORT 6633
77
78#define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
79
80/* Port numbering. Ports are numbered starting from 1. */
81enum ofp_port_no {
82 /* Maximum number of physical and logical switch ports. */
83 OFPP_MAX = 0xffffff00,
84
85 /* Reserved OpenFlow Port (fake output "ports"). */
86 OFPP_IN_PORT = 0xfffffff8, /* Send the packet out the input port. This
87 reserved port must be explicitly used
88 in order to send back out of the input
89 port. */
90 OFPP_TABLE = 0xfffffff9, /* Submit the packet to the first flow table
91 NB: This destination port can only be
92 used in packet-out messages. */
93 OFPP_NORMAL = 0xfffffffa, /* Process with normal L2/L3 switching. */
94 OFPP_FLOOD = 0xfffffffb, /* All physical ports in VLAN, except input
95 port and those blocked or link down. */
96 OFPP_ALL = 0xfffffffc, /* All physical ports except input port. */
97 OFPP_CONTROLLER = 0xfffffffd, /* Send to controller. */
98 OFPP_LOCAL = 0xfffffffe, /* Local openflow "port". */
99 OFPP_ANY = 0xffffffff /* Wildcard port used only for flow mod
100 (delete) and flow stats requests. Selects
101 all flows regardless of output port
102 (including flows with no output port). */
103};
104
105enum ofp_type {
106 /* Immutable messages. */
107 OFPT_HELLO = 0, /* Symmetric message */
108 OFPT_ERROR = 1, /* Symmetric message */
109 OFPT_ECHO_REQUEST = 2, /* Symmetric message */
110 OFPT_ECHO_REPLY = 3, /* Symmetric message */
111 OFPT_EXPERIMENTER = 4, /* Symmetric message */
112
113 /* Switch configuration messages. */
114 OFPT_FEATURES_REQUEST = 5, /* Controller/switch message */
115 OFPT_FEATURES_REPLY = 6, /* Controller/switch message */
116 OFPT_GET_CONFIG_REQUEST = 7, /* Controller/switch message */
117 OFPT_GET_CONFIG_REPLY = 8, /* Controller/switch message */
118 OFPT_SET_CONFIG = 9, /* Controller/switch message */
119
120 /* Asynchronous messages. */
121 OFPT_PACKET_IN = 10, /* Async message */
122 OFPT_FLOW_REMOVED = 11, /* Async message */
123 OFPT_PORT_STATUS = 12, /* Async message */
124
125 /* Controller command messages. */
126 OFPT_PACKET_OUT = 13, /* Controller/switch message */
127 OFPT_FLOW_MOD = 14, /* Controller/switch message */
128 OFPT_GROUP_MOD = 15, /* Controller/switch message */
129 OFPT_PORT_MOD = 16, /* Controller/switch message */
130 OFPT_TABLE_MOD = 17, /* Controller/switch message */
131
132 /* Statistics messages. */
133 OFPT_STATS_REQUEST = 18, /* Controller/switch message */
134 OFPT_STATS_REPLY = 19, /* Controller/switch message */
135
136 /* Barrier messages. */
137 OFPT_BARRIER_REQUEST = 20, /* Controller/switch message */
138 OFPT_BARRIER_REPLY = 21, /* Controller/switch message */
139
140 /* Queue Configuration messages. */
141 OFPT_QUEUE_GET_CONFIG_REQUEST = 22, /* Controller/switch message */
142 OFPT_QUEUE_GET_CONFIG_REPLY = 23, /* Controller/switch message */
143
144 /* Controller role change request messages. */
145 OFPT_ROLE_REQUEST = 24, /* Controller/switch message */
146 OFPT_ROLE_REPLY = 25, /* Controller/switch message */
147};
148
149/* Header on all OpenFlow packets. */
150struct ofp_header {
151 uint8_t version; /* OFP_VERSION. */
152 uint8_t type; /* One of the OFPT_ constants. */
153 uint16_t length; /* Length including this ofp_header. */
154 uint32_t xid; /* Transaction id associated with this packet.
155 Replies use the same id as was in the request
156 to facilitate pairing. */
157};
158OFP_ASSERT(sizeof(struct ofp_header) == 8);
159
160/* OFPT_HELLO. This message has an empty body, but implementations must
161 * ignore any data included in the body, to allow for future extensions. */
162struct ofp_hello {
163 struct ofp_header header;
164};
165
166#define OFP_DEFAULT_MISS_SEND_LEN 128
167
168enum ofp_config_flags {
169 /* Handling of IP fragments. */
170 OFPC_FRAG_NORMAL = 0, /* No special handling for fragments. */
171 OFPC_FRAG_DROP = 1 << 0, /* Drop fragments. */
172 OFPC_FRAG_REASM = 1 << 1, /* Reassemble (only if OFPC_IP_REASM set). */
173 OFPC_FRAG_MASK = 3,
174
175 /* TTL processing - applicable for IP and MPLS packets */
176 OFPC_INVALID_TTL_TO_CONTROLLER = 1 << 2, /* Send packets with invalid TTL
177 to the controller */
178};
179
180/* Switch configuration. */
181struct ofp_switch_config {
182 struct ofp_header header;
183 uint16_t flags; /* OFPC_* flags. */
184 uint16_t miss_send_len; /* Max bytes of new flow that datapath
185 should send to the controller. See
186 ofp_controller_max_len for valid values.
187 */
188};
189OFP_ASSERT(sizeof(struct ofp_switch_config) == 12);
190
191/* Flags to indicate behavior of the flow table for unmatched packets.
192 These flags are used in ofp_table_stats messages to describe the current
193 configuration and in ofp_table_mod messages to configure table behavior. */
194enum ofp_table_config {
195 OFPTC_TABLE_MISS_CONTROLLER = 0, /* Send to controller. */
196 OFPTC_TABLE_MISS_CONTINUE = 1 << 0, /* Continue to the next table in the
197 pipeline (OpenFlow 1.0
198 behavior). */
199 OFPTC_TABLE_MISS_DROP = 1 << 1, /* Drop the packet. */
200 OFPTC_TABLE_MISS_MASK = 3
201};
202
203/* Table numbering. Tables can use any number up to OFPT_MAX. */
204enum ofp_table {
205 /* Last usable table number. */
206 OFPTT_MAX = 0xfe,
207
208 /* Fake tables. */
209 OFPTT_ALL = 0xff /* Wildcard table used for table config,
210 flow stats and flow deletes. */
211};
212
213
214/* Configure/Modify behavior of a flow table */
215struct ofp_table_mod {
216 struct ofp_header header;
217 uint8_t table_id; /* ID of the table, OFPTT_ALL indicates all tables */
218 uint8_t pad[3]; /* Pad to 32 bits */
219 uint32_t config; /* Bitmap of OFPTC_* flags */
220};
221OFP_ASSERT(sizeof(struct ofp_table_mod) == 16);
222
223/* Capabilities supported by the datapath. */
224enum ofp_capabilities {
225 OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
226 OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
227 OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
228 OFPC_GROUP_STATS = 1 << 3, /* Group statistics. */
229 OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
230 OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */
231 OFPC_PORT_BLOCKED = 1 << 8 /* Switch will block looping ports. */
232};
233
234/* Flags to indicate behavior of the physical port. These flags are
235 * used in ofp_port to describe the current configuration. They are
236 * used in the ofp_port_mod message to configure the port's behavior.
237 */
238enum ofp_port_config {
239 OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
240
241 OFPPC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
242 OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
243 OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
244};
245
246/* Current state of the physical port. These are not configurable from
247 * the controller.
248 */
249enum ofp_port_state {
250 OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
251 OFPPS_BLOCKED = 1 << 1, /* Port is blocked */
252 OFPPS_LIVE = 1 << 2, /* Live for Fast Failover Group. */
253};
254
255/* Features of ports available in a datapath. */
256enum ofp_port_features {
257 OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
258 OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
259 OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
260 OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
261 OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
262 OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
263 OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
264 OFPPF_40GB_FD = 1 << 7, /* 40 Gb full-duplex rate support. */
265 OFPPF_100GB_FD = 1 << 8, /* 100 Gb full-duplex rate support. */
266 OFPPF_1TB_FD = 1 << 9, /* 1 Tb full-duplex rate support. */
267 OFPPF_OTHER = 1 << 10, /* Other rate, not in the list. */
268
269 OFPPF_COPPER = 1 << 11, /* Copper medium. */
270 OFPPF_FIBER = 1 << 12, /* Fiber medium. */
271 OFPPF_AUTONEG = 1 << 13, /* Auto-negotiation. */
272 OFPPF_PAUSE = 1 << 14, /* Pause. */
273 OFPPF_PAUSE_ASYM = 1 << 15 /* Asymmetric pause. */
274};
275
276/* Description of a port */
277struct ofp_port {
278 uint32_t port_no;
279 uint8_t pad[4];
280 uint8_t hw_addr[OFP_ETH_ALEN];
281 uint8_t pad2[2]; /* Align to 64 bits. */
282 char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
283
284 uint32_t config; /* Bitmap of OFPPC_* flags. */
285 uint32_t state; /* Bitmap of OFPPS_* flags. */
286
287 /* Bitmaps of OFPPF_* that describe features. All bits zeroed if
288 * unsupported or unavailable. */
289 uint32_t curr; /* Current features. */
290 uint32_t advertised; /* Features being advertised by the port. */
291 uint32_t supported; /* Features supported by the port. */
292 uint32_t peer; /* Features advertised by peer. */
293
294 uint32_t curr_speed; /* Current port bitrate in kbps. */
295 uint32_t max_speed; /* Max port bitrate in kbps */
296};
297OFP_ASSERT(sizeof(struct ofp_port) == 64);
298
299/* Switch features. */
300struct ofp_switch_features {
301 struct ofp_header header;
302 uint64_t datapath_id; /* Datapath unique ID. The lower 48-bits are for
303 a MAC address, while the upper 16-bits are
304 implementer-defined. */
305
306 uint32_t n_buffers; /* Max packets buffered at once. */
307
308 uint8_t n_tables; /* Number of tables supported by datapath. */
309 uint8_t pad[3]; /* Align to 64-bits. */
310
311 /* Features. */
312 uint32_t capabilities; /* Bitmap of support "ofp_capabilities". */
313 uint32_t reserved;
314
315 /* Port info.*/
316 struct ofp_port ports[0]; /* Port definitions. The number of ports
317 is inferred from the length field in
318 the header. */
319};
320OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
321
322/* What changed about the physical port */
323enum ofp_port_reason {
324 OFPPR_ADD = 0, /* The port was added. */
325 OFPPR_DELETE = 1, /* The port was removed. */
326 OFPPR_MODIFY = 2, /* Some attribute of the port has changed. */
327};
328
329/* A physical port has changed in the datapath */
330struct ofp_port_status {
331 struct ofp_header header;
332 uint8_t reason; /* One of OFPPR_*. */
333 uint8_t pad[7]; /* Align to 64-bits. */
334 struct ofp_port desc;
335};
336OFP_ASSERT(sizeof(struct ofp_port_status) == 80);
337
338/* Modify behavior of the physical port */
339struct ofp_port_mod {
340 struct ofp_header header;
341 uint32_t port_no;
342 uint8_t pad[4];
343 uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
344 configurable. This is used to
345 sanity-check the request, so it must
346 be the same as returned in an
347 ofp_port struct. */
348 uint8_t pad2[2]; /* Pad to 64 bits. */
349 uint32_t config; /* Bitmap of OFPPC_* flags. */
350 uint32_t mask; /* Bitmap of OFPPC_* flags to be changed. */
351
352 uint32_t advertise; /* Bitmap of OFPPF_*. Zero all bits to prevent
353 any action taking place. */
354 uint8_t pad3[4]; /* Pad to 64 bits. */
355};
356OFP_ASSERT(sizeof(struct ofp_port_mod) == 40);
357
358/* ## -------------------------- ## */
359/* ## OpenFlow Extensible Match. ## */
360/* ## -------------------------- ## */
361
362/* The match type indicates the match structure (set of fields that compose the
363 * match) in use. The match type is placed in the type field at the beginning
364 * of all match structures. The "OpenFlow Extensible Match" type corresponds
365 * to OXM TLV format described below and must be supported by all OpenFlow
366 * switches. Extensions that define other match types may be published on the
367 * ONF wiki. Support for extensions is optional.
368 */
369enum ofp_match_type {
370 OFPMT_STANDARD = 0, /* Deprecated. */
371 OFPMT_OXM = 1, /* OpenFlow Extensible Match */
372};
373
374/* Fields to match against flows */
375struct ofp_match {
376 uint16_t type; /* One of OFPMT_* */
377 uint16_t length; /* Length of ofp_match (excluding padding) */
378 /* Followed by:
379 * - Exactly (length - 4) (possibly 0) bytes containing OXM TLVs, then
380 * - Exactly ((length + 7)/8*8 - length) (between 0 and 7) bytes of
381 * all-zero bytes
382 * In summary, ofp_match is padded as needed, to make its overall size
383 * a multiple of 8, to preserve alignement in structures using it.
384 */
385 uint8_t oxm_fields[4]; /* OXMs start here - Make compiler happy */
386};
387OFP_ASSERT(sizeof(struct ofp_match) == 8);
388
389/* Components of a OXM TLV header. */
390#define OXM_HEADER__(CLASS, FIELD, HASMASK, LENGTH) \
391 (((CLASS) << 16) | ((FIELD) << 9) | ((HASMASK) << 8) | (LENGTH))
392#define OXM_HEADER(CLASS, FIELD, LENGTH) \
393 OXM_HEADER__(CLASS, FIELD, 0, LENGTH)
394#define OXM_HEADER_W(CLASS, FIELD, LENGTH) \
395 OXM_HEADER__(CLASS, FIELD, 1, (LENGTH) * 2)
396#define OXM_CLASS(HEADER) ((HEADER) >> 16)
397#define OXM_FIELD(HEADER) (((HEADER) >> 9) & 0x7f)
398#define OXM_TYPE(HEADER) (((HEADER) >> 9) & 0x7fffff)
399#define OXM_HASMASK(HEADER) (((HEADER) >> 8) & 1)
400#define OXM_LENGTH(HEADER) ((HEADER) & 0xff)
401
402#define OXM_MAKE_WILD_HEADER(HEADER) \
403 OXM_HEADER_W(OXM_CLASS(HEADER), OXM_FIELD(HEADER), OXM_LENGTH(HEADER))
404
405/* OXM Class IDs.
406 * The high order bit differentiate reserved classes from member classes.
407 * Classes 0x0000 to 0x7FFF are member classes, allocated by ONF.
408 * Classes 0x8000 to 0xFFFE are reserved classes, reserved for standardisation.
409 */
410enum ofp_oxm_class {
411 OFPXMC_NXM_0 = 0x0000, /* Backward compatibility with NXM */
412 OFPXMC_NXM_1 = 0x0001, /* Backward compatibility with NXM */
413 OFPXMC_OPENFLOW_BASIC = 0x8000, /* Basic class for OpenFlow */
414 OFPXMC_EXPERIMENTER = 0xFFFF, /* Experimenter class */
415};
416
417/* OXM Flow match field types for OpenFlow basic class. */
418enum oxm_ofb_match_fields {
419 OFPXMT_OFB_IN_PORT = 0, /* Switch input port. */
420 OFPXMT_OFB_IN_PHY_PORT = 1, /* Switch physical input port. */
421 OFPXMT_OFB_METADATA = 2, /* Metadata passed between tables. */
422 OFPXMT_OFB_ETH_DST = 3, /* Ethernet destination address. */
423 OFPXMT_OFB_ETH_SRC = 4, /* Ethernet source address. */
424 OFPXMT_OFB_ETH_TYPE = 5, /* Ethernet frame type. */
425 OFPXMT_OFB_VLAN_VID = 6, /* VLAN id. */
426 OFPXMT_OFB_VLAN_PCP = 7, /* VLAN priority. */
427 OFPXMT_OFB_IP_DSCP = 8, /* IP DSCP (6 bits in ToS field). */
428 OFPXMT_OFB_IP_ECN = 9, /* IP ECN (2 bits in ToS field). */
429 OFPXMT_OFB_IP_PROTO = 10, /* IP protocol. */
430 OFPXMT_OFB_IPV4_SRC = 11, /* IPv4 source address. */
431 OFPXMT_OFB_IPV4_DST = 12, /* IPv4 destination address. */
432 OFPXMT_OFB_TCP_SRC = 13, /* TCP source port. */
433 OFPXMT_OFB_TCP_DST = 14, /* TCP destination port. */
434 OFPXMT_OFB_UDP_SRC = 15, /* UDP source port. */
435 OFPXMT_OFB_UDP_DST = 16, /* UDP destination port. */
436 OFPXMT_OFB_SCTP_SRC = 17, /* SCTP source port. */
437 OFPXMT_OFB_SCTP_DST = 18, /* SCTP destination port. */
438 OFPXMT_OFB_ICMPV4_TYPE = 19, /* ICMP type. */
439 OFPXMT_OFB_ICMPV4_CODE = 20, /* ICMP code. */
440 OFPXMT_OFB_ARP_OP = 21, /* ARP opcode. */
441 OFPXMT_OFB_ARP_SPA = 22, /* ARP source IPv4 address. */
442 OFPXMT_OFB_ARP_TPA = 23, /* ARP target IPv4 address. */
443 OFPXMT_OFB_ARP_SHA = 24, /* ARP source hardware address. */
444 OFPXMT_OFB_ARP_THA = 25, /* ARP target hardware address. */
445 OFPXMT_OFB_IPV6_SRC = 26, /* IPv6 source address. */
446 OFPXMT_OFB_IPV6_DST = 27, /* IPv6 destination address. */
447 OFPXMT_OFB_IPV6_FLABEL = 28, /* IPv6 Flow Label */
448 OFPXMT_OFB_ICMPV6_TYPE = 29, /* ICMPv6 type. */
449 OFPXMT_OFB_ICMPV6_CODE = 30, /* ICMPv6 code. */
450 OFPXMT_OFB_IPV6_ND_TARGET = 31, /* Target address for ND. */
451 OFPXMT_OFB_IPV6_ND_SLL = 32, /* Source link-layer for ND. */
452 OFPXMT_OFB_IPV6_ND_TLL = 33, /* Target link-layer for ND. */
453 OFPXMT_OFB_MPLS_LABEL = 34, /* MPLS label. */
454 OFPXMT_OFB_MPLS_TC = 35, /* MPLS TC. */
455};
456
457#define OFPXMT_OFB_ALL ((UINT64_C(1) << 36) - 1)
458
459/* OpenFlow port on which the packet was received.
460 * May be a physical port, a logical port, or the reserved port OFPP_LOCAL
461 *
462 * Prereqs: None.
463 *
464 * Format: 32-bit integer in network byte order.
465 *
466 * Masking: Not maskable. */
467#define OXM_OF_IN_PORT OXM_HEADER (0x8000, OFPXMT_OFB_IN_PORT, 4)
468
469/* Physical port on which the packet was received.
470 *
471 * Consider a packet received on a tunnel interface defined over a link
472 * aggregation group (LAG) with two physical port members. If the tunnel
473 * interface is the logical port bound to OpenFlow. In this case,
474 * OFPXMT_OF_IN_PORT is the tunnel's port number and OFPXMT_OF_IN_PHY_PORT is
475 * the physical port number of the LAG on which the tunnel is configured.
476 *
477 * When a packet is received directly on a physical port and not processed by a
478 * logical port, OFPXMT_OF_IN_PORT and OFPXMT_OF_IN_PHY_PORT have the same
479 * value.
480 *
481 * This field is usually not available in a regular match and only available
482 * in ofp_packet_in messages when it's different from OXM_OF_IN_PORT.
483 *
484 * Prereqs: OXM_OF_IN_PORT must be present.
485 *
486 * Format: 32-bit integer in network byte order.
487 *
488 * Masking: Not maskable. */
489#define OXM_OF_IN_PHY_PORT OXM_HEADER (0x8000, OFPXMT_OFB_IN_PHY_PORT, 4)
490
491/* Table metadata.
492 *
493 * Prereqs: None.
494 *
495 * Format: 64-bit integer in network byte order.
496 *
497 * Masking: Arbitrary masks.
498 */
499#define OXM_OF_METADATA OXM_HEADER (0x8000, OFPXMT_OFB_METADATA, 8)
500#define OXM_OF_METADATA_W OXM_HEADER_W(0x8000, OFPXMT_OFB_METADATA, 8)
501
502/* Source or destination address in Ethernet header.
503 *
504 * Prereqs: None.
505 *
506 * Format: 48-bit Ethernet MAC address.
507 *
508 * Masking: Arbitrary masks. */
509#define OXM_OF_ETH_DST OXM_HEADER (0x8000, OFPXMT_OFB_ETH_DST, 6)
510#define OXM_OF_ETH_DST_W OXM_HEADER_W(0x8000, OFPXMT_OFB_ETH_DST, 6)
511#define OXM_OF_ETH_SRC OXM_HEADER (0x8000, OFPXMT_OFB_ETH_SRC, 6)
512#define OXM_OF_ETH_SRC_W OXM_HEADER_W(0x8000, OFPXMT_OFB_ETH_SRC, 6)
513
514/* Packet's Ethernet type.
515 *
516 * Prereqs: None.
517 *
518 * Format: 16-bit integer in network byte order.
519 *
520 * Masking: Not maskable. */
521#define OXM_OF_ETH_TYPE OXM_HEADER (0x8000, OFPXMT_OFB_ETH_TYPE, 2)
522
523/* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
524 * special conditions.
525 */
526enum ofp_vlan_id {
527 OFPVID_PRESENT = 0x1000, /* Bit that indicate that a VLAN id is set */
528 OFPVID_NONE = 0x0000, /* No VLAN id was set. */
529};
530/* Define for compatibility */
531#define OFP_VLAN_NONE OFPVID_NONE
532
533/* 802.1Q VID.
534 *
535 * For a packet with an 802.1Q header, this is the VLAN-ID (VID) from the
536 * outermost tag, with the CFI bit forced to 1. For a packet with no 802.1Q
537 * header, this has value OFPVID_NONE.
538 *
539 * Prereqs: None.
540 *
541 * Format: 16-bit integer in network byte order with bit 13 indicating
542 * presence of VLAN header and 3 most-significant bits forced to 0.
543 * Only the lower 13 bits have meaning.
544 *
545 * Masking: Arbitrary masks.
546 *
547 * This field can be used in various ways:
548 *
549 * - If it is not constrained at all, the nx_match matches packets without
550 * an 802.1Q header or with an 802.1Q header that has any VID value.
551 *
552 * - Testing for an exact match with 0x0 matches only packets without
553 * an 802.1Q header.
554 *
555 * - Testing for an exact match with a VID value with CFI=1 matches packets
556 * that have an 802.1Q header with a specified VID.
557 *
558 * - Testing for an exact match with a nonzero VID value with CFI=0 does
559 * not make sense. The switch may reject this combination.
560 *
561 * - Testing with nxm_value=0, nxm_mask=0x0fff matches packets with no 802.1Q
562 * header or with an 802.1Q header with a VID of 0.
563 *
564 * - Testing with nxm_value=0x1000, nxm_mask=0x1000 matches packets with
565 * an 802.1Q header that has any VID value.
566 */
567#define OXM_OF_VLAN_VID OXM_HEADER (0x8000, OFPXMT_OFB_VLAN_VID, 2)
568#define OXM_OF_VLAN_VID_W OXM_HEADER_W(0x8000, OFPXMT_OFB_VLAN_VID, 2)
569
570/* 802.1Q PCP.
571 *
572 * For a packet with an 802.1Q header, this is the VLAN-PCP from the
573 * outermost tag. For a packet with no 802.1Q header, this has value
574 * 0.
575 *
576 * Prereqs: OXM_OF_VLAN_VID must be different from OFPVID_NONE.
577 *
578 * Format: 8-bit integer with 5 most-significant bits forced to 0.
579 * Only the lower 3 bits have meaning.
580 *
581 * Masking: Not maskable.
582 */
583#define OXM_OF_VLAN_PCP OXM_HEADER (0x8000, OFPXMT_OFB_VLAN_PCP, 1)
584
585/* The Diff Serv Code Point (DSCP) bits of the IP header.
586 * Part of the IPv4 ToS field or the IPv6 Traffic Class field.
587 *
588 * Prereqs: OXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
589 *
590 * Format: 8-bit integer with 2 most-significant bits forced to 0.
591 * Only the lower 6 bits have meaning.
592 *
593 * Masking: Not maskable. */
594#define OXM_OF_IP_DSCP OXM_HEADER (0x8000, OFPXMT_OFB_IP_DSCP, 1)
595
596/* The ECN bits of the IP header.
597 * Part of the IPv4 ToS field or the IPv6 Traffic Class field.
598 *
599 * Prereqs: OXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
600 *
601 * Format: 8-bit integer with 6 most-significant bits forced to 0.
602 * Only the lower 2 bits have meaning.
603 *
604 * Masking: Not maskable. */
605#define OXM_OF_IP_ECN OXM_HEADER (0x8000, OFPXMT_OFB_IP_ECN, 1)
606
607/* The "protocol" byte in the IP header.
608 *
609 * Prereqs: OXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
610 *
611 * Format: 8-bit integer.
612 *
613 * Masking: Not maskable. */
614#define OXM_OF_IP_PROTO OXM_HEADER (0x8000, OFPXMT_OFB_IP_PROTO, 1)
615
616/* The source or destination address in the IP header.
617 *
618 * Prereqs: OXM_OF_ETH_TYPE must match 0x0800 exactly.
619 *
620 * Format: 32-bit integer in network byte order.
621 *
622 * Masking: Arbitrary masks.
623 */
624#define OXM_OF_IPV4_SRC OXM_HEADER (0x8000, OFPXMT_OFB_IPV4_SRC, 4)
625#define OXM_OF_IPV4_SRC_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV4_SRC, 4)
626#define OXM_OF_IPV4_DST OXM_HEADER (0x8000, OFPXMT_OFB_IPV4_DST, 4)
627#define OXM_OF_IPV4_DST_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV4_DST, 4)
628
629/* The source or destination port in the TCP header.
630 *
631 * Prereqs:
632 * OXM_OF_ETH_TYPE must be either 0x0800 or 0x86dd.
633 * OXM_OF_IP_PROTO must match 6 exactly.
634 *
635 * Format: 16-bit integer in network byte order.
636 *
637 * Masking: Not maskable. */
638#define OXM_OF_TCP_SRC OXM_HEADER (0x8000, OFPXMT_OFB_TCP_SRC, 2)
639#define OXM_OF_TCP_DST OXM_HEADER (0x8000, OFPXMT_OFB_TCP_DST, 2)
640
641/* The source or destination port in the UDP header.
642 *
643 * Prereqs:
644 * OXM_OF_ETH_TYPE must match either 0x0800 or 0x86dd.
645 * OXM_OF_IP_PROTO must match 17 exactly.
646 *
647 * Format: 16-bit integer in network byte order.
648 *
649 * Masking: Not maskable. */
650#define OXM_OF_UDP_SRC OXM_HEADER (0x8000, OFPXMT_OFB_UDP_SRC, 2)
651#define OXM_OF_UDP_DST OXM_HEADER (0x8000, OFPXMT_OFB_UDP_DST, 2)
652
653/* The source or destination port in the SCTP header.
654 *
655 * Prereqs:
656 * OXM_OF_ETH_TYPE must match either 0x0800 or 0x86dd.
657 * OXM_OF_IP_PROTO must match 132 exactly.
658 *
659 * Format: 16-bit integer in network byte order.
660 *
661 * Masking: Not maskable. */
662#define OXM_OF_SCTP_SRC OXM_HEADER (0x8000, OFPXMT_OFB_SCTP_SRC, 2)
663#define OXM_OF_SCTP_DST OXM_HEADER (0x8000, OFPXMT_OFB_SCTP_DST, 2)
664
665/* The type or code in the ICMP header.
666 *
667 * Prereqs:
668 * OXM_OF_ETH_TYPE must match 0x0800 exactly.
669 * OXM_OF_IP_PROTO must match 1 exactly.
670 *
671 * Format: 8-bit integer.
672 *
673 * Masking: Not maskable. */
674#define OXM_OF_ICMPV4_TYPE OXM_HEADER (0x8000, OFPXMT_OFB_ICMPV4_TYPE, 1)
675#define OXM_OF_ICMPV4_CODE OXM_HEADER (0x8000, OFPXMT_OFB_ICMPV4_CODE, 1)
676
677/* ARP opcode.
678 *
679 * For an Ethernet+IP ARP packet, the opcode in the ARP header. Always 0
680 * otherwise.
681 *
682 * Prereqs: OXM_OF_ETH_TYPE must match 0x0806 exactly.
683 *
684 * Format: 16-bit integer in network byte order.
685 *
686 * Masking: Not maskable. */
687#define OXM_OF_ARP_OP OXM_HEADER (0x8000, OFPXMT_OFB_ARP_OP, 2)
688
689/* For an Ethernet+IP ARP packet, the source or target protocol address
690 * in the ARP header. Always 0 otherwise.
691 *
692 * Prereqs: OXM_OF_ETH_TYPE must match 0x0806 exactly.
693 *
694 * Format: 32-bit integer in network byte order.
695 *
696 * Masking: Arbitrary masks.
697 */
698#define OXM_OF_ARP_SPA OXM_HEADER (0x8000, OFPXMT_OFB_ARP_SPA, 4)
699#define OXM_OF_ARP_SPA_W OXM_HEADER_W(0x8000, OFPXMT_OFB_ARP_SPA, 4)
700#define OXM_OF_ARP_TPA OXM_HEADER (0x8000, OFPXMT_OFB_ARP_TPA, 4)
701#define OXM_OF_ARP_TPA_W OXM_HEADER_W(0x8000, OFPXMT_OFB_ARP_TPA, 4)
702
703/* For an Ethernet+IP ARP packet, the source or target hardware address
704 * in the ARP header. Always 0 otherwise.
705 *
706 * Prereqs: OXM_OF_ETH_TYPE must match 0x0806 exactly.
707 *
708 * Format: 48-bit Ethernet MAC address.
709 *
710 * Masking: Not maskable. */
711#define OXM_OF_ARP_SHA OXM_HEADER (0x8000, OFPXMT_OFB_ARP_SHA, 6)
712#define OXM_OF_ARP_THA OXM_HEADER (0x8000, OFPXMT_OFB_ARP_THA, 6)
713
714/* The source or destination address in the IPv6 header.
715 *
716 * Prereqs: OXM_OF_ETH_TYPE must match 0x86dd exactly.
717 *
718 * Format: 128-bit IPv6 address.
719 *
720 * Masking: Arbitrary masks.
721 */
722#define OXM_OF_IPV6_SRC OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_SRC, 16)
723#define OXM_OF_IPV6_SRC_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV6_SRC, 16)
724#define OXM_OF_IPV6_DST OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_DST, 16)
725#define OXM_OF_IPV6_DST_W OXM_HEADER_W(0x8000, OFPXMT_OFB_IPV6_DST, 16)
726
727/* The IPv6 Flow Label
728 *
729 * Prereqs:
730 * OXM_OF_ETH_TYPE must match 0x86dd exactly
731 *
732 * Format: 32-bit integer with 12 most-significant bits forced to 0.
733 * Only the lower 20 bits have meaning.
734 *
735 * Masking: Maskable. */
736#define OXM_OF_IPV6_FLABEL OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_FLABEL, 4)
737
738/* The type or code in the ICMPv6 header.
739 *
740 * Prereqs:
741 * OXM_OF_ETH_TYPE must match 0x86dd exactly.
742 * OXM_OF_IP_PROTO must match 58 exactly.
743 *
744 * Format: 8-bit integer.
745 *
746 * Masking: Not maskable. */
747#define OXM_OF_ICMPV6_TYPE OXM_HEADER (0x8000, OFPXMT_OFB_ICMPV6_TYPE, 1)
748#define OXM_OF_ICMPV6_CODE OXM_HEADER (0x8000, OFPXMT_OFB_ICMPV6_CODE, 1)
749
750/* The target address in an IPv6 Neighbor Discovery message.
751 *
752 * Prereqs:
753 * OXM_OF_ETH_TYPE must match 0x86dd exactly.
754 * OXM_OF_IP_PROTO must match 58 exactly.
755 * OXM_OF_ICMPV6_TYPE must be either 135 or 136.
756 *
757 * Format: 128-bit IPv6 address.
758 *
759 * Masking: Not maskable. */
760#define OXM_OF_IPV6_ND_TARGET OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_ND_TARGET, 16)
761
762/* The source link-layer address option in an IPv6 Neighbor Discovery
763 * message.
764 *
765 * Prereqs:
766 * OXM_OF_ETH_TYPE must match 0x86dd exactly.
767 * OXM_OF_IP_PROTO must match 58 exactly.
768 * OXM_OF_ICMPV6_TYPE must be exactly 135.
769 *
770 * Format: 48-bit Ethernet MAC address.
771 *
772 * Masking: Not maskable. */
773#define OXM_OF_IPV6_ND_SLL OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_ND_SLL, 6)
774
775/* The target link-layer address option in an IPv6 Neighbor Discovery
776 * message.
777 *
778 * Prereqs:
779 * OXM_OF_ETH_TYPE must match 0x86dd exactly.
780 * OXM_OF_IP_PROTO must match 58 exactly.
781 * OXM_OF_ICMPV6_TYPE must be exactly 136.
782 *
783 * Format: 48-bit Ethernet MAC address.
784 *
785 * Masking: Not maskable. */
786#define OXM_OF_IPV6_ND_TLL OXM_HEADER (0x8000, OFPXMT_OFB_IPV6_ND_TLL, 6)
787
788/* The LABEL in the first MPLS shim header.
789 *
790 * Prereqs:
791 * OXM_OF_ETH_TYPE must match 0x8847 or 0x8848 exactly.
792 *
793 * Format: 32-bit integer in network byte order with 12 most-significant
794 * bits forced to 0. Only the lower 20 bits have meaning.
795 *
796 * Masking: Not maskable. */
797#define OXM_OF_MPLS_LABEL OXM_HEADER (0x8000, OFPXMT_OFB_MPLS_LABEL, 4)
798
799/* The TC in the first MPLS shim header.
800 *
801 * Prereqs:
802 * OXM_OF_ETH_TYPE must match 0x8847 or 0x8848 exactly.
803 *
804 * Format: 8-bit integer with 5 most-significant bits forced to 0.
805 * Only the lower 3 bits have meaning.
806 *
807 * Masking: Not maskable. */
808#define OXM_OF_MPLS_TC OXM_HEADER (0x8000, OFPXMT_OFB_MPLS_TC, 1)
809
810/* Header for OXM experimenter match fields. */
811struct ofp_oxm_experimenter_header {
812 uint32_t oxm_header; /* oxm_class = OFPXMC_EXPERIMENTER */
813 uint32_t experimenter; /* Experimenter ID which takes the same
814 form as in struct ofp_experimenter_header. */
815};
816OFP_ASSERT(sizeof(struct ofp_oxm_experimenter_header) == 8);
817
818/* ## ----------------- ## */
819/* ## OpenFlow Actions. ## */
820/* ## ----------------- ## */
821
822enum ofp_action_type {
823 OFPAT_OUTPUT = 0, /* Output to switch port. */
824 OFPAT_COPY_TTL_OUT = 11, /* Copy TTL "outwards" -- from next-to-outermost
825 to outermost */
826 OFPAT_COPY_TTL_IN = 12, /* Copy TTL "inwards" -- from outermost to
827 next-to-outermost */
828 OFPAT_SET_MPLS_TTL = 15, /* MPLS TTL */
829 OFPAT_DEC_MPLS_TTL = 16, /* Decrement MPLS TTL */
830
831 OFPAT_PUSH_VLAN = 17, /* Push a new VLAN tag */
832 OFPAT_POP_VLAN = 18, /* Pop the outer VLAN tag */
833 OFPAT_PUSH_MPLS = 19, /* Push a new MPLS tag */
834 OFPAT_POP_MPLS = 20, /* Pop the outer MPLS tag */
835 OFPAT_SET_QUEUE = 21, /* Set queue id when outputting to a port */
836 OFPAT_GROUP = 22, /* Apply group. */
837 OFPAT_SET_NW_TTL = 23, /* IP TTL. */
838 OFPAT_DEC_NW_TTL = 24, /* Decrement IP TTL. */
839 OFPAT_SET_FIELD = 25, /* Set a header field using OXM TLV format. */
840 OFPAT_EXPERIMENTER = 0xffff
841};
842
843enum ofp_controller_max_len {
844 OFPCML_MAX = 0xffe5, /* maximum max_len value which can be used
845 to request a specific byte length. */
846 OFPCML_NO_BUFFER = 0xffff /* indicates that no buffering should be
847 applied and the whole packet is to be
848 sent to the controller. */
849};
850
851/* Action structure for OFPAT_OUTPUT, which sends packets out 'port'.
852 * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
853 * number of bytes to send. A 'max_len' of zero means no bytes of the
854 * packet should be sent. A 'max_len' of OFPCML_NO_BUFFER means that
855 * the packet is not buffered and the complete packet is to be sent to
856 * the controller. */
857struct ofp_action_output {
858 uint16_t type; /* OFPAT_OUTPUT. */
859 uint16_t len; /* Length is 16. */
860 uint32_t port; /* Output port. */
861 uint16_t max_len; /* Max length to send to controller. */
862 uint8_t pad[6]; /* Pad to 64 bits. */
863};
864OFP_ASSERT(sizeof(struct ofp_action_output) == 16);
865
866/* Action structure for OFPAT_SET_MPLS_TTL. */
867struct ofp_action_mpls_ttl {
868 uint16_t type; /* OFPAT_SET_MPLS_TTL. */
869 uint16_t len; /* Length is 8. */
870 uint8_t mpls_ttl; /* MPLS TTL */
871 uint8_t pad[3];
872};
873OFP_ASSERT(sizeof(struct ofp_action_mpls_ttl) == 8);
874
875/* Action structure for OFPAT_PUSH_VLAN/MPLS. */
876struct ofp_action_push {
877 uint16_t type; /* OFPAT_PUSH_VLAN/MPLS. */
878 uint16_t len; /* Length is 8. */
879 uint16_t ethertype; /* Ethertype */
880 uint8_t pad[2];
881};
882OFP_ASSERT(sizeof(struct ofp_action_push) == 8);
883
884/* Action structure for OFPAT_POP_MPLS. */
885struct ofp_action_pop_mpls {
886 uint16_t type; /* OFPAT_POP_MPLS. */
887 uint16_t len; /* Length is 8. */
888 uint16_t ethertype; /* Ethertype */
889 uint8_t pad[2];
890};
891OFP_ASSERT(sizeof(struct ofp_action_pop_mpls) == 8);
892
893/* Action structure for OFPAT_GROUP. */
894struct ofp_action_group {
895 uint16_t type; /* OFPAT_GROUP. */
896 uint16_t len; /* Length is 8. */
897 uint32_t group_id; /* Group identifier. */
898};
899OFP_ASSERT(sizeof(struct ofp_action_group) == 8);
900
901/* Action structure for OFPAT_SET_NW_TTL. */
902struct ofp_action_nw_ttl {
903 uint16_t type; /* OFPAT_SET_NW_TTL. */
904 uint16_t len; /* Length is 8. */
905 uint8_t nw_ttl; /* IP TTL */
906 uint8_t pad[3];
907};
908OFP_ASSERT(sizeof(struct ofp_action_nw_ttl) == 8);
909
910/* Action structure for OFPAT_SET_FIELD. */
911struct ofp_action_set_field {
912 uint16_t type; /* OFPAT_SET_FIELD. */
913 uint16_t len; /* Length is padded to 64 bits. */
914 /* Followed by:
915 * - Exactly oxm_len bytes containing a single OXM TLV, then
916 * - Exactly ((oxm_len + 4) + 7)/8*8 - (oxm_len + 4) (between 0 and 7)
917 * bytes of all-zero bytes
918 */
919 uint8_t field[4]; /* OXM TLV - Make compiler happy */
920};
921OFP_ASSERT(sizeof(struct ofp_action_set_field) == 8);
922
923/* Action header for OFPAT_EXPERIMENTER.
924 * The rest of the body is experimenter-defined. */
925struct ofp_action_experimenter_header {
926 uint16_t type; /* OFPAT_EXPERIMENTER. */
927 uint16_t len; /* Length is a multiple of 8. */
928 uint32_t experimenter; /* Experimenter ID which takes the same
929 form as in struct
930 ofp_experimenter_header. */
931};
932OFP_ASSERT(sizeof(struct ofp_action_experimenter_header) == 8);
933
934/* Action header that is common to all actions. The length includes the
935 * header and any padding used to make the action 64-bit aligned.
936 * NB: The length of an action *must* always be a multiple of eight. */
937struct ofp_action_header {
938 uint16_t type; /* One of OFPAT_*. */
939 uint16_t len; /* Length of action, including this
940 header. This is the length of action,
941 including any padding to make it
942 64-bit aligned. */
943 uint8_t pad[4];
944};
945OFP_ASSERT(sizeof(struct ofp_action_header) == 8);
946
947/* ## ---------------------- ## */
948/* ## OpenFlow Instructions. ## */
949/* ## ---------------------- ## */
950
951enum ofp_instruction_type {
952 OFPIT_GOTO_TABLE = 1, /* Setup the next table in the lookup
953 pipeline */
954 OFPIT_WRITE_METADATA = 2, /* Setup the metadata field for use later in
955 pipeline */
956 OFPIT_WRITE_ACTIONS = 3, /* Write the action(s) onto the datapath action
957 set */
958 OFPIT_APPLY_ACTIONS = 4, /* Applies the action(s) immediately */
959 OFPIT_CLEAR_ACTIONS = 5, /* Clears all actions from the datapath
960 action set */
961
962 OFPIT_EXPERIMENTER = 0xFFFF /* Experimenter instruction */
963};
964
965/* Generic ofp_instruction structure */
966struct ofp_instruction {
967 uint16_t type; /* Instruction type */
968 uint16_t len; /* Length of this struct in bytes. */
969 uint8_t pad[4]; /* Align to 64-bits */
970};
971OFP_ASSERT(sizeof(struct ofp_instruction) == 8);
972
973/* Instruction structure for OFPIT_GOTO_TABLE */
974struct ofp_instruction_goto_table {
975 uint16_t type; /* OFPIT_GOTO_TABLE */
976 uint16_t len; /* Length of this struct in bytes. */
977 uint8_t table_id; /* Set next table in the lookup pipeline */
978 uint8_t pad[3]; /* Pad to 64 bits. */
979};
980OFP_ASSERT(sizeof(struct ofp_instruction_goto_table) == 8);
981
982/* Instruction structure for OFPIT_WRITE_METADATA */
983struct ofp_instruction_write_metadata {
984 uint16_t type; /* OFPIT_WRITE_METADATA */
985 uint16_t len; /* Length of this struct in bytes. */
986 uint8_t pad[4]; /* Align to 64-bits */
987 uint64_t metadata; /* Metadata value to write */
988 uint64_t metadata_mask; /* Metadata write bitmask */
989};
990OFP_ASSERT(sizeof(struct ofp_instruction_write_metadata) == 24);
991
992/* Instruction structure for OFPIT_WRITE/APPLY/CLEAR_ACTIONS */
993struct ofp_instruction_actions {
994 uint16_t type; /* One of OFPIT_*_ACTIONS */
995 uint16_t len; /* Length of this struct in bytes. */
996 uint8_t pad[4]; /* Align to 64-bits */
997 struct ofp_action_header actions[0]; /* Actions associated with
998 OFPIT_WRITE_ACTIONS and
999 OFPIT_APPLY_ACTIONS */
1000};
1001OFP_ASSERT(sizeof(struct ofp_instruction_actions) == 8);
1002
1003/* Instruction structure for experimental instructions */
1004struct ofp_instruction_experimenter {
1005 uint16_t type; /* OFPIT_EXPERIMENTER */
1006 uint16_t len; /* Length of this struct in bytes */
1007 uint32_t experimenter; /* Experimenter ID which takes the same form
1008 as in struct ofp_experimenter_header. */
1009 /* Experimenter-defined arbitrary additional data. */
1010};
1011OFP_ASSERT(sizeof(struct ofp_instruction_experimenter) == 8);
1012
1013/* ## --------------------------- ## */
1014/* ## OpenFlow Flow Modification. ## */
1015/* ## --------------------------- ## */
1016
1017enum ofp_flow_mod_command {
1018 OFPFC_ADD = 0, /* New flow. */
1019 OFPFC_MODIFY = 1, /* Modify all matching flows. */
1020 OFPFC_MODIFY_STRICT = 2, /* Modify entry strictly matching wildcards and
1021 priority. */
1022 OFPFC_DELETE = 3, /* Delete all matching flows. */
1023 OFPFC_DELETE_STRICT = 4, /* Delete entry strictly matching wildcards and
1024 priority. */
1025};
1026
1027/* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
1028 * is permanent. */
1029#define OFP_FLOW_PERMANENT 0
1030
1031/* By default, choose a priority in the middle. */
1032#define OFP_DEFAULT_PRIORITY 0x8000
1033
1034enum ofp_flow_mod_flags {
1035 OFPFF_SEND_FLOW_REM = 1 << 0, /* Send flow removed message when flow
1036 * expires or is deleted. */
1037 OFPFF_CHECK_OVERLAP = 1 << 1, /* Check for overlapping entries first. */
1038 OFPFF_RESET_COUNTS = 1 << 2 /* Reset flow packet and byte counts. */
1039};
1040
1041/* Flow setup and teardown (controller -> datapath). */
1042struct ofp_flow_mod {
1043 struct ofp_header header;
1044 uint64_t cookie; /* Opaque controller-issued identifier. */
1045 uint64_t cookie_mask; /* Mask used to restrict the cookie bits
1046 that must match when the command is
1047 OFPFC_MODIFY* or OFPFC_DELETE*. A value
1048 of 0 indicates no restriction. */
1049
1050 /* Flow actions. */
1051 uint8_t table_id; /* ID of the table to put the flow in.
1052 For OFPFC_DELETE_* commands, OFPTT_ALL
1053 can also be used to delete matching
1054 flows from all tables. */
1055 uint8_t command; /* One of OFPFC_*. */
1056 uint16_t idle_timeout; /* Idle time before discarding (seconds). */
1057 uint16_t hard_timeout; /* Max time before discarding (seconds). */
1058 uint16_t priority; /* Priority level of flow entry. */
1059 uint32_t buffer_id; /* Buffered packet to apply to, or
1060 OFP_NO_BUFFER.
1061 Not meaningful for OFPFC_DELETE*. */
1062 uint32_t out_port; /* For OFPFC_DELETE* commands, require
1063 matching entries to include this as an
1064 output port. A value of OFPP_ANY
1065 indicates no restriction. */
1066 uint32_t out_group; /* For OFPFC_DELETE* commands, require
1067 matching entries to include this as an
1068 output group. A value of OFPG_ANY
1069 indicates no restriction. */
1070 uint16_t flags; /* One of OFPFF_*. */
1071 uint8_t pad[2];
1072 struct ofp_match match; /* Fields to match. Variable size. */
1073 //struct ofp_instruction instructions[0]; /* Instruction set */
1074};
1075OFP_ASSERT(sizeof(struct ofp_flow_mod) == 56);
1076
1077/* Group numbering. Groups can use any number up to OFPG_MAX. */
1078enum ofp_group {
1079 /* Last usable group number. */
1080 OFPG_MAX = 0xffffff00,
1081
1082 /* Fake groups. */
1083 OFPG_ALL = 0xfffffffc, /* Represents all groups for group delete
1084 commands. */
1085 OFPG_ANY = 0xffffffff /* Wildcard group used only for flow stats
1086 requests. Selects all flows regardless of
1087 group (including flows with no group).
1088 */
1089};
1090
1091/* Group commands */
1092enum ofp_group_mod_command {
1093 OFPGC_ADD = 0, /* New group. */
1094 OFPGC_MODIFY = 1, /* Modify all matching groups. */
1095 OFPGC_DELETE = 2, /* Delete all matching groups. */
1096};
1097
1098/* Bucket for use in groups. */
1099struct ofp_bucket {
1100 uint16_t len; /* Length the bucket in bytes, including
1101 this header and any padding to make it
1102 64-bit aligned. */
1103 uint16_t weight; /* Relative weight of bucket. Only
1104 defined for select groups. */
1105 uint32_t watch_port; /* Port whose state affects whether this
1106 bucket is live. Only required for fast
1107 failover groups. */
1108 uint32_t watch_group; /* Group whose state affects whether this
1109 bucket is live. Only required for fast
1110 failover groups. */
1111 uint8_t pad[4];
1112 struct ofp_action_header actions[0]; /* The action length is inferred
1113 from the length field in the
1114 header. */
1115};
1116OFP_ASSERT(sizeof(struct ofp_bucket) == 16);
1117
1118/* Group setup and teardown (controller -> datapath). */
1119struct ofp_group_mod {
1120 struct ofp_header header;
1121 uint16_t command; /* One of OFPGC_*. */
1122 uint8_t type; /* One of OFPGT_*. */
1123 uint8_t pad; /* Pad to 64 bits. */
1124 uint32_t group_id; /* Group identifier. */
1125 struct ofp_bucket buckets[0]; /* The length of the bucket array is inferred
1126 from the length field in the header. */
1127};
1128OFP_ASSERT(sizeof(struct ofp_group_mod) == 16);
1129
1130/* Group types. Values in the range [128, 255] are reserved for experimental
1131 * use. */
1132enum ofp_group_type {
1133 OFPGT_ALL = 0, /* All (multicast/broadcast) group. */
1134 OFPGT_SELECT = 1, /* Select group. */
1135 OFPGT_INDIRECT = 2, /* Indirect group. */
1136 OFPGT_FF = 3, /* Fast failover group. */
1137};
1138
1139/* Special buffer-id to indicate 'no buffer' */
1140#define OFP_NO_BUFFER 0xffffffff
1141
1142/* Send packet (controller -> datapath). */
1143struct ofp_packet_out {
1144 struct ofp_header header;
1145 uint32_t buffer_id; /* ID assigned by datapath (OFP_NO_BUFFER
1146 if none). */
1147 uint32_t in_port; /* Packet's input port or OFPP_CONTROLLER. */
1148 uint16_t actions_len; /* Size of action array in bytes. */
1149 uint8_t pad[6];
1150 struct ofp_action_header actions[0]; /* Action list. */
1151 /* uint8_t data[0]; */ /* Packet data. The length is inferred
1152 from the length field in the header.
1153 (Only meaningful if buffer_id == -1.) */
1154};
1155OFP_ASSERT(sizeof(struct ofp_packet_out) == 24);
1156
1157/* Why is this packet being sent to the controller? */
1158enum ofp_packet_in_reason {
1159 OFPR_NO_MATCH = 0, /* No matching flow. */
1160 OFPR_ACTION = 1, /* Action explicitly output to controller. */
1161 OFPR_INVALID_TTL = 2, /* Packet has invalid TTL */
1162};
1163
1164/* Packet received on port (datapath -> controller). */
1165struct ofp_packet_in {
1166 struct ofp_header header;
1167 uint32_t buffer_id; /* ID assigned by datapath. */
1168 uint16_t total_len; /* Full length of frame. */
1169 uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
1170 uint8_t table_id; /* ID of the table that was looked up */
1171 struct ofp_match match; /* Packet metadata. Variable size. */
1172 /* Followed by:
1173 * - Exactly 2 all-zero padding bytes, then
1174 * - An Ethernet frame whose length is inferred from header.length.
1175 * The padding bytes preceding the Ethernet frame ensure that the IP
1176 * header (if any) following the Ethernet header is 32-bit aligned.
1177 */
1178 //uint8_t pad[2]; /* Align to 64 bit + 16 bit */
1179 //uint8_t data[0]; /* Ethernet frame */
1180};
1181OFP_ASSERT(sizeof(struct ofp_packet_in) == 24);
1182
1183/* Why was this flow removed? */
1184enum ofp_flow_removed_reason {
1185 OFPRR_IDLE_TIMEOUT = 0, /* Flow idle time exceeded idle_timeout. */
1186 OFPRR_HARD_TIMEOUT = 1, /* Time exceeded hard_timeout. */
1187 OFPRR_DELETE = 2, /* Evicted by a DELETE flow mod. */
1188 OFPRR_GROUP_DELETE = 3, /* Group was removed. */
1189};
1190
1191/* Flow removed (datapath -> controller). */
1192struct ofp_flow_removed {
1193 struct ofp_header header;
1194 uint64_t cookie; /* Opaque controller-issued identifier. */
1195
1196 uint16_t priority; /* Priority level of flow entry. */
1197 uint8_t reason; /* One of OFPRR_*. */
1198 uint8_t table_id; /* ID of the table */
1199
1200 uint32_t duration_sec; /* Time flow was alive in seconds. */
1201 uint32_t duration_nsec; /* Time flow was alive in nanoseconds beyond
1202 duration_sec. */
1203 uint16_t idle_timeout; /* Idle timeout from original flow mod. */
1204 uint16_t hard_timeout; /* Hard timeout from original flow mod. */
1205 uint64_t packet_count;
1206 uint64_t byte_count;
1207 struct ofp_match match; /* Description of fields. Variable size. */
1208};
1209OFP_ASSERT(sizeof(struct ofp_flow_removed) == 56);
1210
1211/* Values for 'type' in ofp_error_message. These values are immutable: they
1212 * will not change in future versions of the protocol (although new values may
1213 * be added). */
1214enum ofp_error_type {
1215 OFPET_HELLO_FAILED = 0, /* Hello protocol failed. */
1216 OFPET_BAD_REQUEST = 1, /* Request was not understood. */
1217 OFPET_BAD_ACTION = 2, /* Error in action description. */
1218 OFPET_BAD_INSTRUCTION = 3, /* Error in instruction list. */
1219 OFPET_BAD_MATCH = 4, /* Error in match. */
1220 OFPET_FLOW_MOD_FAILED = 5, /* Problem modifying flow entry. */
1221 OFPET_GROUP_MOD_FAILED = 6, /* Problem modifying group entry. */
1222 OFPET_PORT_MOD_FAILED = 7, /* Port mod request failed. */
1223 OFPET_TABLE_MOD_FAILED = 8, /* Table mod request failed. */
1224 OFPET_QUEUE_OP_FAILED = 9, /* Queue operation failed. */
1225 OFPET_SWITCH_CONFIG_FAILED = 10, /* Switch config request failed. */
1226 OFPET_ROLE_REQUEST_FAILED = 11, /* Controller Role request failed. */
1227 OFPET_EXPERIMENTER = 0xffff /* Experimenter error messages. */
1228};
1229
1230/* ofp_error_msg 'code' values for OFPET_HELLO_FAILED. 'data' contains an
1231 * ASCII text string that may give failure details. */
1232enum ofp_hello_failed_code {
1233 OFPHFC_INCOMPATIBLE = 0, /* No compatible version. */
1234 OFPHFC_EPERM = 1, /* Permissions error. */
1235};
1236
1237/* ofp_error_msg 'code' values for OFPET_BAD_REQUEST. 'data' contains at least
1238 * the first 64 bytes of the failed request. */
1239enum ofp_bad_request_code {
1240 OFPBRC_BAD_VERSION = 0, /* ofp_header.version not supported. */
1241 OFPBRC_BAD_TYPE = 1, /* ofp_header.type not supported. */
1242 OFPBRC_BAD_STAT = 2, /* ofp_stats_request.type not supported. */
1243 OFPBRC_BAD_EXPERIMENTER = 3, /* Experimenter id not supported
1244 * (in ofp_experimenter_header or
1245 * ofp_stats_request or ofp_stats_reply). */
1246 OFPBRC_BAD_EXP_TYPE = 4, /* Experimenter type not supported. */
1247 OFPBRC_EPERM = 5, /* Permissions error. */
1248 OFPBRC_BAD_LEN = 6, /* Wrong request length for type. */
1249 OFPBRC_BUFFER_EMPTY = 7, /* Specified buffer has already been used. */
1250 OFPBRC_BUFFER_UNKNOWN = 8, /* Specified buffer does not exist. */
1251 OFPBRC_BAD_TABLE_ID = 9, /* Specified table-id invalid or does not
1252 * exist. */
1253 OFPBRC_IS_SLAVE = 10, /* Denied because controller is slave. */
1254 OFPBRC_BAD_PORT = 11, /* Invalid port. */
1255 OFPBRC_BAD_PACKET = 12, /* Invalid packet in packet-out. */
1256};
1257
1258/* ofp_error_msg 'code' values for OFPET_BAD_ACTION. 'data' contains at least
1259 * the first 64 bytes of the failed request. */
1260enum ofp_bad_action_code {
1261 OFPBAC_BAD_TYPE = 0, /* Unknown action type. */
1262 OFPBAC_BAD_LEN = 1, /* Length problem in actions. */
1263 OFPBAC_BAD_EXPERIMENTER = 2, /* Unknown experimenter id specified. */
1264 OFPBAC_BAD_EXP_TYPE = 3, /* Unknown action for experimenter id. */
1265 OFPBAC_BAD_OUT_PORT = 4, /* Problem validating output port. */
1266 OFPBAC_BAD_ARGUMENT = 5, /* Bad action argument. */
1267 OFPBAC_EPERM = 6, /* Permissions error. */
1268 OFPBAC_TOO_MANY = 7, /* Can't handle this many actions. */
1269 OFPBAC_BAD_QUEUE = 8, /* Problem validating output queue. */
1270 OFPBAC_BAD_OUT_GROUP = 9, /* Invalid group id in forward action. */
1271 OFPBAC_MATCH_INCONSISTENT = 10, /* Action can't apply for this match,
1272 or Set-Field missing prerequisite. */
1273 OFPBAC_UNSUPPORTED_ORDER = 11, /* Action order is unsupported for the
1274 action list in an Apply-Actions instruction */
1275 OFPBAC_BAD_TAG = 12, /* Actions uses an unsupported
1276 tag/encap. */
1277 OFPBAC_BAD_SET_TYPE = 13, /* Unsupported type in SET_FIELD action. */
1278 OFPBAC_BAD_SET_LEN = 14, /* Length problem in SET_FIELD action. */
1279 OFPBAC_BAD_SET_ARGUMENT = 15, /* Bad argument in SET_FIELD action. */
1280};
1281
1282/* ofp_error_msg 'code' values for OFPET_BAD_INSTRUCTION. 'data' contains at least
1283 * the first 64 bytes of the failed request. */
1284enum ofp_bad_instruction_code {
1285 OFPBIC_UNKNOWN_INST = 0, /* Unknown instruction. */
1286 OFPBIC_UNSUP_INST = 1, /* Switch or table does not support the
1287 instruction. */
1288 OFPBIC_BAD_TABLE_ID = 2, /* Invalid Table-ID specified. */
1289 OFPBIC_UNSUP_METADATA = 3, /* Metadata value unsupported by datapath. */
1290 OFPBIC_UNSUP_METADATA_MASK = 4, /* Metadata mask value unsupported by
1291 datapath. */
1292 OFPBIC_BAD_EXPERIMENTER = 5, /* Unknown experimenter id specified. */
1293 OFPBIC_BAD_EXP_TYPE = 6, /* Unknown instruction for experimenter id. */
1294 OFPBIC_BAD_LEN = 7, /* Length problem in instructions. */
1295 OFPBIC_EPERM = 8, /* Permissions error. */
1296};
1297
1298/* ofp_error_msg 'code' values for OFPET_BAD_MATCH. 'data' contains at least
1299 * the first 64 bytes of the failed request. */
1300enum ofp_bad_match_code {
1301 OFPBMC_BAD_TYPE = 0, /* Unsupported match type specified by the
1302 match */
1303 OFPBMC_BAD_LEN = 1, /* Length problem in match. */
1304 OFPBMC_BAD_TAG = 2, /* Match uses an unsupported tag/encap. */
1305 OFPBMC_BAD_DL_ADDR_MASK = 3, /* Unsupported datalink addr mask - switch
1306 does not support arbitrary datalink
1307 address mask. */
1308 OFPBMC_BAD_NW_ADDR_MASK = 4, /* Unsupported network addr mask - switch
1309 does not support arbitrary network
1310 address mask. */
1311 OFPBMC_BAD_WILDCARDS = 5, /* Unsupported combination of fields masked
1312 or omitted in the match. */
1313 OFPBMC_BAD_FIELD = 6, /* Unsupported field type in the match. */
1314 OFPBMC_BAD_VALUE = 7, /* Unsupported value in a match field. */
1315 OFPBMC_BAD_MASK = 8, /* Unsupported mask specified in the match,
1316 field is not dl-address or nw-address. */
1317 OFPBMC_BAD_PREREQ = 9, /* A prerequisite was not met. */
1318 OFPBMC_DUP_FIELD = 10, /* A field type was duplicated. */
1319 OFPBMC_EPERM = 11, /* Permissions error. */
1320};
1321
1322/* ofp_error_msg 'code' values for OFPET_FLOW_MOD_FAILED. 'data' contains
1323 * at least the first 64 bytes of the failed request. */
1324enum ofp_flow_mod_failed_code {
1325 OFPFMFC_UNKNOWN = 0, /* Unspecified error. */
1326 OFPFMFC_TABLE_FULL = 1, /* Flow not added because table was full. */
1327 OFPFMFC_BAD_TABLE_ID = 2, /* Table does not exist */
1328 OFPFMFC_OVERLAP = 3, /* Attempted to add overlapping flow with
1329 CHECK_OVERLAP flag set. */
1330 OFPFMFC_EPERM = 4, /* Permissions error. */
1331 OFPFMFC_BAD_TIMEOUT = 5, /* Flow not added because of unsupported
1332 idle/hard timeout. */
1333 OFPFMFC_BAD_COMMAND = 6, /* Unsupported or unknown command. */
1334 OFPFMFC_BAD_FLAGS = 7, /* Unsupported or unknown flags. */
1335};
1336
1337/* ofp_error_msg 'code' values for OFPET_GROUP_MOD_FAILED. 'data' contains
1338 * at least the first 64 bytes of the failed request. */
1339enum ofp_group_mod_failed_code {
1340 OFPGMFC_GROUP_EXISTS = 0, /* Group not added because a group ADD
1341 attempted to replace an
1342 already-present group. */
1343 OFPGMFC_INVALID_GROUP = 1, /* Group not added because Group
1344 specified is invalid. */
1345 OFPGMFC_WEIGHT_UNSUPPORTED = 2, /* Switch does not support unequal load
1346 sharing with select groups. */
1347 OFPGMFC_OUT_OF_GROUPS = 3, /* The group table is full. */
1348 OFPGMFC_OUT_OF_BUCKETS = 4, /* The maximum number of action buckets
1349 for a group has been exceeded. */
1350 OFPGMFC_CHAINING_UNSUPPORTED = 5, /* Switch does not support groups that
1351 forward to groups. */
1352 OFPGMFC_WATCH_UNSUPPORTED = 6, /* This group cannot watch the watch_port
1353 or watch_group specified. */
1354 OFPGMFC_LOOP = 7, /* Group entry would cause a loop. */
1355 OFPGMFC_UNKNOWN_GROUP = 8, /* Group not modified because a group
1356 MODIFY attempted to modify a
1357 non-existent group. */
1358 OFPGMFC_CHAINED_GROUP = 9, /* Group not deleted because another
1359 group is forwarding to it. */
1360 OFPGMFC_BAD_TYPE = 10, /* Unsupported or unknown group type. */
1361 OFPGMFC_BAD_COMMAND = 11, /* Unsupported or unknown command. */
1362 OFPGMFC_BAD_BUCKET = 12, /* Error in bucket. */
1363 OFPGMFC_BAD_WATCH = 13, /* Error in watch port/group. */
1364 OFPGMFC_EPERM = 14, /* Permissions error. */
1365};
1366
1367/* ofp_error_msg 'code' values for OFPET_PORT_MOD_FAILED. 'data' contains
1368 * at least the first 64 bytes of the failed request. */
1369enum ofp_port_mod_failed_code {
1370 OFPPMFC_BAD_PORT = 0, /* Specified port number does not exist. */
1371 OFPPMFC_BAD_HW_ADDR = 1, /* Specified hardware address does not
1372 * match the port number. */
1373 OFPPMFC_BAD_CONFIG = 2, /* Specified config is invalid. */
1374 OFPPMFC_BAD_ADVERTISE = 3, /* Specified advertise is invalid. */
1375 OFPPMFC_EPERM = 4, /* Permissions error. */
1376};
1377
1378/* ofp_error_msg 'code' values for OFPET_TABLE_MOD_FAILED. 'data' contains
1379 * at least the first 64 bytes of the failed request. */
1380enum ofp_table_mod_failed_code {
1381 OFPTMFC_BAD_TABLE = 0, /* Specified table does not exist. */
1382 OFPTMFC_BAD_CONFIG = 1, /* Specified config is invalid. */
1383 OFPTMFC_EPERM = 2, /* Permissions error. */
1384};
1385
1386/* ofp_error msg 'code' values for OFPET_QUEUE_OP_FAILED. 'data' contains
1387 * at least the first 64 bytes of the failed request */
1388enum ofp_queue_op_failed_code {
1389 OFPQOFC_BAD_PORT = 0, /* Invalid port (or port does not exist). */
1390 OFPQOFC_BAD_QUEUE = 1, /* Queue does not exist. */
1391 OFPQOFC_EPERM = 2, /* Permissions error. */
1392};
1393
1394/* ofp_error_msg 'code' values for OFPET_SWITCH_CONFIG_FAILED. 'data' contains
1395 * at least the first 64 bytes of the failed request. */
1396enum ofp_switch_config_failed_code {
1397 OFPSCFC_BAD_FLAGS = 0, /* Specified flags is invalid. */
1398 OFPSCFC_BAD_LEN = 1, /* Specified len is invalid. */
1399 OFPQCFC_EPERM = 2, /* Permissions error. */
1400};
1401
1402/* ofp_error_msg 'code' values for OFPET_ROLE_REQUEST_FAILED. 'data' contains
1403 * at least the first 64 bytes of the failed request. */
1404enum ofp_role_request_failed_code {
1405 OFPRRFC_STALE = 0, /* Stale Message: old generation_id. */
1406 OFPRRFC_UNSUP = 1, /* Controller role change unsupported. */
1407 OFPRRFC_BAD_ROLE = 2, /* Invalid role. */
1408};
1409
1410/* OFPT_ERROR: Error message (datapath -> controller). */
1411struct ofp_error_msg {
1412 struct ofp_header header;
1413
1414 uint16_t type;
1415 uint16_t code;
1416 uint8_t data[0]; /* Variable-length data. Interpreted based
1417 on the type and code. No padding. */
1418};
1419OFP_ASSERT(sizeof(struct ofp_error_msg) == 12);
1420
1421/* OFPET_EXPERIMENTER: Error message (datapath -> controller). */
1422struct ofp_error_experimenter_msg {
1423 struct ofp_header header;
1424
1425 uint16_t type; /* OFPET_EXPERIMENTER. */
1426 uint16_t exp_type; /* Experimenter defined. */
1427 uint32_t experimenter; /* Experimenter ID which takes the same form
1428 as in struct ofp_experimenter_header. */
1429 uint8_t data[0]; /* Variable-length data. Interpreted based
1430 on the type and code. No padding. */
1431};
1432OFP_ASSERT(sizeof(struct ofp_error_experimenter_msg) == 16);
1433
1434enum ofp_stats_types {
1435 /* Description of this OpenFlow switch.
1436 * The request body is empty.
1437 * The reply body is struct ofp_desc_stats. */
1438 OFPST_DESC = 0,
1439
1440 /* Individual flow statistics.
1441 * The request body is struct ofp_flow_stats_request.
1442 * The reply body is an array of struct ofp_flow_stats. */
1443 OFPST_FLOW = 1,
1444
1445 /* Aggregate flow statistics.
1446 * The request body is struct ofp_aggregate_stats_request.
1447 * The reply body is struct ofp_aggregate_stats_reply. */
1448 OFPST_AGGREGATE = 2,
1449
1450 /* Flow table statistics.
1451 * The request body is empty.
1452 * The reply body is an array of struct ofp_table_stats. */
1453 OFPST_TABLE = 3,
1454
1455 /* Port statistics.
1456 * The request body is struct ofp_port_stats_request.
1457 * The reply body is an array of struct ofp_port_stats. */
1458 OFPST_PORT = 4,
1459
1460 /* Queue statistics for a port
1461 * The request body is struct ofp_queue_stats_request.
1462 * The reply body is an array of struct ofp_queue_stats */
1463 OFPST_QUEUE = 5,
1464
1465 /* Group counter statistics.
1466 * The request body is struct ofp_group_stats_request.
1467 * The reply is an array of struct ofp_group_stats. */
1468 OFPST_GROUP = 6,
1469
1470 /* Group description statistics.
1471 * The request body is empty.
1472 * The reply body is an array of struct ofp_group_desc_stats. */
1473 OFPST_GROUP_DESC = 7,
1474
1475 /* Group features.
1476 * The request body is empty.
1477 * The reply body is struct ofp_group_features_stats. */
1478 OFPST_GROUP_FEATURES = 8,
1479
1480 /* Experimenter extension.
1481 * The request and reply bodies begin with
1482 * struct ofp_experimenter_stats_header.
1483 * The request and reply bodies are otherwise experimenter-defined. */
1484 OFPST_EXPERIMENTER = 0xffff
1485};
1486
1487struct ofp_stats_request {
1488 struct ofp_header header;
1489 uint16_t type; /* One of the OFPST_* constants. */
1490 uint16_t flags; /* OFPSF_REQ_* flags (none yet defined). */
1491 uint8_t pad[4];
1492 uint8_t body[0]; /* Body of the request. */
1493};
1494OFP_ASSERT(sizeof(struct ofp_stats_request) == 16);
1495
1496enum ofp_stats_reply_flags {
1497 OFPSF_REPLY_MORE = 1 << 0 /* More replies to follow. */
1498};
1499
1500struct ofp_stats_reply {
1501 struct ofp_header header;
1502 uint16_t type; /* One of the OFPST_* constants. */
1503 uint16_t flags; /* OFPSF_REPLY_* flags. */
1504 uint8_t pad[4];
1505 uint8_t body[0]; /* Body of the reply. */
1506};
1507OFP_ASSERT(sizeof(struct ofp_stats_reply) == 16);
1508
1509#define DESC_STR_LEN 256
1510#define SERIAL_NUM_LEN 32
1511/* Body of reply to OFPST_DESC request. Each entry is a NULL-terminated
1512 * ASCII string. */
1513struct ofp_desc_stats {
1514 char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */
1515 char hw_desc[DESC_STR_LEN]; /* Hardware description. */
1516 char sw_desc[DESC_STR_LEN]; /* Software description. */
1517 char serial_num[SERIAL_NUM_LEN]; /* Serial number. */
1518 char dp_desc[DESC_STR_LEN]; /* Human readable description of datapath. */
1519};
1520OFP_ASSERT(sizeof(struct ofp_desc_stats) == 1056);
1521
1522/* Body for ofp_stats_request of type OFPST_FLOW. */
1523struct ofp_flow_stats_request {
1524 uint8_t table_id; /* ID of table to read (from ofp_table_stats),
1525 OFPTT_ALL for all tables. */
1526 uint8_t pad[3]; /* Align to 32 bits. */
1527 uint32_t out_port; /* Require matching entries to include this
1528 as an output port. A value of OFPP_ANY
1529 indicates no restriction. */
1530 uint32_t out_group; /* Require matching entries to include this
1531 as an output group. A value of OFPG_ANY
1532 indicates no restriction. */
1533 uint8_t pad2[4]; /* Align to 64 bits. */
1534 uint64_t cookie; /* Require matching entries to contain this
1535 cookie value */
1536 uint64_t cookie_mask; /* Mask used to restrict the cookie bits that
1537 must match. A value of 0 indicates
1538 no restriction. */
1539 struct ofp_match match; /* Fields to match. Variable size. */
1540};
1541OFP_ASSERT(sizeof(struct ofp_flow_stats_request) == 40);
1542
1543/* Body of reply to OFPST_FLOW request. */
1544struct ofp_flow_stats {
1545 uint16_t length; /* Length of this entry. */
1546 uint8_t table_id; /* ID of table flow came from. */
1547 uint8_t pad;
1548 uint32_t duration_sec; /* Time flow has been alive in seconds. */
1549 uint32_t duration_nsec; /* Time flow has been alive in nanoseconds beyond
1550 duration_sec. */
1551 uint16_t priority; /* Priority of the entry. */
1552 uint16_t idle_timeout; /* Number of seconds idle before expiration. */
1553 uint16_t hard_timeout; /* Number of seconds before expiration. */
1554 uint8_t pad2[6]; /* Align to 64-bits. */
1555 uint64_t cookie; /* Opaque controller-issued identifier. */
1556 uint64_t packet_count; /* Number of packets in flow. */
1557 uint64_t byte_count; /* Number of bytes in flow. */
1558 struct ofp_match match; /* Description of fields. Variable size. */
1559 //struct ofp_instruction instructions[0]; /* Instruction set. */
1560};
1561OFP_ASSERT(sizeof(struct ofp_flow_stats) == 56);
1562
1563/* Body for ofp_stats_request of type OFPST_AGGREGATE. */
1564struct ofp_aggregate_stats_request {
1565 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
1566 OFPTT_ALL for all tables. */
1567 uint8_t pad[3]; /* Align to 32 bits. */
1568 uint32_t out_port; /* Require matching entries to include this
1569 as an output port. A value of OFPP_ANY
1570 indicates no restriction. */
1571 uint32_t out_group; /* Require matching entries to include this
1572 as an output group. A value of OFPG_ANY
1573 indicates no restriction. */
1574 uint8_t pad2[4]; /* Align to 64 bits. */
1575 uint64_t cookie; /* Require matching entries to contain this
1576 cookie value */
1577 uint64_t cookie_mask; /* Mask used to restrict the cookie bits that
1578 must match. A value of 0 indicates
1579 no restriction. */
1580 struct ofp_match match; /* Fields to match. Variable size. */
1581};
1582OFP_ASSERT(sizeof(struct ofp_aggregate_stats_request) == 40);
1583
1584/* Body of reply to OFPST_AGGREGATE request. */
1585struct ofp_aggregate_stats_reply {
1586 uint64_t packet_count; /* Number of packets in flows. */
1587 uint64_t byte_count; /* Number of bytes in flows. */
1588 uint32_t flow_count; /* Number of flows. */
1589 uint8_t pad[4]; /* Align to 64 bits. */
1590};
1591OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
1592
1593/* Body of reply to OFPST_TABLE request. */
1594struct ofp_table_stats {
1595 uint8_t table_id; /* Identifier of table. Lower numbered tables
1596 are consulted first. */
1597 uint8_t pad[7]; /* Align to 64-bits. */
1598 char name[OFP_MAX_TABLE_NAME_LEN];
1599 uint64_t match; /* Bitmap of (1 << OFPXMT_*) that indicate the
1600 fields the table can match on. */
1601 uint64_t wildcards; /* Bitmap of (1 << OFPXMT_*) wildcards that are
1602 supported by the table. */
1603 uint32_t write_actions; /* Bitmap of OFPAT_* that are supported
1604 by the table with OFPIT_WRITE_ACTIONS. */
1605 uint32_t apply_actions; /* Bitmap of OFPAT_* that are supported
1606 by the table with OFPIT_APPLY_ACTIONS. */
1607 uint64_t write_setfields;/* Bitmap of (1 << OFPXMT_*) header fields that
1608 can be set with OFPIT_WRITE_ACTIONS. */
1609 uint64_t apply_setfields;/* Bitmap of (1 << OFPXMT_*) header fields that
1610 can be set with OFPIT_APPLY_ACTIONS. */
1611 uint64_t metadata_match; /* Bits of metadata table can match. */
1612 uint64_t metadata_write; /* Bits of metadata table can write. */
1613 uint32_t instructions; /* Bitmap of OFPIT_* values supported. */
1614 uint32_t config; /* Bitmap of OFPTC_* values */
1615 uint32_t max_entries; /* Max number of entries supported. */
1616 uint32_t active_count; /* Number of active entries. */
1617 uint64_t lookup_count; /* Number of packets looked up in table. */
1618 uint64_t matched_count; /* Number of packets that hit table. */
1619};
1620OFP_ASSERT(sizeof(struct ofp_table_stats) == 128);
1621
1622/* Body for ofp_stats_request of type OFPST_PORT. */
1623struct ofp_port_stats_request {
1624 uint32_t port_no; /* OFPST_PORT message must request statistics
1625 * either for a single port (specified in
1626 * port_no) or for all ports (if port_no ==
1627 * OFPP_ANY). */
1628 uint8_t pad[4];
1629};
1630OFP_ASSERT(sizeof(struct ofp_port_stats_request) == 8);
1631
1632/* Body of reply to OFPST_PORT request. If a counter is unsupported, set
1633 * the field to all ones. */
1634struct ofp_port_stats {
1635 uint32_t port_no;
1636 uint8_t pad[4]; /* Align to 64-bits. */
1637 uint64_t rx_packets; /* Number of received packets. */
1638 uint64_t tx_packets; /* Number of transmitted packets. */
1639 uint64_t rx_bytes; /* Number of received bytes. */
1640 uint64_t tx_bytes; /* Number of transmitted bytes. */
1641 uint64_t rx_dropped; /* Number of packets dropped by RX. */
1642 uint64_t tx_dropped; /* Number of packets dropped by TX. */
1643 uint64_t rx_errors; /* Number of receive errors. This is a super-set
1644 of more specific receive errors and should be
1645 greater than or equal to the sum of all
1646 rx_*_err values. */
1647 uint64_t tx_errors; /* Number of transmit errors. This is a super-set
1648 of more specific transmit errors and should be
1649 greater than or equal to the sum of all
1650 tx_*_err values (none currently defined.) */
1651 uint64_t rx_frame_err; /* Number of frame alignment errors. */
1652 uint64_t rx_over_err; /* Number of packets with RX overrun. */
1653 uint64_t rx_crc_err; /* Number of CRC errors. */
1654 uint64_t collisions; /* Number of collisions. */
1655};
1656OFP_ASSERT(sizeof(struct ofp_port_stats) == 104);
1657
1658/* Body of OFPST_GROUP request. */
1659struct ofp_group_stats_request {
1660 uint32_t group_id; /* All groups if OFPG_ALL. */
1661 uint8_t pad[4]; /* Align to 64 bits. */
1662};
1663OFP_ASSERT(sizeof(struct ofp_group_stats_request) == 8);
1664
1665/* Used in group stats replies. */
1666struct ofp_bucket_counter {
1667 uint64_t packet_count; /* Number of packets processed by bucket. */
1668 uint64_t byte_count; /* Number of bytes processed by bucket. */
1669};
1670OFP_ASSERT(sizeof(struct ofp_bucket_counter) == 16);
1671
1672/* Body of reply to OFPST_GROUP request. */
1673struct ofp_group_stats {
1674 uint16_t length; /* Length of this entry. */
1675 uint8_t pad[2]; /* Align to 64 bits. */
1676 uint32_t group_id; /* Group identifier. */
1677 uint32_t ref_count; /* Number of flows or groups that directly forward
1678 to this group. */
1679 uint8_t pad2[4]; /* Align to 64 bits. */
1680 uint64_t packet_count; /* Number of packets processed by group. */
1681 uint64_t byte_count; /* Number of bytes processed by group. */
1682 struct ofp_bucket_counter bucket_stats[0];
1683};
1684OFP_ASSERT(sizeof(struct ofp_group_stats) == 32);
1685
1686/* Body of reply to OFPST_GROUP_DESC request. */
1687struct ofp_group_desc_stats {
1688 uint16_t length; /* Length of this entry. */
1689 uint8_t type; /* One of OFPGT_*. */
1690 uint8_t pad; /* Pad to 64 bits. */
1691 uint32_t group_id; /* Group identifier. */
1692 struct ofp_bucket buckets[0];
1693};
1694OFP_ASSERT(sizeof(struct ofp_group_desc_stats) == 8);
1695
1696/* Group configuration flags */
1697enum ofp_group_capabilities {
1698 OFPGFC_SELECT_WEIGHT = 1 << 0, /* Support weight for select groups */
1699 OFPGFC_SELECT_LIVENESS = 1 << 1, /* Support liveness for select groups */
1700 OFPGFC_CHAINING = 1 << 2, /* Support chaining groups */
1701 OFPGFC_CHAINING_CHECKS = 1 << 3, /* Check chaining for loops and delete */
1702};
1703
1704/* Body of reply to OFPST_GROUP_FEATURES request. Group features. */
1705struct ofp_group_features_stats {
1706 uint32_t types; /* Bitmap of OFPGT_* values supported. */
1707 uint32_t capabilities; /* Bitmap of OFPGFC_* capability supported. */
1708 uint32_t max_groups[4]; /* Maximum number of groups for each type. */
1709 uint32_t actions[4]; /* Bitmaps of OFPAT_* that are supported. */
1710};
1711OFP_ASSERT(sizeof(struct ofp_group_features_stats) == 40);
1712
1713/* Body for ofp_stats_request/reply of type OFPST_EXPERIMENTER. */
1714struct ofp_experimenter_stats_header {
1715 uint32_t experimenter; /* Experimenter ID which takes the same form
1716 as in struct ofp_experimenter_header. */
1717 uint32_t exp_type; /* Experimenter defined. */
1718 /* Experimenter-defined arbitrary additional data. */
1719};
1720OFP_ASSERT(sizeof(struct ofp_experimenter_stats_header) == 8);
1721
1722/* Experimenter extension. */
1723struct ofp_experimenter_header {
1724 struct ofp_header header; /* Type OFPT_EXPERIMENTER. */
1725 uint32_t experimenter; /* Experimenter ID:
1726 * - MSB 0: low-order bytes are IEEE OUI.
1727 * - MSB != 0: defined by ONF. */
1728 uint32_t exp_type; /* Experimenter defined. */
1729 /* Experimenter-defined arbitrary additional data. */
1730};
1731OFP_ASSERT(sizeof(struct ofp_experimenter_header) == 16);
1732
1733/* All ones is used to indicate all queues in a port (for stats retrieval). */
1734#define OFPQ_ALL 0xffffffff
1735
1736/* Min rate > 1000 means not configured. */
1737#define OFPQ_MIN_RATE_UNCFG 0xffff
1738
1739/* Max rate > 1000 means not configured. */
1740#define OFPQ_MAX_RATE_UNCFG 0xffff
1741
1742enum ofp_queue_properties {
1743 OFPQT_MIN_RATE = 1, /* Minimum datarate guaranteed. */
1744 OFPQT_MAX_RATE = 2, /* Maximum datarate. */
1745 OFPQT_EXPERIMENTER = 0xffff /* Experimenter defined property. */
1746};
1747
1748/* Common description for a queue. */
1749struct ofp_queue_prop_header {
1750 uint16_t property; /* One of OFPQT_. */
1751 uint16_t len; /* Length of property, including this header. */
1752 uint8_t pad[4]; /* 64-bit alignemnt. */
1753};
1754OFP_ASSERT(sizeof(struct ofp_queue_prop_header) == 8);
1755
1756/* Min-Rate queue property description. */
1757struct ofp_queue_prop_min_rate {
1758 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MIN, len: 16. */
1759 uint16_t rate; /* In 1/10 of a percent; >1000 -> disabled. */
1760 uint8_t pad[6]; /* 64-bit alignment */
1761};
1762OFP_ASSERT(sizeof(struct ofp_queue_prop_min_rate) == 16);
1763
1764/* Max-Rate queue property description. */
1765struct ofp_queue_prop_max_rate {
1766 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MAX, len: 16. */
1767 uint16_t rate; /* In 1/10 of a percent; >1000 -> disabled. */
1768 uint8_t pad[6]; /* 64-bit alignment */
1769};
1770OFP_ASSERT(sizeof(struct ofp_queue_prop_max_rate) == 16);
1771
1772/* Experimenter queue property description. */
1773struct ofp_queue_prop_experimenter {
1774 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_EXPERIMENTER, len: 16. */
1775 uint32_t experimenter; /* Experimenter ID which takes the same
1776 form as in struct
1777 ofp_experimenter_header. */
1778 uint8_t pad[4]; /* 64-bit alignment */
1779 uint8_t data[0]; /* Experimenter defined data. */
1780};
1781OFP_ASSERT(sizeof(struct ofp_queue_prop_experimenter) == 16);
1782
1783/* Full description for a queue. */
1784struct ofp_packet_queue {
1785 uint32_t queue_id; /* id for the specific queue. */
1786 uint32_t port; /* Port this queue is attached to. */
1787 uint16_t len; /* Length in bytes of this queue desc. */
1788 uint8_t pad[6]; /* 64-bit alignment. */
1789 struct ofp_queue_prop_header properties[0]; /* List of properties. */
1790};
1791OFP_ASSERT(sizeof(struct ofp_packet_queue) == 16);
1792
1793/* Query for port queue configuration. */
1794struct ofp_queue_get_config_request {
1795 struct ofp_header header;
1796 uint32_t port; /* Port to be queried. Should refer
1797 to a valid physical port (i.e. < OFPP_MAX),
1798 or OFPP_ANY to request all configured
1799 queues.*/
1800 uint8_t pad[4];
1801};
1802OFP_ASSERT(sizeof(struct ofp_queue_get_config_request) == 16);
1803
1804/* Queue configuration for a given port. */
1805struct ofp_queue_get_config_reply {
1806 struct ofp_header header;
1807 uint32_t port;
1808 uint8_t pad[4];
1809 struct ofp_packet_queue queues[0]; /* List of configured queues. */
1810};
1811OFP_ASSERT(sizeof(struct ofp_queue_get_config_reply) == 16);
1812
1813/* OFPAT_SET_QUEUE action struct: send packets to given queue on port. */
1814struct ofp_action_set_queue {
1815 uint16_t type; /* OFPAT_SET_QUEUE. */
1816 uint16_t len; /* Len is 8. */
1817 uint32_t queue_id; /* Queue id for the packets. */
1818};
1819OFP_ASSERT(sizeof(struct ofp_action_set_queue) == 8);
1820
1821struct ofp_queue_stats_request {
1822 uint32_t port_no; /* All ports if OFPP_ANY. */
1823 uint32_t queue_id; /* All queues if OFPQ_ALL. */
1824};
1825OFP_ASSERT(sizeof(struct ofp_queue_stats_request) == 8);
1826
1827struct ofp_queue_stats {
1828 uint32_t port_no;
1829 uint32_t queue_id; /* Queue i.d */
1830 uint64_t tx_bytes; /* Number of transmitted bytes. */
1831 uint64_t tx_packets; /* Number of transmitted packets. */
1832 uint64_t tx_errors; /* Number of packets dropped due to overrun. */
1833};
1834OFP_ASSERT(sizeof(struct ofp_queue_stats) == 32);
1835
1836/* Configures the "role" of the sending controller. The default role is:
1837 *
1838 * - Equal (NX_ROLE_EQUAL), which allows the controller access to all
1839 * OpenFlow features. All controllers have equal responsibility.
1840 *
1841 * The other possible roles are a related pair:
1842 *
1843 * - Master (NX_ROLE_MASTER) is equivalent to Equal, except that there may
1844 * be at most one Master controller at a time: when a controller
1845 * configures itself as Master, any existing Master is demoted to the
1846 * Slave role.
1847 *
1848 * - Slave (NX_ROLE_SLAVE) allows the controller read-only access to
1849 * OpenFlow features. In particular attempts to modify the flow table
1850 * will be rejected with an OFPBRC_EPERM error.
1851 *
1852 * Slave controllers do not receive OFPT_PACKET_IN or OFPT_FLOW_REMOVED
1853 * messages, but they do receive OFPT_PORT_STATUS messages.
1854 */
1855
1856/* Controller roles. */
1857enum ofp_controller_role {
1858 OFPCR_ROLE_NOCHANGE = 0, /* Don't change current role. */
1859 OFPCR_ROLE_EQUAL = 1, /* Default role, full access. */
1860 OFPCR_ROLE_MASTER = 2, /* Full access, at most one master. */
1861 OFPCR_ROLE_SLAVE = 3, /* Read-only access. */
1862};
1863
1864/* Role request and reply message. */
1865struct ofp_role_request {
1866 struct ofp_header header; /* Type OFPT_ROLE_REQUEST/OFPT_ROLE_REPLY. */
1867 uint32_t role; /* One of NX_ROLE_*. */
1868 uint8_t pad[4]; /* Align to 64 bits. */
1869 uint64_t generation_id; /* Master Election Generation Id */
1870};
1871OFP_ASSERT(sizeof(struct ofp_role_request) == 24);
1872
1873#endif /* openflow/openflow.h */