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