ofproto: Periodically log a summary of flow table changes.
[sliver-openvswitch.git] / ofproto / ofproto-provider.h
1 /*
2  * Copyright (c) 2009, 2010, 2011, 2012 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 #include "ofproto/ofproto.h"
23 #include "cfm.h"
24 #include "classifier.h"
25 #include "heap.h"
26 #include "list.h"
27 #include "ofp-errors.h"
28 #include "ofp-util.h"
29 #include "shash.h"
30 #include "timeval.h"
31
32 struct ofputil_flow_mod;
33 struct simap;
34
35 /* An OpenFlow switch.
36  *
37  * With few exceptions, ofproto implementations may look at these fields but
38  * should not modify them. */
39 struct ofproto {
40     struct hmap_node hmap_node; /* In global 'all_ofprotos' hmap. */
41     const struct ofproto_class *ofproto_class;
42     char *type;                 /* Datapath type. */
43     char *name;                 /* Datapath name. */
44
45     /* Settings. */
46     uint64_t fallback_dpid;     /* Datapath ID if no better choice found. */
47     uint64_t datapath_id;       /* Datapath ID. */
48     unsigned flow_eviction_threshold; /* Threshold at which to begin flow
49                                        * table eviction. Only affects the
50                                        * ofproto-dpif implementation */
51     bool forward_bpdu;          /* Option to allow forwarding of BPDU frames
52                                  * when NORMAL action is invoked. */
53     char *mfr_desc;             /* Manufacturer. */
54     char *hw_desc;              /* Hardware. */
55     char *sw_desc;              /* Software version. */
56     char *serial_desc;          /* Serial number. */
57     char *dp_desc;              /* Datapath description. */
58     enum ofp_config_flags frag_handling; /* One of OFPC_*.  */
59
60     /* Datapath. */
61     struct hmap ports;          /* Contains "struct ofport"s. */
62     struct shash port_by_name;
63
64     /* Flow tables. */
65     struct oftable *tables;
66     int n_tables;
67
68     /* OpenFlow connections. */
69     struct connmgr *connmgr;
70
71     /* Flow table operation tracking. */
72     int state;                  /* Internal state. */
73     struct list pending;        /* List of "struct ofopgroup"s. */
74     unsigned int n_pending;     /* list_size(&pending). */
75     struct hmap deletions;      /* All OFOPERATION_DELETE "ofoperation"s. */
76
77     /* Flow table operation logging. */
78     int n_add, n_delete, n_modify; /* Number of unreported ops of each kind. */
79     long long int first_op, last_op; /* Range of times for unreported ops. */
80     long long int next_op_report;    /* Time to report ops, or LLONG_MAX. */
81     long long int op_backoff;        /* Earliest time to report ops again. */
82
83     /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
84      *
85      * This is deprecated.  It is only for compatibility with broken device
86      * drivers in old versions of Linux that do not properly support VLANs when
87      * VLAN devices are not used.  When broken device drivers are no longer in
88      * widespread use, we will delete these interfaces. */
89     unsigned long int *vlan_bitmap; /* 4096-bit bitmap of in-use VLANs. */
90     bool vlans_changed;             /* True if new VLANs are in use. */
91     int min_mtu;                    /* Current MTU of non-internal ports. */
92 };
93
94 void ofproto_init_tables(struct ofproto *, int n_tables);
95
96 struct ofproto *ofproto_lookup(const char *name);
97 struct ofport *ofproto_get_port(const struct ofproto *, uint16_t ofp_port);
98
99 /* An OpenFlow port within a "struct ofproto".
100  *
101  * With few exceptions, ofproto implementations may look at these fields but
102  * should not modify them. */
103 struct ofport {
104     struct hmap_node hmap_node; /* In struct ofproto's "ports" hmap. */
105     struct ofproto *ofproto;    /* The ofproto that contains this port. */
106     struct netdev *netdev;
107     struct ofputil_phy_port pp;
108     uint16_t ofp_port;          /* OpenFlow port number. */
109     unsigned int change_seq;
110     int mtu;
111 };
112
113 void ofproto_port_set_state(struct ofport *, enum ofputil_port_state);
114
115 enum oftable_flags {
116     OFTABLE_HIDDEN = 1 << 0,   /* Hide from most OpenFlow operations. */
117     OFTABLE_READONLY = 1 << 1  /* Don't allow OpenFlow to change this table. */
118 };
119
120 /* A flow table within a "struct ofproto". */
121 struct oftable {
122     enum oftable_flags flags;
123     struct classifier cls;      /* Contains "struct rule"s. */
124     char *name;                 /* Table name exposed via OpenFlow, or NULL. */
125
126     /* Maximum number of flows or UINT_MAX if there is no limit besides any
127      * limit imposed by resource limitations. */
128     unsigned int max_flows;
129
130     /* These members determine the handling of an attempt to add a flow that
131      * would cause the table to have more than 'max_flows' flows.
132      *
133      * If 'eviction_fields' is NULL, overflows will be rejected with an error.
134      *
135      * If 'eviction_fields' is nonnull (regardless of whether n_eviction_fields
136      * is nonzero), an overflow will cause a flow to be removed.  The flow to
137      * be removed is chosen to give fairness among groups distinguished by
138      * different values for the subfields within 'groups'. */
139     struct mf_subfield *eviction_fields;
140     size_t n_eviction_fields;
141
142     /* Eviction groups.
143      *
144      * When a flow is added that would cause the table to have more than
145      * 'max_flows' flows, and 'eviction_fields' is nonnull, these groups are
146      * used to decide which rule to evict: the rule is chosen from the eviction
147      * group that contains the greatest number of rules.*/
148     uint32_t eviction_group_id_basis;
149     struct hmap eviction_groups_by_id;
150     struct heap eviction_groups_by_size;
151 };
152
153 /* Assigns TABLE to each oftable, in turn, in OFPROTO.
154  *
155  * All parameters are evaluated multiple times. */
156 #define OFPROTO_FOR_EACH_TABLE(TABLE, OFPROTO)              \
157     for ((TABLE) = (OFPROTO)->tables;                       \
158          (TABLE) < &(OFPROTO)->tables[(OFPROTO)->n_tables]; \
159          (TABLE)++)
160
161 /* An OpenFlow flow within a "struct ofproto".
162  *
163  * With few exceptions, ofproto implementations may look at these fields but
164  * should not modify them. */
165 struct rule {
166     struct list ofproto_node;    /* Owned by ofproto base code. */
167     struct ofproto *ofproto;     /* The ofproto that contains this rule. */
168     struct cls_rule cr;          /* In owning ofproto's classifier. */
169
170     struct ofoperation *pending; /* Operation now in progress, if nonnull. */
171
172     ovs_be64 flow_cookie;        /* Controller-issued identifier. */
173
174     long long int created;       /* Creation time. */
175     long long int modified;      /* Time of last modification. */
176     long long int used;          /* Last use; time created if never used. */
177     uint16_t hard_timeout;       /* In seconds from ->modified. */
178     uint16_t idle_timeout;       /* In seconds from ->used. */
179     uint8_t table_id;            /* Index in ofproto's 'tables' array. */
180     bool send_flow_removed;      /* Send a flow removed message? */
181
182     /* Eviction groups. */
183     bool evictable;              /* If false, prevents eviction. */
184     struct heap_node evg_node;   /* In eviction_group's "rules" heap. */
185     struct eviction_group *eviction_group; /* NULL if not in any group. */
186
187     union ofp_action *actions;   /* OpenFlow actions. */
188     int n_actions;               /* Number of elements in actions[]. */
189 };
190
191 static inline struct rule *
192 rule_from_cls_rule(const struct cls_rule *cls_rule)
193 {
194     return cls_rule ? CONTAINER_OF(cls_rule, struct rule, cr) : NULL;
195 }
196
197 void ofproto_rule_update_used(struct rule *, long long int used);
198 void ofproto_rule_expire(struct rule *, uint8_t reason);
199 void ofproto_rule_destroy(struct rule *);
200
201 void ofoperation_complete(struct ofoperation *, enum ofperr);
202 struct rule *ofoperation_get_victim(struct ofoperation *);
203
204 /* ofproto class structure, to be defined by each ofproto implementation.
205  *
206  *
207  * Data Structures
208  * ===============
209  *
210  * These functions work primarily with three different kinds of data
211  * structures:
212  *
213  *   - "struct ofproto", which represents an OpenFlow switch.
214  *
215  *   - "struct ofport", which represents a port within an ofproto.
216  *
217  *   - "struct rule", which represents an OpenFlow flow within an ofproto.
218  *
219  * Each of these data structures contains all of the implementation-independent
220  * generic state for the respective concept, called the "base" state.  None of
221  * them contains any extra space for ofproto implementations to use.  Instead,
222  * each implementation is expected to declare its own data structure that
223  * contains an instance of the generic data structure plus additional
224  * implementation-specific members, called the "derived" state.  The
225  * implementation can use casts or (preferably) the CONTAINER_OF macro to
226  * obtain access to derived state given only a pointer to the embedded generic
227  * data structure.
228  *
229  *
230  * Life Cycle
231  * ==========
232  *
233  * Four stylized functions accompany each of these data structures:
234  *
235  *            "alloc"       "construct"       "destruct"       "dealloc"
236  *            ------------  ----------------  ---------------  --------------
237  *   ofproto  ->alloc       ->construct       ->destruct       ->dealloc
238  *   ofport   ->port_alloc  ->port_construct  ->port_destruct  ->port_dealloc
239  *   rule     ->rule_alloc  ->rule_construct  ->rule_destruct  ->rule_dealloc
240  *
241  * Any instance of a given data structure goes through the following life
242  * cycle:
243  *
244  *   1. The client calls the "alloc" function to obtain raw memory.  If "alloc"
245  *      fails, skip all the other steps.
246  *
247  *   2. The client initializes all of the data structure's base state.  If this
248  *      fails, skip to step 7.
249  *
250  *   3. The client calls the "construct" function.  The implementation
251  *      initializes derived state.  It may refer to the already-initialized
252  *      base state.  If "construct" fails, skip to step 6.
253  *
254  *   4. The data structure is now initialized and in use.
255  *
256  *   5. When the data structure is no longer needed, the client calls the
257  *      "destruct" function.  The implementation uninitializes derived state.
258  *      The base state has not been uninitialized yet, so the implementation
259  *      may still refer to it.
260  *
261  *   6. The client uninitializes all of the data structure's base state.
262  *
263  *   7. The client calls the "dealloc" to free the raw memory.  The
264  *      implementation must not refer to base or derived state in the data
265  *      structure, because it has already been uninitialized.
266  *
267  * Each "alloc" function allocates and returns a new instance of the respective
268  * data structure.  The "alloc" function is not given any information about the
269  * use of the new data structure, so it cannot perform much initialization.
270  * Its purpose is just to ensure that the new data structure has enough room
271  * for base and derived state.  It may return a null pointer if memory is not
272  * available, in which case none of the other functions is called.
273  *
274  * Each "construct" function initializes derived state in its respective data
275  * structure.  When "construct" is called, all of the base state has already
276  * been initialized, so the "construct" function may refer to it.  The
277  * "construct" function is allowed to fail, in which case the client calls the
278  * "dealloc" function (but not the "destruct" function).
279  *
280  * Each "destruct" function uninitializes and frees derived state in its
281  * respective data structure.  When "destruct" is called, the base state has
282  * not yet been uninitialized, so the "destruct" function may refer to it.  The
283  * "destruct" function is not allowed to fail.
284  *
285  * Each "dealloc" function frees raw memory that was allocated by the the
286  * "alloc" function.  The memory's base and derived members might not have ever
287  * been initialized (but if "construct" returned successfully, then it has been
288  * "destruct"ed already).  The "dealloc" function is not allowed to fail.
289  *
290  *
291  * Conventions
292  * ===========
293  *
294  * Most of these functions return 0 if they are successful or a positive error
295  * code on failure.  Depending on the function, valid error codes are either
296  * errno values or OFPERR_* OpenFlow error codes.
297  *
298  * Most of these functions are expected to execute synchronously, that is, to
299  * block as necessary to obtain a result.  Thus, these functions may return
300  * EAGAIN (or EWOULDBLOCK or EINPROGRESS) only where the function descriptions
301  * explicitly say those errors are a possibility.  We may relax this
302  * requirement in the future if and when we encounter performance problems. */
303 struct ofproto_class {
304 /* ## ----------------- ## */
305 /* ## Factory Functions ## */
306 /* ## ----------------- ## */
307
308     /* Enumerates the types of all support ofproto types into 'types'.  The
309      * caller has already initialized 'types' and other ofproto classes might
310      * already have added names to it. */
311     void (*enumerate_types)(struct sset *types);
312
313     /* Enumerates the names of all existing datapath of the specified 'type'
314      * into 'names' 'all_dps'.  The caller has already initialized 'names' as
315      * an empty sset.
316      *
317      * 'type' is one of the types enumerated by ->enumerate_types().
318      *
319      * Returns 0 if successful, otherwise a positive errno value.
320      */
321     int (*enumerate_names)(const char *type, struct sset *names);
322
323     /* Deletes the datapath with the specified 'type' and 'name'.  The caller
324      * should have closed any open ofproto with this 'type' and 'name'; this
325      * function is allowed to fail if that is not the case.
326      *
327      * 'type' is one of the types enumerated by ->enumerate_types().
328      * 'name' is one of the names enumerated by ->enumerate_names() for 'type'.
329      *
330      * Returns 0 if successful, otherwise a positive errno value.
331      */
332     int (*del)(const char *type, const char *name);
333
334 /* ## --------------------------- ## */
335 /* ## Top-Level ofproto Functions ## */
336 /* ## --------------------------- ## */
337
338     /* Life-cycle functions for an "ofproto" (see "Life Cycle" above).
339      *
340      *
341      * Construction
342      * ============
343      *
344      * ->construct() should not modify any base members of the ofproto.  The
345      * client will initialize the ofproto's 'ports' and 'tables' members after
346      * construction is complete.
347      *
348      * When ->construct() is called, the client does not yet know how many flow
349      * tables the datapath supports, so ofproto->n_tables will be 0 and
350      * ofproto->tables will be NULL.  ->construct() should call
351      * ofproto_init_tables() to allocate and initialize ofproto->n_tables and
352      * ofproto->tables.  Each flow table will be initially empty, so
353      * ->construct() should delete flows from the underlying datapath, if
354      * necessary, rather than populating the tables.
355      *
356      * Only one ofproto instance needs to be supported for any given datapath.
357      * If a datapath is already open as part of one "ofproto", then another
358      * attempt to "construct" the same datapath as part of another ofproto is
359      * allowed to fail with an error.
360      *
361      * ->construct() returns 0 if successful, otherwise a positive errno
362      * value.
363      *
364      *
365      * Destruction
366      * ===========
367      *
368      * If 'ofproto' has any pending asynchronous operations, ->destruct()
369      * must complete all of them by calling ofoperation_complete().
370      *
371      * ->destruct() must also destroy all remaining rules in the ofproto's
372      * tables, by passing each remaining rule to ofproto_rule_destroy().  The
373      * client will destroy the flow tables themselves after ->destruct()
374      * returns.
375      */
376     struct ofproto *(*alloc)(void);
377     int (*construct)(struct ofproto *ofproto);
378     void (*destruct)(struct ofproto *ofproto);
379     void (*dealloc)(struct ofproto *ofproto);
380
381     /* Performs any periodic activity required by 'ofproto'.  It should:
382      *
383      *   - Call connmgr_send_packet_in() for each received packet that missed
384      *     in the OpenFlow flow table or that had a OFPP_CONTROLLER output
385      *     action.
386      *
387      *   - Call ofproto_rule_expire() for each OpenFlow flow that has reached
388      *     its hard_timeout or idle_timeout, to expire the flow.
389      *
390      * Returns 0 if successful, otherwise a positive errno value. */
391     int (*run)(struct ofproto *ofproto);
392
393     /* Performs periodic activity required by 'ofproto' that needs to be done
394      * with the least possible latency.
395      *
396      * This is run multiple times per main loop.  An ofproto provider may
397      * implement it or not, according to whether it provides a performance
398      * boost for that ofproto implementation. */
399     int (*run_fast)(struct ofproto *ofproto);
400
401     /* Causes the poll loop to wake up when 'ofproto''s 'run' function needs to
402      * be called, e.g. by calling the timer or fd waiting functions in
403      * poll-loop.h.  */
404     void (*wait)(struct ofproto *ofproto);
405
406     /* Adds some memory usage statistics for the implementation of 'ofproto'
407      * into 'usage', for use with memory_report().
408      *
409      * This function is optional. */
410     void (*get_memory_usage)(const struct ofproto *ofproto,
411                              struct simap *usage);
412
413     /* Every "struct rule" in 'ofproto' is about to be deleted, one by one.
414      * This function may prepare for that, for example by clearing state in
415      * advance.  It should *not* actually delete any "struct rule"s from
416      * 'ofproto', only prepare for it.
417      *
418      * This function is optional; it's really just for optimization in case
419      * it's cheaper to delete all the flows from your hardware in a single pass
420      * than to do it one by one. */
421     void (*flush)(struct ofproto *ofproto);
422
423     /* Helper for the OpenFlow OFPT_FEATURES_REQUEST request.
424      *
425      * The implementation should store true in '*arp_match_ip' if the switch
426      * supports matching IP addresses inside ARP requests and replies, false
427      * otherwise.
428      *
429      * The implementation should store in '*actions' a bitmap of the supported
430      * OpenFlow actions.  Vendor actions are not included in '*actions'. */
431     void (*get_features)(struct ofproto *ofproto,
432                          bool *arp_match_ip,
433                          enum ofputil_action_bitmap *actions);
434
435     /* Helper for the OpenFlow OFPST_TABLE statistics request.
436      *
437      * The 'ots' array contains 'ofproto->n_tables' elements.  Each element is
438      * initialized as:
439      *
440      *   - 'table_id' to the array index.
441      *
442      *   - 'name' to "table#" where # is the table ID.
443      *
444      *   - 'wildcards' to OFPFW10_ALL.
445      *
446      *   - 'max_entries' to 1,000,000.
447      *
448      *   - 'active_count' to the classifier_count() for the table.
449      *
450      *   - 'lookup_count' and 'matched_count' to 0.
451      *
452      * The implementation should update any members in each element for which
453      * it has better values:
454      *
455      *   - 'name' to a more meaningful name.
456      *
457      *   - 'wildcards' to the set of wildcards actually supported by the table
458      *     (if it doesn't support all OpenFlow wildcards).
459      *
460      *   - 'max_entries' to the maximum number of flows actually supported by
461      *     the hardware.
462      *
463      *   - 'lookup_count' to the number of packets looked up in this flow table
464      *     so far.
465      *
466      *   - 'matched_count' to the number of packets looked up in this flow
467      *     table so far that matched one of the flow entries.
468      *
469      * Keep in mind that all of the members of struct ofp_table_stats are in
470      * network byte order.
471      */
472     void (*get_tables)(struct ofproto *ofproto, struct ofp_table_stats *ots);
473
474 /* ## ---------------- ## */
475 /* ## ofport Functions ## */
476 /* ## ---------------- ## */
477
478     /* Life-cycle functions for a "struct ofport" (see "Life Cycle" above).
479      *
480      * ->port_construct() should not modify any base members of the ofport.
481      *
482      * ofports are managed by the base ofproto code.  The ofproto
483      * implementation should only create and destroy them in response to calls
484      * to these functions.  The base ofproto code will create and destroy
485      * ofports in the following situations:
486      *
487      *   - Just after the ->construct() function is called, the base ofproto
488      *     iterates over all of the implementation's ports, using
489      *     ->port_dump_start() and related functions, and constructs an ofport
490      *     for each dumped port.
491      *
492      *   - If ->port_poll() reports that a specific port has changed, then the
493      *     base ofproto will query that port with ->port_query_by_name() and
494      *     construct or destruct ofports as necessary to reflect the updated
495      *     set of ports.
496      *
497      *   - If ->port_poll() returns ENOBUFS to report an unspecified port set
498      *     change, then the base ofproto will iterate over all of the
499      *     implementation's ports, in the same way as at ofproto
500      *     initialization, and construct and destruct ofports to reflect all of
501      *     the changes.
502      *
503      * ->port_construct() returns 0 if successful, otherwise a positive errno
504      * value.
505      */
506     struct ofport *(*port_alloc)(void);
507     int (*port_construct)(struct ofport *ofport);
508     void (*port_destruct)(struct ofport *ofport);
509     void (*port_dealloc)(struct ofport *ofport);
510
511     /* Called after 'ofport->netdev' is replaced by a new netdev object.  If
512      * the ofproto implementation uses the ofport's netdev internally, then it
513      * should switch to using the new one.  The old one has been closed.
514      *
515      * An ofproto implementation that doesn't need to do anything in this
516      * function may use a null pointer. */
517     void (*port_modified)(struct ofport *ofport);
518
519     /* Called after an OpenFlow request changes a port's configuration.
520      * 'ofport->pp.config' contains the new configuration.  'old_config'
521      * contains the previous configuration.
522      *
523      * The caller implements OFPUTIL_PC_PORT_DOWN using netdev functions to
524      * turn NETDEV_UP on and off, so this function doesn't have to do anything
525      * for that bit (and it won't be called if that is the only bit that
526      * changes). */
527     void (*port_reconfigured)(struct ofport *ofport,
528                               enum ofputil_port_config old_config);
529
530     /* Looks up a port named 'devname' in 'ofproto'.  On success, initializes
531      * '*port' appropriately.
532      *
533      * The caller owns the data in 'port' and must free it with
534      * ofproto_port_destroy() when it is no longer needed. */
535     int (*port_query_by_name)(const struct ofproto *ofproto,
536                               const char *devname, struct ofproto_port *port);
537
538     /* Attempts to add 'netdev' as a port on 'ofproto'.  Returns 0 if
539      * successful, otherwise a positive errno value.  If successful, sets
540      * '*ofp_portp' to the new port's port number.
541      *
542      * It doesn't matter whether the new port will be returned by a later call
543      * to ->port_poll(); the implementation may do whatever is more
544      * convenient. */
545     int (*port_add)(struct ofproto *ofproto, struct netdev *netdev,
546                     uint16_t *ofp_portp);
547
548     /* Deletes port number 'ofp_port' from the datapath for 'ofproto'.  Returns
549      * 0 if successful, otherwise a positive errno value.
550      *
551      * It doesn't matter whether the new port will be returned by a later call
552      * to ->port_poll(); the implementation may do whatever is more
553      * convenient. */
554     int (*port_del)(struct ofproto *ofproto, uint16_t ofp_port);
555
556     /* Get port stats */
557     int (*port_get_stats)(const struct ofport *port,
558                           struct netdev_stats *stats);
559
560     /* Port iteration functions.
561      *
562      * The client might not be entirely in control of the ports within an
563      * ofproto.  Some hardware implementations, for example, might have a fixed
564      * set of ports in a datapath, and the Linux datapath allows the system
565      * administrator to externally add and remove ports with ovs-dpctl.  For
566      * this reason, the client needs a way to iterate through all the ports
567      * that are actually in a datapath.  These functions provide that
568      * functionality.
569      *
570      * The 'state' pointer provides the implementation a place to
571      * keep track of its position.  Its format is opaque to the caller.
572      *
573      * The ofproto provider retains ownership of the data that it stores into
574      * ->port_dump_next()'s 'port' argument.  The data must remain valid until
575      * at least the next call to ->port_dump_next() or ->port_dump_done() for
576      * 'state'.  The caller will not modify or free it.
577      *
578      * Details
579      * =======
580      *
581      * ->port_dump_start() attempts to begin dumping the ports in 'ofproto'.
582      * On success, it should return 0 and initialize '*statep' with any data
583      * needed for iteration.  On failure, returns a positive errno value, and
584      * the client will not call ->port_dump_next() or ->port_dump_done().
585      *
586      * ->port_dump_next() attempts to retrieve another port from 'ofproto' for
587      * 'state'.  If there is another port, it should store the port's
588      * information into 'port' and return 0.  It should return EOF if all ports
589      * have already been iterated.  Otherwise, on error, it should return a
590      * positive errno value.  This function will not be called again once it
591      * returns nonzero once for a given iteration (but the 'port_dump_done'
592      * function will be called afterward).
593      *
594      * ->port_dump_done() allows the implementation to release resources used
595      * for iteration.  The caller might decide to stop iteration in the middle
596      * by calling this function before ->port_dump_next() returns nonzero.
597      *
598      * Usage Example
599      * =============
600      *
601      * int error;
602      * void *state;
603      *
604      * error = ofproto->ofproto_class->port_dump_start(ofproto, &state);
605      * if (!error) {
606      *     for (;;) {
607      *         struct ofproto_port port;
608      *
609      *         error = ofproto->ofproto_class->port_dump_next(
610      *                     ofproto, state, &port);
611      *         if (error) {
612      *             break;
613      *         }
614      *         // Do something with 'port' here (without modifying or freeing
615      *         // any of its data).
616      *     }
617      *     ofproto->ofproto_class->port_dump_done(ofproto, state);
618      * }
619      * // 'error' is now EOF (success) or a positive errno value (failure).
620      */
621     int (*port_dump_start)(const struct ofproto *ofproto, void **statep);
622     int (*port_dump_next)(const struct ofproto *ofproto, void *state,
623                           struct ofproto_port *port);
624     int (*port_dump_done)(const struct ofproto *ofproto, void *state);
625
626     /* Polls for changes in the set of ports in 'ofproto'.  If the set of ports
627      * in 'ofproto' has changed, then this function should do one of the
628      * following:
629      *
630      * - Preferably: store the name of the device that was added to or deleted
631      *   from 'ofproto' in '*devnamep' and return 0.  The caller is responsible
632      *   for freeing '*devnamep' (with free()) when it no longer needs it.
633      *
634      * - Alternatively: return ENOBUFS, without indicating the device that was
635      *   added or deleted.
636      *
637      * Occasional 'false positives', in which the function returns 0 while
638      * indicating a device that was not actually added or deleted or returns
639      * ENOBUFS without any change, are acceptable.
640      *
641      * The purpose of 'port_poll' is to let 'ofproto' know about changes made
642      * externally to the 'ofproto' object, e.g. by a system administrator via
643      * ovs-dpctl.  Therefore, it's OK, and even preferable, for port_poll() to
644      * not report changes made through calls to 'port_add' or 'port_del' on the
645      * same 'ofproto' object.  (But it's OK for it to report them too, just
646      * slightly less efficient.)
647      *
648      * If the set of ports in 'ofproto' has not changed, returns EAGAIN.  May
649      * also return other positive errno values to indicate that something has
650      * gone wrong.
651      *
652      * If the set of ports in a datapath is fixed, or if the only way that the
653      * set of ports in a datapath can change is through ->port_add() and
654      * ->port_del(), then this function may be a null pointer.
655      */
656     int (*port_poll)(const struct ofproto *ofproto, char **devnamep);
657
658     /* Arranges for the poll loop to wake up when ->port_poll() will return a
659      * value other than EAGAIN.
660      *
661      * If the set of ports in a datapath is fixed, or if the only way that the
662      * set of ports in a datapath can change is through ->port_add() and
663      * ->port_del(), or if the poll loop will always wake up anyway when
664      * ->port_poll() will return a value other than EAGAIN, then this function
665      * may be a null pointer.
666      */
667     void (*port_poll_wait)(const struct ofproto *ofproto);
668
669     /* Checks the status of LACP negotiation for 'port'.  Returns 1 if LACP
670      * partner information for 'port' is up-to-date, 0 if LACP partner
671      * information is not current (generally indicating a connectivity
672      * problem), or -1 if LACP is not enabled on 'port'.
673      *
674      * This function may be a null pointer if the ofproto implementation does
675      * not support LACP. */
676     int (*port_is_lacp_current)(const struct ofport *port);
677
678 /* ## ----------------------- ## */
679 /* ## OpenFlow Rule Functions ## */
680 /* ## ----------------------- ## */
681
682
683
684     /* Chooses an appropriate table for 'cls_rule' within 'ofproto'.  On
685      * success, stores the table ID into '*table_idp' and returns 0.  On
686      * failure, returns an OpenFlow error code.
687      *
688      * The choice of table should be a function of 'cls_rule' and 'ofproto''s
689      * datapath capabilities.  It should not depend on the flows already in
690      * 'ofproto''s flow tables.  Failure implies that an OpenFlow rule with
691      * 'cls_rule' as its matching condition can never be inserted into
692      * 'ofproto', even starting from an empty flow table.
693      *
694      * If multiple tables are candidates for inserting the flow, the function
695      * should choose one arbitrarily (but deterministically).
696      *
697      * If this function is NULL then table 0 is always chosen. */
698     enum ofperr (*rule_choose_table)(const struct ofproto *ofproto,
699                                      const struct cls_rule *cls_rule,
700                                      uint8_t *table_idp);
701
702     /* Life-cycle functions for a "struct rule" (see "Life Cycle" above).
703      *
704      *
705      * Asynchronous Operation Support
706      * ==============================
707      *
708      * The life-cycle operations on rules can operate asynchronously, meaning
709      * that ->rule_construct() and ->rule_destruct() only need to initiate
710      * their respective operations and do not need to wait for them to complete
711      * before they return.  ->rule_modify_actions() also operates
712      * asynchronously.
713      *
714      * An ofproto implementation reports the success or failure of an
715      * asynchronous operation on a rule using the rule's 'pending' member,
716      * which points to a opaque "struct ofoperation" that represents the
717      * ongoing opreation.  When the operation completes, the ofproto
718      * implementation calls ofoperation_complete(), passing the ofoperation and
719      * an error indication.
720      *
721      * Only the following contexts may call ofoperation_complete():
722      *
723      *   - The function called to initiate the operation,
724      *     e.g. ->rule_construct() or ->rule_destruct().  This is the best
725      *     choice if the operation completes quickly.
726      *
727      *   - The implementation's ->run() function.
728      *
729      *   - The implementation's ->destruct() function.
730      *
731      * The ofproto base code updates the flow table optimistically, assuming
732      * that the operation will probably succeed:
733      *
734      *   - ofproto adds or replaces the rule in the flow table before calling
735      *     ->rule_construct().
736      *
737      *   - ofproto updates the rule's actions before calling
738      *     ->rule_modify_actions().
739      *
740      *   - ofproto removes the rule before calling ->rule_destruct().
741      *
742      * With one exception, when an asynchronous operation completes with an
743      * error, ofoperation_complete() backs out the already applied changes:
744      *
745      *   - If adding or replacing a rule in the flow table fails, ofproto
746      *     removes the new rule or restores the original rule.
747      *
748      *   - If modifying a rule's actions fails, ofproto restores the original
749      *     actions.
750      *
751      *   - Removing a rule is not allowed to fail.  It must always succeed.
752      *
753      * The ofproto base code serializes operations: if any operation is in
754      * progress on a given rule, ofproto postpones initiating any new operation
755      * on that rule until the pending operation completes.  Therefore, every
756      * operation must eventually complete through a call to
757      * ofoperation_complete() to avoid delaying new operations indefinitely
758      * (including any OpenFlow request that affects the rule in question, even
759      * just to query its statistics).
760      *
761      *
762      * Construction
763      * ============
764      *
765      * When ->rule_construct() is called, the caller has already inserted
766      * 'rule' into 'rule->ofproto''s flow table numbered 'rule->table_id'.
767      * There are two cases:
768      *
769      *   - 'rule' is a new rule in its flow table.  In this case,
770      *     ofoperation_get_victim(rule) returns NULL.
771      *
772      *   - 'rule' is replacing an existing rule in its flow table that had the
773      *     same matching criteria and priority.  In this case,
774      *     ofoperation_get_victim(rule) returns the rule being replaced (the
775      *     "victim" rule).
776      *
777      * ->rule_construct() should set the following in motion:
778      *
779      *   - Validate that the matching rule in 'rule->cr' is supported by the
780      *     datapath.  For example, if the rule's table does not support
781      *     registers, then it is an error if 'rule->cr' does not wildcard all
782      *     registers.
783      *
784      *   - Validate that 'rule->actions' and 'rule->n_actions' are well-formed
785      *     OpenFlow actions that the datapath can correctly implement.  The
786      *     validate_actions() function (in ofp-util.c) can be useful as a model
787      *     for action validation, but it accepts all of the OpenFlow actions
788      *     that OVS understands.  If your ofproto implementation only
789      *     implements a subset of those, then you should implement your own
790      *     action validation.
791      *
792      *   - If the rule is valid, update the datapath flow table, adding the new
793      *     rule or replacing the existing one.
794      *
795      *   - If 'rule' is replacing an existing rule, uninitialize any derived
796      *     state for the victim rule, as in step 5 in the "Life Cycle"
797      *     described above.
798      *
799      * (On failure, the ofproto code will roll back the insertion from the flow
800      * table, either removing 'rule' or replacing it by the victim rule if
801      * there is one.)
802      *
803      * ->rule_construct() must act in one of the following ways:
804      *
805      *   - If it succeeds, it must call ofoperation_complete() and return 0.
806      *
807      *   - If it fails, it must act in one of the following ways:
808      *
809      *       * Call ofoperation_complete() and return 0.
810      *
811      *       * Return an OpenFlow error code.  (Do not call
812      *         ofoperation_complete() in this case.)
813      *
814      *     Either way, ->rule_destruct() will not be called for 'rule', but
815      *     ->rule_dealloc() will be.
816      *
817      *   - If the operation is only partially complete, then it must return 0.
818      *     Later, when the operation is complete, the ->run() or ->destruct()
819      *     function must call ofoperation_complete() to report success or
820      *     failure.
821      *
822      * ->rule_construct() should not modify any base members of struct rule.
823      *
824      *
825      * Destruction
826      * ===========
827      *
828      * When ->rule_destruct() is called, the caller has already removed 'rule'
829      * from 'rule->ofproto''s flow table.  ->rule_destruct() should set in
830      * motion removing 'rule' from the datapath flow table.  If removal
831      * completes synchronously, it should call ofoperation_complete().
832      * Otherwise, the ->run() or ->destruct() function must later call
833      * ofoperation_complete() after the operation completes.
834      *
835      * Rule destruction must not fail. */
836     struct rule *(*rule_alloc)(void);
837     enum ofperr (*rule_construct)(struct rule *rule);
838     void (*rule_destruct)(struct rule *rule);
839     void (*rule_dealloc)(struct rule *rule);
840
841     /* Obtains statistics for 'rule', storing the number of packets that have
842      * matched it in '*packet_count' and the number of bytes in those packets
843      * in '*byte_count'.  UINT64_MAX indicates that the packet count or byte
844      * count is unknown. */
845     void (*rule_get_stats)(struct rule *rule, uint64_t *packet_count,
846                            uint64_t *byte_count);
847
848     /* Applies the actions in 'rule' to 'packet'.  (This implements sending
849      * buffered packets for OpenFlow OFPT_FLOW_MOD commands.)
850      *
851      * Takes ownership of 'packet' (so it should eventually free it, with
852      * ofpbuf_delete()).
853      *
854      * 'flow' reflects the flow information for 'packet'.  All of the
855      * information in 'flow' is extracted from 'packet', except for
856      * flow->tun_id and flow->in_port, which are assigned the correct values
857      * for the incoming packet.  The register values are zeroed.  'packet''s
858      * header pointers (e.g. packet->l3) are appropriately initialized.
859      *
860      * The implementation should add the statistics for 'packet' into 'rule'.
861      *
862      * Returns 0 if successful, otherwise an OpenFlow error code. */
863     enum ofperr (*rule_execute)(struct rule *rule, const struct flow *flow,
864                                 struct ofpbuf *packet);
865
866     /* When ->rule_modify_actions() is called, the caller has already replaced
867      * the OpenFlow actions in 'rule' by a new set.  (The original actions are
868      * in rule->pending->actions.)
869      *
870      * ->rule_modify_actions() should set the following in motion:
871      *
872      *   - Validate that the actions now in 'rule' are well-formed OpenFlow
873      *     actions that the datapath can correctly implement.
874      *
875      *   - Update the datapath flow table with the new actions.
876      *
877      * If the operation synchronously completes, ->rule_modify_actions() may
878      * call ofoperation_complete() before it returns.  Otherwise, ->run()
879      * should call ofoperation_complete() later, after the operation does
880      * complete.
881      *
882      * If the operation fails, then the base ofproto code will restore the
883      * original 'actions' and 'n_actions' of 'rule'.
884      *
885      * ->rule_modify_actions() should not modify any base members of struct
886      * rule. */
887     void (*rule_modify_actions)(struct rule *rule);
888
889     /* Changes the OpenFlow IP fragment handling policy to 'frag_handling',
890      * which takes one of the following values, with the corresponding
891      * meanings:
892      *
893      *  - OFPC_FRAG_NORMAL: The switch should treat IP fragments the same way
894      *    as other packets, omitting TCP and UDP port numbers (always setting
895      *    them to 0).
896      *
897      *  - OFPC_FRAG_DROP: The switch should drop all IP fragments without
898      *    passing them through the flow table.
899      *
900      *  - OFPC_FRAG_REASM: The switch should reassemble IP fragments before
901      *    passing packets through the flow table.
902      *
903      *  - OFPC_FRAG_NX_MATCH (a Nicira extension): Similar to OFPC_FRAG_NORMAL,
904      *    except that TCP and UDP port numbers should be included in fragments
905      *    with offset 0.
906      *
907      * Implementations are not required to support every mode.
908      * OFPC_FRAG_NORMAL is the default mode when an ofproto is created.
909      *
910      * At the time of the call to ->set_frag_handling(), the current mode is
911      * available in 'ofproto->frag_handling'.  ->set_frag_handling() returns
912      * true if the requested mode was set, false if it is not supported.
913      *
914      * Upon successful return, the caller changes 'ofproto->frag_handling' to
915      * reflect the new mode.
916      */
917     bool (*set_frag_handling)(struct ofproto *ofproto,
918                               enum ofp_config_flags frag_handling);
919
920     /* Implements the OpenFlow OFPT_PACKET_OUT command.  The datapath should
921      * execute the 'n_actions' in the 'actions' array on 'packet'.
922      *
923      * The caller retains ownership of 'packet', so ->packet_out() should not
924      * modify or free it.
925      *
926      * This function must validate that the 'n_actions' elements in 'actions'
927      * are well-formed OpenFlow actions that can be correctly implemented by
928      * the datapath.  If not, then it should return an OpenFlow error code.
929      *
930      * 'flow' reflects the flow information for 'packet'.  All of the
931      * information in 'flow' is extracted from 'packet', except for
932      * flow->in_port (see below).  flow->tun_id and its register values are
933      * zeroed.
934      *
935      * flow->in_port comes from the OpenFlow OFPT_PACKET_OUT message.  The
936      * implementation should reject invalid flow->in_port values by returning
937      * OFPERR_NXBRC_BAD_IN_PORT.  For consistency, the implementation should
938      * consider valid for flow->in_port any value that could possibly be seen
939      * in a packet that it passes to connmgr_send_packet_in().  Ideally, even
940      * an implementation that never generates packet-ins (e.g. due to hardware
941      * limitations) should still allow flow->in_port values for every possible
942      * physical port and OFPP_LOCAL.  The only virtual ports (those above
943      * OFPP_MAX) that the caller will ever pass in as flow->in_port, other than
944      * OFPP_LOCAL, are OFPP_NONE and OFPP_CONTROLLER.  The implementation
945      * should allow both of these, treating each of them as packets generated
946      * by the controller as opposed to packets originating from some switch
947      * port.
948      *
949      * (Ordinarily the only effect of flow->in_port is on output actions that
950      * involve the input port, such as actions that output to OFPP_IN_PORT,
951      * OFPP_FLOOD, or OFPP_ALL.  flow->in_port can also affect Nicira extension
952      * "resubmit" actions.)
953      *
954      * 'packet' is not matched against the OpenFlow flow table, so its
955      * statistics should not be included in OpenFlow flow statistics.
956      *
957      * Returns 0 if successful, otherwise an OpenFlow error code. */
958     enum ofperr (*packet_out)(struct ofproto *ofproto, struct ofpbuf *packet,
959                               const struct flow *flow,
960                               const union ofp_action *actions,
961                               size_t n_actions);
962
963 /* ## ------------------------- ## */
964 /* ## OFPP_NORMAL configuration ## */
965 /* ## ------------------------- ## */
966
967     /* Configures NetFlow on 'ofproto' according to the options in
968      * 'netflow_options', or turns off NetFlow if 'netflow_options' is NULL.
969      *
970      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
971      * NetFlow, as does a null pointer. */
972     int (*set_netflow)(struct ofproto *ofproto,
973                        const struct netflow_options *netflow_options);
974
975     void (*get_netflow_ids)(const struct ofproto *ofproto,
976                             uint8_t *engine_type, uint8_t *engine_id);
977
978     /* Configures sFlow on 'ofproto' according to the options in
979      * 'sflow_options', or turns off sFlow if 'sflow_options' is NULL.
980      *
981      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
982      * sFlow, as does a null pointer. */
983     int (*set_sflow)(struct ofproto *ofproto,
984                      const struct ofproto_sflow_options *sflow_options);
985
986     /* Configures connectivity fault management on 'ofport'.
987      *
988      * If 'cfm_settings' is nonnull, configures CFM according to its members.
989      *
990      * If 'cfm_settings' is null, removes any connectivity fault management
991      * configuration from 'ofport'.
992      *
993      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
994      * support CFM, as does a null pointer. */
995     int (*set_cfm)(struct ofport *ofport, const struct cfm_settings *s);
996
997     /* Checks the fault status of CFM configured on 'ofport'.  Returns a
998      * bitmask of 'cfm_fault_reason's to indicate a CFM fault (generally
999      * indicating a connectivity problem).  Returns zero if CFM is not faulted,
1000      * and -1 if CFM is not enabled on 'port'.
1001      *
1002      * This function may be a null pointer if the ofproto implementation does
1003      * not support CFM. */
1004     int (*get_cfm_fault)(const struct ofport *ofport);
1005
1006     /* Gets the MPIDs of the remote maintenance points broadcasting to
1007      * 'ofport'.  Populates 'rmps' with a provider owned array of MPIDs, and
1008      * 'n_rmps' with the number of MPIDs in 'rmps'. Returns a number less than
1009      * 0 if CFM is not enabled of 'ofport'.
1010      *
1011      * This function may be a null pointer if the ofproto implementation does
1012      * not support CFM. */
1013     int (*get_cfm_remote_mpids)(const struct ofport *ofport,
1014                                 const uint64_t **rmps, size_t *n_rmps);
1015
1016     /* Checks the health of CFM configured on 'ofport'.  Returns an integer
1017      * to indicate the health percentage of the 'ofport' which is an average of
1018      * the health of all the remote_mps.  Returns an integer between 0 and 100
1019      * where 0 means that the 'ofport' is very unhealthy and 100 means the
1020      * 'ofport' is perfectly healthy.  Returns -1 if CFM is not enabled on
1021      * 'port' or if the number of remote_mpids is > 1.
1022      *
1023      * This function may be a null pointer if the ofproto implementation does
1024      * not support CFM. */
1025     int (*get_cfm_health)(const struct ofport *ofport);
1026
1027     /* Configures spanning tree protocol (STP) on 'ofproto' using the
1028      * settings defined in 's'.
1029      *
1030      * If 's' is nonnull, configures STP according to its members.
1031      *
1032      * If 's' is null, removes any STP configuration from 'ofproto'.
1033      *
1034      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1035      * support STP, as does a null pointer. */
1036     int (*set_stp)(struct ofproto *ofproto,
1037                    const struct ofproto_stp_settings *s);
1038
1039     /* Retrieves state of spanning tree protocol (STP) on 'ofproto'.
1040      *
1041      * Stores STP state for 'ofproto' in 's'.  If the 'enabled' member
1042      * is false, the other member values are not meaningful.
1043      *
1044      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1045      * support STP, as does a null pointer. */
1046     int (*get_stp_status)(struct ofproto *ofproto,
1047                           struct ofproto_stp_status *s);
1048
1049     /* Configures spanning tree protocol (STP) on 'ofport' using the
1050      * settings defined in 's'.
1051      *
1052      * If 's' is nonnull, configures STP according to its members.  The
1053      * caller is responsible for assigning STP port numbers (using the
1054      * 'port_num' member in the range of 1 through 255, inclusive) and
1055      * ensuring there are no duplicates.
1056      *
1057      * If 's' is null, removes any STP configuration from 'ofport'.
1058      *
1059      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1060      * support STP, as does a null pointer. */
1061     int (*set_stp_port)(struct ofport *ofport,
1062                         const struct ofproto_port_stp_settings *s);
1063
1064     /* Retrieves spanning tree protocol (STP) port status of 'ofport'.
1065      *
1066      * Stores STP state for 'ofport' in 's'.  If the 'enabled' member is
1067      * false, the other member values are not meaningful.
1068      *
1069      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1070      * support STP, as does a null pointer. */
1071     int (*get_stp_port_status)(struct ofport *ofport,
1072                                struct ofproto_port_stp_status *s);
1073
1074     /* Registers meta-data associated with the 'n_qdscp' Qualities of Service
1075      * 'queues' attached to 'ofport'.  This data is not intended to be
1076      * sufficient to implement QoS.  Instead, providers may use this
1077      * information to implement features which require knowledge of what queues
1078      * exist on a port, and some basic information about them.
1079      *
1080      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1081      * support QoS, as does a null pointer. */
1082     int (*set_queues)(struct ofport *ofport,
1083                       const struct ofproto_port_queue *queues, size_t n_qdscp);
1084
1085     /* If 's' is nonnull, this function registers a "bundle" associated with
1086      * client data pointer 'aux' in 'ofproto'.  A bundle is the same concept as
1087      * a Port in OVSDB, that is, it consists of one or more "slave" devices
1088      * (Interfaces, in OVSDB) along with VLAN and LACP configuration and, if
1089      * there is more than one slave, a bonding configuration.  If 'aux' is
1090      * already registered then this function updates its configuration to 's'.
1091      * Otherwise, this function registers a new bundle.
1092      *
1093      * If 's' is NULL, this function unregisters the bundle registered on
1094      * 'ofproto' associated with client data pointer 'aux'.  If no such bundle
1095      * has been registered, this has no effect.
1096      *
1097      * This function affects only the behavior of the NXAST_AUTOPATH action and
1098      * output to the OFPP_NORMAL port.  An implementation that does not support
1099      * it at all may set it to NULL or return EOPNOTSUPP.  An implementation
1100      * that supports only a subset of the functionality should implement what
1101      * it can and return 0. */
1102     int (*bundle_set)(struct ofproto *ofproto, void *aux,
1103                       const struct ofproto_bundle_settings *s);
1104
1105     /* If 'port' is part of any bundle, removes it from that bundle.  If the
1106      * bundle now has no ports, deletes the bundle.  If the bundle now has only
1107      * one port, deconfigures the bundle's bonding configuration. */
1108     void (*bundle_remove)(struct ofport *ofport);
1109
1110     /* If 's' is nonnull, this function registers a mirror associated with
1111      * client data pointer 'aux' in 'ofproto'.  A mirror is the same concept as
1112      * a Mirror in OVSDB.  If 'aux' is already registered then this function
1113      * updates its configuration to 's'.  Otherwise, this function registers a
1114      * new mirror.
1115      *
1116      * If 's' is NULL, this function unregisters the mirror registered on
1117      * 'ofproto' associated with client data pointer 'aux'.  If no such mirror
1118      * has been registered, this has no effect.
1119      *
1120      * An implementation that does not support mirroring at all may set
1121      * it to NULL or return EOPNOTSUPP.  An implementation that supports
1122      * only a subset of the functionality should implement what it can
1123      * and return 0. */
1124     int (*mirror_set)(struct ofproto *ofproto, void *aux,
1125                       const struct ofproto_mirror_settings *s);
1126
1127     /* Retrieves statistics from mirror associated with client data
1128      * pointer 'aux' in 'ofproto'.  Stores packet and byte counts in
1129      * 'packets' and 'bytes', respectively.  If a particular counter is
1130      * not supported, the appropriate argument is set to UINT64_MAX.
1131      *
1132      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1133      * support retrieving mirror statistics. */
1134     int (*mirror_get_stats)(struct ofproto *ofproto, void *aux,
1135                             uint64_t *packets, uint64_t *bytes);
1136
1137     /* Configures the VLANs whose bits are set to 1 in 'flood_vlans' as VLANs
1138      * on which all packets are flooded, instead of using MAC learning.  If
1139      * 'flood_vlans' is NULL, then MAC learning applies to all VLANs.
1140      *
1141      * This function affects only the behavior of the OFPP_NORMAL action.  An
1142      * implementation that does not support it may set it to NULL or return
1143      * EOPNOTSUPP. */
1144     int (*set_flood_vlans)(struct ofproto *ofproto,
1145                            unsigned long *flood_vlans);
1146
1147     /* Returns true if 'aux' is a registered bundle that is currently in use as
1148      * the output for a mirror. */
1149     bool (*is_mirror_output_bundle)(const struct ofproto *ofproto, void *aux);
1150
1151     /* When the configuration option of forward_bpdu changes, this function
1152      * will be invoked. */
1153     void (*forward_bpdu_changed)(struct ofproto *ofproto);
1154
1155     /* Sets the MAC aging timeout for the OFPP_NORMAL action to 'idle_time',
1156      * in seconds. */
1157     void (*set_mac_idle_time)(struct ofproto *ofproto, unsigned int idle_time);
1158
1159 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
1160  *
1161  * This is deprecated.  It is only for compatibility with broken device drivers
1162  * in old versions of Linux that do not properly support VLANs when VLAN
1163  * devices are not used.  When broken device drivers are no longer in
1164  * widespread use, we will delete these interfaces. */
1165
1166     /* If 'realdev_ofp_port' is nonzero, then this function configures 'ofport'
1167      * as a VLAN splinter port for VLAN 'vid', associated with the real device
1168      * that has OpenFlow port number 'realdev_ofp_port'.
1169      *
1170      * If 'realdev_ofp_port' is zero, then this function deconfigures 'ofport'
1171      * as a VLAN splinter port.
1172      *
1173      * This function should be NULL if a an implementation does not support
1174      * it. */
1175     int (*set_realdev)(struct ofport *ofport,
1176                        uint16_t realdev_ofp_port, int vid);
1177 };
1178
1179 extern const struct ofproto_class ofproto_dpif_class;
1180
1181 int ofproto_class_register(const struct ofproto_class *);
1182 int ofproto_class_unregister(const struct ofproto_class *);
1183
1184 /* ofproto_flow_mod() returns this value if the flow_mod could not be processed
1185  * because it overlaps with an ongoing flow table operation that has not yet
1186  * completed.  The caller should retry the operation later.
1187  *
1188  * ofproto.c also uses this value internally for additional (similar) purposes.
1189  *
1190  * This particular value is a good choice because it is large, so that it does
1191  * not collide with any errno value, but not large enough to collide with an
1192  * OFPERR_* value. */
1193 enum { OFPROTO_POSTPONE = 1 << 16 };
1194 BUILD_ASSERT_DECL(OFPROTO_POSTPONE < OFPERR_OFS);
1195
1196 int ofproto_flow_mod(struct ofproto *, const struct ofputil_flow_mod *);
1197 void ofproto_add_flow(struct ofproto *, const struct cls_rule *,
1198                       const union ofp_action *, size_t n_actions);
1199 bool ofproto_delete_flow(struct ofproto *, const struct cls_rule *);
1200 void ofproto_flush_flows(struct ofproto *);
1201
1202 #endif /* ofproto/ofproto-provider.h */