Signed-off-by: Simon Horman <ho...@verge.net.au>

---

v8
* Manual rebase
* Make use of enum ofp_version
* Add ofp-print test

v7
* Omitted

v6
* No change

v5
* No change

v4
* Initial post

fix port test
---
 ofproto/ofproto.c  | 62 ++++++++++++++++++++++++++++++++++++++++++++++--------
 tests/ofp-print.at | 37 +++++++++++++++++++++++++++++++-
 2 files changed, 89 insertions(+), 10 deletions(-)

diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 3a96982..1521a61 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -2353,16 +2353,11 @@ handle_table_stats_request(struct ofconn *ofconn,
 }
 
 static void
-append_port_stat(struct ofport *port, struct list *replies)
+append_port_stat10(struct ofport *port, struct netdev_stats stats,
+                   struct list *replies)
 {
-    struct netdev_stats stats;
     struct ofp10_port_stats *ops;
 
-    /* Intentionally ignore return value, since errors will set
-     * 'stats' to all-1s, which is correct for OpenFlow, and
-     * netdev_get_stats() will log errors. */
-    ofproto_port_get_stats(port, &stats);
-
     ops = ofpmp_append(replies, sizeof *ops);
     ops->port_no = htons(port->pp.port_no);
     memset(ops->pad, 0, sizeof ops->pad);
@@ -2380,6 +2375,55 @@ append_port_stat(struct ofport *port, struct list 
*replies)
     put_32aligned_be64(&ops->collisions, htonll(stats.collisions));
 }
 
+static void
+append_port_stat11(struct ofport *port, struct netdev_stats stats,
+                   struct list *replies)
+{
+    struct ofp11_port_stats *ops;
+
+    ops = ofpmp_append(replies, sizeof *ops);
+    ops->port_no = ofputil_port_to_ofp11(port->pp.port_no);
+    memset(ops->pad, 0, sizeof ops->pad);
+    ops->rx_packets = htonll(stats.rx_packets);
+    ops->tx_packets = htonll(stats.tx_packets);
+    ops->rx_bytes = htonll(stats.rx_bytes);
+    ops->tx_bytes = htonll(stats.tx_bytes);
+    ops->rx_dropped = htonll(stats.rx_dropped);
+    ops->tx_dropped = htonll(stats.tx_dropped);
+    ops->rx_errors = htonll(stats.rx_errors);
+    ops->tx_errors = htonll(stats.tx_errors);
+    ops->rx_frame_err = htonll(stats.rx_frame_errors);
+    ops->rx_over_err = htonll(stats.rx_over_errors);
+    ops->rx_crc_err = htonll(stats.rx_crc_errors);
+    ops->collisions = htonll(stats.collisions);
+}
+
+static void
+append_port_stat(struct ofport *port, enum ofp_version ofp_version,
+                 struct list *replies)
+{
+    struct netdev_stats stats;
+
+    /* Intentionally ignore return value, since errors will set
+     * 'stats' to all-1s, which is correct for OpenFlow, and
+     * netdev_get_stats() will log errors. */
+    ofproto_port_get_stats(port, &stats);
+
+    switch (ofp_version) {
+    case OFP12_VERSION:
+    case OFP11_VERSION:
+        append_port_stat11(port, stats, replies);
+        break;
+
+    case OFP10_VERSION:
+        append_port_stat10(port, stats, replies);
+        break;
+
+    default:
+        NOT_REACHED();
+    }
+}
+
 static enum ofperr
 handle_port_stats_request(struct ofconn *ofconn,
                           const struct ofp_header *request)
@@ -2393,11 +2437,11 @@ handle_port_stats_request(struct ofconn *ofconn,
     if (psr->port_no != htons(OFPP_NONE)) {
         port = ofproto_get_port(p, ntohs(psr->port_no));
         if (port) {
-            append_port_stat(port, &replies);
+            append_port_stat(port, request->version, &replies);
         }
     } else {
         HMAP_FOR_EACH (port, hmap_node, &p->ports) {
-            append_port_stat(port, &replies);
+            append_port_stat(port, request->version, &replies);
         }
     }
 
diff --git a/tests/ofp-print.at b/tests/ofp-print.at
index 10152e7..47d62cb 100644
--- a/tests/ofp-print.at
+++ b/tests/ofp-print.at
@@ -4961,7 +4961,7 @@ OFPST_PORT request (OF1.2) (xid=0x2): 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 \
@@ -5004,6 +5004,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  0: 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 65535: 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  0: 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

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to