2 * Copyright (c) 2008, 2009, 2010 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 /* OpenFlow: protocol between controller and datapath. */
19 #ifndef OPENFLOW_OPENFLOW_H
20 #define OPENFLOW_OPENFLOW_H 1
23 #include <linux/types.h>
29 #define OFP_ASSERT(EXPR) /* SWIG can't handle OFP_ASSERT. */
30 #elif !defined(__cplusplus)
31 /* Build-time assertion for use in a declaration context. */
32 #define OFP_ASSERT(EXPR) \
33 extern int (*build_assert(void))[ sizeof(struct { \
34 unsigned int build_assert_failed : (EXPR) ? 1 : -1; })]
35 #else /* __cplusplus */
36 #include <boost/static_assert.hpp>
37 #define OFP_ASSERT BOOST_STATIC_ASSERT
38 #endif /* __cplusplus */
40 /* The most significant bit being set in the version field indicates an
41 * experimental OpenFlow version.
43 #define OFP_VERSION 0x97
45 #define OFP_MAX_TABLE_NAME_LEN 32
46 #define OFP_MAX_PORT_NAME_LEN 16
48 #define OFP_TCP_PORT 6633
49 #define OFP_SSL_PORT 6633
51 #define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
53 /* Port numbering. Physical ports are numbered starting from 0. */
55 /* Maximum number of physical switch ports. */
58 /* Fake output "ports". */
59 OFPP_IN_PORT = 0xfff8, /* Send the packet out the input port. This
60 virtual port must be explicitly used
61 in order to send back out of the input
63 OFPP_TABLE = 0xfff9, /* Perform actions in flow table.
64 NB: This can only be the destination
65 port for packet-out messages. */
66 OFPP_NORMAL = 0xfffa, /* Process with normal L2/L3 switching. */
67 OFPP_FLOOD = 0xfffb, /* All physical ports except input port and
68 those disabled by STP. */
69 OFPP_ALL = 0xfffc, /* All physical ports except input port. */
70 OFPP_CONTROLLER = 0xfffd, /* Send to controller. */
71 OFPP_LOCAL = 0xfffe, /* Local openflow "port". */
72 OFPP_NONE = 0xffff /* Not associated with a physical port. */
76 /* Immutable messages. */
77 OFPT_HELLO, /* Symmetric message */
78 OFPT_ERROR, /* Symmetric message */
79 OFPT_ECHO_REQUEST, /* Symmetric message */
80 OFPT_ECHO_REPLY, /* Symmetric message */
81 OFPT_VENDOR, /* Symmetric message */
83 /* Switch configuration messages. */
84 OFPT_FEATURES_REQUEST, /* Controller/switch message */
85 OFPT_FEATURES_REPLY, /* Controller/switch message */
86 OFPT_GET_CONFIG_REQUEST, /* Controller/switch message */
87 OFPT_GET_CONFIG_REPLY, /* Controller/switch message */
88 OFPT_SET_CONFIG, /* Controller/switch message */
90 /* Asynchronous messages. */
91 OFPT_PACKET_IN, /* Async message */
92 OFPT_FLOW_EXPIRED, /* Async message */
93 OFPT_PORT_STATUS, /* Async message */
95 /* Controller command messages. */
96 OFPT_PACKET_OUT, /* Controller/switch message */
97 OFPT_FLOW_MOD, /* Controller/switch message */
98 OFPT_PORT_MOD, /* Controller/switch message */
100 /* Statistics messages. */
101 OFPT_STATS_REQUEST, /* Controller/switch message */
102 OFPT_STATS_REPLY /* Controller/switch message */
105 /* Header on all OpenFlow packets. */
107 uint8_t version; /* OFP_VERSION. */
108 uint8_t type; /* One of the OFPT_ constants. */
109 uint16_t length; /* Length including this ofp_header. */
110 uint32_t xid; /* Transaction id associated with this packet.
111 Replies use the same id as was in the request
112 to facilitate pairing. */
114 OFP_ASSERT(sizeof(struct ofp_header) == 8);
116 /* OFPT_HELLO. This message has an empty body, but implementations must
117 * ignore any data included in the body, to allow for future extensions. */
119 struct ofp_header header;
122 #define OFP_DEFAULT_MISS_SEND_LEN 128
124 enum ofp_config_flags {
125 /* Tells datapath to notify the controller of expired flow entries. */
126 OFPC_SEND_FLOW_EXP = 1 << 0,
128 /* Handling of IP fragments. */
129 OFPC_FRAG_NORMAL = 0 << 1, /* No special handling for fragments. */
130 OFPC_FRAG_DROP = 1 << 1, /* Drop fragments. */
131 OFPC_FRAG_REASM = 2 << 1, /* Reassemble (only if OFPC_IP_REASM set). */
132 OFPC_FRAG_MASK = 3 << 1
135 /* Switch configuration. */
136 struct ofp_switch_config {
137 struct ofp_header header;
138 uint16_t flags; /* OFPC_* flags. */
139 uint16_t miss_send_len; /* Max bytes of new flow that datapath should
140 send to the controller. */
142 OFP_ASSERT(sizeof(struct ofp_switch_config) == 12);
144 /* Capabilities supported by the datapath. */
145 enum ofp_capabilities {
146 OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
147 OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
148 OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
149 OFPC_STP = 1 << 3, /* 802.1d spanning tree. */
150 OFPC_MULTI_PHY_TX = 1 << 4, /* Supports transmitting through multiple
151 physical interfaces */
152 OFPC_IP_REASM = 1 << 5 /* Can reassemble IP fragments. */
155 /* Flags to indicate behavior of the physical port. These flags are
156 * used in ofp_phy_port to describe the current configuration. They are
157 * used in the ofp_port_mod message to configure the port's behavior.
159 enum ofp_port_config {
160 OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
162 OFPPC_NO_STP = 1 << 1, /* Disable 802.1D spanning tree on port. */
163 OFPPC_NO_RECV = 1 << 2, /* Drop most packets received on port. */
164 OFPPC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
165 OFPPC_NO_FLOOD = 1 << 4, /* Do not include this port when flooding. */
166 OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
167 OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
170 /* Current state of the physical port. These are not configurable from
173 enum ofp_port_state {
174 OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
176 /* The OFPPS_STP_* bits have no effect on switch operation. The
177 * controller must adjust OFPPC_NO_RECV, OFPPC_NO_FWD, and
178 * OFPPC_NO_PACKET_IN appropriately to fully implement an 802.1D spanning
180 OFPPS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
181 OFPPS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
182 OFPPS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
183 OFPPS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
184 OFPPS_STP_MASK = 3 << 8 /* Bit mask for OFPPS_STP_* values. */
187 /* Features of physical ports available in a datapath. */
188 enum ofp_port_features {
189 OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
190 OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
191 OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
192 OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
193 OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
194 OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
195 OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
196 OFPPF_COPPER = 1 << 7, /* Copper medium. */
197 OFPPF_FIBER = 1 << 8, /* Fiber medium. */
198 OFPPF_AUTONEG = 1 << 9, /* Auto-negotiation. */
199 OFPPF_PAUSE = 1 << 10, /* Pause. */
200 OFPPF_PAUSE_ASYM = 1 << 11 /* Asymmetric pause. */
203 /* Description of a physical port */
204 struct ofp_phy_port {
206 uint8_t hw_addr[OFP_ETH_ALEN];
207 uint8_t name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
209 uint32_t config; /* Bitmap of OFPPC_* flags. */
210 uint32_t state; /* Bitmap of OFPPS_* flags. */
212 /* Bitmaps of OFPPF_* that describe features. All bits zeroed if
213 * unsupported or unavailable. */
214 uint32_t curr; /* Current features. */
215 uint32_t advertised; /* Features being advertised by the port. */
216 uint32_t supported; /* Features supported by the port. */
217 uint32_t peer; /* Features advertised by peer. */
219 OFP_ASSERT(sizeof(struct ofp_phy_port) == 48);
221 /* Switch features. */
222 struct ofp_switch_features {
223 struct ofp_header header;
224 uint64_t datapath_id; /* Datapath unique ID. Only the lower 48-bits
227 uint32_t n_buffers; /* Max packets buffered at once. */
229 uint8_t n_tables; /* Number of tables supported by datapath. */
230 uint8_t pad[3]; /* Align to 64-bits. */
233 uint32_t capabilities; /* Bitmap of support "ofp_capabilities". */
234 uint32_t actions; /* Bitmap of supported "ofp_action_type"s. */
237 struct ofp_phy_port ports[0]; /* Port definitions. The number of ports
238 is inferred from the length field in
241 OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
243 /* What changed about the physical port */
244 enum ofp_port_reason {
245 OFPPR_ADD, /* The port was added. */
246 OFPPR_DELETE, /* The port was removed. */
247 OFPPR_MODIFY /* Some attribute of the port has changed. */
250 /* A physical port has changed in the datapath */
251 struct ofp_port_status {
252 struct ofp_header header;
253 uint8_t reason; /* One of OFPPR_*. */
254 uint8_t pad[7]; /* Align to 64-bits. */
255 struct ofp_phy_port desc;
257 OFP_ASSERT(sizeof(struct ofp_port_status) == 64);
259 /* Modify behavior of the physical port */
260 struct ofp_port_mod {
261 struct ofp_header header;
263 uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
264 configurable. This is used to
265 sanity-check the request, so it must
266 be the same as returned in an
267 ofp_phy_port struct. */
269 uint32_t config; /* Bitmap of OFPPC_* flags. */
270 uint32_t mask; /* Bitmap of OFPPC_* flags to be changed. */
272 uint32_t advertise; /* Bitmap of "ofp_port_features"s. Zero all
273 bits to prevent any action taking place. */
274 uint8_t pad[4]; /* Pad to 64-bits. */
276 OFP_ASSERT(sizeof(struct ofp_port_mod) == 32);
278 /* Why is this packet being sent to the controller? */
279 enum ofp_packet_in_reason {
280 OFPR_NO_MATCH, /* No matching flow. */
281 OFPR_ACTION /* Action explicitly output to controller. */
284 /* Packet received on port (datapath -> controller). */
285 struct ofp_packet_in {
286 struct ofp_header header;
287 uint32_t buffer_id; /* ID assigned by datapath. */
288 uint16_t total_len; /* Full length of frame. */
289 uint16_t in_port; /* Port on which frame was received. */
290 uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
292 uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word,
293 so the IP header is 32-bit aligned. The
294 amount of data is inferred from the length
295 field in the header. Because of padding,
296 offsetof(struct ofp_packet_in, data) ==
297 sizeof(struct ofp_packet_in) - 2. */
299 OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);
301 enum ofp_action_type {
302 OFPAT_OUTPUT, /* Output to switch port. */
303 OFPAT_SET_VLAN_VID, /* Set the 802.1q VLAN id. */
304 OFPAT_SET_VLAN_PCP, /* Set the 802.1q priority. */
305 OFPAT_STRIP_VLAN, /* Strip the 802.1q header. */
306 OFPAT_SET_DL_SRC, /* Ethernet source address. */
307 OFPAT_SET_DL_DST, /* Ethernet destination address. */
308 OFPAT_SET_NW_SRC, /* IP source address. */
309 OFPAT_SET_NW_DST, /* IP destination address. */
310 OFPAT_SET_TP_SRC, /* TCP/UDP source port. */
311 OFPAT_SET_TP_DST, /* TCP/UDP destination port. */
312 OFPAT_VENDOR = 0xffff
315 /* Action structure for OFPAT_OUTPUT, which sends packets out 'port'.
316 * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
317 * number of bytes to send. A 'max_len' of zero means no bytes of the
318 * packet should be sent. */
319 struct ofp_action_output {
320 uint16_t type; /* OFPAT_OUTPUT. */
321 uint16_t len; /* Length is 8. */
322 uint16_t port; /* Output port. */
323 uint16_t max_len; /* Max length to send to controller. */
325 OFP_ASSERT(sizeof(struct ofp_action_output) == 8);
327 /* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
328 * special conditions. All ones is used to match that no VLAN id was
330 #define OFP_VLAN_NONE 0xffff
332 /* Action structure for OFPAT_SET_VLAN_VID. */
333 struct ofp_action_vlan_vid {
334 uint16_t type; /* OFPAT_SET_VLAN_VID. */
335 uint16_t len; /* Length is 8. */
336 uint16_t vlan_vid; /* VLAN id. */
339 OFP_ASSERT(sizeof(struct ofp_action_vlan_vid) == 8);
341 /* Action structure for OFPAT_SET_VLAN_PCP. */
342 struct ofp_action_vlan_pcp {
343 uint16_t type; /* OFPAT_SET_VLAN_PCP. */
344 uint16_t len; /* Length is 8. */
345 uint8_t vlan_pcp; /* VLAN priority. */
348 OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp) == 8);
350 /* Action structure for OFPAT_SET_DL_SRC/DST. */
351 struct ofp_action_dl_addr {
352 uint16_t type; /* OFPAT_SET_DL_SRC/DST. */
353 uint16_t len; /* Length is 16. */
354 uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */
357 OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
359 /* Action structure for OFPAT_SET_NW_SRC/DST. */
360 struct ofp_action_nw_addr {
361 uint16_t type; /* OFPAT_SET_TW_SRC/DST. */
362 uint16_t len; /* Length is 8. */
363 uint32_t nw_addr; /* IP address. */
365 OFP_ASSERT(sizeof(struct ofp_action_nw_addr) == 8);
367 /* Action structure for OFPAT_SET_TP_SRC/DST. */
368 struct ofp_action_tp_port {
369 uint16_t type; /* OFPAT_SET_TP_SRC/DST. */
370 uint16_t len; /* Length is 8. */
371 uint16_t tp_port; /* TCP/UDP port. */
374 OFP_ASSERT(sizeof(struct ofp_action_tp_port) == 8);
376 /* Action header for OFPAT_VENDOR. The rest of the body is vendor-defined. */
377 struct ofp_action_vendor_header {
378 uint16_t type; /* OFPAT_VENDOR. */
379 uint16_t len; /* Length is a multiple of 8. */
380 uint32_t vendor; /* Vendor ID, which takes the same form
381 as in "struct ofp_vendor_header". */
383 OFP_ASSERT(sizeof(struct ofp_action_vendor_header) == 8);
385 /* Action header that is common to all actions. The length includes the
386 * header and any padding used to make the action 64-bit aligned.
387 * NB: The length of an action *must* always be a multiple of eight. */
388 struct ofp_action_header {
389 uint16_t type; /* One of OFPAT_*. */
390 uint16_t len; /* Length of action, including this
391 header. This is the length of action,
392 including any padding to make it
396 OFP_ASSERT(sizeof(struct ofp_action_header) == 8);
400 struct ofp_action_header header;
401 struct ofp_action_vendor_header vendor;
402 struct ofp_action_output output;
403 struct ofp_action_vlan_vid vlan_vid;
404 struct ofp_action_vlan_pcp vlan_pcp;
405 struct ofp_action_nw_addr nw_addr;
406 struct ofp_action_tp_port tp_port;
408 OFP_ASSERT(sizeof(union ofp_action) == 8);
410 /* Send packet (controller -> datapath). */
411 struct ofp_packet_out {
412 struct ofp_header header;
413 uint32_t buffer_id; /* ID assigned by datapath (-1 if none). */
414 uint16_t in_port; /* Packet's input port (OFPP_NONE if none). */
415 uint16_t actions_len; /* Size of action array in bytes. */
416 struct ofp_action_header actions[0]; /* Actions. */
417 /* uint8_t data[0]; */ /* Packet data. The length is inferred
418 from the length field in the header.
419 (Only meaningful if buffer_id == -1.) */
421 OFP_ASSERT(sizeof(struct ofp_packet_out) == 16);
423 enum ofp_flow_mod_command {
424 OFPFC_ADD, /* New flow. */
425 OFPFC_MODIFY, /* Modify all matching flows. */
426 OFPFC_MODIFY_STRICT, /* Modify entry strictly matching wildcards */
427 OFPFC_DELETE, /* Delete all matching flows. */
428 OFPFC_DELETE_STRICT /* Strictly match wildcards and priority. */
431 /* Flow wildcards. */
432 enum ofp_flow_wildcards {
433 OFPFW_IN_PORT = 1 << 0, /* Switch input port. */
434 OFPFW_DL_VLAN = 1 << 1, /* VLAN. */
435 OFPFW_DL_SRC = 1 << 2, /* Ethernet source address. */
436 OFPFW_DL_DST = 1 << 3, /* Ethernet destination address. */
437 OFPFW_DL_TYPE = 1 << 4, /* Ethernet frame type. */
438 OFPFW_NW_PROTO = 1 << 5, /* IP protocol. */
439 OFPFW_TP_SRC = 1 << 6, /* TCP/UDP source port. */
440 OFPFW_TP_DST = 1 << 7, /* TCP/UDP destination port. */
442 /* IP source address wildcard bit count. 0 is exact match, 1 ignores the
443 * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
444 * the entire field. This is the *opposite* of the usual convention where
445 * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded. */
446 OFPFW_NW_SRC_SHIFT = 8,
447 OFPFW_NW_SRC_BITS = 6,
448 OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT,
449 OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT,
451 /* IP destination address wildcard bit count. Same format as source. */
452 OFPFW_NW_DST_SHIFT = 14,
453 OFPFW_NW_DST_BITS = 6,
454 OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT,
455 OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT,
457 /* Wildcard all fields. */
458 OFPFW_ALL = ((1 << 20) - 1)
461 /* The wildcards for ICMP type and code fields use the transport source
462 * and destination port fields, respectively. */
463 #define OFPFW_ICMP_TYPE OFPFW_TP_SRC
464 #define OFPFW_ICMP_CODE OFPFW_TP_DST
466 /* Values below this cutoff are 802.3 packets and the two bytes
467 * following MAC addresses are used as a frame length. Otherwise, the
468 * two bytes are used as the Ethernet type.
470 #define OFP_DL_TYPE_ETH2_CUTOFF 0x0600
472 /* Value of dl_type to indicate that the frame does not include an
475 #define OFP_DL_TYPE_NOT_ETH_TYPE 0x05ff
477 /* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
478 * special conditions. All ones indicates that no VLAN id was set.
480 #define OFP_VLAN_NONE 0xffff
482 /* Fields to match against flows */
484 uint32_t wildcards; /* Wildcard fields. */
485 uint16_t in_port; /* Input switch port. */
486 uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
487 uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
488 uint16_t dl_vlan; /* Input VLAN. */
489 uint16_t dl_type; /* Ethernet frame type. */
490 uint8_t nw_proto; /* IP protocol. */
491 uint8_t pad; /* Align to 32-bits. */
492 uint32_t nw_src; /* IP source address. */
493 uint32_t nw_dst; /* IP destination address. */
494 uint16_t tp_src; /* TCP/UDP source port. */
495 uint16_t tp_dst; /* TCP/UDP destination port. */
497 OFP_ASSERT(sizeof(struct ofp_match) == 36);
499 /* The match fields for ICMP type and code use the transport source and
500 * destination port fields, respectively. */
501 #define icmp_type tp_src
502 #define icmp_code tp_dst
504 /* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
506 #define OFP_FLOW_PERMANENT 0
508 /* By default, choose a priority in the middle. */
509 #define OFP_DEFAULT_PRIORITY 0x8000
511 /* Flow setup and teardown (controller -> datapath). */
512 struct ofp_flow_mod {
513 struct ofp_header header;
514 struct ofp_match match; /* Fields to match */
517 uint16_t command; /* One of OFPFC_*. */
518 uint16_t idle_timeout; /* Idle time before discarding (seconds). */
519 uint16_t hard_timeout; /* Max time before discarding (seconds). */
520 uint16_t priority; /* Priority level of flow entry. */
521 uint32_t buffer_id; /* Buffered packet to apply to (or -1).
522 Not meaningful for OFPFC_DELETE*. */
523 uint16_t out_port; /* For OFPFC_DELETE* commands, require
524 matching entries to include this as an
525 output port. A value of OFPP_NONE
526 indicates no restriction. */
527 uint8_t pad[2]; /* Align to 32-bits. */
528 uint32_t reserved; /* Reserved for future use. */
529 struct ofp_action_header actions[0]; /* The action length is inferred
530 from the length field in the
533 OFP_ASSERT(sizeof(struct ofp_flow_mod) == 64);
535 /* Why did this flow expire? */
536 enum ofp_flow_expired_reason {
537 OFPER_IDLE_TIMEOUT, /* Flow idle time exceeded idle_timeout. */
538 OFPER_HARD_TIMEOUT /* Time exceeded hard_timeout. */
541 /* Flow expiration (datapath -> controller). */
542 struct ofp_flow_expired {
543 struct ofp_header header;
544 struct ofp_match match; /* Description of fields. */
546 uint16_t priority; /* Priority level of flow entry. */
547 uint8_t reason; /* One of OFPER_*. */
548 uint8_t pad[1]; /* Align to 32-bits. */
550 uint32_t duration; /* Time flow was alive in seconds. */
551 uint8_t pad2[4]; /* Align to 64-bits. */
552 uint64_t packet_count;
555 OFP_ASSERT(sizeof(struct ofp_flow_expired) == 72);
557 /* Values for 'type' in ofp_error_message. These values are immutable: they
558 * will not change in future versions of the protocol (although new values may
560 enum ofp_error_type {
561 OFPET_HELLO_FAILED, /* Hello protocol failed. */
562 OFPET_BAD_REQUEST, /* Request was not understood. */
563 OFPET_BAD_ACTION, /* Error in action description. */
564 OFPET_FLOW_MOD_FAILED, /* Problem modifying flow entry. */
565 OFPET_PORT_MOD_FAILED /* OFPT_PORT_MOD failed. */
568 /* ofp_error_msg 'code' values for OFPET_HELLO_FAILED. 'data' contains an
569 * ASCII text string that may give failure details. */
570 enum ofp_hello_failed_code {
571 OFPHFC_INCOMPATIBLE /* No compatible version. */
574 /* ofp_error_msg 'code' values for OFPET_BAD_REQUEST. 'data' contains at least
575 * the first 64 bytes of the failed request. */
576 enum ofp_bad_request_code {
577 OFPBRC_BAD_VERSION, /* ofp_header.version not supported. */
578 OFPBRC_BAD_TYPE, /* ofp_header.type not supported. */
579 OFPBRC_BAD_STAT, /* ofp_stats_request.type not supported. */
580 OFPBRC_BAD_VENDOR, /* Vendor not supported (in ofp_vendor_header
581 * or ofp_stats_request or ofp_stats_reply). */
582 OFPBRC_BAD_SUBTYPE, /* Vendor subtype not supported. */
583 OFPBRC_BAD_LENGTH, /* Wrong request length for type. */
584 OFPBRC_BUFFER_EMPTY, /* Specified buffer has already been used. */
585 OFPBRC_BAD_COOKIE /* Specified buffer does not exist. */
588 /* ofp_error_msg 'code' values for OFPET_BAD_ACTION. 'data' contains at least
589 * the first 64 bytes of the failed request. */
590 enum ofp_bad_action_code {
591 OFPBAC_BAD_TYPE, /* Unknown action type. */
592 OFPBAC_BAD_LEN, /* Length problem in actions. */
593 OFPBAC_BAD_VENDOR, /* Unknown vendor id specified. */
594 OFPBAC_BAD_VENDOR_TYPE, /* Unknown action type for vendor id. */
595 OFPBAC_BAD_OUT_PORT, /* Problem validating output action. */
596 OFPBAC_BAD_ARGUMENT, /* Bad action argument. */
597 OFPBAC_TOO_MANY /* Can't handle this many actions. */
600 /* ofp_error_msg 'code' values for OFPET_FLOW_MOD_FAILED. 'data' contains
601 * at least the first 64 bytes of the failed request. */
602 enum ofp_flow_mod_failed_code {
603 OFPFMFC_ALL_TABLES_FULL, /* Flow not added because of full tables. */
604 OFPFMFC_BAD_COMMAND /* Unknown command. */
607 /* ofp_error_msg 'code' values for OFPET_PORT_MOD_FAILED. 'data' contains
608 * at least the first 64 bytes of the failed request. */
609 enum ofp_port_mod_failed_code {
610 OFPPMFC_BAD_PORT, /* Specified port does not exist. */
611 OFPPMFC_BAD_HW_ADDR, /* Specified hardware address is wrong. */
614 /* OFPT_ERROR: Error message (datapath -> controller). */
615 struct ofp_error_msg {
616 struct ofp_header header;
620 uint8_t data[0]; /* Variable-length data. Interpreted based
621 on the type and code. */
623 OFP_ASSERT(sizeof(struct ofp_error_msg) == 12);
625 enum ofp_stats_types {
626 /* Description of this OpenFlow switch.
627 * The request body is empty.
628 * The reply body is struct ofp_desc_stats. */
631 /* Individual flow statistics.
632 * The request body is struct ofp_flow_stats_request.
633 * The reply body is an array of struct ofp_flow_stats. */
636 /* Aggregate flow statistics.
637 * The request body is struct ofp_aggregate_stats_request.
638 * The reply body is struct ofp_aggregate_stats_reply. */
641 /* Flow table statistics.
642 * The request body is empty.
643 * The reply body is an array of struct ofp_table_stats. */
646 /* Physical port statistics.
647 * The request body is empty.
648 * The reply body is an array of struct ofp_port_stats. */
652 * The request and reply bodies begin with a 32-bit vendor ID, which takes
653 * the same form as in "struct ofp_vendor_header". The request and reply
654 * bodies are otherwise vendor-defined. */
655 OFPST_VENDOR = 0xffff
658 struct ofp_stats_request {
659 struct ofp_header header;
660 uint16_t type; /* One of the OFPST_* constants. */
661 uint16_t flags; /* OFPSF_REQ_* flags (none yet defined). */
662 uint8_t body[0]; /* Body of the request. */
664 OFP_ASSERT(sizeof(struct ofp_stats_request) == 12);
666 enum ofp_stats_reply_flags {
667 OFPSF_REPLY_MORE = 1 << 0 /* More replies to follow. */
670 struct ofp_stats_reply {
671 struct ofp_header header;
672 uint16_t type; /* One of the OFPST_* constants. */
673 uint16_t flags; /* OFPSF_REPLY_* flags. */
674 uint8_t body[0]; /* Body of the reply. */
676 OFP_ASSERT(sizeof(struct ofp_stats_reply) == 12);
678 #define DESC_STR_LEN 256
679 #define SERIAL_NUM_LEN 32
680 /* Body of reply to OFPST_DESC request. Each entry is a NULL-terminated
682 struct ofp_desc_stats {
683 char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */
684 char hw_desc[DESC_STR_LEN]; /* Hardware description. */
685 char sw_desc[DESC_STR_LEN]; /* Software description. */
686 char serial_num[SERIAL_NUM_LEN]; /* Serial number. */
688 OFP_ASSERT(sizeof(struct ofp_desc_stats) == 800);
690 /* Body for ofp_stats_request of type OFPST_FLOW. */
691 struct ofp_flow_stats_request {
692 struct ofp_match match; /* Fields to match. */
693 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
694 or 0xff for all tables. */
695 uint8_t pad; /* Align to 32 bits. */
696 uint16_t out_port; /* Require matching entries to include this
697 as an output port. A value of OFPP_NONE
698 indicates no restriction. */
700 OFP_ASSERT(sizeof(struct ofp_flow_stats_request) == 40);
702 /* Body of reply to OFPST_FLOW request. */
703 struct ofp_flow_stats {
704 uint16_t length; /* Length of this entry. */
705 uint8_t table_id; /* ID of table flow came from. */
707 struct ofp_match match; /* Description of fields. */
708 uint32_t duration; /* Time flow has been alive in seconds. */
709 uint16_t priority; /* Priority of the entry. Only meaningful
710 when this is not an exact-match entry. */
711 uint16_t idle_timeout; /* Number of seconds idle before expiration. */
712 uint16_t hard_timeout; /* Number of seconds before expiration. */
713 uint16_t pad2[3]; /* Pad to 64 bits. */
714 uint64_t packet_count; /* Number of packets in flow. */
715 uint64_t byte_count; /* Number of bytes in flow. */
716 struct ofp_action_header actions[0]; /* Actions. */
718 OFP_ASSERT(sizeof(struct ofp_flow_stats) == 72);
720 /* Body for ofp_stats_request of type OFPST_AGGREGATE. */
721 struct ofp_aggregate_stats_request {
722 struct ofp_match match; /* Fields to match. */
723 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
724 or 0xff for all tables. */
725 uint8_t pad; /* Align to 32 bits. */
726 uint16_t out_port; /* Require matching entries to include this
727 as an output port. A value of OFPP_NONE
728 indicates no restriction. */
730 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_request) == 40);
732 /* Body of reply to OFPST_AGGREGATE request. */
733 struct ofp_aggregate_stats_reply {
734 uint64_t packet_count; /* Number of packets in flows. */
735 uint64_t byte_count; /* Number of bytes in flows. */
736 uint32_t flow_count; /* Number of flows. */
737 uint8_t pad[4]; /* Align to 64 bits. */
739 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
741 /* Body of reply to OFPST_TABLE request. */
742 struct ofp_table_stats {
743 uint8_t table_id; /* Identifier of table. Lower numbered tables
744 are consulted first. */
745 uint8_t pad[3]; /* Align to 32-bits. */
746 char name[OFP_MAX_TABLE_NAME_LEN];
747 uint32_t wildcards; /* Bitmap of OFPFW_* wildcards that are
748 supported by the table. */
749 uint32_t max_entries; /* Max number of entries supported. */
750 uint32_t active_count; /* Number of active entries. */
751 uint64_t lookup_count; /* Number of packets looked up in table. */
752 uint64_t matched_count; /* Number of packets that hit table. */
754 OFP_ASSERT(sizeof(struct ofp_table_stats) == 64);
756 /* Body of reply to OFPST_PORT request. If a counter is unsupported, set
757 * the field to all ones. */
758 struct ofp_port_stats {
760 uint8_t pad[6]; /* Align to 64-bits. */
761 uint64_t rx_packets; /* Number of received packets. */
762 uint64_t tx_packets; /* Number of transmitted packets. */
763 uint64_t rx_bytes; /* Number of received bytes. */
764 uint64_t tx_bytes; /* Number of transmitted bytes. */
765 uint64_t rx_dropped; /* Number of packets dropped by RX. */
766 uint64_t tx_dropped; /* Number of packets dropped by TX. */
767 uint64_t rx_errors; /* Number of receive errors. This is a super-set
768 of receive errors and should be great than or
769 equal to the sum of all rx_*_err values. */
770 uint64_t tx_errors; /* Number of transmit errors. This is a super-set
771 of transmit errors. */
772 uint64_t rx_frame_err; /* Number of frame alignment errors. */
773 uint64_t rx_over_err; /* Number of packets with RX overrun. */
774 uint64_t rx_crc_err; /* Number of CRC errors. */
775 uint64_t collisions; /* Number of collisions. */
777 OFP_ASSERT(sizeof(struct ofp_port_stats) == 104);
779 /* Vendor extension. */
780 struct ofp_vendor_header {
781 struct ofp_header header; /* Type OFPT_VENDOR. */
782 uint32_t vendor; /* Vendor ID:
783 * - MSB 0: low-order bytes are IEEE OUI.
784 * - MSB != 0: defined by OpenFlow
786 /* Vendor-defined arbitrary additional data. */
788 OFP_ASSERT(sizeof(struct ofp_vendor_header) == 12);
790 #endif /* openflow/openflow.h */