openflow: Implement OF1.4+ OFPMP_QUEUE_DESC multipart message.
[cascardo/ovs.git] / lib / ofp-msgs.h
1 /*
2  * Copyright (c) 2012, 2013, 2014, 2015, 2016 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 ovs_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 /* Immutable standard messages.
96  *
97  * The OpenFlow standard promises to preserve these messages and their numbers
98  * in future versions, so we mark them as <all>, which covers every OpenFlow
99  * version numbered 0x01...0xff, rather than as OF1.0+, which covers only
100  * OpenFlow versions that we otherwise implement.
101  *
102  * Without <all> here, then we would fail to decode "hello" messages that
103  * announce a version higher than we understand, even though there still could
104  * be a version in common with the peer that we do understand.  The <all>
105  * keyword is less useful for the other messages, because our OpenFlow channels
106  * accept only OpenFlow messages with a previously negotiated version.
107  */
108
109     /* OFPT <all> (0): uint8_t[]. */
110     OFPRAW_OFPT_HELLO,
111
112     /* OFPT <all> (1): struct ofp_error_msg, uint8_t[]. */
113     OFPRAW_OFPT_ERROR,
114
115     /* OFPT <all> (2): uint8_t[]. */
116     OFPRAW_OFPT_ECHO_REQUEST,
117
118     /* OFPT <all> (3): uint8_t[]. */
119     OFPRAW_OFPT_ECHO_REPLY,
120
121 /* Other standard messages.
122  *
123  * The meanings of these messages can (and often do) change from one version
124  * of OpenFlow to another. */
125
126     /* OFPT 1.0+ (5): void. */
127     OFPRAW_OFPT_FEATURES_REQUEST,
128
129     /* OFPT 1.0 (6): struct ofp_switch_features, struct ofp10_phy_port[]. */
130     OFPRAW_OFPT10_FEATURES_REPLY,
131     /* OFPT 1.1-1.2 (6): struct ofp_switch_features, struct ofp11_port[]. */
132     OFPRAW_OFPT11_FEATURES_REPLY,
133     /* OFPT 1.3+ (6): struct ofp_switch_features. */
134     OFPRAW_OFPT13_FEATURES_REPLY,
135
136     /* OFPT 1.0+ (7): void. */
137     OFPRAW_OFPT_GET_CONFIG_REQUEST,
138
139     /* OFPT 1.0+ (8): struct ofp_switch_config. */
140     OFPRAW_OFPT_GET_CONFIG_REPLY,
141
142     /* OFPT 1.0+ (9): struct ofp_switch_config. */
143     OFPRAW_OFPT_SET_CONFIG,
144
145     /* OFPT 1.0 (10): struct ofp10_packet_in up to data, uint8_t[]. */
146     OFPRAW_OFPT10_PACKET_IN,
147     /* OFPT 1.1 (10): struct ofp11_packet_in, uint8_t[]. */
148     OFPRAW_OFPT11_PACKET_IN,
149     /* OFPT 1.2 (10): struct ofp12_packet_in, uint8_t[]. */
150     OFPRAW_OFPT12_PACKET_IN,
151     /* OFPT 1.3+ (10): struct ofp13_packet_in, uint8_t[]. */
152     OFPRAW_OFPT13_PACKET_IN,
153     /* NXT 1.0+ (17): struct nx_packet_in, uint8_t[]. */
154     OFPRAW_NXT_PACKET_IN,
155
156     /* OFPT 1.0 (11): struct ofp10_flow_removed. */
157     OFPRAW_OFPT10_FLOW_REMOVED,
158     /* OFPT 1.1+ (11): struct ofp11_flow_removed, uint8_t[8][]. */
159     OFPRAW_OFPT11_FLOW_REMOVED,
160     /* NXT 1.0+ (14): struct nx_flow_removed, uint8_t[8][]. */
161     OFPRAW_NXT_FLOW_REMOVED,
162
163     /* OFPT 1.0 (12): struct ofp_port_status, struct ofp10_phy_port. */
164     OFPRAW_OFPT10_PORT_STATUS,
165     /* OFPT 1.1-1.3 (12): struct ofp_port_status, struct ofp11_port. */
166     OFPRAW_OFPT11_PORT_STATUS,
167     /* OFPT 1.4+ (12): struct ofp_port_status, struct ofp14_port, uint8_t[8][]. */
168     OFPRAW_OFPT14_PORT_STATUS,
169
170     /* OFPT 1.0 (13): struct ofp10_packet_out, uint8_t[]. */
171     OFPRAW_OFPT10_PACKET_OUT,
172     /* OFPT 1.1+ (13): struct ofp11_packet_out, uint8_t[]. */
173     OFPRAW_OFPT11_PACKET_OUT,
174
175     /* OFPT 1.0 (14): struct ofp10_flow_mod, uint8_t[8][]. */
176     OFPRAW_OFPT10_FLOW_MOD,
177     /* OFPT 1.1+ (14): struct ofp11_flow_mod, struct ofp11_instruction[]. */
178     OFPRAW_OFPT11_FLOW_MOD,
179     /* NXT 1.0+ (13): struct nx_flow_mod, uint8_t[8][]. */
180     OFPRAW_NXT_FLOW_MOD,
181
182     /* OFPT 1.1-1.4 (15): struct ofp11_group_mod, uint8_t[8][]. */
183     OFPRAW_OFPT11_GROUP_MOD,
184     /* OFPT 1.5+ (15): struct ofp15_group_mod, uint8_t[8][]. */
185     OFPRAW_OFPT15_GROUP_MOD,
186
187     /* OFPT 1.0 (15): struct ofp10_port_mod. */
188     OFPRAW_OFPT10_PORT_MOD,
189     /* OFPT 1.1-1.3 (16): struct ofp11_port_mod. */
190     OFPRAW_OFPT11_PORT_MOD,
191     /* OFPT 1.4+ (16): struct ofp14_port_mod, uint8_t[8][]. */
192     OFPRAW_OFPT14_PORT_MOD,
193
194     /* OFPT 1.1-1.3 (17): struct ofp11_table_mod. */
195     OFPRAW_OFPT11_TABLE_MOD,
196     /* OFPT 1.4+ (17): struct ofp14_table_mod, uint8_t[8][]. */
197     OFPRAW_OFPT14_TABLE_MOD,
198
199     /* OFPT 1.0 (18): void. */
200     OFPRAW_OFPT10_BARRIER_REQUEST,
201     /* OFPT 1.1+ (20): void. */
202     OFPRAW_OFPT11_BARRIER_REQUEST,
203
204     /* OFPT 1.0 (19): void. */
205     OFPRAW_OFPT10_BARRIER_REPLY,
206     /* OFPT 1.1+ (21): void. */
207     OFPRAW_OFPT11_BARRIER_REPLY,
208
209     /* OFPT 1.0 (20): struct ofp10_queue_get_config_request. */
210     OFPRAW_OFPT10_QUEUE_GET_CONFIG_REQUEST,
211     /* OFPT 1.1-1.3 (22): struct ofp11_queue_get_config_request. */
212     OFPRAW_OFPT11_QUEUE_GET_CONFIG_REQUEST,
213
214     /* OFPT 1.0 (21): struct ofp10_queue_get_config_reply, uint8_t[8][]. */
215     OFPRAW_OFPT10_QUEUE_GET_CONFIG_REPLY,
216     /* OFPT 1.1-1.3 (23): struct ofp11_queue_get_config_reply, uint8_t[8][]. */
217     OFPRAW_OFPT11_QUEUE_GET_CONFIG_REPLY,
218
219     /* OFPT 1.2+ (24): struct ofp12_role_request. */
220     OFPRAW_OFPT12_ROLE_REQUEST,
221     /* NXT 1.0+ (10): struct nx_role_request. */
222     OFPRAW_NXT_ROLE_REQUEST,
223
224     /* OFPT 1.2+ (25): struct ofp12_role_request. */
225     OFPRAW_OFPT12_ROLE_REPLY,
226     /* NXT 1.0+ (11): struct nx_role_request. */
227     OFPRAW_NXT_ROLE_REPLY,
228
229     /* OFPT 1.3 (26): void. */
230     OFPRAW_OFPT13_GET_ASYNC_REQUEST,
231     /* OFPT 1.4+ (26): void. */
232     OFPRAW_OFPT14_GET_ASYNC_REQUEST,
233     /* OFPT 1.3 (27): struct ofp13_async_config. */
234     OFPRAW_OFPT13_GET_ASYNC_REPLY,
235     /* OFPT 1.4+ (27): uint8_t[8][]. */
236     OFPRAW_OFPT14_GET_ASYNC_REPLY,
237     /* OFPT 1.3 (28): struct ofp13_async_config. */
238     OFPRAW_OFPT13_SET_ASYNC,
239     /* NXT 1.0+ (19): struct nx_async_config. */
240     OFPRAW_NXT_SET_ASYNC_CONFIG,
241     /* OFPT 1.4+ (28): uint8_t[8][]. */
242     OFPRAW_OFPT14_SET_ASYNC,
243
244     /* OFPT 1.3+ (29): struct ofp13_meter_mod, uint8_t[8][]. */
245     OFPRAW_OFPT13_METER_MOD,
246
247     /* OFPT 1.4+ (30): struct ofp14_role_status, uint8_t[8][]. */
248     OFPRAW_OFPT14_ROLE_STATUS,
249
250     /* OFPT 1.4+ (32): struct ofp14_requestforward, uint8_t[8][]. */
251     OFPRAW_OFPT14_REQUESTFORWARD,
252
253     /* OFPT 1.4+ (33): struct ofp14_bundle_ctrl_msg, uint8_t[8][]. */
254     OFPRAW_OFPT14_BUNDLE_CONTROL,
255
256     /* OFPT 1.4+ (34): struct ofp14_bundle_ctrl_msg, uint8_t[]. */
257     OFPRAW_OFPT14_BUNDLE_ADD_MESSAGE,
258
259 /* Standard statistics. */
260
261     /* OFPST 1.0+ (0): void. */
262     OFPRAW_OFPST_DESC_REQUEST,
263
264     /* OFPST 1.0+ (0): struct ofp_desc_stats. */
265     OFPRAW_OFPST_DESC_REPLY,
266
267     /* OFPST 1.0 (1): struct ofp10_flow_stats_request. */
268     OFPRAW_OFPST10_FLOW_REQUEST,
269     /* OFPST 1.1+ (1): struct ofp11_flow_stats_request, uint8_t[8][]. */
270     OFPRAW_OFPST11_FLOW_REQUEST,
271     /* NXST 1.0 (0): struct nx_flow_stats_request, uint8_t[8][]. */
272     OFPRAW_NXST_FLOW_REQUEST,
273
274     /* OFPST 1.0 (1): uint8_t[]. */
275     OFPRAW_OFPST10_FLOW_REPLY,
276     /* OFPST 1.1-1.2 (1): uint8_t[]. */
277     OFPRAW_OFPST11_FLOW_REPLY,
278     /* OFPST 1.3+ (1): uint8_t[]. */
279     OFPRAW_OFPST13_FLOW_REPLY,
280     /* NXST 1.0 (0): uint8_t[]. */
281     OFPRAW_NXST_FLOW_REPLY,
282
283     /* OFPST 1.0 (2): struct ofp10_flow_stats_request. */
284     OFPRAW_OFPST10_AGGREGATE_REQUEST,
285     /* OFPST 1.1+ (2): struct ofp11_flow_stats_request, uint8_t[8][]. */
286     OFPRAW_OFPST11_AGGREGATE_REQUEST,
287     /* NXST 1.0 (1): struct nx_flow_stats_request, uint8_t[8][]. */
288     OFPRAW_NXST_AGGREGATE_REQUEST,
289
290     /* OFPST 1.0+ (2): struct ofp_aggregate_stats_reply. */
291     OFPRAW_OFPST_AGGREGATE_REPLY,
292     /* NXST 1.0 (1): struct ofp_aggregate_stats_reply. */
293     OFPRAW_NXST_AGGREGATE_REPLY,
294
295     /* OFPST 1.0+ (3): void. */
296     OFPRAW_OFPST_TABLE_REQUEST,
297
298     /* OFPST 1.0 (3): struct ofp10_table_stats[]. */
299     OFPRAW_OFPST10_TABLE_REPLY,
300     /* OFPST 1.1 (3): struct ofp11_table_stats[]. */
301     OFPRAW_OFPST11_TABLE_REPLY,
302     /* OFPST 1.2 (3): struct ofp12_table_stats[]. */
303     OFPRAW_OFPST12_TABLE_REPLY,
304     /* OFPST 1.3+ (3): struct ofp13_table_stats[]. */
305     OFPRAW_OFPST13_TABLE_REPLY,
306
307     /* OFPST 1.0 (4): struct ofp10_port_stats_request. */
308     OFPRAW_OFPST10_PORT_REQUEST,
309     /* OFPST 1.1+ (4): struct ofp11_port_stats_request. */
310     OFPRAW_OFPST11_PORT_REQUEST,
311
312     /* OFPST 1.0 (4): struct ofp10_port_stats[]. */
313     OFPRAW_OFPST10_PORT_REPLY,
314     /* OFPST 1.1-1.2 (4): struct ofp11_port_stats[]. */
315     OFPRAW_OFPST11_PORT_REPLY,
316     /* OFPST 1.3 (4): struct ofp13_port_stats[]. */
317     OFPRAW_OFPST13_PORT_REPLY,
318     /* OFPST 1.4+ (4): uint8_t[8][]. */
319     OFPRAW_OFPST14_PORT_REPLY,
320
321     /* OFPST 1.0 (5): struct ofp10_queue_stats_request. */
322     OFPRAW_OFPST10_QUEUE_REQUEST,
323     /* OFPST 1.1+ (5): struct ofp11_queue_stats_request. */
324     OFPRAW_OFPST11_QUEUE_REQUEST,
325
326     /* OFPST 1.0 (5): struct ofp10_queue_stats[]. */
327     OFPRAW_OFPST10_QUEUE_REPLY,
328     /* OFPST 1.1-1.2 (5): struct ofp11_queue_stats[]. */
329     OFPRAW_OFPST11_QUEUE_REPLY,
330     /* OFPST 1.3 (5): struct ofp13_queue_stats[]. */
331     OFPRAW_OFPST13_QUEUE_REPLY,
332     /* OFPST 1.4+ (5): uint8_t[8][]. */
333     OFPRAW_OFPST14_QUEUE_REPLY,
334
335     /* OFPST 1.1+ (6): struct ofp11_group_stats_request. */
336     OFPRAW_OFPST11_GROUP_REQUEST,
337
338     /* OFPST 1.1-1.2 (6): uint8_t[8][]. */
339     OFPRAW_OFPST11_GROUP_REPLY,
340     /* OFPST 1.3+ (6): uint8_t[8][]. */
341     OFPRAW_OFPST13_GROUP_REPLY,
342
343     /* OFPST 1.1-1.4 (7): void. */
344     OFPRAW_OFPST11_GROUP_DESC_REQUEST,
345     /* OFPST 1.5+ (7): struct ofp15_group_desc_request. */
346     OFPRAW_OFPST15_GROUP_DESC_REQUEST,
347
348     /* OFPST 1.1+ (7): uint8_t[8][]. */
349     OFPRAW_OFPST11_GROUP_DESC_REPLY,
350
351     /* OFPST 1.2+ (8): void. */
352     OFPRAW_OFPST12_GROUP_FEATURES_REQUEST,
353
354     /* OFPST 1.2+ (8): struct ofp12_group_features_stats. */
355     OFPRAW_OFPST12_GROUP_FEATURES_REPLY,
356
357     /* OFPST 1.3+ (9): struct ofp13_meter_multipart_request. */
358     OFPRAW_OFPST13_METER_REQUEST,
359
360     /* OFPST 1.3+ (9): uint8_t[8][]. */
361     OFPRAW_OFPST13_METER_REPLY,
362
363     /* OFPST 1.3+ (10): struct ofp13_meter_multipart_request. */
364     OFPRAW_OFPST13_METER_CONFIG_REQUEST,
365
366     /* OFPST 1.3+ (10): uint8_t[8][]. */
367     OFPRAW_OFPST13_METER_CONFIG_REPLY,
368
369     /* OFPST 1.3+ (11): void. */
370     OFPRAW_OFPST13_METER_FEATURES_REQUEST,
371
372     /* OFPST 1.3+ (11): struct ofp13_meter_features. */
373     OFPRAW_OFPST13_METER_FEATURES_REPLY,
374
375     /* OFPST 1.3+ (12): void. */
376     OFPRAW_OFPST13_TABLE_FEATURES_REQUEST,
377
378     /* OFPST 1.3+ (12): struct ofp13_table_features, uint8_t[8][]. */
379     OFPRAW_OFPST13_TABLE_FEATURES_REPLY,
380
381     /* OFPST 1.4+ (14): void. */
382     OFPRAW_OFPST14_TABLE_DESC_REQUEST,
383
384     /* OFPST 1.4+ (14): struct ofp14_table_desc, uint8_t[8][]. */
385     OFPRAW_OFPST14_TABLE_DESC_REPLY,
386
387     /* OFPST 1.0-1.4 (13): void. */
388     OFPRAW_OFPST10_PORT_DESC_REQUEST,
389     /* OFPST 1.5+ (13): struct ofp15_port_desc_request. */
390     OFPRAW_OFPST15_PORT_DESC_REQUEST,
391
392     /* OFPST 1.0 (13): struct ofp10_phy_port[]. */
393     OFPRAW_OFPST10_PORT_DESC_REPLY,
394     /* OFPST 1.1-1.3 (13): struct ofp11_port[]. */
395     OFPRAW_OFPST11_PORT_DESC_REPLY,
396     /* OFPST 1.4+ (13): uint8_t[8][]. */
397     OFPRAW_OFPST14_PORT_DESC_REPLY,
398
399     /* OFPST 1.4+ (15): struct ofp14_queue_desc_request. */
400     OFPRAW_OFPST14_QUEUE_DESC_REQUEST,
401     /* OFPST 1.4+ (15): uint8_t[8][]. */
402     OFPRAW_OFPST14_QUEUE_DESC_REPLY,
403
404     /* OFPST 1.4+ (16): uint8_t[8][]. */
405     OFPRAW_OFPST14_FLOW_MONITOR_REQUEST,
406     /* NXST 1.0 (2): uint8_t[8][]. */
407     OFPRAW_NXST_FLOW_MONITOR_REQUEST,
408
409     /* OFPST 1.4+ (16): uint8_t[8][]. */
410     OFPRAW_OFPST14_FLOW_MONITOR_REPLY,
411     /* NXST 1.0 (2): uint8_t[8][]. */
412     OFPRAW_NXST_FLOW_MONITOR_REPLY,
413
414 /* Nicira extension messages.
415  *
416  * Nicira extensions that correspond to standard OpenFlow messages are listed
417  * alongside the standard versions above. */
418
419     /* NXT 1.0 (12): struct nx_set_flow_format. */
420     OFPRAW_NXT_SET_FLOW_FORMAT,
421
422     /* NXT 1.0+ (15): struct nx_flow_mod_table_id. */
423     OFPRAW_NXT_FLOW_MOD_TABLE_ID,
424
425     /* NXT 1.0+ (16): struct nx_set_packet_in_format. */
426     OFPRAW_NXT_SET_PACKET_IN_FORMAT,
427
428     /* NXT 1.0+ (18): void. */
429     OFPRAW_NXT_FLOW_AGE,
430
431     /* NXT 1.0+ (20): struct nx_controller_id. */
432     OFPRAW_NXT_SET_CONTROLLER_ID,
433
434     /* NXT 1.0+ (21): struct nx_flow_monitor_cancel. */
435     OFPRAW_NXT_FLOW_MONITOR_CANCEL,
436
437     /* NXT 1.0+ (22): void. */
438     OFPRAW_NXT_FLOW_MONITOR_PAUSED,
439
440     /* NXT 1.0+ (23): void. */
441     OFPRAW_NXT_FLOW_MONITOR_RESUMED,
442
443     /* NXT 1.0+ (24): struct nx_tlv_table_mod, struct nx_tlv_map[]. */
444     OFPRAW_NXT_TLV_TABLE_MOD,
445
446     /* NXT 1.0+ (25): void. */
447     OFPRAW_NXT_TLV_TABLE_REQUEST,
448
449     /* NXT 1.0+ (26): struct nx_tlv_table_reply, struct nx_tlv_map[]. */
450     OFPRAW_NXT_TLV_TABLE_REPLY,
451 };
452
453 /* Decoding messages into OFPRAW_* values. */
454 enum ofperr ofpraw_decode(enum ofpraw *, const struct ofp_header *);
455 enum ofpraw ofpraw_decode_assert(const struct ofp_header *);
456 enum ofperr ofpraw_pull(enum ofpraw *, struct ofpbuf *);
457 enum ofpraw ofpraw_pull_assert(struct ofpbuf *);
458
459 enum ofperr ofpraw_decode_partial(enum ofpraw *,
460                                   const struct ofp_header *, size_t length);
461
462 /* Encoding messages using OFPRAW_* values. */
463 struct ofpbuf *ofpraw_alloc(enum ofpraw, uint8_t ofp_version,
464                             size_t extra_tailroom);
465 struct ofpbuf *ofpraw_alloc_xid(enum ofpraw, uint8_t ofp_version,
466                                 ovs_be32 xid, size_t extra_tailroom);
467 struct ofpbuf *ofpraw_alloc_reply(enum ofpraw,
468                                   const struct ofp_header *request,
469                                   size_t extra_tailroom);
470 struct ofpbuf *ofpraw_alloc_stats_reply(const struct ofp_header *request,
471                                         size_t extra_tailroom);
472
473 void ofpraw_put(enum ofpraw, uint8_t ofp_version, struct ofpbuf *);
474 void ofpraw_put_xid(enum ofpraw, uint8_t ofp_version, ovs_be32 xid,
475                     struct ofpbuf *);
476 void ofpraw_put_reply(enum ofpraw, const struct ofp_header *request,
477                       struct ofpbuf *);
478 void ofpraw_put_stats_reply(const struct ofp_header *request, struct ofpbuf *);
479
480 /* Information about OFPRAW_* values. */
481 const char *ofpraw_get_name(enum ofpraw);
482 enum ofpraw ofpraw_stats_request_to_reply(enum ofpraw, uint8_t version);
483 \f
484 /* Semantic identifiers for OpenFlow messages.
485  *
486  * Each OFPTYPE_* enumeration constant represents one or more concrete format
487  * of OpenFlow message.  When two variants of a message have essentially the
488  * same meaning, they are assigned a single OFPTYPE_* value.
489  *
490  * The comments here must follow a stylized form because the "extract-ofp-msgs"
491  * program parses them at build time to generate data tables.  The format is
492  * simply to list each OFPRAW_* enumeration constant for a given OFPTYPE_*,
493  * each followed by a period. */
494 enum ofptype {
495     /* Immutable messages. */
496     OFPTYPE_HELLO,               /* OFPRAW_OFPT_HELLO. */
497     OFPTYPE_ERROR,               /* OFPRAW_OFPT_ERROR. */
498     OFPTYPE_ECHO_REQUEST,        /* OFPRAW_OFPT_ECHO_REQUEST. */
499     OFPTYPE_ECHO_REPLY,          /* OFPRAW_OFPT_ECHO_REPLY. */
500
501     /* Switch configuration messages. */
502     OFPTYPE_FEATURES_REQUEST,    /* OFPRAW_OFPT_FEATURES_REQUEST. */
503     OFPTYPE_FEATURES_REPLY,      /* OFPRAW_OFPT10_FEATURES_REPLY.
504                                   * OFPRAW_OFPT11_FEATURES_REPLY.
505                                   * OFPRAW_OFPT13_FEATURES_REPLY. */
506     OFPTYPE_GET_CONFIG_REQUEST,  /* OFPRAW_OFPT_GET_CONFIG_REQUEST. */
507     OFPTYPE_GET_CONFIG_REPLY,    /* OFPRAW_OFPT_GET_CONFIG_REPLY. */
508     OFPTYPE_SET_CONFIG,          /* OFPRAW_OFPT_SET_CONFIG. */
509
510     /* Asynchronous messages. */
511     OFPTYPE_PACKET_IN,           /* OFPRAW_OFPT10_PACKET_IN.
512                                   * OFPRAW_OFPT11_PACKET_IN.
513                                   * OFPRAW_OFPT12_PACKET_IN.
514                                   * OFPRAW_OFPT13_PACKET_IN.
515                                   * OFPRAW_NXT_PACKET_IN. */
516     OFPTYPE_FLOW_REMOVED,        /* OFPRAW_OFPT10_FLOW_REMOVED.
517                                   * OFPRAW_OFPT11_FLOW_REMOVED.
518                                   * OFPRAW_NXT_FLOW_REMOVED. */
519     OFPTYPE_PORT_STATUS,         /* OFPRAW_OFPT10_PORT_STATUS.
520                                   * OFPRAW_OFPT11_PORT_STATUS.
521                                   * OFPRAW_OFPT14_PORT_STATUS. */
522
523     /* Controller command messages. */
524     OFPTYPE_PACKET_OUT,          /* OFPRAW_OFPT10_PACKET_OUT.
525                                   * OFPRAW_OFPT11_PACKET_OUT. */
526     OFPTYPE_FLOW_MOD,            /* OFPRAW_OFPT10_FLOW_MOD.
527                                   * OFPRAW_OFPT11_FLOW_MOD.
528                                   * OFPRAW_NXT_FLOW_MOD. */
529     OFPTYPE_GROUP_MOD,           /* OFPRAW_OFPT11_GROUP_MOD.
530                                   * OFPRAW_OFPT15_GROUP_MOD. */
531     OFPTYPE_PORT_MOD,            /* OFPRAW_OFPT10_PORT_MOD.
532                                   * OFPRAW_OFPT11_PORT_MOD.
533                                   * OFPRAW_OFPT14_PORT_MOD. */
534     OFPTYPE_TABLE_MOD,           /* OFPRAW_OFPT11_TABLE_MOD.
535                                   * OFPRAW_OFPT14_TABLE_MOD. */
536
537     /* Barrier messages. */
538     OFPTYPE_BARRIER_REQUEST,     /* OFPRAW_OFPT10_BARRIER_REQUEST.
539                                   * OFPRAW_OFPT11_BARRIER_REQUEST. */
540     OFPTYPE_BARRIER_REPLY,       /* OFPRAW_OFPT10_BARRIER_REPLY.
541                                   * OFPRAW_OFPT11_BARRIER_REPLY. */
542
543     /* Queue Configuration messages. */
544     OFPTYPE_QUEUE_GET_CONFIG_REQUEST, /* OFPRAW_OFPT10_QUEUE_GET_CONFIG_REQUEST.
545                                        * OFPRAW_OFPT11_QUEUE_GET_CONFIG_REQUEST.
546                                        * OFPRAW_OFPST14_QUEUE_DESC_REQUEST. */
547     OFPTYPE_QUEUE_GET_CONFIG_REPLY, /* OFPRAW_OFPT10_QUEUE_GET_CONFIG_REPLY.
548                                      * OFPRAW_OFPT11_QUEUE_GET_CONFIG_REPLY.
549                                      * OFPRAW_OFPST14_QUEUE_DESC_REPLY. */
550
551     /* Controller role change request messages. */
552     OFPTYPE_ROLE_REQUEST,         /* OFPRAW_OFPT12_ROLE_REQUEST.
553                                    * OFPRAW_NXT_ROLE_REQUEST. */
554     OFPTYPE_ROLE_REPLY,           /* OFPRAW_OFPT12_ROLE_REPLY.
555                                    * OFPRAW_NXT_ROLE_REPLY. */
556
557     /* Asynchronous message configuration. */
558     OFPTYPE_GET_ASYNC_REQUEST,    /* OFPRAW_OFPT13_GET_ASYNC_REQUEST.
559                                    * OFPRAW_OFPT14_GET_ASYNC_REQUEST. */
560     OFPTYPE_GET_ASYNC_REPLY,      /* OFPRAW_OFPT13_GET_ASYNC_REPLY.
561                                    * OFPRAW_OFPT14_GET_ASYNC_REPLY. */
562     OFPTYPE_SET_ASYNC_CONFIG,     /* OFPRAW_NXT_SET_ASYNC_CONFIG.
563                                    * OFPRAW_OFPT13_SET_ASYNC.
564                                    * OFPRAW_OFPT14_SET_ASYNC. */
565
566     /* Meters and rate limiters configuration messages. */
567     OFPTYPE_METER_MOD,            /* OFPRAW_OFPT13_METER_MOD. */
568
569     /* Controller role change event messages. */
570     OFPTYPE_ROLE_STATUS,          /* OFPRAW_OFPT14_ROLE_STATUS. */
571
572     /* Request forwarding by the switch. */
573     OFPTYPE_REQUESTFORWARD,       /* OFPRAW_OFPT14_REQUESTFORWARD. */
574
575     OFPTYPE_BUNDLE_CONTROL,       /* OFPRAW_OFPT14_BUNDLE_CONTROL. */
576
577     OFPTYPE_BUNDLE_ADD_MESSAGE,   /* OFPRAW_OFPT14_BUNDLE_ADD_MESSAGE. */
578
579     /* Statistics. */
580     OFPTYPE_DESC_STATS_REQUEST,      /* OFPRAW_OFPST_DESC_REQUEST. */
581     OFPTYPE_DESC_STATS_REPLY,        /* OFPRAW_OFPST_DESC_REPLY. */
582     OFPTYPE_FLOW_STATS_REQUEST,      /* OFPRAW_OFPST10_FLOW_REQUEST.
583                                       * OFPRAW_OFPST11_FLOW_REQUEST.
584                                       * OFPRAW_NXST_FLOW_REQUEST. */
585     OFPTYPE_FLOW_STATS_REPLY,        /* OFPRAW_OFPST10_FLOW_REPLY.
586                                       * OFPRAW_OFPST11_FLOW_REPLY.
587                                       * OFPRAW_OFPST13_FLOW_REPLY.
588                                       * OFPRAW_NXST_FLOW_REPLY. */
589     OFPTYPE_AGGREGATE_STATS_REQUEST, /* OFPRAW_OFPST10_AGGREGATE_REQUEST.
590                                       * OFPRAW_OFPST11_AGGREGATE_REQUEST.
591                                       * OFPRAW_NXST_AGGREGATE_REQUEST. */
592     OFPTYPE_AGGREGATE_STATS_REPLY,   /* OFPRAW_OFPST_AGGREGATE_REPLY.
593                                       * OFPRAW_NXST_AGGREGATE_REPLY. */
594     OFPTYPE_TABLE_STATS_REQUEST,     /* OFPRAW_OFPST_TABLE_REQUEST. */
595     OFPTYPE_TABLE_STATS_REPLY,       /* OFPRAW_OFPST10_TABLE_REPLY.
596                                       * OFPRAW_OFPST11_TABLE_REPLY.
597                                       * OFPRAW_OFPST12_TABLE_REPLY.
598                                       * OFPRAW_OFPST13_TABLE_REPLY. */
599     OFPTYPE_PORT_STATS_REQUEST,      /* OFPRAW_OFPST10_PORT_REQUEST.
600                                       * OFPRAW_OFPST11_PORT_REQUEST. */
601     OFPTYPE_PORT_STATS_REPLY,        /* OFPRAW_OFPST10_PORT_REPLY.
602                                       * OFPRAW_OFPST11_PORT_REPLY.
603                                       * OFPRAW_OFPST13_PORT_REPLY.
604                                       * OFPRAW_OFPST14_PORT_REPLY. */
605     OFPTYPE_QUEUE_STATS_REQUEST,     /* OFPRAW_OFPST10_QUEUE_REQUEST.
606                                       * OFPRAW_OFPST11_QUEUE_REQUEST. */
607     OFPTYPE_QUEUE_STATS_REPLY,       /* OFPRAW_OFPST10_QUEUE_REPLY.
608                                       * OFPRAW_OFPST11_QUEUE_REPLY.
609                                       * OFPRAW_OFPST13_QUEUE_REPLY.
610                                       * OFPRAW_OFPST14_QUEUE_REPLY. */
611
612     OFPTYPE_GROUP_STATS_REQUEST,     /* OFPRAW_OFPST11_GROUP_REQUEST. */
613
614     OFPTYPE_GROUP_STATS_REPLY,       /* OFPRAW_OFPST11_GROUP_REPLY.
615                                       * OFPRAW_OFPST13_GROUP_REPLY. */
616
617     OFPTYPE_GROUP_DESC_STATS_REQUEST, /* OFPRAW_OFPST11_GROUP_DESC_REQUEST.
618                                        * OFPRAW_OFPST15_GROUP_DESC_REQUEST. */
619
620     OFPTYPE_GROUP_DESC_STATS_REPLY,  /* OFPRAW_OFPST11_GROUP_DESC_REPLY. */
621
622     OFPTYPE_GROUP_FEATURES_STATS_REQUEST, /* OFPRAW_OFPST12_GROUP_FEATURES_REQUEST. */
623
624     OFPTYPE_GROUP_FEATURES_STATS_REPLY, /* OFPRAW_OFPST12_GROUP_FEATURES_REPLY. */
625
626     OFPTYPE_METER_STATS_REQUEST,     /* OFPRAW_OFPST13_METER_REQUEST. */
627
628     OFPTYPE_METER_STATS_REPLY,       /* OFPRAW_OFPST13_METER_REPLY. */
629
630     OFPTYPE_METER_CONFIG_STATS_REQUEST, /* OFPRAW_OFPST13_METER_CONFIG_REQUEST. */
631
632     OFPTYPE_METER_CONFIG_STATS_REPLY, /* OFPRAW_OFPST13_METER_CONFIG_REPLY. */
633
634     OFPTYPE_METER_FEATURES_STATS_REQUEST, /* OFPRAW_OFPST13_METER_FEATURES_REQUEST. */
635
636     OFPTYPE_METER_FEATURES_STATS_REPLY, /* OFPRAW_OFPST13_METER_FEATURES_REPLY. */
637
638     OFPTYPE_TABLE_FEATURES_STATS_REQUEST, /* OFPRAW_OFPST13_TABLE_FEATURES_REQUEST. */
639
640     OFPTYPE_TABLE_FEATURES_STATS_REPLY, /* OFPRAW_OFPST13_TABLE_FEATURES_REPLY. */
641
642     OFPTYPE_TABLE_DESC_REQUEST,      /* OFPRAW_OFPST14_TABLE_DESC_REQUEST. */
643
644     OFPTYPE_TABLE_DESC_REPLY,        /* OFPRAW_OFPST14_TABLE_DESC_REPLY. */
645
646     OFPTYPE_PORT_DESC_STATS_REQUEST, /* OFPRAW_OFPST10_PORT_DESC_REQUEST.
647                                       * OFPRAW_OFPST15_PORT_DESC_REQUEST. */
648
649     OFPTYPE_PORT_DESC_STATS_REPLY,   /* OFPRAW_OFPST10_PORT_DESC_REPLY.
650                                       * OFPRAW_OFPST11_PORT_DESC_REPLY.
651                                       * OFPRAW_OFPST14_PORT_DESC_REPLY. */
652
653     OFPTYPE_FLOW_MONITOR_STATS_REQUEST, /* OFPRAW_OFPST14_FLOW_MONITOR_REQUEST.
654                                          * OFPRAW_NXST_FLOW_MONITOR_REQUEST. */
655     OFPTYPE_FLOW_MONITOR_STATS_REPLY,   /* OFPRAW_OFPST14_FLOW_MONITOR_REPLY.
656                                          * OFPRAW_NXST_FLOW_MONITOR_REPLY. */
657
658     /* Nicira extensions. */
659     OFPTYPE_SET_FLOW_FORMAT,      /* OFPRAW_NXT_SET_FLOW_FORMAT. */
660     OFPTYPE_FLOW_MOD_TABLE_ID,    /* OFPRAW_NXT_FLOW_MOD_TABLE_ID. */
661     OFPTYPE_SET_PACKET_IN_FORMAT, /* OFPRAW_NXT_SET_PACKET_IN_FORMAT. */
662     OFPTYPE_FLOW_AGE,             /* OFPRAW_NXT_FLOW_AGE. */
663     OFPTYPE_SET_CONTROLLER_ID,    /* OFPRAW_NXT_SET_CONTROLLER_ID. */
664     OFPTYPE_NXT_TLV_TABLE_MOD, /* OFPRAW_NXT_TLV_TABLE_MOD. */
665     OFPTYPE_NXT_TLV_TABLE_REQUEST, /* OFPRAW_NXT_TLV_TABLE_REQUEST. */
666     OFPTYPE_NXT_TLV_TABLE_REPLY, /* OFPRAW_NXT_TLV_TABLE_REPLY. */
667
668     /* Flow monitor extension. */
669     OFPTYPE_FLOW_MONITOR_CANCEL,        /* OFPRAW_NXT_FLOW_MONITOR_CANCEL. */
670     OFPTYPE_FLOW_MONITOR_PAUSED,        /* OFPRAW_NXT_FLOW_MONITOR_PAUSED. */
671     OFPTYPE_FLOW_MONITOR_RESUMED,       /* OFPRAW_NXT_FLOW_MONITOR_RESUMED. */
672 };
673
674 /* Decoding messages into OFPTYPE_* values. */
675 enum ofperr ofptype_decode(enum ofptype *, const struct ofp_header *);
676 enum ofperr ofptype_pull(enum ofptype *, struct ofpbuf *);
677 enum ofptype ofptype_from_ofpraw(enum ofpraw);
678
679 /* Information about OFTYPE_* values. */
680 const char *ofptype_get_name(enum ofptype);
681 \f
682 /* OpenFlow message properties. */
683 void ofpmsg_update_length(struct ofpbuf *);
684 const void *ofpmsg_body(const struct ofp_header *);
685 bool ofpmsg_is_stat_request(const struct ofp_header *);
686 \f
687 /* Multipart messages (aka "statistics").
688  *
689  * Individual OpenFlow messages are limited to 64 kB in size, but some messages
690  * need to be longer.  Therefore, multipart messages allow a longer message to
691  * be divided into multiple parts at some convenient boundary.  For example,
692  * limiting the response to a "flow dump" request to 64 kB would unreasonably
693  * limit the maximum number of flows in an OpenFlow switch, so a "flow dump" is
694  * expressed as a multipart request/reply pair, with the reply broken into
695  * pieces between flows.
696  *
697  * Multipart messages always consist of a request/reply pair.
698  *
699  * In OpenFlow 1.0, 1.1, and 1.2, requests must always fit in a single message,
700  * that is, only a multipart reply may have more than one part.  OpenFlow 1.3
701  * adds one multipart request.  This code does not yet support multipart
702  * requests. */
703
704 /* Encoding multipart replies.
705  *
706  * These functions are useful for multipart replies that might really require
707  * more than one message.  A multipart message that is known in advance to fit
708  * within 64 kB doesn't need any special treatment, so you might as well use
709  * the ofpraw_alloc_*() functions.
710  *
711  * These functions work with a "struct ovs_list" of "struct ofpbuf"s, each of
712  * which represents one part of a multipart message. */
713 void ofpmp_init(struct ovs_list *, const struct ofp_header *request);
714 struct ofpbuf *ofpmp_reserve(struct ovs_list *, size_t len);
715 void *ofpmp_append(struct ovs_list *, size_t len);
716 void ofpmp_postappend(struct ovs_list *, size_t start_ofs);
717
718 enum ofp_version ofpmp_version(struct ovs_list *);
719 enum ofpraw ofpmp_decode_raw(struct ovs_list *);
720
721 /* Decoding multipart replies. */
722 uint16_t ofpmp_flags(const struct ofp_header *);
723 bool ofpmp_more(const struct ofp_header *);
724
725 #endif /* ofp-msgs.h */