/*
- * 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.
#include <unistd.h>
#include "socket-util.h"
-#include "svec.h"
+#include "sset.h"
#include "util.h"
#include "vlog.h"
* 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;
}
}
}
- svec_destroy(&targets);
if (c->n_fds) {
*collectorsp = c;
/*
- * 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.
#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 *);
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.
*
* 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
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;
}
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;
struct dpif_upcall;
struct ofconn;
struct ofputil_flow_removed;
+struct sset;
/* ofproto supports two kinds of OpenFlow connections:
*
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 *);
/*
- * 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.
#include "ofproto.h"
#include "packets.h"
#include "socket-util.h"
-#include "svec.h"
#include "timeval.h"
#include "util.h"
#include "vlog.h"
/*
- * 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.
#include <stdint.h>
#include "flow.h"
-#include "svec.h"
+#include "sset.h"
/* Default active timeout interval, in seconds.
*
struct ofexpired;
struct netflow_options {
- struct svec collectors;
+ struct sset collectors;
uint8_t engine_type;
uint8_t engine_id;
int active_timeout;
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
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;
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);
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);
* 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);
#include "shash.h"
#include "sset.h"
#include "stream-ssl.h"
-#include "svec.h"
#include "tag.h"
#include "timer.h"
#include "timeval.h"
}
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);
}
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();
}
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);
}
#include <stdint.h>
#include "flow.h"
#include "netflow.h"
+#include "sset.h"
#include "tag.h"
#ifdef __cplusplus
struct ofhooks;
struct ofproto;
struct shash;
-struct svec;
struct ofproto_controller_info {
bool is_connected;
};
struct ofproto_sflow_options {
- struct svec targets;
+ struct sset targets;
uint32_t sampling_rate;
uint32_t polling_interval;
uint32_t header_len;
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 *);
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. */
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;
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;
break;
case OPT_NETFLOW:
- svec_add(&s->netflow, optarg);
+ sset_add(&s->netflow, optarg);
break;
case 'l':
break;
case OPT_SNOOP:
- svec_add(&s->snoops, optarg);
+ sset_add(&s->snoops, optarg);
break;
case OPT_PORTS:
}
}
- 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);
}
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) {
}
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);
}
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;
* 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);
}