COVERAGE_DEFINE(facet_revalidate);
COVERAGE_DEFINE(facet_unexpected);
COVERAGE_DEFINE(facet_suppress);
+COVERAGE_DEFINE(subfacet_install_fail);
/* Maximum depth of flow table recursion (due to resubmit actions) in a
* flow translation. */
}
static struct rule_dpif *rule_dpif_lookup(struct ofproto_dpif *,
- const struct flow *);
+ const struct flow *,
+ struct flow_wildcards *wc);
static struct rule_dpif *rule_dpif_lookup__(struct ofproto_dpif *,
const struct flow *,
+ struct flow_wildcards *wc,
uint8_t table);
static struct rule_dpif *rule_dpif_miss_rule(struct ofproto_dpif *ofproto,
const struct flow *flow);
+static void rule_get_stats(struct rule *, uint64_t *packets, uint64_t *bytes);
static void rule_credit_stats(struct rule_dpif *,
const struct dpif_flow_stats *);
-static void flow_push_stats(struct facet *, const struct dpif_flow_stats *);
static tag_type rule_calculate_tag(const struct flow *,
const struct minimask *, uint32_t basis);
static void rule_invalidate(const struct rule_dpif *);
};
struct xlate_out {
+ /* Wildcards relevant in translation. Any fields that were used to
+ * calculate the action must be set for caching and kernel
+ * wildcarding to work. For example, if the flow lookup involved
+ * performing the "normal" action on IPv4 and ARP packets, 'wc'
+ * would have the 'in_port' (always set), 'dl_type' (flow match),
+ * 'vlan_tci' (normal action), and 'dl_dst' (normal action) fields
+ * set. */
+ struct flow_wildcards wc;
+
tag_type tags; /* Tags associated with actions. */
enum slow_path_reason slow; /* 0 if fast path may be used. */
bool has_learn; /* Actions include NXAST_LEARN? */
static void xlate_report(struct xlate_ctx *ctx, const char *s);
+static void xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src);
+
/* A subfacet (see "struct subfacet" below) has three possible installation
* states:
*
struct subfacet **, int n);
static void subfacet_reset_dp_stats(struct subfacet *,
struct dpif_flow_stats *);
-static void subfacet_update_time(struct subfacet *, long long int used);
static void subfacet_update_stats(struct subfacet *,
const struct dpif_flow_stats *);
static int subfacet_install(struct subfacet *,
struct dpif_flow_stats *);
static void subfacet_uninstall(struct subfacet *);
-/* An exact-match instantiation of an OpenFlow flow.
+/* A unique, non-overlapping instantiation of an OpenFlow flow.
*
* A facet associates a "struct flow", which represents the Open vSwitch
- * userspace idea of an exact-match flow, with one or more subfacets. Each
- * subfacet tracks the datapath's idea of the exact-match flow equivalent to
- * the facet. When the kernel module (or other dpif implementation) and Open
- * vSwitch userspace agree on the definition of a flow key, there is exactly
- * one subfacet per facet. If the dpif implementation supports more-specific
- * flow matching than userspace, however, a facet can have more than one
- * subfacet, each of which corresponds to some distinction in flow that
- * userspace simply doesn't understand.
+ * userspace idea of an exact-match flow, with one or more subfacets.
+ * While the facet is created based on an exact-match flow, it is stored
+ * within the ofproto based on the wildcards that could be expressed
+ * based on the flow table and other configuration. (See the 'wc'
+ * description in "struct xlate_out" for more details.)
*
- * Flow expiration works in terms of subfacets, so a facet must have at least
- * one subfacet or it will never expire, leaking memory. */
+ * Each subfacet tracks the datapath's idea of the flow equivalent to
+ * the facet. When the kernel module (or other dpif implementation) and
+ * Open vSwitch userspace agree on the definition of a flow key, there
+ * is exactly one subfacet per facet. If the dpif implementation
+ * supports more-specific flow matching than userspace, however, a facet
+ * can have more than one subfacet. Examples include the dpif
+ * implementation not supporting the same wildcards as userspace or some
+ * distinction in flow that userspace simply doesn't understand.
+ *
+ * Flow expiration works in terms of subfacets, so a facet must have at
+ * least one subfacet or it will never expire, leaking memory. */
struct facet {
/* Owners. */
struct hmap_node hmap_node; /* In owning ofproto's 'facets' hmap. */
long long int used; /* Time last used; time created if not used. */
/* Key. */
- struct flow flow;
+ struct flow flow; /* Flow of the creating subfacet. */
+ struct cls_rule cr; /* In 'ofproto_dpif's facets classifier. */
/* These statistics:
*
long long int learn_rl; /* Rate limiter for facet_learn(). */
};
-static struct facet *facet_create(const struct flow_miss *, uint32_t hash);
+static struct facet *facet_create(const struct flow_miss *, struct rule_dpif *,
+ struct xlate_out *,
+ struct dpif_flow_stats *);
static void facet_remove(struct facet *);
static void facet_free(struct facet *);
-static struct facet *facet_find(struct ofproto_dpif *,
- const struct flow *, uint32_t hash);
+static struct facet *facet_find(struct ofproto_dpif *, const struct flow *);
static struct facet *facet_lookup_valid(struct ofproto_dpif *,
- const struct flow *, uint32_t hash);
+ const struct flow *);
static bool facet_revalidate(struct facet *);
static bool facet_check_consistency(struct facet *);
static void facet_flush_stats(struct facet *);
-static void facet_update_time(struct facet *, long long int used);
static void facet_reset_counters(struct facet *);
-static void facet_push_stats(struct facet *);
+static void facet_push_stats(struct facet *, bool may_learn);
static void facet_learn(struct facet *);
static void facet_account(struct facet *);
static void push_all_stats(void);
int vid;
};
-static uint32_t vsp_realdev_to_vlandev(const struct ofproto_dpif *,
- uint32_t realdev, ovs_be16 vlan_tci);
+static uint16_t vsp_realdev_to_vlandev(const struct ofproto_dpif *,
+ uint16_t realdev_ofp_port,
+ ovs_be16 vlan_tci);
static bool vsp_adjust_flow(const struct ofproto_dpif *, struct flow *);
static void vsp_remove(struct ofport_dpif *);
static void vsp_add(struct ofport_dpif *, uint16_t realdev_ofp_port, int vid);
struct tag_set revalidate_set; /* Revalidate only matching facets. */
struct hmap drop_keys; /* Set of dropped odp keys. */
+ bool recv_set_enable; /* Enables or disables receiving packets. */
};
/* All existing ofproto_backer instances, indexed by ofproto->up.type. */
/* Special OpenFlow rules. */
struct rule_dpif *miss_rule; /* Sends flow table misses to controller. */
struct rule_dpif *no_packet_in_rule; /* Drops flow table misses. */
-
- /* Statistics. */
- uint64_t n_matches;
+ struct rule_dpif *drop_frags_rule; /* Used in OFPC_FRAG_DROP mode. */
/* Bridging. */
struct netflow *netflow;
bool has_bonded_bundles;
/* Facets. */
- struct hmap facets;
+ struct classifier facets; /* Contains 'struct facet's. */
struct hmap subfacets;
struct governor *governor;
long long int consistency_rl;
* for debugging the asynchronous flow_mod implementation.) */
static bool clogged;
+/* By default, flows in the datapath are wildcarded (megaflows). They
+ * may be disabled with the "ovs-appctl dpif/disable-megaflows" command. */
+static bool enable_megaflows = true;
+
/* All existing ofproto_dpif instances, indexed by ->up.name. */
static struct hmap all_ofproto_dpifs = HMAP_INITIALIZER(&all_ofproto_dpifs);
const struct initial_vals *, struct ds *);
/* Packet processing. */
-static void update_learning_table(struct ofproto_dpif *,
- const struct flow *, int vlan,
+static void update_learning_table(struct ofproto_dpif *, const struct flow *,
+ struct flow_wildcards *, int vlan,
struct ofbundle *);
/* Upcalls. */
#define FLOW_MISS_MAX_BATCH 50
push_all_stats();
}
+ /* If vswitchd started with other_config:flow_restore_wait set as "true",
+ * and the configuration has now changed to "false", enable receiving
+ * packets from the datapath. */
+ if (!backer->recv_set_enable && !ofproto_get_flow_restore_wait()) {
+ backer->recv_set_enable = true;
+
+ error = dpif_recv_set(backer->dpif, backer->recv_set_enable);
+ if (error) {
+ VLOG_ERR("Failed to enable receiving packets in dpif.");
+ return error;
+ }
+ dpif_flow_flush(backer->dpif);
+ backer->need_revalidate = REV_RECONFIGURE;
+ }
+
if (backer->need_revalidate
|| !tag_set_is_empty(&backer->revalidate_set)) {
struct tag_set revalidate_set = backer->revalidate_set;
HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
struct facet *facet, *next;
+ struct cls_cursor cursor;
if (ofproto->backer != backer) {
continue;
}
- HMAP_FOR_EACH_SAFE (facet, next, hmap_node, &ofproto->facets) {
+ cls_cursor_init(&cursor, &ofproto->facets, NULL);
+ CLS_CURSOR_FOR_EACH_SAFE (facet, next, cr, &cursor) {
if (need_revalidate
|| tag_set_intersects(&revalidate_set, facet->xout.tags)) {
facet_revalidate(facet);
}
}
- if (timer_expired(&backer->next_expiration)) {
+ if (!backer->recv_set_enable) {
+ /* Wake up before a max of 1000ms. */
+ timer_set_duration(&backer->next_expiration, 1000);
+ } else if (timer_expired(&backer->next_expiration)) {
int delay = expire(backer);
timer_set_duration(&backer->next_expiration, delay);
}
{
unsigned int work;
+ /* If recv_set_enable is false, we should not handle upcalls. */
+ if (!backer->recv_set_enable) {
+ return 0;
+ }
+
/* Handle one or more batches of upcalls, until there's nothing left to do
* or until we do a fixed total amount of work.
*
backer->need_revalidate = 0;
simap_init(&backer->tnl_backers);
tag_set_init(&backer->revalidate_set);
+ backer->recv_set_enable = !ofproto_get_flow_restore_wait();
*backerp = backer;
- dpif_flow_flush(backer->dpif);
+ if (backer->recv_set_enable) {
+ dpif_flow_flush(backer->dpif);
+ }
/* Loop through the ports already on the datapath and remove any
* that we don't need anymore. */
shash_add(&all_dpif_backers, type, backer);
- error = dpif_recv_set(backer->dpif, true);
+ error = dpif_recv_set(backer->dpif, backer->recv_set_enable);
if (error) {
VLOG_ERR("failed to listen on datapath of type %s: %s",
type, strerror(error));
max_ports = dpif_get_max_ports(ofproto->backer->dpif);
ofproto_init_max_ports(ofproto_, MIN(max_ports, OFPP_MAX));
- ofproto->n_matches = 0;
-
ofproto->netflow = NULL;
ofproto->sflow = NULL;
ofproto->ipfix = NULL;
}
ofproto->has_bonded_bundles = false;
- hmap_init(&ofproto->facets);
+ classifier_init(&ofproto->facets);
hmap_init(&ofproto->subfacets);
ofproto->governor = NULL;
ofproto->consistency_rl = LLONG_MIN;
return error;
}
- *rulep = rule_dpif_lookup__(ofproto, &fm.match.flow, TBL_INTERNAL);
+ *rulep = rule_dpif_lookup__(ofproto, &fm.match.flow, NULL, TBL_INTERNAL);
ovs_assert(*rulep != NULL);
return 0;
ofpbuf_clear(&ofpacts);
error = add_internal_flow(ofproto, id++, &ofpacts,
&ofproto->no_packet_in_rule);
+ if (error) {
+ return error;
+ }
+
+ error = add_internal_flow(ofproto, id++, &ofpacts,
+ &ofproto->drop_frags_rule);
return error;
}
hmap_destroy(&ofproto->bundles);
mac_learning_destroy(ofproto->ml);
- hmap_destroy(&ofproto->facets);
+ classifier_destroy(&ofproto->facets);
hmap_destroy(&ofproto->subfacets);
governor_destroy(ofproto->governor);
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
struct ofport_dpif *ofport;
+ /* Do not perform any periodic activity required by 'ofproto' while
+ * waiting for flow restore to complete. */
+ if (ofproto_get_flow_restore_wait()) {
+ return 0;
+ }
+
HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
port_run_fast(ofport);
}
complete_operations(ofproto);
}
+ /* Do not perform any periodic activity below required by 'ofproto' while
+ * waiting for flow restore to complete. */
+ if (ofproto_get_flow_restore_wait()) {
+ return 0;
+ }
+
error = run_fast(ofproto_);
if (error) {
return error;
/* Check the consistency of a random facet, to aid debugging. */
if (time_msec() >= ofproto->consistency_rl
- && !hmap_is_empty(&ofproto->facets)
+ && !classifier_is_empty(&ofproto->facets)
&& !ofproto->backer->need_revalidate) {
+ struct cls_table *table;
+ struct cls_rule *cr;
struct facet *facet;
ofproto->consistency_rl = time_msec() + 250;
- facet = CONTAINER_OF(hmap_random_node(&ofproto->facets),
- struct facet, hmap_node);
+ table = CONTAINER_OF(hmap_random_node(&ofproto->facets.tables),
+ struct cls_table, hmap_node);
+ cr = CONTAINER_OF(hmap_random_node(&table->rules), struct cls_rule,
+ hmap_node);
+ facet = CONTAINER_OF(cr, struct facet, cr);
+
if (!tag_set_intersects(&ofproto->backer->revalidate_set,
facet->xout.tags)) {
if (!facet_check_consistency(facet)) {
poll_immediate_wake();
}
+ if (ofproto_get_flow_restore_wait()) {
+ return;
+ }
+
dpif_wait(ofproto->backer->dpif);
dpif_recv_wait(ofproto->backer->dpif);
if (ofproto->sflow) {
{
const struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
- simap_increase(usage, "facets", hmap_count(&ofproto->facets));
+ simap_increase(usage, "facets", classifier_count(&ofproto->facets));
simap_increase(usage, "subfacets", hmap_count(&ofproto->subfacets));
}
{
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
struct dpif_dp_stats s;
+ uint64_t n_miss, n_no_pkt_in, n_bytes, n_dropped_frags;
+ uint64_t n_lookup;
strcpy(ots->name, "classifier");
dpif_get_dp_stats(ofproto->backer->dpif, &s);
+ rule_get_stats(&ofproto->miss_rule->up, &n_miss, &n_bytes);
+ rule_get_stats(&ofproto->no_packet_in_rule->up, &n_no_pkt_in, &n_bytes);
+ rule_get_stats(&ofproto->drop_frags_rule->up, &n_dropped_frags, &n_bytes);
- ots->lookup_count = htonll(s.n_hit + s.n_missed);
- ots->matched_count = htonll(s.n_hit + ofproto->n_matches);
+ n_lookup = s.n_hit + s.n_missed - n_dropped_frags;
+ ots->lookup_count = htonll(n_lookup);
+ ots->matched_count = htonll(n_lookup - n_miss - n_no_pkt_in);
}
static struct ofport *
if (port->bundle && port->bundle->bond) {
bond_slave_set_netdev(port->bundle->bond, port, port->up.netdev);
}
+
+ if (port->cfm) {
+ cfm_set_netdev(port->cfm, port->up.netdev);
+ }
}
static void
}
}
-/* Returns true if STP should process 'flow'. */
+/* Returns true if STP should process 'flow'. Sets fields in 'wc' that
+ * were used to make the determination.*/
static bool
-stp_should_process_flow(const struct flow *flow)
+stp_should_process_flow(const struct flow *flow, struct flow_wildcards *wc)
{
+ memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
return eth_addr_equals(flow->dl_dst, eth_addr_stp);
}
uint64_t slow_stub[128 / 8]; /* Buffer for compose_slow_path() */
struct xlate_out xout;
bool xout_garbage; /* 'xout' needs to be uninitialized? */
+
+ struct ofpbuf mask; /* Flow mask for "put" ops. */
+ struct odputil_keybuf maskbuf;
+
+ /* If this is a "put" op, then a pointer to the subfacet that should
+ * be marked as uninstalled if the operation fails. */
+ struct subfacet *subfacet;
};
/* Sends an OFPT_PACKET_IN message for 'packet' of type OFPR_NO_MATCH to each
}
static enum slow_path_reason
-process_special(struct ofproto_dpif *ofproto, const struct flow *flow,
+process_special(struct xlate_ctx *ctx, const struct flow *flow,
const struct ofport_dpif *ofport, const struct ofpbuf *packet)
{
+ struct ofproto_dpif *ofproto = ctx->ofproto;
+ struct flow_wildcards *wc = &ctx->xout->wc;
+
if (!ofport) {
return 0;
- } else if (ofport->cfm && cfm_should_process_flow(ofport->cfm, flow)) {
+ } else if (ofport->cfm && cfm_should_process_flow(ofport->cfm, flow, wc)) {
if (packet) {
cfm_process_heartbeat(ofport->cfm, packet);
}
lacp_process_packet(ofport->bundle->lacp, ofport, packet);
}
return SLOW_LACP;
- } else if (ofproto->stp && stp_should_process_flow(flow)) {
+ } else if (ofproto->stp && stp_should_process_flow(flow, wc)) {
if (packet) {
stp_process_packet(ofport, packet);
}
eth_pop_vlan(packet);
}
+ op->subfacet = NULL;
op->xout_garbage = false;
op->dpif_op.type = DPIF_OP_EXECUTE;
op->dpif_op.u.execute.key = miss->key;
op->dpif_op.u.execute.key_len = miss->key_len;
op->dpif_op.u.execute.packet = packet;
+ ofpbuf_use_stack(&op->mask, &op->maskbuf, sizeof op->maskbuf);
}
/* Helper for handle_flow_miss_without_facet() and
{
struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
- ofproto->n_matches++;
-
if (rule->up.cr.priority == FAIL_OPEN_PRIORITY) {
/*
* Extra-special case for fail-open mode.
}
/* Figures out whether a flow that missed in 'ofproto', whose details are in
- * 'miss', is likely to be worth tracking in detail in userspace and (usually)
- * installing a datapath flow. The answer is usually "yes" (a return value of
- * true). However, for short flows the cost of bookkeeping is much higher than
- * the benefits, so when the datapath holds a large number of flows we impose
- * some heuristics to decide which flows are likely to be worth tracking. */
+ * 'miss' masked by 'wc', is likely to be worth tracking in detail in userspace
+ * and (usually) installing a datapath flow. The answer is usually "yes" (a
+ * return value of true). However, for short flows the cost of bookkeeping is
+ * much higher than the benefits, so when the datapath holds a large number of
+ * flows we impose some heuristics to decide which flows are likely to be worth
+ * tracking. */
static bool
-flow_miss_should_make_facet(struct ofproto_dpif *ofproto,
- struct flow_miss *miss, uint32_t hash)
+flow_miss_should_make_facet(struct flow_miss *miss, struct flow_wildcards *wc)
{
+ struct ofproto_dpif *ofproto = miss->ofproto;
+ uint32_t hash;
+
if (!ofproto->governor) {
size_t n_subfacets;
ofproto->governor = governor_create(ofproto->up.name);
}
+ hash = flow_hash_in_wildcards(&miss->flow, wc, 0);
return governor_should_install_flow(ofproto->governor, hash,
list_size(&miss->packets));
}
-/* Handles 'miss', which matches 'rule', without creating a facet or subfacet
- * or creating any datapath flow. May add an "execute" operation to 'ops' and
- * increment '*n_ops'. */
+/* Handles 'miss' without creating a facet or subfacet or creating any datapath
+ * flow. 'miss->flow' must have matched 'rule' and been xlated into 'xout'.
+ * May add an "execute" operation to 'ops' and increment '*n_ops'. */
static void
-handle_flow_miss_without_facet(struct flow_miss *miss,
+handle_flow_miss_without_facet(struct rule_dpif *rule, struct xlate_out *xout,
+ struct flow_miss *miss,
struct flow_miss_op *ops, size_t *n_ops)
{
- struct rule_dpif *rule = rule_dpif_lookup(miss->ofproto, &miss->flow);
- long long int now = time_msec();
struct ofpbuf *packet;
- struct xlate_in xin;
LIST_FOR_EACH (packet, list_node, &miss->packets) {
- struct flow_miss_op *op = &ops[*n_ops];
- struct dpif_flow_stats stats;
COVERAGE_INC(facet_suppress);
handle_flow_miss_common(rule, packet, &miss->flow);
- dpif_flow_stats_extract(&miss->flow, packet, now, &stats);
- rule_credit_stats(rule, &stats);
+ if (xout->slow) {
+ struct xlate_in xin;
- xlate_in_init(&xin, miss->ofproto, &miss->flow, &miss->initial_vals,
- rule, stats.tcp_flags, packet);
- xin.resubmit_stats = &stats;
- xlate_actions(&xin, &op->xout);
+ xlate_in_init(&xin, miss->ofproto, &miss->flow,
+ &miss->initial_vals, rule, 0, packet);
+ xlate_actions_for_side_effects(&xin);
+ }
- if (op->xout.odp_actions.size) {
+ if (xout->odp_actions.size) {
+ struct flow_miss_op *op = &ops[*n_ops];
struct dpif_execute *execute = &op->dpif_op.u.execute;
init_flow_miss_execute_op(miss, packet, op);
+ xlate_out_copy(&op->xout, xout);
execute->actions = op->xout.odp_actions.data;
execute->actions_len = op->xout.odp_actions.size;
op->xout_garbage = true;
(*n_ops)++;
- } else {
- xlate_out_uninit(&op->xout);
}
}
}
* here, then the new subfacet or its packets could look (occasionally) as
* though it was used some time after the facet was used. That can make a
* one-packet flow look like it has a nonzero duration, which looks odd in
- * e.g. NetFlow statistics. */
+ * e.g. NetFlow statistics.
+ *
+ * If non-null, 'stats' will be folded into 'facet'. */
static void
handle_flow_miss_with_facet(struct flow_miss *miss, struct facet *facet,
- long long int now,
+ long long int now, struct dpif_flow_stats *stats,
struct flow_miss_op *ops, size_t *n_ops)
{
struct ofproto_dpif *ofproto = ofproto_dpif_cast(facet->rule->up.ofproto);
struct subfacet *subfacet;
struct ofpbuf *packet;
- subfacet = subfacet_create(facet, miss, now);
- want_path = subfacet->facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
+ want_path = facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
LIST_FOR_EACH (packet, list_node, &miss->packets) {
struct flow_miss_op *op = &ops[*n_ops];
- struct dpif_flow_stats stats;
handle_flow_miss_common(facet->rule, packet, &miss->flow);
if (want_path != SF_FAST_PATH) {
struct xlate_in xin;
- xlate_in_init(&xin, ofproto, &facet->flow, &facet->initial_vals,
+ xlate_in_init(&xin, ofproto, &miss->flow, &miss->initial_vals,
facet->rule, 0, packet);
xlate_actions_for_side_effects(&xin);
}
- dpif_flow_stats_extract(&facet->flow, packet, now, &stats);
- subfacet_update_stats(subfacet, &stats);
-
if (facet->xout.odp_actions.size) {
struct dpif_execute *execute = &op->dpif_op.u.execute;
}
}
+ /* Don't install the flow if it's the result of the "userspace"
+ * action for an already installed facet. This can occur when a
+ * datapath flow with wildcards has a "userspace" action and flows
+ * sent to userspace result in a different subfacet, which will then
+ * be rejected as overlapping by the datapath. */
+ if (miss->upcall_type == DPIF_UC_ACTION
+ && !list_is_empty(&facet->subfacets)) {
+ if (stats) {
+ facet->used = MAX(facet->used, stats->used);
+ facet->packet_count += stats->n_packets;
+ facet->byte_count += stats->n_bytes;
+ facet->tcp_flags |= stats->tcp_flags;
+ }
+ return;
+ }
+
+ subfacet = subfacet_create(facet, miss, now);
+ if (stats) {
+ subfacet_update_stats(subfacet, stats);
+ }
+
if (miss->upcall_type == DPIF_UC_MISS || subfacet->path != want_path) {
struct flow_miss_op *op = &ops[(*n_ops)++];
struct dpif_flow_put *put = &op->dpif_op.u.flow_put;
subfacet->path = want_path;
+ ofpbuf_use_stack(&op->mask, &op->maskbuf, sizeof op->maskbuf);
+ if (enable_megaflows) {
+ odp_flow_key_from_mask(&op->mask, &facet->xout.wc.masks,
+ &miss->flow, UINT32_MAX);
+ }
+
op->xout_garbage = false;
op->dpif_op.type = DPIF_OP_FLOW_PUT;
- put->flags = DPIF_FP_CREATE | DPIF_FP_MODIFY;
+ op->subfacet = subfacet;
+ put->flags = DPIF_FP_CREATE;
put->key = miss->key;
put->key_len = miss->key_len;
+ put->mask = op->mask.data;
+ put->mask_len = op->mask.size;
+
if (want_path == SF_FAST_PATH) {
put->actions = facet->xout.odp_actions.data;
put->actions_len = facet->xout.odp_actions.size;
} else {
- compose_slow_path(ofproto, &facet->flow, facet->xout.slow,
+ compose_slow_path(ofproto, &miss->flow, facet->xout.slow,
op->slow_stub, sizeof op->slow_stub,
&put->actions, &put->actions_len);
}
size_t *n_ops)
{
struct ofproto_dpif *ofproto = miss->ofproto;
+ struct dpif_flow_stats stats__;
+ struct dpif_flow_stats *stats = &stats__;
+ struct ofpbuf *packet;
struct facet *facet;
long long int now;
- uint32_t hash;
- /* The caller must ensure that miss->hmap_node.hash contains
- * flow_hash(miss->flow, 0). */
- hash = miss->hmap_node.hash;
+ now = time_msec();
+ memset(stats, 0, sizeof *stats);
+ stats->used = now;
+ LIST_FOR_EACH (packet, list_node, &miss->packets) {
+ stats->tcp_flags |= packet_get_tcp_flags(packet, &miss->flow);
+ stats->n_bytes += packet->size;
+ stats->n_packets++;
+ }
- facet = facet_lookup_valid(ofproto, &miss->flow, hash);
+ facet = facet_lookup_valid(ofproto, &miss->flow);
if (!facet) {
+ struct flow_wildcards wc;
+ struct rule_dpif *rule;
+ struct xlate_out xout;
+ struct xlate_in xin;
+
+ flow_wildcards_init_catchall(&wc);
+ rule = rule_dpif_lookup(ofproto, &miss->flow, &wc);
+ rule_credit_stats(rule, stats);
+
+ xlate_in_init(&xin, ofproto, &miss->flow, &miss->initial_vals, rule,
+ stats->tcp_flags, NULL);
+ xin.resubmit_stats = stats;
+ xin.may_learn = true;
+ xlate_actions(&xin, &xout);
+ flow_wildcards_or(&xout.wc, &xout.wc, &wc);
+
/* There does not exist a bijection between 'struct flow' and datapath
* flow keys with fitness ODP_FIT_TO_LITTLE. This breaks a fundamental
* assumption used throughout the facet and subfacet handling code.
* Since we have to handle these misses in userspace anyway, we simply
- * skip facet creation, avoiding the problem alltogether. */
+ * skip facet creation, avoiding the problem altogether. */
if (miss->key_fitness == ODP_FIT_TOO_LITTLE
- || !flow_miss_should_make_facet(ofproto, miss, hash)) {
- handle_flow_miss_without_facet(miss, ops, n_ops);
+ || !flow_miss_should_make_facet(miss, &xout.wc)) {
+ handle_flow_miss_without_facet(rule, &xout, miss, ops, n_ops);
return;
}
- facet = facet_create(miss, hash);
- now = facet->used;
- } else {
- now = time_msec();
+ facet = facet_create(miss, rule, &xout, stats);
+ stats = NULL;
}
- handle_flow_miss_with_facet(miss, facet, now, ops, n_ops);
+ handle_flow_miss_with_facet(miss, facet, now, stats, ops, n_ops);
}
static struct drop_key *
hmap_insert(&backer->drop_keys, &drop_key->hmap_node,
hash_bytes(drop_key->key, drop_key->key_len, 0));
dpif_flow_put(backer->dpif, DPIF_FP_CREATE | DPIF_FP_MODIFY,
- drop_key->key, drop_key->key_len, NULL, 0, NULL);
+ drop_key->key, drop_key->key_len,
+ NULL, 0, NULL, 0, NULL);
}
continue;
}
}
dpif_operate(backer->dpif, dpif_ops, n_ops);
- /* Free memory. */
for (i = 0; i < n_ops; i++) {
+ if (dpif_ops[i]->error != 0
+ && flow_miss_ops[i].dpif_op.type == DPIF_OP_FLOW_PUT
+ && flow_miss_ops[i].subfacet) {
+ struct subfacet *subfacet = flow_miss_ops[i].subfacet;
+
+ COVERAGE_INC(subfacet_install_fail);
+
+ /* Zero-out subfacet counters when installation failed, but
+ * datapath reported hits. This should not happen and
+ * indicates a bug, since if the datapath flow exists, we
+ * should not be attempting to create a new subfacet. A
+ * buggy datapath could trigger this, so just zero out the
+ * counters and log an error. */
+ if (subfacet->dp_packet_count || subfacet->dp_byte_count) {
+ VLOG_ERR_RL(&rl, "failed to install subfacet for which "
+ "datapath reported hits");
+ subfacet->dp_packet_count = subfacet->dp_byte_count = 0;
+ }
+
+ subfacet->path = SF_NOT_INSTALLED;
+ }
+
+ /* Free memory. */
if (flow_miss_ops[i].xout_garbage) {
xlate_out_uninit(&flow_miss_ops[i].xout);
}
const struct dpif_flow_stats *stats)
{
struct facet *facet = subfacet->facet;
+ struct dpif_flow_stats diff;
+
+ diff.tcp_flags = stats->tcp_flags;
+ diff.used = stats->used;
if (stats->n_packets >= subfacet->dp_packet_count) {
- uint64_t extra = stats->n_packets - subfacet->dp_packet_count;
- facet->packet_count += extra;
+ diff.n_packets = stats->n_packets - subfacet->dp_packet_count;
} else {
VLOG_WARN_RL(&rl, "unexpected packet count from the datapath");
+ diff.n_packets = 0;
}
if (stats->n_bytes >= subfacet->dp_byte_count) {
- facet->byte_count += stats->n_bytes - subfacet->dp_byte_count;
+ diff.n_bytes = stats->n_bytes - subfacet->dp_byte_count;
} else {
VLOG_WARN_RL(&rl, "unexpected byte count from datapath");
+ diff.n_bytes = 0;
}
subfacet->dp_packet_count = stats->n_packets;
subfacet->dp_byte_count = stats->n_bytes;
+ subfacet_update_stats(subfacet, &diff);
- facet->tcp_flags |= stats->tcp_flags;
-
- subfacet_update_time(subfacet, stats->used);
if (facet->accounted_bytes < facet->byte_count) {
facet_learn(facet);
facet_account(facet);
{
const struct dpif_flow_stats *stats;
struct dpif_flow_dump dump;
- const struct nlattr *key;
struct ofproto_dpif *ofproto;
- size_t key_len;
+ const struct nlattr *key, *mask;
+ size_t key_len, mask_len;
dpif_flow_dump_start(&dump, backer->dpif);
- while (dpif_flow_dump_next(&dump, &key, &key_len, NULL, NULL, &stats)) {
+ while (dpif_flow_dump_next(&dump, &key, &key_len,
+ &mask, &mask_len, NULL, NULL, &stats)) {
struct flow flow;
struct subfacet *subfacet;
- struct ofport_dpif *ofport;
uint32_t key_hash;
if (ofproto_receive(backer, NULL, key, key_len, &flow, NULL, &ofproto,
ofproto->total_subfacet_count += hmap_count(&ofproto->subfacets);
ofproto->n_update_stats++;
- ofport = get_ofp_port(ofproto, flow.in_port);
- if (ofport && ofport->tnl_port) {
- netdev_vport_inc_rx(ofport->up.netdev, stats);
- }
-
key_hash = odp_flow_key_hash(key, key_len);
subfacet = subfacet_find(ofproto, key, key_len, key_hash);
switch (subfacet ? subfacet->path : SF_NOT_INSTALLED) {
* The caller must already have determined that no facet with an identical
* 'miss->flow' exists in 'miss->ofproto'.
*
- * 'hash' must be the return value of flow_hash(miss->flow, 0).
+ * 'rule' and 'xout' must have been created based on 'miss'.
+ *
+ * 'facet'' statistics are initialized based on 'stats'.
*
* The facet will initially have no subfacets. The caller should create (at
* least) one subfacet with subfacet_create(). */
static struct facet *
-facet_create(const struct flow_miss *miss, uint32_t hash)
+facet_create(const struct flow_miss *miss, struct rule_dpif *rule,
+ struct xlate_out *xout, struct dpif_flow_stats *stats)
{
struct ofproto_dpif *ofproto = miss->ofproto;
- struct xlate_in xin;
struct facet *facet;
+ struct match match;
facet = xzalloc(sizeof *facet);
- facet->used = time_msec();
+ facet->packet_count = facet->prev_packet_count = stats->n_packets;
+ facet->byte_count = facet->prev_byte_count = stats->n_bytes;
+ facet->tcp_flags = stats->tcp_flags;
+ facet->used = stats->used;
facet->flow = miss->flow;
facet->initial_vals = miss->initial_vals;
- facet->rule = rule_dpif_lookup(ofproto, &facet->flow);
facet->learn_rl = time_msec() + 500;
+ facet->rule = rule;
- hmap_insert(&ofproto->facets, &facet->hmap_node, hash);
list_push_back(&facet->rule->facets, &facet->list_node);
list_init(&facet->subfacets);
netflow_flow_init(&facet->nf_flow);
netflow_flow_update_time(ofproto->netflow, &facet->nf_flow, facet->used);
- xlate_in_init(&xin, ofproto, &facet->flow, &facet->initial_vals,
- facet->rule, 0, NULL);
- xin.may_learn = true;
- xlate_actions(&xin, &facet->xout);
+ xlate_out_copy(&facet->xout, xout);
+
+ match_init(&match, &facet->flow, &facet->xout.wc);
+ cls_rule_init(&facet->cr, &match, OFP_DEFAULT_PRIORITY);
+ classifier_insert(&ofproto->facets, &facet->cr);
+
facet->nf_flow.output_iface = facet->xout.nf_output_iface;
return facet;
return !error;
}
-/* Remove 'facet' from 'ofproto' and free up the associated memory:
+/* Remove 'facet' from its ofproto and free up the associated memory:
*
* - If 'facet' was installed in the datapath, uninstalls it and updates its
* rule's statistics, via subfacet_uninstall().
&facet->subfacets) {
subfacet_destroy__(subfacet);
}
- hmap_remove(&ofproto->facets, &facet->hmap_node);
+ classifier_remove(&ofproto->facets, &facet->cr);
+ cls_rule_destroy(&facet->cr);
list_remove(&facet->list_node);
facet_free(facet);
}
static void
facet_learn(struct facet *facet)
{
- struct ofproto_dpif *ofproto = ofproto_dpif_cast(facet->rule->up.ofproto);
long long int now = time_msec();
- struct xlate_in xin;
if (!facet->xout.has_fin_timeout && now < facet->learn_rl) {
return;
return;
}
- xlate_in_init(&xin, ofproto, &facet->flow, &facet->initial_vals,
- facet->rule, facet->tcp_flags, NULL);
- xin.may_learn = true;
- xlate_actions_for_side_effects(&xin);
+ facet_push_stats(facet, true);
}
static void
ovs_assert(!subfacet->dp_packet_count);
}
- facet_push_stats(facet);
+ facet_push_stats(facet, false);
if (facet->accounted_bytes < facet->byte_count) {
facet_account(facet);
facet->accounted_bytes = facet->byte_count;
netflow_expire(ofproto->netflow, &facet->nf_flow, &expired);
}
- facet->rule->packet_count += facet->packet_count;
- facet->rule->byte_count += facet->byte_count;
-
/* Reset counters to prevent double counting if 'facet' ever gets
* reinstalled. */
facet_reset_counters(facet);
facet->tcp_flags = 0;
}
-/* Searches 'ofproto''s table of facets for one exactly equal to 'flow'.
- * Returns it if found, otherwise a null pointer.
- *
- * 'hash' must be the return value of flow_hash(flow, 0).
+/* Searches 'ofproto''s table of facets for one which would be responsible for
+ * 'flow'. Returns it if found, otherwise a null pointer.
*
* The returned facet might need revalidation; use facet_lookup_valid()
* instead if that is important. */
static struct facet *
-facet_find(struct ofproto_dpif *ofproto,
- const struct flow *flow, uint32_t hash)
+facet_find(struct ofproto_dpif *ofproto, const struct flow *flow)
{
- struct facet *facet;
-
- HMAP_FOR_EACH_WITH_HASH (facet, hmap_node, hash, &ofproto->facets) {
- if (flow_equal(flow, &facet->flow)) {
- return facet;
- }
- }
-
- return NULL;
+ struct cls_rule *cr = classifier_lookup(&ofproto->facets, flow, NULL);
+ return cr ? CONTAINER_OF(cr, struct facet, cr) : NULL;
}
-/* Searches 'ofproto''s table of facets for one exactly equal to 'flow'.
- * Returns it if found, otherwise a null pointer.
- *
- * 'hash' must be the return value of flow_hash(flow, 0).
+/* Searches 'ofproto''s table of facets for one capable that covers
+ * 'flow'. Returns it if found, otherwise a null pointer.
*
* The returned facet is guaranteed to be valid. */
static struct facet *
-facet_lookup_valid(struct ofproto_dpif *ofproto, const struct flow *flow,
- uint32_t hash)
+facet_lookup_valid(struct ofproto_dpif *ofproto, const struct flow *flow)
{
struct facet *facet;
- facet = facet_find(ofproto, flow, hash);
+ facet = facet_find(ofproto, flow);
if (facet
&& (ofproto->backer->need_revalidate
|| tag_set_intersects(&ofproto->backer->revalidate_set,
bool ok;
/* Check the rule for consistency. */
- rule = rule_dpif_lookup(ofproto, &facet->flow);
+ rule = rule_dpif_lookup(ofproto, &facet->flow, NULL);
if (rule != facet->rule) {
if (!VLOG_DROP_WARN(&rl)) {
struct ds s = DS_EMPTY_INITIALIZER;
struct ofproto_dpif *ofproto = ofproto_dpif_cast(facet->rule->up.ofproto);
struct rule_dpif *new_rule;
struct subfacet *subfacet;
+ struct flow_wildcards wc;
struct xlate_out xout;
struct xlate_in xin;
&recv_ofproto, NULL, NULL);
if (error
|| recv_ofproto != ofproto
- || memcmp(&recv_flow, &facet->flow, sizeof recv_flow)) {
+ || facet != facet_find(ofproto, &recv_flow)) {
facet_remove(facet);
return false;
}
}
- new_rule = rule_dpif_lookup(ofproto, &facet->flow);
+ flow_wildcards_init_catchall(&wc);
+ new_rule = rule_dpif_lookup(ofproto, &facet->flow, &wc);
/* Calculate new datapath actions.
*
xlate_in_init(&xin, ofproto, &facet->flow, &facet->initial_vals, new_rule,
0, NULL);
xlate_actions(&xin, &xout);
+ flow_wildcards_or(&xout.wc, &xout.wc, &wc);
/* A facet's slow path reason should only change under dramatic
* circumstances. Rather than try to update everything, it's simpler to
- * remove the facet and start over. */
- if (facet->xout.slow != xout.slow) {
+ * remove the facet and start over.
+ *
+ * More importantly, if a facet's wildcards change, it will be relatively
+ * difficult to figure out if its subfacets still belong to it, and if not
+ * which facet they may belong to. Again, to avoid the complexity, we
+ * simply give up instead. */
+ if (facet->xout.slow != xout.slow
+ || memcmp(&facet->xout.wc, &xout.wc, sizeof xout.wc)) {
facet_remove(facet);
xlate_out_uninit(&xout);
return false;
return true;
}
-/* Updates 'facet''s used time. Caller is responsible for calling
- * facet_push_stats() to update the flows which 'facet' resubmits into. */
-static void
-facet_update_time(struct facet *facet, long long int used)
-{
- struct ofproto_dpif *ofproto = ofproto_dpif_cast(facet->rule->up.ofproto);
- if (used > facet->used) {
- facet->used = used;
- ofproto_rule_update_used(&facet->rule->up, used);
- netflow_flow_update_time(ofproto->netflow, &facet->nf_flow, used);
- }
-}
-
static void
facet_reset_counters(struct facet *facet)
{
}
static void
-facet_push_stats(struct facet *facet)
+facet_push_stats(struct facet *facet, bool may_learn)
{
struct dpif_flow_stats stats;
stats.n_packets = facet->packet_count - facet->prev_packet_count;
stats.n_bytes = facet->byte_count - facet->prev_byte_count;
stats.used = facet->used;
- stats.tcp_flags = 0;
+ stats.tcp_flags = facet->tcp_flags;
+
+ if (may_learn || stats.n_packets || facet->used > facet->prev_used) {
+ struct ofproto_dpif *ofproto =
+ ofproto_dpif_cast(facet->rule->up.ofproto);
+
+ struct ofport_dpif *in_port;
+ struct xlate_in xin;
- if (stats.n_packets || stats.n_bytes || facet->used > facet->prev_used) {
facet->prev_packet_count = facet->packet_count;
facet->prev_byte_count = facet->byte_count;
facet->prev_used = facet->used;
- flow_push_stats(facet, &stats);
+ in_port = get_ofp_port(ofproto, facet->flow.in_port);
+ if (in_port && in_port->tnl_port) {
+ netdev_vport_inc_rx(in_port->up.netdev, &stats);
+ }
- update_mirror_stats(ofproto_dpif_cast(facet->rule->up.ofproto),
- facet->xout.mirrors, stats.n_packets,
+ rule_credit_stats(facet->rule, &stats);
+ netflow_flow_update_time(ofproto->netflow, &facet->nf_flow,
+ facet->used);
+ netflow_flow_update_flags(&facet->nf_flow, facet->tcp_flags);
+ update_mirror_stats(ofproto, facet->xout.mirrors, stats.n_packets,
stats.n_bytes);
+
+ xlate_in_init(&xin, ofproto, &facet->flow, &facet->initial_vals,
+ facet->rule, stats.tcp_flags, NULL);
+ xin.resubmit_stats = &stats;
+ xin.may_learn = may_learn;
+ xlate_actions_for_side_effects(&xin);
}
}
}
HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
+ struct cls_cursor cursor;
struct facet *facet;
- HMAP_FOR_EACH (facet, hmap_node, &ofproto->facets) {
- facet_push_stats(facet);
+ cls_cursor_init(&cursor, &ofproto->facets, NULL);
+ CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
+ facet_push_stats(facet, false);
if (run_fast) {
run_fast_rl();
}
rule->byte_count += stats->n_bytes;
ofproto_rule_update_used(&rule->up, stats->used);
}
-
-/* Pushes flow statistics to the rules which 'facet->flow' resubmits
- * into given 'facet->rule''s actions and mirrors. */
-static void
-flow_push_stats(struct facet *facet, const struct dpif_flow_stats *stats)
-{
- struct rule_dpif *rule = facet->rule;
- struct ofproto_dpif *ofproto = ofproto_dpif_cast(rule->up.ofproto);
- struct xlate_in xin;
-
- ofproto_rule_update_used(&rule->up, stats->used);
-
- xlate_in_init(&xin, ofproto, &facet->flow, &facet->initial_vals, rule,
- 0, NULL);
- xin.resubmit_stats = stats;
- xlate_actions_for_side_effects(&xin);
-}
\f
/* Subfacets. */
enum subfacet_path path = facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
const struct nlattr *actions = odp_actions->data;
size_t actions_len = odp_actions->size;
+ struct odputil_keybuf maskbuf;
+ struct ofpbuf mask;
uint64_t slow_path_stub[128 / 8];
enum dpif_flow_put_flags flags;
int ret;
- flags = DPIF_FP_CREATE | DPIF_FP_MODIFY;
+ flags = subfacet->path == SF_NOT_INSTALLED ? DPIF_FP_CREATE
+ : DPIF_FP_MODIFY;
if (stats) {
flags |= DPIF_FP_ZERO_STATS;
}
&actions, &actions_len);
}
+ ofpbuf_use_stack(&mask, &maskbuf, sizeof maskbuf);
+ if (enable_megaflows) {
+ odp_flow_key_from_mask(&mask, &facet->xout.wc.masks,
+ &facet->flow, UINT32_MAX);
+ }
+
ret = dpif_flow_put(ofproto->backer->dpif, flags, subfacet->key,
- subfacet->key_len, actions, actions_len, stats);
+ subfacet->key_len, mask.data, mask.size,
+ actions, actions_len, stats);
if (stats) {
subfacet_reset_dp_stats(subfacet, stats);
}
- if (!ret) {
+ if (ret) {
+ COVERAGE_INC(subfacet_install_fail);
+ } else {
subfacet->path = path;
}
return ret;
subfacet->dp_byte_count = 0;
}
-/* Updates 'subfacet''s used time. The caller is responsible for calling
- * facet_push_stats() to update the flows which 'subfacet' resubmits into. */
-static void
-subfacet_update_time(struct subfacet *subfacet, long long int used)
-{
- if (used > subfacet->used) {
- subfacet->used = used;
- facet_update_time(subfacet->facet, used);
- }
-}
-
/* Folds the statistics from 'stats' into the counters in 'subfacet'.
*
* Because of the meaning of a subfacet's counters, it only makes sense to do
if (stats->n_packets || stats->used > subfacet->used) {
struct facet *facet = subfacet->facet;
- subfacet_update_time(subfacet, stats->used);
+ subfacet->used = MAX(subfacet->used, stats->used);
+ facet->used = MAX(facet->used, stats->used);
facet->packet_count += stats->n_packets;
facet->byte_count += stats->n_bytes;
facet->tcp_flags |= stats->tcp_flags;
- netflow_flow_update_flags(&facet->nf_flow, stats->tcp_flags);
}
}
\f
/* Rules. */
+/* Lookup 'flow' in 'ofproto''s classifier. If 'wc' is non-null, sets
+ * the fields that were relevant as part of the lookup. */
static struct rule_dpif *
-rule_dpif_lookup(struct ofproto_dpif *ofproto, const struct flow *flow)
+rule_dpif_lookup(struct ofproto_dpif *ofproto, const struct flow *flow,
+ struct flow_wildcards *wc)
{
struct rule_dpif *rule;
- rule = rule_dpif_lookup__(ofproto, flow, 0);
+ rule = rule_dpif_lookup__(ofproto, flow, wc, 0);
if (rule) {
return rule;
}
static struct rule_dpif *
rule_dpif_lookup__(struct ofproto_dpif *ofproto, const struct flow *flow,
- uint8_t table_id)
+ struct flow_wildcards *wc, uint8_t table_id)
{
struct cls_rule *cls_rule;
struct classifier *cls;
+ bool frag;
if (table_id >= N_TABLES) {
return NULL;
}
+ if (wc) {
+ memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
+ wc->masks.nw_frag |= FLOW_NW_FRAG_MASK;
+ }
+
cls = &ofproto->up.tables[table_id].cls;
- if (flow->nw_frag & FLOW_NW_FRAG_ANY
- && ofproto->up.frag_handling == OFPC_FRAG_NORMAL) {
- /* For OFPC_NORMAL frag_handling, we must pretend that transport ports
- * are unavailable. */
+ frag = (flow->nw_frag & FLOW_NW_FRAG_ANY) != 0;
+ if (frag && ofproto->up.frag_handling == OFPC_FRAG_NORMAL) {
+ /* We must pretend that transport ports are unavailable. */
struct flow ofpc_normal_flow = *flow;
ofpc_normal_flow.tp_src = htons(0);
ofpc_normal_flow.tp_dst = htons(0);
- cls_rule = classifier_lookup(cls, &ofpc_normal_flow);
+ cls_rule = classifier_lookup(cls, &ofpc_normal_flow, wc);
+ } else if (frag && ofproto->up.frag_handling == OFPC_FRAG_DROP) {
+ cls_rule = &ofproto->drop_frags_rule->up.cr;
+ if (wc) {
+ flow_wildcards_init_exact(wc);
+ }
} else {
- cls_rule = classifier_lookup(cls, flow);
+ cls_rule = classifier_lookup(cls, flow, wc);
}
return rule_dpif_cast(rule_from_cls_rule(cls_rule));
}
rule_get_stats(struct rule *rule_, uint64_t *packets, uint64_t *bytes)
{
struct rule_dpif *rule = rule_dpif_cast(rule_);
- struct facet *facet;
/* push_all_stats() can handle flow misses which, when using the learn
* action, can cause rules to be added and deleted. This can corrupt our
* in facets. This counts, for example, facets that have expired. */
*packets = rule->packet_count;
*bytes = rule->byte_count;
-
- /* Add any statistics that are tracked by facets. This includes
- * statistical data recently updated by ofproto_update_stats() as well as
- * stats for packets that were executed "by hand" via dpif_execute(). */
- LIST_FOR_EACH (facet, list_node, &rule->facets) {
- *packets += facet->packet_count;
- *bytes += facet->byte_count;
- }
}
static void
flow.in_port = peer->up.ofp_port;
peer_ofproto = ofproto_dpif_cast(peer->up.ofproto);
- rule = rule_dpif_lookup(peer_ofproto, &flow);
+ rule = rule_dpif_lookup(peer_ofproto, &flow, NULL);
rule_dpif_execute(rule, &flow, packet);
return 0;
ofpbuf_use_stub(&odp_actions, odp_actions_stub, sizeof odp_actions_stub);
if (ofport->tnl_port) {
+ struct flow_wildcards wc;
struct dpif_flow_stats stats;
- odp_port = tnl_port_send(ofport->tnl_port, &flow);
+ odp_port = tnl_port_send(ofport->tnl_port, &flow, &wc);
if (odp_port == OVSP_NONE) {
return ENODEV;
}
bool check_stp)
{
const struct ofport_dpif *ofport = get_ofp_port(ctx->ofproto, ofp_port);
+ struct flow_wildcards *wc = &ctx->xout->wc;
ovs_be16 flow_vlan_tci;
uint32_t flow_skb_mark;
uint8_t flow_nw_tos;
memset(ctx->xin->flow.regs, 0, sizeof ctx->xin->flow.regs);
in_port = get_ofp_port(ctx->ofproto, ctx->xin->flow.in_port);
- special = process_special(ctx->ofproto, &ctx->xin->flow, in_port,
+ special = process_special(ctx, &ctx->xin->flow, in_port,
ctx->xin->packet);
if (special) {
ctx->xout->slow = special;
pdscp = get_priority(ofport, ctx->xin->flow.skb_priority);
if (pdscp) {
+ wc->masks.nw_tos |= IP_ECN_MASK;
ctx->xin->flow.nw_tos &= ~IP_DSCP_MASK;
ctx->xin->flow.nw_tos |= pdscp->dscp;
}
* matches, while explicit set actions on tunnel metadata are.
*/
struct flow_tnl flow_tnl = ctx->xin->flow.tunnel;
- odp_port = tnl_port_send(ofport->tnl_port, &ctx->xin->flow);
+ odp_port = tnl_port_send(ofport->tnl_port, &ctx->xin->flow,
+ &ctx->xout->wc);
if (odp_port == OVSP_NONE) {
xlate_report(ctx, "Tunneling decided against output");
goto out; /* restore flow_nw_tos */
&ctx->xout->odp_actions);
ctx->xin->flow.tunnel = flow_tnl; /* Restore tunnel metadata */
} else {
+ uint16_t vlandev_port;
+
odp_port = ofport->odp_port;
- out_port = vsp_realdev_to_vlandev(ctx->ofproto, odp_port,
- ctx->xin->flow.vlan_tci);
- if (out_port != odp_port) {
+ if (!hmap_is_empty(&ctx->ofproto->realdev_vid_map)) {
+ wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
+ }
+ vlandev_port = vsp_realdev_to_vlandev(ctx->ofproto, ofp_port,
+ ctx->xin->flow.vlan_tci);
+ if (vlandev_port == ofp_port) {
+ out_port = odp_port;
+ } else {
+ out_port = ofp_port_to_odp_port(ctx->ofproto, vlandev_port);
ctx->xin->flow.vlan_tci = htons(0);
}
ctx->xin->flow.skb_mark &= ~IPSEC_MARK;
}
commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
- &ctx->xout->odp_actions);
+ &ctx->xout->odp_actions, &ctx->xout->wc);
nl_msg_put_u32(&ctx->xout->odp_actions, OVS_ACTION_ATTR_OUTPUT, out_port);
ctx->sflow_odp_port = odp_port;
/* Look up a flow with 'in_port' as the input port. */
ctx->xin->flow.in_port = in_port;
- rule = rule_dpif_lookup__(ctx->ofproto, &ctx->xin->flow, table_id);
+ rule = rule_dpif_lookup__(ctx->ofproto, &ctx->xin->flow,
+ &ctx->xout->wc, table_id);
tag_the_flow(ctx, rule);
static void
execute_mpls_push_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
{
+ struct flow_wildcards *wc = &ctx->xout->wc;
ovs_assert(eth_type_mpls(eth_type));
+ memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
+ memset(&wc->masks.mpls_depth, 0xff, sizeof wc->masks.mpls_depth);
+
if (ctx->base_flow.mpls_depth) {
ctx->xin->flow.mpls_lse &= ~htonl(MPLS_BOS_MASK);
ctx->xin->flow.mpls_depth++;
} else {
label = htonl(0x0); /* IPV4 Explicit Null. */
}
+ wc->masks.nw_tos |= IP_DSCP_MASK;
+ wc->masks.nw_ttl = 0xff;
tc = (ctx->xin->flow.nw_tos & IP_DSCP_MASK) >> 2;
ttl = ctx->xin->flow.nw_ttl ? ctx->xin->flow.nw_ttl : 0x40;
ctx->xin->flow.mpls_lse = set_mpls_lse_values(ttl, tc, 1, label);
static void
execute_mpls_pop_action(struct xlate_ctx *ctx, ovs_be16 eth_type)
{
+ struct flow_wildcards *wc = &ctx->xout->wc;
+
ovs_assert(eth_type_mpls(ctx->xin->flow.dl_type));
ovs_assert(!eth_type_mpls(eth_type));
+ memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
+ memset(&wc->masks.mpls_depth, 0xff, sizeof wc->masks.mpls_depth);
+
if (ctx->xin->flow.mpls_depth) {
ctx->xin->flow.mpls_depth--;
ctx->xin->flow.mpls_lse = htonl(0);
return false;
}
+ ctx->xout->wc.masks.nw_ttl = 0xff;
if (ctx->xin->flow.nw_ttl > 1) {
ctx->xin->flow.nw_ttl--;
return false;
execute_dec_mpls_ttl_action(struct xlate_ctx *ctx)
{
uint8_t ttl = mpls_lse_to_ttl(ctx->xin->flow.mpls_lse);
+ struct flow_wildcards *wc = &ctx->xout->wc;
+
+ memset(&wc->masks.mpls_lse, 0xff, sizeof wc->masks.mpls_lse);
if (!eth_type_mpls(ctx->xin->flow.dl_type)) {
return false;
{
uint64_t port = mf_get_subfield(&or->src, &ctx->xin->flow);
if (port <= UINT16_MAX) {
+ union mf_subvalue value;
+
+ memset(&value, 0xff, sizeof value);
+ mf_write_subfield_flow(&or->src, &value, &ctx->xout->wc.masks);
xlate_output_action(ctx, port, or->max_len, false);
}
}
{
uint16_t port;
- port = bundle_execute(bundle, &ctx->xin->flow, slave_enabled_cb,
- ctx->ofproto);
+ port = bundle_execute(bundle, &ctx->xin->flow, &ctx->xout->wc,
+ slave_enabled_cb, ctx->ofproto);
if (bundle->dst.field) {
nxm_reg_load(&bundle->dst, port, &ctx->xin->flow);
} else {
struct ofpbuf ofpacts;
int error;
+ ctx->xout->has_learn = true;
+
+ learn_mask(learn, &ctx->xout->wc);
+
+ if (!ctx->xin->may_learn) {
+ return;
+ }
+
ofpbuf_use_stack(&ofpacts, ofpacts_stub, sizeof ofpacts_stub);
learn_execute(learn, &ctx->xin->flow, &fm, &ofpacts);
if (ctx->xin->tcp_flags & (TCP_FIN | TCP_RST) && ctx->rule) {
struct rule_dpif *rule = ctx->rule;
+ if (list_is_empty(&rule->up.expirable)) {
+ list_insert(&ctx->ofproto->up.expirable, &rule->up.expirable);
+ }
+
reduce_timeout(oft->fin_idle_timeout, &rule->up.idle_timeout);
reduce_timeout(oft->fin_hard_timeout, &rule->up.hard_timeout);
}
uint32_t probability = (os->probability << 16) | os->probability;
commit_odp_actions(&ctx->xin->flow, &ctx->base_flow,
- &ctx->xout->odp_actions);
+ &ctx->xout->odp_actions, &ctx->xout->wc);
compose_flow_sample_cookie(os->probability, os->collector_set_id,
os->obs_domain_id, os->obs_point_id, &cookie);
break;
case OFPACT_SET_L4_SRC_PORT:
+ memset(&ctx->xout->wc.masks.nw_proto, 0xff,
+ sizeof ctx->xout->wc.masks.nw_proto);
if (is_ip_any(&ctx->xin->flow)) {
ctx->xin->flow.tp_src =
htons(ofpact_get_SET_L4_SRC_PORT(a)->port);
break;
case OFPACT_SET_L4_DST_PORT:
+ memset(&ctx->xout->wc.masks.nw_proto, 0xff,
+ sizeof ctx->xout->wc.masks.nw_proto);
if (is_ip_any(&ctx->xin->flow)) {
ctx->xin->flow.tp_dst =
htons(ofpact_get_SET_L4_DST_PORT(a)->port);
break;
case OFPACT_REG_MOVE:
- nxm_execute_reg_move(ofpact_get_REG_MOVE(a), &ctx->xin->flow);
+ nxm_execute_reg_move(ofpact_get_REG_MOVE(a), &ctx->xin->flow,
+ &ctx->xout->wc);
break;
case OFPACT_REG_LOAD:
case OFPACT_STACK_PUSH:
nxm_execute_stack_push(ofpact_get_STACK_PUSH(a), &ctx->xin->flow,
- &ctx->stack);
+ &ctx->xout->wc, &ctx->stack);
break;
case OFPACT_STACK_POP:
break;
case OFPACT_MULTIPATH:
- multipath_execute(ofpact_get_MULTIPATH(a), &ctx->xin->flow);
+ multipath_execute(ofpact_get_MULTIPATH(a), &ctx->xin->flow,
+ &ctx->xout->wc);
break;
case OFPACT_BUNDLE:
break;
case OFPACT_LEARN:
- ctx->xout->has_learn = true;
- if (ctx->xin->may_learn) {
- xlate_learn_action(ctx, ofpact_get_LEARN(a));
- }
+ xlate_learn_action(ctx, ofpact_get_LEARN(a));
break;
case OFPACT_EXIT:
break;
case OFPACT_FIN_TIMEOUT:
+ memset(&ctx->xout->wc.masks.nw_proto, 0xff,
+ sizeof ctx->xout->wc.masks.nw_proto);
ctx->xout->has_fin_timeout = true;
xlate_fin_timeout(ctx, ofpact_get_FIN_TIMEOUT(a));
break;
ctx->table_id = ogt->table_id;
/* Look up a flow from the new table. */
- rule = rule_dpif_lookup__(ctx->ofproto, &ctx->xin->flow, ctx->table_id);
+ rule = rule_dpif_lookup__(ctx->ofproto, &ctx->xin->flow,
+ &ctx->xout->wc, ctx->table_id);
tag_the_flow(ctx, rule);
* that in the future we always keep a copy of the original flow for
* tracing purposes. */
static bool hit_resubmit_limit;
+ struct flow_wildcards *wc = &xout->wc;
enum slow_path_reason special;
const struct ofpact *ofpacts;
* to another device without any modifications this will cause us to
* insert a new tag since the original one was stripped off by the
* VLAN device.
- * - Tunnel 'flow' is largely cleared when transitioning between
- * the input and output stages since it does not make sense to output
- * a packet with the exact headers that it was received with (i.e.
- * the destination IP is us). The one exception is the tun_id, which
- * is preserved to allow use in later resubmit lookups and loads into
- * registers.
+ * - Tunnel metadata as received is retained in 'flow'. This allows
+ * tunnel metadata matching also in later tables.
+ * Since a kernel action for setting the tunnel metadata will only be
+ * generated with actual tunnel output, changing the tunnel metadata
+ * values in 'flow' (such as tun_id) will only have effect with a later
+ * tunnel output action.
* - Tunnel 'base_flow' is completely cleared since that is what the
* kernel does. If we wish to maintain the original values an action
* needs to be generated. */
ctx.base_flow.vlan_tci = xin->initial_vals.vlan_tci;
ctx.base_flow.tunnel.ip_tos = xin->initial_vals.tunnel_ip_tos;
+ flow_wildcards_init_catchall(&ctx.xout->wc);
+ memset(&wc->masks.in_port, 0xff, sizeof wc->masks.in_port);
+ memset(&wc->masks.skb_priority, 0xff, sizeof wc->masks.skb_priority);
+ memset(&wc->masks.dl_type, 0xff, sizeof wc->masks.dl_type);
+ wc->masks.nw_frag |= FLOW_NW_FRAG_MASK;
+
+ if (tnl_port_should_receive(&ctx.xin->flow)) {
+ memset(&wc->masks.tunnel, 0xff, sizeof wc->masks.tunnel);
+ }
+
+ /* Disable most wildcarding for NetFlow. */
+ if (xin->ofproto->netflow) {
+ netflow_mask_wc(&ctx.xin->flow, wc);
+ }
+
ctx.xout->tags = 0;
ctx.xout->slow = 0;
ctx.xout->has_learn = false;
}
in_port = get_ofp_port(ctx.ofproto, ctx.xin->flow.in_port);
- special = process_special(ctx.ofproto, &ctx.xin->flow, in_port,
+ special = process_special(&ctx, &ctx.xin->flow, in_port,
ctx.xin->packet);
if (special) {
ctx.xout->slow = special;
}
ofpbuf_uninit(&ctx.stack);
+
+ /* Clear the metadata and register wildcard masks, because we won't
+ * use non-header fields as part of the cache. */
+ memset(&ctx.xout->wc.masks.metadata, 0,
+ sizeof ctx.xout->wc.masks.metadata);
+ memset(&ctx.xout->wc.masks.regs, 0, sizeof ctx.xout->wc.masks.regs);
}
/* Translates the 'ofpacts_len' bytes of "struct ofpact"s starting at 'ofpacts'
ctx->xin->report_hook(ctx, s);
}
}
+
+static void
+xlate_out_copy(struct xlate_out *dst, const struct xlate_out *src)
+{
+ dst->wc = src->wc;
+ dst->tags = src->tags;
+ dst->slow = src->slow;
+ dst->has_learn = src->has_learn;
+ dst->has_normal = src->has_normal;
+ dst->has_fin_timeout = src->has_fin_timeout;
+ dst->nf_output_iface = src->nf_output_iface;
+ dst->mirrors = src->mirrors;
+
+ ofpbuf_use_stub(&dst->odp_actions, dst->odp_actions_stub,
+ sizeof dst->odp_actions_stub);
+ ofpbuf_put(&dst->odp_actions, src->odp_actions.data,
+ src->odp_actions.size);
+}
\f
/* OFPP_NORMAL implementation. */
port = ofbundle_get_a_port(out_bundle);
} else {
port = bond_choose_output_slave(out_bundle->bond, &ctx->xin->flow,
- vid, &ctx->xout->tags);
+ &ctx->xout->wc, vid, &ctx->xout->tags);
if (!port) {
/* No slaves enabled, so drop packet. */
return;
m = ofproto->mirrors[mirror_mask_ffs(mirrors) - 1];
+ if (m->vlans) {
+ ctx->xout->wc.masks.vlan_tci |= htons(VLAN_CFI | VLAN_VID_MASK);
+ }
+
if (!vlan_is_mirrored(m, vlan)) {
mirrors = zero_rightmost_1bit(mirrors);
continue;
* migration. Older Citrix-patched Linux DomU used gratuitous ARP replies to
* indicate this; newer upstream kernels use gratuitous ARP requests. */
static bool
-is_gratuitous_arp(const struct flow *flow)
+is_gratuitous_arp(const struct flow *flow, struct flow_wildcards *wc)
{
- return (flow->dl_type == htons(ETH_TYPE_ARP)
- && eth_addr_is_broadcast(flow->dl_dst)
- && (flow->nw_proto == ARP_OP_REPLY
- || (flow->nw_proto == ARP_OP_REQUEST
- && flow->nw_src == flow->nw_dst)));
+ if (flow->dl_type != htons(ETH_TYPE_ARP)) {
+ return false;
+ }
+
+ memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
+ if (!eth_addr_is_broadcast(flow->dl_dst)) {
+ return false;
+ }
+
+ memset(&wc->masks.nw_proto, 0xff, sizeof wc->masks.nw_proto);
+ if (flow->nw_proto == ARP_OP_REPLY) {
+ return true;
+ } else if (flow->nw_proto == ARP_OP_REQUEST) {
+ memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
+ memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
+
+ return flow->nw_src == flow->nw_dst;
+ } else {
+ return false;
+ }
}
static void
update_learning_table(struct ofproto_dpif *ofproto,
- const struct flow *flow, int vlan,
- struct ofbundle *in_bundle)
+ const struct flow *flow, struct flow_wildcards *wc,
+ int vlan, struct ofbundle *in_bundle)
{
struct mac_entry *mac;
}
mac = mac_learning_insert(ofproto->ml, flow->dl_src, vlan);
- if (is_gratuitous_arp(flow)) {
+ if (is_gratuitous_arp(flow, wc)) {
/* We don't want to learn from gratuitous ARP packets that are
* reflected back over bond slaves so we lock the learning table. */
if (!in_bundle->bond) {
case BV_DROP_IF_MOVED:
mac = mac_learning_lookup(ofproto->ml, flow->dl_src, vlan, NULL);
if (mac && mac->port.p != in_bundle &&
- (!is_gratuitous_arp(flow)
+ (!is_gratuitous_arp(flow, &ctx->xout->wc)
|| mac_entry_is_grat_arp_locked(mac))) {
xlate_report(ctx, "SLB bond thinks this packet looped back, "
"dropping");
static void
xlate_normal(struct xlate_ctx *ctx)
{
+ struct flow_wildcards *wc = &ctx->xout->wc;
struct ofport_dpif *in_port;
struct ofbundle *in_bundle;
struct mac_entry *mac;
ctx->xout->has_normal = true;
+ memset(&wc->masks.dl_src, 0xff, sizeof wc->masks.dl_src);
+ memset(&wc->masks.dl_dst, 0xff, sizeof wc->masks.dl_dst);
+ wc->masks.vlan_tci |= htons(VLAN_VID_MASK | VLAN_CFI);
+
in_bundle = lookup_input_bundle(ctx->ofproto, ctx->xin->flow.in_port,
ctx->xin->packet != NULL, &in_port);
if (!in_bundle) {
/* Learn source MAC. */
if (ctx->xin->may_learn) {
- update_learning_table(ctx->ofproto, &ctx->xin->flow, vlan, in_bundle);
+ update_learning_table(ctx->ofproto, &ctx->xin->flow, wc,
+ vlan, in_bundle);
}
/* Determine output bundle. */
if (subfacet->path == SF_FAST_PATH) {
struct dpif_flow_stats stats;
- subfacet_install(subfacet, &facet->xout.odp_actions, &stats);
+ subfacet_install(subfacet, &facet->xout.odp_actions,
+ &stats);
subfacet_update_stats(subfacet, &stats);
}
}
static void
send_netflow_active_timeouts(struct ofproto_dpif *ofproto)
{
+ struct cls_cursor cursor;
struct facet *facet;
- HMAP_FOR_EACH (facet, hmap_node, &ofproto->facets) {
+ cls_cursor_init(&cursor, &ofproto->facets, NULL);
+ CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
send_active_timeout(ofproto, facet);
}
}
{
const char *dpname = argv[1];
struct ofproto_dpif *ofproto;
- struct ofpbuf odp_key;
+ struct ofpbuf odp_key, odp_mask;
struct ofpbuf *packet;
struct initial_vals initial_vals;
struct ds result;
packet = NULL;
ofpbuf_init(&odp_key, 0);
ds_init(&result);
+ ofpbuf_init(&odp_mask, 0);
ofproto = ofproto_dpif_lookup(dpname);
if (!ofproto) {
/* Convert string to datapath key. */
ofpbuf_init(&odp_key, 0);
- error = odp_flow_key_from_string(flow_s, NULL, &odp_key);
+ error = odp_flow_from_string(flow_s, NULL, &odp_key, &odp_mask);
if (error) {
unixctl_command_reply_error(conn, "Bad flow syntax");
goto exit;
ds_destroy(&result);
ofpbuf_delete(packet);
ofpbuf_uninit(&odp_key);
+ ofpbuf_uninit(&odp_mask);
}
static void
flow_format(ds, flow);
ds_put_char(ds, '\n');
- rule = rule_dpif_lookup(ofproto, flow);
+ rule = rule_dpif_lookup(ofproto, flow, NULL);
trace_format_rule(ds, 0, 0, rule);
if (rule == ofproto->miss_rule) {
} else if (rule == ofproto->no_packet_in_rule) {
ds_put_cstr(ds, "\nNo match, packets dropped because "
"OFPPC_NO_PACKET_IN is set on in_port.\n");
+ } else if (rule == ofproto->drop_frags_rule) {
+ ds_put_cstr(ds, "\nPackets dropped because they are IP fragments "
+ "and the fragment handling mode is \"drop\".\n");
}
if (rule) {
uint64_t odp_actions_stub[1024 / 8];
struct ofpbuf odp_actions;
-
struct trace_ctx trace;
+ struct match match;
uint8_t tcp_flags;
tcp_flags = packet ? packet_get_tcp_flags(packet, flow) : 0;
packet);
trace.xin.resubmit_hook = trace_resubmit;
trace.xin.report_hook = trace_report;
+
xlate_actions(&trace.xin, &trace.xout);
ds_put_char(ds, '\n');
trace_format_flow(ds, 0, "Final flow", &trace);
+
+ match_init(&match, flow, &trace.xout.wc);
+ ds_put_cstr(ds, "Relevant fields: ");
+ match_format(&match, ds, OFP_DEFAULT_PRIORITY);
+ ds_put_char(ds, '\n');
+
ds_put_cstr(ds, "Datapath actions: ");
format_odp_actions(ds, trace.xout.odp_actions.data,
trace.xout.odp_actions.size);
static void
ofproto_dpif_self_check__(struct ofproto_dpif *ofproto, struct ds *reply)
{
+ struct cls_cursor cursor;
struct facet *facet;
int errors;
errors = 0;
- HMAP_FOR_EACH (facet, hmap_node, &ofproto->facets) {
+ cls_cursor_init(&cursor, &ofproto->facets, NULL);
+ CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
if (!facet_check_consistency(facet)) {
errors++;
}
ds_destroy(&ds);
}
+/* Dump the megaflow (facet) cache. This is useful to check the
+ * correctness of flow wildcarding, since the same mechanism is used for
+ * both xlate caching and kernel wildcarding.
+ *
+ * It's important to note that in the output the flow description uses
+ * OpenFlow (OFP) ports, but the actions use datapath (ODP) ports.
+ *
+ * This command is only needed for advanced debugging, so it's not
+ * documented in the man page. */
+static void
+ofproto_unixctl_dpif_dump_megaflows(struct unixctl_conn *conn,
+ int argc OVS_UNUSED, const char *argv[],
+ void *aux OVS_UNUSED)
+{
+ struct ds ds = DS_EMPTY_INITIALIZER;
+ const struct ofproto_dpif *ofproto;
+ long long int now = time_msec();
+ struct cls_cursor cursor;
+ struct facet *facet;
+
+ ofproto = ofproto_dpif_lookup(argv[1]);
+ if (!ofproto) {
+ unixctl_command_reply_error(conn, "no such bridge");
+ return;
+ }
+
+ cls_cursor_init(&cursor, &ofproto->facets, NULL);
+ CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
+ cls_rule_format(&facet->cr, &ds);
+ ds_put_cstr(&ds, ", ");
+ ds_put_format(&ds, "n_subfacets:%zu, ", list_size(&facet->subfacets));
+ ds_put_format(&ds, "used:%.3fs, ", (now - facet->used) / 1000.0);
+ ds_put_cstr(&ds, "Datapath actions: ");
+ if (facet->xout.slow) {
+ uint64_t slow_path_stub[128 / 8];
+ const struct nlattr *actions;
+ size_t actions_len;
+
+ compose_slow_path(ofproto, &facet->flow, facet->xout.slow,
+ slow_path_stub, sizeof slow_path_stub,
+ &actions, &actions_len);
+ format_odp_actions(&ds, actions, actions_len);
+ } else {
+ format_odp_actions(&ds, facet->xout.odp_actions.data,
+ facet->xout.odp_actions.size);
+ }
+ ds_put_cstr(&ds, "\n");
+ }
+
+ ds_chomp(&ds, '\n');
+ unixctl_command_reply(conn, ds_cstr(&ds));
+ ds_destroy(&ds);
+}
+
+/* Disable using the megaflows.
+ *
+ * This command is only needed for advanced debugging, so it's not
+ * documented in the man page. */
+static void
+ofproto_unixctl_dpif_disable_megaflows(struct unixctl_conn *conn,
+ int argc OVS_UNUSED,
+ const char *argv[] OVS_UNUSED,
+ void *aux OVS_UNUSED)
+{
+ struct ofproto_dpif *ofproto;
+
+ enable_megaflows = false;
+
+ HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
+ flush(&ofproto->up);
+ }
+
+ unixctl_command_reply(conn, "megaflows disabled");
+}
+
+/* Re-enable using megaflows.
+ *
+ * This command is only needed for advanced debugging, so it's not
+ * documented in the man page. */
+static void
+ofproto_unixctl_dpif_enable_megaflows(struct unixctl_conn *conn,
+ int argc OVS_UNUSED,
+ const char *argv[] OVS_UNUSED,
+ void *aux OVS_UNUSED)
+{
+ struct ofproto_dpif *ofproto;
+
+ enable_megaflows = true;
+
+ HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, &all_ofproto_dpifs) {
+ flush(&ofproto->up);
+ }
+
+ unixctl_command_reply(conn, "megaflows enabled");
+}
+
static void
ofproto_unixctl_dpif_dump_flows(struct unixctl_conn *conn,
int argc OVS_UNUSED, const char *argv[],
HMAP_FOR_EACH (subfacet, hmap_node, &ofproto->subfacets) {
struct facet *facet = subfacet->facet;
+ struct odputil_keybuf maskbuf;
+ struct ofpbuf mask;
- odp_flow_key_format(subfacet->key, subfacet->key_len, &ds);
+ ofpbuf_use_stack(&mask, &maskbuf, sizeof maskbuf);
+ if (enable_megaflows) {
+ odp_flow_key_from_mask(&mask, &facet->xout.wc.masks,
+ &facet->flow, UINT32_MAX);
+ }
+
+ odp_flow_format(subfacet->key, subfacet->key_len,
+ mask.data, mask.size, &ds);
ds_put_format(&ds, ", packets:%"PRIu64", bytes:%"PRIu64", used:",
subfacet->dp_packet_count, subfacet->dp_byte_count);
ofproto_unixctl_dpif_dump_flows, NULL);
unixctl_command_register("dpif/del-flows", "bridge", 1, 1,
ofproto_unixctl_dpif_del_flows, NULL);
+ unixctl_command_register("dpif/dump-megaflows", "bridge", 1, 1,
+ ofproto_unixctl_dpif_dump_megaflows, NULL);
+ unixctl_command_register("dpif/disable-megaflows", "", 0, 0,
+ ofproto_unixctl_dpif_disable_megaflows, NULL);
+ unixctl_command_register("dpif/enable-megaflows", "", 0, 0,
+ ofproto_unixctl_dpif_enable_megaflows, NULL);
}
\f
/* Linux VLAN device support (e.g. "eth0.10" for VLAN 10.)
return hash_2words(realdev_ofp_port, vid);
}
-/* Returns the ODP port number of the Linux VLAN device that corresponds to
- * 'vlan_tci' on the network device with port number 'realdev_odp_port' in
- * 'ofproto'. For example, given 'realdev_odp_port' of eth0 and 'vlan_tci' 9,
- * it would return the port number of eth0.9.
+/* Returns the OFP port number of the Linux VLAN device that corresponds to
+ * 'vlan_tci' on the network device with port number 'realdev_ofp_port' in
+ * 'struct ofport_dpif'. For example, given 'realdev_ofp_port' of eth0 and
+ * 'vlan_tci' 9, it would return the port number of eth0.9.
*
- * Unless VLAN splinters are enabled for port 'realdev_odp_port', this
- * function just returns its 'realdev_odp_port' argument. */
-static uint32_t
+ * Unless VLAN splinters are enabled for port 'realdev_ofp_port', this
+ * function just returns its 'realdev_ofp_port' argument. */
+static uint16_t
vsp_realdev_to_vlandev(const struct ofproto_dpif *ofproto,
- uint32_t realdev_odp_port, ovs_be16 vlan_tci)
+ uint16_t realdev_ofp_port, ovs_be16 vlan_tci)
{
if (!hmap_is_empty(&ofproto->realdev_vid_map)) {
- uint16_t realdev_ofp_port;
int vid = vlan_tci_to_vid(vlan_tci);
const struct vlan_splinter *vsp;
- realdev_ofp_port = odp_port_to_ofp_port(ofproto, realdev_odp_port);
HMAP_FOR_EACH_WITH_HASH (vsp, realdev_vid_node,
hash_realdev_vid(realdev_ofp_port, vid),
&ofproto->realdev_vid_map) {
if (vsp->realdev_ofp_port == realdev_ofp_port
&& vsp->vid == vid) {
- return ofp_port_to_odp_port(ofproto, vsp->vlandev_ofp_port);
+ return vsp->vlandev_ofp_port;
}
}
}
- return realdev_odp_port;
+ return realdev_ofp_port;
}
static struct vlan_splinter *