]>
Commit | Line | Data |
---|---|---|
535e3acf | 1 | /* Copyright (c) 2009-2017 Nicira, Inc. |
9583bc14 EJ |
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 | ||
07a3cd5c | 18 | /* ofproto-dpif -- DPIF based ofproto implementation. |
e1ec7dd4 | 19 | * |
07a3cd5c | 20 | * ofproto-dpif provides an ofproto implementation for those platforms which |
e1ec7dd4 | 21 | * implement the netdev and dpif interface defined in netdev.h and dpif.h. The |
1139c77d | 22 | * most important of which is the Linux Kernel Module (dpif-netlink), but |
e1ec7dd4 EJ |
23 | * alternatives are supported such as a userspace only implementation |
24 | * (dpif-netdev), and a dummy implementation used for unit testing. | |
25 | * | |
07a3cd5c | 26 | * ofproto-dpif is divided into three major chunks. |
e1ec7dd4 EJ |
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 | |
07a3cd5c | 35 | * ofproto-dpif-upcall is responsible for retrieving upcalls from the kernel, |
e1ec7dd4 EJ |
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 | |
07a3cd5c BP |
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" | |
333ad77d | 53 | #include "id-pool.h" |
07a3cd5c BP |
54 | #include "ovs-thread.h" |
55 | #include "ofproto-provider.h" | |
56 | #include "util.h" | |
07a3cd5c BP |
57 | |
58 | struct dpif_flow_stats; | |
59 | struct ofproto_async_msg; | |
60 | struct ofproto_dpif; | |
911b4a7e | 61 | struct uuid; |
07a3cd5c | 62 | struct xlate_cache; |
06db81cc | 63 | struct xlate_ctx; |
07a3cd5c BP |
64 | |
65 | /* Number of implemented OpenFlow tables. */ | |
66 | enum { N_TABLES = 255 }; | |
67 | enum { TBL_INTERNAL = N_TABLES - 1 }; /* Used for internal hidden rules. */ | |
68 | BUILD_ASSERT_DECL(N_TABLES >= 2 && N_TABLES <= 255); | |
69 | ||
70 | struct rule_dpif { | |
71 | struct rule up; | |
72 | ||
73 | /* These statistics: | |
74 | * | |
75 | * - Do include packets and bytes from datapath flows which have not | |
76 | * recently been processed by a revalidator. */ | |
77 | struct ovs_mutex stats_mutex; | |
16441315 | 78 | struct dpif_flow_detailed_stats stats OVS_GUARDED; |
07a3cd5c BP |
79 | |
80 | /* In non-NULL, will point to a new rule (for which a reference is held) to | |
81 | * which all the stats updates should be forwarded. This exists only | |
82 | * transitionally when flows are replaced. | |
83 | * | |
84 | * Protected by stats_mutex. If both 'rule->stats_mutex' and | |
85 | * 'rule->new_rule->stats_mutex' must be held together, acquire them in that | |
86 | * order, */ | |
87 | struct rule_dpif *new_rule OVS_GUARDED; | |
88 | bool forward_counts OVS_GUARDED; /* Forward counts? 'used' time will be | |
89 | * forwarded in all cases. */ | |
90 | ||
91 | /* If non-zero then the recirculation id that has | |
92 | * been allocated for use with this rule. | |
93 | * The recirculation id and associated internal flow should | |
94 | * be freed when the rule is freed */ | |
95 | uint32_t recirc_id; | |
96 | }; | |
97 | ||
98 | struct rule_dpif *rule_dpif_lookup_from_table(struct ofproto_dpif *, | |
99 | ovs_version_t, struct flow *, | |
100 | struct flow_wildcards *, | |
101 | const struct dpif_flow_stats *, | |
102 | uint8_t *table_id, | |
103 | ofp_port_t in_port, | |
104 | bool may_packet_in, | |
105 | bool honor_table_miss, | |
106 | struct xlate_cache *); | |
107 | ||
108 | void rule_dpif_credit_stats(struct rule_dpif *, | |
16441315 | 109 | const struct dpif_flow_stats *, bool); |
07a3cd5c BP |
110 | |
111 | void rule_set_recirc_id(struct rule *, uint32_t id); | |
112 | ||
113 | /* Returns true if 'rule' is an internal rule, false otherwise. */ | |
114 | static inline bool | |
115 | rule_dpif_is_internal(const struct rule_dpif *rule) | |
116 | { | |
117 | return rule->up.table_id == TBL_INTERNAL; | |
118 | } | |
119 | \f | |
120 | /* Groups. */ | |
121 | ||
2e3fd24c JS |
122 | enum group_selection_method { |
123 | SEL_METHOD_DEFAULT, | |
124 | SEL_METHOD_DP_HASH, | |
125 | SEL_METHOD_HASH, | |
126 | }; | |
127 | ||
07a3cd5c BP |
128 | struct group_dpif { |
129 | struct ofgroup up; | |
130 | ||
131 | /* These statistics: | |
132 | * | |
133 | * - Do include packets and bytes from datapath flows which have not | |
134 | * recently been processed by a revalidator. */ | |
135 | struct ovs_mutex stats_mutex; | |
136 | uint64_t packet_count OVS_GUARDED; /* Number of packets received. */ | |
137 | uint64_t byte_count OVS_GUARDED; /* Number of bytes received. */ | |
2e3fd24c JS |
138 | |
139 | enum group_selection_method selection_method; | |
140 | enum ovs_hash_alg hash_alg; /* dp_hash algorithm to be applied. */ | |
141 | uint32_t hash_basis; /* Basis for dp_hash. */ | |
142 | uint32_t hash_mask; /* Used to mask dp_hash (2^N - 1).*/ | |
143 | struct ofputil_bucket **hash_map; /* Map hash values to buckets. */ | |
07a3cd5c BP |
144 | }; |
145 | ||
146 | void group_dpif_credit_stats(struct group_dpif *, | |
147 | struct ofputil_bucket *, | |
148 | const struct dpif_flow_stats *); | |
149 | struct group_dpif *group_dpif_lookup(struct ofproto_dpif *, | |
150 | uint32_t group_id, ovs_version_t version, | |
151 | bool take_ref); | |
2e3fd24c | 152 | |
07a3cd5c BP |
153 | \f |
154 | /* Backers. | |
155 | * | |
156 | * A "backer" is the datapath (dpif) on which an dpif-based bridge (an | |
157 | * ofproto-dpif) resides. A backer can host several bridges, but a bridge is | |
158 | * backed by only a single dpif. */ | |
e1ec7dd4 | 159 | |
b440dd8c | 160 | |
1c2f091b AZ |
161 | /* DPIF_SUPPORT_FIELD(TYPE, FIELD_NAME, FIELD_DESCRIPTION) |
162 | * | |
163 | * Each 'DPIF_SUPPORT_FIELD' defines a member in 'struct dpif_backer_support' | |
164 | * and represents support for a datapath action. | |
165 | * They are defined as macros to keep 'dpif_show_support()' in sync | |
166 | * as new fields are added. */ | |
167 | #define DPIF_SUPPORT_FIELDS \ | |
1c2f091b AZ |
168 | /* True if the datapath supports masked data in OVS_ACTION_ATTR_SET \ |
169 | * actions. */ \ | |
170 | DPIF_SUPPORT_FIELD(bool, masked_set_action, "Masked set action") \ | |
171 | \ | |
172 | /* True if the datapath supports tnl_push and pop actions. */ \ | |
173 | DPIF_SUPPORT_FIELD(bool, tnl_push_pop, "Tunnel push pop") \ | |
174 | \ | |
175 | /* True if the datapath supports OVS_FLOW_ATTR_UFID. */ \ | |
176 | DPIF_SUPPORT_FIELD(bool, ufid, "Ufid") \ | |
177 | \ | |
178 | /* True if the datapath supports OVS_ACTION_ATTR_TRUNC action. */ \ | |
179 | DPIF_SUPPORT_FIELD(bool, trunc, "Truncate action") \ | |
180 | \ | |
181 | /* True if the datapath supports OVS_ACTION_ATTR_CLONE action. */ \ | |
182 | DPIF_SUPPORT_FIELD(bool, clone, "Clone action") \ | |
183 | \ | |
184 | /* Maximum level of nesting allowed by OVS_ACTION_ATTR_SAMPLE action. */\ | |
adfe7a0b JR |
185 | DPIF_SUPPORT_FIELD(size_t, sample_nesting, "Sample nesting") \ |
186 | \ | |
187 | /* OVS_CT_ATTR_EVENTMASK supported by OVS_ACTION_ATTR_CT action. */ \ | |
1fe178d2 EG |
188 | DPIF_SUPPORT_FIELD(bool, ct_eventmask, "Conntrack eventmask") \ |
189 | \ | |
190 | /* True if the datapath supports OVS_ACTION_ATTR_CT_CLEAR action. */ \ | |
6a0b0d3b JS |
191 | DPIF_SUPPORT_FIELD(bool, ct_clear, "Conntrack clear") \ |
192 | \ | |
193 | /* Highest supported dp_hash algorithm. */ \ | |
5b34f8fc NS |
194 | DPIF_SUPPORT_FIELD(size_t, max_hash_alg, "Max dp_hash algorithm") \ |
195 | \ | |
187bb41f YHW |
196 | /* True if the datapath supports OVS_ACTION_ATTR_CHECK_PKT_LEN. */ \ |
197 | DPIF_SUPPORT_FIELD(bool, check_pkt_len, "Check pkt length action") \ | |
198 | \ | |
199 | /* True if the datapath supports OVS_CT_ATTR_TIMEOUT in \ | |
200 | * OVS_ACTION_ATTR_CT action. */ \ | |
a13a0209 AT |
201 | DPIF_SUPPORT_FIELD(bool, ct_timeout, "Conntrack timeout policy") \ |
202 | \ | |
203 | /* True if the datapath supports explicit drop action. */ \ | |
9df65060 VDA |
204 | DPIF_SUPPORT_FIELD(bool, explicit_drop_action, "Explicit Drop action") \ |
205 | \ | |
206 | /* True if the datapath supports balance_tcp optimization */ \ | |
207 | DPIF_SUPPORT_FIELD(bool, lb_output_action, "Optimized Balance TCP mode") | |
a13a0209 | 208 | |
2494ccd7 | 209 | |
1c2f091b AZ |
210 | /* Stores the various features which the corresponding backer supports. */ |
211 | struct dpif_backer_support { | |
212 | #define DPIF_SUPPORT_FIELD(TYPE, NAME, TITLE) TYPE NAME; | |
213 | DPIF_SUPPORT_FIELDS | |
214 | #undef DPIF_SUPPORT_FIELD | |
aaca4fe0 | 215 | |
2494ccd7 JS |
216 | /* Each member represents support for related OVS_KEY_ATTR_* fields. */ |
217 | struct odp_support odp; | |
b440dd8c JS |
218 | }; |
219 | ||
07a3cd5c BP |
220 | /* Reasons that we might need to revalidate every datapath flow, and |
221 | * corresponding coverage counters. | |
222 | * | |
223 | * A value of 0 means that there is no need to revalidate. | |
224 | * | |
225 | * It would be nice to have some cleaner way to integrate with coverage | |
226 | * counters, but with only a few reasons I guess this is good enough for | |
227 | * now. */ | |
228 | enum revalidate_reason { | |
229 | REV_RECONFIGURE = 1, /* Switch configuration changed. */ | |
230 | REV_STP, /* Spanning tree protocol port status change. */ | |
231 | REV_RSTP, /* RSTP port status change. */ | |
232 | REV_BOND, /* Bonding changed. */ | |
233 | REV_PORT_TOGGLED, /* Port enabled or disabled by CFM, LACP, ...*/ | |
234 | REV_FLOW_TABLE, /* Flow table changed. */ | |
235 | REV_MAC_LEARNING, /* Mac learning changed. */ | |
236 | REV_MCAST_SNOOPING, /* Multicast snooping changed. */ | |
237 | }; | |
621b8064 | 238 | |
07a3cd5c BP |
239 | /* All datapaths of a given type share a single dpif backer instance. */ |
240 | struct dpif_backer { | |
241 | char *type; | |
242 | int refcount; | |
243 | struct dpif *dpif; | |
244 | struct udpif *udpif; | |
a027899e | 245 | |
07a3cd5c BP |
246 | struct ovs_rwlock odp_to_ofport_lock; |
247 | struct hmap odp_to_ofport_map OVS_GUARDED; /* Contains "struct ofport"s. */ | |
a027899e | 248 | |
07a3cd5c | 249 | struct simap tnl_backers; /* Set of dpif ports backing tunnels. */ |
70742c7f | 250 | |
07a3cd5c | 251 | enum revalidate_reason need_revalidate; /* Revalidate all flows. */ |
70742c7f | 252 | |
07a3cd5c | 253 | bool recv_set_enable; /* Enables or disables receiving packets. */ |
70742c7f | 254 | |
333ad77d AZ |
255 | /* Meter. */ |
256 | struct id_pool *meter_ids; /* Datapath meter allocation. */ | |
257 | ||
993cae67 YHW |
258 | /* Connection tracking. */ |
259 | struct id_pool *tp_ids; /* Datapath timeout policy id | |
260 | * allocation. */ | |
261 | struct cmap ct_zones; /* "struct ct_zone"s indexed by zone | |
262 | * id. */ | |
263 | struct hmap ct_tps; /* "struct ct_timeout_policy"s indexed | |
264 | * by timeout policy (struct simap). */ | |
265 | struct ovs_list ct_tp_kill_list; /* A list of timeout policy to be | |
266 | * deleted. */ | |
267 | ||
07a3cd5c BP |
268 | /* Version string of the datapath stored in OVSDB. */ |
269 | char *dp_version_string; | |
003ce655 | 270 | |
07a3cd5c | 271 | /* Datapath feature support. */ |
88186383 AZ |
272 | struct dpif_backer_support bt_support; /* Boot time support. Set once |
273 | when vswitch starts up, then | |
274 | it is read only through out | |
275 | the life time of vswitchd. */ | |
276 | struct dpif_backer_support rt_support; /* Runtime support. Can be | |
277 | set to a lower level in | |
278 | feature than 'bt_support'. */ | |
279 | ||
07a3cd5c BP |
280 | struct atomic_count tnl_count; |
281 | }; | |
70742c7f | 282 | |
07a3cd5c BP |
283 | /* All existing ofproto_backer instances, indexed by ofproto->up.type. */ |
284 | extern struct shash all_dpif_backers; | |
56c091ec | 285 | |
07a3cd5c BP |
286 | struct ofport_dpif *odp_port_to_ofport(const struct dpif_backer *, odp_port_t); |
287 | \f | |
288 | /* A bridge based on a "dpif" datapath. */ | |
289 | ||
290 | struct ofproto_dpif { | |
911b4a7e JP |
291 | /* In 'all_ofproto_dpifs_by_name'. */ |
292 | struct hmap_node all_ofproto_dpifs_by_name_node; | |
293 | ||
294 | /* In 'all_ofproto_dpifs_by_uuid'. */ | |
295 | struct hmap_node all_ofproto_dpifs_by_uuid_node; | |
296 | ||
07a3cd5c BP |
297 | struct ofproto up; |
298 | struct dpif_backer *backer; | |
299 | ||
300 | /* Unique identifier for this instantiation of this bridge in this running | |
301 | * process. */ | |
302 | struct uuid uuid; | |
303 | ||
304 | ATOMIC(ovs_version_t) tables_version; /* For classifier lookups. */ | |
305 | ||
306 | uint64_t dump_seq; /* Last read of udpif_dump_seq(). */ | |
307 | ||
308 | /* Special OpenFlow rules. */ | |
309 | struct rule_dpif *miss_rule; /* Sends flow table misses to controller. */ | |
310 | struct rule_dpif *no_packet_in_rule; /* Drops flow table misses. */ | |
311 | struct rule_dpif *drop_frags_rule; /* Used in OFPUTIL_FRAG_DROP mode. */ | |
312 | ||
313 | /* Bridging. */ | |
314 | struct netflow *netflow; | |
315 | struct dpif_sflow *sflow; | |
316 | struct dpif_ipfix *ipfix; | |
317 | struct hmap bundles; /* Contains "struct ofbundle"s. */ | |
318 | struct mac_learning *ml; | |
319 | struct mcast_snooping *ms; | |
320 | bool has_bonded_bundles; | |
321 | bool lacp_enabled; | |
322 | struct mbridge *mbridge; | |
323 | ||
324 | struct ovs_mutex stats_mutex; | |
325 | struct netdev_stats stats OVS_GUARDED; /* To account packets generated and | |
326 | * consumed in userspace. */ | |
327 | ||
328 | /* Spanning tree. */ | |
329 | struct stp *stp; | |
330 | long long int stp_last_tick; | |
331 | ||
332 | /* Rapid Spanning Tree. */ | |
333 | struct rstp *rstp; | |
334 | long long int rstp_last_tick; | |
335 | ||
336 | /* Ports. */ | |
337 | struct sset ports; /* Set of standard port names. */ | |
338 | struct sset ghost_ports; /* Ports with no datapath port. */ | |
339 | struct sset port_poll_set; /* Queued names for port_poll() reply. */ | |
340 | int port_poll_errno; /* Last errno for port_poll() reply. */ | |
341 | uint64_t change_seq; /* Connectivity status changes. */ | |
342 | ||
343 | /* Work queues. */ | |
344 | struct guarded_list ams; /* Contains "struct ofproto_async_msgs"s. */ | |
345 | struct seq *ams_seq; /* For notifying 'ams' reception. */ | |
346 | uint64_t ams_seqno; | |
44810e6d VDA |
347 | |
348 | bool is_controller_connected; /* True if any controller admitted this | |
349 | * switch connection. */ | |
07a3cd5c | 350 | }; |
ad3efdcb | 351 | |
911b4a7e JP |
352 | struct ofproto_dpif *ofproto_dpif_lookup_by_name(const char *name); |
353 | struct ofproto_dpif *ofproto_dpif_lookup_by_uuid(const struct uuid *uuid); | |
d13ee228 | 354 | |
07a3cd5c | 355 | ovs_version_t ofproto_dpif_get_tables_version(struct ofproto_dpif *); |
9583bc14 | 356 | |
07a3cd5c BP |
357 | void ofproto_dpif_credit_table_stats(struct ofproto_dpif *, uint8_t table_id, |
358 | uint64_t n_matches, uint64_t n_misses); | |
f4fb341b | 359 | |
1f4a8933 JR |
360 | int ofproto_dpif_execute_actions(struct ofproto_dpif *, ovs_version_t, |
361 | const struct flow *, struct rule_dpif *, | |
362 | const struct ofpact *, size_t ofpacts_len, | |
363 | struct dp_packet *); | |
364 | int ofproto_dpif_execute_actions__(struct ofproto_dpif *, ovs_version_t, | |
365 | const struct flow *, struct rule_dpif *, | |
366 | const struct ofpact *, size_t ofpacts_len, | |
2d9b49dd | 367 | int depth, int resubmits, |
790c5d26 | 368 | struct dp_packet *); |
a2b53dec BP |
369 | void ofproto_dpif_send_async_msg(struct ofproto_dpif *, |
370 | struct ofproto_async_msg *); | |
2eb79142 JG |
371 | int ofproto_dpif_send_packet(const struct ofport_dpif *, bool oam, |
372 | struct dp_packet *); | |
07a3cd5c BP |
373 | enum ofperr ofproto_dpif_flow_mod_init_for_learn( |
374 | struct ofproto_dpif *, const struct ofputil_flow_mod *, | |
375 | struct ofproto_flow_mod *); | |
46c88433 | 376 | |
e672ff9b JR |
377 | struct ofport_dpif *ofp_port_to_ofport(const struct ofproto_dpif *, |
378 | ofp_port_t); | |
8449c4d6 | 379 | |
adcf00ba | 380 | int ofproto_dpif_add_internal_flow(struct ofproto_dpif *, |
6a6b7060 | 381 | struct match *, int priority, |
290ad78a | 382 | uint16_t idle_timeout, |
adcf00ba AZ |
383 | const struct ofpbuf *ofpacts, |
384 | struct rule **rulep); | |
385 | int ofproto_dpif_delete_internal_flow(struct ofproto_dpif *, struct match *, | |
386 | int priority); | |
9df65060 | 387 | int ofproto_dpif_add_lb_output_buckets(struct ofproto_dpif *, uint32_t bond_id, |
91fc374a | 388 | const ofp_port_t *member_map); |
9df65060 VDA |
389 | int ofproto_dpif_delete_lb_output_buckets(struct ofproto_dpif *, |
390 | uint32_t bond_id); | |
391 | bool ovs_lb_output_action_supported(struct ofproto_dpif *); | |
290835f9 | 392 | |
07a3cd5c | 393 | bool ovs_native_tunneling_is_on(struct ofproto_dpif *); |
003ce655 | 394 | |
187bb41f YHW |
395 | bool ofproto_dpif_ct_zone_timeout_policy_get_name( |
396 | const struct dpif_backer *backer, uint16_t zone, uint16_t dl_type, | |
397 | uint8_t nw_proto, char **tp_name, bool *unwildcard); | |
398 | ||
a13a0209 AT |
399 | bool ovs_explicit_drop_action_supported(struct ofproto_dpif *); |
400 | ||
9583bc14 | 401 | #endif /* ofproto-dpif.h */ |