cef32f29ae8159e7ff706789e36fe88bc99b446d
[openvswitch] / 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     /* NX(1,516).  The reason in an ofp_port_status message is not valid. */
130     OFPERR_NXBRC_BAD_REASON,
131
132 /* ## ---------------- ## */
133 /* ## OFPET_BAD_ACTION ## */
134 /* ## ---------------- ## */
135
136     /* OF(2).  Error in action description. */
137     OFPERR_OFPET_BAD_ACTION,
138
139     /* OF(2,0).  Unknown action type. */
140     OFPERR_OFPBAC_BAD_TYPE,
141
142     /* OF(2,1).  Length problem in actions. */
143     OFPERR_OFPBAC_BAD_LEN,
144
145     /* OF(2,2).  Unknown experimenter id specified. */
146     OFPERR_OFPBAC_BAD_VENDOR,
147
148     /* OF(2,3).  Unknown action type for experimenter id. */
149     OFPERR_OFPBAC_BAD_VENDOR_TYPE,
150
151     /* OF(2,4).  Problem validating output port. */
152     OFPERR_OFPBAC_BAD_OUT_PORT,
153
154     /* OF(2,5).  Bad action argument. */
155     OFPERR_OFPBAC_BAD_ARGUMENT,
156
157     /* OF(2,6).  Permissions error. */
158     OFPERR_OFPBAC_EPERM,
159
160     /* OF(2,7).  Can't handle this many actions. */
161     OFPERR_OFPBAC_TOO_MANY,
162
163     /* OF(2,8).  Problem validating output queue. */
164     OFPERR_OFPBAC_BAD_QUEUE,
165
166     /* OF1.1(2,9).  Invalid group id in forward action. */
167     OFPERR_OFPBAC_BAD_OUT_GROUP,
168
169     /* OF1.1(2,10).  Action can't apply for this match. */
170     OFPERR_OFPBAC_MATCH_INCONSISTENT,
171
172     /* OF1.1(2,11).  Action order is unsupported for the action list in an
173      * Apply-Actions instruction */
174     OFPERR_OFPBAC_UNSUPPORTED_ORDER,
175
176     /* OF1.1(2,12).  Actions uses an unsupported tag/encap. */
177     OFPERR_OFPBAC_BAD_TAG,
178
179     /* NX(2,256).  Must-be-zero action argument had nonzero value. */
180     OFPERR_NXBAC_MUST_BE_ZERO,
181
182 /* ## --------------------- ## */
183 /* ## OFPET_BAD_INSTRUCTION ## */
184 /* ## --------------------- ## */
185
186     /* OF1.1(3).  Error in instruction list. */
187     OFPERR_OFPET_BAD_INSTRUCTION,
188
189     /* OF1.1(3,0).  Unknown instruction. */
190     OFPERR_OFPBIC_UNKNOWN_INST,
191
192     /* OF1.1(3,1).  Switch or table does not support the instruction. */
193     OFPERR_OFPBIC_UNSUP_INST,
194
195     /* OF1.1(3,2).  Invalid Table-ID specified. */
196     OFPERR_OFPBIC_BAD_TABLE_ID,
197
198     /* OF1.1(3,3).  Metadata value unsupported by datapath. */
199     OFPERR_OFPBIC_UNSUP_METADATA,
200
201     /* OF1.1(3,4).  Metadata mask value unsupported by datapath. */
202     OFPERR_OFPBIC_UNSUP_METADATA_MASK,
203
204     /* OF1.1(3,5).  Specific experimenter instruction unsupported. */
205     OFPERR_OFPBIC_UNSUP_EXP_INST,
206
207 /* ## --------------- ## */
208 /* ## OFPET_BAD_MATCH ## */
209 /* ## --------------- ## */
210
211     /* OF1.1(4).  Error in match. */
212     OFPERR_OFPET_BAD_MATCH,
213
214     /* OF1.1(4,0).  Unsupported match type specified by the match */
215     OFPERR_OFPBMC_BAD_TYPE,
216
217     /* OF1.1(4,1).  Length problem in match. */
218     OFPERR_OFPBMC_BAD_LEN,
219
220     /* OF1.1(4,2).  Match uses an unsupported tag/encap. */
221     OFPERR_OFPBMC_BAD_TAG,
222
223     /* OF1.1(4,3).  Unsupported datalink addr mask - switch does not support
224      * arbitrary datalink address mask. */
225     OFPERR_OFPBMC_BAD_DL_ADDR_MASK,
226
227     /* OF1.1(4,4).  Unsupported network addr mask - switch does not support
228      * arbitrary network address mask. */
229     OFPERR_OFPBMC_BAD_NW_ADDR_MASK,
230
231     /* OF1.1(4,5).  Unsupported wildcard specified in the match. */
232     OFPERR_OFPBMC_BAD_WILDCARDS,
233
234     /* OF1.1(4,6).  Unsupported field in the match. */
235     OFPERR_OFPBMC_BAD_FIELD,
236
237     /* OF1.1(4,7).  Unsupported value in a match field. */
238     OFPERR_OFPBMC_BAD_VALUE,
239
240 /* ## --------------------- ## */
241 /* ## OFPET_FLOW_MOD_FAILED ## */
242 /* ## --------------------- ## */
243
244     /* OF1.0(3), OF1.1(5).  Problem modifying flow entry. */
245     OFPERR_OFPET_FLOW_MOD_FAILED,
246
247     /* OF1.1(5,0).  Unspecified error. */
248     OFPERR_OFPFMFC_UNKNOWN,
249
250     /* OF1.0(3,0).  Flow not added because of full tables. */
251     OFPERR_OFPFMFC_ALL_TABLES_FULL,
252
253     /* OF1.1(5,1).  Flow not added because table was full. */
254     OFPERR_OFPFMFC_TABLE_FULL,
255
256     /* OF1.1(5,2).  Table does not exist */
257     OFPERR_OFPFMFC_BAD_TABLE_ID,
258
259     /* OF1.0(3,1), OF1.1(5,3).  Attempted to add overlapping flow with
260      * CHECK_OVERLAP flag set. */
261     OFPERR_OFPFMFC_OVERLAP,
262
263     /* OF1.0(3,2), OF1.1(5,4).  Permissions error. */
264     OFPERR_OFPFMFC_EPERM,
265
266     /* OF1.1(5,5).  Flow not added because of unsupported idle/hard timeout. */
267     OFPERR_OFPFMFC_BAD_TIMEOUT,
268
269     /* OF1.0(3,3).  Flow not added because of non-zero idle/hard timeout. */
270     OFPERR_OFPFMFC_BAD_EMERG_TIMEOUT,
271
272     /* OF1.0(3,4), OF1.1(5,6).  Unsupported or unknown command. */
273     OFPERR_OFPFMFC_BAD_COMMAND,
274
275     /* OF1.0(3,5).  Unsupported action list - cannot process in the order
276      * specified. */
277     OFPERR_OFPFMFC_UNSUPPORTED,
278
279     /* NX1.0(3,256), NX1.1(5,256).  Generic hardware error. */
280     OFPERR_NXFMFC_HARDWARE,
281
282     /* NX1.0(3,257), NX1.1(5,257).  A nonexistent table ID was specified in the
283      * "command" field of struct ofp_flow_mod, when the nxt_flow_mod_table_id
284      * extension is enabled. */
285     OFPERR_NXFMFC_BAD_TABLE_ID,
286
287 /* ## ---------------------- ## */
288 /* ## OFPET_GROUP_MOD_FAILED ## */
289 /* ## ---------------------- ## */
290
291     /* OF1.1(6).  Problem modifying group entry. */
292     OFPERR_OFPET_GROUP_MOD_FAILED,
293
294     /* OF1.1(6,0).  Group not added because a group ADD attempted to replace an
295      * already-present group. */
296     OFPERR_OFPGMFC_GROUP_EXISTS,
297
298     /* OF1.1(6,1).  Group not added because Group specified is invalid. */
299     OFPERR_OFPGMFC_INVALID_GROUP,
300
301     /* OF1.1(6,2).  Switch does not support unequal load sharing with select
302      * groups. */
303     OFPERR_OFPGMFC_WEIGHT_UNSUPPORTED,
304
305     /* OF1.1(6,3).  The group table is full. */
306     OFPERR_OFPGMFC_OUT_OF_GROUPS,
307
308     /* OF1.1(6,4).  The maximum number of action buckets for a group has been
309      * exceeded. */
310     OFPERR_OFPGMFC_OUT_OF_BUCKETS,
311
312     /* OF1.1(6,5).  Switch does not support groups that forward to groups. */
313     OFPERR_OFPGMFC_CHAINING_UNSUPPORTED,
314
315     /* OF1.1(6,6).  This group cannot watch the watch_port or watch_group
316      * specified. */
317     OFPERR_OFPGMFC_WATCH_UNSUPPORTED,
318
319     /* OF1.1(6,7).  Group entry would cause a loop. */
320     OFPERR_OFPGMFC_LOOP,
321
322     /* OF1.1(6,8).  Group not modified because a group MODIFY attempted to
323      * modify a non-existent group. */
324     OFPERR_OFPGMFC_UNKNOWN_GROUP,
325
326 /* ## --------------------- ## */
327 /* ## OFPET_PORT_MOD_FAILED ## */
328 /* ## --------------------- ## */
329
330     /* OF1.0(4), OF1.1(7).  OFPT_PORT_MOD failed. */
331     OFPERR_OFPET_PORT_MOD_FAILED,
332
333     /* OF1.0(4,0), OF1.1(7,0).  Specified port does not exist. */
334     OFPERR_OFPPMFC_BAD_PORT,
335
336     /* OF1.0(4,1), OF1.1(7,1).  Specified hardware address does not match the
337      * port number. */
338     OFPERR_OFPPMFC_BAD_HW_ADDR,
339
340     /* OF1.1(7,2).  Specified config is invalid. */
341     OFPERR_OFPPMFC_BAD_CONFIG,
342
343     /* OF1.1(7,3).  Specified advertise is invalid. */
344     OFPERR_OFPPMFC_BAD_ADVERTISE,
345
346 /* ## ---------------------- ## */
347 /* ## OFPET_TABLE_MOD_FAILED ## */
348 /* ## ---------------------- ## */
349
350     /* OF1.1(8).  Table mod request failed. */
351     OFPERR_OFPET_TABLE_MOD_FAILED,
352
353     /* OF1.1(8,0).  Specified table does not exist. */
354     OFPERR_OFPTMFC_BAD_TABLE,
355
356     /* OF1.1(8,1).  Specified config is invalid. */
357     OFPERR_OFPTMFC_BAD_CONFIG,
358
359 /* ## --------------------- ## */
360 /* ## OFPET_QUEUE_OP_FAILED ## */
361 /* ## --------------------- ## */
362
363     /* OF1.0(5), OF1.1(9).  Queue operation failed. */
364     OFPERR_OFPET_QUEUE_OP_FAILED,
365
366     /* OF1.0(5,0), OF1.1(9,0).  Invalid port (or port does not exist). */
367     OFPERR_OFPQOFC_BAD_PORT,
368
369     /* OF1.0(5,1), OF1.1(9,1).  Queue does not exist. */
370     OFPERR_OFPQOFC_BAD_QUEUE,
371
372     /* OF1.0(5,2), OF1.1(9,2).  Permissions error. */
373     OFPERR_OFPQOFC_EPERM,
374
375 /* ## -------------------------- ## */
376 /* ## OFPET_SWITCH_CONFIG_FAILED ## */
377 /* ## -------------------------- ## */
378
379     /* OF1.1(10).  Switch config request failed. */
380     OFPERR_OFPET_SWITCH_CONFIG_FAILED,
381
382     /* OF1.1(10,0).  Specified flags is invalid. */
383     OFPERR_OFPSCFC_BAD_FLAGS,
384
385     /* OF1.1(10,1).  Specified len is invalid. */
386     OFPERR_OFPSCFC_BAD_LEN,
387 };
388
389 extern const struct ofperr_domain ofperr_of10;
390 extern const struct ofperr_domain ofperr_of11;
391
392 const struct ofperr_domain *ofperr_domain_from_version(uint8_t version);
393
394 bool ofperr_is_valid(enum ofperr);
395 bool ofperr_is_category(enum ofperr);
396 bool ofperr_is_nx_extension(enum ofperr);
397 bool ofperr_is_encodable(enum ofperr, const struct ofperr_domain *);
398
399 enum ofperr ofperr_decode(const struct ofperr_domain *,
400                           uint16_t type, uint16_t code);
401 enum ofperr ofperr_decode_type(const struct ofperr_domain *, uint16_t type);
402
403 enum ofperr ofperr_decode_msg(const struct ofp_header *, size_t *payload_ofs);
404 struct ofpbuf *ofperr_encode_reply(enum ofperr, const struct ofp_header *);
405 struct ofpbuf *ofperr_encode_hello(enum ofperr, const struct ofperr_domain *,
406                                    const char *);
407
408 const char *ofperr_get_name(enum ofperr);
409 const char *ofperr_get_description(enum ofperr);
410
411 void ofperr_format(struct ds *, enum ofperr);
412 const char *ofperr_to_string(enum ofperr);
413
414 #endif /* ofp-errors.h */