ofp-util: Allow decoding of Open Flow 1.1 & 1.2 Table Statistics Request Messages
[sliver-openvswitch.git] / lib / ofp-util.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 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_UTIL_H
18 #define OFP_UTIL_H 1
19
20 #include <assert.h>
21 #include <stdbool.h>
22 #include <stddef.h>
23 #include <stdint.h>
24 #include "classifier.h"
25 #include "compiler.h"
26 #include "flow.h"
27 #include "match.h"
28 #include "netdev.h"
29 #include "openflow/nicira-ext.h"
30 #include "openvswitch/types.h"
31
32 struct ofpbuf;
33
34 /* Port numbers. */
35 enum ofperr ofputil_port_from_ofp11(ovs_be32 ofp11_port, uint16_t *ofp10_port);
36 ovs_be32 ofputil_port_to_ofp11(uint16_t ofp10_port);
37
38 enum ofperr ofputil_check_output_port(uint16_t ofp_port, int max_ports);
39 bool ofputil_port_from_string(const char *, uint16_t *port);
40 void ofputil_format_port(uint16_t port, struct ds *);
41
42 /* Converting OFPFW10_NW_SRC_MASK and OFPFW10_NW_DST_MASK wildcard bit counts
43  * to and from IP bitmasks. */
44 ovs_be32 ofputil_wcbits_to_netmask(int wcbits);
45 int ofputil_netmask_to_wcbits(ovs_be32 netmask);
46
47 /* Protocols.
48  *
49  * These are arranged from most portable to least portable, or alternatively
50  * from least powerful to most powerful.  Formats earlier on the list are more
51  * likely to be understood for the purpose of making requests, but formats
52  * later on the list are more likely to accurately describe a flow within a
53  * switch.
54  *
55  * On any given OpenFlow connection, a single protocol is in effect at any
56  * given time.  These values use separate bits only because that makes it easy
57  * to test whether a particular protocol is within a given set of protocols and
58  * to implement set union and intersection.
59  */
60 enum ofputil_protocol {
61     /* OpenFlow 1.0-based protocols. */
62     OFPUTIL_P_OF10     = 1 << 0, /* OpenFlow 1.0 flow format. */
63     OFPUTIL_P_OF10_TID = 1 << 1, /* OF1.0 + flow_mod_table_id extension. */
64 #define OFPUTIL_P_OF10_ANY (OFPUTIL_P_OF10 | OFPUTIL_P_OF10_TID)
65
66     /* OpenFlow 1.0 with NXM-based flow formats. */
67     OFPUTIL_P_NXM      = 1 << 2, /* Nicira extended match. */
68     OFPUTIL_P_NXM_TID  = 1 << 3, /* NXM + flow_mod_table_id extension. */
69 #define OFPUTIL_P_NXM_ANY (OFPUTIL_P_NXM | OFPUTIL_P_NXM_TID)
70
71     /* OpenFlow 1.2 */
72     OFPUTIL_P_OF12      = 1 << 4, /* OpenFlow 1.2 flow format. */
73
74     /* All protocols. */
75 #define OFPUTIL_P_ANY (OFPUTIL_P_OF10_ANY | OFPUTIL_P_NXM_ANY)
76
77     /* Protocols in which a specific table may be specified in flow_mods. */
78 #define OFPUTIL_P_TID (OFPUTIL_P_OF10_TID | OFPUTIL_P_NXM_TID)
79 };
80
81 /* Protocols to use for flow dumps, from most to least preferred. */
82 extern enum ofputil_protocol ofputil_flow_dump_protocols[];
83 extern size_t ofputil_n_flow_dump_protocols;
84
85 enum ofputil_protocol
86 ofputil_protocol_from_ofp_version(enum ofp_version version);
87 enum ofp_version  ofputil_protocol_to_ofp_version(enum ofputil_protocol);
88
89 bool ofputil_protocol_is_valid(enum ofputil_protocol);
90 enum ofputil_protocol ofputil_protocol_set_tid(enum ofputil_protocol,
91                                                bool enable);
92 enum ofputil_protocol ofputil_protocol_to_base(enum ofputil_protocol);
93 enum ofputil_protocol ofputil_protocol_set_base(
94     enum ofputil_protocol cur, enum ofputil_protocol new_base);
95
96 const char *ofputil_protocol_to_string(enum ofputil_protocol);
97 char *ofputil_protocols_to_string(enum ofputil_protocol);
98 enum ofputil_protocol ofputil_protocols_from_string(const char *);
99 enum ofputil_protocol ofputil_usable_protocols(const struct match *);
100
101 struct ofpbuf *ofputil_encode_set_protocol(enum ofputil_protocol current,
102                                            enum ofputil_protocol want,
103                                            enum ofputil_protocol *next);
104
105 /* nx_flow_format */
106 struct ofpbuf *ofputil_encode_nx_set_flow_format(enum nx_flow_format);
107 enum ofputil_protocol ofputil_nx_flow_format_to_protocol(enum nx_flow_format);
108 bool ofputil_nx_flow_format_is_valid(enum nx_flow_format);
109 const char *ofputil_nx_flow_format_to_string(enum nx_flow_format);
110
111 /* Work with ofp10_match. */
112 void ofputil_wildcard_from_ofpfw10(uint32_t ofpfw, struct flow_wildcards *);
113 void ofputil_match_from_ofp10_match(const struct ofp10_match *,
114                                     struct match *);
115 void ofputil_normalize_match(struct match *);
116 void ofputil_normalize_match_quiet(struct match *);
117 void ofputil_match_to_ofp10_match(const struct match *, struct ofp10_match *);
118
119 /* Work with ofp11_match. */
120 enum ofperr ofputil_pull_ofp11_match(struct ofpbuf *, struct match *,
121                                      uint16_t *padded_match_len);
122 enum ofperr ofputil_match_from_ofp11_match(const struct ofp11_match *,
123                                            struct match *);
124 void ofputil_match_to_ofp11_match(const struct match *, struct ofp11_match *);
125
126 /* dl_type translation between OpenFlow and 'struct flow' format. */
127 ovs_be16 ofputil_dl_type_to_openflow(ovs_be16 flow_dl_type);
128 ovs_be16 ofputil_dl_type_from_openflow(ovs_be16 ofp_dl_type);
129
130 /* PACKET_IN. */
131 bool ofputil_packet_in_format_is_valid(enum nx_packet_in_format);
132 int ofputil_packet_in_format_from_string(const char *);
133 const char *ofputil_packet_in_format_to_string(enum nx_packet_in_format);
134 struct ofpbuf *ofputil_make_set_packet_in_format(enum nx_packet_in_format);
135
136 /* NXT_FLOW_MOD_TABLE_ID extension. */
137 struct ofpbuf *ofputil_make_flow_mod_table_id(bool flow_mod_table_id);
138
139 /* Protocol-independent flow_mod.
140  *
141  * The handling of cookies across multiple versions of OpenFlow is a bit
142  * confusing.  A full description of Open vSwitch's cookie handling is
143  * in the DESIGN file.  The following table shows the expected values of
144  * the cookie-related fields for the different flow_mod commands in
145  * OpenFlow 1.0 ("OF10") and NXM.  "<used>" and "-" indicate a value
146  * that may be populated and an ignored field, respectively.
147  *
148  *               cookie  cookie_mask  new_cookie
149  *               ======  ===========  ==========
150  * OF10 Add        -          0         <used>
151  * OF10 Modify     -          0         <used>
152  * OF10 Delete     -          0           -
153  * NXM Add         -          0         <used>
154  * NXM Modify    <used>     <used>      <used>
155  * NXM Delete    <used>     <used>        -
156  */
157 struct ofputil_flow_mod {
158     struct match match;
159     unsigned int priority;
160     ovs_be64 cookie;         /* Cookie bits to match. */
161     ovs_be64 cookie_mask;    /* 1-bit in each 'cookie' bit to match. */
162     ovs_be64 new_cookie;     /* New cookie to install or -1. */
163     uint8_t table_id;
164     uint16_t command;
165     uint16_t idle_timeout;
166     uint16_t hard_timeout;
167     uint32_t buffer_id;
168     uint16_t out_port;
169     uint16_t flags;
170     struct ofpact *ofpacts;     /* Series of "struct ofpact"s. */
171     size_t ofpacts_len;         /* Length of ofpacts, in bytes. */
172 };
173
174 enum ofperr ofputil_decode_flow_mod(struct ofputil_flow_mod *,
175                                     const struct ofp_header *,
176                                     enum ofputil_protocol,
177                                     struct ofpbuf *ofpacts);
178 struct ofpbuf *ofputil_encode_flow_mod(const struct ofputil_flow_mod *,
179                                        enum ofputil_protocol);
180
181 enum ofputil_protocol ofputil_flow_mod_usable_protocols(
182     const struct ofputil_flow_mod *fms, size_t n_fms);
183
184 /* Flow stats or aggregate stats request, independent of protocol. */
185 struct ofputil_flow_stats_request {
186     bool aggregate;             /* Aggregate results? */
187     struct match match;
188     ovs_be64 cookie;
189     ovs_be64 cookie_mask;
190     uint16_t out_port;
191     uint8_t table_id;
192 };
193
194 enum ofperr ofputil_decode_flow_stats_request(
195     struct ofputil_flow_stats_request *, const struct ofp_header *);
196 struct ofpbuf *ofputil_encode_flow_stats_request(
197     const struct ofputil_flow_stats_request *, enum ofputil_protocol);
198 enum ofputil_protocol ofputil_flow_stats_request_usable_protocols(
199     const struct ofputil_flow_stats_request *);
200
201 /* Flow stats reply, independent of protocol. */
202 struct ofputil_flow_stats {
203     struct match match;
204     ovs_be64 cookie;
205     uint8_t table_id;
206     uint32_t duration_sec;
207     uint32_t duration_nsec;
208     uint16_t priority;
209     uint16_t idle_timeout;
210     uint16_t hard_timeout;
211     int idle_age;               /* Seconds since last packet, -1 if unknown. */
212     int hard_age;               /* Seconds since last change, -1 if unknown. */
213     uint64_t packet_count;      /* Packet count, UINT64_MAX if unknown. */
214     uint64_t byte_count;        /* Byte count, UINT64_MAX if unknown. */
215     struct ofpact *ofpacts;
216     size_t ofpacts_len;
217 };
218
219 int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
220                                     struct ofpbuf *msg,
221                                     bool flow_age_extension,
222                                     struct ofpbuf *ofpacts);
223 void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
224                                      struct list *replies);
225
226 /* Aggregate stats reply, independent of protocol. */
227 struct ofputil_aggregate_stats {
228     uint64_t packet_count;      /* Packet count, UINT64_MAX if unknown. */
229     uint64_t byte_count;        /* Byte count, UINT64_MAX if unknown. */
230     uint32_t flow_count;
231 };
232
233 struct ofpbuf *ofputil_encode_aggregate_stats_reply(
234     const struct ofputil_aggregate_stats *stats,
235     const struct ofp_header *request);
236 enum ofperr ofputil_decode_aggregate_stats_reply(
237     struct ofputil_aggregate_stats *,
238     const struct ofp_header *reply);
239
240 /* Flow removed message, independent of protocol. */
241 struct ofputil_flow_removed {
242     struct match match;
243     uint16_t priority;
244     ovs_be64 cookie;
245     uint8_t reason;             /* One of OFPRR_*. */
246     uint32_t duration_sec;
247     uint32_t duration_nsec;
248     uint16_t idle_timeout;
249     uint16_t hard_timeout;
250     uint64_t packet_count;      /* Packet count, UINT64_MAX if unknown. */
251     uint64_t byte_count;        /* Byte count, UINT64_MAX if unknown. */
252 };
253
254 enum ofperr ofputil_decode_flow_removed(struct ofputil_flow_removed *,
255                                         const struct ofp_header *);
256 struct ofpbuf *ofputil_encode_flow_removed(const struct ofputil_flow_removed *,
257                                            enum ofputil_protocol);
258
259 /* Abstract packet-in message. */
260 struct ofputil_packet_in {
261     const void *packet;
262     size_t packet_len;
263
264     enum ofp_packet_in_reason reason;    /* One of OFPR_*. */
265     uint16_t controller_id;              /* Controller ID to send to. */
266     uint8_t table_id;
267     ovs_be64 cookie;
268
269     uint32_t buffer_id;
270     int send_len;
271     uint16_t total_len;         /* Full length of frame. */
272
273     struct flow_metadata fmd;   /* Metadata at creation time. */
274 };
275
276 enum ofperr ofputil_decode_packet_in(struct ofputil_packet_in *,
277                                      const struct ofp_header *);
278 struct ofpbuf *ofputil_encode_packet_in(const struct ofputil_packet_in *,
279                                         enum ofputil_protocol protocol,
280                                         enum nx_packet_in_format);
281
282 const char *ofputil_packet_in_reason_to_string(enum ofp_packet_in_reason);
283 bool ofputil_packet_in_reason_from_string(const char *,
284                                           enum ofp_packet_in_reason *);
285
286 /* Abstract packet-out message.
287  *
288  * ofputil_decode_packet_out() will ensure that 'in_port' is a physical port
289  * (OFPP_MAX or less) or one of OFPP_LOCAL, OFPP_NONE, or OFPP_CONTROLLER. */
290 struct ofputil_packet_out {
291     const void *packet;         /* Packet data, if buffer_id == UINT32_MAX. */
292     size_t packet_len;          /* Length of packet data in bytes. */
293     uint32_t buffer_id;         /* Buffer id or UINT32_MAX if no buffer. */
294     uint16_t in_port;           /* Packet's input port. */
295     struct ofpact *ofpacts;     /* Actions. */
296     size_t ofpacts_len;         /* Size of ofpacts in bytes. */
297 };
298
299 enum ofperr ofputil_decode_packet_out(struct ofputil_packet_out *,
300                                       const struct ofp_header *,
301                                       struct ofpbuf *ofpacts);
302 struct ofpbuf *ofputil_encode_packet_out(const struct ofputil_packet_out *,
303                                          enum ofputil_protocol protocol);
304
305 enum ofputil_port_config {
306     /* OpenFlow 1.0 and 1.1 share these values for these port config bits. */
307     OFPUTIL_PC_PORT_DOWN    = 1 << 0, /* Port is administratively down. */
308     OFPUTIL_PC_NO_RECV      = 1 << 2, /* Drop all packets received by port. */
309     OFPUTIL_PC_NO_FWD       = 1 << 5, /* Drop packets forwarded to port. */
310     OFPUTIL_PC_NO_PACKET_IN = 1 << 6, /* No send packet-in msgs for port. */
311     /* OpenFlow 1.0 only. */
312     OFPUTIL_PC_NO_STP       = 1 << 1, /* No 802.1D spanning tree for port. */
313     OFPUTIL_PC_NO_RECV_STP  = 1 << 3, /* Drop received 802.1D STP packets. */
314     OFPUTIL_PC_NO_FLOOD     = 1 << 4, /* Do not include port when flooding. */
315     /* There are no OpenFlow 1.1-only bits. */
316 };
317
318 enum ofputil_port_state {
319     /* OpenFlow 1.0 and 1.1 share this values for these port state bits. */
320     OFPUTIL_PS_LINK_DOWN   = 1 << 0, /* No physical link present. */
321     /* OpenFlow 1.1 only. */
322     OFPUTIL_PS_BLOCKED     = 1 << 1, /* Port is blocked */
323     OFPUTIL_PS_LIVE        = 1 << 2, /* Live for Fast Failover Group. */
324     /* OpenFlow 1.0 only. */
325     OFPUTIL_PS_STP_LISTEN  = 0 << 8, /* Not learning or relaying frames. */
326     OFPUTIL_PS_STP_LEARN   = 1 << 8, /* Learning but not relaying frames. */
327     OFPUTIL_PS_STP_FORWARD = 2 << 8, /* Learning and relaying frames. */
328     OFPUTIL_PS_STP_BLOCK   = 3 << 8, /* Not part of spanning tree. */
329     OFPUTIL_PS_STP_MASK    = 3 << 8  /* Bit mask for OFPPS10_STP_* values. */
330 };
331
332 /* Abstract ofp10_phy_port or ofp11_port. */
333 struct ofputil_phy_port {
334     uint16_t port_no;
335     uint8_t hw_addr[OFP_ETH_ALEN];
336     char name[OFP_MAX_PORT_NAME_LEN];
337     enum ofputil_port_config config;
338     enum ofputil_port_state state;
339
340     /* NETDEV_F_* feature bitmasks. */
341     enum netdev_features curr;       /* Current features. */
342     enum netdev_features advertised; /* Features advertised by the port. */
343     enum netdev_features supported;  /* Features supported by the port. */
344     enum netdev_features peer;       /* Features advertised by peer. */
345
346     /* Speed. */
347     uint32_t curr_speed;        /* Current speed, in kbps. */
348     uint32_t max_speed;         /* Maximum supported speed, in kbps. */
349 };
350
351 enum ofputil_capabilities {
352     /* OpenFlow 1.0, 1.1 and 1.2 share these values for these capabilities. */
353     OFPUTIL_C_FLOW_STATS     = 1 << 0,  /* Flow statistics. */
354     OFPUTIL_C_TABLE_STATS    = 1 << 1,  /* Table statistics. */
355     OFPUTIL_C_PORT_STATS     = 1 << 2,  /* Port statistics. */
356     OFPUTIL_C_IP_REASM       = 1 << 5,  /* Can reassemble IP fragments. */
357     OFPUTIL_C_QUEUE_STATS    = 1 << 6,  /* Queue statistics. */
358
359     /* OpenFlow 1.0 and 1.1 share this capability. */
360     OFPUTIL_C_ARP_MATCH_IP   = 1 << 7,  /* Match IP addresses in ARP pkts. */
361
362     /* OpenFlow 1.0 only. */
363     OFPUTIL_C_STP            = 1 << 3,  /* 802.1d spanning tree. */
364
365     /* OpenFlow 1.1 and 1.2 share this capability. */
366     OFPUTIL_C_GROUP_STATS    = 1 << 4,  /* Group statistics. */
367
368     /* OpenFlow 1.2 only */
369     OFPUTIL_C_PORT_BLOCKED   = 1 << 8,  /* Switch will block looping ports */
370 };
371
372 enum ofputil_action_bitmap {
373     OFPUTIL_A_OUTPUT         = 1 << 0,
374     OFPUTIL_A_SET_VLAN_VID   = 1 << 1,
375     OFPUTIL_A_SET_VLAN_PCP   = 1 << 2,
376     OFPUTIL_A_STRIP_VLAN     = 1 << 3,
377     OFPUTIL_A_SET_DL_SRC     = 1 << 4,
378     OFPUTIL_A_SET_DL_DST     = 1 << 5,
379     OFPUTIL_A_SET_NW_SRC     = 1 << 6,
380     OFPUTIL_A_SET_NW_DST     = 1 << 7,
381     OFPUTIL_A_SET_NW_ECN     = 1 << 8,
382     OFPUTIL_A_SET_NW_TOS     = 1 << 9,
383     OFPUTIL_A_SET_TP_SRC     = 1 << 10,
384     OFPUTIL_A_SET_TP_DST     = 1 << 11,
385     OFPUTIL_A_ENQUEUE        = 1 << 12,
386     OFPUTIL_A_COPY_TTL_OUT   = 1 << 13,
387     OFPUTIL_A_COPY_TTL_IN    = 1 << 14,
388     OFPUTIL_A_SET_MPLS_LABEL = 1 << 15,
389     OFPUTIL_A_SET_MPLS_TC    = 1 << 16,
390     OFPUTIL_A_SET_MPLS_TTL   = 1 << 17,
391     OFPUTIL_A_DEC_MPLS_TTL   = 1 << 18,
392     OFPUTIL_A_PUSH_VLAN      = 1 << 19,
393     OFPUTIL_A_POP_VLAN       = 1 << 20,
394     OFPUTIL_A_PUSH_MPLS      = 1 << 21,
395     OFPUTIL_A_POP_MPLS       = 1 << 22,
396     OFPUTIL_A_SET_QUEUE      = 1 << 23,
397     OFPUTIL_A_GROUP          = 1 << 24,
398     OFPUTIL_A_SET_NW_TTL     = 1 << 25,
399     OFPUTIL_A_DEC_NW_TTL     = 1 << 26,
400     OFPUTIL_A_SET_FIELD      = 1 << 27,
401 };
402
403 /* Abstract ofp_switch_features. */
404 struct ofputil_switch_features {
405     uint64_t datapath_id;       /* Datapath unique ID. */
406     uint32_t n_buffers;         /* Max packets buffered at once. */
407     uint8_t n_tables;           /* Number of tables supported by datapath. */
408     enum ofputil_capabilities capabilities;
409     enum ofputil_action_bitmap actions;
410 };
411
412 enum ofperr ofputil_decode_switch_features(const struct ofp_header *,
413                                            struct ofputil_switch_features *,
414                                            struct ofpbuf *);
415
416 struct ofpbuf *ofputil_encode_switch_features(
417     const struct ofputil_switch_features *, enum ofputil_protocol,
418     ovs_be32 xid);
419 void ofputil_put_switch_features_port(const struct ofputil_phy_port *,
420                                       struct ofpbuf *);
421 bool ofputil_switch_features_ports_trunc(struct ofpbuf *b);
422
423 /* phy_port helper functions. */
424 int ofputil_pull_phy_port(enum ofp_version ofp_version, struct ofpbuf *,
425                           struct ofputil_phy_port *);
426 size_t ofputil_count_phy_ports(uint8_t ofp_version, struct ofpbuf *);
427
428 /* Abstract ofp_port_status. */
429 struct ofputil_port_status {
430     enum ofp_port_reason reason;
431     struct ofputil_phy_port desc;
432 };
433
434 enum ofperr ofputil_decode_port_status(const struct ofp_header *,
435                                        struct ofputil_port_status *);
436 struct ofpbuf *ofputil_encode_port_status(const struct ofputil_port_status *,
437                                           enum ofputil_protocol);
438
439 /* Abstract ofp_port_mod. */
440 struct ofputil_port_mod {
441     uint16_t port_no;
442     uint8_t hw_addr[OFP_ETH_ALEN];
443     enum ofputil_port_config config;
444     enum ofputil_port_config mask;
445     enum netdev_features advertise;
446 };
447
448 enum ofperr ofputil_decode_port_mod(const struct ofp_header *,
449                                     struct ofputil_port_mod *);
450 struct ofpbuf *ofputil_encode_port_mod(const struct ofputil_port_mod *,
451                                        enum ofputil_protocol);
452
453 /* Abstract table stats.
454  *
455  * For now we use ofp12_table_stats as a superset of the other protocol
456  * versions' table stats. */
457
458 struct ofpbuf *ofputil_encode_table_stats_reply(
459     const struct ofp12_table_stats[], int n,
460     const struct ofp_header *request);
461
462 /* Abstract nx_flow_monitor_request. */
463 struct ofputil_flow_monitor_request {
464     uint32_t id;
465     enum nx_flow_monitor_flags flags;
466     uint16_t out_port;
467     uint8_t table_id;
468     struct match match;
469 };
470
471 int ofputil_decode_flow_monitor_request(struct ofputil_flow_monitor_request *,
472                                         struct ofpbuf *msg);
473 void ofputil_append_flow_monitor_request(
474     const struct ofputil_flow_monitor_request *, struct ofpbuf *msg);
475
476 /* Abstract nx_flow_update. */
477 struct ofputil_flow_update {
478     enum nx_flow_update_event event;
479
480     /* Used only for NXFME_ADDED, NXFME_DELETED, NXFME_MODIFIED. */
481     enum ofp_flow_removed_reason reason;
482     uint16_t idle_timeout;
483     uint16_t hard_timeout;
484     uint8_t table_id;
485     ovs_be64 cookie;
486     struct match *match;
487     uint16_t priority;
488     struct ofpact *ofpacts;
489     size_t ofpacts_len;
490
491     /* Used only for NXFME_ABBREV. */
492     ovs_be32 xid;
493 };
494
495 int ofputil_decode_flow_update(struct ofputil_flow_update *,
496                                struct ofpbuf *msg, struct ofpbuf *ofpacts);
497 void ofputil_start_flow_update(struct list *replies);
498 void ofputil_append_flow_update(const struct ofputil_flow_update *,
499                                 struct list *replies);
500
501 /* Abstract nx_flow_monitor_cancel. */
502 uint32_t ofputil_decode_flow_monitor_cancel(const struct ofp_header *);
503 struct ofpbuf *ofputil_encode_flow_monitor_cancel(uint32_t id);
504
505 /* Encoding OpenFlow stats messages. */
506 void ofputil_append_port_desc_stats_reply(enum ofp_version ofp_version,
507                                           const struct ofputil_phy_port *pp,
508                                           struct list *replies);
509
510 /* Encoding simple OpenFlow messages. */
511 struct ofpbuf *make_echo_request(enum ofp_version);
512 struct ofpbuf *make_echo_reply(const struct ofp_header *rq);
513
514 struct ofpbuf *ofputil_encode_barrier_request(enum ofp_version);
515
516 const char *ofputil_frag_handling_to_string(enum ofp_config_flags);
517 bool ofputil_frag_handling_from_string(const char *, enum ofp_config_flags *);
518
519 \f
520 /* Actions. */
521
522 /* The type of an action.
523  *
524  * For each implemented OFPAT10_* and NXAST_* action type, there is a
525  * corresponding constant prefixed with OFPUTIL_, e.g.:
526  *
527  * OFPUTIL_OFPAT10_OUTPUT
528  * OFPUTIL_OFPAT10_SET_VLAN_VID
529  * OFPUTIL_OFPAT10_SET_VLAN_PCP
530  * OFPUTIL_OFPAT10_STRIP_VLAN
531  * OFPUTIL_OFPAT10_SET_DL_SRC
532  * OFPUTIL_OFPAT10_SET_DL_DST
533  * OFPUTIL_OFPAT10_SET_NW_SRC
534  * OFPUTIL_OFPAT10_SET_NW_DST
535  * OFPUTIL_OFPAT10_SET_NW_TOS
536  * OFPUTIL_OFPAT10_SET_TP_SRC
537  * OFPUTIL_OFPAT10_SET_TP_DST
538  * OFPUTIL_OFPAT10_ENQUEUE
539  * OFPUTIL_NXAST_RESUBMIT
540  * OFPUTIL_NXAST_SET_TUNNEL
541  * OFPUTIL_NXAST_SET_QUEUE
542  * OFPUTIL_NXAST_POP_QUEUE
543  * OFPUTIL_NXAST_REG_MOVE
544  * OFPUTIL_NXAST_REG_LOAD
545  * OFPUTIL_NXAST_NOTE
546  * OFPUTIL_NXAST_SET_TUNNEL64
547  * OFPUTIL_NXAST_MULTIPATH
548  * OFPUTIL_NXAST_AUTOPATH
549  * OFPUTIL_NXAST_BUNDLE
550  * OFPUTIL_NXAST_BUNDLE_LOAD
551  * OFPUTIL_NXAST_RESUBMIT_TABLE
552  * OFPUTIL_NXAST_OUTPUT_REG
553  * OFPUTIL_NXAST_LEARN
554  * OFPUTIL_NXAST_DEC_TTL
555  * OFPUTIL_NXAST_FIN_TIMEOUT
556  *
557  * (The above list helps developers who want to "grep" for these definitions.)
558  */
559 enum OVS_PACKED_ENUM ofputil_action_code {
560     OFPUTIL_ACTION_INVALID,
561 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)           OFPUTIL_##ENUM,
562 #define OFPAT11_ACTION(ENUM, STRUCT, NAME)           OFPUTIL_##ENUM,
563 #define OFPAT12_ACTION(ENUM, STRUCT, NAME)           OFPUTIL_##ENUM,
564 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) OFPUTIL_##ENUM,
565 #include "ofp-util.def"
566 };
567
568 /* The number of values of "enum ofputil_action_code". */
569 enum {
570 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)           + 1
571 #define OFPAT11_ACTION(ENUM, STRUCT, NAME)           + 1
572 #define OFPAT12_ACTION(ENUM, STRUCT, NAME)           + 1
573 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) + 1
574     OFPUTIL_N_ACTIONS = 1
575 #include "ofp-util.def"
576 };
577
578 int ofputil_action_code_from_name(const char *);
579
580 void *ofputil_put_action(enum ofputil_action_code, struct ofpbuf *buf);
581
582 /* For each OpenFlow action <ENUM> that has a corresponding action structure
583  * struct <STRUCT>, this defines two functions:
584  *
585  *   void ofputil_init_<ENUM>(struct <STRUCT> *action);
586  *
587  *     Initializes the parts of 'action' that identify it as having type <ENUM>
588  *     and length 'sizeof *action' and zeros the rest.  For actions that have
589  *     variable length, the length used and cleared is that of struct <STRUCT>.
590  *
591  *  struct <STRUCT> *ofputil_put_<ENUM>(struct ofpbuf *buf);
592  *
593  *     Appends a new 'action', of length 'sizeof(struct <STRUCT>)', to 'buf',
594  *     initializes it with ofputil_init_<ENUM>(), and returns it.
595  */
596 #define OFPAT10_ACTION(ENUM, STRUCT, NAME)              \
597     void ofputil_init_##ENUM(struct STRUCT *);          \
598     struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
599 #define OFPAT11_ACTION(ENUM, STRUCT, NAME)              \
600     void ofputil_init_##ENUM(struct STRUCT *);          \
601     struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
602 #define OFPAT12_ACTION(ENUM, STRUCT, NAME)              \
603     void ofputil_init_##ENUM(struct STRUCT *);          \
604     struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
605 #define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)    \
606     void ofputil_init_##ENUM(struct STRUCT *);          \
607     struct STRUCT *ofputil_put_##ENUM(struct ofpbuf *);
608 #include "ofp-util.def"
609
610 #define OFP_ACTION_ALIGN 8      /* Alignment of ofp_actions. */
611
612 enum ofperr validate_actions(const union ofp_action *, size_t n_actions,
613                              const struct flow *, int max_ports);
614 bool action_outputs_to_port(const union ofp_action *, ovs_be16 port);
615
616 enum ofperr ofputil_pull_actions(struct ofpbuf *, unsigned int actions_len,
617                                  union ofp_action **, size_t *);
618
619 bool ofputil_actions_equal(const union ofp_action *a, size_t n_a,
620                            const union ofp_action *b, size_t n_b);
621 union ofp_action *ofputil_actions_clone(const union ofp_action *, size_t n);
622
623 /* Handy utility for parsing flows and actions. */
624 bool ofputil_parse_key_value(char **stringp, char **keyp, char **valuep);
625
626 #endif /* ofp-util.h */