Support decoding of NTR selection method
[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     const struct ofputil_group_props props;
504 };
505
506 bool ofproto_group_lookup(const struct ofproto *ofproto, uint32_t group_id,
507                           struct ofgroup **group);
508
509 void ofproto_group_ref(struct ofgroup *);
510 void ofproto_group_unref(struct ofgroup *);
511
512 /* ofproto class structure, to be defined by each ofproto implementation.
513  *
514  *
515  * Data Structures
516  * ===============
517  *
518  * These functions work primarily with four different kinds of data
519  * structures:
520  *
521  *   - "struct ofproto", which represents an OpenFlow switch.
522  *
523  *   - "struct ofport", which represents a port within an ofproto.
524  *
525  *   - "struct rule", which represents an OpenFlow flow within an ofproto.
526  *
527  *   - "struct ofgroup", which represents an OpenFlow 1.1+ group within an
528  *     ofproto.
529  *
530  * Each of these data structures contains all of the implementation-independent
531  * generic state for the respective concept, called the "base" state.  None of
532  * them contains any extra space for ofproto implementations to use.  Instead,
533  * each implementation is expected to declare its own data structure that
534  * contains an instance of the generic data structure plus additional
535  * implementation-specific members, called the "derived" state.  The
536  * implementation can use casts or (preferably) the CONTAINER_OF macro to
537  * obtain access to derived state given only a pointer to the embedded generic
538  * data structure.
539  *
540  *
541  * Life Cycle
542  * ==========
543  *
544  * Four stylized functions accompany each of these data structures:
545  *
546  *            "alloc"       "construct"       "destruct"       "dealloc"
547  *            ------------  ----------------  ---------------  --------------
548  *   ofproto  ->alloc       ->construct       ->destruct       ->dealloc
549  *   ofport   ->port_alloc  ->port_construct  ->port_destruct  ->port_dealloc
550  *   rule     ->rule_alloc  ->rule_construct  ->rule_destruct  ->rule_dealloc
551  *   group    ->group_alloc ->group_construct ->group_destruct ->group_dealloc
552  *
553  * "ofproto", "ofport", and "group" have this exact life cycle.  The "rule"
554  * data structure also follow this life cycle with some additional elaborations
555  * described under "Rule Life Cycle" below.
556  *
557  * Any instance of a given data structure goes through the following life
558  * cycle:
559  *
560  *   1. The client calls the "alloc" function to obtain raw memory.  If "alloc"
561  *      fails, skip all the other steps.
562  *
563  *   2. The client initializes all of the data structure's base state.  If this
564  *      fails, skip to step 7.
565  *
566  *   3. The client calls the "construct" function.  The implementation
567  *      initializes derived state.  It may refer to the already-initialized
568  *      base state.  If "construct" fails, skip to step 6.
569  *
570  *   4. The data structure is now initialized and in use.
571  *
572  *   5. When the data structure is no longer needed, the client calls the
573  *      "destruct" function.  The implementation uninitializes derived state.
574  *      The base state has not been uninitialized yet, so the implementation
575  *      may still refer to it.
576  *
577  *   6. The client uninitializes all of the data structure's base state.
578  *
579  *   7. The client calls the "dealloc" to free the raw memory.  The
580  *      implementation must not refer to base or derived state in the data
581  *      structure, because it has already been uninitialized.
582  *
583  * Each "alloc" function allocates and returns a new instance of the respective
584  * data structure.  The "alloc" function is not given any information about the
585  * use of the new data structure, so it cannot perform much initialization.
586  * Its purpose is just to ensure that the new data structure has enough room
587  * for base and derived state.  It may return a null pointer if memory is not
588  * available, in which case none of the other functions is called.
589  *
590  * Each "construct" function initializes derived state in its respective data
591  * structure.  When "construct" is called, all of the base state has already
592  * been initialized, so the "construct" function may refer to it.  The
593  * "construct" function is allowed to fail, in which case the client calls the
594  * "dealloc" function (but not the "destruct" function).
595  *
596  * Each "destruct" function uninitializes and frees derived state in its
597  * respective data structure.  When "destruct" is called, the base state has
598  * not yet been uninitialized, so the "destruct" function may refer to it.  The
599  * "destruct" function is not allowed to fail.
600  *
601  * Each "dealloc" function frees raw memory that was allocated by the the
602  * "alloc" function.  The memory's base and derived members might not have ever
603  * been initialized (but if "construct" returned successfully, then it has been
604  * "destruct"ed already).  The "dealloc" function is not allowed to fail.
605  *
606  *
607  * Conventions
608  * ===========
609  *
610  * Most of these functions return 0 if they are successful or a positive error
611  * code on failure.  Depending on the function, valid error codes are either
612  * errno values or OFPERR_* OpenFlow error codes.
613  *
614  * Most of these functions are expected to execute synchronously, that is, to
615  * block as necessary to obtain a result.  Thus, these functions may return
616  * EAGAIN (or EWOULDBLOCK or EINPROGRESS) only where the function descriptions
617  * explicitly say those errors are a possibility.  We may relax this
618  * requirement in the future if and when we encounter performance problems. */
619 struct ofproto_class {
620 /* ## ----------------- ## */
621 /* ## Factory Functions ## */
622 /* ## ----------------- ## */
623
624     /* Initializes provider.  The caller may pass in 'iface_hints',
625      * which contains an shash of "struct iface_hint" elements indexed
626      * by the interface's name.  The provider may use these hints to
627      * describe the startup configuration in order to reinitialize its
628      * state.  The caller owns the provided data, so a provider must
629      * make copies of anything required.  An ofproto provider must
630      * remove any existing state that is not described by the hint, and
631      * may choose to remove it all. */
632     void (*init)(const struct shash *iface_hints);
633
634     /* Enumerates the types of all supported ofproto types into 'types'.  The
635      * caller has already initialized 'types'.  The implementation should add
636      * its own types to 'types' but not remove any existing ones, because other
637      * ofproto classes might already have added names to it. */
638     void (*enumerate_types)(struct sset *types);
639
640     /* Enumerates the names of all existing datapath of the specified 'type'
641      * into 'names' 'all_dps'.  The caller has already initialized 'names' as
642      * an empty sset.
643      *
644      * 'type' is one of the types enumerated by ->enumerate_types().
645      *
646      * Returns 0 if successful, otherwise a positive errno value.
647      */
648     int (*enumerate_names)(const char *type, struct sset *names);
649
650     /* Deletes the datapath with the specified 'type' and 'name'.  The caller
651      * should have closed any open ofproto with this 'type' and 'name'; this
652      * function is allowed to fail if that is not the case.
653      *
654      * 'type' is one of the types enumerated by ->enumerate_types().
655      * 'name' is one of the names enumerated by ->enumerate_names() for 'type'.
656      *
657      * Returns 0 if successful, otherwise a positive errno value.
658      */
659     int (*del)(const char *type, const char *name);
660
661     /* Returns the type to pass to netdev_open() when a datapath of type
662      * 'datapath_type' has a port of type 'port_type', for a few special
663      * cases when a netdev type differs from a port type.  For example,
664      * when using the userspace datapath, a port of type "internal"
665      * needs to be opened as "tap".
666      *
667      * Returns either 'type' itself or a string literal, which must not
668      * be freed. */
669     const char *(*port_open_type)(const char *datapath_type,
670                                   const char *port_type);
671
672 /* ## ------------------------ ## */
673 /* ## Top-Level type Functions ## */
674 /* ## ------------------------ ## */
675
676     /* Performs any periodic activity required on ofprotos of type
677      * 'type'.
678      *
679      * An ofproto provider may implement it or not, depending on whether
680      * it needs type-level maintenance.
681      *
682      * Returns 0 if successful, otherwise a positive errno value. */
683     int (*type_run)(const char *type);
684
685     /* Causes the poll loop to wake up when a type 'type''s 'run'
686      * function needs to be called, e.g. by calling the timer or fd
687      * waiting functions in poll-loop.h.
688      *
689      * An ofproto provider may implement it or not, depending on whether
690      * it needs type-level maintenance. */
691     void (*type_wait)(const char *type);
692
693 /* ## --------------------------- ## */
694 /* ## Top-Level ofproto Functions ## */
695 /* ## --------------------------- ## */
696
697     /* Life-cycle functions for an "ofproto" (see "Life Cycle" above).
698      *
699      *
700      * Construction
701      * ============
702      *
703      * ->construct() should not modify any base members of the ofproto.  The
704      * client will initialize the ofproto's 'ports' and 'tables' members after
705      * construction is complete.
706      *
707      * When ->construct() is called, the client does not yet know how many flow
708      * tables the datapath supports, so ofproto->n_tables will be 0 and
709      * ofproto->tables will be NULL.  ->construct() should call
710      * ofproto_init_tables() to allocate and initialize ofproto->n_tables and
711      * ofproto->tables.  Each flow table will be initially empty, so
712      * ->construct() should delete flows from the underlying datapath, if
713      * necessary, rather than populating the tables.
714      *
715      * If the ofproto knows the maximum port number that the datapath can have,
716      * then it can call ofproto_init_max_ports().  If it does so, then the
717      * client will ensure that the actions it allows to be used through
718      * OpenFlow do not refer to ports above that maximum number.
719      *
720      * Only one ofproto instance needs to be supported for any given datapath.
721      * If a datapath is already open as part of one "ofproto", then another
722      * attempt to "construct" the same datapath as part of another ofproto is
723      * allowed to fail with an error.
724      *
725      * ->construct() returns 0 if successful, otherwise a positive errno
726      * value.
727      *
728      *
729      * Destruction
730      * ===========
731      *
732      * ->destruct() must also destroy all remaining rules in the ofproto's
733      * tables, by passing each remaining rule to ofproto_rule_delete().
734      *
735      * The client will destroy the flow tables themselves after ->destruct()
736      * returns.
737      */
738     struct ofproto *(*alloc)(void);
739     int (*construct)(struct ofproto *ofproto);
740     void (*destruct)(struct ofproto *ofproto);
741     void (*dealloc)(struct ofproto *ofproto);
742
743     /* Performs any periodic activity required by 'ofproto'.  It should:
744      *
745      *   - Call connmgr_send_packet_in() for each received packet that missed
746      *     in the OpenFlow flow table or that had a OFPP_CONTROLLER output
747      *     action.
748      *
749      *   - Call ofproto_rule_expire() for each OpenFlow flow that has reached
750      *     its hard_timeout or idle_timeout, to expire the flow.
751      *
752      * Returns 0 if successful, otherwise a positive errno value. */
753     int (*run)(struct ofproto *ofproto);
754
755     /* Causes the poll loop to wake up when 'ofproto''s 'run' function needs to
756      * be called, e.g. by calling the timer or fd waiting functions in
757      * poll-loop.h.  */
758     void (*wait)(struct ofproto *ofproto);
759
760     /* Adds some memory usage statistics for the implementation of 'ofproto'
761      * into 'usage', for use with memory_report().
762      *
763      * This function is optional. */
764     void (*get_memory_usage)(const struct ofproto *ofproto,
765                              struct simap *usage);
766
767     /* Adds some memory usage statistics for the implementation of 'type'
768      * into 'usage', for use with memory_report().
769      *
770      * This function is optional. */
771     void (*type_get_memory_usage)(const char *type, struct simap *usage);
772
773     /* Every "struct rule" in 'ofproto' is about to be deleted, one by one.
774      * This function may prepare for that, for example by clearing state in
775      * advance.  It should *not* actually delete any "struct rule"s from
776      * 'ofproto', only prepare for it.
777      *
778      * This function is optional; it's really just for optimization in case
779      * it's cheaper to delete all the flows from your hardware in a single pass
780      * than to do it one by one. */
781     void (*flush)(struct ofproto *ofproto);
782
783     /* Helper for the OpenFlow OFPT_TABLE_FEATURES request.
784      *
785      * The 'features' array contains 'ofproto->n_tables' elements.  Each
786      * element is initialized as:
787      *
788      *   - 'table_id' to the array index.
789      *
790      *   - 'name' to "table#" where # is the table ID.
791      *
792      *   - 'metadata_match' and 'metadata_write' to OVS_BE64_MAX.
793      *
794      *   - 'config' to the table miss configuration.
795      *
796      *   - 'max_entries' to 1,000,000.
797      *
798      *   - Both 'nonmiss' and 'miss' to:
799      *
800      *     * 'next' to all 1-bits for all later tables.
801      *
802      *     * 'instructions' to all instructions.
803      *
804      *     * 'write' and 'apply' both to:
805      *
806      *       - 'ofpacts': All actions.
807      *
808      *       - 'set_fields': All fields.
809      *
810      *   - 'match', 'mask', and 'wildcard' to all fields.
811      *
812      * If 'stats' is nonnull, it also contains 'ofproto->n_tables' elements.
813      * Each element is initialized as:
814      *
815      *   - 'table_id' to the array index.
816      *
817      *   - 'active_count' to the classifier_count() for the table.
818      *
819      *   - 'lookup_count' and 'matched_count' to 0.
820      *
821      * The implementation should update any members in each element for which
822      * it has better values:
823      *
824      *   - Any member of 'features' to better describe the implementation's
825      *     capabilities.
826      *
827      *   - 'lookup_count' to the number of packets looked up in this flow table
828      *     so far.
829      *
830      *   - 'matched_count' to the number of packets looked up in this flow
831      *     table so far that matched one of the flow entries.
832      */
833     void (*query_tables)(struct ofproto *ofproto,
834                          struct ofputil_table_features *features,
835                          struct ofputil_table_stats *stats);
836
837 /* ## ---------------- ## */
838 /* ## ofport Functions ## */
839 /* ## ---------------- ## */
840
841     /* Life-cycle functions for a "struct ofport" (see "Life Cycle" above).
842      *
843      * ->port_construct() should not modify any base members of the ofport.
844      * An ofproto implementation should use the 'ofp_port' member of
845      * "struct ofport" as the OpenFlow port number.
846      *
847      * ofports are managed by the base ofproto code.  The ofproto
848      * implementation should only create and destroy them in response to calls
849      * to these functions.  The base ofproto code will create and destroy
850      * ofports in the following situations:
851      *
852      *   - Just after the ->construct() function is called, the base ofproto
853      *     iterates over all of the implementation's ports, using
854      *     ->port_dump_start() and related functions, and constructs an ofport
855      *     for each dumped port.
856      *
857      *   - If ->port_poll() reports that a specific port has changed, then the
858      *     base ofproto will query that port with ->port_query_by_name() and
859      *     construct or destruct ofports as necessary to reflect the updated
860      *     set of ports.
861      *
862      *   - If ->port_poll() returns ENOBUFS to report an unspecified port set
863      *     change, then the base ofproto will iterate over all of the
864      *     implementation's ports, in the same way as at ofproto
865      *     initialization, and construct and destruct ofports to reflect all of
866      *     the changes.
867      *
868      * ->port_construct() returns 0 if successful, otherwise a positive errno
869      * value.
870      */
871     struct ofport *(*port_alloc)(void);
872     int (*port_construct)(struct ofport *ofport);
873     void (*port_destruct)(struct ofport *ofport);
874     void (*port_dealloc)(struct ofport *ofport);
875
876     /* Called after 'ofport->netdev' is replaced by a new netdev object.  If
877      * the ofproto implementation uses the ofport's netdev internally, then it
878      * should switch to using the new one.  The old one has been closed.
879      *
880      * An ofproto implementation that doesn't need to do anything in this
881      * function may use a null pointer. */
882     void (*port_modified)(struct ofport *ofport);
883
884     /* Called after an OpenFlow request changes a port's configuration.
885      * 'ofport->pp.config' contains the new configuration.  'old_config'
886      * contains the previous configuration.
887      *
888      * The caller implements OFPUTIL_PC_PORT_DOWN using netdev functions to
889      * turn NETDEV_UP on and off, so this function doesn't have to do anything
890      * for that bit (and it won't be called if that is the only bit that
891      * changes). */
892     void (*port_reconfigured)(struct ofport *ofport,
893                               enum ofputil_port_config old_config);
894
895     /* Looks up a port named 'devname' in 'ofproto'.  On success, returns 0 and
896      * initializes '*port' appropriately. Otherwise, returns a positive errno
897      * value.
898      *
899      * The caller owns the data in 'port' and must free it with
900      * ofproto_port_destroy() when it is no longer needed. */
901     int (*port_query_by_name)(const struct ofproto *ofproto,
902                               const char *devname, struct ofproto_port *port);
903
904     /* Attempts to add 'netdev' as a port on 'ofproto'.  Returns 0 if
905      * successful, otherwise a positive errno value.  The caller should
906      * inform the implementation of the OpenFlow port through the
907      * ->port_construct() method.
908      *
909      * It doesn't matter whether the new port will be returned by a later call
910      * to ->port_poll(); the implementation may do whatever is more
911      * convenient. */
912     int (*port_add)(struct ofproto *ofproto, struct netdev *netdev);
913
914     /* Deletes port number 'ofp_port' from the datapath for 'ofproto'.  Returns
915      * 0 if successful, otherwise a positive errno value.
916      *
917      * It doesn't matter whether the new port will be returned by a later call
918      * to ->port_poll(); the implementation may do whatever is more
919      * convenient. */
920     int (*port_del)(struct ofproto *ofproto, ofp_port_t ofp_port);
921
922     /* Get port stats */
923     int (*port_get_stats)(const struct ofport *port,
924                           struct netdev_stats *stats);
925
926     /* Port iteration functions.
927      *
928      * The client might not be entirely in control of the ports within an
929      * ofproto.  Some hardware implementations, for example, might have a fixed
930      * set of ports in a datapath.  For this reason, the client needs a way to
931      * iterate through all the ports that are actually in a datapath.  These
932      * functions provide that functionality.
933      *
934      * The 'state' pointer provides the implementation a place to
935      * keep track of its position.  Its format is opaque to the caller.
936      *
937      * The ofproto provider retains ownership of the data that it stores into
938      * ->port_dump_next()'s 'port' argument.  The data must remain valid until
939      * at least the next call to ->port_dump_next() or ->port_dump_done() for
940      * 'state'.  The caller will not modify or free it.
941      *
942      * Details
943      * =======
944      *
945      * ->port_dump_start() attempts to begin dumping the ports in 'ofproto'.
946      * On success, it should return 0 and initialize '*statep' with any data
947      * needed for iteration.  On failure, returns a positive errno value, and
948      * the client will not call ->port_dump_next() or ->port_dump_done().
949      *
950      * ->port_dump_next() attempts to retrieve another port from 'ofproto' for
951      * 'state'.  If there is another port, it should store the port's
952      * information into 'port' and return 0.  It should return EOF if all ports
953      * have already been iterated.  Otherwise, on error, it should return a
954      * positive errno value.  This function will not be called again once it
955      * returns nonzero once for a given iteration (but the 'port_dump_done'
956      * function will be called afterward).
957      *
958      * ->port_dump_done() allows the implementation to release resources used
959      * for iteration.  The caller might decide to stop iteration in the middle
960      * by calling this function before ->port_dump_next() returns nonzero.
961      *
962      * Usage Example
963      * =============
964      *
965      * int error;
966      * void *state;
967      *
968      * error = ofproto->ofproto_class->port_dump_start(ofproto, &state);
969      * if (!error) {
970      *     for (;;) {
971      *         struct ofproto_port port;
972      *
973      *         error = ofproto->ofproto_class->port_dump_next(
974      *                     ofproto, state, &port);
975      *         if (error) {
976      *             break;
977      *         }
978      *         // Do something with 'port' here (without modifying or freeing
979      *         // any of its data).
980      *     }
981      *     ofproto->ofproto_class->port_dump_done(ofproto, state);
982      * }
983      * // 'error' is now EOF (success) or a positive errno value (failure).
984      */
985     int (*port_dump_start)(const struct ofproto *ofproto, void **statep);
986     int (*port_dump_next)(const struct ofproto *ofproto, void *state,
987                           struct ofproto_port *port);
988     int (*port_dump_done)(const struct ofproto *ofproto, void *state);
989
990     /* Polls for changes in the set of ports in 'ofproto'.  If the set of ports
991      * in 'ofproto' has changed, then this function should do one of the
992      * following:
993      *
994      * - Preferably: store the name of the device that was added to or deleted
995      *   from 'ofproto' in '*devnamep' and return 0.  The caller is responsible
996      *   for freeing '*devnamep' (with free()) when it no longer needs it.
997      *
998      * - Alternatively: return ENOBUFS, without indicating the device that was
999      *   added or deleted.
1000      *
1001      * Occasional 'false positives', in which the function returns 0 while
1002      * indicating a device that was not actually added or deleted or returns
1003      * ENOBUFS without any change, are acceptable.
1004      *
1005      * The purpose of 'port_poll' is to let 'ofproto' know about changes made
1006      * externally to the 'ofproto' object, e.g. by a system administrator via
1007      * ovs-dpctl.  Therefore, it's OK, and even preferable, for port_poll() to
1008      * not report changes made through calls to 'port_add' or 'port_del' on the
1009      * same 'ofproto' object.  (But it's OK for it to report them too, just
1010      * slightly less efficient.)
1011      *
1012      * If the set of ports in 'ofproto' has not changed, returns EAGAIN.  May
1013      * also return other positive errno values to indicate that something has
1014      * gone wrong.
1015      *
1016      * If the set of ports in a datapath is fixed, or if the only way that the
1017      * set of ports in a datapath can change is through ->port_add() and
1018      * ->port_del(), then this function may be a null pointer.
1019      */
1020     int (*port_poll)(const struct ofproto *ofproto, char **devnamep);
1021
1022     /* Arranges for the poll loop to wake up when ->port_poll() will return a
1023      * value other than EAGAIN.
1024      *
1025      * If the set of ports in a datapath is fixed, or if the only way that the
1026      * set of ports in a datapath can change is through ->port_add() and
1027      * ->port_del(), or if the poll loop will always wake up anyway when
1028      * ->port_poll() will return a value other than EAGAIN, then this function
1029      * may be a null pointer.
1030      */
1031     void (*port_poll_wait)(const struct ofproto *ofproto);
1032
1033     /* Checks the status of LACP negotiation for 'port'.  Returns 1 if LACP
1034      * partner information for 'port' is up-to-date, 0 if LACP partner
1035      * information is not current (generally indicating a connectivity
1036      * problem), or -1 if LACP is not enabled on 'port'.
1037      *
1038      * This function may be a null pointer if the ofproto implementation does
1039      * not support LACP.
1040      */
1041     int (*port_is_lacp_current)(const struct ofport *port);
1042
1043     /* Get LACP port stats. Returns -1 if LACP is not enabled on 'port'.
1044      *
1045      * This function may be a null pointer if the ofproto implementation does
1046      * not support LACP.
1047      */
1048     int (*port_get_lacp_stats)(const struct ofport *port,
1049                                struct lacp_slave_stats *stats);
1050
1051 /* ## ----------------------- ## */
1052 /* ## OpenFlow Rule Functions ## */
1053 /* ## ----------------------- ## */
1054
1055     /* Chooses an appropriate table for 'match' within 'ofproto'.  On
1056      * success, stores the table ID into '*table_idp' and returns 0.  On
1057      * failure, returns an OpenFlow error code.
1058      *
1059      * The choice of table should be a function of 'match' and 'ofproto''s
1060      * datapath capabilities.  It should not depend on the flows already in
1061      * 'ofproto''s flow tables.  Failure implies that an OpenFlow rule with
1062      * 'match' as its matching condition can never be inserted into 'ofproto',
1063      * even starting from an empty flow table.
1064      *
1065      * If multiple tables are candidates for inserting the flow, the function
1066      * should choose one arbitrarily (but deterministically).
1067      *
1068      * If this function is NULL then table 0 is always chosen. */
1069     enum ofperr (*rule_choose_table)(const struct ofproto *ofproto,
1070                                      const struct match *match,
1071                                      uint8_t *table_idp);
1072
1073     /* Life-cycle functions for a "struct rule".
1074      *
1075      *
1076      * Rule Life Cycle
1077      * ===============
1078      *
1079      * The life cycle of a struct rule is an elaboration of the basic life
1080      * cycle described above under "Life Cycle".
1081      *
1082      * After a rule is successfully constructed, it is then inserted.  If
1083      * insertion is successful, then before it is later destructed, it is
1084      * deleted.
1085      *
1086      * You can think of a rule as having the following extra steps inserted
1087      * between "Life Cycle" steps 4 and 5:
1088      *
1089      *   4.1. The client inserts the rule into the flow table, making it
1090      *        visible in flow table lookups.
1091      *
1092      *   4.2. The client calls "rule_insert" to insert the flow.  The
1093      *        implementation attempts to install the flow in the underlying
1094      *        hardware and returns an error code indicate success or failure.
1095      *        On failure, go to step 5.
1096      *
1097      *   4.3. The rule is now installed in the flow table.  Eventually it will
1098      *        be deleted.
1099      *
1100      *   4.4. The client removes the rule from the flow table.  It is no longer
1101      *        visible in flow table lookups.
1102      *
1103      *   4.5. The client calls "rule_delete".  The implementation uninstalls
1104      *        the flow from the underlying hardware.  Deletion is not allowed
1105      *        to fail.
1106      *
1107      *
1108      * Construction
1109      * ============
1110      *
1111      * When ->rule_construct() is called, 'rule' is a new rule that is not yet
1112      * inserted into a flow table.  ->rule_construct() should initialize enough
1113      * of the rule's derived state for 'rule' to be suitable for inserting into
1114      * a flow table.  ->rule_construct() should not modify any base members of
1115      * struct rule.
1116      *
1117      * If ->rule_construct() fails (as indicated by returning a nonzero
1118      * OpenFlow error code), the ofproto base code will uninitialize and
1119      * deallocate 'rule'.  See "Rule Life Cycle" above for more details.
1120      *
1121      * ->rule_construct() may also:
1122      *
1123      *   - Validate that the datapath supports the matching rule in 'rule->cr'
1124      *     datapath.  For example, if the rule's table does not support
1125      *     registers, then it is an error if 'rule->cr' does not wildcard all
1126      *     registers.
1127      *
1128      *   - Validate that the datapath can correctly implement 'rule->ofpacts'.
1129      *
1130      * Some implementations might need to defer these tasks to ->rule_insert(),
1131      * which is also acceptable.
1132      *
1133      *
1134      * Insertion
1135      * =========
1136      *
1137      * Following successful construction, the ofproto base case inserts 'rule'
1138      * into its flow table, then it calls ->rule_insert().  ->rule_insert()
1139      * must add the new rule to the datapath flow table and return only after
1140      * this is complete (whether it succeeds or fails).
1141      *
1142      * If ->rule_insert() fails, the ofproto base code will remove 'rule' from
1143      * the flow table, destruct, uninitialize, and deallocate 'rule'.  See
1144      * "Rule Life Cycle" above for more details.
1145      *
1146      *
1147      * Deletion
1148      * ========
1149      *
1150      * The ofproto base code removes 'rule' from its flow table before it calls
1151      * ->rule_delete().  ->rule_delete() must remove 'rule' from the datapath
1152      * flow table and return only after this has completed successfully.
1153      *
1154      * Rule deletion must not fail.
1155      *
1156      *
1157      * Destruction
1158      * ===========
1159      *
1160      * ->rule_destruct() must uninitialize derived state.
1161      *
1162      * Rule destruction must not fail. */
1163     struct rule *(*rule_alloc)(void);
1164     enum ofperr (*rule_construct)(struct rule *rule)
1165         /* OVS_REQUIRES(ofproto_mutex) */;
1166     enum ofperr (*rule_insert)(struct rule *rule)
1167         /* OVS_REQUIRES(ofproto_mutex) */;
1168     void (*rule_delete)(struct rule *rule) /* OVS_REQUIRES(ofproto_mutex) */;
1169     void (*rule_destruct)(struct rule *rule);
1170     void (*rule_dealloc)(struct rule *rule);
1171
1172     /* Obtains statistics for 'rule', storing the number of packets that have
1173      * matched it in '*packet_count' and the number of bytes in those packets
1174      * in '*byte_count'.  UINT64_MAX indicates that the packet count or byte
1175      * count is unknown. */
1176     void (*rule_get_stats)(struct rule *rule, uint64_t *packet_count,
1177                            uint64_t *byte_count, long long int *used)
1178         /* OVS_EXCLUDED(ofproto_mutex) */;
1179
1180     /* Applies the actions in 'rule' to 'packet'.  (This implements sending
1181      * buffered packets for OpenFlow OFPT_FLOW_MOD commands.)
1182      *
1183      * Takes ownership of 'packet' (so it should eventually free it, with
1184      * ofpbuf_delete()).
1185      *
1186      * 'flow' reflects the flow information for 'packet'.  All of the
1187      * information in 'flow' is extracted from 'packet', except for
1188      * flow->tunnel and flow->in_port, which are assigned the correct values
1189      * for the incoming packet.  The register values are zeroed.  'packet''s
1190      * header pointers and offsets (e.g. packet->l3) are appropriately
1191      * initialized.  packet->l3 is aligned on a 32-bit boundary.
1192      *
1193      * The implementation should add the statistics for 'packet' into 'rule'.
1194      *
1195      * Returns 0 if successful, otherwise an OpenFlow error code. */
1196     enum ofperr (*rule_execute)(struct rule *rule, const struct flow *flow,
1197                                 struct dp_packet *packet);
1198
1199     /* If the datapath can properly implement changing 'rule''s actions to the
1200      * 'ofpacts_len' bytes in 'ofpacts', returns 0.  Otherwise, returns an enum
1201      * ofperr indicating why the new actions wouldn't work.
1202      *
1203      * May be a null pointer if any set of actions is acceptable. */
1204     enum ofperr (*rule_premodify_actions)(const struct rule *rule,
1205                                           const struct ofpact *ofpacts,
1206                                           size_t ofpacts_len)
1207         /* OVS_REQUIRES(ofproto_mutex) */;
1208
1209     /* When ->rule_modify_actions() is called, the caller has already replaced
1210      * the OpenFlow actions in 'rule' by a new set.  (If
1211      * ->rule_premodify_actions is nonnull, then it was previously called to
1212      * verify that the new set of actions is acceptable.)
1213      *
1214      * ->rule_modify_actions() must:
1215      *
1216      *   - Update the datapath flow table with the new actions.
1217      *
1218      *   - Only if 'reset_counters' is true, reset any packet or byte counters
1219      *     associated with the rule to zero, so that rule_get_stats() will not
1220      *     longer count those packets or bytes.
1221      *
1222      * Rule modification must not fail.
1223      *
1224      * ->rule_modify_actions() should not modify any base members of struct
1225      * rule. */
1226     void (*rule_modify_actions)(struct rule *rule, bool reset_counters)
1227         /* OVS_REQUIRES(ofproto_mutex) */;
1228
1229     /* Changes the OpenFlow IP fragment handling policy to 'frag_handling',
1230      * which takes one of the following values, with the corresponding
1231      * meanings:
1232      *
1233      *  - OFPC_FRAG_NORMAL: The switch should treat IP fragments the same way
1234      *    as other packets, omitting TCP and UDP port numbers (always setting
1235      *    them to 0).
1236      *
1237      *  - OFPC_FRAG_DROP: The switch should drop all IP fragments without
1238      *    passing them through the flow table.
1239      *
1240      *  - OFPC_FRAG_REASM: The switch should reassemble IP fragments before
1241      *    passing packets through the flow table.
1242      *
1243      *  - OFPC_FRAG_NX_MATCH (a Nicira extension): Similar to OFPC_FRAG_NORMAL,
1244      *    except that TCP and UDP port numbers should be included in fragments
1245      *    with offset 0.
1246      *
1247      * Implementations are not required to support every mode.
1248      * OFPC_FRAG_NORMAL is the default mode when an ofproto is created.
1249      *
1250      * At the time of the call to ->set_frag_handling(), the current mode is
1251      * available in 'ofproto->frag_handling'.  ->set_frag_handling() returns
1252      * true if the requested mode was set, false if it is not supported.
1253      *
1254      * Upon successful return, the caller changes 'ofproto->frag_handling' to
1255      * reflect the new mode.
1256      */
1257     bool (*set_frag_handling)(struct ofproto *ofproto,
1258                               enum ofp_config_flags frag_handling);
1259
1260     /* Implements the OpenFlow OFPT_PACKET_OUT command.  The datapath should
1261      * execute the 'ofpacts_len' bytes of "struct ofpacts" in 'ofpacts'.
1262      *
1263      * The caller retains ownership of 'packet' and of 'ofpacts', so
1264      * ->packet_out() should not modify or free them.
1265      *
1266      * This function must validate that it can correctly implement 'ofpacts'.
1267      * If not, then it should return an OpenFlow error code.
1268      *
1269      * 'flow' reflects the flow information for 'packet'.  All of the
1270      * information in 'flow' is extracted from 'packet', except for
1271      * flow->in_port (see below).  flow->tunnel and its register values are
1272      * zeroed.
1273      *
1274      * flow->in_port comes from the OpenFlow OFPT_PACKET_OUT message.  The
1275      * implementation should reject invalid flow->in_port values by returning
1276      * OFPERR_OFPBRC_BAD_PORT.  (If the implementation called
1277      * ofproto_init_max_ports(), then the client will reject these ports
1278      * itself.)  For consistency, the implementation should consider valid for
1279      * flow->in_port any value that could possibly be seen in a packet that it
1280      * passes to connmgr_send_packet_in().  Ideally, even an implementation
1281      * that never generates packet-ins (e.g. due to hardware limitations)
1282      * should still allow flow->in_port values for every possible physical port
1283      * and OFPP_LOCAL.  The only virtual ports (those above OFPP_MAX) that the
1284      * caller will ever pass in as flow->in_port, other than OFPP_LOCAL, are
1285      * OFPP_NONE and OFPP_CONTROLLER.  The implementation should allow both of
1286      * these, treating each of them as packets generated by the controller as
1287      * opposed to packets originating from some switch port.
1288      *
1289      * (Ordinarily the only effect of flow->in_port is on output actions that
1290      * involve the input port, such as actions that output to OFPP_IN_PORT,
1291      * OFPP_FLOOD, or OFPP_ALL.  flow->in_port can also affect Nicira extension
1292      * "resubmit" actions.)
1293      *
1294      * 'packet' is not matched against the OpenFlow flow table, so its
1295      * statistics should not be included in OpenFlow flow statistics.
1296      *
1297      * Returns 0 if successful, otherwise an OpenFlow error code. */
1298     enum ofperr (*packet_out)(struct ofproto *ofproto, struct dp_packet *packet,
1299                               const struct flow *flow,
1300                               const struct ofpact *ofpacts,
1301                               size_t ofpacts_len);
1302
1303 /* ## ------------------------- ## */
1304 /* ## OFPP_NORMAL configuration ## */
1305 /* ## ------------------------- ## */
1306
1307     /* Configures NetFlow on 'ofproto' according to the options in
1308      * 'netflow_options', or turns off NetFlow if 'netflow_options' is NULL.
1309      *
1310      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
1311      * NetFlow, as does a null pointer. */
1312     int (*set_netflow)(struct ofproto *ofproto,
1313                        const struct netflow_options *netflow_options);
1314
1315     void (*get_netflow_ids)(const struct ofproto *ofproto,
1316                             uint8_t *engine_type, uint8_t *engine_id);
1317
1318     /* Configures sFlow on 'ofproto' according to the options in
1319      * 'sflow_options', or turns off sFlow if 'sflow_options' is NULL.
1320      *
1321      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
1322      * sFlow, as does a null pointer. */
1323     int (*set_sflow)(struct ofproto *ofproto,
1324                      const struct ofproto_sflow_options *sflow_options);
1325
1326     /* Configures IPFIX on 'ofproto' according to the options in
1327      * 'bridge_exporter_options' and the 'flow_exporters_options'
1328      * array, or turns off IPFIX if 'bridge_exporter_options' and
1329      * 'flow_exporters_options' is NULL.
1330      *
1331      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
1332      * IPFIX, as does a null pointer. */
1333     int (*set_ipfix)(
1334         struct ofproto *ofproto,
1335         const struct ofproto_ipfix_bridge_exporter_options
1336             *bridge_exporter_options,
1337         const struct ofproto_ipfix_flow_exporter_options
1338             *flow_exporters_options, size_t n_flow_exporters_options);
1339
1340     /* Configures connectivity fault management on 'ofport'.
1341      *
1342      * If 'cfm_settings' is nonnull, configures CFM according to its members.
1343      *
1344      * If 'cfm_settings' is null, removes any connectivity fault management
1345      * configuration from 'ofport'.
1346      *
1347      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1348      * support CFM, as does a null pointer. */
1349     int (*set_cfm)(struct ofport *ofport, const struct cfm_settings *s);
1350
1351     /* Checks the status change of CFM on 'ofport'.  Returns true if
1352      * there is status change since last call or if CFM is not specified. */
1353     bool (*cfm_status_changed)(struct ofport *ofport);
1354
1355     /* Populates 'smap' with the status of CFM on 'ofport'.  Returns 0 on
1356      * success, or a positive errno.  EOPNOTSUPP as a return value indicates
1357      * that this ofproto_class does not support CFM, as does a null pointer.
1358      *
1359      * The caller must provide and own '*status', and it must free the array
1360      * returned in 'status->rmps'.  '*status' is indeterminate if the return
1361      * value is non-zero. */
1362     int (*get_cfm_status)(const struct ofport *ofport,
1363                           struct cfm_status *status);
1364
1365     /* Configures LLDP on 'ofport'.
1366      *
1367      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1368      * support LLDP, as does a null pointer. */
1369     int (*set_lldp)(struct ofport *ofport, const struct smap *cfg);
1370
1371     /* Checks the status of LLDP configured on 'ofport'.  Returns true if the
1372      * port's LLDP status was successfully stored into '*status'.  Returns
1373      * false if the port did not have LLDP configured, in which case '*status'
1374      * is indeterminate.
1375      *
1376      * The caller must provide and own '*status'.  '*status' is indeterminate
1377      * if the return value is non-zero. */
1378     bool (*get_lldp_status)(const struct ofport *ofport,
1379                             struct lldp_status *status);
1380
1381     /* Configures Auto Attach.
1382      *
1383      * If 's' is nonnull, configures Auto Attach according to its members.
1384      *
1385      * If 's' is null, removes any Auto Attach configuration.
1386      */
1387     int (*set_aa)(struct ofproto *ofproto,
1388                   const struct aa_settings *s);
1389
1390     /* If 's' is nonnull, this function registers a mapping associated with
1391      * client data pointer 'aux' in 'ofproto'.  If 'aux' is already registered
1392      * then this function updates its configuration to 's'.  Otherwise, this
1393      * function registers a new mapping.
1394      *
1395      * An implementation that does not support mapping at all may set
1396      * it to NULL or return EOPNOTSUPP.  An implementation that supports
1397      * only a subset of the functionality should implement what it can
1398      * and return 0.
1399      */
1400     int (*aa_mapping_set)(struct ofproto *ofproto, void *aux,
1401                           const struct aa_mapping_settings *s);
1402
1403     /* If 's' is nonnull, this function unregisters a mapping associated with
1404      * client data pointer 'aux' in 'ofproto'.  If 'aux' is already registered
1405      * then this function updates its configuration to 's'.  Otherwise, this
1406      * function unregisters a new mapping.
1407      *
1408      * An implementation that does not support mapping at all may set
1409      * it to NULL or return EOPNOTSUPP.  An implementation that supports
1410      * only a subset of the functionality should implement what it can
1411      * and return 0.
1412      */
1413     int (*aa_mapping_unset)(struct ofproto *ofproto, void *aux);
1414
1415     /*
1416      * Returns the a list of AutoAttach VLAN operations.  When Auto Attach is
1417      * enabled, the VLAN associated with an I-SID/VLAN mapping is first
1418      * negotiated with an Auto Attach Server.  Once an I-SID VLAN mapping
1419      * becomes active, the corresponding VLAN needs to be communicated to the
1420      * bridge in order to add the VLAN to the trunk port linking the Auto
1421      * Attach Client (in this case openvswitch) and the Auto Attach Server.
1422      *
1423      * The list entries are of type "struct bridge_aa_vlan".  Each entry
1424      * specifies the operation (add or remove), the interface on which to
1425      * execute the operation and the VLAN.
1426      */
1427     int (*aa_vlan_get_queued)(struct ofproto *ofproto, struct ovs_list *list);
1428
1429     /*
1430      * Returns the current number of entries in the list of VLAN operations
1431      * in the Auto Attach Client (see previous function description
1432      * aa_vlan_get_queued).  Returns 0 if Auto Attach is disabled.
1433      */
1434     unsigned int (*aa_vlan_get_queue_size)(struct ofproto *ofproto);
1435
1436     /* Configures BFD on 'ofport'.
1437      *
1438      * If 'cfg' is NULL, or 'cfg' does not contain the key value pair
1439      * "enable=true", removes BFD from 'ofport'.  Otherwise, configures BFD
1440      * according to 'cfg'.
1441      *
1442      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1443      * support BFD, as does a null pointer. */
1444     int (*set_bfd)(struct ofport *ofport, const struct smap *cfg);
1445
1446     /* Checks the status change of BFD on 'ofport'.  Returns true if there
1447      * is status change since last call or if BFD is not specified. */
1448     bool (*bfd_status_changed)(struct ofport *ofport);
1449
1450     /* Populates 'smap' with the status of BFD on 'ofport'.  Returns 0 on
1451      * success, or a positive errno.  EOPNOTSUPP as a return value indicates
1452      * that this ofproto_class does not support BFD, as does a null pointer. */
1453     int (*get_bfd_status)(struct ofport *ofport, struct smap *smap);
1454
1455     /* Configures spanning tree protocol (STP) on 'ofproto' using the
1456      * settings defined in 's'.
1457      *
1458      * If 's' is nonnull, configures STP according to its members.
1459      *
1460      * If 's' is null, removes any STP configuration from 'ofproto'.
1461      *
1462      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1463      * support STP, as does a null pointer. */
1464     int (*set_stp)(struct ofproto *ofproto,
1465                    const struct ofproto_stp_settings *s);
1466
1467     /* Retrieves state of spanning tree protocol (STP) on 'ofproto'.
1468      *
1469      * Stores STP state for 'ofproto' in 's'.  If the 'enabled' member
1470      * is false, the other member values are not meaningful.
1471      *
1472      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1473      * support STP, as does a null pointer. */
1474     int (*get_stp_status)(struct ofproto *ofproto,
1475                           struct ofproto_stp_status *s);
1476
1477     /* Configures spanning tree protocol (STP) on 'ofport' using the
1478      * settings defined in 's'.
1479      *
1480      * If 's' is nonnull, configures STP according to its members.  The
1481      * caller is responsible for assigning STP port numbers (using the
1482      * 'port_num' member in the range of 1 through 255, inclusive) and
1483      * ensuring there are no duplicates.
1484      *
1485      * If 's' is null, removes any STP configuration from 'ofport'.
1486      *
1487      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1488      * support STP, as does a null pointer. */
1489     int (*set_stp_port)(struct ofport *ofport,
1490                         const struct ofproto_port_stp_settings *s);
1491
1492     /* Retrieves spanning tree protocol (STP) port status of 'ofport'.
1493      *
1494      * Stores STP state for 'ofport' in 's'.  If the 'enabled' member is
1495      * false, the other member values are not meaningful.
1496      *
1497      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1498      * support STP, as does a null pointer. */
1499     int (*get_stp_port_status)(struct ofport *ofport,
1500                                struct ofproto_port_stp_status *s);
1501
1502     /* Retrieves spanning tree protocol (STP) port statistics of 'ofport'.
1503      *
1504      * Stores STP state for 'ofport' in 's'.  If the 'enabled' member is
1505      * false, the other member values are not meaningful.
1506      *
1507      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1508      * support STP, as does a null pointer. */
1509     int (*get_stp_port_stats)(struct ofport *ofport,
1510                               struct ofproto_port_stp_stats *s);
1511
1512     /* Configures Rapid Spanning Tree Protocol (RSTP) on 'ofproto' using the
1513      * settings defined in 's'.
1514      *
1515      * If 's' is nonnull, configures RSTP according to its members.
1516      *
1517      * If 's' is null, removes any RSTP configuration from 'ofproto'.
1518      *
1519      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1520      * support RSTP, as does a null pointer. */
1521     void (*set_rstp)(struct ofproto *ofproto,
1522                     const struct ofproto_rstp_settings *s);
1523
1524     /* Retrieves state of Rapid Spanning Tree Protocol (RSTP) on 'ofproto'.
1525      *
1526      * Stores RSTP state for 'ofproto' in 's'.  If the 'enabled' member
1527      * is false, the other member values are not meaningful.
1528      *
1529      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1530      * support RSTP, as does a null pointer. */
1531     void (*get_rstp_status)(struct ofproto *ofproto,
1532                            struct ofproto_rstp_status *s);
1533
1534     /* Configures Rapid Spanning Tree Protocol (RSTP) on 'ofport' using the
1535      * settings defined in 's'.
1536      *
1537      * If 's' is nonnull, configures RSTP according to its members.  The
1538      * caller is responsible for assigning RSTP port numbers (using the
1539      * 'port_num' member in the range of 1 through 255, inclusive) and
1540      * ensuring there are no duplicates.
1541      *
1542      * If 's' is null, removes any RSTP configuration from 'ofport'.
1543      *
1544      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1545      * support STP, as does a null pointer. */
1546     void (*set_rstp_port)(struct ofport *ofport,
1547                          const struct ofproto_port_rstp_settings *s);
1548
1549     /* Retrieves Rapid Spanning Tree Protocol (RSTP) port status of 'ofport'.
1550      *
1551      * Stores RSTP state for 'ofport' in 's'.  If the 'enabled' member is
1552      * false, the other member values are not meaningful.
1553      *
1554      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1555      * support RSTP, as does a null pointer. */
1556     void (*get_rstp_port_status)(struct ofport *ofport,
1557                                 struct ofproto_port_rstp_status *s);
1558
1559     /* Registers meta-data associated with the 'n_qdscp' Qualities of Service
1560      * 'queues' attached to 'ofport'.  This data is not intended to be
1561      * sufficient to implement QoS.  Instead, providers may use this
1562      * information to implement features which require knowledge of what queues
1563      * exist on a port, and some basic information about them.
1564      *
1565      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1566      * support QoS, as does a null pointer. */
1567     int (*set_queues)(struct ofport *ofport,
1568                       const struct ofproto_port_queue *queues, size_t n_qdscp);
1569
1570     /* If 's' is nonnull, this function registers a "bundle" associated with
1571      * client data pointer 'aux' in 'ofproto'.  A bundle is the same concept as
1572      * a Port in OVSDB, that is, it consists of one or more "slave" devices
1573      * (Interfaces, in OVSDB) along with VLAN and LACP configuration and, if
1574      * there is more than one slave, a bonding configuration.  If 'aux' is
1575      * already registered then this function updates its configuration to 's'.
1576      * Otherwise, this function registers a new bundle.
1577      *
1578      * If 's' is NULL, this function unregisters the bundle registered on
1579      * 'ofproto' associated with client data pointer 'aux'.  If no such bundle
1580      * has been registered, this has no effect.
1581      *
1582      * This function affects only the behavior of the NXAST_AUTOPATH action and
1583      * output to the OFPP_NORMAL port.  An implementation that does not support
1584      * it at all may set it to NULL or return EOPNOTSUPP.  An implementation
1585      * that supports only a subset of the functionality should implement what
1586      * it can and return 0. */
1587     int (*bundle_set)(struct ofproto *ofproto, void *aux,
1588                       const struct ofproto_bundle_settings *s);
1589
1590     /* If 'port' is part of any bundle, removes it from that bundle.  If the
1591      * bundle now has no ports, deletes the bundle.  If the bundle now has only
1592      * one port, deconfigures the bundle's bonding configuration. */
1593     void (*bundle_remove)(struct ofport *ofport);
1594
1595     /* If 's' is nonnull, this function registers a mirror associated with
1596      * client data pointer 'aux' in 'ofproto'.  A mirror is the same concept as
1597      * a Mirror in OVSDB.  If 'aux' is already registered then this function
1598      * updates its configuration to 's'.  Otherwise, this function registers a
1599      * new mirror.
1600      *
1601      * If 's' is NULL, this function unregisters the mirror registered on
1602      * 'ofproto' associated with client data pointer 'aux'.  If no such mirror
1603      * has been registered, this has no effect.
1604      *
1605      * An implementation that does not support mirroring at all may set
1606      * it to NULL or return EOPNOTSUPP.  An implementation that supports
1607      * only a subset of the functionality should implement what it can
1608      * and return 0. */
1609     int (*mirror_set)(struct ofproto *ofproto, void *aux,
1610                       const struct ofproto_mirror_settings *s);
1611
1612     /* Retrieves statistics from mirror associated with client data
1613      * pointer 'aux' in 'ofproto'.  Stores packet and byte counts in
1614      * 'packets' and 'bytes', respectively.  If a particular counter is
1615      * not supported, the appropriate argument is set to UINT64_MAX.
1616      *
1617      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1618      * support retrieving mirror statistics. */
1619     int (*mirror_get_stats)(struct ofproto *ofproto, void *aux,
1620                             uint64_t *packets, uint64_t *bytes);
1621
1622     /* Configures the VLANs whose bits are set to 1 in 'flood_vlans' as VLANs
1623      * on which all packets are flooded, instead of using MAC learning.  If
1624      * 'flood_vlans' is NULL, then MAC learning applies to all VLANs.
1625      *
1626      * This function affects only the behavior of the OFPP_NORMAL action.  An
1627      * implementation that does not support it may set it to NULL or return
1628      * EOPNOTSUPP. */
1629     int (*set_flood_vlans)(struct ofproto *ofproto,
1630                            unsigned long *flood_vlans);
1631
1632     /* Returns true if 'aux' is a registered bundle that is currently in use as
1633      * the output for a mirror. */
1634     bool (*is_mirror_output_bundle)(const struct ofproto *ofproto, void *aux);
1635
1636     /* When the configuration option of forward_bpdu changes, this function
1637      * will be invoked. */
1638     void (*forward_bpdu_changed)(struct ofproto *ofproto);
1639
1640     /* Sets the MAC aging timeout for the OFPP_NORMAL action to 'idle_time', in
1641      * seconds, and the maximum number of MAC table entries to
1642      * 'max_entries'.
1643      *
1644      * An implementation that doesn't support configuring these features may
1645      * set this function to NULL or implement it as a no-op. */
1646     void (*set_mac_table_config)(struct ofproto *ofproto,
1647                                  unsigned int idle_time, size_t max_entries);
1648
1649     /* Configures multicast snooping on 'ofport' using the settings
1650      * defined in 's'.
1651      *
1652      * If 's' is nonnull, this function updates multicast snooping
1653      * configuration to 's' in 'ofproto'.
1654      *
1655      * If 's' is NULL, this function disables multicast snooping
1656      * on 'ofproto'.
1657      *
1658      * An implementation that does not support multicast snooping may set
1659      * it to NULL or return EOPNOTSUPP. */
1660     int (*set_mcast_snooping)(struct ofproto *ofproto,
1661                               const struct ofproto_mcast_snooping_settings *s);
1662
1663     /* Configures multicast snooping port's flood setting on 'ofproto'.
1664      *
1665      * If 's' is nonnull, this function updates multicast snooping
1666      * configuration to 's' in 'ofproto'.
1667      *
1668      * If 's' is NULL, this function doesn't change anything.
1669      *
1670      * An implementation that does not support multicast snooping may set
1671      * it to NULL or return EOPNOTSUPP. */
1672     int (*set_mcast_snooping_port)(struct ofproto *ofproto_, void *aux,
1673                           const struct ofproto_mcast_snooping_port_settings *s);
1674
1675 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
1676  *
1677  * This is deprecated.  It is only for compatibility with broken device drivers
1678  * in old versions of Linux that do not properly support VLANs when VLAN
1679  * devices are not used.  When broken device drivers are no longer in
1680  * widespread use, we will delete these interfaces. */
1681
1682     /* If 'realdev_ofp_port' is nonzero, then this function configures 'ofport'
1683      * as a VLAN splinter port for VLAN 'vid', associated with the real device
1684      * that has OpenFlow port number 'realdev_ofp_port'.
1685      *
1686      * If 'realdev_ofp_port' is zero, then this function deconfigures 'ofport'
1687      * as a VLAN splinter port.
1688      *
1689      * This function should be NULL if an implementation does not support it.
1690      */
1691     int (*set_realdev)(struct ofport *ofport,
1692                        ofp_port_t realdev_ofp_port, int vid);
1693
1694 /* ## ------------------------ ## */
1695 /* ## OpenFlow meter functions ## */
1696 /* ## ------------------------ ## */
1697
1698     /* These functions should be NULL if an implementation does not support
1699      * them.  They must be all null or all non-null.. */
1700
1701     /* Initializes 'features' to describe the metering features supported by
1702      * 'ofproto'. */
1703     void (*meter_get_features)(const struct ofproto *ofproto,
1704                                struct ofputil_meter_features *features);
1705
1706     /* If '*id' is UINT32_MAX, adds a new meter with the given 'config'.  On
1707      * success the function must store a provider meter ID other than
1708      * UINT32_MAX in '*id'.  All further references to the meter will be made
1709      * with the returned provider meter id rather than the OpenFlow meter id.
1710      * The caller does not try to interpret the provider meter id, giving the
1711      * implementation the freedom to either use the OpenFlow meter_id value
1712      * provided in the meter configuration, or any other value suitable for the
1713      * implementation.
1714      *
1715      * If '*id' is a value other than UINT32_MAX, modifies the existing meter
1716      * with that meter provider ID to have configuration 'config', while
1717      * leaving '*id' unchanged.  On failure, the existing meter configuration
1718      * is left intact. */
1719     enum ofperr (*meter_set)(struct ofproto *ofproto, ofproto_meter_id *id,
1720                              const struct ofputil_meter_config *config);
1721
1722     /* Gets the meter and meter band packet and byte counts for maximum of
1723      * 'stats->n_bands' bands for the meter with provider ID 'id' within
1724      * 'ofproto'.  The caller fills in the other stats values.  The band stats
1725      * are copied to memory at 'stats->bands' provided by the caller.  The
1726      * number of returned band stats is returned in 'stats->n_bands'. */
1727     enum ofperr (*meter_get)(const struct ofproto *ofproto,
1728                              ofproto_meter_id id,
1729                              struct ofputil_meter_stats *stats);
1730
1731     /* Deletes a meter, making the 'ofproto_meter_id' invalid for any
1732      * further calls. */
1733     void (*meter_del)(struct ofproto *, ofproto_meter_id);
1734
1735
1736 /* ## -------------------- ## */
1737 /* ## OpenFlow 1.1+ groups ## */
1738 /* ## -------------------- ## */
1739
1740     struct ofgroup *(*group_alloc)(void);
1741     enum ofperr (*group_construct)(struct ofgroup *);
1742     void (*group_destruct)(struct ofgroup *);
1743     void (*group_dealloc)(struct ofgroup *);
1744
1745     enum ofperr (*group_modify)(struct ofgroup *);
1746
1747     enum ofperr (*group_get_stats)(const struct ofgroup *,
1748                                    struct ofputil_group_stats *);
1749
1750 /* ## --------------------- ## */
1751 /* ## Datapath information  ## */
1752 /* ## --------------------- ## */
1753     /* Retrieve the version string of the datapath. The version
1754      * string can be NULL if it can not be determined.
1755      *
1756      * The version retuned is read only. The caller should not
1757      * free it.
1758      *
1759      * This function should be NULL if an implementation does not support it.
1760      */
1761     const char *(*get_datapath_version)(const struct ofproto *);
1762 };
1763
1764 extern const struct ofproto_class ofproto_dpif_class;
1765
1766 int ofproto_class_register(const struct ofproto_class *);
1767 int ofproto_class_unregister(const struct ofproto_class *);
1768
1769 int ofproto_flow_mod(struct ofproto *, struct ofputil_flow_mod *)
1770     OVS_EXCLUDED(ofproto_mutex);
1771 void ofproto_add_flow(struct ofproto *, const struct match *, int priority,
1772                       const struct ofpact *ofpacts, size_t ofpacts_len)
1773     OVS_EXCLUDED(ofproto_mutex);
1774 void ofproto_delete_flow(struct ofproto *, const struct match *, int priority)
1775     OVS_EXCLUDED(ofproto_mutex);
1776 void ofproto_flush_flows(struct ofproto *);
1777
1778 \f
1779 static inline const struct rule_actions *
1780 rule_get_actions(const struct rule *rule)
1781 {
1782     return ovsrcu_get(const struct rule_actions *, &rule->actions);
1783 }
1784
1785 /* Returns true if 'rule' is an OpenFlow 1.3 "table-miss" rule, false
1786  * otherwise.
1787  *
1788  * ("Table-miss" rules are special because a packet_in generated through one
1789  * uses OFPR_NO_MATCH as its reason, whereas packet_ins generated by any other
1790  * rule use OFPR_ACTION.) */
1791 static inline bool
1792 rule_is_table_miss(const struct rule *rule)
1793 {
1794     return rule->cr.priority == 0 && cls_rule_is_catchall(&rule->cr);
1795 }
1796
1797 /* Returns true if 'rule' should be hidden from the controller.
1798  *
1799  * Rules with priority higher than UINT16_MAX are set up by ofproto itself
1800  * (e.g. by in-band control) and are intentionally hidden from the
1801  * controller. */
1802 static inline bool
1803 rule_is_hidden(const struct rule *rule)
1804 {
1805     return rule->cr.priority > UINT16_MAX;
1806 }
1807
1808 static inline struct rule *
1809 rule_from_cls_rule(const struct cls_rule *cls_rule)
1810 {
1811     return cls_rule ? CONTAINER_OF(cls_rule, struct rule, cr) : NULL;
1812 }
1813
1814 #endif /* ofproto/ofproto-provider.h */