ofproto: Better document the ofproto_class interface.
[sliver-openvswitch.git] / ofproto / private.h
1 /*
2  * Copyright (c) 2009, 2010, 2011 Nicira Networks.
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_PRIVATE_H
18 #define OFPROTO_PRIVATE_H 1
19
20 /* Definitions for use within ofproto. */
21
22 #include "ofproto/ofproto.h"
23 #include "classifier.h"
24 #include "list.h"
25 #include "shash.h"
26 #include "timeval.h"
27
28 /* An OpenFlow switch.
29  *
30  * With few exceptions, ofproto implementations may look at these fields but
31  * should not modify them. */
32 struct ofproto {
33     const struct ofproto_class *ofproto_class;
34     char *type;                 /* Datapath type. */
35     char *name;                 /* Datapath name. */
36     struct hmap_node hmap_node; /* In global 'all_ofprotos' hmap. */
37
38     /* Settings. */
39     uint64_t fallback_dpid;     /* Datapath ID if no better choice found. */
40     uint64_t datapath_id;       /* Datapath ID. */
41     char *mfr_desc;             /* Manufacturer. */
42     char *hw_desc;              /* Hardware. */
43     char *sw_desc;              /* Software version. */
44     char *serial_desc;          /* Serial number. */
45     char *dp_desc;              /* Datapath description. */
46
47     /* Datapath. */
48     struct netdev_monitor *netdev_monitor;
49     struct hmap ports;          /* Contains "struct ofport"s. */
50     struct shash port_by_name;
51
52     /* Flow table. */
53     struct classifier cls;      /* Contains "struct rule"s. */
54
55     /* OpenFlow connections. */
56     struct connmgr *connmgr;
57 };
58
59 struct ofproto *ofproto_lookup(const char *name);
60 struct ofport *ofproto_get_port(const struct ofproto *, uint16_t ofp_port);
61
62 /* An OpenFlow port within a "struct ofproto".
63  *
64  * With few exceptions, ofproto implementations may look at these fields but
65  * should not modify them. */
66 struct ofport {
67     struct ofproto *ofproto;    /* The ofproto that contains this port. */
68     struct hmap_node hmap_node; /* In struct ofproto's "ports" hmap. */
69     struct netdev *netdev;
70     struct ofp_phy_port opp;
71     uint16_t ofp_port;          /* OpenFlow port number. */
72 };
73
74 /* An OpenFlow flow within a "struct ofproto".
75  *
76  * With few exceptions, ofproto implementations may look at these fields but
77  * should not modify them. */
78 struct rule {
79     struct ofproto *ofproto;     /* The ofproto that contains this rule. */
80     struct cls_rule cr;          /* In owning ofproto's classifier. */
81
82     ovs_be64 flow_cookie;        /* Controller-issued identifier. */
83
84     long long int created;       /* Creation time. */
85     uint16_t idle_timeout;       /* In seconds from time of last use. */
86     uint16_t hard_timeout;       /* In seconds from time of creation. */
87     bool send_flow_removed;      /* Send a flow removed message? */
88
89     union ofp_action *actions;   /* OpenFlow actions. */
90     int n_actions;               /* Number of elements in actions[]. */
91 };
92
93 static inline struct rule *
94 rule_from_cls_rule(const struct cls_rule *cls_rule)
95 {
96     return cls_rule ? CONTAINER_OF(cls_rule, struct rule, cr) : NULL;
97 }
98
99 struct rule *ofproto_rule_lookup(struct ofproto *, const struct flow *);
100 void ofproto_rule_expire(struct rule *, uint8_t reason);
101 void ofproto_rule_destroy(struct rule *);
102
103 /* ofproto class structure, to be defined by each ofproto implementation.
104  *
105  *
106  * Data Structures
107  * ===============
108  *
109  * These functions work primarily with three different kinds of data
110  * structures:
111  *
112  *   - "struct ofproto", which represents an OpenFlow switch.
113  *
114  *   - "struct ofport", which represents a port within an ofproto.
115  *
116  *   - "struct rule", which represents an OpenFlow flow within an ofproto.
117  *
118  * Each of these data structures contains all of the implementation-independent
119  * generic state for the respective concept, called the "base" state.  None of
120  * them contains any extra space for ofproto implementations to use.  Instead,
121  * each implementation is expected to declare its own data structure that
122  * contains an instance of the generic data structure plus additional
123  * implementation-specific members, called the "derived" state.  The
124  * implementation can use casts or (preferably) the CONTAINER_OF macro to
125  * obtain access to derived state given only a pointer to the embedded generic
126  * data structure.
127  *
128  *
129  * Life Cycle
130  * ==========
131  *
132  * Four stylized functions accompany each of these data structures:
133  *
134  *            "alloc"       "construct"       "destruct"       "dealloc"
135  *            ------------  ----------------  ---------------  --------------
136  *   ofproto  ->alloc       ->construct       ->destruct       ->dealloc
137  *   ofport   ->port_alloc  ->port_construct  ->port_destruct  ->port_dealloc
138  *   rule     ->rule_alloc  ->rule_construct  ->rule_destruct  ->rule_dealloc
139  *
140  * Any instance of a given data structure goes through the following life
141  * cycle:
142  *
143  *   1. The client calls the "alloc" function to obtain raw memory.  If "alloc"
144  *      fails, skip all the other steps.
145  *
146  *   2. The client initializes all of the data structure's base state.  If this
147  *      fails, skip to step 7.
148  *
149  *   3. The client calls the "construct" function.  The implementation
150  *      initializes derived state.  It may refer to the already-initialized
151  *      base state.  If "construct" fails, skip to step 6.
152  *
153  *   4. The data structure is now initialized and in use.
154  *
155  *   5. When the data structure is no longer needed, the client calls the
156  *      "destruct" function.  The implementation uninitializes derived state.
157  *      The base state has not been uninitialized yet, so the implementation
158  *      may still refer to it.
159  *
160  *   6. The client uninitializes all of the data structure's base state.
161  *
162  *   7. The client calls the "dealloc" to free the raw memory.  The
163  *      implementation must not refer to base or derived state in the data
164  *      structure, because it has already been uninitialized.
165  *
166  * Each "alloc" function allocates and returns a new instance of the respective
167  * data structure.  The "alloc" function is not given any information about the
168  * use of the new data structure, so it cannot perform much initialization.
169  * Its purpose is just to ensure that the new data structure has enough room
170  * for base and derived state.  It may return a null pointer if memory is not
171  * available, in which case none of the other functions is called.
172  *
173  * Each "construct" function initializes derived state in its respective data
174  * structure.  When "construct" is called, all of the base state has already
175  * been initialized, so the "construct" function may refer to it.  The
176  * "construct" function is allowed to fail, in which case the client calls the
177  * "dealloc" function (but not the "destruct" function).
178  *
179  * Each "destruct" function uninitializes and frees derived state in its
180  * respective data structure.  When "destruct" is called, the base state has
181  * not yet been uninitialized, so the "destruct" function may refer to it.  The
182  * "destruct" function is not allowed to fail.
183  *
184  * Each "dealloc" function frees raw memory that was allocated by the the
185  * "alloc" function.  The memory's base and derived members might not have ever
186  * been initialized (but if "construct" returned successfully, then it has been
187  * "destruct"ed already).  The "dealloc" function is not allowed to fail.
188  *
189  *
190  * Conventions
191  * ===========
192  *
193  * Most of these functions return 0 if they are successful or a positive error
194  * code on failure.  Depending on the function, valid error codes are either
195  * errno values or OpenFlow error codes constructed with ofp_mkerr().
196  *
197  * Most of these functions are expected to execute synchronously, that is, to
198  * block as necessary to obtain a result.  Thus, these functions may return
199  * EAGAIN (or EWOULDBLOCK or EINPROGRESS) only where the function descriptions
200  * explicitly say those errors are a possibility.  We may relax this
201  * requirement in the future if and when we encounter performance problems. */
202 struct ofproto_class {
203 /* ## ----------------- ## */
204 /* ## Factory Functions ## */
205 /* ## ----------------- ## */
206
207     /* Enumerates the types of all support ofproto types into 'types'.  The
208      * caller has already initialized 'types' and other ofproto classes might
209      * already have added names to it. */
210     void (*enumerate_types)(struct sset *types);
211
212     /* Enumerates the names of all existing datapath of the specified 'type'
213      * into 'names' 'all_dps'.  The caller has already initialized 'names' as
214      * an empty sset.
215      *
216      * 'type' is one of the types enumerated by ->enumerate_types().
217      *
218      * Returns 0 if successful, otherwise a positive errno value.
219      */
220     int (*enumerate_names)(const char *type, struct sset *names);
221
222     /* Deletes the datapath with the specified 'type' and 'name'.  The caller
223      * should have closed any open ofproto with this 'type' and 'name'; this
224      * function is allowed to fail if that is not the case.
225      *
226      * 'type' is one of the types enumerated by ->enumerate_types().
227      * 'name' is one of the names enumerated by ->enumerate_names() for 'type'.
228      *
229      * Returns 0 if successful, otherwise a positive errno value.
230      */
231     int (*del)(const char *type, const char *name);
232
233 /* ## --------------------------- ## */
234 /* ## Top-Level ofproto Functions ## */
235 /* ## --------------------------- ## */
236
237     /* Life-cycle functions for an "ofproto" (see "Life Cycle" above).
238      *
239      * ->construct() should not modify any base members of the ofproto, even
240      * though it may be tempting in a few cases.  In particular, the client
241      * will initialize the ofproto's 'ports' member after construction is
242      * complete.  An ofproto's flow table should be initially empty, so
243      * ->construct() should delete flows from the underlying datapath, if
244      * necessary, rather than populating the ofproto's 'cls'.
245      *
246      * Only one ofproto instance needs to be supported for any given datapath.
247      * If a datapath is already open as part of one "ofproto", then another
248      * attempt to "construct" the same datapath as part of another ofproto is
249      * allowed to fail with an error.
250      *
251      * ->construct() returns 0 if successful, otherwise a positive errno
252      * value. */
253     struct ofproto *(*alloc)(void);
254     int (*construct)(struct ofproto *ofproto);
255     void (*destruct)(struct ofproto *ofproto);
256     void (*dealloc)(struct ofproto *ofproto);
257
258     /* Performs any periodic activity required by 'ofproto'.  It should:
259      *
260      *   - Call connmgr_send_packet_in() for each received packet that missed
261      *     in the OpenFlow flow table or that had a OFPP_CONTROLLER output
262      *     action.
263      *
264      *   - Call ofproto_rule_expire() for each OpenFlow flow that has reached
265      *     its hard_timeout or idle_timeout, to expire the flow.
266      *
267      * Returns 0 if successful, otherwise a positive errno value.  The ENODEV
268      * return value specifically means that the datapath underlying 'ofproto'
269      * has been destroyed (externally, e.g. by an admin running ovs-dpctl).
270      */
271     int (*run)(struct ofproto *ofproto);
272
273     /* Causes the poll loop to wake up when 'ofproto''s 'run' function needs to
274      * be called, e.g. by calling the timer or fd waiting functions in
275      * poll-loop.h.  */
276     void (*wait)(struct ofproto *ofproto);
277
278     /* Every "struct rule" in 'ofproto' is about to be deleted, one by one.
279      * This function may prepare for that, for example by clearing state in
280      * advance.  It should *not* actually delete any "struct rule"s from
281      * 'ofproto', only prepare for it.
282      *
283      * This function is optional; it's really just for optimization in case
284      * it's cheaper to delete all the flows from your hardware in a single pass
285      * than to do it one by one. */
286     void (*flush)(struct ofproto *ofproto);
287
288 /* ## ---------------- ## */
289 /* ## ofport Functions ## */
290 /* ## ---------------- ## */
291
292     /* Life-cycle functions for a "struct ofport" (see "Life Cycle" above).
293      *
294      * ->port_construct() should not modify any base members of the ofport.
295      *
296      * ofports are managed by the base ofproto code.  The ofproto
297      * implementation should only create and destroy them in response to calls
298      * to these functions.  The base ofproto code will create and destroy
299      * ofports in the following situations:
300      *
301      *   - Just after the ->construct() function is called, the base ofproto
302      *     iterates over all of the implementation's ports, using
303      *     ->port_dump_start() and related functions, and constructs an ofport
304      *     for each dumped port.
305      *
306      *   - If ->port_poll() reports that a specific port has changed, then the
307      *     base ofproto will query that port with ->port_query_by_name() and
308      *     construct or destruct ofports as necessary to reflect the updated
309      *     set of ports.
310      *
311      *   - If ->port_poll() returns ENOBUFS to report an unspecified port set
312      *     change, then the base ofproto will iterate over all of the
313      *     implementation's ports, in the same way as at ofproto
314      *     initialization, and construct and destruct ofports to reflect all of
315      *     the changes.
316      *
317      * ->port_construct() returns 0 if successful, otherwise a positive errno
318      * value.
319      */
320     struct ofport *(*port_alloc)(void);
321     int (*port_construct)(struct ofport *ofport);
322     void (*port_destruct)(struct ofport *ofport);
323     void (*port_dealloc)(struct ofport *ofport);
324
325     /* Called after 'ofport->netdev' is replaced by a new netdev object.  If
326      * the ofproto implementation uses the ofport's netdev internally, then it
327      * should switch to using the new one.  The old one has been closed.
328      *
329      * An ofproto implementation that doesn't need to do anything in this
330      * function may use a null pointer. */
331     void (*port_modified)(struct ofport *ofport);
332
333     /* Called after an OpenFlow OFPT_PORT_MOD request changes a port's
334      * configuration.  'ofport->opp.config' contains the new configuration.
335      * 'old_config' contains the previous configuration.
336      *
337      * The caller implements OFPPC_PORT_DOWN using netdev functions to turn
338      * NETDEV_UP on and off, so this function doesn't have to do anything for
339      * that bit (and it won't be called if that is the only bit that
340      * changes). */
341     void (*port_reconfigured)(struct ofport *ofport, ovs_be32 old_config);
342
343     /* Looks up a port named 'devname' in 'ofproto'.  On success, initializes
344      * '*port' appropriately.
345      *
346      * The caller owns the data in 'port' and must free it with
347      * ofproto_port_destroy() when it is no longer needed. */
348     int (*port_query_by_name)(const struct ofproto *ofproto,
349                               const char *devname, struct ofproto_port *port);
350
351     /* Attempts to add 'netdev' as a port on 'ofproto'.  Returns 0 if
352      * successful, otherwise a positive errno value.  If successful, sets
353      * '*ofp_portp' to the new port's port number.
354      *
355      * It doesn't matter whether the new port will be returned by a later call
356      * to ->port_poll(); the implementation may do whatever is more
357      * convenient. */
358     int (*port_add)(struct ofproto *ofproto, struct netdev *netdev,
359                     uint16_t *ofp_portp);
360
361     /* Deletes port number 'ofp_port' from the datapath for 'ofproto'.  Returns
362      * 0 if successful, otherwise a positive errno value.
363      *
364      * It doesn't matter whether the new port will be returned by a later call
365      * to ->port_poll(); the implementation may do whatever is more
366      * convenient. */
367     int (*port_del)(struct ofproto *ofproto, uint16_t ofp_port);
368
369     /* Attempts to begin dumping the ports in 'ofproto'.  On success, returns 0
370      * and initializes '*statep' with any data needed for iteration.  On
371      * failure, returns a positive errno value. */
372     int (*port_dump_start)(const struct ofproto *ofproto, void **statep);
373
374     /* Attempts to retrieve another port from 'ofproto' for 'state', which was
375      * initialized by a successful call to the 'port_dump_start' function for
376      * 'ofproto'.  On success, stores a new ofproto_port into 'port' and
377      * returns 0.  Returns EOF if the end of the port table has been reached,
378      * or a positive errno value on error.  This function will not be called
379      * again once it returns nonzero once for a given iteration (but the
380      * 'port_dump_done' function will be called afterward).
381      *
382      * The ofproto provider retains ownership of the data stored in 'port'.  It
383      * must remain valid until at least the next call to 'port_dump_next' or
384      * 'port_dump_done' for 'state'. */
385     int (*port_dump_next)(const struct ofproto *ofproto, void *state,
386                           struct ofproto_port *port);
387
388     /* Releases resources from 'ofproto' for 'state', which was initialized by
389      * a successful call to the 'port_dump_start' function for 'ofproto'.  */
390     int (*port_dump_done)(const struct ofproto *ofproto, void *state);
391
392     /* Polls for changes in the set of ports in 'ofproto'.  If the set of ports
393      * in 'ofproto' has changed, then this function should do one of the
394      * following:
395      *
396      * - Preferably: store the name of the device that was added to or deleted
397      *   from 'ofproto' in '*devnamep' and return 0.  The caller is responsible
398      *   for freeing '*devnamep' (with free()) when it no longer needs it.
399      *
400      * - Alternatively: return ENOBUFS, without indicating the device that was
401      *   added or deleted.
402      *
403      * Occasional 'false positives', in which the function returns 0 while
404      * indicating a device that was not actually added or deleted or returns
405      * ENOBUFS without any change, are acceptable.
406      *
407      * The purpose of 'port_poll' is to let 'ofproto' know about changes made
408      * externally to the 'ofproto' object, e.g. by a system administrator via
409      * ovs-dpctl.  Therefore, it's OK, and even preferable, for port_poll() to
410      * not report changes made through calls to 'port_add' or 'port_del' on the
411      * same 'ofproto' object.  (But it's OK for it to report them too, just
412      * slightly less efficient.)
413      *
414      * If the set of ports in 'ofproto' has not changed, returns EAGAIN.  May
415      * also return other positive errno values to indicate that something has
416      * gone wrong.
417      *
418      * If the set of ports in a datapath is fixed, or if the only way that the
419      * set of ports in a datapath can change is through ->port_add() and
420      * ->port_del(), then this function may be a null pointer.
421      */
422     int (*port_poll)(const struct ofproto *ofproto, char **devnamep);
423
424     /* Arranges for the poll loop to wake up when ->port_poll() will return a
425      * value other than EAGAIN.
426      *
427      * If the set of ports in a datapath is fixed, or if the only way that the
428      * set of ports in a datapath can change is through ->port_add() and
429      * ->port_del(), or if the poll loop will always wake up anyway when
430      * ->port_poll() will return a value other than EAGAIN, then this function
431      * may be a null pointer.
432      */
433     void (*port_poll_wait)(const struct ofproto *ofproto);
434
435     /* Checks the status of LACP negotiation for 'port'.  Returns 1 if LACP
436      * partner information for 'port' is up-to-date, 0 if LACP partner
437      * information is not current (generally indicating a connectivity
438      * problem), or -1 if LACP is not enabled on 'port'.
439      *
440      * This function may be a null pointer if the ofproto implementation does
441      * not support LACP. */
442     int (*port_is_lacp_current)(const struct ofport *port);
443
444 /* ## ----------------------- ## */
445 /* ## OpenFlow Rule Functions ## */
446 /* ## ----------------------- ## */
447
448     /* Life-cycle functions for a "struct rule" (see "Life Cycle" above).
449      *
450      * ->rule_construct() should first check whether the rule is acceptable:
451      *
452      *   - Validate that the matching rule in 'rule->cr' is supported by the
453      *     datapath.  If not, then return an OpenFlow error code (as returned
454      *     by ofp_mkerr()).
455      *
456      *     For example, if the datapath does not support registers, then it
457      *     should return an error if 'rule->cr' does not wildcard all
458      *     registers.
459      *
460      *   - Validate that 'rule->actions' and 'rule->n_actions' are well-formed
461      *     OpenFlow actions that can be correctly implemented by the datapath.
462      *     If not, then return an OpenFlow error code (as returned by
463      *     ofp_mkerr()).
464      *
465      *     The validate_actions() function (in ofp-util.c) can be useful as a
466      *     model for action validation, but it accepts all of the OpenFlow
467      *     actions that OVS understands.  If your ofproto implementation only
468      *     implements a subset of those, then you should implement your own
469      *     action validation.
470      *
471      * If the rule is acceptable, then ->rule_construct() should modify the
472      * flow table:
473      *
474      *   - If there was already a rule with exactly the same matching criteria
475      *     and priority in the classifier, then it should remove that rule from
476      *     the classifier and destroy it (with ofproto_rule_destroy()).
477      *
478      *   - Insert the new rule into the ofproto's 'cls' classifier, and into
479      *     the datapath flow table.
480      *
481      *     (The function classifier_insert() both inserts a rule into the
482      *     classifier and removes any rule with identical matching criteria, so
483      *     this single call implements parts of both steps above.)
484      *
485      * Other than inserting 'rule->cr' into the classifier, ->rule_construct()
486      * should not modify any base members of struct rule.
487      *
488      * When ->rule_destruct() is called, 'rule' has already been removed from
489      * the classifier and the datapath flow table (by calling ->rule_remove()),
490      * so ->rule_destruct() should not duplicate that behavior. */
491     struct rule *(*rule_alloc)(void);
492     int (*rule_construct)(struct rule *rule);
493     void (*rule_destruct)(struct rule *rule);
494     void (*rule_dealloc)(struct rule *rule);
495
496     /* Removes 'rule' from 'rule->ofproto->cls' and from the datapath.
497      *
498      * 'rule' will be destructed, with ->rule_destruct(), soon after. */
499     void (*rule_remove)(struct rule *rule);
500
501     /* Obtains statistics for 'rule', storing the number of packets that have
502      * matched it in '*packet_count' and the number of bytes in those packets
503      * in '*byte_count'. */
504     void (*rule_get_stats)(struct rule *rule, uint64_t *packet_count,
505                            uint64_t *byte_count);
506
507     /* Applies the actions in 'rule' to 'packet'.  (This implements sending
508      * buffered packets for OpenFlow OFPT_FLOW_MOD commands.)
509      *
510      * Takes ownership of 'packet' (so it should eventually free it, with
511      * ofpbuf_delete()).
512      *
513      * 'flow' reflects the flow information for 'packet'.  All of the
514      * information in 'flow' is extracted from 'packet', except for
515      * flow->tun_id and flow->in_port, which are assigned the correct values
516      * for the incoming packet.  The register values are zeroed.
517      *
518      * The statistics for 'packet' should be included in 'rule'.
519      *
520      * Returns 0 if successful, otherwise an OpenFlow error code (as returned
521      * by ofp_mkerr()). */
522     int (*rule_execute)(struct rule *rule, struct flow *flow,
523                         struct ofpbuf *packet);
524
525     /* Validates that the 'n' elements in 'actions' are well-formed OpenFlow
526      * actions that can be correctly implemented by the datapath.  If not, then
527      * return an OpenFlow error code (as returned by ofp_mkerr()).  If so,
528      * then update the datapath to implement the new actions and return 0.
529      *
530      * When this function runs, 'rule' still has its original actions.  If this
531      * function returns 0, then the caller will update 'rule' with the new
532      * actions and free the old ones. */
533     int (*rule_modify_actions)(struct rule *rule,
534                                const union ofp_action *actions, size_t n);
535
536     /* These functions implement the OpenFlow IP fragment handling policy.  By
537      * default ('drop_frags' == false), an OpenFlow switch should treat IP
538      * fragments the same way as other packets (although TCP and UDP port
539      * numbers cannot be determined).  With 'drop_frags' == true, the switch
540      * should drop all IP fragments without passing them through the flow
541      * table. */
542     bool (*get_drop_frags)(struct ofproto *ofproto);
543     void (*set_drop_frags)(struct ofproto *ofproto, bool drop_frags);
544
545     /* Implements the OpenFlow OFPT_PACKET_OUT command.  The datapath should
546      * execute the 'n_actions' in the 'actions' array on 'packet'.
547      *
548      * The caller retains ownership of 'packet', so ->packet_out() should not
549      * modify or free it.
550      *
551      * This function must validate that the 'n_actions' elements in 'actions'
552      * are well-formed OpenFlow actions that can be correctly implemented by
553      * the datapath.  If not, then it should return an OpenFlow error code (as
554      * returned by ofp_mkerr()).
555      *
556      * 'flow' reflects the flow information for 'packet'.  All of the
557      * information in 'flow' is extracted from 'packet', except for
558      * flow->in_port, which is taken from the OFPT_PACKET_OUT message.
559      * flow->tun_id and its register values are zeroed.
560      *
561      * 'packet' is not matched against the OpenFlow flow table, so its
562      * statistics should not be included in OpenFlow flow statistics.
563      *
564      * Returns 0 if successful, otherwise an OpenFlow error code (as returned
565      * by ofp_mkerr()). */
566     int (*packet_out)(struct ofproto *ofproto, struct ofpbuf *packet,
567                       const struct flow *flow,
568                       const union ofp_action *actions,
569                       size_t n_actions);
570
571 /* ## ------------------------- ## */
572 /* ## OFPP_NORMAL configuration ## */
573 /* ## ------------------------- ## */
574
575     /* Configures NetFlow on 'ofproto' according to the options in
576      * 'netflow_options', or turns off NetFlow if 'netflow_options' is NULL.
577      *
578      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
579      * sFlow, as does a null pointer. */
580     int (*set_netflow)(struct ofproto *ofproto,
581                        const struct netflow_options *netflow_options);
582
583     void (*get_netflow_ids)(const struct ofproto *ofproto,
584                             uint8_t *engine_type, uint8_t *engine_id);
585
586     /* Configures sFlow on 'ofproto' according to the options in
587      * 'sflow_options', or turns off sFlow if 'sflow_options' is NULL.
588      *
589      * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
590      * sFlow, as does a null pointer. */
591     int (*set_sflow)(struct ofproto *ofproto,
592                      const struct ofproto_sflow_options *sflow_options);
593
594     /* Configures connectivity fault management on 'ofport'.
595      *
596      * If 'cfm' is nonnull, takes basic configuration from the configuration
597      * members in 'cfm', and the set of remote maintenance points from the
598      * 'n_remote_mps' elements in 'remote_mps'.  Ignores the statistics members
599      * of 'cfm'.
600      *
601      * If 'cfm' is null, removes any connectivity fault management
602      * configuration from 'ofport'.
603      *
604      * EOPNOTSUPP as a return value indicates that this ofproto_class does not
605      * support CFM, as does a null pointer. */
606     int (*set_cfm)(struct ofport *ofport, const struct cfm *cfm,
607                    const uint16_t *remote_mps, size_t n_remote_mps);
608
609     /* Stores the connectivity fault management object associated with 'ofport'
610      * in '*cfmp'.  Stores a null pointer in '*cfmp' if CFM is not configured
611      * on 'ofport'.  The caller must not modify or destroy the returned object.
612      *
613      * This function may be NULL if this ofproto_class does not support CFM. */
614     int (*get_cfm)(struct ofport *ofport, const struct cfm **cfmp);
615
616     /* If 's' is nonnull, this function registers a "bundle" associated with
617      * client data pointer 'aux' in 'ofproto'.  A bundle is the same concept as
618      * a Port in OVSDB, that is, it consists of one or more "slave" devices
619      * (Interfaces, in OVSDB) along with VLAN and LACP configuration and, if
620      * there is more than one slave, a bonding configuration.  If 'aux' is
621      * already registered then this function updates its configuration to 's'.
622      * Otherwise, this function registers a new bundle.
623      *
624      * If 's' is NULL, this function unregisters the bundle registered on
625      * 'ofproto' associated with client data pointer 'aux'.  If no such bundle
626      * has been registered, this has no effect.
627      *
628      * This function affects only the behavior of the NXAST_AUTOPATH action and
629      * output to the OFPP_NORMAL port.  An implementation that does not support
630      * it at all may set it to NULL or return EOPNOTSUPP.  An implementation
631      * that supports only a subset of the functionality should implement what
632      * it can and return 0. */
633     int (*bundle_set)(struct ofproto *ofproto, void *aux,
634                       const struct ofproto_bundle_settings *s);
635
636     /* If 'port' is part of any bundle, removes it from that bundle.  If the
637      * bundle now has no ports, deletes the bundle.  If the bundle now has only
638      * one port, deconfigures the bundle's bonding configuration. */
639     void (*bundle_remove)(struct ofport *ofport);
640
641     /* If 's' is nonnull, this function registers a mirror associated with
642      * client data pointer 'aux' in 'ofproto'.  A mirror is the same concept as
643      * a Mirror in OVSDB.  If 'aux' is already registered then this function
644      * updates its configuration to 's'.  Otherwise, this function registers a
645      * new mirror.
646      *
647      * If 's' is NULL, this function unregisters the mirror registered on
648      * 'ofproto' associated with client data pointer 'aux'.  If no such mirror
649      * has been registered, this has no effect.
650      *
651      * This function affects only the behavior of the OFPP_NORMAL action.  An
652      * implementation that does not support it at all may set it to NULL or
653      * return EOPNOTSUPP.  An implementation that supports only a subset of the
654      * functionality should implement what it can and return 0. */
655     int (*mirror_set)(struct ofproto *ofproto, void *aux,
656                       const struct ofproto_mirror_settings *s);
657
658     /* Configures the VLANs whose bits are set to 1 in 'flood_vlans' as VLANs
659      * on which all packets are flooded, instead of using MAC learning.  If
660      * 'flood_vlans' is NULL, then MAC learning applies to all VLANs.
661      *
662      * This function affects only the behavior of the OFPP_NORMAL action.  An
663      * implementation that does not support it may set it to NULL or return
664      * EOPNOTSUPP. */
665     int (*set_flood_vlans)(struct ofproto *ofproto,
666                            unsigned long *flood_vlans);
667
668     /* Returns true if 'aux' is a registered bundle that is currently in use as
669      * the output for a mirror. */
670     bool (*is_mirror_output_bundle)(struct ofproto *ofproto, void *aux);
671 };
672
673 extern const struct ofproto_class ofproto_dpif_class;
674
675 int ofproto_class_register(const struct ofproto_class *);
676 int ofproto_class_unregister(const struct ofproto_class *);
677
678 void ofproto_add_flow(struct ofproto *, const struct cls_rule *,
679                       const union ofp_action *, size_t n_actions);
680 void ofproto_delete_flow(struct ofproto *, const struct cls_rule *);
681 void ofproto_flush_flows(struct ofproto *);
682
683 #endif /* ofproto/private.h */