2009-07-08 13:19:16 -07:00
|
|
|
|
/*
|
2011-01-28 12:39:15 -08:00
|
|
|
|
* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at:
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
2009-07-08 13:19:16 -07:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "command-line.h"
|
|
|
|
|
#include "compiler.h"
|
|
|
|
|
#include "daemon.h"
|
|
|
|
|
#include "dirs.h"
|
|
|
|
|
#include "dpif.h"
|
2010-11-12 12:43:16 -08:00
|
|
|
|
#include "dummy.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#include "leak-checker.h"
|
|
|
|
|
#include "list.h"
|
|
|
|
|
#include "netdev.h"
|
|
|
|
|
#include "ofpbuf.h"
|
2009-07-08 10:30:42 -07:00
|
|
|
|
#include "ofproto/ofproto.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#include "openflow/openflow.h"
|
|
|
|
|
#include "packets.h"
|
|
|
|
|
#include "poll-loop.h"
|
|
|
|
|
#include "rconn.h"
|
2010-01-06 14:35:20 -08:00
|
|
|
|
#include "stream-ssl.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
#include "svec.h"
|
|
|
|
|
#include "timeval.h"
|
|
|
|
|
#include "unixctl.h"
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "vconn.h"
|
|
|
|
|
#include "vlog.h"
|
2010-07-16 11:02:49 -07:00
|
|
|
|
|
2010-10-19 14:47:01 -07:00
|
|
|
|
VLOG_DEFINE_THIS_MODULE(openflowd);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
/* Settings that may be configured by the user. */
|
|
|
|
|
struct ofsettings {
|
2010-11-12 12:42:57 -08:00
|
|
|
|
const char *unixctl_path; /* File name for unixctl socket. */
|
|
|
|
|
|
2010-04-20 10:05:57 -07:00
|
|
|
|
/* Controller configuration. */
|
2010-04-20 10:43:42 -07:00
|
|
|
|
struct ofproto_controller *controllers;
|
|
|
|
|
size_t n_controllers;
|
2010-07-15 20:56:43 -07:00
|
|
|
|
enum ofproto_fail_mode fail_mode;
|
2010-11-12 14:19:23 -08:00
|
|
|
|
bool run_forever; /* Continue running even with no controller? */
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
/* Datapath. */
|
|
|
|
|
uint64_t datapath_id; /* Datapath ID. */
|
2010-01-22 14:37:05 -05:00
|
|
|
|
char *dp_name; /* Name of local datapath. */
|
|
|
|
|
char *dp_type; /* Type of local datapath. */
|
2009-11-23 11:32:08 -08:00
|
|
|
|
struct svec ports; /* Set of ports to add to datapath (if any). */
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
/* Description strings. */
|
|
|
|
|
const char *mfr_desc; /* Manufacturer. */
|
|
|
|
|
const char *hw_desc; /* Hardware. */
|
|
|
|
|
const char *sw_desc; /* Software version. */
|
|
|
|
|
const char *serial_desc; /* Serial number. */
|
2010-01-28 15:07:18 -08:00
|
|
|
|
const char *dp_desc; /* Datapath description. */
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
/* Related vconns and network devices. */
|
|
|
|
|
struct svec 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. */
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-29 12:39:55 -08:00
|
|
|
|
static unixctl_cb_func ovs_openflowd_exit;
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
static void parse_options(int argc, char *argv[], struct ofsettings *);
|
|
|
|
|
static void usage(void) NO_RETURN;
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
struct unixctl_server *unixctl;
|
|
|
|
|
struct ofproto *ofproto;
|
|
|
|
|
struct ofsettings s;
|
|
|
|
|
int error;
|
2010-01-22 14:37:05 -05:00
|
|
|
|
struct dpif *dpif;
|
2009-11-03 12:25:29 -08:00
|
|
|
|
struct netflow_options nf_options;
|
2010-11-29 12:39:55 -08:00
|
|
|
|
bool exiting;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2010-01-19 15:00:56 -08:00
|
|
|
|
proctitle_init(argc, argv);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
set_program_name(argv[0]);
|
|
|
|
|
parse_options(argc, argv, &s);
|
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
|
|
|
|
|
|
die_if_already_running();
|
2009-12-17 10:56:01 -08:00
|
|
|
|
daemonize_start();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
/* Start listening for ovs-appctl requests. */
|
2010-11-12 12:42:57 -08:00
|
|
|
|
error = unixctl_server_create(s.unixctl_path, &unixctl);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
if (error) {
|
2010-01-15 10:31:57 -08:00
|
|
|
|
exit(EXIT_FAILURE);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 12:39:55 -08:00
|
|
|
|
unixctl_command_register("exit", ovs_openflowd_exit, &exiting);
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
VLOG_INFO("Open vSwitch version %s", VERSION BUILDNR);
|
|
|
|
|
VLOG_INFO("OpenFlow protocol version 0x%02x", OFP_VERSION);
|
|
|
|
|
|
2010-01-22 14:37:05 -05:00
|
|
|
|
error = dpif_create_and_open(s.dp_name, s.dp_type, &dpif);
|
|
|
|
|
if (error) {
|
|
|
|
|
ovs_fatal(error, "could not create datapath");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add ports to the datapath if requested by the user. */
|
2009-11-23 11:32:08 -08:00
|
|
|
|
if (s.ports.n) {
|
|
|
|
|
const char *port;
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
SVEC_FOR_EACH (i, port, &s.ports) {
|
2010-12-03 14:41:38 -08:00
|
|
|
|
struct netdev *netdev;
|
|
|
|
|
|
|
|
|
|
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);
|
2009-11-23 11:32:08 -08:00
|
|
|
|
if (error) {
|
|
|
|
|
ovs_fatal(error, "failed to add %s as a port", port);
|
|
|
|
|
}
|
2010-12-03 14:41:38 -08:00
|
|
|
|
|
|
|
|
|
netdev_close(netdev);
|
2009-11-23 11:32:08 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
/* Start OpenFlow processing. */
|
2010-01-22 14:37:05 -05:00
|
|
|
|
error = ofproto_create(s.dp_name, s.dp_type, NULL, NULL, &ofproto);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
if (error) {
|
|
|
|
|
ovs_fatal(error, "could not initialize openflow switch");
|
|
|
|
|
}
|
|
|
|
|
if (s.datapath_id) {
|
|
|
|
|
ofproto_set_datapath_id(ofproto, s.datapath_id);
|
|
|
|
|
}
|
2010-01-12 23:01:25 -08:00
|
|
|
|
ofproto_set_desc(ofproto, s.mfr_desc, s.hw_desc, s.sw_desc,
|
|
|
|
|
s.serial_desc, s.dp_desc);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
error = ofproto_set_snoops(ofproto, &s.snoops);
|
|
|
|
|
if (error) {
|
|
|
|
|
ovs_fatal(error,
|
|
|
|
|
"failed to configure controller snooping connections");
|
|
|
|
|
}
|
2009-11-03 12:25:29 -08:00
|
|
|
|
memset(&nf_options, 0, sizeof nf_options);
|
|
|
|
|
nf_options.collectors = s.netflow;
|
|
|
|
|
error = ofproto_set_netflow(ofproto, &nf_options);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
if (error) {
|
|
|
|
|
ovs_fatal(error, "failed to configure NetFlow collectors");
|
|
|
|
|
}
|
2010-04-20 10:43:42 -07:00
|
|
|
|
ofproto_set_controllers(ofproto, s.controllers, s.n_controllers);
|
2010-07-15 20:56:43 -07:00
|
|
|
|
ofproto_set_fail_mode(ofproto, s.fail_mode);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
2009-12-17 10:56:01 -08:00
|
|
|
|
daemonize_complete();
|
|
|
|
|
|
2010-11-29 12:39:55 -08:00
|
|
|
|
exiting = false;
|
|
|
|
|
while (!exiting && (s.run_forever || ofproto_is_alive(ofproto))) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
error = ofproto_run(ofproto);
|
|
|
|
|
if (error) {
|
|
|
|
|
ovs_fatal(error, "unrecoverable datapath error");
|
|
|
|
|
}
|
|
|
|
|
unixctl_server_run(unixctl);
|
2009-06-19 14:09:09 -07:00
|
|
|
|
dp_run();
|
2009-07-30 16:04:45 -07:00
|
|
|
|
netdev_run();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
ofproto_wait(ofproto);
|
|
|
|
|
unixctl_server_wait(unixctl);
|
2009-06-19 14:09:09 -07:00
|
|
|
|
dp_wait();
|
2009-07-30 16:04:45 -07:00
|
|
|
|
netdev_wait();
|
2010-11-29 12:39:55 -08:00
|
|
|
|
if (exiting) {
|
|
|
|
|
poll_immediate_wake();
|
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
|
poll_block();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-22 14:37:05 -05:00
|
|
|
|
dpif_close(dpif);
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-11-29 12:39:55 -08:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ovs_openflowd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED,
|
|
|
|
|
void *exiting_)
|
|
|
|
|
{
|
|
|
|
|
bool *exiting = exiting_;
|
|
|
|
|
*exiting = true;
|
|
|
|
|
unixctl_command_reply(conn, 200, NULL);
|
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
/* User interface. */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
parse_options(int argc, char *argv[], struct ofsettings *s)
|
|
|
|
|
{
|
|
|
|
|
enum {
|
|
|
|
|
OPT_DATAPATH_ID = UCHAR_MAX + 1,
|
2010-01-29 15:45:46 -08:00
|
|
|
|
OPT_MFR_DESC,
|
|
|
|
|
OPT_HW_DESC,
|
|
|
|
|
OPT_SW_DESC,
|
|
|
|
|
OPT_SERIAL_DESC,
|
2010-01-12 23:01:25 -08:00
|
|
|
|
OPT_DP_DESC,
|
2009-07-08 13:19:16 -07:00
|
|
|
|
OPT_ACCEPT_VCONN,
|
|
|
|
|
OPT_NO_RESOLV_CONF,
|
|
|
|
|
OPT_BR_NAME,
|
|
|
|
|
OPT_FAIL_MODE,
|
|
|
|
|
OPT_INACTIVITY_PROBE,
|
|
|
|
|
OPT_MAX_IDLE,
|
|
|
|
|
OPT_MAX_BACKOFF,
|
|
|
|
|
OPT_SNOOP,
|
|
|
|
|
OPT_RATE_LIMIT,
|
|
|
|
|
OPT_BURST_LIMIT,
|
|
|
|
|
OPT_BOOTSTRAP_CA_CERT,
|
|
|
|
|
OPT_OUT_OF_BAND,
|
|
|
|
|
OPT_IN_BAND,
|
|
|
|
|
OPT_NETFLOW,
|
2009-11-23 11:32:08 -08:00
|
|
|
|
OPT_PORTS,
|
2010-11-12 12:42:57 -08:00
|
|
|
|
OPT_UNIXCTL,
|
2010-11-12 12:43:16 -08:00
|
|
|
|
OPT_ENABLE_DUMMY,
|
2009-07-08 13:19:16 -07:00
|
|
|
|
VLOG_OPTION_ENUMS,
|
2011-01-28 12:39:15 -08:00
|
|
|
|
LEAK_CHECKER_OPTION_ENUMS,
|
|
|
|
|
DAEMON_OPTION_ENUMS
|
2009-07-08 13:19:16 -07:00
|
|
|
|
};
|
|
|
|
|
static struct option long_options[] = {
|
|
|
|
|
{"datapath-id", required_argument, 0, OPT_DATAPATH_ID},
|
2010-01-29 15:45:46 -08:00
|
|
|
|
{"mfr-desc", required_argument, 0, OPT_MFR_DESC},
|
|
|
|
|
{"hw-desc", required_argument, 0, OPT_HW_DESC},
|
|
|
|
|
{"sw-desc", required_argument, 0, OPT_SW_DESC},
|
|
|
|
|
{"serial-desc", required_argument, 0, OPT_SERIAL_DESC},
|
|
|
|
|
{"dp-desc", required_argument, 0, OPT_DP_DESC},
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{"accept-vconn", required_argument, 0, OPT_ACCEPT_VCONN},
|
|
|
|
|
{"no-resolv-conf", no_argument, 0, OPT_NO_RESOLV_CONF},
|
|
|
|
|
{"config", required_argument, 0, 'F'},
|
|
|
|
|
{"br-name", required_argument, 0, OPT_BR_NAME},
|
|
|
|
|
{"fail", required_argument, 0, OPT_FAIL_MODE},
|
|
|
|
|
{"inactivity-probe", required_argument, 0, OPT_INACTIVITY_PROBE},
|
|
|
|
|
{"max-idle", required_argument, 0, OPT_MAX_IDLE},
|
|
|
|
|
{"max-backoff", required_argument, 0, OPT_MAX_BACKOFF},
|
|
|
|
|
{"listen", required_argument, 0, 'l'},
|
|
|
|
|
{"snoop", required_argument, 0, OPT_SNOOP},
|
|
|
|
|
{"rate-limit", optional_argument, 0, OPT_RATE_LIMIT},
|
|
|
|
|
{"burst-limit", required_argument, 0, OPT_BURST_LIMIT},
|
|
|
|
|
{"out-of-band", no_argument, 0, OPT_OUT_OF_BAND},
|
|
|
|
|
{"in-band", no_argument, 0, OPT_IN_BAND},
|
|
|
|
|
{"netflow", required_argument, 0, OPT_NETFLOW},
|
2009-11-23 11:32:08 -08:00
|
|
|
|
{"ports", required_argument, 0, OPT_PORTS},
|
2010-11-12 12:42:57 -08:00
|
|
|
|
{"unixctl", required_argument, 0, OPT_UNIXCTL},
|
2010-11-12 12:43:16 -08:00
|
|
|
|
{"enable-dummy", no_argument, 0, OPT_ENABLE_DUMMY},
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{"verbose", optional_argument, 0, 'v'},
|
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
|
{"version", no_argument, 0, 'V'},
|
|
|
|
|
DAEMON_LONG_OPTIONS,
|
|
|
|
|
VLOG_LONG_OPTIONS,
|
|
|
|
|
LEAK_CHECKER_LONG_OPTIONS,
|
|
|
|
|
#ifdef HAVE_OPENSSL
|
2010-01-06 14:35:20 -08:00
|
|
|
|
STREAM_SSL_LONG_OPTIONS
|
2009-07-08 13:19:16 -07:00
|
|
|
|
{"bootstrap-ca-cert", required_argument, 0, OPT_BOOTSTRAP_CA_CERT},
|
|
|
|
|
#endif
|
|
|
|
|
{0, 0, 0, 0},
|
|
|
|
|
};
|
|
|
|
|
char *short_options = long_options_to_short_options(long_options);
|
2010-04-20 10:43:42 -07:00
|
|
|
|
struct ofproto_controller controller_opts;
|
2010-08-06 16:49:20 -07:00
|
|
|
|
struct svec controllers;
|
|
|
|
|
int i;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
/* Set defaults that we can figure out before parsing options. */
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.target = NULL;
|
|
|
|
|
controller_opts.max_backoff = 8;
|
|
|
|
|
controller_opts.probe_interval = 5;
|
|
|
|
|
controller_opts.band = OFPROTO_IN_BAND;
|
|
|
|
|
controller_opts.accept_re = NULL;
|
|
|
|
|
controller_opts.update_resolv_conf = true;
|
|
|
|
|
controller_opts.rate_limit = 0;
|
|
|
|
|
controller_opts.burst_limit = 0;
|
2010-11-12 12:42:57 -08:00
|
|
|
|
s->unixctl_path = NULL;
|
2010-07-15 20:56:43 -07:00
|
|
|
|
s->fail_mode = OFPROTO_FAIL_STANDALONE;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
s->datapath_id = 0;
|
|
|
|
|
s->mfr_desc = NULL;
|
|
|
|
|
s->hw_desc = NULL;
|
|
|
|
|
s->sw_desc = NULL;
|
|
|
|
|
s->serial_desc = NULL;
|
2010-01-12 23:01:25 -08:00
|
|
|
|
s->dp_desc = NULL;
|
2010-08-06 16:49:20 -07:00
|
|
|
|
svec_init(&controllers);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
svec_init(&s->snoops);
|
|
|
|
|
s->max_idle = 0;
|
|
|
|
|
svec_init(&s->netflow);
|
2009-11-23 11:32:08 -08:00
|
|
|
|
svec_init(&s->ports);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
for (;;) {
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, short_options, long_options, NULL);
|
|
|
|
|
if (c == -1) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
case OPT_DATAPATH_ID:
|
2009-12-03 11:28:40 -08:00
|
|
|
|
if (!dpid_from_string(optarg, &s->datapath_id)) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ovs_fatal(0, "argument to --datapath-id must be "
|
2009-11-13 13:21:13 -08:00
|
|
|
|
"exactly 16 hex digits and may not be all-zero");
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2010-01-29 15:45:46 -08:00
|
|
|
|
case OPT_MFR_DESC:
|
2009-07-08 13:19:16 -07:00
|
|
|
|
s->mfr_desc = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2010-01-29 15:45:46 -08:00
|
|
|
|
case OPT_HW_DESC:
|
2009-07-08 13:19:16 -07:00
|
|
|
|
s->hw_desc = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2010-01-29 15:45:46 -08:00
|
|
|
|
case OPT_SW_DESC:
|
2009-07-08 13:19:16 -07:00
|
|
|
|
s->sw_desc = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2010-01-29 15:45:46 -08:00
|
|
|
|
case OPT_SERIAL_DESC:
|
2009-07-08 13:19:16 -07:00
|
|
|
|
s->serial_desc = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2010-01-12 23:01:25 -08:00
|
|
|
|
case OPT_DP_DESC:
|
|
|
|
|
s->dp_desc = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
case OPT_ACCEPT_VCONN:
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.accept_re = optarg;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_NO_RESOLV_CONF:
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.update_resolv_conf = false;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_FAIL_MODE:
|
2010-04-20 10:48:15 -07:00
|
|
|
|
if (!strcmp(optarg, "open") || !strcmp(optarg, "standalone")) {
|
2010-07-15 20:56:43 -07:00
|
|
|
|
s->fail_mode = OFPROTO_FAIL_STANDALONE;
|
2010-04-20 10:48:15 -07:00
|
|
|
|
} else if (!strcmp(optarg, "closed")
|
|
|
|
|
|| !strcmp(optarg, "secure")) {
|
2010-07-15 20:56:43 -07:00
|
|
|
|
s->fail_mode = OFPROTO_FAIL_SECURE;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
} else {
|
2010-04-20 10:48:15 -07:00
|
|
|
|
ovs_fatal(0, "--fail argument must be \"standalone\" "
|
|
|
|
|
"or \"secure\"");
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_INACTIVITY_PROBE:
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.probe_interval = atoi(optarg);
|
|
|
|
|
if (controller_opts.probe_interval < 5) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ovs_fatal(0, "--inactivity-probe argument must be at least 5");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_MAX_IDLE:
|
|
|
|
|
if (!strcmp(optarg, "permanent")) {
|
|
|
|
|
s->max_idle = OFP_FLOW_PERMANENT;
|
|
|
|
|
} else {
|
|
|
|
|
s->max_idle = atoi(optarg);
|
|
|
|
|
if (s->max_idle < 1 || s->max_idle > 65535) {
|
|
|
|
|
ovs_fatal(0, "--max-idle argument must be between 1 and "
|
|
|
|
|
"65535 or the word 'permanent'");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_MAX_BACKOFF:
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.max_backoff = atoi(optarg);
|
|
|
|
|
if (controller_opts.max_backoff < 1) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ovs_fatal(0, "--max-backoff argument must be at least 1");
|
2010-04-20 10:43:42 -07:00
|
|
|
|
} else if (controller_opts.max_backoff > 3600) {
|
|
|
|
|
controller_opts.max_backoff = 3600;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_RATE_LIMIT:
|
|
|
|
|
if (optarg) {
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.rate_limit = atoi(optarg);
|
|
|
|
|
if (controller_opts.rate_limit < 1) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ovs_fatal(0, "--rate-limit argument must be at least 1");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.rate_limit = 1000;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_BURST_LIMIT:
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.burst_limit = atoi(optarg);
|
|
|
|
|
if (controller_opts.burst_limit < 1) {
|
2009-07-08 13:19:16 -07:00
|
|
|
|
ovs_fatal(0, "--burst-limit argument must be at least 1");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_OUT_OF_BAND:
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.band = OFPROTO_OUT_OF_BAND;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_IN_BAND:
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.band = OFPROTO_IN_BAND;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_NETFLOW:
|
|
|
|
|
svec_add(&s->netflow, optarg);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'l':
|
2010-08-06 16:49:20 -07:00
|
|
|
|
svec_add(&controllers, optarg);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case OPT_SNOOP:
|
|
|
|
|
svec_add(&s->snoops, optarg);
|
|
|
|
|
break;
|
|
|
|
|
|
2009-11-23 11:32:08 -08:00
|
|
|
|
case OPT_PORTS:
|
|
|
|
|
svec_split(&s->ports, optarg, ",");
|
|
|
|
|
break;
|
|
|
|
|
|
2010-11-12 12:42:57 -08:00
|
|
|
|
case OPT_UNIXCTL:
|
|
|
|
|
s->unixctl_path = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
2010-11-12 12:43:16 -08:00
|
|
|
|
case OPT_ENABLE_DUMMY:
|
|
|
|
|
dummy_enable();
|
|
|
|
|
break;
|
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
|
case 'h':
|
|
|
|
|
usage();
|
|
|
|
|
|
|
|
|
|
case 'V':
|
|
|
|
|
OVS_PRINT_VERSION(OFP_VERSION, OFP_VERSION);
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
|
|
|
|
|
DAEMON_OPTION_HANDLERS
|
|
|
|
|
|
|
|
|
|
VLOG_OPTION_HANDLERS
|
|
|
|
|
|
|
|
|
|
LEAK_CHECKER_OPTION_HANDLERS
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENSSL
|
2010-01-06 14:35:20 -08:00
|
|
|
|
STREAM_SSL_OPTION_HANDLERS
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
|
|
case OPT_BOOTSTRAP_CA_CERT:
|
2010-01-06 14:35:20 -08:00
|
|
|
|
stream_ssl_set_ca_cert_file(optarg, true);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
free(short_options);
|
|
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
|
argv += optind;
|
2010-08-06 16:49:14 -07:00
|
|
|
|
if (argc < 1) {
|
|
|
|
|
ovs_fatal(0, "need at least one non-option arguments; "
|
2009-07-08 13:19:16 -07:00
|
|
|
|
"use --help for usage");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set accept_controller_regex. */
|
2010-04-20 10:43:42 -07:00
|
|
|
|
if (!controller_opts.accept_re) {
|
|
|
|
|
controller_opts.accept_re
|
2010-01-06 14:35:20 -08:00
|
|
|
|
= stream_ssl_is_configured() ? "^ssl:.*" : "^tcp:.*";
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Rate limiting. */
|
2010-04-20 10:43:42 -07:00
|
|
|
|
if (controller_opts.rate_limit && controller_opts.rate_limit < 100) {
|
2010-04-20 10:05:57 -07:00
|
|
|
|
VLOG_WARN("Rate limit set to unusually low value %d",
|
2010-04-20 10:43:42 -07:00
|
|
|
|
controller_opts.rate_limit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Local vconns. */
|
|
|
|
|
dp_parse_name(argv[0], &s->dp_name, &s->dp_type);
|
|
|
|
|
|
2010-08-06 16:49:20 -07:00
|
|
|
|
/* Figure out controller names. */
|
2010-11-12 14:19:23 -08:00
|
|
|
|
s->run_forever = false;
|
2010-08-06 16:49:20 -07:00
|
|
|
|
if (!controllers.n) {
|
2010-11-29 12:28:26 -08:00
|
|
|
|
svec_add_nocopy(&controllers, xasprintf("punix:%s/%s.mgmt",
|
|
|
|
|
ovs_rundir(), s->dp_name));
|
2010-08-06 16:49:20 -07:00
|
|
|
|
}
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
2010-11-12 14:19:23 -08:00
|
|
|
|
if (!strcmp(argv[i], "none")) {
|
|
|
|
|
s->run_forever = true;
|
|
|
|
|
} else {
|
|
|
|
|
svec_add(&controllers, argv[i]);
|
|
|
|
|
}
|
2010-08-06 16:49:20 -07:00
|
|
|
|
}
|
|
|
|
|
if (argc < 2) {
|
|
|
|
|
svec_add(&controllers, "discover");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Set up controllers. */
|
|
|
|
|
s->n_controllers = controllers.n;
|
2010-04-20 10:43:42 -07:00
|
|
|
|
s->controllers = xmalloc(s->n_controllers * sizeof *s->controllers);
|
2010-10-07 23:51:02 -07:00
|
|
|
|
for (i = 0; i < s->n_controllers; i++) {
|
|
|
|
|
s->controllers[i] = controller_opts;
|
|
|
|
|
s->controllers[i].target = controllers.names[i];
|
2010-04-20 10:43:42 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Sanity check. */
|
|
|
|
|
if (controller_opts.band == OFPROTO_OUT_OF_BAND) {
|
|
|
|
|
for (i = 0; i < s->n_controllers; i++) {
|
|
|
|
|
if (!strcmp(s->controllers[i].target, "discover")) {
|
|
|
|
|
ovs_fatal(0, "Cannot perform discovery with out-of-band "
|
|
|
|
|
"control");
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
usage(void)
|
|
|
|
|
{
|
|
|
|
|
printf("%s: an OpenFlow switch implementation.\n"
|
2010-11-29 12:36:31 -08:00
|
|
|
|
"usage: %s [OPTIONS] [TYPE@]DATAPATH [CONTROLLER...]\n"
|
|
|
|
|
"where DATAPATH is a local datapath (e.g. \"dp0\")\n"
|
|
|
|
|
"optionally with an explicit TYPE (default: \"system\").\n"
|
2010-04-20 10:43:42 -07:00
|
|
|
|
"Each CONTROLLER is an active OpenFlow connection method. If\n"
|
|
|
|
|
"none is given, ovs-openflowd performs controller discovery.\n",
|
2009-07-08 13:19:16 -07:00
|
|
|
|
program_name, program_name);
|
|
|
|
|
vconn_usage(true, true, true);
|
|
|
|
|
printf("\nOpenFlow options:\n"
|
|
|
|
|
" -d, --datapath-id=ID Use ID as the OpenFlow switch ID\n"
|
2009-11-13 13:21:13 -08:00
|
|
|
|
" (ID must consist of 16 hex digits)\n"
|
2010-01-29 15:45:46 -08:00
|
|
|
|
" --mfr-desc=MFR Identify manufacturer as MFR\n"
|
|
|
|
|
" --hw-desc=HW Identify hardware as HW\n"
|
|
|
|
|
" --sw-desc=SW Identify software as SW\n"
|
|
|
|
|
" --serial-desc=SERIAL Identify serial number as SERIAL\n"
|
|
|
|
|
" --dp-desc=DP_DESC Identify dp description as DP_DESC\n"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
"\nController discovery options:\n"
|
|
|
|
|
" --accept-vconn=REGEX accept matching discovered controllers\n"
|
|
|
|
|
" --no-resolv-conf do not update /etc/resolv.conf\n"
|
|
|
|
|
"\nNetworking options:\n"
|
|
|
|
|
" --fail=open|closed when controller connection fails:\n"
|
|
|
|
|
" closed: drop all packets\n"
|
|
|
|
|
" open (default): act as learning switch\n"
|
|
|
|
|
" --inactivity-probe=SECS time between inactivity probes\n"
|
2009-07-08 10:30:42 -07:00
|
|
|
|
" --max-idle=SECS max idle for flows set up by switch\n"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
" --max-backoff=SECS max time between controller connection\n"
|
2009-07-28 10:21:03 -07:00
|
|
|
|
" attempts (default: 8 seconds)\n"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
" -l, --listen=METHOD allow management connections on METHOD\n"
|
|
|
|
|
" (a passive OpenFlow connection method)\n"
|
|
|
|
|
" --snoop=METHOD allow controller snooping on METHOD\n"
|
|
|
|
|
" (a passive OpenFlow connection method)\n"
|
|
|
|
|
" --out-of-band controller connection is out-of-band\n"
|
|
|
|
|
" --netflow=HOST:PORT configure NetFlow output target\n"
|
|
|
|
|
"\nRate-limiting of \"packet-in\" messages to the controller:\n"
|
|
|
|
|
" --rate-limit[=PACKETS] max rate, in packets/s (default: 1000)\n"
|
2010-01-04 13:21:13 -08:00
|
|
|
|
" --burst-limit=BURST limit on packet credit for idle time\n");
|
2009-07-08 13:19:16 -07:00
|
|
|
|
daemon_usage();
|
|
|
|
|
vlog_usage();
|
|
|
|
|
printf("\nOther options:\n"
|
2010-11-12 12:42:57 -08:00
|
|
|
|
" --unixctl=SOCKET override default control socket name\n"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
" -h, --help display this help message\n"
|
|
|
|
|
" -V, --version display version information\n");
|
|
|
|
|
leak_checker_usage();
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
}
|