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