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