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