2 * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "ofproto/ofproto-dpif.h"
20 #include "ofproto/ofproto-provider.h"
27 #include "byte-order.h"
32 #include "dynamic-string.h"
33 #include "fail-open.h"
37 #include "mac-learning.h"
38 #include "meta-flow.h"
39 #include "multipath.h"
40 #include "netdev-vport.h"
45 #include "odp-execute.h"
48 #include "ofp-actions.h"
49 #include "ofp-parse.h"
50 #include "ofp-print.h"
51 #include "ofproto-dpif-governor.h"
52 #include "ofproto-dpif-ipfix.h"
53 #include "ofproto-dpif-mirror.h"
54 #include "ofproto-dpif-sflow.h"
55 #include "ofproto-dpif-xlate.h"
56 #include "poll-loop.h"
61 #include "unaligned.h"
63 #include "vlan-bitmap.h"
66 VLOG_DEFINE_THIS_MODULE(ofproto_dpif);
68 COVERAGE_DEFINE(ofproto_dpif_expired);
69 COVERAGE_DEFINE(facet_changed_rule);
70 COVERAGE_DEFINE(facet_revalidate);
71 COVERAGE_DEFINE(facet_unexpected);
72 COVERAGE_DEFINE(facet_suppress);
73 COVERAGE_DEFINE(subfacet_install_fail);
75 /* Number of implemented OpenFlow tables. */
76 enum { N_TABLES = 255 };
77 enum { TBL_INTERNAL = N_TABLES - 1 }; /* Used for internal hidden rules. */
78 BUILD_ASSERT_DECL(N_TABLES >= 2 && N_TABLES <= 255);
83 static struct rule_dpif *rule_dpif_lookup(struct ofproto_dpif *,
85 struct flow_wildcards *wc);
87 static void rule_get_stats(struct rule *, uint64_t *packets, uint64_t *bytes);
88 static void rule_invalidate(const struct rule_dpif *);
91 struct hmap_node hmap_node; /* In struct ofproto's "bundles" hmap. */
92 struct ofproto_dpif *ofproto; /* Owning ofproto. */
93 void *aux; /* Key supplied by ofproto's client. */
94 char *name; /* Identifier for log messages. */
97 struct list ports; /* Contains "struct ofport"s. */
98 enum port_vlan_mode vlan_mode; /* VLAN mode */
99 int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */
100 unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1.
101 * NULL if all VLANs are trunked. */
102 struct lacp *lacp; /* LACP if LACP is enabled, otherwise NULL. */
103 struct bond *bond; /* Nonnull iff more than one port. */
104 bool use_priority_tags; /* Use 802.1p tag for frames in VLAN 0? */
107 bool floodable; /* True if no port has OFPUTIL_PC_NO_FLOOD set. */
110 static void bundle_remove(struct ofport *);
111 static void bundle_update(struct ofbundle *);
112 static void bundle_destroy(struct ofbundle *);
113 static void bundle_del_port(struct ofport_dpif *);
114 static void bundle_run(struct ofbundle *);
115 static void bundle_wait(struct ofbundle *);
117 static void stp_run(struct ofproto_dpif *ofproto);
118 static void stp_wait(struct ofproto_dpif *ofproto);
119 static int set_stp_port(struct ofport *,
120 const struct ofproto_port_stp_settings *);
122 static void compose_slow_path(const struct ofproto_dpif *, const struct flow *,
123 enum slow_path_reason,
124 uint64_t *stub, size_t stub_size,
125 const struct nlattr **actionsp,
126 size_t *actions_lenp);
128 /* A subfacet (see "struct subfacet" below) has three possible installation
131 * - SF_NOT_INSTALLED: Not installed in the datapath. This will only be the
132 * case just after the subfacet is created, just before the subfacet is
133 * destroyed, or if the datapath returns an error when we try to install a
136 * - SF_FAST_PATH: The subfacet's actions are installed in the datapath.
138 * - SF_SLOW_PATH: An action that sends every packet for the subfacet through
139 * ofproto_dpif is installed in the datapath.
142 SF_NOT_INSTALLED, /* No datapath flow for this subfacet. */
143 SF_FAST_PATH, /* Full actions are installed. */
144 SF_SLOW_PATH, /* Send-to-userspace action is installed. */
147 /* A dpif flow and actions associated with a facet.
149 * See also the large comment on struct facet. */
152 struct hmap_node hmap_node; /* In struct ofproto_dpif 'subfacets' list. */
153 struct list list_node; /* In struct facet's 'facets' list. */
154 struct facet *facet; /* Owning facet. */
155 struct dpif_backer *backer; /* Owning backer. */
157 enum odp_key_fitness key_fitness;
161 long long int used; /* Time last used; time created if not used. */
162 long long int created; /* Time created. */
164 uint64_t dp_packet_count; /* Last known packet count in the datapath. */
165 uint64_t dp_byte_count; /* Last known byte count in the datapath. */
167 enum subfacet_path path; /* Installed in datapath? */
170 #define SUBFACET_DESTROY_MAX_BATCH 50
172 static struct subfacet *subfacet_create(struct facet *, struct flow_miss *miss,
174 static struct subfacet *subfacet_find(struct dpif_backer *,
175 const struct nlattr *key, size_t key_len,
177 static void subfacet_destroy(struct subfacet *);
178 static void subfacet_destroy__(struct subfacet *);
179 static void subfacet_destroy_batch(struct dpif_backer *,
180 struct subfacet **, int n);
181 static void subfacet_reset_dp_stats(struct subfacet *,
182 struct dpif_flow_stats *);
183 static void subfacet_update_stats(struct subfacet *,
184 const struct dpif_flow_stats *);
185 static int subfacet_install(struct subfacet *,
186 const struct ofpbuf *odp_actions,
187 struct dpif_flow_stats *);
188 static void subfacet_uninstall(struct subfacet *);
190 /* A unique, non-overlapping instantiation of an OpenFlow flow.
192 * A facet associates a "struct flow", which represents the Open vSwitch
193 * userspace idea of an exact-match flow, with one or more subfacets.
194 * While the facet is created based on an exact-match flow, it is stored
195 * within the ofproto based on the wildcards that could be expressed
196 * based on the flow table and other configuration. (See the 'wc'
197 * description in "struct xlate_out" for more details.)
199 * Each subfacet tracks the datapath's idea of the flow equivalent to
200 * the facet. When the kernel module (or other dpif implementation) and
201 * Open vSwitch userspace agree on the definition of a flow key, there
202 * is exactly one subfacet per facet. If the dpif implementation
203 * supports more-specific flow matching than userspace, however, a facet
204 * can have more than one subfacet. Examples include the dpif
205 * implementation not supporting the same wildcards as userspace or some
206 * distinction in flow that userspace simply doesn't understand.
208 * Flow expiration works in terms of subfacets, so a facet must have at
209 * least one subfacet or it will never expire, leaking memory. */
212 struct hmap_node hmap_node; /* In owning ofproto's 'facets' hmap. */
213 struct ofproto_dpif *ofproto;
216 struct list subfacets;
217 long long int used; /* Time last used; time created if not used. */
220 struct flow flow; /* Flow of the creating subfacet. */
221 struct cls_rule cr; /* In 'ofproto_dpif's facets classifier. */
225 * - Do include packets and bytes sent "by hand", e.g. with
228 * - Do include packets and bytes that were obtained from the datapath
229 * when a subfacet's statistics were reset (e.g. dpif_flow_put() with
230 * DPIF_FP_ZERO_STATS).
232 * - Do not include packets or bytes that can be obtained from the
233 * datapath for any existing subfacet.
235 uint64_t packet_count; /* Number of packets received. */
236 uint64_t byte_count; /* Number of bytes received. */
238 /* Resubmit statistics. */
239 uint64_t prev_packet_count; /* Number of packets from last stats push. */
240 uint64_t prev_byte_count; /* Number of bytes from last stats push. */
241 long long int prev_used; /* Used time from last stats push. */
244 uint64_t accounted_bytes; /* Bytes processed by facet_account(). */
245 struct netflow_flow nf_flow; /* Per-flow NetFlow tracking data. */
246 uint8_t tcp_flags; /* TCP flags seen for this 'rule'. */
248 struct xlate_out xout;
249 bool fail_open; /* Facet matched the fail open rule. */
251 /* Storage for a single subfacet, to reduce malloc() time and space
252 * overhead. (A facet always has at least one subfacet and in the common
253 * case has exactly one subfacet. However, 'one_subfacet' may not
254 * always be valid, since it could have been removed after newer
255 * subfacets were pushed onto the 'subfacets' list.) */
256 struct subfacet one_subfacet;
258 long long int learn_rl; /* Rate limiter for facet_learn(). */
261 static struct facet *facet_create(const struct flow_miss *, struct rule_dpif *,
263 struct dpif_flow_stats *);
264 static void facet_remove(struct facet *);
265 static void facet_free(struct facet *);
267 static struct facet *facet_find(struct ofproto_dpif *, const struct flow *);
268 static struct facet *facet_lookup_valid(struct ofproto_dpif *,
269 const struct flow *);
270 static bool facet_revalidate(struct facet *);
271 static bool facet_check_consistency(struct facet *);
273 static void facet_flush_stats(struct facet *);
275 static void facet_reset_counters(struct facet *);
276 static void facet_push_stats(struct facet *, bool may_learn);
277 static void facet_learn(struct facet *);
278 static void facet_account(struct facet *);
279 static void push_all_stats(void);
281 static bool facet_is_controller_flow(struct facet *);
284 struct hmap_node odp_port_node; /* In dpif_backer's "odp_to_ofport_map". */
288 struct ofbundle *bundle; /* Bundle that contains this port, if any. */
289 struct list bundle_node; /* In struct ofbundle's "ports" list. */
290 struct cfm *cfm; /* Connectivity Fault Management, if any. */
291 struct bfd *bfd; /* BFD, if any. */
292 tag_type tag; /* Tag associated with this port. */
293 bool may_enable; /* May be enabled in bonds. */
294 bool is_tunnel; /* This port is a tunnel. */
295 long long int carrier_seq; /* Carrier status changes. */
296 struct ofport_dpif *peer; /* Peer if patch port. */
299 struct stp_port *stp_port; /* Spanning Tree Protocol, if any. */
300 enum stp_state stp_state; /* Always STP_DISABLED if STP not in use. */
301 long long int stp_state_entered;
303 struct hmap priorities; /* Map of attached 'priority_to_dscp's. */
305 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
307 * This is deprecated. It is only for compatibility with broken device
308 * drivers in old versions of Linux that do not properly support VLANs when
309 * VLAN devices are not used. When broken device drivers are no longer in
310 * widespread use, we will delete these interfaces. */
311 ofp_port_t realdev_ofp_port;
315 /* Node in 'ofport_dpif''s 'priorities' map. Used to maintain a map from
316 * 'priority' (the datapath's term for QoS queue) to the dscp bits which all
317 * traffic egressing the 'ofport' with that priority should be marked with. */
318 struct priority_to_dscp {
319 struct hmap_node hmap_node; /* Node in 'ofport_dpif''s 'priorities' map. */
320 uint32_t priority; /* Priority of this queue (see struct flow). */
322 uint8_t dscp; /* DSCP bits to mark outgoing traffic with. */
325 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
327 * This is deprecated. It is only for compatibility with broken device drivers
328 * in old versions of Linux that do not properly support VLANs when VLAN
329 * devices are not used. When broken device drivers are no longer in
330 * widespread use, we will delete these interfaces. */
331 struct vlan_splinter {
332 struct hmap_node realdev_vid_node;
333 struct hmap_node vlandev_node;
334 ofp_port_t realdev_ofp_port;
335 ofp_port_t vlandev_ofp_port;
339 static bool vsp_adjust_flow(const struct ofproto_dpif *, struct flow *);
340 static void vsp_remove(struct ofport_dpif *);
341 static void vsp_add(struct ofport_dpif *, ofp_port_t realdev_ofp_port, int vid);
343 static odp_port_t ofp_port_to_odp_port(const struct ofproto_dpif *,
346 static ofp_port_t odp_port_to_ofp_port(const struct ofproto_dpif *,
349 static struct ofport_dpif *
350 ofport_dpif_cast(const struct ofport *ofport)
352 return ofport ? CONTAINER_OF(ofport, struct ofport_dpif, up) : NULL;
355 static void port_run(struct ofport_dpif *);
356 static void port_run_fast(struct ofport_dpif *);
357 static void port_wait(struct ofport_dpif *);
358 static int set_bfd(struct ofport *, const struct smap *);
359 static int set_cfm(struct ofport *, const struct cfm_settings *);
360 static void ofport_clear_priorities(struct ofport_dpif *);
361 static void ofport_update_peer(struct ofport_dpif *);
362 static void run_fast_rl(void);
364 struct dpif_completion {
365 struct list list_node;
366 struct ofoperation *op;
369 /* Extra information about a classifier table.
370 * Currently used just for optimized flow revalidation. */
372 /* If either of these is nonnull, then this table has a form that allows
373 * flows to be tagged to avoid revalidating most flows for the most common
374 * kinds of flow table changes. */
375 struct cls_table *catchall_table; /* Table that wildcards all fields. */
376 struct cls_table *other_table; /* Table with any other wildcard set. */
377 uint32_t basis; /* Keeps each table's tags separate. */
380 /* Reasons that we might need to revalidate every facet, and corresponding
383 * A value of 0 means that there is no need to revalidate.
385 * It would be nice to have some cleaner way to integrate with coverage
386 * counters, but with only a few reasons I guess this is good enough for
388 enum revalidate_reason {
389 REV_RECONFIGURE = 1, /* Switch configuration changed. */
390 REV_STP, /* Spanning tree protocol port status change. */
391 REV_PORT_TOGGLED, /* Port enabled or disabled by CFM, LACP, ...*/
392 REV_FLOW_TABLE, /* Flow table changed. */
393 REV_INCONSISTENCY /* Facet self-check failed. */
395 COVERAGE_DEFINE(rev_reconfigure);
396 COVERAGE_DEFINE(rev_stp);
397 COVERAGE_DEFINE(rev_port_toggled);
398 COVERAGE_DEFINE(rev_flow_table);
399 COVERAGE_DEFINE(rev_inconsistency);
401 /* Drop keys are odp flow keys which have drop flows installed in the kernel.
402 * These are datapath flows which have no associated ofproto, if they did we
403 * would use facets. */
405 struct hmap_node hmap_node;
410 struct avg_subfacet_rates {
411 double add_rate; /* Moving average of new flows created per minute. */
412 double del_rate; /* Moving average of flows deleted per minute. */
415 /* All datapaths of a given type share a single dpif backer instance. */
420 struct timer next_expiration;
421 struct hmap odp_to_ofport_map; /* ODP port to ofport mapping. */
423 struct simap tnl_backers; /* Set of dpif ports backing tunnels. */
425 /* Facet revalidation flags applying to facets which use this backer. */
426 enum revalidate_reason need_revalidate; /* Revalidate every facet. */
427 struct tag_set revalidate_set; /* Revalidate only matching facets. */
429 struct hmap drop_keys; /* Set of dropped odp keys. */
430 bool recv_set_enable; /* Enables or disables receiving packets. */
432 struct hmap subfacets;
433 struct governor *governor;
435 /* Subfacet statistics.
437 * These keep track of the total number of subfacets added and deleted and
438 * flow life span. They are useful for computing the flow rates stats
439 * exposed via "ovs-appctl dpif/show". The goal is to learn about
440 * traffic patterns in ways that we can use later to improve Open vSwitch
441 * performance in new situations. */
442 long long int created; /* Time when it is created. */
443 unsigned max_n_subfacet; /* Maximum number of flows */
444 unsigned avg_n_subfacet; /* Average number of flows. */
445 long long int avg_subfacet_life; /* Average life span of subfacets. */
447 /* The average number of subfacets... */
448 struct avg_subfacet_rates hourly; /* ...over the last hour. */
449 struct avg_subfacet_rates daily; /* ...over the last day. */
450 struct avg_subfacet_rates lifetime; /* ...over the switch lifetime. */
451 long long int last_minute; /* Last time 'hourly' was updated. */
453 /* Number of subfacets added or deleted since 'last_minute'. */
454 unsigned subfacet_add_count;
455 unsigned subfacet_del_count;
457 /* Number of subfacets added or deleted from 'created' to 'last_minute.' */
458 unsigned long long int total_subfacet_add_count;
459 unsigned long long int total_subfacet_del_count;
462 /* All existing ofproto_backer instances, indexed by ofproto->up.type. */
463 static struct shash all_dpif_backers = SHASH_INITIALIZER(&all_dpif_backers);
465 static void drop_key_clear(struct dpif_backer *);
466 static struct ofport_dpif *
467 odp_port_to_ofport(const struct dpif_backer *, odp_port_t odp_port);
468 static void update_moving_averages(struct dpif_backer *backer);
470 struct ofproto_dpif {
471 struct hmap_node all_ofproto_dpifs_node; /* In 'all_ofproto_dpifs'. */
473 struct dpif_backer *backer;
475 /* Special OpenFlow rules. */
476 struct rule_dpif *miss_rule; /* Sends flow table misses to controller. */
477 struct rule_dpif *no_packet_in_rule; /* Drops flow table misses. */
478 struct rule_dpif *drop_frags_rule; /* Used in OFPC_FRAG_DROP mode. */
481 struct netflow *netflow;
482 struct dpif_sflow *sflow;
483 struct dpif_ipfix *ipfix;
484 struct hmap bundles; /* Contains "struct ofbundle"s. */
485 struct mac_learning *ml;
486 bool has_bonded_bundles;
487 struct mbridge *mbridge;
490 struct classifier facets; /* Contains 'struct facet's. */
491 long long int consistency_rl;
494 struct table_dpif tables[N_TABLES];
496 /* Support for debugging async flow mods. */
497 struct list completions;
499 struct netdev_stats stats; /* To account packets generated and consumed in
504 long long int stp_last_tick;
506 /* VLAN splinters. */
507 struct hmap realdev_vid_map; /* (realdev,vid) -> vlandev. */
508 struct hmap vlandev_map; /* vlandev -> (realdev,vid). */
511 struct sset ports; /* Set of standard port names. */
512 struct sset ghost_ports; /* Ports with no datapath port. */
513 struct sset port_poll_set; /* Queued names for port_poll() reply. */
514 int port_poll_errno; /* Last errno for port_poll() reply. */
516 /* Per ofproto's dpif stats. */
521 /* Defer flow mod completion until "ovs-appctl ofproto/unclog"? (Useful only
522 * for debugging the asynchronous flow_mod implementation.) */
525 /* By default, flows in the datapath are wildcarded (megaflows). They
526 * may be disabled with the "ovs-appctl dpif/disable-megaflows" command. */
527 static bool enable_megaflows = true;
529 /* All existing ofproto_dpif instances, indexed by ->up.name. */
530 static struct hmap all_ofproto_dpifs = HMAP_INITIALIZER(&all_ofproto_dpifs);
532 static void ofproto_dpif_unixctl_init(void);
534 static inline struct ofproto_dpif *
535 ofproto_dpif_cast(const struct ofproto *ofproto)
537 ovs_assert(ofproto->ofproto_class == &ofproto_dpif_class);
538 return CONTAINER_OF(ofproto, struct ofproto_dpif, up);
541 static struct ofport_dpif *get_ofp_port(const struct ofproto_dpif *ofproto,
542 ofp_port_t ofp_port);
545 #define FLOW_MISS_MAX_BATCH 50
546 static int handle_upcalls(struct dpif_backer *, unsigned int max_batch);
548 /* Flow expiration. */
549 static int expire(struct dpif_backer *);
552 static void send_netflow_active_timeouts(struct ofproto_dpif *);
555 static int send_packet(const struct ofport_dpif *, struct ofpbuf *packet);
557 /* Global variables. */
558 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
560 /* Initial mappings of port to bridge mappings. */
561 static struct shash init_ofp_ports = SHASH_INITIALIZER(&init_ofp_ports);
564 ofproto_dpif_flow_mod(struct ofproto_dpif *ofproto,
565 struct ofputil_flow_mod *fm)
567 return ofproto_flow_mod(&ofproto->up, fm);
571 ofproto_dpif_send_packet_in(struct ofproto_dpif *ofproto,
572 struct ofputil_packet_in *pin)
574 connmgr_send_packet_in(ofproto->up.connmgr, pin);
577 /* Factory functions. */
580 init(const struct shash *iface_hints)
582 struct shash_node *node;
584 /* Make a local copy, since we don't own 'iface_hints' elements. */
585 SHASH_FOR_EACH(node, iface_hints) {
586 const struct iface_hint *orig_hint = node->data;
587 struct iface_hint *new_hint = xmalloc(sizeof *new_hint);
589 new_hint->br_name = xstrdup(orig_hint->br_name);
590 new_hint->br_type = xstrdup(orig_hint->br_type);
591 new_hint->ofp_port = orig_hint->ofp_port;
593 shash_add(&init_ofp_ports, node->name, new_hint);
598 enumerate_types(struct sset *types)
600 dp_enumerate_types(types);
604 enumerate_names(const char *type, struct sset *names)
606 struct ofproto_dpif *ofproto;
609 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
610 if (strcmp(type, ofproto->up.type)) {
613 sset_add(names, ofproto->up.name);
620 del(const char *type, const char *name)
625 error = dpif_open(name, type, &dpif);
627 error = dpif_delete(dpif);
634 port_open_type(const char *datapath_type, const char *port_type)
636 return dpif_port_open_type(datapath_type, port_type);
639 /* Type functions. */
641 static void process_dpif_port_changes(struct dpif_backer *);
642 static void process_dpif_all_ports_changed(struct dpif_backer *);
643 static void process_dpif_port_change(struct dpif_backer *,
644 const char *devname);
645 static void process_dpif_port_error(struct dpif_backer *, int error);
647 static struct ofproto_dpif *
648 lookup_ofproto_dpif_by_port_name(const char *name)
650 struct ofproto_dpif *ofproto;
652 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
653 if (sset_contains(&ofproto->ports, name)) {
662 type_run(const char *type)
664 static long long int push_timer = LLONG_MIN;
665 struct dpif_backer *backer;
667 backer = shash_find_data(&all_dpif_backers, type);
669 /* This is not necessarily a problem, since backers are only
670 * created on demand. */
674 dpif_run(backer->dpif);
676 /* The most natural place to push facet statistics is when they're pulled
677 * from the datapath. However, when there are many flows in the datapath,
678 * this expensive operation can occur so frequently, that it reduces our
679 * ability to quickly set up flows. To reduce the cost, we push statistics
681 if (time_msec() > push_timer) {
682 push_timer = time_msec() + 2000;
686 /* If vswitchd started with other_config:flow_restore_wait set as "true",
687 * and the configuration has now changed to "false", enable receiving
688 * packets from the datapath. */
689 if (!backer->recv_set_enable && !ofproto_get_flow_restore_wait()) {
692 backer->recv_set_enable = true;
694 error = dpif_recv_set(backer->dpif, backer->recv_set_enable);
696 VLOG_ERR("Failed to enable receiving packets in dpif.");
699 dpif_flow_flush(backer->dpif);
700 backer->need_revalidate = REV_RECONFIGURE;
703 if (backer->need_revalidate
704 || !tag_set_is_empty(&backer->revalidate_set)) {
705 struct tag_set revalidate_set = backer->revalidate_set;
706 bool need_revalidate = backer->need_revalidate;
707 struct ofproto_dpif *ofproto;
708 struct simap_node *node;
709 struct simap tmp_backers;
711 /* Handle tunnel garbage collection. */
712 simap_init(&tmp_backers);
713 simap_swap(&backer->tnl_backers, &tmp_backers);
715 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
716 struct ofport_dpif *iter;
718 if (backer != ofproto->backer) {
722 HMAP_FOR_EACH (iter, up.hmap_node, &ofproto->up.ports) {
723 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
726 if (!iter->is_tunnel) {
730 dp_port = netdev_vport_get_dpif_port(iter->up.netdev,
731 namebuf, sizeof namebuf);
732 node = simap_find(&tmp_backers, dp_port);
734 simap_put(&backer->tnl_backers, dp_port, node->data);
735 simap_delete(&tmp_backers, node);
736 node = simap_find(&backer->tnl_backers, dp_port);
738 node = simap_find(&backer->tnl_backers, dp_port);
740 odp_port_t odp_port = ODPP_NONE;
742 if (!dpif_port_add(backer->dpif, iter->up.netdev,
744 simap_put(&backer->tnl_backers, dp_port,
745 odp_to_u32(odp_port));
746 node = simap_find(&backer->tnl_backers, dp_port);
751 iter->odp_port = node ? u32_to_odp(node->data) : ODPP_NONE;
752 if (tnl_port_reconfigure(iter, iter->up.netdev,
754 backer->need_revalidate = REV_RECONFIGURE;
759 SIMAP_FOR_EACH (node, &tmp_backers) {
760 dpif_port_del(backer->dpif, u32_to_odp(node->data));
762 simap_destroy(&tmp_backers);
764 switch (backer->need_revalidate) {
765 case REV_RECONFIGURE: COVERAGE_INC(rev_reconfigure); break;
766 case REV_STP: COVERAGE_INC(rev_stp); break;
767 case REV_PORT_TOGGLED: COVERAGE_INC(rev_port_toggled); break;
768 case REV_FLOW_TABLE: COVERAGE_INC(rev_flow_table); break;
769 case REV_INCONSISTENCY: COVERAGE_INC(rev_inconsistency); break;
772 if (backer->need_revalidate) {
773 /* Clear the drop_keys in case we should now be accepting some
774 * formerly dropped flows. */
775 drop_key_clear(backer);
778 /* Clear the revalidation flags. */
779 tag_set_init(&backer->revalidate_set);
780 backer->need_revalidate = 0;
782 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
783 struct facet *facet, *next;
784 struct cls_cursor cursor;
786 if (ofproto->backer != backer) {
790 if (need_revalidate) {
791 struct ofport_dpif *ofport;
792 struct ofbundle *bundle;
794 xlate_ofproto_set(ofproto, ofproto->up.name, ofproto->ml,
795 ofproto->mbridge, ofproto->sflow,
796 ofproto->ipfix, ofproto->up.frag_handling,
797 ofproto->up.forward_bpdu,
798 connmgr_has_in_band(ofproto->up.connmgr),
799 ofproto->netflow != NULL,
800 ofproto->stp != NULL);
802 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
803 xlate_bundle_set(ofproto, bundle, bundle->name,
804 bundle->vlan_mode, bundle->vlan,
805 bundle->trunks, bundle->use_priority_tags,
806 bundle->bond, bundle->lacp,
810 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
811 xlate_ofport_set(ofproto, ofport->bundle, ofport,
812 ofport->up.ofp_port, ofport->odp_port,
813 ofport->up.netdev, ofport->cfm,
814 ofport->bfd, ofport->peer,
815 ofport->up.pp.config, ofport->stp_state,
816 ofport->is_tunnel, ofport->may_enable);
820 cls_cursor_init(&cursor, &ofproto->facets, NULL);
821 CLS_CURSOR_FOR_EACH_SAFE (facet, next, cr, &cursor) {
823 || tag_set_intersects(&revalidate_set, facet->xout.tags)) {
824 facet_revalidate(facet);
831 if (!backer->recv_set_enable) {
832 /* Wake up before a max of 1000ms. */
833 timer_set_duration(&backer->next_expiration, 1000);
834 } else if (timer_expired(&backer->next_expiration)) {
835 int delay = expire(backer);
836 timer_set_duration(&backer->next_expiration, delay);
839 process_dpif_port_changes(backer);
841 if (backer->governor) {
844 governor_run(backer->governor);
846 /* If the governor has shrunk to its minimum size and the number of
847 * subfacets has dwindled, then drop the governor entirely.
849 * For hysteresis, the number of subfacets to drop the governor is
850 * smaller than the number needed to trigger its creation. */
851 n_subfacets = hmap_count(&backer->subfacets);
852 if (n_subfacets * 4 < flow_eviction_threshold
853 && governor_is_idle(backer->governor)) {
854 governor_destroy(backer->governor);
855 backer->governor = NULL;
862 /* Check for and handle port changes in 'backer''s dpif. */
864 process_dpif_port_changes(struct dpif_backer *backer)
870 error = dpif_port_poll(backer->dpif, &devname);
876 process_dpif_all_ports_changed(backer);
880 process_dpif_port_change(backer, devname);
885 process_dpif_port_error(backer, error);
892 process_dpif_all_ports_changed(struct dpif_backer *backer)
894 struct ofproto_dpif *ofproto;
895 struct dpif_port dpif_port;
896 struct dpif_port_dump dump;
897 struct sset devnames;
900 sset_init(&devnames);
901 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
902 if (ofproto->backer == backer) {
903 struct ofport *ofport;
905 HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) {
906 sset_add(&devnames, netdev_get_name(ofport->netdev));
910 DPIF_PORT_FOR_EACH (&dpif_port, &dump, backer->dpif) {
911 sset_add(&devnames, dpif_port.name);
914 SSET_FOR_EACH (devname, &devnames) {
915 process_dpif_port_change(backer, devname);
917 sset_destroy(&devnames);
921 process_dpif_port_change(struct dpif_backer *backer, const char *devname)
923 struct ofproto_dpif *ofproto;
924 struct dpif_port port;
926 /* Don't report on the datapath's device. */
927 if (!strcmp(devname, dpif_base_name(backer->dpif))) {
931 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node,
932 &all_ofproto_dpifs) {
933 if (simap_contains(&ofproto->backer->tnl_backers, devname)) {
938 ofproto = lookup_ofproto_dpif_by_port_name(devname);
939 if (dpif_port_query_by_name(backer->dpif, devname, &port)) {
940 /* The port was removed. If we know the datapath,
941 * report it through poll_set(). If we don't, it may be
942 * notifying us of a removal we initiated, so ignore it.
943 * If there's a pending ENOBUFS, let it stand, since
944 * everything will be reevaluated. */
945 if (ofproto && ofproto->port_poll_errno != ENOBUFS) {
946 sset_add(&ofproto->port_poll_set, devname);
947 ofproto->port_poll_errno = 0;
949 } else if (!ofproto) {
950 /* The port was added, but we don't know with which
951 * ofproto we should associate it. Delete it. */
952 dpif_port_del(backer->dpif, port.port_no);
954 struct ofport_dpif *ofport;
956 ofport = ofport_dpif_cast(shash_find_data(
957 &ofproto->up.port_by_name, devname));
959 && ofport->odp_port != port.port_no
960 && !odp_port_to_ofport(backer, port.port_no))
962 /* 'ofport''s datapath port number has changed from
963 * 'ofport->odp_port' to 'port.port_no'. Update our internal data
964 * structures to match. */
965 hmap_remove(&backer->odp_to_ofport_map, &ofport->odp_port_node);
966 ofport->odp_port = port.port_no;
967 hmap_insert(&backer->odp_to_ofport_map, &ofport->odp_port_node,
968 hash_odp_port(port.port_no));
969 backer->need_revalidate = REV_RECONFIGURE;
972 dpif_port_destroy(&port);
975 /* Propagate 'error' to all ofprotos based on 'backer'. */
977 process_dpif_port_error(struct dpif_backer *backer, int error)
979 struct ofproto_dpif *ofproto;
981 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
982 if (ofproto->backer == backer) {
983 sset_clear(&ofproto->port_poll_set);
984 ofproto->port_poll_errno = error;
990 dpif_backer_run_fast(struct dpif_backer *backer, int max_batch)
994 /* If recv_set_enable is false, we should not handle upcalls. */
995 if (!backer->recv_set_enable) {
999 /* Handle one or more batches of upcalls, until there's nothing left to do
1000 * or until we do a fixed total amount of work.
1002 * We do work in batches because it can be much cheaper to set up a number
1003 * of flows and fire off their patches all at once. We do multiple batches
1004 * because in some cases handling a packet can cause another packet to be
1005 * queued almost immediately as part of the return flow. Both
1006 * optimizations can make major improvements on some benchmarks and
1007 * presumably for real traffic as well. */
1009 while (work < max_batch) {
1010 int retval = handle_upcalls(backer, max_batch - work);
1021 type_run_fast(const char *type)
1023 struct dpif_backer *backer;
1025 backer = shash_find_data(&all_dpif_backers, type);
1027 /* This is not necessarily a problem, since backers are only
1028 * created on demand. */
1032 return dpif_backer_run_fast(backer, FLOW_MISS_MAX_BATCH);
1038 static long long int port_rl = LLONG_MIN;
1039 static unsigned int backer_rl = 0;
1041 if (time_msec() >= port_rl) {
1042 struct ofproto_dpif *ofproto;
1043 struct ofport_dpif *ofport;
1045 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
1047 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1048 port_run_fast(ofport);
1051 port_rl = time_msec() + 200;
1054 /* XXX: We have to be careful not to do too much work in this function. If
1055 * we call dpif_backer_run_fast() too often, or with too large a batch,
1056 * performance improves signifcantly, but at a cost. It's possible for the
1057 * number of flows in the datapath to increase without bound, and for poll
1058 * loops to take 10s of seconds. The correct solution to this problem,
1059 * long term, is to separate flow miss handling into it's own thread so it
1060 * isn't affected by revalidations, and expirations. Until then, this is
1061 * the best we can do. */
1062 if (++backer_rl >= 10) {
1063 struct shash_node *node;
1066 SHASH_FOR_EACH (node, &all_dpif_backers) {
1067 dpif_backer_run_fast(node->data, 1);
1073 type_wait(const char *type)
1075 struct dpif_backer *backer;
1077 backer = shash_find_data(&all_dpif_backers, type);
1079 /* This is not necessarily a problem, since backers are only
1080 * created on demand. */
1084 if (backer->governor) {
1085 governor_wait(backer->governor);
1088 timer_wait(&backer->next_expiration);
1091 /* Basic life-cycle. */
1093 static int add_internal_flows(struct ofproto_dpif *);
1095 static struct ofproto *
1098 struct ofproto_dpif *ofproto = xmalloc(sizeof *ofproto);
1099 return &ofproto->up;
1103 dealloc(struct ofproto *ofproto_)
1105 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1110 close_dpif_backer(struct dpif_backer *backer)
1112 struct shash_node *node;
1114 ovs_assert(backer->refcount > 0);
1116 if (--backer->refcount) {
1120 drop_key_clear(backer);
1121 hmap_destroy(&backer->drop_keys);
1123 simap_destroy(&backer->tnl_backers);
1124 hmap_destroy(&backer->odp_to_ofport_map);
1125 node = shash_find(&all_dpif_backers, backer->type);
1127 shash_delete(&all_dpif_backers, node);
1128 dpif_close(backer->dpif);
1130 ovs_assert(hmap_is_empty(&backer->subfacets));
1131 hmap_destroy(&backer->subfacets);
1132 governor_destroy(backer->governor);
1137 /* Datapath port slated for removal from datapath. */
1138 struct odp_garbage {
1139 struct list list_node;
1140 odp_port_t odp_port;
1144 open_dpif_backer(const char *type, struct dpif_backer **backerp)
1146 struct dpif_backer *backer;
1147 struct dpif_port_dump port_dump;
1148 struct dpif_port port;
1149 struct shash_node *node;
1150 struct list garbage_list;
1151 struct odp_garbage *garbage, *next;
1157 backer = shash_find_data(&all_dpif_backers, type);
1164 backer_name = xasprintf("ovs-%s", type);
1166 /* Remove any existing datapaths, since we assume we're the only
1167 * userspace controlling the datapath. */
1169 dp_enumerate_names(type, &names);
1170 SSET_FOR_EACH(name, &names) {
1171 struct dpif *old_dpif;
1173 /* Don't remove our backer if it exists. */
1174 if (!strcmp(name, backer_name)) {
1178 if (dpif_open(name, type, &old_dpif)) {
1179 VLOG_WARN("couldn't open old datapath %s to remove it", name);
1181 dpif_delete(old_dpif);
1182 dpif_close(old_dpif);
1185 sset_destroy(&names);
1187 backer = xmalloc(sizeof *backer);
1189 error = dpif_create_and_open(backer_name, type, &backer->dpif);
1192 VLOG_ERR("failed to open datapath of type %s: %s", type,
1193 ovs_strerror(error));
1198 backer->type = xstrdup(type);
1199 backer->governor = NULL;
1200 backer->refcount = 1;
1201 hmap_init(&backer->odp_to_ofport_map);
1202 hmap_init(&backer->drop_keys);
1203 hmap_init(&backer->subfacets);
1204 timer_set_duration(&backer->next_expiration, 1000);
1205 backer->need_revalidate = 0;
1206 simap_init(&backer->tnl_backers);
1207 tag_set_init(&backer->revalidate_set);
1208 backer->recv_set_enable = !ofproto_get_flow_restore_wait();
1211 if (backer->recv_set_enable) {
1212 dpif_flow_flush(backer->dpif);
1215 /* Loop through the ports already on the datapath and remove any
1216 * that we don't need anymore. */
1217 list_init(&garbage_list);
1218 dpif_port_dump_start(&port_dump, backer->dpif);
1219 while (dpif_port_dump_next(&port_dump, &port)) {
1220 node = shash_find(&init_ofp_ports, port.name);
1221 if (!node && strcmp(port.name, dpif_base_name(backer->dpif))) {
1222 garbage = xmalloc(sizeof *garbage);
1223 garbage->odp_port = port.port_no;
1224 list_push_front(&garbage_list, &garbage->list_node);
1227 dpif_port_dump_done(&port_dump);
1229 LIST_FOR_EACH_SAFE (garbage, next, list_node, &garbage_list) {
1230 dpif_port_del(backer->dpif, garbage->odp_port);
1231 list_remove(&garbage->list_node);
1235 shash_add(&all_dpif_backers, type, backer);
1237 error = dpif_recv_set(backer->dpif, backer->recv_set_enable);
1239 VLOG_ERR("failed to listen on datapath of type %s: %s",
1240 type, ovs_strerror(error));
1241 close_dpif_backer(backer);
1245 backer->max_n_subfacet = 0;
1246 backer->created = time_msec();
1247 backer->last_minute = backer->created;
1248 memset(&backer->hourly, 0, sizeof backer->hourly);
1249 memset(&backer->daily, 0, sizeof backer->daily);
1250 memset(&backer->lifetime, 0, sizeof backer->lifetime);
1251 backer->subfacet_add_count = 0;
1252 backer->subfacet_del_count = 0;
1253 backer->total_subfacet_add_count = 0;
1254 backer->total_subfacet_del_count = 0;
1255 backer->avg_n_subfacet = 0;
1256 backer->avg_subfacet_life = 0;
1262 construct(struct ofproto *ofproto_)
1264 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1265 struct shash_node *node, *next;
1266 odp_port_t max_ports;
1270 error = open_dpif_backer(ofproto->up.type, &ofproto->backer);
1275 max_ports = dpif_get_max_ports(ofproto->backer->dpif);
1276 ofproto_init_max_ports(ofproto_, u16_to_ofp(MIN(odp_to_u32(max_ports),
1277 ofp_to_u16(OFPP_MAX))));
1279 ofproto->netflow = NULL;
1280 ofproto->sflow = NULL;
1281 ofproto->ipfix = NULL;
1282 ofproto->stp = NULL;
1283 hmap_init(&ofproto->bundles);
1284 ofproto->ml = mac_learning_create(MAC_ENTRY_DEFAULT_IDLE_TIME);
1285 ofproto->mbridge = mbridge_create();
1286 ofproto->has_bonded_bundles = false;
1288 classifier_init(&ofproto->facets);
1289 ofproto->consistency_rl = LLONG_MIN;
1291 for (i = 0; i < N_TABLES; i++) {
1292 struct table_dpif *table = &ofproto->tables[i];
1294 table->catchall_table = NULL;
1295 table->other_table = NULL;
1296 table->basis = random_uint32();
1299 list_init(&ofproto->completions);
1301 ofproto_dpif_unixctl_init();
1303 hmap_init(&ofproto->vlandev_map);
1304 hmap_init(&ofproto->realdev_vid_map);
1306 sset_init(&ofproto->ports);
1307 sset_init(&ofproto->ghost_ports);
1308 sset_init(&ofproto->port_poll_set);
1309 ofproto->port_poll_errno = 0;
1311 SHASH_FOR_EACH_SAFE (node, next, &init_ofp_ports) {
1312 struct iface_hint *iface_hint = node->data;
1314 if (!strcmp(iface_hint->br_name, ofproto->up.name)) {
1315 /* Check if the datapath already has this port. */
1316 if (dpif_port_exists(ofproto->backer->dpif, node->name)) {
1317 sset_add(&ofproto->ports, node->name);
1320 free(iface_hint->br_name);
1321 free(iface_hint->br_type);
1323 shash_delete(&init_ofp_ports, node);
1327 hmap_insert(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node,
1328 hash_string(ofproto->up.name, 0));
1329 memset(&ofproto->stats, 0, sizeof ofproto->stats);
1331 ofproto_init_tables(ofproto_, N_TABLES);
1332 error = add_internal_flows(ofproto);
1333 ofproto->up.tables[TBL_INTERNAL].flags = OFTABLE_HIDDEN | OFTABLE_READONLY;
1336 ofproto->n_missed = 0;
1342 add_internal_flow(struct ofproto_dpif *ofproto, int id,
1343 const struct ofpbuf *ofpacts, struct rule_dpif **rulep)
1345 struct ofputil_flow_mod fm;
1348 match_init_catchall(&fm.match);
1350 match_set_reg(&fm.match, 0, id);
1351 fm.new_cookie = htonll(0);
1352 fm.cookie = htonll(0);
1353 fm.cookie_mask = htonll(0);
1354 fm.modify_cookie = false;
1355 fm.table_id = TBL_INTERNAL;
1356 fm.command = OFPFC_ADD;
1357 fm.idle_timeout = 0;
1358 fm.hard_timeout = 0;
1362 fm.ofpacts = ofpacts->data;
1363 fm.ofpacts_len = ofpacts->size;
1365 error = ofproto_flow_mod(&ofproto->up, &fm);
1367 VLOG_ERR_RL(&rl, "failed to add internal flow %d (%s)",
1368 id, ofperr_to_string(error));
1372 *rulep = rule_dpif_lookup_in_table(ofproto, &fm.match.flow, NULL,
1374 ovs_assert(*rulep != NULL);
1380 add_internal_flows(struct ofproto_dpif *ofproto)
1382 struct ofpact_controller *controller;
1383 uint64_t ofpacts_stub[128 / 8];
1384 struct ofpbuf ofpacts;
1388 ofpbuf_use_stack(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
1391 controller = ofpact_put_CONTROLLER(&ofpacts);
1392 controller->max_len = UINT16_MAX;
1393 controller->controller_id = 0;
1394 controller->reason = OFPR_NO_MATCH;
1395 ofpact_pad(&ofpacts);
1397 error = add_internal_flow(ofproto, id++, &ofpacts, &ofproto->miss_rule);
1402 ofpbuf_clear(&ofpacts);
1403 error = add_internal_flow(ofproto, id++, &ofpacts,
1404 &ofproto->no_packet_in_rule);
1409 error = add_internal_flow(ofproto, id++, &ofpacts,
1410 &ofproto->drop_frags_rule);
1415 complete_operations(struct ofproto_dpif *ofproto)
1417 struct dpif_completion *c, *next;
1419 LIST_FOR_EACH_SAFE (c, next, list_node, &ofproto->completions) {
1420 ofoperation_complete(c->op, 0);
1421 list_remove(&c->list_node);
1427 destruct(struct ofproto *ofproto_)
1429 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1430 struct rule_dpif *rule, *next_rule;
1431 struct oftable *table;
1433 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1434 xlate_remove_ofproto(ofproto);
1436 hmap_remove(&all_ofproto_dpifs, &ofproto->all_ofproto_dpifs_node);
1437 complete_operations(ofproto);
1439 OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {
1440 struct cls_cursor cursor;
1442 cls_cursor_init(&cursor, &table->cls, NULL);
1443 CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
1444 ofproto_rule_destroy(&rule->up);
1448 mbridge_unref(ofproto->mbridge);
1450 netflow_destroy(ofproto->netflow);
1451 dpif_sflow_unref(ofproto->sflow);
1452 hmap_destroy(&ofproto->bundles);
1453 mac_learning_unref(ofproto->ml);
1455 classifier_destroy(&ofproto->facets);
1457 hmap_destroy(&ofproto->vlandev_map);
1458 hmap_destroy(&ofproto->realdev_vid_map);
1460 sset_destroy(&ofproto->ports);
1461 sset_destroy(&ofproto->ghost_ports);
1462 sset_destroy(&ofproto->port_poll_set);
1464 close_dpif_backer(ofproto->backer);
1468 run_fast(struct ofproto *ofproto_)
1470 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1471 struct ofport_dpif *ofport;
1473 /* Do not perform any periodic activity required by 'ofproto' while
1474 * waiting for flow restore to complete. */
1475 if (ofproto_get_flow_restore_wait()) {
1479 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1480 port_run_fast(ofport);
1487 run(struct ofproto *ofproto_)
1489 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1490 struct ofport_dpif *ofport;
1491 struct ofbundle *bundle;
1495 complete_operations(ofproto);
1498 if (mbridge_need_revalidate(ofproto->mbridge)) {
1499 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1500 mac_learning_flush(ofproto->ml, NULL);
1503 /* Do not perform any periodic activity below required by 'ofproto' while
1504 * waiting for flow restore to complete. */
1505 if (ofproto_get_flow_restore_wait()) {
1509 error = run_fast(ofproto_);
1514 if (ofproto->netflow) {
1515 if (netflow_run(ofproto->netflow)) {
1516 send_netflow_active_timeouts(ofproto);
1519 if (ofproto->sflow) {
1520 dpif_sflow_run(ofproto->sflow);
1523 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1526 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1531 mac_learning_run(ofproto->ml, &ofproto->backer->revalidate_set);
1533 /* Check the consistency of a random facet, to aid debugging. */
1534 if (time_msec() >= ofproto->consistency_rl
1535 && !classifier_is_empty(&ofproto->facets)
1536 && !ofproto->backer->need_revalidate) {
1537 struct cls_table *table;
1538 struct cls_rule *cr;
1539 struct facet *facet;
1541 ofproto->consistency_rl = time_msec() + 250;
1543 table = CONTAINER_OF(hmap_random_node(&ofproto->facets.tables),
1544 struct cls_table, hmap_node);
1545 cr = CONTAINER_OF(hmap_random_node(&table->rules), struct cls_rule,
1547 facet = CONTAINER_OF(cr, struct facet, cr);
1549 if (!tag_set_intersects(&ofproto->backer->revalidate_set,
1550 facet->xout.tags)) {
1551 if (!facet_check_consistency(facet)) {
1552 ofproto->backer->need_revalidate = REV_INCONSISTENCY;
1561 wait(struct ofproto *ofproto_)
1563 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1564 struct ofport_dpif *ofport;
1565 struct ofbundle *bundle;
1567 if (!clogged && !list_is_empty(&ofproto->completions)) {
1568 poll_immediate_wake();
1571 if (ofproto_get_flow_restore_wait()) {
1575 dpif_wait(ofproto->backer->dpif);
1576 dpif_recv_wait(ofproto->backer->dpif);
1577 if (ofproto->sflow) {
1578 dpif_sflow_wait(ofproto->sflow);
1580 if (!tag_set_is_empty(&ofproto->backer->revalidate_set)) {
1581 poll_immediate_wake();
1583 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1586 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1587 bundle_wait(bundle);
1589 if (ofproto->netflow) {
1590 netflow_wait(ofproto->netflow);
1592 mac_learning_wait(ofproto->ml);
1594 if (ofproto->backer->need_revalidate) {
1595 /* Shouldn't happen, but if it does just go around again. */
1596 VLOG_DBG_RL(&rl, "need revalidate in ofproto_wait_cb()");
1597 poll_immediate_wake();
1602 get_memory_usage(const struct ofproto *ofproto_, struct simap *usage)
1604 const struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1605 struct cls_cursor cursor;
1606 size_t n_subfacets = 0;
1607 struct facet *facet;
1609 simap_increase(usage, "facets", classifier_count(&ofproto->facets));
1611 cls_cursor_init(&cursor, &ofproto->facets, NULL);
1612 CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
1613 n_subfacets += list_size(&facet->subfacets);
1615 simap_increase(usage, "subfacets", n_subfacets);
1619 flush(struct ofproto *ofproto_)
1621 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1622 struct subfacet *subfacet, *next_subfacet;
1623 struct subfacet *batch[SUBFACET_DESTROY_MAX_BATCH];
1627 HMAP_FOR_EACH_SAFE (subfacet, next_subfacet, hmap_node,
1628 &ofproto->backer->subfacets) {
1629 if (subfacet->facet->ofproto != ofproto) {
1633 if (subfacet->path != SF_NOT_INSTALLED) {
1634 batch[n_batch++] = subfacet;
1635 if (n_batch >= SUBFACET_DESTROY_MAX_BATCH) {
1636 subfacet_destroy_batch(ofproto->backer, batch, n_batch);
1640 subfacet_destroy(subfacet);
1645 subfacet_destroy_batch(ofproto->backer, batch, n_batch);
1650 get_features(struct ofproto *ofproto_ OVS_UNUSED,
1651 bool *arp_match_ip, enum ofputil_action_bitmap *actions)
1653 *arp_match_ip = true;
1654 *actions = (OFPUTIL_A_OUTPUT |
1655 OFPUTIL_A_SET_VLAN_VID |
1656 OFPUTIL_A_SET_VLAN_PCP |
1657 OFPUTIL_A_STRIP_VLAN |
1658 OFPUTIL_A_SET_DL_SRC |
1659 OFPUTIL_A_SET_DL_DST |
1660 OFPUTIL_A_SET_NW_SRC |
1661 OFPUTIL_A_SET_NW_DST |
1662 OFPUTIL_A_SET_NW_TOS |
1663 OFPUTIL_A_SET_TP_SRC |
1664 OFPUTIL_A_SET_TP_DST |
1669 get_tables(struct ofproto *ofproto_, struct ofp12_table_stats *ots)
1671 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1672 struct dpif_dp_stats s;
1673 uint64_t n_miss, n_no_pkt_in, n_bytes, n_dropped_frags;
1676 strcpy(ots->name, "classifier");
1678 dpif_get_dp_stats(ofproto->backer->dpif, &s);
1679 rule_get_stats(&ofproto->miss_rule->up, &n_miss, &n_bytes);
1680 rule_get_stats(&ofproto->no_packet_in_rule->up, &n_no_pkt_in, &n_bytes);
1681 rule_get_stats(&ofproto->drop_frags_rule->up, &n_dropped_frags, &n_bytes);
1683 n_lookup = s.n_hit + s.n_missed - n_dropped_frags;
1684 ots->lookup_count = htonll(n_lookup);
1685 ots->matched_count = htonll(n_lookup - n_miss - n_no_pkt_in);
1688 static struct ofport *
1691 struct ofport_dpif *port = xmalloc(sizeof *port);
1696 port_dealloc(struct ofport *port_)
1698 struct ofport_dpif *port = ofport_dpif_cast(port_);
1703 port_construct(struct ofport *port_)
1705 struct ofport_dpif *port = ofport_dpif_cast(port_);
1706 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1707 const struct netdev *netdev = port->up.netdev;
1708 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
1709 struct dpif_port dpif_port;
1712 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1713 port->bundle = NULL;
1716 port->tag = tag_create_random();
1717 port->may_enable = true;
1718 port->stp_port = NULL;
1719 port->stp_state = STP_DISABLED;
1720 port->is_tunnel = false;
1722 hmap_init(&port->priorities);
1723 port->realdev_ofp_port = 0;
1724 port->vlandev_vid = 0;
1725 port->carrier_seq = netdev_get_carrier_resets(netdev);
1727 if (netdev_vport_is_patch(netdev)) {
1728 /* By bailing out here, we don't submit the port to the sFlow module
1729 * to be considered for counter polling export. This is correct
1730 * because the patch port represents an interface that sFlow considers
1731 * to be "internal" to the switch as a whole, and therefore not an
1732 * candidate for counter polling. */
1733 port->odp_port = ODPP_NONE;
1734 ofport_update_peer(port);
1738 error = dpif_port_query_by_name(ofproto->backer->dpif,
1739 netdev_vport_get_dpif_port(netdev, namebuf,
1746 port->odp_port = dpif_port.port_no;
1748 if (netdev_get_tunnel_config(netdev)) {
1749 tnl_port_add(port, port->up.netdev, port->odp_port);
1750 port->is_tunnel = true;
1752 /* Sanity-check that a mapping doesn't already exist. This
1753 * shouldn't happen for non-tunnel ports. */
1754 if (odp_port_to_ofp_port(ofproto, port->odp_port) != OFPP_NONE) {
1755 VLOG_ERR("port %s already has an OpenFlow port number",
1757 dpif_port_destroy(&dpif_port);
1761 hmap_insert(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node,
1762 hash_odp_port(port->odp_port));
1764 dpif_port_destroy(&dpif_port);
1766 if (ofproto->sflow) {
1767 dpif_sflow_add_port(ofproto->sflow, port_, port->odp_port);
1774 port_destruct(struct ofport *port_)
1776 struct ofport_dpif *port = ofport_dpif_cast(port_);
1777 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1778 const char *devname = netdev_get_name(port->up.netdev);
1779 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
1780 const char *dp_port_name;
1782 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1783 xlate_ofport_remove(port);
1785 dp_port_name = netdev_vport_get_dpif_port(port->up.netdev, namebuf,
1787 if (dpif_port_exists(ofproto->backer->dpif, dp_port_name)) {
1788 /* The underlying device is still there, so delete it. This
1789 * happens when the ofproto is being destroyed, since the caller
1790 * assumes that removal of attached ports will happen as part of
1792 if (!port->is_tunnel) {
1793 dpif_port_del(ofproto->backer->dpif, port->odp_port);
1798 port->peer->peer = NULL;
1802 if (port->odp_port != ODPP_NONE && !port->is_tunnel) {
1803 hmap_remove(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node);
1807 sset_find_and_delete(&ofproto->ports, devname);
1808 sset_find_and_delete(&ofproto->ghost_ports, devname);
1809 bundle_remove(port_);
1810 set_cfm(port_, NULL);
1811 set_bfd(port_, NULL);
1812 if (ofproto->sflow) {
1813 dpif_sflow_del_port(ofproto->sflow, port->odp_port);
1816 ofport_clear_priorities(port);
1817 hmap_destroy(&port->priorities);
1821 port_modified(struct ofport *port_)
1823 struct ofport_dpif *port = ofport_dpif_cast(port_);
1825 if (port->bundle && port->bundle->bond) {
1826 bond_slave_set_netdev(port->bundle->bond, port, port->up.netdev);
1830 cfm_set_netdev(port->cfm, port->up.netdev);
1833 if (port->is_tunnel && tnl_port_reconfigure(port, port->up.netdev,
1835 ofproto_dpif_cast(port->up.ofproto)->backer->need_revalidate =
1839 ofport_update_peer(port);
1843 port_reconfigured(struct ofport *port_, enum ofputil_port_config old_config)
1845 struct ofport_dpif *port = ofport_dpif_cast(port_);
1846 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
1847 enum ofputil_port_config changed = old_config ^ port->up.pp.config;
1849 if (changed & (OFPUTIL_PC_NO_RECV | OFPUTIL_PC_NO_RECV_STP |
1850 OFPUTIL_PC_NO_FWD | OFPUTIL_PC_NO_FLOOD |
1851 OFPUTIL_PC_NO_PACKET_IN)) {
1852 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1854 if (changed & OFPUTIL_PC_NO_FLOOD && port->bundle) {
1855 bundle_update(port->bundle);
1861 set_sflow(struct ofproto *ofproto_,
1862 const struct ofproto_sflow_options *sflow_options)
1864 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1865 struct dpif_sflow *ds = ofproto->sflow;
1867 if (sflow_options) {
1869 struct ofport_dpif *ofport;
1871 ds = ofproto->sflow = dpif_sflow_create();
1872 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
1873 dpif_sflow_add_port(ds, &ofport->up, ofport->odp_port);
1875 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1877 dpif_sflow_set_options(ds, sflow_options);
1880 dpif_sflow_unref(ds);
1881 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1882 ofproto->sflow = NULL;
1890 struct ofproto *ofproto_,
1891 const struct ofproto_ipfix_bridge_exporter_options *bridge_exporter_options,
1892 const struct ofproto_ipfix_flow_exporter_options *flow_exporters_options,
1893 size_t n_flow_exporters_options)
1895 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1896 struct dpif_ipfix *di = ofproto->ipfix;
1898 if (bridge_exporter_options || flow_exporters_options) {
1900 di = ofproto->ipfix = dpif_ipfix_create();
1902 dpif_ipfix_set_options(
1903 di, bridge_exporter_options, flow_exporters_options,
1904 n_flow_exporters_options);
1907 dpif_ipfix_unref(di);
1908 ofproto->ipfix = NULL;
1915 set_cfm(struct ofport *ofport_, const struct cfm_settings *s)
1917 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1924 struct ofproto_dpif *ofproto;
1926 ofproto = ofproto_dpif_cast(ofport->up.ofproto);
1927 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1928 ofport->cfm = cfm_create(ofport->up.netdev);
1931 if (cfm_configure(ofport->cfm, s)) {
1937 cfm_unref(ofport->cfm);
1943 get_cfm_status(const struct ofport *ofport_,
1944 struct ofproto_cfm_status *status)
1946 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1949 status->faults = cfm_get_fault(ofport->cfm);
1950 status->remote_opstate = cfm_get_opup(ofport->cfm);
1951 status->health = cfm_get_health(ofport->cfm);
1952 cfm_get_remote_mpids(ofport->cfm, &status->rmps, &status->n_rmps);
1960 set_bfd(struct ofport *ofport_, const struct smap *cfg)
1962 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport_->ofproto);
1963 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1967 ofport->bfd = bfd_configure(old, netdev_get_name(ofport->up.netdev), cfg);
1968 if (ofport->bfd != old) {
1969 ofproto->backer->need_revalidate = REV_RECONFIGURE;
1976 get_bfd_status(struct ofport *ofport_, struct smap *smap)
1978 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1981 bfd_get_status(ofport->bfd, smap);
1988 /* Spanning Tree. */
1991 send_bpdu_cb(struct ofpbuf *pkt, int port_num, void *ofproto_)
1993 struct ofproto_dpif *ofproto = ofproto_;
1994 struct stp_port *sp = stp_get_port(ofproto->stp, port_num);
1995 struct ofport_dpif *ofport;
1997 ofport = stp_port_get_aux(sp);
1999 VLOG_WARN_RL(&rl, "%s: cannot send BPDU on unknown port %d",
2000 ofproto->up.name, port_num);
2002 struct eth_header *eth = pkt->l2;
2004 netdev_get_etheraddr(ofport->up.netdev, eth->eth_src);
2005 if (eth_addr_is_zero(eth->eth_src)) {
2006 VLOG_WARN_RL(&rl, "%s: cannot send BPDU on port %d "
2007 "with unknown MAC", ofproto->up.name, port_num);
2009 send_packet(ofport, pkt);
2015 /* Configures STP on 'ofproto_' using the settings defined in 's'. */
2017 set_stp(struct ofproto *ofproto_, const struct ofproto_stp_settings *s)
2019 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2021 /* Only revalidate flows if the configuration changed. */
2022 if (!s != !ofproto->stp) {
2023 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2027 if (!ofproto->stp) {
2028 ofproto->stp = stp_create(ofproto_->name, s->system_id,
2029 send_bpdu_cb, ofproto);
2030 ofproto->stp_last_tick = time_msec();
2033 stp_set_bridge_id(ofproto->stp, s->system_id);
2034 stp_set_bridge_priority(ofproto->stp, s->priority);
2035 stp_set_hello_time(ofproto->stp, s->hello_time);
2036 stp_set_max_age(ofproto->stp, s->max_age);
2037 stp_set_forward_delay(ofproto->stp, s->fwd_delay);
2039 struct ofport *ofport;
2041 HMAP_FOR_EACH (ofport, hmap_node, &ofproto->up.ports) {
2042 set_stp_port(ofport, NULL);
2045 stp_destroy(ofproto->stp);
2046 ofproto->stp = NULL;
2053 get_stp_status(struct ofproto *ofproto_, struct ofproto_stp_status *s)
2055 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2059 s->bridge_id = stp_get_bridge_id(ofproto->stp);
2060 s->designated_root = stp_get_designated_root(ofproto->stp);
2061 s->root_path_cost = stp_get_root_path_cost(ofproto->stp);
2070 update_stp_port_state(struct ofport_dpif *ofport)
2072 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2073 enum stp_state state;
2075 /* Figure out new state. */
2076 state = ofport->stp_port ? stp_port_get_state(ofport->stp_port)
2080 if (ofport->stp_state != state) {
2081 enum ofputil_port_state of_state;
2084 VLOG_DBG_RL(&rl, "port %s: STP state changed from %s to %s",
2085 netdev_get_name(ofport->up.netdev),
2086 stp_state_name(ofport->stp_state),
2087 stp_state_name(state));
2088 if (stp_learn_in_state(ofport->stp_state)
2089 != stp_learn_in_state(state)) {
2090 /* xxx Learning action flows should also be flushed. */
2091 mac_learning_flush(ofproto->ml,
2092 &ofproto->backer->revalidate_set);
2094 fwd_change = stp_forward_in_state(ofport->stp_state)
2095 != stp_forward_in_state(state);
2097 ofproto->backer->need_revalidate = REV_STP;
2098 ofport->stp_state = state;
2099 ofport->stp_state_entered = time_msec();
2101 if (fwd_change && ofport->bundle) {
2102 bundle_update(ofport->bundle);
2105 /* Update the STP state bits in the OpenFlow port description. */
2106 of_state = ofport->up.pp.state & ~OFPUTIL_PS_STP_MASK;
2107 of_state |= (state == STP_LISTENING ? OFPUTIL_PS_STP_LISTEN
2108 : state == STP_LEARNING ? OFPUTIL_PS_STP_LEARN
2109 : state == STP_FORWARDING ? OFPUTIL_PS_STP_FORWARD
2110 : state == STP_BLOCKING ? OFPUTIL_PS_STP_BLOCK
2112 ofproto_port_set_state(&ofport->up, of_state);
2116 /* Configures STP on 'ofport_' using the settings defined in 's'. The
2117 * caller is responsible for assigning STP port numbers and ensuring
2118 * there are no duplicates. */
2120 set_stp_port(struct ofport *ofport_,
2121 const struct ofproto_port_stp_settings *s)
2123 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2124 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2125 struct stp_port *sp = ofport->stp_port;
2127 if (!s || !s->enable) {
2129 ofport->stp_port = NULL;
2130 stp_port_disable(sp);
2131 update_stp_port_state(ofport);
2134 } else if (sp && stp_port_no(sp) != s->port_num
2135 && ofport == stp_port_get_aux(sp)) {
2136 /* The port-id changed, so disable the old one if it's not
2137 * already in use by another port. */
2138 stp_port_disable(sp);
2141 sp = ofport->stp_port = stp_get_port(ofproto->stp, s->port_num);
2142 stp_port_enable(sp);
2144 stp_port_set_aux(sp, ofport);
2145 stp_port_set_priority(sp, s->priority);
2146 stp_port_set_path_cost(sp, s->path_cost);
2148 update_stp_port_state(ofport);
2154 get_stp_port_status(struct ofport *ofport_,
2155 struct ofproto_port_stp_status *s)
2157 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2158 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2159 struct stp_port *sp = ofport->stp_port;
2161 if (!ofproto->stp || !sp) {
2167 s->port_id = stp_port_get_id(sp);
2168 s->state = stp_port_get_state(sp);
2169 s->sec_in_state = (time_msec() - ofport->stp_state_entered) / 1000;
2170 s->role = stp_port_get_role(sp);
2171 stp_port_get_counts(sp, &s->tx_count, &s->rx_count, &s->error_count);
2177 stp_run(struct ofproto_dpif *ofproto)
2180 long long int now = time_msec();
2181 long long int elapsed = now - ofproto->stp_last_tick;
2182 struct stp_port *sp;
2185 stp_tick(ofproto->stp, MIN(INT_MAX, elapsed));
2186 ofproto->stp_last_tick = now;
2188 while (stp_get_changed_port(ofproto->stp, &sp)) {
2189 struct ofport_dpif *ofport = stp_port_get_aux(sp);
2192 update_stp_port_state(ofport);
2196 if (stp_check_and_reset_fdb_flush(ofproto->stp)) {
2197 mac_learning_flush(ofproto->ml, &ofproto->backer->revalidate_set);
2203 stp_wait(struct ofproto_dpif *ofproto)
2206 poll_timer_wait(1000);
2210 /* Returns true if STP should process 'flow'. Sets fields in 'wc' that
2211 * were used to make the determination.*/
2213 stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc)
2215 memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
2216 return eth_addr_equals(flow->dl_dst, eth_addr_stp);
2220 stp_process_packet(const struct ofport_dpif *ofport,
2221 const struct ofpbuf *packet)
2223 struct ofpbuf payload = *packet;
2224 struct eth_header *eth = payload.data;
2225 struct stp_port *sp = ofport->stp_port;
2227 /* Sink packets on ports that have STP disabled when the bridge has
2229 if (!sp || stp_port_get_state(sp) == STP_DISABLED) {
2233 /* Trim off padding on payload. */
2234 if (payload.size > ntohs(eth->eth_type) + ETH_HEADER_LEN) {
2235 payload.size = ntohs(eth->eth_type) + ETH_HEADER_LEN;
2238 if (ofpbuf_try_pull(&payload, ETH_HEADER_LEN + LLC_HEADER_LEN)) {
2239 stp_received_bpdu(sp, payload.data, payload.size);
2244 ofproto_dpif_queue_to_priority(const struct ofproto_dpif *ofproto,
2245 uint32_t queue_id, uint32_t *priority)
2247 return dpif_queue_to_priority(ofproto->backer->dpif, queue_id, priority);
2250 static struct priority_to_dscp *
2251 get_priority(const struct ofport_dpif *ofport, uint32_t priority)
2253 struct priority_to_dscp *pdscp;
2256 hash = hash_int(priority, 0);
2257 HMAP_FOR_EACH_IN_BUCKET (pdscp, hmap_node, hash, &ofport->priorities) {
2258 if (pdscp->priority == priority) {
2266 ofproto_dpif_dscp_from_priority(const struct ofport_dpif *ofport,
2267 uint32_t priority, uint8_t *dscp)
2269 struct priority_to_dscp *pdscp = get_priority(ofport, priority);
2270 *dscp = pdscp ? pdscp->dscp : 0;
2271 return pdscp != NULL;
2275 ofport_clear_priorities(struct ofport_dpif *ofport)
2277 struct priority_to_dscp *pdscp, *next;
2279 HMAP_FOR_EACH_SAFE (pdscp, next, hmap_node, &ofport->priorities) {
2280 hmap_remove(&ofport->priorities, &pdscp->hmap_node);
2286 set_queues(struct ofport *ofport_,
2287 const struct ofproto_port_queue *qdscp_list,
2290 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
2291 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2292 struct hmap new = HMAP_INITIALIZER(&new);
2295 for (i = 0; i < n_qdscp; i++) {
2296 struct priority_to_dscp *pdscp;
2300 dscp = (qdscp_list[i].dscp << 2) & IP_DSCP_MASK;
2301 if (dpif_queue_to_priority(ofproto->backer->dpif, qdscp_list[i].queue,
2306 pdscp = get_priority(ofport, priority);
2308 hmap_remove(&ofport->priorities, &pdscp->hmap_node);
2310 pdscp = xmalloc(sizeof *pdscp);
2311 pdscp->priority = priority;
2313 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2316 if (pdscp->dscp != dscp) {
2318 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2321 hmap_insert(&new, &pdscp->hmap_node, hash_int(pdscp->priority, 0));
2324 if (!hmap_is_empty(&ofport->priorities)) {
2325 ofport_clear_priorities(ofport);
2326 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2329 hmap_swap(&new, &ofport->priorities);
2337 /* Expires all MAC learning entries associated with 'bundle' and forces its
2338 * ofproto to revalidate every flow.
2340 * Normally MAC learning entries are removed only from the ofproto associated
2341 * with 'bundle', but if 'all_ofprotos' is true, then the MAC learning entries
2342 * are removed from every ofproto. When patch ports and SLB bonds are in use
2343 * and a VM migration happens and the gratuitous ARPs are somehow lost, this
2344 * avoids a MAC_ENTRY_IDLE_TIME delay before the migrated VM can communicate
2345 * with the host from which it migrated. */
2347 bundle_flush_macs(struct ofbundle *bundle, bool all_ofprotos)
2349 struct ofproto_dpif *ofproto = bundle->ofproto;
2350 struct mac_learning *ml = ofproto->ml;
2351 struct mac_entry *mac, *next_mac;
2353 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2354 LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) {
2355 if (mac->port.p == bundle) {
2357 struct ofproto_dpif *o;
2359 HMAP_FOR_EACH (o, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
2361 struct mac_entry *e;
2363 e = mac_learning_lookup(o->ml, mac->mac, mac->vlan,
2366 mac_learning_expire(o->ml, e);
2372 mac_learning_expire(ml, mac);
2377 static struct ofbundle *
2378 bundle_lookup(const struct ofproto_dpif *ofproto, void *aux)
2380 struct ofbundle *bundle;
2382 HMAP_FOR_EACH_IN_BUCKET (bundle, hmap_node, hash_pointer(aux, 0),
2383 &ofproto->bundles) {
2384 if (bundle->aux == aux) {
2392 bundle_update(struct ofbundle *bundle)
2394 struct ofport_dpif *port;
2396 bundle->floodable = true;
2397 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2398 if (port->up.pp.config & OFPUTIL_PC_NO_FLOOD
2399 || !stp_forward_in_state(port->stp_state)) {
2400 bundle->floodable = false;
2407 bundle_del_port(struct ofport_dpif *port)
2409 struct ofbundle *bundle = port->bundle;
2411 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2413 list_remove(&port->bundle_node);
2414 port->bundle = NULL;
2417 lacp_slave_unregister(bundle->lacp, port);
2420 bond_slave_unregister(bundle->bond, port);
2423 bundle_update(bundle);
2427 bundle_add_port(struct ofbundle *bundle, ofp_port_t ofp_port,
2428 struct lacp_slave_settings *lacp)
2430 struct ofport_dpif *port;
2432 port = get_ofp_port(bundle->ofproto, ofp_port);
2437 if (port->bundle != bundle) {
2438 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2440 bundle_del_port(port);
2443 port->bundle = bundle;
2444 list_push_back(&bundle->ports, &port->bundle_node);
2445 if (port->up.pp.config & OFPUTIL_PC_NO_FLOOD
2446 || !stp_forward_in_state(port->stp_state)) {
2447 bundle->floodable = false;
2451 bundle->ofproto->backer->need_revalidate = REV_RECONFIGURE;
2452 lacp_slave_register(bundle->lacp, port, lacp);
2459 bundle_destroy(struct ofbundle *bundle)
2461 struct ofproto_dpif *ofproto;
2462 struct ofport_dpif *port, *next_port;
2468 ofproto = bundle->ofproto;
2469 mbridge_unregister_bundle(ofproto->mbridge, bundle->aux);
2471 xlate_bundle_remove(bundle);
2473 LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) {
2474 bundle_del_port(port);
2477 bundle_flush_macs(bundle, true);
2478 hmap_remove(&ofproto->bundles, &bundle->hmap_node);
2480 free(bundle->trunks);
2481 lacp_unref(bundle->lacp);
2482 bond_unref(bundle->bond);
2487 bundle_set(struct ofproto *ofproto_, void *aux,
2488 const struct ofproto_bundle_settings *s)
2490 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2491 bool need_flush = false;
2492 struct ofport_dpif *port;
2493 struct ofbundle *bundle;
2494 unsigned long *trunks;
2500 bundle_destroy(bundle_lookup(ofproto, aux));
2504 ovs_assert(s->n_slaves == 1 || s->bond != NULL);
2505 ovs_assert((s->lacp != NULL) == (s->lacp_slaves != NULL));
2507 bundle = bundle_lookup(ofproto, aux);
2509 bundle = xmalloc(sizeof *bundle);
2511 bundle->ofproto = ofproto;
2512 hmap_insert(&ofproto->bundles, &bundle->hmap_node,
2513 hash_pointer(aux, 0));
2515 bundle->name = NULL;
2517 list_init(&bundle->ports);
2518 bundle->vlan_mode = PORT_VLAN_TRUNK;
2520 bundle->trunks = NULL;
2521 bundle->use_priority_tags = s->use_priority_tags;
2522 bundle->lacp = NULL;
2523 bundle->bond = NULL;
2525 bundle->floodable = true;
2526 mbridge_register_bundle(ofproto->mbridge, bundle);
2529 if (!bundle->name || strcmp(s->name, bundle->name)) {
2531 bundle->name = xstrdup(s->name);
2536 if (!bundle->lacp) {
2537 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2538 bundle->lacp = lacp_create();
2540 lacp_configure(bundle->lacp, s->lacp);
2542 lacp_unref(bundle->lacp);
2543 bundle->lacp = NULL;
2546 /* Update set of ports. */
2548 for (i = 0; i < s->n_slaves; i++) {
2549 if (!bundle_add_port(bundle, s->slaves[i],
2550 s->lacp ? &s->lacp_slaves[i] : NULL)) {
2554 if (!ok || list_size(&bundle->ports) != s->n_slaves) {
2555 struct ofport_dpif *next_port;
2557 LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) {
2558 for (i = 0; i < s->n_slaves; i++) {
2559 if (s->slaves[i] == port->up.ofp_port) {
2564 bundle_del_port(port);
2568 ovs_assert(list_size(&bundle->ports) <= s->n_slaves);
2570 if (list_is_empty(&bundle->ports)) {
2571 bundle_destroy(bundle);
2575 /* Set VLAN tagging mode */
2576 if (s->vlan_mode != bundle->vlan_mode
2577 || s->use_priority_tags != bundle->use_priority_tags) {
2578 bundle->vlan_mode = s->vlan_mode;
2579 bundle->use_priority_tags = s->use_priority_tags;
2584 vlan = (s->vlan_mode == PORT_VLAN_TRUNK ? -1
2585 : s->vlan >= 0 && s->vlan <= 4095 ? s->vlan
2587 if (vlan != bundle->vlan) {
2588 bundle->vlan = vlan;
2592 /* Get trunked VLANs. */
2593 switch (s->vlan_mode) {
2594 case PORT_VLAN_ACCESS:
2598 case PORT_VLAN_TRUNK:
2599 trunks = CONST_CAST(unsigned long *, s->trunks);
2602 case PORT_VLAN_NATIVE_UNTAGGED:
2603 case PORT_VLAN_NATIVE_TAGGED:
2604 if (vlan != 0 && (!s->trunks
2605 || !bitmap_is_set(s->trunks, vlan)
2606 || bitmap_is_set(s->trunks, 0))) {
2607 /* Force trunking the native VLAN and prohibit trunking VLAN 0. */
2609 trunks = bitmap_clone(s->trunks, 4096);
2611 trunks = bitmap_allocate1(4096);
2613 bitmap_set1(trunks, vlan);
2614 bitmap_set0(trunks, 0);
2616 trunks = CONST_CAST(unsigned long *, s->trunks);
2623 if (!vlan_bitmap_equal(trunks, bundle->trunks)) {
2624 free(bundle->trunks);
2625 if (trunks == s->trunks) {
2626 bundle->trunks = vlan_bitmap_clone(trunks);
2628 bundle->trunks = trunks;
2633 if (trunks != s->trunks) {
2638 if (!list_is_short(&bundle->ports)) {
2639 bundle->ofproto->has_bonded_bundles = true;
2641 if (bond_reconfigure(bundle->bond, s->bond)) {
2642 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2645 bundle->bond = bond_create(s->bond);
2646 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2649 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2650 bond_slave_register(bundle->bond, port, port->up.netdev);
2653 bond_unref(bundle->bond);
2654 bundle->bond = NULL;
2657 /* If we changed something that would affect MAC learning, un-learn
2658 * everything on this port and force flow revalidation. */
2660 bundle_flush_macs(bundle, false);
2667 bundle_remove(struct ofport *port_)
2669 struct ofport_dpif *port = ofport_dpif_cast(port_);
2670 struct ofbundle *bundle = port->bundle;
2673 bundle_del_port(port);
2674 if (list_is_empty(&bundle->ports)) {
2675 bundle_destroy(bundle);
2676 } else if (list_is_short(&bundle->ports)) {
2677 bond_unref(bundle->bond);
2678 bundle->bond = NULL;
2684 send_pdu_cb(void *port_, const void *pdu, size_t pdu_size)
2686 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 10);
2687 struct ofport_dpif *port = port_;
2688 uint8_t ea[ETH_ADDR_LEN];
2691 error = netdev_get_etheraddr(port->up.netdev, ea);
2693 struct ofpbuf packet;
2696 ofpbuf_init(&packet, 0);
2697 packet_pdu = eth_compose(&packet, eth_addr_lacp, ea, ETH_TYPE_LACP,
2699 memcpy(packet_pdu, pdu, pdu_size);
2701 send_packet(port, &packet);
2702 ofpbuf_uninit(&packet);
2704 VLOG_ERR_RL(&rl, "port %s: cannot obtain Ethernet address of iface "
2705 "%s (%s)", port->bundle->name,
2706 netdev_get_name(port->up.netdev), ovs_strerror(error));
2711 bundle_send_learning_packets(struct ofbundle *bundle)
2713 struct ofproto_dpif *ofproto = bundle->ofproto;
2714 int error, n_packets, n_errors;
2715 struct mac_entry *e;
2717 error = n_packets = n_errors = 0;
2718 LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
2719 if (e->port.p != bundle) {
2720 struct ofpbuf *learning_packet;
2721 struct ofport_dpif *port;
2725 /* The assignment to "port" is unnecessary but makes "grep"ing for
2726 * struct ofport_dpif more effective. */
2727 learning_packet = bond_compose_learning_packet(bundle->bond,
2731 ret = send_packet(port, learning_packet);
2732 ofpbuf_delete(learning_packet);
2742 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
2743 VLOG_WARN_RL(&rl, "bond %s: %d errors sending %d gratuitous learning "
2744 "packets, last error was: %s",
2745 bundle->name, n_errors, n_packets, ovs_strerror(error));
2747 VLOG_DBG("bond %s: sent %d gratuitous learning packets",
2748 bundle->name, n_packets);
2753 bundle_run(struct ofbundle *bundle)
2756 lacp_run(bundle->lacp, send_pdu_cb);
2759 struct ofport_dpif *port;
2761 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
2762 bond_slave_set_may_enable(bundle->bond, port, port->may_enable);
2765 bond_run(bundle->bond, &bundle->ofproto->backer->revalidate_set,
2766 lacp_status(bundle->lacp));
2767 if (bond_should_send_learning_packets(bundle->bond)) {
2768 bundle_send_learning_packets(bundle);
2774 bundle_wait(struct ofbundle *bundle)
2777 lacp_wait(bundle->lacp);
2780 bond_wait(bundle->bond);
2787 mirror_set__(struct ofproto *ofproto_, void *aux,
2788 const struct ofproto_mirror_settings *s)
2790 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2791 struct ofbundle **srcs, **dsts;
2796 mirror_destroy(ofproto->mbridge, aux);
2800 srcs = xmalloc(s->n_srcs * sizeof *srcs);
2801 dsts = xmalloc(s->n_dsts * sizeof *dsts);
2803 for (i = 0; i < s->n_srcs; i++) {
2804 srcs[i] = bundle_lookup(ofproto, s->srcs[i]);
2807 for (i = 0; i < s->n_dsts; i++) {
2808 dsts[i] = bundle_lookup(ofproto, s->dsts[i]);
2811 error = mirror_set(ofproto->mbridge, aux, s->name, srcs, s->n_srcs, dsts,
2812 s->n_dsts, s->src_vlans,
2813 bundle_lookup(ofproto, s->out_bundle), s->out_vlan);
2820 mirror_get_stats__(struct ofproto *ofproto, void *aux,
2821 uint64_t *packets, uint64_t *bytes)
2824 return mirror_get_stats(ofproto_dpif_cast(ofproto)->mbridge, aux, packets,
2829 set_flood_vlans(struct ofproto *ofproto_, unsigned long *flood_vlans)
2831 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2832 if (mac_learning_set_flood_vlans(ofproto->ml, flood_vlans)) {
2833 mac_learning_flush(ofproto->ml, &ofproto->backer->revalidate_set);
2839 is_mirror_output_bundle(const struct ofproto *ofproto_, void *aux)
2841 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2842 struct ofbundle *bundle = bundle_lookup(ofproto, aux);
2843 return bundle && mirror_bundle_out(ofproto->mbridge, bundle) != 0;
2847 forward_bpdu_changed(struct ofproto *ofproto_)
2849 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2850 ofproto->backer->need_revalidate = REV_RECONFIGURE;
2854 set_mac_table_config(struct ofproto *ofproto_, unsigned int idle_time,
2857 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
2858 mac_learning_set_idle_time(ofproto->ml, idle_time);
2859 mac_learning_set_max_entries(ofproto->ml, max_entries);
2864 static struct ofport_dpif *
2865 get_ofp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port)
2867 struct ofport *ofport = ofproto_get_port(&ofproto->up, ofp_port);
2868 return ofport ? ofport_dpif_cast(ofport) : NULL;
2871 static struct ofport_dpif *
2872 get_odp_port(const struct ofproto_dpif *ofproto, odp_port_t odp_port)
2874 struct ofport_dpif *port = odp_port_to_ofport(ofproto->backer, odp_port);
2875 return port && &ofproto->up == port->up.ofproto ? port : NULL;
2879 ofproto_port_from_dpif_port(struct ofproto_dpif *ofproto,
2880 struct ofproto_port *ofproto_port,
2881 struct dpif_port *dpif_port)
2883 ofproto_port->name = dpif_port->name;
2884 ofproto_port->type = dpif_port->type;
2885 ofproto_port->ofp_port = odp_port_to_ofp_port(ofproto, dpif_port->port_no);
2889 ofport_update_peer(struct ofport_dpif *ofport)
2891 const struct ofproto_dpif *ofproto;
2892 struct dpif_backer *backer;
2893 const char *peer_name;
2895 if (!netdev_vport_is_patch(ofport->up.netdev)) {
2899 backer = ofproto_dpif_cast(ofport->up.ofproto)->backer;
2900 backer->need_revalidate = REV_RECONFIGURE;
2903 ofport->peer->peer = NULL;
2904 ofport->peer = NULL;
2907 peer_name = netdev_vport_patch_peer(ofport->up.netdev);
2912 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
2913 struct ofport *peer_ofport;
2914 struct ofport_dpif *peer;
2915 const char *peer_peer;
2917 if (ofproto->backer != backer) {
2921 peer_ofport = shash_find_data(&ofproto->up.port_by_name, peer_name);
2926 peer = ofport_dpif_cast(peer_ofport);
2927 peer_peer = netdev_vport_patch_peer(peer->up.netdev);
2928 if (peer_peer && !strcmp(netdev_get_name(ofport->up.netdev),
2930 ofport->peer = peer;
2931 ofport->peer->peer = ofport;
2939 port_run_fast(struct ofport_dpif *ofport)
2941 if (ofport->cfm && cfm_should_send_ccm(ofport->cfm)) {
2942 struct ofpbuf packet;
2944 ofpbuf_init(&packet, 0);
2945 cfm_compose_ccm(ofport->cfm, &packet, ofport->up.pp.hw_addr);
2946 send_packet(ofport, &packet);
2947 ofpbuf_uninit(&packet);
2950 if (ofport->bfd && bfd_should_send_packet(ofport->bfd)) {
2951 struct ofpbuf packet;
2953 ofpbuf_init(&packet, 0);
2954 bfd_put_packet(ofport->bfd, &packet, ofport->up.pp.hw_addr);
2955 send_packet(ofport, &packet);
2956 ofpbuf_uninit(&packet);
2961 port_run(struct ofport_dpif *ofport)
2963 long long int carrier_seq = netdev_get_carrier_resets(ofport->up.netdev);
2964 bool carrier_changed = carrier_seq != ofport->carrier_seq;
2965 bool enable = netdev_get_carrier(ofport->up.netdev);
2967 ofport->carrier_seq = carrier_seq;
2969 port_run_fast(ofport);
2972 int cfm_opup = cfm_get_opup(ofport->cfm);
2974 cfm_run(ofport->cfm);
2975 enable = enable && !cfm_get_fault(ofport->cfm);
2977 if (cfm_opup >= 0) {
2978 enable = enable && cfm_opup;
2983 bfd_run(ofport->bfd);
2984 enable = enable && bfd_forwarding(ofport->bfd);
2987 if (ofport->bundle) {
2988 enable = enable && lacp_slave_may_enable(ofport->bundle->lacp, ofport);
2989 if (carrier_changed) {
2990 lacp_slave_carrier_changed(ofport->bundle->lacp, ofport);
2994 if (ofport->may_enable != enable) {
2995 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
2996 ofproto->backer->need_revalidate = REV_PORT_TOGGLED;
2999 ofport->may_enable = enable;
3003 port_wait(struct ofport_dpif *ofport)
3006 cfm_wait(ofport->cfm);
3010 bfd_wait(ofport->bfd);
3015 port_query_by_name(const struct ofproto *ofproto_, const char *devname,
3016 struct ofproto_port *ofproto_port)
3018 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3019 struct dpif_port dpif_port;
3022 if (sset_contains(&ofproto->ghost_ports, devname)) {
3023 const char *type = netdev_get_type_from_name(devname);
3025 /* We may be called before ofproto->up.port_by_name is populated with
3026 * the appropriate ofport. For this reason, we must get the name and
3027 * type from the netdev layer directly. */
3029 const struct ofport *ofport;
3031 ofport = shash_find_data(&ofproto->up.port_by_name, devname);
3032 ofproto_port->ofp_port = ofport ? ofport->ofp_port : OFPP_NONE;
3033 ofproto_port->name = xstrdup(devname);
3034 ofproto_port->type = xstrdup(type);
3040 if (!sset_contains(&ofproto->ports, devname)) {
3043 error = dpif_port_query_by_name(ofproto->backer->dpif,
3044 devname, &dpif_port);
3046 ofproto_port_from_dpif_port(ofproto, ofproto_port, &dpif_port);
3052 port_add(struct ofproto *ofproto_, struct netdev *netdev)
3054 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3055 const char *devname = netdev_get_name(netdev);
3056 char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
3057 const char *dp_port_name;
3059 if (netdev_vport_is_patch(netdev)) {
3060 sset_add(&ofproto->ghost_ports, netdev_get_name(netdev));
3064 dp_port_name = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf);
3065 if (!dpif_port_exists(ofproto->backer->dpif, dp_port_name)) {
3066 odp_port_t port_no = ODPP_NONE;
3069 error = dpif_port_add(ofproto->backer->dpif, netdev, &port_no);
3073 if (netdev_get_tunnel_config(netdev)) {
3074 simap_put(&ofproto->backer->tnl_backers,
3075 dp_port_name, odp_to_u32(port_no));
3079 if (netdev_get_tunnel_config(netdev)) {
3080 sset_add(&ofproto->ghost_ports, devname);
3082 sset_add(&ofproto->ports, devname);
3088 port_del(struct ofproto *ofproto_, ofp_port_t ofp_port)
3090 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3091 struct ofport_dpif *ofport = get_ofp_port(ofproto, ofp_port);
3098 sset_find_and_delete(&ofproto->ghost_ports,
3099 netdev_get_name(ofport->up.netdev));
3100 ofproto->backer->need_revalidate = REV_RECONFIGURE;
3101 if (!ofport->is_tunnel) {
3102 error = dpif_port_del(ofproto->backer->dpif, ofport->odp_port);
3104 /* The caller is going to close ofport->up.netdev. If this is a
3105 * bonded port, then the bond is using that netdev, so remove it
3106 * from the bond. The client will need to reconfigure everything
3107 * after deleting ports, so then the slave will get re-added. */
3108 bundle_remove(&ofport->up);
3115 port_get_stats(const struct ofport *ofport_, struct netdev_stats *stats)
3117 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
3122 error = netdev_get_stats(ofport->up.netdev, stats);
3124 if (!error && ofport_->ofp_port == OFPP_LOCAL) {
3125 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
3127 /* ofproto->stats.tx_packets represents packets that we created
3128 * internally and sent to some port (e.g. packets sent with
3129 * send_packet()). Account for them as if they had come from
3130 * OFPP_LOCAL and got forwarded. */
3132 if (stats->rx_packets != UINT64_MAX) {
3133 stats->rx_packets += ofproto->stats.tx_packets;
3136 if (stats->rx_bytes != UINT64_MAX) {
3137 stats->rx_bytes += ofproto->stats.tx_bytes;
3140 /* ofproto->stats.rx_packets represents packets that were received on
3141 * some port and we processed internally and dropped (e.g. STP).
3142 * Account for them as if they had been forwarded to OFPP_LOCAL. */
3144 if (stats->tx_packets != UINT64_MAX) {
3145 stats->tx_packets += ofproto->stats.rx_packets;
3148 if (stats->tx_bytes != UINT64_MAX) {
3149 stats->tx_bytes += ofproto->stats.rx_bytes;
3156 struct port_dump_state {
3161 struct ofproto_port port;
3166 port_dump_start(const struct ofproto *ofproto_ OVS_UNUSED, void **statep)
3168 *statep = xzalloc(sizeof(struct port_dump_state));
3173 port_dump_next(const struct ofproto *ofproto_, void *state_,
3174 struct ofproto_port *port)
3176 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3177 struct port_dump_state *state = state_;
3178 const struct sset *sset;
3179 struct sset_node *node;
3181 if (state->has_port) {
3182 ofproto_port_destroy(&state->port);
3183 state->has_port = false;
3185 sset = state->ghost ? &ofproto->ghost_ports : &ofproto->ports;
3186 while ((node = sset_at_position(sset, &state->bucket, &state->offset))) {
3189 error = port_query_by_name(ofproto_, node->name, &state->port);
3191 *port = state->port;
3192 state->has_port = true;
3194 } else if (error != ENODEV) {
3199 if (!state->ghost) {
3200 state->ghost = true;
3203 return port_dump_next(ofproto_, state_, port);
3210 port_dump_done(const struct ofproto *ofproto_ OVS_UNUSED, void *state_)
3212 struct port_dump_state *state = state_;
3214 if (state->has_port) {
3215 ofproto_port_destroy(&state->port);
3222 port_poll(const struct ofproto *ofproto_, char **devnamep)
3224 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3226 if (ofproto->port_poll_errno) {
3227 int error = ofproto->port_poll_errno;
3228 ofproto->port_poll_errno = 0;
3232 if (sset_is_empty(&ofproto->port_poll_set)) {
3236 *devnamep = sset_pop(&ofproto->port_poll_set);
3241 port_poll_wait(const struct ofproto *ofproto_)
3243 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
3244 dpif_port_poll_wait(ofproto->backer->dpif);
3248 port_is_lacp_current(const struct ofport *ofport_)
3250 const struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
3251 return (ofport->bundle && ofport->bundle->lacp
3252 ? lacp_slave_is_current(ofport->bundle->lacp, ofport)
3256 /* Upcall handling. */
3258 /* Flow miss batching.
3260 * Some dpifs implement operations faster when you hand them off in a batch.
3261 * To allow batching, "struct flow_miss" queues the dpif-related work needed
3262 * for a given flow. Each "struct flow_miss" corresponds to sending one or
3263 * more packets, plus possibly installing the flow in the dpif.
3265 * So far we only batch the operations that affect flow setup time the most.
3266 * It's possible to batch more than that, but the benefit might be minimal. */
3268 struct hmap_node hmap_node;
3269 struct ofproto_dpif *ofproto;
3271 enum odp_key_fitness key_fitness;
3272 const struct nlattr *key;
3274 struct list packets;
3275 enum dpif_upcall_type upcall_type;
3278 struct flow_miss_op {
3279 struct dpif_op dpif_op;
3281 uint64_t slow_stub[128 / 8]; /* Buffer for compose_slow_path() */
3282 struct xlate_out xout;
3283 bool xout_garbage; /* 'xout' needs to be uninitialized? */
3285 struct ofpbuf mask; /* Flow mask for "put" ops. */
3286 struct odputil_keybuf maskbuf;
3288 /* If this is a "put" op, then a pointer to the subfacet that should
3289 * be marked as uninstalled if the operation fails. */
3290 struct subfacet *subfacet;
3293 /* Sends an OFPT_PACKET_IN message for 'packet' of type OFPR_NO_MATCH to each
3294 * OpenFlow controller as necessary according to their individual
3295 * configurations. */
3297 send_packet_in_miss(struct ofproto_dpif *ofproto, const struct ofpbuf *packet,
3298 const struct flow *flow)
3300 struct ofputil_packet_in pin;
3302 pin.packet = packet->data;
3303 pin.packet_len = packet->size;
3304 pin.reason = OFPR_NO_MATCH;
3305 pin.controller_id = 0;
3310 pin.send_len = 0; /* not used for flow table misses */
3312 flow_get_metadata(flow, &pin.fmd);
3314 connmgr_send_packet_in(ofproto->up.connmgr, &pin);
3317 static struct flow_miss *
3318 flow_miss_find(struct hmap *todo, const struct ofproto_dpif *ofproto,
3319 const struct flow *flow, uint32_t hash)
3321 struct flow_miss *miss;
3323 HMAP_FOR_EACH_WITH_HASH (miss, hmap_node, hash, todo) {
3324 if (miss->ofproto == ofproto && flow_equal(&miss->flow, flow)) {
3332 /* Partially Initializes 'op' as an "execute" operation for 'miss' and
3333 * 'packet'. The caller must initialize op->actions and op->actions_len. If
3334 * 'miss' is associated with a subfacet the caller must also initialize the
3335 * returned op->subfacet, and if anything needs to be freed after processing
3336 * the op, the caller must initialize op->garbage also. */
3338 init_flow_miss_execute_op(struct flow_miss *miss, struct ofpbuf *packet,
3339 struct flow_miss_op *op)
3341 if (miss->flow.in_port.ofp_port
3342 != vsp_realdev_to_vlandev(miss->ofproto, miss->flow.in_port.ofp_port,
3343 miss->flow.vlan_tci)) {
3344 /* This packet was received on a VLAN splinter port. We
3345 * added a VLAN to the packet to make the packet resemble
3346 * the flow, but the actions were composed assuming that
3347 * the packet contained no VLAN. So, we must remove the
3348 * VLAN header from the packet before trying to execute the
3350 eth_pop_vlan(packet);
3353 op->subfacet = NULL;
3354 op->xout_garbage = false;
3355 op->dpif_op.type = DPIF_OP_EXECUTE;
3356 op->dpif_op.u.execute.key = miss->key;
3357 op->dpif_op.u.execute.key_len = miss->key_len;
3358 op->dpif_op.u.execute.packet = packet;
3359 ofpbuf_use_stack(&op->mask, &op->maskbuf, sizeof op->maskbuf);
3362 /* Helper for handle_flow_miss_without_facet() and
3363 * handle_flow_miss_with_facet(). */
3365 handle_flow_miss_common(struct ofproto_dpif *ofproto, struct ofpbuf *packet,
3366 const struct flow *flow, bool fail_open)
3370 * Extra-special case for fail-open mode.
3372 * We are in fail-open mode and the packet matched the fail-open
3373 * rule, but we are connected to a controller too. We should send
3374 * the packet up to the controller in the hope that it will try to
3375 * set up a flow and thereby allow us to exit fail-open.
3377 * See the top-level comment in fail-open.c for more information.
3379 send_packet_in_miss(ofproto, packet, flow);
3383 /* Figures out whether a flow that missed in 'ofproto', whose details are in
3384 * 'miss' masked by 'wc', is likely to be worth tracking in detail in userspace
3385 * and (usually) installing a datapath flow. The answer is usually "yes" (a
3386 * return value of true). However, for short flows the cost of bookkeeping is
3387 * much higher than the benefits, so when the datapath holds a large number of
3388 * flows we impose some heuristics to decide which flows are likely to be worth
3391 flow_miss_should_make_facet(struct flow_miss *miss, struct flow_wildcards *wc)
3393 struct dpif_backer *backer = miss->ofproto->backer;
3396 switch (flow_miss_model) {
3397 case OFPROTO_HANDLE_MISS_AUTO:
3399 case OFPROTO_HANDLE_MISS_WITH_FACETS:
3401 case OFPROTO_HANDLE_MISS_WITHOUT_FACETS:
3405 if (!backer->governor) {
3408 n_subfacets = hmap_count(&backer->subfacets);
3409 if (n_subfacets * 2 <= flow_eviction_threshold) {
3413 backer->governor = governor_create();
3416 hash = flow_hash_in_wildcards(&miss->flow, wc, 0);
3417 return governor_should_install_flow(backer->governor, hash,
3418 list_size(&miss->packets));
3421 /* Handles 'miss' without creating a facet or subfacet or creating any datapath
3422 * flow. 'miss->flow' must have matched 'rule' and been xlated into 'xout'.
3423 * May add an "execute" operation to 'ops' and increment '*n_ops'. */
3425 handle_flow_miss_without_facet(struct rule_dpif *rule, struct xlate_out *xout,
3426 struct flow_miss *miss,
3427 struct flow_miss_op *ops, size_t *n_ops)
3429 struct ofpbuf *packet;
3431 LIST_FOR_EACH (packet, list_node, &miss->packets) {
3433 COVERAGE_INC(facet_suppress);
3435 handle_flow_miss_common(miss->ofproto, packet, &miss->flow,
3436 rule->up.cr.priority == FAIL_OPEN_PRIORITY);
3439 struct xlate_in xin;
3441 xlate_in_init(&xin, miss->ofproto, &miss->flow, rule, 0, packet);
3442 xlate_actions_for_side_effects(&xin);
3445 if (xout->odp_actions.size) {
3446 struct flow_miss_op *op = &ops[*n_ops];
3447 struct dpif_execute *execute = &op->dpif_op.u.execute;
3449 init_flow_miss_execute_op(miss, packet, op);
3450 xlate_out_copy(&op->xout, xout);
3451 execute->actions = op->xout.odp_actions.data;
3452 execute->actions_len = op->xout.odp_actions.size;
3453 op->xout_garbage = true;
3460 /* Handles 'miss', which matches 'facet'. May add any required datapath
3461 * operations to 'ops', incrementing '*n_ops' for each new op.
3463 * All of the packets in 'miss' are considered to have arrived at time 'now'.
3464 * This is really important only for new facets: if we just called time_msec()
3465 * here, then the new subfacet or its packets could look (occasionally) as
3466 * though it was used some time after the facet was used. That can make a
3467 * one-packet flow look like it has a nonzero duration, which looks odd in
3468 * e.g. NetFlow statistics.
3470 * If non-null, 'stats' will be folded into 'facet'. */
3472 handle_flow_miss_with_facet(struct flow_miss *miss, struct facet *facet,
3473 long long int now, struct dpif_flow_stats *stats,
3474 struct flow_miss_op *ops, size_t *n_ops)
3476 enum subfacet_path want_path;
3477 struct subfacet *subfacet;
3478 struct ofpbuf *packet;
3480 want_path = facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
3482 LIST_FOR_EACH (packet, list_node, &miss->packets) {
3483 struct flow_miss_op *op = &ops[*n_ops];
3485 handle_flow_miss_common(miss->ofproto, packet, &miss->flow,
3488 if (want_path != SF_FAST_PATH) {
3489 struct rule_dpif *rule;
3490 struct xlate_in xin;
3492 rule = rule_dpif_lookup(facet->ofproto, &facet->flow, NULL);
3493 xlate_in_init(&xin, facet->ofproto, &miss->flow, rule, 0, packet);
3494 xlate_actions_for_side_effects(&xin);
3497 if (facet->xout.odp_actions.size) {
3498 struct dpif_execute *execute = &op->dpif_op.u.execute;
3500 init_flow_miss_execute_op(miss, packet, op);
3501 execute->actions = facet->xout.odp_actions.data,
3502 execute->actions_len = facet->xout.odp_actions.size;
3507 /* Don't install the flow if it's the result of the "userspace"
3508 * action for an already installed facet. This can occur when a
3509 * datapath flow with wildcards has a "userspace" action and flows
3510 * sent to userspace result in a different subfacet, which will then
3511 * be rejected as overlapping by the datapath. */
3512 if (miss->upcall_type == DPIF_UC_ACTION
3513 && !list_is_empty(&facet->subfacets)) {
3515 facet->used = MAX(facet->used, stats->used);
3516 facet->packet_count += stats->n_packets;
3517 facet->byte_count += stats->n_bytes;
3518 facet->tcp_flags |= stats->tcp_flags;
3523 subfacet = subfacet_create(facet, miss, now);
3525 subfacet_update_stats(subfacet, stats);
3528 if (miss->upcall_type == DPIF_UC_MISS || subfacet->path != want_path) {
3529 struct flow_miss_op *op = &ops[(*n_ops)++];
3530 struct dpif_flow_put *put = &op->dpif_op.u.flow_put;
3532 subfacet->path = want_path;
3534 ofpbuf_use_stack(&op->mask, &op->maskbuf, sizeof op->maskbuf);
3535 if (enable_megaflows) {
3536 odp_flow_key_from_mask(&op->mask, &facet->xout.wc.masks,
3537 &miss->flow, UINT32_MAX);
3540 op->xout_garbage = false;
3541 op->dpif_op.type = DPIF_OP_FLOW_PUT;
3542 op->subfacet = subfacet;
3543 put->flags = DPIF_FP_CREATE;
3544 put->key = miss->key;
3545 put->key_len = miss->key_len;
3546 put->mask = op->mask.data;
3547 put->mask_len = op->mask.size;
3549 if (want_path == SF_FAST_PATH) {
3550 put->actions = facet->xout.odp_actions.data;
3551 put->actions_len = facet->xout.odp_actions.size;
3553 compose_slow_path(facet->ofproto, &miss->flow, facet->xout.slow,
3554 op->slow_stub, sizeof op->slow_stub,
3555 &put->actions, &put->actions_len);
3561 /* Handles flow miss 'miss'. May add any required datapath operations
3562 * to 'ops', incrementing '*n_ops' for each new op. */
3564 handle_flow_miss(struct flow_miss *miss, struct flow_miss_op *ops,
3567 struct ofproto_dpif *ofproto = miss->ofproto;
3568 struct dpif_flow_stats stats__;
3569 struct dpif_flow_stats *stats = &stats__;
3570 struct ofpbuf *packet;
3571 struct facet *facet;
3575 memset(stats, 0, sizeof *stats);
3577 LIST_FOR_EACH (packet, list_node, &miss->packets) {
3578 stats->tcp_flags |= packet_get_tcp_flags(packet, &miss->flow);
3579 stats->n_bytes += packet->size;
3583 facet = facet_lookup_valid(ofproto, &miss->flow);
3585 struct flow_wildcards wc;
3586 struct rule_dpif *rule;
3587 struct xlate_out xout;
3588 struct xlate_in xin;
3590 flow_wildcards_init_catchall(&wc);
3591 rule = rule_dpif_lookup(ofproto, &miss->flow, &wc);
3592 rule_credit_stats(rule, stats);
3594 xlate_in_init(&xin, ofproto, &miss->flow, rule, stats->tcp_flags,
3596 xin.resubmit_stats = stats;
3597 xin.may_learn = true;
3598 xlate_actions(&xin, &xout);
3599 flow_wildcards_or(&xout.wc, &xout.wc, &wc);
3601 /* There does not exist a bijection between 'struct flow' and datapath
3602 * flow keys with fitness ODP_FIT_TO_LITTLE. This breaks a fundamental
3603 * assumption used throughout the facet and subfacet handling code.
3604 * Since we have to handle these misses in userspace anyway, we simply
3605 * skip facet creation, avoiding the problem altogether. */
3606 if (miss->key_fitness == ODP_FIT_TOO_LITTLE
3607 || !flow_miss_should_make_facet(miss, &xout.wc)) {
3608 handle_flow_miss_without_facet(rule, &xout, miss, ops, n_ops);
3612 facet = facet_create(miss, rule, &xout, stats);
3615 handle_flow_miss_with_facet(miss, facet, now, stats, ops, n_ops);
3618 static struct drop_key *
3619 drop_key_lookup(const struct dpif_backer *backer, const struct nlattr *key,
3622 struct drop_key *drop_key;
3624 HMAP_FOR_EACH_WITH_HASH (drop_key, hmap_node, hash_bytes(key, key_len, 0),
3625 &backer->drop_keys) {
3626 if (drop_key->key_len == key_len
3627 && !memcmp(drop_key->key, key, key_len)) {
3635 drop_key_clear(struct dpif_backer *backer)
3637 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 15);
3638 struct drop_key *drop_key, *next;
3640 HMAP_FOR_EACH_SAFE (drop_key, next, hmap_node, &backer->drop_keys) {
3643 error = dpif_flow_del(backer->dpif, drop_key->key, drop_key->key_len,
3645 if (error && !VLOG_DROP_WARN(&rl)) {
3646 struct ds ds = DS_EMPTY_INITIALIZER;
3647 odp_flow_key_format(drop_key->key, drop_key->key_len, &ds);
3648 VLOG_WARN("Failed to delete drop key (%s) (%s)",
3649 ovs_strerror(error), ds_cstr(&ds));
3653 hmap_remove(&backer->drop_keys, &drop_key->hmap_node);
3654 free(drop_key->key);
3659 /* Given a datpath, packet, and flow metadata ('backer', 'packet', and 'key'
3660 * respectively), populates 'flow' with the result of odp_flow_key_to_flow().
3661 * Optionally, if nonnull, populates 'fitnessp' with the fitness of 'flow' as
3662 * returned by odp_flow_key_to_flow(). Also, optionally populates 'ofproto'
3663 * with the ofproto_dpif, and 'odp_in_port' with the datapath in_port, that
3664 * 'packet' ingressed.
3666 * If 'ofproto' is nonnull, requires 'flow''s in_port to exist. Otherwise sets
3667 * 'flow''s in_port to OFPP_NONE.
3669 * This function does post-processing on data returned from
3670 * odp_flow_key_to_flow() to help make VLAN splinters transparent to the rest
3671 * of the upcall processing logic. In particular, if the extracted in_port is
3672 * a VLAN splinter port, it replaces flow->in_port by the "real" port, sets
3673 * flow->vlan_tci correctly for the VLAN of the VLAN splinter port, and pushes
3674 * a VLAN header onto 'packet' (if it is nonnull).
3676 * Similarly, this function also includes some logic to help with tunnels. It
3677 * may modify 'flow' as necessary to make the tunneling implementation
3678 * transparent to the upcall processing logic.
3680 * Returns 0 if successful, ENODEV if the parsed flow has no associated ofport,
3681 * or some other positive errno if there are other problems. */
3683 ofproto_receive(const struct dpif_backer *backer, struct ofpbuf *packet,
3684 const struct nlattr *key, size_t key_len,
3685 struct flow *flow, enum odp_key_fitness *fitnessp,
3686 struct ofproto_dpif **ofproto, odp_port_t *odp_in_port)
3688 const struct ofport_dpif *port;
3689 enum odp_key_fitness fitness;
3692 fitness = odp_flow_key_to_flow(key, key_len, flow);
3693 if (fitness == ODP_FIT_ERROR) {
3699 *odp_in_port = flow->in_port.odp_port;
3702 port = (tnl_port_should_receive(flow)
3703 ? tnl_port_receive(flow)
3704 : odp_port_to_ofport(backer, flow->in_port.odp_port));
3705 flow->in_port.ofp_port = port ? port->up.ofp_port : OFPP_NONE;
3710 /* XXX: Since the tunnel module is not scoped per backer, for a tunnel port
3711 * it's theoretically possible that we'll receive an ofport belonging to an
3712 * entirely different datapath. In practice, this can't happen because no
3713 * platforms has two separate datapaths which each support tunneling. */
3714 ovs_assert(ofproto_dpif_cast(port->up.ofproto)->backer == backer);
3716 if (vsp_adjust_flow(ofproto_dpif_cast(port->up.ofproto), flow)) {
3718 /* Make the packet resemble the flow, so that it gets sent to
3719 * an OpenFlow controller properly, so that it looks correct
3720 * for sFlow, and so that flow_extract() will get the correct
3721 * vlan_tci if it is called on 'packet'.
3723 * The allocated space inside 'packet' probably also contains
3724 * 'key', that is, both 'packet' and 'key' are probably part of
3725 * a struct dpif_upcall (see the large comment on that
3726 * structure definition), so pushing data on 'packet' is in
3727 * general not a good idea since it could overwrite 'key' or
3728 * free it as a side effect. However, it's OK in this special
3729 * case because we know that 'packet' is inside a Netlink
3730 * attribute: pushing 4 bytes will just overwrite the 4-byte
3731 * "struct nlattr", which is fine since we don't need that
3732 * header anymore. */
3733 eth_push_vlan(packet, flow->vlan_tci);
3735 /* We can't reproduce 'key' from 'flow'. */
3736 fitness = fitness == ODP_FIT_PERFECT ? ODP_FIT_TOO_MUCH : fitness;
3741 *ofproto = ofproto_dpif_cast(port->up.ofproto);
3746 *fitnessp = fitness;
3752 handle_miss_upcalls(struct dpif_backer *backer, struct dpif_upcall *upcalls,
3755 struct dpif_upcall *upcall;
3756 struct flow_miss *miss;
3757 struct flow_miss misses[FLOW_MISS_MAX_BATCH];
3758 struct flow_miss_op flow_miss_ops[FLOW_MISS_MAX_BATCH * 2];
3759 struct dpif_op *dpif_ops[FLOW_MISS_MAX_BATCH * 2];
3769 /* Construct the to-do list.
3771 * This just amounts to extracting the flow from each packet and sticking
3772 * the packets that have the same flow in the same "flow_miss" structure so
3773 * that we can process them together. */
3776 for (upcall = upcalls; upcall < &upcalls[n_upcalls]; upcall++) {
3777 struct flow_miss *miss = &misses[n_misses];
3778 struct flow_miss *existing_miss;
3779 struct ofproto_dpif *ofproto;
3780 odp_port_t odp_in_port;
3785 error = ofproto_receive(backer, upcall->packet, upcall->key,
3786 upcall->key_len, &flow, &miss->key_fitness,
3787 &ofproto, &odp_in_port);
3788 if (error == ENODEV) {
3789 struct drop_key *drop_key;
3791 /* Received packet on datapath port for which we couldn't
3792 * associate an ofproto. This can happen if a port is removed
3793 * while traffic is being received. Print a rate-limited message
3794 * in case it happens frequently. Install a drop flow so
3795 * that future packets of the flow are inexpensively dropped
3797 VLOG_INFO_RL(&rl, "received packet on unassociated datapath port "
3798 "%"PRIu32, odp_in_port);
3800 drop_key = drop_key_lookup(backer, upcall->key, upcall->key_len);
3802 drop_key = xmalloc(sizeof *drop_key);
3803 drop_key->key = xmemdup(upcall->key, upcall->key_len);
3804 drop_key->key_len = upcall->key_len;
3806 hmap_insert(&backer->drop_keys, &drop_key->hmap_node,
3807 hash_bytes(drop_key->key, drop_key->key_len, 0));
3808 dpif_flow_put(backer->dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY,
3809 drop_key->key, drop_key->key_len,
3810 NULL, 0, NULL, 0, NULL);
3818 ofproto->n_missed++;
3819 flow_extract(upcall->packet, flow.skb_priority, flow.skb_mark,
3820 &flow.tunnel, &flow.in_port, &miss->flow);
3822 /* Add other packets to a to-do list. */
3823 hash = flow_hash(&miss->flow, 0);
3824 existing_miss = flow_miss_find(&todo, ofproto, &miss->flow, hash);
3825 if (!existing_miss) {
3826 hmap_insert(&todo, &miss->hmap_node, hash);
3827 miss->ofproto = ofproto;
3828 miss->key = upcall->key;
3829 miss->key_len = upcall->key_len;
3830 miss->upcall_type = upcall->type;
3831 list_init(&miss->packets);
3835 miss = existing_miss;
3837 list_push_back(&miss->packets, &upcall->packet->list_node);
3840 /* Process each element in the to-do list, constructing the set of
3841 * operations to batch. */
3843 HMAP_FOR_EACH (miss, hmap_node, &todo) {
3844 handle_flow_miss(miss, flow_miss_ops, &n_ops);
3846 ovs_assert(n_ops <= ARRAY_SIZE(flow_miss_ops));
3848 /* Execute batch. */
3849 for (i = 0; i < n_ops; i++) {
3850 dpif_ops[i] = &flow_miss_ops[i].dpif_op;
3852 dpif_operate(backer->dpif, dpif_ops, n_ops);
3854 for (i = 0; i < n_ops; i++) {
3855 if (dpif_ops[i]->error != 0
3856 && flow_miss_ops[i].dpif_op.type == DPIF_OP_FLOW_PUT
3857 && flow_miss_ops[i].subfacet) {
3858 struct subfacet *subfacet = flow_miss_ops[i].subfacet;
3860 COVERAGE_INC(subfacet_install_fail);
3862 /* Zero-out subfacet counters when installation failed, but
3863 * datapath reported hits. This should not happen and
3864 * indicates a bug, since if the datapath flow exists, we
3865 * should not be attempting to create a new subfacet. A
3866 * buggy datapath could trigger this, so just zero out the
3867 * counters and log an error. */
3868 if (subfacet->dp_packet_count || subfacet->dp_byte_count) {
3869 VLOG_ERR_RL(&rl, "failed to install subfacet for which "
3870 "datapath reported hits");
3871 subfacet->dp_packet_count = subfacet->dp_byte_count = 0;
3874 subfacet->path = SF_NOT_INSTALLED;
3878 if (flow_miss_ops[i].xout_garbage) {
3879 xlate_out_uninit(&flow_miss_ops[i].xout);
3882 hmap_destroy(&todo);
3885 static enum { SFLOW_UPCALL, MISS_UPCALL, BAD_UPCALL, FLOW_SAMPLE_UPCALL,
3887 classify_upcall(const struct dpif_upcall *upcall)
3889 size_t userdata_len;
3890 union user_action_cookie cookie;
3892 /* First look at the upcall type. */
3893 switch (upcall->type) {
3894 case DPIF_UC_ACTION:
3900 case DPIF_N_UC_TYPES:
3902 VLOG_WARN_RL(&rl, "upcall has unexpected type %"PRIu32, upcall->type);
3906 /* "action" upcalls need a closer look. */
3907 if (!upcall->userdata) {
3908 VLOG_WARN_RL(&rl, "action upcall missing cookie");
3911 userdata_len = nl_attr_get_size(upcall->userdata);
3912 if (userdata_len < sizeof cookie.type
3913 || userdata_len > sizeof cookie) {
3914 VLOG_WARN_RL(&rl, "action upcall cookie has unexpected size %zu",
3918 memset(&cookie, 0, sizeof cookie);
3919 memcpy(&cookie, nl_attr_get(upcall->userdata), userdata_len);
3920 if (userdata_len == sizeof cookie.sflow
3921 && cookie.type == USER_ACTION_COOKIE_SFLOW) {
3922 return SFLOW_UPCALL;
3923 } else if (userdata_len == sizeof cookie.slow_path
3924 && cookie.type == USER_ACTION_COOKIE_SLOW_PATH) {
3926 } else if (userdata_len == sizeof cookie.flow_sample
3927 && cookie.type == USER_ACTION_COOKIE_FLOW_SAMPLE) {
3928 return FLOW_SAMPLE_UPCALL;
3929 } else if (userdata_len == sizeof cookie.ipfix
3930 && cookie.type == USER_ACTION_COOKIE_IPFIX) {
3931 return IPFIX_UPCALL;
3933 VLOG_WARN_RL(&rl, "invalid user cookie of type %"PRIu16
3934 " and size %zu", cookie.type, userdata_len);
3940 handle_sflow_upcall(struct dpif_backer *backer,
3941 const struct dpif_upcall *upcall)
3943 struct ofproto_dpif *ofproto;
3944 union user_action_cookie cookie;
3946 odp_port_t odp_in_port;
3948 if (ofproto_receive(backer, upcall->packet, upcall->key, upcall->key_len,
3949 &flow, NULL, &ofproto, &odp_in_port)
3950 || !ofproto->sflow) {
3954 memset(&cookie, 0, sizeof cookie);
3955 memcpy(&cookie, nl_attr_get(upcall->userdata), sizeof cookie.sflow);
3956 dpif_sflow_received(ofproto->sflow, upcall->packet, &flow,
3957 odp_in_port, &cookie);
3961 handle_flow_sample_upcall(struct dpif_backer *backer,
3962 const struct dpif_upcall *upcall)
3964 struct ofproto_dpif *ofproto;
3965 union user_action_cookie cookie;
3968 if (ofproto_receive(backer, upcall->packet, upcall->key, upcall->key_len,
3969 &flow, NULL, &ofproto, NULL)
3970 || !ofproto->ipfix) {
3974 memset(&cookie, 0, sizeof cookie);
3975 memcpy(&cookie, nl_attr_get(upcall->userdata), sizeof cookie.flow_sample);
3977 /* The flow reflects exactly the contents of the packet. Sample
3978 * the packet using it. */
3979 dpif_ipfix_flow_sample(ofproto->ipfix, upcall->packet, &flow,
3980 cookie.flow_sample.collector_set_id,
3981 cookie.flow_sample.probability,
3982 cookie.flow_sample.obs_domain_id,
3983 cookie.flow_sample.obs_point_id);
3987 handle_ipfix_upcall(struct dpif_backer *backer,
3988 const struct dpif_upcall *upcall)
3990 struct ofproto_dpif *ofproto;
3993 if (ofproto_receive(backer, upcall->packet, upcall->key, upcall->key_len,
3994 &flow, NULL, &ofproto, NULL)
3995 || !ofproto->ipfix) {
3999 /* The flow reflects exactly the contents of the packet. Sample
4000 * the packet using it. */
4001 dpif_ipfix_bridge_sample(ofproto->ipfix, upcall->packet, &flow);
4005 handle_upcalls(struct dpif_backer *backer, unsigned int max_batch)
4007 struct dpif_upcall misses[FLOW_MISS_MAX_BATCH];
4008 struct ofpbuf miss_bufs[FLOW_MISS_MAX_BATCH];
4009 uint64_t miss_buf_stubs[FLOW_MISS_MAX_BATCH][4096 / 8];
4014 ovs_assert(max_batch <= FLOW_MISS_MAX_BATCH);
4017 for (n_processed = 0; n_processed < max_batch; n_processed++) {
4018 struct dpif_upcall *upcall = &misses[n_misses];
4019 struct ofpbuf *buf = &miss_bufs[n_misses];
4022 ofpbuf_use_stub(buf, miss_buf_stubs[n_misses],
4023 sizeof miss_buf_stubs[n_misses]);
4024 error = dpif_recv(backer->dpif, upcall, buf);
4030 switch (classify_upcall(upcall)) {
4032 /* Handle it later. */
4037 handle_sflow_upcall(backer, upcall);
4041 case FLOW_SAMPLE_UPCALL:
4042 handle_flow_sample_upcall(backer, upcall);
4047 handle_ipfix_upcall(backer, upcall);
4057 /* Handle deferred MISS_UPCALL processing. */
4058 handle_miss_upcalls(backer, misses, n_misses);
4059 for (i = 0; i < n_misses; i++) {
4060 ofpbuf_uninit(&miss_bufs[i]);
4066 /* Flow expiration. */
4068 static int subfacet_max_idle(const struct dpif_backer *);
4069 static void update_stats(struct dpif_backer *);
4070 static void rule_expire(struct rule_dpif *);
4071 static void expire_subfacets(struct dpif_backer *, int dp_max_idle);
4073 /* This function is called periodically by run(). Its job is to collect
4074 * updates for the flows that have been installed into the datapath, most
4075 * importantly when they last were used, and then use that information to
4076 * expire flows that have not been used recently.
4078 * Returns the number of milliseconds after which it should be called again. */
4080 expire(struct dpif_backer *backer)
4082 struct ofproto_dpif *ofproto;
4086 /* Periodically clear out the drop keys in an effort to keep them
4087 * relatively few. */
4088 drop_key_clear(backer);
4090 /* Update stats for each flow in the backer. */
4091 update_stats(backer);
4093 n_subfacets = hmap_count(&backer->subfacets);
4095 struct subfacet *subfacet;
4096 long long int total, now;
4100 HMAP_FOR_EACH (subfacet, hmap_node, &backer->subfacets) {
4101 total += now - subfacet->created;
4103 backer->avg_subfacet_life += total / n_subfacets;
4105 backer->avg_subfacet_life /= 2;
4107 backer->avg_n_subfacet += n_subfacets;
4108 backer->avg_n_subfacet /= 2;
4110 backer->max_n_subfacet = MAX(backer->max_n_subfacet, n_subfacets);
4112 max_idle = subfacet_max_idle(backer);
4113 expire_subfacets(backer, max_idle);
4115 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
4116 struct rule *rule, *next_rule;
4118 if (ofproto->backer != backer) {
4122 /* Expire OpenFlow flows whose idle_timeout or hard_timeout
4124 LIST_FOR_EACH_SAFE (rule, next_rule, expirable,
4125 &ofproto->up.expirable) {
4126 rule_expire(rule_dpif_cast(rule));
4129 /* All outstanding data in existing flows has been accounted, so it's a
4130 * good time to do bond rebalancing. */
4131 if (ofproto->has_bonded_bundles) {
4132 struct ofbundle *bundle;
4134 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
4136 bond_rebalance(bundle->bond, &backer->revalidate_set);
4142 return MIN(max_idle, 1000);
4145 /* Updates flow table statistics given that the datapath just reported 'stats'
4146 * as 'subfacet''s statistics. */
4148 update_subfacet_stats(struct subfacet *subfacet,
4149 const struct dpif_flow_stats *stats)
4151 struct facet *facet = subfacet->facet;
4152 struct dpif_flow_stats diff;
4154 diff.tcp_flags = stats->tcp_flags;
4155 diff.used = stats->used;
4157 if (stats->n_packets >= subfacet->dp_packet_count) {
4158 diff.n_packets = stats->n_packets - subfacet->dp_packet_count;
4160 VLOG_WARN_RL(&rl, "unexpected packet count from the datapath");
4164 if (stats->n_bytes >= subfacet->dp_byte_count) {
4165 diff.n_bytes = stats->n_bytes - subfacet->dp_byte_count;
4167 VLOG_WARN_RL(&rl, "unexpected byte count from datapath");
4171 facet->ofproto->n_hit += diff.n_packets;
4172 subfacet->dp_packet_count = stats->n_packets;
4173 subfacet->dp_byte_count = stats->n_bytes;
4174 subfacet_update_stats(subfacet, &diff);
4176 if (facet->accounted_bytes < facet->byte_count) {
4178 facet_account(facet);
4179 facet->accounted_bytes = facet->byte_count;
4183 /* 'key' with length 'key_len' bytes is a flow in 'dpif' that we know nothing
4184 * about, or a flow that shouldn't be installed but was anyway. Delete it. */
4186 delete_unexpected_flow(struct dpif_backer *backer,
4187 const struct nlattr *key, size_t key_len)
4189 if (!VLOG_DROP_WARN(&rl)) {
4193 odp_flow_key_format(key, key_len, &s);
4194 VLOG_WARN("unexpected flow: %s", ds_cstr(&s));
4198 COVERAGE_INC(facet_unexpected);
4199 dpif_flow_del(backer->dpif, key, key_len, NULL);
4202 /* Update 'packet_count', 'byte_count', and 'used' members of installed facets.
4204 * This function also pushes statistics updates to rules which each facet
4205 * resubmits into. Generally these statistics will be accurate. However, if a
4206 * facet changes the rule it resubmits into at some time in between
4207 * update_stats() runs, it is possible that statistics accrued to the
4208 * old rule will be incorrectly attributed to the new rule. This could be
4209 * avoided by calling update_stats() whenever rules are created or
4210 * deleted. However, the performance impact of making so many calls to the
4211 * datapath do not justify the benefit of having perfectly accurate statistics.
4213 * In addition, this function maintains per ofproto flow hit counts. The patch
4214 * port is not treated specially. e.g. A packet ingress from br0 patched into
4215 * br1 will increase the hit count of br0 by 1, however, does not affect
4216 * the hit or miss counts of br1.
4219 update_stats(struct dpif_backer *backer)
4221 const struct dpif_flow_stats *stats;
4222 struct dpif_flow_dump dump;
4223 const struct nlattr *key, *mask;
4224 size_t key_len, mask_len;
4226 dpif_flow_dump_start(&dump, backer->dpif);
4227 while (dpif_flow_dump_next(&dump, &key, &key_len,
4228 &mask, &mask_len, NULL, NULL, &stats)) {
4229 struct subfacet *subfacet;
4232 key_hash = odp_flow_key_hash(key, key_len);
4233 subfacet = subfacet_find(backer, key, key_len, key_hash);
4234 switch (subfacet ? subfacet->path : SF_NOT_INSTALLED) {
4236 update_subfacet_stats(subfacet, stats);
4240 /* Stats are updated per-packet. */
4243 case SF_NOT_INSTALLED:
4245 delete_unexpected_flow(backer, key, key_len);
4250 dpif_flow_dump_done(&dump);
4252 update_moving_averages(backer);
4255 /* Calculates and returns the number of milliseconds of idle time after which
4256 * subfacets should expire from the datapath. When a subfacet expires, we fold
4257 * its statistics into its facet, and when a facet's last subfacet expires, we
4258 * fold its statistic into its rule. */
4260 subfacet_max_idle(const struct dpif_backer *backer)
4263 * Idle time histogram.
4265 * Most of the time a switch has a relatively small number of subfacets.
4266 * When this is the case we might as well keep statistics for all of them
4267 * in userspace and to cache them in the kernel datapath for performance as
4270 * As the number of subfacets increases, the memory required to maintain
4271 * statistics about them in userspace and in the kernel becomes
4272 * significant. However, with a large number of subfacets it is likely
4273 * that only a few of them are "heavy hitters" that consume a large amount
4274 * of bandwidth. At this point, only heavy hitters are worth caching in
4275 * the kernel and maintaining in userspaces; other subfacets we can
4278 * The technique used to compute the idle time is to build a histogram with
4279 * N_BUCKETS buckets whose width is BUCKET_WIDTH msecs each. Each subfacet
4280 * that is installed in the kernel gets dropped in the appropriate bucket.
4281 * After the histogram has been built, we compute the cutoff so that only
4282 * the most-recently-used 1% of subfacets (but at least
4283 * flow_eviction_threshold flows) are kept cached. At least
4284 * the most-recently-used bucket of subfacets is kept, so actually an
4285 * arbitrary number of subfacets can be kept in any given expiration run
4286 * (though the next run will delete most of those unless they receive
4289 * This requires a second pass through the subfacets, in addition to the
4290 * pass made by update_stats(), because the former function never looks at
4291 * uninstallable subfacets.
4293 enum { BUCKET_WIDTH = ROUND_UP(100, TIME_UPDATE_INTERVAL) };
4294 enum { N_BUCKETS = 5000 / BUCKET_WIDTH };
4295 int buckets[N_BUCKETS] = { 0 };
4296 int total, subtotal, bucket;
4297 struct subfacet *subfacet;
4301 total = hmap_count(&backer->subfacets);
4302 if (total <= flow_eviction_threshold) {
4303 return N_BUCKETS * BUCKET_WIDTH;
4306 /* Build histogram. */
4308 HMAP_FOR_EACH (subfacet, hmap_node, &backer->subfacets) {
4309 long long int idle = now - subfacet->used;
4310 int bucket = (idle <= 0 ? 0
4311 : idle >= BUCKET_WIDTH * N_BUCKETS ? N_BUCKETS - 1
4312 : (unsigned int) idle / BUCKET_WIDTH);
4316 /* Find the first bucket whose flows should be expired. */
4317 subtotal = bucket = 0;
4319 subtotal += buckets[bucket++];
4320 } while (bucket < N_BUCKETS &&
4321 subtotal < MAX(flow_eviction_threshold, total / 100));
4323 if (VLOG_IS_DBG_ENABLED()) {
4327 ds_put_cstr(&s, "keep");
4328 for (i = 0; i < N_BUCKETS; i++) {
4330 ds_put_cstr(&s, ", drop");
4333 ds_put_format(&s, " %d:%d", i * BUCKET_WIDTH, buckets[i]);
4336 VLOG_INFO("%s (msec:count)", ds_cstr(&s));
4340 return bucket * BUCKET_WIDTH;
4344 expire_subfacets(struct dpif_backer *backer, int dp_max_idle)
4346 /* Cutoff time for most flows. */
4347 long long int normal_cutoff = time_msec() - dp_max_idle;
4349 /* We really want to keep flows for special protocols around, so use a more
4350 * conservative cutoff. */
4351 long long int special_cutoff = time_msec() - 10000;
4353 struct subfacet *subfacet, *next_subfacet;
4354 struct subfacet *batch[SUBFACET_DESTROY_MAX_BATCH];
4358 HMAP_FOR_EACH_SAFE (subfacet, next_subfacet, hmap_node,
4359 &backer->subfacets) {
4360 long long int cutoff;
4362 cutoff = (subfacet->facet->xout.slow & (SLOW_CFM | SLOW_BFD | SLOW_LACP
4366 if (subfacet->used < cutoff) {
4367 if (subfacet->path != SF_NOT_INSTALLED) {
4368 batch[n_batch++] = subfacet;
4369 if (n_batch >= SUBFACET_DESTROY_MAX_BATCH) {
4370 subfacet_destroy_batch(backer, batch, n_batch);
4374 subfacet_destroy(subfacet);
4380 subfacet_destroy_batch(backer, batch, n_batch);
4384 /* If 'rule' is an OpenFlow rule, that has expired according to OpenFlow rules,
4385 * then delete it entirely. */
4387 rule_expire(struct rule_dpif *rule)
4392 if (rule->up.pending) {
4393 /* We'll have to expire it later. */
4397 /* Has 'rule' expired? */
4399 if (rule->up.hard_timeout
4400 && now > rule->up.modified + rule->up.hard_timeout * 1000) {
4401 reason = OFPRR_HARD_TIMEOUT;
4402 } else if (rule->up.idle_timeout
4403 && now > rule->up.used + rule->up.idle_timeout * 1000) {
4404 reason = OFPRR_IDLE_TIMEOUT;
4409 COVERAGE_INC(ofproto_dpif_expired);
4411 /* Get rid of the rule. */
4412 ofproto_rule_expire(&rule->up, reason);
4417 /* Creates and returns a new facet based on 'miss'.
4419 * The caller must already have determined that no facet with an identical
4420 * 'miss->flow' exists in 'miss->ofproto'.
4422 * 'rule' and 'xout' must have been created based on 'miss'.
4424 * 'facet'' statistics are initialized based on 'stats'.
4426 * The facet will initially have no subfacets. The caller should create (at
4427 * least) one subfacet with subfacet_create(). */
4428 static struct facet *
4429 facet_create(const struct flow_miss *miss, struct rule_dpif *rule,
4430 struct xlate_out *xout, struct dpif_flow_stats *stats)
4432 struct ofproto_dpif *ofproto = miss->ofproto;
4433 struct facet *facet;
4436 facet = xzalloc(sizeof *facet);
4437 facet->ofproto = miss->ofproto;
4438 facet->packet_count = facet->prev_packet_count = stats->n_packets;
4439 facet->byte_count = facet->prev_byte_count = stats->n_bytes;
4440 facet->tcp_flags = stats->tcp_flags;
4441 facet->used = stats->used;
4442 facet->flow = miss->flow;
4443 facet->learn_rl = time_msec() + 500;
4445 list_init(&facet->subfacets);
4446 netflow_flow_init(&facet->nf_flow);
4447 netflow_flow_update_time(ofproto->netflow, &facet->nf_flow, facet->used);
4449 xlate_out_copy(&facet->xout, xout);
4451 match_init(&match, &facet->flow, &facet->xout.wc);
4452 cls_rule_init(&facet->cr, &match, OFP_DEFAULT_PRIORITY);
4453 classifier_insert(&ofproto->facets, &facet->cr);
4455 facet->nf_flow.output_iface = facet->xout.nf_output_iface;
4456 facet->fail_open = rule->up.cr.priority == FAIL_OPEN_PRIORITY;
4462 facet_free(struct facet *facet)
4465 xlate_out_uninit(&facet->xout);
4470 /* Executes, within 'ofproto', the 'n_actions' actions in 'actions' on
4471 * 'packet', which arrived on 'in_port'. */
4473 execute_odp_actions(struct ofproto_dpif *ofproto, const struct flow *flow,
4474 const struct nlattr *odp_actions, size_t actions_len,
4475 struct ofpbuf *packet)
4477 struct odputil_keybuf keybuf;
4481 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
4482 odp_flow_key_from_flow(&key, flow,
4483 ofp_port_to_odp_port(ofproto, flow->in_port.ofp_port));
4485 error = dpif_execute(ofproto->backer->dpif, key.data, key.size,
4486 odp_actions, actions_len, packet);
4490 /* Remove 'facet' from its ofproto and free up the associated memory:
4492 * - If 'facet' was installed in the datapath, uninstalls it and updates its
4493 * rule's statistics, via subfacet_uninstall().
4495 * - Removes 'facet' from its rule and from ofproto->facets.
4498 facet_remove(struct facet *facet)
4500 struct subfacet *subfacet, *next_subfacet;
4502 ovs_assert(!list_is_empty(&facet->subfacets));
4504 /* First uninstall all of the subfacets to get final statistics. */
4505 LIST_FOR_EACH (subfacet, list_node, &facet->subfacets) {
4506 subfacet_uninstall(subfacet);
4509 /* Flush the final stats to the rule.
4511 * This might require us to have at least one subfacet around so that we
4512 * can use its actions for accounting in facet_account(), which is why we
4513 * have uninstalled but not yet destroyed the subfacets. */
4514 facet_flush_stats(facet);
4516 /* Now we're really all done so destroy everything. */
4517 LIST_FOR_EACH_SAFE (subfacet, next_subfacet, list_node,
4518 &facet->subfacets) {
4519 subfacet_destroy__(subfacet);
4521 classifier_remove(&facet->ofproto->facets, &facet->cr);
4522 cls_rule_destroy(&facet->cr);
4526 /* Feed information from 'facet' back into the learning table to keep it in
4527 * sync with what is actually flowing through the datapath. */
4529 facet_learn(struct facet *facet)
4531 long long int now = time_msec();
4533 if (!facet->xout.has_fin_timeout && now < facet->learn_rl) {
4537 facet->learn_rl = now + 500;
4539 if (!facet->xout.has_learn
4540 && !facet->xout.has_normal
4541 && (!facet->xout.has_fin_timeout
4542 || !(facet->tcp_flags & (TCP_FIN | TCP_RST)))) {
4546 facet_push_stats(facet, true);
4550 facet_account(struct facet *facet)
4552 const struct nlattr *a;
4557 if (!facet->xout.has_normal || !facet->ofproto->has_bonded_bundles) {
4560 n_bytes = facet->byte_count - facet->accounted_bytes;
4562 /* This loop feeds byte counters to bond_account() for rebalancing to use
4563 * as a basis. We also need to track the actual VLAN on which the packet
4564 * is going to be sent to ensure that it matches the one passed to
4565 * bond_choose_output_slave(). (Otherwise, we will account to the wrong
4568 * We use the actions from an arbitrary subfacet because they should all
4569 * be equally valid for our purpose. */
4570 vlan_tci = facet->flow.vlan_tci;
4571 NL_ATTR_FOR_EACH_UNSAFE (a, left, facet->xout.odp_actions.data,
4572 facet->xout.odp_actions.size) {
4573 const struct ovs_action_push_vlan *vlan;
4574 struct ofport_dpif *port;
4576 switch (nl_attr_type(a)) {
4577 case OVS_ACTION_ATTR_OUTPUT:
4578 port = get_odp_port(facet->ofproto, nl_attr_get_odp_port(a));
4579 if (port && port->bundle && port->bundle->bond) {
4580 bond_account(port->bundle->bond, &facet->flow,
4581 vlan_tci_to_vid(vlan_tci), n_bytes);
4585 case OVS_ACTION_ATTR_POP_VLAN:
4586 vlan_tci = htons(0);
4589 case OVS_ACTION_ATTR_PUSH_VLAN:
4590 vlan = nl_attr_get(a);
4591 vlan_tci = vlan->vlan_tci;
4597 /* Returns true if the only action for 'facet' is to send to the controller.
4598 * (We don't report NetFlow expiration messages for such facets because they
4599 * are just part of the control logic for the network, not real traffic). */
4601 facet_is_controller_flow(struct facet *facet)
4604 struct ofproto_dpif *ofproto = facet->ofproto;
4605 const struct rule_dpif *rule = rule_dpif_lookup(ofproto, &facet->flow,
4607 const struct ofpact *ofpacts = rule->up.ofpacts;
4608 size_t ofpacts_len = rule->up.ofpacts_len;
4610 if (ofpacts_len > 0 &&
4611 ofpacts->type == OFPACT_CONTROLLER &&
4612 ofpact_next(ofpacts) >= ofpact_end(ofpacts, ofpacts_len)) {
4619 /* Folds all of 'facet''s statistics into its rule. Also updates the
4620 * accounting ofhook and emits a NetFlow expiration if appropriate. All of
4621 * 'facet''s statistics in the datapath should have been zeroed and folded into
4622 * its packet and byte counts before this function is called. */
4624 facet_flush_stats(struct facet *facet)
4626 struct ofproto_dpif *ofproto = facet->ofproto;
4627 struct subfacet *subfacet;
4629 LIST_FOR_EACH (subfacet, list_node, &facet->subfacets) {
4630 ovs_assert(!subfacet->dp_byte_count);
4631 ovs_assert(!subfacet->dp_packet_count);
4634 facet_push_stats(facet, false);
4635 if (facet->accounted_bytes < facet->byte_count) {
4636 facet_account(facet);
4637 facet->accounted_bytes = facet->byte_count;
4640 if (ofproto->netflow && !facet_is_controller_flow(facet)) {
4641 struct ofexpired expired;
4642 expired.flow = facet->flow;
4643 expired.packet_count = facet->packet_count;
4644 expired.byte_count = facet->byte_count;
4645 expired.used = facet->used;
4646 netflow_expire(ofproto->netflow, &facet->nf_flow, &expired);
4649 /* Reset counters to prevent double counting if 'facet' ever gets
4651 facet_reset_counters(facet);
4653 netflow_flow_clear(&facet->nf_flow);
4654 facet->tcp_flags = 0;
4657 /* Searches 'ofproto''s table of facets for one which would be responsible for
4658 * 'flow'. Returns it if found, otherwise a null pointer.
4660 * The returned facet might need revalidation; use facet_lookup_valid()
4661 * instead if that is important. */
4662 static struct facet *
4663 facet_find(struct ofproto_dpif *ofproto, const struct flow *flow)
4665 struct cls_rule *cr = classifier_lookup(&ofproto->facets, flow, NULL);
4666 return cr ? CONTAINER_OF(cr, struct facet, cr) : NULL;
4669 /* Searches 'ofproto''s table of facets for one capable that covers
4670 * 'flow'. Returns it if found, otherwise a null pointer.
4672 * The returned facet is guaranteed to be valid. */
4673 static struct facet *
4674 facet_lookup_valid(struct ofproto_dpif *ofproto, const struct flow *flow)
4676 struct facet *facet;
4678 facet = facet_find(ofproto, flow);
4680 && (ofproto->backer->need_revalidate
4681 || tag_set_intersects(&ofproto->backer->revalidate_set,
4683 && !facet_revalidate(facet)) {
4691 facet_check_consistency(struct facet *facet)
4693 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 15);
4695 struct xlate_out xout;
4696 struct xlate_in xin;
4698 struct rule_dpif *rule;
4701 /* Check the datapath actions for consistency. */
4702 rule = rule_dpif_lookup(facet->ofproto, &facet->flow, NULL);
4703 xlate_in_init(&xin, facet->ofproto, &facet->flow, rule, 0, NULL);
4704 xlate_actions(&xin, &xout);
4706 fail_open = rule->up.cr.priority == FAIL_OPEN_PRIORITY;
4707 ok = ofpbuf_equal(&facet->xout.odp_actions, &xout.odp_actions)
4708 && facet->xout.slow == xout.slow
4709 && facet->fail_open == fail_open;
4710 if (!ok && !VLOG_DROP_WARN(&rl)) {
4711 struct ds s = DS_EMPTY_INITIALIZER;
4713 flow_format(&s, &facet->flow);
4714 ds_put_cstr(&s, ": inconsistency in facet");
4716 if (!ofpbuf_equal(&facet->xout.odp_actions, &xout.odp_actions)) {
4717 ds_put_cstr(&s, " (actions were: ");
4718 format_odp_actions(&s, facet->xout.odp_actions.data,
4719 facet->xout.odp_actions.size);
4720 ds_put_cstr(&s, ") (correct actions: ");
4721 format_odp_actions(&s, xout.odp_actions.data,
4722 xout.odp_actions.size);
4723 ds_put_char(&s, ')');
4726 if (facet->xout.slow != xout.slow) {
4727 ds_put_format(&s, " slow path incorrect. should be %d", xout.slow);
4730 if (facet->fail_open != fail_open) {
4731 ds_put_format(&s, " fail open incorrect. should be %s",
4732 fail_open ? "true" : "false");
4736 xlate_out_uninit(&xout);
4741 /* Re-searches the classifier for 'facet':
4743 * - If the rule found is different from 'facet''s current rule, moves
4744 * 'facet' to the new rule and recompiles its actions.
4746 * - If the rule found is the same as 'facet''s current rule, leaves 'facet'
4747 * where it is and recompiles its actions anyway.
4749 * - If any of 'facet''s subfacets correspond to a new flow according to
4750 * ofproto_receive(), 'facet' is removed.
4752 * Returns true if 'facet' is still valid. False if 'facet' was removed. */
4754 facet_revalidate(struct facet *facet)
4756 struct ofproto_dpif *ofproto = facet->ofproto;
4757 struct rule_dpif *new_rule;
4758 struct subfacet *subfacet;
4759 struct flow_wildcards wc;
4760 struct xlate_out xout;
4761 struct xlate_in xin;
4763 COVERAGE_INC(facet_revalidate);
4765 /* Check that child subfacets still correspond to this facet. Tunnel
4766 * configuration changes could cause a subfacet's OpenFlow in_port to
4768 LIST_FOR_EACH (subfacet, list_node, &facet->subfacets) {
4769 struct ofproto_dpif *recv_ofproto;
4770 struct flow recv_flow;
4773 error = ofproto_receive(ofproto->backer, NULL, subfacet->key,
4774 subfacet->key_len, &recv_flow, NULL,
4775 &recv_ofproto, NULL);
4777 || recv_ofproto != ofproto
4778 || facet != facet_find(ofproto, &recv_flow)) {
4779 facet_remove(facet);
4784 flow_wildcards_init_catchall(&wc);
4785 new_rule = rule_dpif_lookup(ofproto, &facet->flow, &wc);
4787 /* Calculate new datapath actions.
4789 * We do not modify any 'facet' state yet, because we might need to, e.g.,
4790 * emit a NetFlow expiration and, if so, we need to have the old state
4791 * around to properly compose it. */
4792 xlate_in_init(&xin, ofproto, &facet->flow, new_rule, 0, NULL);
4793 xlate_actions(&xin, &xout);
4794 flow_wildcards_or(&xout.wc, &xout.wc, &wc);
4796 /* A facet's slow path reason should only change under dramatic
4797 * circumstances. Rather than try to update everything, it's simpler to
4798 * remove the facet and start over.
4800 * More importantly, if a facet's wildcards change, it will be relatively
4801 * difficult to figure out if its subfacets still belong to it, and if not
4802 * which facet they may belong to. Again, to avoid the complexity, we
4803 * simply give up instead. */
4804 if (facet->xout.slow != xout.slow
4805 || memcmp(&facet->xout.wc, &xout.wc, sizeof xout.wc)) {
4806 facet_remove(facet);
4807 xlate_out_uninit(&xout);
4811 if (!ofpbuf_equal(&facet->xout.odp_actions, &xout.odp_actions)) {
4812 LIST_FOR_EACH(subfacet, list_node, &facet->subfacets) {
4813 if (subfacet->path == SF_FAST_PATH) {
4814 struct dpif_flow_stats stats;
4816 subfacet_install(subfacet, &xout.odp_actions, &stats);
4817 subfacet_update_stats(subfacet, &stats);
4821 facet_flush_stats(facet);
4823 ofpbuf_clear(&facet->xout.odp_actions);
4824 ofpbuf_put(&facet->xout.odp_actions, xout.odp_actions.data,
4825 xout.odp_actions.size);
4828 /* Update 'facet' now that we've taken care of all the old state. */
4829 facet->xout.tags = xout.tags;
4830 facet->xout.slow = xout.slow;
4831 facet->xout.has_learn = xout.has_learn;
4832 facet->xout.has_normal = xout.has_normal;
4833 facet->xout.has_fin_timeout = xout.has_fin_timeout;
4834 facet->xout.nf_output_iface = xout.nf_output_iface;
4835 facet->xout.mirrors = xout.mirrors;
4836 facet->nf_flow.output_iface = facet->xout.nf_output_iface;
4837 facet->used = MAX(facet->used, new_rule->up.created);
4838 facet->fail_open = new_rule->up.cr.priority == FAIL_OPEN_PRIORITY;
4840 xlate_out_uninit(&xout);
4845 facet_reset_counters(struct facet *facet)
4847 facet->packet_count = 0;
4848 facet->byte_count = 0;
4849 facet->prev_packet_count = 0;
4850 facet->prev_byte_count = 0;
4851 facet->accounted_bytes = 0;
4855 facet_push_stats(struct facet *facet, bool may_learn)
4857 struct dpif_flow_stats stats;
4859 ovs_assert(facet->packet_count >= facet->prev_packet_count);
4860 ovs_assert(facet->byte_count >= facet->prev_byte_count);
4861 ovs_assert(facet->used >= facet->prev_used);
4863 stats.n_packets = facet->packet_count - facet->prev_packet_count;
4864 stats.n_bytes = facet->byte_count - facet->prev_byte_count;
4865 stats.used = facet->used;
4866 stats.tcp_flags = facet->tcp_flags;
4868 if (may_learn || stats.n_packets || facet->used > facet->prev_used) {
4869 struct ofproto_dpif *ofproto = facet->ofproto;
4870 struct ofport_dpif *in_port;
4871 struct rule_dpif *rule;
4872 struct xlate_in xin;
4874 facet->prev_packet_count = facet->packet_count;
4875 facet->prev_byte_count = facet->byte_count;
4876 facet->prev_used = facet->used;
4878 in_port = get_ofp_port(ofproto, facet->flow.in_port.ofp_port);
4879 if (in_port && in_port->is_tunnel) {
4880 netdev_vport_inc_rx(in_port->up.netdev, &stats);
4883 rule = rule_dpif_lookup(ofproto, &facet->flow, NULL);
4884 rule_credit_stats(rule, &stats);
4885 netflow_flow_update_time(ofproto->netflow, &facet->nf_flow,
4887 netflow_flow_update_flags(&facet->nf_flow, facet->tcp_flags);
4888 mirror_update_stats(ofproto->mbridge, facet->xout.mirrors,
4889 stats.n_packets, stats.n_bytes);
4891 xlate_in_init(&xin, ofproto, &facet->flow, rule, stats.tcp_flags,
4893 xin.resubmit_stats = &stats;
4894 xin.may_learn = may_learn;
4895 xlate_actions_for_side_effects(&xin);
4900 push_all_stats__(bool run_fast)
4902 static long long int rl = LLONG_MIN;
4903 struct ofproto_dpif *ofproto;
4905 if (time_msec() < rl) {
4909 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
4910 struct cls_cursor cursor;
4911 struct facet *facet;
4913 cls_cursor_init(&cursor, &ofproto->facets, NULL);
4914 CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
4915 facet_push_stats(facet, false);
4922 rl = time_msec() + 100;
4926 push_all_stats(void)
4928 push_all_stats__(true);
4932 rule_credit_stats(struct rule_dpif *rule, const struct dpif_flow_stats *stats)
4934 rule->packet_count += stats->n_packets;
4935 rule->byte_count += stats->n_bytes;
4936 ofproto_rule_update_used(&rule->up, stats->used);
4941 static struct subfacet *
4942 subfacet_find(struct dpif_backer *backer, const struct nlattr *key,
4943 size_t key_len, uint32_t key_hash)
4945 struct subfacet *subfacet;
4947 HMAP_FOR_EACH_WITH_HASH (subfacet, hmap_node, key_hash,
4948 &backer->subfacets) {
4949 if (subfacet->key_len == key_len
4950 && !memcmp(key, subfacet->key, key_len)) {
4958 /* Searches 'facet' (within 'ofproto') for a subfacet with the specified
4959 * 'key_fitness', 'key', and 'key_len' members in 'miss'. Returns the
4960 * existing subfacet if there is one, otherwise creates and returns a
4962 static struct subfacet *
4963 subfacet_create(struct facet *facet, struct flow_miss *miss,
4966 struct dpif_backer *backer = miss->ofproto->backer;
4967 enum odp_key_fitness key_fitness = miss->key_fitness;
4968 const struct nlattr *key = miss->key;
4969 size_t key_len = miss->key_len;
4971 struct subfacet *subfacet;
4973 key_hash = odp_flow_key_hash(key, key_len);
4975 if (list_is_empty(&facet->subfacets)) {
4976 subfacet = &facet->one_subfacet;
4978 subfacet = subfacet_find(backer, key, key_len, key_hash);
4980 if (subfacet->facet == facet) {
4984 /* This shouldn't happen. */
4985 VLOG_ERR_RL(&rl, "subfacet with wrong facet");
4986 subfacet_destroy(subfacet);
4989 subfacet = xmalloc(sizeof *subfacet);
4992 hmap_insert(&backer->subfacets, &subfacet->hmap_node, key_hash);
4993 list_push_back(&facet->subfacets, &subfacet->list_node);
4994 subfacet->facet = facet;
4995 subfacet->key_fitness = key_fitness;
4996 subfacet->key = xmemdup(key, key_len);
4997 subfacet->key_len = key_len;
4998 subfacet->used = now;
4999 subfacet->created = now;
5000 subfacet->dp_packet_count = 0;
5001 subfacet->dp_byte_count = 0;
5002 subfacet->path = SF_NOT_INSTALLED;
5003 subfacet->backer = backer;
5005 backer->subfacet_add_count++;
5009 /* Uninstalls 'subfacet' from the datapath, if it is installed, removes it from
5010 * its facet within 'ofproto', and frees it. */
5012 subfacet_destroy__(struct subfacet *subfacet)
5014 struct facet *facet = subfacet->facet;
5015 struct ofproto_dpif *ofproto = facet->ofproto;
5017 /* Update ofproto stats before uninstall the subfacet. */
5018 ofproto->backer->subfacet_del_count++;
5020 subfacet_uninstall(subfacet);
5021 hmap_remove(&subfacet->backer->subfacets, &subfacet->hmap_node);
5022 list_remove(&subfacet->list_node);
5023 free(subfacet->key);
5024 if (subfacet != &facet->one_subfacet) {
5029 /* Destroys 'subfacet', as with subfacet_destroy__(), and then if this was the
5030 * last remaining subfacet in its facet destroys the facet too. */
5032 subfacet_destroy(struct subfacet *subfacet)
5034 struct facet *facet = subfacet->facet;
5036 if (list_is_singleton(&facet->subfacets)) {
5037 /* facet_remove() needs at least one subfacet (it will remove it). */
5038 facet_remove(facet);
5040 subfacet_destroy__(subfacet);
5045 subfacet_destroy_batch(struct dpif_backer *backer,
5046 struct subfacet **subfacets, int n)
5048 struct dpif_op ops[SUBFACET_DESTROY_MAX_BATCH];
5049 struct dpif_op *opsp[SUBFACET_DESTROY_MAX_BATCH];
5050 struct dpif_flow_stats stats[SUBFACET_DESTROY_MAX_BATCH];
5053 for (i = 0; i < n; i++) {
5054 ops[i].type = DPIF_OP_FLOW_DEL;
5055 ops[i].u.flow_del.key = subfacets[i]->key;
5056 ops[i].u.flow_del.key_len = subfacets[i]->key_len;
5057 ops[i].u.flow_del.stats = &stats[i];
5061 dpif_operate(backer->dpif, opsp, n);
5062 for (i = 0; i < n; i++) {
5063 subfacet_reset_dp_stats(subfacets[i], &stats[i]);
5064 subfacets[i]->path = SF_NOT_INSTALLED;
5065 subfacet_destroy(subfacets[i]);
5070 /* Updates 'subfacet''s datapath flow, setting its actions to 'actions_len'
5071 * bytes of actions in 'actions'. If 'stats' is non-null, statistics counters
5072 * in the datapath will be zeroed and 'stats' will be updated with traffic new
5073 * since 'subfacet' was last updated.
5075 * Returns 0 if successful, otherwise a positive errno value. */
5077 subfacet_install(struct subfacet *subfacet, const struct ofpbuf *odp_actions,
5078 struct dpif_flow_stats *stats)
5080 struct facet *facet = subfacet->facet;
5081 enum subfacet_path path = facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
5082 const struct nlattr *actions = odp_actions->data;
5083 size_t actions_len = odp_actions->size;
5084 struct odputil_keybuf maskbuf;
5087 uint64_t slow_path_stub[128 / 8];
5088 enum dpif_flow_put_flags flags;
5091 flags = subfacet->path == SF_NOT_INSTALLED ? DPIF_FP_CREATE
5094 flags |= DPIF_FP_ZERO_STATS;
5097 if (path == SF_SLOW_PATH) {
5098 compose_slow_path(facet->ofproto, &facet->flow, facet->xout.slow,
5099 slow_path_stub, sizeof slow_path_stub,
5100 &actions, &actions_len);
5103 ofpbuf_use_stack(&mask, &maskbuf, sizeof maskbuf);
5104 if (enable_megaflows) {
5105 odp_flow_key_from_mask(&mask, &facet->xout.wc.masks,
5106 &facet->flow, UINT32_MAX);
5109 ret = dpif_flow_put(subfacet->backer->dpif, flags, subfacet->key,
5110 subfacet->key_len, mask.data, mask.size,
5111 actions, actions_len, stats);
5114 subfacet_reset_dp_stats(subfacet, stats);
5118 COVERAGE_INC(subfacet_install_fail);
5120 subfacet->path = path;
5125 /* If 'subfacet' is installed in the datapath, uninstalls it. */
5127 subfacet_uninstall(struct subfacet *subfacet)
5129 if (subfacet->path != SF_NOT_INSTALLED) {
5130 struct ofproto_dpif *ofproto = subfacet->facet->ofproto;
5131 struct dpif_flow_stats stats;
5134 error = dpif_flow_del(ofproto->backer->dpif, subfacet->key,
5135 subfacet->key_len, &stats);
5136 subfacet_reset_dp_stats(subfacet, &stats);
5138 subfacet_update_stats(subfacet, &stats);
5140 subfacet->path = SF_NOT_INSTALLED;
5142 ovs_assert(subfacet->dp_packet_count == 0);
5143 ovs_assert(subfacet->dp_byte_count == 0);
5147 /* Resets 'subfacet''s datapath statistics counters. This should be called
5148 * when 'subfacet''s statistics are cleared in the datapath. If 'stats' is
5149 * non-null, it should contain the statistics returned by dpif when 'subfacet'
5150 * was reset in the datapath. 'stats' will be modified to include only
5151 * statistics new since 'subfacet' was last updated. */
5153 subfacet_reset_dp_stats(struct subfacet *subfacet,
5154 struct dpif_flow_stats *stats)
5157 && subfacet->dp_packet_count <= stats->n_packets
5158 && subfacet->dp_byte_count <= stats->n_bytes) {
5159 stats->n_packets -= subfacet->dp_packet_count;
5160 stats->n_bytes -= subfacet->dp_byte_count;
5163 subfacet->dp_packet_count = 0;
5164 subfacet->dp_byte_count = 0;
5167 /* Folds the statistics from 'stats' into the counters in 'subfacet'.
5169 * Because of the meaning of a subfacet's counters, it only makes sense to do
5170 * this if 'stats' are not tracked in the datapath, that is, if 'stats'
5171 * represents a packet that was sent by hand or if it represents statistics
5172 * that have been cleared out of the datapath. */
5174 subfacet_update_stats(struct subfacet *subfacet,
5175 const struct dpif_flow_stats *stats)
5177 if (stats->n_packets || stats->used > subfacet->used) {
5178 struct facet *facet = subfacet->facet;
5180 subfacet->used = MAX(subfacet->used, stats->used);
5181 facet->used = MAX(facet->used, stats->used);
5182 facet->packet_count += stats->n_packets;
5183 facet->byte_count += stats->n_bytes;
5184 facet->tcp_flags |= stats->tcp_flags;
5190 /* Lookup 'flow' in 'ofproto''s classifier. If 'wc' is non-null, sets
5191 * the fields that were relevant as part of the lookup. */
5192 static struct rule_dpif *
5193 rule_dpif_lookup(struct ofproto_dpif *ofproto, const struct flow *flow,
5194 struct flow_wildcards *wc)
5196 struct rule_dpif *rule;
5198 rule = rule_dpif_lookup_in_table(ofproto, flow, wc, 0);
5203 return rule_dpif_miss_rule(ofproto, flow);
5207 rule_dpif_lookup_in_table(struct ofproto_dpif *ofproto,
5208 const struct flow *flow, struct flow_wildcards *wc,
5211 struct cls_rule *cls_rule;
5212 struct classifier *cls;
5215 if (table_id >= N_TABLES) {
5220 memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
5221 wc->masks.nw_frag |= FLOW_NW_FRAG_MASK;
5224 cls = &ofproto->up.tables[table_id].cls;
5225 frag = (flow->nw_frag & FLOW_NW_FRAG_ANY) != 0;
5226 if (frag && ofproto->up.frag_handling == OFPC_FRAG_NORMAL) {
5227 /* We must pretend that transport ports are unavailable. */
5228 struct flow ofpc_normal_flow = *flow;
5229 ofpc_normal_flow.tp_src = htons(0);
5230 ofpc_normal_flow.tp_dst = htons(0);
5231 cls_rule = classifier_lookup(cls, &ofpc_normal_flow, wc);
5232 } else if (frag && ofproto->up.frag_handling == OFPC_FRAG_DROP) {
5233 cls_rule = &ofproto->drop_frags_rule->up.cr;
5235 flow_wildcards_init_exact(wc);
5238 cls_rule = classifier_lookup(cls, flow, wc);
5240 return rule_dpif_cast(rule_from_cls_rule(cls_rule));
5244 rule_dpif_miss_rule(struct ofproto_dpif *ofproto, const struct flow *flow)
5246 struct ofport_dpif *port;
5248 port = get_ofp_port(ofproto, flow->in_port.ofp_port);
5250 VLOG_WARN_RL(&rl, "packet-in on unknown OpenFlow port %"PRIu16,
5251 flow->in_port.ofp_port);
5252 return ofproto->miss_rule;
5255 if (port->up.pp.config & OFPUTIL_PC_NO_PACKET_IN) {
5256 return ofproto->no_packet_in_rule;
5258 return ofproto->miss_rule;
5262 complete_operation(struct rule_dpif *rule)
5264 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
5266 rule_invalidate(rule);
5268 struct dpif_completion *c = xmalloc(sizeof *c);
5269 c->op = rule->up.pending;
5270 list_push_back(&ofproto->completions, &c->list_node);
5272 ofoperation_complete(rule->up.pending, 0);
5276 static struct rule *
5279 struct rule_dpif *rule = xmalloc(sizeof *rule);
5284 rule_dealloc(struct rule *rule_)
5286 struct rule_dpif *rule = rule_dpif_cast(rule_);
5291 rule_construct(struct rule *rule_)
5293 struct rule_dpif *rule = rule_dpif_cast(rule_);
5294 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
5295 struct rule_dpif *victim;
5298 rule->packet_count = 0;
5299 rule->byte_count = 0;
5301 table_id = rule->up.table_id;
5302 victim = rule_dpif_cast(ofoperation_get_victim(rule->up.pending));
5304 rule->tag = victim->tag;
5305 } else if (table_id == 0) {
5310 miniflow_expand(&rule->up.cr.match.flow, &flow);
5311 rule->tag = rule_calculate_tag(&flow, &rule->up.cr.match.mask,
5312 ofproto->tables[table_id].basis);
5315 complete_operation(rule);
5320 rule_destruct(struct rule *rule)
5322 complete_operation(rule_dpif_cast(rule));
5326 rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes)
5328 struct rule_dpif *rule = rule_dpif_cast(rule_);
5330 /* push_all_stats() can handle flow misses which, when using the learn
5331 * action, can cause rules to be added and deleted. This can corrupt our
5332 * caller's datastructures which assume that rule_get_stats() doesn't have
5333 * an impact on the flow table. To be safe, we disable miss handling. */
5334 push_all_stats__(false);
5336 /* Start from historical data for 'rule' itself that are no longer tracked
5337 * in facets. This counts, for example, facets that have expired. */
5338 *packets = rule->packet_count;
5339 *bytes = rule->byte_count;
5343 rule_dpif_execute(struct rule_dpif *rule, const struct flow *flow,
5344 struct ofpbuf *packet)
5346 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
5347 struct dpif_flow_stats stats;
5348 struct xlate_out xout;
5349 struct xlate_in xin;
5351 dpif_flow_stats_extract(flow, packet, time_msec(), &stats);
5352 rule_credit_stats(rule, &stats);
5354 xlate_in_init(&xin, ofproto, flow, rule, stats.tcp_flags, packet);
5355 xin.resubmit_stats = &stats;
5356 xlate_actions(&xin, &xout);
5358 execute_odp_actions(ofproto, flow, xout.odp_actions.data,
5359 xout.odp_actions.size, packet);
5361 xlate_out_uninit(&xout);
5365 rule_execute(struct rule *rule, const struct flow *flow,
5366 struct ofpbuf *packet)
5368 rule_dpif_execute(rule_dpif_cast(rule), flow, packet);
5369 ofpbuf_delete(packet);
5374 rule_modify_actions(struct rule *rule_)
5376 struct rule_dpif *rule = rule_dpif_cast(rule_);
5378 complete_operation(rule);
5381 /* Sends 'packet' out 'ofport'.
5382 * May modify 'packet'.
5383 * Returns 0 if successful, otherwise a positive errno value. */
5385 send_packet(const struct ofport_dpif *ofport, struct ofpbuf *packet)
5387 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
5388 uint64_t odp_actions_stub[1024 / 8];
5389 struct ofpbuf key, odp_actions;
5390 struct dpif_flow_stats stats;
5391 struct odputil_keybuf keybuf;
5392 struct ofpact_output output;
5393 struct xlate_out xout;
5394 struct xlate_in xin;
5396 union flow_in_port in_port_;
5399 ofpbuf_use_stub(&odp_actions, odp_actions_stub, sizeof odp_actions_stub);
5400 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
5402 /* Use OFPP_NONE as the in_port to avoid special packet processing. */
5403 in_port_.ofp_port = OFPP_NONE;
5404 flow_extract(packet, 0, 0, NULL, &in_port_, &flow);
5405 odp_flow_key_from_flow(&key, &flow, ofp_port_to_odp_port(ofproto,
5407 dpif_flow_stats_extract(&flow, packet, time_msec(), &stats);
5409 ofpact_init(&output.ofpact, OFPACT_OUTPUT, sizeof output);
5410 output.port = ofport->up.ofp_port;
5413 xlate_in_init(&xin, ofproto, &flow, NULL, 0, packet);
5414 xin.ofpacts_len = sizeof output;
5415 xin.ofpacts = &output.ofpact;
5416 xin.resubmit_stats = &stats;
5417 xlate_actions(&xin, &xout);
5419 error = dpif_execute(ofproto->backer->dpif,
5421 xout.odp_actions.data, xout.odp_actions.size,
5423 xlate_out_uninit(&xout);
5426 VLOG_WARN_RL(&rl, "%s: failed to send packet on port %s (%s)",
5427 ofproto->up.name, netdev_get_name(ofport->up.netdev),
5428 ovs_strerror(error));
5431 ofproto->stats.tx_packets++;
5432 ofproto->stats.tx_bytes += packet->size;
5436 /* Composes an ODP action for a "slow path" action for 'flow' within 'ofproto'.
5437 * The action will state 'slow' as the reason that the action is in the slow
5438 * path. (This is purely informational: it allows a human viewing "ovs-dpctl
5439 * dump-flows" output to see why a flow is in the slow path.)
5441 * The 'stub_size' bytes in 'stub' will be used to store the action.
5442 * 'stub_size' must be large enough for the action.
5444 * The action and its size will be stored in '*actionsp' and '*actions_lenp',
5447 compose_slow_path(const struct ofproto_dpif *ofproto, const struct flow *flow,
5448 enum slow_path_reason slow,
5449 uint64_t *stub, size_t stub_size,
5450 const struct nlattr **actionsp, size_t *actions_lenp)
5452 union user_action_cookie cookie;
5455 cookie.type = USER_ACTION_COOKIE_SLOW_PATH;
5456 cookie.slow_path.unused = 0;
5457 cookie.slow_path.reason = slow;
5459 ofpbuf_use_stack(&buf, stub, stub_size);
5460 if (slow & (SLOW_CFM | SLOW_BFD | SLOW_LACP | SLOW_STP)) {
5461 uint32_t pid = dpif_port_get_pid(ofproto->backer->dpif,
5463 odp_put_userspace_action(pid, &cookie, sizeof cookie.slow_path, &buf);
5465 put_userspace_action(ofproto, &buf, flow, &cookie,
5466 sizeof cookie.slow_path);
5468 *actionsp = buf.data;
5469 *actions_lenp = buf.size;
5473 put_userspace_action(const struct ofproto_dpif *ofproto,
5474 struct ofpbuf *odp_actions,
5475 const struct flow *flow,
5476 const union user_action_cookie *cookie,
5477 const size_t cookie_size)
5481 pid = dpif_port_get_pid(ofproto->backer->dpif,
5482 ofp_port_to_odp_port(ofproto,
5483 flow->in_port.ofp_port));
5485 return odp_put_userspace_action(pid, cookie, cookie_size, odp_actions);
5489 calculate_flow_tag(struct ofproto_dpif *ofproto, const struct flow *flow,
5490 uint8_t table_id, struct rule_dpif *rule)
5492 if (table_id > 0 && table_id < N_TABLES) {
5493 struct table_dpif *table = &ofproto->tables[table_id];
5494 if (table->other_table) {
5495 return (rule && rule->tag
5497 : rule_calculate_tag(flow, &table->other_table->mask,
5505 /* Optimized flow revalidation.
5507 * It's a difficult problem, in general, to tell which facets need to have
5508 * their actions recalculated whenever the OpenFlow flow table changes. We
5509 * don't try to solve that general problem: for most kinds of OpenFlow flow
5510 * table changes, we recalculate the actions for every facet. This is
5511 * relatively expensive, but it's good enough if the OpenFlow flow table
5512 * doesn't change very often.
5514 * However, we can expect one particular kind of OpenFlow flow table change to
5515 * happen frequently: changes caused by MAC learning. To avoid wasting a lot
5516 * of CPU on revalidating every facet whenever MAC learning modifies the flow
5517 * table, we add a special case that applies to flow tables in which every rule
5518 * has the same form (that is, the same wildcards), except that the table is
5519 * also allowed to have a single "catch-all" flow that matches all packets. We
5520 * optimize this case by tagging all of the facets that resubmit into the table
5521 * and invalidating the same tag whenever a flow changes in that table. The
5522 * end result is that we revalidate just the facets that need it (and sometimes
5523 * a few more, but not all of the facets or even all of the facets that
5524 * resubmit to the table modified by MAC learning). */
5526 /* Calculates the tag to use for 'flow' and mask 'mask' when it is inserted
5527 * into an OpenFlow table with the given 'basis'. */
5529 rule_calculate_tag(const struct flow *flow, const struct minimask *mask,
5532 if (minimask_is_catchall(mask)) {
5535 uint32_t hash = flow_hash_in_minimask(flow, mask, secret);
5536 return tag_create_deterministic(hash);
5540 /* Following a change to OpenFlow table 'table_id' in 'ofproto', update the
5541 * taggability of that table.
5543 * This function must be called after *each* change to a flow table. If you
5544 * skip calling it on some changes then the pointer comparisons at the end can
5545 * be invalid if you get unlucky. For example, if a flow removal causes a
5546 * cls_table to be destroyed and then a flow insertion causes a cls_table with
5547 * different wildcards to be created with the same address, then this function
5548 * will incorrectly skip revalidation. */
5550 table_update_taggable(struct ofproto_dpif *ofproto, uint8_t table_id)
5552 struct table_dpif *table = &ofproto->tables[table_id];
5553 const struct oftable *oftable = &ofproto->up.tables[table_id];
5554 struct cls_table *catchall, *other;
5555 struct cls_table *t;
5557 catchall = other = NULL;
5559 switch (hmap_count(&oftable->cls.tables)) {
5561 /* We could tag this OpenFlow table but it would make the logic a
5562 * little harder and it's a corner case that doesn't seem worth it
5568 HMAP_FOR_EACH (t, hmap_node, &oftable->cls.tables) {
5569 if (cls_table_is_catchall(t)) {
5571 } else if (!other) {
5574 /* Indicate that we can't tag this by setting both tables to
5575 * NULL. (We know that 'catchall' is already NULL.) */
5582 /* Can't tag this table. */
5586 if (table->catchall_table != catchall || table->other_table != other) {
5587 table->catchall_table = catchall;
5588 table->other_table = other;
5589 ofproto->backer->need_revalidate = REV_FLOW_TABLE;
5593 /* Given 'rule' that has changed in some way (either it is a rule being
5594 * inserted, a rule being deleted, or a rule whose actions are being
5595 * modified), marks facets for revalidation to ensure that packets will be
5596 * forwarded correctly according to the new state of the flow table.
5598 * This function must be called after *each* change to a flow table. See
5599 * the comment on table_update_taggable() for more information. */
5601 rule_invalidate(const struct rule_dpif *rule)
5603 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
5605 table_update_taggable(ofproto, rule->up.table_id);
5607 if (!ofproto->backer->need_revalidate) {
5608 struct table_dpif *table = &ofproto->tables[rule->up.table_id];
5610 if (table->other_table && rule->tag) {
5611 tag_set_add(&ofproto->backer->revalidate_set, rule->tag);
5613 ofproto->backer->need_revalidate = REV_FLOW_TABLE;
5619 set_frag_handling(struct ofproto *ofproto_,
5620 enum ofp_config_flags frag_handling)
5622 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
5623 if (frag_handling != OFPC_FRAG_REASM) {
5624 ofproto->backer->need_revalidate = REV_RECONFIGURE;
5632 packet_out(struct ofproto *ofproto_, struct ofpbuf *packet,
5633 const struct flow *flow,
5634 const struct ofpact *ofpacts, size_t ofpacts_len)
5636 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
5637 struct odputil_keybuf keybuf;
5638 struct dpif_flow_stats stats;
5639 struct xlate_out xout;
5640 struct xlate_in xin;
5644 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
5645 odp_flow_key_from_flow(&key, flow,
5646 ofp_port_to_odp_port(ofproto,
5647 flow->in_port.ofp_port));
5649 dpif_flow_stats_extract(flow, packet, time_msec(), &stats);
5651 xlate_in_init(&xin, ofproto, flow, NULL, stats.tcp_flags, packet);
5652 xin.resubmit_stats = &stats;
5653 xin.ofpacts_len = ofpacts_len;
5654 xin.ofpacts = ofpacts;
5656 xlate_actions(&xin, &xout);
5657 dpif_execute(ofproto->backer->dpif, key.data, key.size,
5658 xout.odp_actions.data, xout.odp_actions.size, packet);
5659 xlate_out_uninit(&xout);
5667 set_netflow(struct ofproto *ofproto_,
5668 const struct netflow_options *netflow_options)
5670 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
5672 if (netflow_options) {
5673 if (!ofproto->netflow) {
5674 ofproto->netflow = netflow_create();
5675 ofproto->backer->need_revalidate = REV_RECONFIGURE;
5677 return netflow_set_options(ofproto->netflow, netflow_options);
5678 } else if (ofproto->netflow) {
5679 ofproto->backer->need_revalidate = REV_RECONFIGURE;
5680 netflow_destroy(ofproto->netflow);
5681 ofproto->netflow = NULL;
5688 get_netflow_ids(const struct ofproto *ofproto_,
5689 uint8_t *engine_type, uint8_t *engine_id)
5691 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
5693 dpif_get_netflow_ids(ofproto->backer->dpif, engine_type, engine_id);
5697 send_active_timeout(struct ofproto_dpif *ofproto, struct facet *facet)
5699 if (!facet_is_controller_flow(facet) &&
5700 netflow_active_timeout_expired(ofproto->netflow, &facet->nf_flow)) {
5701 struct subfacet *subfacet;
5702 struct ofexpired expired;
5704 LIST_FOR_EACH (subfacet, list_node, &facet->subfacets) {
5705 if (subfacet->path == SF_FAST_PATH) {
5706 struct dpif_flow_stats stats;
5708 subfacet_install(subfacet, &facet->xout.odp_actions,
5710 subfacet_update_stats(subfacet, &stats);
5714 expired.flow = facet->flow;
5715 expired.packet_count = facet->packet_count;
5716 expired.byte_count = facet->byte_count;
5717 expired.used = facet->used;
5718 netflow_expire(ofproto->netflow, &facet->nf_flow, &expired);
5723 send_netflow_active_timeouts(struct ofproto_dpif *ofproto)
5725 struct cls_cursor cursor;
5726 struct facet *facet;
5728 cls_cursor_init(&cursor, &ofproto->facets, NULL);
5729 CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
5730 send_active_timeout(ofproto, facet);
5734 static struct ofproto_dpif *
5735 ofproto_dpif_lookup(const char *name)
5737 struct ofproto_dpif *ofproto;
5739 HMAP_FOR_EACH_WITH_HASH (ofproto, all_ofproto_dpifs_node,
5740 hash_string(name, 0), &all_ofproto_dpifs) {
5741 if (!strcmp(ofproto->up.name, name)) {
5749 ofproto_unixctl_fdb_flush(struct unixctl_conn *conn, int argc,
5750 const char *argv[], void *aux OVS_UNUSED)
5752 struct ofproto_dpif *ofproto;
5755 ofproto = ofproto_dpif_lookup(argv[1]);
5757 unixctl_command_reply_error(conn, "no such bridge");
5760 mac_learning_flush(ofproto->ml, &ofproto->backer->revalidate_set);
5762 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
5763 mac_learning_flush(ofproto->ml, &ofproto->backer->revalidate_set);
5767 unixctl_command_reply(conn, "table successfully flushed");
5770 static struct ofport_dpif *
5771 ofbundle_get_a_port(const struct ofbundle *bundle)
5773 return CONTAINER_OF(list_front(&bundle->ports), struct ofport_dpif,
5778 ofproto_unixctl_fdb_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
5779 const char *argv[], void *aux OVS_UNUSED)
5781 struct ds ds = DS_EMPTY_INITIALIZER;
5782 const struct ofproto_dpif *ofproto;
5783 const struct mac_entry *e;
5785 ofproto = ofproto_dpif_lookup(argv[1]);
5787 unixctl_command_reply_error(conn, "no such bridge");
5791 ds_put_cstr(&ds, " port VLAN MAC Age\n");
5792 LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
5793 struct ofbundle *bundle = e->port.p;
5794 char name[OFP_MAX_PORT_NAME_LEN];
5796 ofputil_port_to_string(ofbundle_get_a_port(bundle)->up.ofp_port,
5798 ds_put_format(&ds, "%5s %4d "ETH_ADDR_FMT" %3d\n",
5799 name, e->vlan, ETH_ADDR_ARGS(e->mac),
5800 mac_entry_age(ofproto->ml, e));
5802 unixctl_command_reply(conn, ds_cstr(&ds));
5807 struct xlate_out xout;
5808 struct xlate_in xin;
5814 trace_format_rule(struct ds *result, int level, const struct rule_dpif *rule)
5816 ds_put_char_multiple(result, '\t', level);
5818 ds_put_cstr(result, "No match\n");
5822 ds_put_format(result, "Rule: table=%"PRIu8" cookie=%#"PRIx64" ",
5823 rule ? rule->up.table_id : 0, ntohll(rule->up.flow_cookie));
5824 cls_rule_format(&rule->up.cr, result);
5825 ds_put_char(result, '\n');
5827 ds_put_char_multiple(result, '\t', level);
5828 ds_put_cstr(result, "OpenFlow ");
5829 ofpacts_format(rule->up.ofpacts, rule->up.ofpacts_len, result);
5830 ds_put_char(result, '\n');
5834 trace_format_flow(struct ds *result, int level, const char *title,
5835 struct trace_ctx *trace)
5837 ds_put_char_multiple(result, '\t', level);
5838 ds_put_format(result, "%s: ", title);
5839 if (flow_equal(&trace->xin.flow, &trace->flow)) {
5840 ds_put_cstr(result, "unchanged");
5842 flow_format(result, &trace->xin.flow);
5843 trace->flow = trace->xin.flow;
5845 ds_put_char(result, '\n');
5849 trace_format_regs(struct ds *result, int level, const char *title,
5850 struct trace_ctx *trace)
5854 ds_put_char_multiple(result, '\t', level);
5855 ds_put_format(result, "%s:", title);
5856 for (i = 0; i < FLOW_N_REGS; i++) {
5857 ds_put_format(result, " reg%zu=0x%"PRIx32, i, trace->flow.regs[i]);
5859 ds_put_char(result, '\n');
5863 trace_format_odp(struct ds *result, int level, const char *title,
5864 struct trace_ctx *trace)
5866 struct ofpbuf *odp_actions = &trace->xout.odp_actions;
5868 ds_put_char_multiple(result, '\t', level);
5869 ds_put_format(result, "%s: ", title);
5870 format_odp_actions(result, odp_actions->data, odp_actions->size);
5871 ds_put_char(result, '\n');
5875 trace_resubmit(struct xlate_in *xin, struct rule_dpif *rule, int recurse)
5877 struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin);
5878 struct ds *result = trace->result;
5880 ds_put_char(result, '\n');
5881 trace_format_flow(result, recurse + 1, "Resubmitted flow", trace);
5882 trace_format_regs(result, recurse + 1, "Resubmitted regs", trace);
5883 trace_format_odp(result, recurse + 1, "Resubmitted odp", trace);
5884 trace_format_rule(result, recurse + 1, rule);
5888 trace_report(struct xlate_in *xin, const char *s, int recurse)
5890 struct trace_ctx *trace = CONTAINER_OF(xin, struct trace_ctx, xin);
5891 struct ds *result = trace->result;
5893 ds_put_char_multiple(result, '\t', recurse);
5894 ds_put_cstr(result, s);
5895 ds_put_char(result, '\n');
5899 ofproto_unixctl_trace(struct unixctl_conn *conn, int argc, const char *argv[],
5900 void *aux OVS_UNUSED)
5902 const struct dpif_backer *backer;
5903 struct ofproto_dpif *ofproto;
5904 struct ofpbuf odp_key, odp_mask;
5905 struct ofpbuf *packet;
5913 ofpbuf_init(&odp_key, 0);
5914 ofpbuf_init(&odp_mask, 0);
5916 /* Handle "-generate" or a hex string as the last argument. */
5917 if (!strcmp(argv[argc - 1], "-generate")) {
5918 packet = ofpbuf_new(0);
5921 const char *error = eth_from_hex(argv[argc - 1], &packet);
5924 } else if (argc == 4) {
5925 /* The 3-argument form must end in "-generate' or a hex string. */
5926 unixctl_command_reply_error(conn, error);
5931 /* Parse the flow and determine whether a datapath or
5932 * bridge is specified. If function odp_flow_key_from_string()
5933 * returns 0, the flow is a odp_flow. If function
5934 * parse_ofp_exact_flow() returns 0, the flow is a br_flow. */
5935 if (!odp_flow_from_string(argv[argc - 1], NULL, &odp_key, &odp_mask)) {
5936 /* If the odp_flow is the second argument,
5937 * the datapath name is the first argument. */
5939 const char *dp_type;
5940 if (!strncmp(argv[1], "ovs-", 4)) {
5941 dp_type = argv[1] + 4;
5945 backer = shash_find_data(&all_dpif_backers, dp_type);
5947 unixctl_command_reply_error(conn, "Cannot find datapath "
5952 /* No datapath name specified, so there should be only one
5954 struct shash_node *node;
5955 if (shash_count(&all_dpif_backers) != 1) {
5956 unixctl_command_reply_error(conn, "Must specify datapath "
5957 "name, there is more than one type of datapath");
5960 node = shash_first(&all_dpif_backers);
5961 backer = node->data;
5964 /* Extract the ofproto_dpif object from the ofproto_receive()
5966 if (ofproto_receive(backer, NULL, odp_key.data,
5967 odp_key.size, &flow, NULL, &ofproto, NULL)) {
5968 unixctl_command_reply_error(conn, "Invalid datapath flow");
5971 ds_put_format(&result, "Bridge: %s\n", ofproto->up.name);
5972 } else if (!parse_ofp_exact_flow(&flow, argv[argc - 1])) {
5974 unixctl_command_reply_error(conn, "Must specify bridge name");
5978 ofproto = ofproto_dpif_lookup(argv[1]);
5980 unixctl_command_reply_error(conn, "Unknown bridge name");
5984 unixctl_command_reply_error(conn, "Bad flow syntax");
5988 /* Generate a packet, if requested. */
5990 if (!packet->size) {
5991 flow_compose(packet, &flow);
5993 union flow_in_port in_port_;
5995 in_port_ = flow.in_port;
5996 ds_put_cstr(&result, "Packet: ");
5997 s = ofp_packet_to_string(packet->data, packet->size);
5998 ds_put_cstr(&result, s);
6001 /* Use the metadata from the flow and the packet argument
6002 * to reconstruct the flow. */
6003 flow_extract(packet, flow.skb_priority, flow.skb_mark, NULL,
6008 ofproto_trace(ofproto, &flow, packet, &result);
6009 unixctl_command_reply(conn, ds_cstr(&result));
6012 ds_destroy(&result);
6013 ofpbuf_delete(packet);
6014 ofpbuf_uninit(&odp_key);
6015 ofpbuf_uninit(&odp_mask);
6019 ofproto_trace(struct ofproto_dpif *ofproto, const struct flow *flow,
6020 const struct ofpbuf *packet, struct ds *ds)
6022 struct rule_dpif *rule;
6024 ds_put_cstr(ds, "Flow: ");
6025 flow_format(ds, flow);
6026 ds_put_char(ds, '\n');
6028 rule = rule_dpif_lookup(ofproto, flow, NULL);
6030 trace_format_rule(ds, 0, rule);
6031 if (rule == ofproto->miss_rule) {
6032 ds_put_cstr(ds, "\nNo match, flow generates \"packet in\"s.\n");
6033 } else if (rule == ofproto->no_packet_in_rule) {
6034 ds_put_cstr(ds, "\nNo match, packets dropped because "
6035 "OFPPC_NO_PACKET_IN is set on in_port.\n");
6036 } else if (rule == ofproto->drop_frags_rule) {
6037 ds_put_cstr(ds, "\nPackets dropped because they are IP fragments "
6038 "and the fragment handling mode is \"drop\".\n");
6042 uint64_t odp_actions_stub[1024 / 8];
6043 struct ofpbuf odp_actions;
6044 struct trace_ctx trace;
6048 tcp_flags = packet ? packet_get_tcp_flags(packet, flow) : 0;
6051 ofpbuf_use_stub(&odp_actions,
6052 odp_actions_stub, sizeof odp_actions_stub);
6053 xlate_in_init(&trace.xin, ofproto, flow, rule, tcp_flags, packet);
6054 trace.xin.resubmit_hook = trace_resubmit;
6055 trace.xin.report_hook = trace_report;
6057 xlate_actions(&trace.xin, &trace.xout);
6059 ds_put_char(ds, '\n');
6060 trace_format_flow(ds, 0, "Final flow", &trace);
6062 match_init(&match, flow, &trace.xout.wc);
6063 ds_put_cstr(ds, "Relevant fields: ");
6064 match_format(&match, ds, OFP_DEFAULT_PRIORITY);
6065 ds_put_char(ds, '\n');
6067 ds_put_cstr(ds, "Datapath actions: ");
6068 format_odp_actions(ds, trace.xout.odp_actions.data,
6069 trace.xout.odp_actions.size);
6071 if (trace.xout.slow) {
6072 ds_put_cstr(ds, "\nThis flow is handled by the userspace "
6073 "slow path because it:");
6074 switch (trace.xout.slow) {
6076 ds_put_cstr(ds, "\n\t- Consists of CFM packets.");
6079 ds_put_cstr(ds, "\n\t- Consists of LACP packets.");
6082 ds_put_cstr(ds, "\n\t- Consists of STP packets.");
6085 ds_put_cstr(ds, "\n\t- Consists of BFD packets.");
6087 case SLOW_CONTROLLER:
6088 ds_put_cstr(ds, "\n\t- Sends \"packet-in\" messages "
6089 "to the OpenFlow controller.");
6096 xlate_out_uninit(&trace.xout);
6101 ofproto_dpif_clog(struct unixctl_conn *conn OVS_UNUSED, int argc OVS_UNUSED,
6102 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
6105 unixctl_command_reply(conn, NULL);
6109 ofproto_dpif_unclog(struct unixctl_conn *conn OVS_UNUSED, int argc OVS_UNUSED,
6110 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
6113 unixctl_command_reply(conn, NULL);
6116 /* Runs a self-check of flow translations in 'ofproto'. Appends a message to
6117 * 'reply' describing the results. */
6119 ofproto_dpif_self_check__(struct ofproto_dpif *ofproto, struct ds *reply)
6121 struct cls_cursor cursor;
6122 struct facet *facet;
6126 cls_cursor_init(&cursor, &ofproto->facets, NULL);
6127 CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
6128 if (!facet_check_consistency(facet)) {
6133 ofproto->backer->need_revalidate = REV_INCONSISTENCY;
6137 ds_put_format(reply, "%s: self-check failed (%d errors)\n",
6138 ofproto->up.name, errors);
6140 ds_put_format(reply, "%s: self-check passed\n", ofproto->up.name);
6145 ofproto_dpif_self_check(struct unixctl_conn *conn,
6146 int argc, const char *argv[], void *aux OVS_UNUSED)
6148 struct ds reply = DS_EMPTY_INITIALIZER;
6149 struct ofproto_dpif *ofproto;
6152 ofproto = ofproto_dpif_lookup(argv[1]);
6154 unixctl_command_reply_error(conn, "Unknown ofproto (use "
6155 "ofproto/list for help)");
6158 ofproto_dpif_self_check__(ofproto, &reply);
6160 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
6161 ofproto_dpif_self_check__(ofproto, &reply);
6165 unixctl_command_reply(conn, ds_cstr(&reply));
6169 /* Store the current ofprotos in 'ofproto_shash'. Returns a sorted list
6170 * of the 'ofproto_shash' nodes. It is the responsibility of the caller
6171 * to destroy 'ofproto_shash' and free the returned value. */
6172 static const struct shash_node **
6173 get_ofprotos(struct shash *ofproto_shash)
6175 const struct ofproto_dpif *ofproto;
6177 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
6178 char *name = xasprintf("%s@%s", ofproto->up.type, ofproto->up.name);
6179 shash_add_nocopy(ofproto_shash, name, ofproto);
6182 return shash_sort(ofproto_shash);
6186 ofproto_unixctl_dpif_dump_dps(struct unixctl_conn *conn, int argc OVS_UNUSED,
6187 const char *argv[] OVS_UNUSED,
6188 void *aux OVS_UNUSED)
6190 struct ds ds = DS_EMPTY_INITIALIZER;
6191 struct shash ofproto_shash;
6192 const struct shash_node **sorted_ofprotos;
6195 shash_init(&ofproto_shash);
6196 sorted_ofprotos = get_ofprotos(&ofproto_shash);
6197 for (i = 0; i < shash_count(&ofproto_shash); i++) {
6198 const struct shash_node *node = sorted_ofprotos[i];
6199 ds_put_format(&ds, "%s\n", node->name);
6202 shash_destroy(&ofproto_shash);
6203 free(sorted_ofprotos);
6205 unixctl_command_reply(conn, ds_cstr(&ds));
6210 show_dp_rates(struct ds *ds, const char *heading,
6211 const struct avg_subfacet_rates *rates)
6213 ds_put_format(ds, "%s add rate: %5.3f/min, del rate: %5.3f/min\n",
6214 heading, rates->add_rate, rates->del_rate);
6218 dpif_show_backer(const struct dpif_backer *backer, struct ds *ds)
6220 const struct shash_node **ofprotos;
6221 struct ofproto_dpif *ofproto;
6222 struct shash ofproto_shash;
6223 uint64_t n_hit, n_missed;
6224 long long int minutes;
6227 n_hit = n_missed = 0;
6228 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
6229 if (ofproto->backer == backer) {
6230 n_missed += ofproto->n_missed;
6231 n_hit += ofproto->n_hit;
6235 ds_put_format(ds, "%s: hit:%"PRIu64" missed:%"PRIu64"\n",
6236 dpif_name(backer->dpif), n_hit, n_missed);
6237 ds_put_format(ds, "\tflows: cur: %zu, avg: %u, max: %u,"
6238 " life span: %lldms\n", hmap_count(&backer->subfacets),
6239 backer->avg_n_subfacet, backer->max_n_subfacet,
6240 backer->avg_subfacet_life);
6242 minutes = (time_msec() - backer->created) / (1000 * 60);
6243 if (minutes >= 60) {
6244 show_dp_rates(ds, "\thourly avg:", &backer->hourly);
6246 if (minutes >= 60 * 24) {
6247 show_dp_rates(ds, "\tdaily avg:", &backer->daily);
6249 show_dp_rates(ds, "\toverall avg:", &backer->lifetime);
6251 shash_init(&ofproto_shash);
6252 ofprotos = get_ofprotos(&ofproto_shash);
6253 for (i = 0; i < shash_count(&ofproto_shash); i++) {
6254 struct ofproto_dpif *ofproto = ofprotos[i]->data;
6255 const struct shash_node **ports;
6258 if (ofproto->backer != backer) {
6262 ds_put_format(ds, "\t%s: hit:%"PRIu64" missed:%"PRIu64"\n",
6263 ofproto->up.name, ofproto->n_hit, ofproto->n_missed);
6265 ports = shash_sort(&ofproto->up.port_by_name);
6266 for (j = 0; j < shash_count(&ofproto->up.port_by_name); j++) {
6267 const struct shash_node *node = ports[j];
6268 struct ofport *ofport = node->data;
6270 odp_port_t odp_port;
6272 ds_put_format(ds, "\t\t%s %u/", netdev_get_name(ofport->netdev),
6275 odp_port = ofp_port_to_odp_port(ofproto, ofport->ofp_port);
6276 if (odp_port != ODPP_NONE) {
6277 ds_put_format(ds, "%"PRIu32":", odp_port);
6279 ds_put_cstr(ds, "none:");
6282 ds_put_format(ds, " (%s", netdev_get_type(ofport->netdev));
6285 if (!netdev_get_config(ofport->netdev, &config)) {
6286 const struct smap_node **nodes;
6289 nodes = smap_sort(&config);
6290 for (i = 0; i < smap_count(&config); i++) {
6291 const struct smap_node *node = nodes[i];
6292 ds_put_format(ds, "%c %s=%s", i ? ',' : ':',
6293 node->key, node->value);
6297 smap_destroy(&config);
6299 ds_put_char(ds, ')');
6300 ds_put_char(ds, '\n');
6304 shash_destroy(&ofproto_shash);
6309 ofproto_unixctl_dpif_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
6310 const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
6312 struct ds ds = DS_EMPTY_INITIALIZER;
6313 const struct shash_node **backers;
6316 backers = shash_sort(&all_dpif_backers);
6317 for (i = 0; i < shash_count(&all_dpif_backers); i++) {
6318 dpif_show_backer(backers[i]->data, &ds);
6322 unixctl_command_reply(conn, ds_cstr(&ds));
6326 /* Dump the megaflow (facet) cache. This is useful to check the
6327 * correctness of flow wildcarding, since the same mechanism is used for
6328 * both xlate caching and kernel wildcarding.
6330 * It's important to note that in the output the flow description uses
6331 * OpenFlow (OFP) ports, but the actions use datapath (ODP) ports.
6333 * This command is only needed for advanced debugging, so it's not
6334 * documented in the man page. */
6336 ofproto_unixctl_dpif_dump_megaflows(struct unixctl_conn *conn,
6337 int argc OVS_UNUSED, const char *argv[],
6338 void *aux OVS_UNUSED)
6340 struct ds ds = DS_EMPTY_INITIALIZER;
6341 const struct ofproto_dpif *ofproto;
6342 long long int now = time_msec();
6343 struct cls_cursor cursor;
6344 struct facet *facet;
6346 ofproto = ofproto_dpif_lookup(argv[1]);
6348 unixctl_command_reply_error(conn, "no such bridge");
6352 cls_cursor_init(&cursor, &ofproto->facets, NULL);
6353 CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
6354 cls_rule_format(&facet->cr, &ds);
6355 ds_put_cstr(&ds, ", ");
6356 ds_put_format(&ds, "n_subfacets:%zu, ", list_size(&facet->subfacets));
6357 ds_put_format(&ds, "used:%.3fs, ", (now - facet->used) / 1000.0);
6358 ds_put_cstr(&ds, "Datapath actions: ");
6359 if (facet->xout.slow) {
6360 uint64_t slow_path_stub[128 / 8];
6361 const struct nlattr *actions;
6364 compose_slow_path(ofproto, &facet->flow, facet->xout.slow,
6365 slow_path_stub, sizeof slow_path_stub,
6366 &actions, &actions_len);
6367 format_odp_actions(&ds, actions, actions_len);
6369 format_odp_actions(&ds, facet->xout.odp_actions.data,
6370 facet->xout.odp_actions.size);
6372 ds_put_cstr(&ds, "\n");
6375 ds_chomp(&ds, '\n');
6376 unixctl_command_reply(conn, ds_cstr(&ds));
6380 /* Disable using the megaflows.
6382 * This command is only needed for advanced debugging, so it's not
6383 * documented in the man page. */
6385 ofproto_unixctl_dpif_disable_megaflows(struct unixctl_conn *conn,
6386 int argc OVS_UNUSED,
6387 const char *argv[] OVS_UNUSED,
6388 void *aux OVS_UNUSED)
6390 struct ofproto_dpif *ofproto;
6392 enable_megaflows = false;
6394 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
6395 flush(&ofproto->up);
6398 unixctl_command_reply(conn, "megaflows disabled");
6401 /* Re-enable using megaflows.
6403 * This command is only needed for advanced debugging, so it's not
6404 * documented in the man page. */
6406 ofproto_unixctl_dpif_enable_megaflows(struct unixctl_conn *conn,
6407 int argc OVS_UNUSED,
6408 const char *argv[] OVS_UNUSED,
6409 void *aux OVS_UNUSED)
6411 struct ofproto_dpif *ofproto;
6413 enable_megaflows = true;
6415 HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
6416 flush(&ofproto->up);
6419 unixctl_command_reply(conn, "megaflows enabled");
6423 ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn,
6424 int argc OVS_UNUSED, const char *argv[],
6425 void *aux OVS_UNUSED)
6427 struct ds ds = DS_EMPTY_INITIALIZER;
6428 const struct ofproto_dpif *ofproto;
6429 struct subfacet *subfacet;
6431 ofproto = ofproto_dpif_lookup(argv[1]);
6433 unixctl_command_reply_error(conn, "no such bridge");
6437 update_stats(ofproto->backer);
6439 HMAP_FOR_EACH (subfacet, hmap_node, &ofproto->backer->subfacets) {
6440 struct facet *facet = subfacet->facet;
6441 struct odputil_keybuf maskbuf;
6444 if (facet->ofproto != ofproto) {
6448 ofpbuf_use_stack(&mask, &maskbuf, sizeof maskbuf);
6449 if (enable_megaflows) {
6450 odp_flow_key_from_mask(&mask, &facet->xout.wc.masks,
6451 &facet->flow, UINT32_MAX);
6454 odp_flow_format(subfacet->key, subfacet->key_len,
6455 mask.data, mask.size, &ds);
6457 ds_put_format(&ds, ", packets:%"PRIu64", bytes:%"PRIu64", used:",
6458 subfacet->dp_packet_count, subfacet->dp_byte_count);
6459 if (subfacet->used) {
6460 ds_put_format(&ds, "%.3fs",
6461 (time_msec() - subfacet->used) / 1000.0);
6463 ds_put_format(&ds, "never");
6465 if (subfacet->facet->tcp_flags) {
6466 ds_put_cstr(&ds, ", flags:");
6467 packet_format_tcp_flags(&ds, subfacet->facet->tcp_flags);
6470 ds_put_cstr(&ds, ", actions:");
6471 if (facet->xout.slow) {
6472 uint64_t slow_path_stub[128 / 8];
6473 const struct nlattr *actions;
6476 compose_slow_path(ofproto, &facet->flow, facet->xout.slow,
6477 slow_path_stub, sizeof slow_path_stub,
6478 &actions, &actions_len);
6479 format_odp_actions(&ds, actions, actions_len);
6481 format_odp_actions(&ds, facet->xout.odp_actions.data,
6482 facet->xout.odp_actions.size);
6484 ds_put_char(&ds, '\n');
6487 unixctl_command_reply(conn, ds_cstr(&ds));
6492 ofproto_unixctl_dpif_del_flows(struct unixctl_conn *conn,
6493 int argc OVS_UNUSED, const char *argv[],
6494 void *aux OVS_UNUSED)
6496 struct ds ds = DS_EMPTY_INITIALIZER;
6497 struct ofproto_dpif *ofproto;
6499 ofproto = ofproto_dpif_lookup(argv[1]);
6501 unixctl_command_reply_error(conn, "no such bridge");
6505 flush(&ofproto->up);
6507 unixctl_command_reply(conn, ds_cstr(&ds));
6512 ofproto_dpif_unixctl_init(void)
6514 static bool registered;
6520 unixctl_command_register(
6522 "[dp_name]|bridge odp_flow|br_flow [-generate|packet]",
6523 1, 3, ofproto_unixctl_trace, NULL);
6524 unixctl_command_register("fdb/flush", "[bridge]", 0, 1,
6525 ofproto_unixctl_fdb_flush, NULL);
6526 unixctl_command_register("fdb/show", "bridge", 1, 1,
6527 ofproto_unixctl_fdb_show, NULL);
6528 unixctl_command_register("ofproto/clog", "", 0, 0,
6529 ofproto_dpif_clog, NULL);
6530 unixctl_command_register("ofproto/unclog", "", 0, 0,
6531 ofproto_dpif_unclog, NULL);
6532 unixctl_command_register("ofproto/self-check", "[bridge]", 0, 1,
6533 ofproto_dpif_self_check, NULL);
6534 unixctl_command_register("dpif/dump-dps", "", 0, 0,
6535 ofproto_unixctl_dpif_dump_dps, NULL);
6536 unixctl_command_register("dpif/show", "", 0, 0, ofproto_unixctl_dpif_show,
6538 unixctl_command_register("dpif/dump-flows", "bridge", 1, 1,
6539 ofproto_unixctl_dpif_dump_flows, NULL);
6540 unixctl_command_register("dpif/del-flows", "bridge", 1, 1,
6541 ofproto_unixctl_dpif_del_flows, NULL);
6542 unixctl_command_register("dpif/dump-megaflows", "bridge", 1, 1,
6543 ofproto_unixctl_dpif_dump_megaflows, NULL);
6544 unixctl_command_register("dpif/disable-megaflows", "", 0, 0,
6545 ofproto_unixctl_dpif_disable_megaflows, NULL);
6546 unixctl_command_register("dpif/enable-megaflows", "", 0, 0,
6547 ofproto_unixctl_dpif_enable_megaflows, NULL);
6550 /* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
6552 * This is deprecated. It is only for compatibility with broken device drivers
6553 * in old versions of Linux that do not properly support VLANs when VLAN
6554 * devices are not used. When broken device drivers are no longer in
6555 * widespread use, we will delete these interfaces. */
6558 set_realdev(struct ofport *ofport_, ofp_port_t realdev_ofp_port, int vid)
6560 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport_->ofproto);
6561 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
6563 if (realdev_ofp_port == ofport->realdev_ofp_port
6564 && vid == ofport->vlandev_vid) {
6568 ofproto->backer->need_revalidate = REV_RECONFIGURE;
6570 if (ofport->realdev_ofp_port) {
6573 if (realdev_ofp_port && ofport->bundle) {
6574 /* vlandevs are enslaved to their realdevs, so they are not allowed to
6575 * themselves be part of a bundle. */
6576 bundle_set(ofport->up.ofproto, ofport->bundle, NULL);
6579 ofport->realdev_ofp_port = realdev_ofp_port;
6580 ofport->vlandev_vid = vid;
6582 if (realdev_ofp_port) {
6583 vsp_add(ofport, realdev_ofp_port, vid);
6590 hash_realdev_vid(ofp_port_t realdev_ofp_port, int vid)
6592 return hash_2words(ofp_to_u16(realdev_ofp_port), vid);
6596 ofproto_has_vlan_splinters(const struct ofproto_dpif *ofproto)
6598 return !hmap_is_empty(&ofproto->realdev_vid_map);
6601 /* Returns the OFP port number of the Linux VLAN device that corresponds to
6602 * 'vlan_tci' on the network device with port number 'realdev_ofp_port' in
6603 * 'struct ofport_dpif'. For example, given 'realdev_ofp_port' of eth0 and
6604 * 'vlan_tci' 9, it would return the port number of eth0.9.
6606 * Unless VLAN splinters are enabled for port 'realdev_ofp_port', this
6607 * function just returns its 'realdev_ofp_port' argument. */
6609 vsp_realdev_to_vlandev(const struct ofproto_dpif *ofproto,
6610 ofp_port_t realdev_ofp_port, ovs_be16 vlan_tci)
6612 if (!hmap_is_empty(&ofproto->realdev_vid_map)) {
6613 int vid = vlan_tci_to_vid(vlan_tci);
6614 const struct vlan_splinter *vsp;
6616 HMAP_FOR_EACH_WITH_HASH (vsp, realdev_vid_node,
6617 hash_realdev_vid(realdev_ofp_port, vid),
6618 &ofproto->realdev_vid_map) {
6619 if (vsp->realdev_ofp_port == realdev_ofp_port
6620 && vsp->vid == vid) {
6621 return vsp->vlandev_ofp_port;
6625 return realdev_ofp_port;
6628 static struct vlan_splinter *
6629 vlandev_find(const struct ofproto_dpif *ofproto, ofp_port_t vlandev_ofp_port)
6631 struct vlan_splinter *vsp;
6633 HMAP_FOR_EACH_WITH_HASH (vsp, vlandev_node,
6634 hash_ofp_port(vlandev_ofp_port),
6635 &ofproto->vlandev_map) {
6636 if (vsp->vlandev_ofp_port == vlandev_ofp_port) {
6644 /* Returns the OpenFlow port number of the "real" device underlying the Linux
6645 * VLAN device with OpenFlow port number 'vlandev_ofp_port' and stores the
6646 * VLAN VID of the Linux VLAN device in '*vid'. For example, given
6647 * 'vlandev_ofp_port' of eth0.9, it would return the OpenFlow port number of
6648 * eth0 and store 9 in '*vid'.
6650 * Returns 0 and does not modify '*vid' if 'vlandev_ofp_port' is not a Linux
6651 * VLAN device. Unless VLAN splinters are enabled, this is what this function
6654 vsp_vlandev_to_realdev(const struct ofproto_dpif *ofproto,
6655 ofp_port_t vlandev_ofp_port, int *vid)
6657 if (!hmap_is_empty(&ofproto->vlandev_map)) {
6658 const struct vlan_splinter *vsp;
6660 vsp = vlandev_find(ofproto, vlandev_ofp_port);
6665 return vsp->realdev_ofp_port;
6671 /* Given 'flow', a flow representing a packet received on 'ofproto', checks
6672 * whether 'flow->in_port' represents a Linux VLAN device. If so, changes
6673 * 'flow->in_port' to the "real" device backing the VLAN device, sets
6674 * 'flow->vlan_tci' to the VLAN VID, and returns true. Otherwise (which is
6675 * always the case unless VLAN splinters are enabled), returns false without
6676 * making any changes. */
6678 vsp_adjust_flow(const struct ofproto_dpif *ofproto, struct flow *flow)
6683 realdev = vsp_vlandev_to_realdev(ofproto, flow->in_port.ofp_port, &vid);
6688 /* Cause the flow to be processed as if it came in on the real device with
6689 * the VLAN device's VLAN ID. */
6690 flow->in_port.ofp_port = realdev;
6691 flow->vlan_tci = htons((vid & VLAN_VID_MASK) | VLAN_CFI);
6696 vsp_remove(struct ofport_dpif *port)
6698 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
6699 struct vlan_splinter *vsp;
6701 vsp = vlandev_find(ofproto, port->up.ofp_port);
6703 hmap_remove(&ofproto->vlandev_map, &vsp->vlandev_node);
6704 hmap_remove(&ofproto->realdev_vid_map, &vsp->realdev_vid_node);
6707 port->realdev_ofp_port = 0;
6709 VLOG_ERR("missing vlan device record");
6714 vsp_add(struct ofport_dpif *port, ofp_port_t realdev_ofp_port, int vid)
6716 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
6718 if (!vsp_vlandev_to_realdev(ofproto, port->up.ofp_port, NULL)
6719 && (vsp_realdev_to_vlandev(ofproto, realdev_ofp_port, htons(vid))
6720 == realdev_ofp_port)) {
6721 struct vlan_splinter *vsp;
6723 vsp = xmalloc(sizeof *vsp);
6724 hmap_insert(&ofproto->vlandev_map, &vsp->vlandev_node,
6725 hash_ofp_port(port->up.ofp_port));
6726 hmap_insert(&ofproto->realdev_vid_map, &vsp->realdev_vid_node,
6727 hash_realdev_vid(realdev_ofp_port, vid));
6728 vsp->realdev_ofp_port = realdev_ofp_port;
6729 vsp->vlandev_ofp_port = port->up.ofp_port;
6732 port->realdev_ofp_port = realdev_ofp_port;
6734 VLOG_ERR("duplicate vlan device record");
6739 ofp_port_to_odp_port(const struct ofproto_dpif *ofproto, ofp_port_t ofp_port)
6741 const struct ofport_dpif *ofport = get_ofp_port(ofproto, ofp_port);
6742 return ofport ? ofport->odp_port : ODPP_NONE;
6745 static struct ofport_dpif *
6746 odp_port_to_ofport(const struct dpif_backer *backer, odp_port_t odp_port)
6748 struct ofport_dpif *port;
6750 HMAP_FOR_EACH_IN_BUCKET (port, odp_port_node, hash_odp_port(odp_port),
6751 &backer->odp_to_ofport_map) {
6752 if (port->odp_port == odp_port) {
6761 odp_port_to_ofp_port(const struct ofproto_dpif *ofproto, odp_port_t odp_port)
6763 struct ofport_dpif *port;
6765 port = odp_port_to_ofport(ofproto->backer, odp_port);
6766 if (port && &ofproto->up == port->up.ofproto) {
6767 return port->up.ofp_port;
6773 /* Compute exponentially weighted moving average, adding 'new' as the newest,
6774 * most heavily weighted element. 'base' designates the rate of decay: after
6775 * 'base' further updates, 'new''s weight in the EWMA decays to about 1/e
6778 exp_mavg(double *avg, int base, double new)
6780 *avg = (*avg * (base - 1) + new) / base;
6784 update_moving_averages(struct dpif_backer *backer)
6786 const int min_ms = 60 * 1000; /* milliseconds in one minute. */
6787 long long int minutes = (time_msec() - backer->created) / min_ms;
6790 backer->lifetime.add_rate = (double) backer->total_subfacet_add_count
6792 backer->lifetime.del_rate = (double) backer->total_subfacet_del_count
6795 backer->lifetime.add_rate = 0.0;
6796 backer->lifetime.del_rate = 0.0;
6799 /* Update hourly averages on the minute boundaries. */
6800 if (time_msec() - backer->last_minute >= min_ms) {
6801 exp_mavg(&backer->hourly.add_rate, 60, backer->subfacet_add_count);
6802 exp_mavg(&backer->hourly.del_rate, 60, backer->subfacet_del_count);
6804 /* Update daily averages on the hour boundaries. */
6805 if ((backer->last_minute - backer->created) / min_ms % 60 == 59) {
6806 exp_mavg(&backer->daily.add_rate, 24, backer->hourly.add_rate);
6807 exp_mavg(&backer->daily.del_rate, 24, backer->hourly.del_rate);
6810 backer->total_subfacet_add_count += backer->subfacet_add_count;
6811 backer->total_subfacet_del_count += backer->subfacet_del_count;
6812 backer->subfacet_add_count = 0;
6813 backer->subfacet_del_count = 0;
6814 backer->last_minute += min_ms;
6818 const struct ofproto_class ofproto_dpif_class = {
6853 port_is_lacp_current,
6854 NULL, /* rule_choose_table */
6861 rule_modify_actions,
6875 get_stp_port_status,
6882 is_mirror_output_bundle,
6883 forward_bpdu_changed,
6884 set_mac_table_config,
6886 NULL, /* meter_get_features */
6887 NULL, /* meter_set */
6888 NULL, /* meter_get */
6889 NULL, /* meter_del */