2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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_OPENFLOW10_H
20 #define OPENFLOW_OPENFLOW10_H 1
22 #include "openflow/openflow-common.h"
24 /* Port number(s) meaning
25 * --------------- --------------------------------------
26 * 0x0000 not assigned a meaning by OpenFlow 1.0
27 * 0x0001...0xfeff "physical" ports
28 * 0xff00...0xfff7 "reserved" but not assigned a meaning by OpenFlow 1.0
29 * 0xfff8...0xffff "reserved" OFPP_* ports with assigned meanings
33 #define OFPP_MAX OFP_PORT_C(0xff00) /* Max # of switch ports. */
34 #define OFPP_FIRST_RESV OFP_PORT_C(0xfff8) /* First assigned reserved port. */
35 #define OFPP_LAST_RESV OFP_PORT_C(0xffff) /* Last assigned reserved port. */
37 /* Reserved output "ports". */
38 #define OFPP_IN_PORT OFP_PORT_C(0xfff8) /* Where the packet came in. */
39 #define OFPP_TABLE OFP_PORT_C(0xfff9) /* Perform actions in flow table. */
40 #define OFPP_NORMAL OFP_PORT_C(0xfffa) /* Process with normal L2/L3. */
41 #define OFPP_FLOOD OFP_PORT_C(0xfffb) /* All ports except input port and
42 * ports disabled by STP. */
43 #define OFPP_ALL OFP_PORT_C(0xfffc) /* All ports except input port. */
44 #define OFPP_CONTROLLER OFP_PORT_C(0xfffd) /* Send to controller. */
45 #define OFPP_LOCAL OFP_PORT_C(0xfffe) /* Local openflow "port". */
46 #define OFPP_NONE OFP_PORT_C(0xffff) /* Not associated with any port. */
48 /* OpenFlow 1.0 specific capabilities supported by the datapath (struct
49 * ofp_switch_features, member capabilities). */
50 enum ofp10_capabilities {
51 OFPC10_STP = 1 << 3, /* 802.1d spanning tree. */
52 OFPC10_RESERVED = 1 << 4, /* Reserved, must not be set. */
55 /* OpenFlow 1.0 specific flags to indicate behavior of the physical port.
56 * These flags are used in ofp10_phy_port to describe the current
57 * configuration. They are used in the ofp10_port_mod message to configure the
60 enum ofp10_port_config {
61 OFPPC10_NO_STP = 1 << 1, /* Disable 802.1D spanning tree on port. */
62 OFPPC10_NO_RECV_STP = 1 << 3, /* Drop received 802.1D STP packets. */
63 OFPPC10_NO_FLOOD = 1 << 4, /* Do not include port when flooding. */
64 #define OFPPC10_ALL (OFPPC_PORT_DOWN | OFPPC10_NO_STP | OFPPC_NO_RECV | \
65 OFPPC10_NO_RECV_STP | OFPPC10_NO_FLOOD | OFPPC_NO_FWD | \
69 /* OpenFlow 1.0 specific current state of the physical port. These are not
70 * configurable from the controller.
72 enum ofp10_port_state {
73 /* The OFPPS10_STP_* bits have no effect on switch operation. The
74 * controller must adjust OFPPC_NO_RECV, OFPPC_NO_FWD, and
75 * OFPPC_NO_PACKET_IN appropriately to fully implement an 802.1D spanning
77 OFPPS10_STP_LISTEN = 0 << 8, /* Not learning or relaying frames. */
78 OFPPS10_STP_LEARN = 1 << 8, /* Learning but not relaying frames. */
79 OFPPS10_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
80 OFPPS10_STP_BLOCK = 3 << 8, /* Not part of spanning tree. */
81 OFPPS10_STP_MASK = 3 << 8 /* Bit mask for OFPPS10_STP_* values. */
83 #define OFPPS10_ALL (OFPPS_LINK_DOWN | OFPPS10_STP_MASK)
86 /* OpenFlow 1.0 specific features of physical ports available in a datapath. */
87 enum ofp10_port_features {
88 OFPPF10_COPPER = 1 << 7, /* Copper medium. */
89 OFPPF10_FIBER = 1 << 8, /* Fiber medium. */
90 OFPPF10_AUTONEG = 1 << 9, /* Auto-negotiation. */
91 OFPPF10_PAUSE = 1 << 10, /* Pause. */
92 OFPPF10_PAUSE_ASYM = 1 << 11 /* Asymmetric pause. */
95 /* Description of a physical port */
96 struct ofp10_phy_port {
98 uint8_t hw_addr[OFP_ETH_ALEN];
99 char name[OFP_MAX_PORT_NAME_LEN]; /* Null-terminated */
101 ovs_be32 config; /* Bitmap of OFPPC_* and OFPPC10_* flags. */
102 ovs_be32 state; /* Bitmap of OFPPS_* and OFPPS10_* flags. */
104 /* Bitmaps of OFPPF_* and OFPPF10_* that describe features. All bits
105 * zeroed if unsupported or unavailable. */
106 ovs_be32 curr; /* Current features. */
107 ovs_be32 advertised; /* Features being advertised by the port. */
108 ovs_be32 supported; /* Features supported by the port. */
109 ovs_be32 peer; /* Features advertised by peer. */
111 OFP_ASSERT(sizeof(struct ofp10_phy_port) == 48);
113 /* Modify behavior of the physical port */
114 struct ofp10_port_mod {
116 uint8_t hw_addr[OFP_ETH_ALEN]; /* The hardware address is not
117 configurable. This is used to
118 sanity-check the request, so it must
119 be the same as returned in an
120 ofp10_phy_port struct. */
122 ovs_be32 config; /* Bitmap of OFPPC_* flags. */
123 ovs_be32 mask; /* Bitmap of OFPPC_* flags to be changed. */
125 ovs_be32 advertise; /* Bitmap of "ofp_port_features"s. Zero all
126 bits to prevent any action taking place. */
127 uint8_t pad[4]; /* Pad to 64-bits. */
129 OFP_ASSERT(sizeof(struct ofp10_port_mod) == 24);
131 struct ofp10_packet_queue {
132 ovs_be32 queue_id; /* id for the specific queue. */
133 ovs_be16 len; /* Length in bytes of this queue desc. */
134 uint8_t pad[2]; /* 64-bit alignment. */
135 /* Followed by any number of queue properties expressed using
136 * ofp_queue_prop_header, to fill out a total of 'len' bytes. */
138 OFP_ASSERT(sizeof(struct ofp10_packet_queue) == 8);
140 /* Query for port queue configuration. */
141 struct ofp10_queue_get_config_request {
142 ovs_be16 port; /* Port to be queried. Should refer
143 to a valid physical port (i.e. < OFPP_MAX) */
145 /* 32-bit alignment. */
147 OFP_ASSERT(sizeof(struct ofp10_queue_get_config_request) == 4);
149 /* Queue configuration for a given port. */
150 struct ofp10_queue_get_config_reply {
153 /* struct ofp10_packet_queue queues[0]; List of configured queues. */
155 OFP_ASSERT(sizeof(struct ofp10_queue_get_config_reply) == 8);
157 /* Packet received on port (datapath -> controller). */
158 struct ofp10_packet_in {
159 ovs_be32 buffer_id; /* ID assigned by datapath. */
160 ovs_be16 total_len; /* Full length of frame. */
161 ovs_be16 in_port; /* Port on which frame was received. */
162 uint8_t reason; /* Reason packet is being sent (one of OFPR_*) */
164 uint8_t data[0]; /* Ethernet frame, halfway through 32-bit word,
165 so the IP header is 32-bit aligned. The
166 amount of data is inferred from the length
167 field in the header. Because of padding,
168 offsetof(struct ofp_packet_in, data) ==
169 sizeof(struct ofp_packet_in) - 2. */
171 OFP_ASSERT(sizeof(struct ofp10_packet_in) == 12);
173 enum ofp10_action_type {
174 OFPAT10_OUTPUT, /* Output to switch port. */
175 OFPAT10_SET_VLAN_VID, /* Set the 802.1q VLAN id. */
176 OFPAT10_SET_VLAN_PCP, /* Set the 802.1q priority. */
177 OFPAT10_STRIP_VLAN, /* Strip the 802.1q header. */
178 OFPAT10_SET_DL_SRC, /* Ethernet source address. */
179 OFPAT10_SET_DL_DST, /* Ethernet destination address. */
180 OFPAT10_SET_NW_SRC, /* IP source address. */
181 OFPAT10_SET_NW_DST, /* IP destination address. */
182 OFPAT10_SET_NW_TOS, /* IP ToS (DSCP field, 6 bits). */
183 OFPAT10_SET_TP_SRC, /* TCP/UDP source port. */
184 OFPAT10_SET_TP_DST, /* TCP/UDP destination port. */
185 OFPAT10_ENQUEUE, /* Output to queue. */
186 OFPAT10_VENDOR = 0xffff
189 /* Action structure for OFPAT10_OUTPUT, which sends packets out 'port'.
190 * When the 'port' is the OFPP_CONTROLLER, 'max_len' indicates the max
191 * number of bytes to send. A 'max_len' of zero means no bytes of the
192 * packet should be sent. */
193 struct ofp10_action_output {
194 ovs_be16 type; /* OFPAT10_OUTPUT. */
195 ovs_be16 len; /* Length is 8. */
196 ovs_be16 port; /* Output port. */
197 ovs_be16 max_len; /* Max length to send to controller. */
199 OFP_ASSERT(sizeof(struct ofp10_action_output) == 8);
201 /* OFPAT10_ENQUEUE action struct: send packets to given queue on port. */
202 struct ofp10_action_enqueue {
203 ovs_be16 type; /* OFPAT10_ENQUEUE. */
204 ovs_be16 len; /* Len is 16. */
205 ovs_be16 port; /* Port that queue belongs. Should
206 refer to a valid physical port
207 (i.e. < OFPP_MAX) or OFPP_IN_PORT. */
208 uint8_t pad[6]; /* Pad for 64-bit alignment. */
209 ovs_be32 queue_id; /* Where to enqueue the packets. */
211 OFP_ASSERT(sizeof(struct ofp10_action_enqueue) == 16);
213 /* Send packet (controller -> datapath). */
214 struct ofp10_packet_out {
215 ovs_be32 buffer_id; /* ID assigned by datapath or UINT32_MAX. */
216 ovs_be16 in_port; /* Packet's input port (OFPP_NONE if none). */
217 ovs_be16 actions_len; /* Size of action array in bytes. */
219 * - Exactly 'actions_len' bytes (possibly 0 bytes, and always a multiple
220 * of 8) containing actions.
221 * - If 'buffer_id' == UINT32_MAX, packet data to fill out the remainder
222 * of the message length.
225 OFP_ASSERT(sizeof(struct ofp10_packet_out) == 8);
227 /* Flow wildcards. */
228 enum ofp10_flow_wildcards {
229 OFPFW10_IN_PORT = 1 << 0, /* Switch input port. */
230 OFPFW10_DL_VLAN = 1 << 1, /* VLAN vid. */
231 OFPFW10_DL_SRC = 1 << 2, /* Ethernet source address. */
232 OFPFW10_DL_DST = 1 << 3, /* Ethernet destination address. */
233 OFPFW10_DL_TYPE = 1 << 4, /* Ethernet frame type. */
234 OFPFW10_NW_PROTO = 1 << 5, /* IP protocol. */
235 OFPFW10_TP_SRC = 1 << 6, /* TCP/UDP source port. */
236 OFPFW10_TP_DST = 1 << 7, /* TCP/UDP destination port. */
238 /* IP source address wildcard bit count. 0 is exact match, 1 ignores the
239 * LSB, 2 ignores the 2 least-significant bits, ..., 32 and higher wildcard
240 * the entire field. This is the *opposite* of the usual convention where
241 * e.g. /24 indicates that 8 bits (not 24 bits) are wildcarded. */
242 OFPFW10_NW_SRC_SHIFT = 8,
243 OFPFW10_NW_SRC_BITS = 6,
244 OFPFW10_NW_SRC_MASK = (((1 << OFPFW10_NW_SRC_BITS) - 1)
245 << OFPFW10_NW_SRC_SHIFT),
246 OFPFW10_NW_SRC_ALL = 32 << OFPFW10_NW_SRC_SHIFT,
248 /* IP destination address wildcard bit count. Same format as source. */
249 OFPFW10_NW_DST_SHIFT = 14,
250 OFPFW10_NW_DST_BITS = 6,
251 OFPFW10_NW_DST_MASK = (((1 << OFPFW10_NW_DST_BITS) - 1)
252 << OFPFW10_NW_DST_SHIFT),
253 OFPFW10_NW_DST_ALL = 32 << OFPFW10_NW_DST_SHIFT,
255 OFPFW10_DL_VLAN_PCP = 1 << 20, /* VLAN priority. */
256 OFPFW10_NW_TOS = 1 << 21, /* IP ToS (DSCP field, 6 bits). */
258 /* Wildcard all fields. */
259 OFPFW10_ALL = ((1 << 22) - 1)
262 /* The wildcards for ICMP type and code fields use the transport source
263 * and destination port fields, respectively. */
264 #define OFPFW10_ICMP_TYPE OFPFW10_TP_SRC
265 #define OFPFW10_ICMP_CODE OFPFW10_TP_DST
267 /* The VLAN id is 12-bits, so we can use the entire 16 bits to indicate
268 * special conditions. All ones indicates that 802.1Q header is not present.
270 #define OFP10_VLAN_NONE 0xffff
272 /* Fields to match against flows */
274 ovs_be32 wildcards; /* Wildcard fields. */
275 ovs_be16 in_port; /* Input switch port. */
276 uint8_t dl_src[OFP_ETH_ALEN]; /* Ethernet source address. */
277 uint8_t dl_dst[OFP_ETH_ALEN]; /* Ethernet destination address. */
278 ovs_be16 dl_vlan; /* Input VLAN. */
279 uint8_t dl_vlan_pcp; /* Input VLAN priority. */
280 uint8_t pad1[1]; /* Align to 64-bits. */
281 ovs_be16 dl_type; /* Ethernet frame type. */
282 uint8_t nw_tos; /* IP ToS (DSCP field, 6 bits). */
283 uint8_t nw_proto; /* IP protocol or lower 8 bits of
285 uint8_t pad2[2]; /* Align to 64-bits. */
286 ovs_be32 nw_src; /* IP source address. */
287 ovs_be32 nw_dst; /* IP destination address. */
288 ovs_be16 tp_src; /* TCP/UDP source port. */
289 ovs_be16 tp_dst; /* TCP/UDP destination port. */
291 OFP_ASSERT(sizeof(struct ofp10_match) == 40);
293 enum ofp10_flow_mod_flags {
294 OFPFF10_EMERG = 1 << 2 /* Part of "emergency flow cache". */
297 /* Flow setup and teardown (controller -> datapath). */
298 struct ofp10_flow_mod {
299 struct ofp10_match match; /* Fields to match */
300 ovs_be64 cookie; /* Opaque controller-issued identifier. */
303 ovs_be16 command; /* One of OFPFC_*. */
304 ovs_be16 idle_timeout; /* Idle time before discarding (seconds). */
305 ovs_be16 hard_timeout; /* Max time before discarding (seconds). */
306 ovs_be16 priority; /* Priority level of flow entry. */
307 ovs_be32 buffer_id; /* Buffered packet to apply to (or -1).
308 Not meaningful for OFPFC_DELETE*. */
309 ovs_be16 out_port; /* For OFPFC_DELETE* commands, require
310 matching entries to include this as an
311 output port. A value of OFPP_NONE
312 indicates no restriction. */
313 ovs_be16 flags; /* One of OFPFF_*. */
314 struct ofp_action_header actions[0]; /* The action length is inferred
315 from the length field in the
318 OFP_ASSERT(sizeof(struct ofp10_flow_mod) == 64);
320 /* Flow removed (datapath -> controller). */
321 struct ofp10_flow_removed {
322 struct ofp10_match match; /* Description of fields. */
323 ovs_be64 cookie; /* Opaque controller-issued identifier. */
325 ovs_be16 priority; /* Priority level of flow entry. */
326 uint8_t reason; /* One of OFPRR_*. */
327 uint8_t pad[1]; /* Align to 32-bits. */
329 ovs_be32 duration_sec; /* Time flow was alive in seconds. */
330 ovs_be32 duration_nsec; /* Time flow was alive in nanoseconds beyond
332 ovs_be16 idle_timeout; /* Idle timeout from original flow mod. */
333 uint8_t pad2[2]; /* Align to 64-bits. */
334 ovs_be64 packet_count;
337 OFP_ASSERT(sizeof(struct ofp10_flow_removed) == 80);
339 /* Statistics request or reply message. */
340 struct ofp10_stats_msg {
341 struct ofp_header header;
342 ovs_be16 type; /* One of the OFPST_* constants. */
343 ovs_be16 flags; /* Requests: always 0.
344 * Replies: 0 or OFPSF_REPLY_MORE. */
346 OFP_ASSERT(sizeof(struct ofp10_stats_msg) == 12);
348 /* Stats request of type OFPST_AGGREGATE or OFPST_FLOW. */
349 struct ofp10_flow_stats_request {
350 struct ofp10_match match; /* Fields to match. */
351 uint8_t table_id; /* ID of table to read (from ofp_table_stats)
352 or 0xff for all tables. */
353 uint8_t pad; /* Align to 32 bits. */
354 ovs_be16 out_port; /* Require matching entries to include this
355 as an output port. A value of OFPP_NONE
356 indicates no restriction. */
358 OFP_ASSERT(sizeof(struct ofp10_flow_stats_request) == 44);
360 /* Body of reply to OFPST_FLOW request. */
361 struct ofp10_flow_stats {
362 ovs_be16 length; /* Length of this entry. */
363 uint8_t table_id; /* ID of table flow came from. */
365 struct ofp10_match match; /* Description of fields. */
366 ovs_be32 duration_sec; /* Time flow has been alive in seconds. */
367 ovs_be32 duration_nsec; /* Time flow has been alive in nanoseconds
368 beyond duration_sec. */
369 ovs_be16 priority; /* Priority of the entry. Only meaningful
370 when this is not an exact-match entry. */
371 ovs_be16 idle_timeout; /* Number of seconds idle before expiration. */
372 ovs_be16 hard_timeout; /* Number of seconds before expiration. */
373 uint8_t pad2[6]; /* Align to 64 bits. */
374 ovs_32aligned_be64 cookie; /* Opaque controller-issued identifier. */
375 ovs_32aligned_be64 packet_count; /* Number of packets in flow. */
376 ovs_32aligned_be64 byte_count; /* Number of bytes in flow. */
377 struct ofp_action_header actions[0]; /* Actions. */
379 OFP_ASSERT(sizeof(struct ofp10_flow_stats) == 88);
381 /* Body of reply to OFPST_TABLE request. */
382 struct ofp10_table_stats {
383 uint8_t table_id; /* Identifier of table. Lower numbered tables
384 are consulted first. */
385 uint8_t pad[3]; /* Align to 32-bits. */
386 char name[OFP_MAX_TABLE_NAME_LEN];
387 ovs_be32 wildcards; /* Bitmap of OFPFW10_* wildcards that are
388 supported by the table. */
389 ovs_be32 max_entries; /* Max number of entries supported. */
390 ovs_be32 active_count; /* Number of active entries. */
391 ovs_32aligned_be64 lookup_count; /* # of packets looked up in table. */
392 ovs_32aligned_be64 matched_count; /* Number of packets that hit table. */
394 OFP_ASSERT(sizeof(struct ofp10_table_stats) == 64);
396 /* Stats request of type OFPST_PORT. */
397 struct ofp10_port_stats_request {
398 ovs_be16 port_no; /* OFPST_PORT message may request statistics
399 for a single port (specified with port_no)
400 or for all ports (port_no == OFPP_NONE). */
403 OFP_ASSERT(sizeof(struct ofp10_port_stats_request) == 8);
405 /* Body of reply to OFPST_PORT request. If a counter is unsupported, set
406 * the field to all ones. */
407 struct ofp10_port_stats {
409 uint8_t pad[6]; /* Align to 64-bits. */
410 ovs_32aligned_be64 rx_packets; /* Number of received packets. */
411 ovs_32aligned_be64 tx_packets; /* Number of transmitted packets. */
412 ovs_32aligned_be64 rx_bytes; /* Number of received bytes. */
413 ovs_32aligned_be64 tx_bytes; /* Number of transmitted bytes. */
414 ovs_32aligned_be64 rx_dropped; /* Number of packets dropped by RX. */
415 ovs_32aligned_be64 tx_dropped; /* Number of packets dropped by TX. */
416 ovs_32aligned_be64 rx_errors; /* Number of receive errors. This is a
417 super-set of receive errors and should be
418 great than or equal to the sum of all
420 ovs_32aligned_be64 tx_errors; /* Number of transmit errors. This is a
421 super-set of transmit errors. */
422 ovs_32aligned_be64 rx_frame_err; /* Number of frame alignment errors. */
423 ovs_32aligned_be64 rx_over_err; /* Number of packets with RX overrun. */
424 ovs_32aligned_be64 rx_crc_err; /* Number of CRC errors. */
425 ovs_32aligned_be64 collisions; /* Number of collisions. */
427 OFP_ASSERT(sizeof(struct ofp10_port_stats) == 104);
429 /* All ones is used to indicate all queues in a port (for stats retrieval). */
430 #define OFPQ_ALL 0xffffffff
432 /* Body for stats request of type OFPST_QUEUE. */
433 struct ofp10_queue_stats_request {
434 ovs_be16 port_no; /* All ports if OFPP_ALL. */
435 uint8_t pad[2]; /* Align to 32-bits. */
436 ovs_be32 queue_id; /* All queues if OFPQ_ALL. */
438 OFP_ASSERT(sizeof(struct ofp10_queue_stats_request) == 8);
440 /* Body for stats reply of type OFPST_QUEUE consists of an array of this
442 struct ofp10_queue_stats {
444 uint8_t pad[2]; /* Align to 32-bits. */
445 ovs_be32 queue_id; /* Queue id. */
446 ovs_32aligned_be64 tx_bytes; /* Number of transmitted bytes. */
447 ovs_32aligned_be64 tx_packets; /* Number of transmitted packets. */
448 ovs_32aligned_be64 tx_errors; /* # of packets dropped due to overrun. */
450 OFP_ASSERT(sizeof(struct ofp10_queue_stats) == 32);
452 /* Vendor extension stats message. */
453 struct ofp10_vendor_stats_msg {
454 struct ofp10_stats_msg osm; /* Type OFPST_VENDOR. */
455 ovs_be32 vendor; /* Vendor ID:
456 * - MSB 0: low-order bytes are IEEE OUI.
457 * - MSB != 0: defined by OpenFlow
459 /* Followed by vendor-defined arbitrary additional data. */
461 OFP_ASSERT(sizeof(struct ofp10_vendor_stats_msg) == 16);
463 #endif /* openflow/openflow-1.0.h */