ovs-dpctl: Add dump-dps command
authorJustin Pettit <jpettit@nicira.com>
Tue, 4 Aug 2009 22:13:40 +0000 (15:13 -0700)
committerJustin Pettit <jpettit@nicira.com>
Fri, 7 Aug 2009 01:04:36 +0000 (18:04 -0700)
The "dump-dps" command prints the name of each datapath on a separate
line.

lib/dpif.c
lib/dpif.h
utilities/ovs-dpctl.8.in
utilities/ovs-dpctl.c

index 21f1173..80f6ed6 100644 (file)
@@ -43,6 +43,7 @@
 #include "ofpbuf.h"
 #include "packets.h"
 #include "poll-loop.h"
+#include "svec.h"
 #include "util.h"
 #include "valgrind.h"
 
@@ -64,6 +65,35 @@ static int open_by_minor(unsigned int minor, struct dpif *);
 static int make_openvswitch_device(unsigned int minor, char **fnp);
 static void check_rw_odp_flow(struct odp_flow *);
 
+
+/* Clears 'all_dps' and enumerates the names of all known created
+ * datapaths into it.  Returns 0 if successful, otherwise a positive 
+ * errno value. */
+int
+dp_enumerate(struct svec *all_dps)
+{
+    int error;
+    int i;
+
+    svec_clear(all_dps);
+    error = 0;
+    for (i = 0; i < ODP_MAX; i++) {
+        struct dpif dpif;
+        char devname[16];
+        int retval;
+
+        sprintf(devname, "dp%d", i);
+        retval = dpif_open(devname, &dpif);
+        if (!retval) {
+            svec_add(all_dps, devname);
+            dpif_close(&dpif);
+        } else if (retval != ENODEV && !error) {
+            error = retval;
+        }
+    }
+    return error;
+}
+
 int
 dpif_open(const char *name, struct dpif *dpif)
 {
index d81cf63..1e5412a 100644 (file)
@@ -28,6 +28,7 @@
 #include <stdint.h>
 
 struct ofpbuf;
+struct svec;
 
 /* A datapath interface.  Opaque. */
 struct dpif {
@@ -35,6 +36,8 @@ struct dpif {
     int fd;
 };
 
+int dp_enumerate(struct svec *);
+
 int dpif_open(const char *name, struct dpif *);
 int dpif_create(const char *name, struct dpif *);
 void dpif_close(struct dpif *);
index 652ebb1..a1719f8 100644 (file)
@@ -1,4 +1,4 @@
-.TH ovs\-dpctl 8 "March 2009" "Open vSwitch" "Open vSwitch Manual"
+.TH ovs\-dpctl 8 "August 2009" "Open vSwitch" "Open vSwitch Manual"
 .ds PN ovs\-dpctl
 
 .SH NAME
@@ -86,6 +86,10 @@ port (analogous to the local port) with that name.
 Removes each \fInetdev\fR from the list of network devices datapath
 \fIdp\fR monitors.
 
+.TP
+\fBdump-dps\fR
+Prints the name of each configured datapath on a separate line.
+
 .TP
 \fBshow \fR[\fIdp\fR...]
 Prints a summary of configured datapaths, including their datapath
index c44291b..1296062 100644 (file)
@@ -36,6 +36,7 @@
 #include "dynamic-string.h"
 #include "netdev.h"
 #include "odp-util.h"
+#include "svec.h"
 #include "timeval.h"
 #include "util.h"
 
@@ -157,6 +158,7 @@ usage(void)
            "  del-dp DP                delete local datapath DP\n"
            "  add-if DP IFACE...       add each IFACE as a port on DP\n"
            "  del-if DP IFACE...       delete each IFACE from DP\n"
+           "  dump-dps                 display names of all datapaths\n"
            "  show                     show basic info on all datapaths\n"
            "  show DP...               show basic info on each DP\n"
            "  dump-flows DP            display flows in DP\n"
@@ -465,6 +467,35 @@ do_show(int argc UNUSED, char *argv[])
     }
 }
 
+static void
+do_dump_dps(int argc UNUSED, char *argv[] UNUSED)
+{
+    struct svec all_dps;
+    unsigned int i;
+    int error;
+
+    svec_init(&all_dps);
+    error = dp_enumerate(&all_dps);
+
+    for (i = 0; i < all_dps.n; i++) {
+        struct dpif dpif;
+        char dpif_name[IF_NAMESIZE];
+
+        if (dpif_open(all_dps.names[i], &dpif)) {
+            continue;
+        }
+        if (!dpif_get_name(&dpif, dpif_name, sizeof dpif_name)) {
+            printf("%s\n", dpif_name);
+        }
+        dpif_close(&dpif);
+    }
+
+    svec_destroy(&all_dps);
+    if (error) {
+        exit(EXIT_FAILURE);
+    }
+}
+
 static void
 do_dump_flows(int argc UNUSED, char *argv[])
 {
@@ -543,6 +574,7 @@ static struct command all_commands[] = {
     { "del-dp", 1, 1, do_del_dp },
     { "add-if", 2, INT_MAX, do_add_if },
     { "del-if", 2, INT_MAX, do_del_if },
+    { "dump-dps", 0, 0, do_dump_dps },
     { "show", 0, INT_MAX, do_show },
     { "dump-flows", 1, 1, do_dump_flows },
     { "del-flows", 1, 1, do_del_flows },