ovs-rcu: Name the ovsrcu_postpone_thread to 'urcu'.

The ovs-rcu module adds a new thread for checking the grace period.
Since the thread name is not set, it will inherit the name of the
thread that creates it.  This makes the 'top' output quite confusing.

This commit names the thread to 'urcu' for clarity.

Acked-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Alex Wang <alexw@nicira.com>
tests: Define a variable "IS_WIN32" for tests.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
stream: Introduce [p]windows_[p]stream_class.

On Linux, we heavily use --remote=punix:* to listen for
connections through unix domain sockets. We also use, unix:*
to connect to a daemon that is listening on unix domain sockets.
Many times, we create default unix domain sockets for listening
and many utilities connect to these sockets by default.

Windows does not have unix domain sockets. So far, we could just use
ptcp:* and tcp:* for listening and initiating connections respectively.
The drawback here is that one has to provide a specific TCP port.

For unit tests, it looks useful to let kernel choose that port.
As such, we can let that chosen kernel port be stored in the
file specified with punix:* and unix:*. For this purpose, introduce
a new [p]windows_[p]stream_class. Since it is just a wrapper around
[p]tcp_[p]stream_class, add it to stream-tcp.c.

commit cb54a8c (unixctl: Add support for Windows.) used the above concept
for only control channel connections (i.e., --unixctl for daemons and its
interaction with ovs-appctl). This commit adds the same support for
all unix domain sockets.  Now that we have a separate class
[p]stream_class for hiding kernel assigned TCP port inside a file meant for
unix domain sockets in windows, make unixctl use it.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
daemon-windows: Rename service variables.

Sa far, we are using variable 'detach' to indicate whether the option
"--service" has been set. We were using variable 'detached' to indicate that
the daemon is being called from the Windows services manager.

An upcoming commit introduces command line option "--detach" for daemons
running on Windows. This will cause confusion with variable names.
Therefore, rename the variables.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
daemon-windows: Implement --detach option for Windows.

When "--detach" is specified, a daemon will create a new
process with the same command line options as the parent.
Additionally, an undocumented command line option "--pipe-handle"
is passed to child. Once the child is ready to handle external
commands, it communicates with the parent that it is ready using
the pipe handle. The parent exits. This lets us run the daemons
in background. This will also help the unit tests because currently
most of the unit tests pass the '--detach' option to the daemons.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
daemon-windows: Create pidfiles with option --pidfile.

In Windows, we cannot delete a file that has been opened.
We use this feature to "lock" the pidfile.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
testsuite.at: pwd for windows.

On MinGW, "pwd -W" gives the present working directory
in the form of windows path (i.e C:/temp instead of /c/temp).
When we pass the directory path to daemons as arguments,
we should be passing it in the form of windows path.

Suggested-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
testsuite.at: kill for windows.

We use kill to cleanup processes from pidfiles.
Windows has a 'taskkill' which does something similar.
We can check if the process with a PID exists with
'tasklist'. Both tasklist and taskkill return 0 for
both success and failure. So, we will have to grep
to see if there is a o/p.

A typical o/p of tasklist is:
$ tasklist | grep ovs
ovsdb-server.exe              3228 RDP-Tcp#0                  2      6,132 K
ovs-vswitchd.exe              2080 RDP-Tcp#0                  2      5,808 K

$ tasklist //fi "PID eq 3228"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
ovsdb-server.exe              3228 RDP-Tcp#0                  2      6,132 K

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
testsuite.at: Workaround for carriage returns on windows.

In unit tests, we compare text written in logs or stdout/stderr
to figure out the success or failure of tests. In Windows,
since new line is represented by CR+LF, autoconf tests run in
MinGW environment fail.

Asking diff to ignore trailing carriage returns is one way
to solve the problem

Suggested-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
TODO: Add the project list from the hackathon.

I've had a couple of requests for an updated project list, so this commit
adds it to the tree.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Joe Stringer <joestringer@nicira.com>
ofproto-macros.at: Assert daemon commands creates pidfile before exiting

I observed that "ofproto-dpif - ofproto-dpif-monitor 2" test,
which merely accesses ovsdb, failed in OVS_VSWITCHD_STOP's
"ovs-appctl -t ovs-vswitchd exit".  This commit tries to catch
the problem earlier by sprinkling AT_CHECKs.
ofproto-dpif.at: Fix some races

These races were exposed on my environment by commit c2a77f33.
("tests/ofproto-dpif: Use vlog to test dpif behaviour.")
ofproto-dpif.at: Use OVS_APP_EXIT_AND_WAIT where appropriate

Leftover of commit 0c473314.
("ofproto-dpif.at: Wait for the monitor's pidfile disappears where necessary")
ofproto-dpif.at: Fix races in dpif/dump-flows test
ofproto-dpif: Whitespace fixes
dpif-netdev: Remove unused members

Simplify code and update comments after commit 61e7deb1.
("dpif-netdev: Use RCU to protect data.")
ofproto-dpif.h: Fix a comment
hmap_random_node: Improve distribution

Improve random distribution for an hmap with a small number of nodes
with the expense of the increased cpu cost.
It would be a fair trade-off because the situation is rather common
for bond, which is currently the only consumer of this API in tree.

Consider 2 items, 4 buckets, no collision.

    bucket 0   item 0
    bucket 1
    bucket 2
    bucket 3   item 1

The old algorithm picks item 0 if rand % 4 == 0.  (25%)
Otherwise it picks item 1.  (75%)

This change makes them 50%.

Acked-by: Ben Pfaff <blp@nicira.com>