]> git.proxmox.com Git - ovs.git/blame - lib/dpif.h
odp-util: Use nl_parse_nested() to simplify format_odp_sample_action().
[ovs.git] / lib / dpif.h
CommitLineData
064af421 1/*
4c738a8d 2 * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
064af421 3 *
a14bc59f
BP
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:
064af421 7 *
a14bc59f
BP
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.
064af421
BP
15 */
16
17
18#ifndef DPIF_H
19#define DPIF_H 1
20
064af421
BP
21#include <stdbool.h>
22#include <stddef.h>
23#include <stdint.h>
9dbb9d5e
BP
24#include "openflow/openflow.h"
25#include "openvswitch/datapath-protocol.h"
032aa6a3 26#include "netdev.h"
9dbb9d5e 27#include "util.h"
064af421 28
03292c46
JG
29#ifdef __cplusplus
30extern "C" {
31#endif
32
c228a364 33struct dpif;
c97fb132 34struct ds;
572b7068 35struct flow;
cdee00fd 36struct nlattr;
064af421 37struct ofpbuf;
d0c23a1a 38struct sset;
999401aa 39struct dpif_class;
064af421 40
999401aa
JG
41int dp_register_provider(const struct dpif_class *);
42int dp_unregister_provider(const char *type);
d0c23a1a 43void dp_enumerate_types(struct sset *types);
f79e673f 44const char *dpif_normalize_type(const char *);
999401aa 45
d0c23a1a 46int dp_enumerate_names(const char *type, struct sset *names);
1a6f1e2a 47void dp_parse_name(const char *datapath_name, char **name, char **type);
5792c5c6 48
1a6f1e2a
JG
49int dpif_open(const char *name, const char *type, struct dpif **);
50int dpif_create(const char *name, const char *type, struct dpif **);
51int dpif_create_and_open(const char *name, const char *type, struct dpif **);
064af421
BP
52void dpif_close(struct dpif *);
53
640e1b20
BP
54void dpif_run(struct dpif *);
55void dpif_wait(struct dpif *);
56
b29ba128 57const char *dpif_name(const struct dpif *);
1a6f1e2a 58const char *dpif_base_name(const struct dpif *);
064af421
BP
59
60int dpif_delete(struct dpif *);
61
df2c07f4 62int dpif_get_dp_stats(const struct dpif *, struct ovs_dp_stats *);
064af421
BP
63int dpif_get_drop_frags(const struct dpif *, bool *drop_frags);
64int dpif_set_drop_frags(struct dpif *, bool drop_frags);
65
c3827f61 66int dpif_port_add(struct dpif *, struct netdev *, uint16_t *port_nop);
064af421 67int dpif_port_del(struct dpif *, uint16_t port_no);
4c738a8d
BP
68
69/* A port within a datapath.
70 *
71 * 'name' and 'type' are suitable for passing to netdev_open(). */
72struct dpif_port {
73 char *name; /* Network device name, e.g. "eth0". */
74 char *type; /* Network device type, e.g. "system". */
75 uint32_t port_no; /* Port number within datapath. */
76};
77void dpif_port_clone(struct dpif_port *, const struct dpif_port *);
78void dpif_port_destroy(struct dpif_port *);
064af421 79int dpif_port_query_by_number(const struct dpif *, uint16_t port_no,
4c738a8d 80 struct dpif_port *);
064af421 81int dpif_port_query_by_name(const struct dpif *, const char *devname,
4c738a8d 82 struct dpif_port *);
335562c0
BP
83int dpif_port_get_name(struct dpif *, uint16_t port_no,
84 char *name, size_t name_size);
996c1b3d 85int dpif_get_max_ports(const struct dpif *);
b0ec0f27
BP
86
87struct dpif_port_dump {
88 const struct dpif *dpif;
89 int error;
90 void *state;
91};
92void dpif_port_dump_start(struct dpif_port_dump *, const struct dpif *);
4c738a8d 93bool dpif_port_dump_next(struct dpif_port_dump *, struct dpif_port *);
b0ec0f27
BP
94int dpif_port_dump_done(struct dpif_port_dump *);
95
4c738a8d 96/* Iterates through each DPIF_PORT in DPIF, using DUMP as state.
b0ec0f27
BP
97 *
98 * Arguments all have pointer type.
99 *
100 * If you break out of the loop, then you need to free the dump structure by
101 * hand using dpif_port_dump_done(). */
4c738a8d 102#define DPIF_PORT_FOR_EACH(DPIF_PORT, DUMP, DPIF) \
b0ec0f27 103 for (dpif_port_dump_start(DUMP, DPIF); \
4c738a8d 104 (dpif_port_dump_next(DUMP, DPIF_PORT) \
b0ec0f27
BP
105 ? true \
106 : (dpif_port_dump_done(DUMP), false)); \
107 )
064af421 108
e9e28be3
BP
109int dpif_port_poll(const struct dpif *, char **devnamep);
110void dpif_port_poll_wait(const struct dpif *);
111
c97fb132
BP
112struct dpif_flow_stats {
113 uint64_t n_packets;
114 uint64_t n_bytes;
115 long long int used;
116 uint8_t tcp_flags;
117};
118
572b7068
BP
119void dpif_flow_stats_extract(const struct flow *, struct ofpbuf *packet,
120 struct dpif_flow_stats *);
c97fb132
BP
121void dpif_flow_stats_format(const struct dpif_flow_stats *, struct ds *);
122
ba25b8f4
BP
123enum dpif_flow_put_flags {
124 DPIF_FP_CREATE = 1 << 0, /* Allow creating a new flow. */
125 DPIF_FP_MODIFY = 1 << 1, /* Allow modifying an existing flow. */
126 DPIF_FP_ZERO_STATS = 1 << 2 /* Zero the stats of an existing flow. */
127};
128
064af421 129int dpif_flow_flush(struct dpif *);
ba25b8f4 130int dpif_flow_put(struct dpif *, enum dpif_flow_put_flags,
feebdea2
BP
131 const struct nlattr *key, size_t key_len,
132 const struct nlattr *actions, size_t actions_len,
c97fb132 133 struct dpif_flow_stats *);
feebdea2
BP
134int dpif_flow_del(struct dpif *,
135 const struct nlattr *key, size_t key_len,
c97fb132 136 struct dpif_flow_stats *);
693c4a01 137int dpif_flow_get(const struct dpif *,
feebdea2 138 const struct nlattr *key, size_t key_len,
c97fb132 139 struct ofpbuf **actionsp, struct dpif_flow_stats *);
704a1e09
BP
140
141struct dpif_flow_dump {
142 const struct dpif *dpif;
143 int error;
144 void *state;
145};
146void dpif_flow_dump_start(struct dpif_flow_dump *, const struct dpif *);
feebdea2
BP
147bool dpif_flow_dump_next(struct dpif_flow_dump *,
148 const struct nlattr **key, size_t *key_len,
149 const struct nlattr **actions, size_t *actions_len,
c97fb132 150 const struct dpif_flow_stats **);
704a1e09 151int dpif_flow_dump_done(struct dpif_flow_dump *);
064af421 152
80e5eed9
BP
153int dpif_execute(struct dpif *,
154 const struct nlattr *key, size_t key_len,
155 const struct nlattr *actions, size_t actions_len,
156 const struct ofpbuf *);
064af421 157
82272ede
BP
158enum dpif_upcall_type {
159 DPIF_UC_MISS, /* Miss in flow table. */
df2c07f4 160 DPIF_UC_ACTION, /* OVS_ACTION_ATTR_USERSPACE action. */
982b8810 161 DPIF_N_UC_TYPES
82272ede
BP
162};
163
01545c1a
BP
164const char *dpif_upcall_type_to_string(enum dpif_upcall_type);
165
856081f6
BP
166/* A packet passed up from the datapath to userspace.
167 *
168 * If 'key' or 'actions' is nonnull, then it points into data owned by
169 * 'packet', so their memory cannot be freed separately. (This is hardly a
170 * great way to do things but it works out OK for the dpif providers and
171 * clients that exist so far.)
172 */
173struct dpif_upcall {
856081f6 174 /* All types. */
82272ede 175 enum dpif_upcall_type type;
856081f6
BP
176 struct ofpbuf *packet; /* Packet data. */
177 struct nlattr *key; /* Flow key. */
178 size_t key_len; /* Length of 'key' in bytes. */
179
82272ede 180 /* DPIF_UC_ACTION only. */
df2c07f4 181 uint64_t userdata; /* Argument to OVS_ACTION_ATTR_USERSPACE. */
856081f6 182};
9dbb9d5e 183
8f24562a
BP
184int dpif_recv_get_mask(const struct dpif *, int *listen_mask);
185int dpif_recv_set_mask(struct dpif *, int listen_mask);
856081f6 186int dpif_recv(struct dpif *, struct dpif_upcall *);
1ba530f4 187void dpif_recv_purge(struct dpif *);
064af421
BP
188void dpif_recv_wait(struct dpif *);
189
53a4218d
BP
190void dpif_get_netflow_ids(const struct dpif *,
191 uint8_t *engine_type, uint8_t *engine_id);
064af421 192
aae51f53
BP
193int dpif_queue_to_priority(const struct dpif *, uint32_t queue_id,
194 uint32_t *priority);
195
03292c46
JG
196#ifdef __cplusplus
197}
198#endif
199
064af421 200#endif /* dpif.h */