1 /* Copyright (c) 2008, 2011, 2012, 2013 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.
35 * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
37 * Licensed under the Apache License, Version 2.0 (the "License");
38 * you may not use this file except in compliance with the License.
39 * You may obtain a copy of the License at:
41 * http://www.apache.org/licenses/LICENSE-2.0
43 * Unless required by applicable law or agreed to in writing, software
44 * distributed under the License is distributed on an "AS IS" BASIS,
45 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
46 * See the License for the specific language governing permissions and
47 * limitations under the License.
50 #ifndef OPENFLOW_COMMON_H
51 #define OPENFLOW_COMMON_H 1
53 #include "openvswitch/types.h"
56 #define OFP_ASSERT(EXPR) /* SWIG can't handle OFP_ASSERT. */
57 #elif !defined(__cplusplus)
58 /* Build-time assertion for use in a declaration context. */
59 #define OFP_ASSERT(EXPR) \
60 extern int (*build_assert(void))[ sizeof(struct { \
61 unsigned int build_assert_failed : (EXPR) ? 1 : -1; })]
62 #else /* __cplusplus */
63 #include <boost/static_assert.hpp>
64 #define OFP_ASSERT BOOST_STATIC_ASSERT
65 #endif /* __cplusplus */
68 * Non-experimental versions released: 0x01 0x02
69 * Experimental versions released: 0x81 -- 0x99
71 /* The most significant bit being set in the version field indicates an
72 * experimental OpenFlow version.
81 /* Vendor (aka experimenter) IDs.
83 * These are used in various places in OpenFlow to identify an extension
84 * defined by some vendor, as opposed to a standardized part of the core
87 * Vendor IDs whose top 8 bits are 0 hold an Ethernet OUI in their low 24 bits.
88 * The Open Networking Foundation assigns vendor IDs whose top 8 bits are
91 * A few vendor IDs are special:
93 * - OF_VENDOR_ID is not a real vendor ID and does not appear in the
94 * OpenFlow protocol itself. It can occasionally be useful within Open
95 * vSwitch to identify a standardized part of OpenFlow.
97 * - ONF_VENDOR_ID is being used within the ONF "extensibility" working
98 * group to identify extensions being proposed for standardization.
100 #define OF_VENDOR_ID 0
101 #define NX_VENDOR_ID 0x00002320 /* Nicira. */
102 #define ONF_VENDOR_ID 0x4f4e4600 /* Open Networking Foundation. */
104 #define OFP_MAX_TABLE_NAME_LEN 32
105 #define OFP_MAX_PORT_NAME_LEN 16
107 #define OFP_OLD_PORT 6633
108 #define OFP_PORT 6653
110 #define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
112 #define OFP_DEFAULT_MISS_SEND_LEN 128
114 /* Values below this cutoff are 802.3 packets and the two bytes
115 * following MAC addresses are used as a frame length. Otherwise, the
116 * two bytes are used as the Ethernet type.
118 #define OFP_DL_TYPE_ETH2_CUTOFF 0x0600
120 /* Value of dl_type to indicate that the frame does not include an
123 #define OFP_DL_TYPE_NOT_ETH_TYPE 0x05ff
125 /* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
127 #define OFP_FLOW_PERMANENT 0
129 /* By default, choose a priority in the middle. */
130 #define OFP_DEFAULT_PRIORITY 0x8000
133 /* Header on all OpenFlow packets. */
135 uint8_t version; /* An OpenFlow version number, e.g. OFP10_VERSION. */
136 uint8_t type; /* One of the OFPT_ constants. */
137 ovs_be16 length; /* Length including this ofp_header. */
138 ovs_be32 xid; /* Transaction id associated with this packet.
139 Replies use the same id as was in the request
140 to facilitate pairing. */
142 OFP_ASSERT(sizeof(struct ofp_header) == 8);
144 /* OFPT_ERROR: Error message (datapath -> controller). */
145 struct ofp_error_msg {
148 uint8_t data[0]; /* Variable-length data. Interpreted based
149 on the type and code. */
151 OFP_ASSERT(sizeof(struct ofp_error_msg) == 4);
153 enum ofp_config_flags {
154 /* Handling of IP fragments. */
155 OFPC_FRAG_NORMAL = 0, /* No special handling for fragments. */
156 OFPC_FRAG_DROP = 1, /* Drop fragments. */
157 OFPC_FRAG_REASM = 2, /* Reassemble (only if OFPC_IP_REASM set). */
158 OFPC_FRAG_NX_MATCH = 3, /* Make first fragments available for matching. */
161 /* OFPC_INVALID_TTL_TO_CONTROLLER is deprecated in OpenFlow 1.3 */
163 /* TTL processing - applicable for IP and MPLS packets. */
164 OFPC_INVALID_TTL_TO_CONTROLLER = 1 << 2, /* Send packets with invalid TTL
165 to the controller. */
168 /* Switch configuration. */
169 struct ofp_switch_config {
170 ovs_be16 flags; /* OFPC_* flags. */
171 ovs_be16 miss_send_len; /* Max bytes of new flow that datapath should
172 send to the controller. */
174 OFP_ASSERT(sizeof(struct ofp_switch_config) == 4);
177 /* Common flags to indicate behavior of the physical port. These flags are
178 * used in ofp_port to describe the current configuration. They are used in
179 * the ofp_port_mod message to configure the port's behavior.
181 enum ofp_port_config {
182 OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
184 OFPPC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
185 OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
186 OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
189 /* Common current state of the physical port. These are not configurable from
192 enum ofp_port_state {
193 OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
196 /* Common features of physical ports available in a datapath. */
197 enum ofp_port_features {
198 OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
199 OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
200 OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
201 OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
202 OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
203 OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
204 OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
207 enum ofp_queue_properties {
208 OFPQT_MIN_RATE = 1, /* Minimum datarate guaranteed. */
209 OFPQT_MAX_RATE = 2, /* Maximum guaranteed rate. */
210 OFPQT_EXPERIMENTER = 0xffff, /* Experimenter defined property. */
213 /* Common description for a queue. */
214 struct ofp_queue_prop_header {
215 ovs_be16 property; /* One of OFPQT_. */
216 ovs_be16 len; /* Length of property, including this header. */
217 uint8_t pad[4]; /* 64-bit alignemnt. */
219 OFP_ASSERT(sizeof(struct ofp_queue_prop_header) == 8);
221 /* Min-Rate and Max-Rate queue property description (OFPQT_MIN and
223 struct ofp_queue_prop_rate {
224 struct ofp_queue_prop_header prop_header;
225 ovs_be16 rate; /* In 1/10 of a percent; >1000 -> disabled. */
226 uint8_t pad[6]; /* 64-bit alignment */
228 OFP_ASSERT(sizeof(struct ofp_queue_prop_rate) == 16);
230 /* Switch features. */
231 struct ofp_switch_features {
232 ovs_be64 datapath_id; /* Datapath unique ID. The lower 48-bits are for
233 a MAC address, while the upper 16-bits are
234 implementer-defined. */
236 ovs_be32 n_buffers; /* Max packets buffered at once. */
238 uint8_t n_tables; /* Number of tables supported by datapath. */
239 uint8_t auxiliary_id; /* OF 1.3: Identify auxiliary connections */
240 uint8_t pad[2]; /* Align to 64-bits. */
243 ovs_be32 capabilities; /* OFPC_*, OFPC10_*, OFPC11_*, OFPC12_*. */
244 ovs_be32 actions; /* Bitmap of supported "ofp_action_type"s.
245 * DEPRECATED in OpenFlow 1.1 */
247 /* Followed by an array of struct ofp10_phy_port or struct ofp11_port
248 * structures. The number is inferred from header.length.
249 * REMOVED in OpenFlow 1.3 */
251 OFP_ASSERT(sizeof(struct ofp_switch_features) == 24);
253 /* Common capabilities supported by the datapath (struct ofp_switch_features,
254 * member capabilities). */
255 enum ofp_capabilities {
256 OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
257 OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
258 OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
259 OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
260 OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */
261 OFPC_ARP_MATCH_IP = 1 << 7 /* Match IP addresses in ARP
265 /* Why is this packet being sent to the controller? */
266 enum ofp_packet_in_reason {
267 OFPR_NO_MATCH, /* No matching flow. */
268 OFPR_ACTION, /* Action explicitly output to controller. */
269 OFPR_INVALID_TTL /* Packet has invalid TTL. */,
273 enum ofp_flow_mod_command {
274 OFPFC_ADD, /* New flow. */
275 OFPFC_MODIFY, /* Modify all matching flows. */
276 OFPFC_MODIFY_STRICT, /* Modify entry strictly matching wildcards */
277 OFPFC_DELETE, /* Delete all matching flows. */
278 OFPFC_DELETE_STRICT /* Strictly match wildcards and priority. */
281 enum ofp_flow_mod_flags {
282 OFPFF_SEND_FLOW_REM = 1 << 0, /* Send flow removed message when flow
283 * expires or is deleted. */
284 OFPFF_CHECK_OVERLAP = 1 << 1, /* Check for overlapping entries first. */
287 /* Action header for OFPAT10_VENDOR and OFPAT11_EXPERIMEMNTER.
288 * The rest of the body is vendor-defined. */
289 struct ofp_action_vendor_header {
290 ovs_be16 type; /* OFPAT10_VENDOR. */
291 ovs_be16 len; /* Length is a multiple of 8. */
292 ovs_be32 vendor; /* Vendor ID, which takes the same form
293 as in "struct ofp_vendor_header". */
295 OFP_ASSERT(sizeof(struct ofp_action_vendor_header) == 8);
297 /* Action header that is common to all actions. The length includes the
298 * header and any padding used to make the action 64-bit aligned.
299 * NB: The length of an action *must* always be a multiple of eight. */
300 struct ofp_action_header {
301 ovs_be16 type; /* One of OFPAT*. */
302 ovs_be16 len; /* Length of action, including this
303 header. This is the length of action,
304 including any padding to make it
308 OFP_ASSERT(sizeof(struct ofp_action_header) == 8);
310 /* Action structure for OFPAT10_SET_VLAN_VID and OFPAT11_SET_VLAN_VID. */
311 struct ofp_action_vlan_vid {
312 ovs_be16 type; /* Type. */
313 ovs_be16 len; /* Length is 8. */
314 ovs_be16 vlan_vid; /* VLAN id. */
317 OFP_ASSERT(sizeof(struct ofp_action_vlan_vid) == 8);
319 /* Action structure for OFPAT10_SET_VLAN_PCP and OFPAT11_SET_VLAN_PCP. */
320 struct ofp_action_vlan_pcp {
321 ovs_be16 type; /* Type. */
322 ovs_be16 len; /* Length is 8. */
323 uint8_t vlan_pcp; /* VLAN priority. */
326 OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp) == 8);
328 /* Action structure for OFPAT10_SET_DL_SRC/DST and OFPAT11_SET_DL_SRC/DST. */
329 struct ofp_action_dl_addr {
330 ovs_be16 type; /* Type. */
331 ovs_be16 len; /* Length is 16. */
332 uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */
335 OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
337 /* Action structure for OFPAT10_SET_NW_SRC/DST and OFPAT11_SET_NW_SRC/DST. */
338 struct ofp_action_nw_addr {
339 ovs_be16 type; /* Type. */
340 ovs_be16 len; /* Length is 8. */
341 ovs_be32 nw_addr; /* IP address. */
343 OFP_ASSERT(sizeof(struct ofp_action_nw_addr) == 8);
345 /* Action structure for OFPAT10_SET_NW_TOS and OFPAT11_SET_NW_TOS. */
346 struct ofp_action_nw_tos {
347 ovs_be16 type; /* Type.. */
348 ovs_be16 len; /* Length is 8. */
349 uint8_t nw_tos; /* DSCP in high 6 bits, rest ignored. */
352 OFP_ASSERT(sizeof(struct ofp_action_nw_tos) == 8);
354 /* Action structure for OFPAT10_SET_TP_SRC/DST and OFPAT11_SET_TP_SRC/DST. */
355 struct ofp_action_tp_port {
356 ovs_be16 type; /* Type. */
357 ovs_be16 len; /* Length is 8. */
358 ovs_be16 tp_port; /* TCP/UDP port. */
361 OFP_ASSERT(sizeof(struct ofp_action_tp_port) == 8);
363 /* Why was this flow removed? */
364 enum ofp_flow_removed_reason {
365 OFPRR_IDLE_TIMEOUT, /* Flow idle time exceeded idle_timeout. */
366 OFPRR_HARD_TIMEOUT, /* Time exceeded hard_timeout. */
367 OFPRR_DELETE, /* Evicted by a DELETE flow mod. */
368 OFPRR_GROUP_DELETE, /* Group was removed. */
369 OFPRR_METER_DELETE, /* Meter was removed. */
370 OFPRR_EVICTION, /* Switch eviction to free resources. */
373 /* What changed about the physical port */
374 enum ofp_port_reason {
375 OFPPR_ADD, /* The port was added. */
376 OFPPR_DELETE, /* The port was removed. */
377 OFPPR_MODIFY /* Some attribute of the port has changed. */
380 /* A physical port has changed in the datapath */
381 struct ofp_port_status {
382 uint8_t reason; /* One of OFPPR_*. */
383 uint8_t pad[7]; /* Align to 64-bits. */
384 /* Followed by struct ofp10_phy_port or struct ofp11_port. */
386 OFP_ASSERT(sizeof(struct ofp_port_status) == 8);
388 enum ofp_stats_reply_flags {
389 OFPSF_REPLY_MORE = 1 << 0 /* More replies to follow. */
392 #define DESC_STR_LEN 256
393 #define SERIAL_NUM_LEN 32
394 /* Body of reply to OFPST_DESC request. Each entry is a NULL-terminated ASCII
396 struct ofp_desc_stats {
397 char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */
398 char hw_desc[DESC_STR_LEN]; /* Hardware description. */
399 char sw_desc[DESC_STR_LEN]; /* Software description. */
400 char serial_num[SERIAL_NUM_LEN]; /* Serial number. */
401 char dp_desc[DESC_STR_LEN]; /* Human readable description of
404 OFP_ASSERT(sizeof(struct ofp_desc_stats) == 1056);
406 /* Reply to OFPST_AGGREGATE request. */
407 struct ofp_aggregate_stats_reply {
408 ovs_32aligned_be64 packet_count; /* Number of packets in flows. */
409 ovs_32aligned_be64 byte_count; /* Number of bytes in flows. */
410 ovs_be32 flow_count; /* Number of flows. */
411 uint8_t pad[4]; /* Align to 64 bits. */
413 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
415 /* The match type indicates the match structure (set of fields that compose the
416 * match) in use. The match type is placed in the type field at the beginning
417 * of all match structures. The "OpenFlow Extensible Match" type corresponds
418 * to OXM TLV format described below and must be supported by all OpenFlow
419 * switches. Extensions that define other match types may be published on the
420 * ONF wiki. Support for extensions is optional.
422 enum ofp_match_type {
423 OFPMT_STANDARD = 0, /* The match fields defined in the ofp11_match
425 OFPMT_OXM = 1, /* OpenFlow Extensible Match */
428 /* Group numbering. Groups can use any number up to OFPG_MAX. */
430 /* Last usable group number. */
431 OFPG_MAX = 0xffffff00,
434 OFPG_ALL = 0xfffffffc, /* All groups, for group delete commands. */
435 OFPG_ANY = 0xffffffff /* Wildcard, for flow stats requests. */
438 /* Group configuration flags */
439 enum ofp_group_capabilities {
440 OFPGFC_SELECT_WEIGHT = 1 << 0, /* Support weight for select groups */
441 OFPGFC_SELECT_LIVENESS = 1 << 1, /* Support liveness for select groups */
442 OFPGFC_CHAINING = 1 << 2, /* Support chaining groups */
443 OFPGFC_CHAINING_CHECKS = 1 << 3, /* Check chaining for loops and delete */
446 enum ofp_hello_elem_type {
447 OFPHET_VERSIONBITMAP = 1, /* Bitmap of version supported. */
450 /* Common header for all Hello Elements */
451 struct ofp_hello_elem_header {
452 ovs_be16 type; /* One of OFPHET_*. */
453 ovs_be16 length; /* Length in bytes of this element. */
455 OFP_ASSERT(sizeof(struct ofp_hello_elem_header) == 4);
457 /* Vendor extension. */
458 struct ofp_vendor_header {
459 struct ofp_header header; /* Type OFPT_VENDOR or OFPT_EXPERIMENTER. */
460 ovs_be32 vendor; /* Vendor ID:
461 * - MSB 0: low-order bytes are IEEE OUI.
462 * - MSB != 0: defined by OpenFlow
464 /* Vendor-defined arbitrary additional data. */
466 OFP_ASSERT(sizeof(struct ofp_vendor_header) == 12);
468 /* Table numbering. Tables can use any number up to OFPT_MAX. */
470 /* Last usable table number. */
474 OFPTT_ALL = 0xff /* Wildcard table used for table config,
475 flow stats and flow deletes. */
478 enum ofp_table_config {
479 /* OpenFlow 1.1 and 1.2 defined this field as shown.
480 * OpenFlow 1.3 and later mark this field as deprecated, but have not
481 * reused it for any new purpose. */
482 OFPTC11_TABLE_MISS_CONTROLLER = 0 << 0, /* Send to controller. */
483 OFPTC11_TABLE_MISS_CONTINUE = 1 << 0, /* Go to next table, like OF1.0. */
484 OFPTC11_TABLE_MISS_DROP = 2 << 0, /* Drop the packet. */
485 OFPTC11_TABLE_MISS_MASK = 3 << 0,
488 OFPTC14_EVICTION = 1 << 2, /* Allow table to evict flows. */
489 OFPTC14_VACANCY_EVENTS = 1 << 3, /* Enable vacancy events. */
492 #endif /* openflow/openflow-common.h */