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