]> git.proxmox.com Git - ovs.git/blame - lib/dpif-provider.h
ofproto-dpif: Print slow-path actions instead of "drop" in dump-flows.
[ovs.git] / lib / dpif-provider.h
CommitLineData
96fba48f 1/*
e0edde6f 2 * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
96fba48f
BP
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 DPIF_PROVIDER_H
18#define DPIF_PROVIDER_H 1
19
20/* Provider interface to dpifs, which provide an interface to an Open vSwitch
bc34d060
BP
21 * datapath. A datapath is a collection of physical or virtual ports that are
22 * exposed over OpenFlow as a single switch. Datapaths and the collections of
23 * ports that they contain may be fixed or dynamic. */
96fba48f 24
43253595 25#include "openflow/openflow.h"
96fba48f 26#include "dpif.h"
43253595 27#include "util.h"
96fba48f 28
1acb6baa
BP
29#ifdef __cplusplus
30extern "C" {
31#endif
32
96fba48f
BP
33/* Open vSwitch datapath interface.
34 *
35 * This structure should be treated as opaque by dpif implementations. */
36struct dpif {
1acb6baa 37 const struct dpif_class *dpif_class;
1a6f1e2a
JG
38 char *base_name;
39 char *full_name;
96fba48f
BP
40 uint8_t netflow_engine_type;
41 uint8_t netflow_engine_id;
42};
43
44void dpif_init(struct dpif *, const struct dpif_class *, const char *name,
45 uint8_t netflow_engine_type, uint8_t netflow_engine_id);
999401aa
JG
46void dpif_uninit(struct dpif *dpif, bool close);
47
96fba48f 48static inline void dpif_assert_class(const struct dpif *dpif,
1acb6baa 49 const struct dpif_class *dpif_class)
96fba48f 50{
cb22974d 51 ovs_assert(dpif->dpif_class == dpif_class);
96fba48f
BP
52}
53
54/* Datapath interface class structure, to be defined by each implementation of
f20279af 55 * a datapath interface.
96fba48f
BP
56 *
57 * These functions return 0 if successful or a positive errno value on failure,
58 * except where otherwise noted.
59 *
60 * These functions are expected to execute synchronously, that is, to block as
61 * necessary to obtain a result. Thus, they may not return EAGAIN or
62 * EWOULDBLOCK or EINPROGRESS. We may relax this requirement in the future if
63 * and when we encounter performance problems. */
64struct dpif_class {
1a6f1e2a 65 /* Type of dpif in this class, e.g. "system", "netdev", etc.
96fba48f 66 *
1a6f1e2a
JG
67 * One of the providers should supply a "system" type, since this is
68 * the type assumed if no type is specified when opening a dpif. */
69 const char *type;
96fba48f 70
d3d22744
BP
71 /* Enumerates the names of all known created datapaths, if possible, into
72 * 'all_dps'. The caller has already initialized 'all_dps' and other dpif
73 * classes might already have added names to it.
74 *
75 * This is used by the vswitch at startup, so that it can delete any
76 * datapaths that are not configured.
77 *
78 * Some kinds of datapaths might not be practically enumerable, in which
79 * case this function may be a null pointer. */
d0c23a1a 80 int (*enumerate)(struct sset *all_dps);
d3d22744 81
0aeaabc8
JP
82 /* Returns the type to pass to netdev_open() when a dpif of class
83 * 'dpif_class' has a port of type 'type', for a few special cases
84 * when a netdev type differs from a port type. For example, when
85 * using the userspace datapath, a port of type "internal" needs to
86 * be opened as "tap".
87 *
88 * Returns either 'type' itself or a string literal, which must not
89 * be freed. */
90 const char *(*port_open_type)(const struct dpif_class *dpif_class,
91 const char *type);
92
1a6f1e2a
JG
93 /* Attempts to open an existing dpif called 'name', if 'create' is false,
94 * or to open an existing dpif or create a new one, if 'create' is true.
96fba48f 95 *
4a387741
BP
96 * 'dpif_class' is the class of dpif to open.
97 *
98 * If successful, stores a pointer to the new dpif in '*dpifp', which must
99 * have class 'dpif_class'. On failure there are no requirements on what
100 * is stored in '*dpifp'. */
101 int (*open)(const struct dpif_class *dpif_class,
102 const char *name, bool create, struct dpif **dpifp);
96fba48f
BP
103
104 /* Closes 'dpif' and frees associated memory. */
105 void (*close)(struct dpif *dpif);
106
107 /* Attempts to destroy the dpif underlying 'dpif'.
108 *
109 * If successful, 'dpif' will not be used again except as an argument for
110 * the 'close' member function. */
1acb6baa 111 int (*destroy)(struct dpif *dpif);
96fba48f 112
640e1b20
BP
113 /* Performs periodic work needed by 'dpif', if any is necessary. */
114 void (*run)(struct dpif *dpif);
115
116 /* Arranges for poll_block() to wake up if the "run" member function needs
117 * to be called for 'dpif'. */
118 void (*wait)(struct dpif *dpif);
119
96fba48f 120 /* Retrieves statistics for 'dpif' into 'stats'. */
a8d9304d 121 int (*get_stats)(const struct dpif *dpif, struct dpif_dp_stats *stats);
96fba48f 122
232dfa4a 123 /* Adds 'netdev' as a new port in 'dpif'. If '*port_no' is not
9b56fe13 124 * UINT32_MAX, attempts to use that as the port's port number.
232dfa4a
JP
125 *
126 * If port is successfully added, sets '*port_no' to the new port's
127 * port number. Returns EBUSY if caller attempted to choose a port
128 * number, and it was in use. */
c3827f61 129 int (*port_add)(struct dpif *dpif, struct netdev *netdev,
9b56fe13 130 uint32_t *port_no);
96fba48f
BP
131
132 /* Removes port numbered 'port_no' from 'dpif'. */
9b56fe13 133 int (*port_del)(struct dpif *dpif, uint32_t port_no);
96fba48f 134
4afba28d
JP
135 /* Queries 'dpif' for a port with the given 'port_no' or 'devname'.
136 * If 'port' is not null, stores information about the port into
137 * '*port' if successful.
4c738a8d 138 *
4afba28d
JP
139 * If 'port' is not null, the caller takes ownership of data in
140 * 'port' and must free it with dpif_port_destroy() when it is no
141 * longer needed. */
9b56fe13 142 int (*port_query_by_number)(const struct dpif *dpif, uint32_t port_no,
4c738a8d 143 struct dpif_port *port);
96fba48f 144 int (*port_query_by_name)(const struct dpif *dpif, const char *devname,
4c738a8d 145 struct dpif_port *port);
96fba48f 146
996c1b3d
BP
147 /* Returns one greater than the largest port number accepted in flow
148 * actions. */
149 int (*get_max_ports)(const struct dpif *dpif);
150
98403001
BP
151 /* Returns the Netlink PID value to supply in OVS_ACTION_ATTR_USERSPACE
152 * actions as the OVS_USERSPACE_ATTR_PID attribute's value, for use in
153 * flows whose packets arrived on port 'port_no'.
154 *
9b56fe13 155 * A 'port_no' of UINT32_MAX should be treated as a special case. The
625b0720
BP
156 * implementation should return a reserved PID, not allocated to any port,
157 * that the client may use for special purposes.
158 *
98403001
BP
159 * The return value only needs to be meaningful when DPIF_UC_ACTION has
160 * been enabled in the 'dpif''s listen mask, and it is allowed to change
161 * when DPIF_UC_ACTION is disabled and then re-enabled.
162 *
163 * A dpif provider that doesn't have meaningful Netlink PIDs can use NULL
164 * for this function. This is equivalent to always returning 0. */
9b56fe13 165 uint32_t (*port_get_pid)(const struct dpif *dpif, uint32_t port_no);
98403001 166
b0ec0f27
BP
167 /* Attempts to begin dumping the ports in a dpif. On success, returns 0
168 * and initializes '*statep' with any data needed for iteration. On
169 * failure, returns a positive errno value. */
170 int (*port_dump_start)(const struct dpif *dpif, void **statep);
171
172 /* Attempts to retrieve another port from 'dpif' for 'state', which was
173 * initialized by a successful call to the 'port_dump_start' function for
4c738a8d 174 * 'dpif'. On success, stores a new dpif_port into 'port' and returns 0.
b0ec0f27
BP
175 * Returns EOF if the end of the port table has been reached, or a positive
176 * errno value on error. This function will not be called again once it
177 * returns nonzero once for a given iteration (but the 'port_dump_done'
4c738a8d
BP
178 * function will be called afterward).
179 *
180 * The dpif provider retains ownership of the data stored in 'port'. It
181 * must remain valid until at least the next call to 'port_dump_next' or
182 * 'port_dump_done' for 'state'. */
b0ec0f27 183 int (*port_dump_next)(const struct dpif *dpif, void *state,
4c738a8d 184 struct dpif_port *port);
b0ec0f27
BP
185
186 /* Releases resources from 'dpif' for 'state', which was initialized by a
187 * successful call to the 'port_dump_start' function for 'dpif'. */
188 int (*port_dump_done)(const struct dpif *dpif, void *state);
96fba48f 189
e9e28be3
BP
190 /* Polls for changes in the set of ports in 'dpif'. If the set of ports in
191 * 'dpif' has changed, then this function should do one of the
192 * following:
193 *
194 * - Preferably: store the name of the device that was added to or deleted
195 * from 'dpif' in '*devnamep' and return 0. The caller is responsible
196 * for freeing '*devnamep' (with free()) when it no longer needs it.
197 *
198 * - Alternatively: return ENOBUFS, without indicating the device that was
199 * added or deleted.
200 *
201 * Occasional 'false positives', in which the function returns 0 while
202 * indicating a device that was not actually added or deleted or returns
203 * ENOBUFS without any change, are acceptable.
204 *
205 * If the set of ports in 'dpif' has not changed, returns EAGAIN. May also
206 * return other positive errno values to indicate that something has gone
207 * wrong. */
208 int (*port_poll)(const struct dpif *dpif, char **devnamep);
209
210 /* Arranges for the poll loop to wake up when 'port_poll' will return a
211 * value other than EAGAIN. */
212 void (*port_poll_wait)(const struct dpif *dpif);
213
feebdea2 214 /* Queries 'dpif' for a flow entry. The flow is specified by the Netlink
df2c07f4 215 * attributes with types OVS_KEY_ATTR_* in the 'key_len' bytes starting at
feebdea2 216 * 'key'.
bc4a05c6 217 *
feebdea2
BP
218 * Returns 0 if successful. If no flow matches, returns ENOENT. On other
219 * failure, returns a positive errno value.
bc4a05c6 220 *
feebdea2
BP
221 * If 'actionsp' is nonnull, then on success '*actionsp' must be set to an
222 * ofpbuf owned by the caller that contains the Netlink attributes for the
223 * flow's actions. The caller must free the ofpbuf (with ofpbuf_delete())
224 * when it is no longer needed.
225 *
226 * If 'stats' is nonnull, then on success it must be updated with the
227 * flow's statistics. */
693c4a01 228 int (*flow_get)(const struct dpif *dpif,
feebdea2 229 const struct nlattr *key, size_t key_len,
c97fb132 230 struct ofpbuf **actionsp, struct dpif_flow_stats *stats);
feebdea2
BP
231
232 /* Adds or modifies a flow in 'dpif'. The flow is specified by the Netlink
89625d1e
BP
233 * attributes with types OVS_KEY_ATTR_* in the 'put->key_len' bytes
234 * starting at 'put->key'. The associated actions are specified by the
235 * Netlink attributes with types OVS_ACTION_ATTR_* in the
236 * 'put->actions_len' bytes starting at 'put->actions'.
feebdea2
BP
237 *
238 * - If the flow's key does not exist in 'dpif', then the flow will be
89625d1e
BP
239 * added if 'put->flags' includes DPIF_FP_CREATE. Otherwise the
240 * operation will fail with ENOENT.
feebdea2 241 *
89625d1e
BP
242 * If the operation succeeds, then 'put->stats', if nonnull, must be
243 * zeroed.
96fba48f 244 *
feebdea2 245 * - If the flow's key does exist in 'dpif', then the flow's actions will
89625d1e 246 * be updated if 'put->flags' includes DPIF_FP_MODIFY. Otherwise the
ba25b8f4 247 * operation will fail with EEXIST. If the flow's actions are updated,
89625d1e 248 * then its statistics will be zeroed if 'put->flags' includes
ba25b8f4 249 * DPIF_FP_ZERO_STATS, and left as-is otherwise.
96fba48f 250 *
89625d1e
BP
251 * If the operation succeeds, then 'put->stats', if nonnull, must be set
252 * to the flow's statistics before the update.
96fba48f 253 */
89625d1e 254 int (*flow_put)(struct dpif *dpif, const struct dpif_flow_put *put);
feebdea2
BP
255
256 /* Deletes a flow from 'dpif' and returns 0, or returns ENOENT if 'dpif'
257 * does not contain such a flow. The flow is specified by the Netlink
b99d3cee
BP
258 * attributes with types OVS_KEY_ATTR_* in the 'del->key_len' bytes
259 * starting at 'del->key'.
96fba48f 260 *
b99d3cee
BP
261 * If the operation succeeds, then 'del->stats', if nonnull, must be set to
262 * the flow's statistics before its deletion. */
263 int (*flow_del)(struct dpif *dpif, const struct dpif_flow_del *del);
96fba48f
BP
264
265 /* Deletes all flows from 'dpif' and clears all of its queues of received
266 * packets. */
267 int (*flow_flush)(struct dpif *dpif);
268
704a1e09
BP
269 /* Attempts to begin dumping the flows in a dpif. On success, returns 0
270 * and initializes '*statep' with any data needed for iteration. On
271 * failure, returns a positive errno value. */
272 int (*flow_dump_start)(const struct dpif *dpif, void **statep);
273
274 /* Attempts to retrieve another flow from 'dpif' for 'state', which was
275 * initialized by a successful call to the 'flow_dump_start' function for
feebdea2
BP
276 * 'dpif'. On success, updates the output parameters as described below
277 * and returns 0. Returns EOF if the end of the flow table has been
278 * reached, or a positive errno value on error. This function will not be
279 * called again once it returns nonzero within a given iteration (but the
280 * 'flow_dump_done' function will be called afterward).
281 *
282 * On success, if 'key' and 'key_len' are nonnull then '*key' and
df2c07f4 283 * '*key_len' must be set to Netlink attributes with types OVS_KEY_ATTR_*
feebdea2 284 * representing the dumped flow's key. If 'actions' and 'actions_len' are
7aec165d 285 * nonnull then they should be set to Netlink attributes with types
df2c07f4 286 * OVS_ACTION_ATTR_* representing the dumped flow's actions. If 'stats'
7aec165d 287 * is nonnull then it should be set to the dumped flow's statistics.
704a1e09 288 *
feebdea2
BP
289 * All of the returned data is owned by 'dpif', not by the caller, and the
290 * caller must not modify or free it. 'dpif' must guarantee that it
291 * remains accessible and unchanging until at least the next call to
292 * 'flow_dump_next' or 'flow_dump_done' for 'state'. */
704a1e09 293 int (*flow_dump_next)(const struct dpif *dpif, void *state,
feebdea2
BP
294 const struct nlattr **key, size_t *key_len,
295 const struct nlattr **actions, size_t *actions_len,
c97fb132 296 const struct dpif_flow_stats **stats);
704a1e09
BP
297
298 /* Releases resources from 'dpif' for 'state', which was initialized by a
299 * successful call to the 'flow_dump_start' function for 'dpif'. */
300 int (*flow_dump_done)(const struct dpif *dpif, void *state);
96fba48f 301
89625d1e
BP
302 /* Performs the 'execute->actions_len' bytes of actions in
303 * 'execute->actions' on the Ethernet frame specified in 'execute->packet'
304 * taken from the flow specified in the 'execute->key_len' bytes of
305 * 'execute->key'. ('execute->key' is mostly redundant with
306 * 'execute->packet', but it contains some metadata that cannot be
296e07ac 307 * recovered from 'execute->packet', such as tunnel and in_port.) */
89625d1e 308 int (*execute)(struct dpif *dpif, const struct dpif_execute *execute);
96fba48f 309
6bc60024
BP
310 /* Executes each of the 'n_ops' operations in 'ops' on 'dpif', in the order
311 * in which they are specified, placing each operation's results in the
312 * "output" members documented in comments.
313 *
314 * This function is optional. It is only worthwhile to implement it if
315 * 'dpif' can perform operations in batch faster than individually. */
c2b565b5 316 void (*operate)(struct dpif *dpif, struct dpif_op **ops, size_t n_ops);
6bc60024 317
a12b3ead
BP
318 /* Enables or disables receiving packets with dpif_recv() for 'dpif'.
319 * Turning packet receive off and then back on is allowed to change Netlink
98403001
BP
320 * PID assignments (see ->port_get_pid()). The client is responsible for
321 * updating flows as necessary if it does this. */
a12b3ead 322 int (*recv_set)(struct dpif *dpif, bool enable);
96fba48f 323
aae51f53 324 /* Translates OpenFlow queue ID 'queue_id' (in host byte order) into a
abff858b 325 * priority value used for setting packet priority. */
aae51f53
BP
326 int (*queue_to_priority)(const struct dpif *dpif, uint32_t queue_id,
327 uint32_t *priority);
328
856081f6 329 /* Polls for an upcall from 'dpif'. If successful, stores the upcall into
90a7c55e
BP
330 * '*upcall', using 'buf' for storage. Should only be called if 'recv_set'
331 * has been used to enable receiving packets from 'dpif'.
96fba48f 332 *
90a7c55e
BP
333 * The implementation should point 'upcall->packet' and 'upcall->key' into
334 * data in the caller-provided 'buf'. If necessary to make room, the
335 * implementation may expand the data in 'buf'. (This is hardly a great
336 * way to do things but it works out OK for the dpif providers that exist
337 * so far.)
856081f6
BP
338 *
339 * This function must not block. If no upcall is pending when it is
340 * called, it should return EAGAIN without blocking. */
90a7c55e
BP
341 int (*recv)(struct dpif *dpif, struct dpif_upcall *upcall,
342 struct ofpbuf *buf);
96fba48f
BP
343
344 /* Arranges for the poll loop to wake up when 'dpif' has a message queued
345 * to be received with the recv member function. */
346 void (*recv_wait)(struct dpif *dpif);
1ba530f4
BP
347
348 /* Throws away any queued upcalls that 'dpif' currently has ready to
349 * return. */
350 void (*recv_purge)(struct dpif *dpif);
96fba48f
BP
351};
352
353extern const struct dpif_class dpif_linux_class;
72865317 354extern const struct dpif_class dpif_netdev_class;
96fba48f 355
1acb6baa
BP
356#ifdef __cplusplus
357}
358#endif
359
96fba48f 360#endif /* dpif-provider.h */