openflow: Separate OF1.0, OF1.1 flow_mod constants and types.
[openvswitch] / lib / ofp-util.c
index 7875cbf86a41167ffd8f0aa057c2f5b60f7ced0c..92d3fe465d2b914e3dc8e4adf5fa3d644a6e4933 100644 (file)
@@ -1104,7 +1104,7 @@ ofputil_decode_flow_mod(struct ofputil_flow_mod *fm,
     raw = ofpraw_pull_assert(&b);
     if (raw == OFPRAW_OFPT10_FLOW_MOD) {
         /* Standard OpenFlow 1.1 flow_mod. */
-        const struct ofp_flow_mod *ofm;
+        const struct ofp10_flow_mod *ofm;
         uint16_t priority;
         enum ofperr error;
 
@@ -1193,7 +1193,7 @@ struct ofpbuf *
 ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
                         enum ofputil_protocol protocol)
 {
-    struct ofp_flow_mod *ofm;
+    struct ofp10_flow_mod *ofm;
     struct nx_flow_mod *nfm;
     struct ofpbuf *msg;
     uint16_t command;
@@ -1284,7 +1284,7 @@ ofputil_flow_mod_usable_protocols(const struct ofputil_flow_mod *fms,
 
 static enum ofperr
 ofputil_decode_ofpst_flow_request(struct ofputil_flow_stats_request *fsr,
-                                  const struct ofp_flow_stats_request *ofsr,
+                                  const struct ofp10_flow_stats_request *ofsr,
                                   bool aggregate)
 {
     fsr->aggregate = aggregate;
@@ -1364,7 +1364,7 @@ ofputil_encode_flow_stats_request(const struct ofputil_flow_stats_request *fsr,
     switch (protocol) {
     case OFPUTIL_P_OF10:
     case OFPUTIL_P_OF10_TID: {
-        struct ofp_flow_stats_request *ofsr;
+        struct ofp10_flow_stats_request *ofsr;
 
         raw = (fsr->aggregate
                ? OFPRAW_OFPST_AGGREGATE_REQUEST
@@ -1461,7 +1461,7 @@ ofputil_decode_flow_stats_reply(struct ofputil_flow_stats *fs,
     if (!msg->size) {
         return EOF;
     } else if (raw == OFPRAW_OFPST_FLOW_REPLY) {
-        const struct ofp_flow_stats *ofs;
+        const struct ofp10_flow_stats *ofs;
         size_t length;
 
         ofs = ofpbuf_try_pull(msg, sizeof *ofs);
@@ -1573,7 +1573,7 @@ ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs,
 
     ofpraw_decode_partial(&raw, reply->data, reply->size);
     if (raw == OFPRAW_OFPST_FLOW_REPLY) {
-        struct ofp_flow_stats *ofs;
+        struct ofp10_flow_stats *ofs;
 
         ofpbuf_put_uninit(reply, sizeof *ofs);
         ofpacts_put_openflow10(fs->ofpacts, fs->ofpacts_len, reply);
@@ -1629,38 +1629,33 @@ ofputil_append_flow_stats_reply(const struct ofputil_flow_stats *fs,
 }
 
 /* Converts abstract ofputil_aggregate_stats 'stats' into an OFPST_AGGREGATE or
- * NXST_AGGREGATE reply according to 'protocol', and returns the message. */
+ * NXST_AGGREGATE reply matching 'request', and returns the message. */
 struct ofpbuf *
 ofputil_encode_aggregate_stats_reply(
     const struct ofputil_aggregate_stats *stats,
     const struct ofp_header *request)
 {
+    struct ofp_aggregate_stats_reply *asr;
+    uint64_t packet_count;
+    uint64_t byte_count;
     struct ofpbuf *msg;
     enum ofpraw raw;
 
     ofpraw_decode(&raw, request);
     if (raw == OFPRAW_OFPST_AGGREGATE_REQUEST) {
-        struct ofp_aggregate_stats_reply *asr;
-
-        msg = ofpraw_alloc_reply(OFPRAW_OFPST_AGGREGATE_REPLY, request, 0);
-        asr = ofpbuf_put_zeros(msg, sizeof *asr);
-        put_32aligned_be64(&asr->packet_count,
-                           htonll(unknown_to_zero(stats->packet_count)));
-        put_32aligned_be64(&asr->byte_count,
-                           htonll(unknown_to_zero(stats->byte_count)));
-        asr->flow_count = htonl(stats->flow_count);
-    } else if (raw == OFPRAW_NXST_AGGREGATE_REQUEST) {
-        struct nx_aggregate_stats_reply *nasr;
-
-        msg = ofpraw_alloc_reply(OFPRAW_NXST_AGGREGATE_REPLY, request, 0);
-        nasr = ofpbuf_put_zeros(msg, sizeof *nasr);
-        nasr->packet_count = htonll(stats->packet_count);
-        nasr->byte_count = htonll(stats->byte_count);
-        nasr->flow_count = htonl(stats->flow_count);
+        packet_count = unknown_to_zero(stats->packet_count);
+        byte_count = unknown_to_zero(stats->byte_count);
     } else {
-        NOT_REACHED();
+        packet_count = stats->packet_count;
+        byte_count = stats->byte_count;
     }
 
+    msg = ofpraw_alloc_stats_reply(request, 0);
+    asr = ofpbuf_put_zeros(msg, sizeof *asr);
+    put_32aligned_be64(&asr->packet_count, htonll(packet_count));
+    put_32aligned_be64(&asr->byte_count, htonll(byte_count));
+    asr->flow_count = htonl(stats->flow_count);
+
     return msg;
 }
 
@@ -1668,26 +1663,16 @@ enum ofperr
 ofputil_decode_aggregate_stats_reply(struct ofputil_aggregate_stats *stats,
                                      const struct ofp_header *reply)
 {
+    struct ofp_aggregate_stats_reply *asr;
     struct ofpbuf msg;
-    enum ofpraw raw;
 
     ofpbuf_use_const(&msg, reply, ntohs(reply->length));
-    raw = ofpraw_pull_assert(&msg);
-    if (raw == OFPRAW_OFPST_AGGREGATE_REPLY) {
-        struct ofp_aggregate_stats_reply *asr = msg.l3;
-
-        stats->packet_count = ntohll(get_32aligned_be64(&asr->packet_count));
-        stats->byte_count = ntohll(get_32aligned_be64(&asr->byte_count));
-        stats->flow_count = ntohl(asr->flow_count);
-    } else if (raw == OFPRAW_NXST_AGGREGATE_REPLY) {
-        struct nx_aggregate_stats_reply *nasr = msg.l3;
-
-        stats->packet_count = ntohll(nasr->packet_count);
-        stats->byte_count = ntohll(nasr->byte_count);
-        stats->flow_count = ntohl(nasr->flow_count);
-    } else {
-        NOT_REACHED();
-    }
+    ofpraw_pull_assert(&msg);
+
+    asr = msg.l3;
+    stats->packet_count = ntohll(get_32aligned_be64(&asr->packet_count));
+    stats->byte_count = ntohll(get_32aligned_be64(&asr->byte_count));
+    stats->flow_count = ntohl(asr->flow_count);
 
     return 0;
 }