From ae0e7009320a4aceff41c53e0ce004cfc18b5f27 Mon Sep 17 00:00:00 2001
From: Justin Pettit <jpettit@nicira.com>
Date: Fri, 4 May 2012 17:27:16 -0700
Subject: [PATCH] ovs-ofctl: Support large number of ports with "show" command.

OpenFlow Features Reply messages prior to 1.3 can give users the wrong
impression about how many ports are on the system.  With this commit,
the command will check if the number of ports may be truncated.  If so,
it will send a Port Description stats request to get the complete list
and ignore the Features Reply port list.

Bug #11087

Signed-off-by: Justin Pettit <jpettit@nicira.com>
---
 utilities/ovs-ofctl.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 4a37067f3..d94ad6405 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -496,8 +496,30 @@ set_switch_config(struct vconn *vconn, struct ofp_switch_config *config_)
 static void
 do_show(int argc OVS_UNUSED, char *argv[])
 {
-    dump_trivial_transaction(argv[1], OFPT_FEATURES_REQUEST);
-    dump_trivial_transaction(argv[1], OFPT_GET_CONFIG_REQUEST);
+    const char *vconn_name = argv[1];
+    struct vconn *vconn;
+    struct ofpbuf *request;
+    struct ofpbuf *reply;
+    bool trunc;
+
+    make_openflow(sizeof(struct ofp_header), OFPT_FEATURES_REQUEST,
+                  &request);
+    open_vconn(vconn_name, &vconn);
+    run(vconn_transact(vconn, request, &reply), "talking to %s", vconn_name);
+
+    trunc = ofputil_switch_features_ports_trunc(reply);
+    ofp_print(stdout, reply->data, reply->size, verbosity + 1);
+
+    ofpbuf_delete(reply);
+    vconn_close(vconn);
+
+    if (trunc) {
+        /* The Features Reply may not contain all the ports, so send a
+         * Port Description stats request, which doesn't have size
+         * constraints. */
+        dump_trivial_stats_transaction(vconn_name, OFPST_PORT_DESC);
+    }
+    dump_trivial_transaction(vconn_name, OFPT_GET_CONFIG_REQUEST);
 }
 
 static void
-- 
2.47.0