openflow: Add enum ofp_version

Use an enum for ofp_version in ofp-util and ofp-msg.
This in conjunction with the use of switch() statements
allows the compiler to warn when a new ofp_version isn't handled.

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

---

Anecdotally, this type of approach has proved to be quite useful
in my work adding support for Open Flow 1.2 messages.

v8
* Initial post
ofproto: As of Open Flow 1.1 switch_features has no capabilities field

In Open Flow 1.0 switch_features has a capabilities field.
However, in Open Flow 1.1, 1.2 and 1.3 this field is reserved.
Thus it should not be read on decode and it seems most appropriate
to set as zero on encode.

This patch takes the approach of setting the features field to
all available features for Open Flow 1.1+. I am unsure if it would
be sufficient to just set it to zero.

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

---

v8
* Initial post
ofp-util: Add of12_action_bits

Add action bits for Open Flow 1.2, these are not the same as Open Flow 1.1.

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

---

v8
* Initial post
ofp-util: Reduce scope of variables in ofputil_encode_flow_mod()

Reduce scope of per-protocol variables in ofputil_encode_flow_mod()

These variables are only needed in one of the cases covered by the switch
statement and will increase in number as more cases (protocols) are
supported.

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

---

v8
* No change

v7
* No change

v6
* Manual Rebase

v5
* No change

v5
* No change

v4
* No change

v3
* No change

v2
* No change

Conflicts:
	lib/ofp-util.c
ofp-util: Update Capabilities for Open Flow 1.2

There are capabilities which are present in one, two and three
of Open Flow 1.0, 1.1 and 1.2. Update OFPC_COMMON to only include
capabilities that are present in all three Open Flow versions and
add ofputil_capabilities_mask() to return the mask of capabilities
for each version.

This does not cover OFPUTIL_C_STP and OFPUTIL_C_GROUP_STATS, which
both use capability bit 3 and are treated as special cases in
ofputil_encode_switch_features() and ofputil_decode_switch_features().

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

---

v8
* Manual rebase
* Merge of the following patches:
  - "ofp-util: Update ofputil_capabilities for Open Flow 1.2"
  - "ofp-util: Update OFPC_COMMON and add ofputil_capabilities_mask"
* Add test

v7
* Manual Rebase
* Use OFPC12_PORT_BLOCKED and OFPC_ARP_MATCH_IP in place of
  OFPUTIL_C_ARP_MATCH_IP and OFPUTIL_C_PORT_BLOCKED in
  ofputil_capabilities_mask(). I'm unsure what I was thinking.

v6
* No change

v5
* No change

v4
* No change

v3
* No change

v2
* No change

switch_features test
nx-match: Separate raw match and header/pad pull/put

In the case of Open Flow 1.2, which is currently the only
time that OXM is be used, there is a 4 byte header before
the match which needs to be taken into account when calculating
the pad length. This complicates nx_match pull and put somewhat.

This patch takes an approach suggested by Ben Pfaff to separate the
encoding of the match and the adding of padding and, in the case of OXM,
a header.

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

---

v8
* Manual rebase
* Remove cookie from OXM API as its not part of OXM

v7
* Correct the parse-oxm sub-command of ovs-ofputil
* Separate raw match encoding and header/pad encoding
* Change subject from "nx-match: Take into account leading header when
  calculating pad"

v6
* No change

v5
* Move nx_padded_match_len into nx-match.h as it will
  be used by code outside of nx-match.c added by subsequent patches.

v4
* Pad is needed even if match is zero length
  (what was I thinking?!)

v3
* Initial post
ofp-util: Add ofputil_pull_ofp12_match()

This may be used by both ofputil_decode_flow_mod() and
ofputil_decode_packet_in()

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

---

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-util: Allow encoding of Open Flow 1.1 & 1.2 Barrier Request Messages

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

---

v8
* Manual Rebase

v7
* Manual Rebase

v6
* No change

v5
* No change

v4
* Initial post

Conflicts:
	lib/ofp-util.c
ofp-util: Make ofperr_encode_msg__() use correct Open Flow version

Make ofperr_encode_msg__() use correct Open Flow version in the header
of messages.

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

---

v8
* Manual rebase

v7
* Manual rebase

v6
* No change

v5
* No change

v4
* Initial post

Conflicts:
	lib/ofp-errors.c
ofp-error: Remove ofperr_domain from external API

It seems that ofp_version suffices in all cases.

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

---

v8
* Initial post

  A preliminary version of this patch changed ofperr_domain_from_version()
  such that it uses NOT_REACHED() for unknown OF versions rather than
  returning 0. This simplifies its callers (all in ofp-error.c) a little.

  This caused a number of testsuite failures and this patch maintains
  the behaviour of ofperr_domain_from_version() that it returns NULL
  if there is an unknown version. And all callers have been made
  to handle that case gracefully.
ofp-util: Make make_echo_request() aware of different OpenFlow versions.

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

---

v8
* Manual Rebase

v7
* Manual Rebase

v6
* No change

v5
* No change

v4
* Initial post
ofp-print: Use the prevailing protocol to call ofputil_decode_flow_mod()

Pass a protocol based on the prevailing protocol to ofputil_decode_flow_mod()

Note that ofputil_protocol_from_ofp_version() needs to be made
Open Flow 1.1 aware.

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

---

v8
* Make use of ofputil_protocol_set_tid()
  As suggested by Ben Pfaff

v7
* Manual Rebase

v6
* No change

v5
* No change

v4
* No change

v3
* No change

v2
* Actually pass calculated protocol to ofputil_decode_flow_mod()

Conflicts:
	lib/ofp-print.c
learning-switch: Call ofputil_encode_flow_mod() with correct protocol

Empirically it appears that process_packet_in() should call
ofputil_encode_flow_mod() with protocol as defived from rconn
rather than sw->protocol.

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

---

v8
* No change

v7
* No change

v6
* No change

v5
* Actually retrieve protocol from rconn.
  This patch was dependent on a subsequent patch.

v4
* No change

v3
* Initial post
ofp-util: Allow encoding of Open Flow 1.2 Flow Mod messages

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

---

v8
* Manual Rebase
* Do not use memset from ofputil_encode_flow_mod it is (now) unnecessary

v7
* Manual Rebase

v6
* No change

v5
* No change

v4
* Manual rebase
* Use OFPT11_FLOW_MOD as type of message.
  Previously OFPT10_FLOW_MOD was incorrectly used.

v3
* Open Flow 1.2 uses an 8bit command, previously 16 bits was used incorrectly
* Use Open Flow 1.2 action encoding, previously Open Flow 1.0 encoding
  was used incorrectly
* ofp11_match_header is added by ofputil_put_match(),
  previously it was incorectly added in ofputil_encode_flow_mod() as well.

v2
* Use ofputil_put_match()

Conflicts:
	lib/ofp-util.c
ofp-util: Allow decoding of Open Flow 1.2 Flow Mod messages

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

---

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

Conflicts:
	lib/ofp-util.c

flow mod test
ofp-util: Allow encoding of Open Flow 1.2 Packet In Messages

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

---

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

Conflicts:
	lib/ofp-util.c
ofp-util: Allow decoding of Open Flow 1.2 Packet In Messages

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

---

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

Conflicts:
	lib/ofp-util.c
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>

---

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>

---

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

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

---

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

Conflicts:
	lib/ofp-util.c