1 /* Copyright (c) 2008, 2011, 2012 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.
80 #define OFP_MAX_TABLE_NAME_LEN 32
81 #define OFP_MAX_PORT_NAME_LEN 16
83 #define OFP_TCP_PORT 6633
84 #define OFP_SSL_PORT 6633
86 #define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
88 /* Header on all OpenFlow packets. */
90 uint8_t version; /* An OpenFlow version number, e.g. OFP10_VERSION. */
91 uint8_t type; /* One of the OFPT_ constants. */
92 ovs_be16 length; /* Length including this ofp_header. */
93 ovs_be32 xid; /* Transaction id associated with this packet.
94 Replies use the same id as was in the request
95 to facilitate pairing. */
97 OFP_ASSERT(sizeof(struct ofp_header) == 8);
99 /* Common flags to indicate behavior of the physical port. These flags are
100 * used in ofp_port to describe the current configuration. They are used in
101 * the ofp_port_mod message to configure the port's behavior.
103 enum ofp_port_config {
104 OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
106 OFPPC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
107 OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
108 OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
111 /* Common current state of the physical port. These are not configurable from
114 enum ofp_port_state {
115 OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
118 /* Common features of physical ports available in a datapath. */
119 enum ofp_port_features {
120 OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
121 OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
122 OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
123 OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
124 OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
125 OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
126 OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
129 struct ofp_packet_queue {
130 ovs_be32 queue_id; /* id for the specific queue. */
131 ovs_be16 len; /* Length in bytes of this queue desc. */
132 uint8_t pad[2]; /* 64-bit alignment. */
133 /* struct ofp_queue_prop_header properties[0]; List of properties. */
135 OFP_ASSERT(sizeof(struct ofp_packet_queue) == 8);
137 enum ofp_queue_properties {
138 OFPQT_NONE = 0, /* No property defined for queue (default). */
139 OFPQT_MIN_RATE, /* Minimum datarate guaranteed. */
140 /* Other types should be added here
141 * (i.e. max rate, precedence, etc). */
144 /* Common description for a queue. */
145 struct ofp_queue_prop_header {
146 ovs_be16 property; /* One of OFPQT_. */
147 ovs_be16 len; /* Length of property, including this header. */
148 uint8_t pad[4]; /* 64-bit alignemnt. */
150 OFP_ASSERT(sizeof(struct ofp_queue_prop_header) == 8);
152 /* Min-Rate queue property description. */
153 struct ofp_queue_prop_min_rate {
154 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MIN, len: 16. */
155 ovs_be16 rate; /* In 1/10 of a percent; >1000 -> disabled. */
156 uint8_t pad[6]; /* 64-bit alignment */
158 OFP_ASSERT(sizeof(struct ofp_queue_prop_min_rate) == 16);
160 /* Switch features. */
161 struct ofp_switch_features {
162 ovs_be64 datapath_id; /* Datapath unique ID. The lower 48-bits are for
163 a MAC address, while the upper 16-bits are
164 implementer-defined. */
166 ovs_be32 n_buffers; /* Max packets buffered at once. */
168 uint8_t n_tables; /* Number of tables supported by datapath. */
169 uint8_t pad[3]; /* Align to 64-bits. */
172 ovs_be32 capabilities; /* OFPC_*, OFPC10_*, OFPC11_*, OFPC12_*. */
173 ovs_be32 actions; /* Bitmap of supported "ofp_action_type"s. */
175 /* Followed by an array of struct ofp10_phy_port or struct ofp11_port
176 * structures. The number is inferred from header.length. */
178 OFP_ASSERT(sizeof(struct ofp_switch_features) == 24);
180 /* Common capabilities supported by the datapath (struct ofp_switch_features,
181 * member capabilities). */
182 enum ofp_capabilities {
183 OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
184 OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
185 OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
186 OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
187 OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */
188 OFPC_ARP_MATCH_IP = 1 << 7 /* Match IP addresses in ARP
192 /* Why is this packet being sent to the controller? */
193 enum ofp_packet_in_reason {
194 OFPR_NO_MATCH, /* No matching flow. */
195 OFPR_ACTION, /* Action explicitly output to controller. */
196 OFPR_INVALID_TTL /* Packet has invalid TTL. */,
200 enum ofp_flow_mod_command {
201 OFPFC_ADD, /* New flow. */
202 OFPFC_MODIFY, /* Modify all matching flows. */
203 OFPFC_MODIFY_STRICT, /* Modify entry strictly matching wildcards */
204 OFPFC_DELETE, /* Delete all matching flows. */
205 OFPFC_DELETE_STRICT /* Strictly match wildcards and priority. */
208 enum ofp_flow_mod_flags {
209 OFPFF_SEND_FLOW_REM = 1 << 0, /* Send flow removed message when flow
210 * expires or is deleted. */
211 OFPFF_CHECK_OVERLAP = 1 << 1, /* Check for overlapping entries first. */
214 /* Action structure for OFPAT10_SET_VLAN_VID and OFPAT11_SET_VLAN_VID. */
215 struct ofp_action_vlan_vid {
216 ovs_be16 type; /* Type. */
217 ovs_be16 len; /* Length is 8. */
218 ovs_be16 vlan_vid; /* VLAN id. */
221 OFP_ASSERT(sizeof(struct ofp_action_vlan_vid) == 8);
223 /* Action structure for OFPAT10_SET_VLAN_PCP and OFPAT11_SET_VLAN_PCP. */
224 struct ofp_action_vlan_pcp {
225 ovs_be16 type; /* Type. */
226 ovs_be16 len; /* Length is 8. */
227 uint8_t vlan_pcp; /* VLAN priority. */
230 OFP_ASSERT(sizeof(struct ofp_action_vlan_pcp) == 8);
232 /* Action structure for OFPAT10_SET_DL_SRC/DST and OFPAT11_SET_DL_SRC/DST. */
233 struct ofp_action_dl_addr {
234 ovs_be16 type; /* Type. */
235 ovs_be16 len; /* Length is 16. */
236 uint8_t dl_addr[OFP_ETH_ALEN]; /* Ethernet address. */
239 OFP_ASSERT(sizeof(struct ofp_action_dl_addr) == 16);
241 /* Action structure for OFPAT10_SET_NW_SRC/DST and OFPAT11_SET_NW_SRC/DST. */
242 struct ofp_action_nw_addr {
243 ovs_be16 type; /* Type. */
244 ovs_be16 len; /* Length is 8. */
245 ovs_be32 nw_addr; /* IP address. */
247 OFP_ASSERT(sizeof(struct ofp_action_nw_addr) == 8);
249 /* Action structure for OFPAT10_SET_NW_TOS and OFPAT11_SET_NW_TOS. */
250 struct ofp_action_nw_tos {
251 ovs_be16 type; /* Type.. */
252 ovs_be16 len; /* Length is 8. */
253 uint8_t nw_tos; /* DSCP in high 6 bits, rest ignored. */
256 OFP_ASSERT(sizeof(struct ofp_action_nw_tos) == 8);
258 /* Action structure for OFPAT10_SET_TP_SRC/DST and OFPAT11_SET_TP_SRC/DST. */
259 struct ofp_action_tp_port {
260 ovs_be16 type; /* Type. */
261 ovs_be16 len; /* Length is 8. */
262 ovs_be16 tp_port; /* TCP/UDP port. */
265 OFP_ASSERT(sizeof(struct ofp_action_tp_port) == 8);
267 /* Why was this flow removed? */
268 enum ofp_flow_removed_reason {
269 OFPRR_IDLE_TIMEOUT, /* Flow idle time exceeded idle_timeout. */
270 OFPRR_HARD_TIMEOUT, /* Time exceeded hard_timeout. */
271 OFPRR_DELETE, /* Evicted by a DELETE flow mod. */
272 OFPRR_GROUP_DELETE, /* Group was removed. */
273 OFPRR_EVICTION, /* Switch eviction to free resources. */
276 /* What changed about the physical port */
277 enum ofp_port_reason {
278 OFPPR_ADD, /* The port was added. */
279 OFPPR_DELETE, /* The port was removed. */
280 OFPPR_MODIFY /* Some attribute of the port has changed. */
283 /* A physical port has changed in the datapath */
284 struct ofp_port_status {
285 uint8_t reason; /* One of OFPPR_*. */
286 uint8_t pad[7]; /* Align to 64-bits. */
287 /* Followed by struct ofp10_phy_port or struct ofp11_port. */
289 OFP_ASSERT(sizeof(struct ofp_port_status) == 8);
291 #define DESC_STR_LEN 256
292 #define SERIAL_NUM_LEN 32
293 /* Body of reply to OFPST_DESC request. Each entry is a NULL-terminated ASCII
295 struct ofp_desc_stats {
296 char mfr_desc[DESC_STR_LEN]; /* Manufacturer description. */
297 char hw_desc[DESC_STR_LEN]; /* Hardware description. */
298 char sw_desc[DESC_STR_LEN]; /* Software description. */
299 char serial_num[SERIAL_NUM_LEN]; /* Serial number. */
300 char dp_desc[DESC_STR_LEN]; /* Human readable description of
303 OFP_ASSERT(sizeof(struct ofp_desc_stats) == 1056);
305 /* Reply to OFPST_AGGREGATE request. */
306 struct ofp_aggregate_stats_reply {
307 ovs_32aligned_be64 packet_count; /* Number of packets in flows. */
308 ovs_32aligned_be64 byte_count; /* Number of bytes in flows. */
309 ovs_be32 flow_count; /* Number of flows. */
310 uint8_t pad[4]; /* Align to 64 bits. */
312 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
314 /* The match type indicates the match structure (set of fields that compose the
315 * match) in use. The match type is placed in the type field at the beginning
316 * of all match structures. The "OpenFlow Extensible Match" type corresponds
317 * to OXM TLV format described below and must be supported by all OpenFlow
318 * switches. Extensions that define other match types may be published on the
319 * ONF wiki. Support for extensions is optional.
321 enum ofp_match_type {
322 OFPMT_STANDARD = 0, /* The match fields defined in the ofp11_match
324 OFPMT_OXM = 1, /* OpenFlow Extensible Match */
327 /* Group numbering. Groups can use any number up to OFPG_MAX. */
329 /* Last usable group number. */
330 OFPG_MAX = 0xffffff00,
333 OFPG_ALL = 0xfffffffc, /* All groups, for group delete commands. */
334 OFPG_ANY = 0xffffffff /* Wildcard, for flow stats requests. */
337 #endif /* openflow/openflow-common.h */