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