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