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