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

---

v4
* Initial post
---
 lib/learning-switch.c |  9 +++++++--
 lib/ofp-util.c        | 19 ++++++++++---------
 lib/ofp-util.h        |  3 ++-
 lib/vconn.c           |  3 ++-
 utilities/ovs-ofctl.c | 26 +++++++++++++++++---------
 5 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/lib/learning-switch.c b/lib/learning-switch.c
index 9fad356..e5f726b 100644
--- a/lib/learning-switch.c
+++ b/lib/learning-switch.c
@@ -323,13 +323,18 @@ send_features_request(struct lswitch *sw, struct rconn 
*rconn)
     if (now >= sw->last_features_request + 1) {
         struct ofpbuf *b;
         struct ofp_switch_config *osc;
+        int ofp_version;
+
+        ofp_version = rconn_get_version(rconn);
+        assert(ofp_version >= 0 && ofp_version <= 0xff);
 
         /* Send OFPT_FEATURES_REQUEST. */
-        make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &b);
+        make_openflow(sizeof(struct ofp_header), ofp_version,
+                      OFPT_FEATURES_REQUEST, &b);
         queue_tx(sw, rconn, b);
 
         /* Send OFPT_SET_CONFIG. */
-        osc = make_openflow(sizeof *osc, OFPT_SET_CONFIG, &b);
+        osc = make_openflow(sizeof *osc, ofp_version, OFPT_SET_CONFIG, &b);
         osc->miss_send_len = htons(OFP_DEFAULT_MISS_SEND_LEN);
         queue_tx(sw, rconn, b);
 
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index c09dbba..c09f5ea 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -2995,7 +2995,7 @@ ofputil_encode_port_mod(const struct ofputil_port_mod *pm,
     if (ofp_version == OFP10_VERSION) {
         struct ofp10_port_mod *opm;
 
-        opm = make_openflow(sizeof *opm, OFPT10_PORT_MOD, &b);
+        opm = make_openflow(sizeof *opm, ofp_version, OFPT10_PORT_MOD, &b);
         opm->port_no = htons(pm->port_no);
         memcpy(opm->hw_addr, pm->hw_addr, ETH_ADDR_LEN);
         opm->config = htonl(pm->config & OFPPC10_ALL);
@@ -3004,7 +3004,7 @@ ofputil_encode_port_mod(const struct ofputil_port_mod *pm,
     } else if (ofp_version == OFP11_VERSION) {
         struct ofp11_port_mod *opm;
 
-        opm = make_openflow(sizeof *opm, OFPT11_PORT_MOD, &b);
+        opm = make_openflow(sizeof *opm, ofp_version, OFPT11_PORT_MOD, &b);
         opm->port_no = htonl(pm->port_no);
         memcpy(opm->hw_addr, pm->hw_addr, ETH_ADDR_LEN);
         opm->config = htonl(pm->config & OFPPC11_ALL);
@@ -3058,9 +3058,9 @@ ofputil_msg_type_name(const struct ofputil_msg_type *type)
 }
 
 /* Allocates and stores in '*bufferp' a new ofpbuf with a size of
- * 'openflow_len', starting with an OpenFlow header with the given 'type' and
- * an arbitrary transaction id.  Allocated bytes beyond the header, if any, are
- * zeroed.
+ * 'openflow_len', starting with an OpenFlow header with the given
+ * 'version' and 'type', and an arbitrary transaction id.  Allocated bytes
+ * beyond the header, if any, are zeroed.
  *
  * The caller is responsible for freeing '*bufferp' when it is no longer
  * needed.
@@ -3071,11 +3071,11 @@ ofputil_msg_type_name(const struct ofputil_msg_type 
*type)
  *
  * Returns the header. */
 void *
-make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **bufferp)
+make_openflow(size_t openflow_len, uint8_t version, uint8_t type,
+              struct ofpbuf **bufferp)
 {
     *bufferp = ofpbuf_new(openflow_len);
-    return put_openflow_xid(openflow_len, OFP10_VERSION, type,
-                            alloc_xid(), *bufferp);
+    return put_openflow_xid(openflow_len, version, type, alloc_xid(), 
*bufferp);
 }
 
 /* Similar to make_openflow() but creates a Nicira vendor extension message
@@ -3459,7 +3459,8 @@ ofputil_encode_barrier_request(void)
 {
     struct ofpbuf *msg;
 
-    make_openflow(sizeof(struct ofp_header), OFPT10_BARRIER_REQUEST, &msg);
+    make_openflow(sizeof(struct ofp_header), OFP10_VERSION,
+                  OFPT10_BARRIER_REQUEST, &msg);
     return msg;
 }
 
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index fb3fede..80b2065 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -517,7 +517,8 @@ struct ofpbuf *ofputil_encode_port_mod(const struct 
ofputil_port_mod *,
                                        enum ofputil_protocol);
 
 /* OpenFlow protocol utility functions. */
-void *make_openflow(size_t openflow_len, uint8_t type, struct ofpbuf **);
+void *make_openflow(size_t openflow_len, uint8_t version, uint8_t type,
+                    struct ofpbuf **);
 void *make_nxmsg(size_t openflow_len, uint32_t subtype, struct ofpbuf **);
 
 void *make_openflow_xid(size_t openflow_len, uint8_t type,
diff --git a/lib/vconn.c b/lib/vconn.c
index 5cd708d..676c4d3 100644
--- a/lib/vconn.c
+++ b/lib/vconn.c
@@ -385,7 +385,8 @@ vcs_send_hello(struct vconn *vconn)
     struct ofpbuf *b;
     int retval;
 
-    make_openflow(sizeof(struct ofp_header), OFPT_HELLO, &b);
+    /* Note that here OFP10_VERSION is the maximum version supported */
+    make_openflow(sizeof(struct ofp_header), OFP10_VERSION, OFPT_HELLO, &b);
     retval = do_send(vconn, b);
     if (!retval) {
         vconn->state = VCS_RECV_HELLO;
diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 6a65dc1..efe7d9d 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -361,7 +361,8 @@ static void
 dump_trivial_transaction(const char *vconn_name, uint8_t request_type)
 {
     struct ofpbuf *request;
-    make_openflow(sizeof(struct ofp_header), request_type, &request);
+    make_openflow(sizeof(struct ofp_header), OFP10_VERSION, request_type,
+                  &request);
     dump_transaction(vconn_name, request);
 }
 
@@ -451,8 +452,8 @@ fetch_switch_config(struct vconn *vconn, struct 
ofp_switch_config *config_)
     struct ofpbuf *request;
     struct ofpbuf *reply;
 
-    make_openflow(sizeof(struct ofp_header), OFPT_GET_CONFIG_REQUEST,
-                  &request);
+    make_openflow(sizeof(struct ofp_header), vconn_get_version(vconn),
+                  OFPT_GET_CONFIG_REQUEST, &request);
     run(vconn_transact(vconn, request, &reply),
         "talking to %s", vconn_get_name(vconn));
 
@@ -475,7 +476,8 @@ set_switch_config(struct vconn *vconn, struct 
ofp_switch_config *config_)
     struct ofp_header save_header;
     struct ofpbuf *request;
 
-    config = make_openflow(sizeof *config, OFPT_SET_CONFIG, &request);
+    config = make_openflow(sizeof *config, vconn_get_version(vconn),
+                           OFPT_SET_CONFIG, &request);
     save_header = config->header;
     *config = *config_;
     config->header = save_header;
@@ -492,8 +494,8 @@ do_show(int argc OVS_UNUSED, char *argv[])
     struct ofpbuf *reply;
     bool trunc;
 
-    make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST,
-                  &request);
+    make_openflow(sizeof(struct ofp_header), vconn_get_version(vconn),
+                  OFPT_FEATURES_REQUEST, &request);
     open_vconn(vconn_name, &vconn);
     run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
 
@@ -538,7 +540,8 @@ fetch_port_by_features(const char *vconn_name,
     bool found = false;
 
     /* Fetch the switch's ofp_switch_features. */
-    make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST, &request);
+    make_openflow(sizeof(struct ofp_header), vconn_get_version(vconn),
+                  OFPT_FEATURES_REQUEST, &request);
     open_vconn(vconn_name, &vconn);
     run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
     vconn_close(vconn);
@@ -1210,8 +1213,11 @@ do_probe(int argc OVS_UNUSED, char *argv[])
     struct vconn *vconn;
     struct ofpbuf *reply;
 
-    make_openflow(sizeof(struct ofp_header), OFPT_ECHO_REQUEST, &request);
     open_vconn(argv[1], &vconn);
+
+    make_openflow(sizeof(struct ofp_header), vconn_get_version(vconn),
+                  OFPT_ECHO_REQUEST, &request);
+
     run(vconn_transact(vconn, request, &reply), "talking to %s", argv[1]);
     if (reply->size != sizeof(struct ofp_header)) {
         ovs_fatal(0, "reply does not match request");
@@ -1383,6 +1389,7 @@ do_ping(int argc, char *argv[])
         struct ofp_header *rq_hdr, *rpy_hdr;
 
         rq_hdr = make_openflow(sizeof(struct ofp_header) + payload,
+                               vconn_get_version(vconn),
                                OFPT_ECHO_REQUEST, &request);
         random_bytes(rq_hdr + 1, payload);
 
@@ -1438,7 +1445,8 @@ do_benchmark(int argc OVS_UNUSED, char *argv[])
         struct ofpbuf *request, *reply;
         struct ofp_header *rq_hdr;
 
-        rq_hdr = make_openflow(message_size, OFPT_ECHO_REQUEST, &request);
+        rq_hdr = make_openflow(message_size, vconn_get_version(vconn),
+                               OFPT_ECHO_REQUEST, &request);
         memset(rq_hdr + 1, 0, payload_size);
         run(vconn_transact(vconn, request, &reply), "transact");
         ofpbuf_delete(reply);
-- 
1.7.10.2.484.gcd07cc5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to