2014-03-23 14:47:47 -07:00
|
|
|
/* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
|
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
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* 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 <errno.h>
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-11-30 13:17:34 -08:00
|
|
|
#ifdef HAVE_MLOCKALL
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
#include "bridge.h"
|
|
|
|
#include "command-line.h"
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "daemon.h"
|
2011-07-26 10:13:07 -07:00
|
|
|
#include "dirs.h"
|
2011-11-17 18:06:55 -08:00
|
|
|
#include "dpif.h"
|
2010-11-29 12:21:08 -08:00
|
|
|
#include "dummy.h"
|
2014-02-26 10:44:46 -08:00
|
|
|
#include "fatal-signal.h"
|
2012-05-08 15:44:21 -07:00
|
|
|
#include "memory.h"
|
2009-07-30 16:04:45 -07:00
|
|
|
#include "netdev.h"
|
2011-10-03 21:52:39 -07:00
|
|
|
#include "openflow/openflow.h"
|
2009-12-03 11:28:40 -08:00
|
|
|
#include "ovsdb-idl.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "poll-loop.h"
|
2012-05-08 15:44:21 -07:00
|
|
|
#include "simap.h"
|
2010-01-06 14:35:20 -08:00
|
|
|
#include "stream-ssl.h"
|
2009-12-03 11:28:40 -08:00
|
|
|
#include "stream.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
#include "svec.h"
|
|
|
|
#include "timeval.h"
|
|
|
|
#include "unixctl.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "vconn.h"
|
2010-07-16 11:02:49 -07:00
|
|
|
#include "vlog.h"
|
2012-03-27 15:57:52 -07:00
|
|
|
#include "lib/vswitch-idl.h"
|
2014-03-24 19:23:08 -07:00
|
|
|
#include "lib/netdev-dpdk.h"
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-10-19 14:47:01 -07:00
|
|
|
VLOG_DEFINE_THIS_MODULE(vswitchd);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2012-06-29 09:22:59 -07:00
|
|
|
/* --mlockall: If set, locks all process memory into physical RAM, preventing
|
|
|
|
* the kernel from paging any of its memory to disk. */
|
|
|
|
static bool want_mlockall;
|
|
|
|
|
2010-05-03 15:43:49 -07:00
|
|
|
static unixctl_cb_func ovs_vswitchd_exit;
|
|
|
|
|
2012-01-19 10:26:03 -08:00
|
|
|
static char *parse_options(int argc, char *argv[], char **unixctl_path);
|
2014-09-15 12:58:09 -07:00
|
|
|
NO_RETURN static void usage(void);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
2012-01-19 10:26:03 -08:00
|
|
|
char *unixctl_path = NULL;
|
2009-07-08 13:19:16 -07:00
|
|
|
struct unixctl_server *unixctl;
|
2011-07-26 10:13:07 -07:00
|
|
|
char *remote;
|
2010-06-10 14:17:41 -07:00
|
|
|
bool exiting;
|
2009-07-08 13:19:16 -07:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
set_program_name(argv[0]);
|
2014-03-24 19:23:08 -07:00
|
|
|
retval = dpdk_init(argc,argv);
|
|
|
|
argc -= retval;
|
|
|
|
argv += retval;
|
|
|
|
|
|
|
|
proctitle_init(argc, argv);
|
2014-01-17 10:43:03 -08:00
|
|
|
service_start(&argc, &argv);
|
2012-01-19 10:26:03 -08:00
|
|
|
remote = parse_options(argc, argv, &unixctl_path);
|
2014-02-26 10:44:46 -08:00
|
|
|
fatal_ignore_sigpipe();
|
2010-02-08 14:09:36 -08:00
|
|
|
ovsrec_init();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2009-12-17 10:56:01 -08:00
|
|
|
daemonize_start();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2012-06-29 09:22:59 -07:00
|
|
|
if (want_mlockall) {
|
|
|
|
#ifdef HAVE_MLOCKALL
|
|
|
|
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
|
2013-06-24 10:54:49 -07:00
|
|
|
VLOG_ERR("mlockall failed: %s", ovs_strerror(errno));
|
2012-06-29 09:22:59 -07:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
VLOG_ERR("mlockall not supported on this system");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-19 10:26:03 -08:00
|
|
|
retval = unixctl_server_create(unixctl_path, &unixctl);
|
2009-07-08 13:19:16 -07:00
|
|
|
if (retval) {
|
2010-01-15 10:31:57 -08:00
|
|
|
exit(EXIT_FAILURE);
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
2011-12-02 15:29:19 -08:00
|
|
|
unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting);
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-06-10 14:17:41 -07:00
|
|
|
bridge_init(remote);
|
2011-07-26 10:13:07 -07:00
|
|
|
free(remote);
|
|
|
|
|
2010-05-03 15:43:49 -07:00
|
|
|
exiting = false;
|
|
|
|
while (!exiting) {
|
2012-05-08 15:44:21 -07:00
|
|
|
memory_run();
|
|
|
|
if (memory_should_report()) {
|
|
|
|
struct simap usage;
|
|
|
|
|
|
|
|
simap_init(&usage);
|
|
|
|
bridge_get_memory_usage(&usage);
|
|
|
|
memory_report(&usage);
|
|
|
|
simap_destroy(&usage);
|
|
|
|
}
|
2010-06-10 14:17:41 -07:00
|
|
|
bridge_run();
|
2009-07-08 13:19:16 -07:00
|
|
|
unixctl_server_run(unixctl);
|
2009-07-30 16:04:45 -07:00
|
|
|
netdev_run();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2012-05-08 15:44:21 -07:00
|
|
|
memory_wait();
|
2010-06-10 14:17:41 -07:00
|
|
|
bridge_wait();
|
2009-07-08 13:19:16 -07:00
|
|
|
unixctl_server_wait(unixctl);
|
2009-07-30 16:04:45 -07:00
|
|
|
netdev_wait();
|
2010-11-16 15:14:58 -08:00
|
|
|
if (exiting) {
|
|
|
|
poll_immediate_wake();
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
poll_block();
|
2014-01-17 10:43:03 -08:00
|
|
|
if (should_service_stop()) {
|
|
|
|
exiting = true;
|
|
|
|
}
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
2010-12-13 13:08:31 -08:00
|
|
|
bridge_exit();
|
|
|
|
unixctl_server_destroy(unixctl);
|
2014-01-17 10:43:03 -08:00
|
|
|
service_stop();
|
2009-07-08 13:19:16 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-07-26 10:13:07 -07:00
|
|
|
static char *
|
2012-01-19 10:26:03 -08:00
|
|
|
parse_options(int argc, char *argv[], char **unixctl_pathp)
|
2009-07-08 13:19:16 -07:00
|
|
|
{
|
|
|
|
enum {
|
|
|
|
OPT_PEER_CA_CERT = UCHAR_MAX + 1,
|
2009-11-30 13:17:34 -08:00
|
|
|
OPT_MLOCKALL,
|
2012-01-19 10:26:03 -08:00
|
|
|
OPT_UNIXCTL,
|
2009-07-08 13:19:16 -07:00
|
|
|
VLOG_OPTION_ENUMS,
|
2010-11-29 12:21:08 -08:00
|
|
|
OPT_BOOTSTRAP_CA_CERT,
|
2011-01-28 12:39:15 -08:00
|
|
|
OPT_ENABLE_DUMMY,
|
2011-11-17 18:06:55 -08:00
|
|
|
OPT_DISABLE_SYSTEM,
|
2014-03-24 19:23:08 -07:00
|
|
|
DAEMON_OPTION_ENUMS,
|
|
|
|
OPT_DPDK,
|
2009-07-08 13:19:16 -07:00
|
|
|
};
|
2013-04-23 16:40:56 -07:00
|
|
|
static const struct option long_options[] = {
|
2011-05-04 13:49:42 -07:00
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{"mlockall", no_argument, NULL, OPT_MLOCKALL},
|
2012-01-19 10:26:03 -08:00
|
|
|
{"unixctl", required_argument, NULL, OPT_UNIXCTL},
|
2009-07-08 13:19:16 -07:00
|
|
|
DAEMON_LONG_OPTIONS,
|
|
|
|
VLOG_LONG_OPTIONS,
|
2011-05-10 09:17:37 -07:00
|
|
|
STREAM_SSL_LONG_OPTIONS,
|
2011-05-04 13:49:42 -07:00
|
|
|
{"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
|
|
|
|
{"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
|
2012-01-19 10:24:46 -08:00
|
|
|
{"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
|
2011-11-17 18:06:55 -08:00
|
|
|
{"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM},
|
2014-03-24 19:23:08 -07:00
|
|
|
{"dpdk", required_argument, NULL, OPT_DPDK},
|
2011-05-04 13:49:42 -07:00
|
|
|
{NULL, 0, NULL, 0},
|
2009-07-08 13:19:16 -07:00
|
|
|
};
|
|
|
|
char *short_options = long_options_to_short_options(long_options);
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, short_options, long_options, NULL);
|
|
|
|
if (c == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'h':
|
|
|
|
usage();
|
|
|
|
|
|
|
|
case 'V':
|
2011-12-06 22:33:49 -08:00
|
|
|
ovs_print_version(OFP10_VERSION, OFP10_VERSION);
|
2009-07-08 13:19:16 -07:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
2009-11-30 13:17:34 -08:00
|
|
|
case OPT_MLOCKALL:
|
2012-06-29 09:22:59 -07:00
|
|
|
want_mlockall = true;
|
2009-11-30 13:17:34 -08:00
|
|
|
break;
|
|
|
|
|
2012-01-19 10:26:03 -08:00
|
|
|
case OPT_UNIXCTL:
|
|
|
|
*unixctl_pathp = optarg;
|
|
|
|
break;
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
VLOG_OPTION_HANDLERS
|
|
|
|
DAEMON_OPTION_HANDLERS
|
2010-01-06 14:35:20 -08:00
|
|
|
STREAM_SSL_OPTION_HANDLERS
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
case OPT_PEER_CA_CERT:
|
2010-01-06 14:35:20 -08:00
|
|
|
stream_ssl_set_peer_ca_cert_file(optarg);
|
2009-07-08 13:19:16 -07:00
|
|
|
break;
|
2009-12-21 13:06:47 -08:00
|
|
|
|
|
|
|
case OPT_BOOTSTRAP_CA_CERT:
|
|
|
|
stream_ssl_set_ca_cert_file(optarg, true);
|
|
|
|
break;
|
2009-07-08 13:19:16 -07:00
|
|
|
|
2010-11-29 12:21:08 -08:00
|
|
|
case OPT_ENABLE_DUMMY:
|
2012-01-19 10:24:46 -08:00
|
|
|
dummy_enable(optarg && !strcmp(optarg, "override"));
|
2010-11-29 12:21:08 -08:00
|
|
|
break;
|
|
|
|
|
2011-11-17 18:06:55 -08:00
|
|
|
case OPT_DISABLE_SYSTEM:
|
|
|
|
dp_blacklist_provider("system");
|
|
|
|
break;
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2014-03-24 19:23:08 -07:00
|
|
|
case OPT_DPDK:
|
2014-09-30 09:57:08 -07:00
|
|
|
ovs_fatal(0, "--dpdk must be given at beginning of command line.");
|
2014-03-24 19:23:08 -07:00
|
|
|
break;
|
|
|
|
|
2009-07-08 13:19:16 -07:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(short_options);
|
|
|
|
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2011-07-26 10:13:07 -07:00
|
|
|
switch (argc) {
|
|
|
|
case 0:
|
|
|
|
return xasprintf("unix:%s/db.sock", ovs_rundir());
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
return xstrdup(argv[0]);
|
|
|
|
|
|
|
|
default:
|
|
|
|
VLOG_FATAL("at most one non-option argument accepted; "
|
2011-03-31 16:23:50 -07:00
|
|
|
"use --help for usage");
|
2009-07-08 13:19:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
2009-06-23 14:18:43 -07:00
|
|
|
printf("%s: Open vSwitch daemon\n"
|
2011-07-26 10:13:07 -07:00
|
|
|
"usage: %s [OPTIONS] [DATABASE]\n"
|
|
|
|
"where DATABASE is a socket on which ovsdb-server is listening\n"
|
|
|
|
" (default: \"unix:%s/db.sock\").\n",
|
|
|
|
program_name, program_name, ovs_rundir());
|
2009-12-21 13:13:48 -08:00
|
|
|
stream_usage("DATABASE", true, false, true);
|
2009-07-08 13:19:16 -07:00
|
|
|
daemon_usage();
|
|
|
|
vlog_usage();
|
2014-08-07 12:40:34 -07:00
|
|
|
printf("\nDPDK options:\n"
|
|
|
|
" --dpdk options Initialize DPDK datapath.\n");
|
2011-02-11 13:16:28 -08:00
|
|
|
printf("\nOther options:\n"
|
2012-01-19 10:26:03 -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");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2010-05-03 15:43:49 -07:00
|
|
|
|
|
|
|
static void
|
2011-12-02 15:29:19 -08:00
|
|
|
ovs_vswitchd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
|
|
|
|
const char *argv[] OVS_UNUSED, void *exiting_)
|
2010-05-03 15:43:49 -07:00
|
|
|
{
|
|
|
|
bool *exiting = exiting_;
|
|
|
|
*exiting = true;
|
2012-02-14 20:53:59 -08:00
|
|
|
unixctl_command_reply(conn, NULL);
|
2010-05-03 15:43:49 -07:00
|
|
|
}
|