From b566902b599073806d69b722cabb3d242f50d1fa Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Tue, 4 Aug 2009 15:13:40 -0700 Subject: [PATCH] ovs-dpctl: Add dump-dps command The "dump-dps" command prints the name of each datapath on a separate line. --- lib/dpif.c | 30 ++++++++++++++++++++++++++++++ lib/dpif.h | 3 +++ utilities/ovs-dpctl.8.in | 6 +++++- utilities/ovs-dpctl.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) diff --git a/lib/dpif.c b/lib/dpif.c index 21f1173f..80f6ed6c 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -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) { diff --git a/lib/dpif.h b/lib/dpif.h index d81cf631..1e5412a4 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -28,6 +28,7 @@ #include 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 *); diff --git a/utilities/ovs-dpctl.8.in b/utilities/ovs-dpctl.8.in index 652ebb13..a1719f8e 100644 --- a/utilities/ovs-dpctl.8.in +++ b/utilities/ovs-dpctl.8.in @@ -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 diff --git a/utilities/ovs-dpctl.c b/utilities/ovs-dpctl.c index c44291b6..12960626 100644 --- a/utilities/ovs-dpctl.c +++ b/utilities/ovs-dpctl.c @@ -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 }, -- 2.30.2