[ovs-dev] [PATCH 40/48] ofp-util: Allow encoding of Open Flow 1.2 Flow Statistics Response Messages
Simon Horman
horms at verge.net.au
Mon Jun 25 06:44:43 UTC 2012
Signed-off-by: Simon Horman <horms at verge.net.au>
---
v4
* Do not manually add header pad, it is handled by
ofputil_postappend_stats_reply()
v3
* Initial post
---
lib/ofp-util.c | 24 ++++++++++++++++++++++--
lib/ofp-util.h | 3 ++-
ofproto/ofproto.c | 2 +-
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index 4fcd151..6e3c372 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -2282,14 +2282,34 @@ unknown_to_zero(uint64_t count)
* those already present in the list of ofpbufs in 'replies'. 'replies' should
* have been initialized with ofputil_start_stats_reply(). */
void
-ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs,
+ofputil_append_flow_stats_reply(uint8_t ofp_version,
+ const struct ofputil_flow_stats *fs,
struct list *replies)
{
struct ofpbuf *reply = ofpbuf_from_list(list_back(replies));
const struct ofp10_stats_msg *osm = reply->data;
size_t start_ofs = reply->size;
- if (osm->type == htons(OFPST_FLOW)) {
+ if (osm->type == htons(OFPST_FLOW) && ofp_version == OFP12_VERSION) {
+ struct ofp11_flow_stats *ofs;
+
+ ofs = ofpbuf_put_uninit(reply, sizeof *ofs);
+ ofs->table_id = fs->table_id;
+ ofs->pad = 0;
+ ofs->duration_sec = htonl(fs->duration_sec);
+ ofs->duration_nsec = htonl(fs->duration_nsec);
+ ofs->priority = htons(fs->rule.priority);
+ ofs->idle_timeout = htons(fs->idle_timeout);
+ ofs->hard_timeout = htons(fs->hard_timeout);
+ memset(ofs->pad2, 0, sizeof ofs->pad2);
+ ofs->cookie = fs->cookie;
+ ofs->packet_count = htonll(unknown_to_zero(fs->packet_count));
+ ofs->byte_count = htonll(unknown_to_zero(fs->byte_count));
+ ofputil_put_match(reply, &fs->rule, 0, 0, OFPUTIL_P_OF12);
+ ofpacts_to_openflow11(fs->ofpacts, reply, OFPIT11_APPLY_ACTIONS);
+ ofs = ofpbuf_at_assert(reply, start_ofs, sizeof *ofs);
+ ofs->length = htons(reply->size - start_ofs);
+ } else if (osm->type == htons(OFPST_FLOW) && ofp_version == OFP10_VERSION) {
struct ofp10_flow_stats *ofs;
ofs = ofpbuf_put_uninit(reply, sizeof *ofs);
diff --git a/lib/ofp-util.h b/lib/ofp-util.h
index c0d5d6d..549b5f8 100644
--- a/lib/ofp-util.h
+++ b/lib/ofp-util.h
@@ -304,7 +304,8 @@ int ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *,
struct ofpbuf *msg,
bool flow_age_extension,
struct ofpbuf *ofpacts);
-void ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *,
+void ofputil_append_flow_stats_reply(uint8_t ofp_version,
+ const struct ofputil_flow_stats *,
struct list *replies);
/* Aggregate stats reply, independent of protocol. */
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 2a95636..5baa826 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -2445,7 +2445,7 @@ handle_flow_stats_request(struct ofconn *ofconn,
ofproto->ofproto_class->rule_get_stats(rule, &fs.packet_count,
&fs.byte_count);
fs.ofpacts = rule->ofpacts;
- ofputil_append_flow_stats_reply(&fs, &replies);
+ ofputil_append_flow_stats_reply(request->version, &fs, &replies);
}
ofconn_send_replies(ofconn, &replies);
--
1.7.10.2.484.gcd07cc5
More information about the dev
mailing list