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