]> git.proxmox.com Git - mirror_ovs.git/blame - lib/dpif-provider.h
datapath: Remove implementation of port groups.
[mirror_ovs.git] / lib / dpif-provider.h
CommitLineData
96fba48f 1/*
1a6f1e2a 2 * Copyright (c) 2009, 2010 Nicira Networks.
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
BP
24
25#include <assert.h>
43253595 26#include "openflow/openflow.h"
96fba48f 27#include "dpif.h"
43253595 28#include "util.h"
96fba48f 29
1acb6baa
BP
30#ifdef __cplusplus
31extern "C" {
32#endif
33
96fba48f
BP
34/* Open vSwitch datapath interface.
35 *
36 * This structure should be treated as opaque by dpif implementations. */
37struct dpif {
1acb6baa 38 const struct dpif_class *dpif_class;
1a6f1e2a
JG
39 char *base_name;
40 char *full_name;
96fba48f
BP
41 uint8_t netflow_engine_type;
42 uint8_t netflow_engine_id;
43};
44
45void dpif_init(struct dpif *, const struct dpif_class *, const char *name,
46 uint8_t netflow_engine_type, uint8_t netflow_engine_id);
999401aa
JG
47void dpif_uninit(struct dpif *dpif, bool close);
48
96fba48f 49static inline void dpif_assert_class(const struct dpif *dpif,
1acb6baa 50 const struct dpif_class *dpif_class)
96fba48f 51{
1acb6baa 52 assert(dpif->dpif_class == dpif_class);
96fba48f
BP
53}
54
55/* Datapath interface class structure, to be defined by each implementation of
f20279af 56 * a datapath interface.
96fba48f
BP
57 *
58 * These functions return 0 if successful or a positive errno value on failure,
59 * except where otherwise noted.
60 *
61 * These functions are expected to execute synchronously, that is, to block as
62 * necessary to obtain a result. Thus, they may not return EAGAIN or
63 * EWOULDBLOCK or EINPROGRESS. We may relax this requirement in the future if
64 * and when we encounter performance problems. */
65struct dpif_class {
1a6f1e2a 66 /* Type of dpif in this class, e.g. "system", "netdev", etc.
96fba48f 67 *
1a6f1e2a
JG
68 * One of the providers should supply a "system" type, since this is
69 * the type assumed if no type is specified when opening a dpif. */
70 const char *type;
96fba48f 71
5792c5c6
BP
72 /* Performs periodic work needed by dpifs of this class, if any is
73 * necessary. */
74 void (*run)(void);
75
76 /* Arranges for poll_block() to wake up if the "run" member function needs
77 * to be called. */
78 void (*wait)(void);
79
d3d22744
BP
80 /* Enumerates the names of all known created datapaths, if possible, into
81 * 'all_dps'. The caller has already initialized 'all_dps' and other dpif
82 * classes might already have added names to it.
83 *
84 * This is used by the vswitch at startup, so that it can delete any
85 * datapaths that are not configured.
86 *
87 * Some kinds of datapaths might not be practically enumerable, in which
88 * case this function may be a null pointer. */
89 int (*enumerate)(struct svec *all_dps);
90
1a6f1e2a
JG
91 /* Attempts to open an existing dpif called 'name', if 'create' is false,
92 * or to open an existing dpif or create a new one, if 'create' is true.
93 * 'type' corresponds to the 'type' field used in the dpif_class
94 * structure.
96fba48f
BP
95 *
96 * If successful, stores a pointer to the new dpif in '*dpifp'. On failure
97 * there are no requirements on what is stored in '*dpifp'. */
1a6f1e2a 98 int (*open)(const char *name, const char *type, bool create,
96fba48f
BP
99 struct dpif **dpifp);
100
101 /* Closes 'dpif' and frees associated memory. */
102 void (*close)(struct dpif *dpif);
103
d3d22744
BP
104 /* Enumerates all names that may be used to open 'dpif' into 'all_names'.
105 * The Linux datapath, for example, supports opening a datapath both by
106 * number, e.g. "dp0", and by the name of the datapath's local port. For
107 * some datapaths, this might be an infinite set (e.g. in a file name,
108 * slashes may be duplicated any number of times), in which case only the
109 * names most likely to be used should be enumerated.
110 *
111 * The caller has already initialized 'all_names' and might already have
112 * added some names to it. This function should not disturb any existing
113 * names in 'all_names'.
114 *
115 * If a datapath class does not support multiple names for a datapath, this
116 * function may be a null pointer.
117 *
118 * This is used by the vswitch at startup, */
119 int (*get_all_names)(const struct dpif *dpif, struct svec *all_names);
120
96fba48f
BP
121 /* Attempts to destroy the dpif underlying 'dpif'.
122 *
123 * If successful, 'dpif' will not be used again except as an argument for
124 * the 'close' member function. */
1acb6baa 125 int (*destroy)(struct dpif *dpif);
96fba48f
BP
126
127 /* Retrieves statistics for 'dpif' into 'stats'. */
128 int (*get_stats)(const struct dpif *dpif, struct odp_stats *stats);
129
130 /* Retrieves 'dpif''s current treatment of IP fragments into '*drop_frags':
131 * true indicates that fragments are dropped, false indicates that
132 * fragments are treated in the same way as other IP packets (except that
133 * the L4 header cannot be read). */
134 int (*get_drop_frags)(const struct dpif *dpif, bool *drop_frags);
135
136 /* Changes 'dpif''s treatment of IP fragments to 'drop_frags', whose
137 * meaning is the same as for the get_drop_frags member function. */
138 int (*set_drop_frags)(struct dpif *dpif, bool drop_frags);
139
140 /* Creates a new port in 'dpif' connected to network device 'devname'.
141 * 'flags' is a set of ODP_PORT_* flags. If successful, sets '*port_no'
142 * to the new port's port number. */
143 int (*port_add)(struct dpif *dpif, const char *devname, uint16_t flags,
144 uint16_t *port_no);
145
146 /* Removes port numbered 'port_no' from 'dpif'. */
147 int (*port_del)(struct dpif *dpif, uint16_t port_no);
148
149 /* Queries 'dpif' for a port with the given 'port_no' or 'devname'. Stores
150 * information about the port into '*port' if successful. */
151 int (*port_query_by_number)(const struct dpif *dpif, uint16_t port_no,
152 struct odp_port *port);
153 int (*port_query_by_name)(const struct dpif *dpif, const char *devname,
154 struct odp_port *port);
155
156 /* Stores in 'ports' information about up to 'n' ports attached to 'dpif',
157 * in no particular order. Returns the number of ports attached to 'dpif'
158 * (not the number stored), if successful, otherwise a negative errno
159 * value. */
160 int (*port_list)(const struct dpif *dpif, struct odp_port *ports, int n);
161
e9e28be3
BP
162 /* Polls for changes in the set of ports in 'dpif'. If the set of ports in
163 * 'dpif' has changed, then this function should do one of the
164 * following:
165 *
166 * - Preferably: store the name of the device that was added to or deleted
167 * from 'dpif' in '*devnamep' and return 0. The caller is responsible
168 * for freeing '*devnamep' (with free()) when it no longer needs it.
169 *
170 * - Alternatively: return ENOBUFS, without indicating the device that was
171 * added or deleted.
172 *
173 * Occasional 'false positives', in which the function returns 0 while
174 * indicating a device that was not actually added or deleted or returns
175 * ENOBUFS without any change, are acceptable.
176 *
177 * If the set of ports in 'dpif' has not changed, returns EAGAIN. May also
178 * return other positive errno values to indicate that something has gone
179 * wrong. */
180 int (*port_poll)(const struct dpif *dpif, char **devnamep);
181
182 /* Arranges for the poll loop to wake up when 'port_poll' will return a
183 * value other than EAGAIN. */
184 void (*port_poll_wait)(const struct dpif *dpif);
185
96fba48f
BP
186 /* For each flow 'flow' in the 'n' flows in 'flows':
187 *
188 * - If a flow matching 'flow->key' exists in 'dpif':
189 *
190 * Stores 0 into 'flow->stats.error' and stores statistics for the flow
191 * into 'flow->stats'.
192 *
193 * If 'flow->n_actions' is zero, then 'flow->actions' is ignored. If
194 * 'flow->n_actions' is nonzero, then 'flow->actions' should point to
195 * an array of the specified number of actions. At most that many of
196 * the flow's actions will be copied into that array.
197 * 'flow->n_actions' will be updated to the number of actions actually
198 * present in the flow, which may be greater than the number stored if
199 * the flow has more actions than space available in the array.
200 *
201 * - Flow-specific errors are indicated by a positive errno value in
202 * 'flow->stats.error'. In particular, ENOENT indicates that no flow
203 * matching 'flow->key' exists in 'dpif'. When an error value is stored,
204 * the contents of 'flow->key' are preserved but other members of 'flow'
205 * should be treated as indeterminate.
206 *
207 * Returns 0 if all 'n' flows in 'flows' were updated (whether they were
208 * individually successful or not is indicated by 'flow->stats.error',
209 * however). Returns a positive errno value if an error that prevented
210 * this update occurred, in which the caller must not depend on any
211 * elements in 'flows' being updated or not updated.
212 */
213 int (*flow_get)(const struct dpif *dpif, struct odp_flow flows[], int n);
214
215 /* Adds or modifies a flow in 'dpif' as specified in 'put':
216 *
217 * - If the flow specified in 'put->flow' does not exist in 'dpif', then
218 * behavior depends on whether ODPPF_CREATE is specified in 'put->flags':
219 * if it is, the flow will be added, otherwise the operation will fail
220 * with ENOENT.
221 *
222 * - Otherwise, the flow specified in 'put->flow' does exist in 'dpif'.
223 * Behavior in this case depends on whether ODPPF_MODIFY is specified in
224 * 'put->flags': if it is, the flow's actions will be updated, otherwise
225 * the operation will fail with EEXIST. If the flow's actions are
226 * updated, then its statistics will be zeroed if ODPPF_ZERO_STATS is set
227 * in 'put->flags', left as-is otherwise.
228 */
229 int (*flow_put)(struct dpif *dpif, struct odp_flow_put *put);
230
231 /* Deletes a flow matching 'flow->key' from 'dpif' or returns ENOENT if
232 * 'dpif' does not contain such a flow.
233 *
234 * If successful, updates 'flow->stats', 'flow->n_actions', and
235 * 'flow->actions' as described in more detail under the flow_get member
236 * function below. */
237 int (*flow_del)(struct dpif *dpif, struct odp_flow *flow);
238
239 /* Deletes all flows from 'dpif' and clears all of its queues of received
240 * packets. */
241 int (*flow_flush)(struct dpif *dpif);
242
243 /* Stores up to 'n' flows in 'dpif' into 'flows', updating their statistics
244 * and actions as described under the flow_get member function. If
245 * successful, returns the number of flows actually present in 'dpif',
246 * which might be greater than the number stored (if 'dpif' has more than
247 * 'n' flows). On failure, returns a negative errno value. */
248 int (*flow_list)(const struct dpif *dpif, struct odp_flow flows[], int n);
249
250 /* Performs the 'n_actions' actions in 'actions' on the Ethernet frame
f1588b1f
BP
251 * specified in 'packet'. */
252 int (*execute)(struct dpif *dpif,
96fba48f
BP
253 const union odp_action actions[], int n_actions,
254 const struct ofpbuf *packet);
255
256 /* Retrieves 'dpif''s "listen mask" into '*listen_mask'. Each ODPL_* bit
257 * set in '*listen_mask' indicates the 'dpif' will receive messages of the
258 * corresponding type when it calls the recv member function. */
259 int (*recv_get_mask)(const struct dpif *dpif, int *listen_mask);
260
261 /* Sets 'dpif''s "listen mask" to 'listen_mask'. Each ODPL_* bit set in
262 * 'listen_mask' indicates the 'dpif' will receive messages of the
263 * corresponding type when it calls the recv member function. */
264 int (*recv_set_mask)(struct dpif *dpif, int listen_mask);
265
72b06300
BP
266 /* Retrieves 'dpif''s sFlow sampling probability into '*probability'.
267 * Return value is 0 or a positive errno value. EOPNOTSUPP indicates that
268 * the datapath does not support sFlow, as does a null pointer.
269 *
b4a7a3f3
BP
270 * '*probability' is expressed as the number of packets out of UINT_MAX to
271 * sample, e.g. probability/UINT_MAX is the probability of sampling a given
272 * packet. */
72b06300
BP
273 int (*get_sflow_probability)(const struct dpif *dpif,
274 uint32_t *probability);
275
276 /* Sets 'dpif''s sFlow sampling probability to 'probability'. Return value
277 * is 0 or a positive errno value. EOPNOTSUPP indicates that the datapath
278 * does not support sFlow, as does a null pointer.
279 *
b4a7a3f3
BP
280 * 'probability' is expressed as the number of packets out of UINT_MAX to
281 * sample, e.g. probability/UINT_MAX is the probability of sampling a given
282 * packet. */
72b06300
BP
283 int (*set_sflow_probability)(struct dpif *dpif, uint32_t probability);
284
aae51f53
BP
285 /* Translates OpenFlow queue ID 'queue_id' (in host byte order) into a
286 * priority value for use in the ODPAT_SET_PRIORITY action in
287 * '*priority'. */
288 int (*queue_to_priority)(const struct dpif *dpif, uint32_t queue_id,
289 uint32_t *priority);
290
96fba48f
BP
291 /* Attempts to receive a message from 'dpif'. If successful, stores the
292 * message into '*packetp'. The message, if one is received, must begin
43253595
BP
293 * with 'struct odp_msg' as a header, and must have at least
294 * DPIF_RECV_MSG_PADDING bytes of headroom (allocated using
295 * e.g. ofpbuf_reserve()). Only messages of the types selected with the
296 * set_listen_mask member function should be received.
96fba48f
BP
297 *
298 * This function must not block. If no message is ready to be received
299 * when it is called, it should return EAGAIN without blocking. */
300 int (*recv)(struct dpif *dpif, struct ofpbuf **packetp);
301
302 /* Arranges for the poll loop to wake up when 'dpif' has a message queued
303 * to be received with the recv member function. */
304 void (*recv_wait)(struct dpif *dpif);
305};
306
307extern const struct dpif_class dpif_linux_class;
72865317 308extern const struct dpif_class dpif_netdev_class;
96fba48f 309
1acb6baa
BP
310#ifdef __cplusplus
311}
312#endif
313
96fba48f 314#endif /* dpif-provider.h */