bridge: Refresh STP statistics separately from status

Currently, we refresh STP status (id, state, role) alongside
statistics (rx, tx, errors), all within instant_stats_run(). This
patch splits statistics out, and refreshes them with the 5 second
stats instead. This paves the way to reducing execution of
instant_stats_run().

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
util: Fix sparse warning.

Without this commit, sparse warns:

    lib/util.c:921:15: warning: symbol 'count_1bits_8' was not declared.
    Should it be static?

Introduced by commit c3cc4d2dd2658 (util: Better count_1bits().).

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
coverage: Fix build when linker sections not supported.

With this change, OVS builds and runs fine without linker section support.

CC: Linda Sun <lsun@vmware.com>
CC: Saurabh Shah <ssaurabh@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
dpif-netdev: Properly create exact match masks.

Normally OVS userspace supplies a mask along with a flow key for each
new data path flow that should be created.  OVS also provides an
option to disable the kernel wildcarding, in which case the flows are
created without a mask.  When kernel wildcarding is disabled, the
datapath should use exact match, i.e. not wildcard any bits in the
flow key.  Currently, what happens with the userspace datapath instead
is that a datapath flow with mostly empty mask is created (i.e., most
fields are wildcarded), as the current code does not examine the given
mask key length to find out that the mask key is actually empty.  This
results in the same datapath flow matching on packets of multiple
different flows, wrong actions being processed, and stats being
incorrect.

This patch refactors userspace datapath code to explicitly initialize
a suitable exact match mask when a flow put without a mask is
executed.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
Classifier: Track address prefixes.

Add a prefix tree (trie) structure for tracking the used address
space, enabling skipping classifier tables containing longer masks
than necessary for an address field value in a packet header being
classified.  This enables less unwildcarding for datapath flows in
parts of the address space without host routes.

Trie lookup is interwoven to the staged lookup, so that a trie is
searched only when the configured trie field becomes relevant
for the lookup.  The trie lookup results are retained so that each
trie is checked at most once for each classifier lookup.

This implementation tracks the number of rules at each address prefix
for the whole classifier.  More aggressive table skipping would be
possible by maintaining lists of tables that have prefixes at the
lengths encountered on tree traversal, or by maintaining separate
tries for subsets of rules separated by metadata fields.

Prefix tracking is configured via OVSDB.  A new column "prefixes" is
added to the database table "Flow_Table".  "prefixes" is a set of
string values listing the field names for which prefix lookup should
be used.

As of now, the fields for which prefix lookup can be enabled are:
- tun_id, tun_src, tun_dst
- nw_src, nw_dst (or aliases ip_src and ip_dst)
- ipv6_src, ipv6_dst

There is a maximum number of fields that can be enabled for any one
flow table.  Currently this limit is 3.

Examples:

ovs-vsctl set Bridge br0 flow_tables:0=@N1 -- \
 --id=@N1 create Flow_Table name=table0
ovs-vsctl set Bridge br0 flow_tables:1=@N1 -- \
 --id=@N1 create Flow_Table name=table1

ovs-vsctl set Flow_Table table0 prefixes=ip_dst,ip_src
ovs-vsctl set Flow_Table table1 prefixes=[]

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto-dpif: Improve comment.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
ofproto-provider: Add comment on struct ofport.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
ofproto: Make ofproto_enumerate_types() match its comment.

The comment says that it clears the passed-in sset, but it didn't.  The bug
didn't actually affect any of the existing callers, which all passed in an
empty sset.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
ofproto: Fix alphabetical order in list of structs.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
netdev: Log a warning when netdev_set_config() fails.

This allows its callers to avoid duplicating the code.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
lacp: Make lacp negotiation test hard-code aggregation keys.

The lacp implementation takes the aggregation key from the key or portid
of the first slave to be added to the lacp object.  When multiple slaves
are added initially to a lacp object (the most common case), which is the
"first" is arbitrary.  Until now, it seems that the "first" was actually
predictable enough for the tests to (unknowingly) rely on it, but an
upcoming commit will break that.  This commit fixes the test by forcing
a particular aggregation key for each lacp object.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
datapath: Fix sparse warning.

Make the new compat function skb_flow_get_ports() static to silence a
sparse warning.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
lib/jhash.c: Fix comment.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto-dpif: Ignore non-packet field masks during flow revalidation

Commit bcd2633a5be(ofproto-dpif: Store relevant fields for wildcarding
in facet) implements flow revalidation by comparing the newly looked
up flow mask with that of the existing facet.

The non-packet fields, such as register masks, are always cleared
by xlate_actions in the masks stored within facets, but they are not
cleared in the newly looked up flow masks, causing otherwise valid
flows to be declared as invalid flows and be removed from the datapath.

This patch provides a fix. I was able to verify the fix on a system set
up by Ying Chen where the bug can be reproduced.

Bug #21680
Reported by: Ying Chen <yingchen@vmware.com>

Acked-by: Justin Pettit <jpettit@nicira.com>
Signed-off-by: Andy Zhou <azhou@nicira.com>
ovs-thread: Reduce logging level for cpuinfo parsing

This was causing test failures on non-Linux platforms.

Reported-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Joe Stringer <joestringer@nicira.com>
Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
bridge: Reconfigure in single pass.

This greatly simplifies the reconfiguration code, making it much easier
to understand and modify.  The old multi-pass configuration had the
property that it didn't delay block packet processing as much, but that's
not much of a worry anymore now that latency critical activities have
been moved outside the main thread.

Signed-off-by: Ben Pfaff <blp@nicira.com>
bridge: Support changing port numbers.

Feature #21293.
Requested-by: Anuprem Chalvadi <achalvadi@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
lib/util: More portable use of builtin popcnt.

- Use the GCC predefined macro __POPCNT__ to detect the availability
  of fast __builtin_popcnt function.
- Use portable preprocessor macros to detect 64-bit build.
- Only define the 32-bit parts when needed and declare the
  count_1bits_8 at file scope to silence a warning.

This time I have tested all code paths to make sure no warnigns are
generated.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Reviewed-by: Simon Horman <horms@verge.net.au>
ofproto-dpif: Remove dead code.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto: Remove arbitrary handler thread limit.

There's no particular reason to limit the number of handler threads to
64.  If someone wants to try more, let them.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>