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