2 * Copyright (c) 2009, 2010, 2011 Nicira Networks.
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-provider.h"
26 #include "byte-order.h"
31 #include "dynamic-string.h"
32 #include "fail-open.h"
36 #include "mac-learning.h"
37 #include "multipath.h"
44 #include "ofp-print.h"
45 #include "ofproto-dpif-sflow.h"
46 #include "poll-loop.h"
48 #include "unaligned.h"
50 #include "vlan-bitmap.h"
53 VLOG_DEFINE_THIS_MODULE(ofproto_dpif);
55 COVERAGE_DEFINE(ofproto_dpif_ctlr_action);
56 COVERAGE_DEFINE(ofproto_dpif_expired);
57 COVERAGE_DEFINE(ofproto_dpif_no_packet_in);
58 COVERAGE_DEFINE(ofproto_dpif_xlate);
59 COVERAGE_DEFINE(facet_changed_rule);
60 COVERAGE_DEFINE(facet_invalidated);
61 COVERAGE_DEFINE(facet_revalidate);
62 COVERAGE_DEFINE(facet_unexpected);
64 /* Maximum depth of flow table recursion (due to resubmit actions) in a
65 * flow translation. */
66 #define MAX_RESUBMIT_RECURSION 16
68 /* Number of implemented OpenFlow tables. */
69 enum { N_TABLES = 255 };
70 BUILD_ASSERT_DECL(N_TABLES >= 1 && N_TABLES <= 255);
78 long long int used; /* Time last used; time created if not used. */
82 * - Do include packets and bytes from facets that have been deleted or
83 * whose own statistics have been folded into the rule.
85 * - Do include packets and bytes sent "by hand" that were accounted to
86 * the rule without any facet being involved (this is a rare corner
87 * case in rule_execute()).
89 * - Do not include packet or bytes that can be obtained from any facet's
90 * packet_count or byte_count member or that can be obtained from the
91 * datapath by, e.g., dpif_flow_get() for any facet.
93 uint64_t packet_count; /* Number of packets received. */
94 uint64_t byte_count; /* Number of bytes received. */
96 tag_type tag; /* Caches rule_calculate_tag() result. */
98 struct list facets; /* List of "struct facet"s. */
101 static struct rule_dpif *rule_dpif_cast(const struct rule *rule)
103 return rule ? CONTAINER_OF(rule, struct rule_dpif, up) : NULL;
106 static struct rule_dpif *rule_dpif_lookup(struct ofproto_dpif *,
107 const struct flow *, uint8_t table);
109 #define MAX_MIRRORS 32
110 typedef uint32_t mirror_mask_t;
111 #define MIRROR_MASK_C(X) UINT32_C(X)
112 BUILD_ASSERT_DECL(sizeof(mirror_mask_t) * CHAR_BIT >= MAX_MIRRORS);
114 struct ofproto_dpif *ofproto; /* Owning ofproto. */
115 size_t idx; /* In ofproto's "mirrors" array. */
116 void *aux; /* Key supplied by ofproto's client. */
117 char *name; /* Identifier for log messages. */
119 /* Selection criteria. */
120 struct hmapx srcs; /* Contains "struct ofbundle *"s. */
121 struct hmapx dsts; /* Contains "struct ofbundle *"s. */
122 unsigned long *vlans; /* Bitmap of chosen VLANs, NULL selects all. */
124 /* Output (mutually exclusive). */
125 struct ofbundle *out; /* Output port or NULL. */
126 int out_vlan; /* Output VLAN or -1. */
129 static void mirror_destroy(struct ofmirror *);
131 /* A group of one or more OpenFlow ports. */
132 #define OFBUNDLE_FLOOD ((struct ofbundle *) 1)
134 struct ofproto_dpif *ofproto; /* Owning ofproto. */
135 struct hmap_node hmap_node; /* In struct ofproto's "bundles" hmap. */
136 void *aux; /* Key supplied by ofproto's client. */
137 char *name; /* Identifier for log messages. */
140 struct list ports; /* Contains "struct ofport"s. */
141 enum port_vlan_mode vlan_mode; /* VLAN mode */
142 int vlan; /* -1=trunk port, else a 12-bit VLAN ID. */
143 unsigned long *trunks; /* Bitmap of trunked VLANs, if 'vlan' == -1.
144 * NULL if all VLANs are trunked. */
145 struct lacp *lacp; /* LACP if LACP is enabled, otherwise NULL. */
146 struct bond *bond; /* Nonnull iff more than one port. */
149 bool floodable; /* True if no port has OFPPC_NO_FLOOD set. */
151 /* Port mirroring info. */
152 mirror_mask_t src_mirrors; /* Mirrors triggered when packet received. */
153 mirror_mask_t dst_mirrors; /* Mirrors triggered when packet sent. */
154 mirror_mask_t mirror_out; /* Mirrors that output to this bundle. */
157 static void bundle_remove(struct ofport *);
158 static void bundle_destroy(struct ofbundle *);
159 static void bundle_del_port(struct ofport_dpif *);
160 static void bundle_run(struct ofbundle *);
161 static void bundle_wait(struct ofbundle *);
163 struct action_xlate_ctx {
164 /* action_xlate_ctx_init() initializes these members. */
167 struct ofproto_dpif *ofproto;
169 /* Flow to which the OpenFlow actions apply. xlate_actions() will modify
170 * this flow when actions change header fields. */
173 /* The packet corresponding to 'flow', or a null pointer if we are
174 * revalidating without a packet to refer to. */
175 const struct ofpbuf *packet;
177 /* Should OFPP_NORMAL MAC learning and NXAST_LEARN actions execute? We
178 * want to execute them if we are actually processing a packet, or if we
179 * are accounting for packets that the datapath has processed, but not if
180 * we are just revalidating. */
183 /* If nonnull, called just before executing a resubmit action.
185 * This is normally null so the client has to set it manually after
186 * calling action_xlate_ctx_init(). */
187 void (*resubmit_hook)(struct action_xlate_ctx *, struct rule_dpif *);
189 /* xlate_actions() initializes and uses these members. The client might want
190 * to look at them after it returns. */
192 struct ofpbuf *odp_actions; /* Datapath actions. */
193 tag_type tags; /* Tags associated with actions. */
194 bool may_set_up_flow; /* True ordinarily; false if the actions must
195 * be reassessed for every packet. */
196 bool has_learn; /* Actions include NXAST_LEARN? */
197 bool has_normal; /* Actions output to OFPP_NORMAL? */
198 uint16_t nf_output_iface; /* Output interface index for NetFlow. */
200 /* xlate_actions() initializes and uses these members, but the client has no
201 * reason to look at them. */
203 int recurse; /* Recursion level, via xlate_table_action. */
204 uint32_t priority; /* Current flow priority. 0 if none. */
205 struct flow base_flow; /* Flow at the last commit. */
206 uint32_t base_priority; /* Priority at the last commit. */
207 uint8_t table_id; /* OpenFlow table ID where flow was found. */
208 uint32_t sflow_n_outputs; /* Number of output ports. */
209 uint16_t sflow_odp_port; /* Output port for composing sFlow action. */
210 uint16_t user_cookie_offset;/* Used for user_action_cookie fixup. */
213 static void action_xlate_ctx_init(struct action_xlate_ctx *,
214 struct ofproto_dpif *, const struct flow *,
215 const struct ofpbuf *);
216 static struct ofpbuf *xlate_actions(struct action_xlate_ctx *,
217 const union ofp_action *in, size_t n_in);
219 /* An exact-match instantiation of an OpenFlow flow. */
221 long long int used; /* Time last used; time created if not used. */
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 its statistics were reset (e.g. dpif_flow_put() with
230 * DPIF_FP_ZERO_STATS).
232 uint64_t packet_count; /* Number of packets received. */
233 uint64_t byte_count; /* Number of bytes received. */
235 uint64_t dp_packet_count; /* Last known packet count in the datapath. */
236 uint64_t dp_byte_count; /* Last known byte count in the datapath. */
238 uint64_t rs_packet_count; /* Packets pushed to resubmit children. */
239 uint64_t rs_byte_count; /* Bytes pushed to resubmit children. */
240 long long int rs_used; /* Used time pushed to resubmit children. */
242 uint64_t accounted_bytes; /* Bytes processed by facet_account(). */
244 struct hmap_node hmap_node; /* In owning ofproto's 'facets' hmap. */
245 struct list list_node; /* In owning rule's 'facets' list. */
246 struct rule_dpif *rule; /* Owning rule. */
247 struct flow flow; /* Exact-match flow. */
248 bool installed; /* Installed in datapath? */
249 bool may_install; /* True ordinarily; false if actions must
250 * be reassessed for every packet. */
251 bool has_learn; /* Actions include NXAST_LEARN? */
252 bool has_normal; /* Actions output to OFPP_NORMAL? */
253 size_t actions_len; /* Number of bytes in actions[]. */
254 struct nlattr *actions; /* Datapath actions. */
255 tag_type tags; /* Tags. */
256 struct netflow_flow nf_flow; /* Per-flow NetFlow tracking data. */
259 static struct facet *facet_create(struct rule_dpif *, const struct flow *,
260 const struct ofpbuf *packet);
261 static void facet_remove(struct ofproto_dpif *, struct facet *);
262 static void facet_free(struct facet *);
264 static struct facet *facet_find(struct ofproto_dpif *, const struct flow *);
265 static struct facet *facet_lookup_valid(struct ofproto_dpif *,
266 const struct flow *);
267 static bool facet_revalidate(struct ofproto_dpif *, struct facet *);
269 static void facet_execute(struct ofproto_dpif *, struct facet *,
270 struct ofpbuf *packet);
272 static int facet_put__(struct ofproto_dpif *, struct facet *,
273 const struct nlattr *actions, size_t actions_len,
274 struct dpif_flow_stats *);
275 static void facet_install(struct ofproto_dpif *, struct facet *,
277 static void facet_uninstall(struct ofproto_dpif *, struct facet *);
278 static void facet_flush_stats(struct ofproto_dpif *, struct facet *);
280 static void facet_make_actions(struct ofproto_dpif *, struct facet *,
281 const struct ofpbuf *packet);
282 static void facet_update_time(struct ofproto_dpif *, struct facet *,
284 static void facet_update_stats(struct ofproto_dpif *, struct facet *,
285 const struct dpif_flow_stats *);
286 static void facet_reset_counters(struct facet *);
287 static void facet_reset_dp_stats(struct facet *, struct dpif_flow_stats *);
288 static void facet_push_stats(struct facet *);
289 static void facet_account(struct ofproto_dpif *, struct facet *);
291 static bool facet_is_controller_flow(struct facet *);
293 static void flow_push_stats(const struct rule_dpif *,
294 struct flow *, uint64_t packets, uint64_t bytes,
297 static uint32_t rule_calculate_tag(const struct flow *,
298 const struct flow_wildcards *,
300 static void rule_invalidate(const struct rule_dpif *);
306 struct ofbundle *bundle; /* Bundle that contains this port, if any. */
307 struct list bundle_node; /* In struct ofbundle's "ports" list. */
308 struct cfm *cfm; /* Connectivity Fault Management, if any. */
309 tag_type tag; /* Tag associated with this port. */
310 uint32_t bond_stable_id; /* stable_id to use as bond slave, or 0. */
311 bool may_enable; /* May be enabled in bonds. */
314 static struct ofport_dpif *
315 ofport_dpif_cast(const struct ofport *ofport)
317 assert(ofport->ofproto->ofproto_class == &ofproto_dpif_class);
318 return ofport ? CONTAINER_OF(ofport, struct ofport_dpif, up) : NULL;
321 static void port_run(struct ofport_dpif *);
322 static void port_wait(struct ofport_dpif *);
323 static int set_cfm(struct ofport *, const struct cfm_settings *);
325 struct dpif_completion {
326 struct list list_node;
327 struct ofoperation *op;
330 /* Extra information about a classifier table.
331 * Currently used just for optimized flow revalidation. */
333 /* If either of these is nonnull, then this table has a form that allows
334 * flows to be tagged to avoid revalidating most flows for the most common
335 * kinds of flow table changes. */
336 struct cls_table *catchall_table; /* Table that wildcards all fields. */
337 struct cls_table *other_table; /* Table with any other wildcard set. */
338 uint32_t basis; /* Keeps each table's tags separate. */
341 struct ofproto_dpif {
350 struct netflow *netflow;
351 struct dpif_sflow *sflow;
352 struct hmap bundles; /* Contains "struct ofbundle"s. */
353 struct mac_learning *ml;
354 struct ofmirror *mirrors[MAX_MIRRORS];
355 bool has_bonded_bundles;
358 struct timer next_expiration;
364 struct table_dpif tables[N_TABLES];
365 bool need_revalidate;
366 struct tag_set revalidate_set;
368 /* Support for debugging async flow mods. */
369 struct list completions;
371 bool has_bundle_action; /* True when the first bundle action appears. */
374 /* Defer flow mod completion until "ovs-appctl ofproto/unclog"? (Useful only
375 * for debugging the asynchronous flow_mod implementation.) */
378 static void ofproto_dpif_unixctl_init(void);
380 static struct ofproto_dpif *
381 ofproto_dpif_cast(const struct ofproto *ofproto)
383 assert(ofproto->ofproto_class == &ofproto_dpif_class);
384 return CONTAINER_OF(ofproto, struct ofproto_dpif, up);
387 static struct ofport_dpif *get_ofp_port(struct ofproto_dpif *,
389 static struct ofport_dpif *get_odp_port(struct ofproto_dpif *,
392 /* Packet processing. */
393 static void update_learning_table(struct ofproto_dpif *,
394 const struct flow *, int vlan,
396 static bool is_admissible(struct ofproto_dpif *, const struct flow *,
397 bool have_packet, tag_type *, int *vlanp,
398 struct ofbundle **in_bundlep);
399 static void handle_upcall(struct ofproto_dpif *, struct dpif_upcall *);
401 /* Flow expiration. */
402 static int expire(struct ofproto_dpif *);
405 static int send_packet(struct ofproto_dpif *, uint32_t odp_port,
406 const struct ofpbuf *packet);
408 compose_sflow_action(const struct ofproto_dpif *, struct ofpbuf *odp_actions,
409 const struct flow *, uint32_t odp_port);
410 /* Global variables. */
411 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
413 /* Factory functions. */
416 enumerate_types(struct sset *types)
418 dp_enumerate_types(types);
422 enumerate_names(const char *type, struct sset *names)
424 return dp_enumerate_names(type, names);
428 del(const char *type, const char *name)
433 error = dpif_open(name, type, &dpif);
435 error = dpif_delete(dpif);
441 /* Basic life-cycle. */
443 static struct ofproto *
446 struct ofproto_dpif *ofproto = xmalloc(sizeof *ofproto);
451 dealloc(struct ofproto *ofproto_)
453 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
458 construct(struct ofproto *ofproto_, int *n_tablesp)
460 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
461 const char *name = ofproto->up.name;
465 error = dpif_create_and_open(name, ofproto->up.type, &ofproto->dpif);
467 VLOG_ERR("failed to open datapath %s: %s", name, strerror(error));
471 ofproto->max_ports = dpif_get_max_ports(ofproto->dpif);
472 ofproto->n_matches = 0;
474 dpif_flow_flush(ofproto->dpif);
475 dpif_recv_purge(ofproto->dpif);
477 error = dpif_recv_set_mask(ofproto->dpif,
478 ((1u << DPIF_UC_MISS) |
479 (1u << DPIF_UC_ACTION)));
481 VLOG_ERR("failed to listen on datapath %s: %s", name, strerror(error));
482 dpif_close(ofproto->dpif);
486 ofproto->netflow = NULL;
487 ofproto->sflow = NULL;
488 hmap_init(&ofproto->bundles);
489 ofproto->ml = mac_learning_create();
490 for (i = 0; i < MAX_MIRRORS; i++) {
491 ofproto->mirrors[i] = NULL;
493 ofproto->has_bonded_bundles = false;
495 timer_set_duration(&ofproto->next_expiration, 1000);
497 hmap_init(&ofproto->facets);
499 for (i = 0; i < N_TABLES; i++) {
500 struct table_dpif *table = &ofproto->tables[i];
502 table->catchall_table = NULL;
503 table->other_table = NULL;
504 table->basis = random_uint32();
506 ofproto->need_revalidate = false;
507 tag_set_init(&ofproto->revalidate_set);
509 list_init(&ofproto->completions);
511 ofproto_dpif_unixctl_init();
513 ofproto->has_bundle_action = false;
515 *n_tablesp = N_TABLES;
520 complete_operations(struct ofproto_dpif *ofproto)
522 struct dpif_completion *c, *next;
524 LIST_FOR_EACH_SAFE (c, next, list_node, &ofproto->completions) {
525 ofoperation_complete(c->op, 0);
526 list_remove(&c->list_node);
532 destruct(struct ofproto *ofproto_)
534 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
535 struct rule_dpif *rule, *next_rule;
536 struct classifier *table;
539 complete_operations(ofproto);
541 OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {
542 struct cls_cursor cursor;
544 cls_cursor_init(&cursor, table, NULL);
545 CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
546 ofproto_rule_destroy(&rule->up);
550 for (i = 0; i < MAX_MIRRORS; i++) {
551 mirror_destroy(ofproto->mirrors[i]);
554 netflow_destroy(ofproto->netflow);
555 dpif_sflow_destroy(ofproto->sflow);
556 hmap_destroy(&ofproto->bundles);
557 mac_learning_destroy(ofproto->ml);
559 hmap_destroy(&ofproto->facets);
561 dpif_close(ofproto->dpif);
565 run(struct ofproto *ofproto_)
567 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
568 struct ofport_dpif *ofport;
569 struct ofbundle *bundle;
573 complete_operations(ofproto);
575 dpif_run(ofproto->dpif);
577 for (i = 0; i < 50; i++) {
578 struct dpif_upcall packet;
581 error = dpif_recv(ofproto->dpif, &packet);
583 if (error == ENODEV) {
584 /* Datapath destroyed. */
590 handle_upcall(ofproto, &packet);
593 if (timer_expired(&ofproto->next_expiration)) {
594 int delay = expire(ofproto);
595 timer_set_duration(&ofproto->next_expiration, delay);
598 if (ofproto->netflow) {
599 netflow_run(ofproto->netflow);
601 if (ofproto->sflow) {
602 dpif_sflow_run(ofproto->sflow);
605 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
608 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
612 mac_learning_run(ofproto->ml, &ofproto->revalidate_set);
614 /* Now revalidate if there's anything to do. */
615 if (ofproto->need_revalidate
616 || !tag_set_is_empty(&ofproto->revalidate_set)) {
617 struct tag_set revalidate_set = ofproto->revalidate_set;
618 bool revalidate_all = ofproto->need_revalidate;
619 struct facet *facet, *next;
621 /* Clear the revalidation flags. */
622 tag_set_init(&ofproto->revalidate_set);
623 ofproto->need_revalidate = false;
625 HMAP_FOR_EACH_SAFE (facet, next, hmap_node, &ofproto->facets) {
627 || tag_set_intersects(&revalidate_set, facet->tags)) {
628 facet_revalidate(ofproto, facet);
637 wait(struct ofproto *ofproto_)
639 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
640 struct ofport_dpif *ofport;
641 struct ofbundle *bundle;
643 if (!clogged && !list_is_empty(&ofproto->completions)) {
644 poll_immediate_wake();
647 dpif_wait(ofproto->dpif);
648 dpif_recv_wait(ofproto->dpif);
649 if (ofproto->sflow) {
650 dpif_sflow_wait(ofproto->sflow);
652 if (!tag_set_is_empty(&ofproto->revalidate_set)) {
653 poll_immediate_wake();
655 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
658 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
661 mac_learning_wait(ofproto->ml);
662 if (ofproto->need_revalidate) {
663 /* Shouldn't happen, but if it does just go around again. */
664 VLOG_DBG_RL(&rl, "need revalidate in ofproto_wait_cb()");
665 poll_immediate_wake();
667 timer_wait(&ofproto->next_expiration);
672 flush(struct ofproto *ofproto_)
674 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
675 struct facet *facet, *next_facet;
677 HMAP_FOR_EACH_SAFE (facet, next_facet, hmap_node, &ofproto->facets) {
678 /* Mark the facet as not installed so that facet_remove() doesn't
679 * bother trying to uninstall it. There is no point in uninstalling it
680 * individually since we are about to blow away all the facets with
681 * dpif_flow_flush(). */
682 facet->installed = false;
683 facet->dp_packet_count = 0;
684 facet->dp_byte_count = 0;
685 facet_remove(ofproto, facet);
687 dpif_flow_flush(ofproto->dpif);
691 get_features(struct ofproto *ofproto_ OVS_UNUSED,
692 bool *arp_match_ip, uint32_t *actions)
694 *arp_match_ip = true;
695 *actions = ((1u << OFPAT_OUTPUT) |
696 (1u << OFPAT_SET_VLAN_VID) |
697 (1u << OFPAT_SET_VLAN_PCP) |
698 (1u << OFPAT_STRIP_VLAN) |
699 (1u << OFPAT_SET_DL_SRC) |
700 (1u << OFPAT_SET_DL_DST) |
701 (1u << OFPAT_SET_NW_SRC) |
702 (1u << OFPAT_SET_NW_DST) |
703 (1u << OFPAT_SET_NW_TOS) |
704 (1u << OFPAT_SET_TP_SRC) |
705 (1u << OFPAT_SET_TP_DST) |
706 (1u << OFPAT_ENQUEUE));
710 get_tables(struct ofproto *ofproto_, struct ofp_table_stats *ots)
712 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
713 struct dpif_dp_stats s;
715 strcpy(ots->name, "classifier");
717 dpif_get_dp_stats(ofproto->dpif, &s);
718 put_32aligned_be64(&ots->lookup_count, htonll(s.n_hit + s.n_missed));
719 put_32aligned_be64(&ots->matched_count,
720 htonll(s.n_hit + ofproto->n_matches));
724 set_netflow(struct ofproto *ofproto_,
725 const struct netflow_options *netflow_options)
727 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
729 if (netflow_options) {
730 if (!ofproto->netflow) {
731 ofproto->netflow = netflow_create();
733 return netflow_set_options(ofproto->netflow, netflow_options);
735 netflow_destroy(ofproto->netflow);
736 ofproto->netflow = NULL;
741 static struct ofport *
744 struct ofport_dpif *port = xmalloc(sizeof *port);
749 port_dealloc(struct ofport *port_)
751 struct ofport_dpif *port = ofport_dpif_cast(port_);
756 port_construct(struct ofport *port_)
758 struct ofport_dpif *port = ofport_dpif_cast(port_);
759 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
761 ofproto->need_revalidate = true;
762 port->odp_port = ofp_port_to_odp_port(port->up.ofp_port);
765 port->tag = tag_create_random();
766 port->may_enable = true;
768 if (ofproto->sflow) {
769 dpif_sflow_add_port(ofproto->sflow, port->odp_port,
770 netdev_get_name(port->up.netdev));
777 port_destruct(struct ofport *port_)
779 struct ofport_dpif *port = ofport_dpif_cast(port_);
780 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
782 ofproto->need_revalidate = true;
783 bundle_remove(port_);
784 set_cfm(port_, NULL);
785 if (ofproto->sflow) {
786 dpif_sflow_del_port(ofproto->sflow, port->odp_port);
791 port_modified(struct ofport *port_)
793 struct ofport_dpif *port = ofport_dpif_cast(port_);
795 if (port->bundle && port->bundle->bond) {
796 bond_slave_set_netdev(port->bundle->bond, port, port->up.netdev);
801 port_reconfigured(struct ofport *port_, ovs_be32 old_config)
803 struct ofport_dpif *port = ofport_dpif_cast(port_);
804 struct ofproto_dpif *ofproto = ofproto_dpif_cast(port->up.ofproto);
805 ovs_be32 changed = old_config ^ port->up.opp.config;
807 if (changed & htonl(OFPPC_NO_RECV | OFPPC_NO_RECV_STP |
808 OFPPC_NO_FWD | OFPPC_NO_FLOOD)) {
809 ofproto->need_revalidate = true;
814 set_sflow(struct ofproto *ofproto_,
815 const struct ofproto_sflow_options *sflow_options)
817 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
818 struct dpif_sflow *ds = ofproto->sflow;
822 struct ofport_dpif *ofport;
824 ds = ofproto->sflow = dpif_sflow_create(ofproto->dpif);
825 HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
826 dpif_sflow_add_port(ds, ofport->odp_port,
827 netdev_get_name(ofport->up.netdev));
829 ofproto->need_revalidate = true;
831 dpif_sflow_set_options(ds, sflow_options);
834 dpif_sflow_destroy(ds);
835 ofproto->need_revalidate = true;
836 ofproto->sflow = NULL;
843 set_cfm(struct ofport *ofport_, const struct cfm_settings *s)
845 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
852 struct ofproto_dpif *ofproto;
854 ofproto = ofproto_dpif_cast(ofport->up.ofproto);
855 ofproto->need_revalidate = true;
856 ofport->cfm = cfm_create(netdev_get_name(ofport->up.netdev));
859 if (cfm_configure(ofport->cfm, s)) {
865 cfm_destroy(ofport->cfm);
871 get_cfm_fault(const struct ofport *ofport_)
873 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
875 return ofport->cfm ? cfm_get_fault(ofport->cfm) : -1;
879 get_cfm_remote_mpids(const struct ofport *ofport_, const uint64_t **rmps,
882 struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
885 cfm_get_remote_mpids(ofport->cfm, rmps, n_rmps);
894 /* Expires all MAC learning entries associated with 'port' and forces ofproto
895 * to revalidate every flow. */
897 bundle_flush_macs(struct ofbundle *bundle)
899 struct ofproto_dpif *ofproto = bundle->ofproto;
900 struct mac_learning *ml = ofproto->ml;
901 struct mac_entry *mac, *next_mac;
903 ofproto->need_revalidate = true;
904 LIST_FOR_EACH_SAFE (mac, next_mac, lru_node, &ml->lrus) {
905 if (mac->port.p == bundle) {
906 mac_learning_expire(ml, mac);
911 static struct ofbundle *
912 bundle_lookup(const struct ofproto_dpif *ofproto, void *aux)
914 struct ofbundle *bundle;
916 HMAP_FOR_EACH_IN_BUCKET (bundle, hmap_node, hash_pointer(aux, 0),
918 if (bundle->aux == aux) {
925 /* Looks up each of the 'n_auxes' pointers in 'auxes' as bundles and adds the
926 * ones that are found to 'bundles'. */
928 bundle_lookup_multiple(struct ofproto_dpif *ofproto,
929 void **auxes, size_t n_auxes,
930 struct hmapx *bundles)
935 for (i = 0; i < n_auxes; i++) {
936 struct ofbundle *bundle = bundle_lookup(ofproto, auxes[i]);
938 hmapx_add(bundles, bundle);
944 bundle_del_port(struct ofport_dpif *port)
946 struct ofbundle *bundle = port->bundle;
948 bundle->ofproto->need_revalidate = true;
950 list_remove(&port->bundle_node);
954 lacp_slave_unregister(bundle->lacp, port);
957 bond_slave_unregister(bundle->bond, port);
960 bundle->floodable = true;
961 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
962 if (port->up.opp.config & htonl(OFPPC_NO_FLOOD)) {
963 bundle->floodable = false;
969 bundle_add_port(struct ofbundle *bundle, uint32_t ofp_port,
970 struct lacp_slave_settings *lacp,
971 uint32_t bond_stable_id)
973 struct ofport_dpif *port;
975 port = get_ofp_port(bundle->ofproto, ofp_port);
980 if (port->bundle != bundle) {
981 bundle->ofproto->need_revalidate = true;
983 bundle_del_port(port);
986 port->bundle = bundle;
987 list_push_back(&bundle->ports, &port->bundle_node);
988 if (port->up.opp.config & htonl(OFPPC_NO_FLOOD)) {
989 bundle->floodable = false;
993 port->bundle->ofproto->need_revalidate = true;
994 lacp_slave_register(bundle->lacp, port, lacp);
997 port->bond_stable_id = bond_stable_id;
1003 bundle_destroy(struct ofbundle *bundle)
1005 struct ofproto_dpif *ofproto;
1006 struct ofport_dpif *port, *next_port;
1013 ofproto = bundle->ofproto;
1014 for (i = 0; i < MAX_MIRRORS; i++) {
1015 struct ofmirror *m = ofproto->mirrors[i];
1017 if (m->out == bundle) {
1019 } else if (hmapx_find_and_delete(&m->srcs, bundle)
1020 || hmapx_find_and_delete(&m->dsts, bundle)) {
1021 ofproto->need_revalidate = true;
1026 LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) {
1027 bundle_del_port(port);
1030 bundle_flush_macs(bundle);
1031 hmap_remove(&ofproto->bundles, &bundle->hmap_node);
1033 free(bundle->trunks);
1034 lacp_destroy(bundle->lacp);
1035 bond_destroy(bundle->bond);
1040 bundle_set(struct ofproto *ofproto_, void *aux,
1041 const struct ofproto_bundle_settings *s)
1043 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1044 bool need_flush = false;
1045 struct ofport_dpif *port;
1046 struct ofbundle *bundle;
1047 unsigned long *trunks;
1053 bundle_destroy(bundle_lookup(ofproto, aux));
1057 assert(s->n_slaves == 1 || s->bond != NULL);
1058 assert((s->lacp != NULL) == (s->lacp_slaves != NULL));
1060 bundle = bundle_lookup(ofproto, aux);
1062 bundle = xmalloc(sizeof *bundle);
1064 bundle->ofproto = ofproto;
1065 hmap_insert(&ofproto->bundles, &bundle->hmap_node,
1066 hash_pointer(aux, 0));
1068 bundle->name = NULL;
1070 list_init(&bundle->ports);
1071 bundle->vlan_mode = PORT_VLAN_TRUNK;
1073 bundle->trunks = NULL;
1074 bundle->lacp = NULL;
1075 bundle->bond = NULL;
1077 bundle->floodable = true;
1079 bundle->src_mirrors = 0;
1080 bundle->dst_mirrors = 0;
1081 bundle->mirror_out = 0;
1084 if (!bundle->name || strcmp(s->name, bundle->name)) {
1086 bundle->name = xstrdup(s->name);
1091 if (!bundle->lacp) {
1092 ofproto->need_revalidate = true;
1093 bundle->lacp = lacp_create();
1095 lacp_configure(bundle->lacp, s->lacp);
1097 lacp_destroy(bundle->lacp);
1098 bundle->lacp = NULL;
1101 /* Update set of ports. */
1103 for (i = 0; i < s->n_slaves; i++) {
1104 if (!bundle_add_port(bundle, s->slaves[i],
1105 s->lacp ? &s->lacp_slaves[i] : NULL,
1106 s->bond_stable_ids ? s->bond_stable_ids[i] : 0)) {
1110 if (!ok || list_size(&bundle->ports) != s->n_slaves) {
1111 struct ofport_dpif *next_port;
1113 LIST_FOR_EACH_SAFE (port, next_port, bundle_node, &bundle->ports) {
1114 for (i = 0; i < s->n_slaves; i++) {
1115 if (s->slaves[i] == port->up.ofp_port) {
1120 bundle_del_port(port);
1124 assert(list_size(&bundle->ports) <= s->n_slaves);
1126 if (list_is_empty(&bundle->ports)) {
1127 bundle_destroy(bundle);
1131 /* Set VLAN tagging mode */
1132 if (s->vlan_mode != bundle->vlan_mode) {
1133 bundle->vlan_mode = s->vlan_mode;
1138 vlan = (s->vlan_mode == PORT_VLAN_TRUNK ? -1
1139 : s->vlan >= 0 && s->vlan <= 4095 ? s->vlan
1141 if (vlan != bundle->vlan) {
1142 bundle->vlan = vlan;
1146 /* Get trunked VLANs. */
1147 switch (s->vlan_mode) {
1148 case PORT_VLAN_ACCESS:
1152 case PORT_VLAN_TRUNK:
1153 trunks = (unsigned long *) s->trunks;
1156 case PORT_VLAN_NATIVE_UNTAGGED:
1157 case PORT_VLAN_NATIVE_TAGGED:
1158 if (vlan != 0 && (!s->trunks
1159 || !bitmap_is_set(s->trunks, vlan)
1160 || bitmap_is_set(s->trunks, 0))) {
1161 /* Force trunking the native VLAN and prohibit trunking VLAN 0. */
1163 trunks = bitmap_clone(s->trunks, 4096);
1165 trunks = bitmap_allocate1(4096);
1167 bitmap_set1(trunks, vlan);
1168 bitmap_set0(trunks, 0);
1170 trunks = (unsigned long *) s->trunks;
1177 if (!vlan_bitmap_equal(trunks, bundle->trunks)) {
1178 free(bundle->trunks);
1179 if (trunks == s->trunks) {
1180 bundle->trunks = vlan_bitmap_clone(trunks);
1182 bundle->trunks = trunks;
1187 if (trunks != s->trunks) {
1192 if (!list_is_short(&bundle->ports)) {
1193 bundle->ofproto->has_bonded_bundles = true;
1195 if (bond_reconfigure(bundle->bond, s->bond)) {
1196 ofproto->need_revalidate = true;
1199 bundle->bond = bond_create(s->bond);
1200 ofproto->need_revalidate = true;
1203 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
1204 bond_slave_register(bundle->bond, port, port->bond_stable_id,
1208 bond_destroy(bundle->bond);
1209 bundle->bond = NULL;
1212 /* If we changed something that would affect MAC learning, un-learn
1213 * everything on this port and force flow revalidation. */
1215 bundle_flush_macs(bundle);
1222 bundle_remove(struct ofport *port_)
1224 struct ofport_dpif *port = ofport_dpif_cast(port_);
1225 struct ofbundle *bundle = port->bundle;
1228 bundle_del_port(port);
1229 if (list_is_empty(&bundle->ports)) {
1230 bundle_destroy(bundle);
1231 } else if (list_is_short(&bundle->ports)) {
1232 bond_destroy(bundle->bond);
1233 bundle->bond = NULL;
1239 send_pdu_cb(void *port_, const void *pdu, size_t pdu_size)
1241 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 10);
1242 struct ofport_dpif *port = port_;
1243 uint8_t ea[ETH_ADDR_LEN];
1246 error = netdev_get_etheraddr(port->up.netdev, ea);
1248 struct ofpbuf packet;
1251 ofpbuf_init(&packet, 0);
1252 packet_pdu = eth_compose(&packet, eth_addr_lacp, ea, ETH_TYPE_LACP,
1254 memcpy(packet_pdu, pdu, pdu_size);
1256 error = netdev_send(port->up.netdev, &packet);
1258 VLOG_WARN_RL(&rl, "port %s: sending LACP PDU on iface %s failed "
1259 "(%s)", port->bundle->name,
1260 netdev_get_name(port->up.netdev), strerror(error));
1262 ofpbuf_uninit(&packet);
1264 VLOG_ERR_RL(&rl, "port %s: cannot obtain Ethernet address of iface "
1265 "%s (%s)", port->bundle->name,
1266 netdev_get_name(port->up.netdev), strerror(error));
1271 bundle_send_learning_packets(struct ofbundle *bundle)
1273 struct ofproto_dpif *ofproto = bundle->ofproto;
1274 int error, n_packets, n_errors;
1275 struct mac_entry *e;
1277 error = n_packets = n_errors = 0;
1278 LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
1279 if (e->port.p != bundle) {
1280 int ret = bond_send_learning_packet(bundle->bond, e->mac, e->vlan);
1290 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
1291 VLOG_WARN_RL(&rl, "bond %s: %d errors sending %d gratuitous learning "
1292 "packets, last error was: %s",
1293 bundle->name, n_errors, n_packets, strerror(error));
1295 VLOG_DBG("bond %s: sent %d gratuitous learning packets",
1296 bundle->name, n_packets);
1301 bundle_run(struct ofbundle *bundle)
1304 lacp_run(bundle->lacp, send_pdu_cb);
1307 struct ofport_dpif *port;
1309 LIST_FOR_EACH (port, bundle_node, &bundle->ports) {
1310 bond_slave_set_may_enable(bundle->bond, port, port->may_enable);
1313 bond_run(bundle->bond, &bundle->ofproto->revalidate_set,
1314 lacp_negotiated(bundle->lacp));
1315 if (bond_should_send_learning_packets(bundle->bond)) {
1316 bundle_send_learning_packets(bundle);
1322 bundle_wait(struct ofbundle *bundle)
1325 lacp_wait(bundle->lacp);
1328 bond_wait(bundle->bond);
1335 mirror_scan(struct ofproto_dpif *ofproto)
1339 for (idx = 0; idx < MAX_MIRRORS; idx++) {
1340 if (!ofproto->mirrors[idx]) {
1347 static struct ofmirror *
1348 mirror_lookup(struct ofproto_dpif *ofproto, void *aux)
1352 for (i = 0; i < MAX_MIRRORS; i++) {
1353 struct ofmirror *mirror = ofproto->mirrors[i];
1354 if (mirror && mirror->aux == aux) {
1363 mirror_set(struct ofproto *ofproto_, void *aux,
1364 const struct ofproto_mirror_settings *s)
1366 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1367 mirror_mask_t mirror_bit;
1368 struct ofbundle *bundle;
1369 struct ofmirror *mirror;
1370 struct ofbundle *out;
1371 struct hmapx srcs; /* Contains "struct ofbundle *"s. */
1372 struct hmapx dsts; /* Contains "struct ofbundle *"s. */
1375 mirror = mirror_lookup(ofproto, aux);
1377 mirror_destroy(mirror);
1383 idx = mirror_scan(ofproto);
1385 VLOG_WARN("bridge %s: maximum of %d port mirrors reached, "
1387 ofproto->up.name, MAX_MIRRORS, s->name);
1391 mirror = ofproto->mirrors[idx] = xzalloc(sizeof *mirror);
1392 mirror->ofproto = ofproto;
1395 mirror->out_vlan = -1;
1396 mirror->name = NULL;
1399 if (!mirror->name || strcmp(s->name, mirror->name)) {
1401 mirror->name = xstrdup(s->name);
1404 /* Get the new configuration. */
1405 if (s->out_bundle) {
1406 out = bundle_lookup(ofproto, s->out_bundle);
1408 mirror_destroy(mirror);
1414 out_vlan = s->out_vlan;
1416 bundle_lookup_multiple(ofproto, s->srcs, s->n_srcs, &srcs);
1417 bundle_lookup_multiple(ofproto, s->dsts, s->n_dsts, &dsts);
1419 /* If the configuration has not changed, do nothing. */
1420 if (hmapx_equals(&srcs, &mirror->srcs)
1421 && hmapx_equals(&dsts, &mirror->dsts)
1422 && vlan_bitmap_equal(mirror->vlans, s->src_vlans)
1423 && mirror->out == out
1424 && mirror->out_vlan == out_vlan)
1426 hmapx_destroy(&srcs);
1427 hmapx_destroy(&dsts);
1431 hmapx_swap(&srcs, &mirror->srcs);
1432 hmapx_destroy(&srcs);
1434 hmapx_swap(&dsts, &mirror->dsts);
1435 hmapx_destroy(&dsts);
1437 free(mirror->vlans);
1438 mirror->vlans = vlan_bitmap_clone(s->src_vlans);
1441 mirror->out_vlan = out_vlan;
1443 /* Update bundles. */
1444 mirror_bit = MIRROR_MASK_C(1) << mirror->idx;
1445 HMAP_FOR_EACH (bundle, hmap_node, &mirror->ofproto->bundles) {
1446 if (hmapx_contains(&mirror->srcs, bundle)) {
1447 bundle->src_mirrors |= mirror_bit;
1449 bundle->src_mirrors &= ~mirror_bit;
1452 if (hmapx_contains(&mirror->dsts, bundle)) {
1453 bundle->dst_mirrors |= mirror_bit;
1455 bundle->dst_mirrors &= ~mirror_bit;
1458 if (mirror->out == bundle) {
1459 bundle->mirror_out |= mirror_bit;
1461 bundle->mirror_out &= ~mirror_bit;
1465 ofproto->need_revalidate = true;
1466 mac_learning_flush(ofproto->ml);
1472 mirror_destroy(struct ofmirror *mirror)
1474 struct ofproto_dpif *ofproto;
1475 mirror_mask_t mirror_bit;
1476 struct ofbundle *bundle;
1482 ofproto = mirror->ofproto;
1483 ofproto->need_revalidate = true;
1484 mac_learning_flush(ofproto->ml);
1486 mirror_bit = MIRROR_MASK_C(1) << mirror->idx;
1487 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1488 bundle->src_mirrors &= ~mirror_bit;
1489 bundle->dst_mirrors &= ~mirror_bit;
1490 bundle->mirror_out &= ~mirror_bit;
1493 hmapx_destroy(&mirror->srcs);
1494 hmapx_destroy(&mirror->dsts);
1495 free(mirror->vlans);
1497 ofproto->mirrors[mirror->idx] = NULL;
1503 set_flood_vlans(struct ofproto *ofproto_, unsigned long *flood_vlans)
1505 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1506 if (mac_learning_set_flood_vlans(ofproto->ml, flood_vlans)) {
1507 ofproto->need_revalidate = true;
1508 mac_learning_flush(ofproto->ml);
1514 is_mirror_output_bundle(struct ofproto *ofproto_, void *aux)
1516 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1517 struct ofbundle *bundle = bundle_lookup(ofproto, aux);
1518 return bundle && bundle->mirror_out != 0;
1522 forward_bpdu_changed(struct ofproto *ofproto_)
1524 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1525 /* Revalidate cached flows whenever forward_bpdu option changes. */
1526 ofproto->need_revalidate = true;
1531 static struct ofport_dpif *
1532 get_ofp_port(struct ofproto_dpif *ofproto, uint16_t ofp_port)
1534 struct ofport *ofport = ofproto_get_port(&ofproto->up, ofp_port);
1535 return ofport ? ofport_dpif_cast(ofport) : NULL;
1538 static struct ofport_dpif *
1539 get_odp_port(struct ofproto_dpif *ofproto, uint32_t odp_port)
1541 return get_ofp_port(ofproto, odp_port_to_ofp_port(odp_port));
1545 ofproto_port_from_dpif_port(struct ofproto_port *ofproto_port,
1546 struct dpif_port *dpif_port)
1548 ofproto_port->name = dpif_port->name;
1549 ofproto_port->type = dpif_port->type;
1550 ofproto_port->ofp_port = odp_port_to_ofp_port(dpif_port->port_no);
1554 port_run(struct ofport_dpif *ofport)
1556 bool enable = netdev_get_carrier(ofport->up.netdev);
1559 cfm_run(ofport->cfm);
1561 if (cfm_should_send_ccm(ofport->cfm)) {
1562 struct ofpbuf packet;
1564 ofpbuf_init(&packet, 0);
1565 cfm_compose_ccm(ofport->cfm, &packet, ofport->up.opp.hw_addr);
1566 send_packet(ofproto_dpif_cast(ofport->up.ofproto),
1567 ofport->odp_port, &packet);
1568 ofpbuf_uninit(&packet);
1571 enable = enable && !cfm_get_fault(ofport->cfm)
1572 && cfm_get_opup(ofport->cfm);
1575 if (ofport->bundle) {
1576 enable = enable && lacp_slave_may_enable(ofport->bundle->lacp, ofport);
1579 if (ofport->may_enable != enable) {
1580 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
1582 if (ofproto->has_bundle_action) {
1583 ofproto->need_revalidate = true;
1587 ofport->may_enable = enable;
1591 port_wait(struct ofport_dpif *ofport)
1594 cfm_wait(ofport->cfm);
1599 port_query_by_name(const struct ofproto *ofproto_, const char *devname,
1600 struct ofproto_port *ofproto_port)
1602 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1603 struct dpif_port dpif_port;
1606 error = dpif_port_query_by_name(ofproto->dpif, devname, &dpif_port);
1608 ofproto_port_from_dpif_port(ofproto_port, &dpif_port);
1614 port_add(struct ofproto *ofproto_, struct netdev *netdev, uint16_t *ofp_portp)
1616 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1620 error = dpif_port_add(ofproto->dpif, netdev, &odp_port);
1622 *ofp_portp = odp_port_to_ofp_port(odp_port);
1628 port_del(struct ofproto *ofproto_, uint16_t ofp_port)
1630 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1633 error = dpif_port_del(ofproto->dpif, ofp_port_to_odp_port(ofp_port));
1635 struct ofport_dpif *ofport = get_ofp_port(ofproto, ofp_port);
1637 /* The caller is going to close ofport->up.netdev. If this is a
1638 * bonded port, then the bond is using that netdev, so remove it
1639 * from the bond. The client will need to reconfigure everything
1640 * after deleting ports, so then the slave will get re-added. */
1641 bundle_remove(&ofport->up);
1647 struct port_dump_state {
1648 struct dpif_port_dump dump;
1653 port_dump_start(const struct ofproto *ofproto_, void **statep)
1655 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1656 struct port_dump_state *state;
1658 *statep = state = xmalloc(sizeof *state);
1659 dpif_port_dump_start(&state->dump, ofproto->dpif);
1660 state->done = false;
1665 port_dump_next(const struct ofproto *ofproto_ OVS_UNUSED, void *state_,
1666 struct ofproto_port *port)
1668 struct port_dump_state *state = state_;
1669 struct dpif_port dpif_port;
1671 if (dpif_port_dump_next(&state->dump, &dpif_port)) {
1672 ofproto_port_from_dpif_port(port, &dpif_port);
1675 int error = dpif_port_dump_done(&state->dump);
1677 return error ? error : EOF;
1682 port_dump_done(const struct ofproto *ofproto_ OVS_UNUSED, void *state_)
1684 struct port_dump_state *state = state_;
1687 dpif_port_dump_done(&state->dump);
1694 port_poll(const struct ofproto *ofproto_, char **devnamep)
1696 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1697 return dpif_port_poll(ofproto->dpif, devnamep);
1701 port_poll_wait(const struct ofproto *ofproto_)
1703 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
1704 dpif_port_poll_wait(ofproto->dpif);
1708 port_is_lacp_current(const struct ofport *ofport_)
1710 const struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
1711 return (ofport->bundle && ofport->bundle->lacp
1712 ? lacp_slave_is_current(ofport->bundle->lacp, ofport)
1716 /* Upcall handling. */
1718 /* Given 'upcall', of type DPIF_UC_ACTION or DPIF_UC_MISS, sends an
1719 * OFPT_PACKET_IN message to each OpenFlow controller as necessary according to
1720 * their individual configurations.
1722 * If 'clone' is true, the caller retains ownership of 'upcall->packet'.
1723 * Otherwise, ownership is transferred to this function. */
1725 send_packet_in(struct ofproto_dpif *ofproto, struct dpif_upcall *upcall,
1726 const struct flow *flow, bool clone)
1728 struct ofputil_packet_in pin;
1729 struct user_action_cookie cookie;
1731 pin.packet = upcall->packet;
1732 pin.in_port = flow->in_port;
1733 pin.reason = upcall->type == DPIF_UC_MISS ? OFPR_NO_MATCH : OFPR_ACTION;
1734 pin.buffer_id = 0; /* not yet known */
1736 memcpy(&cookie, &upcall->userdata, sizeof(cookie));
1737 pin.send_len = cookie.data;
1738 connmgr_send_packet_in(ofproto->up.connmgr, &pin, flow,
1739 clone ? NULL : upcall->packet);
1743 process_special(struct ofproto_dpif *ofproto, const struct flow *flow,
1744 const struct ofpbuf *packet)
1746 struct ofport_dpif *ofport = get_ofp_port(ofproto, flow->in_port);
1752 if (ofport->cfm && cfm_should_process_flow(ofport->cfm, flow)) {
1754 cfm_process_heartbeat(ofport->cfm, packet);
1757 } else if (ofport->bundle && ofport->bundle->lacp
1758 && flow->dl_type == htons(ETH_TYPE_LACP)) {
1760 lacp_process_packet(ofport->bundle->lacp, ofport, packet);
1768 handle_miss_upcall(struct ofproto_dpif *ofproto, struct dpif_upcall *upcall)
1770 struct facet *facet;
1773 /* Obtain in_port and tun_id, at least. */
1774 odp_flow_key_to_flow(upcall->key, upcall->key_len, &flow);
1776 /* Set header pointers in 'flow'. */
1777 flow_extract(upcall->packet, flow.tun_id, flow.in_port, &flow);
1779 /* Handle 802.1ag and LACP. */
1780 if (process_special(ofproto, &flow, upcall->packet)) {
1781 ofpbuf_delete(upcall->packet);
1782 ofproto->n_matches++;
1786 /* Check with in-band control to see if this packet should be sent
1787 * to the local port regardless of the flow table. */
1788 if (connmgr_msg_in_hook(ofproto->up.connmgr, &flow, upcall->packet)) {
1789 send_packet(ofproto, OVSP_LOCAL, upcall->packet);
1792 facet = facet_lookup_valid(ofproto, &flow);
1794 struct rule_dpif *rule = rule_dpif_lookup(ofproto, &flow, 0);
1796 /* Don't send a packet-in if OFPPC_NO_PACKET_IN asserted. */
1797 struct ofport_dpif *port = get_ofp_port(ofproto, flow.in_port);
1799 if (port->up.opp.config & htonl(OFPPC_NO_PACKET_IN)) {
1800 COVERAGE_INC(ofproto_dpif_no_packet_in);
1801 /* XXX install 'drop' flow entry */
1802 ofpbuf_delete(upcall->packet);
1806 VLOG_WARN_RL(&rl, "packet-in on unknown port %"PRIu16,
1810 send_packet_in(ofproto, upcall, &flow, false);
1814 facet = facet_create(rule, &flow, upcall->packet);
1815 } else if (!facet->may_install) {
1816 /* The facet is not installable, that is, we need to process every
1817 * packet, so process the current packet's actions into 'facet'. */
1818 facet_make_actions(ofproto, facet, upcall->packet);
1821 if (facet->rule->up.cr.priority == FAIL_OPEN_PRIORITY) {
1823 * Extra-special case for fail-open mode.
1825 * We are in fail-open mode and the packet matched the fail-open rule,
1826 * but we are connected to a controller too. We should send the packet
1827 * up to the controller in the hope that it will try to set up a flow
1828 * and thereby allow us to exit fail-open.
1830 * See the top-level comment in fail-open.c for more information.
1832 send_packet_in(ofproto, upcall, &flow, true);
1835 facet_execute(ofproto, facet, upcall->packet);
1836 facet_install(ofproto, facet, false);
1837 ofproto->n_matches++;
1841 handle_userspace_upcall(struct ofproto_dpif *ofproto,
1842 struct dpif_upcall *upcall)
1845 struct user_action_cookie cookie;
1847 memcpy(&cookie, &upcall->userdata, sizeof(cookie));
1849 if (cookie.type == USER_ACTION_COOKIE_SFLOW) {
1850 if (ofproto->sflow) {
1851 odp_flow_key_to_flow(upcall->key, upcall->key_len, &flow);
1852 dpif_sflow_received(ofproto->sflow, upcall->packet, &flow, &cookie);
1854 ofpbuf_delete(upcall->packet);
1856 } else if (cookie.type == USER_ACTION_COOKIE_CONTROLLER) {
1857 COVERAGE_INC(ofproto_dpif_ctlr_action);
1858 odp_flow_key_to_flow(upcall->key, upcall->key_len, &flow);
1859 send_packet_in(ofproto, upcall, &flow, false);
1861 VLOG_WARN_RL(&rl, "invalid user cookie : 0x%"PRIx64, upcall->userdata);
1866 handle_upcall(struct ofproto_dpif *ofproto, struct dpif_upcall *upcall)
1868 switch (upcall->type) {
1869 case DPIF_UC_ACTION:
1870 handle_userspace_upcall(ofproto, upcall);
1874 handle_miss_upcall(ofproto, upcall);
1877 case DPIF_N_UC_TYPES:
1879 VLOG_WARN_RL(&rl, "upcall has unexpected type %"PRIu32, upcall->type);
1884 /* Flow expiration. */
1886 static int facet_max_idle(const struct ofproto_dpif *);
1887 static void update_stats(struct ofproto_dpif *);
1888 static void rule_expire(struct rule_dpif *);
1889 static void expire_facets(struct ofproto_dpif *, int dp_max_idle);
1891 /* This function is called periodically by run(). Its job is to collect
1892 * updates for the flows that have been installed into the datapath, most
1893 * importantly when they last were used, and then use that information to
1894 * expire flows that have not been used recently.
1896 * Returns the number of milliseconds after which it should be called again. */
1898 expire(struct ofproto_dpif *ofproto)
1900 struct rule_dpif *rule, *next_rule;
1901 struct classifier *table;
1904 /* Update stats for each flow in the datapath. */
1905 update_stats(ofproto);
1907 /* Expire facets that have been idle too long. */
1908 dp_max_idle = facet_max_idle(ofproto);
1909 expire_facets(ofproto, dp_max_idle);
1911 /* Expire OpenFlow flows whose idle_timeout or hard_timeout has passed. */
1912 OFPROTO_FOR_EACH_TABLE (table, &ofproto->up) {
1913 struct cls_cursor cursor;
1915 cls_cursor_init(&cursor, table, NULL);
1916 CLS_CURSOR_FOR_EACH_SAFE (rule, next_rule, up.cr, &cursor) {
1921 /* All outstanding data in existing flows has been accounted, so it's a
1922 * good time to do bond rebalancing. */
1923 if (ofproto->has_bonded_bundles) {
1924 struct ofbundle *bundle;
1926 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
1928 bond_rebalance(bundle->bond, &ofproto->revalidate_set);
1933 return MIN(dp_max_idle, 1000);
1936 /* Update 'packet_count', 'byte_count', and 'used' members of installed facets.
1938 * This function also pushes statistics updates to rules which each facet
1939 * resubmits into. Generally these statistics will be accurate. However, if a
1940 * facet changes the rule it resubmits into at some time in between
1941 * update_stats() runs, it is possible that statistics accrued to the
1942 * old rule will be incorrectly attributed to the new rule. This could be
1943 * avoided by calling update_stats() whenever rules are created or
1944 * deleted. However, the performance impact of making so many calls to the
1945 * datapath do not justify the benefit of having perfectly accurate statistics.
1948 update_stats(struct ofproto_dpif *p)
1950 const struct dpif_flow_stats *stats;
1951 struct dpif_flow_dump dump;
1952 const struct nlattr *key;
1955 dpif_flow_dump_start(&dump, p->dpif);
1956 while (dpif_flow_dump_next(&dump, &key, &key_len, NULL, NULL, &stats)) {
1957 struct facet *facet;
1960 if (odp_flow_key_to_flow(key, key_len, &flow)) {
1964 odp_flow_key_format(key, key_len, &s);
1965 VLOG_WARN_RL(&rl, "failed to convert datapath flow key to flow: %s",
1971 facet = facet_find(p, &flow);
1973 if (facet && facet->installed) {
1975 if (stats->n_packets >= facet->dp_packet_count) {
1976 uint64_t extra = stats->n_packets - facet->dp_packet_count;
1977 facet->packet_count += extra;
1979 VLOG_WARN_RL(&rl, "unexpected packet count from the datapath");
1982 if (stats->n_bytes >= facet->dp_byte_count) {
1983 facet->byte_count += stats->n_bytes - facet->dp_byte_count;
1985 VLOG_WARN_RL(&rl, "unexpected byte count from datapath");
1988 facet->dp_packet_count = stats->n_packets;
1989 facet->dp_byte_count = stats->n_bytes;
1991 facet_update_time(p, facet, stats->used);
1992 facet_account(p, facet);
1993 facet_push_stats(facet);
1995 /* There's a flow in the datapath that we know nothing about.
1997 COVERAGE_INC(facet_unexpected);
1998 dpif_flow_del(p->dpif, key, key_len, NULL);
2001 dpif_flow_dump_done(&dump);
2004 /* Calculates and returns the number of milliseconds of idle time after which
2005 * facets should expire from the datapath and we should fold their statistics
2006 * into their parent rules in userspace. */
2008 facet_max_idle(const struct ofproto_dpif *ofproto)
2011 * Idle time histogram.
2013 * Most of the time a switch has a relatively small number of facets. When
2014 * this is the case we might as well keep statistics for all of them in
2015 * userspace and to cache them in the kernel datapath for performance as
2018 * As the number of facets increases, the memory required to maintain
2019 * statistics about them in userspace and in the kernel becomes
2020 * significant. However, with a large number of facets it is likely that
2021 * only a few of them are "heavy hitters" that consume a large amount of
2022 * bandwidth. At this point, only heavy hitters are worth caching in the
2023 * kernel and maintaining in userspaces; other facets we can discard.
2025 * The technique used to compute the idle time is to build a histogram with
2026 * N_BUCKETS buckets whose width is BUCKET_WIDTH msecs each. Each facet
2027 * that is installed in the kernel gets dropped in the appropriate bucket.
2028 * After the histogram has been built, we compute the cutoff so that only
2029 * the most-recently-used 1% of facets (but at least
2030 * ofproto->up.flow_eviction_threshold flows) are kept cached. At least
2031 * the most-recently-used bucket of facets is kept, so actually an
2032 * arbitrary number of facets can be kept in any given expiration run
2033 * (though the next run will delete most of those unless they receive
2036 * This requires a second pass through the facets, in addition to the pass
2037 * made by update_stats(), because the former function never looks
2038 * at uninstallable facets.
2040 enum { BUCKET_WIDTH = ROUND_UP(100, TIME_UPDATE_INTERVAL) };
2041 enum { N_BUCKETS = 5000 / BUCKET_WIDTH };
2042 int buckets[N_BUCKETS] = { 0 };
2043 int total, subtotal, bucket;
2044 struct facet *facet;
2048 total = hmap_count(&ofproto->facets);
2049 if (total <= ofproto->up.flow_eviction_threshold) {
2050 return N_BUCKETS * BUCKET_WIDTH;
2053 /* Build histogram. */
2055 HMAP_FOR_EACH (facet, hmap_node, &ofproto->facets) {
2056 long long int idle = now - facet->used;
2057 int bucket = (idle <= 0 ? 0
2058 : idle >= BUCKET_WIDTH * N_BUCKETS ? N_BUCKETS - 1
2059 : (unsigned int) idle / BUCKET_WIDTH);
2063 /* Find the first bucket whose flows should be expired. */
2064 subtotal = bucket = 0;
2066 subtotal += buckets[bucket++];
2067 } while (bucket < N_BUCKETS &&
2068 subtotal < MAX(ofproto->up.flow_eviction_threshold, total / 100));
2070 if (VLOG_IS_DBG_ENABLED()) {
2074 ds_put_cstr(&s, "keep");
2075 for (i = 0; i < N_BUCKETS; i++) {
2077 ds_put_cstr(&s, ", drop");
2080 ds_put_format(&s, " %d:%d", i * BUCKET_WIDTH, buckets[i]);
2083 VLOG_INFO("%s: %s (msec:count)", ofproto->up.name, ds_cstr(&s));
2087 return bucket * BUCKET_WIDTH;
2091 facet_active_timeout(struct ofproto_dpif *ofproto, struct facet *facet)
2093 if (ofproto->netflow && !facet_is_controller_flow(facet) &&
2094 netflow_active_timeout_expired(ofproto->netflow, &facet->nf_flow)) {
2095 struct ofexpired expired;
2097 if (facet->installed) {
2098 struct dpif_flow_stats stats;
2100 facet_put__(ofproto, facet, facet->actions, facet->actions_len,
2102 facet_update_stats(ofproto, facet, &stats);
2105 expired.flow = facet->flow;
2106 expired.packet_count = facet->packet_count;
2107 expired.byte_count = facet->byte_count;
2108 expired.used = facet->used;
2109 netflow_expire(ofproto->netflow, &facet->nf_flow, &expired);
2114 expire_facets(struct ofproto_dpif *ofproto, int dp_max_idle)
2116 long long int cutoff = time_msec() - dp_max_idle;
2117 struct facet *facet, *next_facet;
2119 HMAP_FOR_EACH_SAFE (facet, next_facet, hmap_node, &ofproto->facets) {
2120 facet_active_timeout(ofproto, facet);
2121 if (facet->used < cutoff) {
2122 facet_remove(ofproto, facet);
2127 /* If 'rule' is an OpenFlow rule, that has expired according to OpenFlow rules,
2128 * then delete it entirely. */
2130 rule_expire(struct rule_dpif *rule)
2132 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
2133 struct facet *facet, *next_facet;
2137 /* Has 'rule' expired? */
2139 if (rule->up.hard_timeout
2140 && now > rule->up.modified + rule->up.hard_timeout * 1000) {
2141 reason = OFPRR_HARD_TIMEOUT;
2142 } else if (rule->up.idle_timeout && list_is_empty(&rule->facets)
2143 && now > rule->used + rule->up.idle_timeout * 1000) {
2144 reason = OFPRR_IDLE_TIMEOUT;
2149 COVERAGE_INC(ofproto_dpif_expired);
2151 /* Update stats. (This is a no-op if the rule expired due to an idle
2152 * timeout, because that only happens when the rule has no facets left.) */
2153 LIST_FOR_EACH_SAFE (facet, next_facet, list_node, &rule->facets) {
2154 facet_remove(ofproto, facet);
2157 /* Get rid of the rule. */
2158 ofproto_rule_expire(&rule->up, reason);
2163 /* Creates and returns a new facet owned by 'rule', given a 'flow' and an
2164 * example 'packet' within that flow.
2166 * The caller must already have determined that no facet with an identical
2167 * 'flow' exists in 'ofproto' and that 'flow' is the best match for 'rule' in
2168 * the ofproto's classifier table. */
2169 static struct facet *
2170 facet_create(struct rule_dpif *rule, const struct flow *flow,
2171 const struct ofpbuf *packet)
2173 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
2174 struct facet *facet;
2176 facet = xzalloc(sizeof *facet);
2177 facet->used = time_msec();
2178 hmap_insert(&ofproto->facets, &facet->hmap_node, flow_hash(flow, 0));
2179 list_push_back(&rule->facets, &facet->list_node);
2181 facet->flow = *flow;
2182 netflow_flow_init(&facet->nf_flow);
2183 netflow_flow_update_time(ofproto->netflow, &facet->nf_flow, facet->used);
2185 facet_make_actions(ofproto, facet, packet);
2191 facet_free(struct facet *facet)
2193 free(facet->actions);
2197 /* Executes, within 'ofproto', the 'n_actions' actions in 'actions' on
2198 * 'packet', which arrived on 'in_port'.
2200 * Takes ownership of 'packet'. */
2202 execute_odp_actions(struct ofproto_dpif *ofproto, const struct flow *flow,
2203 const struct nlattr *odp_actions, size_t actions_len,
2204 struct ofpbuf *packet)
2206 struct odputil_keybuf keybuf;
2210 if (actions_len == NLA_ALIGN(NLA_HDRLEN + sizeof(uint64_t))
2211 && odp_actions->nla_type == OVS_ACTION_ATTR_USERSPACE) {
2212 const struct user_action_cookie *cookie;
2213 struct dpif_upcall upcall;
2215 cookie = nl_attr_get_unspec(odp_actions, sizeof(*cookie));
2216 if (cookie->type == USER_ACTION_COOKIE_CONTROLLER) {
2217 /* As an optimization, avoid a round-trip from userspace to kernel
2218 * to userspace. This also avoids possibly filling up kernel packet
2219 * buffers along the way.
2220 * This optimization does not work in case of sFlow is turned ON.
2221 * Since first action would be sFlow SAMPLE action followed by
2222 * Controller action. */
2224 upcall.type = DPIF_UC_ACTION;
2225 upcall.packet = packet;
2228 upcall.userdata = nl_attr_get_u64(odp_actions);
2230 send_packet_in(ofproto, &upcall, flow, false);
2235 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
2236 odp_flow_key_from_flow(&key, flow);
2238 error = dpif_execute(ofproto->dpif, key.data, key.size,
2239 odp_actions, actions_len, packet);
2241 ofpbuf_delete(packet);
2245 /* Executes the actions indicated by 'facet' on 'packet' and credits 'facet''s
2246 * statistics appropriately. 'packet' must have at least sizeof(struct
2247 * ofp_packet_in) bytes of headroom.
2249 * For correct results, 'packet' must actually be in 'facet''s flow; that is,
2250 * applying flow_extract() to 'packet' would yield the same flow as
2253 * 'facet' must have accurately composed datapath actions; that is, it must
2254 * not be in need of revalidation.
2256 * Takes ownership of 'packet'. */
2258 facet_execute(struct ofproto_dpif *ofproto, struct facet *facet,
2259 struct ofpbuf *packet)
2261 struct dpif_flow_stats stats;
2263 assert(ofpbuf_headroom(packet) >= sizeof(struct ofp_packet_in));
2265 dpif_flow_stats_extract(&facet->flow, packet, &stats);
2266 stats.used = time_msec();
2267 if (execute_odp_actions(ofproto, &facet->flow,
2268 facet->actions, facet->actions_len, packet)) {
2269 facet_update_stats(ofproto, facet, &stats);
2273 /* Remove 'facet' from 'ofproto' and free up the associated memory:
2275 * - If 'facet' was installed in the datapath, uninstalls it and updates its
2276 * rule's statistics, via facet_uninstall().
2278 * - Removes 'facet' from its rule and from ofproto->facets.
2281 facet_remove(struct ofproto_dpif *ofproto, struct facet *facet)
2283 facet_uninstall(ofproto, facet);
2284 facet_flush_stats(ofproto, facet);
2285 hmap_remove(&ofproto->facets, &facet->hmap_node);
2286 list_remove(&facet->list_node);
2290 /* Composes the datapath actions for 'facet' based on its rule's actions. */
2292 facet_make_actions(struct ofproto_dpif *p, struct facet *facet,
2293 const struct ofpbuf *packet)
2295 const struct rule_dpif *rule = facet->rule;
2296 struct ofpbuf *odp_actions;
2297 struct action_xlate_ctx ctx;
2299 action_xlate_ctx_init(&ctx, p, &facet->flow, packet);
2300 odp_actions = xlate_actions(&ctx, rule->up.actions, rule->up.n_actions);
2301 facet->tags = ctx.tags;
2302 facet->may_install = ctx.may_set_up_flow;
2303 facet->has_learn = ctx.has_learn;
2304 facet->has_normal = ctx.has_normal;
2305 facet->nf_flow.output_iface = ctx.nf_output_iface;
2307 if (facet->actions_len != odp_actions->size
2308 || memcmp(facet->actions, odp_actions->data, odp_actions->size)) {
2309 free(facet->actions);
2310 facet->actions_len = odp_actions->size;
2311 facet->actions = xmemdup(odp_actions->data, odp_actions->size);
2314 ofpbuf_delete(odp_actions);
2317 /* Updates 'facet''s flow in the datapath setting its actions to 'actions_len'
2318 * bytes of actions in 'actions'. If 'stats' is non-null, statistics counters
2319 * in the datapath will be zeroed and 'stats' will be updated with traffic new
2320 * since 'facet' was last updated.
2322 * Returns 0 if successful, otherwise a positive errno value.*/
2324 facet_put__(struct ofproto_dpif *ofproto, struct facet *facet,
2325 const struct nlattr *actions, size_t actions_len,
2326 struct dpif_flow_stats *stats)
2328 struct odputil_keybuf keybuf;
2329 enum dpif_flow_put_flags flags;
2333 flags = DPIF_FP_CREATE | DPIF_FP_MODIFY;
2335 flags |= DPIF_FP_ZERO_STATS;
2338 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
2339 odp_flow_key_from_flow(&key, &facet->flow);
2341 ret = dpif_flow_put(ofproto->dpif, flags, key.data, key.size,
2342 actions, actions_len, stats);
2345 facet_reset_dp_stats(facet, stats);
2351 /* If 'facet' is installable, inserts or re-inserts it into 'p''s datapath. If
2352 * 'zero_stats' is true, clears any existing statistics from the datapath for
2355 facet_install(struct ofproto_dpif *p, struct facet *facet, bool zero_stats)
2357 struct dpif_flow_stats stats;
2359 if (facet->may_install
2360 && !facet_put__(p, facet, facet->actions, facet->actions_len,
2361 zero_stats ? &stats : NULL)) {
2362 facet->installed = true;
2367 facet_account(struct ofproto_dpif *ofproto, struct facet *facet)
2370 const struct nlattr *a;
2374 if (facet->byte_count <= facet->accounted_bytes) {
2377 n_bytes = facet->byte_count - facet->accounted_bytes;
2378 facet->accounted_bytes = facet->byte_count;
2380 /* Feed information from the active flows back into the learning table to
2381 * ensure that table is always in sync with what is actually flowing
2382 * through the datapath. */
2383 if (facet->has_learn || facet->has_normal) {
2384 struct action_xlate_ctx ctx;
2386 action_xlate_ctx_init(&ctx, ofproto, &facet->flow, NULL);
2387 ctx.may_learn = true;
2388 ofpbuf_delete(xlate_actions(&ctx, facet->rule->up.actions,
2389 facet->rule->up.n_actions));
2392 if (!facet->has_normal || !ofproto->has_bonded_bundles) {
2396 /* This loop feeds byte counters to bond_account() for rebalancing to use
2397 * as a basis. We also need to track the actual VLAN on which the packet
2398 * is going to be sent to ensure that it matches the one passed to
2399 * bond_choose_output_slave(). (Otherwise, we will account to the wrong
2401 vlan_tci = facet->flow.vlan_tci;
2402 NL_ATTR_FOR_EACH_UNSAFE (a, left, facet->actions, facet->actions_len) {
2403 struct ofport_dpif *port;
2405 switch (nl_attr_type(a)) {
2406 case OVS_ACTION_ATTR_OUTPUT:
2407 port = get_odp_port(ofproto, nl_attr_get_u32(a));
2408 if (port && port->bundle && port->bundle->bond) {
2409 bond_account(port->bundle->bond, &facet->flow,
2410 vlan_tci_to_vid(vlan_tci), n_bytes);
2414 case OVS_ACTION_ATTR_POP_VLAN:
2415 vlan_tci = htons(0);
2418 case OVS_ACTION_ATTR_PUSH_VLAN:
2419 vlan_tci = nl_attr_get_be16(a);
2425 /* If 'rule' is installed in the datapath, uninstalls it. */
2427 facet_uninstall(struct ofproto_dpif *p, struct facet *facet)
2429 if (facet->installed) {
2430 struct odputil_keybuf keybuf;
2431 struct dpif_flow_stats stats;
2435 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
2436 odp_flow_key_from_flow(&key, &facet->flow);
2438 error = dpif_flow_del(p->dpif, key.data, key.size, &stats);
2439 facet_reset_dp_stats(facet, &stats);
2441 facet_update_stats(p, facet, &stats);
2443 facet->installed = false;
2445 assert(facet->dp_packet_count == 0);
2446 assert(facet->dp_byte_count == 0);
2450 /* Returns true if the only action for 'facet' is to send to the controller.
2451 * (We don't report NetFlow expiration messages for such facets because they
2452 * are just part of the control logic for the network, not real traffic). */
2454 facet_is_controller_flow(struct facet *facet)
2457 && facet->rule->up.n_actions == 1
2458 && action_outputs_to_port(&facet->rule->up.actions[0],
2459 htons(OFPP_CONTROLLER)));
2462 /* Resets 'facet''s datapath statistics counters. This should be called when
2463 * 'facet''s statistics are cleared in the datapath. If 'stats' is non-null,
2464 * it should contain the statistics returned by dpif when 'facet' was reset in
2465 * the datapath. 'stats' will be modified to only included statistics new
2466 * since 'facet' was last updated. */
2468 facet_reset_dp_stats(struct facet *facet, struct dpif_flow_stats *stats)
2470 if (stats && facet->dp_packet_count <= stats->n_packets
2471 && facet->dp_byte_count <= stats->n_bytes) {
2472 stats->n_packets -= facet->dp_packet_count;
2473 stats->n_bytes -= facet->dp_byte_count;
2476 facet->dp_packet_count = 0;
2477 facet->dp_byte_count = 0;
2480 /* Folds all of 'facet''s statistics into its rule. Also updates the
2481 * accounting ofhook and emits a NetFlow expiration if appropriate. All of
2482 * 'facet''s statistics in the datapath should have been zeroed and folded into
2483 * its packet and byte counts before this function is called. */
2485 facet_flush_stats(struct ofproto_dpif *ofproto, struct facet *facet)
2487 assert(!facet->dp_byte_count);
2488 assert(!facet->dp_packet_count);
2490 facet_push_stats(facet);
2491 facet_account(ofproto, facet);
2493 if (ofproto->netflow && !facet_is_controller_flow(facet)) {
2494 struct ofexpired expired;
2495 expired.flow = facet->flow;
2496 expired.packet_count = facet->packet_count;
2497 expired.byte_count = facet->byte_count;
2498 expired.used = facet->used;
2499 netflow_expire(ofproto->netflow, &facet->nf_flow, &expired);
2502 facet->rule->packet_count += facet->packet_count;
2503 facet->rule->byte_count += facet->byte_count;
2505 /* Reset counters to prevent double counting if 'facet' ever gets
2507 facet_reset_counters(facet);
2509 netflow_flow_clear(&facet->nf_flow);
2512 /* Searches 'ofproto''s table of facets for one exactly equal to 'flow'.
2513 * Returns it if found, otherwise a null pointer.
2515 * The returned facet might need revalidation; use facet_lookup_valid()
2516 * instead if that is important. */
2517 static struct facet *
2518 facet_find(struct ofproto_dpif *ofproto, const struct flow *flow)
2520 struct facet *facet;
2522 HMAP_FOR_EACH_WITH_HASH (facet, hmap_node, flow_hash(flow, 0),
2524 if (flow_equal(flow, &facet->flow)) {
2532 /* Searches 'ofproto''s table of facets for one exactly equal to 'flow'.
2533 * Returns it if found, otherwise a null pointer.
2535 * The returned facet is guaranteed to be valid. */
2536 static struct facet *
2537 facet_lookup_valid(struct ofproto_dpif *ofproto, const struct flow *flow)
2539 struct facet *facet = facet_find(ofproto, flow);
2541 /* The facet we found might not be valid, since we could be in need of
2542 * revalidation. If it is not valid, don't return it. */
2544 && ofproto->need_revalidate
2545 && !facet_revalidate(ofproto, facet)) {
2546 COVERAGE_INC(facet_invalidated);
2553 /* Re-searches 'ofproto''s classifier for a rule matching 'facet':
2555 * - If the rule found is different from 'facet''s current rule, moves
2556 * 'facet' to the new rule and recompiles its actions.
2558 * - If the rule found is the same as 'facet''s current rule, leaves 'facet'
2559 * where it is and recompiles its actions anyway.
2561 * - If there is none, destroys 'facet'.
2563 * Returns true if 'facet' still exists, false if it has been destroyed. */
2565 facet_revalidate(struct ofproto_dpif *ofproto, struct facet *facet)
2567 struct action_xlate_ctx ctx;
2568 struct ofpbuf *odp_actions;
2569 struct rule_dpif *new_rule;
2570 bool actions_changed;
2572 COVERAGE_INC(facet_revalidate);
2574 /* Determine the new rule. */
2575 new_rule = rule_dpif_lookup(ofproto, &facet->flow, 0);
2577 /* No new rule, so delete the facet. */
2578 facet_remove(ofproto, facet);
2582 /* Calculate new datapath actions.
2584 * We do not modify any 'facet' state yet, because we might need to, e.g.,
2585 * emit a NetFlow expiration and, if so, we need to have the old state
2586 * around to properly compose it. */
2587 action_xlate_ctx_init(&ctx, ofproto, &facet->flow, NULL);
2588 odp_actions = xlate_actions(&ctx,
2589 new_rule->up.actions, new_rule->up.n_actions);
2590 actions_changed = (facet->actions_len != odp_actions->size
2591 || memcmp(facet->actions, odp_actions->data,
2592 facet->actions_len));
2594 /* If the datapath actions changed or the installability changed,
2595 * then we need to talk to the datapath. */
2596 if (actions_changed || ctx.may_set_up_flow != facet->installed) {
2597 if (ctx.may_set_up_flow) {
2598 struct dpif_flow_stats stats;
2600 facet_put__(ofproto, facet,
2601 odp_actions->data, odp_actions->size, &stats);
2602 facet_update_stats(ofproto, facet, &stats);
2604 facet_uninstall(ofproto, facet);
2607 /* The datapath flow is gone or has zeroed stats, so push stats out of
2608 * 'facet' into 'rule'. */
2609 facet_flush_stats(ofproto, facet);
2612 /* Update 'facet' now that we've taken care of all the old state. */
2613 facet->tags = ctx.tags;
2614 facet->nf_flow.output_iface = ctx.nf_output_iface;
2615 facet->may_install = ctx.may_set_up_flow;
2616 facet->has_learn = ctx.has_learn;
2617 facet->has_normal = ctx.has_normal;
2618 if (actions_changed) {
2619 free(facet->actions);
2620 facet->actions_len = odp_actions->size;
2621 facet->actions = xmemdup(odp_actions->data, odp_actions->size);
2623 if (facet->rule != new_rule) {
2624 COVERAGE_INC(facet_changed_rule);
2625 list_remove(&facet->list_node);
2626 list_push_back(&new_rule->facets, &facet->list_node);
2627 facet->rule = new_rule;
2628 facet->used = new_rule->up.created;
2629 facet->rs_used = facet->used;
2632 ofpbuf_delete(odp_actions);
2637 /* Updates 'facet''s used time. Caller is responsible for calling
2638 * facet_push_stats() to update the flows which 'facet' resubmits into. */
2640 facet_update_time(struct ofproto_dpif *ofproto, struct facet *facet,
2643 if (used > facet->used) {
2645 if (used > facet->rule->used) {
2646 facet->rule->used = used;
2648 netflow_flow_update_time(ofproto->netflow, &facet->nf_flow, used);
2652 /* Folds the statistics from 'stats' into the counters in 'facet'.
2654 * Because of the meaning of a facet's counters, it only makes sense to do this
2655 * if 'stats' are not tracked in the datapath, that is, if 'stats' represents a
2656 * packet that was sent by hand or if it represents statistics that have been
2657 * cleared out of the datapath. */
2659 facet_update_stats(struct ofproto_dpif *ofproto, struct facet *facet,
2660 const struct dpif_flow_stats *stats)
2662 if (stats->n_packets || stats->used > facet->used) {
2663 facet_update_time(ofproto, facet, stats->used);
2664 facet->packet_count += stats->n_packets;
2665 facet->byte_count += stats->n_bytes;
2666 facet_push_stats(facet);
2667 netflow_flow_update_flags(&facet->nf_flow, stats->tcp_flags);
2672 facet_reset_counters(struct facet *facet)
2674 facet->packet_count = 0;
2675 facet->byte_count = 0;
2676 facet->rs_packet_count = 0;
2677 facet->rs_byte_count = 0;
2678 facet->accounted_bytes = 0;
2682 facet_push_stats(struct facet *facet)
2684 uint64_t rs_packets, rs_bytes;
2686 assert(facet->packet_count >= facet->rs_packet_count);
2687 assert(facet->byte_count >= facet->rs_byte_count);
2688 assert(facet->used >= facet->rs_used);
2690 rs_packets = facet->packet_count - facet->rs_packet_count;
2691 rs_bytes = facet->byte_count - facet->rs_byte_count;
2693 if (rs_packets || rs_bytes || facet->used > facet->rs_used) {
2694 facet->rs_packet_count = facet->packet_count;
2695 facet->rs_byte_count = facet->byte_count;
2696 facet->rs_used = facet->used;
2698 flow_push_stats(facet->rule, &facet->flow,
2699 rs_packets, rs_bytes, facet->used);
2703 struct ofproto_push {
2704 struct action_xlate_ctx ctx;
2711 push_resubmit(struct action_xlate_ctx *ctx, struct rule_dpif *rule)
2713 struct ofproto_push *push = CONTAINER_OF(ctx, struct ofproto_push, ctx);
2716 rule->packet_count += push->packets;
2717 rule->byte_count += push->bytes;
2718 rule->used = MAX(push->used, rule->used);
2722 /* Pushes flow statistics to the rules which 'flow' resubmits into given
2723 * 'rule''s actions. */
2725 flow_push_stats(const struct rule_dpif *rule,
2726 struct flow *flow, uint64_t packets, uint64_t bytes,
2729 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
2730 struct ofproto_push push;
2732 push.packets = packets;
2736 action_xlate_ctx_init(&push.ctx, ofproto, flow, NULL);
2737 push.ctx.resubmit_hook = push_resubmit;
2738 ofpbuf_delete(xlate_actions(&push.ctx,
2739 rule->up.actions, rule->up.n_actions));
2744 static struct rule_dpif *
2745 rule_dpif_lookup(struct ofproto_dpif *ofproto, const struct flow *flow,
2748 if (table_id >= N_TABLES) {
2752 return rule_dpif_cast(rule_from_cls_rule(
2753 classifier_lookup(&ofproto->up.tables[table_id],
2758 complete_operation(struct rule_dpif *rule)
2760 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
2762 rule_invalidate(rule);
2764 struct dpif_completion *c = xmalloc(sizeof *c);
2765 c->op = rule->up.pending;
2766 list_push_back(&ofproto->completions, &c->list_node);
2768 ofoperation_complete(rule->up.pending, 0);
2772 static struct rule *
2775 struct rule_dpif *rule = xmalloc(sizeof *rule);
2780 rule_dealloc(struct rule *rule_)
2782 struct rule_dpif *rule = rule_dpif_cast(rule_);
2787 rule_construct(struct rule *rule_)
2789 struct rule_dpif *rule = rule_dpif_cast(rule_);
2790 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
2791 struct rule_dpif *victim;
2795 error = validate_actions(rule->up.actions, rule->up.n_actions,
2796 &rule->up.cr.flow, ofproto->max_ports);
2801 rule->used = rule->up.created;
2802 rule->packet_count = 0;
2803 rule->byte_count = 0;
2805 victim = rule_dpif_cast(ofoperation_get_victim(rule->up.pending));
2806 if (victim && !list_is_empty(&victim->facets)) {
2807 struct facet *facet;
2809 rule->facets = victim->facets;
2810 list_moved(&rule->facets);
2811 LIST_FOR_EACH (facet, list_node, &rule->facets) {
2812 /* XXX: We're only clearing our local counters here. It's possible
2813 * that quite a few packets are unaccounted for in the datapath
2814 * statistics. These will be accounted to the new rule instead of
2815 * cleared as required. This could be fixed by clearing out the
2816 * datapath statistics for this facet, but currently it doesn't
2818 facet_reset_counters(facet);
2822 /* Must avoid list_moved() in this case. */
2823 list_init(&rule->facets);
2826 table_id = rule->up.table_id;
2827 rule->tag = (victim ? victim->tag
2829 : rule_calculate_tag(&rule->up.cr.flow, &rule->up.cr.wc,
2830 ofproto->tables[table_id].basis));
2832 complete_operation(rule);
2837 rule_destruct(struct rule *rule_)
2839 struct rule_dpif *rule = rule_dpif_cast(rule_);
2840 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
2841 struct facet *facet, *next_facet;
2843 LIST_FOR_EACH_SAFE (facet, next_facet, list_node, &rule->facets) {
2844 facet_revalidate(ofproto, facet);
2847 complete_operation(rule);
2851 rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes)
2853 struct rule_dpif *rule = rule_dpif_cast(rule_);
2854 struct facet *facet;
2856 /* Start from historical data for 'rule' itself that are no longer tracked
2857 * in facets. This counts, for example, facets that have expired. */
2858 *packets = rule->packet_count;
2859 *bytes = rule->byte_count;
2861 /* Add any statistics that are tracked by facets. This includes
2862 * statistical data recently updated by ofproto_update_stats() as well as
2863 * stats for packets that were executed "by hand" via dpif_execute(). */
2864 LIST_FOR_EACH (facet, list_node, &rule->facets) {
2865 *packets += facet->packet_count;
2866 *bytes += facet->byte_count;
2871 rule_execute(struct rule *rule_, struct flow *flow, struct ofpbuf *packet)
2873 struct rule_dpif *rule = rule_dpif_cast(rule_);
2874 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
2875 struct action_xlate_ctx ctx;
2876 struct ofpbuf *odp_actions;
2877 struct facet *facet;
2880 /* First look for a related facet. If we find one, account it to that. */
2881 facet = facet_lookup_valid(ofproto, flow);
2882 if (facet && facet->rule == rule) {
2883 facet_execute(ofproto, facet, packet);
2887 /* Otherwise, if 'rule' is in fact the correct rule for 'packet', then
2888 * create a new facet for it and use that. */
2889 if (rule_dpif_lookup(ofproto, flow, 0) == rule) {
2890 facet = facet_create(rule, flow, packet);
2891 facet_execute(ofproto, facet, packet);
2892 facet_install(ofproto, facet, true);
2896 /* We can't account anything to a facet. If we were to try, then that
2897 * facet would have a non-matching rule, busting our invariants. */
2898 action_xlate_ctx_init(&ctx, ofproto, flow, packet);
2899 odp_actions = xlate_actions(&ctx, rule->up.actions, rule->up.n_actions);
2900 size = packet->size;
2901 if (execute_odp_actions(ofproto, flow, odp_actions->data,
2902 odp_actions->size, packet)) {
2903 rule->used = time_msec();
2904 rule->packet_count++;
2905 rule->byte_count += size;
2906 flow_push_stats(rule, flow, 1, size, rule->used);
2908 ofpbuf_delete(odp_actions);
2914 rule_modify_actions(struct rule *rule_)
2916 struct rule_dpif *rule = rule_dpif_cast(rule_);
2917 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
2920 error = validate_actions(rule->up.actions, rule->up.n_actions,
2921 &rule->up.cr.flow, ofproto->max_ports);
2923 ofoperation_complete(rule->up.pending, error);
2927 complete_operation(rule);
2930 /* Sends 'packet' out of port 'odp_port' within 'ofproto'.
2931 * Returns 0 if successful, otherwise a positive errno value. */
2933 send_packet(struct ofproto_dpif *ofproto, uint32_t odp_port,
2934 const struct ofpbuf *packet)
2936 struct ofpbuf key, odp_actions;
2937 struct odputil_keybuf keybuf;
2941 flow_extract((struct ofpbuf *) packet, 0, 0, &flow);
2942 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
2943 odp_flow_key_from_flow(&key, &flow);
2945 ofpbuf_init(&odp_actions, 32);
2946 compose_sflow_action(ofproto, &odp_actions, &flow, odp_port);
2948 nl_msg_put_u32(&odp_actions, OVS_ACTION_ATTR_OUTPUT, odp_port);
2949 error = dpif_execute(ofproto->dpif,
2951 odp_actions.data, odp_actions.size,
2953 ofpbuf_uninit(&odp_actions);
2956 VLOG_WARN_RL(&rl, "%s: failed to send packet on port %"PRIu32" (%s)",
2957 ofproto->up.name, odp_port, strerror(error));
2962 /* OpenFlow to datapath action translation. */
2964 static void do_xlate_actions(const union ofp_action *in, size_t n_in,
2965 struct action_xlate_ctx *ctx);
2966 static void xlate_normal(struct action_xlate_ctx *);
2968 /* Compose SAMPLE action for sFlow. */
2970 compose_sflow_action(const struct ofproto_dpif *ofproto,
2971 struct ofpbuf *odp_actions,
2972 const struct flow *flow,
2975 uint32_t port_ifindex;
2976 uint32_t probability;
2977 struct user_action_cookie *cookie;
2978 size_t sample_offset, actions_offset;
2979 int user_cookie_offset, n_output;
2981 if (!ofproto->sflow || flow->in_port == OFPP_NONE) {
2985 if (odp_port == OVSP_NONE) {
2989 port_ifindex = dpif_sflow_odp_port_to_ifindex(ofproto->sflow, odp_port);
2993 sample_offset = nl_msg_start_nested(odp_actions, OVS_ACTION_ATTR_SAMPLE);
2995 /* Number of packets out of UINT_MAX to sample. */
2996 probability = dpif_sflow_get_probability(ofproto->sflow);
2997 nl_msg_put_u32(odp_actions, OVS_SAMPLE_ATTR_PROBABILITY, probability);
2999 actions_offset = nl_msg_start_nested(odp_actions, OVS_SAMPLE_ATTR_ACTIONS);
3001 cookie = nl_msg_put_unspec_uninit(odp_actions, OVS_ACTION_ATTR_USERSPACE,
3003 cookie->type = USER_ACTION_COOKIE_SFLOW;
3004 cookie->data = port_ifindex;
3005 cookie->n_output = n_output;
3006 cookie->vlan_tci = 0;
3007 user_cookie_offset = (char *) cookie - (char *) odp_actions->data;
3009 nl_msg_end_nested(odp_actions, actions_offset);
3010 nl_msg_end_nested(odp_actions, sample_offset);
3011 return user_cookie_offset;
3014 /* SAMPLE action must be first action in any given list of actions.
3015 * At this point we do not have all information required to build it. So try to
3016 * build sample action as complete as possible. */
3018 add_sflow_action(struct action_xlate_ctx *ctx)
3020 ctx->user_cookie_offset = compose_sflow_action(ctx->ofproto,
3022 &ctx->flow, OVSP_NONE);
3023 ctx->sflow_odp_port = 0;
3024 ctx->sflow_n_outputs = 0;
3027 /* Fix SAMPLE action according to data collected while composing ODP actions.
3028 * We need to fix SAMPLE actions OVS_SAMPLE_ATTR_ACTIONS attribute, i.e. nested
3029 * USERSPACE action's user-cookie which is required for sflow. */
3031 fix_sflow_action(struct action_xlate_ctx *ctx)
3033 const struct flow *base = &ctx->base_flow;
3034 struct user_action_cookie *cookie;
3036 if (!ctx->user_cookie_offset) {
3040 cookie = ofpbuf_at(ctx->odp_actions, ctx->user_cookie_offset,
3042 assert(cookie != NULL);
3043 assert(cookie->type == USER_ACTION_COOKIE_SFLOW);
3045 if (ctx->sflow_n_outputs) {
3046 cookie->data = dpif_sflow_odp_port_to_ifindex(ctx->ofproto->sflow,
3047 ctx->sflow_odp_port);
3049 if (ctx->sflow_n_outputs >= 255) {
3050 cookie->n_output = 255;
3052 cookie->n_output = ctx->sflow_n_outputs;
3054 cookie->vlan_tci = base->vlan_tci;
3058 commit_vlan_tci(struct action_xlate_ctx *ctx, ovs_be16 vlan_tci)
3060 struct flow *base = &ctx->base_flow;
3061 struct ofpbuf *odp_actions = ctx->odp_actions;
3063 if (base->vlan_tci != vlan_tci) {
3064 if (!(vlan_tci & htons(VLAN_CFI))) {
3065 nl_msg_put_flag(odp_actions, OVS_ACTION_ATTR_POP_VLAN);
3067 if (base->vlan_tci != htons(0)) {
3068 nl_msg_put_flag(odp_actions, OVS_ACTION_ATTR_POP_VLAN);
3070 nl_msg_put_be16(odp_actions, OVS_ACTION_ATTR_PUSH_VLAN,
3071 vlan_tci & ~htons(VLAN_CFI));
3073 base->vlan_tci = vlan_tci;
3078 commit_odp_actions(struct action_xlate_ctx *ctx)
3080 const struct flow *flow = &ctx->flow;
3081 struct flow *base = &ctx->base_flow;
3082 struct ofpbuf *odp_actions = ctx->odp_actions;
3084 if (base->tun_id != flow->tun_id) {
3085 nl_msg_put_be64(odp_actions, OVS_ACTION_ATTR_SET_TUNNEL, flow->tun_id);
3086 base->tun_id = flow->tun_id;
3089 if (base->nw_src != flow->nw_src) {
3090 nl_msg_put_be32(odp_actions, OVS_ACTION_ATTR_SET_NW_SRC, flow->nw_src);
3091 base->nw_src = flow->nw_src;
3094 if (base->nw_dst != flow->nw_dst) {
3095 nl_msg_put_be32(odp_actions, OVS_ACTION_ATTR_SET_NW_DST, flow->nw_dst);
3096 base->nw_dst = flow->nw_dst;
3099 if (base->nw_tos != flow->nw_tos) {
3100 nl_msg_put_u8(odp_actions, OVS_ACTION_ATTR_SET_NW_TOS, flow->nw_tos);
3101 base->nw_tos = flow->nw_tos;
3104 commit_vlan_tci(ctx, flow->vlan_tci);
3106 if (base->tp_src != flow->tp_src) {
3107 nl_msg_put_be16(odp_actions, OVS_ACTION_ATTR_SET_TP_SRC, flow->tp_src);
3108 base->tp_src = flow->tp_src;
3111 if (base->tp_dst != flow->tp_dst) {
3112 nl_msg_put_be16(odp_actions, OVS_ACTION_ATTR_SET_TP_DST, flow->tp_dst);
3113 base->tp_dst = flow->tp_dst;
3116 if (!eth_addr_equals(base->dl_src, flow->dl_src)) {
3117 nl_msg_put_unspec(odp_actions, OVS_ACTION_ATTR_SET_DL_SRC,
3118 flow->dl_src, ETH_ADDR_LEN);
3119 memcpy(base->dl_src, flow->dl_src, ETH_ADDR_LEN);
3122 if (!eth_addr_equals(base->dl_dst, flow->dl_dst)) {
3123 nl_msg_put_unspec(odp_actions, OVS_ACTION_ATTR_SET_DL_DST,
3124 flow->dl_dst, ETH_ADDR_LEN);
3125 memcpy(base->dl_dst, flow->dl_dst, ETH_ADDR_LEN);
3128 if (ctx->base_priority != ctx->priority) {
3129 if (ctx->priority) {
3130 nl_msg_put_u32(odp_actions, OVS_ACTION_ATTR_SET_PRIORITY,
3133 nl_msg_put_flag(odp_actions, OVS_ACTION_ATTR_POP_PRIORITY);
3135 ctx->base_priority = ctx->priority;
3140 compose_output_action(struct action_xlate_ctx *ctx, uint16_t odp_port)
3142 nl_msg_put_u32(ctx->odp_actions, OVS_ACTION_ATTR_OUTPUT, odp_port);
3143 ctx->sflow_odp_port = odp_port;
3144 ctx->sflow_n_outputs++;
3148 add_output_action(struct action_xlate_ctx *ctx, uint16_t ofp_port)
3150 const struct ofport_dpif *ofport = get_ofp_port(ctx->ofproto, ofp_port);
3151 uint16_t odp_port = ofp_port_to_odp_port(ofp_port);
3154 if (ofport->up.opp.config & htonl(OFPPC_NO_FWD)) {
3155 /* Forwarding disabled on port. */
3160 * We don't have an ofport record for this port, but it doesn't hurt to
3161 * allow forwarding to it anyhow. Maybe such a port will appear later
3162 * and we're pre-populating the flow table.
3166 commit_odp_actions(ctx);
3167 compose_output_action(ctx, odp_port);
3168 ctx->nf_output_iface = ofp_port;
3172 xlate_table_action(struct action_xlate_ctx *ctx,
3173 uint16_t in_port, uint8_t table_id)
3175 if (ctx->recurse < MAX_RESUBMIT_RECURSION) {
3176 struct ofproto_dpif *ofproto = ctx->ofproto;
3177 struct rule_dpif *rule;
3178 uint16_t old_in_port;
3179 uint8_t old_table_id;
3181 old_table_id = ctx->table_id;
3182 ctx->table_id = table_id;
3184 /* Look up a flow with 'in_port' as the input port. */
3185 old_in_port = ctx->flow.in_port;
3186 ctx->flow.in_port = in_port;
3187 rule = rule_dpif_lookup(ofproto, &ctx->flow, table_id);
3190 if (table_id > 0 && table_id < N_TABLES) {
3191 struct table_dpif *table = &ofproto->tables[table_id];
3192 if (table->other_table) {
3195 : rule_calculate_tag(&ctx->flow,
3196 &table->other_table->wc,
3201 /* Restore the original input port. Otherwise OFPP_NORMAL and
3202 * OFPP_IN_PORT will have surprising behavior. */
3203 ctx->flow.in_port = old_in_port;
3205 if (ctx->resubmit_hook) {
3206 ctx->resubmit_hook(ctx, rule);
3211 do_xlate_actions(rule->up.actions, rule->up.n_actions, ctx);
3215 ctx->table_id = old_table_id;
3217 static struct vlog_rate_limit recurse_rl = VLOG_RATE_LIMIT_INIT(1, 1);
3219 VLOG_ERR_RL(&recurse_rl, "resubmit actions recursed over %d times",
3220 MAX_RESUBMIT_RECURSION);
3225 xlate_resubmit_table(struct action_xlate_ctx *ctx,
3226 const struct nx_action_resubmit *nar)
3231 in_port = (nar->in_port == htons(OFPP_IN_PORT)
3233 : ntohs(nar->in_port));
3234 table_id = nar->table == 255 ? ctx->table_id : nar->table;
3236 xlate_table_action(ctx, in_port, table_id);
3240 flood_packets(struct action_xlate_ctx *ctx, ovs_be32 mask)
3242 struct ofport_dpif *ofport;
3244 commit_odp_actions(ctx);
3245 HMAP_FOR_EACH (ofport, up.hmap_node, &ctx->ofproto->up.ports) {
3246 uint16_t ofp_port = ofport->up.ofp_port;
3247 if (ofp_port != ctx->flow.in_port && !(ofport->up.opp.config & mask)) {
3248 compose_output_action(ctx, ofport->odp_port);
3252 ctx->nf_output_iface = NF_OUT_FLOOD;
3256 compose_controller_action(struct ofpbuf *odp_actions, int len)
3258 struct user_action_cookie cookie;
3260 cookie.type = USER_ACTION_COOKIE_CONTROLLER;
3262 cookie.n_output = 0;
3263 cookie.vlan_tci = 0;
3265 nl_msg_put_unspec(odp_actions, OVS_ACTION_ATTR_USERSPACE,
3266 &cookie, sizeof(cookie));
3270 xlate_output_action__(struct action_xlate_ctx *ctx,
3271 uint16_t port, uint16_t max_len)
3273 uint16_t prev_nf_output_iface = ctx->nf_output_iface;
3275 ctx->nf_output_iface = NF_OUT_DROP;
3279 add_output_action(ctx, ctx->flow.in_port);
3282 xlate_table_action(ctx, ctx->flow.in_port, ctx->table_id);
3288 flood_packets(ctx, htonl(OFPPC_NO_FLOOD));
3291 flood_packets(ctx, htonl(0));
3293 case OFPP_CONTROLLER:
3294 commit_odp_actions(ctx);
3295 compose_controller_action(ctx->odp_actions, max_len);
3298 add_output_action(ctx, OFPP_LOCAL);
3303 if (port != ctx->flow.in_port) {
3304 add_output_action(ctx, port);
3309 if (prev_nf_output_iface == NF_OUT_FLOOD) {
3310 ctx->nf_output_iface = NF_OUT_FLOOD;
3311 } else if (ctx->nf_output_iface == NF_OUT_DROP) {
3312 ctx->nf_output_iface = prev_nf_output_iface;
3313 } else if (prev_nf_output_iface != NF_OUT_DROP &&
3314 ctx->nf_output_iface != NF_OUT_FLOOD) {
3315 ctx->nf_output_iface = NF_OUT_MULTI;
3320 xlate_output_reg_action(struct action_xlate_ctx *ctx,
3321 const struct nx_action_output_reg *naor)
3325 ofp_port = nxm_read_field_bits(naor->src, naor->ofs_nbits, &ctx->flow);
3327 if (ofp_port <= UINT16_MAX) {
3328 xlate_output_action__(ctx, ofp_port, ntohs(naor->max_len));
3333 xlate_output_action(struct action_xlate_ctx *ctx,
3334 const struct ofp_action_output *oao)
3336 xlate_output_action__(ctx, ntohs(oao->port), ntohs(oao->max_len));
3340 xlate_enqueue_action(struct action_xlate_ctx *ctx,
3341 const struct ofp_action_enqueue *oae)
3343 uint16_t ofp_port, odp_port;
3344 uint32_t ctx_priority, priority;
3347 error = dpif_queue_to_priority(ctx->ofproto->dpif, ntohl(oae->queue_id),
3350 /* Fall back to ordinary output action. */
3351 xlate_output_action__(ctx, ntohs(oae->port), 0);
3355 /* Figure out datapath output port. */
3356 ofp_port = ntohs(oae->port);
3357 if (ofp_port == OFPP_IN_PORT) {
3358 ofp_port = ctx->flow.in_port;
3360 odp_port = ofp_port_to_odp_port(ofp_port);
3362 /* Add datapath actions. */
3363 ctx_priority = ctx->priority;
3364 ctx->priority = priority;
3365 add_output_action(ctx, odp_port);
3366 ctx->priority = ctx_priority;
3368 /* Update NetFlow output port. */
3369 if (ctx->nf_output_iface == NF_OUT_DROP) {
3370 ctx->nf_output_iface = odp_port;
3371 } else if (ctx->nf_output_iface != NF_OUT_FLOOD) {
3372 ctx->nf_output_iface = NF_OUT_MULTI;
3377 xlate_set_queue_action(struct action_xlate_ctx *ctx,
3378 const struct nx_action_set_queue *nasq)
3383 error = dpif_queue_to_priority(ctx->ofproto->dpif, ntohl(nasq->queue_id),
3386 /* Couldn't translate queue to a priority, so ignore. A warning
3387 * has already been logged. */
3391 ctx->priority = priority;
3394 struct xlate_reg_state {
3400 xlate_autopath(struct action_xlate_ctx *ctx,
3401 const struct nx_action_autopath *naa)
3403 uint16_t ofp_port = ntohl(naa->id);
3404 struct ofport_dpif *port = get_ofp_port(ctx->ofproto, ofp_port);
3406 if (!port || !port->bundle) {
3407 ofp_port = OFPP_NONE;
3408 } else if (port->bundle->bond) {
3409 /* Autopath does not support VLAN hashing. */
3410 struct ofport_dpif *slave = bond_choose_output_slave(
3411 port->bundle->bond, &ctx->flow, 0, &ctx->tags);
3413 ofp_port = slave->up.ofp_port;
3416 autopath_execute(naa, &ctx->flow, ofp_port);
3420 slave_enabled_cb(uint16_t ofp_port, void *ofproto_)
3422 struct ofproto_dpif *ofproto = ofproto_;
3423 struct ofport_dpif *port;
3433 case OFPP_CONTROLLER: /* Not supported by the bundle action. */
3436 port = get_ofp_port(ofproto, ofp_port);
3437 return port ? port->may_enable : false;
3442 xlate_learn_action(struct action_xlate_ctx *ctx,
3443 const struct nx_action_learn *learn)
3445 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
3446 struct ofputil_flow_mod fm;
3449 learn_execute(learn, &ctx->flow, &fm);
3451 error = ofproto_flow_mod(&ctx->ofproto->up, &fm);
3452 if (error && !VLOG_DROP_WARN(&rl)) {
3453 char *msg = ofputil_error_to_string(error);
3454 VLOG_WARN("learning action failed to modify flow table (%s)", msg);
3462 do_xlate_actions(const union ofp_action *in, size_t n_in,
3463 struct action_xlate_ctx *ctx)
3465 const struct ofport_dpif *port;
3466 const union ofp_action *ia;
3469 port = get_ofp_port(ctx->ofproto, ctx->flow.in_port);
3471 && port->up.opp.config & htonl(OFPPC_NO_RECV | OFPPC_NO_RECV_STP) &&
3472 port->up.opp.config & (eth_addr_equals(ctx->flow.dl_dst, eth_addr_stp)
3473 ? htonl(OFPPC_NO_RECV_STP)
3474 : htonl(OFPPC_NO_RECV))) {
3475 /* Drop this flow. */
3479 OFPUTIL_ACTION_FOR_EACH_UNSAFE (ia, left, in, n_in) {
3480 const struct ofp_action_dl_addr *oada;
3481 const struct nx_action_resubmit *nar;
3482 const struct nx_action_set_tunnel *nast;
3483 const struct nx_action_set_queue *nasq;
3484 const struct nx_action_multipath *nam;
3485 const struct nx_action_autopath *naa;
3486 const struct nx_action_bundle *nab;
3487 const struct nx_action_output_reg *naor;
3488 enum ofputil_action_code code;
3491 code = ofputil_decode_action_unsafe(ia);
3493 case OFPUTIL_OFPAT_OUTPUT:
3494 xlate_output_action(ctx, &ia->output);
3497 case OFPUTIL_OFPAT_SET_VLAN_VID:
3498 ctx->flow.vlan_tci &= ~htons(VLAN_VID_MASK);
3499 ctx->flow.vlan_tci |= ia->vlan_vid.vlan_vid | htons(VLAN_CFI);
3502 case OFPUTIL_OFPAT_SET_VLAN_PCP:
3503 ctx->flow.vlan_tci &= ~htons(VLAN_PCP_MASK);
3504 ctx->flow.vlan_tci |= htons(
3505 (ia->vlan_pcp.vlan_pcp << VLAN_PCP_SHIFT) | VLAN_CFI);
3508 case OFPUTIL_OFPAT_STRIP_VLAN:
3509 ctx->flow.vlan_tci = htons(0);
3512 case OFPUTIL_OFPAT_SET_DL_SRC:
3513 oada = ((struct ofp_action_dl_addr *) ia);
3514 memcpy(ctx->flow.dl_src, oada->dl_addr, ETH_ADDR_LEN);
3517 case OFPUTIL_OFPAT_SET_DL_DST:
3518 oada = ((struct ofp_action_dl_addr *) ia);
3519 memcpy(ctx->flow.dl_dst, oada->dl_addr, ETH_ADDR_LEN);
3522 case OFPUTIL_OFPAT_SET_NW_SRC:
3523 ctx->flow.nw_src = ia->nw_addr.nw_addr;
3526 case OFPUTIL_OFPAT_SET_NW_DST:
3527 ctx->flow.nw_dst = ia->nw_addr.nw_addr;
3530 case OFPUTIL_OFPAT_SET_NW_TOS:
3531 ctx->flow.nw_tos = ia->nw_tos.nw_tos & IP_DSCP_MASK;
3534 case OFPUTIL_OFPAT_SET_TP_SRC:
3535 ctx->flow.tp_src = ia->tp_port.tp_port;
3538 case OFPUTIL_OFPAT_SET_TP_DST:
3539 ctx->flow.tp_dst = ia->tp_port.tp_port;
3542 case OFPUTIL_OFPAT_ENQUEUE:
3543 xlate_enqueue_action(ctx, (const struct ofp_action_enqueue *) ia);
3546 case OFPUTIL_NXAST_RESUBMIT:
3547 nar = (const struct nx_action_resubmit *) ia;
3548 xlate_table_action(ctx, ntohs(nar->in_port), ctx->table_id);
3551 case OFPUTIL_NXAST_RESUBMIT_TABLE:
3552 xlate_resubmit_table(ctx, (const struct nx_action_resubmit *) ia);
3555 case OFPUTIL_NXAST_SET_TUNNEL:
3556 nast = (const struct nx_action_set_tunnel *) ia;
3557 tun_id = htonll(ntohl(nast->tun_id));
3558 ctx->flow.tun_id = tun_id;
3561 case OFPUTIL_NXAST_SET_QUEUE:
3562 nasq = (const struct nx_action_set_queue *) ia;
3563 xlate_set_queue_action(ctx, nasq);
3566 case OFPUTIL_NXAST_POP_QUEUE:
3570 case OFPUTIL_NXAST_REG_MOVE:
3571 nxm_execute_reg_move((const struct nx_action_reg_move *) ia,
3575 case OFPUTIL_NXAST_REG_LOAD:
3576 nxm_execute_reg_load((const struct nx_action_reg_load *) ia,
3580 case OFPUTIL_NXAST_NOTE:
3581 /* Nothing to do. */
3584 case OFPUTIL_NXAST_SET_TUNNEL64:
3585 tun_id = ((const struct nx_action_set_tunnel64 *) ia)->tun_id;
3586 ctx->flow.tun_id = tun_id;
3589 case OFPUTIL_NXAST_MULTIPATH:
3590 nam = (const struct nx_action_multipath *) ia;
3591 multipath_execute(nam, &ctx->flow);
3594 case OFPUTIL_NXAST_AUTOPATH:
3595 naa = (const struct nx_action_autopath *) ia;
3596 xlate_autopath(ctx, naa);
3599 case OFPUTIL_NXAST_BUNDLE:
3600 ctx->ofproto->has_bundle_action = true;
3601 nab = (const struct nx_action_bundle *) ia;
3602 xlate_output_action__(ctx, bundle_execute(nab, &ctx->flow,
3607 case OFPUTIL_NXAST_BUNDLE_LOAD:
3608 ctx->ofproto->has_bundle_action = true;
3609 nab = (const struct nx_action_bundle *) ia;
3610 bundle_execute_load(nab, &ctx->flow, slave_enabled_cb,
3614 case OFPUTIL_NXAST_OUTPUT_REG:
3615 naor = (const struct nx_action_output_reg *) ia;
3616 xlate_output_reg_action(ctx, naor);
3619 case OFPUTIL_NXAST_LEARN:
3620 ctx->has_learn = true;
3621 if (ctx->may_learn) {
3622 xlate_learn_action(ctx, (const struct nx_action_learn *) ia);
3630 action_xlate_ctx_init(struct action_xlate_ctx *ctx,
3631 struct ofproto_dpif *ofproto, const struct flow *flow,
3632 const struct ofpbuf *packet)
3634 ctx->ofproto = ofproto;
3636 ctx->packet = packet;
3637 ctx->may_learn = packet != NULL;
3638 ctx->resubmit_hook = NULL;
3641 static struct ofpbuf *
3642 xlate_actions(struct action_xlate_ctx *ctx,
3643 const union ofp_action *in, size_t n_in)
3645 COVERAGE_INC(ofproto_dpif_xlate);
3647 ctx->odp_actions = ofpbuf_new(512);
3649 ctx->may_set_up_flow = true;
3650 ctx->has_learn = false;
3651 ctx->has_normal = false;
3652 ctx->nf_output_iface = NF_OUT_DROP;
3655 ctx->base_priority = 0;
3656 ctx->base_flow = ctx->flow;
3657 ctx->base_flow.tun_id = 0;
3660 if (process_special(ctx->ofproto, &ctx->flow, ctx->packet)) {
3661 ctx->may_set_up_flow = false;
3663 add_sflow_action(ctx);
3664 do_xlate_actions(in, n_in, ctx);
3665 fix_sflow_action(ctx);
3668 /* Check with in-band control to see if we're allowed to set up this
3670 if (!connmgr_may_set_up_flow(ctx->ofproto->up.connmgr, &ctx->flow,
3671 ctx->odp_actions->data,
3672 ctx->odp_actions->size)) {
3673 ctx->may_set_up_flow = false;
3676 return ctx->odp_actions;
3679 /* OFPP_NORMAL implementation. */
3682 struct ofport_dpif *port;
3687 struct dst builtin[32];
3689 size_t n, allocated;
3692 static void dst_set_init(struct dst_set *);
3693 static void dst_set_add(struct dst_set *, const struct dst *);
3694 static void dst_set_free(struct dst_set *);
3696 static struct ofport_dpif *ofbundle_get_a_port(const struct ofbundle *);
3698 /* Given 'vid', the VID obtained from the 802.1Q header that was received as
3699 * part of a packet (specify 0 if there was no 802.1Q header), and 'in_bundle',
3700 * the bundle on which the packet was received, returns the VLAN to which the
3703 * Both 'vid' and the return value are in the range 0...4095. */
3705 input_vid_to_vlan(const struct ofbundle *in_bundle, uint16_t vid)
3707 switch (in_bundle->vlan_mode) {
3708 case PORT_VLAN_ACCESS:
3709 return in_bundle->vlan;
3712 case PORT_VLAN_TRUNK:
3715 case PORT_VLAN_NATIVE_UNTAGGED:
3716 case PORT_VLAN_NATIVE_TAGGED:
3717 return vid ? vid : in_bundle->vlan;
3724 /* Given 'vlan', the VLAN that a packet belongs to, and
3725 * 'out_bundle', a bundle on which the packet is to be output, returns the VID
3726 * that should be included in the 802.1Q header. (If the return value is 0,
3727 * then the 802.1Q header should only be included in the packet if there is a
3730 * Both 'vlan' and the return value are in the range 0...4095. */
3732 output_vlan_to_vid(const struct ofbundle *out_bundle, uint16_t vlan)
3734 switch (out_bundle->vlan_mode) {
3735 case PORT_VLAN_ACCESS:
3738 case PORT_VLAN_TRUNK:
3739 case PORT_VLAN_NATIVE_TAGGED:
3742 case PORT_VLAN_NATIVE_UNTAGGED:
3743 return vlan == out_bundle->vlan ? 0 : vlan;
3751 set_dst(struct action_xlate_ctx *ctx, struct dst *dst,
3752 const struct ofbundle *in_bundle, const struct ofbundle *out_bundle)
3756 vlan = input_vid_to_vlan(in_bundle, vlan_tci_to_vid(ctx->flow.vlan_tci));
3757 dst->vid = output_vlan_to_vid(out_bundle, vlan);
3759 dst->port = (!out_bundle->bond
3760 ? ofbundle_get_a_port(out_bundle)
3761 : bond_choose_output_slave(out_bundle->bond, &ctx->flow,
3762 dst->vid, &ctx->tags));
3763 return dst->port != NULL;
3767 mirror_mask_ffs(mirror_mask_t mask)
3769 BUILD_ASSERT_DECL(sizeof(unsigned int) >= sizeof(mask));
3774 dst_set_init(struct dst_set *set)
3776 set->dsts = set->builtin;
3778 set->allocated = ARRAY_SIZE(set->builtin);
3782 dst_set_add(struct dst_set *set, const struct dst *dst)
3784 if (set->n >= set->allocated) {
3785 size_t new_allocated;
3786 struct dst *new_dsts;
3788 new_allocated = set->allocated * 2;
3789 new_dsts = xmalloc(new_allocated * sizeof *new_dsts);
3790 memcpy(new_dsts, set->dsts, set->n * sizeof *new_dsts);
3794 set->dsts = new_dsts;
3795 set->allocated = new_allocated;
3797 set->dsts[set->n++] = *dst;
3801 dst_set_free(struct dst_set *set)
3803 if (set->dsts != set->builtin) {
3809 dst_is_duplicate(const struct dst_set *set, const struct dst *test)
3812 for (i = 0; i < set->n; i++) {
3813 if (set->dsts[i].vid == test->vid
3814 && set->dsts[i].port == test->port) {
3822 ofbundle_trunks_vlan(const struct ofbundle *bundle, uint16_t vlan)
3824 return (bundle->vlan_mode != PORT_VLAN_ACCESS
3825 && (!bundle->trunks || bitmap_is_set(bundle->trunks, vlan)));
3829 ofbundle_includes_vlan(const struct ofbundle *bundle, uint16_t vlan)
3831 return vlan == bundle->vlan || ofbundle_trunks_vlan(bundle, vlan);
3834 /* Returns an arbitrary interface within 'bundle'. */
3835 static struct ofport_dpif *
3836 ofbundle_get_a_port(const struct ofbundle *bundle)
3838 return CONTAINER_OF(list_front(&bundle->ports),
3839 struct ofport_dpif, bundle_node);
3843 compose_dsts(struct action_xlate_ctx *ctx, uint16_t vlan,
3844 const struct ofbundle *in_bundle,
3845 const struct ofbundle *out_bundle, struct dst_set *set)
3849 if (out_bundle == OFBUNDLE_FLOOD) {
3850 struct ofbundle *bundle;
3852 HMAP_FOR_EACH (bundle, hmap_node, &ctx->ofproto->bundles) {
3853 if (bundle != in_bundle
3854 && ofbundle_includes_vlan(bundle, vlan)
3855 && bundle->floodable
3856 && !bundle->mirror_out
3857 && set_dst(ctx, &dst, in_bundle, bundle)) {
3858 dst_set_add(set, &dst);
3861 ctx->nf_output_iface = NF_OUT_FLOOD;
3862 } else if (out_bundle && set_dst(ctx, &dst, in_bundle, out_bundle)) {
3863 dst_set_add(set, &dst);
3864 ctx->nf_output_iface = dst.port->odp_port;
3869 vlan_is_mirrored(const struct ofmirror *m, int vlan)
3871 return !m->vlans || bitmap_is_set(m->vlans, vlan);
3874 /* Returns true if a packet with Ethernet destination MAC 'dst' may be mirrored
3875 * to a VLAN. In general most packets may be mirrored but we want to drop
3876 * protocols that may confuse switches. */
3878 eth_dst_may_rspan(const uint8_t dst[ETH_ADDR_LEN])
3880 /* If you change this function's behavior, please update corresponding
3881 * documentation in vswitch.xml at the same time. */
3882 if (dst[0] != 0x01) {
3883 /* All the currently banned MACs happen to start with 01 currently, so
3884 * this is a quick way to eliminate most of the good ones. */
3886 if (eth_addr_is_reserved(dst)) {
3887 /* Drop STP, IEEE pause frames, and other reserved protocols
3888 * (01-80-c2-00-00-0x). */
3892 if (dst[0] == 0x01 && dst[1] == 0x00 && dst[2] == 0x0c) {
3894 if ((dst[3] & 0xfe) == 0xcc &&
3895 (dst[4] & 0xfe) == 0xcc &&
3896 (dst[5] & 0xfe) == 0xcc) {
3897 /* Drop the following protocols plus others following the same
3900 CDP, VTP, DTP, PAgP (01-00-0c-cc-cc-cc)
3901 Spanning Tree PVSTP+ (01-00-0c-cc-cc-cd)
3902 STP Uplink Fast (01-00-0c-cd-cd-cd) */
3906 if (!(dst[3] | dst[4] | dst[5])) {
3907 /* Drop Inter Switch Link packets (01-00-0c-00-00-00). */
3916 compose_mirror_dsts(struct action_xlate_ctx *ctx,
3917 uint16_t vlan, const struct ofbundle *in_bundle,
3918 struct dst_set *set)
3920 struct ofproto_dpif *ofproto = ctx->ofproto;
3921 mirror_mask_t mirrors;
3925 mirrors = in_bundle->src_mirrors;
3926 for (i = 0; i < set->n; i++) {
3927 mirrors |= set->dsts[i].port->bundle->dst_mirrors;
3934 flow_vid = vlan_tci_to_vid(ctx->flow.vlan_tci);
3936 struct ofmirror *m = ofproto->mirrors[mirror_mask_ffs(mirrors) - 1];
3937 if (vlan_is_mirrored(m, vlan)) {
3941 if (set_dst(ctx, &dst, in_bundle, m->out)
3942 && !dst_is_duplicate(set, &dst)) {
3943 dst_set_add(set, &dst);
3945 } else if (eth_dst_may_rspan(ctx->flow.dl_dst)) {
3946 struct ofbundle *bundle;
3948 HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
3949 if (ofbundle_includes_vlan(bundle, m->out_vlan)
3950 && set_dst(ctx, &dst, in_bundle, bundle))
3952 /* set_dst() got dst->vid from the input packet's VLAN,
3953 * not from m->out_vlan, so recompute it. */
3954 dst.vid = output_vlan_to_vid(bundle, m->out_vlan);
3956 if (dst_is_duplicate(set, &dst)) {
3960 if (bundle == in_bundle && dst.vid == flow_vid) {
3961 /* Don't send out input port on same VLAN. */
3964 dst_set_add(set, &dst);
3969 mirrors &= mirrors - 1;
3974 compose_actions(struct action_xlate_ctx *ctx, uint16_t vlan,
3975 const struct ofbundle *in_bundle,
3976 const struct ofbundle *out_bundle)
3978 uint16_t initial_vid, cur_vid;
3979 const struct dst *dst;
3983 compose_dsts(ctx, vlan, in_bundle, out_bundle, &set);
3984 compose_mirror_dsts(ctx, vlan, in_bundle, &set);
3990 /* Output all the packets we can without having to change the VLAN. */
3991 commit_odp_actions(ctx);
3992 initial_vid = vlan_tci_to_vid(ctx->flow.vlan_tci);
3993 for (dst = set.dsts; dst < &set.dsts[set.n]; dst++) {
3994 if (dst->vid != initial_vid) {
3997 compose_output_action(ctx, dst->port->odp_port);
4000 /* Then output the rest. */
4001 cur_vid = initial_vid;
4002 for (dst = set.dsts; dst < &set.dsts[set.n]; dst++) {
4003 if (dst->vid == initial_vid) {
4006 if (dst->vid != cur_vid) {
4009 tci = htons(dst->vid);
4010 tci |= ctx->flow.vlan_tci & htons(VLAN_PCP_MASK);
4012 tci |= htons(VLAN_CFI);
4014 commit_vlan_tci(ctx, tci);
4018 compose_output_action(ctx, dst->port->odp_port);
4024 /* Returns the effective vlan of a packet, taking into account both the
4025 * 802.1Q header and implicitly tagged ports. A value of 0 indicates that
4026 * the packet is untagged and -1 indicates it has an invalid header and
4027 * should be dropped. */
4029 flow_get_vlan(struct ofproto_dpif *ofproto, const struct flow *flow,
4030 struct ofbundle *in_bundle, bool have_packet)
4032 int vlan = vlan_tci_to_vid(flow->vlan_tci);
4034 if (in_bundle->vlan_mode == PORT_VLAN_ACCESS) {
4035 /* Drop tagged packet on access port */
4037 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
4038 VLOG_WARN_RL(&rl, "bridge %s: dropping VLAN %d tagged "
4039 "packet received on port %s configured with "
4040 "implicit VLAN %"PRIu16,
4041 ofproto->up.name, vlan,
4042 in_bundle->name, in_bundle->vlan);
4045 } else if (ofbundle_includes_vlan(in_bundle, vlan)) {
4048 /* Drop packets from a VLAN not member of the trunk */
4050 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
4051 VLOG_WARN_RL(&rl, "bridge %s: dropping VLAN %d tagged "
4052 "packet received on port %s not configured for "
4054 ofproto->up.name, vlan, in_bundle->name, vlan);
4059 if (in_bundle->vlan_mode != PORT_VLAN_TRUNK) {
4060 return in_bundle->vlan;
4062 return ofbundle_includes_vlan(in_bundle, 0) ? 0 : -1;
4067 /* A VM broadcasts a gratuitous ARP to indicate that it has resumed after
4068 * migration. Older Citrix-patched Linux DomU used gratuitous ARP replies to
4069 * indicate this; newer upstream kernels use gratuitous ARP requests. */
4071 is_gratuitous_arp(const struct flow *flow)
4073 return (flow->dl_type == htons(ETH_TYPE_ARP)
4074 && eth_addr_is_broadcast(flow->dl_dst)
4075 && (flow->nw_proto == ARP_OP_REPLY
4076 || (flow->nw_proto == ARP_OP_REQUEST
4077 && flow->nw_src == flow->nw_dst)));
4081 update_learning_table(struct ofproto_dpif *ofproto,
4082 const struct flow *flow, int vlan,
4083 struct ofbundle *in_bundle)
4085 struct mac_entry *mac;
4087 if (!mac_learning_may_learn(ofproto->ml, flow->dl_src, vlan)) {
4091 mac = mac_learning_insert(ofproto->ml, flow->dl_src, vlan);
4092 if (is_gratuitous_arp(flow)) {
4093 /* We don't want to learn from gratuitous ARP packets that are
4094 * reflected back over bond slaves so we lock the learning table. */
4095 if (!in_bundle->bond) {
4096 mac_entry_set_grat_arp_lock(mac);
4097 } else if (mac_entry_is_grat_arp_locked(mac)) {
4102 if (mac_entry_is_new(mac) || mac->port.p != in_bundle) {
4103 /* The log messages here could actually be useful in debugging,
4104 * so keep the rate limit relatively high. */
4105 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
4106 VLOG_DBG_RL(&rl, "bridge %s: learned that "ETH_ADDR_FMT" is "
4107 "on port %s in VLAN %d",
4108 ofproto->up.name, ETH_ADDR_ARGS(flow->dl_src),
4109 in_bundle->name, vlan);
4111 mac->port.p = in_bundle;
4112 tag_set_add(&ofproto->revalidate_set,
4113 mac_learning_changed(ofproto->ml, mac));
4117 /* Determines whether packets in 'flow' within 'br' should be forwarded or
4118 * dropped. Returns true if they may be forwarded, false if they should be
4121 * If 'have_packet' is true, it indicates that the caller is processing a
4122 * received packet. If 'have_packet' is false, then the caller is just
4123 * revalidating an existing flow because configuration has changed. Either
4124 * way, 'have_packet' only affects logging (there is no point in logging errors
4125 * during revalidation).
4127 * Sets '*in_portp' to the input port. This will be a null pointer if
4128 * flow->in_port does not designate a known input port (in which case
4129 * is_admissible() returns false).
4131 * When returning true, sets '*vlanp' to the effective VLAN of the input
4132 * packet, as returned by flow_get_vlan().
4134 * May also add tags to '*tags', although the current implementation only does
4135 * so in one special case.
4138 is_admissible(struct ofproto_dpif *ofproto, const struct flow *flow,
4140 tag_type *tags, int *vlanp, struct ofbundle **in_bundlep)
4142 struct ofport_dpif *in_port;
4143 struct ofbundle *in_bundle;
4146 /* Find the port and bundle for the received packet. */
4147 in_port = get_ofp_port(ofproto, flow->in_port);
4148 *in_bundlep = in_bundle = in_port ? in_port->bundle : NULL;
4149 if (!in_port || !in_bundle) {
4150 /* No interface? Something fishy... */
4152 /* Odd. A few possible reasons here:
4154 * - We deleted a port but there are still a few packets queued up
4157 * - Someone externally added a port (e.g. "ovs-dpctl add-if") that
4158 * we don't know about.
4160 * - Packet arrived on the local port but the local port is not
4163 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
4165 VLOG_WARN_RL(&rl, "bridge %s: received packet on unknown "
4167 ofproto->up.name, flow->in_port);
4172 *vlanp = vlan = flow_get_vlan(ofproto, flow, in_bundle, have_packet);
4177 /* Drop frames for reserved multicast addresses
4178 * only if forward_bpdu option is absent. */
4179 if (eth_addr_is_reserved(flow->dl_dst) &&
4180 !ofproto->up.forward_bpdu) {
4184 /* Drop frames on bundles reserved for mirroring. */
4185 if (in_bundle->mirror_out) {
4187 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
4188 VLOG_WARN_RL(&rl, "bridge %s: dropping packet received on port "
4189 "%s, which is reserved exclusively for mirroring",
4190 ofproto->up.name, in_bundle->name);
4195 if (in_bundle->bond) {
4196 struct mac_entry *mac;
4198 switch (bond_check_admissibility(in_bundle->bond, in_port,
4199 flow->dl_dst, tags)) {
4206 case BV_DROP_IF_MOVED:
4207 mac = mac_learning_lookup(ofproto->ml, flow->dl_src, vlan, NULL);
4208 if (mac && mac->port.p != in_bundle &&
4209 (!is_gratuitous_arp(flow)
4210 || mac_entry_is_grat_arp_locked(mac))) {
4221 xlate_normal(struct action_xlate_ctx *ctx)
4223 struct ofbundle *in_bundle;
4224 struct ofbundle *out_bundle;
4225 struct mac_entry *mac;
4228 ctx->has_normal = true;
4230 /* Check whether we should drop packets in this flow. */
4231 if (!is_admissible(ctx->ofproto, &ctx->flow, ctx->packet != NULL,
4232 &ctx->tags, &vlan, &in_bundle)) {
4237 /* Learn source MAC. */
4238 if (ctx->may_learn) {
4239 update_learning_table(ctx->ofproto, &ctx->flow, vlan, in_bundle);
4242 /* Determine output bundle. */
4243 mac = mac_learning_lookup(ctx->ofproto->ml, ctx->flow.dl_dst, vlan,
4246 out_bundle = mac->port.p;
4247 } else if (!ctx->packet && !eth_addr_is_multicast(ctx->flow.dl_dst)) {
4248 /* If we are revalidating but don't have a learning entry then eject
4249 * the flow. Installing a flow that floods packets opens up a window
4250 * of time where we could learn from a packet reflected on a bond and
4251 * blackhole packets before the learning table is updated to reflect
4252 * the correct port. */
4253 ctx->may_set_up_flow = false;
4256 out_bundle = OFBUNDLE_FLOOD;
4259 /* Don't send packets out their input bundles. */
4260 if (in_bundle == out_bundle) {
4266 compose_actions(ctx, vlan, in_bundle, out_bundle);
4270 /* Optimized flow revalidation.
4272 * It's a difficult problem, in general, to tell which facets need to have
4273 * their actions recalculated whenever the OpenFlow flow table changes. We
4274 * don't try to solve that general problem: for most kinds of OpenFlow flow
4275 * table changes, we recalculate the actions for every facet. This is
4276 * relatively expensive, but it's good enough if the OpenFlow flow table
4277 * doesn't change very often.
4279 * However, we can expect one particular kind of OpenFlow flow table change to
4280 * happen frequently: changes caused by MAC learning. To avoid wasting a lot
4281 * of CPU on revalidating every facet whenever MAC learning modifies the flow
4282 * table, we add a special case that applies to flow tables in which every rule
4283 * has the same form (that is, the same wildcards), except that the table is
4284 * also allowed to have a single "catch-all" flow that matches all packets. We
4285 * optimize this case by tagging all of the facets that resubmit into the table
4286 * and invalidating the same tag whenever a flow changes in that table. The
4287 * end result is that we revalidate just the facets that need it (and sometimes
4288 * a few more, but not all of the facets or even all of the facets that
4289 * resubmit to the table modified by MAC learning). */
4291 /* Calculates the tag to use for 'flow' and wildcards 'wc' when it is inserted
4292 * into an OpenFlow table with the given 'basis'. */
4294 rule_calculate_tag(const struct flow *flow, const struct flow_wildcards *wc,
4297 if (flow_wildcards_is_catchall(wc)) {
4300 struct flow tag_flow = *flow;
4301 flow_zero_wildcards(&tag_flow, wc);
4302 return tag_create_deterministic(flow_hash(&tag_flow, secret));
4306 /* Following a change to OpenFlow table 'table_id' in 'ofproto', update the
4307 * taggability of that table.
4309 * This function must be called after *each* change to a flow table. If you
4310 * skip calling it on some changes then the pointer comparisons at the end can
4311 * be invalid if you get unlucky. For example, if a flow removal causes a
4312 * cls_table to be destroyed and then a flow insertion causes a cls_table with
4313 * different wildcards to be created with the same address, then this function
4314 * will incorrectly skip revalidation. */
4316 table_update_taggable(struct ofproto_dpif *ofproto, uint8_t table_id)
4318 struct table_dpif *table = &ofproto->tables[table_id];
4319 const struct classifier *cls = &ofproto->up.tables[table_id];
4320 struct cls_table *catchall, *other;
4321 struct cls_table *t;
4323 catchall = other = NULL;
4325 switch (hmap_count(&cls->tables)) {
4327 /* We could tag this OpenFlow table but it would make the logic a
4328 * little harder and it's a corner case that doesn't seem worth it
4334 HMAP_FOR_EACH (t, hmap_node, &cls->tables) {
4335 if (cls_table_is_catchall(t)) {
4337 } else if (!other) {
4340 /* Indicate that we can't tag this by setting both tables to
4341 * NULL. (We know that 'catchall' is already NULL.) */
4348 /* Can't tag this table. */
4352 if (table->catchall_table != catchall || table->other_table != other) {
4353 table->catchall_table = catchall;
4354 table->other_table = other;
4355 ofproto->need_revalidate = true;
4359 /* Given 'rule' that has changed in some way (either it is a rule being
4360 * inserted, a rule being deleted, or a rule whose actions are being
4361 * modified), marks facets for revalidation to ensure that packets will be
4362 * forwarded correctly according to the new state of the flow table.
4364 * This function must be called after *each* change to a flow table. See
4365 * the comment on table_update_taggable() for more information. */
4367 rule_invalidate(const struct rule_dpif *rule)
4369 struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
4371 table_update_taggable(ofproto, rule->up.table_id);
4373 if (!ofproto->need_revalidate) {
4374 struct table_dpif *table = &ofproto->tables[rule->up.table_id];
4376 if (table->other_table && rule->tag) {
4377 tag_set_add(&ofproto->revalidate_set, rule->tag);
4379 ofproto->need_revalidate = true;
4385 get_drop_frags(struct ofproto *ofproto_)
4387 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
4390 dpif_get_drop_frags(ofproto->dpif, &drop_frags);
4395 set_drop_frags(struct ofproto *ofproto_, bool drop_frags)
4397 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
4399 dpif_set_drop_frags(ofproto->dpif, drop_frags);
4403 packet_out(struct ofproto *ofproto_, struct ofpbuf *packet,
4404 const struct flow *flow,
4405 const union ofp_action *ofp_actions, size_t n_ofp_actions)
4407 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
4410 error = validate_actions(ofp_actions, n_ofp_actions, flow,
4411 ofproto->max_ports);
4413 struct odputil_keybuf keybuf;
4414 struct action_xlate_ctx ctx;
4415 struct ofpbuf *odp_actions;
4418 ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
4419 odp_flow_key_from_flow(&key, flow);
4421 action_xlate_ctx_init(&ctx, ofproto, flow, packet);
4422 odp_actions = xlate_actions(&ctx, ofp_actions, n_ofp_actions);
4423 dpif_execute(ofproto->dpif, key.data, key.size,
4424 odp_actions->data, odp_actions->size, packet);
4425 ofpbuf_delete(odp_actions);
4431 get_netflow_ids(const struct ofproto *ofproto_,
4432 uint8_t *engine_type, uint8_t *engine_id)
4434 struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
4436 dpif_get_netflow_ids(ofproto->dpif, engine_type, engine_id);
4439 static struct ofproto_dpif *
4440 ofproto_dpif_lookup(const char *name)
4442 struct ofproto *ofproto = ofproto_lookup(name);
4443 return (ofproto && ofproto->ofproto_class == &ofproto_dpif_class
4444 ? ofproto_dpif_cast(ofproto)
4449 ofproto_unixctl_fdb_show(struct unixctl_conn *conn,
4450 const char *args, void *aux OVS_UNUSED)
4452 struct ds ds = DS_EMPTY_INITIALIZER;
4453 const struct ofproto_dpif *ofproto;
4454 const struct mac_entry *e;
4456 ofproto = ofproto_dpif_lookup(args);
4458 unixctl_command_reply(conn, 501, "no such bridge");
4462 ds_put_cstr(&ds, " port VLAN MAC Age\n");
4463 LIST_FOR_EACH (e, lru_node, &ofproto->ml->lrus) {
4464 struct ofbundle *bundle = e->port.p;
4465 ds_put_format(&ds, "%5d %4d "ETH_ADDR_FMT" %3d\n",
4466 ofbundle_get_a_port(bundle)->odp_port,
4467 e->vlan, ETH_ADDR_ARGS(e->mac), mac_entry_age(e));
4469 unixctl_command_reply(conn, 200, ds_cstr(&ds));
4473 struct ofproto_trace {
4474 struct action_xlate_ctx ctx;
4480 trace_format_rule(struct ds *result, uint8_t table_id, int level,
4481 const struct rule_dpif *rule)
4483 ds_put_char_multiple(result, '\t', level);
4485 ds_put_cstr(result, "No match\n");
4489 ds_put_format(result, "Rule: table=%"PRIu8" cookie=%#"PRIx64" ",
4490 table_id, ntohll(rule->up.flow_cookie));
4491 cls_rule_format(&rule->up.cr, result);
4492 ds_put_char(result, '\n');
4494 ds_put_char_multiple(result, '\t', level);
4495 ds_put_cstr(result, "OpenFlow ");
4496 ofp_print_actions(result, rule->up.actions, rule->up.n_actions);
4497 ds_put_char(result, '\n');
4501 trace_format_flow(struct ds *result, int level, const char *title,
4502 struct ofproto_trace *trace)
4504 ds_put_char_multiple(result, '\t', level);
4505 ds_put_format(result, "%s: ", title);
4506 if (flow_equal(&trace->ctx.flow, &trace->flow)) {
4507 ds_put_cstr(result, "unchanged");
4509 flow_format(result, &trace->ctx.flow);
4510 trace->flow = trace->ctx.flow;
4512 ds_put_char(result, '\n');
4516 trace_format_regs(struct ds *result, int level, const char *title,
4517 struct ofproto_trace *trace)
4521 ds_put_char_multiple(result, '\t', level);
4522 ds_put_format(result, "%s:", title);
4523 for (i = 0; i < FLOW_N_REGS; i++) {
4524 ds_put_format(result, " reg%zu=0x%"PRIx32, i, trace->flow.regs[i]);
4526 ds_put_char(result, '\n');
4530 trace_resubmit(struct action_xlate_ctx *ctx, struct rule_dpif *rule)
4532 struct ofproto_trace *trace = CONTAINER_OF(ctx, struct ofproto_trace, ctx);
4533 struct ds *result = trace->result;
4535 ds_put_char(result, '\n');
4536 trace_format_flow(result, ctx->recurse + 1, "Resubmitted flow", trace);
4537 trace_format_regs(result, ctx->recurse + 1, "Resubmitted regs", trace);
4538 trace_format_rule(result, ctx->table_id, ctx->recurse + 1, rule);
4542 ofproto_unixctl_trace(struct unixctl_conn *conn, const char *args_,
4543 void *aux OVS_UNUSED)
4545 char *dpname, *arg1, *arg2, *arg3;
4546 char *args = xstrdup(args_);
4547 char *save_ptr = NULL;
4548 struct ofproto_dpif *ofproto;
4549 struct ofpbuf odp_key;
4550 struct ofpbuf *packet;
4551 struct rule_dpif *rule;
4557 ofpbuf_init(&odp_key, 0);
4560 dpname = strtok_r(args, " ", &save_ptr);
4561 arg1 = strtok_r(NULL, " ", &save_ptr);
4562 arg2 = strtok_r(NULL, " ", &save_ptr);
4563 arg3 = strtok_r(NULL, "", &save_ptr); /* Get entire rest of line. */
4564 if (dpname && arg1 && (!arg2 || !strcmp(arg2, "-generate")) && !arg3) {
4565 /* ofproto/trace dpname flow [-generate] */
4568 /* Convert string to datapath key. */
4569 ofpbuf_init(&odp_key, 0);
4570 error = odp_flow_key_from_string(arg1, &odp_key);
4572 unixctl_command_reply(conn, 501, "Bad flow syntax");
4576 /* Convert odp_key to flow. */
4577 error = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
4579 unixctl_command_reply(conn, 501, "Invalid flow");
4583 /* Generate a packet, if requested. */
4585 packet = ofpbuf_new(0);
4586 flow_compose(packet, &flow);
4588 } else if (dpname && arg1 && arg2 && arg3) {
4589 /* ofproto/trace dpname tun_id in_port packet */
4593 tun_id = htonll(strtoull(arg1, NULL, 0));
4594 in_port = ofp_port_to_odp_port(atoi(arg2));
4596 packet = ofpbuf_new(strlen(args) / 2);
4597 arg3 = ofpbuf_put_hex(packet, arg3, NULL);
4598 arg3 += strspn(arg3, " ");
4599 if (*arg3 != '\0') {
4600 unixctl_command_reply(conn, 501, "Trailing garbage in command");
4603 if (packet->size < ETH_HEADER_LEN) {
4604 unixctl_command_reply(conn, 501,
4605 "Packet data too short for Ethernet");
4609 ds_put_cstr(&result, "Packet: ");
4610 s = ofp_packet_to_string(packet->data, packet->size, packet->size);
4611 ds_put_cstr(&result, s);
4614 flow_extract(packet, tun_id, in_port, &flow);
4616 unixctl_command_reply(conn, 501, "Bad command syntax");
4620 ofproto = ofproto_dpif_lookup(dpname);
4622 unixctl_command_reply(conn, 501, "Unknown ofproto (use ofproto/list "
4627 ds_put_cstr(&result, "Flow: ");
4628 flow_format(&result, &flow);
4629 ds_put_char(&result, '\n');
4631 rule = rule_dpif_lookup(ofproto, &flow, 0);
4632 trace_format_rule(&result, 0, 0, rule);
4634 struct ofproto_trace trace;
4635 struct ofpbuf *odp_actions;
4637 trace.result = &result;
4639 action_xlate_ctx_init(&trace.ctx, ofproto, &flow, packet);
4640 trace.ctx.resubmit_hook = trace_resubmit;
4641 odp_actions = xlate_actions(&trace.ctx,
4642 rule->up.actions, rule->up.n_actions);
4644 ds_put_char(&result, '\n');
4645 trace_format_flow(&result, 0, "Final flow", &trace);
4646 ds_put_cstr(&result, "Datapath actions: ");
4647 format_odp_actions(&result, odp_actions->data, odp_actions->size);
4648 ofpbuf_delete(odp_actions);
4650 if (!trace.ctx.may_set_up_flow) {
4652 ds_put_cstr(&result, "\nThis flow is not cachable.");
4654 ds_put_cstr(&result, "\nThe datapath actions are incomplete--"
4655 "for complete actions, please supply a packet.");
4660 unixctl_command_reply(conn, 200, ds_cstr(&result));
4663 ds_destroy(&result);
4664 ofpbuf_delete(packet);
4665 ofpbuf_uninit(&odp_key);
4670 ofproto_dpif_clog(struct unixctl_conn *conn OVS_UNUSED,
4671 const char *args_ OVS_UNUSED, void *aux OVS_UNUSED)
4674 unixctl_command_reply(conn, 200, NULL);
4678 ofproto_dpif_unclog(struct unixctl_conn *conn OVS_UNUSED,
4679 const char *args_ OVS_UNUSED, void *aux OVS_UNUSED)
4682 unixctl_command_reply(conn, 200, NULL);
4686 ofproto_dpif_unixctl_init(void)
4688 static bool registered;
4694 unixctl_command_register("ofproto/trace",
4695 "bridge {tun_id in_port packet | odp_flow [-generate]}",
4696 ofproto_unixctl_trace, NULL);
4697 unixctl_command_register("fdb/show", "bridge", ofproto_unixctl_fdb_show,
4699 unixctl_command_register("ofproto/clog", "", ofproto_dpif_clog, NULL);
4700 unixctl_command_register("ofproto/unclog", "", ofproto_dpif_unclog, NULL);
4703 const struct ofproto_class ofproto_dpif_class = {
4730 port_is_lacp_current,
4731 NULL, /* rule_choose_table */
4738 rule_modify_actions,
4747 get_cfm_remote_mpids,
4752 is_mirror_output_bundle,
4753 forward_bpdu_changed,