I am unsure of the overall merit if this change, but it does allow to avoid a small amount of code duplication.
Signed-off-by: Simon Horman <ho...@verge.net.au> --- v4 * Manual rebase * Use an extra level of indirection for the msg argument of ofputil_encode_aggregate_stats_reply__ as the value of the pointer is needed set by ofputil_make_stats_reply() and needed by the caller. v3 * Initial post --- include/openflow/nicira-ext.h | 10 ---------- lib/ofp-print.c | 19 ++++++++++++------- lib/ofp-util.c | 33 +++++++++++++++++---------------- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/include/openflow/nicira-ext.h b/include/openflow/nicira-ext.h index 4ffcb86..4695e4c 100644 --- a/include/openflow/nicira-ext.h +++ b/include/openflow/nicira-ext.h @@ -1931,16 +1931,6 @@ struct nx_aggregate_stats_request { */ }; OFP_ASSERT(sizeof(struct nx_aggregate_stats_request) == 8); - -/* Body for nicira10_stats_msg reply of type NXST_AGGREGATE (analogous to - * OFPST_AGGREGATE reply). */ -struct nx_aggregate_stats_reply { - ovs_be64 packet_count; /* Number of packets, UINT64_MAX if unknown. */ - ovs_be64 byte_count; /* Number of bytes, UINT64_MAX if unknown. */ - ovs_be32 flow_count; /* Number of flows. */ - uint8_t pad[4]; /* Align to 64 bits. */ -}; -OFP_ASSERT(sizeof(struct nx_aggregate_stats_reply) == 24); /* NXT_SET_CONTROLLER_ID. * diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 01d5076..7e8c789 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1001,6 +1001,15 @@ ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh) } static void +ofp_print_ofpst_aggregate_reply__(struct ds *string, + const struct ofp11_aggregate_stats_reply *asr) +{ + ds_put_format(string, " packet_count=%"PRIu64, ntohll(asr->packet_count)); + ds_put_format(string, " byte_count=%"PRIu64, ntohll(asr->byte_count)); + ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count)); +} + +static void ofp_print_ofpst_aggregate_reply(struct ds *string, const struct ofp_header *oh) { struct ofp11_aggregate_stats_reply *asr = ofputil_stats_msg_body(oh); @@ -1014,19 +1023,15 @@ ofp_print_ofpst_aggregate_reply(struct ds *string, const struct ofp_header *oh) asr->flow_count = a10sr->flow_count; } - ds_put_format(string, " packet_count=%"PRIu64, ntohll(asr->packet_count)); - ds_put_format(string, " byte_count=%"PRIu64, ntohll(asr->byte_count)); - ds_put_format(string, " flow_count=%"PRIu32, ntohl(asr->flow_count)); + ofp_print_ofpst_aggregate_reply__(string, asr); } static void ofp_print_nxst_aggregate_reply(struct ds *string, const struct ofp_header *oh) { - const struct nx_aggregate_stats_reply *nasr = ofputil_stats_msg_body(oh); + const struct ofp11_aggregate_stats_reply *asr = ofputil_stats_msg_body(oh); - ds_put_format(string, " packet_count=%"PRIu64, ntohll(nasr->packet_count)); - ds_put_format(string, " byte_count=%"PRIu64, ntohll(nasr->byte_count)); - ds_put_format(string, " flow_count=%"PRIu32, ntohl(nasr->flow_count)); + ofp_print_ofpst_aggregate_reply__(string, asr); } static void print_port_stat(struct ds *string, const char *leader, diff --git a/lib/ofp-util.c b/lib/ofp-util.c index 83f187f..fa67f10 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -1007,7 +1007,7 @@ static const struct ofputil_msg_type ofputil_msg_types[] = { EXTRA_MULTIPLE \ } NXST_REPLY(FLOW, 0, 8), - NXST_REPLY(AGGREGATE, sizeof(struct nx_aggregate_stats_reply), 0), + NXST_REPLY(AGGREGATE, sizeof(struct ofp11_aggregate_stats_reply), 0), #undef NXST_REPLY }; @@ -2439,6 +2439,19 @@ ofputil_append_flow_stats_reply(uint8_t ofp_version, ofputil_postappend_stats_reply(start_ofs, replies); } +static void +ofputil_encode_aggregate_stats_reply__( + const struct ofputil_aggregate_stats *stats, + const struct ofp_header *request, struct ofpbuf **msg) +{ + struct ofp11_aggregate_stats_reply *asr; + + asr = ofputil_make_stats_reply(sizeof *asr, request, msg); + asr->packet_count = htonll(unknown_to_zero(stats->packet_count)); + asr->byte_count = htonll(unknown_to_zero(stats->byte_count)); + asr->flow_count = htonl(stats->flow_count); +} + /* Converts abstract ofputil_aggregate_stats 'stats' into an OFPST_AGGREGATE or * NXST_AGGREGATE reply according to 'protocol', and returns the message. */ struct ofpbuf * @@ -2452,14 +2465,9 @@ ofputil_encode_aggregate_stats_reply( ofputil_decode_msg_type(request, &type); code = ofputil_msg_type_code(type); - if (code == OFPUTIL_OFPST11_AGGREGATE_REQUEST) { - struct ofp11_stats_msg *osm; - struct ofp11_aggregate_stats_reply *asr; - - asr = ofputil_make_stats_reply(sizeof *asr, request, &msg); - asr->packet_count = htonll(unknown_to_zero(stats->packet_count)); - asr->byte_count = htonll(unknown_to_zero(stats->byte_count)); - asr->flow_count = htonl(stats->flow_count); + if (code == OFPUTIL_OFPST11_AGGREGATE_REQUEST || + code == OFPUTIL_NXST_AGGREGATE_REQUEST) { + ofputil_encode_aggregate_stats_reply__(stats, request, &msg); } else if (code == OFPUTIL_OFPST10_AGGREGATE_REQUEST) { struct ofp10_aggregate_stats_reply *asr; @@ -2469,13 +2477,6 @@ ofputil_encode_aggregate_stats_reply( put_32aligned_be64(&asr->byte_count, htonll(unknown_to_zero(stats->byte_count))); asr->flow_count = htonl(stats->flow_count); - } else if (code == OFPUTIL_NXST_AGGREGATE_REQUEST) { - struct nx_aggregate_stats_reply *nasr; - - nasr = ofputil_make_stats_reply(sizeof *nasr, request, &msg); - nasr->packet_count = htonll(stats->packet_count); - nasr->byte_count = htonll(stats->byte_count); - nasr->flow_count = htonl(stats->flow_count); } else { NOT_REACHED(); } -- 1.7.10.2.484.gcd07cc5 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev