lib/dpif-netdev: Clean-up pmd thread signaling.

It could be possible that the thread misses a signal when it reads the
change_seq again after reload.  Also, the counter has no dependent
data, so the memory model for the atomic read can be relaxed.

Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
Extend OVS IPFIX exporter to export tunnel headers

Extend IPFIX exporter to export tunnel headers when both input and output
of the port.
Add three other_config options in IPFIX table: enable-input-sampling,
enable-output-sampling and enable-tunnel-sampling, to control whether
sampling tunnel info, on which direction (input or output).
Insert sampling action before output action and the output tunnel port
is sent to datapath in the sampling action.
Make datapath collect output tunnel info and send it back to userpace
in upcall message with a new additional optional attribute.
Add a tunnel ports map to make the tunnel port lookup faster in sampling
upcalls in IPFIX exporter. Make the IPFIX exporter generate IPFIX template
sets with enterprise elements for the tunnel info, save the tunnel info
in IPFIX cache entries, and send IPFIX DATA with tunnel info.
Add flowDirection element in IPFIX templates.

Signed-off-by: Wenyu Zhang <wenyuz@vmware.com>
Acked-by: Romain Lenglet <rlenglet@vmware.com>
Acked-by: Ben Pfaff <blp@nicira.com>
Acked-by: Pravin B Shelar <pshelar@nicira.com>
ovs-vtep: Clarifications on the README.

The README was not clear on whether the steps are for attaching physical
or virtual machines to the emulated VTEP. This adds more detail to the
README so that readers will know what to do if they want to attach physical
machines or otherwise.

Signed-off-by: Mark Maglana <mmaglana@gmail.com>
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
netinet/in.h: Add definition for IPPROTO_GRE.

Commit b7ea2d480338(Extend OVS IPFIX exporter to export tunnel headers)
added a usage for IPROTO_GRE. But that does not look available in any
Visual Studio headers. So add it.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
acinclude.m4: Do not set vswitchd_ovs_vswitchd_LDFLAGS

Commit d731058395cb used vswitchd_ovs_vswitchd_LDFLAGS to link with DPDK. This
made automake ignore AM_LDFLAGS while linking the daemon.

This commit explicitly adds AM_LDFLAGS to vswitchd_ovs_vswitchd_LDFLAGS and
moves it to vswitchd/automake.mk

Reported-by: Gurucharan Shetty <gshetty@nicira.com>
Suggested-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Daniele Di Proietto <ddiproietto@vmware.com>
Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
fat-rwlock: fat_rwlock_tryrdlock() should never block

fat_rwlock_tryrdlock() used to call fat_rwlock_get_slot__() which could block
in the "slow path" case. This commit adds fat_rwlock_try_get_slot__() which
does not block, even in the "slow path" case.

This fixes a minor issue in dpif-netdev: when the datapath has no registered
upcall handler (e.g. if it is created with dpctl commands), dp_netdev_input()
hangs if it does not find a packet's flow in the classifier.  This is
because dpif-netdev uses its upcall_rwlock as a way to enable and disable
upcalls and thus holds the upcall_rwlock write lock as long as upcalls are
disabled.  Both holding the write lock and creating a slot require the
fat_rwlock's mutex, causing the hang.

Signed-off-by: Daniele Di Proietto <ddiproietto@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
bfd: Clarify bfd:enable.

This commit clarifies the documentation for 'bfd:enable'
when it is not specified.

Signed-off-by: Alex Wang <alexw@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
Add extentions to the standard datapath interface

The datapath interface defined in odp-netlink.h needs some extensions
that are platform dependent. Some examples are the name of the communication
device on Windows and a set of commands that are specific to Windows.

In this change we define a datapath-windows/include/OvsDpInterfaceExt.h
to include any platform specific interface extensions.

OvsDpInterfaceExt.h is in turn included in odp-netlink.h ONLY for _WIN32.
This approach was chosen to avoid including OvsDpInterfaceExt.h directly
although the latter approach is as good as the former.

Also, we define three ioctls in OvsDpInterfaceExt.h:
read:     provides an output buffer (mimics a recv)
write:    provides an input buffer (mimics a send)
transact: provides an input and optionally an output buffer.
          (mimics a send followed by recv)

Signed-off-by: Nithin Raju <nithin@vmware.com>
Co-Authored-by: Ben Pfaff <blp@nicira.com>
Acked-by: Alin Serdean <aserdean@cloudbasesolutions.com>
Acked-by: Ankur Sharma <ankursharma@vmware.com>
Acked-by: Saurabh Shah <ssaurabh@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath-windows: Add Datapath.[ch] and OVS_USE_NL_INTERFACE CPP

In this change we create peer to OvsIoctl.[ch] that would interface
with userspace using the netlink interface. The new files are called
Datapath.[ch]. We are not deleting OvsIoctl.[ch] yet. Datapath.[ch]
provides bare minimum functionality to register a pseudo device for
communication with userspace.

We also define a CPP called OVS_USE_NL_INTERFACE in the ovsext project.
This defines if the old interface (pre-netlink based) or the new
interface (netlink- based) should be enabled in the kernel. By default,
the value is 0 since the Datapath.[ch] are minimal. In the next change,
we'll turn it to 1.

Since Datapath.[ch] containes code copied from OvsIoctl.[ch], acking
the original author as well.

Signed-off-by: Nithin Raju <nithin@vmware.com>
Co-authored-by: Guolin Yang <gyang@vmware.com>
Acked-by: Alin Serdean <aserdean@cloudbasesolutions.com>
Acked-by: Ankur Sharma <ankursharma@vmware.com>
Acked-by: Saurabh Shah <ssaurabh@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath-windows: add infrastructure for supporting netlink

In this change, we define netlink families and commands supported
by the Windows datapath. Only the control family and one command
is supported today to get the PID.

We also implement the 3 ioctls: read, write and transact. This is
bare minimum and can be used to implement the equivalent of a
recv, send, and send-recv in userspace netlink. This interface
is subject to change as iron out the details of the user-kernel
interface for operations around packet receive, events, dump, etc.

We also turn on OVS_USE_NL_INTERFACE to 1 in the ovsext project.

Signed-off-by: Nithin Raju <nithin@vmware.com>
Acked-by: Alin Serdean <aserdean@cloudbasesolutions.com>
Acked-by: Ankur Sharma <ankursharma@vmware.com>
Acked-by: Saurabh Shah <ssaurabh@vmware.com>
Reported-at: https://github.com/openvswitch/ovs-issues/issues/18
Signed-off-by: Ben Pfaff <blp@nicira.com>
netlink-socket.c: implement get pid support on Windows

To verify if the netlink support in the kernel works, I updated
the netlink-socket.c code to get the PID for a given device
descriptor.

In the existing code, userspace sets the PID, which will not be
unique across different processes. So, it is better for the
kernel to generate the PID and give it back to userspace.

dpif-linux.c was ported to Windows (similar to Alin's change in
the cloudbase repo) and was able to exercise the code changes
in netlink-socket.c to read the PID. dpif-linux.c changes are
not being checked in.

Signed-off-by: Nithin Raju <nithin@vmware.com>
Acked-by: Alin Serdean <aserdean@cloudbasesolutions.com>
Acked-by: Ankur Sharma <ankursharma@vmware.com>
Acked-by: Saurabh Shah <ssaurabh@vmware.com>
Reported-at: https://github.com/openvswitch/ovs-issues/issues/18
Signed-off-by: Ben Pfaff <blp@nicira.com>
ovsdb: Allow comparison on optional scalar types

This allows things like initiating a wait request on an interface
ofport being set.

When the optional field is empty and operation is != or excludes
then the result is true; otherwise it is false. If the field is
set then the field is compared normally for its type.

Signed-off-by: Terry Wilson <twilson@redhat.com>
[blp@nicira.com updated ovsdb-server(1) and NEWS.]
Signed-off-by: Ben Pfaff <blp@nicira.com>
tests: Add test that 1.5 copy-field can copy into the standardized xregs.

Signed-off-by: Jean Tourrilhes <jt@hpl.hp.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
ovs-ofctl: Document that "move" uses a standard action in OF1.5+.

Reported-by: Jean Tourrilhes <jt@hpl.hp.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jean Tourrilhes <jt@hpl.hp.com>
datapath-windows: define a version number in DP extensions

We need a version number for the datapath interface extensions that
we can leverage at some point.

Signed-off-by: Nithin Raju <nithin@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
netlink-socket.c: add support for do_lookup_genl_family on Windows

In this patch, we add support for querying the genl family id for any
family supported by the OVS kernel datapath. On platforms that support
netlink natively, the operating system assigns a family ID, and the
OS netlink infrastructure supports querying the family ID by name.

In case of Windows, since OVS datpath provides the netlink support,
it is not necessary to make a call into the kernel. Returning a
family ID that is consistent between the userspace and kernel
is sufficient. Once there is code to support netlink message parsing
as well as constructing netlink messages, we can make a call into
the kernel, but that in itself may not buy anything more than this
approach.

This patch is a precursor to make progress of the other commands.
The next hurdle is to support nl_lookup_genl_mcgroup().

Signed-off-by: Nithin Raju <nithin@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath-windows: add netlink message parsing APIs

In this change we introduce Netlink.c, Netlink.h and NetlinkProto.h
in datapath-windows. These files will provide netlink message
data structures and parsing APIs.

Changes are on similar lines to userspace netlink code.

We have mapped the userspace APIs and data structures to
kernel coding convention.
for example:
nlmsghdr ==> NL_MSG_HDR
nl_attr_get ==> NlAttrGet

Signed-off-by: Ankur Sharma <ankursharma@vmware.com>
Reported-at: https://github.com/openvswitch/ovs-issues/issues/18
Acked-by: Nithin Raju <nithin@vmware.com>
Acked-by: Samuel Ghinet <sghinet@cloudbasesolutions.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath-windows: Using windows kernel netlink parsing APIs.

In this patch we incorporate the usage of netlink message
and the parsing APIs that were added in previous commit.

Signed-off-by: Ankur Sharma <ankursharma@vmware.com>
Reported-at: https://github.com/openvswitch/ovs-issues/issues/18
Acked-by: Nithin Raju <nithin@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath-windows: remove reference to OvsNetlink.h

In this patch we remove reference to OvsNetlink.h.
Since we do not refer to lib/netlink-protocol.h anymore,
hence removed the WIN_DP based check as well.

Signed-off-by: Ankur Sharma <ankursharma@vmware.com>
Reported-at: https://github.com/openvswitch/ovs-issues/issues/18
Acked-by: Nithin Raju <nithin@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath-windows: Use OVS_DEFAULT_PORT_NO instead of 0 in a few places

Signed-off-by: Nithin Raju <nithin@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Saurabh Shah <ssaurabh@vmware.com>