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