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