[ovs-dev] [PATCH 11/27] ofp-print: Allow printing of Open Flow 1.1 & 1.2 Port Reply Messages

Simon Horman horms at verge.net.au
Tue Aug 21 04:55:43 UTC 2012


Signed-off-by: Simon Horman <horms at verge.net.au>

---

v12
* No change

v11
* No change

v10
* No change

v9
* Make use of enum ofp_version
* Add ofp-print test
* Correct printing of port number for Open Flow 1.0
* Replace UINT64_MAX with htonll(UINT64_MAX) in ofp_print_port_stat()
  to correct byte-order problem detected by sparse

v8
* Omitted

v7
* Omitted

v6
* No change

v5
* Initial Post
---
 lib/ofp-print.c    | 87 +++++++++++++++++++++++++++++++++++++++---------------
 tests/ofp-print.at | 37 ++++++++++++++++++++++-
 2 files changed, 99 insertions(+), 25 deletions(-)

diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index 99e6456..bebb28e 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -1064,14 +1064,12 @@ ofp_print_aggregate_stats_reply(struct ds *string, const struct ofp_header *oh)
     ds_put_format(string, " flow_count=%"PRIu32, as.flow_count);
 }
 
-static void print_port_stat(struct ds *string, const char *leader,
-                            const ovs_32aligned_be64 *statp, int more)
+static void ofp_print_port_stat(struct ds *string, const char *leader,
+                                ovs_be64 stat, int more)
 {
-    uint64_t stat = ntohll(get_32aligned_be64(statp));
-
     ds_put_cstr(string, leader);
-    if (stat != UINT64_MAX) {
-        ds_put_format(string, "%"PRIu64, stat);
+    if (stat != htonll(UINT64_MAX)) {
+        ds_put_format(string, "%"PRIu64, ntohll(stat));
     } else {
         ds_put_char(string, '?');
     }
@@ -1082,6 +1080,12 @@ static void print_port_stat(struct ds *string, const char *leader,
     }
 }
 
+static void print_port_stat(struct ds *string, const char *leader,
+                            const ovs_32aligned_be64 *statp, int more)
+{
+    ofp_print_port_stat(string, leader, get_32aligned_be64(statp), more);
+}
+
 static void
 ofp_print_ofpst_port_request(struct ds *string, const struct ofp_header *oh)
 {
@@ -1093,42 +1097,77 @@ static void
 ofp_print_ofpst_port_reply(struct ds *string, const struct ofp_header *oh,
                            int verbosity)
 {
-    struct ofp10_port_stats *ps;
     struct ofpbuf b;
     size_t n;
+    struct ofp11_port_stats ps;
 
     ofpbuf_use_const(&b, oh, ntohs(oh->length));
     ofpraw_pull_assert(&b);
 
-    n = b.size / sizeof *ps;
+    /* struct ofp10_port_stats and struct ofp11_port_stats are the
+     * same size.
+     */
+    n = b.size / sizeof ps;
     ds_put_format(string, " %zu ports\n", n);
     if (verbosity < 1) {
         return;
     }
 
     for (;;) {
-        ps = ofpbuf_try_pull(&b, sizeof *ps);
-        if (!ps) {
-            return;
+
+        switch ((enum ofp_version)oh->version) {
+        case OFP12_VERSION:
+        case OFP11_VERSION: {
+            struct ofp11_port_stats *ps11 = ofpbuf_try_pull(&b, sizeof *ps11);
+            if (!ps11) {
+                return;
+            }
+            ds_put_format(string, "  port %2"PRIu32": ", ntohl(ps11->port_no));
+            ps = *ps11;
+            break;
         }
 
-        ds_put_format(string, "  port %2"PRIu16": ", ntohs(ps->port_no));
+        case OFP10_VERSION: {
+            struct ofp10_port_stats *ps10 = ofpbuf_try_pull(&b, sizeof *ps10);
+            if (!ps10) {
+                return;
+            }
+
+            ds_put_format(string, "  port %2"PRIu16": ", ntohs(ps10->port_no));
+            ps.rx_packets = get_32aligned_be64(&ps10->rx_packets);
+            ps.rx_bytes = get_32aligned_be64(&ps10->rx_bytes);
+            ps.rx_dropped = get_32aligned_be64(&ps10->rx_dropped);
+            ps.rx_errors = get_32aligned_be64(&ps10->rx_errors);
+            ps.rx_frame_err = get_32aligned_be64(&ps10->rx_frame_err);
+            ps.rx_over_err = get_32aligned_be64(&ps10->rx_over_err);
+            ps.rx_crc_err = get_32aligned_be64(&ps10->rx_crc_err);
+            ps.tx_packets = get_32aligned_be64(&ps10->tx_packets);
+            ps.tx_bytes = get_32aligned_be64(&ps10->tx_bytes);
+            ps.tx_dropped = get_32aligned_be64(&ps10->tx_dropped);
+            ps.tx_errors = get_32aligned_be64(&ps10->tx_errors);
+            ps.collisions = get_32aligned_be64(&ps10->collisions);
+            break;
+        }
+
+        default:
+            NOT_REACHED();
+        }
 
         ds_put_cstr(string, "rx ");
-        print_port_stat(string, "pkts=", &ps->rx_packets, 1);
-        print_port_stat(string, "bytes=", &ps->rx_bytes, 1);
-        print_port_stat(string, "drop=", &ps->rx_dropped, 1);
-        print_port_stat(string, "errs=", &ps->rx_errors, 1);
-        print_port_stat(string, "frame=", &ps->rx_frame_err, 1);
-        print_port_stat(string, "over=", &ps->rx_over_err, 1);
-        print_port_stat(string, "crc=", &ps->rx_crc_err, 0);
+        ofp_print_port_stat(string, "pkts=", ps.rx_packets, 1);
+        ofp_print_port_stat(string, "bytes=", ps.rx_bytes, 1);
+        ofp_print_port_stat(string, "drop=", ps.rx_dropped, 1);
+        ofp_print_port_stat(string, "errs=", ps.rx_errors, 1);
+        ofp_print_port_stat(string, "frame=", ps.rx_frame_err, 1);
+        ofp_print_port_stat(string, "over=", ps.rx_over_err, 1);
+        ofp_print_port_stat(string, "crc=", ps.rx_crc_err, 0);
 
         ds_put_cstr(string, "           tx ");
-        print_port_stat(string, "pkts=", &ps->tx_packets, 1);
-        print_port_stat(string, "bytes=", &ps->tx_bytes, 1);
-        print_port_stat(string, "drop=", &ps->tx_dropped, 1);
-        print_port_stat(string, "errs=", &ps->tx_errors, 1);
-        print_port_stat(string, "coll=", &ps->collisions, 0);
+        ofp_print_port_stat(string, "pkts=", ps.tx_packets, 1);
+        ofp_print_port_stat(string, "bytes=", ps.tx_bytes, 1);
+        ofp_print_port_stat(string, "drop=", ps.tx_dropped, 1);
+        ofp_print_port_stat(string, "errs=", ps.tx_errors, 1);
+        ofp_print_port_stat(string, "coll=", ps.collisions, 0);
     }
 }
 
diff --git a/tests/ofp-print.at b/tests/ofp-print.at
index ca7cf6b..d8187cb 100644
--- a/tests/ofp-print.at
+++ b/tests/ofp-print.at
@@ -895,7 +895,7 @@ OFPST_PORT request (xid=0x1): port_no=65535
 ])
 AT_CLEANUP
 
-AT_SETUP([OFPST_PORT reply])
+AT_SETUP([OFPST_PORT reply - OF1.0])
 AT_KEYWORDS([ofp-print OFPT_STATS_REPLY])
 AT_CHECK([ovs-ofctl ofp-print "\
 01 11 01 ac 00 00 00 01 00 04 00 00 00 03 00 00 \
@@ -938,6 +938,41 @@ OFPST_PORT reply (xid=0x1): 4 ports
 ])
 AT_CLEANUP
 
+AT_SETUP([OFPST_PORT reply - OF1.2])
+AT_KEYWORDS([ofp-print OFPT_STATS_REPLY])
+AT_CHECK([ovs-ofctl ofp-print "\
+03 13 01 48 00 00 00 02 00 04 00 00 00 00 00 00 \
+00 00 00 02 00 00 00 00 00 00 00 00 00 01 95 56 \
+00 00 00 00 00 00 00 88 00 00 00 00 02 5d 08 98 \
+00 00 00 00 00 00 2c f8 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 ff ff ff fe 00 00 00 00 \
+00 00 00 00 00 00 00 44 00 00 00 00 00 00 9d 2c \
+00 00 00 00 00 00 16 7c 00 00 00 00 01 1e 36 44 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 44 \
+00 00 00 00 00 00 9d 2c 00 00 00 00 00 00 16 7c \
+00 00 00 00 01 1e 36 44 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \
+00 00 00 00 00 00 00 00 \
+"], [0], [dnl
+OFPST_PORT reply (OF1.2) (xid=0x2): 3 ports
+  port  2: rx pkts=103766, bytes=39651480, drop=0, errs=0, frame=0, over=0, crc=0
+           tx pkts=136, bytes=11512, drop=0, errs=0, coll=0
+  port 4294967294: rx pkts=68, bytes=5756, drop=0, errs=0, frame=0, over=0, crc=0
+           tx pkts=40236, bytes=18757188, drop=0, errs=0, coll=0
+  port  1: rx pkts=68, bytes=5756, drop=0, errs=0, frame=0, over=0, crc=0
+           tx pkts=40236, bytes=18757188, drop=0, errs=0, coll=0
+])
+AT_CLEANUP
+
 AT_SETUP([OFPST_QUEUE request])
 AT_KEYWORDS([ofp-print OFPT_STATS_REQUEST])
 AT_CHECK([ovs-ofctl ofp-print "\
-- 
1.7.10.2.484.gcd07cc5




More information about the dev mailing list