2 * Copyright (c) 2009 Nicira Networks.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef DPIF_PROVIDER_H
18 #define DPIF_PROVIDER_H 1
20 /* Provider interface to dpifs, which provide an interface to an Open vSwitch
26 /* Open vSwitch datapath interface.
28 * This structure should be treated as opaque by dpif implementations. */
30 const struct dpif_class *class;
32 uint8_t netflow_engine_type;
33 uint8_t netflow_engine_id;
36 void dpif_init(struct dpif *, const struct dpif_class *, const char *name,
37 uint8_t netflow_engine_type, uint8_t netflow_engine_id);
38 static inline void dpif_assert_class(const struct dpif *dpif,
39 const struct dpif_class *class)
41 assert(dpif->class == class);
44 /* Datapath interface class structure, to be defined by each implementation of
45 * a datapath interface
47 * These functions return 0 if successful or a positive errno value on failure,
48 * except where otherwise noted.
50 * These functions are expected to execute synchronously, that is, to block as
51 * necessary to obtain a result. Thus, they may not return EAGAIN or
52 * EWOULDBLOCK or EINPROGRESS. We may relax this requirement in the future if
53 * and when we encounter performance problems. */
55 /* Prefix for names of dpifs in this class, e.g. "udatapath:".
57 * One dpif class may have the empty string "" as its prefix, in which case
58 * that dpif class is associated with dpif names that don't match any other
62 /* Class name, for use in error messages. */
65 /* Performs periodic work needed by dpifs of this class, if any is
69 /* Arranges for poll_block() to wake up if the "run" member function needs
73 /* Attempts to open an existing dpif, if 'create' is false, or to open an
74 * existing dpif or create a new one, if 'create' is true. 'name' is the
75 * full dpif name provided by the user, e.g. "udatapath:/var/run/mypath".
76 * This name is useful for error messages but must not be modified.
78 * 'suffix' is a copy of 'name' following the dpif's 'prefix'.
80 * If successful, stores a pointer to the new dpif in '*dpifp'. On failure
81 * there are no requirements on what is stored in '*dpifp'. */
82 int (*open)(const char *name, char *suffix, bool create,
85 /* Closes 'dpif' and frees associated memory. */
86 void (*close)(struct dpif *dpif);
88 /* Attempts to destroy the dpif underlying 'dpif'.
90 * If successful, 'dpif' will not be used again except as an argument for
91 * the 'close' member function. */
92 int (*delete)(struct dpif *dpif);
94 /* Retrieves statistics for 'dpif' into 'stats'. */
95 int (*get_stats)(const struct dpif *dpif, struct odp_stats *stats);
97 /* Retrieves 'dpif''s current treatment of IP fragments into '*drop_frags':
98 * true indicates that fragments are dropped, false indicates that
99 * fragments are treated in the same way as other IP packets (except that
100 * the L4 header cannot be read). */
101 int (*get_drop_frags)(const struct dpif *dpif, bool *drop_frags);
103 /* Changes 'dpif''s treatment of IP fragments to 'drop_frags', whose
104 * meaning is the same as for the get_drop_frags member function. */
105 int (*set_drop_frags)(struct dpif *dpif, bool drop_frags);
107 /* Creates a new port in 'dpif' connected to network device 'devname'.
108 * 'flags' is a set of ODP_PORT_* flags. If successful, sets '*port_no'
109 * to the new port's port number. */
110 int (*port_add)(struct dpif *dpif, const char *devname, uint16_t flags,
113 /* Removes port numbered 'port_no' from 'dpif'. */
114 int (*port_del)(struct dpif *dpif, uint16_t port_no);
116 /* Queries 'dpif' for a port with the given 'port_no' or 'devname'. Stores
117 * information about the port into '*port' if successful. */
118 int (*port_query_by_number)(const struct dpif *dpif, uint16_t port_no,
119 struct odp_port *port);
120 int (*port_query_by_name)(const struct dpif *dpif, const char *devname,
121 struct odp_port *port);
123 /* Stores in 'ports' information about up to 'n' ports attached to 'dpif',
124 * in no particular order. Returns the number of ports attached to 'dpif'
125 * (not the number stored), if successful, otherwise a negative errno
127 int (*port_list)(const struct dpif *dpif, struct odp_port *ports, int n);
129 /* Stores in 'ports' the port numbers of up to 'n' ports that belong to
130 * 'group' in 'dpif'. Returns the number of ports in 'group' (not the
131 * number stored), if successful, otherwise a negative errno value. */
132 int (*port_group_get)(const struct dpif *dpif, int group,
133 uint16_t ports[], int n);
135 /* Changes port group 'group' in 'dpif' to consist of the 'n' ports whose
136 * numbers are given in 'ports'.
138 * Use the get_stats member function to obtain the number of supported port
140 int (*port_group_set)(struct dpif *dpif, int group,
141 const uint16_t ports[], int n);
143 /* For each flow 'flow' in the 'n' flows in 'flows':
145 * - If a flow matching 'flow->key' exists in 'dpif':
147 * Stores 0 into 'flow->stats.error' and stores statistics for the flow
148 * into 'flow->stats'.
150 * If 'flow->n_actions' is zero, then 'flow->actions' is ignored. If
151 * 'flow->n_actions' is nonzero, then 'flow->actions' should point to
152 * an array of the specified number of actions. At most that many of
153 * the flow's actions will be copied into that array.
154 * 'flow->n_actions' will be updated to the number of actions actually
155 * present in the flow, which may be greater than the number stored if
156 * the flow has more actions than space available in the array.
158 * - Flow-specific errors are indicated by a positive errno value in
159 * 'flow->stats.error'. In particular, ENOENT indicates that no flow
160 * matching 'flow->key' exists in 'dpif'. When an error value is stored,
161 * the contents of 'flow->key' are preserved but other members of 'flow'
162 * should be treated as indeterminate.
164 * Returns 0 if all 'n' flows in 'flows' were updated (whether they were
165 * individually successful or not is indicated by 'flow->stats.error',
166 * however). Returns a positive errno value if an error that prevented
167 * this update occurred, in which the caller must not depend on any
168 * elements in 'flows' being updated or not updated.
170 int (*flow_get)(const struct dpif *dpif, struct odp_flow flows[], int n);
172 /* Adds or modifies a flow in 'dpif' as specified in 'put':
174 * - If the flow specified in 'put->flow' does not exist in 'dpif', then
175 * behavior depends on whether ODPPF_CREATE is specified in 'put->flags':
176 * if it is, the flow will be added, otherwise the operation will fail
179 * - Otherwise, the flow specified in 'put->flow' does exist in 'dpif'.
180 * Behavior in this case depends on whether ODPPF_MODIFY is specified in
181 * 'put->flags': if it is, the flow's actions will be updated, otherwise
182 * the operation will fail with EEXIST. If the flow's actions are
183 * updated, then its statistics will be zeroed if ODPPF_ZERO_STATS is set
184 * in 'put->flags', left as-is otherwise.
186 int (*flow_put)(struct dpif *dpif, struct odp_flow_put *put);
188 /* Deletes a flow matching 'flow->key' from 'dpif' or returns ENOENT if
189 * 'dpif' does not contain such a flow.
191 * If successful, updates 'flow->stats', 'flow->n_actions', and
192 * 'flow->actions' as described in more detail under the flow_get member
194 int (*flow_del)(struct dpif *dpif, struct odp_flow *flow);
196 /* Deletes all flows from 'dpif' and clears all of its queues of received
198 int (*flow_flush)(struct dpif *dpif);
200 /* Stores up to 'n' flows in 'dpif' into 'flows', updating their statistics
201 * and actions as described under the flow_get member function. If
202 * successful, returns the number of flows actually present in 'dpif',
203 * which might be greater than the number stored (if 'dpif' has more than
204 * 'n' flows). On failure, returns a negative errno value. */
205 int (*flow_list)(const struct dpif *dpif, struct odp_flow flows[], int n);
207 /* Performs the 'n_actions' actions in 'actions' on the Ethernet frame
208 * specified in 'packet'.
210 * Pretends that the frame was originally received on the port numbered
211 * 'in_port'. This affects only ODPAT_OUTPUT_GROUP actions, which will not
212 * send a packet out their input port. Specify the number of an unused
213 * port (e.g. UINT16_MAX is currently always unused) to avoid this
215 int (*execute)(struct dpif *dpif, uint16_t in_port,
216 const union odp_action actions[], int n_actions,
217 const struct ofpbuf *packet);
219 /* Retrieves 'dpif''s "listen mask" into '*listen_mask'. Each ODPL_* bit
220 * set in '*listen_mask' indicates the 'dpif' will receive messages of the
221 * corresponding type when it calls the recv member function. */
222 int (*recv_get_mask)(const struct dpif *dpif, int *listen_mask);
224 /* Sets 'dpif''s "listen mask" to 'listen_mask'. Each ODPL_* bit set in
225 * 'listen_mask' indicates the 'dpif' will receive messages of the
226 * corresponding type when it calls the recv member function. */
227 int (*recv_set_mask)(struct dpif *dpif, int listen_mask);
229 /* Attempts to receive a message from 'dpif'. If successful, stores the
230 * message into '*packetp'. The message, if one is received, must begin
231 * with 'struct odp_msg' as a header. Only messages of the types selected
232 * with the set_listen_mask member function should be received.
234 * This function must not block. If no message is ready to be received
235 * when it is called, it should return EAGAIN without blocking. */
236 int (*recv)(struct dpif *dpif, struct ofpbuf **packetp);
238 /* Arranges for the poll loop to wake up when 'dpif' has a message queued
239 * to be received with the recv member function. */
240 void (*recv_wait)(struct dpif *dpif);
243 extern const struct dpif_class dpif_linux_class;
245 #endif /* dpif-provider.h */