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