From: Ben Pfaff Date: Fri, 25 Mar 2011 22:04:12 +0000 (-0700) Subject: ofproto: Change string sets in interface from svec to sset. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=81e2083fe6b7c16055f01c4b1e40f25867594bf6;p=openvswitch ofproto: Change string sets in interface from svec to sset. --- diff --git a/ofproto/collectors.c b/ofproto/collectors.c index 58d6abbc..bd3e89b1 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 #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 ac70f375..47b148ba 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 #include -#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/connmgr.c b/ofproto/connmgr.c index 95cc43d1..83b3159e 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -319,7 +319,7 @@ static struct ofconn *find_controller_by_target(struct connmgr *, const char *target); static void update_fail_open(struct connmgr *); static int set_pvconns(struct pvconn ***pvconnsp, size_t *n_pvconnsp, - const struct svec *); + const struct sset *); /* Returns true if 'mgr' has any configured primary controllers. * @@ -470,22 +470,29 @@ connmgr_reconnect(const struct connmgr *mgr) * A "snoop" is a pvconn to which every OpenFlow message to or from the most * important controller on 'mgr' is mirrored. */ int -connmgr_set_snoops(struct connmgr *mgr, const struct svec *snoops) +connmgr_set_snoops(struct connmgr *mgr, const struct sset *snoops) { return set_pvconns(&mgr->snoops, &mgr->n_snoops, snoops); } /* Adds each of the snoops currently configured on 'mgr' to 'snoops'. */ void -connmgr_get_snoops(const struct connmgr *mgr, struct svec *snoops) +connmgr_get_snoops(const struct connmgr *mgr, struct sset *snoops) { size_t i; for (i = 0; i < mgr->n_snoops; i++) { - svec_add(snoops, pvconn_get_name(mgr->snoops[i])); + sset_add(snoops, pvconn_get_name(mgr->snoops[i])); } } +/* Returns true if 'mgr' has at least one snoop, false if it has none. */ +bool +connmgr_has_snoops(const struct connmgr *mgr) +{ + return mgr->n_snoops > 0; +} + /* Creates a new controller for 'target' in 'mgr'. update_controller() needs * to be called later to finish the new ofconn's configuration. */ static void @@ -583,10 +590,11 @@ update_fail_open(struct connmgr *mgr) 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; @@ -595,10 +603,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; diff --git a/ofproto/connmgr.h b/ofproto/connmgr.h index 4710e6da..6ee9cb42 100644 --- a/ofproto/connmgr.h +++ b/ofproto/connmgr.h @@ -26,6 +26,7 @@ struct dpif_upcall; struct ofconn; struct ofputil_flow_removed; +struct sset; /* ofproto supports two kinds of OpenFlow connections: * @@ -66,8 +67,9 @@ void connmgr_set_controllers(struct connmgr *, const struct ofproto_controller[], size_t n); void connmgr_reconnect(const struct connmgr *); -int connmgr_set_snoops(struct connmgr *, const struct svec *snoops); -void connmgr_get_snoops(const struct connmgr *, struct svec *snoops); +int connmgr_set_snoops(struct connmgr *, const struct sset *snoops); +bool connmgr_has_snoops(const struct connmgr *); +void connmgr_get_snoops(const struct connmgr *, struct sset *snoops); /* Individual connections to OpenFlow controllers. */ enum ofconn_type ofconn_get_type(const struct ofconn *); diff --git a/ofproto/netflow.c b/ofproto/netflow.c index 77572fe5..2d69db80 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 58fe7cb3..bf5bf45b 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 #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 05794e1c..5351b837 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 8b8b28dd..ebdbc682 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -57,7 +57,6 @@ #include "shash.h" #include "sset.h" #include "stream-ssl.h" -#include "svec.h" #include "tag.h" #include "timer.h" #include "timeval.h" @@ -544,7 +543,7 @@ ofproto_set_desc(struct ofproto *p, } int -ofproto_set_snoops(struct ofproto *ofproto, const struct svec *snoops) +ofproto_set_snoops(struct ofproto *ofproto, const struct sset *snoops) { return connmgr_set_snoops(ofproto->connmgr, snoops); } @@ -553,7 +552,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(); } @@ -668,8 +667,14 @@ ofproto_get_fail_mode(const struct ofproto *p) return connmgr_get_fail_mode(p->connmgr); } +bool +ofproto_has_snoops(const struct ofproto *ofproto) +{ + return connmgr_has_snoops(ofproto->connmgr); +} + void -ofproto_get_snoops(const struct ofproto *ofproto, struct svec *snoops) +ofproto_get_snoops(const struct ofproto *ofproto, struct sset *snoops) { connmgr_get_snoops(ofproto->connmgr, snoops); } diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h index b049fe1a..96f00988 100644 --- a/ofproto/ofproto.h +++ b/ofproto/ofproto.h @@ -24,6 +24,7 @@ #include #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 d2e0336f..f1c52f99 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 22af407b..eb6f2ebe 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -820,12 +820,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); } @@ -839,8 +841,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) { @@ -870,7 +873,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); } @@ -1812,7 +1815,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; @@ -1892,16 +1894,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); }