Add ability to direct "packet-in"s to particular controllers.
[sliver-openvswitch.git] / lib / ofp-errors.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef OFP_ERRORS_H
18 #define OFP_ERRORS_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <stdint.h>
23
24 struct ds;
25 struct ofp_header;
26
27 /* Error codes.
28  *
29  * We embed system errno values and OpenFlow standard and vendor extension
30  * error codes into the positive range of "int":
31  *
32  *   - Errno values are assumed to use the range 1 through 2**30 - 1.
33  *
34  *     (C and POSIX say that errno values are positive.  We assume that they
35  *     are less than 2**29.  They are actually less than 65536 on at least
36  *     Linux, FreeBSD, OpenBSD, and Windows.)
37  *
38  *   - OpenFlow standard and vendor extension error codes use the range
39  *     starting at 2**30 (OFPERR_OFS).
40  *
41  * Zero and negative values are not used.
42  */
43
44 #define OFPERR_OFS (1 << 30)
45
46 enum ofperr {
47 /* ## ------------------ ## */
48 /* ## OFPET_HELLO_FAILED ## */
49 /* ## ------------------ ## */
50
51     /* OF(0).  Hello protocol failed. */
52     OFPERR_OFPET_HELLO_FAILED = OFPERR_OFS,
53
54     /* OF(0,0).  No compatible version. */
55     OFPERR_OFPHFC_INCOMPATIBLE,
56
57     /* OF(0,1).  Permissions error. */
58     OFPERR_OFPHFC_EPERM,
59
60 /* ## ----------------- ## */
61 /* ## OFPET_BAD_REQUEST ## */
62 /* ## ----------------- ## */
63
64     /* OF(1).  Request was not understood. */
65     OFPERR_OFPET_BAD_REQUEST,
66
67     /* OF(1,0).  ofp_header.version not supported. */
68     OFPERR_OFPBRC_BAD_VERSION,
69
70     /* OF(1,1).  ofp_header.type not supported. */
71     OFPERR_OFPBRC_BAD_TYPE,
72
73     /* OF(1,2).  ofp_stats_msg.type not supported. */
74     OFPERR_OFPBRC_BAD_STAT,
75
76     /* OF(1,3).  Vendor not supported (in ofp_vendor_header or
77      * ofp_stats_msg). */
78     OFPERR_OFPBRC_BAD_VENDOR,
79
80     /* OF(1,4).  Vendor subtype not supported. */
81     OFPERR_OFPBRC_BAD_SUBTYPE,
82
83     /* OF(1,5).  Permissions error. */
84     OFPERR_OFPBRC_EPERM,
85
86     /* OF(1,6).  Wrong request length for type. */
87     OFPERR_OFPBRC_BAD_LEN,
88
89     /* OF(1,7).  Specified buffer has already been used. */
90     OFPERR_OFPBRC_BUFFER_EMPTY,
91
92     /* OF(1,8).  Specified buffer does not exist. */
93     OFPERR_OFPBRC_BUFFER_UNKNOWN,
94
95     /* OF1.1(1,9).  Specified table-id invalid or does not exist. */
96     OFPERR_OFPBRC_BAD_TABLE_ID,
97
98     /* NX(1,256).  Invalid NXM flow match. */
99     OFPERR_NXBRC_NXM_INVALID,
100
101     /* NX(1,257).  The nxm_type, or nxm_type taken in combination with
102      * nxm_hasmask or nxm_length or both, is invalid or not implemented. */
103     OFPERR_NXBRC_NXM_BAD_TYPE,
104
105     /* NX(1,258).  Invalid nxm_value. */
106     OFPERR_NXBRC_NXM_BAD_VALUE,
107
108     /* NX(1,259).  Invalid nxm_mask. */
109     OFPERR_NXBRC_NXM_BAD_MASK,
110
111     /* NX(1,260).  A prerequisite was not met. */
112     OFPERR_NXBRC_NXM_BAD_PREREQ,
113
114     /* NX(1,261).  A given nxm_type was specified more than once. */
115     OFPERR_NXBRC_NXM_DUP_TYPE,
116
117     /* NX(1,512).  A request specified a nonexistent table ID. */
118     OFPERR_NXBRC_BAD_TABLE_ID,
119
120     /* NX(1,513).  NXT_ROLE_REQUEST specified an invalid role. */
121     OFPERR_NXBRC_BAD_ROLE,
122
123     /* NX(1,514).  The in_port in an ofp_packet_out request is invalid. */
124     OFPERR_NXBRC_BAD_IN_PORT,
125
126     /* NX(1,515).  Must-be-zero field had nonzero value. */
127     OFPERR_NXBRC_MUST_BE_ZERO,
128
129 /* ## ---------------- ## */
130 /* ## OFPET_BAD_ACTION ## */
131 /* ## ---------------- ## */
132
133     /* OF(2).  Error in action description. */
134     OFPERR_OFPET_BAD_ACTION,
135
136     /* OF(2,0).  Unknown action type. */
137     OFPERR_OFPBAC_BAD_TYPE,
138
139     /* OF(2,1).  Length problem in actions. */
140     OFPERR_OFPBAC_BAD_LEN,
141
142     /* OF(2,2).  Unknown experimenter id specified. */
143     OFPERR_OFPBAC_BAD_VENDOR,
144
145     /* OF(2,3).  Unknown action type for experimenter id. */
146     OFPERR_OFPBAC_BAD_VENDOR_TYPE,
147
148     /* OF(2,4).  Problem validating output port. */
149     OFPERR_OFPBAC_BAD_OUT_PORT,
150
151     /* OF(2,5).  Bad action argument. */
152     OFPERR_OFPBAC_BAD_ARGUMENT,
153
154     /* OF(2,6).  Permissions error. */
155     OFPERR_OFPBAC_EPERM,
156
157     /* OF(2,7).  Can't handle this many actions. */
158     OFPERR_OFPBAC_TOO_MANY,
159
160     /* OF(2,8).  Problem validating output queue. */
161     OFPERR_OFPBAC_BAD_QUEUE,
162
163     /* OF1.1(2,9).  Invalid group id in forward action. */
164     OFPERR_OFPBAC_BAD_OUT_GROUP,
165
166     /* OF1.1(2,10).  Action can't apply for this match. */
167     OFPERR_OFPBAC_MATCH_INCONSISTENT,
168
169     /* OF1.1(2,11).  Action order is unsupported for the action list in an
170      * Apply-Actions instruction */
171     OFPERR_OFPBAC_UNSUPPORTED_ORDER,
172
173     /* OF1.1(2,12).  Actions uses an unsupported tag/encap. */
174     OFPERR_OFPBAC_BAD_TAG,
175
176     /* NX(2,256).  Must-be-zero action argument had nonzero value. */
177     OFPERR_NXBAC_MUST_BE_ZERO,
178
179 /* ## --------------------- ## */
180 /* ## OFPET_BAD_INSTRUCTION ## */
181 /* ## --------------------- ## */
182
183     /* OF1.1(3).  Error in instruction list. */
184     OFPERR_OFPET_BAD_INSTRUCTION,
185
186     /* OF1.1(3,0).  Unknown instruction. */
187     OFPERR_OFPBIC_UNKNOWN_INST,
188
189     /* OF1.1(3,1).  Switch or table does not support the instruction. */
190     OFPERR_OFPBIC_UNSUP_INST,
191
192     /* OF1.1(3,2).  Invalid Table-ID specified. */
193     OFPERR_OFPBIC_BAD_TABLE_ID,
194
195     /* OF1.1(3,3).  Metadata value unsupported by datapath. */
196     OFPERR_OFPBIC_UNSUP_METADATA,
197
198     /* OF1.1(3,4).  Metadata mask value unsupported by datapath. */
199     OFPERR_OFPBIC_UNSUP_METADATA_MASK,
200
201     /* OF1.1(3,5).  Specific experimenter instruction unsupported. */
202     OFPERR_OFPBIC_UNSUP_EXP_INST,
203
204 /* ## --------------- ## */
205 /* ## OFPET_BAD_MATCH ## */
206 /* ## --------------- ## */
207
208     /* OF1.1(4).  Error in match. */
209     OFPERR_OFPET_BAD_MATCH,
210
211     /* OF1.1(4,0).  Unsupported match type specified by the match */
212     OFPERR_OFPBMC_BAD_TYPE,
213
214     /* OF1.1(4,1).  Length problem in match. */
215     OFPERR_OFPBMC_BAD_LEN,
216
217     /* OF1.1(4,2).  Match uses an unsupported tag/encap. */
218     OFPERR_OFPBMC_BAD_TAG,
219
220     /* OF1.1(4,3).  Unsupported datalink addr mask - switch does not support
221      * arbitrary datalink address mask. */
222     OFPERR_OFPBMC_BAD_DL_ADDR_MASK,
223
224     /* OF1.1(4,4).  Unsupported network addr mask - switch does not support
225      * arbitrary network address mask. */
226     OFPERR_OFPBMC_BAD_NW_ADDR_MASK,
227
228     /* OF1.1(4,5).  Unsupported wildcard specified in the match. */
229     OFPERR_OFPBMC_BAD_WILDCARDS,
230
231     /* OF1.1(4,6).  Unsupported field in the match. */
232     OFPERR_OFPBMC_BAD_FIELD,
233
234     /* OF1.1(4,7).  Unsupported value in a match field. */
235     OFPERR_OFPBMC_BAD_VALUE,
236
237 /* ## --------------------- ## */
238 /* ## OFPET_FLOW_MOD_FAILED ## */
239 /* ## --------------------- ## */
240
241     /* OF1.0(3), OF1.1(5).  Problem modifying flow entry. */
242     OFPERR_OFPET_FLOW_MOD_FAILED,
243
244     /* OF1.1(5,0).  Unspecified error. */
245     OFPERR_OFPFMFC_UNKNOWN,
246
247     /* OF1.0(3,0).  Flow not added because of full tables. */
248     OFPERR_OFPFMFC_ALL_TABLES_FULL,
249
250     /* OF1.1(5,1).  Flow not added because table was full. */
251     OFPERR_OFPFMFC_TABLE_FULL,
252
253     /* OF1.1(5,2).  Table does not exist */
254     OFPERR_OFPFMFC_BAD_TABLE_ID,
255
256     /* OF1.0(3,1), OF1.1(5,3).  Attempted to add overlapping flow with
257      * CHECK_OVERLAP flag set. */
258     OFPERR_OFPFMFC_OVERLAP,
259
260     /* OF1.0(3,2), OF1.1(5,4).  Permissions error. */
261     OFPERR_OFPFMFC_EPERM,
262
263     /* OF1.1(5,5).  Flow not added because of unsupported idle/hard timeout. */
264     OFPERR_OFPFMFC_BAD_TIMEOUT,
265
266     /* OF1.0(3,3).  Flow not added because of non-zero idle/hard timeout. */
267     OFPERR_OFPFMFC_BAD_EMERG_TIMEOUT,
268
269     /* OF1.0(3,4), OF1.1(5,6).  Unsupported or unknown command. */
270     OFPERR_OFPFMFC_BAD_COMMAND,
271
272     /* OF1.0(3,5).  Unsupported action list - cannot process in the order
273      * specified. */
274     OFPERR_OFPFMFC_UNSUPPORTED,
275
276     /* NX1.0(3,256), NX1.1(5,256).  Generic hardware error. */
277     OFPERR_NXFMFC_HARDWARE,
278
279     /* NX1.0(3,257), NX1.1(5,257).  A nonexistent table ID was specified in the
280      * "command" field of struct ofp_flow_mod, when the nxt_flow_mod_table_id
281      * extension is enabled. */
282     OFPERR_NXFMFC_BAD_TABLE_ID,
283
284 /* ## ---------------------- ## */
285 /* ## OFPET_GROUP_MOD_FAILED ## */
286 /* ## ---------------------- ## */
287
288     /* OF1.1(6).  Problem modifying group entry. */
289     OFPERR_OFPET_GROUP_MOD_FAILED,
290
291     /* OF1.1(6,0).  Group not added because a group ADD attempted to replace an
292      * already-present group. */
293     OFPERR_OFPGMFC_GROUP_EXISTS,
294
295     /* OF1.1(6,1).  Group not added because Group specified is invalid. */
296     OFPERR_OFPGMFC_INVALID_GROUP,
297
298     /* OF1.1(6,2).  Switch does not support unequal load sharing with select
299      * groups. */
300     OFPERR_OFPGMFC_WEIGHT_UNSUPPORTED,
301
302     /* OF1.1(6,3).  The group table is full. */
303     OFPERR_OFPGMFC_OUT_OF_GROUPS,
304
305     /* OF1.1(6,4).  The maximum number of action buckets for a group has been
306      * exceeded. */
307     OFPERR_OFPGMFC_OUT_OF_BUCKETS,
308
309     /* OF1.1(6,5).  Switch does not support groups that forward to groups. */
310     OFPERR_OFPGMFC_CHAINING_UNSUPPORTED,
311
312     /* OF1.1(6,6).  This group cannot watch the watch_port or watch_group
313      * specified. */
314     OFPERR_OFPGMFC_WATCH_UNSUPPORTED,
315
316     /* OF1.1(6,7).  Group entry would cause a loop. */
317     OFPERR_OFPGMFC_LOOP,
318
319     /* OF1.1(6,8).  Group not modified because a group MODIFY attempted to
320      * modify a non-existent group. */
321     OFPERR_OFPGMFC_UNKNOWN_GROUP,
322
323 /* ## --------------------- ## */
324 /* ## OFPET_PORT_MOD_FAILED ## */
325 /* ## --------------------- ## */
326
327     /* OF1.0(4), OF1.1(7).  OFPT_PORT_MOD failed. */
328     OFPERR_OFPET_PORT_MOD_FAILED,
329
330     /* OF1.0(4,0), OF1.1(7,0).  Specified port does not exist. */
331     OFPERR_OFPPMFC_BAD_PORT,
332
333     /* OF1.0(4,1), OF1.1(7,1).  Specified hardware address does not match the
334      * port number. */
335     OFPERR_OFPPMFC_BAD_HW_ADDR,
336
337     /* OF1.1(7,2).  Specified config is invalid. */
338     OFPERR_OFPPMFC_BAD_CONFIG,
339
340     /* OF1.1(7,3).  Specified advertise is invalid. */
341     OFPERR_OFPPMFC_BAD_ADVERTISE,
342
343 /* ## ---------------------- ## */
344 /* ## OFPET_TABLE_MOD_FAILED ## */
345 /* ## ---------------------- ## */
346
347     /* OF1.1(8).  Table mod request failed. */
348     OFPERR_OFPET_TABLE_MOD_FAILED,
349
350     /* OF1.1(8,0).  Specified table does not exist. */
351     OFPERR_OFPTMFC_BAD_TABLE,
352
353     /* OF1.1(8,1).  Specified config is invalid. */
354     OFPERR_OFPTMFC_BAD_CONFIG,
355
356 /* ## --------------------- ## */
357 /* ## OFPET_QUEUE_OP_FAILED ## */
358 /* ## --------------------- ## */
359
360     /* OF1.0(5), OF1.1(9).  Queue operation failed. */
361     OFPERR_OFPET_QUEUE_OP_FAILED,
362
363     /* OF1.0(5,0), OF1.1(9,0).  Invalid port (or port does not exist). */
364     OFPERR_OFPQOFC_BAD_PORT,
365
366     /* OF1.0(5,1), OF1.1(9,1).  Queue does not exist. */
367     OFPERR_OFPQOFC_BAD_QUEUE,
368
369     /* OF1.0(5,2), OF1.1(9,2).  Permissions error. */
370     OFPERR_OFPQOFC_EPERM,
371
372 /* ## -------------------------- ## */
373 /* ## OFPET_SWITCH_CONFIG_FAILED ## */
374 /* ## -------------------------- ## */
375
376     /* OF1.1(10).  Switch config request failed. */
377     OFPERR_OFPET_SWITCH_CONFIG_FAILED,
378
379     /* OF1.1(10,0).  Specified flags is invalid. */
380     OFPERR_OFPSCFC_BAD_FLAGS,
381
382     /* OF1.1(10,1).  Specified len is invalid. */
383     OFPERR_OFPSCFC_BAD_LEN,
384 };
385
386 extern const struct ofperr_domain ofperr_of10;
387 extern const struct ofperr_domain ofperr_of11;
388
389 const struct ofperr_domain *ofperr_domain_from_version(uint8_t version);
390
391 bool ofperr_is_valid(enum ofperr);
392 bool ofperr_is_category(enum ofperr);
393 bool ofperr_is_nx_extension(enum ofperr);
394 bool ofperr_is_encodable(enum ofperr, const struct ofperr_domain *);
395
396 enum ofperr ofperr_decode(const struct ofperr_domain *,
397                           uint16_t type, uint16_t code);
398 enum ofperr ofperr_decode_type(const struct ofperr_domain *, uint16_t type);
399
400 enum ofperr ofperr_decode_msg(const struct ofp_header *, size_t *payload_ofs);
401 struct ofpbuf *ofperr_encode_reply(enum ofperr, const struct ofp_header *);
402 struct ofpbuf *ofperr_encode_hello(enum ofperr, const struct ofperr_domain *,
403                                    const char *);
404
405 const char *ofperr_get_name(enum ofperr);
406 const char *ofperr_get_description(enum ofperr);
407
408 void ofperr_format(struct ds *, enum ofperr);
409 const char *ofperr_to_string(enum ofperr);
410
411 #endif /* ofp-errors.h */