From dfdfc8d43d102f4b5851d26773c1786ee2b13877 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 23 Nov 2010 13:31:07 -0800 Subject: [PATCH] ofp-util: New functions for creating Nicira extension messages. --- 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 71e57677f..11836ccdd 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -821,11 +821,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 @@ -870,6 +867,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 @@ -879,6 +898,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 a 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 733fc7149..f82e083a5 100644 --- a/lib/ofp-util.h +++ b/lib/ofp-util.h @@ -115,15 +115,27 @@ 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 *); size_t ofputil_stats_body_len(const struct ofp_header *oh); -- 2.43.0