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 */
41 #define OFP_PACKED __attribute__((packed))
43 #define OFP_PACKED /* SWIG doesn't understand __attribute. */
47 * Non-experimental versions released: 0x01
48 * Experimental versions released: 0x81 -- 0x99
50 /* The most significant bit being set in the version field indicates an
51 * experimental OpenFlow version.
53 #define OFP_VERSION 0x01
55 #define OFP_MAX_TABLE_NAME_LEN 32
56 #define OFP_MAX_PORT_NAME_LEN 16
58 #define OFP_TCP_PORT 6633
59 #define OFP_SSL_PORT 6633
61 #define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
63 /* Port numbering. Physical ports are numbered starting from 1. */
65 /* Maximum number of physical switch ports. */
68 /* Fake output "ports". */
69 OFPP_IN_PORT = 0xfff8, /* Send the packet out the input port. This
70 virtual port must be explicitly used
71 in order to send back out of the input
73 OFPP_TABLE = 0xfff9, /* Perform actions in flow table.
74 NB: This can only be the destination
75 port for packet-out messages. */
76 OFPP_NORMAL = 0xfffa, /* Process with normal L2/L3 switching. */
77 OFPP_FLOOD = 0xfffb, /* All physical ports except input port and
78 those disabled by STP. */
79 OFPP_ALL = 0xfffc, /* All physical ports except input port. */
80 OFPP_CONTROLLER = 0xfffd, /* Send to controller. */
81 OFPP_LOCAL = 0xfffe, /* Local openflow "port". */
82 OFPP_NONE = 0xffff /* Not associated with a physical port. */
86 /* Immutable messages. */
87 OFPT_HELLO, /* Symmetric message */
88 OFPT_ERROR, /* Symmetric message */
89 OFPT_ECHO_REQUEST, /* Symmetric message */
90 OFPT_ECHO_REPLY, /* Symmetric message */
91 OFPT_VENDOR, /* Symmetric message */
93 /* Switch configuration messages. */
94 OFPT_FEATURES_REQUEST, /* Controller/switch message */
95 OFPT_FEATURES_REPLY, /* Controller/switch message */
96 OFPT_GET_CONFIG_REQUEST, /* Controller/switch message */
97 OFPT_GET_CONFIG_REPLY, /* Controller/switch message */
98 OFPT_SET_CONFIG, /* Controller/switch message */
100 /* Asynchronous messages. */
101 OFPT_PACKET_IN, /* Async message */
102 OFPT_FLOW_REMOVED, /* Async message */
103 OFPT_PORT_STATUS, /* Async message */
105 /* Controller command messages. */
106 OFPT_PACKET_OUT, /* Controller/switch message */
107 OFPT_FLOW_MOD, /* Controller/switch message */
108 OFPT_PORT_MOD, /* Controller/switch message */
110 /* Statistics messages. */
111 OFPT_STATS_REQUEST, /* Controller/switch message */
112 OFPT_STATS_REPLY, /* Controller/switch message */
114 /* Barrier messages. */
115 OFPT_BARRIER_REQUEST, /* Controller/switch message */
116 OFPT_BARRIER_REPLY, /* Controller/switch message */
118 /* Queue Configuration messages. */
119 OFPT_QUEUE_GET_CONFIG_REQUEST, /* Controller/switch message */
120 OFPT_QUEUE_GET_CONFIG_REPLY /* Controller/switch message */
123 /* Header on all OpenFlow packets. */
125 uint8_t version; /* OFP_VERSION. */
126 uint8_t type; /* One of the OFPT_ constants. */
127 uint16_t length; /* Length including this ofp_header. */
128 uint32_t xid; /* Transaction id associated with this packet.
129 Replies use the same id as was in the request
130 to facilitate pairing. */
132 OFP_ASSERT(sizeof(struct ofp_header) == 8);
134 /* OFPT_HELLO. This message has an empty body, but implementations must
135 * ignore any data included in the body, to allow for future extensions. */
137 struct ofp_header header;
140 #define OFP_DEFAULT_MISS_SEND_LEN 128
142 enum ofp_config_flags {
143 /* Handling of IP fragments. */
144 OFPC_FRAG_NORMAL = 0, /* No special handling for fragments. */
145 OFPC_FRAG_DROP = 1, /* Drop fragments. */
146 OFPC_FRAG_REASM = 2, /* Reassemble (only if OFPC_IP_REASM set). */
150 /* Switch configuration. */
151 struct ofp_switch_config {
152 struct ofp_header header;
153 uint16_t flags; /* OFPC_* flags. */
154 uint16_t miss_send_len; /* Max bytes of new flow that datapath should
155 send to the controller. */
157 OFP_ASSERT(sizeof(struct ofp_switch_config) == 12);
159 /* Capabilities supported by the datapath. */
160 enum ofp_capabilities {
161 OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
162 OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
163 OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
164 OFPC_STP = 1 << 3, /* 802.1d spanning tree. */
165 OFPC_RESERVED = 1 << 4, /* Reserved, must not be set. */
166 OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
167 OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */
168 OFPC_ARP_MATCH_IP = 1 << 7 /* Match IP addresses in ARP
172 /* Flags to indicate behavior of the physical port. These flags are
173 * used in ofp_phy_port to describe the current configuration. They are
174 * used in the ofp_port_mod message to configure the port's behavior.
176 enum ofp_port_config {
177 OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
179 OFPPC_NO_STP = 1 << 1, /* Disable 802.1D spanning tree on port. */
180 OFPPC_NO_RECV = 1 << 2, /* Drop all packets except 802.1D
181 spanning tree packets. */
182 OFPPC_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
183 OFPPC_NO_FLOOD = 1 << 4, /* Do not include this port when flooding. */
184 OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
185 OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
188 /* Current state of the physical port. These are not configurable from
191 enum ofp_port_state {
192 OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
194 /* The OFPPS_STP_* bits have no effect on switch operation. The
195 * controller must adjust OFPPC_NO_RECV, OFPPC_NO_FWD, and
196 * OFPPC_NO_PACKET_IN appropriately to fully implement an 802.1D spanning
198 OFPPS_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
199 OFPPS_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
200 OFPPS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
201 OFPPS_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
202 OFPPS_STP_MASK = 3 << 8 /* Bit mask for OFPPS_STP_* values. */
205 /* Features of physical ports available in a datapath. */
206 enum ofp_port_features {
207 OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
208 OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
209 OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
210 OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
211 OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
212 OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
213 OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
214 OFPPF_COPPER = 1 << 7, /* Copper medium. */
215 OFPPF_FIBER = 1 << 8, /* Fiber medium. */
216 OFPPF_AUTONEG = 1 << 9, /* Auto-negotiation. */
217 OFPPF_PAUSE = 1 << 10, /* Pause. */
218 OFPPF_PAUSE_ASYM = 1 << 11 /* Asymmetric pause. */
221 /* Description of a physical port */
222 struct ofp_phy_port {
224 uint8_t hw_addr[OFP_ETH_ALEN];
225 uint8_t name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
227 uint32_t config; /* Bitmap of OFPPC_* flags. */
228 uint32_t state; /* Bitmap of OFPPS_* flags. */
230 /* Bitmaps of OFPPF_* that describe features. All bits zeroed if
231 * unsupported or unavailable. */
232 uint32_t curr; /* Current features. */
233 uint32_t advertised; /* Features being advertised by the port. */
234 uint32_t supported; /* Features supported by the port. */
235 uint32_t peer; /* Features advertised by peer. */
237 OFP_ASSERT(sizeof(struct ofp_phy_port) == 48);
239 /* Switch features. */
240 struct ofp_switch_features {
241 struct ofp_header header;
242 uint64_t datapath_id; /* Datapath unique ID. The lower 48-bits are for
243 a MAC address, while the upper 16-bits are
244 implementer-defined. */
246 uint32_t n_buffers; /* Max packets buffered at once. */
248 uint8_t n_tables; /* Number of tables supported by datapath. */
249 uint8_t pad[3]; /* Align to 64-bits. */
252 uint32_t capabilities; /* Bitmap of support "ofp_capabilities". */
253 uint32_t actions; /* Bitmap of supported "ofp_action_type"s. */
256 struct ofp_phy_port ports[0]; /* Port definitions. The number of ports
257 is inferred from the length field in
260 OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
262 /* What changed about the physical port */
263 enum ofp_port_reason {
264 OFPPR_ADD, /* The port was added. */
265 OFPPR_DELETE, /* The port was removed. */
266 OFPPR_MODIFY /* Some attribute of the port has changed. */
269 /* A physical port has changed in the datapath */
270 struct ofp_port_status {
271 struct ofp_header header;
272 uint8_t reason; /* One of OFPPR_*. */
273 uint8_t pad[7]; /* Align to 64-bits. */
274 struct ofp_phy_port desc;
276 OFP_ASSERT(sizeof(struct ofp_port_status) == 64);
278 /* Modify behavior of the physical port */
279 struct ofp_port_mod {
280 struct ofp_header header;
282 uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
283 configurable. This is used to
284 sanity-check the request, so it must
285 be the same as returned in an
286 ofp_phy_port struct. */
288 uint32_t config; /* Bitmap of OFPPC_* flags. */
289 uint32_t mask; /* Bitmap of OFPPC_* flags to be changed. */
291 uint32_t advertise; /* Bitmap of "ofp_port_features"s. Zero all
292 bits to prevent any action taking place. */
293 uint8_t pad[4]; /* Pad to 64-bits. */
295 OFP_ASSERT(sizeof(struct ofp_port_mod) == 32);
297 /* Why is this packet being sent to the controller? */
298 enum ofp_packet_in_reason {
299 OFPR_NO_MATCH, /* No matching flow. */
300 OFPR_ACTION /* Action explicitly output to controller. */
303 /* Packet received on port (datapath -> controller). */
304 struct ofp_packet_in {
305 struct ofp_header header;
306 uint32_t buffer_id; /* ID assigned by datapath. */
307 uint16_t total_len; /* Full length of frame. */
308 uint16_t in_port; /* Port on which frame was received. */
309 uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
311 uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word,
312 so the IP header is 32-bit aligned. The
313 amount of data is inferred from the length
314 field in the header. Because of padding,
315 offsetof(struct ofp_packet_in, data) ==
316 sizeof(struct ofp_packet_in) - 2. */
318 OFP_ASSERT(sizeof(struct ofp_packet_in) == 20);
320 enum ofp_action_type {
321 OFPAT_OUTPUT, /* Output to switch port. */
322 OFPAT_SET_VLAN_VID, /* Set the 802.1q VLAN id. */
323 OFPAT_SET_VLAN_PCP, /* Set the 802.1q priority. */
324 OFPAT_STRIP_VLAN, /* Strip the 802.1q header. */
325 OFPAT_SET_DL_SRC, /* Ethernet source address. */
326 OFPAT_SET_DL_DST, /* Ethernet destination address. */
327 OFPAT_SET_NW_SRC, /* IP source address. */
328 OFPAT_SET_NW_DST, /* IP destination address. */
329 OFPAT_SET_NW_TOS, /* IP ToS (DSCP field, 6 bits). */
330 OFPAT_SET_TP_SRC, /* TCP/UDP source port. */
331 OFPAT_SET_TP_DST, /* TCP/UDP destination port. */
332 OFPAT_ENQUEUE, /* Output to queue. */
333 OFPAT_VENDOR = 0xffff
336 /* Action structure for OFPAT_OUTPUT, which sends packets out 'port'.
337 * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
338 * number of bytes to send. A 'max_len' of zero means no bytes of the
339 * packet should be sent. */
340 struct ofp_action_output {
341 uint16_t type; /* OFPAT_OUTPUT. */
342 uint16_t len; /* Length is 8. */
343 uint16_t port; /* Output port. */
344 uint16_t max_len; /* Max length to send to controller. */
346 OFP_ASSERT(sizeof(struct ofp_action_output) == 8);
348 /* The VLAN id is 12 bits, so we can use the entire 16 bits to indicate
349 * special conditions. All ones is used to match that no VLAN id was
351 #define OFP_VLAN_NONE 0xffff
353 /* Action structure for OFPAT_SET_VLAN_VID. */
354 struct ofp_action_vlan_vid {
355 uint16_t type; /* OFPAT_SET_VLAN_VID. */
356 uint16_t len; /* Length is 8. */
357 uint16_t vlan_vid; /* VLAN id. */
360 OFP_ASSERT(sizeof(struct ofp_action_vlan_vid) == 8);
362 /* Action structure for OFPAT_SET_VLAN_PCP. */
363 struct ofp_action_vlan_pcp {
364 uint16_t type; /* OFPAT_SET_VLAN_PCP. */
365 uint16_t len; /* Length is 8. */
366 uint8_t vlan_pcp; /* VLAN priority. */
369 OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp) == 8);
371 /* Action structure for OFPAT_SET_DL_SRC/DST. */
372 struct ofp_action_dl_addr {
373 uint16_t type; /* OFPAT_SET_DL_SRC/DST. */
374 uint16_t len; /* Length is 16. */
375 uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */
378 OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
380 /* Action structure for OFPAT_SET_NW_SRC/DST. */
381 struct ofp_action_nw_addr {
382 uint16_t type; /* OFPAT_SET_TW_SRC/DST. */
383 uint16_t len; /* Length is 8. */
384 uint32_t nw_addr; /* IP address. */
386 OFP_ASSERT(sizeof(struct ofp_action_nw_addr) == 8);
388 /* Action structure for OFPAT_SET_NW_TOS. */
389 struct ofp_action_nw_tos {
390 uint16_t type; /* OFPAT_SET_TW_TOS. */
391 uint16_t len; /* Length is 8. */
392 uint8_t nw_tos; /* IP TOS (DSCP field, 6 bits). */
395 OFP_ASSERT(sizeof(struct ofp_action_nw_tos) == 8);
397 /* Action structure for OFPAT_SET_TP_SRC/DST. */
398 struct ofp_action_tp_port {
399 uint16_t type; /* OFPAT_SET_TP_SRC/DST. */
400 uint16_t len; /* Length is 8. */
401 uint16_t tp_port; /* TCP/UDP port. */
404 OFP_ASSERT(sizeof(struct ofp_action_tp_port) == 8);
406 /* Action header for OFPAT_VENDOR. The rest of the body is vendor-defined. */
407 struct ofp_action_vendor_header {
408 uint16_t type; /* OFPAT_VENDOR. */
409 uint16_t len; /* Length is a multiple of 8. */
410 uint32_t vendor; /* Vendor ID, which takes the same form
411 as in "struct ofp_vendor_header". */
413 OFP_ASSERT(sizeof(struct ofp_action_vendor_header) == 8);
415 /* Action header that is common to all actions. The length includes the
416 * header and any padding used to make the action 64-bit aligned.
417 * NB: The length of an action *must* always be a multiple of eight. */
418 struct ofp_action_header {
419 uint16_t type; /* One of OFPAT_*. */
420 uint16_t len; /* Length of action, including this
421 header. This is the length of action,
422 including any padding to make it
426 OFP_ASSERT(sizeof(struct ofp_action_header) == 8);
430 struct ofp_action_header header;
431 struct ofp_action_vendor_header vendor;
432 struct ofp_action_output output;
433 struct ofp_action_vlan_vid vlan_vid;
434 struct ofp_action_vlan_pcp vlan_pcp;
435 struct ofp_action_nw_addr nw_addr;
436 struct ofp_action_nw_tos nw_tos;
437 struct ofp_action_tp_port tp_port;
439 OFP_ASSERT(sizeof(union ofp_action) == 8);
441 /* Send packet (controller -> datapath). */
442 struct ofp_packet_out {
443 struct ofp_header header;
444 uint32_t buffer_id; /* ID assigned by datapath (-1 if none). */
445 uint16_t in_port; /* Packet's input port (OFPP_NONE if none). */
446 uint16_t actions_len; /* Size of action array in bytes. */
447 struct ofp_action_header actions[0]; /* Actions. */
448 /* uint8_t data[0]; */ /* Packet data. The length is inferred
449 from the length field in the header.
450 (Only meaningful if buffer_id == -1.) */
452 OFP_ASSERT(sizeof(struct ofp_packet_out) == 16);
454 enum ofp_flow_mod_command {
455 OFPFC_ADD, /* New flow. */
456 OFPFC_MODIFY, /* Modify all matching flows. */
457 OFPFC_MODIFY_STRICT, /* Modify entry strictly matching wildcards */
458 OFPFC_DELETE, /* Delete all matching flows. */
459 OFPFC_DELETE_STRICT /* Strictly match wildcards and priority. */
462 /* Flow wildcards. */
463 enum ofp_flow_wildcards {
464 OFPFW_IN_PORT = 1 << 0, /* Switch input port. */
465 OFPFW_DL_VLAN = 1 << 1, /* VLAN vid. */
466 OFPFW_DL_SRC = 1 << 2, /* Ethernet source address. */
467 OFPFW_DL_DST = 1 << 3, /* Ethernet destination address. */
468 OFPFW_DL_TYPE = 1 << 4, /* Ethernet frame type. */
469 OFPFW_NW_PROTO = 1 << 5, /* IP protocol. */
470 OFPFW_TP_SRC = 1 << 6, /* TCP/UDP source port. */
471 OFPFW_TP_DST = 1 << 7, /* TCP/UDP destination port. */
473 /* IP source address wildcard bit count. 0 is exact match, 1 ignores the
474 * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
475 * the entire field. This is the *opposite* of the usual convention where
476 * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded. */
477 OFPFW_NW_SRC_SHIFT = 8,
478 OFPFW_NW_SRC_BITS = 6,
479 OFPFW_NW_SRC_MASK = ((1 << OFPFW_NW_SRC_BITS) - 1) << OFPFW_NW_SRC_SHIFT,
480 OFPFW_NW_SRC_ALL = 32 << OFPFW_NW_SRC_SHIFT,
482 /* IP destination address wildcard bit count. Same format as source. */
483 OFPFW_NW_DST_SHIFT = 14,
484 OFPFW_NW_DST_BITS = 6,
485 OFPFW_NW_DST_MASK = ((1 << OFPFW_NW_DST_BITS) - 1) << OFPFW_NW_DST_SHIFT,
486 OFPFW_NW_DST_ALL = 32 << OFPFW_NW_DST_SHIFT,
488 OFPFW_DL_VLAN_PCP = 1 << 20, /* VLAN priority. */
489 OFPFW_NW_TOS = 1 << 21, /* IP ToS (DSCP field, 6 bits). */
491 /* Wildcard all fields. */
492 OFPFW_ALL = ((1 << 22) - 1)
495 /* The wildcards for ICMP type and code fields use the transport source
496 * and destination port fields, respectively. */
497 #define OFPFW_ICMP_TYPE OFPFW_TP_SRC
498 #define OFPFW_ICMP_CODE OFPFW_TP_DST
500 /* Values below this cutoff are 802.3 packets and the two bytes
501 * following MAC addresses are used as a frame length. Otherwise, the
502 * two bytes are used as the Ethernet type.
504 #define OFP_DL_TYPE_ETH2_CUTOFF 0x0600
506 /* Value of dl_type to indicate that the frame does not include an
509 #define OFP_DL_TYPE_NOT_ETH_TYPE 0x05ff
511 /* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
512 * special conditions. All ones indicates that no VLAN id was set.
514 #define OFP_VLAN_NONE 0xffff
516 /* Fields to match against flows */
518 uint32_t wildcards; /* Wildcard fields. */
519 uint16_t in_port; /* Input switch port. */
520 uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
521 uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
522 uint16_t dl_vlan; /* Input VLAN. */
523 uint8_t dl_vlan_pcp; /* Input VLAN priority. */
524 uint8_t pad1[1]; /* Align to 64-bits. */
525 uint16_t dl_type; /* Ethernet frame type. */
526 uint8_t nw_tos; /* IP ToS (DSCP field, 6 bits). */
527 uint8_t nw_proto; /* IP protocol or lower 8 bits of
529 uint8_t pad2[2]; /* Align to 64-bits. */
530 uint32_t nw_src; /* IP source address. */
531 uint32_t nw_dst; /* IP destination address. */
532 uint16_t tp_src; /* TCP/UDP source port. */
533 uint16_t tp_dst; /* TCP/UDP destination port. */
535 OFP_ASSERT(sizeof(struct ofp_match) == 40);
537 /* The match fields for ICMP type and code use the transport source and
538 * destination port fields, respectively. */
539 #define icmp_type tp_src
540 #define icmp_code tp_dst
542 /* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
544 #define OFP_FLOW_PERMANENT 0
546 /* By default, choose a priority in the middle. */
547 #define OFP_DEFAULT_PRIORITY 0x8000
549 enum ofp_flow_mod_flags {
550 OFPFF_SEND_FLOW_REM = 1 << 0, /* Send flow removed message when flow
551 * expires or is deleted. */
552 OFPFF_CHECK_OVERLAP = 1 << 1, /* Check for overlapping entries first. */
553 OFPFF_EMERG = 1 << 2 /* Ramark this is for emergency. */
556 /* Flow setup and teardown (controller -> datapath). */
557 struct ofp_flow_mod {
558 struct ofp_header header;
559 struct ofp_match match; /* Fields to match */
560 uint64_t cookie; /* Opaque controller-issued identifier. */
563 uint16_t command; /* One of OFPFC_*. */
564 uint16_t idle_timeout; /* Idle time before discarding (seconds). */
565 uint16_t hard_timeout; /* Max time before discarding (seconds). */
566 uint16_t priority; /* Priority level of flow entry. */
567 uint32_t buffer_id; /* Buffered packet to apply to (or -1).
568 Not meaningful for OFPFC_DELETE*. */
569 uint16_t out_port; /* For OFPFC_DELETE* commands, require
570 matching entries to include this as an
571 output port. A value of OFPP_NONE
572 indicates no restriction. */
573 uint16_t flags; /* One of OFPFF_*. */
574 struct ofp_action_header actions[0]; /* The action length is inferred
575 from the length field in the
578 OFP_ASSERT(sizeof(struct ofp_flow_mod) == 72);
580 /* Why was this flow removed? */
581 enum ofp_flow_removed_reason {
582 OFPRR_IDLE_TIMEOUT, /* Flow idle time exceeded idle_timeout. */
583 OFPRR_HARD_TIMEOUT, /* Time exceeded hard_timeout. */
584 OFPRR_DELETE /* Evicted by a DELETE flow mod. */
587 /* Flow removed (datapath -> controller). */
588 struct ofp_flow_removed {
589 struct ofp_header header;
590 struct ofp_match match; /* Description of fields. */
591 uint64_t cookie; /* Opaque controller-issued identifier. */
593 uint16_t priority; /* Priority level of flow entry. */
594 uint8_t reason; /* One of OFPRR_*. */
595 uint8_t pad[1]; /* Align to 32-bits. */
597 uint32_t duration_sec; /* Time flow was alive in seconds. */
598 uint32_t duration_nsec; /* Time flow was alive in nanoseconds beyond
600 uint16_t idle_timeout; /* Idle timeout from original flow mod. */
601 uint8_t pad2[2]; /* Align to 64-bits. */
602 uint64_t packet_count;
605 OFP_ASSERT(sizeof(struct ofp_flow_removed) == 88);
607 /* Values for 'type' in ofp_error_message. These values are immutable: they
608 * will not change in future versions of the protocol (although new values may
610 enum ofp_error_type {
611 OFPET_HELLO_FAILED, /* Hello protocol failed. */
612 OFPET_BAD_REQUEST, /* Request was not understood. */
613 OFPET_BAD_ACTION, /* Error in action description. */
614 OFPET_FLOW_MOD_FAILED, /* Problem modifying flow entry. */
615 OFPET_PORT_MOD_FAILED, /* OFPT_PORT_MOD failed. */
616 OFPET_QUEUE_OP_FAILED /* Queue operation failed. */
619 /* ofp_error_msg 'code' values for OFPET_HELLO_FAILED. 'data' contains an
620 * ASCII text string that may give failure details. */
621 enum ofp_hello_failed_code {
622 OFPHFC_INCOMPATIBLE, /* No compatible version. */
623 OFPHFC_EPERM /* Permissions error. */
626 /* ofp_error_msg 'code' values for OFPET_BAD_REQUEST. 'data' contains at least
627 * the first 64 bytes of the failed request. */
628 enum ofp_bad_request_code {
629 OFPBRC_BAD_VERSION, /* ofp_header.version not supported. */
630 OFPBRC_BAD_TYPE, /* ofp_header.type not supported. */
631 OFPBRC_BAD_STAT, /* ofp_stats_request.type not supported. */
632 OFPBRC_BAD_VENDOR, /* Vendor not supported (in ofp_vendor_header
633 * or ofp_stats_request or ofp_stats_reply). */
634 OFPBRC_BAD_SUBTYPE, /* Vendor subtype not supported. */
635 OFPBRC_EPERM, /* Permissions error. */
636 OFPBRC_BAD_LEN, /* Wrong request length for type. */
637 OFPBRC_BUFFER_EMPTY, /* Specified buffer has already been used. */
638 OFPBRC_BUFFER_UNKNOWN /* Specified buffer does not exist. */
641 /* ofp_error_msg 'code' values for OFPET_BAD_ACTION. 'data' contains at least
642 * the first 64 bytes of the failed request. */
643 enum ofp_bad_action_code {
644 OFPBAC_BAD_TYPE, /* Unknown action type. */
645 OFPBAC_BAD_LEN, /* Length problem in actions. */
646 OFPBAC_BAD_VENDOR, /* Unknown vendor id specified. */
647 OFPBAC_BAD_VENDOR_TYPE, /* Unknown action type for vendor id. */
648 OFPBAC_BAD_OUT_PORT, /* Problem validating output action. */
649 OFPBAC_BAD_ARGUMENT, /* Bad action argument. */
650 OFPBAC_EPERM, /* Permissions error. */
651 OFPBAC_TOO_MANY, /* Can't handle this many actions. */
652 OFPBAC_BAD_QUEUE /* Problem validating output queue. */
655 /* ofp_error_msg 'code' values for OFPET_FLOW_MOD_FAILED. 'data' contains
656 * at least the first 64 bytes of the failed request. */
657 enum ofp_flow_mod_failed_code {
658 OFPFMFC_ALL_TABLES_FULL, /* Flow not added because of full tables. */
659 OFPFMFC_OVERLAP, /* Attempted to add overlapping flow with
660 * CHECK_OVERLAP flag set. */
661 OFPFMFC_EPERM, /* Permissions error. */
662 OFPFMFC_BAD_EMERG_TIMEOUT, /* Flow not added because of non-zero idle/hard
664 OFPFMFC_BAD_COMMAND, /* Unknown command. */
665 OFPFMFC_UNSUPPORTED /* Unsupported action list - cannot process in
666 the order specified. */
669 /* ofp_error_msg 'code' values for OFPET_PORT_MOD_FAILED. 'data' contains
670 * at least the first 64 bytes of the failed request. */
671 enum ofp_port_mod_failed_code {
672 OFPPMFC_BAD_PORT, /* Specified port does not exist. */
673 OFPPMFC_BAD_HW_ADDR, /* Specified hardware address is wrong. */
676 /* ofp_error msg 'code' values for OFPET_QUEUE_OP_FAILED. 'data' contains
677 * at least the first 64 bytes of the failed request */
678 enum ofp_queue_op_failed_code {
679 OFPQOFC_BAD_PORT, /* Invalid port (or port does not exist). */
680 OFPQOFC_BAD_QUEUE, /* Queue does not exist. */
681 OFPQOFC_EPERM /* Permissions error. */
684 /* OFPT_ERROR: Error message (datapath -> controller). */
685 struct ofp_error_msg {
686 struct ofp_header header;
690 uint8_t data[0]; /* Variable-length data. Interpreted based
691 on the type and code. */
693 OFP_ASSERT(sizeof(struct ofp_error_msg) == 12);
695 enum ofp_stats_types {
696 /* Description of this OpenFlow switch.
697 * The request body is empty.
698 * The reply body is struct ofp_desc_stats. */
701 /* Individual flow statistics.
702 * The request body is struct ofp_flow_stats_request.
703 * The reply body is an array of struct ofp_flow_stats. */
706 /* Aggregate flow statistics.
707 * The request body is struct ofp_aggregate_stats_request.
708 * The reply body is struct ofp_aggregate_stats_reply. */
711 /* Flow table statistics.
712 * The request body is empty.
713 * The reply body is an array of struct ofp_table_stats. */
716 /* Physical port statistics.
717 * The request body is struct ofp_port_stats_request.
718 * The reply body is an array of struct ofp_port_stats. */
721 /* Queue statistics for a port
722 * The request body defines the port
723 * The reply body is an array of struct ofp_queue_stats */
727 * The request and reply bodies begin with a 32-bit vendor ID, which takes
728 * the same form as in "struct ofp_vendor_header". The request and reply
729 * bodies are otherwise vendor-defined. */
730 OFPST_VENDOR = 0xffff
733 struct ofp_stats_request {
734 struct ofp_header header;
735 uint16_t type; /* One of the OFPST_* constants. */
736 uint16_t flags; /* OFPSF_REQ_* flags (none yet defined). */
737 uint8_t body[0]; /* Body of the request. */
739 OFP_ASSERT(sizeof(struct ofp_stats_request) == 12);
741 enum ofp_stats_reply_flags {
742 OFPSF_REPLY_MORE = 1 << 0 /* More replies to follow. */
745 struct ofp_stats_reply {
746 struct ofp_header header;
747 uint16_t type; /* One of the OFPST_* constants. */
748 uint16_t flags; /* OFPSF_REPLY_* flags. */
749 uint8_t body[0]; /* Body of the reply. */
751 OFP_ASSERT(sizeof(struct ofp_stats_reply) == 12);
753 #define DESC_STR_LEN 256
754 #define SERIAL_NUM_LEN 32
755 /* Body of reply to OFPST_DESC request. Each entry is a NULL-terminated
757 struct ofp_desc_stats {
758 char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */
759 char hw_desc[DESC_STR_LEN]; /* Hardware description. */
760 char sw_desc[DESC_STR_LEN]; /* Software description. */
761 char serial_num[SERIAL_NUM_LEN]; /* Serial number. */
762 char dp_desc[DESC_STR_LEN]; /* Human readable description of
765 OFP_ASSERT(sizeof(struct ofp_desc_stats) == 1056);
767 /* Body for ofp_stats_request of type OFPST_FLOW. */
768 struct ofp_flow_stats_request {
769 struct ofp_match match; /* Fields to match. */
770 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
771 or 0xff for all tables. */
772 uint8_t pad; /* Align to 32 bits. */
773 uint16_t out_port; /* Require matching entries to include this
774 as an output port. A value of OFPP_NONE
775 indicates no restriction. */
777 OFP_ASSERT(sizeof(struct ofp_flow_stats_request) == 44);
779 /* Body of reply to OFPST_FLOW request. */
780 struct ofp_flow_stats {
781 uint16_t length; /* Length of this entry. */
782 uint8_t table_id; /* ID of table flow came from. */
784 struct ofp_match match; /* Description of fields. */
785 uint32_t duration_sec; /* Time flow has been alive in seconds. */
786 uint32_t duration_nsec; /* Time flow has been alive in nanoseconds
787 beyond duration_sec. */
788 uint16_t priority; /* Priority of the entry. Only meaningful
789 when this is not an exact-match entry. */
790 uint16_t idle_timeout; /* Number of seconds idle before expiration. */
791 uint16_t hard_timeout; /* Number of seconds before expiration. */
792 uint8_t pad2[6]; /* Align to 64 bits. */
793 uint64_t cookie; /* Opaque controller-issued identifier. */
794 uint64_t packet_count; /* Number of packets in flow. */
795 uint64_t byte_count; /* Number of bytes in flow. */
796 struct ofp_action_header actions[0]; /* Actions. */
798 OFP_ASSERT(sizeof(struct ofp_flow_stats) == 88);
800 /* Body for ofp_stats_request of type OFPST_AGGREGATE. */
801 struct ofp_aggregate_stats_request {
802 struct ofp_match match; /* Fields to match. */
803 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
804 or 0xff for all tables. */
805 uint8_t pad; /* Align to 32 bits. */
806 uint16_t out_port; /* Require matching entries to include this
807 as an output port. A value of OFPP_NONE
808 indicates no restriction. */
810 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_request) == 44);
812 /* Body of reply to OFPST_AGGREGATE request. */
813 struct ofp_aggregate_stats_reply {
814 uint64_t packet_count; /* Number of packets in flows. */
815 uint64_t byte_count; /* Number of bytes in flows. */
816 uint32_t flow_count; /* Number of flows. */
817 uint8_t pad[4]; /* Align to 64 bits. */
819 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
821 /* Body of reply to OFPST_TABLE request. */
822 struct ofp_table_stats {
823 uint8_t table_id; /* Identifier of table. Lower numbered tables
824 are consulted first. */
825 uint8_t pad[3]; /* Align to 32-bits. */
826 char name[OFP_MAX_TABLE_NAME_LEN];
827 uint32_t wildcards; /* Bitmap of OFPFW_* wildcards that are
828 supported by the table. */
829 uint32_t max_entries; /* Max number of entries supported. */
830 uint32_t active_count; /* Number of active entries. */
831 uint64_t lookup_count; /* Number of packets looked up in table. */
832 uint64_t matched_count; /* Number of packets that hit table. */
834 OFP_ASSERT(sizeof(struct ofp_table_stats) == 64);
836 /* Body for ofp_stats_request of type OFPST_PORT. */
837 struct ofp_port_stats_request {
838 uint16_t port_no; /* OFPST_PORT message may request statistics
839 for a single port (specified with port_no)
840 or for all ports (port_no == OFPP_NONE). */
843 OFP_ASSERT(sizeof(struct ofp_port_stats_request) == 8);
845 /* Body of reply to OFPST_PORT request. If a counter is unsupported, set
846 * the field to all ones. */
847 struct ofp_port_stats {
849 uint8_t pad[6]; /* Align to 64-bits. */
850 uint64_t rx_packets; /* Number of received packets. */
851 uint64_t tx_packets; /* Number of transmitted packets. */
852 uint64_t rx_bytes; /* Number of received bytes. */
853 uint64_t tx_bytes; /* Number of transmitted bytes. */
854 uint64_t rx_dropped; /* Number of packets dropped by RX. */
855 uint64_t tx_dropped; /* Number of packets dropped by TX. */
856 uint64_t rx_errors; /* Number of receive errors. This is a super-set
857 of receive errors and should be great than or
858 equal to the sum of all rx_*_err values. */
859 uint64_t tx_errors; /* Number of transmit errors. This is a super-set
860 of transmit errors. */
861 uint64_t rx_frame_err; /* Number of frame alignment errors. */
862 uint64_t rx_over_err; /* Number of packets with RX overrun. */
863 uint64_t rx_crc_err; /* Number of CRC errors. */
864 uint64_t collisions; /* Number of collisions. */
866 OFP_ASSERT(sizeof(struct ofp_port_stats) == 104);
868 /* Vendor extension. */
869 struct ofp_vendor_header {
870 struct ofp_header header; /* Type OFPT_VENDOR. */
871 uint32_t vendor; /* Vendor ID:
872 * - MSB 0: low-order bytes are IEEE OUI.
873 * - MSB != 0: defined by OpenFlow
875 /* Vendor-defined arbitrary additional data. */
877 OFP_ASSERT(sizeof(struct ofp_vendor_header) == 12);
879 #endif /* openflow/openflow.h */