2
0
mirror of https://github.com/openvswitch/ovs synced 2025-09-02 23:35:27 +00:00

ofpbuf: Simplify ofpbuf API.

ofpbuf was complicated due to its wide usage across all
layers of OVS, Now we have introduced independent dp_packet
which can be used for datapath packet, we can simplify ofpbuf.
Following patch removes DPDK mbuf and access API of ofpbuf
members.

Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Pravin B Shelar
2015-03-02 17:29:44 -08:00
parent cf62fa4c70
commit 6fd6ed71cb
42 changed files with 705 additions and 1058 deletions

View File

@@ -372,7 +372,7 @@ ofpraw_decode_assert(const struct ofp_header *oh)
}
/* Determines the OFPRAW_* type of the OpenFlow message in 'msg', which starts
* at 'ofpbuf_data(msg)' and has length 'ofpbuf_size(msg)' bytes. On success,
* at 'msg->data' and has length 'msg->size' bytes. On success,
* returns 0 and stores the type into '*rawp'. On failure, returns an OFPERR_*
* error code and zeros '*rawp'.
*
@@ -382,8 +382,8 @@ ofpraw_decode_assert(const struct ofp_header *oh)
* In addition to setting '*rawp', this function pulls off the OpenFlow header
* (including the stats headers, vendor header, and any subtype header) with
* ofpbuf_pull(). It also sets 'msg->frame' to the start of the OpenFlow
* header and 'msg->l3' just beyond the headers (that is, to the final value of
* ofpbuf_data(msg)). */
* header and 'msg->msg' just beyond the headers (that is, to the final value of
* msg->data). */
enum ofperr
ofpraw_pull(enum ofpraw *rawp, struct ofpbuf *msg)
{
@@ -400,12 +400,12 @@ ofpraw_pull(enum ofpraw *rawp, struct ofpbuf *msg)
enum ofpraw raw;
/* Set default outputs. */
msg->frame = ofpbuf_data(msg);
ofpbuf_set_l3(msg, msg->frame);
msg->header = msg->data;
msg->msg = msg->header;
*rawp = 0;
len = ofpbuf_size(msg);
error = ofphdrs_decode(&hdrs, ofpbuf_data(msg), len);
len = msg->size;
error = ofphdrs_decode(&hdrs, msg->data, len);
if (error) {
return error;
}
@@ -417,8 +417,8 @@ ofpraw_pull(enum ofpraw *rawp, struct ofpbuf *msg)
info = raw_info_get(raw);
instance = raw_instance_get(info, hdrs.version);
msg->frame = ofpbuf_pull(msg, instance->hdrs_len);
ofpbuf_set_l3(msg, ofpbuf_data(msg));
msg->header = ofpbuf_pull(msg, instance->hdrs_len);
msg->msg = msg->data;
min_len = instance->hdrs_len + info->min_body;
switch (info->extra_multiple) {
@@ -593,7 +593,7 @@ ofpraw_alloc_stats_reply(const struct ofp_header *request,
* must specify a valid (raw, version) pair.
*
* Upon return, 'buf->frame' points to the beginning of the OpenFlow header and
* 'buf->l3' points just after it, to where the message's body will start. The
* 'buf->msg' points just after it, to where the message's body will start. The
* caller must actually allocating the body into the space reserved for it,
* e.g. with ofpbuf_put_uninit(). */
void
@@ -665,17 +665,17 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid,
ofpbuf_prealloc_tailroom(buf, (instance->hdrs_len + info->min_body
+ extra_tailroom));
buf->frame = ofpbuf_put_uninit(buf, instance->hdrs_len);
ofpbuf_set_l3(buf, ofpbuf_tail(buf));
buf->header = ofpbuf_put_uninit(buf, instance->hdrs_len);
buf->msg = ofpbuf_tail(buf);
oh = buf->frame;
oh = buf->header;
oh->version = version;
oh->type = hdrs->type;
oh->length = htons(ofpbuf_size(buf));
oh->length = htons(buf->size);
oh->xid = xid;
if (hdrs->type == OFPT_VENDOR) {
struct nicira_header *nh = buf->frame;
struct nicira_header *nh = buf->header;
ovs_assert(hdrs->vendor == NX_VENDOR_ID);
nh->vendor = htonl(hdrs->vendor);
@@ -683,17 +683,17 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid,
} else if (version == OFP10_VERSION
&& (hdrs->type == OFPT10_STATS_REQUEST ||
hdrs->type == OFPT10_STATS_REPLY)) {
struct ofp10_stats_msg *osm = buf->frame;
struct ofp10_stats_msg *osm = buf->header;
osm->type = htons(hdrs->stat);
osm->flags = htons(0);
if (hdrs->stat == OFPST_VENDOR) {
struct ofp10_vendor_stats_msg *ovsm = buf->frame;
struct ofp10_vendor_stats_msg *ovsm = buf->header;
ovsm->vendor = htonl(hdrs->vendor);
if (hdrs->vendor == NX_VENDOR_ID) {
struct nicira10_stats_msg *nsm = buf->frame;
struct nicira10_stats_msg *nsm = buf->header;
nsm->subtype = htonl(hdrs->subtype);
memset(nsm->pad, 0, sizeof nsm->pad);
@@ -704,18 +704,18 @@ ofpraw_put__(enum ofpraw raw, uint8_t version, ovs_be32 xid,
} else if (version != OFP10_VERSION
&& (hdrs->type == OFPT11_STATS_REQUEST ||
hdrs->type == OFPT11_STATS_REPLY)) {
struct ofp11_stats_msg *osm = buf->frame;
struct ofp11_stats_msg *osm = buf->header;
osm->type = htons(hdrs->stat);
osm->flags = htons(0);
memset(osm->pad, 0, sizeof osm->pad);
if (hdrs->stat == OFPST_VENDOR) {
struct ofp11_vendor_stats_msg *ovsm = buf->frame;
struct ofp11_vendor_stats_msg *ovsm = buf->header;
ovsm->vendor = htonl(hdrs->vendor);
if (hdrs->vendor == NX_VENDOR_ID) {
struct nicira11_stats_msg *nsm = buf->frame;
struct nicira11_stats_msg *nsm = buf->header;
nsm->subtype = htonl(hdrs->subtype);
} else {
@@ -792,7 +792,7 @@ ofptype_decode(enum ofptype *typep, const struct ofp_header *oh)
}
/* Determines the OFPTYPE_* type of the OpenFlow message in 'msg', which starts
* at 'ofpbuf_data(msg)' and has length 'ofpbuf_size(msg)' bytes. On success,
* at 'msg->data' and has length 'msg->size' bytes. On success,
* returns 0 and stores the type into '*typep'. On failure, returns an
* OFPERR_* error code and zeros '*typep'.
*
@@ -802,8 +802,8 @@ ofptype_decode(enum ofptype *typep, const struct ofp_header *oh)
* In addition to setting '*typep', this function pulls off the OpenFlow header
* (including the stats headers, vendor header, and any subtype header) with
* ofpbuf_pull(). It also sets 'msg->frame' to the start of the OpenFlow
* header and 'msg->l3' just beyond the headers (that is, to the final value of
* ofpbuf_data(msg)). */
* header and 'msg->msg' just beyond the headers (that is, to the final value of
* msg->data). */
enum ofperr
ofptype_pull(enum ofptype *typep, struct ofpbuf *buf)
{
@@ -826,12 +826,12 @@ ofptype_from_ofpraw(enum ofpraw raw)
}
/* Updates the 'length' field of the OpenFlow message in 'buf' to
* 'ofpbuf_size(buf)'. */
* 'buf->size'. */
void
ofpmsg_update_length(struct ofpbuf *buf)
{
struct ofp_header *oh = ofpbuf_at_assert(buf, 0, sizeof *oh);
oh->length = htons(ofpbuf_size(buf));
oh->length = htons(buf->size);
}
/* Returns just past the OpenFlow header (including the stats headers, vendor
@@ -882,7 +882,7 @@ ofpmp_reserve(struct ovs_list *replies, size_t len)
{
struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
if (ofpbuf_size(msg) + len <= UINT16_MAX) {
if (msg->size + len <= UINT16_MAX) {
ofpbuf_prealloc_tailroom(msg, len);
return msg;
} else {
@@ -890,16 +890,16 @@ ofpmp_reserve(struct ovs_list *replies, size_t len)
struct ofpbuf *next;
struct ofphdrs hdrs;
ofphdrs_decode_assert(&hdrs, ofpbuf_data(msg), ofpbuf_size(msg));
ofphdrs_decode_assert(&hdrs, msg->data, msg->size);
hdrs_len = ofphdrs_len(&hdrs);
next = ofpbuf_new(MAX(1024, hdrs_len + len));
ofpbuf_put(next, ofpbuf_data(msg), hdrs_len);
next->frame = ofpbuf_data(next);
ofpbuf_set_l3(next, ofpbuf_tail(next));
ofpbuf_put(next, msg->data, hdrs_len);
next->header = next->data;
next->msg = ofpbuf_tail(next);
list_push_back(replies, &next->list_node);
*ofpmp_flags__(ofpbuf_data(msg)) |= htons(OFPSF_REPLY_MORE);
*ofpmp_flags__(msg->data) |= htons(OFPSF_REPLY_MORE);
return next;
}
@@ -929,11 +929,11 @@ ofpmp_postappend(struct ovs_list *replies, size_t start_ofs)
struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
ovs_assert(start_ofs <= UINT16_MAX);
if (ofpbuf_size(msg) > UINT16_MAX) {
size_t len = ofpbuf_size(msg) - start_ofs;
if (msg->size > UINT16_MAX) {
size_t len = msg->size - start_ofs;
memcpy(ofpmp_append(replies, len),
(const uint8_t *) ofpbuf_data(msg) + start_ofs, len);
ofpbuf_set_size(msg, start_ofs);
(const uint8_t *) msg->data + start_ofs, len);
msg->size = start_ofs;
}
}
@@ -943,7 +943,7 @@ enum ofp_version
ofpmp_version(struct ovs_list *replies)
{
struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
const struct ofp_header *oh = ofpbuf_data(msg);
const struct ofp_header *oh = msg->data;
return oh->version;
}
@@ -957,7 +957,7 @@ ofpmp_decode_raw(struct ovs_list *replies)
enum ofperr error;
enum ofpraw raw;
error = ofpraw_decode_partial(&raw, ofpbuf_data(msg), ofpbuf_size(msg));
error = ofpraw_decode_partial(&raw, msg->data, msg->size);
ovs_assert(!error);
return raw;
}