]>
Commit | Line | Data |
---|---|---|
d08a2e92 | 1 | /* |
04f48a68 | 2 | * Copyright (c) 2009-2017 Nicira, Inc. |
d08a2e92 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 | ||
5bee6e26 JP |
17 | #ifndef OFPROTO_OFPROTO_PROVIDER_H |
18 | #define OFPROTO_OFPROTO_PROVIDER_H 1 | |
d08a2e92 | 19 | |
15aaf599 BP |
20 | /* Definitions for use within ofproto. |
21 | * | |
22 | * | |
23 | * Thread-safety | |
24 | * ============= | |
25 | * | |
26 | * Lots of ofproto data structures are only accessed from a single thread. | |
27 | * Those data structures are generally not thread-safe. | |
28 | * | |
29 | * The ofproto-dpif ofproto implementation accesses the flow table from | |
30 | * multiple threads, including modifying the flow table from multiple threads | |
31 | * via the "learn" action, so the flow table and various structures that index | |
32 | * it have been made thread-safe. Refer to comments on individual data | |
33 | * structures for details. | |
34 | */ | |
d08a2e92 | 35 | |
1de11730 | 36 | #include "cfm.h" |
abe529af | 37 | #include "classifier.h" |
35412852 | 38 | #include "guarded-list.h" |
254750ce | 39 | #include "heap.h" |
98eaac36 | 40 | #include "hindex.h" |
fe59694b | 41 | #include "object-collection.h" |
b598f214 | 42 | #include "ofproto/ofproto.h" |
b19bab5b | 43 | #include "openvswitch/list.h" |
b598f214 | 44 | #include "openvswitch/ofp-actions.h" |
f4248336 | 45 | #include "openvswitch/ofp-util.h" |
e03c096d | 46 | #include "openvswitch/ofp-errors.h" |
a2143702 | 47 | #include "ovs-atomic.h" |
06a0f3e2 | 48 | #include "ovs-rcu.h" |
a3779dbc | 49 | #include "ovs-thread.h" |
ee89ea7b | 50 | #include "openvswitch/shash.h" |
e1b1d06a | 51 | #include "simap.h" |
abe529af | 52 | #include "timeval.h" |
8d8ab6c2 | 53 | #include "tun-metadata.h" |
5d08a275 | 54 | #include "versions.h" |
aafee638 | 55 | #include "vl-mff-map.h" |
abe529af | 56 | |
81a76618 | 57 | struct match; |
75a75043 | 58 | struct ofputil_flow_mod; |
ccc09689 | 59 | struct bfd_cfg; |
9cae45dc | 60 | struct meter; |
b20f4073 | 61 | struct ofoperation; |
1f4a8933 | 62 | struct ofproto_packet_out; |
d4f6865c | 63 | struct smap; |
75a75043 | 64 | |
abe7b10f BP |
65 | extern struct ovs_mutex ofproto_mutex; |
66 | ||
abe529af BP |
67 | /* An OpenFlow switch. |
68 | * | |
69 | * With few exceptions, ofproto implementations may look at these fields but | |
70 | * should not modify them. */ | |
71 | struct ofproto { | |
6e492d81 | 72 | struct hmap_node hmap_node; /* In global 'all_ofprotos' hmap. */ |
abe529af BP |
73 | const struct ofproto_class *ofproto_class; |
74 | char *type; /* Datapath type. */ | |
75 | char *name; /* Datapath name. */ | |
abe529af BP |
76 | |
77 | /* Settings. */ | |
78 | uint64_t fallback_dpid; /* Datapath ID if no better choice found. */ | |
79 | uint64_t datapath_id; /* Datapath ID. */ | |
8402c74b SS |
80 | bool forward_bpdu; /* Option to allow forwarding of BPDU frames |
81 | * when NORMAL action is invoked. */ | |
71dab241 | 82 | char *mfr_desc; /* Manufacturer (NULL for default). */ |
061bfea4 BP |
83 | char *hw_desc; /* Hardware (NULL for default). */ |
84 | char *sw_desc; /* Software version (NULL for default). */ | |
85 | char *serial_desc; /* Serial number (NULL for default). */ | |
86 | char *dp_desc; /* Datapath description (NULL for default). */ | |
ad99e2ed | 87 | enum ofputil_frag_handling frag_handling; |
abe529af BP |
88 | |
89 | /* Datapath. */ | |
abe529af BP |
90 | struct hmap ports; /* Contains "struct ofport"s. */ |
91 | struct shash port_by_name; | |
e1b1d06a | 92 | struct simap ofp_requests; /* OpenFlow port number requests. */ |
430dbb14 AW |
93 | uint16_t alloc_port_no; /* Last allocated OpenFlow port number. */ |
94 | uint16_t max_ports; /* Max possible OpenFlow port num, plus one. */ | |
fdcea803 | 95 | struct hmap ofport_usage; /* Map ofport to last used time. */ |
da4a6191 | 96 | uint64_t change_seq; /* Change sequence for netdev status. */ |
abe529af | 97 | |
6c1491fb | 98 | /* Flow tables. */ |
448c2fa8 | 99 | long long int eviction_group_timer; /* For rate limited reheapification. */ |
d0918789 | 100 | struct oftable *tables; |
6c1491fb | 101 | int n_tables; |
44e0c35d | 102 | ovs_version_t tables_version; /* Controls which rules are visible to |
1c38055d | 103 | * table lookups. */ |
abe529af | 104 | |
2c916028 BP |
105 | /* Rules indexed on their cookie values, in all flow tables. */ |
106 | struct hindex cookies OVS_GUARDED_BY(ofproto_mutex); | |
35f48b8b | 107 | struct hmap learned_cookies OVS_GUARDED_BY(ofproto_mutex); |
98eaac36 | 108 | |
abe7b10f | 109 | /* List of expirable flows, in all flow tables. */ |
ca6ba700 | 110 | struct ovs_list expirable OVS_GUARDED_BY(ofproto_mutex); |
e503cc19 | 111 | |
9cae45dc JR |
112 | /* Meter table. |
113 | * OpenFlow meters start at 1. To avoid confusion we leave the first | |
114 | * pointer in the array un-used, and index directly with the OpenFlow | |
115 | * meter_id. */ | |
116 | struct ofputil_meter_features meter_features; | |
117 | struct meter **meters; /* 'meter_features.max_meter' + 1 pointers. */ | |
118 | ||
abe529af BP |
119 | /* OpenFlow connections. */ |
120 | struct connmgr *connmgr; | |
7ee20df1 | 121 | |
ada3428f | 122 | int min_mtu; /* Current MTU of non-internal ports. */ |
7395c052 NZ |
123 | |
124 | /* Groups. */ | |
db88b35c | 125 | struct cmap groups; /* Contains "struct ofgroup"s. */ |
7395c052 NZ |
126 | uint32_t n_groups[4] OVS_GUARDED; /* # of existing groups of each type. */ |
127 | struct ofputil_group_features ogf; | |
8d8ab6c2 JG |
128 | |
129 | /* Tunnel TLV mapping table. */ | |
130 | OVSRCU_TYPE(struct tun_table *) metadata_tab; | |
04f48a68 YHW |
131 | |
132 | /* Variable length mf_field mapping. Stores all configured variable length | |
133 | * meta-flow fields (struct mf_field) in a switch. */ | |
134 | struct vl_mff_map vl_mff_map; | |
abe529af BP |
135 | }; |
136 | ||
0f5f95a9 | 137 | void ofproto_init_tables(struct ofproto *, int n_tables); |
430dbb14 | 138 | void ofproto_init_max_ports(struct ofproto *, uint16_t max_ports); |
0f5f95a9 | 139 | |
abe529af | 140 | struct ofproto *ofproto_lookup(const char *name); |
4e022ec0 | 141 | struct ofport *ofproto_get_port(const struct ofproto *, ofp_port_t ofp_port); |
abe529af BP |
142 | |
143 | /* An OpenFlow port within a "struct ofproto". | |
1a6495b5 BP |
144 | * |
145 | * The port's name is netdev_get_name(port->netdev). | |
abe529af BP |
146 | * |
147 | * With few exceptions, ofproto implementations may look at these fields but | |
148 | * should not modify them. */ | |
149 | struct ofport { | |
abe529af | 150 | struct hmap_node hmap_node; /* In struct ofproto's "ports" hmap. */ |
6e492d81 | 151 | struct ofproto *ofproto; /* The ofproto that contains this port. */ |
abe529af | 152 | struct netdev *netdev; |
9e1fd49b | 153 | struct ofputil_phy_port pp; |
4e022ec0 | 154 | ofp_port_t ofp_port; /* OpenFlow port number. */ |
61501798 | 155 | uint64_t change_seq; |
65e0be10 | 156 | long long int created; /* Time created, in msec. */ |
9197df76 | 157 | int mtu; |
abe529af BP |
158 | }; |
159 | ||
9e1fd49b | 160 | void ofproto_port_set_state(struct ofport *, enum ofputil_port_state); |
5a2dfd47 | 161 | |
c2f0373a BP |
162 | /* OpenFlow table flags: |
163 | * | |
164 | * - "Hidden" tables are not included in OpenFlow operations that operate on | |
165 | * "all tables". For example, a request for flow stats on all tables will | |
166 | * omit flows in hidden tables, table stats requests will omit the table | |
167 | * entirely, and the switch features reply will not count the hidden table. | |
168 | * | |
169 | * However, operations that specifically name the particular table still | |
170 | * operate on it. For example, flow_mods and flow stats requests on a | |
171 | * hidden table work. | |
172 | * | |
173 | * To avoid gaps in table IDs (which have unclear validity in OpenFlow), | |
174 | * hidden tables must be the highest-numbered tables that a provider | |
175 | * implements. | |
176 | * | |
177 | * - "Read-only" tables can't be changed through OpenFlow operations. (At | |
178 | * the moment all flow table operations go effectively through OpenFlow, so | |
179 | * this means that read-only tables can't be changed at all after the | |
180 | * read-only flag is set.) | |
181 | * | |
182 | * The generic ofproto layer never sets these flags. An ofproto provider can | |
183 | * set them if it is appropriate. | |
184 | */ | |
5c67e4af BP |
185 | enum oftable_flags { |
186 | OFTABLE_HIDDEN = 1 << 0, /* Hide from most OpenFlow operations. */ | |
adcf00ba AZ |
187 | OFTABLE_READONLY = 1 << 1 /* Don't allow OpenFlow controller to change |
188 | this table. */ | |
5c67e4af BP |
189 | }; |
190 | ||
15aaf599 BP |
191 | /* A flow table within a "struct ofproto". |
192 | * | |
193 | * | |
194 | * Thread-safety | |
195 | * ============= | |
196 | * | |
afae68b1 | 197 | * Adding or removing rules requires holding ofproto_mutex. |
15aaf599 | 198 | * |
afae68b1 JR |
199 | * Rules in 'cls' are RCU protected. For extended access to a rule, try |
200 | * incrementing its ref_count with ofproto_rule_try_ref(), or | |
201 | * ofproto_rule_ref(), if the rule is still known to be in 'cls'. A rule | |
202 | * will be freed using ovsrcu_postpone() once its 'ref_count' reaches zero. | |
15aaf599 | 203 | * |
afae68b1 | 204 | * Modifying a rule requires the rule's own mutex. |
15aaf599 | 205 | * |
afae68b1 JR |
206 | * Freeing a rule requires ofproto_mutex. After removing the rule from the |
207 | * classifier, release a ref_count from the rule ('cls''s reference to the | |
208 | * rule). | |
15aaf599 BP |
209 | * |
210 | * Refer to the thread-safety notes on struct rule for more information.*/ | |
d0918789 | 211 | struct oftable { |
5c67e4af | 212 | enum oftable_flags flags; |
d0918789 | 213 | struct classifier cls; /* Contains "struct rule"s. */ |
254750ce BP |
214 | char *name; /* Table name exposed via OpenFlow, or NULL. */ |
215 | ||
216 | /* Maximum number of flows or UINT_MAX if there is no limit besides any | |
217 | * limit imposed by resource limitations. */ | |
218 | unsigned int max_flows; | |
d79e3d70 JR |
219 | /* Current number of flows, not counting temporary duplicates nor deferred |
220 | * deletions. */ | |
221 | unsigned int n_flows; | |
254750ce BP |
222 | |
223 | /* These members determine the handling of an attempt to add a flow that | |
224 | * would cause the table to have more than 'max_flows' flows. | |
225 | * | |
226 | * If 'eviction_fields' is NULL, overflows will be rejected with an error. | |
227 | * | |
228 | * If 'eviction_fields' is nonnull (regardless of whether n_eviction_fields | |
229 | * is nonzero), an overflow will cause a flow to be removed. The flow to | |
230 | * be removed is chosen to give fairness among groups distinguished by | |
231 | * different values for the subfields within 'groups'. */ | |
232 | struct mf_subfield *eviction_fields; | |
233 | size_t n_eviction_fields; | |
234 | ||
235 | /* Eviction groups. | |
236 | * | |
237 | * When a flow is added that would cause the table to have more than | |
238 | * 'max_flows' flows, and 'eviction_fields' is nonnull, these groups are | |
239 | * used to decide which rule to evict: the rule is chosen from the eviction | |
240 | * group that contains the greatest number of rules.*/ | |
241 | uint32_t eviction_group_id_basis; | |
242 | struct hmap eviction_groups_by_id; | |
243 | struct heap eviction_groups_by_size; | |
67761761 | 244 | |
82c22d34 | 245 | /* Flow table miss handling configuration. */ |
3c1bb396 | 246 | ATOMIC(enum ofputil_table_miss) miss_config; |
d611866c | 247 | |
82c22d34 BP |
248 | /* Eviction is enabled if either the client (vswitchd) enables it or an |
249 | * OpenFlow controller enables it; thus, a nonzero value indicates that | |
250 | * eviction is enabled. */ | |
251 | #define EVICTION_CLIENT (1 << 0) /* Set to 1 if client enables eviction. */ | |
252 | #define EVICTION_OPENFLOW (1 << 1) /* Set to 1 if OpenFlow enables eviction. */ | |
253 | unsigned int eviction; | |
254 | ||
6c6eedc5 SJ |
255 | /* If zero, vacancy events are disabled. If nonzero, this is the type of |
256 | vacancy event that is enabled: either OFPTR_VACANCY_DOWN or | |
257 | OFPTR_VACANCY_UP. Only one type of vacancy event can be enabled at a | |
258 | time. */ | |
259 | enum ofp14_table_reason vacancy_event; | |
de7d3c07 SJ |
260 | |
261 | /* Non-zero values for vacancy_up and vacancy_down indicates that vacancy | |
262 | * is enabled by table-mod, else these values are set to zero when | |
263 | * vacancy is disabled */ | |
264 | uint8_t vacancy_down; /* Vacancy threshold when space decreases (%). */ | |
265 | uint8_t vacancy_up; /* Vacancy threshold when space increases (%). */ | |
266 | ||
d611866c SH |
267 | atomic_ulong n_matched; |
268 | atomic_ulong n_missed; | |
d0918789 BP |
269 | }; |
270 | ||
271 | /* Assigns TABLE to each oftable, in turn, in OFPROTO. | |
272 | * | |
273 | * All parameters are evaluated multiple times. */ | |
274 | #define OFPROTO_FOR_EACH_TABLE(TABLE, OFPROTO) \ | |
275 | for ((TABLE) = (OFPROTO)->tables; \ | |
276 | (TABLE) < &(OFPROTO)->tables[(OFPROTO)->n_tables]; \ | |
277 | (TABLE)++) | |
278 | ||
abe529af BP |
279 | /* An OpenFlow flow within a "struct ofproto". |
280 | * | |
281 | * With few exceptions, ofproto implementations may look at these fields but | |
15aaf599 BP |
282 | * should not modify them. |
283 | * | |
284 | * | |
285 | * Thread-safety | |
286 | * ============= | |
287 | * | |
288 | * Except near the beginning or ending of its lifespan, rule 'rule' belongs to | |
289 | * the classifier rule->ofproto->tables[rule->table_id].cls. The text below | |
290 | * calls this classifier 'cls'. | |
291 | * | |
292 | * Motivation | |
293 | * ---------- | |
294 | * | |
295 | * The thread safety rules described here for "struct rule" are motivated by | |
296 | * two goals: | |
297 | * | |
298 | * - Prevent threads that read members of "struct rule" from reading bad | |
299 | * data due to changes by some thread concurrently modifying those | |
300 | * members. | |
301 | * | |
302 | * - Prevent two threads making changes to members of a given "struct rule" | |
303 | * from interfering with each other. | |
304 | * | |
305 | * | |
306 | * Rules | |
307 | * ----- | |
308 | * | |
afae68b1 JR |
309 | * A rule 'rule' may be accessed without a risk of being freed by a thread |
310 | * until the thread quiesces (i.e., rules are RCU protected and destructed | |
311 | * using ovsrcu_postpone()). Code that needs to hold onto a rule for a | |
312 | * while should increment 'rule->ref_count' either with ofproto_rule_ref() | |
313 | * (if 'ofproto_mutex' is held), or with ofproto_rule_try_ref() (when some | |
314 | * other thread might remove the rule from 'cls'). ofproto_rule_try_ref() | |
315 | * will fail if the rule has already been scheduled for destruction. | |
15aaf599 BP |
316 | * |
317 | * 'rule->ref_count' protects 'rule' from being freed. It doesn't protect the | |
afae68b1 | 318 | * rule from being deleted from 'cls' (that's 'ofproto_mutex') and it doesn't |
7ea33f75 | 319 | * protect members of 'rule' from modification (that's 'rule->mutex'). |
15aaf599 BP |
320 | * |
321 | * 'rule->mutex' protects the members of 'rule' from modification. It doesn't | |
afae68b1 JR |
322 | * protect the rule from being deleted from 'cls' (that's 'ofproto_mutex') and |
323 | * it doesn't prevent the rule from being freed (that's 'rule->ref_count'). | |
15aaf599 BP |
324 | * |
325 | * Regarding thread safety, the members of a rule fall into the following | |
326 | * categories: | |
327 | * | |
328 | * - Immutable. These members are marked 'const'. | |
329 | * | |
330 | * - Members that may be safely read or written only by code holding | |
331 | * ofproto_mutex. These are marked OVS_GUARDED_BY(ofproto_mutex). | |
332 | * | |
333 | * - Members that may be safely read only by code holding ofproto_mutex or | |
334 | * 'rule->mutex', and safely written only by coding holding ofproto_mutex | |
335 | * AND 'rule->mutex'. These are marked OVS_GUARDED. | |
336 | */ | |
30d0452c JR |
337 | enum OVS_PACKED_ENUM rule_state { |
338 | RULE_INITIALIZED, /* Rule has been initialized, but not inserted to the | |
339 | * ofproto data structures. Versioning makes sure the | |
340 | * rule is not visible to lookups by other threads, even | |
341 | * if the rule is added to a classifier. */ | |
342 | RULE_INSERTED, /* Rule has been inserted to ofproto data structures and | |
343 | * may be visible to lookups by other threads. */ | |
344 | RULE_REMOVED, /* Rule has been removed from ofproto data structures, | |
345 | * and may still be visible to lookups by other threads | |
346 | * until they quiesce, after which the rule will be | |
347 | * removed from the classifier as well. */ | |
348 | }; | |
349 | ||
abe529af | 350 | struct rule { |
49a0e0eb BP |
351 | /* Where this rule resides in an OpenFlow switch. |
352 | * | |
353 | * These are immutable once the rule is constructed, hence 'const'. */ | |
354 | struct ofproto *const ofproto; /* The ofproto that contains this rule. */ | |
355 | const struct cls_rule cr; /* In owning ofproto's classifier. */ | |
356 | const uint8_t table_id; /* Index in ofproto's 'tables' array. */ | |
30d0452c JR |
357 | |
358 | enum rule_state state; | |
49a0e0eb | 359 | |
15aaf599 BP |
360 | /* Protects members marked OVS_GUARDED. |
361 | * Readers only need to hold this mutex. | |
b90d6ee5 JR |
362 | * Writers must hold both this mutex AND ofproto_mutex. |
363 | * By implication writers can read *without* taking this mutex while they | |
364 | * hold ofproto_mutex. */ | |
15aaf599 BP |
365 | struct ovs_mutex mutex OVS_ACQ_AFTER(ofproto_mutex); |
366 | ||
367 | /* Number of references. | |
368 | * The classifier owns one reference. | |
369 | * Any thread trying to keep a rule from being freed should hold its own | |
370 | * reference. */ | |
37bec3d3 | 371 | struct ovs_refcount ref_count; |
abe529af | 372 | |
15aaf599 | 373 | /* A "flow cookie" is the OpenFlow name for a 64-bit value associated with |
82a3160e BP |
374 | * a flow. */ |
375 | const ovs_be64 flow_cookie; /* Immutable once rule is constructed. */ | |
2c916028 | 376 | struct hindex_node cookie_node OVS_GUARDED_BY(ofproto_mutex); |
abe529af | 377 | |
15aaf599 | 378 | enum ofputil_flow_mod_flags flags OVS_GUARDED; |
abe529af | 379 | |
15aaf599 | 380 | /* Timeouts. */ |
a3779dbc EJ |
381 | uint16_t hard_timeout OVS_GUARDED; /* In seconds from ->modified. */ |
382 | uint16_t idle_timeout OVS_GUARDED; /* In seconds from ->used. */ | |
383 | ||
ca26eb44 | 384 | /* Eviction precedence. */ |
cf119e09 | 385 | const uint16_t importance; |
ca26eb44 | 386 | |
f695ebfa JR |
387 | /* Removal reason for sending flow removed message. |
388 | * Used only if 'flags' has OFPUTIL_FF_SEND_FLOW_REM set and if the | |
389 | * value is not OVS_OFPRR_NONE. */ | |
390 | uint8_t removed_reason; | |
391 | ||
15aaf599 | 392 | /* Eviction groups (see comment on struct eviction_group for explanation) . |
884e1dc4 | 393 | * |
15aaf599 BP |
394 | * 'eviction_group' is this rule's eviction group, or NULL if it is not in |
395 | * any eviction group. When 'eviction_group' is nonnull, 'evg_node' is in | |
396 | * the ->eviction_group->rules hmap. */ | |
397 | struct eviction_group *eviction_group OVS_GUARDED_BY(ofproto_mutex); | |
398 | struct heap_node evg_node OVS_GUARDED_BY(ofproto_mutex); | |
ad3efdcb | 399 | |
15aaf599 BP |
400 | /* OpenFlow actions. See struct rule_actions for more thread-safety |
401 | * notes. */ | |
39c94593 | 402 | const struct rule_actions * const actions; |
2b07c8b1 | 403 | |
15aaf599 | 404 | /* In owning meter's 'rules' list. An empty list if there is no meter. */ |
ca6ba700 | 405 | struct ovs_list meter_list_node OVS_GUARDED_BY(ofproto_mutex); |
9cae45dc | 406 | |
15aaf599 BP |
407 | /* Flow monitors (e.g. for NXST_FLOW_MONITOR, related to struct ofmonitor). |
408 | * | |
409 | * 'add_seqno' is the sequence number when this rule was created. | |
410 | * 'modify_seqno' is the sequence number when this rule was last modified. | |
411 | * See 'monitor_seqno' in connmgr.c for more information. */ | |
412 | enum nx_flow_monitor_flags monitor_flags OVS_GUARDED_BY(ofproto_mutex); | |
413 | uint64_t add_seqno OVS_GUARDED_BY(ofproto_mutex); | |
414 | uint64_t modify_seqno OVS_GUARDED_BY(ofproto_mutex); | |
e503cc19 | 415 | |
abe7b10f BP |
416 | /* Optimisation for flow expiry. In ofproto's 'expirable' list if this |
417 | * rule is expirable, otherwise empty. */ | |
ca6ba700 | 418 | struct ovs_list expirable OVS_GUARDED_BY(ofproto_mutex); |
b90d6ee5 JR |
419 | |
420 | /* Times. Last so that they are more likely close to the stats managed | |
421 | * by the provider. */ | |
422 | long long int created OVS_GUARDED; /* Creation time. */ | |
423 | ||
424 | /* Must hold 'mutex' for both read/write, 'ofproto_mutex' not needed. */ | |
425 | long long int modified OVS_GUARDED; /* Time of last modification. */ | |
abe529af BP |
426 | }; |
427 | ||
a2143702 | 428 | void ofproto_rule_ref(struct rule *); |
f5d16e55 | 429 | bool ofproto_rule_try_ref(struct rule *); |
a2143702 BP |
430 | void ofproto_rule_unref(struct rule *); |
431 | ||
003ce655 JR |
432 | static inline const struct rule_actions * rule_get_actions(const struct rule *); |
433 | static inline bool rule_is_table_miss(const struct rule *); | |
5e8b38b0 | 434 | static inline bool rule_is_hidden(const struct rule *); |
cfa955b0 | 435 | |
6f00e29b BP |
436 | /* A set of actions within a "struct rule". |
437 | * | |
438 | * | |
439 | * Thread-safety | |
440 | * ============= | |
441 | * | |
afae68b1 JR |
442 | * A struct rule_actions may be accessed without a risk of being freed by |
443 | * code that holds 'rule->mutex' (where 'rule' is the rule for which | |
444 | * 'rule->actions == actions') or during the RCU active period. | |
4c7562c5 | 445 | * |
39c94593 | 446 | * All members are immutable: they do not change during the rule's |
4c7562c5 | 447 | * lifetime. */ |
6f00e29b | 448 | struct rule_actions { |
4c7562c5 BP |
449 | /* Flags. |
450 | * | |
35f48b8b BP |
451 | * 'has_meter' is true if 'ofpacts' contains an OFPACT_METER action. |
452 | * | |
453 | * 'has_learn_with_delete' is true if 'ofpacts' contains an OFPACT_LEARN | |
454 | * action whose flags include NX_LEARN_F_DELETE_LEARNED. */ | |
4c7562c5 | 455 | bool has_meter; |
35f48b8b | 456 | bool has_learn_with_delete; |
cc099268 | 457 | bool has_groups; |
4c7562c5 BP |
458 | |
459 | /* Actions. */ | |
dc723c44 | 460 | uint32_t ofpacts_len; /* Size of 'ofpacts', in bytes. */ |
dc723c44 | 461 | struct ofpact ofpacts[]; /* Sequence of "struct ofpacts". */ |
6f00e29b | 462 | }; |
dc723c44 | 463 | BUILD_ASSERT_DECL(offsetof(struct rule_actions, ofpacts) % OFPACT_ALIGNTO == 0); |
6f00e29b | 464 | |
4c7562c5 | 465 | const struct rule_actions *rule_actions_create(const struct ofpact *, size_t); |
dc723c44 | 466 | void rule_actions_destroy(const struct rule_actions *); |
cdbdeeda SH |
467 | bool ofproto_rule_has_out_port(const struct rule *, ofp_port_t port) |
468 | OVS_REQUIRES(ofproto_mutex); | |
6f00e29b | 469 | |
fe59694b JR |
470 | #define DECL_OFPROTO_COLLECTION(TYPE, NAME) \ |
471 | DECL_OBJECT_COLLECTION(TYPE, NAME) \ | |
472 | static inline void NAME##_collection_ref(struct NAME##_collection *coll) \ | |
473 | { \ | |
474 | for (size_t i = 0; i < coll->collection.n; i++) { \ | |
475 | ofproto_##NAME##_ref((TYPE)coll->collection.objs[i]); \ | |
476 | } \ | |
477 | } \ | |
478 | \ | |
479 | static inline void NAME##_collection_unref(struct NAME##_collection *coll) \ | |
480 | { \ | |
481 | for (size_t i = 0; i < coll->collection.n; i++) { \ | |
482 | ofproto_##NAME##_unref((TYPE)coll->collection.objs[i]); \ | |
483 | } \ | |
484 | } | |
485 | ||
486 | DECL_OFPROTO_COLLECTION (struct rule *, rule) | |
487 | ||
488 | #define RULE_COLLECTION_FOR_EACH(RULE, RULES) \ | |
489 | for (size_t i__ = 0; \ | |
490 | i__ < rule_collection_n(RULES) \ | |
491 | ? (RULE = rule_collection_rules(RULES)[i__]) != NULL : false; \ | |
492 | i__++) | |
493 | ||
494 | /* Pairwise iteration through two rule collections that must be of the same | |
495 | * size. */ | |
496 | #define RULE_COLLECTIONS_FOR_EACH(RULE1, RULE2, RULES1, RULES2) \ | |
497 | for (size_t i__ = 0; \ | |
498 | i__ < rule_collection_n(RULES1) \ | |
499 | ? ((RULE1 = rule_collection_rules(RULES1)[i__]), \ | |
500 | (RULE2 = rule_collection_rules(RULES2)[i__]) != NULL) \ | |
501 | : false; \ | |
502 | i__++) | |
a8e547c1 | 503 | |
e79a6c83 EJ |
504 | /* Limits the number of flows allowed in the datapath. Only affects the |
505 | * ofproto-dpif implementation. */ | |
506 | extern unsigned ofproto_flow_limit; | |
380f49c4 | 507 | |
72310b04 JS |
508 | /* Maximum idle time (in ms) for flows to be cached in the datapath. |
509 | * Revalidators may expire flows more quickly than the configured value based | |
510 | * on system load and other factors. This variable is subject to change. */ | |
511 | extern unsigned ofproto_max_idle; | |
512 | ||
e79a6c83 EJ |
513 | /* Number of upcall handler and revalidator threads. Only affects the |
514 | * ofproto-dpif implementation. */ | |
515 | extern size_t n_handlers, n_revalidators; | |
448a4b2f | 516 | |
003ce655 | 517 | static inline struct rule *rule_from_cls_rule(const struct cls_rule *); |
abe529af | 518 | |
15aaf599 BP |
519 | void ofproto_rule_expire(struct rule *rule, uint8_t reason) |
520 | OVS_REQUIRES(ofproto_mutex); | |
8b81d1ef | 521 | void ofproto_rule_delete(struct ofproto *, struct rule *) |
15aaf599 | 522 | OVS_EXCLUDED(ofproto_mutex); |
1f4a8933 JR |
523 | void ofproto_rule_reduce_timeouts__(struct rule *rule, uint16_t idle_timeout, |
524 | uint16_t hard_timeout) | |
525 | OVS_REQUIRES(ofproto_mutex) OVS_EXCLUDED(rule->mutex); | |
994c9973 BP |
526 | void ofproto_rule_reduce_timeouts(struct rule *rule, uint16_t idle_timeout, |
527 | uint16_t hard_timeout) | |
15aaf599 | 528 | OVS_EXCLUDED(ofproto_mutex); |
abe529af | 529 | |
db88b35c | 530 | /* A group within a "struct ofproto", RCU-protected. |
7395c052 NZ |
531 | * |
532 | * With few exceptions, ofproto implementations may look at these fields but | |
533 | * should not modify them. */ | |
534 | struct ofgroup { | |
db88b35c | 535 | struct cmap_node cmap_node; /* In ofproto's "groups" cmap. */ |
809c7548 | 536 | |
5d08a275 JR |
537 | /* Group versioning. */ |
538 | struct versions versions; | |
539 | ||
809c7548 RW |
540 | /* Number of references. |
541 | * | |
542 | * This is needed to keep track of references to the group in the xlate | |
543 | * module. | |
544 | * | |
545 | * If the main thread removes the group from an ofproto, we need to | |
546 | * guarantee that the group remains accessible to users of | |
547 | * xlate_group_actions and the xlate_cache, as the xlate_cache will not be | |
548 | * cleaned up until the corresponding datapath flows are revalidated. */ | |
549 | struct ovs_refcount ref_count; | |
550 | ||
551 | /* No lock is needed to protect the fields below since they are not | |
552 | * modified after construction. */ | |
5d08a275 | 553 | struct ofproto * const ofproto; /* The ofproto that contains this group. */ |
eaf004bd AZ |
554 | const uint32_t group_id; |
555 | const enum ofp11_group_type type; /* One of OFPGT_*. */ | |
cc099268 | 556 | bool being_deleted; /* Group removal has begun. */ |
7395c052 | 557 | |
eaf004bd AZ |
558 | const long long int created; /* Creation time. */ |
559 | const long long int modified; /* Time of last modification. */ | |
7395c052 | 560 | |
db88b35c | 561 | const struct ovs_list buckets; /* Contains "struct ofputil_bucket"s. */ |
eaf004bd | 562 | const uint32_t n_buckets; |
bc65c25a SH |
563 | |
564 | const struct ofputil_group_props props; | |
cc099268 JR |
565 | |
566 | struct rule_collection rules OVS_GUARDED; /* Referring rules. */ | |
7395c052 NZ |
567 | }; |
568 | ||
db88b35c | 569 | struct ofgroup *ofproto_group_lookup(const struct ofproto *ofproto, |
5d08a275 JR |
570 | uint32_t group_id, ovs_version_t version, |
571 | bool take_ref); | |
7395c052 | 572 | |
809c7548 | 573 | void ofproto_group_ref(struct ofgroup *); |
db88b35c | 574 | bool ofproto_group_try_ref(struct ofgroup *); |
809c7548 | 575 | void ofproto_group_unref(struct ofgroup *); |
7395c052 | 576 | |
cc099268 JR |
577 | void ofproto_group_delete_all(struct ofproto *) |
578 | OVS_EXCLUDED(ofproto_mutex); | |
daab0ae6 | 579 | |
2b0b0b80 JR |
580 | DECL_OFPROTO_COLLECTION (struct ofgroup *, group) |
581 | ||
582 | #define GROUP_COLLECTION_FOR_EACH(GROUP, GROUPS) \ | |
583 | for (size_t i__ = 0; \ | |
584 | i__ < group_collection_n(GROUPS) \ | |
585 | ? (GROUP = group_collection_groups(GROUPS)[i__]) != NULL: false; \ | |
586 | i__++) | |
587 | ||
588 | /* Pairwise iteration through two group collections that must be of the same | |
589 | * size. */ | |
590 | #define GROUP_COLLECTIONS_FOR_EACH(GROUP1, GROUP2, GROUPS1, GROUPS2) \ | |
591 | for (size_t i__ = 0; \ | |
592 | i__ < group_collection_n(GROUPS1) \ | |
593 | ? ((GROUP1 = group_collection_groups(GROUPS1)[i__]), \ | |
594 | (GROUP2 = group_collection_groups(GROUPS2)[i__]) != NULL) \ | |
595 | : false; \ | |
596 | i__++) | |
597 | ||
abe529af BP |
598 | /* ofproto class structure, to be defined by each ofproto implementation. |
599 | * | |
600 | * | |
601 | * Data Structures | |
602 | * =============== | |
603 | * | |
7395c052 | 604 | * These functions work primarily with four different kinds of data |
abe529af BP |
605 | * structures: |
606 | * | |
607 | * - "struct ofproto", which represents an OpenFlow switch. | |
608 | * | |
609 | * - "struct ofport", which represents a port within an ofproto. | |
610 | * | |
611 | * - "struct rule", which represents an OpenFlow flow within an ofproto. | |
612 | * | |
7395c052 NZ |
613 | * - "struct ofgroup", which represents an OpenFlow 1.1+ group within an |
614 | * ofproto. | |
615 | * | |
abe529af BP |
616 | * Each of these data structures contains all of the implementation-independent |
617 | * generic state for the respective concept, called the "base" state. None of | |
618 | * them contains any extra space for ofproto implementations to use. Instead, | |
619 | * each implementation is expected to declare its own data structure that | |
620 | * contains an instance of the generic data structure plus additional | |
621 | * implementation-specific members, called the "derived" state. The | |
622 | * implementation can use casts or (preferably) the CONTAINER_OF macro to | |
623 | * obtain access to derived state given only a pointer to the embedded generic | |
624 | * data structure. | |
625 | * | |
626 | * | |
627 | * Life Cycle | |
628 | * ========== | |
629 | * | |
630 | * Four stylized functions accompany each of these data structures: | |
631 | * | |
632 | * "alloc" "construct" "destruct" "dealloc" | |
633 | * ------------ ---------------- --------------- -------------- | |
634 | * ofproto ->alloc ->construct ->destruct ->dealloc | |
635 | * ofport ->port_alloc ->port_construct ->port_destruct ->port_dealloc | |
636 | * rule ->rule_alloc ->rule_construct ->rule_destruct ->rule_dealloc | |
7395c052 | 637 | * group ->group_alloc ->group_construct ->group_destruct ->group_dealloc |
abe529af | 638 | * |
7395c052 NZ |
639 | * "ofproto", "ofport", and "group" have this exact life cycle. The "rule" |
640 | * data structure also follow this life cycle with some additional elaborations | |
8037acb4 BP |
641 | * described under "Rule Life Cycle" below. |
642 | * | |
abe529af BP |
643 | * Any instance of a given data structure goes through the following life |
644 | * cycle: | |
645 | * | |
646 | * 1. The client calls the "alloc" function to obtain raw memory. If "alloc" | |
647 | * fails, skip all the other steps. | |
648 | * | |
649 | * 2. The client initializes all of the data structure's base state. If this | |
650 | * fails, skip to step 7. | |
651 | * | |
652 | * 3. The client calls the "construct" function. The implementation | |
653 | * initializes derived state. It may refer to the already-initialized | |
654 | * base state. If "construct" fails, skip to step 6. | |
655 | * | |
656 | * 4. The data structure is now initialized and in use. | |
657 | * | |
658 | * 5. When the data structure is no longer needed, the client calls the | |
659 | * "destruct" function. The implementation uninitializes derived state. | |
660 | * The base state has not been uninitialized yet, so the implementation | |
661 | * may still refer to it. | |
662 | * | |
663 | * 6. The client uninitializes all of the data structure's base state. | |
664 | * | |
665 | * 7. The client calls the "dealloc" to free the raw memory. The | |
666 | * implementation must not refer to base or derived state in the data | |
667 | * structure, because it has already been uninitialized. | |
668 | * | |
669 | * Each "alloc" function allocates and returns a new instance of the respective | |
670 | * data structure. The "alloc" function is not given any information about the | |
671 | * use of the new data structure, so it cannot perform much initialization. | |
672 | * Its purpose is just to ensure that the new data structure has enough room | |
673 | * for base and derived state. It may return a null pointer if memory is not | |
674 | * available, in which case none of the other functions is called. | |
675 | * | |
676 | * Each "construct" function initializes derived state in its respective data | |
677 | * structure. When "construct" is called, all of the base state has already | |
678 | * been initialized, so the "construct" function may refer to it. The | |
679 | * "construct" function is allowed to fail, in which case the client calls the | |
680 | * "dealloc" function (but not the "destruct" function). | |
681 | * | |
682 | * Each "destruct" function uninitializes and frees derived state in its | |
683 | * respective data structure. When "destruct" is called, the base state has | |
684 | * not yet been uninitialized, so the "destruct" function may refer to it. The | |
685 | * "destruct" function is not allowed to fail. | |
686 | * | |
898dcef1 | 687 | * Each "dealloc" function frees raw memory that was allocated by the |
abe529af BP |
688 | * "alloc" function. The memory's base and derived members might not have ever |
689 | * been initialized (but if "construct" returned successfully, then it has been | |
690 | * "destruct"ed already). The "dealloc" function is not allowed to fail. | |
691 | * | |
692 | * | |
693 | * Conventions | |
694 | * =========== | |
695 | * | |
696 | * Most of these functions return 0 if they are successful or a positive error | |
697 | * code on failure. Depending on the function, valid error codes are either | |
90bf1e07 | 698 | * errno values or OFPERR_* OpenFlow error codes. |
abe529af BP |
699 | * |
700 | * Most of these functions are expected to execute synchronously, that is, to | |
701 | * block as necessary to obtain a result. Thus, these functions may return | |
702 | * EAGAIN (or EWOULDBLOCK or EINPROGRESS) only where the function descriptions | |
703 | * explicitly say those errors are a possibility. We may relax this | |
704 | * requirement in the future if and when we encounter performance problems. */ | |
705 | struct ofproto_class { | |
706 | /* ## ----------------- ## */ | |
707 | /* ## Factory Functions ## */ | |
708 | /* ## ----------------- ## */ | |
709 | ||
b0408fca JP |
710 | /* Initializes provider. The caller may pass in 'iface_hints', |
711 | * which contains an shash of "struct iface_hint" elements indexed | |
712 | * by the interface's name. The provider may use these hints to | |
713 | * describe the startup configuration in order to reinitialize its | |
714 | * state. The caller owns the provided data, so a provider must | |
715 | * make copies of anything required. An ofproto provider must | |
716 | * remove any existing state that is not described by the hint, and | |
717 | * may choose to remove it all. */ | |
718 | void (*init)(const struct shash *iface_hints); | |
719 | ||
5b5b11ea BP |
720 | /* Enumerates the types of all supported ofproto types into 'types'. The |
721 | * caller has already initialized 'types'. The implementation should add | |
722 | * its own types to 'types' but not remove any existing ones, because other | |
723 | * ofproto classes might already have added names to it. */ | |
abe529af | 724 | void (*enumerate_types)(struct sset *types); |
5bf0e941 BP |
725 | |
726 | /* Enumerates the names of all existing datapath of the specified 'type' | |
727 | * into 'names' 'all_dps'. The caller has already initialized 'names' as | |
728 | * an empty sset. | |
729 | * | |
730 | * 'type' is one of the types enumerated by ->enumerate_types(). | |
731 | * | |
732 | * Returns 0 if successful, otherwise a positive errno value. | |
733 | */ | |
abe529af | 734 | int (*enumerate_names)(const char *type, struct sset *names); |
5bf0e941 BP |
735 | |
736 | /* Deletes the datapath with the specified 'type' and 'name'. The caller | |
737 | * should have closed any open ofproto with this 'type' and 'name'; this | |
738 | * function is allowed to fail if that is not the case. | |
739 | * | |
740 | * 'type' is one of the types enumerated by ->enumerate_types(). | |
741 | * 'name' is one of the names enumerated by ->enumerate_names() for 'type'. | |
742 | * | |
743 | * Returns 0 if successful, otherwise a positive errno value. | |
744 | */ | |
abe529af BP |
745 | int (*del)(const char *type, const char *name); |
746 | ||
0aeaabc8 JP |
747 | /* Returns the type to pass to netdev_open() when a datapath of type |
748 | * 'datapath_type' has a port of type 'port_type', for a few special | |
749 | * cases when a netdev type differs from a port type. For example, | |
750 | * when using the userspace datapath, a port of type "internal" | |
751 | * needs to be opened as "tap". | |
752 | * | |
753 | * Returns either 'type' itself or a string literal, which must not | |
754 | * be freed. */ | |
755 | const char *(*port_open_type)(const char *datapath_type, | |
756 | const char *port_type); | |
757 | ||
11a574a7 JP |
758 | /* ## ------------------------ ## */ |
759 | /* ## Top-Level type Functions ## */ | |
760 | /* ## ------------------------ ## */ | |
761 | ||
762 | /* Performs any periodic activity required on ofprotos of type | |
763 | * 'type'. | |
764 | * | |
765 | * An ofproto provider may implement it or not, depending on whether | |
766 | * it needs type-level maintenance. | |
767 | * | |
768 | * Returns 0 if successful, otherwise a positive errno value. */ | |
769 | int (*type_run)(const char *type); | |
770 | ||
11a574a7 JP |
771 | /* Causes the poll loop to wake up when a type 'type''s 'run' |
772 | * function needs to be called, e.g. by calling the timer or fd | |
773 | * waiting functions in poll-loop.h. | |
774 | * | |
775 | * An ofproto provider may implement it or not, depending on whether | |
776 | * it needs type-level maintenance. */ | |
777 | void (*type_wait)(const char *type); | |
778 | ||
abe529af BP |
779 | /* ## --------------------------- ## */ |
780 | /* ## Top-Level ofproto Functions ## */ | |
781 | /* ## --------------------------- ## */ | |
782 | ||
783 | /* Life-cycle functions for an "ofproto" (see "Life Cycle" above). | |
7ee20df1 BP |
784 | * |
785 | * | |
786 | * Construction | |
787 | * ============ | |
abe529af | 788 | * |
073e2a6f BP |
789 | * ->construct() should not modify any base members of the ofproto. The |
790 | * client will initialize the ofproto's 'ports' and 'tables' members after | |
791 | * construction is complete. | |
6c1491fb | 792 | * |
073e2a6f BP |
793 | * When ->construct() is called, the client does not yet know how many flow |
794 | * tables the datapath supports, so ofproto->n_tables will be 0 and | |
0f5f95a9 BP |
795 | * ofproto->tables will be NULL. ->construct() should call |
796 | * ofproto_init_tables() to allocate and initialize ofproto->n_tables and | |
797 | * ofproto->tables. Each flow table will be initially empty, so | |
798 | * ->construct() should delete flows from the underlying datapath, if | |
799 | * necessary, rather than populating the tables. | |
abe529af | 800 | * |
91858960 BP |
801 | * If the ofproto knows the maximum port number that the datapath can have, |
802 | * then it can call ofproto_init_max_ports(). If it does so, then the | |
803 | * client will ensure that the actions it allows to be used through | |
804 | * OpenFlow do not refer to ports above that maximum number. | |
805 | * | |
abe529af BP |
806 | * Only one ofproto instance needs to be supported for any given datapath. |
807 | * If a datapath is already open as part of one "ofproto", then another | |
808 | * attempt to "construct" the same datapath as part of another ofproto is | |
5bf0e941 BP |
809 | * allowed to fail with an error. |
810 | * | |
811 | * ->construct() returns 0 if successful, otherwise a positive errno | |
7ee20df1 BP |
812 | * value. |
813 | * | |
814 | * | |
815 | * Destruction | |
816 | * =========== | |
817 | * | |
073e2a6f | 818 | * ->destruct() must also destroy all remaining rules in the ofproto's |
daab0ae6 BP |
819 | * tables, by passing each remaining rule to ofproto_rule_delete(), then |
820 | * destroy all remaining groups by calling ofproto_group_delete_all(). | |
8037acb4 BP |
821 | * |
822 | * The client will destroy the flow tables themselves after ->destruct() | |
073e2a6f | 823 | * returns. |
7ee20df1 | 824 | */ |
abe529af | 825 | struct ofproto *(*alloc)(void); |
0f5f95a9 | 826 | int (*construct)(struct ofproto *ofproto); |
abe529af BP |
827 | void (*destruct)(struct ofproto *ofproto); |
828 | void (*dealloc)(struct ofproto *ofproto); | |
829 | ||
830 | /* Performs any periodic activity required by 'ofproto'. It should: | |
831 | * | |
832 | * - Call connmgr_send_packet_in() for each received packet that missed | |
833 | * in the OpenFlow flow table or that had a OFPP_CONTROLLER output | |
834 | * action. | |
835 | * | |
836 | * - Call ofproto_rule_expire() for each OpenFlow flow that has reached | |
837 | * its hard_timeout or idle_timeout, to expire the flow. | |
5bf0e941 | 838 | * |
5fcc0d00 | 839 | * Returns 0 if successful, otherwise a positive errno value. */ |
abe529af BP |
840 | int (*run)(struct ofproto *ofproto); |
841 | ||
842 | /* Causes the poll loop to wake up when 'ofproto''s 'run' function needs to | |
843 | * be called, e.g. by calling the timer or fd waiting functions in | |
844 | * poll-loop.h. */ | |
845 | void (*wait)(struct ofproto *ofproto); | |
846 | ||
0d085684 BP |
847 | /* Adds some memory usage statistics for the implementation of 'ofproto' |
848 | * into 'usage', for use with memory_report(). | |
849 | * | |
850 | * This function is optional. */ | |
851 | void (*get_memory_usage)(const struct ofproto *ofproto, | |
852 | struct simap *usage); | |
853 | ||
1c030aa5 EJ |
854 | /* Adds some memory usage statistics for the implementation of 'type' |
855 | * into 'usage', for use with memory_report(). | |
856 | * | |
857 | * This function is optional. */ | |
858 | void (*type_get_memory_usage)(const char *type, struct simap *usage); | |
859 | ||
abe529af BP |
860 | /* Every "struct rule" in 'ofproto' is about to be deleted, one by one. |
861 | * This function may prepare for that, for example by clearing state in | |
862 | * advance. It should *not* actually delete any "struct rule"s from | |
863 | * 'ofproto', only prepare for it. | |
864 | * | |
865 | * This function is optional; it's really just for optimization in case | |
866 | * it's cheaper to delete all the flows from your hardware in a single pass | |
867 | * than to do it one by one. */ | |
868 | void (*flush)(struct ofproto *ofproto); | |
869 | ||
3c1bb396 | 870 | /* Helper for the OpenFlow OFPT_TABLE_FEATURES request. |
6c1491fb | 871 | * |
3c1bb396 BP |
872 | * The 'features' array contains 'ofproto->n_tables' elements. Each |
873 | * element is initialized as: | |
6c1491fb BP |
874 | * |
875 | * - 'table_id' to the array index. | |
876 | * | |
877 | * - 'name' to "table#" where # is the table ID. | |
878 | * | |
2ee9b978 | 879 | * - 'metadata_match' and 'metadata_write' to OVS_BE64_MAX. |
307975da | 880 | * |
b187a283 | 881 | * - 'config' to the table miss configuration. |
6c1491fb BP |
882 | * |
883 | * - 'max_entries' to 1,000,000. | |
884 | * | |
3c1bb396 | 885 | * - Both 'nonmiss' and 'miss' to: |
6c1491fb | 886 | * |
3c1bb396 | 887 | * * 'next' to all 1-bits for all later tables. |
6c1491fb | 888 | * |
3c1bb396 | 889 | * * 'instructions' to all instructions. |
6c1491fb | 890 | * |
3c1bb396 | 891 | * * 'write' and 'apply' both to: |
6c1491fb | 892 | * |
3c1bb396 | 893 | * - 'ofpacts': All actions. |
6c1491fb | 894 | * |
3c1bb396 | 895 | * - 'set_fields': All fields. |
307975da | 896 | * |
3c1bb396 | 897 | * - 'match', 'mask', and 'wildcard' to all fields. |
307975da | 898 | * |
3c1bb396 BP |
899 | * If 'stats' is nonnull, it also contains 'ofproto->n_tables' elements. |
900 | * Each element is initialized as: | |
307975da | 901 | * |
3c1bb396 BP |
902 | * - 'table_id' to the array index. |
903 | * | |
d79e3d70 | 904 | * - 'active_count' to the 'n_flows' of struct ofproto for the table. |
307975da | 905 | * |
3c1bb396 BP |
906 | * - 'lookup_count' and 'matched_count' to 0. |
907 | * | |
908 | * The implementation should update any members in each element for which | |
909 | * it has better values: | |
307975da | 910 | * |
3c1bb396 BP |
911 | * - Any member of 'features' to better describe the implementation's |
912 | * capabilities. | |
6c1491fb BP |
913 | * |
914 | * - 'lookup_count' to the number of packets looked up in this flow table | |
915 | * so far. | |
916 | * | |
917 | * - 'matched_count' to the number of packets looked up in this flow | |
918 | * table so far that matched one of the flow entries. | |
6c1491fb | 919 | */ |
3c1bb396 BP |
920 | void (*query_tables)(struct ofproto *ofproto, |
921 | struct ofputil_table_features *features, | |
922 | struct ofputil_table_stats *stats); | |
6c1491fb | 923 | |
621b8064 | 924 | /* Sets the current tables version the provider should use for classifier |
1fc71871 JR |
925 | * lookups. This must be called with a new version number after each set |
926 | * of flow table changes has been completed, so that datapath revalidation | |
927 | * can be triggered. */ | |
44e0c35d | 928 | void (*set_tables_version)(struct ofproto *ofproto, ovs_version_t version); |
1fc71871 | 929 | |
abe529af BP |
930 | /* ## ---------------- ## */ |
931 | /* ## ofport Functions ## */ | |
932 | /* ## ---------------- ## */ | |
933 | ||
934 | /* Life-cycle functions for a "struct ofport" (see "Life Cycle" above). | |
935 | * | |
936 | * ->port_construct() should not modify any base members of the ofport. | |
e1b1d06a JP |
937 | * An ofproto implementation should use the 'ofp_port' member of |
938 | * "struct ofport" as the OpenFlow port number. | |
abe529af BP |
939 | * |
940 | * ofports are managed by the base ofproto code. The ofproto | |
941 | * implementation should only create and destroy them in response to calls | |
942 | * to these functions. The base ofproto code will create and destroy | |
943 | * ofports in the following situations: | |
944 | * | |
945 | * - Just after the ->construct() function is called, the base ofproto | |
946 | * iterates over all of the implementation's ports, using | |
947 | * ->port_dump_start() and related functions, and constructs an ofport | |
948 | * for each dumped port. | |
949 | * | |
950 | * - If ->port_poll() reports that a specific port has changed, then the | |
951 | * base ofproto will query that port with ->port_query_by_name() and | |
952 | * construct or destruct ofports as necessary to reflect the updated | |
953 | * set of ports. | |
954 | * | |
955 | * - If ->port_poll() returns ENOBUFS to report an unspecified port set | |
956 | * change, then the base ofproto will iterate over all of the | |
957 | * implementation's ports, in the same way as at ofproto | |
958 | * initialization, and construct and destruct ofports to reflect all of | |
959 | * the changes. | |
5bf0e941 | 960 | * |
9aad5a5a BP |
961 | * - On graceful shutdown, the base ofproto code will destruct all |
962 | * the ports. | |
963 | * | |
5bf0e941 BP |
964 | * ->port_construct() returns 0 if successful, otherwise a positive errno |
965 | * value. | |
9aad5a5a BP |
966 | * |
967 | * | |
968 | * ->port_destruct() | |
969 | * ================= | |
970 | * | |
971 | * ->port_destruct() takes a 'del' parameter. If the provider implements | |
972 | * the datapath itself (e.g. dpif-netdev, it can ignore 'del'. On the | |
973 | * other hand, if the provider is an interface to an external datapath | |
974 | * (e.g. to a kernel module that implement the datapath) then 'del' should | |
975 | * influence destruction behavior in the following way: | |
976 | * | |
977 | * - If 'del' is true, it should remove the port from the underlying | |
978 | * implementation. This is the common case. | |
979 | * | |
980 | * - If 'del' is false, it should leave the port in the underlying | |
981 | * implementation. This is used when Open vSwitch is performing a | |
982 | * graceful shutdown and ensures that, across Open vSwitch restarts, | |
983 | * the underlying ports are not removed and recreated. That makes an | |
984 | * important difference for, e.g., "internal" ports that have | |
985 | * configured IP addresses; without this distinction, the IP address | |
986 | * and other configured state for the port is lost. | |
abe529af BP |
987 | */ |
988 | struct ofport *(*port_alloc)(void); | |
989 | int (*port_construct)(struct ofport *ofport); | |
9aad5a5a | 990 | void (*port_destruct)(struct ofport *ofport, bool del); |
abe529af BP |
991 | void (*port_dealloc)(struct ofport *ofport); |
992 | ||
993 | /* Called after 'ofport->netdev' is replaced by a new netdev object. If | |
994 | * the ofproto implementation uses the ofport's netdev internally, then it | |
995 | * should switch to using the new one. The old one has been closed. | |
996 | * | |
997 | * An ofproto implementation that doesn't need to do anything in this | |
998 | * function may use a null pointer. */ | |
999 | void (*port_modified)(struct ofport *ofport); | |
1000 | ||
9e1fd49b BP |
1001 | /* Called after an OpenFlow request changes a port's configuration. |
1002 | * 'ofport->pp.config' contains the new configuration. 'old_config' | |
1003 | * contains the previous configuration. | |
abe529af | 1004 | * |
9e1fd49b BP |
1005 | * The caller implements OFPUTIL_PC_PORT_DOWN using netdev functions to |
1006 | * turn NETDEV_UP on and off, so this function doesn't have to do anything | |
1007 | * for that bit (and it won't be called if that is the only bit that | |
abe529af | 1008 | * changes). */ |
9e1fd49b BP |
1009 | void (*port_reconfigured)(struct ofport *ofport, |
1010 | enum ofputil_port_config old_config); | |
abe529af | 1011 | |
090fd77e JS |
1012 | /* Looks up a port named 'devname' in 'ofproto'. On success, returns 0 and |
1013 | * initializes '*port' appropriately. Otherwise, returns a positive errno | |
1014 | * value. | |
abe529af BP |
1015 | * |
1016 | * The caller owns the data in 'port' and must free it with | |
1017 | * ofproto_port_destroy() when it is no longer needed. */ | |
1018 | int (*port_query_by_name)(const struct ofproto *ofproto, | |
1019 | const char *devname, struct ofproto_port *port); | |
1020 | ||
e1b1d06a JP |
1021 | /* Attempts to add 'netdev' as a port on 'ofproto'. Returns 0 if |
1022 | * successful, otherwise a positive errno value. The caller should | |
1023 | * inform the implementation of the OpenFlow port through the | |
1024 | * ->port_construct() method. | |
5bf0e941 BP |
1025 | * |
1026 | * It doesn't matter whether the new port will be returned by a later call | |
1027 | * to ->port_poll(); the implementation may do whatever is more | |
1028 | * convenient. */ | |
e1b1d06a | 1029 | int (*port_add)(struct ofproto *ofproto, struct netdev *netdev); |
abe529af | 1030 | |
5bf0e941 BP |
1031 | /* Deletes port number 'ofp_port' from the datapath for 'ofproto'. Returns |
1032 | * 0 if successful, otherwise a positive errno value. | |
1033 | * | |
1034 | * It doesn't matter whether the new port will be returned by a later call | |
1035 | * to ->port_poll(); the implementation may do whatever is more | |
1036 | * convenient. */ | |
4e022ec0 | 1037 | int (*port_del)(struct ofproto *ofproto, ofp_port_t ofp_port); |
abe529af | 1038 | |
91364d18 IM |
1039 | /* Refreshes datapath configuration of 'port'. |
1040 | * Returns 0 if successful, otherwise a positive errno value. */ | |
1041 | int (*port_set_config)(const struct ofport *port, const struct smap *cfg); | |
1042 | ||
6527c598 PS |
1043 | /* Get port stats */ |
1044 | int (*port_get_stats)(const struct ofport *port, | |
1045 | struct netdev_stats *stats); | |
1046 | ||
d39258c8 BP |
1047 | /* Port iteration functions. |
1048 | * | |
1049 | * The client might not be entirely in control of the ports within an | |
1050 | * ofproto. Some hardware implementations, for example, might have a fixed | |
acf60855 JP |
1051 | * set of ports in a datapath. For this reason, the client needs a way to |
1052 | * iterate through all the ports that are actually in a datapath. These | |
1053 | * functions provide that functionality. | |
d39258c8 BP |
1054 | * |
1055 | * The 'state' pointer provides the implementation a place to | |
1056 | * keep track of its position. Its format is opaque to the caller. | |
1057 | * | |
1058 | * The ofproto provider retains ownership of the data that it stores into | |
1059 | * ->port_dump_next()'s 'port' argument. The data must remain valid until | |
1060 | * at least the next call to ->port_dump_next() or ->port_dump_done() for | |
1061 | * 'state'. The caller will not modify or free it. | |
1062 | * | |
1063 | * Details | |
1064 | * ======= | |
1065 | * | |
1066 | * ->port_dump_start() attempts to begin dumping the ports in 'ofproto'. | |
1067 | * On success, it should return 0 and initialize '*statep' with any data | |
1068 | * needed for iteration. On failure, returns a positive errno value, and | |
1069 | * the client will not call ->port_dump_next() or ->port_dump_done(). | |
1070 | * | |
1071 | * ->port_dump_next() attempts to retrieve another port from 'ofproto' for | |
1072 | * 'state'. If there is another port, it should store the port's | |
1073 | * information into 'port' and return 0. It should return EOF if all ports | |
1074 | * have already been iterated. Otherwise, on error, it should return a | |
1075 | * positive errno value. This function will not be called again once it | |
1076 | * returns nonzero once for a given iteration (but the 'port_dump_done' | |
1077 | * function will be called afterward). | |
1078 | * | |
1079 | * ->port_dump_done() allows the implementation to release resources used | |
1080 | * for iteration. The caller might decide to stop iteration in the middle | |
1081 | * by calling this function before ->port_dump_next() returns nonzero. | |
1082 | * | |
1083 | * Usage Example | |
1084 | * ============= | |
1085 | * | |
1086 | * int error; | |
1087 | * void *state; | |
1088 | * | |
1089 | * error = ofproto->ofproto_class->port_dump_start(ofproto, &state); | |
1090 | * if (!error) { | |
1091 | * for (;;) { | |
1092 | * struct ofproto_port port; | |
1093 | * | |
1094 | * error = ofproto->ofproto_class->port_dump_next( | |
1095 | * ofproto, state, &port); | |
1096 | * if (error) { | |
1097 | * break; | |
1098 | * } | |
1099 | * // Do something with 'port' here (without modifying or freeing | |
1100 | * // any of its data). | |
1101 | * } | |
1102 | * ofproto->ofproto_class->port_dump_done(ofproto, state); | |
1103 | * } | |
1104 | * // 'error' is now EOF (success) or a positive errno value (failure). | |
1105 | */ | |
abe529af | 1106 | int (*port_dump_start)(const struct ofproto *ofproto, void **statep); |
abe529af BP |
1107 | int (*port_dump_next)(const struct ofproto *ofproto, void *state, |
1108 | struct ofproto_port *port); | |
abe529af BP |
1109 | int (*port_dump_done)(const struct ofproto *ofproto, void *state); |
1110 | ||
1111 | /* Polls for changes in the set of ports in 'ofproto'. If the set of ports | |
1112 | * in 'ofproto' has changed, then this function should do one of the | |
1113 | * following: | |
1114 | * | |
1115 | * - Preferably: store the name of the device that was added to or deleted | |
1116 | * from 'ofproto' in '*devnamep' and return 0. The caller is responsible | |
1117 | * for freeing '*devnamep' (with free()) when it no longer needs it. | |
1118 | * | |
1119 | * - Alternatively: return ENOBUFS, without indicating the device that was | |
1120 | * added or deleted. | |
1121 | * | |
1122 | * Occasional 'false positives', in which the function returns 0 while | |
1123 | * indicating a device that was not actually added or deleted or returns | |
1124 | * ENOBUFS without any change, are acceptable. | |
1125 | * | |
1126 | * The purpose of 'port_poll' is to let 'ofproto' know about changes made | |
1127 | * externally to the 'ofproto' object, e.g. by a system administrator via | |
1128 | * ovs-dpctl. Therefore, it's OK, and even preferable, for port_poll() to | |
1129 | * not report changes made through calls to 'port_add' or 'port_del' on the | |
1130 | * same 'ofproto' object. (But it's OK for it to report them too, just | |
1131 | * slightly less efficient.) | |
1132 | * | |
1133 | * If the set of ports in 'ofproto' has not changed, returns EAGAIN. May | |
1134 | * also return other positive errno values to indicate that something has | |
5bf0e941 BP |
1135 | * gone wrong. |
1136 | * | |
1137 | * If the set of ports in a datapath is fixed, or if the only way that the | |
1138 | * set of ports in a datapath can change is through ->port_add() and | |
1139 | * ->port_del(), then this function may be a null pointer. | |
1140 | */ | |
abe529af BP |
1141 | int (*port_poll)(const struct ofproto *ofproto, char **devnamep); |
1142 | ||
5bf0e941 BP |
1143 | /* Arranges for the poll loop to wake up when ->port_poll() will return a |
1144 | * value other than EAGAIN. | |
1145 | * | |
1146 | * If the set of ports in a datapath is fixed, or if the only way that the | |
1147 | * set of ports in a datapath can change is through ->port_add() and | |
1148 | * ->port_del(), or if the poll loop will always wake up anyway when | |
1149 | * ->port_poll() will return a value other than EAGAIN, then this function | |
1150 | * may be a null pointer. | |
1151 | */ | |
abe529af BP |
1152 | void (*port_poll_wait)(const struct ofproto *ofproto); |
1153 | ||
5bf0e941 BP |
1154 | /* Checks the status of LACP negotiation for 'port'. Returns 1 if LACP |
1155 | * partner information for 'port' is up-to-date, 0 if LACP partner | |
1156 | * information is not current (generally indicating a connectivity | |
1157 | * problem), or -1 if LACP is not enabled on 'port'. | |
1158 | * | |
1159 | * This function may be a null pointer if the ofproto implementation does | |
0477baa9 DF |
1160 | * not support LACP. |
1161 | */ | |
abe529af BP |
1162 | int (*port_is_lacp_current)(const struct ofport *port); |
1163 | ||
50b9699f NM |
1164 | /* Get LACP port stats. Returns -1 if LACP is not enabled on 'port'. |
1165 | * | |
1166 | * This function may be a null pointer if the ofproto implementation does | |
0477baa9 DF |
1167 | * not support LACP. |
1168 | */ | |
50b9699f | 1169 | int (*port_get_lacp_stats)(const struct ofport *port, |
0477baa9 | 1170 | struct lacp_slave_stats *stats); |
50b9699f | 1171 | |
5bf0e941 BP |
1172 | /* ## ----------------------- ## */ |
1173 | /* ## OpenFlow Rule Functions ## */ | |
1174 | /* ## ----------------------- ## */ | |
1175 | ||
81a76618 | 1176 | /* Chooses an appropriate table for 'match' within 'ofproto'. On |
0ab6decf | 1177 | * success, stores the table ID into '*table_idp' and returns 0. On |
90bf1e07 | 1178 | * failure, returns an OpenFlow error code. |
0ab6decf | 1179 | * |
81a76618 | 1180 | * The choice of table should be a function of 'match' and 'ofproto''s |
0ab6decf BP |
1181 | * datapath capabilities. It should not depend on the flows already in |
1182 | * 'ofproto''s flow tables. Failure implies that an OpenFlow rule with | |
81a76618 BP |
1183 | * 'match' as its matching condition can never be inserted into 'ofproto', |
1184 | * even starting from an empty flow table. | |
0ab6decf BP |
1185 | * |
1186 | * If multiple tables are candidates for inserting the flow, the function | |
1187 | * should choose one arbitrarily (but deterministically). | |
1188 | * | |
13521ff5 | 1189 | * If this function is NULL then table 0 is always chosen. */ |
90bf1e07 | 1190 | enum ofperr (*rule_choose_table)(const struct ofproto *ofproto, |
81a76618 | 1191 | const struct match *match, |
90bf1e07 | 1192 | uint8_t *table_idp); |
0ab6decf | 1193 | |
8037acb4 BP |
1194 | /* Life-cycle functions for a "struct rule". |
1195 | * | |
1196 | * | |
1197 | * Rule Life Cycle | |
1198 | * =============== | |
1199 | * | |
1200 | * The life cycle of a struct rule is an elaboration of the basic life | |
1201 | * cycle described above under "Life Cycle". | |
1202 | * | |
1203 | * After a rule is successfully constructed, it is then inserted. If | |
834fe5cb BP |
1204 | * insertion is successful, then before it is later destructed, it is |
1205 | * deleted. | |
8037acb4 BP |
1206 | * |
1207 | * You can think of a rule as having the following extra steps inserted | |
1208 | * between "Life Cycle" steps 4 and 5: | |
1209 | * | |
1210 | * 4.1. The client inserts the rule into the flow table, making it | |
1211 | * visible in flow table lookups. | |
1212 | * | |
834fe5cb BP |
1213 | * 4.2. The client calls "rule_insert" to insert the flow. The |
1214 | * implementation attempts to install the flow in the underlying | |
1215 | * hardware and returns an error code indicate success or failure. | |
1216 | * On failure, go to step 5. | |
8037acb4 BP |
1217 | * |
1218 | * 4.3. The rule is now installed in the flow table. Eventually it will | |
1219 | * be deleted. | |
1220 | * | |
1221 | * 4.4. The client removes the rule from the flow table. It is no longer | |
1222 | * visible in flow table lookups. | |
1223 | * | |
834fe5cb BP |
1224 | * 4.5. The client calls "rule_delete". The implementation uninstalls |
1225 | * the flow from the underlying hardware. Deletion is not allowed | |
1226 | * to fail. | |
7ee20df1 BP |
1227 | * |
1228 | * | |
1229 | * Construction | |
1230 | * ============ | |
1231 | * | |
8037acb4 BP |
1232 | * When ->rule_construct() is called, 'rule' is a new rule that is not yet |
1233 | * inserted into a flow table. ->rule_construct() should initialize enough | |
1234 | * of the rule's derived state for 'rule' to be suitable for inserting into | |
1235 | * a flow table. ->rule_construct() should not modify any base members of | |
1236 | * struct rule. | |
7ee20df1 | 1237 | * |
8037acb4 BP |
1238 | * If ->rule_construct() fails (as indicated by returning a nonzero |
1239 | * OpenFlow error code), the ofproto base code will uninitialize and | |
1240 | * deallocate 'rule'. See "Rule Life Cycle" above for more details. | |
7ee20df1 | 1241 | * |
39c94593 | 1242 | * ->rule_construct() must also: |
8037acb4 BP |
1243 | * |
1244 | * - Validate that the datapath supports the matching rule in 'rule->cr' | |
7ee20df1 BP |
1245 | * datapath. For example, if the rule's table does not support |
1246 | * registers, then it is an error if 'rule->cr' does not wildcard all | |
5bf0e941 BP |
1247 | * registers. |
1248 | * | |
548de4dd | 1249 | * - Validate that the datapath can correctly implement 'rule->ofpacts'. |
5bf0e941 | 1250 | * |
39c94593 JR |
1251 | * After a successful construction the rest of the rule life cycle calls |
1252 | * may not fail, so ->rule_construct() must also make sure that the rule | |
1253 | * can be inserted in to the datapath. | |
8037acb4 BP |
1254 | * |
1255 | * | |
1256 | * Insertion | |
1257 | * ========= | |
1258 | * | |
1259 | * Following successful construction, the ofproto base case inserts 'rule' | |
1260 | * into its flow table, then it calls ->rule_insert(). ->rule_insert() | |
834fe5cb | 1261 | * must add the new rule to the datapath flow table and return only after |
39c94593 JR |
1262 | * this is complete. The 'new_rule' may be a duplicate of an 'old_rule'. |
1263 | * In this case the 'old_rule' is non-null, and the implementation should | |
748eb2f5 JR |
1264 | * forward rule statistics counts from the 'old_rule' to the 'new_rule' if |
1265 | * 'forward_counts' is 'true', 'used' timestamp is always forwarded. This | |
1266 | * may not fail. | |
5bf0e941 | 1267 | * |
5bf0e941 | 1268 | * |
8037acb4 BP |
1269 | * Deletion |
1270 | * ======== | |
5bf0e941 | 1271 | * |
8037acb4 | 1272 | * The ofproto base code removes 'rule' from its flow table before it calls |
1fc71871 JR |
1273 | * ->rule_delete() (if non-null). ->rule_delete() must remove 'rule' from |
1274 | * the datapath flow table and return only after this has completed | |
1275 | * successfully. | |
7ee20df1 | 1276 | * |
8037acb4 | 1277 | * Rule deletion must not fail. |
7ee20df1 BP |
1278 | * |
1279 | * | |
1280 | * Destruction | |
1281 | * =========== | |
1282 | * | |
8037acb4 | 1283 | * ->rule_destruct() must uninitialize derived state. |
7ee20df1 BP |
1284 | * |
1285 | * Rule destruction must not fail. */ | |
abe529af | 1286 | struct rule *(*rule_alloc)(void); |
15aaf599 BP |
1287 | enum ofperr (*rule_construct)(struct rule *rule) |
1288 | /* OVS_REQUIRES(ofproto_mutex) */; | |
39c94593 | 1289 | void (*rule_insert)(struct rule *rule, struct rule *old_rule, |
748eb2f5 | 1290 | bool forward_counts) |
b20f4073 | 1291 | /* OVS_REQUIRES(ofproto_mutex) */; |
15aaf599 | 1292 | void (*rule_delete)(struct rule *rule) /* OVS_REQUIRES(ofproto_mutex) */; |
abe529af BP |
1293 | void (*rule_destruct)(struct rule *rule); |
1294 | void (*rule_dealloc)(struct rule *rule); | |
1295 | ||
5bf0e941 BP |
1296 | /* Obtains statistics for 'rule', storing the number of packets that have |
1297 | * matched it in '*packet_count' and the number of bytes in those packets | |
5e9d0469 BP |
1298 | * in '*byte_count'. UINT64_MAX indicates that the packet count or byte |
1299 | * count is unknown. */ | |
abe529af | 1300 | void (*rule_get_stats)(struct rule *rule, uint64_t *packet_count, |
dc437090 | 1301 | uint64_t *byte_count, long long int *used) |
15aaf599 | 1302 | /* OVS_EXCLUDED(ofproto_mutex) */; |
abe529af | 1303 | |
1f4a8933 JR |
1304 | /* Translates actions in 'opo->ofpacts', for 'opo->packet' in flow tables |
1305 | * in version 'opo->version'. This is useful for OpenFlow OFPT_PACKET_OUT. | |
1306 | * | |
1307 | * This function must validate that it can correctly translate | |
1308 | * 'opo->ofpacts'. If not, then it should return an OpenFlow error code. | |
1309 | * | |
1310 | * 'opo->flow' reflects the flow information for 'opo->packet'. All of the | |
1311 | * information in 'opo->flow' is extracted from 'opo->packet', except for | |
1312 | * 'in_port', which is assigned to the correct value for the incoming | |
1313 | * packet. 'tunnel' and register values should be zeroed. 'packet''s | |
1314 | * header pointers and offsets (e.g. packet->l3) are appropriately | |
1315 | * initialized. packet->l3 is aligned on a 32-bit boundary. | |
1316 | * | |
1317 | * Returns 0 if successful, otherwise an OpenFlow error code. | |
1318 | * | |
1319 | * This function may be called with 'ofproto_mutex' held. */ | |
1320 | enum ofperr (*packet_xlate)(struct ofproto *, | |
1321 | struct ofproto_packet_out *opo); | |
1322 | ||
6dd3c787 JR |
1323 | /* Free resources taken by a successful packet_xlate(). If multiple |
1324 | * packet_xlate() calls have been made in sequence, the corresponding | |
1325 | * packet_xlate_revert() calls have to be made in reverse order. */ | |
1326 | void (*packet_xlate_revert)(struct ofproto *, struct ofproto_packet_out *); | |
1327 | ||
1f4a8933 JR |
1328 | /* Executes the datapath actions, translation side-effects, and stats as |
1329 | * produced by ->packet_xlate(). The caller retains ownership of 'opo'. | |
1330 | */ | |
1331 | void (*packet_execute)(struct ofproto *, struct ofproto_packet_out *opo); | |
1332 | ||
7257b535 BP |
1333 | /* Changes the OpenFlow IP fragment handling policy to 'frag_handling', |
1334 | * which takes one of the following values, with the corresponding | |
1335 | * meanings: | |
1336 | * | |
ad99e2ed BP |
1337 | * - OFPUTIL_FRAG_NORMAL: The switch should treat IP fragments the same |
1338 | * way as other packets, omitting TCP and UDP port numbers (always | |
1339 | * setting them to 0). | |
7257b535 | 1340 | * |
ad99e2ed | 1341 | * - OFPUTIL_FRAG_DROP: The switch should drop all IP fragments without |
7257b535 BP |
1342 | * passing them through the flow table. |
1343 | * | |
ad99e2ed | 1344 | * - OFPUTIL_FRAG_REASM: The switch should reassemble IP fragments before |
7257b535 BP |
1345 | * passing packets through the flow table. |
1346 | * | |
ad99e2ed BP |
1347 | * - OFPUTIL_FRAG_NX_MATCH (a Nicira extension): Similar to |
1348 | * OFPUTIL_FRAG_NORMAL, except that TCP and UDP port numbers should be | |
1349 | * included in fragments with offset 0. | |
7257b535 BP |
1350 | * |
1351 | * Implementations are not required to support every mode. | |
ad99e2ed | 1352 | * OFPUTIL_FRAG_NORMAL is the default mode when an ofproto is created. |
7257b535 BP |
1353 | * |
1354 | * At the time of the call to ->set_frag_handling(), the current mode is | |
1355 | * available in 'ofproto->frag_handling'. ->set_frag_handling() returns | |
1356 | * true if the requested mode was set, false if it is not supported. | |
1357 | * | |
1358 | * Upon successful return, the caller changes 'ofproto->frag_handling' to | |
1359 | * reflect the new mode. | |
1360 | */ | |
1361 | bool (*set_frag_handling)(struct ofproto *ofproto, | |
ad99e2ed | 1362 | enum ofputil_frag_handling frag_handling); |
abe529af | 1363 | |
77ab5fd2 BP |
1364 | enum ofperr (*nxt_resume)(struct ofproto *ofproto, |
1365 | const struct ofputil_packet_in_private *); | |
1366 | ||
5bf0e941 BP |
1367 | /* ## ------------------------- ## */ |
1368 | /* ## OFPP_NORMAL configuration ## */ | |
1369 | /* ## ------------------------- ## */ | |
1370 | ||
abe529af BP |
1371 | /* Configures NetFlow on 'ofproto' according to the options in |
1372 | * 'netflow_options', or turns off NetFlow if 'netflow_options' is NULL. | |
1373 | * | |
1374 | * EOPNOTSUPP as a return value indicates that 'ofproto' does not support | |
f8cd50a4 | 1375 | * NetFlow, as does a null pointer. */ |
abe529af BP |
1376 | int (*set_netflow)(struct ofproto *ofproto, |
1377 | const struct netflow_options *netflow_options); | |
1378 | ||
1379 | void (*get_netflow_ids)(const struct ofproto *ofproto, | |
1380 | uint8_t *engine_type, uint8_t *engine_id); | |
1381 | ||
1382 | /* Configures sFlow on 'ofproto' according to the options in | |
1383 | * 'sflow_options', or turns off sFlow if 'sflow_options' is NULL. | |
1384 | * | |
1385 | * EOPNOTSUPP as a return value indicates that 'ofproto' does not support | |
1386 | * sFlow, as does a null pointer. */ | |
1387 | int (*set_sflow)(struct ofproto *ofproto, | |
1388 | const struct ofproto_sflow_options *sflow_options); | |
1389 | ||
29089a54 RL |
1390 | /* Configures IPFIX on 'ofproto' according to the options in |
1391 | * 'bridge_exporter_options' and the 'flow_exporters_options' | |
1392 | * array, or turns off IPFIX if 'bridge_exporter_options' and | |
1393 | * 'flow_exporters_options' is NULL. | |
1394 | * | |
1395 | * EOPNOTSUPP as a return value indicates that 'ofproto' does not support | |
1396 | * IPFIX, as does a null pointer. */ | |
1397 | int (*set_ipfix)( | |
1398 | struct ofproto *ofproto, | |
1399 | const struct ofproto_ipfix_bridge_exporter_options | |
1400 | *bridge_exporter_options, | |
1401 | const struct ofproto_ipfix_flow_exporter_options | |
1402 | *flow_exporters_options, size_t n_flow_exporters_options); | |
1403 | ||
fb8f22c1 BY |
1404 | /* Gets IPFIX stats on 'ofproto' according to the exporter of birdge |
1405 | * IPFIX or flow-based IPFIX. | |
1406 | * | |
1407 | * OFPERR_NXST_NOT_CONFIGURED as a return value indicates that bridge | |
1408 | * IPFIX or flow-based IPFIX is not configured. */ | |
1409 | int (*get_ipfix_stats)( | |
1410 | const struct ofproto *ofproto, | |
1411 | bool bridge_ipfix, struct ovs_list *replies | |
1412 | ); | |
1413 | ||
abe529af BP |
1414 | /* Configures connectivity fault management on 'ofport'. |
1415 | * | |
a5610457 | 1416 | * If 'cfm_settings' is nonnull, configures CFM according to its members. |
abe529af | 1417 | * |
a5610457 | 1418 | * If 'cfm_settings' is null, removes any connectivity fault management |
abe529af BP |
1419 | * configuration from 'ofport'. |
1420 | * | |
1421 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1422 | * support CFM, as does a null pointer. */ | |
a5610457 | 1423 | int (*set_cfm)(struct ofport *ofport, const struct cfm_settings *s); |
abe529af | 1424 | |
8f5514fe AW |
1425 | /* Checks the status change of CFM on 'ofport'. Returns true if |
1426 | * there is status change since last call or if CFM is not specified. */ | |
1427 | bool (*cfm_status_changed)(struct ofport *ofport); | |
1428 | ||
1429 | /* Populates 'smap' with the status of CFM on 'ofport'. Returns 0 on | |
1430 | * success, or a positive errno. EOPNOTSUPP as a return value indicates | |
1431 | * that this ofproto_class does not support CFM, as does a null pointer. | |
88bf179a AW |
1432 | * |
1433 | * The caller must provide and own '*status', and it must free the array | |
1434 | * returned in 'status->rmps'. '*status' is indeterminate if the return | |
1435 | * value is non-zero. */ | |
1436 | int (*get_cfm_status)(const struct ofport *ofport, | |
685acfd9 | 1437 | struct cfm_status *status); |
3967a833 | 1438 | |
0477baa9 DF |
1439 | /* Configures LLDP on 'ofport'. |
1440 | * | |
1441 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1442 | * support LLDP, as does a null pointer. */ | |
1443 | int (*set_lldp)(struct ofport *ofport, const struct smap *cfg); | |
1444 | ||
1445 | /* Checks the status of LLDP configured on 'ofport'. Returns true if the | |
1446 | * port's LLDP status was successfully stored into '*status'. Returns | |
1447 | * false if the port did not have LLDP configured, in which case '*status' | |
1448 | * is indeterminate. | |
1449 | * | |
1450 | * The caller must provide and own '*status'. '*status' is indeterminate | |
1451 | * if the return value is non-zero. */ | |
1452 | bool (*get_lldp_status)(const struct ofport *ofport, | |
1453 | struct lldp_status *status); | |
1454 | ||
1455 | /* Configures Auto Attach. | |
1456 | * | |
1457 | * If 's' is nonnull, configures Auto Attach according to its members. | |
1458 | * | |
1459 | * If 's' is null, removes any Auto Attach configuration. | |
1460 | */ | |
1461 | int (*set_aa)(struct ofproto *ofproto, | |
1462 | const struct aa_settings *s); | |
1463 | ||
1464 | /* If 's' is nonnull, this function registers a mapping associated with | |
1465 | * client data pointer 'aux' in 'ofproto'. If 'aux' is already registered | |
1466 | * then this function updates its configuration to 's'. Otherwise, this | |
1467 | * function registers a new mapping. | |
1468 | * | |
1469 | * An implementation that does not support mapping at all may set | |
1470 | * it to NULL or return EOPNOTSUPP. An implementation that supports | |
1471 | * only a subset of the functionality should implement what it can | |
1472 | * and return 0. | |
1473 | */ | |
1474 | int (*aa_mapping_set)(struct ofproto *ofproto, void *aux, | |
1475 | const struct aa_mapping_settings *s); | |
1476 | ||
1477 | /* If 's' is nonnull, this function unregisters a mapping associated with | |
1478 | * client data pointer 'aux' in 'ofproto'. If 'aux' is already registered | |
1479 | * then this function updates its configuration to 's'. Otherwise, this | |
1480 | * function unregisters a new mapping. | |
1481 | * | |
1482 | * An implementation that does not support mapping at all may set | |
1483 | * it to NULL or return EOPNOTSUPP. An implementation that supports | |
1484 | * only a subset of the functionality should implement what it can | |
1485 | * and return 0. | |
1486 | */ | |
1487 | int (*aa_mapping_unset)(struct ofproto *ofproto, void *aux); | |
1488 | ||
1489 | /* | |
1490 | * Returns the a list of AutoAttach VLAN operations. When Auto Attach is | |
1491 | * enabled, the VLAN associated with an I-SID/VLAN mapping is first | |
1492 | * negotiated with an Auto Attach Server. Once an I-SID VLAN mapping | |
1493 | * becomes active, the corresponding VLAN needs to be communicated to the | |
1494 | * bridge in order to add the VLAN to the trunk port linking the Auto | |
1495 | * Attach Client (in this case openvswitch) and the Auto Attach Server. | |
1496 | * | |
1497 | * The list entries are of type "struct bridge_aa_vlan". Each entry | |
1498 | * specifies the operation (add or remove), the interface on which to | |
1499 | * execute the operation and the VLAN. | |
1500 | */ | |
1501 | int (*aa_vlan_get_queued)(struct ofproto *ofproto, struct ovs_list *list); | |
1502 | ||
1503 | /* | |
1504 | * Returns the current number of entries in the list of VLAN operations | |
1505 | * in the Auto Attach Client (see previous function description | |
1506 | * aa_vlan_get_queued). Returns 0 if Auto Attach is disabled. | |
1507 | */ | |
1508 | unsigned int (*aa_vlan_get_queue_size)(struct ofproto *ofproto); | |
1509 | ||
ccc09689 EJ |
1510 | /* Configures BFD on 'ofport'. |
1511 | * | |
1512 | * If 'cfg' is NULL, or 'cfg' does not contain the key value pair | |
1513 | * "enable=true", removes BFD from 'ofport'. Otherwise, configures BFD | |
1514 | * according to 'cfg'. | |
1515 | * | |
1516 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1517 | * support BFD, as does a null pointer. */ | |
1518 | int (*set_bfd)(struct ofport *ofport, const struct smap *cfg); | |
1519 | ||
8f5514fe AW |
1520 | /* Checks the status change of BFD on 'ofport'. Returns true if there |
1521 | * is status change since last call or if BFD is not specified. */ | |
1522 | bool (*bfd_status_changed)(struct ofport *ofport); | |
1523 | ||
ccc09689 | 1524 | /* Populates 'smap' with the status of BFD on 'ofport'. Returns 0 on |
8f5514fe AW |
1525 | * success, or a positive errno. EOPNOTSUPP as a return value indicates |
1526 | * that this ofproto_class does not support BFD, as does a null pointer. */ | |
ccc09689 EJ |
1527 | int (*get_bfd_status)(struct ofport *ofport, struct smap *smap); |
1528 | ||
21f7563c JP |
1529 | /* Configures spanning tree protocol (STP) on 'ofproto' using the |
1530 | * settings defined in 's'. | |
1531 | * | |
1532 | * If 's' is nonnull, configures STP according to its members. | |
1533 | * | |
1534 | * If 's' is null, removes any STP configuration from 'ofproto'. | |
1535 | * | |
1536 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1537 | * support STP, as does a null pointer. */ | |
1538 | int (*set_stp)(struct ofproto *ofproto, | |
1539 | const struct ofproto_stp_settings *s); | |
1540 | ||
1541 | /* Retrieves state of spanning tree protocol (STP) on 'ofproto'. | |
1542 | * | |
1543 | * Stores STP state for 'ofproto' in 's'. If the 'enabled' member | |
1544 | * is false, the other member values are not meaningful. | |
1545 | * | |
1546 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1547 | * support STP, as does a null pointer. */ | |
1548 | int (*get_stp_status)(struct ofproto *ofproto, | |
1549 | struct ofproto_stp_status *s); | |
1550 | ||
1551 | /* Configures spanning tree protocol (STP) on 'ofport' using the | |
1552 | * settings defined in 's'. | |
1553 | * | |
1554 | * If 's' is nonnull, configures STP according to its members. The | |
1555 | * caller is responsible for assigning STP port numbers (using the | |
1556 | * 'port_num' member in the range of 1 through 255, inclusive) and | |
1557 | * ensuring there are no duplicates. | |
1558 | * | |
1559 | * If 's' is null, removes any STP configuration from 'ofport'. | |
1560 | * | |
1561 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1562 | * support STP, as does a null pointer. */ | |
1563 | int (*set_stp_port)(struct ofport *ofport, | |
1564 | const struct ofproto_port_stp_settings *s); | |
1565 | ||
1566 | /* Retrieves spanning tree protocol (STP) port status of 'ofport'. | |
1567 | * | |
1568 | * Stores STP state for 'ofport' in 's'. If the 'enabled' member is | |
1569 | * false, the other member values are not meaningful. | |
1570 | * | |
1571 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1572 | * support STP, as does a null pointer. */ | |
1573 | int (*get_stp_port_status)(struct ofport *ofport, | |
1574 | struct ofproto_port_stp_status *s); | |
1575 | ||
fd28ce3a JS |
1576 | /* Retrieves spanning tree protocol (STP) port statistics of 'ofport'. |
1577 | * | |
1578 | * Stores STP state for 'ofport' in 's'. If the 'enabled' member is | |
1579 | * false, the other member values are not meaningful. | |
1580 | * | |
1581 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1582 | * support STP, as does a null pointer. */ | |
1583 | int (*get_stp_port_stats)(struct ofport *ofport, | |
1584 | struct ofproto_port_stp_stats *s); | |
1585 | ||
9efd308e DV |
1586 | /* Configures Rapid Spanning Tree Protocol (RSTP) on 'ofproto' using the |
1587 | * settings defined in 's'. | |
1588 | * | |
1589 | * If 's' is nonnull, configures RSTP according to its members. | |
1590 | * | |
1591 | * If 's' is null, removes any RSTP configuration from 'ofproto'. | |
1592 | * | |
1593 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1594 | * support RSTP, as does a null pointer. */ | |
1595 | void (*set_rstp)(struct ofproto *ofproto, | |
1596 | const struct ofproto_rstp_settings *s); | |
1597 | ||
1598 | /* Retrieves state of Rapid Spanning Tree Protocol (RSTP) on 'ofproto'. | |
1599 | * | |
1600 | * Stores RSTP state for 'ofproto' in 's'. If the 'enabled' member | |
1601 | * is false, the other member values are not meaningful. | |
1602 | * | |
1603 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1604 | * support RSTP, as does a null pointer. */ | |
1605 | void (*get_rstp_status)(struct ofproto *ofproto, | |
1606 | struct ofproto_rstp_status *s); | |
1607 | ||
1608 | /* Configures Rapid Spanning Tree Protocol (RSTP) on 'ofport' using the | |
1609 | * settings defined in 's'. | |
1610 | * | |
1611 | * If 's' is nonnull, configures RSTP according to its members. The | |
1612 | * caller is responsible for assigning RSTP port numbers (using the | |
1613 | * 'port_num' member in the range of 1 through 255, inclusive) and | |
1614 | * ensuring there are no duplicates. | |
1615 | * | |
1616 | * If 's' is null, removes any RSTP configuration from 'ofport'. | |
1617 | * | |
1618 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1619 | * support STP, as does a null pointer. */ | |
1620 | void (*set_rstp_port)(struct ofport *ofport, | |
1621 | const struct ofproto_port_rstp_settings *s); | |
1622 | ||
1623 | /* Retrieves Rapid Spanning Tree Protocol (RSTP) port status of 'ofport'. | |
1624 | * | |
1625 | * Stores RSTP state for 'ofport' in 's'. If the 'enabled' member is | |
1626 | * false, the other member values are not meaningful. | |
1627 | * | |
1628 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1629 | * support RSTP, as does a null pointer. */ | |
1630 | void (*get_rstp_port_status)(struct ofport *ofport, | |
1631 | struct ofproto_port_rstp_status *s); | |
1632 | ||
8b36f51e EJ |
1633 | /* Registers meta-data associated with the 'n_qdscp' Qualities of Service |
1634 | * 'queues' attached to 'ofport'. This data is not intended to be | |
1635 | * sufficient to implement QoS. Instead, providers may use this | |
1636 | * information to implement features which require knowledge of what queues | |
1637 | * exist on a port, and some basic information about them. | |
1638 | * | |
1639 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1640 | * support QoS, as does a null pointer. */ | |
1641 | int (*set_queues)(struct ofport *ofport, | |
1642 | const struct ofproto_port_queue *queues, size_t n_qdscp); | |
1643 | ||
abe529af BP |
1644 | /* If 's' is nonnull, this function registers a "bundle" associated with |
1645 | * client data pointer 'aux' in 'ofproto'. A bundle is the same concept as | |
1646 | * a Port in OVSDB, that is, it consists of one or more "slave" devices | |
1647 | * (Interfaces, in OVSDB) along with VLAN and LACP configuration and, if | |
1648 | * there is more than one slave, a bonding configuration. If 'aux' is | |
1649 | * already registered then this function updates its configuration to 's'. | |
1650 | * Otherwise, this function registers a new bundle. | |
1651 | * | |
1652 | * If 's' is NULL, this function unregisters the bundle registered on | |
1653 | * 'ofproto' associated with client data pointer 'aux'. If no such bundle | |
1654 | * has been registered, this has no effect. | |
1655 | * | |
1656 | * This function affects only the behavior of the NXAST_AUTOPATH action and | |
1657 | * output to the OFPP_NORMAL port. An implementation that does not support | |
1658 | * it at all may set it to NULL or return EOPNOTSUPP. An implementation | |
1659 | * that supports only a subset of the functionality should implement what | |
1660 | * it can and return 0. */ | |
1661 | int (*bundle_set)(struct ofproto *ofproto, void *aux, | |
1662 | const struct ofproto_bundle_settings *s); | |
1663 | ||
1664 | /* If 'port' is part of any bundle, removes it from that bundle. If the | |
1665 | * bundle now has no ports, deletes the bundle. If the bundle now has only | |
1666 | * one port, deconfigures the bundle's bonding configuration. */ | |
1667 | void (*bundle_remove)(struct ofport *ofport); | |
1668 | ||
1669 | /* If 's' is nonnull, this function registers a mirror associated with | |
1670 | * client data pointer 'aux' in 'ofproto'. A mirror is the same concept as | |
1671 | * a Mirror in OVSDB. If 'aux' is already registered then this function | |
1672 | * updates its configuration to 's'. Otherwise, this function registers a | |
1673 | * new mirror. | |
1674 | * | |
1675 | * If 's' is NULL, this function unregisters the mirror registered on | |
1676 | * 'ofproto' associated with client data pointer 'aux'. If no such mirror | |
1677 | * has been registered, this has no effect. | |
1678 | * | |
c06bba01 JP |
1679 | * An implementation that does not support mirroring at all may set |
1680 | * it to NULL or return EOPNOTSUPP. An implementation that supports | |
1681 | * only a subset of the functionality should implement what it can | |
1682 | * and return 0. */ | |
abe529af BP |
1683 | int (*mirror_set)(struct ofproto *ofproto, void *aux, |
1684 | const struct ofproto_mirror_settings *s); | |
1685 | ||
9d24de3b JP |
1686 | /* Retrieves statistics from mirror associated with client data |
1687 | * pointer 'aux' in 'ofproto'. Stores packet and byte counts in | |
1688 | * 'packets' and 'bytes', respectively. If a particular counter is | |
1689 | * not supported, the appropriate argument is set to UINT64_MAX. | |
1690 | * | |
1691 | * EOPNOTSUPP as a return value indicates that this ofproto_class does not | |
1692 | * support retrieving mirror statistics. */ | |
1693 | int (*mirror_get_stats)(struct ofproto *ofproto, void *aux, | |
1694 | uint64_t *packets, uint64_t *bytes); | |
1695 | ||
abe529af BP |
1696 | /* Configures the VLANs whose bits are set to 1 in 'flood_vlans' as VLANs |
1697 | * on which all packets are flooded, instead of using MAC learning. If | |
1698 | * 'flood_vlans' is NULL, then MAC learning applies to all VLANs. | |
1699 | * | |
1700 | * This function affects only the behavior of the OFPP_NORMAL action. An | |
1701 | * implementation that does not support it may set it to NULL or return | |
1702 | * EOPNOTSUPP. */ | |
1703 | int (*set_flood_vlans)(struct ofproto *ofproto, | |
1704 | unsigned long *flood_vlans); | |
1705 | ||
1706 | /* Returns true if 'aux' is a registered bundle that is currently in use as | |
1707 | * the output for a mirror. */ | |
b4affc74 | 1708 | bool (*is_mirror_output_bundle)(const struct ofproto *ofproto, void *aux); |
8402c74b SS |
1709 | |
1710 | /* When the configuration option of forward_bpdu changes, this function | |
1711 | * will be invoked. */ | |
1712 | void (*forward_bpdu_changed)(struct ofproto *ofproto); | |
52a90c29 | 1713 | |
c4069512 BP |
1714 | /* Sets the MAC aging timeout for the OFPP_NORMAL action to 'idle_time', in |
1715 | * seconds, and the maximum number of MAC table entries to | |
1716 | * 'max_entries'. | |
1717 | * | |
1718 | * An implementation that doesn't support configuring these features may | |
1719 | * set this function to NULL or implement it as a no-op. */ | |
1720 | void (*set_mac_table_config)(struct ofproto *ofproto, | |
1721 | unsigned int idle_time, size_t max_entries); | |
e764773c | 1722 | |
7c38d0a5 FL |
1723 | /* Configures multicast snooping on 'ofport' using the settings |
1724 | * defined in 's'. | |
1725 | * | |
1726 | * If 's' is nonnull, this function updates multicast snooping | |
1727 | * configuration to 's' in 'ofproto'. | |
1728 | * | |
1729 | * If 's' is NULL, this function disables multicast snooping | |
1730 | * on 'ofproto'. | |
1731 | * | |
1732 | * An implementation that does not support multicast snooping may set | |
1733 | * it to NULL or return EOPNOTSUPP. */ | |
1734 | int (*set_mcast_snooping)(struct ofproto *ofproto, | |
1735 | const struct ofproto_mcast_snooping_settings *s); | |
1736 | ||
1737 | /* Configures multicast snooping port's flood setting on 'ofproto'. | |
1738 | * | |
8e04a33f FL |
1739 | * If 's' is nonnull, this function updates multicast snooping |
1740 | * configuration to 's' in 'ofproto'. | |
1741 | * | |
1742 | * If 's' is NULL, this function doesn't change anything. | |
7c38d0a5 FL |
1743 | * |
1744 | * An implementation that does not support multicast snooping may set | |
1745 | * it to NULL or return EOPNOTSUPP. */ | |
1746 | int (*set_mcast_snooping_port)(struct ofproto *ofproto_, void *aux, | |
8e04a33f | 1747 | const struct ofproto_mcast_snooping_port_settings *s); |
7c38d0a5 | 1748 | |
9cae45dc JR |
1749 | /* ## ------------------------ ## */ |
1750 | /* ## OpenFlow meter functions ## */ | |
1751 | /* ## ------------------------ ## */ | |
1752 | ||
1753 | /* These functions should be NULL if an implementation does not support | |
1754 | * them. They must be all null or all non-null.. */ | |
1755 | ||
1756 | /* Initializes 'features' to describe the metering features supported by | |
1757 | * 'ofproto'. */ | |
1758 | void (*meter_get_features)(const struct ofproto *ofproto, | |
1759 | struct ofputil_meter_features *features); | |
1760 | ||
1761 | /* If '*id' is UINT32_MAX, adds a new meter with the given 'config'. On | |
1762 | * success the function must store a provider meter ID other than | |
1763 | * UINT32_MAX in '*id'. All further references to the meter will be made | |
1764 | * with the returned provider meter id rather than the OpenFlow meter id. | |
1765 | * The caller does not try to interpret the provider meter id, giving the | |
1766 | * implementation the freedom to either use the OpenFlow meter_id value | |
1767 | * provided in the meter configuration, or any other value suitable for the | |
1768 | * implementation. | |
1769 | * | |
1770 | * If '*id' is a value other than UINT32_MAX, modifies the existing meter | |
e555eb7c JR |
1771 | * with that meter provider ID to have configuration 'config', while |
1772 | * leaving '*id' unchanged. On failure, the existing meter configuration | |
1773 | * is left intact. */ | |
9cae45dc | 1774 | enum ofperr (*meter_set)(struct ofproto *ofproto, ofproto_meter_id *id, |
5dddf960 | 1775 | struct ofputil_meter_config *config); |
9cae45dc JR |
1776 | |
1777 | /* Gets the meter and meter band packet and byte counts for maximum of | |
5dddf960 JR |
1778 | * 'n_bands' bands for the meter with provider ID 'id' within 'ofproto'. |
1779 | * The caller fills in the other stats values. The band stats are copied | |
1780 | * to memory at 'stats->bands' provided by the caller. The number of | |
1781 | * returned band stats is returned in 'stats->n_bands'. */ | |
9cae45dc JR |
1782 | enum ofperr (*meter_get)(const struct ofproto *ofproto, |
1783 | ofproto_meter_id id, | |
5dddf960 JR |
1784 | struct ofputil_meter_stats *stats, |
1785 | uint16_t n_bands); | |
9cae45dc JR |
1786 | |
1787 | /* Deletes a meter, making the 'ofproto_meter_id' invalid for any | |
1788 | * further calls. */ | |
1789 | void (*meter_del)(struct ofproto *, ofproto_meter_id); | |
7395c052 NZ |
1790 | |
1791 | ||
1792 | /* ## -------------------- ## */ | |
1793 | /* ## OpenFlow 1.1+ groups ## */ | |
1794 | /* ## -------------------- ## */ | |
1795 | ||
1796 | struct ofgroup *(*group_alloc)(void); | |
1797 | enum ofperr (*group_construct)(struct ofgroup *); | |
1798 | void (*group_destruct)(struct ofgroup *); | |
1799 | void (*group_dealloc)(struct ofgroup *); | |
1800 | ||
2b0b0b80 | 1801 | void (*group_modify)(struct ofgroup *); |
7395c052 NZ |
1802 | |
1803 | enum ofperr (*group_get_stats)(const struct ofgroup *, | |
1804 | struct ofputil_group_stats *); | |
b5cbbcf6 AZ |
1805 | |
1806 | /* ## --------------------- ## */ | |
1807 | /* ## Datapath information ## */ | |
1808 | /* ## --------------------- ## */ | |
1809 | /* Retrieve the version string of the datapath. The version | |
1810 | * string can be NULL if it can not be determined. | |
1811 | * | |
1812 | * The version retuned is read only. The caller should not | |
1813 | * free it. | |
1814 | * | |
1815 | * This function should be NULL if an implementation does not support it. | |
1816 | */ | |
1817 | const char *(*get_datapath_version)(const struct ofproto *); | |
2a7c4805 | 1818 | |
d4f6865c DDP |
1819 | /* Pass custom configuration options to the 'type' datapath. |
1820 | * | |
1821 | * This function should be NULL if an implementation does not support it. | |
1822 | */ | |
1823 | void (*type_set_config)(const char *type, | |
1824 | const struct smap *other_config); | |
1825 | ||
2a7c4805 JP |
1826 | /* ## ------------------- ## */ |
1827 | /* ## Connection tracking ## */ | |
1828 | /* ## ------------------- ## */ | |
1829 | /* Flushes the connection tracking tables. If 'zone' is not NULL, | |
1830 | * only deletes connections in '*zone'. */ | |
1831 | void (*ct_flush)(const struct ofproto *, const uint16_t *zone); | |
abe529af BP |
1832 | }; |
1833 | ||
1834 | extern const struct ofproto_class ofproto_dpif_class; | |
1835 | ||
1836 | int ofproto_class_register(const struct ofproto_class *); | |
1837 | int ofproto_class_unregister(const struct ofproto_class *); | |
d08a2e92 | 1838 | |
5bacd5cd JR |
1839 | /* Criteria that flow_mod and other operations use for selecting rules on |
1840 | * which to operate. */ | |
1841 | struct rule_criteria { | |
1842 | /* An OpenFlow table or 255 for all tables. */ | |
1843 | uint8_t table_id; | |
1844 | ||
1845 | /* OpenFlow matching criteria. Interpreted different in "loose" way by | |
1846 | * collect_rules_loose() and "strict" way by collect_rules_strict(), as | |
1847 | * defined in the OpenFlow spec. */ | |
1848 | struct cls_rule cr; | |
1849 | ovs_version_t version; | |
1850 | ||
1851 | /* Matching criteria for the OpenFlow cookie. Consider a bit B in a rule's | |
1852 | * cookie and the corresponding bits C in 'cookie' and M in 'cookie_mask'. | |
1853 | * The rule will not be selected if M is 1 and B != C. */ | |
1854 | ovs_be64 cookie; | |
1855 | ovs_be64 cookie_mask; | |
1856 | ||
1857 | /* Selection based on actions within a rule: | |
1858 | * | |
1859 | * If out_port != OFPP_ANY, selects only rules that output to out_port. | |
1860 | * If out_group != OFPG_ALL, select only rules that output to out_group. */ | |
1861 | ofp_port_t out_port; | |
1862 | uint32_t out_group; | |
1863 | ||
1864 | /* If true, collects only rules that are modifiable. */ | |
1865 | bool include_hidden; | |
1866 | bool include_readonly; | |
1867 | }; | |
1868 | ||
8be00367 JR |
1869 | /* flow_mod with execution context. */ |
1870 | struct ofproto_flow_mod { | |
5bacd5cd JR |
1871 | /* Allocated by 'init' phase, may be freed after 'start' phase, as these |
1872 | * are not needed for 'revert' nor 'finish'. */ | |
1873 | struct rule *temp_rule; | |
1874 | struct rule_criteria criteria; | |
1875 | struct cls_conjunction *conjs; | |
1876 | size_t n_conjs; | |
8be00367 | 1877 | |
81dee635 JR |
1878 | /* Replicate needed fields from ofputil_flow_mod to not need it after the |
1879 | * flow has been created. */ | |
5a27991d | 1880 | uint16_t command; |
7338102b | 1881 | bool modify_cookie; |
5bacd5cd | 1882 | /* Fields derived from ofputil_flow_mod. */ |
81dee635 | 1883 | bool modify_may_add_flow; |
8b6987d7 | 1884 | bool modify_keep_counts; |
81dee635 JR |
1885 | enum nx_flow_update_event event; |
1886 | ||
5bacd5cd JR |
1887 | /* These are only used during commit execution. |
1888 | * ofproto_flow_mod_uninit() does NOT clean these up. */ | |
44e0c35d | 1889 | ovs_version_t version; /* Version in which changes take |
8be00367 | 1890 | * effect. */ |
1f4a8933 | 1891 | bool learn_adds_rule; /* Learn execution adds a rule. */ |
8be00367 JR |
1892 | struct rule_collection old_rules; /* Affected rules. */ |
1893 | struct rule_collection new_rules; /* Replacement rules. */ | |
1894 | }; | |
1895 | ||
5bacd5cd JR |
1896 | void ofproto_flow_mod_uninit(struct ofproto_flow_mod *); |
1897 | ||
8be00367 JR |
1898 | /* port_mod with execution context. */ |
1899 | struct ofproto_port_mod { | |
1900 | struct ofputil_port_mod pm; | |
1901 | struct ofport *port; /* Affected port. */ | |
1902 | }; | |
1903 | ||
2b0b0b80 JR |
1904 | /* flow_mod with execution context. */ |
1905 | struct ofproto_group_mod { | |
1906 | struct ofputil_group_mod gm; | |
1907 | ||
5d08a275 JR |
1908 | ovs_version_t version; /* Version in which changes take |
1909 | * effect. */ | |
2b0b0b80 JR |
1910 | struct ofgroup *new_group; /* New group. */ |
1911 | struct group_collection old_groups; /* Affected groups. */ | |
1912 | }; | |
1913 | ||
1f4a8933 JR |
1914 | /* packet_out with execution context. */ |
1915 | struct ofproto_packet_out { | |
1916 | ovs_version_t version; | |
1917 | struct dp_packet *packet; | |
1918 | struct flow *flow; | |
1919 | struct ofpact *ofpacts; | |
1920 | size_t ofpacts_len; | |
1921 | ||
1922 | void *aux; /* Provider private. */ | |
1923 | }; | |
1924 | ||
1925 | void ofproto_packet_out_uninit(struct ofproto_packet_out *); | |
1926 | ||
7338102b | 1927 | enum ofperr ofproto_flow_mod(struct ofproto *, const struct ofputil_flow_mod *) |
15aaf599 | 1928 | OVS_EXCLUDED(ofproto_mutex); |
2c7ee524 JR |
1929 | enum ofperr ofproto_flow_mod_init_for_learn(struct ofproto *, |
1930 | const struct ofputil_flow_mod *, | |
1931 | struct ofproto_flow_mod *) | |
1932 | OVS_EXCLUDED(ofproto_mutex); | |
1933 | enum ofperr ofproto_flow_mod_learn(struct ofproto_flow_mod *, bool keep_ref) | |
1934 | OVS_EXCLUDED(ofproto_mutex); | |
1f4a8933 JR |
1935 | enum ofperr ofproto_flow_mod_learn_refresh(struct ofproto_flow_mod *ofm); |
1936 | enum ofperr ofproto_flow_mod_learn_start(struct ofproto_flow_mod *ofm) | |
1937 | OVS_REQUIRES(ofproto_mutex); | |
6dd3c787 JR |
1938 | void ofproto_flow_mod_learn_revert(struct ofproto_flow_mod *ofm) |
1939 | OVS_REQUIRES(ofproto_mutex); | |
1f4a8933 JR |
1940 | void ofproto_flow_mod_learn_finish(struct ofproto_flow_mod *ofm, |
1941 | struct ofproto *orig_ofproto) | |
1942 | OVS_REQUIRES(ofproto_mutex); | |
eb391b76 | 1943 | void ofproto_add_flow(struct ofproto *, const struct match *, int priority, |
15aaf599 BP |
1944 | const struct ofpact *ofpacts, size_t ofpacts_len) |
1945 | OVS_EXCLUDED(ofproto_mutex); | |
eb391b76 | 1946 | void ofproto_delete_flow(struct ofproto *, const struct match *, int priority) |
25010c68 | 1947 | OVS_REQUIRES(ofproto_mutex); |
d08a2e92 BP |
1948 | void ofproto_flush_flows(struct ofproto *); |
1949 | ||
89108874 JR |
1950 | enum ofperr ofproto_check_ofpacts(struct ofproto *, |
1951 | const struct ofpact ofpacts[], | |
d61973d6 JR |
1952 | size_t ofpacts_len) |
1953 | OVS_REQUIRES(ofproto_mutex); | |
003ce655 JR |
1954 | \f |
1955 | static inline const struct rule_actions * | |
1956 | rule_get_actions(const struct rule *rule) | |
1957 | { | |
39c94593 | 1958 | return rule->actions; |
003ce655 JR |
1959 | } |
1960 | ||
1961 | /* Returns true if 'rule' is an OpenFlow 1.3 "table-miss" rule, false | |
1962 | * otherwise. | |
1963 | * | |
1964 | * ("Table-miss" rules are special because a packet_in generated through one | |
1965 | * uses OFPR_NO_MATCH as its reason, whereas packet_ins generated by any other | |
1966 | * rule use OFPR_ACTION.) */ | |
1967 | static inline bool | |
1968 | rule_is_table_miss(const struct rule *rule) | |
1969 | { | |
1970 | return rule->cr.priority == 0 && cls_rule_is_catchall(&rule->cr); | |
1971 | } | |
1972 | ||
5e8b38b0 BP |
1973 | /* Returns true if 'rule' should be hidden from the controller. |
1974 | * | |
1975 | * Rules with priority higher than UINT16_MAX are set up by ofproto itself | |
1976 | * (e.g. by in-band control) and are intentionally hidden from the | |
1977 | * controller. */ | |
1978 | static inline bool | |
1979 | rule_is_hidden(const struct rule *rule) | |
1980 | { | |
1981 | return rule->cr.priority > UINT16_MAX; | |
1982 | } | |
1983 | ||
003ce655 JR |
1984 | static inline struct rule * |
1985 | rule_from_cls_rule(const struct cls_rule *cls_rule) | |
1986 | { | |
1987 | return cls_rule ? CONTAINER_OF(cls_rule, struct rule, cr) : NULL; | |
1988 | } | |
1989 | ||
8d8ab6c2 JG |
1990 | static inline const struct tun_table * |
1991 | ofproto_get_tun_tab(const struct ofproto *ofproto) | |
1992 | { | |
1993 | return ovsrcu_get(struct tun_table *, &ofproto->metadata_tab); | |
1994 | } | |
1995 | ||
5bee6e26 | 1996 | #endif /* ofproto/ofproto-provider.h */ |