#include "bond.h"
#include "bundle.h"
#include "byte-order.h"
+#include "connectivity.h"
#include "connmgr.h"
#include "coverage.h"
#include "cfm.h"
#include "ofproto-dpif-upcall.h"
#include "ofproto-dpif-xlate.h"
#include "poll-loop.h"
+#include "seq.h"
#include "simap.h"
#include "smap.h"
#include "timer.h"
#define SUBFACET_DESTROY_MAX_BATCH 50
-static struct subfacet *subfacet_create(struct facet *, struct flow_miss *);
+static struct subfacet *subfacet_create(struct facet *, struct flow_miss *,
+ uint32_t key_hash);
static struct subfacet *subfacet_find(struct dpif_backer *,
const struct nlattr *key, size_t key_len,
uint32_t key_hash);
/* Accounting. */
uint64_t accounted_bytes; /* Bytes processed by facet_account(). */
- struct netflow_flow nf_flow; /* Per-flow NetFlow tracking data. */
uint16_t tcp_flags; /* TCP flags seen for this 'rule'. */
struct xlate_out xout;
COVERAGE_DEFINE(rev_mac_learning);
COVERAGE_DEFINE(rev_inconsistency);
-struct avg_subfacet_rates {
- double add_rate; /* Moving average of new flows created per minute. */
- double del_rate; /* Moving average of flows deleted per minute. */
-};
-
/* All datapaths of a given type share a single dpif backer instance. */
struct dpif_backer {
char *type;
struct timer next_expiration;
struct ovs_rwlock odp_to_ofport_lock;
- struct hmap odp_to_ofport_map OVS_GUARDED; /* ODP port to ofport map. */
+ struct hmap odp_to_ofport_map OVS_GUARDED; /* Contains "struct ofport"s. */
struct simap tnl_backers; /* Set of dpif ports backing tunnels. */
* exposed via "ovs-appctl dpif/show". The goal is to learn about
* traffic patterns in ways that we can use later to improve Open vSwitch
* performance in new situations. */
- long long int created; /* Time when it is created. */
unsigned max_n_subfacet; /* Maximum number of flows */
unsigned avg_n_subfacet; /* Average number of flows. */
long long int avg_subfacet_life; /* Average life span of subfacets. */
struct hmap bundles; /* Contains "struct ofbundle"s. */
struct mac_learning *ml;
bool has_bonded_bundles;
+ bool lacp_enabled;
struct mbridge *mbridge;
/* Facets. */
struct sset ghost_ports; /* Ports with no datapath port. */
struct sset port_poll_set; /* Queued names for port_poll() reply. */
int port_poll_errno; /* Last errno for port_poll() reply. */
+ uint64_t change_seq; /* Connectivity status changes. */
/* Per ofproto's dpif stats. */
uint64_t n_hit;
/* Flow expiration. */
static int expire(struct dpif_backer *);
-/* NetFlow. */
-static void send_netflow_active_timeouts(struct ofproto_dpif *);
-
/* Global variables. */
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
backer->n_handler_threads = n_handler_threads;
backer->max_n_subfacet = 0;
- backer->created = time_msec();
backer->avg_n_subfacet = 0;
backer->avg_subfacet_life = 0;
ofproto->ml = mac_learning_create(MAC_ENTRY_DEFAULT_IDLE_TIME);
ofproto->mbridge = mbridge_create();
ofproto->has_bonded_bundles = false;
+ ofproto->lacp_enabled = false;
ovs_mutex_init(&ofproto->stats_mutex);
ovs_mutex_init(&ofproto->vsp_mutex);
sset_init(&ofproto->ghost_ports);
sset_init(&ofproto->port_poll_set);
ofproto->port_poll_errno = 0;
+ ofproto->change_seq = 0;
SHASH_FOR_EACH_SAFE (node, next, &init_ofp_ports) {
struct iface_hint *iface_hint = node->data;
mbridge_unref(ofproto->mbridge);
- netflow_destroy(ofproto->netflow);
+ netflow_unref(ofproto->netflow);
dpif_sflow_unref(ofproto->sflow);
hmap_destroy(&ofproto->bundles);
mac_learning_unref(ofproto->ml);
run(struct ofproto *ofproto_)
{
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
- struct ofport_dpif *ofport;
- struct ofbundle *bundle;
+ uint64_t new_seq;
int error;
if (mbridge_need_revalidate(ofproto->mbridge)) {
}
if (ofproto->netflow) {
- if (netflow_run(ofproto->netflow)) {
- send_netflow_active_timeouts(ofproto);
- }
+ netflow_run(ofproto->netflow);
}
if (ofproto->sflow) {
dpif_sflow_run(ofproto->sflow);
dpif_ipfix_run(ofproto->ipfix);
}
- HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
- port_run(ofport);
+ new_seq = seq_read(connectivity_seq_get());
+ if (ofproto->change_seq != new_seq) {
+ struct ofport_dpif *ofport;
+
+ HMAP_FOR_EACH (ofport, up.hmap_node, &ofproto->up.ports) {
+ port_run(ofport);
+ }
+
+ ofproto->change_seq = new_seq;
}
- HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
- bundle_run(bundle);
+ if (ofproto->lacp_enabled || ofproto->has_bonded_bundles) {
+ struct ofbundle *bundle;
+
+ HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
+ bundle_run(bundle);
+ }
}
stp_run(ofproto);
wait(struct ofproto *ofproto_)
{
struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_);
- struct ofbundle *bundle;
if (ofproto_get_flow_restore_wait()) {
return;
if (ofproto->ipfix) {
dpif_ipfix_wait(ofproto->ipfix);
}
- HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
- bundle_wait(bundle);
+ if (ofproto->lacp_enabled || ofproto->has_bonded_bundles) {
+ struct ofbundle *bundle;
+
+ HMAP_FOR_EACH (bundle, hmap_node, &ofproto->bundles) {
+ bundle_wait(bundle);
+ }
}
if (ofproto->netflow) {
netflow_wait(ofproto->netflow);
s->state = stp_port_get_state(sp);
s->sec_in_state = (time_msec() - ofport->stp_state_entered) / 1000;
s->role = stp_port_get_role(sp);
+
+ return 0;
+}
+
+static int
+get_stp_port_stats(struct ofport *ofport_,
+ struct ofproto_port_stp_stats *s)
+{
+ struct ofport_dpif *ofport = ofport_dpif_cast(ofport_);
+ struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofport->up.ofproto);
+ struct stp_port *sp = ofport->stp_port;
+
+ if (!ofproto->stp || !sp) {
+ s->enabled = false;
+ return 0;
+ }
+
+ s->enabled = true;
stp_port_get_counts(sp, &s->tx_count, &s->rx_count, &s->error_count);
return 0;
/* LACP. */
if (s->lacp) {
+ ofproto->lacp_enabled = true;
if (!bundle->lacp) {
ofproto->backer->need_revalidate = REV_RECONFIGURE;
bundle->lacp = lacp_create();
{
enum subfacet_path want_path;
struct subfacet *subfacet;
+ uint32_t key_hash;
+ /* Update facet stats. */
facet->packet_count += miss->stats.n_packets;
facet->prev_packet_count += miss->stats.n_packets;
facet->byte_count += miss->stats.n_bytes;
facet->prev_byte_count += miss->stats.n_bytes;
- want_path = facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
+ /* Look for an existing subfacet. If we find one, update its used time. */
+ key_hash = odp_flow_key_hash(miss->key, miss->key_len);
+ if (!list_is_empty(&facet->subfacets)) {
+ subfacet = subfacet_find(miss->ofproto->backer,
+ miss->key, miss->key_len, key_hash);
+ if (subfacet) {
+ if (subfacet->facet == facet) {
+ subfacet->used = MAX(subfacet->used, miss->stats.used);
+ } else {
+ /* This shouldn't happen. */
+ VLOG_ERR_RL(&rl, "subfacet with wrong facet");
+ subfacet_destroy(subfacet);
+ subfacet = NULL;
+ }
+ }
+ } else {
+ subfacet = NULL;
+ }
/* Don't install the flow if it's the result of the "userspace"
* action for an already installed facet. This can occur when a
return;
}
- subfacet = subfacet_create(facet, miss);
+ /* Create a subfacet, if we don't already have one. */
+ if (!subfacet) {
+ subfacet = subfacet_create(facet, miss, key_hash);
+ }
+
+ /* Install the subfacet, if it's not already installed. */
+ want_path = facet->xout.slow ? SF_SLOW_PATH : SF_FAST_PATH;
if (subfacet->path != want_path) {
struct flow_miss_op *op = &ops[(*n_ops)++];
struct dpif_flow_put *put = &op->dpif_op.u.flow_put;
facet->learn_rl = time_msec() + 500;
list_init(&facet->subfacets);
- netflow_flow_init(&facet->nf_flow);
- netflow_flow_update_time(ofproto->netflow, &facet->nf_flow, facet->used);
xlate_out_copy(&facet->xout, &miss->xout);
classifier_insert(&ofproto->facets, &facet->cr);
ovs_rwlock_unlock(&ofproto->facets.rwlock);
- facet->nf_flow.output_iface = facet->xout.nf_output_iface;
+ if (ofproto->netflow && !facet_is_controller_flow(facet)) {
+ netflow_flow_update(ofproto->netflow, &facet->flow,
+ facet->xout.nf_output_iface, &miss->stats);
+ }
+
return facet;
}
}
if (ofproto->netflow && !facet_is_controller_flow(facet)) {
- struct ofexpired expired;
- expired.flow = facet->flow;
- expired.packet_count = facet->packet_count;
- expired.byte_count = facet->byte_count;
- expired.used = facet->used;
- netflow_expire(ofproto->netflow, &facet->nf_flow, &expired);
+ netflow_expire(ofproto->netflow, &facet->flow);
+ netflow_flow_clear(ofproto->netflow, &facet->flow);
}
/* Reset counters to prevent double counting if 'facet' ever gets
* reinstalled. */
facet_reset_counters(facet);
-
- netflow_flow_clear(&facet->nf_flow);
facet->tcp_flags = 0;
}
xlate_in_init(&xin, ofproto, &facet->flow, new_rule, 0, NULL);
xlate_actions(&xin, &xout);
flow_wildcards_or(&xout.wc, &xout.wc, &wc);
+ /* Make sure non -packet fields are not masked. If not cleared,
+ * the memcmp() below may fail, causing an otherwise valid facet
+ * to be removed. */
+ flow_wildcards_clear_non_packet_fields(&xout.wc);
/* A facet's slow path reason should only change under dramatic
* circumstances. Rather than try to update everything, it's simpler to
facet->xout.has_fin_timeout = xout.has_fin_timeout;
facet->xout.nf_output_iface = xout.nf_output_iface;
facet->xout.mirrors = xout.mirrors;
- facet->nf_flow.output_iface = facet->xout.nf_output_iface;
ovs_mutex_lock(&new_rule->up.mutex);
facet->used = MAX(facet->used, new_rule->up.created);
in_port = get_ofp_port(ofproto, flow->in_port.ofp_port);
if (in_port && in_port->is_tunnel) {
netdev_vport_inc_rx(in_port->up.netdev, stats);
+ if (in_port->bfd) {
+ bfd_account_rx(in_port->bfd, stats);
+ }
}
xlate_in_init(&xin, ofproto, flow, NULL, stats->tcp_flags, NULL);
facet->prev_byte_count = facet->byte_count;
facet->prev_used = facet->used;
- netflow_flow_update_time(facet->ofproto->netflow, &facet->nf_flow,
- facet->used);
- netflow_flow_update_flags(&facet->nf_flow, facet->tcp_flags);
+ if (facet->ofproto->netflow && !facet_is_controller_flow(facet)) {
+ netflow_flow_update(facet->ofproto->netflow, &facet->flow,
+ facet->xout.nf_output_iface, &stats);
+ }
mirror_update_stats(facet->ofproto->mbridge, facet->xout.mirrors,
stats.n_packets, stats.n_bytes);
flow_push_stats(facet->ofproto, &facet->flow, &stats, may_learn);
return NULL;
}
-/* Searches 'facet' (within 'ofproto') for a subfacet with the specified
- * 'key_fitness', 'key', and 'key_len' members in 'miss'. Returns the
- * existing subfacet if there is one, otherwise creates and returns a
- * new subfacet. */
+/* Creates and returns a new subfacet within 'facet' for the flow in 'miss'.
+ * 'key_hash' must be a hash over miss->key. The caller must have already
+ * ensured that no subfacet subfacet already exists. */
static struct subfacet *
-subfacet_create(struct facet *facet, struct flow_miss *miss)
+subfacet_create(struct facet *facet, struct flow_miss *miss, uint32_t key_hash)
{
struct dpif_backer *backer = miss->ofproto->backer;
const struct nlattr *key = miss->key;
size_t key_len = miss->key_len;
- uint32_t key_hash;
struct subfacet *subfacet;
- key_hash = odp_flow_key_hash(key, key_len);
-
- if (list_is_empty(&facet->subfacets)) {
- subfacet = &facet->one_subfacet;
- } else {
- subfacet = subfacet_find(backer, key, key_len, key_hash);
- if (subfacet) {
- if (subfacet->facet == facet) {
- return subfacet;
- }
-
- /* This shouldn't happen. */
- VLOG_ERR_RL(&rl, "subfacet with wrong facet");
- subfacet_destroy(subfacet);
- }
-
- subfacet = xmalloc(sizeof *subfacet);
- }
+ subfacet = (list_is_empty(&facet->subfacets)
+ ? &facet->one_subfacet
+ : xmalloc(sizeof *subfacet));
COVERAGE_INC(subfacet_create);
hmap_insert(&backer->subfacets, &subfacet->hmap_node, key_hash);
return netflow_set_options(ofproto->netflow, netflow_options);
} else if (ofproto->netflow) {
ofproto->backer->need_revalidate = REV_RECONFIGURE;
- netflow_destroy(ofproto->netflow);
+ netflow_unref(ofproto->netflow);
ofproto->netflow = NULL;
}
dpif_get_netflow_ids(ofproto->backer->dpif, engine_type, engine_id);
}
-
-static void
-send_active_timeout(struct ofproto_dpif *ofproto, struct facet *facet)
-{
- if (!facet_is_controller_flow(facet) &&
- netflow_active_timeout_expired(ofproto->netflow, &facet->nf_flow)) {
- struct subfacet *subfacet;
- struct ofexpired expired;
-
- LIST_FOR_EACH (subfacet, list_node, &facet->subfacets) {
- if (subfacet->path == SF_FAST_PATH) {
- struct dpif_flow_stats stats;
-
- subfacet_install(subfacet, &facet->xout.odp_actions,
- &stats);
- subfacet_update_stats(subfacet, &stats);
- }
- }
-
- expired.flow = facet->flow;
- expired.packet_count = facet->packet_count;
- expired.byte_count = facet->byte_count;
- expired.used = facet->used;
- netflow_expire(ofproto->netflow, &facet->nf_flow, &expired);
- }
-}
-
-static void
-send_netflow_active_timeouts(struct ofproto_dpif *ofproto)
-{
- struct cls_cursor cursor;
- struct facet *facet;
-
- ovs_rwlock_rdlock(&ofproto->facets.rwlock);
- cls_cursor_init(&cursor, &ofproto->facets, NULL);
- CLS_CURSOR_FOR_EACH (facet, cr, &cursor) {
- send_active_timeout(ofproto, facet);
- }
- ovs_rwlock_unlock(&ofproto->facets.rwlock);
-}
\f
static struct ofproto_dpif *
ofproto_dpif_lookup(const char *name)
ds_put_char_multiple(result, '\t', level);
ds_put_format(result, "%s:", title);
for (i = 0; i < FLOW_N_REGS; i++) {
- ds_put_format(result, " reg%zu=0x%"PRIx32, i, trace->flow.regs[i]);
+ ds_put_format(result, " reg%"PRIuSIZE"=0x%"PRIx32, i, trace->flow.regs[i]);
}
ds_put_char(result, '\n');
}
}
/* OpenFlow 1.1 and later suggest that the switch enforces certain forms of
- * consistency between the flow and the actions, so enforce these by
- * default if the actions can only work in OF1.1 or later. */
- enforce_consistency = !(usable_protocols & OFPUTIL_P_OF10_ANY);
+ * consistency between the flow and the actions. With -consistent, we
+ * enforce consistency even for a flow supported in OpenFlow 1.0. */
if (!strcmp(argv[1], "-consistent")) {
enforce_consistency = true;
argv++;
argc--;
+ } else {
+ enforce_consistency = false;
}
error = parse_flow_and_packet(argc, argv, &ofproto, &flow, &packet);
unixctl_command_reply_error(conn, "invalid in_port");
goto exit;
}
- retval = ofpacts_check(ofpacts.data, ofpacts.size, &flow,
- enforce_consistency,
- u16_to_ofp(ofproto->up.max_ports), 0, 0);
+ if (enforce_consistency) {
+ retval = ofpacts_check_consistency(ofpacts.data, ofpacts.size, &flow,
+ u16_to_ofp(ofproto->up.max_ports),
+ 0, 0, usable_protocols);
+ } else {
+ retval = ofpacts_check(ofpacts.data, ofpacts.size, &flow,
+ u16_to_ofp(ofproto->up.max_ports), 0, 0,
+ &usable_protocols);
+ }
+
if (retval) {
ds_clear(&result);
ds_put_format(&result, "Bad actions: %s", ofperr_to_string(retval));
ds_put_format(ds, "%s: hit:%"PRIu64" missed:%"PRIu64"\n",
dpif_name(backer->dpif), n_hit, n_missed);
- ds_put_format(ds, "\tflows: cur: %zu, avg: %u, max: %u,"
+ ds_put_format(ds, "\tflows: cur: %"PRIuSIZE", avg: %u, max: %u,"
" life span: %lldms\n", hmap_count(&backer->subfacets),
backer->avg_n_subfacet, backer->max_n_subfacet,
backer->avg_subfacet_life);
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, "n_subfacets:%"PRIuSIZE", ", 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) {
get_stp_status,
set_stp_port,
get_stp_port_status,
+ get_stp_port_stats,
set_queues,
bundle_set,
bundle_remove,