mirror of
https://github.com/openvswitch/ovs
synced 2025-10-19 14:37:21 +00:00
ovs-openflowd: Use sset in place of svec.
Also deletes svec_split() since this was the only user.
This commit is contained in:
18
lib/svec.c
18
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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);
|
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 *
|
const char *
|
||||||
svec_back(const struct svec *svec)
|
svec_back(const struct svec *svec)
|
||||||
{
|
{
|
||||||
|
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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_print(const struct svec *svec, const char *title);
|
||||||
void svec_parse_words(struct svec *svec, const char *words);
|
void svec_parse_words(struct svec *svec, const char *words);
|
||||||
bool svec_equal(const struct svec *, const struct svec *);
|
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 *,
|
char *svec_join(const struct svec *,
|
||||||
const char *delimiter, const char *terminator);
|
const char *delimiter, const char *terminator);
|
||||||
const char *svec_back(const struct svec *);
|
const char *svec_back(const struct svec *);
|
||||||
|
@@ -40,7 +40,6 @@
|
|||||||
#include "poll-loop.h"
|
#include "poll-loop.h"
|
||||||
#include "rconn.h"
|
#include "rconn.h"
|
||||||
#include "stream-ssl.h"
|
#include "stream-ssl.h"
|
||||||
#include "svec.h"
|
|
||||||
#include "timeval.h"
|
#include "timeval.h"
|
||||||
#include "unixctl.h"
|
#include "unixctl.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@@ -63,7 +62,7 @@ struct ofsettings {
|
|||||||
uint64_t datapath_id; /* Datapath ID. */
|
uint64_t datapath_id; /* Datapath ID. */
|
||||||
char *dp_name; /* Name of local datapath. */
|
char *dp_name; /* Name of local datapath. */
|
||||||
char *dp_type; /* Type 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. */
|
/* Description strings. */
|
||||||
const char *mfr_desc; /* Manufacturer. */
|
const char *mfr_desc; /* Manufacturer. */
|
||||||
@@ -96,6 +95,7 @@ main(int argc, char *argv[])
|
|||||||
int error;
|
int error;
|
||||||
struct dpif *dpif;
|
struct dpif *dpif;
|
||||||
struct netflow_options nf_options;
|
struct netflow_options nf_options;
|
||||||
|
const char *port;
|
||||||
bool exiting;
|
bool exiting;
|
||||||
|
|
||||||
proctitle_init(argc, argv);
|
proctitle_init(argc, argv);
|
||||||
@@ -123,25 +123,20 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Add ports to the datapath if requested by the user. */
|
/* Add ports to the datapath if requested by the user. */
|
||||||
if (s.ports.n) {
|
SSET_FOR_EACH (port, &s.ports) {
|
||||||
const char *port;
|
struct netdev *netdev;
|
||||||
size_t i;
|
|
||||||
|
|
||||||
SVEC_FOR_EACH (i, port, &s.ports) {
|
error = netdev_open_default(port, &netdev);
|
||||||
struct netdev *netdev;
|
if (error) {
|
||||||
|
ovs_fatal(error, "%s: failed to open network device", port);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
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. */
|
/* Start OpenFlow processing. */
|
||||||
@@ -206,6 +201,21 @@ ovs_openflowd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED,
|
|||||||
|
|
||||||
/* User interface. */
|
/* 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
|
static void
|
||||||
parse_options(int argc, char *argv[], struct ofsettings *s)
|
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);
|
char *short_options = long_options_to_short_options(long_options);
|
||||||
struct ofproto_controller controller_opts;
|
struct ofproto_controller controller_opts;
|
||||||
struct svec controllers;
|
struct sset controllers;
|
||||||
|
const char *name;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Set defaults that we can figure out before parsing options. */
|
/* 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->sw_desc = NULL;
|
||||||
s->serial_desc = NULL;
|
s->serial_desc = NULL;
|
||||||
s->dp_desc = NULL;
|
s->dp_desc = NULL;
|
||||||
svec_init(&controllers);
|
sset_init(&controllers);
|
||||||
sset_init(&s->snoops);
|
sset_init(&s->snoops);
|
||||||
s->max_idle = 0;
|
s->max_idle = 0;
|
||||||
sset_init(&s->netflow);
|
sset_init(&s->netflow);
|
||||||
svec_init(&s->ports);
|
sset_init(&s->ports);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@@ -402,7 +413,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
svec_add(&controllers, optarg);
|
sset_add(&controllers, optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_SNOOP:
|
case OPT_SNOOP:
|
||||||
@@ -410,7 +421,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_PORTS:
|
case OPT_PORTS:
|
||||||
svec_split(&s->ports, optarg, ",");
|
parse_ports(optarg, &s->ports);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OPT_UNIXCTL:
|
case OPT_UNIXCTL:
|
||||||
@@ -469,25 +480,28 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
|
|||||||
|
|
||||||
/* Figure out controller names. */
|
/* Figure out controller names. */
|
||||||
s->run_forever = false;
|
s->run_forever = false;
|
||||||
if (!controllers.n) {
|
if (sset_is_empty(&controllers)) {
|
||||||
svec_add_nocopy(&controllers, xasprintf("punix:%s/%s.mgmt",
|
sset_add_and_free(&controllers, xasprintf("punix:%s/%s.mgmt",
|
||||||
ovs_rundir(), s->dp_name));
|
ovs_rundir(), s->dp_name));
|
||||||
}
|
}
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (!strcmp(argv[i], "none")) {
|
if (!strcmp(argv[i], "none")) {
|
||||||
s->run_forever = true;
|
s->run_forever = true;
|
||||||
} else {
|
} else {
|
||||||
svec_add(&controllers, argv[i]);
|
sset_add(&controllers, argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up controllers. */
|
/* Set up controllers. */
|
||||||
s->n_controllers = controllers.n;
|
s->n_controllers = sset_count(&controllers);
|
||||||
s->controllers = xmalloc(s->n_controllers * sizeof *s->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] = controller_opts;
|
||||||
s->controllers[i].target = controllers.names[i];
|
s->controllers[i].target = xstrdup(name);
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
|
sset_destroy(&controllers);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Reference in New Issue
Block a user