The group bucket encoding code appears in two places in almost identical form. Consolidate this into a helper function.
The helper name includes ofp11 as later patches will add and ofp15 version to support (draft) OpenFlow 1.5 buckets. EXT-350 Signed-off-by: Simon Horman <simon.hor...@netronome.com> --- lib/ofp-util.c | 46 ++++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 2f3dec8..0f34a11 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -7189,6 +7189,24 @@ ofputil_decode_group_stats_reply(struct ofpbuf *msg, return 0; } +static void +ofputil_put_ofp11_bucket(const struct ofputil_bucket *bucket, + struct ofpbuf *openflow, enum ofp_version ofp_version) +{ + struct ofp11_bucket *ob; + size_t start; + + start = ofpbuf_size(openflow); + ofpbuf_put_zeros(openflow, sizeof *ob); + ofpacts_put_openflow_actions(bucket->ofpacts, bucket->ofpacts_len, + openflow, ofp_version); + ob = ofpbuf_at_assert(openflow, start, sizeof *ob); + ob->len = htons(ofpbuf_size(openflow) - start); + ob->weight = htons(bucket->weight); + ob->watch_port = ofputil_port_to_ofp11(bucket->watch_port); + ob->watch_group = htonl(bucket->watch_group); +} + /* Appends a group stats reply that contains the data in 'gds' to those already * present in the list of ofpbufs in 'replies'. 'replies' should have been * initialized with ofpmp_init(). */ @@ -7206,18 +7224,7 @@ ofputil_append_group_desc_reply(const struct ofputil_group_desc *gds, start_ogds = ofpbuf_size(reply); ofpbuf_put_zeros(reply, sizeof *ogds); LIST_FOR_EACH (bucket, list_node, buckets) { - struct ofp11_bucket *ob; - size_t start_ob; - - start_ob = ofpbuf_size(reply); - ofpbuf_put_zeros(reply, sizeof *ob); - ofpacts_put_openflow_actions(bucket->ofpacts, bucket->ofpacts_len, - reply, version); - ob = ofpbuf_at_assert(reply, start_ob, sizeof *ob); - ob->len = htons(ofpbuf_size(reply) - start_ob); - ob->weight = htons(bucket->weight); - ob->watch_port = ofputil_port_to_ofp11(bucket->watch_port); - ob->watch_group = htonl(bucket->watch_group); + ofputil_put_ofp11_bucket(bucket, reply, version); } ogds = ofpbuf_at_assert(reply, start_ogds, sizeof *ogds); ogds->length = htons(ofpbuf_size(reply) - start_ogds); @@ -7342,9 +7349,7 @@ ofputil_encode_group_mod(enum ofp_version ofp_version, struct ofpbuf *b; struct ofp11_group_mod *ogm; size_t start_ogm; - size_t start_bucket; struct ofputil_bucket *bucket; - struct ofp11_bucket *ob; switch (ofp_version) { case OFP10_VERSION: { @@ -7370,18 +7375,7 @@ ofputil_encode_group_mod(enum ofp_version ofp_version, ofpbuf_put_zeros(b, sizeof *ogm); LIST_FOR_EACH (bucket, list_node, &gm->buckets) { - start_bucket = ofpbuf_size(b); - ofpbuf_put_zeros(b, sizeof *ob); - if (bucket->ofpacts && bucket->ofpacts_len) { - ofpacts_put_openflow_actions(bucket->ofpacts, - bucket->ofpacts_len, b, - ofp_version); - } - ob = ofpbuf_at_assert(b, start_bucket, sizeof *ob); - ob->len = htons(ofpbuf_size(b) - start_bucket);; - ob->weight = htons(bucket->weight); - ob->watch_port = ofputil_port_to_ofp11(bucket->watch_port); - ob->watch_group = htonl(bucket->watch_group); + ofputil_put_ofp11_bucket(bucket, b, ofp_version); } ogm = ofpbuf_at_assert(b, start_ogm, sizeof *ogm); ogm->command = htons(gm->command); -- 2.1.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev