blob: c0b5090d19069774344f21bb9776b5b1a306cf29 [file] [log] [blame]
Dan Talaycof75360a2010-02-05 22:22:54 -08001/* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2 * Junior University
3 *
4 * We are making the OpenFlow specification and associated documentation
5 * (Software) available for public use and benefit with the expectation
6 * that others will use, modify and enhance the Software and contribute
7 * those enhancements back to the community. However, since we would
8 * like to make the Software available for broadest use, with as few
9 * restrictions as possible permission is hereby granted, free of
10 * charge, to any person obtaining a copy of this Software to deal in
11 * the Software under the copyrights without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, sublicense, and/or sell copies of the Software, and to
14 * permit persons to whom the Software is furnished to do so, subject to
15 * the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 *
29 * The name and trademarks of copyright holder(s) may NOT be used in
30 * advertising or publicity pertaining to the Software or any
31 * derivatives without specific, written prior permission.
32 */
33
34/* OpenFlow: protocol between controller and datapath. */
35
36#ifndef OPENFLOW_OPENFLOW_H
37#define OPENFLOW_OPENFLOW_H 1
38
39#ifdef __KERNEL__
40#include <linux/types.h>
41#else
42#include <stdint.h>
43#endif
44
45#ifdef SWIG
46#define OFP_ASSERT(EXPR) /* SWIG can't handle OFP_ASSERT. */
47#elif !defined(__cplusplus)
48/* Build-time assertion for use in a declaration context. */
49#define OFP_ASSERT(EXPR) \
50 extern int (*build_assert(void))[ sizeof(struct { \
51 unsigned int build_assert_failed : (EXPR) ? 1 : -1; })]
52#else /* __cplusplus */
53#define OFP_ASSERT(_EXPR) typedef int build_assert_failed[(_EXPR) ? 1 : -1]
54#endif /* __cplusplus */
55
56#ifndef SWIG
57#define OFP_PACKED __attribute__((packed))
58#else
59#define OFP_PACKED /* SWIG doesn't understand __attribute. */
60#endif
61
62/* Version number:
63 * Non-experimental versions released: 0x01
64 * Experimental versions released: 0x81 -- 0x99
65 */
66/* The most significant bit being set in the version field indicates an
67 * experimental OpenFlow version.
68 */
Dan Talayco88bea172010-02-19 12:28:06 -080069#define OFP_VERSION 0x01
Dan Talaycof75360a2010-02-05 22:22:54 -080070
71#define OFP_MAX_TABLE_NAME_LEN 32
72#define OFP_MAX_PORT_NAME_LEN 16
73
74#define OFP_TCP_PORT 6633
75#define OFP_SSL_PORT 6633
76
77#define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
78
79/* Port numbering. Physical ports are numbered starting from 1. */
80enum ofp_port {
81 /* Maximum number of physical switch ports. */
82 OFPP_MAX = 0xff00,
83
84 /* Fake output "ports". */
85 OFPP_IN_PORT = 0xfff8, /* Send the packet out the input port. This
86 virtual port must be explicitly used
87 in order to send back out of the input
88 port. */
89 OFPP_TABLE = 0xfff9, /* Perform actions in flow table.
90 NB: This can only be the destination
91 port for packet-out messages. */
92 OFPP_NORMAL = 0xfffa, /* Process with normal L2/L3 switching. */
93 OFPP_FLOOD = 0xfffb, /* All physical ports except input port and
94 those disabled by STP. */
95 OFPP_ALL = 0xfffc, /* All physical ports except input port. */
96 OFPP_CONTROLLER = 0xfffd, /* Send to controller. */
97 OFPP_LOCAL = 0xfffe, /* Local openflow "port". */
98 OFPP_NONE = 0xffff /* Not associated with a physical port. */
99};
100
101enum ofp_type {
102 /* Immutable messages. */
103 OFPT_HELLO, /* Symmetric message */
104 OFPT_ERROR, /* Symmetric message */
105 OFPT_ECHO_REQUEST, /* Symmetric message */
106 OFPT_ECHO_REPLY, /* Symmetric message */
107 OFPT_VENDOR, /* Symmetric message */
108
109 /* Switch configuration messages. */
110 OFPT_FEATURES_REQUEST, /* Controller/switch message */
111 OFPT_FEATURES_REPLY, /* Controller/switch message */
112 OFPT_GET_CONFIG_REQUEST, /* Controller/switch message */
113 OFPT_GET_CONFIG_REPLY, /* Controller/switch message */
114 OFPT_SET_CONFIG, /* Controller/switch message */
115
116 /* Asynchronous messages. */
117 OFPT_PACKET_IN, /* Async message */
118 OFPT_FLOW_REMOVED, /* Async message */
119 OFPT_PORT_STATUS, /* Async message */
120
121 /* Controller command messages. */
122 OFPT_PACKET_OUT, /* Controller/switch message */
123 OFPT_FLOW_MOD, /* Controller/switch message */
124 OFPT_PORT_MOD, /* Controller/switch message */
125
126 /* Statistics messages. */
127 OFPT_STATS_REQUEST, /* Controller/switch message */
128 OFPT_STATS_REPLY, /* Controller/switch message */
129
130 /* Barrier messages. */
131 OFPT_BARRIER_REQUEST, /* Controller/switch message */
132 OFPT_BARRIER_REPLY, /* Controller/switch message */
133
134 /* Queue Configuration messages. */
135 OFPT_QUEUE_GET_CONFIG_REQUEST, /* Controller/switch message */
136 OFPT_QUEUE_GET_CONFIG_REPLY /* Controller/switch message */
137
138};
139
140/* Header on all OpenFlow packets. */
141struct ofp_header {
142 uint8_t version; /* OFP_VERSION. */
143 uint8_t type; /* One of the OFPT_ constants. */
144 uint16_t length; /* Length including this ofp_header. */
145 uint32_t xid; /* Transaction id associated with this packet.
146 Replies use the same id as was in the request
147 to facilitate pairing. */
148};
149OFP_ASSERT(sizeof(struct ofp_header) == 8);
150
151/* OFPT_HELLO. This message has an empty body, but implementations must
152 * ignore any data included in the body, to allow for future extensions. */
153struct ofp_hello {
154 struct ofp_header header;
155};
156
157#define OFP_DEFAULT_MISS_SEND_LEN 128
158
159enum ofp_config_flags {
160 /* Handling of IP fragments. */
161 OFPC_FRAG_NORMAL = 0, /* No special handling for fragments. */
162 OFPC_FRAG_DROP = 1, /* Drop fragments. */
163 OFPC_FRAG_REASM = 2, /* Reassemble (only if OFPC_IP_REASM set). */
164 OFPC_FRAG_MASK = 3
165};
166
167/* Switch configuration. */
168struct ofp_switch_config {
169 struct ofp_header header;
170 uint16_t flags; /* OFPC_* flags. */
171 uint16_t miss_send_len; /* Max bytes of new flow that datapath should
172 send to the controller. */
173};
174OFP_ASSERT(sizeof(struct ofp_switch_config) == 12);
175
176/* Capabilities supported by the datapath. */
177enum ofp_capabilities {
178 OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
179 OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
180 OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
181 OFPC_STP = 1 << 3, /* 802.1d spanning tree. */
182 OFPC_RESERVED = 1 << 4, /* Reserved, must be zero. */
183 OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
184 OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */
185 OFPC_ARP_MATCH_IP = 1 << 7 /* Match IP addresses in ARP pkts. */
186};
187
188/* Flags to indicate behavior of the physical port. These flags are
189 * used in ofp_phy_port to describe the current configuration. They are
190 * used in the ofp_port_mod message to configure the port's behavior.
191 */
192enum ofp_port_config {
193 OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
194
195 OFPPC_NO_STP = 1 << 1, /* Disable 802.1D spanning tree on port. */
196 OFPPC_NO_RECV = 1 << 2, /* Drop all packets except 802.1D spanning
197 tree packets. */
198 OFPPC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
199 OFPPC_NO_FLOOD = 1 << 4, /* Do not include this port when flooding. */
200 OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
201 OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
202};
203
204/* Current state of the physical port. These are not configurable from
205 * the controller.
206 */
207enum ofp_port_state {
208 OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
209
210 /* The OFPPS_STP_* bits have no effect on switch operation. The
211 * controller must adjust OFPPC_NO_RECV, OFPPC_NO_FWD, and
212 * OFPPC_NO_PACKET_IN appropriately to fully implement an 802.1D spanning
213 * tree. */
214 OFPPS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
215 OFPPS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
216 OFPPS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
217 OFPPS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
218 OFPPS_STP_MASK = 3 << 8 /* Bit mask for OFPPS_STP_* values. */
219};
220
221/* Features of physical ports available in a datapath. */
222enum ofp_port_features {
223 OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
224 OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
225 OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
226 OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
227 OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
228 OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
229 OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
230 OFPPF_COPPER = 1 << 7, /* Copper medium. */
231 OFPPF_FIBER = 1 << 8, /* Fiber medium. */
232 OFPPF_AUTONEG = 1 << 9, /* Auto-negotiation. */
233 OFPPF_PAUSE = 1 << 10, /* Pause. */
234 OFPPF_PAUSE_ASYM = 1 << 11 /* Asymmetric pause. */
235};
236
237/* Description of a physical port */
238struct ofp_phy_port {
239 uint16_t port_no;
240 uint8_t hw_addr[OFP_ETH_ALEN];
241 char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
242
243 uint32_t config; /* Bitmap of OFPPC_* flags. */
244 uint32_t state; /* Bitmap of OFPPS_* flags. */
245
246 /* Bitmaps of OFPPF_* that describe features. All bits zeroed if
247 * unsupported or unavailable. */
248 uint32_t curr; /* Current features. */
249 uint32_t advertised; /* Features being advertised by the port. */
250 uint32_t supported; /* Features supported by the port. */
251 uint32_t peer; /* Features advertised by peer. */
252};
253OFP_ASSERT(sizeof(struct ofp_phy_port) == 48);
254
255/* Switch features. */
256struct ofp_switch_features {
257 struct ofp_header header;
258 uint64_t datapath_id; /* Datapath unique ID. The lower 48-bits are for
259 a MAC address, while the upper 16-bits are
260 implementer-defined. */
261
262 uint32_t n_buffers; /* Max packets buffered at once. */
263
264 uint8_t n_tables; /* Number of tables supported by datapath. */
265 uint8_t pad[3]; /* Align to 64-bits. */
266
267 /* Features. */
268 uint32_t capabilities; /* Bitmap of support "ofp_capabilities". */
269 uint32_t actions; /* Bitmap of supported "ofp_action_type"s. */
270
271 /* Port info.*/
272 struct ofp_phy_port ports[0]; /* Port definitions. The number of ports
273 is inferred from the length field in
274 the header. */
275};
276OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
277
278/* What changed about the physical port */
279enum ofp_port_reason {
280 OFPPR_ADD, /* The port was added. */
281 OFPPR_DELETE, /* The port was removed. */
282 OFPPR_MODIFY /* Some attribute of the port has changed. */
283};
284
285/* A physical port has changed in the datapath */
286struct ofp_port_status {
287 struct ofp_header header;
288 uint8_t reason; /* One of OFPPR_*. */
289 uint8_t pad[7]; /* Align to 64-bits. */
290 struct ofp_phy_port desc;
291};
292OFP_ASSERT(sizeof(struct ofp_port_status) == 64);
293
294/* Modify behavior of the physical port */
295struct ofp_port_mod {
296 struct ofp_header header;
297 uint16_t port_no;
298 uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
299 configurable. This is used to
300 sanity-check the request, so it must
301 be the same as returned in an
302 ofp_phy_port struct. */
303
304 uint32_t config; /* Bitmap of OFPPC_* flags. */
305 uint32_t mask; /* Bitmap of OFPPC_* flags to be changed. */
306
307 uint32_t advertise; /* Bitmap of "ofp_port_features"s. Zero all
308 bits to prevent any action taking place. */
309 uint8_t pad[4]; /* Pad to 64-bits. */
310};
311OFP_ASSERT(sizeof(struct ofp_port_mod) == 32);
312
313/* Why is this packet being sent to the controller? */
314enum ofp_packet_in_reason {
315 OFPR_NO_MATCH, /* No matching flow. */
316 OFPR_ACTION /* Action explicitly output to controller. */
317};
318
319/* Packet received on port (datapath -> controller). */
320struct ofp_packet_in {
321 struct ofp_header header;
322 uint32_t buffer_id; /* ID assigned by datapath. */
323 uint16_t total_len; /* Full length of frame. */
324 uint16_t in_port; /* Port on which frame was received. */
325 uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
326 uint8_t pad;
327 uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word,
328 so the IP header is 32-bit aligned. The
329 amount of data is inferred from the length
330 field in the header. Because of padding,
331 offsetof(struct ofp_packet_in, data) ==
332 sizeof(struct ofp_packet_in) - 2. */
333};
334OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);
335
336enum ofp_action_type {
337 OFPAT_OUTPUT, /* Output to switch port. */
338 OFPAT_SET_VLAN_VID, /* Set the 802.1q VLAN id. */
339 OFPAT_SET_VLAN_PCP, /* Set the 802.1q priority. */
340 OFPAT_STRIP_VLAN, /* Strip the 802.1q header. */
341 OFPAT_SET_DL_SRC, /* Ethernet source address. */
342 OFPAT_SET_DL_DST, /* Ethernet destination address. */
343 OFPAT_SET_NW_SRC, /* IP source address. */
344 OFPAT_SET_NW_DST, /* IP destination address. */
345 OFPAT_SET_NW_TOS, /* IP ToS (DSCP field, 6 bits). */
346 OFPAT_SET_TP_SRC, /* TCP/UDP source port. */
347 OFPAT_SET_TP_DST, /* TCP/UDP destination port. */
348 OFPAT_ENQUEUE, /* Output to queue. */
349 OFPAT_VENDOR = 0xffff
350};
351
352/* Action structure for OFPAT_OUTPUT, which sends packets out 'port'.
353 * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
354 * number of bytes to send. A 'max_len' of zero means no bytes of the
355 * packet should be sent.*/
356struct ofp_action_output {
357 uint16_t type; /* OFPAT_OUTPUT. */
358 uint16_t len; /* Length is 8. */
359 uint16_t port; /* Output port. */
360 uint16_t max_len; /* Max length to send to controller. */
361};
362OFP_ASSERT(sizeof(struct ofp_action_output) == 8);
363
364/* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
365 * special conditions. All ones is used to match that no VLAN id was
366 * set. */
367#define OFP_VLAN_NONE 0xffff
368
369/* Action structure for OFPAT_SET_VLAN_VID. */
370struct ofp_action_vlan_vid {
371 uint16_t type; /* OFPAT_SET_VLAN_VID. */
372 uint16_t len; /* Length is 8. */
373 uint16_t vlan_vid; /* VLAN id. */
374 uint8_t pad[2];
375};
376OFP_ASSERT(sizeof(struct ofp_action_vlan_vid) == 8);
377
378/* Action structure for OFPAT_SET_VLAN_PCP. */
379struct ofp_action_vlan_pcp {
380 uint16_t type; /* OFPAT_SET_VLAN_PCP. */
381 uint16_t len; /* Length is 8. */
382 uint8_t vlan_pcp; /* VLAN priority. */
383 uint8_t pad[3];
384};
385OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp) == 8);
386
387/* Action structure for OFPAT_SET_DL_SRC/DST. */
388struct ofp_action_dl_addr {
389 uint16_t type; /* OFPAT_SET_DL_SRC/DST. */
390 uint16_t len; /* Length is 16. */
391 uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */
392 uint8_t pad[6];
393};
394OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
395
396/* Action structure for OFPAT_SET_NW_SRC/DST. */
397struct ofp_action_nw_addr {
398 uint16_t type; /* OFPAT_SET_TW_SRC/DST. */
399 uint16_t len; /* Length is 8. */
400 uint32_t nw_addr; /* IP address. */
401};
402OFP_ASSERT(sizeof(struct ofp_action_nw_addr) == 8);
403
404/* Action structure for OFPAT_SET_TP_SRC/DST. */
405struct ofp_action_tp_port {
406 uint16_t type; /* OFPAT_SET_TP_SRC/DST. */
407 uint16_t len; /* Length is 8. */
408 uint16_t tp_port; /* TCP/UDP port. */
409 uint8_t pad[2];
410};
411OFP_ASSERT(sizeof(struct ofp_action_tp_port) == 8);
412
413/* Action structure for OFPAT_SET_NW_TOS. */
414struct ofp_action_nw_tos {
415 uint16_t type; /* OFPAT_SET_TW_SRC/DST. */
416 uint16_t len; /* Length is 8. */
417 uint8_t nw_tos; /* IP ToS (DSCP field, 6 bits). */
418 uint8_t pad[3];
419};
420OFP_ASSERT(sizeof(struct ofp_action_nw_tos) == 8);
421
422/* Action header for OFPAT_VENDOR. The rest of the body is vendor-defined. */
423struct ofp_action_vendor_header {
424 uint16_t type; /* OFPAT_VENDOR. */
425 uint16_t len; /* Length is a multiple of 8. */
426 uint32_t vendor; /* Vendor ID, which takes the same form
427 as in "struct ofp_vendor_header". */
428};
429OFP_ASSERT(sizeof(struct ofp_action_vendor_header) == 8);
430
431/* Action header that is common to all actions. The length includes the
432 * header and any padding used to make the action 64-bit aligned.
433 * NB: The length of an action *must* always be a multiple of eight. */
434struct ofp_action_header {
435 uint16_t type; /* One of OFPAT_*. */
436 uint16_t len; /* Length of action, including this
437 header. This is the length of action,
438 including any padding to make it
439 64-bit aligned. */
440 uint8_t pad[4];
441};
442OFP_ASSERT(sizeof(struct ofp_action_header) == 8);
443
444/* Send packet (controller -> datapath). */
445struct ofp_packet_out {
446 struct ofp_header header;
447 uint32_t buffer_id; /* ID assigned by datapath (-1 if none). */
448 uint16_t in_port; /* Packet's input port (OFPP_NONE if none). */
449 uint16_t actions_len; /* Size of action array in bytes. */
450 struct ofp_action_header actions[0]; /* Actions. */
451 /* uint8_t data[0]; */ /* Packet data. The length is inferred
452 from the length field in the header.
453 (Only meaningful if buffer_id == -1.) */
454};
455OFP_ASSERT(sizeof(struct ofp_packet_out) == 16);
456
457enum ofp_flow_mod_command {
458 OFPFC_ADD, /* New flow. */
459 OFPFC_MODIFY, /* Modify all matching flows. */
460 OFPFC_MODIFY_STRICT, /* Modify entry strictly matching wildcards */
461 OFPFC_DELETE, /* Delete all matching flows. */
462 OFPFC_DELETE_STRICT /* Strictly match wildcards and priority. */
463};
464
465/* Flow wildcards. */
466enum ofp_flow_wildcards {
467 OFPFW_IN_PORT = 1 << 0, /* Switch input port. */
468 OFPFW_DL_VLAN = 1 << 1, /* VLAN id. */
469 OFPFW_DL_SRC = 1 << 2, /* Ethernet source address. */
470 OFPFW_DL_DST = 1 << 3, /* Ethernet destination address. */
471 OFPFW_DL_TYPE = 1 << 4, /* Ethernet frame type. */
472 OFPFW_NW_PROTO = 1 << 5, /* IP protocol. */
473 OFPFW_TP_SRC = 1 << 6, /* TCP/UDP source port. */
474 OFPFW_TP_DST = 1 << 7, /* TCP/UDP destination port. */
475
476 /* IP source address wildcard bit count. 0 is exact match, 1 ignores the
477 * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
478 * the entire field. This is the *opposite* of the usual convention where
479 * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded. */
480 OFPFW_NW_SRC_SHIFT = 8,
481 OFPFW_NW_SRC_BITS = 6,
482 OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT,
483 OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT,
484
485 /* IP destination address wildcard bit count. Same format as source. */
486 OFPFW_NW_DST_SHIFT = 14,
487 OFPFW_NW_DST_BITS = 6,
488 OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT,
489 OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT,
490
491 OFPFW_DL_VLAN_PCP = 1 << 20, /* VLAN priority. */
492 OFPFW_NW_TOS = 1 << 21, /* IP ToS (DSCP field, 6 bits). */
493
494 /* Wildcard all fields. */
495 OFPFW_ALL = ((1 << 22) - 1)
496};
497
498/* The wildcards for ICMP type and code fields use the transport source
499 * and destination port fields, respectively. */
500#define OFPFW_ICMP_TYPE OFPFW_TP_SRC
501#define OFPFW_ICMP_CODE OFPFW_TP_DST
502
503/* Values below this cutoff are 802.3 packets and the two bytes
504 * following MAC addresses are used as a frame length. Otherwise, the
505 * two bytes are used as the Ethernet type.
506 */
507#define OFP_DL_TYPE_ETH2_CUTOFF 0x0600
508
509/* Value of dl_type to indicate that the frame does not include an
510 * Ethernet type.
511 */
512#define OFP_DL_TYPE_NOT_ETH_TYPE 0x05ff
513
514/* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
515 * special conditions. All ones indicates that no VLAN id was set.
516 */
517#define OFP_VLAN_NONE 0xffff
518
519/* Fields to match against flows */
520struct ofp_match {
521 uint32_t wildcards; /* Wildcard fields. */
522 uint16_t in_port; /* Input switch port. */
523 uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
524 uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
525 uint16_t dl_vlan; /* Input VLAN id. */
526 uint8_t dl_vlan_pcp; /* Input VLAN priority. */
527 uint8_t pad1[1]; /* Align to 64-bits */
528 uint16_t dl_type; /* Ethernet frame type. */
529 uint8_t nw_tos; /* IP ToS (actually DSCP field, 6 bits). */
530 uint8_t nw_proto; /* IP protocol or lower 8 bits of
531 * ARP opcode. */
532 uint8_t pad2[2]; /* Align to 64-bits */
533 uint32_t nw_src; /* IP source address. */
534 uint32_t nw_dst; /* IP destination address. */
535 uint16_t tp_src; /* TCP/UDP source port. */
536 uint16_t tp_dst; /* TCP/UDP destination port. */
537};
538OFP_ASSERT(sizeof(struct ofp_match) == 40);
539
540/* The match fields for ICMP type and code use the transport source and
541 * destination port fields, respectively. */
542#define icmp_type tp_src
543#define icmp_code tp_dst
544
545/* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
546 * is permanent. */
547#define OFP_FLOW_PERMANENT 0
548
549/* By default, choose a priority in the middle. */
550#define OFP_DEFAULT_PRIORITY 0x8000
551
552enum ofp_flow_mod_flags {
553 OFPFF_SEND_FLOW_REM = 1 << 0, /* Send flow removed message when flow
554 * expires or is deleted. */
555 OFPFF_CHECK_OVERLAP = 1 << 1, /* Check for overlapping entries first. */
556 OFPFF_EMERG = 1 << 2 /* Remark this is for emergency. */
557};
558
559/* Flow setup and teardown (controller -> datapath). */
560struct ofp_flow_mod {
561 struct ofp_header header;
562 struct ofp_match match; /* Fields to match */
563 uint64_t cookie; /* Opaque controller-issued identifier. */
564
565 /* Flow actions. */
566 uint16_t command; /* One of OFPFC_*. */
567 uint16_t idle_timeout; /* Idle time before discarding (seconds). */
568 uint16_t hard_timeout; /* Max time before discarding (seconds). */
569 uint16_t priority; /* Priority level of flow entry. */
570 uint32_t buffer_id; /* Buffered packet to apply to (or -1).
571 Not meaningful for OFPFC_DELETE*. */
572 uint16_t out_port; /* For OFPFC_DELETE* commands, require
573 matching entries to include this as an
574 output port. A value of OFPP_NONE
575 indicates no restriction. */
576 uint16_t flags; /* One of OFPFF_*. */
577 struct ofp_action_header actions[0]; /* The action length is inferred
578 from the length field in the
579 header. */
580};
581OFP_ASSERT(sizeof(struct ofp_flow_mod) == 72);
582
583/* Why was this flow removed? */
584enum ofp_flow_removed_reason {
585 OFPRR_IDLE_TIMEOUT, /* Flow idle time exceeded idle_timeout. */
586 OFPRR_HARD_TIMEOUT, /* Time exceeded hard_timeout. */
587 OFPRR_DELETE /* Evicted by a DELETE flow mod. */
588};
589
590/* Flow removed (datapath -> controller). */
591struct ofp_flow_removed {
592 struct ofp_header header;
593 struct ofp_match match; /* Description of fields. */
594 uint64_t cookie; /* Opaque controller-issued identifier. */
595
596 uint16_t priority; /* Priority level of flow entry. */
597 uint8_t reason; /* One of OFPRR_*. */
598 uint8_t pad[1]; /* Align to 32-bits. */
599
600 uint32_t duration_sec; /* Time flow was alive in seconds. */
601 uint32_t duration_nsec; /* Time flow was alive in nanoseconds beyond
602 duration_sec. */
603 uint16_t idle_timeout; /* Idle timeout from original flow mod. */
604 uint8_t pad2[2]; /* Align to 64-bits. */
605 uint64_t packet_count;
606 uint64_t byte_count;
607};
608OFP_ASSERT(sizeof(struct ofp_flow_removed) == 88);
609
610/* Values for 'type' in ofp_error_message. These values are immutable: they
611 * will not change in future versions of the protocol (although new values may
612 * be added). */
613enum ofp_error_type {
614 OFPET_HELLO_FAILED, /* Hello protocol failed. */
615 OFPET_BAD_REQUEST, /* Request was not understood. */
616 OFPET_BAD_ACTION, /* Error in action description. */
617 OFPET_FLOW_MOD_FAILED, /* Problem modifying flow entry. */
618 OFPET_PORT_MOD_FAILED, /* Port mod request failed. */
619 OFPET_QUEUE_OP_FAILED /* Queue operation failed. */
620};
621
622/* ofp_error_msg 'code' values for OFPET_HELLO_FAILED. 'data' contains an
623 * ASCII text string that may give failure details. */
624enum ofp_hello_failed_code {
625 OFPHFC_INCOMPATIBLE, /* No compatible version. */
626 OFPHFC_EPERM /* Permissions error. */
627};
628
629/* ofp_error_msg 'code' values for OFPET_BAD_REQUEST. 'data' contains at least
630 * the first 64 bytes of the failed request. */
631enum ofp_bad_request_code {
632 OFPBRC_BAD_VERSION, /* ofp_header.version not supported. */
633 OFPBRC_BAD_TYPE, /* ofp_header.type not supported. */
634 OFPBRC_BAD_STAT, /* ofp_stats_request.type not supported. */
635 OFPBRC_BAD_VENDOR, /* Vendor not supported (in ofp_vendor_header
636 * or ofp_stats_request or ofp_stats_reply). */
637 OFPBRC_BAD_SUBTYPE, /* Vendor subtype not supported. */
638 OFPBRC_EPERM, /* Permissions error. */
639 OFPBRC_BAD_LEN, /* Wrong request length for type. */
640 OFPBRC_BUFFER_EMPTY, /* Specified buffer has already been used. */
641 OFPBRC_BUFFER_UNKNOWN /* Specified buffer does not exist. */
642};
643
644/* ofp_error_msg 'code' values for OFPET_BAD_ACTION. 'data' contains at least
645 * the first 64 bytes of the failed request. */
646enum ofp_bad_action_code {
647 OFPBAC_BAD_TYPE, /* Unknown action type. */
648 OFPBAC_BAD_LEN, /* Length problem in actions. */
649 OFPBAC_BAD_VENDOR, /* Unknown vendor id specified. */
650 OFPBAC_BAD_VENDOR_TYPE, /* Unknown action type for vendor id. */
651 OFPBAC_BAD_OUT_PORT, /* Problem validating output action. */
652 OFPBAC_BAD_ARGUMENT, /* Bad action argument. */
653 OFPBAC_EPERM, /* Permissions error. */
654 OFPBAC_TOO_MANY, /* Can't handle this many actions. */
655 OFPBAC_BAD_QUEUE /* Problem validating output queue. */
656};
657
658/* ofp_error_msg 'code' values for OFPET_FLOW_MOD_FAILED. 'data' contains
659 * at least the first 64 bytes of the failed request. */
660enum ofp_flow_mod_failed_code {
661 OFPFMFC_ALL_TABLES_FULL, /* Flow not added because of full tables. */
662 OFPFMFC_OVERLAP, /* Attempted to add overlapping flow with
663 * CHECK_OVERLAP flag set. */
664 OFPFMFC_EPERM, /* Permissions error. */
665 OFPFMFC_BAD_EMERG_TIMEOUT, /* Flow not added because of non-zero idle/hard
666 * timeout. */
667 OFPFMFC_BAD_COMMAND, /* Unknown command. */
668 OFPFMFC_UNSUPPORTED /* Unsupported action list - cannot process in
669 * the order specified. */
670};
671
672/* ofp_error_msg 'code' values for OFPET_PORT_MOD_FAILED. 'data' contains
673 * at least the first 64 bytes of the failed request. */
674enum ofp_port_mod_failed_code {
675 OFPPMFC_BAD_PORT, /* Specified port does not exist. */
676 OFPPMFC_BAD_HW_ADDR, /* Specified hardware address is wrong. */
677};
678
679/* ofp_error msg 'code' values for OFPET_QUEUE_OP_FAILED. 'data' contains
680 * at least the first 64 bytes of the failed request */
681enum ofp_queue_op_failed_code {
682 OFPQOFC_BAD_PORT, /* Invalid port (or port does not exist). */
683 OFPQOFC_BAD_QUEUE, /* Queue does not exist. */
684 OFPQOFC_EPERM /* Permissions error. */
685};
686
687/* OFPT_ERROR: Error message (datapath -> controller). */
688struct ofp_error_msg {
689 struct ofp_header header;
690
691 uint16_t type;
692 uint16_t code;
693 uint8_t data[0]; /* Variable-length data. Interpreted based
694 on the type and code. */
695};
696OFP_ASSERT(sizeof(struct ofp_error_msg) == 12);
697
698enum ofp_stats_types {
699 /* Description of this OpenFlow switch.
700 * The request body is empty.
701 * The reply body is struct ofp_desc_stats. */
702 OFPST_DESC,
703
704 /* Individual flow statistics.
705 * The request body is struct ofp_flow_stats_request.
706 * The reply body is an array of struct ofp_flow_stats. */
707 OFPST_FLOW,
708
709 /* Aggregate flow statistics.
710 * The request body is struct ofp_aggregate_stats_request.
711 * The reply body is struct ofp_aggregate_stats_reply. */
712 OFPST_AGGREGATE,
713
714 /* Flow table statistics.
715 * The request body is empty.
716 * The reply body is an array of struct ofp_table_stats. */
717 OFPST_TABLE,
718
719 /* Physical port statistics.
720 * The request body is struct ofp_port_stats_request.
721 * The reply body is an array of struct ofp_port_stats. */
722 OFPST_PORT,
723
724 /* Queue statistics for a port
725 * The request body defines the port
726 * The reply body is an array of struct ofp_queue_stats */
727 OFPST_QUEUE,
728
729 /* Vendor extension.
730 * The request and reply bodies begin with a 32-bit vendor ID, which takes
731 * the same form as in "struct ofp_vendor_header". The request and reply
732 * bodies are otherwise vendor-defined. */
733 OFPST_VENDOR = 0xffff
734};
735
736struct ofp_stats_request {
737 struct ofp_header header;
738 uint16_t type; /* One of the OFPST_* constants. */
739 uint16_t flags; /* OFPSF_REQ_* flags (none yet defined). */
740 uint8_t body[0]; /* Body of the request. */
741};
742OFP_ASSERT(sizeof(struct ofp_stats_request) == 12);
743
744enum ofp_stats_reply_flags {
745 OFPSF_REPLY_MORE = 1 << 0 /* More replies to follow. */
746};
747
748struct ofp_stats_reply {
749 struct ofp_header header;
750 uint16_t type; /* One of the OFPST_* constants. */
751 uint16_t flags; /* OFPSF_REPLY_* flags. */
752 uint8_t body[0]; /* Body of the reply. */
753};
754OFP_ASSERT(sizeof(struct ofp_stats_reply) == 12);
755
756#define DESC_STR_LEN 256
757#define SERIAL_NUM_LEN 32
758/* Body of reply to OFPST_DESC request. Each entry is a NULL-terminated
759 * ASCII string. */
760struct ofp_desc_stats {
761 char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */
762 char hw_desc[DESC_STR_LEN]; /* Hardware description. */
763 char sw_desc[DESC_STR_LEN]; /* Software description. */
764 char serial_num[SERIAL_NUM_LEN]; /* Serial number. */
765 char dp_desc[DESC_STR_LEN]; /* Human readable description of datapath. */
766};
767OFP_ASSERT(sizeof(struct ofp_desc_stats) == 1056);
768
769/* Body for ofp_stats_request of type OFPST_FLOW. */
770struct ofp_flow_stats_request {
771 struct ofp_match match; /* Fields to match. */
772 uint8_t table_id; /* ID of table to read (from ofp_table_stats),
773 0xff for all tables or 0xfe for emergency. */
774 uint8_t pad; /* Align to 32 bits. */
775 uint16_t out_port; /* Require matching entries to include this
776 as an output port. A value of OFPP_NONE
777 indicates no restriction. */
778};
779OFP_ASSERT(sizeof(struct ofp_flow_stats_request) == 44);
780
781/* Body of reply to OFPST_FLOW request. */
782struct ofp_flow_stats {
783 uint16_t length; /* Length of this entry. */
784 uint8_t table_id; /* ID of table flow came from. */
785 uint8_t pad;
786 struct ofp_match match; /* Description of fields. */
787 uint32_t duration_sec; /* Time flow has been alive in seconds. */
788 uint32_t duration_nsec; /* Time flow has been alive in nanoseconds beyond
789 duration_sec. */
790 uint16_t priority; /* Priority of the entry. Only meaningful
791 when this is not an exact-match entry. */
792 uint16_t idle_timeout; /* Number of seconds idle before expiration. */
793 uint16_t hard_timeout; /* Number of seconds before expiration. */
794 uint8_t pad2[6]; /* Align to 64-bits. */
795 uint64_t cookie; /* Opaque controller-issued identifier. */
796 uint64_t packet_count; /* Number of packets in flow. */
797 uint64_t byte_count; /* Number of bytes in flow. */
798 struct ofp_action_header actions[0]; /* Actions. */
799};
800OFP_ASSERT(sizeof(struct ofp_flow_stats) == 88);
801
802/* Body for ofp_stats_request of type OFPST_AGGREGATE. */
803struct ofp_aggregate_stats_request {
804 struct ofp_match match; /* Fields to match. */
805 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
806 0xff for all tables or 0xfe for emergency. */
807 uint8_t pad; /* Align to 32 bits. */
808 uint16_t out_port; /* Require matching entries to include this
809 as an output port. A value of OFPP_NONE
810 indicates no restriction. */
811};
812OFP_ASSERT(sizeof(struct ofp_aggregate_stats_request) == 44);
813
814/* Body of reply to OFPST_AGGREGATE request. */
815struct ofp_aggregate_stats_reply {
816 uint64_t packet_count; /* Number of packets in flows. */
817 uint64_t byte_count; /* Number of bytes in flows. */
818 uint32_t flow_count; /* Number of flows. */
819 uint8_t pad[4]; /* Align to 64 bits. */
820};
821OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
822
823/* Body of reply to OFPST_TABLE request. */
824struct ofp_table_stats {
825 uint8_t table_id; /* Identifier of table. Lower numbered tables
826 are consulted first. */
827 uint8_t pad[3]; /* Align to 32-bits. */
828 char name[OFP_MAX_TABLE_NAME_LEN];
829 uint32_t wildcards; /* Bitmap of OFPFW_* wildcards that are
830 supported by the table. */
831 uint32_t max_entries; /* Max number of entries supported. */
832 uint32_t active_count; /* Number of active entries. */
833 uint64_t lookup_count; /* Number of packets looked up in table. */
834 uint64_t matched_count; /* Number of packets that hit table. */
835};
836OFP_ASSERT(sizeof(struct ofp_table_stats) == 64);
837
838/* Body for ofp_stats_request of type OFPST_PORT. */
839struct ofp_port_stats_request {
840 uint16_t port_no; /* OFPST_PORT message must request statistics
841 * either for a single port (specified in
842 * port_no) or for all ports (if port_no ==
843 * OFPP_NONE). */
844 uint8_t pad[6];
845};
846OFP_ASSERT(sizeof(struct ofp_port_stats_request) == 8);
847
848/* Body of reply to OFPST_PORT request. If a counter is unsupported, set
849 * the field to all ones. */
850struct ofp_port_stats {
851 uint16_t port_no;
852 uint8_t pad[6]; /* Align to 64-bits. */
853 uint64_t rx_packets; /* Number of received packets. */
854 uint64_t tx_packets; /* Number of transmitted packets. */
855 uint64_t rx_bytes; /* Number of received bytes. */
856 uint64_t tx_bytes; /* Number of transmitted bytes. */
857 uint64_t rx_dropped; /* Number of packets dropped by RX. */
858 uint64_t tx_dropped; /* Number of packets dropped by TX. */
859 uint64_t rx_errors; /* Number of receive errors. This is a super-set
860 of more specific receive errors and should be
861 greater than or equal to the sum of all
862 rx_*_err values. */
863 uint64_t tx_errors; /* Number of transmit errors. This is a super-set
864 of more specific transmit errors and should be
865 greater than or equal to the sum of all
866 tx_*_err values (none currently defined.) */
867 uint64_t rx_frame_err; /* Number of frame alignment errors. */
868 uint64_t rx_over_err; /* Number of packets with RX overrun. */
869 uint64_t rx_crc_err; /* Number of CRC errors. */
870 uint64_t collisions; /* Number of collisions. */
871};
872OFP_ASSERT(sizeof(struct ofp_port_stats) == 104);
873
874/* Vendor extension. */
875struct ofp_vendor_header {
876 struct ofp_header header; /* Type OFPT_VENDOR. */
877 uint32_t vendor; /* Vendor ID:
878 * - MSB 0: low-order bytes are IEEE OUI.
879 * - MSB != 0: defined by OpenFlow
880 * consortium. */
881 /* Vendor-defined arbitrary additional data. */
882};
883OFP_ASSERT(sizeof(struct ofp_vendor_header) == 12);
884
885/* All ones is used to indicate all queues in a port (for stats retrieval). */
886#define OFPQ_ALL 0xffffffff
887
888/* Min rate > 1000 means not configured. */
889#define OFPQ_MIN_RATE_UNCFG 0xffff
890
891enum ofp_queue_properties {
892 OFPQT_NONE = 0, /* No property defined for queue (default). */
893 OFPQT_MIN_RATE, /* Minimum datarate guaranteed. */
894 /* Other types should be added here
895 * (i.e. max rate, precedence, etc). */
896};
897
898/* Common description for a queue. */
899struct ofp_queue_prop_header {
900 uint16_t property; /* One of OFPQT_. */
901 uint16_t len; /* Length of property, including this header. */
902 uint8_t pad[4]; /* 64-bit alignemnt. */
903};
904OFP_ASSERT(sizeof(struct ofp_queue_prop_header) == 8);
905
906/* Min-Rate queue property description. */
907struct ofp_queue_prop_min_rate {
908 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MIN, len: 16. */
909 uint16_t rate; /* In 1/10 of a percent; >1000 -> disabled. */
910 uint8_t pad[6]; /* 64-bit alignment */
911};
912OFP_ASSERT(sizeof(struct ofp_queue_prop_min_rate) == 16);
913
914/* Full description for a queue. */
915struct ofp_packet_queue {
916 uint32_t queue_id; /* id for the specific queue. */
917 uint16_t len; /* Length in bytes of this queue desc. */
918 uint8_t pad[2]; /* 64-bit alignment. */
919 struct ofp_queue_prop_header properties[0]; /* List of properties. */
920};
921OFP_ASSERT(sizeof(struct ofp_packet_queue) == 8);
922
923/* Query for port queue configuration. */
924struct ofp_queue_get_config_request {
925 struct ofp_header header;
926 uint16_t port; /* Port to be queried. Should refer
927 to a valid physical port (i.e. < OFPP_MAX) */
928 uint8_t pad[2]; /* 32-bit alignment. */
929};
930OFP_ASSERT(sizeof(struct ofp_queue_get_config_request) == 12);
931
932/* Queue configuration for a given port. */
933struct ofp_queue_get_config_reply {
934 struct ofp_header header;
935 uint16_t port;
936 uint8_t pad[6];
937 struct ofp_packet_queue queues[0]; /* List of configured queues. */
938};
939OFP_ASSERT(sizeof(struct ofp_queue_get_config_reply) == 16);
940
941/* OFPAT_ENQUEUE action struct: send packets to given queue on port. */
942struct ofp_action_enqueue {
943 uint16_t type; /* OFPAT_ENQUEUE. */
944 uint16_t len; /* Len is 16. */
945 uint16_t port; /* Port that queue belongs. Should
946 refer to a valid physical port
947 (i.e. < OFPP_MAX) or OFPP_IN_PORT. */
948 uint8_t pad[6]; /* Pad for 64-bit alignment. */
949 uint32_t queue_id; /* Where to enqueue the packets. */
950};
951OFP_ASSERT(sizeof(struct ofp_action_enqueue) == 16);
952
953struct ofp_queue_stats_request {
954 uint16_t port_no; /* All ports if OFPT_ALL. */
955 uint8_t pad[2]; /* Align to 32-bits. */
956 uint32_t queue_id; /* All queues if OFPQ_ALL. */
957};
958OFP_ASSERT(sizeof(struct ofp_queue_stats_request) == 8);
959
960struct ofp_queue_stats {
961 uint16_t port_no;
962 uint8_t pad[2]; /* Align to 32-bits. */
963 uint32_t queue_id; /* Queue i.d */
964 uint64_t tx_bytes; /* Number of transmitted bytes. */
965 uint64_t tx_packets; /* Number of transmitted packets. */
966 uint64_t tx_errors; /* Number of packets dropped due to overrun. */
967};
968OFP_ASSERT(sizeof(struct ofp_queue_stats) == 32);
969
970#endif /* openflow/openflow.h */