ofproto: Allow the use of the OpenFlow 1.4 protocol
[sliver-openvswitch.git] / lib / ofp-util.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 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_UTIL_H
18 #define OFP_UTIL_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22 #include <stdint.h>
23 #include "compiler.h"
24 #include "flow.h"
25 #include "list.h"
26 #include "match.h"
27 #include "netdev.h"
28 #include "openflow/nicira-ext.h"
29 #include "openvswitch/types.h"
30 #include "type-props.h"
31
32 struct ofpbuf;
33 union ofp_action;
34 struct ofpact_set_field;
35
36 /* Port numbers. */
37 enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port,
38                                     ofp_port_t *ofp10_port);
39 ovs_be32 ofputil_port_to_ofp11(ofp_port_t ofp10_port);
40
41 bool ofputil_port_from_string(const char *, ofp_port_t *portp);
42 void ofputil_format_port(ofp_port_t port, struct ds *);
43 void ofputil_port_to_string(ofp_port_t, char namebuf[OFP_MAX_PORT_NAME_LEN],
44                             size_t bufsize);
45
46 /* Group numbers. */
47 enum { MAX_GROUP_NAME_LEN = INT_STRLEN(uint32_t) };
48 bool ofputil_group_from_string(const char *, uint32_t *group_id);
49 void ofputil_format_group(uint32_t group_id, struct ds *);
50 void ofputil_group_to_string(uint32_t group_id,
51                              char namebuf[MAX_GROUP_NAME_LEN + 1],
52                              size_t bufsize);
53
54 /* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts
55  * to and from IP bitmasks. */
56 ovs_be32 ofputil_wcbits_to_netmask(int wcbits);
57 int ofputil_netmask_to_wcbits(ovs_be32 netmask);
58
59 /* Protocols.
60  *
61  * A "protocol" is an OpenFlow version plus, for some OpenFlow versions,
62  * a bit extra about the flow match format in use.
63  *
64  * These are arranged from most portable to least portable, or alternatively
65  * from least powerful to most powerful.  Protocols earlier on the list are
66  * more likely to be understood for the purpose of making requests, but
67  * protocol later on the list are more likely to accurately describe a flow
68  * within a switch.
69  *
70  * On any given OpenFlow connection, a single protocol is in effect at any
71  * given time.  These values use separate bits only because that makes it easy
72  * to test whether a particular protocol is within a given set of protocols and
73  * to implement set union and intersection.
74  */
75 enum ofputil_protocol {
76     /* OpenFlow 1.0 protocols.
77      *
78      * The "STD" protocols use the standard OpenFlow 1.0 flow format.
79      * The "NXM" protocols use the Nicira Extensible Match (NXM) flow format.
80      *
81      * The protocols with "TID" mean that the nx_flow_mod_table_id Nicira
82      * extension has been enabled.  The other protocols have it disabled.
83      */
84 #define OFPUTIL_P_NONE 0
85     OFPUTIL_P_OF10_STD     = 1 << 0,
86     OFPUTIL_P_OF10_STD_TID = 1 << 1,
87     OFPUTIL_P_OF10_NXM     = 1 << 2,
88     OFPUTIL_P_OF10_NXM_TID = 1 << 3,
89 #define OFPUTIL_P_OF10_STD_ANY (OFPUTIL_P_OF10_STD | OFPUTIL_P_OF10_STD_TID)
90 #define OFPUTIL_P_OF10_NXM_ANY (OFPUTIL_P_OF10_NXM | OFPUTIL_P_OF10_NXM_TID)
91 #define OFPUTIL_P_OF10_ANY (OFPUTIL_P_OF10_STD_ANY | OFPUTIL_P_OF10_NXM_ANY)
92
93     /* OpenFlow 1.1 protocol.
94      *
95      * We only support the standard OpenFlow 1.1 flow format.
96      *
97      * OpenFlow 1.1 always operates with an equivalent of the
98      * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
99      * variant. */
100     OFPUTIL_P_OF11_STD     = 1 << 4,
101
102     /* OpenFlow 1.2+ protocols (only one variant each).
103      *
104      * These use the standard OpenFlow Extensible Match (OXM) flow format.
105      *
106      * OpenFlow 1.2+ always operates with an equivalent of the
107      * nx_flow_mod_table_id Nicira extension enabled, so there is no "TID"
108      * variant. */
109     OFPUTIL_P_OF12_OXM      = 1 << 5,
110     OFPUTIL_P_OF13_OXM      = 1 << 6,
111     OFPUTIL_P_OF14_OXM      = 1 << 7,
112 #define OFPUTIL_P_ANY_OXM (OFPUTIL_P_OF12_OXM | OFPUTIL_P_OF13_OXM | OFPUTIL_P_OF14_OXM)
113
114 #define OFPUTIL_P_NXM_OF11_UP (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_OF11_STD | \
115                                OFPUTIL_P_ANY_OXM)
116
117 #define OFPUTIL_P_NXM_OXM_ANY (OFPUTIL_P_OF10_NXM_ANY | OFPUTIL_P_ANY_OXM)
118
119 #define OFPUTIL_P_OF11_UP (OFPUTIL_P_OF11_STD | OFPUTIL_P_ANY_OXM)
120
121 #define OFPUTIL_P_OF12_UP (OFPUTIL_P_ANY_OXM)
122
123 #define OFPUTIL_P_OF13_UP (OFPUTIL_P_OF13_OXM)
124
125 #define OFPUTIL_P_OF14_UP (OFPUTIL_P_OF14_OXM)
126
127     /* All protocols. */
128 #define OFPUTIL_P_ANY ((1 << 8) - 1)
129
130     /* Protocols in which a specific table may be specified in flow_mods. */
131 #define OFPUTIL_P_TID (OFPUTIL_P_OF10_STD_TID | \
132                        OFPUTIL_P_OF10_NXM_TID | \
133                        OFPUTIL_P_OF11_STD |     \
134                        OFPUTIL_P_ANY_OXM)
135 };
136
137 /* Protocols to use for flow dumps, from most to least preferred. */
138 extern enum ofputil_protocol ofputil_flow_dump_protocols[];
139 extern size_t ofputil_n_flow_dump_protocols;
140
141 enum ofputil_protocol ofputil_protocol_from_ofp_version(enum ofp_version);
142 enum ofputil_protocol ofputil_protocols_from_ofp_version(enum ofp_version);
143 enum ofp_version ofputil_protocol_to_ofp_version(enum ofputil_protocol);
144
145 bool ofputil_protocol_is_valid(enum ofputil_protocol);
146 enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
147                                                bool enable);
148 enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
149 enum ofputil_protocol ofputil_protocol_set_base(
150     enum ofputil_protocol cur, enum ofputil_protocol new_base);
151
152 const char *ofputil_protocol_to_string(enum ofputil_protocol);
153 char *ofputil_protocols_to_string(enum ofputil_protocol);
154 enum ofputil_protocol ofputil_protocols_from_string(const char *);
155
156 void ofputil_format_version(struct ds *, enum ofp_version);
157 void ofputil_format_version_name(struct ds *, enum ofp_version);
158
159 /* A bitmap of version numbers
160  *
161  * Bit offsets correspond to ofp_version numbers which in turn correspond to
162  * wire-protocol numbers for Open Flow versions..  E.g. (1u << OFP11_VERSION)
163  * is the mask for Open Flow 1.1.  If the bit for a version is set then it is
164  * allowed, otherwise it is disallowed. */
165
166 void ofputil_format_version_bitmap(struct ds *msg, uint32_t bitmap);
167 void ofputil_format_version_bitmap_names(struct ds *msg, uint32_t bitmap);
168
169 uint32_t ofputil_protocols_to_version_bitmap(enum ofputil_protocol);
170 enum ofputil_protocol ofputil_protocols_from_version_bitmap(uint32_t bitmap);
171
172 /* Bitmap of OpenFlow versions that Open vSwitch supports. */
173 #define OFPUTIL_SUPPORTED_VERSIONS \
174     ((1u << OFP10_VERSION) | (1u << OFP12_VERSION) | (1u << OFP13_VERSION))
175
176 /* Bitmap of OpenFlow versions to enable by default (a subset of
177  * OFPUTIL_SUPPORTED_VERSIONS). */
178 #define OFPUTIL_DEFAULT_VERSIONS (1u << OFP10_VERSION)
179
180 enum ofputil_protocol ofputil_protocols_from_string(const char *s);
181
182 const char *ofputil_version_to_string(enum ofp_version ofp_version);
183 uint32_t ofputil_versions_from_string(const char *s);
184 uint32_t ofputil_versions_from_strings(char ** const s, size_t count);
185
186 bool ofputil_decode_hello(const struct ofp_header *,
187                           uint32_t *allowed_versions);
188 struct ofpbuf *ofputil_encode_hello(uint32_t version_bitmap);
189
190 struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
191                                            enum ofputil_protocol want,
192                                            enum ofputil_protocol *next);
193
194 /* nx_flow_format */
195 struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
196 enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
197 bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
198 const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
199
200 /* Work with ofp10_match. */
201 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
202 void ofputil_match_from_ofp10_match(const struct ofp10_match *,
203                                     struct match *);
204 void ofputil_normalize_match(struct match *);
205 void ofputil_normalize_match_quiet(struct match *);
206 void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
207
208 /* Work with ofp11_match. */
209 enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
210                                      uint16_t *padded_match_len);
211 enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
212                                            struct match *);
213 int ofputil_put_ofp11_match(struct ofpbuf *, const struct match *,
214                             enum ofputil_protocol);
215 void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
216 int ofputil_match_typical_len(enum ofputil_protocol);
217
218 /* dl_type translation between OpenFlow and 'struct flow' format. */
219 ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
220 ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
221
222 /* PACKET_IN. */
223 bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
224 int ofputil_packet_in_format_from_string(const char *);
225 const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
226 struct ofpbuf *ofputil_make_set_packet_in_format(enum ofp_version,
227                                                  enum nx_packet_in_format);
228
229 /* NXT_FLOW_MOD_TABLE_ID extension. */
230 struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
231
232 /* Protocol-independent flow_mod flags. */
233 enum ofputil_flow_mod_flags {
234     /* Flags that are maintained with a flow as part of its state.
235      *
236      * (OFPUTIL_FF_EMERG would be here too, if OVS supported it.) */
237     OFPUTIL_FF_SEND_FLOW_REM = 1 << 0, /* All versions. */
238     OFPUTIL_FF_NO_PKT_COUNTS = 1 << 1, /* OpenFlow 1.3+. */
239     OFPUTIL_FF_NO_BYT_COUNTS = 1 << 2, /* OpenFlow 1.3+. */
240 #define OFPUTIL_FF_STATE (OFPUTIL_FF_SEND_FLOW_REM      \
241                           | OFPUTIL_FF_NO_PKT_COUNTS    \
242                           | OFPUTIL_FF_NO_BYT_COUNTS)
243
244     /* Flags that affect flow_mod behavior but are not part of flow state. */
245     OFPUTIL_FF_CHECK_OVERLAP = 1 << 3, /* All versions. */
246     OFPUTIL_FF_EMERG         = 1 << 4, /* OpenFlow 1.0 only. */
247     OFPUTIL_FF_RESET_COUNTS  = 1 << 5, /* OpenFlow 1.2+. */
248 };
249
250 /* Protocol-independent flow_mod.
251  *
252  * The handling of cookies across multiple versions of OpenFlow is a bit
253  * confusing.  See DESIGN for the details. */
254 struct ofputil_flow_mod {
255     struct list list_node;    /* For queuing flow_mods. */
256
257     struct match match;
258     unsigned int priority;
259
260     /* Cookie matching.  The flow_mod affects only flows that have cookies that
261      * bitwise match 'cookie' bits in positions where 'cookie_mask has 1-bits.
262      *
263      * 'cookie_mask' should be zero for OFPFC_ADD flow_mods. */
264     ovs_be64 cookie;         /* Cookie bits to match. */
265     ovs_be64 cookie_mask;    /* 1-bit in each 'cookie' bit to match. */
266
267     /* Cookie changes.
268      *
269      * OFPFC_ADD uses 'new_cookie' as the new flow's cookie.  'new_cookie'
270      * should not be UINT64_MAX.
271      *
272      * OFPFC_MODIFY and OFPFC_MODIFY_STRICT have two cases:
273      *
274      *   - If one or more matching flows exist and 'modify_cookie' is true,
275      *     then the flow_mod changes the existing flows' cookies to
276      *     'new_cookie'.  'new_cookie' should not be UINT64_MAX.
277      *
278      *   - If no matching flow exists, 'new_cookie' is not UINT64_MAX, and
279      *     'cookie_mask' is 0, then the flow_mod adds a new flow with
280      *     'new_cookie' as its cookie.
281      */
282     ovs_be64 new_cookie;     /* New cookie to install or UINT64_MAX. */
283     bool modify_cookie;      /* Set cookie of existing flow to 'new_cookie'? */
284
285     uint8_t table_id;
286     uint16_t command;
287     uint16_t idle_timeout;
288     uint16_t hard_timeout;
289     uint32_t buffer_id;
290     ofp_port_t out_port;
291     uint32_t out_group;
292     enum ofputil_flow_mod_flags flags;
293     struct ofpact *ofpacts;     /* Series of "struct ofpact"s. */
294     size_t ofpacts_len;         /* Length of ofpacts, in bytes. */
295 };
296
297 enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
298                                     const struct ofp_header *,
299                                     enum ofputil_protocol,
300                                     struct ofpbuf *ofpacts,
301                                     ofp_port_t max_port,
302                                     uint8_t max_table);
303 struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
304                                        enum ofputil_protocol);
305
306 /* Flow stats or aggregate stats request, independent of protocol. */
307 struct ofputil_flow_stats_request {
308     bool aggregate;             /* Aggregate results? */
309     struct match match;
310     ovs_be64 cookie;
311     ovs_be64 cookie_mask;
312     ofp_port_t out_port;
313     uint32_t out_group;
314     uint8_t table_id;
315 };
316
317 enum ofperr ofputil_decode_flow_stats_request(
318     struct ofputil_flow_stats_request *, const struct ofp_header *);
319 struct ofpbuf *ofputil_encode_flow_stats_request(
320     const struct ofputil_flow_stats_request *, enum ofputil_protocol);
321
322 /* Flow stats reply, independent of protocol. */
323 struct ofputil_flow_stats {
324     struct match match;
325     ovs_be64 cookie;
326     uint8_t table_id;
327     uint16_t priority;
328     uint16_t idle_timeout;
329     uint16_t hard_timeout;
330     uint32_t duration_sec;
331     uint32_t duration_nsec;
332     int idle_age;               /* Seconds since last packet, -1 if unknown. */
333     int hard_age;               /* Seconds since last change, -1 if unknown. */
334     uint64_t packet_count;      /* Packet count, UINT64_MAX if unknown. */
335     uint64_t byte_count;        /* Byte count, UINT64_MAX if unknown. */
336     struct ofpact *ofpacts;
337     size_t ofpacts_len;
338     enum ofputil_flow_mod_flags flags;
339 };
340
341 int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
342                                     struct ofpbuf *msg,
343                                     bool flow_age_extension,
344                                     struct ofpbuf *ofpacts);
345 void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
346                                      struct list *replies);
347
348 /* Aggregate stats reply, independent of protocol. */
349 struct ofputil_aggregate_stats {
350     uint64_t packet_count;      /* Packet count, UINT64_MAX if unknown. */
351     uint64_t byte_count;        /* Byte count, UINT64_MAX if unknown. */
352     uint32_t flow_count;
353 };
354
355 struct ofpbuf *ofputil_encode_aggregate_stats_reply(
356     const struct ofputil_aggregate_stats *stats,
357     const struct ofp_header *request);
358 enum ofperr ofputil_decode_aggregate_stats_reply(
359     struct ofputil_aggregate_stats *,
360     const struct ofp_header *reply);
361
362 /* Flow removed message, independent of protocol. */
363 struct ofputil_flow_removed {
364     struct match match;
365     ovs_be64 cookie;
366     uint16_t priority;
367     uint8_t reason;             /* One of OFPRR_*. */
368     uint8_t table_id;           /* 255 if message didn't include table ID. */
369     uint32_t duration_sec;
370     uint32_t duration_nsec;
371     uint16_t idle_timeout;
372     uint16_t hard_timeout;
373     uint64_t packet_count;      /* Packet count, UINT64_MAX if unknown. */
374     uint64_t byte_count;        /* Byte count, UINT64_MAX if unknown. */
375 };
376
377 enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
378                                         const struct ofp_header *);
379 struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
380                                            enum ofputil_protocol);
381
382 /* Abstract packet-in message. */
383 struct ofputil_packet_in {
384     /* Packet data and metadata.
385      *
386      * To save bandwidth, in some cases a switch may send only the first
387      * several bytes of a packet, indicated by 'packet_len < total_len'.  When
388      * the full packet is included, 'packet_len == total_len'. */
389     const void *packet;
390     size_t packet_len;          /* Number of bytes in 'packet'. */
391     size_t total_len;           /* Size of packet, pre-truncation. */
392     struct flow_metadata fmd;
393
394     /* Identifies a buffer in the switch that contains the full packet, to
395      * allow the controller to reference it later without having to send the
396      * entire packet back to the switch.
397      *
398      * UINT32_MAX indicates that the packet is not buffered in the switch.  A
399      * switch should only use UINT32_MAX when it sends the entire packet. */
400     uint32_t buffer_id;
401
402     /* Reason that the packet-in is being sent. */
403     enum ofp_packet_in_reason reason;    /* One of OFPR_*. */
404
405     /* Information about the OpenFlow flow that triggered the packet-in.
406      *
407      * A packet-in triggered by a flow table miss has no associated flow.  In
408      * that case, 'cookie' is UINT64_MAX. */
409     uint8_t table_id;                    /* OpenFlow table ID. */
410     ovs_be64 cookie;                     /* Flow's cookie. */
411 };
412
413 enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
414                                      const struct ofp_header *);
415 struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
416                                         enum ofputil_protocol protocol,
417                                         enum nx_packet_in_format);
418
419 enum { OFPUTIL_PACKET_IN_REASON_BUFSIZE = INT_STRLEN(int) + 1 };
420 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason,
421                                                char *reasonbuf,
422                                                size_t bufsize);
423 bool ofputil_packet_in_reason_from_string(const char *,
424                                           enum ofp_packet_in_reason *);
425
426 /* Abstract packet-out message.
427  *
428  * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
429  * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
430 struct ofputil_packet_out {
431     const void *packet;         /* Packet data, if buffer_id == UINT32_MAX. */
432     size_t packet_len;          /* Length of packet data in bytes. */
433     uint32_t buffer_id;         /* Buffer id or UINT32_MAX if no buffer. */
434     ofp_port_t in_port;         /* Packet's input port. */
435     struct ofpact *ofpacts;     /* Actions. */
436     size_t ofpacts_len;         /* Size of ofpacts in bytes. */
437 };
438
439 enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
440                                       const struct ofp_header *,
441                                       struct ofpbuf *ofpacts);
442 struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
443                                          enum ofputil_protocol protocol);
444
445 enum ofputil_port_config {
446     /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
447     OFPUTIL_PC_PORT_DOWN    = 1 << 0, /* Port is administratively down. */
448     OFPUTIL_PC_NO_RECV      = 1 << 2, /* Drop all packets received by port. */
449     OFPUTIL_PC_NO_FWD       = 1 << 5, /* Drop packets forwarded to port. */
450     OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
451     /* OpenFlow 1.0 only. */
452     OFPUTIL_PC_NO_STP       = 1 << 1, /* No 802.1D spanning tree for port. */
453     OFPUTIL_PC_NO_RECV_STP  = 1 << 3, /* Drop received 802.1D STP packets. */
454     OFPUTIL_PC_NO_FLOOD     = 1 << 4, /* Do not include port when flooding. */
455     /* There are no OpenFlow 1.1-only bits. */
456 };
457
458 enum ofputil_port_state {
459     /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
460     OFPUTIL_PS_LINK_DOWN   = 1 << 0, /* No physical link present. */
461     /* OpenFlow 1.1 only. */
462     OFPUTIL_PS_BLOCKED     = 1 << 1, /* Port is blocked */
463     OFPUTIL_PS_LIVE        = 1 << 2, /* Live for Fast Failover Group. */
464     /* OpenFlow 1.0 only. */
465     OFPUTIL_PS_STP_LISTEN  = 0 << 8, /* Not learning or relaying frames. */
466     OFPUTIL_PS_STP_LEARN   = 1 << 8, /* Learning but not relaying frames. */
467     OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
468     OFPUTIL_PS_STP_BLOCK   = 3 << 8, /* Not part of spanning tree. */
469     OFPUTIL_PS_STP_MASK    = 3 << 8  /* Bit mask for OFPPS10_STP_* values. */
470 };
471
472 /* Abstract ofp10_phy_port or ofp11_port. */
473 struct ofputil_phy_port {
474     ofp_port_t port_no;
475     uint8_t hw_addr[OFP_ETH_ALEN];
476     char name[OFP_MAX_PORT_NAME_LEN];
477     enum ofputil_port_config config;
478     enum ofputil_port_state state;
479
480     /* NETDEV_F_* feature bitmasks. */
481     enum netdev_features curr;       /* Current features. */
482     enum netdev_features advertised; /* Features advertised by the port. */
483     enum netdev_features supported;  /* Features supported by the port. */
484     enum netdev_features peer;       /* Features advertised by peer. */
485
486     /* Speed. */
487     uint32_t curr_speed;        /* Current speed, in kbps. */
488     uint32_t max_speed;         /* Maximum supported speed, in kbps. */
489 };
490
491 enum ofputil_capabilities {
492     /* OpenFlow 1.0, 1.1, 1.2, and 1.3 share these capability values. */
493     OFPUTIL_C_FLOW_STATS     = 1 << 0,  /* Flow statistics. */
494     OFPUTIL_C_TABLE_STATS    = 1 << 1,  /* Table statistics. */
495     OFPUTIL_C_PORT_STATS     = 1 << 2,  /* Port statistics. */
496     OFPUTIL_C_IP_REASM       = 1 << 5,  /* Can reassemble IP fragments. */
497     OFPUTIL_C_QUEUE_STATS    = 1 << 6,  /* Queue statistics. */
498
499     /* OpenFlow 1.0 and 1.1 share this capability. */
500     OFPUTIL_C_ARP_MATCH_IP   = 1 << 7,  /* Match IP addresses in ARP pkts. */
501
502     /* OpenFlow 1.0 only. */
503     OFPUTIL_C_STP            = 1 << 3,  /* 802.1d spanning tree. */
504
505     /* OpenFlow 1.1, 1.2, and 1.3 share this capability. */
506     OFPUTIL_C_GROUP_STATS    = 1 << 4,  /* Group statistics. */
507
508     /* OpenFlow 1.2 and 1.3 share this capability */
509     OFPUTIL_C_PORT_BLOCKED   = 1 << 8,  /* Switch will block looping ports */
510 };
511
512 enum ofputil_action_bitmap {
513     OFPUTIL_A_OUTPUT         = 1 << 0,
514     OFPUTIL_A_SET_VLAN_VID   = 1 << 1,
515     OFPUTIL_A_SET_VLAN_PCP   = 1 << 2,
516     OFPUTIL_A_STRIP_VLAN     = 1 << 3,
517     OFPUTIL_A_SET_DL_SRC     = 1 << 4,
518     OFPUTIL_A_SET_DL_DST     = 1 << 5,
519     OFPUTIL_A_SET_NW_SRC     = 1 << 6,
520     OFPUTIL_A_SET_NW_DST     = 1 << 7,
521     OFPUTIL_A_SET_NW_ECN     = 1 << 8,
522     OFPUTIL_A_SET_NW_TOS     = 1 << 9,
523     OFPUTIL_A_SET_TP_SRC     = 1 << 10,
524     OFPUTIL_A_SET_TP_DST     = 1 << 11,
525     OFPUTIL_A_ENQUEUE        = 1 << 12,
526     OFPUTIL_A_COPY_TTL_OUT   = 1 << 13,
527     OFPUTIL_A_COPY_TTL_IN    = 1 << 14,
528     OFPUTIL_A_SET_MPLS_LABEL = 1 << 15,
529     OFPUTIL_A_SET_MPLS_TC    = 1 << 16,
530     OFPUTIL_A_SET_MPLS_TTL   = 1 << 17,
531     OFPUTIL_A_DEC_MPLS_TTL   = 1 << 18,
532     OFPUTIL_A_PUSH_VLAN      = 1 << 19,
533     OFPUTIL_A_POP_VLAN       = 1 << 20,
534     OFPUTIL_A_PUSH_MPLS      = 1 << 21,
535     OFPUTIL_A_POP_MPLS       = 1 << 22,
536     OFPUTIL_A_SET_QUEUE      = 1 << 23,
537     OFPUTIL_A_GROUP          = 1 << 24,
538     OFPUTIL_A_SET_NW_TTL     = 1 << 25,
539     OFPUTIL_A_DEC_NW_TTL     = 1 << 26,
540     OFPUTIL_A_SET_FIELD      = 1 << 27,
541 };
542
543 /* Abstract ofp_switch_features. */
544 struct ofputil_switch_features {
545     uint64_t datapath_id;       /* Datapath unique ID. */
546     uint32_t n_buffers;         /* Max packets buffered at once. */
547     uint8_t n_tables;           /* Number of tables supported by datapath. */
548     uint8_t auxiliary_id;       /* Identify auxiliary connections */
549     enum ofputil_capabilities capabilities;
550     enum ofputil_action_bitmap actions;
551 };
552
553 enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
554                                            struct ofputil_switch_features *,
555                                            struct ofpbuf *);
556
557 struct ofpbuf *ofputil_encode_switch_features(
558     const struct ofputil_switch_features *, enum ofputil_protocol,
559     ovs_be32 xid);
560 void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
561                                       struct ofpbuf *);
562 bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
563
564 /* phy_port helper functions. */
565 int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
566                           struct ofputil_phy_port *);
567 size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
568
569 /* Abstract ofp_port_status. */
570 struct ofputil_port_status {
571     enum ofp_port_reason reason;
572     struct ofputil_phy_port desc;
573 };
574
575 enum ofperr ofputil_decode_port_status(const struct ofp_header *,
576                                        struct ofputil_port_status *);
577 struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
578                                           enum ofputil_protocol);
579
580 /* Abstract ofp_port_mod. */
581 struct ofputil_port_mod {
582     ofp_port_t port_no;
583     uint8_t hw_addr[OFP_ETH_ALEN];
584     enum ofputil_port_config config;
585     enum ofputil_port_config mask;
586     enum netdev_features advertise;
587 };
588
589 enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
590                                     struct ofputil_port_mod *);
591 struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
592                                        enum ofputil_protocol);
593
594 /* Abstract ofp_table_mod. */
595 struct ofputil_table_mod {
596     uint8_t table_id;         /* ID of the table, 0xff indicates all tables. */
597     enum ofp_table_config config;
598 };
599
600 enum ofperr ofputil_decode_table_mod(const struct ofp_header *,
601                                     struct ofputil_table_mod *);
602 struct ofpbuf *ofputil_encode_table_mod(const struct ofputil_table_mod *,
603                                        enum ofputil_protocol);
604
605 /* Meter band configuration for all supported band types. */
606 struct ofputil_meter_band {
607     uint16_t type;
608     uint8_t prec_level;         /* Non-zero if type == OFPMBT_DSCP_REMARK. */
609     uint32_t rate;
610     uint32_t burst_size;
611 };
612
613 struct ofputil_meter_band_stats {
614     uint64_t packet_count;
615     uint64_t byte_count;
616 };
617
618 struct ofputil_meter_config {
619     uint32_t meter_id;
620     uint16_t flags;
621     uint16_t n_bands;
622     struct ofputil_meter_band *bands;
623 };
624
625 /* Abstract ofp_meter_mod. */
626 struct ofputil_meter_mod {
627     uint16_t command;
628     struct ofputil_meter_config meter;
629 };
630
631 struct ofputil_meter_stats {
632     uint32_t meter_id;
633     uint32_t flow_count;
634     uint64_t packet_in_count;
635     uint64_t byte_in_count;
636     uint32_t duration_sec;
637     uint32_t duration_nsec;
638     uint16_t n_bands;
639     struct ofputil_meter_band_stats *bands;
640 };
641
642 struct ofputil_meter_features {
643     uint32_t max_meters;        /* Maximum number of meters. */
644     uint32_t band_types;        /* Can support max 32 band types. */
645     uint32_t capabilities;      /* Supported flags. */
646     uint8_t  max_bands;
647     uint8_t  max_color;
648 };
649
650 enum ofperr ofputil_decode_meter_mod(const struct ofp_header *,
651                                      struct ofputil_meter_mod *,
652                                      struct ofpbuf *bands);
653 struct ofpbuf *ofputil_encode_meter_mod(enum ofp_version,
654                                         const struct ofputil_meter_mod *);
655
656 void ofputil_decode_meter_features(const struct ofp_header *,
657                                    struct ofputil_meter_features *);
658 struct ofpbuf *ofputil_encode_meter_features_reply(const struct
659                                                    ofputil_meter_features *,
660                                                    const struct ofp_header *
661                                                    request);
662 void ofputil_decode_meter_request(const struct ofp_header *,
663                                   uint32_t *meter_id);
664
665 void ofputil_append_meter_config(struct list *replies,
666                                  const struct ofputil_meter_config *);
667
668 void ofputil_append_meter_stats(struct list *replies,
669                                 const struct ofputil_meter_stats *);
670
671 enum ofputil_meter_request_type {
672     OFPUTIL_METER_FEATURES,
673     OFPUTIL_METER_CONFIG,
674     OFPUTIL_METER_STATS
675 };
676
677 struct ofpbuf *ofputil_encode_meter_request(enum ofp_version,
678                                             enum ofputil_meter_request_type,
679                                             uint32_t meter_id);
680
681 int ofputil_decode_meter_stats(struct ofpbuf *,
682                                struct ofputil_meter_stats *,
683                                struct ofpbuf *bands);
684
685 int ofputil_decode_meter_config(struct ofpbuf *,
686                                 struct ofputil_meter_config *,
687                                 struct ofpbuf *bands);
688
689 /* Type for meter_id in ofproto provider interface, UINT32_MAX if invalid. */
690 typedef struct { uint32_t uint32; } ofproto_meter_id;
691
692 /* Abstract ofp_role_request and reply. */
693 struct ofputil_role_request {
694     enum ofp12_controller_role role;
695     bool have_generation_id;
696     uint64_t generation_id;
697 };
698
699 struct ofputil_role_status {
700     enum ofp12_controller_role role;
701     enum ofp14_controller_role_reason reason;
702     uint64_t generation_id;
703 };
704
705 enum ofperr ofputil_decode_role_message(const struct ofp_header *,
706                                         struct ofputil_role_request *);
707 struct ofpbuf *ofputil_encode_role_reply(const struct ofp_header *,
708                                          const struct ofputil_role_request *);
709
710 struct ofpbuf *ofputil_encode_role_status(
711                                 const struct ofputil_role_status *status,
712                                 enum ofputil_protocol protocol);
713
714 enum ofperr ofputil_decode_role_status(const struct ofp_header *oh,
715                                        struct ofputil_role_status *rs);
716 /* Abstract table stats.
717  *
718  * For now we use ofp12_table_stats as a superset of the other protocol
719  * versions' table stats. */
720
721 struct ofpbuf *ofputil_encode_table_stats_reply(
722     const struct ofp12_table_stats[], int n,
723     const struct ofp_header *request);
724
725 /* Queue configuration request. */
726 struct ofpbuf *ofputil_encode_queue_get_config_request(enum ofp_version,
727                                                        ofp_port_t port);
728 enum ofperr ofputil_decode_queue_get_config_request(const struct ofp_header *,
729                                                     ofp_port_t *port);
730
731 /* Queue configuration reply. */
732 struct ofputil_queue_config {
733     uint32_t queue_id;
734
735     /* Each of these optional values is expressed in tenths of a percent.
736      * Values greater than 1000 indicate that the feature is disabled.
737      * UINT16_MAX indicates that the value is omitted. */
738     uint16_t min_rate;
739     uint16_t max_rate;
740 };
741
742 struct ofpbuf *ofputil_encode_queue_get_config_reply(
743     const struct ofp_header *request);
744 void ofputil_append_queue_get_config_reply(
745     struct ofpbuf *reply, const struct ofputil_queue_config *);
746
747 enum ofperr ofputil_decode_queue_get_config_reply(struct ofpbuf *reply,
748                                                   ofp_port_t *);
749 int ofputil_pull_queue_get_config_reply(struct ofpbuf *reply,
750                                         struct ofputil_queue_config *);
751
752
753 /* Abstract nx_flow_monitor_request. */
754 struct ofputil_flow_monitor_request {
755     uint32_t id;
756     enum nx_flow_monitor_flags flags;
757     ofp_port_t out_port;
758     uint8_t table_id;
759     struct match match;
760 };
761
762 int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
763                                         struct ofpbuf *msg);
764 void ofputil_append_flow_monitor_request(
765     const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
766
767 /* Abstract nx_flow_update. */
768 struct ofputil_flow_update {
769     enum nx_flow_update_event event;
770
771     /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
772     enum ofp_flow_removed_reason reason;
773     uint16_t idle_timeout;
774     uint16_t hard_timeout;
775     uint8_t table_id;
776     uint16_t priority;
777     ovs_be64 cookie;
778     struct match *match;
779     struct ofpact *ofpacts;
780     size_t ofpacts_len;
781
782     /* Used only for NXFME_ABBREV. */
783     ovs_be32 xid;
784 };
785
786 int ofputil_decode_flow_update(struct ofputil_flow_update *,
787                                struct ofpbuf *msg, struct ofpbuf *ofpacts);
788 void ofputil_start_flow_update(struct list *replies);
789 void ofputil_append_flow_update(const struct ofputil_flow_update *,
790                                 struct list *replies);
791
792 /* Abstract nx_flow_monitor_cancel. */
793 uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
794 struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
795
796 /* Encoding OpenFlow stats messages. */
797 void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
798                                           const struct ofputil_phy_port *pp,
799                                           struct list *replies);
800
801 /* Encoding simple OpenFlow messages. */
802 struct ofpbuf *make_echo_request(enum ofp_version);
803 struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
804
805 struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
806
807 const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
808 bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
809
810 \f
811 /* Actions. */
812
813 /* The type of an action.
814  *
815  * For each implemented OFPAT10_* and NXAST_* action type, there is a
816  * corresponding constant prefixed with OFPUTIL_, e.g.:
817  *
818  * OFPUTIL_OFPAT10_OUTPUT
819  * OFPUTIL_OFPAT10_SET_VLAN_VID
820  * OFPUTIL_OFPAT10_SET_VLAN_PCP
821  * OFPUTIL_OFPAT10_STRIP_VLAN
822  * OFPUTIL_OFPAT10_SET_DL_SRC
823  * OFPUTIL_OFPAT10_SET_DL_DST
824  * OFPUTIL_OFPAT10_SET_NW_SRC
825  * OFPUTIL_OFPAT10_SET_NW_DST
826  * OFPUTIL_OFPAT10_SET_NW_TOS
827  * OFPUTIL_OFPAT10_SET_TP_SRC
828  * OFPUTIL_OFPAT10_SET_TP_DST
829  * OFPUTIL_OFPAT10_ENQUEUE
830  * OFPUTIL_NXAST_RESUBMIT
831  * OFPUTIL_NXAST_SET_TUNNEL
832  * OFPUTIL_NXAST_SET_METADATA
833  * OFPUTIL_NXAST_SET_QUEUE
834  * OFPUTIL_NXAST_POP_QUEUE
835  * OFPUTIL_NXAST_REG_MOVE
836  * OFPUTIL_NXAST_REG_LOAD
837  * OFPUTIL_NXAST_NOTE
838  * OFPUTIL_NXAST_SET_TUNNEL64
839  * OFPUTIL_NXAST_MULTIPATH
840  * OFPUTIL_NXAST_BUNDLE
841  * OFPUTIL_NXAST_BUNDLE_LOAD
842  * OFPUTIL_NXAST_RESUBMIT_TABLE
843  * OFPUTIL_NXAST_OUTPUT_REG
844  * OFPUTIL_NXAST_LEARN
845  * OFPUTIL_NXAST_DEC_TTL
846  * OFPUTIL_NXAST_FIN_TIMEOUT
847  *
848  * (The above list helps developers who want to "grep" for these definitions.)
849  */
850 enum OVS_PACKED_ENUM ofputil_action_code {
851     OFPUTIL_ACTION_INVALID,
852 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)             OFPUTIL_##ENUM,
853 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
854 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)   OFPUTIL_##ENUM,
855 #include "ofp-util.def"
856 };
857
858 /* The number of values of "enum ofputil_action_code". */
859 enum {
860 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)             + 1
861 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
862 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)   + 1
863     OFPUTIL_N_ACTIONS = 1
864 #include "ofp-util.def"
865 };
866
867 int ofputil_action_code_from_name(const char *);
868 const char * ofputil_action_name_from_code(enum ofputil_action_code code);
869
870 void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
871
872 /* For each OpenFlow action <ENUM> that has a corresponding action structure
873  * struct <STRUCT>, this defines two functions:
874  *
875  *   void ofputil_init_<ENUM>(struct <STRUCT> *action);
876  *
877  *     Initializes the parts of 'action' that identify it as having type <ENUM>
878  *     and length 'sizeof *action' and zeros the rest.  For actions that have
879  *     variable length, the length used and cleared is that of struct <STRUCT>.
880  *
881  *  struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
882  *
883  *     Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
884  *     initializes it with ofputil_init_<ENUM>(), and returns it.
885  */
886 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)              \
887     void ofputil_init_##ENUM(struct STRUCT *);          \
888     struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
889 #define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)  \
890     void ofputil_init_##ENUM(struct STRUCT *);          \
891     struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
892 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)    \
893     void ofputil_init_##ENUM(struct STRUCT *);          \
894     struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
895 #include "ofp-util.def"
896
897 #define OFP_ACTION_ALIGN 8      /* Alignment of ofp_actions. */
898
899 bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
900
901 enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
902                                  union ofp_action **, size_t *);
903
904 bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
905                            const union ofp_action *b, size_t n_b);
906 union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
907
908 /* Handy utility for parsing flows and actions. */
909 bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
910
911 struct ofputil_port_stats {
912     ofp_port_t port_no;
913     struct netdev_stats stats;
914     uint32_t duration_sec;      /* UINT32_MAX if unknown. */
915     uint32_t duration_nsec;
916 };
917
918 struct ofpbuf *ofputil_encode_dump_ports_request(enum ofp_version ofp_version,
919                                                  ofp_port_t port);
920 void ofputil_append_port_stat(struct list *replies,
921                               const struct ofputil_port_stats *ops);
922 size_t ofputil_count_port_stats(const struct ofp_header *);
923 int ofputil_decode_port_stats(struct ofputil_port_stats *, struct ofpbuf *msg);
924 enum ofperr ofputil_decode_port_stats_request(const struct ofp_header *request,
925                                               ofp_port_t *ofp10_port);
926
927 struct ofputil_queue_stats_request {
928     ofp_port_t port_no;           /* OFPP_ANY means "all ports". */
929     uint32_t queue_id;
930 };
931
932 enum ofperr
933 ofputil_decode_queue_stats_request(const struct ofp_header *request,
934                                    struct ofputil_queue_stats_request *oqsr);
935 struct ofpbuf *
936 ofputil_encode_queue_stats_request(enum ofp_version ofp_version,
937                                    const struct ofputil_queue_stats_request *oqsr);
938
939 struct ofputil_queue_stats {
940     ofp_port_t port_no;
941     uint32_t queue_id;
942
943     /* Values of unsupported statistics are set to all-1-bits (UINT64_MAX). */
944     uint64_t tx_bytes;
945     uint64_t tx_packets;
946     uint64_t tx_errors;
947
948     /* UINT32_MAX if unknown. */
949     uint32_t duration_sec;
950     uint32_t duration_nsec;
951 };
952
953 size_t ofputil_count_queue_stats(const struct ofp_header *);
954 int ofputil_decode_queue_stats(struct ofputil_queue_stats *qs, struct ofpbuf *msg);
955 void ofputil_append_queue_stat(struct list *replies,
956                                const struct ofputil_queue_stats *oqs);
957
958 /* Bucket for use in groups. */
959 struct ofputil_bucket {
960     struct list list_node;
961     uint16_t weight;            /* Relative weight, for "select" groups. */
962     ofp_port_t watch_port;      /* Port whose state affects whether this bucket
963                                  * is live. Only required for fast failover
964                                  * groups. */
965     uint32_t watch_group;       /* Group whose state affects whether this
966                                  * bucket is live. Only required for fast
967                                  * failover groups. */
968     struct ofpact *ofpacts;     /* Series of "struct ofpact"s. */
969     size_t ofpacts_len;         /* Length of ofpacts, in bytes. */
970 };
971
972 /* Protocol-independent group_mod. */
973 struct ofputil_group_mod {
974     uint16_t command;             /* One of OFPGC11_*. */
975     uint8_t type;                 /* One of OFPGT11_*. */
976     uint32_t group_id;            /* Group identifier. */
977     struct list buckets;          /* Contains "struct ofputil_bucket"s. */
978 };
979
980 struct bucket_counter {
981     uint64_t packet_count;   /* Number of packets processed by bucket. */
982     uint64_t byte_count;     /* Number of bytes processed by bucket. */
983 };
984
985 /* Group stats reply, independent of protocol. */
986 struct ofputil_group_stats {
987     uint32_t group_id;    /* Group identifier. */
988     uint32_t ref_count;
989     uint64_t packet_count;      /* Packet count, UINT64_MAX if unknown. */
990     uint64_t byte_count;        /* Byte count, UINT64_MAX if unknown. */
991     uint32_t duration_sec;      /* UINT32_MAX if unknown. */
992     uint32_t duration_nsec;
993     uint32_t n_buckets;
994     struct bucket_counter *bucket_stats;
995 };
996
997 /* Group features reply, independent of protocol.
998  *
999  * Only OF1.2 and later support group features replies. */
1000 struct ofputil_group_features {
1001     uint32_t  types;           /* Bitmap of OFPGT_* values supported. */
1002     uint32_t  capabilities;    /* Bitmap of OFPGFC12_* capability supported. */
1003     uint32_t  max_groups[4];   /* Maximum number of groups for each type. */
1004
1005     /* Bitmaps of OFPAT_* that are supported.  OF1.2+ actions only. */
1006     uint32_t  actions[4];
1007 };
1008
1009 /* Group desc reply, independent of protocol. */
1010 struct ofputil_group_desc {
1011     uint8_t type;               /* One of OFPGT_*. */
1012     uint32_t group_id;          /* Group identifier. */
1013     struct list buckets;        /* Contains "struct ofputil_bucket"s. */
1014 };
1015
1016 void ofputil_bucket_list_destroy(struct list *buckets);
1017
1018 static inline bool
1019 ofputil_bucket_has_liveness(const struct ofputil_bucket *bucket)
1020 {
1021     return (bucket->watch_port != OFPP_ANY ||
1022             bucket->watch_group != OFPG_ANY);
1023 }
1024
1025 struct ofpbuf *ofputil_encode_group_stats_request(enum ofp_version,
1026                                                   uint32_t group_id);
1027 enum ofperr ofputil_decode_group_stats_request(
1028     const struct ofp_header *request, uint32_t *group_id);
1029 void ofputil_append_group_stats(struct list *replies,
1030                                 const struct ofputil_group_stats *);
1031 struct ofpbuf *ofputil_encode_group_features_request(enum ofp_version);
1032 struct ofpbuf *ofputil_encode_group_features_reply(
1033     const struct ofputil_group_features *, const struct ofp_header *request);
1034 void ofputil_decode_group_features_reply(const struct ofp_header *,
1035                                          struct ofputil_group_features *);
1036 struct ofpbuf *ofputil_encode_group_mod(enum ofp_version ofp_version,
1037                                         const struct ofputil_group_mod *gm);
1038
1039 enum ofperr ofputil_decode_group_mod(const struct ofp_header *,
1040                                      struct ofputil_group_mod *);
1041
1042 int ofputil_decode_group_stats_reply(struct ofpbuf *,
1043                                      struct ofputil_group_stats *);
1044
1045 int ofputil_decode_group_desc_reply(struct ofputil_group_desc *,
1046                                     struct ofpbuf *, enum ofp_version);
1047
1048 void ofputil_append_group_desc_reply(const struct ofputil_group_desc *,
1049                                      struct list *buckets,
1050                                      struct list *replies);
1051 struct ofpbuf *ofputil_encode_group_desc_request(enum ofp_version);
1052
1053 #endif /* ofp-util.h */