Skip to content

Commit

Permalink
ofproto: Change string sets in interface from svec to sset.
Browse files Browse the repository at this point in the history
  • Loading branch information
blp committed Mar 31, 2011
1 parent 53d0466 commit 81e2083
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 65 deletions.
20 changes: 7 additions & 13 deletions ofproto/collectors.c
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -24,7 +24,7 @@
#include <unistd.h>

#include "socket-util.h"
#include "svec.h"
#include "sset.h"
#include "util.h"
#include "vlog.h"

Expand All @@ -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;

Expand All @@ -81,7 +76,6 @@ collectors_create(const struct svec *targets_, uint16_t default_port,
}
}
}
svec_destroy(&targets);

if (c->n_fds) {
*collectorsp = c;
Expand Down
7 changes: 4 additions & 3 deletions ofproto/collectors.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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 *);

Expand Down
23 changes: 15 additions & 8 deletions ofproto/connmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
6 changes: 4 additions & 2 deletions ofproto/connmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
struct dpif_upcall;
struct ofconn;
struct ofputil_flow_removed;
struct sset;

/* ofproto supports two kinds of OpenFlow connections:
*
Expand Down Expand Up @@ -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 *);
Expand Down
3 changes: 1 addition & 2 deletions ofproto/netflow.c
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions ofproto/netflow.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,7 +19,7 @@

#include <stdint.h>
#include "flow.h"
#include "svec.h"
#include "sset.h"

/* Default active timeout interval, in seconds.
*
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions ofproto/ofproto-sflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
13 changes: 9 additions & 4 deletions ofproto/ofproto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 6 additions & 5 deletions ofproto/ofproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <stdint.h>
#include "flow.h"
#include "netflow.h"
#include "sset.h"
#include "tag.h"

#ifdef __cplusplus
Expand All @@ -35,7 +36,6 @@ struct nlattr;
struct ofhooks;
struct ofproto;
struct shash;
struct svec;

struct ofproto_controller_info {
bool is_connected;
Expand All @@ -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;
Expand Down Expand Up @@ -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 *);
Expand All @@ -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. */
Expand Down
12 changes: 6 additions & 6 deletions utilities/ovs-openflowd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -398,15 +398,15 @@ 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':
svec_add(&controllers, optarg);
break;

case OPT_SNOOP:
svec_add(&s->snoops, optarg);
sset_add(&s->snoops, optarg);
break;

case OPT_PORTS:
Expand Down
Loading

0 comments on commit 81e2083

Please sign in to comment.