Skip to content

Commit

Permalink
ofp-util: compile group stats with visual studio
Browse files Browse the repository at this point in the history
Visual studio supports zero-size array within a struct or union,
but has to be the last element. GCC does not have this restriction.

Commits 644cfd8 and 6fdaa45 make use of 0 size array.
Remove them so that visual studio can compile them as well.

Reported-by: Gurucharan Shetty <[email protected]>
Signed-off-by: Andy Zhou <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
azhou-nicira committed May 8, 2014
1 parent 6d765f1 commit 63759e7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
2 changes: 1 addition & 1 deletion include/openflow/openflow-1.1.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ struct ofp11_group_stats {
uint8_t pad2[4]; /* Align to 64 bits. */
ovs_be64 packet_count; /* Number of packets processed by group. */
ovs_be64 byte_count; /* Number of bytes processed by group. */
struct ofp11_bucket_counter bucket_stats[0];
/* struct ofp11_bucket_counter bucket_stats[]; */
};
OFP_ASSERT(sizeof(struct ofp11_group_stats) == 32);

Expand Down
2 changes: 1 addition & 1 deletion include/openflow/openflow-1.3.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ struct ofp13_group_stats {
ovs_be32 duration_sec; /* Time group has been alive in seconds. */
ovs_be32 duration_nsec; /* Time group has been alive in nanoseconds
beyond duration_sec. */
struct ofp11_bucket_counter bucket_stats[0];
/* struct ofp11_bucket_counter bucket_stats[]; */
};
OFP_ASSERT(sizeof(struct ofp13_group_stats) == 40);

Expand Down
53 changes: 29 additions & 24 deletions lib/ofp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6274,19 +6274,11 @@ ofputil_encode_group_desc_request(enum ofp_version ofp_version)
}

static void
ofputil_group_stats_to_ofp11__(const struct ofputil_group_stats *gs,
struct ofp11_group_stats *gs11, size_t length,
struct ofp11_bucket_counter bucket_cnts[])
ofputil_group_bucket_counters_to_ofp11(const struct ofputil_group_stats *gs,
struct ofp11_bucket_counter bucket_cnts[])
{
int i;

memset(gs11, 0, length);
gs11->length = htons(length);
gs11->group_id = htonl(gs->group_id);
gs11->ref_count = htonl(gs->ref_count);
gs11->packet_count = htonll(gs->packet_count);
gs11->byte_count = htonll(gs->byte_count);

for (i = 0; i < gs->n_buckets; i++) {
bucket_cnts[i].packet_count = htonll(gs->bucket_stats[i].packet_count);
bucket_cnts[i].byte_count = htonll(gs->bucket_stats[i].byte_count);
Expand All @@ -6295,18 +6287,27 @@ ofputil_group_stats_to_ofp11__(const struct ofputil_group_stats *gs,

static void
ofputil_group_stats_to_ofp11(const struct ofputil_group_stats *gs,
struct ofp11_group_stats *gs11, size_t length)
struct ofp11_group_stats *gs11, size_t length,
struct ofp11_bucket_counter bucket_cnts[])
{
ofputil_group_stats_to_ofp11__(gs, gs11, length, gs11->bucket_stats);
memset(gs11, 0, sizeof *gs11);
gs11->length = htons(length);
gs11->group_id = htonl(gs->group_id);
gs11->ref_count = htonl(gs->ref_count);
gs11->packet_count = htonll(gs->packet_count);
gs11->byte_count = htonll(gs->byte_count);
ofputil_group_bucket_counters_to_ofp11(gs, bucket_cnts);
}

static void
ofputil_group_stats_to_ofp13(const struct ofputil_group_stats *gs,
struct ofp13_group_stats *gs13, size_t length)
struct ofp13_group_stats *gs13, size_t length,
struct ofp11_bucket_counter bucket_cnts[])
{
ofputil_group_stats_to_ofp11__(gs, &gs13->gs, length, gs13->bucket_stats);
ofputil_group_stats_to_ofp11(gs, &gs13->gs, length, bucket_cnts);
gs13->duration_sec = htonl(gs->duration_sec);
gs13->duration_nsec = htonl(gs->duration_nsec);

}

/* Encodes 'gs' properly for the format of the list of group statistics
Expand All @@ -6318,28 +6319,32 @@ ofputil_append_group_stats(struct list *replies,
{
struct ofpbuf *msg = ofpbuf_from_list(list_back(replies));
struct ofp_header *oh = ofpbuf_data(msg);
size_t bucket_counter_size;
struct ofp11_bucket_counter *bucket_counters;
size_t length;

bucket_counter_size = gs->n_buckets * sizeof(struct ofp11_bucket_counter);

switch ((enum ofp_version) oh->version) {
case OFP11_VERSION:
case OFP12_VERSION:{
struct ofp11_group_stats *reply;
struct ofp11_group_stats *gs11;

length = gs->n_buckets * sizeof reply->bucket_stats[0]
+ sizeof *reply;
reply = ofpmp_append(replies, length);
ofputil_group_stats_to_ofp11(gs, reply, length);
length = sizeof *gs11 + bucket_counter_size;
gs11 = ofpmp_append(replies, length);
bucket_counters = (struct ofp11_bucket_counter *)(gs11 + 1);
ofputil_group_stats_to_ofp11(gs, gs11, length, bucket_counters);
break;
}

case OFP13_VERSION:
case OFP14_VERSION:{
struct ofp13_group_stats *reply;
struct ofp13_group_stats *gs13;

length = gs->n_buckets * sizeof reply->bucket_stats[0]
+ sizeof *reply;
reply = ofpmp_append(replies, length);
ofputil_group_stats_to_ofp13(gs, reply, length);
length = sizeof *gs13 + bucket_counter_size;
gs13 = ofpmp_append(replies, length);
bucket_counters = (struct ofp11_bucket_counter *)(gs13 + 1);
ofputil_group_stats_to_ofp13(gs, gs13, length, bucket_counters);
break;
}

Expand Down

0 comments on commit 63759e7

Please sign in to comment.