ofp-msgs: Update OFPRAW_OFPT_SET_CONFIG for OpenFlow 1.2
[sliver-openvswitch.git] / lib / ofp-msgs.h
1 /*
2  * Copyright (c) 2012 Nicira, Inc.
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_MSGS_H
18 #define OFP_MSGS_H 1
19
20 /* OpenFlow message headers abstraction.
21  *
22  * OpenFlow headers are unnecessarily complicated:
23  *
24  *   - Some messages with the same meaning were renumbered between 1.0 and 1.1.
25  *
26  *   - "Statistics" (aka multipart) messages have a different format from other
27  *     messages.
28  *
29  *   - The 1.0 header for statistics messages is an odd number of 32-bit words
30  *     long, leaving 64-bit quantities in the body misaligned.  The 1.1 header
31  *     for statistics added a padding word to fix this misalignment, although
32  *     many statistic message bodies did not change.
33  *
34  *   - Vendor-defined messages have an additional header but no standard way to
35  *     distinguish individual types of message within a given vendor.
36  *
37  * This file attempts to abstract out the differences between the various forms
38  * of headers.
39  */
40
41 #include "openvswitch/types.h"
42 #include "ofp-errors.h"
43 #include "util.h"
44
45 struct list;
46 \f
47 /* Raw identifiers for OpenFlow messages.
48  *
49  * Some OpenFlow messages with similar meanings have multiple variants across
50  * OpenFlow versions or vendor extensions.  Each variant has a different
51  * OFPRAW_* enumeration constant.  More specifically, if two messages have
52  * different types, different numbers, or different arguments, then they must
53  * have different OFPRAW_* values.
54  *
55  * The comments here must follow a stylized form because the "extract-ofp-msgs"
56  * program parses them at build time to generate data tables.  The syntax of
57  * each comment is:
58  *
59  *    type versions (number): arguments.
60  *
61  * where the syntax of each part is:
62  *
63  *    - type: One of OFPT (standard OpenFlow message), OFPST (standard OpenFlow
64  *      statistics message), NXT (Nicira extension message), or NXST (Nicira
65  *      extension statistics message).
66  *
67  *      As new vendors implement extensions it will make sense to expand the
68  *      dictionary of possible types.
69  *
70  *    - versions: The OpenFlow version or versions in which this message is
71  *      supported, e.g. "1.0" or "1.1" or "1.0+".
72  *
73  *    - number:
74  *         For OFPT, the 'type' in struct ofp_header.
75  *         For OFPST, the 'type' in struct ofp_stats_msg or ofp11_stats_msg.
76  *         For NXT, the 'subtype' in struct nicira_header.
77  *         For NXST, the 'subtype' in struct nicira10_stats_msg or
78  *           nicira11_stats_msg.
79  *
80  *    - arguments: The types of data that follow the OpenFlow headers (the
81  *      message "body").  This can be "void" if the message has no body.
82  *      Otherwise, it should be a comma-separated sequence of C types.  The
83  *      last type in the sequence can end with [] if the body ends in a
84  *      variable-length sequence.
85  *
86  *      The arguments are used to validate the lengths of messages when a
87  *      header is parsed.  Any message whose length isn't valid as a length of
88  *      the specified types will be rejected with OFPERR_OFPBRC_BAD_LEN.
89  *
90  *      A few OpenFlow messages, such as OFPT_PACKET_IN, intentionally end with
91  *      only part of a structure, up to some specified member.  The syntax "up
92  *      to <member>" indicates this, e.g. "struct ofp11_packet_in up to data".
93  */
94 enum ofpraw {
95 /* Standard messages. */
96
97     /* OFPT 1.0+ (0): uint8_t[]. */
98     OFPRAW_OFPT_HELLO,
99
100     /* OFPT 1.0+ (1): struct ofp_error_msg, uint8_t[]. */
101     OFPRAW_OFPT_ERROR,
102
103     /* OFPT 1.0+ (2): uint8_t[]. */
104     OFPRAW_OFPT_ECHO_REQUEST,
105
106     /* OFPT 1.0+ (3): uint8_t[]. */
107     OFPRAW_OFPT_ECHO_REPLY,
108
109     /* OFPT 1.0+ (5): void. */
110     OFPRAW_OFPT_FEATURES_REQUEST,
111
112     /* OFPT 1.0 (6): struct ofp_switch_features, struct ofp10_phy_port[]. */
113     OFPRAW_OFPT10_FEATURES_REPLY,
114     /* OFPT 1.1+ (6): struct ofp_switch_features, struct ofp11_port[]. */
115     OFPRAW_OFPT11_FEATURES_REPLY,
116
117     /* OFPT 1.0+ (7): void. */
118     OFPRAW_OFPT_GET_CONFIG_REQUEST,
119
120     /* OFPT 1.0+ (8): struct ofp_switch_config. */
121     OFPRAW_OFPT_GET_CONFIG_REPLY,
122
123     /* OFPT 1.0+ (9): struct ofp_switch_config. */
124     OFPRAW_OFPT_SET_CONFIG,
125
126     /* OFPT 1.0 (10): struct ofp_packet_in up to data, uint8_t[]. */
127     OFPRAW_OFPT10_PACKET_IN,
128     /* OFPT 1.1 (10): struct ofp11_packet_in up to data, uint8_t[]. */
129     OFPRAW_OFPT11_PACKET_IN,
130     /* OFPT 1.2 (10): struct ofp12_packet_in, uint8_t[]. */
131     OFPRAW_OFPT12_PACKET_IN,
132     /* NXT 1.0+ (17): struct nx_packet_in, uint8_t[]. */
133     OFPRAW_NXT_PACKET_IN,
134
135     /* OFPT 1.0 (11): struct ofp_flow_removed. */
136     OFPRAW_OFPT10_FLOW_REMOVED,
137     /* NXT 1.0+ (14): struct nx_flow_removed, uint8_t[8][]. */
138     OFPRAW_NXT_FLOW_REMOVED,
139
140     /* OFPT 1.0 (12): struct ofp_port_status, struct ofp10_phy_port. */
141     OFPRAW_OFPT10_PORT_STATUS,
142     /* OFPT 1.1+ (12): struct ofp_port_status, struct ofp11_port. */
143     OFPRAW_OFPT11_PORT_STATUS,
144
145     /* OFPT 1.0 (13): struct ofp_packet_out, uint8_t[]. */
146     OFPRAW_OFPT10_PACKET_OUT,
147     /* OFPT 1.1+ (13): struct ofp11_packet_out, uint8_t[]. */
148     OFPRAW_OFPT11_PACKET_OUT,
149
150     /* OFPT 1.0 (14): struct ofp10_flow_mod, struct ofp_action_header[]. */
151     OFPRAW_OFPT10_FLOW_MOD,
152     /* OFPT 1.1+ (14): struct ofp11_flow_mod, struct ofp11_instruction[]. */
153     OFPRAW_OFPT11_FLOW_MOD,
154     /* NXT 1.0+ (13): struct nx_flow_mod, uint8_t[8][]. */
155     OFPRAW_NXT_FLOW_MOD,
156
157     /* OFPT 1.0 (15): struct ofp10_port_mod. */
158     OFPRAW_OFPT10_PORT_MOD,
159     /* OFPT 1.1 (16): struct ofp11_port_mod. */
160     OFPRAW_OFPT11_PORT_MOD,
161
162     /* OFPT 1.0 (18): void. */
163     OFPRAW_OFPT10_BARRIER_REQUEST,
164     /* OFPT 1.1 (20): void. */
165     OFPRAW_OFPT11_BARRIER_REQUEST,
166
167     /* OFPT 1.0 (19): void. */
168     OFPRAW_OFPT10_BARRIER_REPLY,
169     /* OFPT 1.1 (21): void. */
170     OFPRAW_OFPT11_BARRIER_REPLY,
171
172 /* Standard statistics. */
173
174     /* OFPST 1.0+ (0): void. */
175     OFPRAW_OFPST_DESC_REQUEST,
176
177     /* OFPST 1.0+ (0): struct ofp_desc_stats. */
178     OFPRAW_OFPST_DESC_REPLY,
179
180     /* OFPST 1.0 (1): struct ofp10_flow_stats_request. */
181     OFPRAW_OFPST_FLOW_REQUEST,
182     /* NXST 1.0 (0): struct nx_flow_stats_request, uint8_t[8][]. */
183     OFPRAW_NXST_FLOW_REQUEST,
184
185     /* OFPST 1.0 (1): uint8_t[]. */
186     OFPRAW_OFPST_FLOW_REPLY,
187     /* NXST 1.0 (0): uint8_t[]. */
188     OFPRAW_NXST_FLOW_REPLY,
189
190     /* OFPST 1.0 (2): struct ofp10_flow_stats_request. */
191     OFPRAW_OFPST_AGGREGATE_REQUEST,
192     /* NXST 1.0 (1): struct nx_flow_stats_request, uint8_t[8][]. */
193     OFPRAW_NXST_AGGREGATE_REQUEST,
194
195     /* OFPST 1.0 (2): struct ofp_aggregate_stats_reply. */
196     OFPRAW_OFPST_AGGREGATE_REPLY,
197     /* NXST 1.0 (1): struct ofp_aggregate_stats_reply. */
198     OFPRAW_NXST_AGGREGATE_REPLY,
199
200     /* OFPST 1.0 (3): void. */
201     OFPRAW_OFPST_TABLE_REQUEST,
202
203     /* OFPST 1.0 (3): struct ofp10_table_stats[]. */
204     OFPRAW_OFPST_TABLE_REPLY,
205
206     /* OFPST 1.0 (4): struct ofp10_port_stats_request. */
207     OFPRAW_OFPST_PORT_REQUEST,
208
209     /* OFPST 1.0 (4): struct ofp10_port_stats[]. */
210     OFPRAW_OFPST_PORT_REPLY,
211
212     /* OFPST 1.0 (5): struct ofp10_queue_stats_request. */
213     OFPRAW_OFPST_QUEUE_REQUEST,
214
215     /* OFPST 1.0 (5): struct ofp10_queue_stats[]. */
216     OFPRAW_OFPST_QUEUE_REPLY,
217
218     /* OFPST 1.0 (13): void. */
219     OFPRAW_OFPST_PORT_DESC_REQUEST,
220
221     /* OFPST 1.0 (13): struct ofp10_phy_port[]. */
222     OFPRAW_OFPST_PORT_DESC_REPLY,
223
224 /* Nicira extension messages.
225  *
226  * Nicira extensions that correspond to standard OpenFlow messages are listed
227  * alongside the standard versions above. */
228
229     /* NXT 1.0+ (10): struct nx_role_request. */
230     OFPRAW_NXT_ROLE_REQUEST,
231
232     /* NXT 1.0+ (11): struct nx_role_request. */
233     OFPRAW_NXT_ROLE_REPLY,
234
235     /* NXT 1.0+ (12): struct nx_set_flow_format. */
236     OFPRAW_NXT_SET_FLOW_FORMAT,
237
238     /* NXT 1.0+ (15): struct nx_flow_mod_table_id. */
239     OFPRAW_NXT_FLOW_MOD_TABLE_ID,
240
241     /* NXT 1.0+ (16): struct nx_set_packet_in_format. */
242     OFPRAW_NXT_SET_PACKET_IN_FORMAT,
243
244     /* NXT 1.0+ (18): void. */
245     OFPRAW_NXT_FLOW_AGE,
246
247     /* NXT 1.0+ (19): struct nx_async_config. */
248     OFPRAW_NXT_SET_ASYNC_CONFIG,
249
250     /* NXT 1.0+ (20): struct nx_controller_id. */
251     OFPRAW_NXT_SET_CONTROLLER_ID,
252
253     /* NXT 1.0+ (21): struct nx_flow_monitor_cancel. */
254     OFPRAW_NXT_FLOW_MONITOR_CANCEL,
255
256     /* NXT 1.0+ (22): void. */
257     OFPRAW_NXT_FLOW_MONITOR_PAUSED,
258
259     /* NXT 1.0+ (23): void. */
260     OFPRAW_NXT_FLOW_MONITOR_RESUMED,
261
262 /* Nicira extension statistics.
263  *
264  * Nicira extension statistics that correspond to standard OpenFlow statistics
265  * are listed alongside the standard versions above. */
266
267     /* NXST 1.0 (2): uint8_t[8][]. */
268     OFPRAW_NXST_FLOW_MONITOR_REQUEST,
269
270     /* NXST 1.0 (2): uint8_t[8][]. */
271     OFPRAW_NXST_FLOW_MONITOR_REPLY,
272 };
273
274 /* Decoding messages into OFPRAW_* values. */
275 enum ofperr ofpraw_decode(enum ofpraw *, const struct ofp_header *);
276 enum ofperr ofpraw_pull(enum ofpraw *, struct ofpbuf *);
277 enum ofpraw ofpraw_pull_assert(struct ofpbuf *);
278
279 enum ofperr ofpraw_decode_partial(enum ofpraw *,
280                                   const struct ofp_header *, size_t length);
281
282 /* Encoding messages using OFPRAW_* values. */
283 struct ofpbuf *ofpraw_alloc(enum ofpraw, uint8_t ofp_version,
284                             size_t extra_tailroom);
285 struct ofpbuf *ofpraw_alloc_xid(enum ofpraw, uint8_t ofp_version,
286                                 ovs_be32 xid, size_t extra_tailroom);
287 struct ofpbuf *ofpraw_alloc_reply(enum ofpraw,
288                                   const struct ofp_header *request,
289                                   size_t extra_tailroom);
290 struct ofpbuf *ofpraw_alloc_stats_reply(const struct ofp_header *request,
291                                         size_t extra_tailroom);
292
293 void ofpraw_put(enum ofpraw, uint8_t ofp_version, struct ofpbuf *);
294 void ofpraw_put_xid(enum ofpraw, uint8_t ofp_version, ovs_be32 xid,
295                     struct ofpbuf *);
296 void ofpraw_put_reply(enum ofpraw, const struct ofp_header *request,
297                       struct ofpbuf *);
298 void ofpraw_put_stats_reply(const struct ofp_header *request, struct ofpbuf *);
299
300 /* Information about OFPRAW_* values. */
301 const char *ofpraw_get_name(enum ofpraw);
302 enum ofpraw ofpraw_stats_request_to_reply(enum ofpraw, uint8_t version);
303 \f
304 /* Semantic identifiers for OpenFlow messages.
305  *
306  * Each OFPTYPE_* enumeration constant represents one or more concrete format
307  * of OpenFlow message.  When two variants of a message have essentially the
308  * same meaning, they are assigned a single OFPTYPE_* value.
309  *
310  * The comments here must follow a stylized form because the "extract-ofp-msgs"
311  * program parses them at build time to generate data tables.  The format is
312  * simply to list each OFPRAW_* enumeration constant for a given OFPTYPE_*,
313  * each followed by a period. */
314 enum ofptype {
315     /* Immutable messages. */
316     OFPTYPE_HELLO,               /* OFPRAW_OFPT_HELLO. */
317     OFPTYPE_ERROR,               /* OFPRAW_OFPT_ERROR. */
318     OFPTYPE_ECHO_REQUEST,        /* OFPRAW_OFPT_ECHO_REQUEST. */
319     OFPTYPE_ECHO_REPLY,          /* OFPRAW_OFPT_ECHO_REPLY. */
320
321     /* Switch configuration messages. */
322     OFPTYPE_FEATURES_REQUEST,    /* OFPRAW_OFPT_FEATURES_REQUEST. */
323     OFPTYPE_FEATURES_REPLY,      /* OFPRAW_OFPT10_FEATURES_REPLY.
324                                   * OFPRAW_OFPT11_FEATURES_REPLY. */
325     OFPTYPE_GET_CONFIG_REQUEST,  /* OFPRAW_OFPT_GET_CONFIG_REQUEST. */
326     OFPTYPE_GET_CONFIG_REPLY,    /* OFPRAW_OFPT_GET_CONFIG_REPLY. */
327     OFPTYPE_SET_CONFIG,          /* OFPRAW_OFPT_SET_CONFIG. */
328
329     /* Asynchronous messages. */
330     OFPTYPE_PACKET_IN,           /* OFPRAW_OFPT10_PACKET_IN.
331                                   * OFPRAW_OFPT11_PACKET_IN.
332                                   * OFPRAW_OFPT12_PACKET_IN.
333                                   * OFPRAW_NXT_PACKET_IN. */
334     OFPTYPE_FLOW_REMOVED,        /* OFPRAW_OFPT10_FLOW_REMOVED.
335                                   * OFPRAW_NXT_FLOW_REMOVED. */
336     OFPTYPE_PORT_STATUS,         /* OFPRAW_OFPT10_PORT_STATUS.
337                                   * OFPRAW_OFPT11_PORT_STATUS. */
338
339     /* Controller command messages. */
340     OFPTYPE_PACKET_OUT,          /* OFPRAW_OFPT10_PACKET_OUT.
341                                   * OFPRAW_OFPT11_PACKET_OUT. */
342     OFPTYPE_FLOW_MOD,            /* OFPRAW_OFPT10_FLOW_MOD.
343                                   * OFPRAW_OFPT11_FLOW_MOD.
344                                   * OFPRAW_NXT_FLOW_MOD. */
345     OFPTYPE_PORT_MOD,            /* OFPRAW_OFPT10_PORT_MOD.
346                                   * OFPRAW_OFPT11_PORT_MOD. */
347
348     /* Barrier messages. */
349     OFPTYPE_BARRIER_REQUEST,     /* OFPRAW_OFPT10_BARRIER_REQUEST.
350                                   * OFPRAW_OFPT11_BARRIER_REQUEST. */
351     OFPTYPE_BARRIER_REPLY,       /* OFPRAW_OFPT10_BARRIER_REPLY.
352                                   * OFPRAW_OFPT11_BARRIER_REPLY. */
353
354     /* Statistics. */
355     OFPTYPE_DESC_STATS_REQUEST,      /* OFPRAW_OFPST_DESC_REQUEST. */
356     OFPTYPE_DESC_STATS_REPLY,        /* OFPRAW_OFPST_DESC_REPLY. */
357     OFPTYPE_FLOW_STATS_REQUEST,      /* OFPRAW_OFPST_FLOW_REQUEST.
358                                       * OFPRAW_NXST_FLOW_REQUEST. */
359     OFPTYPE_FLOW_STATS_REPLY,        /* OFPRAW_OFPST_FLOW_REPLY.
360                                       * OFPRAW_NXST_FLOW_REPLY. */
361     OFPTYPE_AGGREGATE_STATS_REQUEST, /* OFPRAW_OFPST_AGGREGATE_REQUEST.
362                                       * OFPRAW_NXST_AGGREGATE_REQUEST. */
363     OFPTYPE_AGGREGATE_STATS_REPLY,   /* OFPRAW_OFPST_AGGREGATE_REPLY.
364                                       * OFPRAW_NXST_AGGREGATE_REPLY. */
365     OFPTYPE_TABLE_STATS_REQUEST,     /* OFPRAW_OFPST_TABLE_REQUEST. */
366     OFPTYPE_TABLE_STATS_REPLY,       /* OFPRAW_OFPST_TABLE_REPLY. */
367     OFPTYPE_PORT_STATS_REQUEST,      /* OFPRAW_OFPST_PORT_REQUEST. */
368     OFPTYPE_PORT_STATS_REPLY,        /* OFPRAW_OFPST_PORT_REPLY. */
369     OFPTYPE_QUEUE_STATS_REQUEST,     /* OFPRAW_OFPST_QUEUE_REQUEST. */
370     OFPTYPE_QUEUE_STATS_REPLY,       /* OFPRAW_OFPST_QUEUE_REPLY. */
371     OFPTYPE_PORT_DESC_STATS_REQUEST, /* OFPRAW_OFPST_PORT_DESC_REQUEST. */
372     OFPTYPE_PORT_DESC_STATS_REPLY,   /* OFPRAW_OFPST_PORT_DESC_REPLY. */
373
374     /* Nicira extensions. */
375     OFPTYPE_ROLE_REQUEST,         /* OFPRAW_NXT_ROLE_REQUEST. */
376     OFPTYPE_ROLE_REPLY,           /* OFPRAW_NXT_ROLE_REPLY. */
377     OFPTYPE_SET_FLOW_FORMAT,      /* OFPRAW_NXT_SET_FLOW_FORMAT. */
378     OFPTYPE_FLOW_MOD_TABLE_ID,    /* OFPRAW_NXT_FLOW_MOD_TABLE_ID. */
379     OFPTYPE_SET_PACKET_IN_FORMAT, /* OFPRAW_NXT_SET_PACKET_IN_FORMAT. */
380     OFPTYPE_FLOW_AGE,             /* OFPRAW_NXT_FLOW_AGE. */
381     OFPTYPE_SET_ASYNC_CONFIG,     /* OFPRAW_NXT_SET_ASYNC_CONFIG. */
382     OFPTYPE_SET_CONTROLLER_ID,    /* OFPRAW_NXT_SET_CONTROLLER_ID. */
383
384     /* Flow monitor extension. */
385     OFPTYPE_FLOW_MONITOR_STATS_REQUEST, /* OFPRAW_NXST_FLOW_MONITOR_REQUEST. */
386     OFPTYPE_FLOW_MONITOR_STATS_REPLY,   /* OFPRAW_NXST_FLOW_MONITOR_REPLY. */
387     OFPTYPE_FLOW_MONITOR_CANCEL,        /* OFPRAW_NXT_FLOW_MONITOR_CANCEL. */
388     OFPTYPE_FLOW_MONITOR_PAUSED,        /* OFPRAW_NXT_FLOW_MONITOR_PAUSED. */
389     OFPTYPE_FLOW_MONITOR_RESUMED,       /* OFPRAW_NXT_FLOW_MONITOR_RESUMED. */
390 };
391
392 /* Decoding messages into OFPTYPE_* values. */
393 enum ofperr ofptype_decode(enum ofptype *, const struct ofp_header *);
394 enum ofperr ofptype_pull(enum ofptype *, struct ofpbuf *);
395 enum ofptype ofptype_from_ofpraw(enum ofpraw);
396 \f
397 /* OpenFlow message properties. */
398 void ofpmsg_update_length(struct ofpbuf *);
399 const void *ofpmsg_body(const struct ofp_header *);
400 \f
401 /* Multipart messages (aka "statistics").
402  *
403  * Individual OpenFlow messages are limited to 64 kB in size, but some messages
404  * need to be longer.  Therefore, multipart messages allow a longer message to
405  * be divided into multiple parts at some convenient boundary.  For example,
406  * limiting the response to a "flow dump" request to 64 kB would unreasonably
407  * limit the maximum number of flows in an OpenFlow switch, so a "flow dump" is
408  * expressed as a multipart request/reply pair, with the reply broken into
409  * pieces between flows.
410  *
411  * Multipart messages always consist of a request/reply pair.
412  *
413  * In OpenFlow 1.0, 1.1, and 1.2, requests must always fit in a single message,
414  * that is, only a multipart reply may have more than one part.  OpenFlow 1.3
415  * adds one multipart request.  This code does not yet support multipart
416  * requests. */
417
418 /* Encoding multipart replies.
419  *
420  * These functions are useful for multipart replies that might really require
421  * more than one message.  A multipart message that is known in advance to fit
422  * within 64 kB doesn't need any special treatment, so you might as well use
423  * the ofpraw_alloc_*() functions.
424  *
425  * These functions work with a "struct list" of "struct ofpbuf"s, each of
426  * which represents one part of a multipart message. */
427 void ofpmp_init(struct list *, const struct ofp_header *request);
428 struct ofpbuf *ofpmp_reserve(struct list *, size_t len);
429 void *ofpmp_append(struct list *, size_t len);
430 void ofpmp_postappend(struct list *, size_t start_ofs);
431
432 /* Decoding multipart replies. */
433 uint16_t ofpmp_flags(const struct ofp_header *);
434 bool ofpmp_more(const struct ofp_header *);
435
436 #endif /* ofp-msgs.h */