]> git.proxmox.com Git - mirror_ovs.git/blob - ofproto/ofproto-dpif.h
xlate: Use OVS_CT_ATTR_EVENTMASK.
[mirror_ovs.git] / ofproto / ofproto-dpif.h
1 /* Copyright (c) 2009-2017 Nicira, Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License. */
14
15 #ifndef OFPROTO_DPIF_H
16 #define OFPROTO_DPIF_H 1
17
18 /* ofproto-dpif -- DPIF based ofproto implementation.
19 *
20 * ofproto-dpif provides an ofproto implementation for those platforms which
21 * implement the netdev and dpif interface defined in netdev.h and dpif.h. The
22 * most important of which is the Linux Kernel Module (dpif-linux), but
23 * alternatives are supported such as a userspace only implementation
24 * (dpif-netdev), and a dummy implementation used for unit testing.
25 *
26 * ofproto-dpif is divided into three major chunks.
27 *
28 * - ofproto-dpif.c
29 * The main ofproto-dpif module is responsible for implementing the
30 * provider interface, installing and removing datapath flows, maintaining
31 * packet statistics, running protocols (BFD, LACP, STP, etc), and
32 * configuring relevant submodules.
33 *
34 * - ofproto-dpif-upcall.c
35 * ofproto-dpif-upcall is responsible for retrieving upcalls from the kernel,
36 * processing miss upcalls, and handing more complex ones up to the main
37 * ofproto-dpif module. Miss upcall processing boils down to figuring out
38 * what each packet's actions are, executing them (i.e. asking the kernel to
39 * forward it), and handing it up to ofproto-dpif to decided whether or not
40 * to install a kernel flow.
41 *
42 * - ofproto-dpif-xlate.c
43 * ofproto-dpif-xlate is responsible for translating OpenFlow actions into
44 * datapath actions.
45 */
46
47 #include <stdint.h>
48
49 #include "dpif.h"
50 #include "fail-open.h"
51 #include "hmapx.h"
52 #include "odp-util.h"
53 #include "openvswitch/ofp-util.h"
54 #include "ovs-thread.h"
55 #include "ofproto-provider.h"
56 #include "util.h"
57 #include "ovs-thread.h"
58
59 struct dpif_flow_stats;
60 struct ofproto_async_msg;
61 struct ofproto_dpif;
62 struct xlate_cache;
63
64 /* Number of implemented OpenFlow tables. */
65 enum { N_TABLES = 255 };
66 enum { TBL_INTERNAL = N_TABLES - 1 }; /* Used for internal hidden rules. */
67 BUILD_ASSERT_DECL(N_TABLES >= 2 && N_TABLES <= 255);
68
69 struct rule_dpif {
70 struct rule up;
71
72 /* These statistics:
73 *
74 * - Do include packets and bytes from datapath flows which have not
75 * recently been processed by a revalidator. */
76 struct ovs_mutex stats_mutex;
77 struct dpif_flow_stats stats OVS_GUARDED;
78
79 /* In non-NULL, will point to a new rule (for which a reference is held) to
80 * which all the stats updates should be forwarded. This exists only
81 * transitionally when flows are replaced.
82 *
83 * Protected by stats_mutex. If both 'rule->stats_mutex' and
84 * 'rule->new_rule->stats_mutex' must be held together, acquire them in that
85 * order, */
86 struct rule_dpif *new_rule OVS_GUARDED;
87 bool forward_counts OVS_GUARDED; /* Forward counts? 'used' time will be
88 * forwarded in all cases. */
89
90 /* If non-zero then the recirculation id that has
91 * been allocated for use with this rule.
92 * The recirculation id and associated internal flow should
93 * be freed when the rule is freed */
94 uint32_t recirc_id;
95 };
96
97 struct rule_dpif *rule_dpif_lookup_from_table(struct ofproto_dpif *,
98 ovs_version_t, struct flow *,
99 struct flow_wildcards *,
100 const struct dpif_flow_stats *,
101 uint8_t *table_id,
102 ofp_port_t in_port,
103 bool may_packet_in,
104 bool honor_table_miss,
105 struct xlate_cache *);
106
107 void rule_dpif_credit_stats(struct rule_dpif *,
108 const struct dpif_flow_stats *);
109
110 void rule_set_recirc_id(struct rule *, uint32_t id);
111
112 /* Returns true if 'rule' is an internal rule, false otherwise. */
113 static inline bool
114 rule_dpif_is_internal(const struct rule_dpif *rule)
115 {
116 return rule->up.table_id == TBL_INTERNAL;
117 }
118 \f
119 /* Groups. */
120
121 struct group_dpif {
122 struct ofgroup up;
123
124 /* These statistics:
125 *
126 * - Do include packets and bytes from datapath flows which have not
127 * recently been processed by a revalidator. */
128 struct ovs_mutex stats_mutex;
129 uint64_t packet_count OVS_GUARDED; /* Number of packets received. */
130 uint64_t byte_count OVS_GUARDED; /* Number of bytes received. */
131 };
132
133 void group_dpif_credit_stats(struct group_dpif *,
134 struct ofputil_bucket *,
135 const struct dpif_flow_stats *);
136 struct group_dpif *group_dpif_lookup(struct ofproto_dpif *,
137 uint32_t group_id, ovs_version_t version,
138 bool take_ref);
139 \f
140 /* Backers.
141 *
142 * A "backer" is the datapath (dpif) on which an dpif-based bridge (an
143 * ofproto-dpif) resides. A backer can host several bridges, but a bridge is
144 * backed by only a single dpif. */
145
146
147 /* DPIF_SUPPORT_FIELD(TYPE, FIELD_NAME, FIELD_DESCRIPTION)
148 *
149 * Each 'DPIF_SUPPORT_FIELD' defines a member in 'struct dpif_backer_support'
150 * and represents support for a datapath action.
151 * They are defined as macros to keep 'dpif_show_support()' in sync
152 * as new fields are added. */
153 #define DPIF_SUPPORT_FIELDS \
154 /* True if the datapath supports variable-length \
155 * OVS_USERSPACE_ATTR_USERDATA in OVS_ACTION_ATTR_USERSPACE actions. \
156 * False if the datapath supports only 8-byte (or shorter) userdata. */ \
157 DPIF_SUPPORT_FIELD(bool, variable_length_userdata, \
158 "Variable length userdata") \
159 \
160 /* True if the datapath supports masked data in OVS_ACTION_ATTR_SET \
161 * actions. */ \
162 DPIF_SUPPORT_FIELD(bool, masked_set_action, "Masked set action") \
163 \
164 /* True if the datapath supports tnl_push and pop actions. */ \
165 DPIF_SUPPORT_FIELD(bool, tnl_push_pop, "Tunnel push pop") \
166 \
167 /* True if the datapath supports OVS_FLOW_ATTR_UFID. */ \
168 DPIF_SUPPORT_FIELD(bool, ufid, "Ufid") \
169 \
170 /* True if the datapath supports OVS_ACTION_ATTR_TRUNC action. */ \
171 DPIF_SUPPORT_FIELD(bool, trunc, "Truncate action") \
172 \
173 /* True if the datapath supports OVS_ACTION_ATTR_CLONE action. */ \
174 DPIF_SUPPORT_FIELD(bool, clone, "Clone action") \
175 \
176 /* Maximum level of nesting allowed by OVS_ACTION_ATTR_SAMPLE action. */\
177 DPIF_SUPPORT_FIELD(size_t, sample_nesting, "Sample nesting") \
178 \
179 /* OVS_CT_ATTR_EVENTMASK supported by OVS_ACTION_ATTR_CT action. */ \
180 DPIF_SUPPORT_FIELD(bool, ct_eventmask, "Conntrack eventmask")
181
182 /* Stores the various features which the corresponding backer supports. */
183 struct dpif_backer_support {
184 #define DPIF_SUPPORT_FIELD(TYPE, NAME, TITLE) TYPE NAME;
185 DPIF_SUPPORT_FIELDS
186 #undef DPIF_SUPPORT_FIELD
187
188 /* Each member represents support for related OVS_KEY_ATTR_* fields. */
189 struct odp_support odp;
190 };
191
192 /* Reasons that we might need to revalidate every datapath flow, and
193 * corresponding coverage counters.
194 *
195 * A value of 0 means that there is no need to revalidate.
196 *
197 * It would be nice to have some cleaner way to integrate with coverage
198 * counters, but with only a few reasons I guess this is good enough for
199 * now. */
200 enum revalidate_reason {
201 REV_RECONFIGURE = 1, /* Switch configuration changed. */
202 REV_STP, /* Spanning tree protocol port status change. */
203 REV_RSTP, /* RSTP port status change. */
204 REV_BOND, /* Bonding changed. */
205 REV_PORT_TOGGLED, /* Port enabled or disabled by CFM, LACP, ...*/
206 REV_FLOW_TABLE, /* Flow table changed. */
207 REV_MAC_LEARNING, /* Mac learning changed. */
208 REV_MCAST_SNOOPING, /* Multicast snooping changed. */
209 };
210
211 /* All datapaths of a given type share a single dpif backer instance. */
212 struct dpif_backer {
213 char *type;
214 int refcount;
215 struct dpif *dpif;
216 struct udpif *udpif;
217
218 struct ovs_rwlock odp_to_ofport_lock;
219 struct hmap odp_to_ofport_map OVS_GUARDED; /* Contains "struct ofport"s. */
220
221 struct simap tnl_backers; /* Set of dpif ports backing tunnels. */
222
223 enum revalidate_reason need_revalidate; /* Revalidate all flows. */
224
225 bool recv_set_enable; /* Enables or disables receiving packets. */
226
227 /* Version string of the datapath stored in OVSDB. */
228 char *dp_version_string;
229
230 /* Datapath feature support. */
231 struct dpif_backer_support support;
232 struct atomic_count tnl_count;
233 };
234
235 /* All existing ofproto_backer instances, indexed by ofproto->up.type. */
236 extern struct shash all_dpif_backers;
237
238 struct ofport_dpif *odp_port_to_ofport(const struct dpif_backer *, odp_port_t);
239 \f
240 /* A bridge based on a "dpif" datapath. */
241
242 struct ofproto_dpif {
243 struct hmap_node all_ofproto_dpifs_node; /* In 'all_ofproto_dpifs'. */
244 struct ofproto up;
245 struct dpif_backer *backer;
246
247 /* Unique identifier for this instantiation of this bridge in this running
248 * process. */
249 struct uuid uuid;
250
251 ATOMIC(ovs_version_t) tables_version; /* For classifier lookups. */
252
253 uint64_t dump_seq; /* Last read of udpif_dump_seq(). */
254
255 /* Special OpenFlow rules. */
256 struct rule_dpif *miss_rule; /* Sends flow table misses to controller. */
257 struct rule_dpif *no_packet_in_rule; /* Drops flow table misses. */
258 struct rule_dpif *drop_frags_rule; /* Used in OFPUTIL_FRAG_DROP mode. */
259
260 /* Bridging. */
261 struct netflow *netflow;
262 struct dpif_sflow *sflow;
263 struct dpif_ipfix *ipfix;
264 struct hmap bundles; /* Contains "struct ofbundle"s. */
265 struct mac_learning *ml;
266 struct mcast_snooping *ms;
267 bool has_bonded_bundles;
268 bool lacp_enabled;
269 struct mbridge *mbridge;
270
271 struct ovs_mutex stats_mutex;
272 struct netdev_stats stats OVS_GUARDED; /* To account packets generated and
273 * consumed in userspace. */
274
275 /* Spanning tree. */
276 struct stp *stp;
277 long long int stp_last_tick;
278
279 /* Rapid Spanning Tree. */
280 struct rstp *rstp;
281 long long int rstp_last_tick;
282
283 /* Ports. */
284 struct sset ports; /* Set of standard port names. */
285 struct sset ghost_ports; /* Ports with no datapath port. */
286 struct sset port_poll_set; /* Queued names for port_poll() reply. */
287 int port_poll_errno; /* Last errno for port_poll() reply. */
288 uint64_t change_seq; /* Connectivity status changes. */
289
290 /* Work queues. */
291 struct guarded_list ams; /* Contains "struct ofproto_async_msgs"s. */
292 struct seq *ams_seq; /* For notifying 'ams' reception. */
293 uint64_t ams_seqno;
294 };
295
296 /* All existing ofproto_dpif instances, indexed by ->up.name. */
297 extern struct hmap all_ofproto_dpifs;
298
299 struct ofproto_dpif *ofproto_dpif_lookup(const char *name);
300
301 ovs_version_t ofproto_dpif_get_tables_version(struct ofproto_dpif *);
302
303 void ofproto_dpif_credit_table_stats(struct ofproto_dpif *, uint8_t table_id,
304 uint64_t n_matches, uint64_t n_misses);
305
306 int ofproto_dpif_execute_actions(struct ofproto_dpif *, ovs_version_t,
307 const struct flow *, struct rule_dpif *,
308 const struct ofpact *, size_t ofpacts_len,
309 struct dp_packet *);
310 int ofproto_dpif_execute_actions__(struct ofproto_dpif *, ovs_version_t,
311 const struct flow *, struct rule_dpif *,
312 const struct ofpact *, size_t ofpacts_len,
313 int depth, int resubmits,
314 struct dp_packet *);
315 void ofproto_dpif_send_async_msg(struct ofproto_dpif *,
316 struct ofproto_async_msg *);
317 int ofproto_dpif_send_packet(const struct ofport_dpif *, bool oam,
318 struct dp_packet *);
319 enum ofperr ofproto_dpif_flow_mod_init_for_learn(
320 struct ofproto_dpif *, const struct ofputil_flow_mod *,
321 struct ofproto_flow_mod *);
322
323 struct ofport_dpif *ofp_port_to_ofport(const struct ofproto_dpif *,
324 ofp_port_t);
325
326 int ofproto_dpif_add_internal_flow(struct ofproto_dpif *,
327 const struct match *, int priority,
328 uint16_t idle_timeout,
329 const struct ofpbuf *ofpacts,
330 struct rule **rulep);
331 int ofproto_dpif_delete_internal_flow(struct ofproto_dpif *, struct match *,
332 int priority);
333
334 bool ovs_native_tunneling_is_on(struct ofproto_dpif *);
335
336 #endif /* ofproto-dpif.h */