[ovs-dev] [tests+nxm-ofctl 35/42] ofp-util: New functions for creating Nicira extension messages.

Ben Pfaff blp at nicira.com
Tue Nov 23 22:44:07 UTC 2010


---
 lib/ofp-util.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 lib/ofp-util.h |   12 +++++++++++
 2 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 375ab11..0ed738d 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -817,11 +817,8 @@ void *
 make_nxmsg_xid(size_t openflow_len, uint32_t subtype, ovs_be32 xid,
                struct ofpbuf **bufferp)
 {
-    struct nicira_header *nxh = make_openflow_xid(openflow_len, OFPT_VENDOR,
-                                                  xid, bufferp);
-    nxh->vendor = htonl(NX_VENDOR_ID);
-    nxh->subtype = htonl(subtype);
-    return nxh;
+    *bufferp = ofpbuf_new(openflow_len);
+    return put_nxmsg_xid(openflow_len, subtype, xid, *bufferp);
 }
 
 /* Appends 'openflow_len' bytes to 'buffer', starting with an OpenFlow header
@@ -866,6 +863,28 @@ put_openflow_xid(size_t openflow_len, uint8_t type, ovs_be32 xid,
     return oh;
 }
 
+/* Similar to put_openflow() but append a Nicira vendor extension message with
+ * the specific 'subtype'.  'subtype' should be in host byte order. */
+void *
+put_nxmsg(size_t openflow_len, uint32_t subtype, struct ofpbuf *buffer)
+{
+    return put_nxmsg_xid(openflow_len, subtype, alloc_xid(), buffer);
+}
+
+/* Similar to put_openflow_xid() but append a Nicira vendor extension message
+ * with the specific 'subtype'.  'subtype' should be in host byte order. */
+void *
+put_nxmsg_xid(size_t openflow_len, uint32_t subtype, ovs_be32 xid,
+              struct ofpbuf *buffer)
+{
+    struct nicira_header *nxh;
+
+    nxh = put_openflow_xid(openflow_len, OFPT_VENDOR, xid, buffer);
+    nxh->vendor = htonl(NX_VENDOR_ID);
+    nxh->subtype = htonl(subtype);
+    return nxh;
+}
+
 /* Updates the 'length' field of the OpenFlow message in 'buffer' to
  * 'buffer->size'. */
 void
@@ -875,6 +894,37 @@ update_openflow_length(struct ofpbuf *buffer)
     oh->length = htons(buffer->size);
 }
 
+/* Creates an ofp_stats_request with the given 'type' and 'body_len' bytes of
+ * space allocated for the 'body' member.  Returns the first byte of the 'body'
+ * member. */
+void *
+ofputil_make_stats_request(size_t body_len, uint16_t type,
+                           struct ofpbuf **bufferp)
+{
+    struct ofp_stats_request *osr;
+    osr = make_openflow((offsetof(struct ofp_stats_request, body)
+                        + body_len), OFPT_STATS_REQUEST, bufferp);
+    osr->type = htons(type);
+    osr->flags = htons(0);
+    return osr->body;
+}
+
+/* Creates an stats request message with Nicira as vendor and the given
+ * 'subtype', of total length 'openflow_len'.  Returns the message. */
+void *
+ofputil_make_nxstats_request(size_t openflow_len, uint32_t subtype,
+                             struct ofpbuf **bufferp)
+{
+    struct nicira_stats_msg *nsm;
+
+    nsm = make_openflow(openflow_len, OFPT_STATS_REQUEST, bufferp);
+    nsm->type = htons(OFPST_VENDOR);
+    nsm->flags = htons(0);
+    nsm->vendor = htonl(NX_VENDOR_ID);
+    nsm->subtype = htonl(subtype);
+    return nsm;
+}
+
 /* Returns the first byte of the 'body' member of the ofp_stats_request or
  * ofp_stats_reply in 'oh'. */
 const void *
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index bc01766..a7761a7 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -115,14 +115,26 @@ char *ofp_match_to_literal_string(const struct ofp_match *match);
 /* OpenFlow protocol utility functions. */
 void *make_openflow(size_t openflow_len, 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,
                         ovs_be32 xid, struct ofpbuf **);
 void *make_nxmsg_xid(size_t openflow_len, uint32_t subtype, ovs_be32 xid,
                      struct ofpbuf **);
+
 void *put_openflow(size_t openflow_len, uint8_t type, struct ofpbuf *);
 void *put_openflow_xid(size_t openflow_len, uint8_t type, ovs_be32 xid,
                        struct ofpbuf *);
+
+void *put_nxmsg(size_t openflow_len, uint32_t subtype, struct ofpbuf *);
+void *put_nxmsg_xid(size_t openflow_len, uint32_t subtype, ovs_be32 xid,
+                    struct ofpbuf *);
+
 void update_openflow_length(struct ofpbuf *);
+
+void *ofputil_make_stats_request(size_t body_len, uint16_t type,
+                                 struct ofpbuf **);
+void *ofputil_make_nxstats_request(size_t openflow_len, uint32_t subtype,
+                                   struct ofpbuf **);
 const void *ofputil_stats_body(const struct ofp_header *);
 
 struct ofpbuf *make_flow_mod(uint16_t command, const struct cls_rule *,
-- 
1.7.1





More information about the dev mailing list