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