Adding checksum to ICMP packets created by OVS for testing.

OVS provides a utility to create ICMP packets for the purpose of
testing using ovs-appctl netdev-dummy/receive.  These packets created
by flow_compose() earlier did not have the ICMP checksum in them.
With this commit, the checksum will be added to these test ICMP
packets.

Signed-off-by: Mehak Mahajan <mmahajan@nicira.com>
vconn: Ensure that vconn_run() is enough to complete a connection.

Until now, it seems that all vconn users have immediately started reading
messages from the connection.  Today, however, I added a new user that
only wants to read packets after the OpenFlow version is negotiated, so
it never called vconn_recv() before that happened.  It turns out that if
you do this, the version never gets negotiated at all.

This commit fixes the problem by ensuring that vconn_run() will continue
version negotiation if it isn't done yet.

This changes the error return that I get for Unix sockets in the
test-vconn "accept-then-close" test from EPIPE to ECONNRESET, so this
commit also adjusts that test to accept either error code; both of them
seem reasonable enough to me.

Signed-off-by: Ben Pfaff <blp@nicira.com>
vconn: Fix vconn_get_version().

It's documented to return -1 if the version isn't yet known, but in fact
it returned 0.

Signed-off-by: Ben Pfaff <blp@nicira.com>
learning-switch: Make lswitch own its rconn.

Until now, ovs-controller and the learning-switch code split responsibility
for the OpenFlow connection.  This commit moves all the responsibility into
the learning-switch code.

The rationale here is twofold.  First, the split itself seems odd; I think
there must have been a reason for it at one time, but I don't remember it
and don't see one anymore.  Second, I intend to make the lswitch code more
stateful in upcoming commits, and it seems odd to have the lswitch manage
quite a bit of state but not the entity that that state applies to.

Signed-off-by: Ben Pfaff <blp@nicira.com>
learning-switch: Delay sending handshake until version negotiation is done.

The learning-switch implementation needs to know the OpenFlow version in
use to send the initial handshake messages (e.g. the feature request), but
the version is not always available at the time that the code currently
sends the handshake.  This can cause an assertion failure later when
ofputil_encode_flow_mod() checks the protocol, which will be 0 if the
version wasn't known.

This commit fixes the problem by introducing a state machine that sends the
handshake messages only after version negotiation has finished.

Reported-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Ben Pfaff <blp@nicira.com>
learning-switch: Don't use exact-match on every field by default.

OVS has all kinds of odd fields, e.g. registers, and it doesn't make sense
to try to match on all of them.  This commit changes learning-switch to
only try to match on the fields defined by OpenFlow 1.0.  That's still not
minimal, but it's more reasonable.

This commit should not have an immediately visible effect since
ovs-controller always sends OF1.0 format flows to the switch, and OF1.0
format flows don't have these extra fields.  But in the future when we
add support for new protocols and flow formats to ovs-controller, it
will make a difference.

Signed-off-by: Ben Pfaff <blp@nicira.com>
learning-switch: Normalize the flows that are sent to the switch.

This suppresses a long-standing warning from ovs-vswitchd about
non-normalized flows.

Signed-off-by: Ben Pfaff <blp@nicira.com>
vconn: Properly line up description for "tcp:" and "ssl:" usage.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
tests: Test that ofp10_match bytes that should be ignored really are.

Rob Sherwood reported a bug in OVS treatment of ofp10_match bytes that
should be ignored some time ago:

> In any case, the pktact.SingleWildcardMatch and
> pktact.AllExceptOneWildcardMatch tests were failing because it looks
> like OVS (v1.4 release) was  not matching vlan tagged packets when the
> match wildcarded vlan but the dl_vlan value (which should be ignored,
> because it is wildcarded) was non-zero.  We've worked around this in
> OFTest by making sure that the dl_vlan value is zero when vlan is
> wildcarded and now the test passes.
>
> In other words:
>
> if (ofp_match->wildcards&OFPFW_DL_VLAN) is true, then the match should
> match both tagged and untagged packets, independent of the value of
> ofp_match->dl_vlan.  OVS (seemingly) only matches tagged packets if
> ofp_match->dl_vlan == 0.

I wasn't able to spot the problem at the time, and I still don't see a
problem (perhaps it has been fixed since then), but this commit should
prevent any regression for this specific problem and for anything like it.

It would be natural to modify the parse-ofp11-match test in the same way,
but this commit doesn't do it.

Rob's original bug report is at:
https://mailman.stanford.edu/pipermail/openflow-discuss/2012-March/003107.html

Reported-by: Rob Sherwood <rob.sherwood@bigswitch.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
vlog: Ignore return value of some write() calls.

A couple of calls to write() would generate warnings when the
"-Wunused-result" compiler option is enabled.  This change ignores the
return value, since we can't do anything about it in logging code.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
ofp-util: ofputil_pull_ofp11_match: Allow OXM match

* Allow OXM matches which specified in OpenFlow 1.2.
  Also allow them for OpenFlow 1.1 as there seems little reason not to.

* Pass padded_match_len parameter which if on NULL will be set to
  the padded match len. This will be used when decoding flow statistics
  response messages.

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

---

v10
* Allow OXM for OpenFlow 1.1, as suggested by Ben Pfaff
  - Do not add ofputil_pull_ofp12_match(), rather,
    allow an enhanced ofputil_pull_ofp11_match() to handle
    both OpenFlow 1.1 and 1.2.
  - Rename from "ofp-util: Add ofputil_pull_ofp12_match()" to
    "ofp-util: ofputil_pull_ofp11_match: Allow OXM match"

v9
* No change

v8
* Manual Rebase
  - Remove cookie and cookie mask parameters
* Use '__' as a suffix rather than a prefix

v7
* Make use of oxm_pull_match()
  Change subject from "ofp-util: Add ofputil_ofp12_decode_match()" to
  "ofp-util: Add ofputil_pull_ofp12_match()"

v6
* No change

v5
* Add padded_match_len parameter to
  ofputil_pull_ofp12_match() and __ofputil_pull_ofp11_match().
  This will be used when decoding messages that need
  to know the match length.
* Read mach_length from omh after the length of buf has been verified,
  else an over-run may occur.

v4
* No change

v3
* Do not pull ofpbuf_pull() in the case of a STANDARD match.
  This simplifies things a little.

v2
* No change
ofp-print: Open Flow 1.2 Flow Mod message tests

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

---

v10
* Remove non-test portions as they have already been merged.
  Ben, did you intentionally omit the tests? If so, feel free
  to drop this patch.
* Rename from "ofp-util: Allow encoding of Open Flow 1.2 Flow Mod Messages"
  to "ofp-print: Open Flow 1.2 Flow Mod message tests"

v9
* No change

v8
* Manual rebase
* Add ofp-print test

v7
* Manual rebase

v6
* No change

v5
* Manual rebase

v4
* No change

v3
* No change

v2
* No change
ofp-util: Allow encoding of Open Flow 1.2 Packet In Messages

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

---

v10
* No change

v9
* No change

v8
* Manual Rebase

v7
* Manual Rebase
* Use struct ofp12_packet_in instead of struct ofp11_packet_in

v6
* No change

v5
* No change

v4
* No change

v3
* Add protocol parameter to ofputil_encode_packet_in().
  This allows packet_in_format to be ignored for Open Flow 1.2.

v2
* Update for new ofputil_put_match() implementation
ofp-util: Allow decoding of Open Flow 1.2 Packet In Messages

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

---

v10
* No change

v9
* No change

v8
* Manual rebase
* Add ofp-print test

v7
* Manual rebase
* Use struct ofp12_packet_in instead of struct ofp11_packet_in

v6
* No change

v5
* Manual rebase

v4
* No change

v3
* Add OF1.2 entry to to ofputil_msg_types
* Make OF1.2 the first option in the if statement in ofputil_decode_packet_in()
* Rename o11pi as opi, which is consistent with the style used elsewhere
* Rebase

v2
* No change
ofp-msgs: Update OFPRAW_OFPT_SET_CONFIG for OpenFlow 1.2

This is sufficient to allow encoding and decoding of
OpenFlow 1.2 Set Config messages as the format is the same
as OpenFlow 1.0 and OpenFlow 1.2.

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

---

v10
* No change

v9
* No change

v8
* No change

v7
* Initial Post
ofp-actions: Return action size

Modify ofpacts_put_openflow11_actions() to return the length of actions
appended. This will be used when encoding Packet Out messages for
Open Flow 1.1 and 1.2. The motivation for this is to avoid open coding
the size calculation which may end up being needed elsewhere too.

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

---

v10
* No change

v9
* No change

v8
* Initial post
ofp-util: Prepare Packet Out encoder for other Open Flow versions

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

---

v11
* Manual rebase

v10
* No change

v9
* Resolve breakage caused by reordering patches in v8

v8
* Make use of enum ofp_version

v7
* Manual Rebase

v6
* No change

v5
* No change

v4
* Manual rebase

v3
* Add protocol variable to do_probe().
  Previously this was added by a separate patch.

v2
* No change
ofp-util: Allow encoding of Open Flow 1.1 and 1.2 Packet Out Messages

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

---

v10
* No change

v9
* No change

v8
* Manual Rebase
* ofpacts_put_openflow11_actions() now returns the length of encoded
  actions, make use of this.

v7
* Manual Rebase

v6
* No change

v5
* No change

v4
* Manual rebase

v3
* Correct title: this patch relates to Packet Out not Packet In
* Correct decoding of buffer_id, it is 32bits wide not 16bits wide
* Add decoding of stats reply messages

v2
* No change

ofp-actions: Return action size

Modify ofpacts_put_openflow11_actions() to return the length of actions
appended. This will be used when encoding Packet Out messages for
Open Flow 1.1 and 1.2. The motivation for this is to avoid open coding
the size calculation which may end up being needed elsewhere too.

Signed-off-by: Simon Horman <horms@verge.net.au>
ofp-util: Prepare Packet Out decoder for other Open Flow versions

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

---

v10
* No change

v9
* No change

v8
* No change

v7
* Manual Rebase
* Only use OFPERR_NXBRC_BAD_IN_PORT in the case of OFPRAW_OFPT10_PACKET_OUT

v6
* No change

v5
* No change

v4
* No change

v3
* Differentiate versions using oh->version rather than relying
  on a separate code for each version of the Packet Out message.

v2
* No change
ofp-util: Allow decoding of Open Flow 1.1 and 1.2 Packet Out Messages

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

---

v10
* No change

v9
* No change

v8
* Return error value returned by ofputil_port_from_ofp11()
  rather than OFPERR_OFPBMC_BAD_VALUE.
  - This fix, from v3, disappeared somewhere along the way
* Add ofp-print test for Open Flow 1.2
  - I'm not sure how to generate an Open Flow 1.1 message at this point

v7
* Manual rebase

v6
* No change

v5
* No change

v4
* No change

v3
* Manual rebase
* Correct title: This patch relates to Packet Out not Packet In
* Use OFPT_PACKET_OUT instead of OFPT11_PACKET_OUT, it seems
  easier to use a single code and differentiate using the version
  in the ofp_header
* Return error value returned by ofputil_port_from_ofp11()
  rather than OFPERR_OFPBMC_BAD_VALUE.

v2
* No change