[ovs-dev] [sset 6/8] ovs-openflowd: Use sset in place of svec.
Ethan Jackson
ethan at nicira.com
Wed Mar 30 21:59:53 UTC 2011
Looks Good.
On Fri, Mar 25, 2011 at 3:40 PM, Ben Pfaff <blp at nicira.com> wrote:
> Also deletes svec_split() since this was the only user.
> ---
> lib/svec.c | 18 +----------
> lib/svec.h | 3 +-
> utilities/ovs-openflowd.c | 74 ++++++++++++++++++++++++++------------------
> 3 files changed, 46 insertions(+), 49 deletions(-)
>
> diff --git a/lib/svec.c b/lib/svec.c
> index d576c21..03c3747 100644
> --- a/lib/svec.c
> +++ b/lib/svec.c
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2008, 2009, 2010 Nicira Networks.
> + * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
> *
> * Licensed under the Apache License, Version 2.0 (the "License");
> * you may not use this file except in compliance with the License.
> @@ -372,22 +372,6 @@ svec_join(const struct svec *svec,
> return ds_cstr(&ds);
> }
>
> -/* Breaks 's' into tokens at any character in 'delimiters', and appends each
> - * token to 'svec'. Empty tokens are not added. */
> -void
> -svec_split(struct svec *svec, const char *s_, const char *delimiters)
> -{
> - char *s = xstrdup(s_);
> - char *save_ptr = NULL;
> - char *token;
> -
> - for (token = strtok_r(s, delimiters, &save_ptr); token != NULL;
> - token = strtok_r(NULL, delimiters, &save_ptr)) {
> - svec_add(svec, token);
> - }
> - free(s);
> -}
> -
> const char *
> svec_back(const struct svec *svec)
> {
> diff --git a/lib/svec.h b/lib/svec.h
> index 7fdc6b5..0ee058c 100644
> --- a/lib/svec.h
> +++ b/lib/svec.h
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2008, 2009 Nicira Networks.
> + * Copyright (c) 2008, 2009, 2011 Nicira Networks.
> *
> * Licensed under the Apache License, Version 2.0 (the "License");
> * you may not use this file except in compliance with the License.
> @@ -57,7 +57,6 @@ void svec_swap(struct svec *a, struct svec *b);
> void svec_print(const struct svec *svec, const char *title);
> void svec_parse_words(struct svec *svec, const char *words);
> bool svec_equal(const struct svec *, const struct svec *);
> -void svec_split(struct svec *, const char *s, const char *delimiters);
> char *svec_join(const struct svec *,
> const char *delimiter, const char *terminator);
> const char *svec_back(const struct svec *);
> diff --git a/utilities/ovs-openflowd.c b/utilities/ovs-openflowd.c
> index f1c52f9..f096af1 100644
> --- a/utilities/ovs-openflowd.c
> +++ b/utilities/ovs-openflowd.c
> @@ -40,7 +40,6 @@
> #include "poll-loop.h"
> #include "rconn.h"
> #include "stream-ssl.h"
> -#include "svec.h"
> #include "timeval.h"
> #include "unixctl.h"
> #include "util.h"
> @@ -63,7 +62,7 @@ struct ofsettings {
> uint64_t datapath_id; /* Datapath ID. */
> char *dp_name; /* Name of local datapath. */
> char *dp_type; /* Type of local datapath. */
> - struct svec ports; /* Set of ports to add to datapath (if any). */
> + struct sset ports; /* Set of ports to add to datapath (if any). */
>
> /* Description strings. */
> const char *mfr_desc; /* Manufacturer. */
> @@ -96,6 +95,7 @@ main(int argc, char *argv[])
> int error;
> struct dpif *dpif;
> struct netflow_options nf_options;
> + const char *port;
> bool exiting;
>
> proctitle_init(argc, argv);
> @@ -123,25 +123,20 @@ main(int argc, char *argv[])
> }
>
> /* Add ports to the datapath if requested by the user. */
> - if (s.ports.n) {
> - const char *port;
> - size_t i;
> + SSET_FOR_EACH (port, &s.ports) {
> + struct netdev *netdev;
>
> - SVEC_FOR_EACH (i, port, &s.ports) {
> - struct netdev *netdev;
> -
> - error = netdev_open_default(port, &netdev);
> - if (error) {
> - ovs_fatal(error, "%s: failed to open network device", port);
> - }
> -
> - error = dpif_port_add(dpif, netdev, NULL);
> - if (error) {
> - ovs_fatal(error, "failed to add %s as a port", port);
> - }
> + error = netdev_open_default(port, &netdev);
> + if (error) {
> + ovs_fatal(error, "%s: failed to open network device", port);
> + }
>
> - netdev_close(netdev);
> + error = dpif_port_add(dpif, netdev, NULL);
> + if (error) {
> + ovs_fatal(error, "failed to add %s as a port", port);
> }
> +
> + netdev_close(netdev);
> }
>
> /* Start OpenFlow processing. */
> @@ -206,6 +201,21 @@ ovs_openflowd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED,
>
> /* User interface. */
>
> +/* Breaks 'ports' apart at commas and adds each resulting word to 'ports'. */
> +static void
> +parse_ports(const char *s_, struct sset *ports)
> +{
> + char *s = xstrdup(s_);
> + char *save_ptr = NULL;
> + char *token;
> +
> + for (token = strtok_r(s, ",", &save_ptr); token != NULL;
> + token = strtok_r(NULL, ",", &save_ptr)) {
> + sset_add(ports, token);
> + }
> + free(s);
> +}
> +
> static void
> parse_options(int argc, char *argv[], struct ofsettings *s)
> {
> @@ -272,7 +282,8 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
> };
> char *short_options = long_options_to_short_options(long_options);
> struct ofproto_controller controller_opts;
> - struct svec controllers;
> + struct sset controllers;
> + const char *name;
> int i;
>
> /* Set defaults that we can figure out before parsing options. */
> @@ -290,11 +301,11 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
> s->sw_desc = NULL;
> s->serial_desc = NULL;
> s->dp_desc = NULL;
> - svec_init(&controllers);
> + sset_init(&controllers);
> sset_init(&s->snoops);
> s->max_idle = 0;
> sset_init(&s->netflow);
> - svec_init(&s->ports);
> + sset_init(&s->ports);
> for (;;) {
> int c;
>
> @@ -402,7 +413,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
> break;
>
> case 'l':
> - svec_add(&controllers, optarg);
> + sset_add(&controllers, optarg);
> break;
>
> case OPT_SNOOP:
> @@ -410,7 +421,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
> break;
>
> case OPT_PORTS:
> - svec_split(&s->ports, optarg, ",");
> + parse_ports(optarg, &s->ports);
> break;
>
> case OPT_UNIXCTL:
> @@ -469,25 +480,28 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
>
> /* Figure out controller names. */
> s->run_forever = false;
> - if (!controllers.n) {
> - svec_add_nocopy(&controllers, xasprintf("punix:%s/%s.mgmt",
> - ovs_rundir(), s->dp_name));
> + if (sset_is_empty(&controllers)) {
> + sset_add_and_free(&controllers, xasprintf("punix:%s/%s.mgmt",
> + ovs_rundir(), s->dp_name));
> }
> for (i = 1; i < argc; i++) {
> if (!strcmp(argv[i], "none")) {
> s->run_forever = true;
> } else {
> - svec_add(&controllers, argv[i]);
> + sset_add(&controllers, argv[i]);
> }
> }
>
> /* Set up controllers. */
> - s->n_controllers = controllers.n;
> + s->n_controllers = sset_count(&controllers);
> s->controllers = xmalloc(s->n_controllers * sizeof *s->controllers);
> - for (i = 0; i < s->n_controllers; i++) {
> + i = 0;
> + SSET_FOR_EACH (name, &controllers) {
> s->controllers[i] = controller_opts;
> - s->controllers[i].target = controllers.names[i];
> + s->controllers[i].target = xstrdup(name);
> + i++;
> }
> + sset_destroy(&controllers);
> }
>
> static void
> --
> 1.7.1
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
More information about the dev
mailing list