[ovs-dev] [netlink v3 14/16] ovs-dpctl: Use netdev_get_config() to print vport configurations.

Ben Pfaff blp at nicira.com
Thu Dec 30 00:56:35 UTC 2010


This is cleaner than parsing "odp_port"s directly.  It takes one step
toward eliminating use of odp_port from any userspace code outside of
lib/netdev-vport.c and lib/dpif-linux.c.
---
 lib/odp-util.c        |   29 -----------------------------
 lib/odp-util.h        |    1 -
 utilities/ovs-dpctl.c |   39 +++++++++++++++++++++++++++++++++------
 3 files changed, 33 insertions(+), 36 deletions(-)

diff --git a/lib/odp-util.c b/lib/odp-util.c
index 7b9258a..be826d0 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -198,35 +198,6 @@ format_odp_flow(struct ds *ds, const struct odp_flow *f)
     ds_put_cstr(ds, ", actions:");
     format_odp_actions(ds, f->actions, f->actions_len);
 }
-
-void
-format_odp_port_type(struct ds *ds, const struct odp_port *p)
-{
-    if (!strcmp(p->type, "gre") 
-            || !strcmp(p->type, "ipsec_gre")
-            || !strcmp(p->type, "capwap")) {
-        const struct tnl_port_config *config;
-
-        config = (struct tnl_port_config *)p->config;
-
-        ds_put_format(ds, " (%s: remote_ip="IP_FMT, 
-                p->type, IP_ARGS(&config->daddr));
-
-        if (config->saddr) {
-            ds_put_format(ds, ", local_ip="IP_FMT, IP_ARGS(&config->saddr));
-        }
-
-        if (config->in_key) {
-            ds_put_format(ds, ", in_key=%#"PRIx64, ntohll(config->in_key));
-        }
-
-        ds_put_cstr(ds, ")");
-    } else if (!strcmp(p->type, "patch")) {
-        ds_put_format(ds, " (%s: peer=%s)", p->type, (char *)p->config);
-    } else if (strcmp(p->type, "system")) {
-        ds_put_format(ds, " (%s)", p->type);
-    }
-}
 
 /* Returns the correct length of the payload for a flow key attribute of the
  * specified 'type', or -1 if 'type' is unknown. */
diff --git a/lib/odp-util.h b/lib/odp-util.h
index b5ead84..9486661 100644
--- a/lib/odp-util.h
+++ b/lib/odp-util.h
@@ -62,7 +62,6 @@ void format_odp_actions(struct ds *, const struct nlattr *odp_actions,
                         size_t actions_len);
 void format_odp_flow_stats(struct ds *, const struct odp_flow_stats *);
 void format_odp_flow(struct ds *, const struct odp_flow *);
-void format_odp_port_type(struct ds *, const struct odp_port *);
 
 /* By my calculations currently the longest valid nlattr-formatted flow key is
  * 80 bytes long, so this leaves some safety margin.
diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c
index a824608..1cdce3b 100644
--- a/utilities/ovs-dpctl.c
+++ b/utilities/ovs-dpctl.c
@@ -351,14 +351,41 @@ show_dpif(struct dpif *dpif)
                stats.max_miss_queue, stats.max_action_queue);
     }
     DPIF_PORT_FOR_EACH (&odp_port, &dump, dpif) {
-        struct ds ds;
-
         printf("\tport %u: %s", odp_port.port, odp_port.devname);
 
-        ds_init(&ds);
-        format_odp_port_type(&ds, &odp_port);
-        printf("%s\n", ds_cstr(&ds));
-        ds_destroy(&ds);
+        if (strcmp(odp_port.type, "system")) {
+            struct netdev_options netdev_options;
+            struct netdev *netdev;
+            int error;
+
+            printf (" (%s", odp_port.type);
+
+            netdev_options.name = odp_port.devname;
+            netdev_options.type = odp_port.type;
+            netdev_options.args = NULL;
+            netdev_options.ethertype = NETDEV_ETH_TYPE_NONE;
+            error = netdev_open(&netdev_options, &netdev);
+            if (!error) {
+                const struct shash_node **nodes;
+                const struct shash *config;
+                size_t i;
+
+                config = netdev_get_config(netdev);
+                nodes = shash_sort(config);
+                for (i = 0; i < shash_count(config); i++) {
+                    const struct shash_node *node = nodes[i];
+                    printf("%c %s=%s", i ? ',' : ':',
+                           node->name, (char *) node->data);
+                }
+                free(nodes);
+
+                netdev_close(netdev);
+            } else {
+                printf(": open failed (%s)", strerror(error));
+            }
+            putchar(')');
+        }
+        putchar('\n');
     }
     dpif_close(dpif);
 }
-- 
1.7.1





More information about the dev mailing list