1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
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:
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
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
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.
34 /* OpenFlow: protocol between controller and datapath. */
36 #ifndef OPENFLOW_OPENFLOW_H
37 #define OPENFLOW_OPENFLOW_H 1
40 #include <linux/types.h>
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 */
57 #define OFP_PACKED __attribute__((packed))
59 #define OFP_PACKED /* SWIG doesn't understand __attribute. */
63 * Non-experimental versions released: 0x01
64 * Experimental versions released: 0x81 -- 0x99
66 /* The most significant bit being set in the version field indicates an
67 * experimental OpenFlow version.
69 #define OFP_VERSION 0x01
71 #define OFP_MAX_TABLE_NAME_LEN 32
72 #define OFP_MAX_PORT_NAME_LEN 16
74 #define OFP_TCP_PORT 6633
75 #define OFP_SSL_PORT 6633
77 #define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
79 /* Port numbering. Physical ports are numbered starting from 1. */
81 /* Maximum number of physical switch ports. */
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
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. */
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 */
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 */
116 /* Asynchronous messages. */
117 OFPT_PACKET_IN
, /* Async message */
118 OFPT_FLOW_REMOVED
, /* Async message */
119 OFPT_PORT_STATUS
, /* Async message */
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 */
126 /* Statistics messages. */
127 OFPT_STATS_REQUEST
, /* Controller/switch message */
128 OFPT_STATS_REPLY
, /* Controller/switch message */
130 /* Barrier messages. */
131 OFPT_BARRIER_REQUEST
, /* Controller/switch message */
132 OFPT_BARRIER_REPLY
, /* Controller/switch message */
134 /* Queue Configuration messages. */
135 OFPT_QUEUE_GET_CONFIG_REQUEST
, /* Controller/switch message */
136 OFPT_QUEUE_GET_CONFIG_REPLY
/* Controller/switch message */
140 /* Header on all OpenFlow packets. */
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. */
149 OFP_ASSERT(sizeof(struct ofp_header
) == 8);
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. */
154 struct ofp_header header
;
157 #define OFP_DEFAULT_MISS_SEND_LEN 128
159 enum 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). */
167 /* Switch configuration. */
168 struct 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. */
174 OFP_ASSERT(sizeof(struct ofp_switch_config
) == 12);
176 /* Capabilities supported by the datapath. */
177 enum 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. */
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.
192 enum ofp_port_config
{
193 OFPPC_PORT_DOWN
= 1 << 0, /* Port is administratively down. */
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
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. */
204 /* Current state of the physical port. These are not configurable from
207 enum ofp_port_state
{
208 OFPPS_LINK_DOWN
= 1 << 0, /* No physical link present. */
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
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. */
221 /* Features of physical ports available in a datapath. */
222 enum 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. */
237 /* Description of a physical port */
238 struct ofp_phy_port
{
240 uint8_t hw_addr
[OFP_ETH_ALEN
];
241 char name
[OFP_MAX_PORT_NAME_LEN
]; /* Null-terminated */
243 uint32_t config
; /* Bitmap of OFPPC_* flags. */
244 uint32_t state
; /* Bitmap of OFPPS_* flags. */
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. */
253 OFP_ASSERT(sizeof(struct ofp_phy_port
) == 48);
255 /* Switch features. */
256 struct 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. */
262 uint32_t n_buffers
; /* Max packets buffered at once. */
264 uint8_t n_tables
; /* Number of tables supported by datapath. */
265 uint8_t pad
[3]; /* Align to 64-bits. */
268 uint32_t capabilities
; /* Bitmap of support "ofp_capabilities". */
269 uint32_t actions
; /* Bitmap of supported "ofp_action_type"s. */
272 struct ofp_phy_port ports
[0]; /* Port definitions. The number of ports
273 is inferred from the length field in
276 OFP_ASSERT(sizeof(struct ofp_switch_features
) == 32);
278 /* What changed about the physical port */
279 enum 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. */
285 /* A physical port has changed in the datapath */
286 struct 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
;
292 OFP_ASSERT(sizeof(struct ofp_port_status
) == 64);
294 /* Modify behavior of the physical port */
295 struct ofp_port_mod
{
296 struct ofp_header header
;
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. */
304 uint32_t config
; /* Bitmap of OFPPC_* flags. */
305 uint32_t mask
; /* Bitmap of OFPPC_* flags to be changed. */
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. */
311 OFP_ASSERT(sizeof(struct ofp_port_mod
) == 32);
313 /* Why is this packet being sent to the controller? */
314 enum ofp_packet_in_reason
{
315 OFPR_NO_MATCH
, /* No matching flow. */
316 OFPR_ACTION
/* Action explicitly output to controller. */
319 /* Packet received on port (datapath -> controller). */
320 struct 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_*) */
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. */
334 OFP_ASSERT(sizeof(struct ofp_packet_in
) == 20);
336 enum 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
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.*/
356 struct 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. */
362 OFP_ASSERT(sizeof(struct ofp_action_output
) == 8);
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
367 #define OFP_VLAN_NONE 0xffff
369 /* Action structure for OFPAT_SET_VLAN_VID. */
370 struct 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. */
376 OFP_ASSERT(sizeof(struct ofp_action_vlan_vid
) == 8);
378 /* Action structure for OFPAT_SET_VLAN_PCP. */
379 struct 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. */
385 OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp
) == 8);
387 /* Action structure for OFPAT_SET_DL_SRC/DST. */
388 struct 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. */
394 OFP_ASSERT(sizeof(struct ofp_action_dl_addr
) == 16);
396 /* Action structure for OFPAT_SET_NW_SRC/DST. */
397 struct 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. */
402 OFP_ASSERT(sizeof(struct ofp_action_nw_addr
) == 8);
404 /* Action structure for OFPAT_SET_TP_SRC/DST. */
405 struct 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. */
411 OFP_ASSERT(sizeof(struct ofp_action_tp_port
) == 8);
413 /* Action structure for OFPAT_SET_NW_TOS. */
414 struct 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). */
420 OFP_ASSERT(sizeof(struct ofp_action_nw_tos
) == 8);
422 /* Action header for OFPAT_VENDOR. The rest of the body is vendor-defined. */
423 struct 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". */
429 OFP_ASSERT(sizeof(struct ofp_action_vendor_header
) == 8);
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. */
434 struct 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
442 OFP_ASSERT(sizeof(struct ofp_action_header
) == 8);
444 /* Send packet (controller -> datapath). */
445 struct 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.) */
455 OFP_ASSERT(sizeof(struct ofp_packet_out
) == 16);
457 enum 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. */
465 /* Flow wildcards. */
466 enum 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. */
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
,
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
,
491 OFPFW_DL_VLAN_PCP
= 1 << 20, /* VLAN priority. */
492 OFPFW_NW_TOS
= 1 << 21, /* IP ToS (DSCP field, 6 bits). */
494 /* Wildcard all fields. */
495 OFPFW_ALL
= ((1 << 22) - 1)
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
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.
507 #define OFP_DL_TYPE_ETH2_CUTOFF 0x0600
509 /* Value of dl_type to indicate that the frame does not include an
512 #define OFP_DL_TYPE_NOT_ETH_TYPE 0x05ff
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.
517 #define OFP_VLAN_NONE 0xffff
519 /* Fields to match against flows */
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
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. */
538 OFP_ASSERT(sizeof(struct ofp_match
) == 40);
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
545 /* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
547 #define OFP_FLOW_PERMANENT 0
549 /* By default, choose a priority in the middle. */
550 #define OFP_DEFAULT_PRIORITY 0x8000
552 enum 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. */
559 /* Flow setup and teardown (controller -> datapath). */
560 struct ofp_flow_mod
{
561 struct ofp_header header
;
562 struct ofp_match match
; /* Fields to match */
563 uint64_t cookie
; /* Opaque controller-issued identifier. */
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
581 OFP_ASSERT(sizeof(struct ofp_flow_mod
) == 72);
583 /* Why was this flow removed? */
584 enum 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. */
590 /* Flow removed (datapath -> controller). */
591 struct ofp_flow_removed
{
592 struct ofp_header header
;
593 struct ofp_match match
; /* Description of fields. */
594 uint64_t cookie
; /* Opaque controller-issued identifier. */
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. */
600 uint32_t duration_sec
; /* Time flow was alive in seconds. */
601 uint32_t duration_nsec
; /* Time flow was alive in nanoseconds beyond
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
;
608 OFP_ASSERT(sizeof(struct ofp_flow_removed
) == 88);
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
613 enum 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. */
622 /* ofp_error_msg 'code' values for OFPET_HELLO_FAILED. 'data' contains an
623 * ASCII text string that may give failure details. */
624 enum ofp_hello_failed_code
{
625 OFPHFC_INCOMPATIBLE
, /* No compatible version. */
626 OFPHFC_EPERM
/* Permissions error. */
629 /* ofp_error_msg 'code' values for OFPET_BAD_REQUEST. 'data' contains at least
630 * the first 64 bytes of the failed request. */
631 enum 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. */
644 /* ofp_error_msg 'code' values for OFPET_BAD_ACTION. 'data' contains at least
645 * the first 64 bytes of the failed request. */
646 enum 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. */
658 /* ofp_error_msg 'code' values for OFPET_FLOW_MOD_FAILED. 'data' contains
659 * at least the first 64 bytes of the failed request. */
660 enum 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
667 OFPFMFC_BAD_COMMAND
, /* Unknown command. */
668 OFPFMFC_UNSUPPORTED
/* Unsupported action list - cannot process in
669 * the order specified. */
672 /* ofp_error_msg 'code' values for OFPET_PORT_MOD_FAILED. 'data' contains
673 * at least the first 64 bytes of the failed request. */
674 enum ofp_port_mod_failed_code
{
675 OFPPMFC_BAD_PORT
, /* Specified port does not exist. */
676 OFPPMFC_BAD_HW_ADDR
, /* Specified hardware address is wrong. */
679 /* ofp_error msg 'code' values for OFPET_QUEUE_OP_FAILED. 'data' contains
680 * at least the first 64 bytes of the failed request */
681 enum 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. */
687 /* OFPT_ERROR: Error message (datapath -> controller). */
688 struct ofp_error_msg
{
689 struct ofp_header header
;
693 uint8_t data
[0]; /* Variable-length data. Interpreted based
694 on the type and code. */
696 OFP_ASSERT(sizeof(struct ofp_error_msg
) == 12);
698 enum ofp_stats_types
{
699 /* Description of this OpenFlow switch.
700 * The request body is empty.
701 * The reply body is struct ofp_desc_stats. */
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. */
709 /* Aggregate flow statistics.
710 * The request body is struct ofp_aggregate_stats_request.
711 * The reply body is struct ofp_aggregate_stats_reply. */
714 /* Flow table statistics.
715 * The request body is empty.
716 * The reply body is an array of struct ofp_table_stats. */
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. */
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 */
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
736 struct 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. */
742 OFP_ASSERT(sizeof(struct ofp_stats_request
) == 12);
744 enum ofp_stats_reply_flags
{
745 OFPSF_REPLY_MORE
= 1 << 0 /* More replies to follow. */
748 struct 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. */
754 OFP_ASSERT(sizeof(struct ofp_stats_reply
) == 12);
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
760 struct 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. */
767 OFP_ASSERT(sizeof(struct ofp_desc_stats
) == 1056);
769 /* Body for ofp_stats_request of type OFPST_FLOW. */
770 struct 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. */
779 OFP_ASSERT(sizeof(struct ofp_flow_stats_request
) == 44);
781 /* Body of reply to OFPST_FLOW request. */
782 struct ofp_flow_stats
{
783 uint16_t length
; /* Length of this entry. */
784 uint8_t table_id
; /* ID of table flow came from. */
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
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. */
800 OFP_ASSERT(sizeof(struct ofp_flow_stats
) == 88);
802 /* Body for ofp_stats_request of type OFPST_AGGREGATE. */
803 struct 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. */
812 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_request
) == 44);
814 /* Body of reply to OFPST_AGGREGATE request. */
815 struct 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. */
821 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply
) == 24);
823 /* Body of reply to OFPST_TABLE request. */
824 struct 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. */
836 OFP_ASSERT(sizeof(struct ofp_table_stats
) == 64);
838 /* Body for ofp_stats_request of type OFPST_PORT. */
839 struct 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 ==
846 OFP_ASSERT(sizeof(struct ofp_port_stats_request
) == 8);
848 /* Body of reply to OFPST_PORT request. If a counter is unsupported, set
849 * the field to all ones. */
850 struct ofp_port_stats
{
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
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. */
872 OFP_ASSERT(sizeof(struct ofp_port_stats
) == 104);
874 /* Vendor extension. */
875 struct 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
881 /* Vendor-defined arbitrary additional data. */
883 OFP_ASSERT(sizeof(struct ofp_vendor_header
) == 12);
885 /* All ones is used to indicate all queues in a port (for stats retrieval). */
886 #define OFPQ_ALL 0xffffffff
888 /* Min rate > 1000 means not configured. */
889 #define OFPQ_MIN_RATE_UNCFG 0xffff
891 enum 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). */
898 /* Common description for a queue. */
899 struct 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. */
904 OFP_ASSERT(sizeof(struct ofp_queue_prop_header
) == 8);
906 /* Min-Rate queue property description. */
907 struct 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 */
912 OFP_ASSERT(sizeof(struct ofp_queue_prop_min_rate
) == 16);
914 /* Full description for a queue. */
915 struct 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. */
921 OFP_ASSERT(sizeof(struct ofp_packet_queue
) == 8);
923 /* Query for port queue configuration. */
924 struct 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. */
930 OFP_ASSERT(sizeof(struct ofp_queue_get_config_request
) == 12);
932 /* Queue configuration for a given port. */
933 struct ofp_queue_get_config_reply
{
934 struct ofp_header header
;
937 struct ofp_packet_queue queues
[0]; /* List of configured queues. */
939 OFP_ASSERT(sizeof(struct ofp_queue_get_config_reply
) == 16);
941 /* OFPAT_ENQUEUE action struct: send packets to given queue on port. */
942 struct 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. */
951 OFP_ASSERT(sizeof(struct ofp_action_enqueue
) == 16);
953 struct 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. */
958 OFP_ASSERT(sizeof(struct ofp_queue_stats_request
) == 8);
960 struct ofp_queue_stats
{
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. */
968 OFP_ASSERT(sizeof(struct ofp_queue_stats
) == 32);
970 #endif /* openflow/openflow.h */