]> git.proxmox.com Git - ovs.git/blob - ofproto/ofproto-provider.h
bond: Remove bond_hash_src.
[ovs.git] / ofproto / ofproto-provider.h
1 /*
2 * Copyright (c) 2009-2017 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef OFPROTO_OFPROTO_PROVIDER_H
18 #define OFPROTO_OFPROTO_PROVIDER_H 1
19
20 /* Definitions for use within ofproto.
21 *
22 *
23 * Thread-safety
24 * =============
25 *
26 * Lots of ofproto data structures are only accessed from a single thread.
27 * Those data structures are generally not thread-safe.
28 *
29 * The ofproto-dpif ofproto implementation accesses the flow table from
30 * multiple threads, including modifying the flow table from multiple threads
31 * via the "learn" action, so the flow table and various structures that index
32 * it have been made thread-safe. Refer to comments on individual data
33 * structures for details.
34 */
35
36 #include "cfm.h"
37 #include "classifier.h"
38 #include "guarded-list.h"
39 #include "heap.h"
40 #include "hindex.h"
41 #include "object-collection.h"
42 #include "ofproto/ofproto.h"
43 #include "openvswitch/list.h"
44 #include "openvswitch/ofp-actions.h"
45 #include "openvswitch/ofp-util.h"
46 #include "openvswitch/ofp-errors.h"
47 #include "ovs-atomic.h"
48 #include "ovs-rcu.h"
49 #include "ovs-thread.h"
50 #include "openvswitch/shash.h"
51 #include "simap.h"
52 #include "timeval.h"
53 #include "tun-metadata.h"
54 #include "versions.h"
55 #include "vl-mff-map.h"
56
57 struct match;
58 struct ofputil_flow_mod;
59 struct bfd_cfg;
60 struct meter;
61 struct ofoperation;
62 struct ofproto_packet_out;
63 struct smap;
64
65 extern struct ovs_mutex ofproto_mutex;
66
67 /* An OpenFlow switch.
68 *
69 * With few exceptions, ofproto implementations may look at these fields but
70 * should not modify them. */
71 struct ofproto {
72 struct hmap_node hmap_node; /* In global 'all_ofprotos' hmap. */
73 const struct ofproto_class *ofproto_class;
74 char *type; /* Datapath type. */
75 char *name; /* Datapath name. */
76
77 /* Settings. */
78 uint64_t fallback_dpid; /* Datapath ID if no better choice found. */
79 uint64_t datapath_id; /* Datapath ID. */
80 bool forward_bpdu; /* Option to allow forwarding of BPDU frames
81 * when NORMAL action is invoked. */
82 char *mfr_desc; /* Manufacturer (NULL for default). */
83 char *hw_desc; /* Hardware (NULL for default). */
84 char *sw_desc; /* Software version (NULL for default). */
85 char *serial_desc; /* Serial number (NULL for default). */
86 char *dp_desc; /* Datapath description (NULL for default). */
87 enum ofputil_frag_handling frag_handling;
88
89 /* Datapath. */
90 struct hmap ports; /* Contains "struct ofport"s. */
91 struct shash port_by_name;
92 struct simap ofp_requests; /* OpenFlow port number requests. */
93 uint16_t alloc_port_no; /* Last allocated OpenFlow port number. */
94 uint16_t max_ports; /* Max possible OpenFlow port num, plus one. */
95 struct hmap ofport_usage; /* Map ofport to last used time. */
96 uint64_t change_seq; /* Change sequence for netdev status. */
97
98 /* Flow tables. */
99 long long int eviction_group_timer; /* For rate limited reheapification. */
100 struct oftable *tables;
101 int n_tables;
102 ovs_version_t tables_version; /* Controls which rules are visible to
103 * table lookups. */
104
105 /* Rules indexed on their cookie values, in all flow tables. */
106 struct hindex cookies OVS_GUARDED_BY(ofproto_mutex);
107 struct hmap learned_cookies OVS_GUARDED_BY(ofproto_mutex);
108
109 /* List of expirable flows, in all flow tables. */
110 struct ovs_list expirable OVS_GUARDED_BY(ofproto_mutex);
111
112 /* Meter table. */
113 struct ofputil_meter_features meter_features;
114 struct hmap meters; /* uint32_t indexed 'struct meter *'. */
115 uint32_t slowpath_meter_id; /* Datapath slowpath meter. UINT32_MAX
116 if not defined. */
117 uint32_t controller_meter_id; /* Datapath controller meter. UINT32_MAX
118 if not defined. */
119
120 /* OpenFlow connections. */
121 struct connmgr *connmgr;
122
123 int min_mtu; /* Current MTU of non-internal ports. */
124
125 /* Groups. */
126 struct cmap groups; /* Contains "struct ofgroup"s. */
127 uint32_t n_groups[4] OVS_GUARDED; /* # of existing groups of each type. */
128 struct ofputil_group_features ogf;
129
130 /* Tunnel TLV mapping table. */
131 OVSRCU_TYPE(struct tun_table *) metadata_tab;
132
133 /* Variable length mf_field mapping. Stores all configured variable length
134 * meta-flow fields (struct mf_field) in a switch. */
135 struct vl_mff_map vl_mff_map;
136 };
137
138 void ofproto_init_tables(struct ofproto *, int n_tables);
139 void ofproto_init_max_ports(struct ofproto *, uint16_t max_ports);
140
141 struct ofproto *ofproto_lookup(const char *name);
142 struct ofport *ofproto_get_port(const struct ofproto *, ofp_port_t ofp_port);
143
144 /* An OpenFlow port within a "struct ofproto".
145 *
146 * The port's name is netdev_get_name(port->netdev).
147 *
148 * With few exceptions, ofproto implementations may look at these fields but
149 * should not modify them. */
150 struct ofport {
151 struct hmap_node hmap_node; /* In struct ofproto's "ports" hmap. */
152 struct ofproto *ofproto; /* The ofproto that contains this port. */
153 struct netdev *netdev;
154 struct ofputil_phy_port pp;
155 ofp_port_t ofp_port; /* OpenFlow port number. */
156 uint64_t change_seq;
157 long long int created; /* Time created, in msec. */
158 int mtu;
159 };
160
161 void ofproto_port_set_state(struct ofport *, enum ofputil_port_state);
162
163 /* OpenFlow table flags:
164 *
165 * - "Hidden" tables are not included in OpenFlow operations that operate on
166 * "all tables". For example, a request for flow stats on all tables will
167 * omit flows in hidden tables, table stats requests will omit the table
168 * entirely, and the switch features reply will not count the hidden table.
169 *
170 * However, operations that specifically name the particular table still
171 * operate on it. For example, flow_mods and flow stats requests on a
172 * hidden table work.
173 *
174 * To avoid gaps in table IDs (which have unclear validity in OpenFlow),
175 * hidden tables must be the highest-numbered tables that a provider
176 * implements.
177 *
178 * - "Read-only" tables can't be changed through OpenFlow operations. (At
179 * the moment all flow table operations go effectively through OpenFlow, so
180 * this means that read-only tables can't be changed at all after the
181 * read-only flag is set.)
182 *
183 * The generic ofproto layer never sets these flags. An ofproto provider can
184 * set them if it is appropriate.
185 */
186 enum oftable_flags {
187 OFTABLE_HIDDEN = 1 << 0, /* Hide from most OpenFlow operations. */
188 OFTABLE_READONLY = 1 << 1 /* Don't allow OpenFlow controller to change
189 this table. */
190 };
191
192 /* A flow table within a "struct ofproto".
193 *
194 *
195 * Thread-safety
196 * =============
197 *
198 * Adding or removing rules requires holding ofproto_mutex.
199 *
200 * Rules in 'cls' are RCU protected. For extended access to a rule, try
201 * incrementing its ref_count with ofproto_rule_try_ref(), or
202 * ofproto_rule_ref(), if the rule is still known to be in 'cls'. A rule
203 * will be freed using ovsrcu_postpone() once its 'ref_count' reaches zero.
204 *
205 * Modifying a rule requires the rule's own mutex.
206 *
207 * Freeing a rule requires ofproto_mutex. After removing the rule from the
208 * classifier, release a ref_count from the rule ('cls''s reference to the
209 * rule).
210 *
211 * Refer to the thread-safety notes on struct rule for more information.*/
212 struct oftable {
213 enum oftable_flags flags;
214 struct classifier cls; /* Contains "struct rule"s. */
215 char *name; /* Table name exposed via OpenFlow, or NULL. */
216
217 /* Maximum number of flows or UINT_MAX if there is no limit besides any
218 * limit imposed by resource limitations. */
219 unsigned int max_flows;
220 /* Current number of flows, not counting temporary duplicates nor deferred
221 * deletions. */
222 unsigned int n_flows;
223
224 /* These members determine the handling of an attempt to add a flow that
225 * would cause the table to have more than 'max_flows' flows.
226 *
227 * If 'eviction_fields' is NULL, overflows will be rejected with an error.
228 *
229 * If 'eviction_fields' is nonnull (regardless of whether n_eviction_fields
230 * is nonzero), an overflow will cause a flow to be removed. The flow to
231 * be removed is chosen to give fairness among groups distinguished by
232 * different values for the subfields within 'groups'. */
233 struct mf_subfield *eviction_fields;
234 size_t n_eviction_fields;
235
236 /* Eviction groups.
237 *
238 * When a flow is added that would cause the table to have more than
239 * 'max_flows' flows, and 'eviction_fields' is nonnull, these groups are
240 * used to decide which rule to evict: the rule is chosen from the eviction
241 * group that contains the greatest number of rules.*/
242 uint32_t eviction_group_id_basis;
243 struct hmap eviction_groups_by_id;
244 struct heap eviction_groups_by_size;
245
246 /* Flow table miss handling configuration. */
247 ATOMIC(enum ofputil_table_miss) miss_config;
248
249 /* Eviction is enabled if either the client (vswitchd) enables it or an
250 * OpenFlow controller enables it; thus, a nonzero value indicates that
251 * eviction is enabled. */
252 #define EVICTION_CLIENT (1 << 0) /* Set to 1 if client enables eviction. */
253 #define EVICTION_OPENFLOW (1 << 1) /* Set to 1 if OpenFlow enables eviction. */
254 unsigned int eviction;
255
256 /* If zero, vacancy events are disabled. If nonzero, this is the type of
257 vacancy event that is enabled: either OFPTR_VACANCY_DOWN or
258 OFPTR_VACANCY_UP. Only one type of vacancy event can be enabled at a
259 time. */
260 enum ofp14_table_reason vacancy_event;
261
262 /* Non-zero values for vacancy_up and vacancy_down indicates that vacancy
263 * is enabled by table-mod, else these values are set to zero when
264 * vacancy is disabled */
265 uint8_t vacancy_down; /* Vacancy threshold when space decreases (%). */
266 uint8_t vacancy_up; /* Vacancy threshold when space increases (%). */
267
268 atomic_ulong n_matched;
269 atomic_ulong n_missed;
270 };
271
272 /* Assigns TABLE to each oftable, in turn, in OFPROTO.
273 *
274 * All parameters are evaluated multiple times. */
275 #define OFPROTO_FOR_EACH_TABLE(TABLE, OFPROTO) \
276 for ((TABLE) = (OFPROTO)->tables; \
277 (TABLE) < &(OFPROTO)->tables[(OFPROTO)->n_tables]; \
278 (TABLE)++)
279
280 /* An OpenFlow flow within a "struct ofproto".
281 *
282 * With few exceptions, ofproto implementations may look at these fields but
283 * should not modify them.
284 *
285 *
286 * Thread-safety
287 * =============
288 *
289 * Except near the beginning or ending of its lifespan, rule 'rule' belongs to
290 * the classifier rule->ofproto->tables[rule->table_id].cls. The text below
291 * calls this classifier 'cls'.
292 *
293 * Motivation
294 * ----------
295 *
296 * The thread safety rules described here for "struct rule" are motivated by
297 * two goals:
298 *
299 * - Prevent threads that read members of "struct rule" from reading bad
300 * data due to changes by some thread concurrently modifying those
301 * members.
302 *
303 * - Prevent two threads making changes to members of a given "struct rule"
304 * from interfering with each other.
305 *
306 *
307 * Rules
308 * -----
309 *
310 * A rule 'rule' may be accessed without a risk of being freed by a thread
311 * until the thread quiesces (i.e., rules are RCU protected and destructed
312 * using ovsrcu_postpone()). Code that needs to hold onto a rule for a
313 * while should increment 'rule->ref_count' either with ofproto_rule_ref()
314 * (if 'ofproto_mutex' is held), or with ofproto_rule_try_ref() (when some
315 * other thread might remove the rule from 'cls'). ofproto_rule_try_ref()
316 * will fail if the rule has already been scheduled for destruction.
317 *
318 * 'rule->ref_count' protects 'rule' from being freed. It doesn't protect the
319 * rule from being deleted from 'cls' (that's 'ofproto_mutex') and it doesn't
320 * protect members of 'rule' from modification (that's 'rule->mutex').
321 *
322 * 'rule->mutex' protects the members of 'rule' from modification. It doesn't
323 * protect the rule from being deleted from 'cls' (that's 'ofproto_mutex') and
324 * it doesn't prevent the rule from being freed (that's 'rule->ref_count').
325 *
326 * Regarding thread safety, the members of a rule fall into the following
327 * categories:
328 *
329 * - Immutable. These members are marked 'const'.
330 *
331 * - Members that may be safely read or written only by code holding
332 * ofproto_mutex. These are marked OVS_GUARDED_BY(ofproto_mutex).
333 *
334 * - Members that may be safely read only by code holding ofproto_mutex or
335 * 'rule->mutex', and safely written only by coding holding ofproto_mutex
336 * AND 'rule->mutex'. These are marked OVS_GUARDED.
337 */
338 enum OVS_PACKED_ENUM rule_state {
339 RULE_INITIALIZED, /* Rule has been initialized, but not inserted to the
340 * ofproto data structures. Versioning makes sure the
341 * rule is not visible to lookups by other threads, even
342 * if the rule is added to a classifier. */
343 RULE_INSERTED, /* Rule has been inserted to ofproto data structures and
344 * may be visible to lookups by other threads. */
345 RULE_REMOVED, /* Rule has been removed from ofproto data structures,
346 * and may still be visible to lookups by other threads
347 * until they quiesce, after which the rule will be
348 * removed from the classifier as well. */
349 };
350
351 struct rule {
352 /* Where this rule resides in an OpenFlow switch.
353 *
354 * These are immutable once the rule is constructed, hence 'const'. */
355 struct ofproto *const ofproto; /* The ofproto that contains this rule. */
356 const struct cls_rule cr; /* In owning ofproto's classifier. */
357 const uint8_t table_id; /* Index in ofproto's 'tables' array. */
358
359 enum rule_state state;
360
361 /* Protects members marked OVS_GUARDED.
362 * Readers only need to hold this mutex.
363 * Writers must hold both this mutex AND ofproto_mutex.
364 * By implication writers can read *without* taking this mutex while they
365 * hold ofproto_mutex. */
366 struct ovs_mutex mutex OVS_ACQ_AFTER(ofproto_mutex);
367
368 /* Number of references.
369 * The classifier owns one reference.
370 * Any thread trying to keep a rule from being freed should hold its own
371 * reference. */
372 struct ovs_refcount ref_count;
373
374 /* A "flow cookie" is the OpenFlow name for a 64-bit value associated with
375 * a flow. */
376 const ovs_be64 flow_cookie; /* Immutable once rule is constructed. */
377 struct hindex_node cookie_node OVS_GUARDED_BY(ofproto_mutex);
378
379 enum ofputil_flow_mod_flags flags OVS_GUARDED;
380
381 /* Timeouts. */
382 uint16_t hard_timeout OVS_GUARDED; /* In seconds from ->modified. */
383 uint16_t idle_timeout OVS_GUARDED; /* In seconds from ->used. */
384
385 /* Eviction precedence. */
386 const uint16_t importance;
387
388 /* Removal reason for sending flow removed message.
389 * Used only if 'flags' has OFPUTIL_FF_SEND_FLOW_REM set and if the
390 * value is not OVS_OFPRR_NONE. */
391 uint8_t removed_reason;
392
393 /* Eviction groups (see comment on struct eviction_group for explanation) .
394 *
395 * 'eviction_group' is this rule's eviction group, or NULL if it is not in
396 * any eviction group. When 'eviction_group' is nonnull, 'evg_node' is in
397 * the ->eviction_group->rules hmap. */
398 struct eviction_group *eviction_group OVS_GUARDED_BY(ofproto_mutex);
399 struct heap_node evg_node OVS_GUARDED_BY(ofproto_mutex);
400
401 /* OpenFlow actions. See struct rule_actions for more thread-safety
402 * notes. */
403 const struct rule_actions * const actions;
404
405 /* In owning meter's 'rules' list. An empty list if there is no meter. */
406 struct ovs_list meter_list_node OVS_GUARDED_BY(ofproto_mutex);
407
408 /* Flow monitors (e.g. for NXST_FLOW_MONITOR, related to struct ofmonitor).
409 *
410 * 'add_seqno' is the sequence number when this rule was created.
411 * 'modify_seqno' is the sequence number when this rule was last modified.
412 * See 'monitor_seqno' in connmgr.c for more information. */
413 enum nx_flow_monitor_flags monitor_flags OVS_GUARDED_BY(ofproto_mutex);
414 uint64_t add_seqno OVS_GUARDED_BY(ofproto_mutex);
415 uint64_t modify_seqno OVS_GUARDED_BY(ofproto_mutex);
416
417 /* Optimisation for flow expiry. In ofproto's 'expirable' list if this
418 * rule is expirable, otherwise empty. */
419 struct ovs_list expirable OVS_GUARDED_BY(ofproto_mutex);
420
421 /* Times. Last so that they are more likely close to the stats managed
422 * by the provider. */
423 long long int created OVS_GUARDED; /* Creation time. */
424
425 /* Must hold 'mutex' for both read/write, 'ofproto_mutex' not needed. */
426 long long int modified OVS_GUARDED; /* Time of last modification. */
427
428 /* 1-bit for each present TLV in flow match / action. */
429 uint64_t match_tlv_bitmap;
430 uint64_t ofpacts_tlv_bitmap;
431 };
432
433 void ofproto_rule_ref(struct rule *);
434 bool ofproto_rule_try_ref(struct rule *);
435 void ofproto_rule_unref(struct rule *);
436
437 static inline const struct rule_actions * rule_get_actions(const struct rule *);
438 static inline bool rule_is_table_miss(const struct rule *);
439 static inline bool rule_is_hidden(const struct rule *);
440
441 /* A set of actions within a "struct rule".
442 *
443 *
444 * Thread-safety
445 * =============
446 *
447 * A struct rule_actions may be accessed without a risk of being freed by
448 * code that holds 'rule->mutex' (where 'rule' is the rule for which
449 * 'rule->actions == actions') or during the RCU active period.
450 *
451 * All members are immutable: they do not change during the rule's
452 * lifetime. */
453 struct rule_actions {
454 /* Flags.
455 *
456 * 'has_meter' is true if 'ofpacts' contains an OFPACT_METER action.
457 *
458 * 'has_learn_with_delete' is true if 'ofpacts' contains an OFPACT_LEARN
459 * action whose flags include NX_LEARN_F_DELETE_LEARNED. */
460 bool has_meter;
461 bool has_learn_with_delete;
462 bool has_groups;
463
464 /* Actions. */
465 uint32_t ofpacts_len; /* Size of 'ofpacts', in bytes. */
466 struct ofpact ofpacts[]; /* Sequence of "struct ofpacts". */
467 };
468 BUILD_ASSERT_DECL(offsetof(struct rule_actions, ofpacts) % OFPACT_ALIGNTO == 0);
469
470 const struct rule_actions *rule_actions_create(const struct ofpact *, size_t);
471 void rule_actions_destroy(const struct rule_actions *);
472 bool ofproto_rule_has_out_port(const struct rule *, ofp_port_t port)
473 OVS_REQUIRES(ofproto_mutex);
474
475 #define DECL_OFPROTO_COLLECTION(TYPE, NAME) \
476 DECL_OBJECT_COLLECTION(TYPE, NAME) \
477 static inline void NAME##_collection_ref(struct NAME##_collection *coll) \
478 { \
479 for (size_t i = 0; i < coll->collection.n; i++) { \
480 ofproto_##NAME##_ref((TYPE)coll->collection.objs[i]); \
481 } \
482 } \
483 \
484 static inline void NAME##_collection_unref(struct NAME##_collection *coll) \
485 { \
486 for (size_t i = 0; i < coll->collection.n; i++) { \
487 ofproto_##NAME##_unref((TYPE)coll->collection.objs[i]); \
488 } \
489 }
490
491 DECL_OFPROTO_COLLECTION (struct rule *, rule)
492
493 #define RULE_COLLECTION_FOR_EACH(RULE, RULES) \
494 for (size_t i__ = 0; \
495 i__ < rule_collection_n(RULES) \
496 ? (RULE = rule_collection_rules(RULES)[i__]) != NULL : false; \
497 i__++)
498
499 /* Pairwise iteration through two rule collections that must be of the same
500 * size. */
501 #define RULE_COLLECTIONS_FOR_EACH(RULE1, RULE2, RULES1, RULES2) \
502 for (size_t i__ = 0; \
503 i__ < rule_collection_n(RULES1) \
504 ? ((RULE1 = rule_collection_rules(RULES1)[i__]), \
505 (RULE2 = rule_collection_rules(RULES2)[i__]) != NULL) \
506 : false; \
507 i__++)
508
509 /* Limits the number of flows allowed in the datapath. Only affects the
510 * ofproto-dpif implementation. */
511 extern unsigned ofproto_flow_limit;
512
513 /* Maximum idle time (in ms) for flows to be cached in the datapath.
514 * Revalidators may expire flows more quickly than the configured value based
515 * on system load and other factors. This variable is subject to change. */
516 extern unsigned ofproto_max_idle;
517
518 /* Number of upcall handler and revalidator threads. Only affects the
519 * ofproto-dpif implementation. */
520 extern size_t n_handlers, n_revalidators;
521
522 static inline struct rule *rule_from_cls_rule(const struct cls_rule *);
523
524 void ofproto_rule_expire(struct rule *rule, uint8_t reason)
525 OVS_REQUIRES(ofproto_mutex);
526 void ofproto_rule_delete(struct ofproto *, struct rule *)
527 OVS_EXCLUDED(ofproto_mutex);
528 void ofproto_rule_reduce_timeouts__(struct rule *rule, uint16_t idle_timeout,
529 uint16_t hard_timeout)
530 OVS_REQUIRES(ofproto_mutex) OVS_EXCLUDED(rule->mutex);
531 void ofproto_rule_reduce_timeouts(struct rule *rule, uint16_t idle_timeout,
532 uint16_t hard_timeout)
533 OVS_EXCLUDED(ofproto_mutex);
534
535 /* A group within a "struct ofproto", RCU-protected.
536 *
537 * With few exceptions, ofproto implementations may look at these fields but
538 * should not modify them. */
539 struct ofgroup {
540 struct cmap_node cmap_node; /* In ofproto's "groups" cmap. */
541
542 /* Group versioning. */
543 struct versions versions;
544
545 /* Number of references.
546 *
547 * This is needed to keep track of references to the group in the xlate
548 * module.
549 *
550 * If the main thread removes the group from an ofproto, we need to
551 * guarantee that the group remains accessible to users of
552 * xlate_group_actions and the xlate_cache, as the xlate_cache will not be
553 * cleaned up until the corresponding datapath flows are revalidated. */
554 struct ovs_refcount ref_count;
555
556 /* No lock is needed to protect the fields below since they are not
557 * modified after construction. */
558 struct ofproto * const ofproto; /* The ofproto that contains this group. */
559 const uint32_t group_id;
560 const enum ofp11_group_type type; /* One of OFPGT_*. */
561 bool being_deleted; /* Group removal has begun. */
562
563 const long long int created; /* Creation time. */
564 const long long int modified; /* Time of last modification. */
565
566 const struct ovs_list buckets; /* Contains "struct ofputil_bucket"s. */
567 const uint32_t n_buckets;
568
569 const struct ofputil_group_props props;
570
571 struct rule_collection rules OVS_GUARDED; /* Referring rules. */
572 };
573
574 struct ofgroup *ofproto_group_lookup(const struct ofproto *ofproto,
575 uint32_t group_id, ovs_version_t version,
576 bool take_ref);
577
578 void ofproto_group_ref(struct ofgroup *);
579 bool ofproto_group_try_ref(struct ofgroup *);
580 void ofproto_group_unref(struct ofgroup *);
581
582 void ofproto_group_delete_all(struct ofproto *)
583 OVS_EXCLUDED(ofproto_mutex);
584
585 DECL_OFPROTO_COLLECTION (struct ofgroup *, group)
586
587 #define GROUP_COLLECTION_FOR_EACH(GROUP, GROUPS) \
588 for (size_t i__ = 0; \
589 i__ < group_collection_n(GROUPS) \
590 ? (GROUP = group_collection_groups(GROUPS)[i__]) != NULL: false; \
591 i__++)
592
593 /* Pairwise iteration through two group collections that must be of the same
594 * size. */
595 #define GROUP_COLLECTIONS_FOR_EACH(GROUP1, GROUP2, GROUPS1, GROUPS2) \
596 for (size_t i__ = 0; \
597 i__ < group_collection_n(GROUPS1) \
598 ? ((GROUP1 = group_collection_groups(GROUPS1)[i__]), \
599 (GROUP2 = group_collection_groups(GROUPS2)[i__]) != NULL) \
600 : false; \
601 i__++)
602
603 /* ofproto class structure, to be defined by each ofproto implementation.
604 *
605 *
606 * Data Structures
607 * ===============
608 *
609 * These functions work primarily with four different kinds of data
610 * structures:
611 *
612 * - "struct ofproto", which represents an OpenFlow switch.
613 *
614 * - "struct ofport", which represents a port within an ofproto.
615 *
616 * - "struct rule", which represents an OpenFlow flow within an ofproto.
617 *
618 * - "struct ofgroup", which represents an OpenFlow 1.1+ group within an
619 * ofproto.
620 *
621 * Each of these data structures contains all of the implementation-independent
622 * generic state for the respective concept, called the "base" state. None of
623 * them contains any extra space for ofproto implementations to use. Instead,
624 * each implementation is expected to declare its own data structure that
625 * contains an instance of the generic data structure plus additional
626 * implementation-specific members, called the "derived" state. The
627 * implementation can use casts or (preferably) the CONTAINER_OF macro to
628 * obtain access to derived state given only a pointer to the embedded generic
629 * data structure.
630 *
631 *
632 * Life Cycle
633 * ==========
634 *
635 * Four stylized functions accompany each of these data structures:
636 *
637 * "alloc" "construct" "destruct" "dealloc"
638 * ------------ ---------------- --------------- --------------
639 * ofproto ->alloc ->construct ->destruct ->dealloc
640 * ofport ->port_alloc ->port_construct ->port_destruct ->port_dealloc
641 * rule ->rule_alloc ->rule_construct ->rule_destruct ->rule_dealloc
642 * group ->group_alloc ->group_construct ->group_destruct ->group_dealloc
643 *
644 * "ofproto", "ofport", and "group" have this exact life cycle. The "rule"
645 * data structure also follow this life cycle with some additional elaborations
646 * described under "Rule Life Cycle" below.
647 *
648 * Any instance of a given data structure goes through the following life
649 * cycle:
650 *
651 * 1. The client calls the "alloc" function to obtain raw memory. If "alloc"
652 * fails, skip all the other steps.
653 *
654 * 2. The client initializes all of the data structure's base state. If this
655 * fails, skip to step 7.
656 *
657 * 3. The client calls the "construct" function. The implementation
658 * initializes derived state. It may refer to the already-initialized
659 * base state. If "construct" fails, skip to step 6.
660 *
661 * 4. The data structure is now initialized and in use.
662 *
663 * 5. When the data structure is no longer needed, the client calls the
664 * "destruct" function. The implementation uninitializes derived state.
665 * The base state has not been uninitialized yet, so the implementation
666 * may still refer to it.
667 *
668 * 6. The client uninitializes all of the data structure's base state.
669 *
670 * 7. The client calls the "dealloc" to free the raw memory. The
671 * implementation must not refer to base or derived state in the data
672 * structure, because it has already been uninitialized.
673 *
674 * Each "alloc" function allocates and returns a new instance of the respective
675 * data structure. The "alloc" function is not given any information about the
676 * use of the new data structure, so it cannot perform much initialization.
677 * Its purpose is just to ensure that the new data structure has enough room
678 * for base and derived state. It may return a null pointer if memory is not
679 * available, in which case none of the other functions is called.
680 *
681 * Each "construct" function initializes derived state in its respective data
682 * structure. When "construct" is called, all of the base state has already
683 * been initialized, so the "construct" function may refer to it. The
684 * "construct" function is allowed to fail, in which case the client calls the
685 * "dealloc" function (but not the "destruct" function).
686 *
687 * Each "destruct" function uninitializes and frees derived state in its
688 * respective data structure. When "destruct" is called, the base state has
689 * not yet been uninitialized, so the "destruct" function may refer to it. The
690 * "destruct" function is not allowed to fail.
691 *
692 * Each "dealloc" function frees raw memory that was allocated by the
693 * "alloc" function. The memory's base and derived members might not have ever
694 * been initialized (but if "construct" returned successfully, then it has been
695 * "destruct"ed already). The "dealloc" function is not allowed to fail.
696 *
697 *
698 * Conventions
699 * ===========
700 *
701 * Most of these functions return 0 if they are successful or a positive error
702 * code on failure. Depending on the function, valid error codes are either
703 * errno values or OFPERR_* OpenFlow error codes.
704 *
705 * Most of these functions are expected to execute synchronously, that is, to
706 * block as necessary to obtain a result. Thus, these functions may return
707 * EAGAIN (or EWOULDBLOCK or EINPROGRESS) only where the function descriptions
708 * explicitly say those errors are a possibility. We may relax this
709 * requirement in the future if and when we encounter performance problems. */
710 struct ofproto_class {
711 /* ## ----------------- ## */
712 /* ## Factory Functions ## */
713 /* ## ----------------- ## */
714
715 /* Initializes provider. The caller may pass in 'iface_hints',
716 * which contains an shash of "struct iface_hint" elements indexed
717 * by the interface's name. The provider may use these hints to
718 * describe the startup configuration in order to reinitialize its
719 * state. The caller owns the provided data, so a provider must
720 * make copies of anything required. An ofproto provider must
721 * remove any existing state that is not described by the hint, and
722 * may choose to remove it all. */
723 void (*init)(const struct shash *iface_hints);
724
725 /* Enumerates the types of all supported ofproto types into 'types'. The
726 * caller has already initialized 'types'. The implementation should add
727 * its own types to 'types' but not remove any existing ones, because other
728 * ofproto classes might already have added names to it. */
729 void (*enumerate_types)(struct sset *types);
730
731 /* Enumerates the names of all existing datapath of the specified 'type'
732 * into 'names' 'all_dps'. The caller has already initialized 'names' as
733 * an empty sset.
734 *
735 * 'type' is one of the types enumerated by ->enumerate_types().
736 *
737 * Returns 0 if successful, otherwise a positive errno value.
738 */
739 int (*enumerate_names)(const char *type, struct sset *names);
740
741 /* Deletes the datapath with the specified 'type' and 'name'. The caller
742 * should have closed any open ofproto with this 'type' and 'name'; this
743 * function is allowed to fail if that is not the case.
744 *
745 * 'type' is one of the types enumerated by ->enumerate_types().
746 * 'name' is one of the names enumerated by ->enumerate_names() for 'type'.
747 *
748 * Returns 0 if successful, otherwise a positive errno value.
749 */
750 int (*del)(const char *type, const char *name);
751
752 /* Returns the type to pass to netdev_open() when a datapath of type
753 * 'datapath_type' has a port of type 'port_type', for a few special
754 * cases when a netdev type differs from a port type. For example,
755 * when using the userspace datapath, a port of type "internal"
756 * needs to be opened as "tap".
757 *
758 * Returns either 'type' itself or a string literal, which must not
759 * be freed. */
760 const char *(*port_open_type)(const char *datapath_type,
761 const char *port_type);
762
763 /* ## ------------------------ ## */
764 /* ## Top-Level type Functions ## */
765 /* ## ------------------------ ## */
766
767 /* Performs any periodic activity required on ofprotos of type
768 * 'type'.
769 *
770 * An ofproto provider may implement it or not, depending on whether
771 * it needs type-level maintenance.
772 *
773 * Returns 0 if successful, otherwise a positive errno value. */
774 int (*type_run)(const char *type);
775
776 /* Causes the poll loop to wake up when a type 'type''s 'run'
777 * function needs to be called, e.g. by calling the timer or fd
778 * waiting functions in poll-loop.h.
779 *
780 * An ofproto provider may implement it or not, depending on whether
781 * it needs type-level maintenance. */
782 void (*type_wait)(const char *type);
783
784 /* ## --------------------------- ## */
785 /* ## Top-Level ofproto Functions ## */
786 /* ## --------------------------- ## */
787
788 /* Life-cycle functions for an "ofproto" (see "Life Cycle" above).
789 *
790 *
791 * Construction
792 * ============
793 *
794 * ->construct() should not modify any base members of the ofproto. The
795 * client will initialize the ofproto's 'ports' and 'tables' members after
796 * construction is complete.
797 *
798 * When ->construct() is called, the client does not yet know how many flow
799 * tables the datapath supports, so ofproto->n_tables will be 0 and
800 * ofproto->tables will be NULL. ->construct() should call
801 * ofproto_init_tables() to allocate and initialize ofproto->n_tables and
802 * ofproto->tables. Each flow table will be initially empty, so
803 * ->construct() should delete flows from the underlying datapath, if
804 * necessary, rather than populating the tables.
805 *
806 * If the ofproto knows the maximum port number that the datapath can have,
807 * then it can call ofproto_init_max_ports(). If it does so, then the
808 * client will ensure that the actions it allows to be used through
809 * OpenFlow do not refer to ports above that maximum number.
810 *
811 * Only one ofproto instance needs to be supported for any given datapath.
812 * If a datapath is already open as part of one "ofproto", then another
813 * attempt to "construct" the same datapath as part of another ofproto is
814 * allowed to fail with an error.
815 *
816 * ->construct() returns 0 if successful, otherwise a positive errno
817 * value.
818 *
819 *
820 * Destruction
821 * ===========
822 *
823 * ->destruct() must also destroy all remaining rules in the ofproto's
824 * tables, by passing each remaining rule to ofproto_rule_delete(), then
825 * destroy all remaining groups by calling ofproto_group_delete_all().
826 *
827 * The client will destroy the flow tables themselves after ->destruct()
828 * returns.
829 */
830 struct ofproto *(*alloc)(void);
831 int (*construct)(struct ofproto *ofproto);
832 void (*destruct)(struct ofproto *ofproto, bool del);
833 void (*dealloc)(struct ofproto *ofproto);
834
835 /* Performs any periodic activity required by 'ofproto'. It should:
836 *
837 * - Call connmgr_send_packet_in() for each received packet that missed
838 * in the OpenFlow flow table or that had a OFPP_CONTROLLER output
839 * action.
840 *
841 * - Call ofproto_rule_expire() for each OpenFlow flow that has reached
842 * its hard_timeout or idle_timeout, to expire the flow.
843 *
844 * Returns 0 if successful, otherwise a positive errno value. */
845 int (*run)(struct ofproto *ofproto);
846
847 /* Causes the poll loop to wake up when 'ofproto''s 'run' function needs to
848 * be called, e.g. by calling the timer or fd waiting functions in
849 * poll-loop.h. */
850 void (*wait)(struct ofproto *ofproto);
851
852 /* Adds some memory usage statistics for the implementation of 'ofproto'
853 * into 'usage', for use with memory_report().
854 *
855 * This function is optional. */
856 void (*get_memory_usage)(const struct ofproto *ofproto,
857 struct simap *usage);
858
859 /* Adds some memory usage statistics for the implementation of 'type'
860 * into 'usage', for use with memory_report().
861 *
862 * This function is optional. */
863 void (*type_get_memory_usage)(const char *type, struct simap *usage);
864
865 /* Every "struct rule" in 'ofproto' is about to be deleted, one by one.
866 * This function may prepare for that, for example by clearing state in
867 * advance. It should *not* actually delete any "struct rule"s from
868 * 'ofproto', only prepare for it.
869 *
870 * This function is optional; it's really just for optimization in case
871 * it's cheaper to delete all the flows from your hardware in a single pass
872 * than to do it one by one. */
873 void (*flush)(struct ofproto *ofproto);
874
875 /* Helper for the OpenFlow OFPT_TABLE_FEATURES request.
876 *
877 * The 'features' array contains 'ofproto->n_tables' elements. Each
878 * element is initialized as:
879 *
880 * - 'table_id' to the array index.
881 *
882 * - 'name' to "table#" where # is the table ID.
883 *
884 * - 'metadata_match' and 'metadata_write' to OVS_BE64_MAX.
885 *
886 * - 'config' to the table miss configuration.
887 *
888 * - 'max_entries' to 1,000,000.
889 *
890 * - Both 'nonmiss' and 'miss' to:
891 *
892 * * 'next' to all 1-bits for all later tables.
893 *
894 * * 'instructions' to all instructions.
895 *
896 * * 'write' and 'apply' both to:
897 *
898 * - 'ofpacts': All actions.
899 *
900 * - 'set_fields': All fields.
901 *
902 * - 'match', 'mask', and 'wildcard' to all fields.
903 *
904 * If 'stats' is nonnull, it also contains 'ofproto->n_tables' elements.
905 * Each element is initialized as:
906 *
907 * - 'table_id' to the array index.
908 *
909 * - 'active_count' to the 'n_flows' of struct ofproto for the table.
910 *
911 * - 'lookup_count' and 'matched_count' to 0.
912 *
913 * The implementation should update any members in each element for which
914 * it has better values:
915 *
916 * - Any member of 'features' to better describe the implementation's
917 * capabilities.
918 *
919 * - 'lookup_count' to the number of packets looked up in this flow table
920 * so far.
921 *
922 * - 'matched_count' to the number of packets looked up in this flow
923 * table so far that matched one of the flow entries.
924 */
925 void (*query_tables)(struct ofproto *ofproto,
926 struct ofputil_table_features *features,
927 struct ofputil_table_stats *stats);
928
929 /* Sets the current tables version the provider should use for classifier
930 * lookups. This must be called with a new version number after each set
931 * of flow table changes has been completed, so that datapath revalidation
932 * can be triggered. */
933 void (*set_tables_version)(struct ofproto *ofproto, ovs_version_t version);
934
935 /* ## ---------------- ## */
936 /* ## ofport Functions ## */
937 /* ## ---------------- ## */
938
939 /* Life-cycle functions for a "struct ofport" (see "Life Cycle" above).
940 *
941 * ->port_construct() should not modify any base members of the ofport.
942 * An ofproto implementation should use the 'ofp_port' member of
943 * "struct ofport" as the OpenFlow port number.
944 *
945 * ofports are managed by the base ofproto code. The ofproto
946 * implementation should only create and destroy them in response to calls
947 * to these functions. The base ofproto code will create and destroy
948 * ofports in the following situations:
949 *
950 * - Just after the ->construct() function is called, the base ofproto
951 * iterates over all of the implementation's ports, using
952 * ->port_dump_start() and related functions, and constructs an ofport
953 * for each dumped port.
954 *
955 * - If ->port_poll() reports that a specific port has changed, then the
956 * base ofproto will query that port with ->port_query_by_name() and
957 * construct or destruct ofports as necessary to reflect the updated
958 * set of ports.
959 *
960 * - If ->port_poll() returns ENOBUFS to report an unspecified port set
961 * change, then the base ofproto will iterate over all of the
962 * implementation's ports, in the same way as at ofproto
963 * initialization, and construct and destruct ofports to reflect all of
964 * the changes.
965 *
966 * - On graceful shutdown, the base ofproto code will destruct all
967 * the ports.
968 *
969 * ->port_construct() returns 0 if successful, otherwise a positive errno
970 * value.
971 *
972 *
973 * ->port_destruct()
974 * =================
975 *
976 * ->port_destruct() takes a 'del' parameter. If the provider implements
977 * the datapath itself (e.g. dpif-netdev, it can ignore 'del'. On the
978 * other hand, if the provider is an interface to an external datapath
979 * (e.g. to a kernel module that implement the datapath) then 'del' should
980 * influence destruction behavior in the following way:
981 *
982 * - If 'del' is true, it should remove the port from the underlying
983 * implementation. This is the common case.
984 *
985 * - If 'del' is false, it should leave the port in the underlying
986 * implementation. This is used when Open vSwitch is performing a
987 * graceful shutdown and ensures that, across Open vSwitch restarts,
988 * the underlying ports are not removed and recreated. That makes an
989 * important difference for, e.g., "internal" ports that have
990 * configured IP addresses; without this distinction, the IP address
991 * and other configured state for the port is lost.
992 */
993 struct ofport *(*port_alloc)(void);
994 int (*port_construct)(struct ofport *ofport);
995 void (*port_destruct)(struct ofport *ofport, bool del);
996 void (*port_dealloc)(struct ofport *ofport);
997
998 /* Called after 'ofport->netdev' is replaced by a new netdev object. If
999 * the ofproto implementation uses the ofport's netdev internally, then it
1000 * should switch to using the new one. The old one has been closed.
1001 *
1002 * An ofproto implementation that doesn't need to do anything in this
1003 * function may use a null pointer. */
1004 void (*port_modified)(struct ofport *ofport);
1005
1006 /* Called after an OpenFlow request changes a port's configuration.
1007 * 'ofport->pp.config' contains the new configuration. 'old_config'
1008 * contains the previous configuration.
1009 *
1010 * The caller implements OFPUTIL_PC_PORT_DOWN using netdev functions to
1011 * turn NETDEV_UP on and off, so this function doesn't have to do anything
1012 * for that bit (and it won't be called if that is the only bit that
1013 * changes). */
1014 void (*port_reconfigured)(struct ofport *ofport,
1015 enum ofputil_port_config old_config);
1016
1017 /* Looks up a port named 'devname' in 'ofproto'. On success, returns 0 and
1018 * initializes '*port' appropriately. Otherwise, returns a positive errno
1019 * value.
1020 *
1021 * The caller owns the data in 'port' and must free it with
1022 * ofproto_port_destroy() when it is no longer needed. */
1023 int (*port_query_by_name)(const struct ofproto *ofproto,
1024 const char *devname, struct ofproto_port *port);
1025
1026 /* Attempts to add 'netdev' as a port on 'ofproto'. Returns 0 if
1027 * successful, otherwise a positive errno value. The caller should
1028 * inform the implementation of the OpenFlow port through the
1029 * ->port_construct() method.
1030 *
1031 * It doesn't matter whether the new port will be returned by a later call
1032 * to ->port_poll(); the implementation may do whatever is more
1033 * convenient. */
1034 int (*port_add)(struct ofproto *ofproto, struct netdev *netdev);
1035
1036 /* Deletes port number 'ofp_port' from the datapath for 'ofproto'. Returns
1037 * 0 if successful, otherwise a positive errno value.
1038 *
1039 * It doesn't matter whether the new port will be returned by a later call
1040 * to ->port_poll(); the implementation may do whatever is more
1041 * convenient. */
1042 int (*port_del)(struct ofproto *ofproto, ofp_port_t ofp_port);
1043
1044 /* Refreshes datapath configuration of 'port'.
1045 * Returns 0 if successful, otherwise a positive errno value. */
1046 int (*port_set_config)(const struct ofport *port, const struct smap *cfg);
1047
1048 /* Get port stats */
1049 int (*port_get_stats)(const struct ofport *port,
1050 struct netdev_stats *stats);
1051
1052 /* Port iteration functions.
1053 *
1054 * The client might not be entirely in control of the ports within an
1055 * ofproto. Some hardware implementations, for example, might have a fixed
1056 * set of ports in a datapath. For this reason, the client needs a way to
1057 * iterate through all the ports that are actually in a datapath. These
1058 * functions provide that functionality.
1059 *
1060 * The 'state' pointer provides the implementation a place to
1061 * keep track of its position. Its format is opaque to the caller.
1062 *
1063 * The ofproto provider retains ownership of the data that it stores into
1064 * ->port_dump_next()'s 'port' argument. The data must remain valid until
1065 * at least the next call to ->port_dump_next() or ->port_dump_done() for
1066 * 'state'. The caller will not modify or free it.
1067 *
1068 * Details
1069 * =======
1070 *
1071 * ->port_dump_start() attempts to begin dumping the ports in 'ofproto'.
1072 * On success, it should return 0 and initialize '*statep' with any data
1073 * needed for iteration. On failure, returns a positive errno value, and
1074 * the client will not call ->port_dump_next() or ->port_dump_done().
1075 *
1076 * ->port_dump_next() attempts to retrieve another port from 'ofproto' for
1077 * 'state'. If there is another port, it should store the port's
1078 * information into 'port' and return 0. It should return EOF if all ports
1079 * have already been iterated. Otherwise, on error, it should return a
1080 * positive errno value. This function will not be called again once it
1081 * returns nonzero once for a given iteration (but the 'port_dump_done'
1082 * function will be called afterward).
1083 *
1084 * ->port_dump_done() allows the implementation to release resources used
1085 * for iteration. The caller might decide to stop iteration in the middle
1086 * by calling this function before ->port_dump_next() returns nonzero.
1087 *
1088 * Usage Example
1089 * =============
1090 *
1091 * int error;
1092 * void *state;
1093 *
1094 * error = ofproto->ofproto_class->port_dump_start(ofproto, &state);
1095 * if (!error) {
1096 * for (;;) {
1097 * struct ofproto_port port;
1098 *
1099 * error = ofproto->ofproto_class->port_dump_next(
1100 * ofproto, state, &port);
1101 * if (error) {
1102 * break;
1103 * }
1104 * // Do something with 'port' here (without modifying or freeing
1105 * // any of its data).
1106 * }
1107 * ofproto->ofproto_class->port_dump_done(ofproto, state);
1108 * }
1109 * // 'error' is now EOF (success) or a positive errno value (failure).
1110 */
1111 int (*port_dump_start)(const struct ofproto *ofproto, void **statep);
1112 int (*port_dump_next)(const struct ofproto *ofproto, void *state,
1113 struct ofproto_port *port);
1114 int (*port_dump_done)(const struct ofproto *ofproto, void *state);
1115
1116 /* Polls for changes in the set of ports in 'ofproto'. If the set of ports
1117 * in 'ofproto' has changed, then this function should do one of the
1118 * following:
1119 *
1120 * - Preferably: store the name of the device that was added to or deleted
1121 * from 'ofproto' in '*devnamep' and return 0. The caller is responsible
1122 * for freeing '*devnamep' (with free()) when it no longer needs it.
1123 *
1124 * - Alternatively: return ENOBUFS, without indicating the device that was
1125 * added or deleted.
1126 *
1127 * Occasional 'false positives', in which the function returns 0 while
1128 * indicating a device that was not actually added or deleted or returns
1129 * ENOBUFS without any change, are acceptable.
1130 *
1131 * The purpose of 'port_poll' is to let 'ofproto' know about changes made
1132 * externally to the 'ofproto' object, e.g. by a system administrator via
1133 * ovs-dpctl. Therefore, it's OK, and even preferable, for port_poll() to
1134 * not report changes made through calls to 'port_add' or 'port_del' on the
1135 * same 'ofproto' object. (But it's OK for it to report them too, just
1136 * slightly less efficient.)
1137 *
1138 * If the set of ports in 'ofproto' has not changed, returns EAGAIN. May
1139 * also return other positive errno values to indicate that something has
1140 * gone wrong.
1141 *
1142 * If the set of ports in a datapath is fixed, or if the only way that the
1143 * set of ports in a datapath can change is through ->port_add() and
1144 * ->port_del(), then this function may be a null pointer.
1145 */
1146 int (*port_poll)(const struct ofproto *ofproto, char **devnamep);
1147
1148 /* Arranges for the poll loop to wake up when ->port_poll() will return a
1149 * value other than EAGAIN.
1150 *
1151 * If the set of ports in a datapath is fixed, or if the only way that the
1152 * set of ports in a datapath can change is through ->port_add() and
1153 * ->port_del(), or if the poll loop will always wake up anyway when
1154 * ->port_poll() will return a value other than EAGAIN, then this function
1155 * may be a null pointer.
1156 */
1157 void (*port_poll_wait)(const struct ofproto *ofproto);
1158
1159 /* Checks the status of LACP negotiation for 'port'. Returns 1 if LACP
1160 * partner information for 'port' is up-to-date, 0 if LACP partner
1161 * information is not current (generally indicating a connectivity
1162 * problem), or -1 if LACP is not enabled on 'port'.
1163 *
1164 * This function may be a null pointer if the ofproto implementation does
1165 * not support LACP.
1166 */
1167 int (*port_is_lacp_current)(const struct ofport *port);
1168
1169 /* Get LACP port stats. Returns -1 if LACP is not enabled on 'port'.
1170 *
1171 * This function may be a null pointer if the ofproto implementation does
1172 * not support LACP.
1173 */
1174 int (*port_get_lacp_stats)(const struct ofport *port,
1175 struct lacp_slave_stats *stats);
1176
1177 /* ## ----------------------- ## */
1178 /* ## OpenFlow Rule Functions ## */
1179 /* ## ----------------------- ## */
1180
1181 /* Chooses an appropriate table for 'match' within 'ofproto'. On
1182 * success, stores the table ID into '*table_idp' and returns 0. On
1183 * failure, returns an OpenFlow error code.
1184 *
1185 * The choice of table should be a function of 'match' and 'ofproto''s
1186 * datapath capabilities. It should not depend on the flows already in
1187 * 'ofproto''s flow tables. Failure implies that an OpenFlow rule with
1188 * 'match' as its matching condition can never be inserted into 'ofproto',
1189 * even starting from an empty flow table.
1190 *
1191 * If multiple tables are candidates for inserting the flow, the function
1192 * should choose one arbitrarily (but deterministically).
1193 *
1194 * If this function is NULL then table 0 is always chosen. */
1195 enum ofperr (*rule_choose_table)(const struct ofproto *ofproto,
1196 const struct match *match,
1197 uint8_t *table_idp);
1198
1199 /* Life-cycle functions for a "struct rule".
1200 *
1201 *
1202 * Rule Life Cycle
1203 * ===============
1204 *
1205 * The life cycle of a struct rule is an elaboration of the basic life
1206 * cycle described above under "Life Cycle".
1207 *
1208 * After a rule is successfully constructed, it is then inserted. If
1209 * insertion is successful, then before it is later destructed, it is
1210 * deleted.
1211 *
1212 * You can think of a rule as having the following extra steps inserted
1213 * between "Life Cycle" steps 4 and 5:
1214 *
1215 * 4.1. The client inserts the rule into the flow table, making it
1216 * visible in flow table lookups.
1217 *
1218 * 4.2. The client calls "rule_insert" to insert the flow. The
1219 * implementation attempts to install the flow in the underlying
1220 * hardware and returns an error code indicate success or failure.
1221 * On failure, go to step 5.
1222 *
1223 * 4.3. The rule is now installed in the flow table. Eventually it will
1224 * be deleted.
1225 *
1226 * 4.4. The client removes the rule from the flow table. It is no longer
1227 * visible in flow table lookups.
1228 *
1229 * 4.5. The client calls "rule_delete". The implementation uninstalls
1230 * the flow from the underlying hardware. Deletion is not allowed
1231 * to fail.
1232 *
1233 *
1234 * Construction
1235 * ============
1236 *
1237 * When ->rule_construct() is called, 'rule' is a new rule that is not yet
1238 * inserted into a flow table. ->rule_construct() should initialize enough
1239 * of the rule's derived state for 'rule' to be suitable for inserting into
1240 * a flow table. ->rule_construct() should not modify any base members of
1241 * struct rule.
1242 *
1243 * If ->rule_construct() fails (as indicated by returning a nonzero
1244 * OpenFlow error code), the ofproto base code will uninitialize and
1245 * deallocate 'rule'. See "Rule Life Cycle" above for more details.
1246 *
1247 * ->rule_construct() must also:
1248 *
1249 * - Validate that the datapath supports the matching rule in 'rule->cr'
1250 * datapath. For example, if the rule's table does not support
1251 * registers, then it is an error if 'rule->cr' does not wildcard all
1252 * registers.
1253 *
1254 * - Validate that the datapath can correctly implement 'rule->ofpacts'.
1255 *
1256 * After a successful construction the rest of the rule life cycle calls
1257 * may not fail, so ->rule_construct() must also make sure that the rule
1258 * can be inserted in to the datapath.
1259 *
1260 *
1261 * Insertion
1262 * =========
1263 *
1264 * Following successful construction, the ofproto base case inserts 'rule'
1265 * into its flow table, then it calls ->rule_insert(). ->rule_insert()
1266 * must add the new rule to the datapath flow table and return only after
1267 * this is complete. The 'new_rule' may be a duplicate of an 'old_rule'.
1268 * In this case the 'old_rule' is non-null, and the implementation should
1269 * forward rule statistics counts from the 'old_rule' to the 'new_rule' if
1270 * 'forward_counts' is 'true', 'used' timestamp is always forwarded. This
1271 * may not fail.
1272 *
1273 *
1274 * Deletion
1275 * ========
1276 *
1277 * The ofproto base code removes 'rule' from its flow table before it calls
1278 * ->rule_delete() (if non-null). ->rule_delete() must remove 'rule' from
1279 * the datapath flow table and return only after this has completed
1280 * successfully.
1281 *
1282 * Rule deletion must not fail.
1283 *
1284 *
1285 * Destruction
1286 * ===========
1287 *
1288 * ->rule_destruct() must uninitialize derived state.
1289 *
1290 * Rule destruction must not fail. */
1291 struct rule *(*rule_alloc)(void);
1292 enum ofperr (*rule_construct)(struct rule *rule)
1293 /* OVS_REQUIRES(ofproto_mutex) */;
1294 void (*rule_insert)(struct rule *rule, struct rule *old_rule,
1295 bool forward_counts)
1296 /* OVS_REQUIRES(ofproto_mutex) */;
1297 void (*rule_delete)(struct rule *rule) /* OVS_REQUIRES(ofproto_mutex) */;
1298 void (*rule_destruct)(struct rule *rule);
1299 void (*rule_dealloc)(struct rule *rule);
1300
1301 /* Obtains statistics for 'rule', storing the number of packets that have
1302 * matched it in '*packet_count' and the number of bytes in those packets
1303 * in '*byte_count'. UINT64_MAX indicates that the packet count or byte
1304 * count is unknown. */
1305 void (*rule_get_stats)(struct rule *rule, uint64_t *packet_count,
1306 uint64_t *byte_count, long long int *used)
1307 /* OVS_EXCLUDED(ofproto_mutex) */;
1308
1309 /* Translates actions in 'opo->ofpacts', for 'opo->packet' in flow tables
1310 * in version 'opo->version'. This is useful for OpenFlow OFPT_PACKET_OUT.
1311 *
1312 * This function must validate that it can correctly translate
1313 * 'opo->ofpacts'. If not, then it should return an OpenFlow error code.
1314 *
1315 * 'opo->flow' reflects the flow information for 'opo->packet'. All of the
1316 * information in 'opo->flow' is extracted from 'opo->packet', except for
1317 * 'in_port', which is assigned to the correct value for the incoming
1318 * packet. 'tunnel' and register values should be zeroed. 'packet''s
1319 * header pointers and offsets (e.g. packet->l3) are appropriately
1320 * initialized. packet->l3 is aligned on a 32-bit boundary.
1321 *
1322 * Returns 0 if successful, otherwise an OpenFlow error code.
1323 *
1324 * This function may be called with 'ofproto_mutex' held. */
1325 enum ofperr (*packet_xlate)(struct ofproto *,
1326 struct ofproto_packet_out *opo);
1327
1328 /* Free resources taken by a successful packet_xlate(). If multiple
1329 * packet_xlate() calls have been made in sequence, the corresponding
1330 * packet_xlate_revert() calls have to be made in reverse order. */
1331 void (*packet_xlate_revert)(struct ofproto *, struct ofproto_packet_out *);
1332
1333 /* Executes the datapath actions, translation side-effects, and stats as
1334 * produced by ->packet_xlate(). The caller retains ownership of 'opo'.
1335 */
1336 void (*packet_execute)(struct ofproto *, struct ofproto_packet_out *opo);
1337
1338 /* Changes the OpenFlow IP fragment handling policy to 'frag_handling',
1339 * which takes one of the following values, with the corresponding
1340 * meanings:
1341 *
1342 * - OFPUTIL_FRAG_NORMAL: The switch should treat IP fragments the same
1343 * way as other packets, omitting TCP and UDP port numbers (always
1344 * setting them to 0).
1345 *
1346 * - OFPUTIL_FRAG_DROP: The switch should drop all IP fragments without
1347 * passing them through the flow table.
1348 *
1349 * - OFPUTIL_FRAG_REASM: The switch should reassemble IP fragments before
1350 * passing packets through the flow table.
1351 *
1352 * - OFPUTIL_FRAG_NX_MATCH (a Nicira extension): Similar to
1353 * OFPUTIL_FRAG_NORMAL, except that TCP and UDP port numbers should be
1354 * included in fragments with offset 0.
1355 *
1356 * Implementations are not required to support every mode.
1357 * OFPUTIL_FRAG_NORMAL is the default mode when an ofproto is created.
1358 *
1359 * At the time of the call to ->set_frag_handling(), the current mode is
1360 * available in 'ofproto->frag_handling'. ->set_frag_handling() returns
1361 * true if the requested mode was set, false if it is not supported.
1362 *
1363 * Upon successful return, the caller changes 'ofproto->frag_handling' to
1364 * reflect the new mode.
1365 */
1366 bool (*set_frag_handling)(struct ofproto *ofproto,
1367 enum ofputil_frag_handling frag_handling);
1368
1369 enum ofperr (*nxt_resume)(struct ofproto *ofproto,
1370 const struct ofputil_packet_in_private *);
1371
1372 /* ## ------------------------- ## */
1373 /* ## OFPP_NORMAL configuration ## */
1374 /* ## ------------------------- ## */
1375
1376 /* Configures NetFlow on 'ofproto' according to the options in
1377 * 'netflow_options', or turns off NetFlow if 'netflow_options' is NULL.
1378 *
1379 * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
1380 * NetFlow, as does a null pointer. */
1381 int (*set_netflow)(struct ofproto *ofproto,
1382 const struct netflow_options *netflow_options);
1383
1384 void (*get_netflow_ids)(const struct ofproto *ofproto,
1385 uint8_t *engine_type, uint8_t *engine_id);
1386
1387 /* Configures sFlow on 'ofproto' according to the options in
1388 * 'sflow_options', or turns off sFlow if 'sflow_options' is NULL.
1389 *
1390 * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
1391 * sFlow, as does a null pointer. */
1392 int (*set_sflow)(struct ofproto *ofproto,
1393 const struct ofproto_sflow_options *sflow_options);
1394
1395 /* Configures IPFIX on 'ofproto' according to the options in
1396 * 'bridge_exporter_options' and the 'flow_exporters_options'
1397 * array, or turns off IPFIX if 'bridge_exporter_options' and
1398 * 'flow_exporters_options' is NULL.
1399 *
1400 * EOPNOTSUPP as a return value indicates that 'ofproto' does not support
1401 * IPFIX, as does a null pointer. */
1402 int (*set_ipfix)(
1403 struct ofproto *ofproto,
1404 const struct ofproto_ipfix_bridge_exporter_options
1405 *bridge_exporter_options,
1406 const struct ofproto_ipfix_flow_exporter_options
1407 *flow_exporters_options, size_t n_flow_exporters_options);
1408
1409 /* Gets IPFIX stats on 'ofproto' according to the exporter of birdge
1410 * IPFIX or flow-based IPFIX.
1411 *
1412 * OFPERR_NXST_NOT_CONFIGURED as a return value indicates that bridge
1413 * IPFIX or flow-based IPFIX is not configured. */
1414 int (*get_ipfix_stats)(
1415 const struct ofproto *ofproto,
1416 bool bridge_ipfix, struct ovs_list *replies
1417 );
1418
1419 /* Configures connectivity fault management on 'ofport'.
1420 *
1421 * If 'cfm_settings' is nonnull, configures CFM according to its members.
1422 *
1423 * If 'cfm_settings' is null, removes any connectivity fault management
1424 * configuration from 'ofport'.
1425 *
1426 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1427 * support CFM, as does a null pointer. */
1428 int (*set_cfm)(struct ofport *ofport, const struct cfm_settings *s);
1429
1430 /* Checks the status change of CFM on 'ofport'. Returns true if
1431 * there is status change since last call or if CFM is not specified. */
1432 bool (*cfm_status_changed)(struct ofport *ofport);
1433
1434 /* Populates 'smap' with the status of CFM on 'ofport'. Returns 0 on
1435 * success, or a positive errno. EOPNOTSUPP as a return value indicates
1436 * that this ofproto_class does not support CFM, as does a null pointer.
1437 *
1438 * The caller must provide and own '*status', and it must free the array
1439 * returned in 'status->rmps'. '*status' is indeterminate if the return
1440 * value is non-zero. */
1441 int (*get_cfm_status)(const struct ofport *ofport,
1442 struct cfm_status *status);
1443
1444 /* Configures LLDP on 'ofport'.
1445 *
1446 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1447 * support LLDP, as does a null pointer. */
1448 int (*set_lldp)(struct ofport *ofport, const struct smap *cfg);
1449
1450 /* Checks the status of LLDP configured on 'ofport'. Returns true if the
1451 * port's LLDP status was successfully stored into '*status'. Returns
1452 * false if the port did not have LLDP configured, in which case '*status'
1453 * is indeterminate.
1454 *
1455 * The caller must provide and own '*status'. '*status' is indeterminate
1456 * if the return value is non-zero. */
1457 bool (*get_lldp_status)(const struct ofport *ofport,
1458 struct lldp_status *status);
1459
1460 /* Configures Auto Attach.
1461 *
1462 * If 's' is nonnull, configures Auto Attach according to its members.
1463 *
1464 * If 's' is null, removes any Auto Attach configuration.
1465 */
1466 int (*set_aa)(struct ofproto *ofproto,
1467 const struct aa_settings *s);
1468
1469 /* If 's' is nonnull, this function registers a mapping associated with
1470 * client data pointer 'aux' in 'ofproto'. If 'aux' is already registered
1471 * then this function updates its configuration to 's'. Otherwise, this
1472 * function registers a new mapping.
1473 *
1474 * An implementation that does not support mapping at all may set
1475 * it to NULL or return EOPNOTSUPP. An implementation that supports
1476 * only a subset of the functionality should implement what it can
1477 * and return 0.
1478 */
1479 int (*aa_mapping_set)(struct ofproto *ofproto, void *aux,
1480 const struct aa_mapping_settings *s);
1481
1482 /* If 's' is nonnull, this function unregisters a mapping associated with
1483 * client data pointer 'aux' in 'ofproto'. If 'aux' is already registered
1484 * then this function updates its configuration to 's'. Otherwise, this
1485 * function unregisters a new mapping.
1486 *
1487 * An implementation that does not support mapping at all may set
1488 * it to NULL or return EOPNOTSUPP. An implementation that supports
1489 * only a subset of the functionality should implement what it can
1490 * and return 0.
1491 */
1492 int (*aa_mapping_unset)(struct ofproto *ofproto, void *aux);
1493
1494 /*
1495 * Returns the a list of AutoAttach VLAN operations. When Auto Attach is
1496 * enabled, the VLAN associated with an I-SID/VLAN mapping is first
1497 * negotiated with an Auto Attach Server. Once an I-SID VLAN mapping
1498 * becomes active, the corresponding VLAN needs to be communicated to the
1499 * bridge in order to add the VLAN to the trunk port linking the Auto
1500 * Attach Client (in this case openvswitch) and the Auto Attach Server.
1501 *
1502 * The list entries are of type "struct bridge_aa_vlan". Each entry
1503 * specifies the operation (add or remove), the interface on which to
1504 * execute the operation and the VLAN.
1505 */
1506 int (*aa_vlan_get_queued)(struct ofproto *ofproto, struct ovs_list *list);
1507
1508 /*
1509 * Returns the current number of entries in the list of VLAN operations
1510 * in the Auto Attach Client (see previous function description
1511 * aa_vlan_get_queued). Returns 0 if Auto Attach is disabled.
1512 */
1513 unsigned int (*aa_vlan_get_queue_size)(struct ofproto *ofproto);
1514
1515 /* Configures BFD on 'ofport'.
1516 *
1517 * If 'cfg' is NULL, or 'cfg' does not contain the key value pair
1518 * "enable=true", removes BFD from 'ofport'. Otherwise, configures BFD
1519 * according to 'cfg'.
1520 *
1521 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1522 * support BFD, as does a null pointer. */
1523 int (*set_bfd)(struct ofport *ofport, const struct smap *cfg);
1524
1525 /* Checks the status change of BFD on 'ofport'. Returns true if there
1526 * is status change since last call or if BFD is not specified. */
1527 bool (*bfd_status_changed)(struct ofport *ofport);
1528
1529 /* Populates 'smap' with the status of BFD on 'ofport'. Returns 0 on
1530 * success, or a positive errno. EOPNOTSUPP as a return value indicates
1531 * that this ofproto_class does not support BFD, as does a null pointer. */
1532 int (*get_bfd_status)(struct ofport *ofport, struct smap *smap);
1533
1534 /* Configures spanning tree protocol (STP) on 'ofproto' using the
1535 * settings defined in 's'.
1536 *
1537 * If 's' is nonnull, configures STP according to its members.
1538 *
1539 * If 's' is null, removes any STP configuration from 'ofproto'.
1540 *
1541 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1542 * support STP, as does a null pointer. */
1543 int (*set_stp)(struct ofproto *ofproto,
1544 const struct ofproto_stp_settings *s);
1545
1546 /* Retrieves state of spanning tree protocol (STP) on 'ofproto'.
1547 *
1548 * Stores STP state for 'ofproto' in 's'. If the 'enabled' member
1549 * is false, the other member values are not meaningful.
1550 *
1551 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1552 * support STP, as does a null pointer. */
1553 int (*get_stp_status)(struct ofproto *ofproto,
1554 struct ofproto_stp_status *s);
1555
1556 /* Configures spanning tree protocol (STP) on 'ofport' using the
1557 * settings defined in 's'.
1558 *
1559 * If 's' is nonnull, configures STP according to its members. The
1560 * caller is responsible for assigning STP port numbers (using the
1561 * 'port_num' member in the range of 1 through 255, inclusive) and
1562 * ensuring there are no duplicates.
1563 *
1564 * If 's' is null, removes any STP configuration from 'ofport'.
1565 *
1566 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1567 * support STP, as does a null pointer. */
1568 int (*set_stp_port)(struct ofport *ofport,
1569 const struct ofproto_port_stp_settings *s);
1570
1571 /* Retrieves spanning tree protocol (STP) port status of 'ofport'.
1572 *
1573 * Stores STP state for 'ofport' in 's'. If the 'enabled' member is
1574 * false, the other member values are not meaningful.
1575 *
1576 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1577 * support STP, as does a null pointer. */
1578 int (*get_stp_port_status)(struct ofport *ofport,
1579 struct ofproto_port_stp_status *s);
1580
1581 /* Retrieves spanning tree protocol (STP) port statistics of 'ofport'.
1582 *
1583 * Stores STP state for 'ofport' in 's'. If the 'enabled' member is
1584 * false, the other member values are not meaningful.
1585 *
1586 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1587 * support STP, as does a null pointer. */
1588 int (*get_stp_port_stats)(struct ofport *ofport,
1589 struct ofproto_port_stp_stats *s);
1590
1591 /* Configures Rapid Spanning Tree Protocol (RSTP) on 'ofproto' using the
1592 * settings defined in 's'.
1593 *
1594 * If 's' is nonnull, configures RSTP according to its members.
1595 *
1596 * If 's' is null, removes any RSTP configuration from 'ofproto'.
1597 *
1598 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1599 * support RSTP, as does a null pointer. */
1600 void (*set_rstp)(struct ofproto *ofproto,
1601 const struct ofproto_rstp_settings *s);
1602
1603 /* Retrieves state of Rapid Spanning Tree Protocol (RSTP) on 'ofproto'.
1604 *
1605 * Stores RSTP state for 'ofproto' in 's'. If the 'enabled' member
1606 * is false, the other member values are not meaningful.
1607 *
1608 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1609 * support RSTP, as does a null pointer. */
1610 void (*get_rstp_status)(struct ofproto *ofproto,
1611 struct ofproto_rstp_status *s);
1612
1613 /* Configures Rapid Spanning Tree Protocol (RSTP) on 'ofport' using the
1614 * settings defined in 's'.
1615 *
1616 * If 's' is nonnull, configures RSTP according to its members. The
1617 * caller is responsible for assigning RSTP port numbers (using the
1618 * 'port_num' member in the range of 1 through 255, inclusive) and
1619 * ensuring there are no duplicates.
1620 *
1621 * If 's' is null, removes any RSTP configuration from 'ofport'.
1622 *
1623 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1624 * support STP, as does a null pointer. */
1625 void (*set_rstp_port)(struct ofport *ofport,
1626 const struct ofproto_port_rstp_settings *s);
1627
1628 /* Retrieves Rapid Spanning Tree Protocol (RSTP) port status of 'ofport'.
1629 *
1630 * Stores RSTP state for 'ofport' in 's'. If the 'enabled' member is
1631 * false, the other member values are not meaningful.
1632 *
1633 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1634 * support RSTP, as does a null pointer. */
1635 void (*get_rstp_port_status)(struct ofport *ofport,
1636 struct ofproto_port_rstp_status *s);
1637
1638 /* Registers meta-data associated with the 'n_qdscp' Qualities of Service
1639 * 'queues' attached to 'ofport'. This data is not intended to be
1640 * sufficient to implement QoS. Instead, providers may use this
1641 * information to implement features which require knowledge of what queues
1642 * exist on a port, and some basic information about them.
1643 *
1644 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1645 * support QoS, as does a null pointer. */
1646 int (*set_queues)(struct ofport *ofport,
1647 const struct ofproto_port_queue *queues, size_t n_qdscp);
1648
1649 /* If 's' is nonnull, this function registers a "bundle" associated with
1650 * client data pointer 'aux' in 'ofproto'. A bundle is the same concept as
1651 * a Port in OVSDB, that is, it consists of one or more "slave" devices
1652 * (Interfaces, in OVSDB) along with VLAN and LACP configuration and, if
1653 * there is more than one slave, a bonding configuration. If 'aux' is
1654 * already registered then this function updates its configuration to 's'.
1655 * Otherwise, this function registers a new bundle.
1656 *
1657 * If 's' is NULL, this function unregisters the bundle registered on
1658 * 'ofproto' associated with client data pointer 'aux'. If no such bundle
1659 * has been registered, this has no effect.
1660 *
1661 * This function affects only the behavior of the NXAST_AUTOPATH action and
1662 * output to the OFPP_NORMAL port. An implementation that does not support
1663 * it at all may set it to NULL or return EOPNOTSUPP. An implementation
1664 * that supports only a subset of the functionality should implement what
1665 * it can and return 0. */
1666 int (*bundle_set)(struct ofproto *ofproto, void *aux,
1667 const struct ofproto_bundle_settings *s);
1668
1669 /* If 'port' is part of any bundle, removes it from that bundle. If the
1670 * bundle now has no ports, deletes the bundle. If the bundle now has only
1671 * one port, deconfigures the bundle's bonding configuration. */
1672 void (*bundle_remove)(struct ofport *ofport);
1673
1674 /* If 's' is nonnull, this function registers a mirror associated with
1675 * client data pointer 'aux' in 'ofproto'. A mirror is the same concept as
1676 * a Mirror in OVSDB. If 'aux' is already registered then this function
1677 * updates its configuration to 's'. Otherwise, this function registers a
1678 * new mirror.
1679 *
1680 * If 's' is NULL, this function unregisters the mirror registered on
1681 * 'ofproto' associated with client data pointer 'aux'. If no such mirror
1682 * has been registered, this has no effect.
1683 *
1684 * An implementation that does not support mirroring at all may set
1685 * it to NULL or return EOPNOTSUPP. An implementation that supports
1686 * only a subset of the functionality should implement what it can
1687 * and return 0. */
1688 int (*mirror_set)(struct ofproto *ofproto, void *aux,
1689 const struct ofproto_mirror_settings *s);
1690
1691 /* Retrieves statistics from mirror associated with client data
1692 * pointer 'aux' in 'ofproto'. Stores packet and byte counts in
1693 * 'packets' and 'bytes', respectively. If a particular counter is
1694 * not supported, the appropriate argument is set to UINT64_MAX.
1695 *
1696 * EOPNOTSUPP as a return value indicates that this ofproto_class does not
1697 * support retrieving mirror statistics. */
1698 int (*mirror_get_stats)(struct ofproto *ofproto, void *aux,
1699 uint64_t *packets, uint64_t *bytes);
1700
1701 /* Configures the VLANs whose bits are set to 1 in 'flood_vlans' as VLANs
1702 * on which all packets are flooded, instead of using MAC learning. If
1703 * 'flood_vlans' is NULL, then MAC learning applies to all VLANs.
1704 *
1705 * This function affects only the behavior of the OFPP_NORMAL action. An
1706 * implementation that does not support it may set it to NULL or return
1707 * EOPNOTSUPP. */
1708 int (*set_flood_vlans)(struct ofproto *ofproto,
1709 unsigned long *flood_vlans);
1710
1711 /* Returns true if 'aux' is a registered bundle that is currently in use as
1712 * the output for a mirror. */
1713 bool (*is_mirror_output_bundle)(const struct ofproto *ofproto, void *aux);
1714
1715 /* When the configuration option of forward_bpdu changes, this function
1716 * will be invoked. */
1717 void (*forward_bpdu_changed)(struct ofproto *ofproto);
1718
1719 /* Sets the MAC aging timeout for the OFPP_NORMAL action to 'idle_time', in
1720 * seconds, and the maximum number of MAC table entries to
1721 * 'max_entries'.
1722 *
1723 * An implementation that doesn't support configuring these features may
1724 * set this function to NULL or implement it as a no-op. */
1725 void (*set_mac_table_config)(struct ofproto *ofproto,
1726 unsigned int idle_time, size_t max_entries);
1727
1728 /* Configures multicast snooping on 'ofport' using the settings
1729 * defined in 's'.
1730 *
1731 * If 's' is nonnull, this function updates multicast snooping
1732 * configuration to 's' in 'ofproto'.
1733 *
1734 * If 's' is NULL, this function disables multicast snooping
1735 * on 'ofproto'.
1736 *
1737 * An implementation that does not support multicast snooping may set
1738 * it to NULL or return EOPNOTSUPP. */
1739 int (*set_mcast_snooping)(struct ofproto *ofproto,
1740 const struct ofproto_mcast_snooping_settings *s);
1741
1742 /* Configures multicast snooping port's flood setting on 'ofproto'.
1743 *
1744 * If 's' is nonnull, this function updates multicast snooping
1745 * configuration to 's' in 'ofproto'.
1746 *
1747 * If 's' is NULL, this function doesn't change anything.
1748 *
1749 * An implementation that does not support multicast snooping may set
1750 * it to NULL or return EOPNOTSUPP. */
1751 int (*set_mcast_snooping_port)(struct ofproto *ofproto_, void *aux,
1752 const struct ofproto_mcast_snooping_port_settings *s);
1753
1754 /* ## ------------------------ ## */
1755 /* ## OpenFlow meter functions ## */
1756 /* ## ------------------------ ## */
1757
1758 /* These functions should be NULL if an implementation does not support
1759 * them. They must be all null or all non-null.. */
1760
1761 /* Initializes 'features' to describe the metering features supported by
1762 * 'ofproto'. */
1763 void (*meter_get_features)(const struct ofproto *ofproto,
1764 struct ofputil_meter_features *features);
1765
1766 /* If '*id' is UINT32_MAX, adds a new meter with the given 'config'. On
1767 * success the function must store a provider meter ID other than
1768 * UINT32_MAX in '*id'. All further references to the meter will be made
1769 * with the returned provider meter id rather than the OpenFlow meter id.
1770 * The caller does not try to interpret the provider meter id, giving the
1771 * implementation the freedom to either use the OpenFlow meter_id value
1772 * provided in the meter configuration, or any other value suitable for the
1773 * implementation.
1774 *
1775 * If '*id' is a value other than UINT32_MAX, modifies the existing meter
1776 * with that meter provider ID to have configuration 'config', while
1777 * leaving '*id' unchanged. On failure, the existing meter configuration
1778 * is left intact. */
1779 enum ofperr (*meter_set)(struct ofproto *ofproto, ofproto_meter_id *id,
1780 struct ofputil_meter_config *config);
1781
1782 /* Gets the meter and meter band packet and byte counts for maximum of
1783 * 'n_bands' bands for the meter with provider ID 'id' within 'ofproto'.
1784 * The caller fills in the other stats values. The band stats are copied
1785 * to memory at 'stats->bands' provided by the caller. The number of
1786 * returned band stats is returned in 'stats->n_bands'. */
1787 enum ofperr (*meter_get)(const struct ofproto *ofproto,
1788 ofproto_meter_id id,
1789 struct ofputil_meter_stats *stats,
1790 uint16_t n_bands);
1791
1792 /* Deletes a meter, making the 'ofproto_meter_id' invalid for any
1793 * further calls. */
1794 void (*meter_del)(struct ofproto *, ofproto_meter_id);
1795
1796
1797 /* ## -------------------- ## */
1798 /* ## OpenFlow 1.1+ groups ## */
1799 /* ## -------------------- ## */
1800
1801 struct ofgroup *(*group_alloc)(void);
1802 enum ofperr (*group_construct)(struct ofgroup *);
1803 void (*group_destruct)(struct ofgroup *);
1804 void (*group_dealloc)(struct ofgroup *);
1805
1806 void (*group_modify)(struct ofgroup *);
1807
1808 enum ofperr (*group_get_stats)(const struct ofgroup *,
1809 struct ofputil_group_stats *);
1810
1811 /* ## --------------------- ## */
1812 /* ## Datapath information ## */
1813 /* ## --------------------- ## */
1814 /* Retrieve the version string of the datapath. The version
1815 * string can be NULL if it can not be determined.
1816 *
1817 * The version retuned is read only. The caller should not
1818 * free it.
1819 *
1820 * This function should be NULL if an implementation does not support it.
1821 */
1822 const char *(*get_datapath_version)(const struct ofproto *);
1823
1824 /* Pass custom configuration options to the 'type' datapath.
1825 *
1826 * This function should be NULL if an implementation does not support it.
1827 */
1828 void (*type_set_config)(const char *type,
1829 const struct smap *other_config);
1830
1831 /* ## ------------------- ## */
1832 /* ## Connection tracking ## */
1833 /* ## ------------------- ## */
1834 /* Flushes the connection tracking tables. If 'zone' is not NULL,
1835 * only deletes connections in '*zone'. */
1836 void (*ct_flush)(const struct ofproto *, const uint16_t *zone);
1837 };
1838
1839 extern const struct ofproto_class ofproto_dpif_class;
1840
1841 int ofproto_class_register(const struct ofproto_class *);
1842 int ofproto_class_unregister(const struct ofproto_class *);
1843
1844 /* Criteria that flow_mod and other operations use for selecting rules on
1845 * which to operate. */
1846 struct rule_criteria {
1847 /* An OpenFlow table or 255 for all tables. */
1848 uint8_t table_id;
1849
1850 /* OpenFlow matching criteria. Interpreted different in "loose" way by
1851 * collect_rules_loose() and "strict" way by collect_rules_strict(), as
1852 * defined in the OpenFlow spec. */
1853 struct cls_rule cr;
1854 ovs_version_t version;
1855
1856 /* Matching criteria for the OpenFlow cookie. Consider a bit B in a rule's
1857 * cookie and the corresponding bits C in 'cookie' and M in 'cookie_mask'.
1858 * The rule will not be selected if M is 1 and B != C. */
1859 ovs_be64 cookie;
1860 ovs_be64 cookie_mask;
1861
1862 /* Selection based on actions within a rule:
1863 *
1864 * If out_port != OFPP_ANY, selects only rules that output to out_port.
1865 * If out_group != OFPG_ALL, select only rules that output to out_group. */
1866 ofp_port_t out_port;
1867 uint32_t out_group;
1868
1869 /* If true, collects only rules that are modifiable. */
1870 bool include_hidden;
1871 bool include_readonly;
1872 };
1873
1874 /* flow_mod with execution context. */
1875 struct ofproto_flow_mod {
1876 /* Allocated by 'init' phase, may be freed after 'start' phase, as these
1877 * are not needed for 'revert' nor 'finish'. */
1878 struct rule *temp_rule;
1879 struct rule_criteria criteria;
1880 struct cls_conjunction *conjs;
1881 size_t n_conjs;
1882
1883 /* Replicate needed fields from ofputil_flow_mod to not need it after the
1884 * flow has been created. */
1885 uint16_t command;
1886 bool modify_cookie;
1887 /* Fields derived from ofputil_flow_mod. */
1888 bool modify_may_add_flow;
1889 bool modify_keep_counts;
1890 enum nx_flow_update_event event;
1891
1892 /* These are only used during commit execution.
1893 * ofproto_flow_mod_uninit() does NOT clean these up. */
1894 ovs_version_t version; /* Version in which changes take
1895 * effect. */
1896 bool learn_adds_rule; /* Learn execution adds a rule. */
1897 struct rule_collection old_rules; /* Affected rules. */
1898 struct rule_collection new_rules; /* Replacement rules. */
1899 };
1900
1901 void ofproto_flow_mod_uninit(struct ofproto_flow_mod *);
1902
1903 /* port_mod with execution context. */
1904 struct ofproto_port_mod {
1905 struct ofputil_port_mod pm;
1906 struct ofport *port; /* Affected port. */
1907 };
1908
1909 /* flow_mod with execution context. */
1910 struct ofproto_group_mod {
1911 struct ofputil_group_mod gm;
1912
1913 ovs_version_t version; /* Version in which changes take
1914 * effect. */
1915 struct ofgroup *new_group; /* New group. */
1916 struct group_collection old_groups; /* Affected groups. */
1917 };
1918
1919 /* packet_out with execution context. */
1920 struct ofproto_packet_out {
1921 ovs_version_t version;
1922 struct dp_packet *packet;
1923 struct flow *flow;
1924 struct ofpact *ofpacts;
1925 size_t ofpacts_len;
1926
1927 void *aux; /* Provider private. */
1928 };
1929
1930 void ofproto_packet_out_uninit(struct ofproto_packet_out *);
1931
1932 enum ofperr ofproto_flow_mod(struct ofproto *, const struct ofputil_flow_mod *)
1933 OVS_EXCLUDED(ofproto_mutex);
1934 enum ofperr ofproto_flow_mod_init_for_learn(struct ofproto *,
1935 const struct ofputil_flow_mod *,
1936 struct ofproto_flow_mod *)
1937 OVS_EXCLUDED(ofproto_mutex);
1938 enum ofperr ofproto_flow_mod_learn(struct ofproto_flow_mod *, bool keep_ref,
1939 unsigned limit, bool *below_limit)
1940 OVS_EXCLUDED(ofproto_mutex);
1941 enum ofperr ofproto_flow_mod_learn_refresh(struct ofproto_flow_mod *ofm);
1942 enum ofperr ofproto_flow_mod_learn_start(struct ofproto_flow_mod *ofm)
1943 OVS_REQUIRES(ofproto_mutex);
1944 void ofproto_flow_mod_learn_revert(struct ofproto_flow_mod *ofm)
1945 OVS_REQUIRES(ofproto_mutex);
1946 void ofproto_flow_mod_learn_finish(struct ofproto_flow_mod *ofm,
1947 struct ofproto *orig_ofproto)
1948 OVS_REQUIRES(ofproto_mutex);
1949 void ofproto_add_flow(struct ofproto *, const struct match *, int priority,
1950 const struct ofpact *ofpacts, size_t ofpacts_len)
1951 OVS_EXCLUDED(ofproto_mutex);
1952 void ofproto_delete_flow(struct ofproto *, const struct match *, int priority)
1953 OVS_REQUIRES(ofproto_mutex);
1954 void ofproto_flush_flows(struct ofproto *);
1955
1956 enum ofperr ofproto_check_ofpacts(struct ofproto *,
1957 const struct ofpact ofpacts[],
1958 size_t ofpacts_len)
1959 OVS_REQUIRES(ofproto_mutex);
1960 \f
1961 static inline const struct rule_actions *
1962 rule_get_actions(const struct rule *rule)
1963 {
1964 return rule->actions;
1965 }
1966
1967 /* Returns true if 'rule' is an OpenFlow 1.3 "table-miss" rule, false
1968 * otherwise.
1969 *
1970 * ("Table-miss" rules are special because a packet_in generated through one
1971 * uses OFPR_NO_MATCH as its reason, whereas packet_ins generated by any other
1972 * rule use OFPR_ACTION.) */
1973 static inline bool
1974 rule_is_table_miss(const struct rule *rule)
1975 {
1976 return rule->cr.priority == 0 && cls_rule_is_catchall(&rule->cr);
1977 }
1978
1979 /* Returns true if 'rule' should be hidden from the controller.
1980 *
1981 * Rules with priority higher than UINT16_MAX are set up by ofproto itself
1982 * (e.g. by in-band control) and are intentionally hidden from the
1983 * controller. */
1984 static inline bool
1985 rule_is_hidden(const struct rule *rule)
1986 {
1987 return rule->cr.priority > UINT16_MAX;
1988 }
1989
1990 static inline struct rule *
1991 rule_from_cls_rule(const struct cls_rule *cls_rule)
1992 {
1993 return cls_rule ? CONTAINER_OF(cls_rule, struct rule, cr) : NULL;
1994 }
1995
1996 static inline const struct tun_table *
1997 ofproto_get_tun_tab(const struct ofproto *ofproto)
1998 {
1999 return ovsrcu_get(struct tun_table *, &ofproto->metadata_tab);
2000 }
2001
2002 #endif /* ofproto/ofproto-provider.h */