]> git.proxmox.com Git - ovs.git/blob - include/openflow/openflow-common.h
OpenFlow: Move stats message enums into "common".
[ovs.git] / include / openflow / openflow-common.h
1 /* Copyright (c) 2008, 2011 The Board of Trustees of The Leland Stanford
2 * Junior University
3 *
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:
16 *
17 * The above copyright notice and this permission notice shall be
18 * included in all copies or substantial portions of the Software.
19 *
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
27 * SOFTWARE.
28 *
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.
32 */
33
34 /*
35 * Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
36 *
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:
40 *
41 * http://www.apache.org/licenses/LICENSE-2.0
42 *
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.
48 */
49
50 #ifndef OPENFLOW_COMMON_H
51 #define OPENFLOW_COMMON_H 1
52
53 #include "openvswitch/types.h"
54
55 #ifdef SWIG
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 */
66
67 /* Version number:
68 * Non-experimental versions released: 0x01 0x02
69 * Experimental versions released: 0x81 -- 0x99
70 */
71 /* The most significant bit being set in the version field indicates an
72 * experimental OpenFlow version.
73 */
74 #define OFP10_VERSION 0x01
75 #define OFP11_VERSION 0x02
76 #define OFP12_VERSION 0x03
77
78 #define OFP_MAX_TABLE_NAME_LEN 32
79 #define OFP_MAX_PORT_NAME_LEN 16
80
81 #define OFP_TCP_PORT 6633
82 #define OFP_SSL_PORT 6633
83
84 #define OFP_ETH_ALEN 6 /* Bytes in an Ethernet address. */
85
86 /* Common OpenFlow message types. */
87 enum ofp_type {
88 /* Immutable messages. */
89 OFPT_HELLO, /* Symmetric message */
90 OFPT_ERROR, /* Symmetric message */
91 OFPT_ECHO_REQUEST, /* Symmetric message */
92 OFPT_ECHO_REPLY, /* Symmetric message */
93 OFPT_VENDOR, /* Symmetric message */
94
95 /* Switch configuration messages. */
96 OFPT_FEATURES_REQUEST, /* Controller/switch message */
97 OFPT_FEATURES_REPLY, /* Controller/switch message */
98 OFPT_GET_CONFIG_REQUEST, /* Controller/switch message */
99 OFPT_GET_CONFIG_REPLY, /* Controller/switch message */
100 OFPT_SET_CONFIG, /* Controller/switch message */
101
102 /* Asynchronous messages. */
103 OFPT_PACKET_IN, /* Async message */
104 OFPT_FLOW_REMOVED, /* Async message */
105 OFPT_PORT_STATUS, /* Async message */
106 };
107
108 /* Header on all OpenFlow packets. */
109 struct ofp_header {
110 uint8_t version; /* An OpenFlow version number, e.g. OFP10_VERSION. */
111 uint8_t type; /* One of the OFPT_ constants. */
112 ovs_be16 length; /* Length including this ofp_header. */
113 ovs_be32 xid; /* Transaction id associated with this packet.
114 Replies use the same id as was in the request
115 to facilitate pairing. */
116 };
117 OFP_ASSERT(sizeof(struct ofp_header) == 8);
118
119 /* Common flags to indicate behavior of the physical port. These flags are
120 * used in ofp_port to describe the current configuration. They are used in
121 * the ofp_port_mod message to configure the port's behavior.
122 */
123 enum ofp_port_config {
124 OFPPC_PORT_DOWN = 1 << 0, /* Port is administratively down. */
125
126 OFPPC_NO_RECV = 1 << 2, /* Drop all packets received by port. */
127 OFPPC_NO_FWD = 1 << 5, /* Drop packets forwarded to port. */
128 OFPPC_NO_PACKET_IN = 1 << 6 /* Do not send packet-in msgs for port. */
129 };
130
131 /* Common current state of the physical port. These are not configurable from
132 * the controller.
133 */
134 enum ofp_port_state {
135 OFPPS_LINK_DOWN = 1 << 0, /* No physical link present. */
136 };
137
138 /* Common features of physical ports available in a datapath. */
139 enum ofp_port_features {
140 OFPPF_10MB_HD = 1 << 0, /* 10 Mb half-duplex rate support. */
141 OFPPF_10MB_FD = 1 << 1, /* 10 Mb full-duplex rate support. */
142 OFPPF_100MB_HD = 1 << 2, /* 100 Mb half-duplex rate support. */
143 OFPPF_100MB_FD = 1 << 3, /* 100 Mb full-duplex rate support. */
144 OFPPF_1GB_HD = 1 << 4, /* 1 Gb half-duplex rate support. */
145 OFPPF_1GB_FD = 1 << 5, /* 1 Gb full-duplex rate support. */
146 OFPPF_10GB_FD = 1 << 6, /* 10 Gb full-duplex rate support. */
147 };
148
149 struct ofp_packet_queue {
150 ovs_be32 queue_id; /* id for the specific queue. */
151 ovs_be16 len; /* Length in bytes of this queue desc. */
152 uint8_t pad[2]; /* 64-bit alignment. */
153 /* struct ofp_queue_prop_header properties[0]; List of properties. */
154 };
155 OFP_ASSERT(sizeof(struct ofp_packet_queue) == 8);
156
157 enum ofp_queue_properties {
158 OFPQT_NONE = 0, /* No property defined for queue (default). */
159 OFPQT_MIN_RATE, /* Minimum datarate guaranteed. */
160 /* Other types should be added here
161 * (i.e. max rate, precedence, etc). */
162 };
163
164 /* Common description for a queue. */
165 struct ofp_queue_prop_header {
166 ovs_be16 property; /* One of OFPQT_. */
167 ovs_be16 len; /* Length of property, including this header. */
168 uint8_t pad[4]; /* 64-bit alignemnt. */
169 };
170 OFP_ASSERT(sizeof(struct ofp_queue_prop_header) == 8);
171
172 /* Min-Rate queue property description. */
173 struct ofp_queue_prop_min_rate {
174 struct ofp_queue_prop_header prop_header; /* prop: OFPQT_MIN, len: 16. */
175 ovs_be16 rate; /* In 1/10 of a percent; >1000 -> disabled. */
176 uint8_t pad[6]; /* 64-bit alignment */
177 };
178 OFP_ASSERT(sizeof(struct ofp_queue_prop_min_rate) == 16);
179
180 /* Switch features. */
181 struct ofp_switch_features {
182 struct ofp_header header;
183 ovs_be64 datapath_id; /* Datapath unique ID. The lower 48-bits are for
184 a MAC address, while the upper 16-bits are
185 implementer-defined. */
186
187 ovs_be32 n_buffers; /* Max packets buffered at once. */
188
189 uint8_t n_tables; /* Number of tables supported by datapath. */
190 uint8_t pad[3]; /* Align to 64-bits. */
191
192 /* Features. */
193 ovs_be32 capabilities; /* OFPC_*, OFPC10_*, OFPC11_*, OFPC12_*. */
194 ovs_be32 actions; /* Bitmap of supported "ofp_action_type"s. */
195
196 /* Followed by an array of struct ofp10_phy_port or struct ofp11_port
197 * structures. The number is inferred from header.length. */
198 };
199 OFP_ASSERT(sizeof(struct ofp_switch_features) == 32);
200
201 /* Common capabilities supported by the datapath (struct ofp_switch_features,
202 * member capabilities). */
203 enum ofp_capabilities {
204 OFPC_FLOW_STATS = 1 << 0, /* Flow statistics. */
205 OFPC_TABLE_STATS = 1 << 1, /* Table statistics. */
206 OFPC_PORT_STATS = 1 << 2, /* Port statistics. */
207 OFPC_IP_REASM = 1 << 5, /* Can reassemble IP fragments. */
208 OFPC_QUEUE_STATS = 1 << 6, /* Queue statistics. */
209 OFPC_ARP_MATCH_IP = 1 << 7 /* Match IP addresses in ARP
210 pkts. */
211 };
212
213 /* Why is this packet being sent to the controller? */
214 enum ofp_packet_in_reason {
215 OFPR_NO_MATCH, /* No matching flow. */
216 OFPR_ACTION, /* Action explicitly output to controller. */
217 OFPR_INVALID_TTL /* Packet has invalid TTL. */,
218 OFPR_N_REASONS
219 };
220
221 /* Why was this flow removed? */
222 enum ofp_flow_removed_reason {
223 OFPRR_IDLE_TIMEOUT, /* Flow idle time exceeded idle_timeout. */
224 OFPRR_HARD_TIMEOUT, /* Time exceeded hard_timeout. */
225 OFPRR_DELETE, /* Evicted by a DELETE flow mod. */
226 OFPRR_GROUP_DELETE /* Group was removed. */
227 };
228
229 /* What changed about the physical port */
230 enum ofp_port_reason {
231 OFPPR_ADD, /* The port was added. */
232 OFPPR_DELETE, /* The port was removed. */
233 OFPPR_MODIFY /* Some attribute of the port has changed. */
234 };
235
236 /* A physical port has changed in the datapath */
237 struct ofp_port_status {
238 struct ofp_header header;
239 uint8_t reason; /* One of OFPPR_*. */
240 uint8_t pad[7]; /* Align to 64-bits. */
241 /* Followed by struct ofp10_phy_port or struct ofp11_port. */
242 };
243 OFP_ASSERT(sizeof(struct ofp_port_status) == 16);
244
245 enum ofp_stats_types {
246 /* Description of this OpenFlow switch. (OFPMP_DESC)
247 * The OF1.0 request is struct ofp_stats_msg.
248 * The OF1.0 reply is struct ofp_desc_stats. */
249 OFPST_DESC = 0,
250
251 /* Individual flow statistics. (OFPMP_FLOW)
252 * The OF1.0 request is struct ofp_flow_stats_request.
253 * The OF1.0 reply body is an array of struct ofp_flow_stats. */
254 OFPST_FLOW = 1,
255
256 /* Aggregate flow statistics. (OFPMP_AGGREGATE)
257 * The OF1.0 request is struct ofp_flow_stats_request.
258 * The OF1.0 reply is struct ofp_aggregate_stats_reply. */
259 OFPST_AGGREGATE = 2,
260
261 /* Flow table statistics. (OFPMP_TABLE)
262 * The OF1.0 request is struct ofp_stats_msg.
263 * The OF1.0 reply body is an array of struct ofp_table_stats. */
264 OFPST_TABLE = 3,
265
266 /* Physical port statistics. (OFPMP_PORT_STATS)
267 * The OF1.0 request is struct ofp_port_stats_request.
268 * The OF1.0 reply body is an array of struct ofp_port_stats. */
269 OFPST_PORT = 4,
270
271 /* Queue statistics for a port. (OFPMP_QUEUE)
272 * The OF1.0 request is struct ofp_stats_msg.
273 * The OF1.0 reply body is an array of struct ofp_queue_stats. */
274 OFPST_QUEUE = 5,
275
276 /* Vendor extension.
277 * The OF1.0 request and reply begin with struct ofp_vendor_stats. */
278 OFPST_VENDOR = 0xffff
279 };
280
281 /* The match type indicates the match structure (set of fields that compose the
282 * match) in use. The match type is placed in the type field at the beginning
283 * of all match structures. The "OpenFlow Extensible Match" type corresponds
284 * to OXM TLV format described below and must be supported by all OpenFlow
285 * switches. Extensions that define other match types may be published on the
286 * ONF wiki. Support for extensions is optional.
287 */
288 enum ofp_match_type {
289 OFPMT_STANDARD = 0, /* The match fields defined in the ofp11_match
290 structure apply */
291 OFPMT_OXM = 1, /* OpenFlow Extensible Match */
292 };
293
294 #endif /* openflow/openflow-common.h */