vconn: Add ofputil_version_bitmap

Functions to manipulate a bitmap of allowed versions.

The bitmap is simple a uint32_t, allowing
for versions up until wire-protocol number 31.

Bit offsets correspond to ofp_version numbers which in turn
correspond to wire-protocol numbers for Open Flow versions..
E.g. (1 << OFP10_VERSION) is the mask for Open Flow 1.1.
If the bit for a version is set then it is allowed, otherwise it is
disallowed.

This is in preparation for allowing the range of allowed OpenFlow
versions to be configured.

Signed-off-by: Simon Horman <horms@verge.net.au>
vconn: Allowed OpenFlow versions

Replace minimum version with bitmap of allowed versions.

This is in preparation for allowing the range of allowed OpenFlow
versions to be configured.

As part of this change pvconn_open() is now paramatised over the allowed
versions.  this is to avoid avoids needing to provide version information
as a parameter to pvconn_accept().  This will in turn avoid the need to
pass version information to connmgr_run().

Signed-off-by: Simon Horman <horms@verge.net.au>
ofp-util: Add version bitmap support to hello messages

Allow encoding and decoding of version bitmap in hello messages
as specified in Open Flow 1.3.1.

Signed-off-by: Simon Horman <horms@verge.net.au>

---

v3
* As suggested by Ben Pfaff
  - Skip unknown hello elements
  - Use bitmap directly in the form of a uint32_t
    instead of creating a struct ofp_hello

v2
* Initial post
connmgr: Paramatise ofservice_create() over allowed OpenFlow versions

This is in preparation for allowing configuration of the
allowed OpenFlow versions.

Signed-off-by: Simon Horman <horms@verge.net.au>
ofproto: Make set_pvconns() aware of OpenFlow versions

Paramatise the allowed OpenFlow verion for snoops.
This is in preparation for making the allow OpenFlow verions to
be configured.

Signed-off-by: Simon Horman <horms@verge.net.au>
rconn: Add allowed OpenFlow versions

Add allowed OpenFlow versions to struct rconn to allow
reconnect to use these parameters rather than hard-coded defaults.

This is in preparation for allowing configuration of the
allowed OpenFlow versions.

Signed-off-by: Simon Horman <horms@verge.net.au>
ofproto, connmgr: Parameterise OpenFlow versions for adding controller

Allow allowed Open Flow versions to be passed rather
than relying on hard-coded defaults.

This is in preparation for allowing configuration of the
allowed OpenFlow versions.

Signed-off-by: Simon Horman <horms@verge.net.au>
ofp-util: Allow use of OpenFlow 12 flow format

This enables the use of the OpenFlow 12 flow format.

Signed-off-by: Simon Horman <horms@verge.net.au>
connmgr: Use version of underlying rconn

Signed-off-by: Simon Horman <horms@verge.net.au>
vswitchd: Configuration of allowed OpenFlow versions

Versions may be configured using a comma delimited list as
the value for 'openflow-versions' the 'other-config' column
of the Bridge table.

Currently list elements other than 'OpenFlow10' and 'OpenFlow12' will
be ignored.

If the list is empty, then OpenFlow10 is used.
This default is consistent with the behaviour of ovs-vswtichd
prior to this patch.

Signed-off-by: Simon Horman <horms@verge.net.au>
lib: Add helpers for OpenFlow version command line options

Signed-off-by: Simon Horman <horms@verge.net.au>
ovs-ofctl: Add option to set allowed OpenFlow versions

--allowed-ofp-versions allows configuration of the versions
that may be used when establishing an OpenFlow connection.

The default is 'OpenFlow10' which is consistent with
the behaviour prior to this patch.

The useful values at this time are:
'OpenFlow10', 'OpenFlow12' and 'OpenFlow10,OpenFlow12'.

Signed-off-by: Simon Horman <horms@verge.net.au>
ovs-controller: Allow setting of allowed OpenFlow versions

--allowed-ofp-versions allows configuration of the versions
that may be used when establishing an OpenFlow connection.

The default is 'OpenFlow10' which is consistent with
the behaviour prior to this patch.

The useful values at this time are:
'OpenFlow10', 'OpenFlow12' and 'OpenFlow10,OpenFlow12'.

Signed-off-by: Simon Horman <horms@verge.net.au>
ovs-ofctl: By default, do not set flow format for OpenFlow 1.1+

Only set the default format for ovs-ofctl monitor if
OpenFlow 1.0 is the prevailing version. IMHO that is
the only case where it makes sense.

Signed-off-by: Simon Horman <horms@verge.net.au>
ofp-util: Open Flow 1.1 and 1.2 flow format capabilities

Open Flow and 1.1 and 1.2 support some of the same
flow format capabilities as NXM.

Signed-off-by: Simon Horman <horms@verge.net.au>
ofp-util: Flow Dump Protocol for OpenFlow 12

Allow only OpenFlow 12 as a flow dump protocol for OpenFlow12.
Allow OpenFlow10 and NXM as flow dump protocols for other OpenFlow versions.
This only changes the behaviour prior to this patch in the case of OpenFlow12
which seemed broken as an attempt would be made to set NXM as the
flow dump format using an OpenFlow 1.0 message even though an OpenFlow 1.2
connection had been negotiated..

Signed-off-by: Simon Horman <horms@verge.net.au>
test: add ofproto OpenFlow1.2 tests

These were useful in isolating a number of bugs.

Signed-off-by: Simon Horman <horms@verge.net.au>

---

The "ofproto - flow table configuration (OpenFlow 1.2)]" test
will need to be updated for the MPLS changes that are outstanding
as they change the following:

wild=0xfffffffff -> wild=0x1fffffffff
match=0xfffffffff -> match=0x1fffffffff
write_setfields=0x0000000fffffffff -> write_setfields=0x0000001fffffffff
apply_setfields=0x0000000fffffffff -> write_setfields=0x0000001fffffffff
ofp-util: Optimize ofputil_version_bitmap_scanr

Make use of __builtin_clz if available which should optimize
ofputil_version_bitmap_scanr() by replacing a loop with
a single CLZ instruction when available.

I'm unsure if this approach is worth it or not.
But a similar approach could be taken to use ffs()
in bitmap_scan().

Signed-off-by: Simon Horman <horms@verge.net.au>
flow: Set ttl in flow_compose().

Thanks to Ben Pfaff for immediately pinpointing the likely location of
the issue.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
Signed-off-by: Simon Horman <horms@verge.net.au>
datapath: Add basic MPLS support to kernel

Allow datapath to recognize and extract MPLS labels into flow keys
and execute actions which push, pop, and set labels on packets.

Based heavily on work by Leo Alterman and Ravi K.

Cc: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: Ravi K <rkerur@gmail.com>
Cc: Leo Alterman <lalterman@nicira.com>
Signed-off-by: Simon Horman <horms@verge.net.au>

---

v2.3
* s/mpls_stack/mpls_bos/
  This is in keeping with the naming used in the OpenFlow 1.3 specification

v2.2
* Call skb_reset_mac_header() in skb_cb_set_mpls_stack()
  eth_hdr(skb) is non-NULL when called in skb_cb_set_mpls_stack().
* Add a call to skb_cb_set_mpls_stack() in ovs_packet_cmd_execute().
  I apologise that I have mislaid my notes on this but
  it avoids a kernel panic. I can investigate again if necessary.
* Use struct ovs_action_push_mpls instead of
  __be16 to decode OVS_ACTION_ATTR_PUSH_MPLS in validate_actions(). This is
  consistent with the data format for the attribute.
* Indentation fix in skb_cb_mpls_stack(). [cosmetic]

v2.1
* Manual rebase

Previous version(s) by Leo Alterman