netdev: Initialize netdev_class_mutex.

This code path currently does not initialize
netdev_class_mutex.
dummy_enable
 ->netdev_dummy_register
   ->netdev_register_provider
     ->ovs_mutex_lock(&netdev_class_mutex)

ovsdb-server on windows crashes without it.

This commit adds a new initialization function.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto: Don't destroy mutex before its use.

Currently, we are calling guarded_list_destroy()
to destroy a mutex and then go ahead and use it through
delete_group
 ->delete_group__
   ->handle_flow_mod__
    ->run_rule_executes
     ->guarded_list_pop_all

The group related unit tests cause ovs-vswitchd to crash
because of this (on windows).

Calling guarded_list_destroy() after delete_group() solves the
problem.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ofproto-dpif-upcall: Fix a bug.

Commit 7d170098 (ofproto-dpif-upcall: Remove the flow_dumper thread.)
initialized the memory barrier inside the udpif_start_threads() function.
However, the udpif_start_threads() function does not check the number of
revalidator threads specified in udpif.  So, when the number is zero, it
causes the error in barrier initialization.  This could happen when the
other_config:flow-restore-wait is set and the udpif_flush() is called.

This commit fixes the issue, by checking the specified number of threads
in udpif_start_threads().

Reported-by: Gurucharan Shetty <gshetty@nicira.com>
Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Gurucharan Shetty <gshetty@nicira.com>
revalidator: Fix ukey stats cache updating.

revalidate_ukey() had a bug where it would update the ukey->stats even
if it decided not to push stats (as an optimisation). ukey->stats should
only be updated when those stats are pushed.

This bug would arise in the following situation:
* A flow has been dumped before.
* The flow needs to be revalidated.
* The flow is low-throughput.
* The flow has new statistics to push.

Such cases rely on flow deletion to update the stats. However, that code
pushes the delta between the ukey->stats and the final flow dump. If the
ukey stats cache is updated without the stats being pushed, those stats
would be lost.

This caused intermittent testsuite failures on "learning action -
self-modifying flow with idle_timeout". Introduced by 698ffe3623f1b630ae
"revalidator: Only revalidate high-throughput flows."

Bug #1238927.

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
tests: Fix race condition waiting for monitor thread.

Occasionally, test #770 "ofproto-dpif - ofproto-dpif-monitor 1" would
fail, because the testsuite looked in the logs for evidence of a thread
being created, but it checked before vswitchd was able to spawn the
thread.

This patch fixes the race by modifying the commands that check for
creation/termination of threads to wait until they see the messages
instead.

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Reviewed-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
ofproto-dpif: Use sequence number to wake up main thread for
packet-in I/O.

This commit adds per 'struct ofproto_dpif' sequence number for
packet-in I/O.  Whenever ofproto_dpif_send_packet_in() is called,
the calling thread will change the sequence number to wake up the
main thread.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Joe Stringer <joestringer@nicira.com>
bridge: Refactor the 'Instant' stats logic.

This commit refactors the 'Instant' stats related logic in bridge.c
by moving it into bridge_run().

This change brings the following effects:

1. bridge.c will wait on the global connectivity sequence number when
   there is no pending instant stats transaction.  and the main thread
   will no longer be waken up every 100 ms for 'Instant' stats check.
   the related overhead is eliminated.

2. the netdev's sequence number is used to avoid updating unchanged netdev
   status.  so, the update is more efficient.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Joe Stringer <joestringer@nicira.com>
Python Logging Formatting Improvements

The Open vSwitch daemons written in C support user-configured logging
patterns as described in ovs-appctl(8). This commit adds this capability
to the daemons written in Python.

- Add a '__log_patterns' attribute to the Vlog class
- Populate this using the default patterns in ovs-appctl(8)
- Add a '__start_time' attribute to the Vlog class to support '%r'
- Update the '_log' method to build the log message according to the
  pattern
- Add a 'set_pattern' method to allow the default patterns to be changed
- Update 'set_levels_from_string' to support setting the pattern from a
  string

Signed-off-by: Dave Tucker <dave@dtucker.co.uk>
Signed-off-by: Ben Pfaff <blp@nicira.com>