[ovs-dev] [PATCH 40/47] ofp-util: Allow encoding of Open Flow 1.1 & 1.2 Port Statistics Reply Messages
Simon Horman
horms at verge.net.au
Wed Aug 1 07:02:23 UTC 2012
Signed-off-by: Simon Horman <horms at verge.net.au>
---
v9
* Move print test to "ofp-print: Allow printing of Open Flow 1.1 & 1.2 Port
Reply Messages"
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 +++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 53 insertions(+), 9 deletions(-)
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 846d465..bdd917d 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -2352,16 +2352,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);
@@ -2379,6 +2374,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)
@@ -2392,11 +2436,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);
}
}
--
1.7.10.2.484.gcd07cc5
More information about the dev
mailing list