c0d22820acdb802e93b96d0a6f93c2415152656b
[cascardo/ovs.git] / include / openflow / openflow-common.h
1 /* Copyright (c) 2008, 2011, 2012, 2013, 2014 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-2014 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 enum ofp_version {
75     OFP10_VERSION = 0x01,
76     OFP11_VERSION = 0x02,
77     OFP12_VERSION = 0x03,
78     OFP13_VERSION = 0x04,
79     OFP14_VERSION = 0x05,
80     OFP15_VERSION = 0x06
81 };
82
83 /* Vendor (aka experimenter) IDs.
84  *
85  * These are used in various places in OpenFlow to identify an extension
86  * defined by some vendor, as opposed to a standardized part of the core
87  * OpenFlow protocol.
88  *
89  * Vendor IDs whose top 8 bits are 0 hold an Ethernet OUI in their low 24 bits.
90  * The Open Networking Foundation assigns vendor IDs whose top 8 bits are
91  * nonzero.
92  *
93  * A few vendor IDs are special:
94  *
95  *    - OF_VENDOR_ID is not a real vendor ID and does not appear in the
96  *      OpenFlow protocol itself.  It can occasionally be useful within Open
97  *      vSwitch to identify a standardized part of OpenFlow.
98  *
99  *    - ONF_VENDOR_ID is being used within the ONF "extensibility" working
100  *      group to identify extensions being proposed for standardization.
101  *
102  * The list is sorted numerically.
103  */
104 #define OF_VENDOR_ID    0
105 #define HPL_VENDOR_ID   0x000004EA /* HP Labs. */
106 #define NTR_VENDOR_ID   0x00001540 /* Netronome. */
107 #define NX_VENDOR_ID    0x00002320 /* Nicira. */
108 #define ONF_VENDOR_ID   0x4f4e4600 /* Open Networking Foundation. */
109
110 #define OFP_MAX_TABLE_NAME_LEN 32
111 #define OFP_MAX_PORT_NAME_LEN  16
112
113 #define OFP_OLD_PORT  6633
114 #define OFP_PORT  6653
115
116 #define OFP_DEFAULT_MISS_SEND_LEN   128
117
118 /* Values below this cutoff are 802.3 packets and the two bytes
119  * following MAC addresses are used as a frame length.  Otherwise, the
120  * two bytes are used as the Ethernet type.
121  */
122 #define OFP_DL_TYPE_ETH2_CUTOFF   0x0600
123
124 /* Value of dl_type to indicate that the frame does not include an
125  * Ethernet type.
126  */
127 #define OFP_DL_TYPE_NOT_ETH_TYPE  0x05ff
128
129 /* Value used in "idle_timeout" and "hard_timeout" to indicate that the entry
130  * is permanent. */
131 #define OFP_FLOW_PERMANENT 0
132
133 /* By default, choose a priority in the middle. */
134 #define OFP_DEFAULT_PRIORITY 0x8000
135
136
137 /* Header on all OpenFlow packets. */
138 struct ofp_header {
139     uint8_t version;    /* An OpenFlow version number, e.g. OFP10_VERSION. */
140     uint8_t type;       /* One of the OFPT_ constants. */
141     ovs_be16 length;    /* Length including this ofp_header. */
142     ovs_be32 xid;       /* Transaction id associated with this packet.
143                            Replies use the same id as was in the request
144                            to facilitate pairing. */
145 };
146 OFP_ASSERT(sizeof(struct ofp_header) == 8);
147
148 /* OFPT_ERROR: Error message (datapath -> controller). */
149 struct ofp_error_msg {
150     ovs_be16 type;
151     ovs_be16 code;
152     uint8_t data[0];          /* Variable-length data.  Interpreted based
153                                  on the type and code. */
154 };
155 OFP_ASSERT(sizeof(struct ofp_error_msg) == 4);
156
157 enum ofp_config_flags {
158     /* Handling of IP fragments. */
159     OFPC_FRAG_NORMAL   = 0,  /* No special handling for fragments. */
160     OFPC_FRAG_DROP     = 1,  /* Drop fragments. */
161     OFPC_FRAG_REASM    = 2,  /* Reassemble (only if OFPC_IP_REASM set). */
162     OFPC_FRAG_NX_MATCH = 3,  /* Make first fragments available for matching. */
163     OFPC_FRAG_MASK     = 3,
164
165     /* OFPC_INVALID_TTL_TO_CONTROLLER is deprecated in OpenFlow 1.3 */
166
167     /* TTL processing - applicable for IP and MPLS packets. */
168     OFPC_INVALID_TTL_TO_CONTROLLER = 1 << 2, /* Send packets with invalid TTL
169                                                 to the controller. */
170 };
171
172 /* Switch configuration. */
173 struct ofp_switch_config {
174     ovs_be16 flags;             /* OFPC_* flags. */
175     ovs_be16 miss_send_len;     /* Max bytes of new flow that datapath should
176                                    send to the controller. */
177 };
178 OFP_ASSERT(sizeof(struct ofp_switch_config) == 4);
179
180
181 /* Common flags to indicate behavior of the physical port.  These flags are
182  * used in ofp_port to describe the current configuration.  They are used in
183  * the ofp_port_mod message to configure the port's behavior.
184  */
185 enum ofp_port_config {
186     OFPPC_PORT_DOWN    = 1 << 0,  /* Port is administratively down. */
187
188     OFPPC_NO_RECV      = 1 << 2,  /* Drop all packets received by port. */
189     OFPPC_NO_FWD       = 1 << 5,  /* Drop packets forwarded to port. */
190     OFPPC_NO_PACKET_IN = 1 << 6   /* Do not send packet-in msgs for port. */
191 };
192
193 /* Common current state of the physical port.  These are not configurable from
194  * the controller.
195  */
196 enum ofp_port_state {
197     OFPPS_LINK_DOWN    = 1 << 0,  /* No physical link present. */
198 };
199
200 /* Common features of physical ports available in a datapath. */
201 enum ofp_port_features {
202     OFPPF_10MB_HD    = 1 << 0,  /* 10 Mb half-duplex rate support. */
203     OFPPF_10MB_FD    = 1 << 1,  /* 10 Mb full-duplex rate support. */
204     OFPPF_100MB_HD   = 1 << 2,  /* 100 Mb half-duplex rate support. */
205     OFPPF_100MB_FD   = 1 << 3,  /* 100 Mb full-duplex rate support. */
206     OFPPF_1GB_HD     = 1 << 4,  /* 1 Gb half-duplex rate support. */
207     OFPPF_1GB_FD     = 1 << 5,  /* 1 Gb full-duplex rate support. */
208     OFPPF_10GB_FD    = 1 << 6,  /* 10 Gb full-duplex rate support. */
209 };
210
211 enum ofp_queue_properties {
212     OFPQT_MIN_RATE = 1,          /* Minimum datarate guaranteed. */
213     OFPQT_MAX_RATE = 2,          /* Maximum guaranteed rate. */
214     OFPQT_EXPERIMENTER = 0xffff, /* Experimenter defined property. */
215 };
216
217 /* Common description for a queue. */
218 struct ofp_queue_prop_header {
219     ovs_be16 property; /* One of OFPQT_. */
220     ovs_be16 len;      /* Length of property, including this header. */
221     uint8_t pad[4];    /* 64-bit alignemnt. */
222 };
223 OFP_ASSERT(sizeof(struct ofp_queue_prop_header) == 8);
224
225 /* Min-Rate and Max-Rate queue property description (OFPQT_MIN and
226  * OFPQT_MAX). */
227 struct ofp_queue_prop_rate {
228     struct ofp_queue_prop_header prop_header;
229     ovs_be16 rate;        /* In 1/10 of a percent; >1000 -> disabled. */
230     uint8_t pad[6];       /* 64-bit alignment */
231 };
232 OFP_ASSERT(sizeof(struct ofp_queue_prop_rate) == 16);
233
234 /* Switch features. */
235 struct ofp_switch_features {
236     ovs_be64 datapath_id;   /* Datapath unique ID.  The lower 48-bits are for
237                                a MAC address, while the upper 16-bits are
238                                implementer-defined. */
239
240     ovs_be32 n_buffers;     /* Max packets buffered at once. */
241
242     uint8_t n_tables;       /* Number of tables supported by datapath. */
243     uint8_t auxiliary_id;   /* OF 1.3: Identify auxiliary connections */
244     uint8_t pad[2];         /* Align to 64-bits. */
245
246     /* Features. */
247     ovs_be32 capabilities;  /* OFPC_*, OFPC10_*, OFPC11_*, OFPC12_*. */
248     ovs_be32 actions;       /* Bitmap of supported "ofp_action_type"s.
249                              * DEPRECATED in OpenFlow 1.1 */
250
251     /* Followed by an array of struct ofp10_phy_port or struct ofp11_port
252      * structures.  The number is inferred from header.length.
253      * REMOVED in OpenFlow 1.3 */
254 };
255 OFP_ASSERT(sizeof(struct ofp_switch_features) == 24);
256
257 /* Common capabilities supported by the datapath (struct ofp_switch_features,
258  * member capabilities). */
259 enum ofp_capabilities {
260     OFPC_FLOW_STATS     = 1 << 0,  /* Flow statistics. */
261     OFPC_TABLE_STATS    = 1 << 1,  /* Table statistics. */
262     OFPC_PORT_STATS     = 1 << 2,  /* Port statistics. */
263     OFPC_IP_REASM       = 1 << 5,  /* Can reassemble IP fragments. */
264     OFPC_QUEUE_STATS    = 1 << 6,  /* Queue statistics. */
265     OFPC_ARP_MATCH_IP   = 1 << 7   /* Match IP addresses in ARP
266                                       pkts. */
267 };
268
269 /* Why is this packet being sent to the controller? */
270 enum ofp_packet_in_reason {
271     OFPR_NO_MATCH,          /* No matching flow. */
272     OFPR_ACTION,            /* Action explicitly output to controller. */
273     OFPR_INVALID_TTL,       /* Packet has invalid TTL. */
274     OFPR_ACTION_SET,        /* Output to controller in action set */
275     OFPR_GROUP,             /* Output to controller in group bucket */
276     OFPR_PACKET_OUT,        /* Output to controller in packet-out */
277     OFPR_N_REASONS
278 };
279
280 enum ofp_flow_mod_command {
281     OFPFC_ADD,              /* New flow. */
282     OFPFC_MODIFY,           /* Modify all matching flows. */
283     OFPFC_MODIFY_STRICT,    /* Modify entry strictly matching wildcards */
284     OFPFC_DELETE,           /* Delete all matching flows. */
285     OFPFC_DELETE_STRICT     /* Strictly match wildcards and priority. */
286 };
287
288 enum ofp_flow_mod_flags {
289     OFPFF_SEND_FLOW_REM = 1 << 0,  /* Send flow removed message when flow
290                                     * expires or is deleted. */
291     OFPFF_CHECK_OVERLAP = 1 << 1,  /* Check for overlapping entries first. */
292 };
293
294 /* Why was this flow removed? */
295 enum ofp_flow_removed_reason {
296     OFPRR_IDLE_TIMEOUT,         /* Flow idle time exceeded idle_timeout. */
297     OFPRR_HARD_TIMEOUT,         /* Time exceeded hard_timeout. */
298     OFPRR_DELETE,               /* Evicted by a DELETE flow mod. */
299     OFPRR_GROUP_DELETE,         /* Group was removed. */
300     OFPRR_METER_DELETE,         /* Meter was removed. */
301     OFPRR_EVICTION,             /* Switch eviction to free resources. */
302
303     OVS_OFPRR_NONE              /* OVS internal_use only, keep last!. */
304 };
305
306 /* What changed about the physical port */
307 enum ofp_port_reason {
308     OFPPR_ADD,              /* The port was added. */
309     OFPPR_DELETE,           /* The port was removed. */
310     OFPPR_MODIFY            /* Some attribute of the port has changed. */
311 };
312
313 /* A physical port has changed in the datapath */
314 struct ofp_port_status {
315     uint8_t reason;          /* One of OFPPR_*. */
316     uint8_t pad[7];          /* Align to 64-bits. */
317     /* Followed by struct ofp10_phy_port, struct ofp11_port, or struct
318      * ofp14_port.  */
319 };
320 OFP_ASSERT(sizeof(struct ofp_port_status) == 8);
321
322 enum ofp_stats_reply_flags {
323     OFPSF_REPLY_MORE  = 1 << 0  /* More replies to follow. */
324 };
325
326 #define DESC_STR_LEN   256
327 #define SERIAL_NUM_LEN 32
328 /* Body of reply to OFPST_DESC request.  Each entry is a NULL-terminated ASCII
329  * string. */
330 struct ofp_desc_stats {
331     char mfr_desc[DESC_STR_LEN];       /* Manufacturer description. */
332     char hw_desc[DESC_STR_LEN];        /* Hardware description. */
333     char sw_desc[DESC_STR_LEN];        /* Software description. */
334     char serial_num[SERIAL_NUM_LEN];   /* Serial number. */
335     char dp_desc[DESC_STR_LEN];        /* Human readable description of
336                                           the datapath. */
337 };
338 OFP_ASSERT(sizeof(struct ofp_desc_stats) == 1056);
339
340 /* Reply to OFPST_AGGREGATE request. */
341 struct ofp_aggregate_stats_reply {
342     ovs_32aligned_be64 packet_count; /* Number of packets in flows. */
343     ovs_32aligned_be64 byte_count;   /* Number of bytes in flows. */
344     ovs_be32 flow_count;      /* Number of flows. */
345     uint8_t pad[4];           /* Align to 64 bits. */
346 };
347 OFP_ASSERT(sizeof(struct ofp_aggregate_stats_reply) == 24);
348
349 /* The match type indicates the match structure (set of fields that compose the
350  * match) in use. The match type is placed in the type field at the beginning
351  * of all match structures. The "OpenFlow Extensible Match" type corresponds
352  * to OXM TLV format described below and must be supported by all OpenFlow
353  * switches. Extensions that define other match types may be published on the
354  * ONF wiki. Support for extensions is optional.
355  */
356 enum ofp_match_type {
357     OFPMT_STANDARD = 0,         /* The match fields defined in the ofp11_match
358                                    structure apply */
359     OFPMT_OXM = 1,              /* OpenFlow Extensible Match */
360 };
361
362 /* Group numbering. Groups can use any number up to OFPG_MAX. */
363 enum ofp_group {
364     /* Last usable group number. */
365     OFPG_MAX        = 0xffffff00,
366
367     /* Fake groups. */
368     OFPG_ALL        = 0xfffffffc,  /* All groups, for group delete commands. */
369     OFPG_ANY        = 0xffffffff   /* Wildcard, for flow stats requests. */
370 };
371
372 /* Group configuration flags */
373 enum ofp_group_capabilities {
374     OFPGFC_SELECT_WEIGHT   = 1 << 0, /* Support weight for select groups */
375     OFPGFC_SELECT_LIVENESS = 1 << 1, /* Support liveness for select groups */
376     OFPGFC_CHAINING        = 1 << 2, /* Support chaining groups */
377     OFPGFC_CHAINING_CHECKS = 1 << 3, /* Check chaining for loops and delete */
378 };
379
380 enum ofp_hello_elem_type {
381     OFPHET_VERSIONBITMAP          = 1, /* Bitmap of version supported. */
382 };
383
384 /* Common header for all Hello Elements */
385 struct ofp_hello_elem_header {
386     ovs_be16    type;        /* One of OFPHET_*. */
387     ovs_be16    length;      /* Length in bytes of this element. */
388 };
389 OFP_ASSERT(sizeof(struct ofp_hello_elem_header) == 4);
390
391 /* Vendor extension. */
392 struct ofp_vendor_header {
393     struct ofp_header header;   /* Type OFPT_VENDOR or OFPT_EXPERIMENTER. */
394     ovs_be32 vendor;            /* Vendor ID:
395                                  * - MSB 0: low-order bytes are IEEE OUI.
396                                  * - MSB != 0: defined by OpenFlow
397                                  *   consortium. */
398     /* Vendor-defined arbitrary additional data. */
399 };
400 OFP_ASSERT(sizeof(struct ofp_vendor_header) == 12);
401
402 /* Table numbering. Tables can use any number up to OFPT_MAX. */
403 enum ofp_table {
404     /* Last usable table number. */
405     OFPTT_MAX = 0xfe,
406
407     /* Fake tables. */
408     OFPTT_ALL = 0xff         /* Wildcard table used for table config,
409                                 flow stats and flow deletes. */
410 };
411
412 enum ofp_table_config {
413     /* OpenFlow 1.1 and 1.2 defined this field as shown.
414      * OpenFlow 1.3 and later mark this field as deprecated, but have not
415      * reused it for any new purpose. */
416     OFPTC11_TABLE_MISS_CONTROLLER = 0 << 0, /* Send to controller. */
417     OFPTC11_TABLE_MISS_CONTINUE   = 1 << 0, /* Go to next table, like OF1.0. */
418     OFPTC11_TABLE_MISS_DROP       = 2 << 0, /* Drop the packet. */
419     OFPTC11_TABLE_MISS_MASK       = 3 << 0,
420
421     /* OpenFlow 1.4. */
422     OFPTC14_EVICTION              = 1 << 2, /* Allow table to evict flows. */
423     OFPTC14_VACANCY_EVENTS        = 1 << 3, /* Enable vacancy events. */
424 };
425
426 #endif /* openflow/openflow-common.h */