2 * Copyright (c) 2010 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 "wdp-xflow.h"
26 #include "mac-learning.h"
32 #include "openflow/nicira-ext.h"
33 #include "openflow/openflow.h"
35 #include "poll-loop.h"
36 #include "port-array.h"
43 #include "wdp-provider.h"
45 #include "xflow-util.h"
49 VLOG_DEFINE_THIS_MODULE(wdp_xflow)
53 TABLEID_CLASSIFIER = 1
56 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
58 /* Maximum numbers of rules. */
59 #define WX_MAX_WILD 65536 /* Wildcarded rules. */
60 #define WX_MAX_EXACT 1048576 /* Exact-match rules. */
63 struct list list_node;
66 struct classifier cls;
67 struct netdev_monitor *netdev_monitor;
68 struct port_array ports; /* Index is xflow port nr;
69 * wdp_port->opp.port_no is OFP port nr. */
70 struct shash port_by_name;
71 long long int next_expiration;
73 /* Rules that might need to be revalidated. */
74 bool need_revalidate; /* Revalidate all subrules? */
75 bool revalidate_all; /* Revalidate all subrules and other rules? */
76 struct tag_set revalidate_set; /* Tag set of (sub)rules to revalidate. */
78 /* Hooks for ovs-vswitchd. */
79 const struct ofhooks *ofhooks;
82 /* Used by default ofhooks. */
83 struct mac_learning *ml;
86 static const struct ofhooks default_ofhooks;
88 static struct list all_wx = LIST_INITIALIZER(&all_wx);
90 static int wx_port_init(struct wx *);
91 static void wx_port_process_change(struct wx *wx, int error, char *devname,
92 wdp_port_poll_cb_func *cb, void *aux);
93 static void wx_port_refresh_groups(struct wx *);
101 wx_cast(const struct wdp *wdp)
103 return CONTAINER_OF(wdp, struct wx, wdp);
107 wx_xlate_actions(struct wx *, const union ofp_action *, size_t n,
108 const flow_t *flow, const struct ofpbuf *packet,
109 tag_type *tags, struct xflow_actions *out,
110 bool *may_set_up_flow);
115 uint64_t packet_count; /* Number of packets received. */
116 uint64_t byte_count; /* Number of bytes received. */
117 uint64_t accounted_bytes; /* Number of bytes passed to account_cb. */
118 long long int used; /* Last-used time (0 if never used). */
119 tag_type tags; /* Tags (set only by hooks). */
121 /* If 'super' is non-NULL, this rule is a subrule, that is, it is an
122 * exact-match rule (having cr.wc.wildcards of 0) generated from the
123 * wildcard rule 'super'. In this case, 'list' is an element of the
126 * If 'super' is NULL, this rule is a super-rule, and 'list' is the head of
127 * a list of subrules. A super-rule with no wildcards (where
128 * cr.wc.wildcards is 0) will never have any subrules. */
129 struct wx_rule *super;
134 * A super-rule with wildcard fields never has xflow actions (since the
135 * datapath only supports exact-match flows). */
136 bool installed; /* Installed in datapath? */
137 bool may_install; /* True ordinarily; false if actions must
138 * be reassessed for every packet. */
140 union xflow_action *xflow_actions;
143 static void wx_rule_destroy(struct wx *, struct wx_rule *);
144 static void wx_rule_update_actions(struct wx *, struct wx_rule *);
145 static void wx_rule_execute(struct wx *, struct wx_rule *,
146 struct ofpbuf *packet, const flow_t *);
147 static bool wx_rule_make_actions(struct wx *, struct wx_rule *,
148 const struct ofpbuf *packet);
149 static void wx_rule_install(struct wx *, struct wx_rule *,
150 struct wx_rule *displaced_rule);
152 static struct wx_rule *
153 wx_rule_cast(const struct cls_rule *cls_rule)
155 return cls_rule ? CONTAINER_OF(cls_rule, struct wx_rule, wr.cr) : NULL;
158 /* Returns true if 'rule' is merely an implementation detail that should be
159 * hidden from the client. */
161 wx_rule_is_hidden(const struct wx_rule *rule)
163 return rule->super != NULL;
167 wx_rule_free(struct wx_rule *rule)
169 wdp_rule_uninit(&rule->wr);
170 free(rule->xflow_actions);
175 wx_rule_account(struct wx *wx OVS_UNUSED, struct wx_rule *rule OVS_UNUSED,
176 uint64_t extra_bytes OVS_UNUSED)
178 /* XXX call account_cb hook */
182 wx_rule_post_uninstall(struct wx *wx, struct wx_rule *rule)
184 struct wx_rule *super = rule->super;
186 wx_rule_account(wx, rule, 0);
188 /* XXX netflow expiration */
191 super->packet_count += rule->packet_count;
192 super->byte_count += rule->byte_count;
194 /* Reset counters to prevent double counting if the rule ever gets
196 rule->packet_count = 0;
197 rule->byte_count = 0;
198 rule->accounted_bytes = 0;
200 //XXX netflow_flow_clear(&rule->nf_flow);
205 xflow_flow_stats_to_msec(const struct xflow_flow_stats *stats)
207 return (stats->used_sec
208 ? stats->used_sec * 1000 + stats->used_nsec / 1000000
213 wx_rule_update_time(struct wx *wx OVS_UNUSED, struct wx_rule *rule,
214 const struct xflow_flow_stats *stats)
216 long long int used = xflow_flow_stats_to_msec(stats);
217 if (used > rule->used) {
219 if (rule->super && used > rule->super->used) {
220 rule->super->used = used;
222 //XXX netflow_flow_update_time(ofproto->netflow, &rule->nf_flow, used);
227 wx_rule_update_stats(struct wx *wx, struct wx_rule *rule,
228 const struct xflow_flow_stats *stats)
230 if (stats->n_packets) {
231 wx_rule_update_time(wx, rule, stats);
232 rule->packet_count += stats->n_packets;
233 rule->byte_count += stats->n_bytes;
234 /* XXX netflow_flow_update_flags(&rule->nf_flow, stats->ip_tos,
235 stats->tcp_flags); */
240 wx_rule_uninstall(struct wx *wx, struct wx_rule *rule)
242 assert(!rule->wr.cr.flow.wildcards);
243 if (rule->installed) {
244 struct xflow_flow xflow_flow;
246 xflow_key_from_flow(&xflow_flow.key, &rule->wr.cr.flow);
247 xflow_flow.actions = NULL;
248 xflow_flow.n_actions = 0;
249 xflow_flow.flags = 0;
250 if (!xfif_flow_del(wx->xfif, &xflow_flow)) {
251 wx_rule_update_stats(wx, rule, &xflow_flow.stats);
253 rule->installed = false;
255 wx_rule_post_uninstall(wx, rule);
261 is_controller_rule(struct wx_rule *rule)
263 /* If the only action is send to the controller then don't report
264 * NetFlow expiration messages since it is just part of the control
265 * logic for the network and not real traffic. */
269 && rule->super->n_actions == 1
270 && action_outputs_to_port(&rule->super->actions[0],
271 htons(OFPP_CONTROLLER)));
276 wx_rule_remove(struct wx *wx, struct wx_rule *rule)
278 if (rule->wr.cr.flow.wildcards) {
279 COVERAGE_INC(wx_del_wc_flow);
280 wx->need_revalidate = true;
282 wx_rule_uninstall(wx, rule);
284 classifier_remove(&wx->cls, &rule->wr.cr);
285 wx_rule_destroy(wx, rule);
289 wx_rule_revalidate(struct wx *wx, struct wx_rule *rule)
291 const flow_t *flow = &rule->wr.cr.flow;
293 COVERAGE_INC(wx_rule_revalidate);
295 struct wx_rule *super;
296 super = wx_rule_cast(classifier_lookup_wild(&wx->cls, flow));
298 wx_rule_remove(wx, rule);
300 } else if (super != rule->super) {
301 COVERAGE_INC(wx_revalidate_moved);
302 list_remove(&rule->list);
303 list_push_back(&super->list, &rule->list);
305 rule->wr.hard_timeout = super->wr.hard_timeout;
306 rule->wr.idle_timeout = super->wr.idle_timeout;
307 rule->wr.created = super->wr.created;
312 wx_rule_update_actions(wx, rule);
316 /* Destroys 'rule'. If 'rule' is a subrule, also removes it from its
317 * super-rule's list of subrules. If 'rule' is a super-rule, also iterates
318 * through all of its subrules and revalidates them, destroying any that no
319 * longer has a super-rule (which is probably all of them).
321 * Before calling this function, the caller must make have removed 'rule' from
322 * the classifier. If 'rule' is an exact-match rule, the caller is also
323 * responsible for ensuring that it has been uninstalled from the datapath. */
325 wx_rule_destroy(struct wx *wx, struct wx_rule *rule)
328 struct wx_rule *subrule, *next;
329 LIST_FOR_EACH_SAFE (subrule, next, struct wx_rule, list, &rule->list) {
330 wx_rule_revalidate(wx, subrule);
333 list_remove(&rule->list);
340 wx_rule_has_out_port(const struct wx_rule *rule, uint16_t out_port)
342 const union ofp_action *oa;
343 struct actions_iterator i;
345 if (out_port == htons(OFPP_NONE)) {
348 for (oa = actions_first(&i, rule->wr.actions,
351 oa = actions_next(&i)) {
352 if (oa->type == htons(OFPAT_OUTPUT) && oa->output.port == out_port) {
360 /* Caller is responsible for initializing the 'cr' and ofp_table_id members of
361 * the returned rule. */
362 static struct wx_rule *
363 wx_rule_create(struct wx_rule *super,
364 const union ofp_action *actions, size_t n_actions,
365 uint16_t idle_timeout, uint16_t hard_timeout)
367 struct wx_rule *rule = xzalloc(sizeof *rule);
368 wdp_rule_init(&rule->wr, actions, n_actions);
369 rule->wr.idle_timeout = idle_timeout;
370 rule->wr.hard_timeout = hard_timeout;
371 rule->used = rule->wr.created;
374 list_push_back(&super->list, &rule->list);
376 list_init(&rule->list);
379 netflow_flow_clear(&rule->nf_flow);
380 netflow_flow_update_time(ofproto->netflow, &rule->nf_flow, rule->created);
386 /* Executes the actions indicated by 'rule' on 'packet', which is in flow
387 * 'flow' and is considered to have arrived on xflow port 'in_port'.
389 * The flow that 'packet' actually contains does not need to actually match
390 * 'rule'; the actions in 'rule' will be applied to it either way. Likewise,
391 * the packet and byte counters for 'rule' will be credited for the packet sent
392 * out whether or not the packet actually matches 'rule'.
394 * If 'rule' is an exact-match rule and 'flow' actually equals the rule's flow,
395 * the caller must already have accurately composed xflow actions for it given
396 * 'packet' using rule_make_actions(). If 'rule' is a wildcard rule, or if
397 * 'rule' is an exact-match rule but 'flow' is not the rule's flow, then this
398 * function will compose a set of xflow actions based on 'rule''s OpenFlow
399 * actions and apply them to 'packet'. */
401 wx_rule_execute(struct wx *wx, struct wx_rule *rule,
402 struct ofpbuf *packet, const flow_t *flow)
404 const union xflow_action *actions;
406 struct xflow_actions a;
408 /* Grab or compose the xflow actions.
410 * The special case for an exact-match 'rule' where 'flow' is not the
411 * rule's flow is important to avoid, e.g., sending a packet out its input
412 * port simply because the xflow actions were composed for the wrong
414 if (rule->wr.cr.flow.wildcards
415 || !flow_equal_headers(flow, &rule->wr.cr.flow))
417 struct wx_rule *super = rule->super ? rule->super : rule;
418 if (wx_xlate_actions(wx, super->wr.actions, super->wr.n_actions, flow,
419 packet, NULL, &a, NULL)) {
423 n_actions = a.n_actions;
425 actions = rule->xflow_actions;
426 n_actions = rule->n_xflow_actions;
429 /* Execute the xflow actions. */
430 if (!xfif_execute(wx->xfif, flow->in_port,
431 actions, n_actions, packet)) {
432 struct xflow_flow_stats stats;
433 flow_extract_stats(flow, packet, &stats);
434 wx_rule_update_stats(wx, rule, &stats);
435 rule->used = time_msec();
436 //XXX netflow_flow_update_time(wx->netflow, &rule->nf_flow, rule->used);
441 wx_rule_insert(struct wx *wx, struct wx_rule *rule, struct ofpbuf *packet,
444 struct wx_rule *displaced_rule;
446 /* Insert the rule in the classifier. */
447 displaced_rule = wx_rule_cast(classifier_insert(&wx->cls, &rule->wr.cr));
448 if (!rule->wr.cr.flow.wildcards) {
449 wx_rule_make_actions(wx, rule, packet);
452 /* Send the packet and credit it to the rule. */
455 flow_extract(packet, 0, in_port, &flow);
456 wx_rule_execute(wx, rule, packet, &flow);
459 /* Install the rule in the datapath only after sending the packet, to
460 * avoid packet reordering. */
461 if (rule->wr.cr.flow.wildcards) {
462 COVERAGE_INC(wx_add_wc_flow);
463 wx->need_revalidate = true;
465 wx_rule_install(wx, rule, displaced_rule);
468 /* Free the rule that was displaced, if any. */
469 if (displaced_rule) {
470 rule->wr.client_data = displaced_rule->wr.client_data;
471 wx_rule_destroy(wx, displaced_rule);
475 static struct wx_rule *
476 wx_rule_create_subrule(struct wx *wx, struct wx_rule *rule, const flow_t *flow)
478 struct wx_rule *subrule;
480 subrule = wx_rule_create(rule, NULL, 0,
481 rule->wr.idle_timeout,
482 rule->wr.hard_timeout);
483 /* Subrules aren't really in any OpenFlow table, so don't bother with
484 * subrule->wr.ofp_table_id. */
485 COVERAGE_INC(wx_subrule_create);
486 cls_rule_from_flow(flow, &subrule->wr.cr);
487 classifier_insert_exact(&wx->cls, &subrule->wr.cr);
492 /* Returns true if the actions changed, false otherwise. */
494 wx_rule_make_actions(struct wx *wx, struct wx_rule *rule,
495 const struct ofpbuf *packet)
497 const struct wx_rule *super;
498 struct xflow_actions a;
501 assert(!rule->wr.cr.flow.wildcards);
503 super = rule->super ? rule->super : rule;
504 wx_xlate_actions(wx, super->wr.actions, super->wr.n_actions,
505 &rule->wr.cr.flow, packet,
506 &rule->tags, &a, &rule->may_install);
508 actions_len = a.n_actions * sizeof *a.actions;
509 if (rule->n_xflow_actions != a.n_actions
510 || memcmp(rule->xflow_actions, a.actions, actions_len)) {
511 COVERAGE_INC(wx_xflow_unchanged);
512 free(rule->xflow_actions);
513 rule->n_xflow_actions = a.n_actions;
514 rule->xflow_actions = xmemdup(a.actions, actions_len);
522 do_put_flow(struct wx *wx, struct wx_rule *rule, int flags,
523 struct xflow_flow_put *put)
525 memset(&put->flow.stats, 0, sizeof put->flow.stats);
526 xflow_key_from_flow(&put->flow.key, &rule->wr.cr.flow);
527 put->flow.actions = rule->xflow_actions;
528 put->flow.n_actions = rule->n_xflow_actions;
531 return xfif_flow_put(wx->xfif, put);
535 wx_rule_install(struct wx *wx, struct wx_rule *rule, struct wx_rule *displaced_rule)
537 assert(!rule->wr.cr.flow.wildcards);
539 if (rule->may_install) {
540 struct xflow_flow_put put;
541 if (!do_put_flow(wx, rule,
542 XFLOWPF_CREATE | XFLOWPF_MODIFY | XFLOWPF_ZERO_STATS,
544 rule->installed = true;
545 if (displaced_rule) {
546 wx_rule_update_stats(wx, displaced_rule, &put.flow.stats);
547 wx_rule_post_uninstall(wx, displaced_rule);
550 } else if (displaced_rule) {
551 wx_rule_uninstall(wx, displaced_rule);
556 wx_rule_reinstall(struct wx *wx, struct wx_rule *rule)
558 if (rule->installed) {
559 struct xflow_flow_put put;
560 COVERAGE_INC(wx_dp_missed);
561 do_put_flow(wx, rule, XFLOWPF_CREATE | XFLOWPF_MODIFY, &put);
563 wx_rule_install(wx, rule, NULL);
568 wx_rule_update_actions(struct wx *wx, struct wx_rule *rule)
570 bool actions_changed;
572 uint16_t new_out_iface, old_out_iface;
574 old_out_iface = rule->nf_flow.output_iface;
576 actions_changed = wx_rule_make_actions(wx, rule, NULL);
578 if (rule->may_install) {
579 if (rule->installed) {
580 if (actions_changed) {
581 struct xflow_flow_put put;
582 do_put_flow(wx, rule, XFLOWPF_CREATE | XFLOWPF_MODIFY
583 | XFLOWPF_ZERO_STATS, &put);
584 wx_rule_update_stats(wx, rule, &put.flow.stats);
586 /* Temporarily set the old output iface so that NetFlow
587 * messages have the correct output interface for the old
589 new_out_iface = rule->nf_flow.output_iface;
590 rule->nf_flow.output_iface = old_out_iface;
592 wx_rule_post_uninstall(wx, rule);
593 //rule->nf_flow.output_iface = new_out_iface;
596 wx_rule_install(wx, rule, NULL);
599 wx_rule_uninstall(wx, rule);
604 add_output_group_action(struct xflow_actions *actions, uint16_t group,
605 uint16_t *nf_output_iface)
607 xflow_actions_add(actions, XFLOWAT_OUTPUT_GROUP)->output_group.group = group;
609 if (group == WX_GROUP_ALL || group == WX_GROUP_FLOOD) {
610 *nf_output_iface = NF_OUT_FLOOD;
615 add_controller_action(struct xflow_actions *actions, uint16_t max_len)
617 union xflow_action *a = xflow_actions_add(actions, XFLOWAT_CONTROLLER);
618 a->controller.arg = max_len;
621 struct wx_xlate_ctx {
623 flow_t flow; /* Flow to which these actions correspond. */
624 int recurse; /* Recursion level, via xlate_table_action. */
626 const struct ofpbuf *packet; /* The packet corresponding to 'flow', or a
627 * null pointer if we are revalidating
628 * without a packet to refer to. */
631 struct xflow_actions *out; /* Datapath actions. */
632 tag_type *tags; /* Tags associated with OFPP_NORMAL actions. */
633 bool may_set_up_flow; /* True ordinarily; false if the actions must
634 * be reassessed for every packet. */
635 uint16_t nf_output_iface; /* Output interface index for NetFlow. */
638 static void do_xlate_actions(const union ofp_action *in, size_t n_in,
639 struct wx_xlate_ctx *ctx);
642 add_output_action(struct wx_xlate_ctx *ctx, uint16_t port)
644 const struct wdp_port *wdp_port = port_array_get(&ctx->wx->ports, port);
647 if (wdp_port->opp.config & OFPPC_NO_FWD) {
648 /* Forwarding disabled on port. */
653 * We don't have an ofport record for this port, but it doesn't hurt to
654 * allow forwarding to it anyhow. Maybe such a port will appear later
655 * and we're pre-populating the flow table.
659 xflow_actions_add(ctx->out, XFLOWAT_OUTPUT)->output.port = port;
660 //ctx->nf_output_iface = port;
663 static struct wx_rule *
664 wx_rule_lookup_valid(struct wx *wx, const flow_t *flow)
666 struct wx_rule *rule = wx_rule_cast(classifier_lookup(&wx->cls, flow));
668 /* The rule we found might not be valid, since we could be in need of
669 * revalidation. If it is not valid, don't return it. */
672 && wx->need_revalidate
673 && !wx_rule_revalidate(wx, rule)) {
674 COVERAGE_INC(wx_invalidated);
682 xlate_table_action(struct wx_xlate_ctx *ctx, uint16_t in_port)
685 uint16_t old_in_port;
686 struct wx_rule *rule;
688 /* Look up a flow with 'in_port' as the input port. Then restore the
689 * original input port (otherwise OFPP_NORMAL and OFPP_IN_PORT will
690 * have surprising behavior). */
691 old_in_port = ctx->flow.in_port;
692 ctx->flow.in_port = in_port;
693 rule = wx_rule_lookup_valid(ctx->wx, &ctx->flow);
694 ctx->flow.in_port = old_in_port;
702 do_xlate_actions(rule->wr.actions, rule->wr.n_actions, ctx);
709 xlate_output_action__(struct wx_xlate_ctx *ctx,
710 uint16_t port, uint16_t max_len)
713 uint16_t prev_nf_output_iface = ctx->nf_output_iface;
715 ctx->nf_output_iface = NF_OUT_DROP;
719 add_output_action(ctx, ctx->flow.in_port);
722 xlate_table_action(ctx, ctx->flow.in_port);
725 if (!ctx->wx->ofhooks->normal_cb(&ctx->flow, ctx->packet,
727 &ctx->nf_output_iface,
729 COVERAGE_INC(wx_uninstallable);
730 ctx->may_set_up_flow = false;
735 add_output_group_action(ctx->out, WX_GROUP_FLOOD,
736 &ctx->nf_output_iface);
739 add_output_group_action(ctx->out, WX_GROUP_ALL, &ctx->nf_output_iface);
741 case OFPP_CONTROLLER:
742 add_controller_action(ctx->out, max_len);
745 add_output_action(ctx, XFLOWP_LOCAL);
748 xflow_port = ofp_port_to_xflow_port(port);
749 if (xflow_port != ctx->flow.in_port) {
750 add_output_action(ctx, xflow_port);
755 if (prev_nf_output_iface == NF_OUT_FLOOD) {
756 ctx->nf_output_iface = NF_OUT_FLOOD;
757 } else if (ctx->nf_output_iface == NF_OUT_DROP) {
758 ctx->nf_output_iface = prev_nf_output_iface;
759 } else if (prev_nf_output_iface != NF_OUT_DROP &&
760 ctx->nf_output_iface != NF_OUT_FLOOD) {
761 ctx->nf_output_iface = NF_OUT_MULTI;
766 xlate_output_action(struct wx_xlate_ctx *ctx,
767 const struct ofp_action_output *oao)
769 xlate_output_action__(ctx, ntohs(oao->port), ntohs(oao->max_len));
772 /* If the final xflow action in 'ctx' is "pop priority", drop it, as an
773 * optimization, because we're going to add another action that sets the
774 * priority immediately after, or because there are no actions following the
777 remove_pop_action(struct wx_xlate_ctx *ctx)
779 size_t n = ctx->out->n_actions;
780 if (n > 0 && ctx->out->actions[n - 1].type == XFLOWAT_POP_PRIORITY) {
781 ctx->out->n_actions--;
786 xlate_enqueue_action(struct wx_xlate_ctx *ctx,
787 const struct ofp_action_enqueue *oae)
789 uint16_t ofp_port, xflow_port;
793 error = xfif_queue_to_priority(ctx->wx->xfif, ntohl(oae->queue_id),
796 /* Fall back to ordinary output action. */
797 xlate_output_action__(ctx, ntohs(oae->port), 0);
801 /* Figure out xflow output port. */
802 ofp_port = ntohs(oae->port);
803 if (ofp_port != OFPP_IN_PORT) {
804 xflow_port = ofp_port_to_xflow_port(ofp_port);
806 xflow_port = ctx->flow.in_port;
809 /* Add xflow actions. */
810 remove_pop_action(ctx);
811 xflow_actions_add(ctx->out, XFLOWAT_SET_PRIORITY)->priority.priority
813 add_output_action(ctx, xflow_port);
814 xflow_actions_add(ctx->out, XFLOWAT_POP_PRIORITY);
816 /* Update NetFlow output port. */
817 if (ctx->nf_output_iface == NF_OUT_DROP) {
818 ctx->nf_output_iface = xflow_port;
819 } else if (ctx->nf_output_iface != NF_OUT_FLOOD) {
820 ctx->nf_output_iface = NF_OUT_MULTI;
825 xlate_nicira_action(struct wx_xlate_ctx *ctx,
826 const struct nx_action_header *nah)
828 const struct nx_action_resubmit *nar;
829 const struct nx_action_set_tunnel *nast;
830 union xflow_action *oa;
831 int subtype = ntohs(nah->subtype);
833 assert(nah->vendor == htonl(NX_VENDOR_ID));
836 nar = (const struct nx_action_resubmit *) nah;
837 xlate_table_action(ctx, ofp_port_to_xflow_port(ntohs(nar->in_port)));
840 case NXAST_SET_TUNNEL:
841 nast = (const struct nx_action_set_tunnel *) nah;
842 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_TUNNEL);
843 ctx->flow.tun_id = oa->tunnel.tun_id = nast->tun_id;
846 /* If you add a new action here that modifies flow data, don't forget to
847 * update the flow key in ctx->flow at the same time. */
850 VLOG_DBG_RL(&rl, "unknown Nicira action type %"PRIu16, subtype);
856 do_xlate_actions(const union ofp_action *in, size_t n_in,
857 struct wx_xlate_ctx *ctx)
859 struct actions_iterator iter;
860 const union ofp_action *ia;
861 const struct wdp_port *port;
863 port = port_array_get(&ctx->wx->ports, ctx->flow.in_port);
864 if (port && port->opp.config & (OFPPC_NO_RECV | OFPPC_NO_RECV_STP) &&
865 port->opp.config & (eth_addr_equals(ctx->flow.dl_dst, stp_eth_addr)
866 ? OFPPC_NO_RECV_STP : OFPPC_NO_RECV)) {
867 /* Drop this flow. */
871 for (ia = actions_first(&iter, in, n_in); ia; ia = actions_next(&iter)) {
872 uint16_t type = ntohs(ia->type);
873 union xflow_action *oa;
877 xlate_output_action(ctx, &ia->output);
880 case OFPAT_SET_VLAN_VID:
881 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_DL_TCI);
882 oa->dl_tci.tci = ia->vlan_vid.vlan_vid & htons(VLAN_VID_MASK);
883 oa->dl_tci.mask = htons(VLAN_VID_MASK);
884 ctx->flow.dl_vlan = ia->vlan_vid.vlan_vid;
887 case OFPAT_SET_VLAN_PCP:
888 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_DL_TCI);
889 oa->dl_tci.tci = htons((ia->vlan_pcp.vlan_pcp << VLAN_PCP_SHIFT)
891 oa->dl_tci.mask = htons(VLAN_PCP_MASK);
893 if (ctx->flow.dl_vlan == htons(OFP_VLAN_NONE)) {
894 ctx->flow.dl_vlan = htons(0);
896 ctx->flow.dl_vlan_pcp = ia->vlan_pcp.vlan_pcp;
899 case OFPAT_STRIP_VLAN:
900 xflow_actions_add(ctx->out, XFLOWAT_STRIP_VLAN);
901 ctx->flow.dl_vlan = htons(OFP_VLAN_NONE);
902 ctx->flow.dl_vlan_pcp = 0;
905 case OFPAT_SET_DL_SRC:
906 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_DL_SRC);
907 memcpy(oa->dl_addr.dl_addr,
908 ((struct ofp_action_dl_addr *) ia)->dl_addr, ETH_ADDR_LEN);
909 memcpy(ctx->flow.dl_src,
910 ((struct ofp_action_dl_addr *) ia)->dl_addr, ETH_ADDR_LEN);
913 case OFPAT_SET_DL_DST:
914 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_DL_DST);
915 memcpy(oa->dl_addr.dl_addr,
916 ((struct ofp_action_dl_addr *) ia)->dl_addr, ETH_ADDR_LEN);
917 memcpy(ctx->flow.dl_dst,
918 ((struct ofp_action_dl_addr *) ia)->dl_addr, ETH_ADDR_LEN);
921 case OFPAT_SET_NW_SRC:
922 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_NW_SRC);
923 ctx->flow.nw_src = oa->nw_addr.nw_addr = ia->nw_addr.nw_addr;
926 case OFPAT_SET_NW_DST:
927 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_NW_DST);
928 ctx->flow.nw_dst = oa->nw_addr.nw_addr = ia->nw_addr.nw_addr;
931 case OFPAT_SET_NW_TOS:
932 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_NW_TOS);
933 ctx->flow.nw_tos = oa->nw_tos.nw_tos = ia->nw_tos.nw_tos;
936 case OFPAT_SET_TP_SRC:
937 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_TP_SRC);
938 ctx->flow.tp_src = oa->tp_port.tp_port = ia->tp_port.tp_port;
941 case OFPAT_SET_TP_DST:
942 oa = xflow_actions_add(ctx->out, XFLOWAT_SET_TP_DST);
943 ctx->flow.tp_dst = oa->tp_port.tp_port = ia->tp_port.tp_port;
947 xlate_enqueue_action(ctx, (const struct ofp_action_enqueue *) ia);
951 xlate_nicira_action(ctx, (const struct nx_action_header *) ia);
955 VLOG_DBG_RL(&rl, "unknown action type %"PRIu16, type);
961 /* Returns true if 'flow' and 'actions' may be set up as a flow in the kernel.
962 * This is true most of the time, but we don't allow flows that would prevent
963 * DHCP replies from being seen by the local port to be set up in the
966 * We only need this, strictly speaking, when in-band control is turned on. */
968 wx_may_set_up(const flow_t *flow, const struct xflow_actions *actions)
970 if (flow->dl_type == htons(ETH_TYPE_IP)
971 && flow->nw_proto == IP_TYPE_UDP
972 && flow->tp_src == htons(DHCP_SERVER_PORT)
973 && flow->tp_dst == htons(DHCP_CLIENT_PORT)) {
976 for (i = 0; i < actions->n_actions; i++) {
977 const struct xflow_action_output *oao = &actions->actions[i].output;
978 if (oao->type == XFLOWAT_OUTPUT && oao->port == XFLOWP_LOCAL) {
989 wx_xlate_actions(struct wx *wx, const union ofp_action *in, size_t n_in,
990 const flow_t *flow, const struct ofpbuf *packet,
991 tag_type *tags, struct xflow_actions *out,
992 bool *may_set_up_flow)
994 tag_type no_tags = 0;
995 struct wx_xlate_ctx ctx;
996 COVERAGE_INC(wx_ofp2xflow);
997 xflow_actions_init(out);
1001 ctx.packet = packet;
1003 ctx.tags = tags ? tags : &no_tags;
1004 ctx.may_set_up_flow = true;
1005 ctx.nf_output_iface = NF_OUT_DROP;
1006 do_xlate_actions(in, n_in, &ctx);
1007 remove_pop_action(&ctx);
1009 if (may_set_up_flow) {
1010 *may_set_up_flow = ctx.may_set_up_flow && wx_may_set_up(flow, out);
1013 if (nf_output_iface) {
1014 *nf_output_iface = ctx.nf_output_iface;
1017 if (xflow_actions_overflow(out)) {
1018 xflow_actions_init(out);
1019 return ofp_mkerr(OFPET_BAD_ACTION, OFPBAC_TOO_MANY);
1025 update_used(struct wx *wx)
1027 struct xflow_flow *flows;
1032 error = xfif_flow_list_all(wx->xfif, &flows, &n_flows);
1037 for (i = 0; i < n_flows; i++) {
1038 struct xflow_flow *f = &flows[i];
1039 struct wx_rule *rule;
1042 xflow_key_to_flow(&f->key, &flow);
1043 rule = wx_rule_cast(classifier_find_rule_exactly(&wx->cls, &flow));
1044 if (!rule || !rule->installed) {
1045 COVERAGE_INC(wx_unexpected_rule);
1046 xfif_flow_del(wx->xfif, f);
1050 wx_rule_update_time(wx, rule, &f->stats);
1051 wx_rule_account(wx, rule, f->stats.n_bytes);
1057 uninstall_idle_flow(struct wx *wx, struct wx_rule *rule)
1059 assert(rule->installed);
1060 assert(!rule->wr.cr.flow.wildcards);
1063 wx_rule_remove(wx, rule);
1065 wx_rule_uninstall(wx, rule);
1070 expire_rule(struct cls_rule *cls_rule, void *wx_)
1072 struct wx *wx = wx_;
1073 struct wx_rule *rule = wx_rule_cast(cls_rule);
1074 long long int hard_expire, idle_expire, expire, now;
1076 hard_expire = (rule->wr.hard_timeout
1077 ? rule->wr.created + rule->wr.hard_timeout * 1000
1079 idle_expire = (rule->wr.idle_timeout
1080 && (rule->super || list_is_empty(&rule->list))
1081 ? rule->used + rule->wr.idle_timeout * 1000
1083 expire = MIN(hard_expire, idle_expire);
1087 if (rule->installed && now >= rule->used + 5000) {
1088 uninstall_idle_flow(wx, rule);
1089 } else if (!rule->wr.cr.flow.wildcards) {
1090 //XXX active_timeout(wx, rule);
1096 COVERAGE_INC(wx_expired);
1098 /* Update stats. This code will be a no-op if the rule expired
1099 * due to an idle timeout. */
1100 if (rule->wr.cr.flow.wildcards) {
1101 struct wx_rule *subrule, *next;
1102 LIST_FOR_EACH_SAFE (subrule, next, struct wx_rule, list, &rule->list) {
1103 wx_rule_remove(wx, subrule);
1106 wx_rule_uninstall(wx, rule);
1110 if (!wx_rule_is_hidden(rule)) {
1111 send_flow_removed(wx, rule, now,
1113 ? OFPRR_HARD_TIMEOUT : OFPRR_IDLE_TIMEOUT));
1116 wx_rule_remove(wx, rule);
1119 struct revalidate_cbdata {
1121 bool revalidate_all; /* Revalidate all exact-match rules? */
1122 bool revalidate_subrules; /* Revalidate all exact-match subrules? */
1123 struct tag_set revalidate_set; /* Set of tags to revalidate. */
1127 revalidate_rule(struct wx *wx, struct wx_rule *rule)
1129 const flow_t *flow = &rule->wr.cr.flow;
1131 COVERAGE_INC(wx_revalidate_rule);
1133 struct wx_rule *super;
1134 super = wx_rule_cast(classifier_lookup_wild(&wx->cls, flow));
1136 wx_rule_remove(wx, rule);
1138 } else if (super != rule->super) {
1139 COVERAGE_INC(wx_revalidate_moved);
1140 list_remove(&rule->list);
1141 list_push_back(&super->list, &rule->list);
1142 rule->super = super;
1143 rule->wr.hard_timeout = super->wr.hard_timeout;
1144 rule->wr.idle_timeout = super->wr.idle_timeout;
1145 rule->wr.created = super->wr.created;
1150 wx_rule_update_actions(wx, rule);
1155 revalidate_cb(struct cls_rule *sub_, void *cbdata_)
1157 struct wx_rule *sub = wx_rule_cast(sub_);
1158 struct revalidate_cbdata *cbdata = cbdata_;
1160 if (cbdata->revalidate_all
1161 || (cbdata->revalidate_subrules && sub->super)
1162 || tag_set_intersects(&cbdata->revalidate_set, sub->tags)) {
1163 revalidate_rule(cbdata->wx, sub);
1168 wx_run_one(struct wx *wx)
1170 if (time_msec() >= wx->next_expiration) {
1171 COVERAGE_INC(wx_expiration);
1172 wx->next_expiration = time_msec() + 1000;
1175 classifier_for_each(&wx->cls, CLS_INC_ALL, expire_rule, wx);
1177 /* XXX account_checkpoint_cb */
1180 if (wx->need_revalidate || !tag_set_is_empty(&wx->revalidate_set)) {
1181 struct revalidate_cbdata cbdata;
1183 cbdata.revalidate_all = wx->revalidate_all;
1184 cbdata.revalidate_subrules = wx->need_revalidate;
1185 cbdata.revalidate_set = wx->revalidate_set;
1186 tag_set_init(&wx->revalidate_set);
1187 COVERAGE_INC(wx_revalidate);
1188 classifier_for_each(&wx->cls, CLS_INC_EXACT, revalidate_cb, &cbdata);
1189 wx->need_revalidate = false;
1198 LIST_FOR_EACH (wx, struct wx, list_node, &all_wx) {
1205 wx_wait_one(struct wx *wx)
1207 if (wx->need_revalidate || !tag_set_is_empty(&wx->revalidate_set)) {
1208 poll_immediate_wake();
1209 } else if (wx->next_expiration != LLONG_MAX) {
1210 poll_timer_wait_until(wx->next_expiration);
1219 LIST_FOR_EACH (wx, struct wx, list_node, &all_wx) {
1225 static int wx_flow_flush(struct wdp *);
1228 wx_enumerate(const struct wdp_class *wdp_class, struct svec *all_wdps)
1230 struct svec names = SVEC_EMPTY_INITIALIZER;
1231 int error = xf_enumerate_names(wdp_class->type, &names);
1232 svec_move(all_wdps, &names);
1237 wx_open(const struct wdp_class *wdp_class, const char *name, bool create,
1244 ? xfif_create_and_open(name, wdp_class->type, &xfif)
1245 : xfif_open(name, wdp_class->type, &xfif));
1249 wx = xzalloc(sizeof *wx);
1250 list_push_back(&all_wx, &wx->list_node);
1251 wdp_init(&wx->wdp, wdp_class, name, 0, 0);
1253 classifier_init(&wx->cls);
1254 wx->netdev_monitor = netdev_monitor_create();
1255 port_array_init(&wx->ports);
1256 shash_init(&wx->port_by_name);
1257 wx->next_expiration = time_msec() + 1000;
1258 tag_set_init(&wx->revalidate_set);
1262 wx->ofhooks = &default_ofhooks;
1264 wx->ml = mac_learning_create();
1273 wx_close(struct wdp *wdp)
1275 struct wx *wx = wx_cast(wdp);
1278 xfif_close(wx->xfif);
1279 classifier_destroy(&wx->cls);
1280 netdev_monitor_destroy(wx->netdev_monitor);
1281 list_remove(&wx->list_node);
1282 mac_learning_destroy(wx->ml);
1287 wx_get_all_names(const struct wdp *wdp, struct svec *all_names)
1289 struct wx *wx = wx_cast(wdp);
1291 return xfif_get_all_names(wx->xfif, all_names);
1295 wx_destroy(struct wdp *wdp)
1297 struct wx *wx = wx_cast(wdp);
1299 return xfif_delete(wx->xfif);
1303 wx_get_features(const struct wdp *wdp, struct ofpbuf **featuresp)
1305 struct wx *wx = wx_cast(wdp);
1306 struct ofp_switch_features *osf;
1308 unsigned int port_no;
1309 struct wdp_port *port;
1311 buf = ofpbuf_new(sizeof *osf);
1312 osf = ofpbuf_put_zeros(buf, sizeof *osf);
1314 osf->capabilities = htonl(OFPC_ARP_MATCH_IP);
1315 osf->actions = htonl((1u << OFPAT_OUTPUT) |
1316 (1u << OFPAT_SET_VLAN_VID) |
1317 (1u << OFPAT_SET_VLAN_PCP) |
1318 (1u << OFPAT_STRIP_VLAN) |
1319 (1u << OFPAT_SET_DL_SRC) |
1320 (1u << OFPAT_SET_DL_DST) |
1321 (1u << OFPAT_SET_NW_SRC) |
1322 (1u << OFPAT_SET_NW_DST) |
1323 (1u << OFPAT_SET_NW_TOS) |
1324 (1u << OFPAT_SET_TP_SRC) |
1325 (1u << OFPAT_SET_TP_DST) |
1326 (1u << OFPAT_ENQUEUE));
1328 PORT_ARRAY_FOR_EACH (port, &wx->ports, port_no) {
1329 hton_ofp_phy_port(ofpbuf_put(buf, &port->opp, sizeof port->opp));
1337 count_subrules(struct cls_rule *cls_rule, void *n_subrules_)
1339 struct wx_rule *rule = wx_rule_cast(cls_rule);
1340 int *n_subrules = n_subrules_;
1348 wx_get_stats(const struct wdp *wdp, struct wdp_stats *stats)
1350 struct wx *wx = wx_cast(wdp);
1351 struct xflow_stats xflow_stats;
1354 error = xfif_get_xf_stats(wx->xfif, &xflow_stats);
1355 stats->max_ports = xflow_stats.max_ports;
1360 wx_get_table_stats(const struct wdp *wdp, struct ofpbuf *stats)
1362 struct wx *wx = wx_cast(wdp);
1363 struct xflow_stats xflow_stats;
1364 struct ofp_table_stats *exact, *wild;
1367 xfif_get_xf_stats(wx->xfif, &xflow_stats);
1368 /* XXX should pass up errors, but there are no appropriate OpenFlow error
1372 classifier_for_each(&wx->cls, CLS_INC_EXACT, count_subrules, &n_subrules);
1374 exact = ofpbuf_put_zeros(stats, sizeof *exact);
1375 exact->table_id = TABLEID_HASH;
1376 strcpy(exact->name, "exact");
1377 exact->wildcards = htonl(0);
1378 exact->max_entries = htonl(MIN(WX_MAX_EXACT, xflow_stats.max_capacity));
1379 exact->active_count = htonl(classifier_count_exact(&wx->cls) - n_subrules);
1380 exact->lookup_count = htonll(xflow_stats.n_hit + xflow_stats.n_missed);
1381 exact->matched_count = htonll(xflow_stats.n_hit);
1383 wild = ofpbuf_put_zeros(stats, sizeof *exact);
1384 wild->table_id = TABLEID_CLASSIFIER;
1385 strcpy(wild->name, "classifier");
1386 wild->wildcards = htonl(OVSFW_ALL);
1387 wild->max_entries = htonl(WX_MAX_WILD);
1388 wild->active_count = htonl(classifier_count_wild(&wx->cls));
1389 wild->lookup_count = htonll(0); /* XXX */
1390 wild->matched_count = htonll(0); /* XXX */
1396 wx_get_drop_frags(const struct wdp *wdp, bool *drop_frags)
1398 struct wx *wx = wx_cast(wdp);
1400 return xfif_get_drop_frags(wx->xfif, drop_frags);
1404 wx_set_drop_frags(struct wdp *wdp, bool drop_frags)
1406 struct wx *wx = wx_cast(wdp);
1408 return xfif_set_drop_frags(wx->xfif, drop_frags);
1412 wx_port_add(struct wdp *wdp, const char *devname,
1413 bool internal, uint16_t *port_no)
1415 struct wx *wx = wx_cast(wdp);
1416 uint16_t xflow_flags = internal ? XFLOW_PORT_INTERNAL : 0;
1417 return xfif_port_add(wx->xfif, devname, xflow_flags, port_no);
1421 wx_port_del(struct wdp *wdp, uint16_t port_no)
1423 struct wx *wx = wx_cast(wdp);
1425 return xfif_port_del(wx->xfif, port_no);
1429 wx_answer_port_query(const struct wdp_port *port, struct wdp_port *portp)
1432 wdp_port_copy(portp, port);
1440 wx_port_query_by_number(const struct wdp *wdp, uint16_t port_no,
1441 struct wdp_port *portp)
1443 struct wx *wx = wx_cast(wdp);
1444 const struct wdp_port *port;
1446 port = port_array_get(&wx->ports, ofp_port_to_xflow_port(port_no));
1447 return wx_answer_port_query(port, portp);
1451 wx_port_query_by_name(const struct wdp *wdp, const char *devname,
1452 struct wdp_port *portp)
1454 struct wx *wx = wx_cast(wdp);
1456 return wx_answer_port_query(shash_find_data(&wx->port_by_name, devname),
1461 wx_port_set_config(struct wdp *wdp, uint16_t port_no, uint32_t config)
1463 struct wx *wx = wx_cast(wdp);
1464 struct wdp_port *port;
1467 port = port_array_get(&wx->ports, ofp_port_to_xflow_port(port_no));
1471 changes = config ^ port->opp.config;
1473 if (changes & OFPPC_PORT_DOWN) {
1475 if (config & OFPPC_PORT_DOWN) {
1476 error = netdev_turn_flags_off(port->netdev, NETDEV_UP, true);
1478 error = netdev_turn_flags_on(port->netdev, NETDEV_UP, true);
1481 port->opp.config ^= OFPPC_PORT_DOWN;
1485 #define REVALIDATE_BITS (OFPPC_NO_RECV | OFPPC_NO_RECV_STP | OFPPC_NO_FWD)
1486 if (changes & REVALIDATE_BITS) {
1487 COVERAGE_INC(wx_costly_flags);
1488 port->opp.config ^= changes & REVALIDATE_BITS;
1489 wx->need_revalidate = true;
1491 #undef REVALIDATE_BITS
1493 if (changes & OFPPC_NO_FLOOD) {
1494 port->opp.config ^= OFPPC_NO_FLOOD;
1495 wx_port_refresh_groups(wx);
1498 if (changes & OFPPC_NO_PACKET_IN) {
1499 port->opp.config ^= OFPPC_NO_PACKET_IN;
1506 wx_port_list(const struct wdp *wdp, struct wdp_port **portsp, size_t *n_portsp)
1508 struct wx *wx = wx_cast(wdp);
1509 struct wdp_port *ports, *port;
1510 unsigned int port_no;
1513 *n_portsp = n_ports = port_array_count(&wx->ports);
1514 *portsp = ports = xmalloc(n_ports * sizeof *ports);
1516 PORT_ARRAY_FOR_EACH (port, &wx->ports, port_no) {
1517 wdp_port_copy(&ports[i++], port);
1519 assert(i == n_ports);
1525 wx_port_poll(struct wdp *wdp, wdp_port_poll_cb_func *cb, void *aux)
1527 struct wx *wx = wx_cast(wdp);
1533 while ((error = xfif_port_poll(wx->xfif, &devname)) != EAGAIN) {
1534 wx_port_process_change(wx, error, devname, cb, aux);
1535 if (error && error != ENOBUFS) {
1539 while ((error = netdev_monitor_poll(wx->netdev_monitor,
1540 &devname)) != EAGAIN) {
1541 wx_port_process_change(wx, error, devname, cb, aux);
1542 if (error && error != ENOBUFS) {
1550 wx_port_poll_wait(const struct wdp *wdp)
1552 struct wx *wx = wx_cast(wdp);
1554 xfif_port_poll_wait(wx->xfif);
1555 netdev_monitor_poll_wait(wx->netdev_monitor);
1559 static struct wdp_rule *
1560 wx_flow_get(const struct wdp *wdp, const flow_t *flow, unsigned int include)
1562 struct wx *wx = wx_cast(wdp);
1563 struct wx_rule *rule;
1566 table_id = flow->wildcards ? TABLEID_CLASSIFIER : TABLEID_HASH;
1567 if (!(include & (1u << table_id))) {
1571 rule = wx_rule_cast(classifier_find_rule_exactly(&wx->cls, flow));
1572 return rule && !wx_rule_is_hidden(rule) ? &rule->wr : NULL;
1575 static struct wdp_rule *
1576 wx_flow_match(const struct wdp *wdp, const flow_t *flow)
1578 struct wx *wx = wx_cast(wdp);
1579 struct wx_rule *rule;
1581 rule = wx_rule_cast(classifier_lookup(&wx->cls, flow));
1583 if (wx_rule_is_hidden(rule)) {
1592 struct wx_for_each_thunk_aux {
1593 wdp_flow_cb_func *client_callback;
1598 wx_for_each_thunk(struct cls_rule *cls_rule, void *aux_)
1600 struct wx_for_each_thunk_aux *aux = aux_;
1601 struct wx_rule *rule = wx_rule_cast(cls_rule);
1603 if (!wx_rule_is_hidden(rule)) {
1604 aux->client_callback(&rule->wr, aux->client_aux);
1609 wx_flow_for_each_match(const struct wdp *wdp, const flow_t *target,
1610 unsigned int include,
1611 wdp_flow_cb_func *client_callback, void *client_aux)
1613 struct wx *wx = wx_cast(wdp);
1614 struct wx_for_each_thunk_aux aux;
1618 if (include & (1u << TABLEID_HASH)) {
1619 cls_include |= CLS_INC_EXACT;
1621 if (include & (1u << TABLEID_CLASSIFIER)) {
1622 cls_include |= CLS_INC_WILD;
1625 aux.client_callback = client_callback;
1626 aux.client_aux = client_aux;
1627 classifier_for_each_match(&wx->cls, target, cls_include,
1628 wx_for_each_thunk, &aux);
1631 /* Obtains statistic counters for 'rule' within 'wx' and stores them into
1632 * '*stats'. If 'rule' is a wildcarded rule, the returned statistic include
1633 * statistics for all of 'rule''s subrules. */
1635 query_stats(struct wx *wx, struct wx_rule *rule, struct wdp_flow_stats *stats)
1637 struct wx_rule *subrule;
1638 struct xflow_flow *xflow_flows;
1639 size_t n_xflow_flows;
1641 /* Start from historical data for 'rule' itself that are no longer tracked
1642 * by the datapath. This counts, for example, subrules that have
1644 stats->n_packets = rule->packet_count;
1645 stats->n_bytes = rule->byte_count;
1646 stats->inserted = rule->wr.created;
1647 stats->used = LLONG_MIN;
1648 stats->tcp_flags = 0;
1651 /* Prepare to ask the datapath for statistics on 'rule', or if it is
1652 * wildcarded then on all of its subrules.
1654 * Also, add any statistics that are not tracked by the datapath for each
1655 * subrule. This includes, for example, statistics for packets that were
1656 * executed "by hand" by ofproto via xfif_execute() but must be accounted
1658 n_xflow_flows = rule->wr.cr.flow.wildcards ? list_size(&rule->list) : 1;
1659 xflow_flows = xzalloc(n_xflow_flows * sizeof *xflow_flows);
1660 if (rule->wr.cr.flow.wildcards) {
1662 LIST_FOR_EACH (subrule, struct wx_rule, list, &rule->list) {
1663 xflow_key_from_flow(&xflow_flows[i++].key, &subrule->wr.cr.flow);
1664 stats->n_packets += subrule->packet_count;
1665 stats->n_bytes += subrule->byte_count;
1668 xflow_key_from_flow(&xflow_flows[0].key, &rule->wr.cr.flow);
1671 /* Fetch up-to-date statistics from the datapath and add them in. */
1672 if (!xfif_flow_get_multiple(wx->xfif, xflow_flows, n_xflow_flows)) {
1674 for (i = 0; i < n_xflow_flows; i++) {
1675 struct xflow_flow *xflow_flow = &xflow_flows[i];
1678 stats->n_packets += xflow_flow->stats.n_packets;
1679 stats->n_bytes += xflow_flow->stats.n_bytes;
1680 used = xflow_flow_stats_to_msec(&xflow_flow->stats);
1681 if (used > stats->used) {
1683 if (xflow_flow->key.dl_type == htons(ETH_TYPE_IP)
1684 && xflow_flow->key.nw_proto == IP_TYPE_TCP) {
1685 stats->ip_tos = xflow_flow->stats.ip_tos;
1688 stats->tcp_flags |= xflow_flow->stats.tcp_flags;
1695 wx_flow_get_stats(const struct wdp *wdp,
1696 const struct wdp_rule *wdp_rule,
1697 struct wdp_flow_stats *stats)
1699 struct wx *wx = wx_cast(wdp);
1700 struct wx_rule *rule = wx_rule_cast(&wdp_rule->cr);
1702 query_stats(wx, rule, stats);
1707 wx_flow_overlaps(const struct wdp *wdp, const flow_t *flow)
1709 struct wx *wx = wx_cast(wdp);
1711 /* XXX overlap with a subrule? */
1712 return classifier_rule_overlaps(&wx->cls, flow);
1716 wx_flow_put(struct wdp *wdp, const struct wdp_flow_put *put,
1717 struct wdp_flow_stats *old_stats, struct wdp_rule **rulep)
1719 struct wx *wx = wx_cast(wdp);
1720 struct wx_rule *rule;
1721 uint8_t ofp_table_id;
1723 ofp_table_id = put->flow->wildcards ? TABLEID_CLASSIFIER : TABLEID_HASH;
1724 if (put->ofp_table_id != 0xff && put->ofp_table_id != ofp_table_id) {
1728 rule = wx_rule_cast(classifier_find_rule_exactly(&wx->cls, put->flow));
1729 if (rule && wx_rule_is_hidden(rule)) {
1734 if (!(put->flags & WDP_PUT_MODIFY)) {
1738 if (!(put->flags & WDP_PUT_CREATE)) {
1741 if ((put->flow->wildcards
1742 ? classifier_count_wild(&wx->cls) >= WX_MAX_WILD
1743 : classifier_count_exact(&wx->cls) >= WX_MAX_EXACT)) {
1744 /* XXX subrules should not count against exact-match limit */
1749 rule = wx_rule_create(NULL, put->actions, put->n_actions,
1750 put->idle_timeout, put->hard_timeout);
1751 cls_rule_from_flow(put->flow, &rule->wr.cr);
1752 rule->wr.ofp_table_id = ofp_table_id;
1753 wx_rule_insert(wx, rule, NULL, 0);
1757 memset(old_stats, 0, sizeof *old_stats);
1767 wx_flow_delete(struct wdp *wdp, struct wdp_rule *wdp_rule,
1768 struct wdp_flow_stats *final_stats)
1770 struct wx *wx = wx_cast(wdp);
1771 struct wx_rule *rule = wx_rule_cast(&wdp_rule->cr);
1773 wx_rule_remove(wx, rule);
1775 memset(final_stats, 0, sizeof *final_stats); /* XXX */
1781 wx_flush_rule(struct cls_rule *cls_rule, void *wx_)
1783 struct wx_rule *rule = wx_rule_cast(cls_rule);
1784 struct wx *wx = wx_;
1786 /* Mark the flow as not installed, even though it might really be
1787 * installed, so that wx_rule_remove() doesn't bother trying to uninstall
1788 * it. There is no point in uninstalling it individually since we are
1789 * about to blow away all the flows with xfif_flow_flush(). */
1790 rule->installed = false;
1792 wx_rule_remove(wx, rule);
1796 wx_flow_flush(struct wdp *wdp)
1798 struct wx *wx = wx_cast(wdp);
1800 COVERAGE_INC(wx_flow_flush);
1801 classifier_for_each(&wx->cls, CLS_INC_ALL, wx_flush_rule, wx);
1802 xfif_flow_flush(wx->xfif);
1807 wx_execute(struct wdp *wdp, uint16_t in_port,
1808 const union ofp_action actions[], int n_actions,
1809 const struct ofpbuf *packet)
1811 struct wx *wx = wx_cast(wdp);
1812 struct xflow_actions xflow_actions;
1816 flow_extract((struct ofpbuf *) packet, 0, in_port, &flow);
1817 error = wx_xlate_actions(wx, actions, n_actions, &flow, packet,
1818 NULL, &xflow_actions, NULL);
1822 xfif_execute(wx->xfif, ofp_port_to_xflow_port(in_port),
1823 xflow_actions.actions, xflow_actions.n_actions, packet);
1828 wx_flow_inject(struct wdp *wdp, struct wdp_rule *wdp_rule,
1829 uint16_t in_port, const struct ofpbuf *packet)
1831 struct wx_rule *rule = wx_rule_cast(&wdp_rule->cr);
1834 error = wx_execute(wdp, in_port, rule->wr.actions, rule->wr.n_actions,
1837 rule->packet_count++;
1838 rule->byte_count += packet->size;
1839 rule->used = time_msec();
1845 wx_recv_get_mask(const struct wdp *wdp, int *listen_mask)
1847 struct wx *wx = wx_cast(wdp);
1848 int xflow_listen_mask;
1851 error = xfif_recv_get_mask(wx->xfif, &xflow_listen_mask);
1854 if (xflow_listen_mask & XFLOWL_MISS) {
1855 *listen_mask |= 1 << WDP_CHAN_MISS;
1857 if (xflow_listen_mask & XFLOWL_ACTION) {
1858 *listen_mask |= 1 << WDP_CHAN_ACTION;
1860 if (xflow_listen_mask & XFLOWL_SFLOW) {
1861 *listen_mask |= 1 << WDP_CHAN_SFLOW;
1868 wx_recv_set_mask(struct wdp *wdp, int listen_mask)
1870 struct wx *wx = wx_cast(wdp);
1871 int xflow_listen_mask;
1873 xflow_listen_mask = 0;
1874 if (listen_mask & (1 << WDP_CHAN_MISS)) {
1875 xflow_listen_mask |= XFLOWL_MISS;
1877 if (listen_mask & (1 << WDP_CHAN_ACTION)) {
1878 xflow_listen_mask |= XFLOWL_ACTION;
1880 if (listen_mask & (1 << WDP_CHAN_SFLOW)) {
1881 xflow_listen_mask |= XFLOWL_SFLOW;
1884 return xfif_recv_set_mask(wx->xfif, xflow_listen_mask);
1888 wx_get_sflow_probability(const struct wdp *wdp, uint32_t *probability)
1890 struct wx *wx = wx_cast(wdp);
1892 return xfif_get_sflow_probability(wx->xfif, probability);
1896 wx_set_sflow_probability(struct wdp *wdp, uint32_t probability)
1898 struct wx *wx = wx_cast(wdp);
1900 return xfif_set_sflow_probability(wx->xfif, probability);
1904 wx_translate_xflow_msg(struct xflow_msg *msg, struct ofpbuf *payload,
1905 struct wdp_packet *packet)
1907 packet->in_port = xflow_port_to_ofp_port(msg->port);
1908 packet->send_len = 0;
1911 switch (msg->type) {
1912 case _XFLOWL_MISS_NR:
1913 packet->channel = WDP_CHAN_MISS;
1914 packet->payload = payload;
1915 packet->tun_id = msg->arg;
1918 case _XFLOWL_ACTION_NR:
1919 packet->channel = WDP_CHAN_ACTION;
1920 packet->payload = payload;
1921 packet->send_len = msg->arg;
1924 case _XFLOWL_SFLOW_NR:
1926 ofpbuf_delete(payload);
1930 VLOG_WARN_RL(&rl, "received XFLOW message of unexpected type %"PRIu32,
1932 ofpbuf_delete(payload);
1937 static const uint8_t *
1938 get_local_mac(const struct wx *wx)
1940 const struct wdp_port *port = port_array_get(&wx->ports, XFLOWP_LOCAL);
1941 return port ? port->opp.hw_addr : NULL;
1944 /* Returns true if 'packet' is a DHCP reply to the local port. Such a reply
1945 * should be sent to the local port regardless of the flow table.
1947 * We only need this, strictly speaking, when in-band control is turned on. */
1949 wx_is_local_dhcp_reply(const struct wx *wx,
1950 const flow_t *flow, const struct ofpbuf *packet)
1952 if (flow->dl_type == htons(ETH_TYPE_IP)
1953 && flow->nw_proto == IP_TYPE_UDP
1954 && flow->tp_src == htons(DHCP_SERVER_PORT)
1955 && flow->tp_dst == htons(DHCP_CLIENT_PORT)
1958 const uint8_t *local_mac = get_local_mac(wx);
1959 struct dhcp_header *dhcp = ofpbuf_at(
1960 packet, (char *)packet->l7 - (char *)packet->data, sizeof *dhcp);
1961 return dhcp && local_mac && eth_addr_equals(dhcp->chaddr, local_mac);
1968 wx_explode_rule(struct wx *wx, struct xflow_msg *msg, struct ofpbuf *payload)
1970 struct wx_rule *rule;
1973 flow_extract(payload, 0, xflow_port_to_ofp_port(msg->port), &flow);
1975 if (wx_is_local_dhcp_reply(wx, &flow, payload)) {
1976 union xflow_action action;
1978 memset(&action, 0, sizeof(action));
1979 action.output.type = XFLOWAT_OUTPUT;
1980 action.output.port = XFLOWP_LOCAL;
1981 xfif_execute(wx->xfif, msg->port, &action, 1, payload);
1984 rule = wx_rule_lookup_valid(wx, &flow);
1989 if (rule->wr.cr.flow.wildcards) {
1990 rule = wx_rule_create_subrule(wx, rule, &flow);
1991 wx_rule_make_actions(wx, rule, payload);
1993 if (!rule->may_install) {
1994 /* The rule is not installable, that is, we need to process every
1995 * packet, so process the current packet and set its actions into
1997 wx_rule_make_actions(wx, rule, payload);
1999 /* XXX revalidate rule if it needs it */
2003 wx_rule_execute(wx, rule, payload, &flow);
2004 wx_rule_reinstall(wx, rule);
2010 wx_recv(struct wdp *wdp, struct wdp_packet *packet)
2012 struct wx *wx = wx_cast(wdp);
2015 /* XXX need to avoid 50*50 potential cost for caller. */
2016 for (i = 0; i < 50; i++) {
2017 struct xflow_msg *msg;
2021 error = xfif_recv(wx->xfif, &buf);
2026 msg = ofpbuf_pull(buf, sizeof *msg);
2027 if (msg->type != _XFLOWL_MISS_NR || !wx_explode_rule(wx, msg, buf)) {
2028 return wx_translate_xflow_msg(msg, buf, packet);
2036 wx_recv_purge_queue__(struct wx *wx, int max, int xflow_listen_mask,
2041 error = xfif_recv_set_mask(wx->xfif, xflow_listen_mask);
2045 while (max > 0 && (error = xfif_recv(wx->xfif, &buf)) == 0) {
2050 if (error && error != EAGAIN) {
2056 wx_recv_purge(struct wdp *wdp)
2058 struct wx *wx = wx_cast(wdp);
2059 struct xflow_stats xflow_stats;
2060 int xflow_listen_mask;
2063 xfif_get_xf_stats(wx->xfif, &xflow_stats);
2065 error = xfif_recv_get_mask(wx->xfif, &xflow_listen_mask);
2066 if (error || !(xflow_listen_mask & XFLOWL_ALL)) {
2070 if (xflow_listen_mask & XFLOWL_MISS) {
2071 wx_recv_purge_queue__(wx, xflow_stats.max_miss_queue, XFLOWL_MISS,
2074 if (xflow_listen_mask & XFLOWL_ACTION) {
2075 wx_recv_purge_queue__(wx, xflow_stats.max_action_queue, XFLOWL_ACTION,
2078 if (xflow_listen_mask & XFLOWL_SFLOW) {
2079 wx_recv_purge_queue__(wx, xflow_stats.max_sflow_queue, XFLOWL_SFLOW,
2083 retval = xfif_recv_set_mask(wx->xfif, xflow_listen_mask);
2084 return retval ? retval : error;
2089 wx_recv_wait(struct wdp *wdp)
2091 struct wx *wx = wx_cast(wdp);
2093 xfif_recv_wait(wx->xfif);
2097 wx_set_ofhooks(struct wdp *wdp, const struct ofhooks *ofhooks, void *aux)
2099 struct wx *wx = wx_cast(wdp);
2101 if (wx->ofhooks == &default_ofhooks) {
2102 mac_learning_destroy(wx->ml);
2106 wx->ofhooks = ofhooks;
2112 wx_revalidate(struct wdp *wdp, tag_type tag)
2114 struct wx *wx = wx_cast(wdp);
2116 tag_set_add(&wx->revalidate_set, tag);
2120 wx_revalidate_all(struct wdp *wdp)
2122 struct wx *wx = wx_cast(wdp);
2124 wx->revalidate_all = true;
2127 static void wx_port_update(struct wx *, const char *devname,
2128 wdp_port_poll_cb_func *cb, void *aux);
2129 static void wx_port_reinit(struct wx *, wdp_port_poll_cb_func *cb, void *aux);
2132 wx_port_process_change(struct wx *wx, int error, char *devname,
2133 wdp_port_poll_cb_func *cb, void *aux)
2135 if (error == ENOBUFS) {
2136 wx_port_reinit(wx, cb, aux);
2137 } else if (!error) {
2138 wx_port_update(wx, devname, cb, aux);
2144 wx_port_refresh_group(struct wx *wx, unsigned int group)
2148 struct wdp_port *port;
2149 unsigned int port_no;
2151 assert(group == WX_GROUP_ALL || group == WX_GROUP_FLOOD);
2153 ports = xmalloc(port_array_count(&wx->ports) * sizeof *ports);
2155 PORT_ARRAY_FOR_EACH (port, &wx->ports, port_no) {
2156 if (group == WX_GROUP_ALL || !(port->opp.config & OFPPC_NO_FLOOD)) {
2157 ports[n_ports++] = port_no;
2160 xfif_port_group_set(wx->xfif, group, ports, n_ports);
2167 wx_port_refresh_groups(struct wx *wx)
2169 wx_port_refresh_group(wx, WX_GROUP_FLOOD);
2170 wx_port_refresh_group(wx, WX_GROUP_ALL);
2174 wx_port_reinit(struct wx *wx, wdp_port_poll_cb_func *cb, void *aux)
2176 struct svec devnames;
2177 struct wdp_port *wdp_port;
2178 unsigned int port_no;
2179 struct xflow_port *xflow_ports;
2180 size_t n_xflow_ports;
2183 svec_init(&devnames);
2184 PORT_ARRAY_FOR_EACH (wdp_port, &wx->ports, port_no) {
2185 svec_add (&devnames, (char *) wdp_port->opp.name);
2187 xfif_port_list(wx->xfif, &xflow_ports, &n_xflow_ports);
2188 for (i = 0; i < n_xflow_ports; i++) {
2189 svec_add(&devnames, xflow_ports[i].devname);
2193 svec_sort_unique(&devnames);
2194 for (i = 0; i < devnames.n; i++) {
2195 wx_port_update(wx, devnames.names[i], cb, aux);
2197 svec_destroy(&devnames);
2199 wx_port_refresh_groups(wx);
2202 static struct wdp_port *
2203 make_wdp_port(const struct xflow_port *xflow_port)
2205 struct netdev_options netdev_options;
2206 enum netdev_flags flags;
2207 struct wdp_port *wdp_port;
2208 struct netdev *netdev;
2212 memset(&netdev_options, 0, sizeof netdev_options);
2213 netdev_options.name = xflow_port->devname;
2214 netdev_options.ethertype = NETDEV_ETH_TYPE_NONE;
2216 error = netdev_open(&netdev_options, &netdev);
2218 VLOG_WARN_RL(&rl, "ignoring port %s (%"PRIu16") because netdev %s "
2219 "cannot be opened (%s)",
2220 xflow_port->devname, xflow_port->port,
2221 xflow_port->devname, strerror(error));
2225 wdp_port = xmalloc(sizeof *wdp_port);
2226 wdp_port->netdev = netdev;
2227 wdp_port->opp.port_no = xflow_port_to_ofp_port(xflow_port->port);
2228 netdev_get_etheraddr(netdev, wdp_port->opp.hw_addr);
2229 strncpy((char *) wdp_port->opp.name, xflow_port->devname,
2230 sizeof wdp_port->opp.name);
2231 wdp_port->opp.name[sizeof wdp_port->opp.name - 1] = '\0';
2233 netdev_get_flags(netdev, &flags);
2234 wdp_port->opp.config = flags & NETDEV_UP ? 0 : OFPPC_PORT_DOWN;
2236 netdev_get_carrier(netdev, &carrier);
2237 wdp_port->opp.state = carrier ? 0 : OFPPS_LINK_DOWN;
2239 netdev_get_features(netdev,
2240 &wdp_port->opp.curr, &wdp_port->opp.advertised,
2241 &wdp_port->opp.supported, &wdp_port->opp.peer);
2243 wdp_port->devname = xstrdup(xflow_port->devname);
2244 wdp_port->internal = (xflow_port->flags & XFLOW_PORT_INTERNAL) != 0;
2249 wx_port_conflicts(const struct wx *wx, const struct xflow_port *xflow_port)
2251 if (port_array_get(&wx->ports, xflow_port->port)) {
2252 VLOG_WARN_RL(&rl, "ignoring duplicate port %"PRIu16" in datapath",
2255 } else if (shash_find(&wx->port_by_name, xflow_port->devname)) {
2256 VLOG_WARN_RL(&rl, "ignoring duplicate device %s in datapath",
2257 xflow_port->devname);
2265 wdp_port_equal(const struct wdp_port *a_, const struct wdp_port *b_)
2267 const struct ofp_phy_port *a = &a_->opp;
2268 const struct ofp_phy_port *b = &b_->opp;
2270 BUILD_ASSERT_DECL(sizeof *a == 48); /* Detect ofp_phy_port changes. */
2271 return (a->port_no == b->port_no
2272 && !memcmp(a->hw_addr, b->hw_addr, sizeof a->hw_addr)
2273 && !strcmp((char *) a->name, (char *) b->name)
2274 && a->state == b->state
2275 && a->config == b->config
2276 && a->curr == b->curr
2277 && a->advertised == b->advertised
2278 && a->supported == b->supported
2279 && a->peer == b->peer);
2283 wx_port_install(struct wx *wx, struct wdp_port *wdp_port)
2285 uint16_t xflow_port = ofp_port_to_xflow_port(wdp_port->opp.port_no);
2286 const char *netdev_name = (const char *) wdp_port->opp.name;
2288 netdev_monitor_add(wx->netdev_monitor, wdp_port->netdev);
2289 port_array_set(&wx->ports, xflow_port, wdp_port);
2290 shash_add(&wx->port_by_name, netdev_name, wdp_port);
2294 wx_port_remove(struct wx *wx, struct wdp_port *wdp_port)
2296 uint16_t xflow_port = ofp_port_to_xflow_port(wdp_port->opp.port_no);
2298 netdev_monitor_remove(wx->netdev_monitor, wdp_port->netdev);
2299 port_array_delete(&wx->ports, xflow_port);
2300 shash_delete(&wx->port_by_name,
2301 shash_find(&wx->port_by_name, (char *) wdp_port->opp.name));
2305 wx_port_free(struct wdp_port *wdp_port)
2308 netdev_close(wdp_port->netdev);
2314 wx_port_update(struct wx *wx, const char *devname,
2315 wdp_port_poll_cb_func *cb, void *aux)
2317 struct xflow_port xflow_port;
2318 struct wdp_port *old_wdp_port;
2319 struct wdp_port *new_wdp_port;
2322 COVERAGE_INC(wx_update_port);
2324 /* Query the datapath for port information. */
2325 error = xfif_port_query_by_name(wx->xfif, devname, &xflow_port);
2327 /* Find the old wdp_port. */
2328 old_wdp_port = shash_find_data(&wx->port_by_name, devname);
2330 if (!old_wdp_port) {
2331 /* There's no port named 'devname' but there might be a port with
2332 * the same port number. This could happen if a port is deleted
2333 * and then a new one added in its place very quickly, or if a port
2334 * is renamed. In the former case we want to send an OFPPR_DELETE
2335 * and an OFPPR_ADD, and in the latter case we want to send a
2336 * single OFPPR_MODIFY. We can distinguish the cases by comparing
2337 * the old port's ifindex against the new port, or perhaps less
2338 * reliably but more portably by comparing the old port's MAC
2339 * against the new port's MAC. However, this code isn't that smart
2340 * and always sends an OFPPR_MODIFY (XXX). */
2341 old_wdp_port = port_array_get(&wx->ports, xflow_port.port);
2343 } else if (error != ENOENT && error != ENODEV) {
2344 VLOG_WARN_RL(&rl, "xfif_port_query_by_name returned unexpected error "
2345 "%s", strerror(error));
2349 /* Create a new wdp_port. */
2350 new_wdp_port = !error ? make_wdp_port(&xflow_port) : NULL;
2352 /* Eliminate a few pathological cases. */
2353 if (!old_wdp_port && !new_wdp_port) {
2355 } else if (old_wdp_port && new_wdp_port) {
2356 /* Most of the 'config' bits are OpenFlow soft state, but
2357 * OFPPC_PORT_DOWN is maintained by the kernel. So transfer the
2358 * OpenFlow bits from old_wdp_port. (make_wdp_port() only sets
2359 * OFPPC_PORT_DOWN and leaves the other bits 0.) */
2360 new_wdp_port->opp.config |= old_wdp_port->opp.config & ~OFPPC_PORT_DOWN;
2362 if (wdp_port_equal(old_wdp_port, new_wdp_port)) {
2363 /* False alarm--no change. */
2364 wx_port_free(new_wdp_port);
2369 /* Now deal with the normal cases. */
2371 wx_port_remove(wx, old_wdp_port);
2374 wx_port_install(wx, new_wdp_port);
2378 if (!old_wdp_port) {
2379 (*cb)(&new_wdp_port->opp, OFPPR_ADD, aux);
2380 } else if (!new_wdp_port) {
2381 (*cb)(&old_wdp_port->opp, OFPPR_DELETE, aux);
2383 (*cb)(&new_wdp_port->opp, OFPPR_MODIFY, aux);
2386 /* Update port groups. */
2387 wx_port_refresh_groups(wx);
2390 wx_port_free(old_wdp_port);
2394 wx_port_init(struct wx *wx)
2396 struct xflow_port *ports;
2401 error = xfif_port_list(wx->xfif, &ports, &n_ports);
2406 for (i = 0; i < n_ports; i++) {
2407 const struct xflow_port *xflow_port = &ports[i];
2408 if (!wx_port_conflicts(wx, xflow_port)) {
2409 struct wdp_port *wdp_port = make_wdp_port(xflow_port);
2411 wx_port_install(wx, wdp_port);
2416 wx_port_refresh_groups(wx);
2421 wdp_xflow_register(void)
2423 static const struct wdp_class wdp_xflow_class = {
2439 wx_port_query_by_number,
2440 wx_port_query_by_name,
2447 wx_flow_for_each_match,
2457 wx_get_sflow_probability,
2458 wx_set_sflow_probability,
2467 static bool inited = false;
2480 xf_enumerate_types(&types);
2483 SVEC_FOR_EACH (i, type, &types) {
2484 struct wdp_class *class;
2486 class = xmalloc(sizeof *class);
2487 *class = wdp_xflow_class;
2488 class->type = xstrdup(type);
2493 if (!wdp_register_provider(class)) {
2498 svec_destroy(&types);
2502 default_normal_ofhook_cb(const flow_t *flow, const struct ofpbuf *packet,
2503 struct xflow_actions *actions, tag_type *tags,
2504 uint16_t *nf_output_iface, void *wx_)
2506 struct wx *wx = wx_;
2509 /* Drop frames for reserved multicast addresses. */
2510 if (eth_addr_is_reserved(flow->dl_dst)) {
2514 /* Learn source MAC (but don't try to learn from revalidation). */
2515 if (packet != NULL) {
2516 tag_type rev_tag = mac_learning_learn(wx->ml, flow->dl_src,
2518 GRAT_ARP_LOCK_NONE);
2520 /* The log messages here could actually be useful in debugging,
2521 * so keep the rate limit relatively high. */
2522 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(30, 300);
2523 VLOG_DBG_RL(&rl, "learned that "ETH_ADDR_FMT" is on port %"PRIu16,
2524 ETH_ADDR_ARGS(flow->dl_src), flow->in_port);
2525 tag_set_add(&wx->revalidate_set, rev_tag);
2529 /* Determine output port. */
2530 out_port = mac_learning_lookup_tag(wx->ml, flow->dl_dst, 0, tags,
2533 add_output_group_action(actions, WX_GROUP_FLOOD, nf_output_iface);
2534 } else if (out_port != flow->in_port) {
2535 xflow_actions_add(actions, XFLOWAT_OUTPUT)->output.port = out_port;
2536 *nf_output_iface = out_port;
2544 static const struct ofhooks default_ofhooks = {
2546 default_normal_ofhook_cb,