Looks Good.
On Fri, Mar 25, 2011 at 3:40 PM, Ben Pfaff <b...@nicira.com> wrote: > --- > ofproto/collectors.c | 20 +++++++------------- > ofproto/collectors.h | 7 ++++--- > ofproto/netflow.c | 3 +-- > ofproto/netflow.h | 6 +++--- > ofproto/ofproto-sflow.c | 10 +++++----- > ofproto/ofproto.c | 23 ++++++++++++++--------- > ofproto/ofproto.h | 11 ++++++----- > utilities/ovs-openflowd.c | 12 ++++++------ > vswitchd/bridge.c | 29 +++++++++++++++-------------- > 9 files changed, 61 insertions(+), 60 deletions(-) > > diff --git a/ofproto/collectors.c b/ofproto/collectors.c > index 58d6abb..bd3e89b 100644 > --- a/ofproto/collectors.c > +++ b/ofproto/collectors.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. > @@ -24,7 +24,7 @@ > #include <unistd.h> > > #include "socket-util.h" > -#include "svec.h" > +#include "sset.h" > #include "util.h" > #include "vlog.h" > > @@ -47,24 +47,19 @@ struct collectors { > * added, otherwise to a new collectors object if at least one was > successfully > * added. Thus, even on a failure return, it is possible that '*collectorsp' > * is nonnull, and even on a successful return, it is possible that > - * '*collectorsp' is null, if 'target's is an empty svec. */ > + * '*collectorsp' is null, if 'target's is an empty sset. */ > int > -collectors_create(const struct svec *targets_, uint16_t default_port, > +collectors_create(const struct sset *targets, uint16_t default_port, > struct collectors **collectorsp) > { > struct collectors *c; > - struct svec targets; > + const char *name; > int retval = 0; > - size_t i; > - > - svec_clone(&targets, targets_); > - svec_sort_unique(&targets); > > c = xmalloc(sizeof *c); > - c->fds = xmalloc(sizeof *c->fds * targets.n); > + c->fds = xmalloc(sizeof *c->fds * sset_count(targets)); > c->n_fds = 0; > - for (i = 0; i < targets.n; i++) { > - const char *name = targets.names[i]; > + SSET_FOR_EACH (name, targets) { > int error; > int fd; > > @@ -81,7 +76,6 @@ collectors_create(const struct svec *targets_, uint16_t > default_port, > } > } > } > - svec_destroy(&targets); > > if (c->n_fds) { > *collectorsp = c; > diff --git a/ofproto/collectors.h b/ofproto/collectors.h > index ac70f37..47b148b 100644 > --- a/ofproto/collectors.h > +++ b/ofproto/collectors.h > @@ -1,5 +1,5 @@ > /* > - * Copyright (c) 2009 Nicira Networks. > + * Copyright (c) 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. > @@ -17,12 +17,13 @@ > #ifndef COLLECTORS_H > #define COLLECTORS_H 1 > > +#include <stddef.h> > #include <stdint.h> > -#include "svec.h" > > struct collectors; > +struct sset; > > -int collectors_create(const struct svec *targets, uint16_t default_port, > +int collectors_create(const struct sset *targets, uint16_t default_port, > struct collectors **); > void collectors_destroy(struct collectors *); > > diff --git a/ofproto/netflow.c b/ofproto/netflow.c > index 77572fe..2d69db8 100644 > --- a/ofproto/netflow.c > +++ b/ofproto/netflow.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. > @@ -28,7 +28,6 @@ > #include "ofproto.h" > #include "packets.h" > #include "socket-util.h" > -#include "svec.h" > #include "timeval.h" > #include "util.h" > #include "vlog.h" > diff --git a/ofproto/netflow.h b/ofproto/netflow.h > index 58fe7cb..bf5bf45 100644 > --- a/ofproto/netflow.h > +++ b/ofproto/netflow.h > @@ -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. > @@ -19,7 +19,7 @@ > > #include <stdint.h> > #include "flow.h" > -#include "svec.h" > +#include "sset.h" > > /* Default active timeout interval, in seconds. > * > @@ -31,7 +31,7 @@ > struct ofexpired; > > struct netflow_options { > - struct svec collectors; > + struct sset collectors; > uint8_t engine_type; > uint8_t engine_id; > int active_timeout; > diff --git a/ofproto/ofproto-sflow.c b/ofproto/ofproto-sflow.c > index 05794e1..5351b83 100644 > --- a/ofproto/ofproto-sflow.c > +++ b/ofproto/ofproto-sflow.c > @@ -72,7 +72,7 @@ static bool > ofproto_sflow_options_equal(const struct ofproto_sflow_options *a, > const struct ofproto_sflow_options *b) > { > - return (svec_equal(&a->targets, &b->targets) > + return (sset_equals(&a->targets, &b->targets) > && a->sampling_rate == b->sampling_rate > && a->polling_interval == b->polling_interval > && a->header_len == b->header_len > @@ -85,7 +85,7 @@ static struct ofproto_sflow_options * > ofproto_sflow_options_clone(const struct ofproto_sflow_options *old) > { > struct ofproto_sflow_options *new = xmemdup(old, sizeof *old); > - svec_clone(&new->targets, &old->targets); > + sset_clone(&new->targets, &old->targets); > new->agent_device = old->agent_device ? xstrdup(old->agent_device) : NULL; > new->control_ip = old->control_ip ? xstrdup(old->control_ip) : NULL; > return new; > @@ -95,7 +95,7 @@ static void > ofproto_sflow_options_destroy(struct ofproto_sflow_options *options) > { > if (options) { > - svec_destroy(&options->targets); > + sset_destroy(&options->targets); > free(options->agent_device); > free(options->control_ip); > free(options); > @@ -395,7 +395,7 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, > SFLAddress agentIP; > time_t now; > > - if (!options->targets.n || !options->sampling_rate) { > + if (sset_is_empty(&options->targets) || !options->sampling_rate) { > /* No point in doing any work if there are no targets or nothing to > * sample. */ > ofproto_sflow_clear(os); > @@ -409,7 +409,7 @@ ofproto_sflow_set_options(struct ofproto_sflow *os, > * collectors (which indicates that opening one or more of the configured > * collectors failed, so that we should retry). */ > if (options_changed > - || collectors_count(os->collectors) < options->targets.n) { > + || collectors_count(os->collectors) < sset_count(&options->targets)) > { > collectors_destroy(os->collectors); > collectors_create(&options->targets, SFL_DEFAULT_COLLECTOR_PORT, > &os->collectors); > diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c > index 5412f8e..0c625b6 100644 > --- a/ofproto/ofproto.c > +++ b/ofproto/ofproto.c > @@ -56,7 +56,6 @@ > #include "shash.h" > #include "sset.h" > #include "stream-ssl.h" > -#include "svec.h" > #include "tag.h" > #include "timeval.h" > #include "unaligned.h" > @@ -873,10 +872,11 @@ ofproto_set_desc(struct ofproto *p, > > static int > set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp, > - const struct svec *svec) > + const struct sset *sset) > { > struct pvconn **pvconns = *pvconnsp; > size_t n_pvconns = *n_pvconnsp; > + const char *name; > int retval = 0; > size_t i; > > @@ -885,10 +885,9 @@ set_pvconns(struct pvconn ***pvconnsp, size_t > *n_pvconnsp, > } > free(pvconns); > > - pvconns = xmalloc(svec->n * sizeof *pvconns); > + pvconns = xmalloc(sset_count(sset) * sizeof *pvconns); > n_pvconns = 0; > - for (i = 0; i < svec->n; i++) { > - const char *name = svec->names[i]; > + SSET_FOR_EACH (name, sset) { > struct pvconn *pvconn; > int error; > > @@ -910,7 +909,7 @@ set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp, > } > > int > -ofproto_set_snoops(struct ofproto *ofproto, const struct svec *snoops) > +ofproto_set_snoops(struct ofproto *ofproto, const struct sset *snoops) > { > return set_pvconns(&ofproto->snoops, &ofproto->n_snoops, snoops); > } > @@ -919,7 +918,7 @@ int > ofproto_set_netflow(struct ofproto *ofproto, > const struct netflow_options *nf_options) > { > - if (nf_options && nf_options->collectors.n) { > + if (nf_options && !sset_is_empty(&nf_options->collectors)) { > if (!ofproto->netflow) { > ofproto->netflow = netflow_create(); > } > @@ -1034,13 +1033,19 @@ ofproto_get_fail_mode(const struct ofproto *p) > return p->fail_mode; > } > > +bool > +ofproto_has_snoops(const struct ofproto *ofproto) > +{ > + return ofproto->n_snoops > 0; > +} > + > void > -ofproto_get_snoops(const struct ofproto *ofproto, struct svec *snoops) > +ofproto_get_snoops(const struct ofproto *ofproto, struct sset *snoops) > { > size_t i; > > for (i = 0; i < ofproto->n_snoops; i++) { > - svec_add(snoops, pvconn_get_name(ofproto->snoops[i])); > + sset_add(snoops, pvconn_get_name(ofproto->snoops[i])); > } > } > > diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h > index b049fe1..96f0098 100644 > --- a/ofproto/ofproto.h > +++ b/ofproto/ofproto.h > @@ -24,6 +24,7 @@ > #include <stdint.h> > #include "flow.h" > #include "netflow.h" > +#include "sset.h" > #include "tag.h" > > #ifdef __cplusplus > @@ -35,7 +36,6 @@ struct nlattr; > struct ofhooks; > struct ofproto; > struct shash; > -struct svec; > > struct ofproto_controller_info { > bool is_connected; > @@ -55,7 +55,7 @@ struct ofexpired { > }; > > struct ofproto_sflow_options { > - struct svec targets; > + struct sset targets; > uint32_t sampling_rate; > uint32_t polling_interval; > uint32_t header_len; > @@ -118,7 +118,7 @@ void ofproto_set_desc(struct ofproto *, > const char *mfr_desc, const char *hw_desc, > const char *sw_desc, const char *serial_desc, > const char *dp_desc); > -int ofproto_set_snoops(struct ofproto *, const struct svec *snoops); > +int ofproto_set_snoops(struct ofproto *, const struct sset *snoops); > int ofproto_set_netflow(struct ofproto *, > const struct netflow_options *nf_options); > void ofproto_set_sflow(struct ofproto *, const struct ofproto_sflow_options > *); > @@ -136,8 +136,9 @@ const struct cfm *ofproto_iface_get_cfm(struct ofproto *, > uint32_t port_no); > uint64_t ofproto_get_datapath_id(const struct ofproto *); > bool ofproto_has_primary_controller(const struct ofproto *); > enum ofproto_fail_mode ofproto_get_fail_mode(const struct ofproto *); > -void ofproto_get_listeners(const struct ofproto *, struct svec *); > -void ofproto_get_snoops(const struct ofproto *, struct svec *); > +void ofproto_get_listeners(const struct ofproto *, struct sset *); > +bool ofproto_has_snoops(const struct ofproto *); > +void ofproto_get_snoops(const struct ofproto *, struct sset *); > void ofproto_get_all_flows(struct ofproto *p, struct ds *); > > /* Functions for use by ofproto implementation modules, not by clients. */ > diff --git a/utilities/ovs-openflowd.c b/utilities/ovs-openflowd.c > index d2e0336..f1c52f9 100644 > --- a/utilities/ovs-openflowd.c > +++ b/utilities/ovs-openflowd.c > @@ -73,13 +73,13 @@ struct ofsettings { > const char *dp_desc; /* Datapath description. */ > > /* Related vconns and network devices. */ > - struct svec snoops; /* Listen for controller snooping conns. */ > + struct sset snoops; /* Listen for controller snooping conns. */ > > /* Failure behavior. */ > int max_idle; /* Idle time for flows in fail-open mode. */ > > /* NetFlow. */ > - struct svec netflow; /* NetFlow targets. */ > + struct sset netflow; /* NetFlow targets. */ > }; > > static unixctl_cb_func ovs_openflowd_exit; > @@ -291,9 +291,9 @@ parse_options(int argc, char *argv[], struct ofsettings > *s) > s->serial_desc = NULL; > s->dp_desc = NULL; > svec_init(&controllers); > - svec_init(&s->snoops); > + sset_init(&s->snoops); > s->max_idle = 0; > - svec_init(&s->netflow); > + sset_init(&s->netflow); > svec_init(&s->ports); > for (;;) { > int c; > @@ -398,7 +398,7 @@ parse_options(int argc, char *argv[], struct ofsettings > *s) > break; > > case OPT_NETFLOW: > - svec_add(&s->netflow, optarg); > + sset_add(&s->netflow, optarg); > break; > > case 'l': > @@ -406,7 +406,7 @@ parse_options(int argc, char *argv[], struct ofsettings > *s) > break; > > case OPT_SNOOP: > - svec_add(&s->snoops, optarg); > + sset_add(&s->snoops, optarg); > break; > > case OPT_PORTS: > diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c > index 4d06e0c..4815e46 100644 > --- a/vswitchd/bridge.c > +++ b/vswitchd/bridge.c > @@ -813,12 +813,14 @@ bridge_reconfigure(const struct ovsrec_open_vswitch > *ovs_cfg) > } > } > > - opts.collectors.n = nf_cfg->n_targets; > - opts.collectors.names = nf_cfg->targets; > + sset_init(&opts.collectors); > + sset_add_array(&opts.collectors, > + nf_cfg->targets, nf_cfg->n_targets); > if (ofproto_set_netflow(br->ofproto, &opts)) { > VLOG_ERR("bridge %s: problem setting netflow collectors", > br->name); > } > + sset_destroy(&opts.collectors); > } else { > ofproto_set_netflow(br->ofproto, NULL); > } > @@ -832,8 +834,9 @@ bridge_reconfigure(const struct ovsrec_open_vswitch > *ovs_cfg) > > memset(&oso, 0, sizeof oso); > > - oso.targets.n = sflow_cfg->n_targets; > - oso.targets.names = sflow_cfg->targets; > + sset_init(&oso.targets); > + sset_add_array(&oso.targets, > + sflow_cfg->targets, sflow_cfg->n_targets); > > oso.sampling_rate = SFL_DEFAULT_SAMPLING_RATE; > if (sflow_cfg->sampling) { > @@ -863,7 +866,7 @@ bridge_reconfigure(const struct ovsrec_open_vswitch > *ovs_cfg) > } > ofproto_set_sflow(br->ofproto, &oso); > > - /* Do not destroy oso.targets because it is owned by sflow_cfg. > */ > + sset_destroy(&oso.targets); > } else { > ofproto_set_sflow(br->ofproto, NULL); > } > @@ -1793,7 +1796,6 @@ static void > bridge_reconfigure_one(struct bridge *br) > { > enum ofproto_fail_mode fail_mode; > - struct svec snoops, old_snoops; > struct port *port, *next; > struct shash_node *node; > struct shash new_ports; > @@ -1873,16 +1875,15 @@ bridge_reconfigure_one(struct bridge *br) > * controller to another?) */ > > /* Configure OpenFlow controller connection snooping. */ > - svec_init(&snoops); > - svec_add_nocopy(&snoops, xasprintf("punix:%s/%s.snoop", > - ovs_rundir(), br->name)); > - svec_init(&old_snoops); > - ofproto_get_snoops(br->ofproto, &old_snoops); > - if (!svec_equal(&snoops, &old_snoops)) { > + if (!ofproto_has_snoops(br->ofproto)) { > + struct sset snoops; > + > + sset_init(&snoops); > + sset_add_and_free(&snoops, xasprintf("punix:%s/%s.snoop", > + ovs_rundir(), br->name)); > ofproto_set_snoops(br->ofproto, &snoops); > + sset_destroy(&snoops); > } > - svec_destroy(&snoops); > - svec_destroy(&old_snoops); > > mirror_reconfigure(br); > } > -- > 1.7.1 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > http://openvswitch.org/mailman/listinfo/dev > _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev