1 /* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
29 #include "command-line.h"
35 #include "fatal-signal.h"
38 #include "openflow/openflow.h"
39 #include "ovsdb-idl.h"
40 #include "poll-loop.h"
42 #include "stream-ssl.h"
48 #include "openvswitch/vconn.h"
49 #include "openvswitch/vlog.h"
50 #include "lib/vswitch-idl.h"
51 #include "lib/netdev-dpdk.h"
53 VLOG_DEFINE_THIS_MODULE(vswitchd
);
55 /* --mlockall: If set, locks all process memory into physical RAM, preventing
56 * the kernel from paging any of its memory to disk. */
57 static bool want_mlockall
;
59 static unixctl_cb_func ovs_vswitchd_exit
;
61 static char *parse_options(int argc
, char *argv
[], char **unixctl_path
);
62 OVS_NO_RETURN
static void usage(void);
65 main(int argc
, char *argv
[])
67 char *unixctl_path
= NULL
;
68 struct unixctl_server
*unixctl
;
73 set_program_name(argv
[0]);
74 retval
= dpdk_init(argc
,argv
);
82 ovs_cmdl_proctitle_init(argc
, argv
);
83 service_start(&argc
, &argv
);
84 remote
= parse_options(argc
, argv
, &unixctl_path
);
85 fatal_ignore_sigpipe();
88 daemonize_start(true);
92 if (mlockall(MCL_CURRENT
| MCL_FUTURE
)) {
93 VLOG_ERR("mlockall failed: %s", ovs_strerror(errno
));
96 VLOG_ERR("mlockall not supported on this system");
100 retval
= unixctl_server_create(unixctl_path
, &unixctl
);
104 unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit
, &exiting
);
112 if (memory_should_report()) {
116 bridge_get_memory_usage(&usage
);
117 memory_report(&usage
);
118 simap_destroy(&usage
);
121 unixctl_server_run(unixctl
);
126 unixctl_server_wait(unixctl
);
129 poll_immediate_wake();
132 if (should_service_stop()) {
137 unixctl_server_destroy(unixctl
);
144 parse_options(int argc
, char *argv
[], char **unixctl_pathp
)
147 OPT_PEER_CA_CERT
= UCHAR_MAX
+ 1,
151 OPT_BOOTSTRAP_CA_CERT
,
157 static const struct option long_options
[] = {
158 {"help", no_argument
, NULL
, 'h'},
159 {"version", no_argument
, NULL
, 'V'},
160 {"mlockall", no_argument
, NULL
, OPT_MLOCKALL
},
161 {"unixctl", required_argument
, NULL
, OPT_UNIXCTL
},
164 STREAM_SSL_LONG_OPTIONS
,
165 {"peer-ca-cert", required_argument
, NULL
, OPT_PEER_CA_CERT
},
166 {"bootstrap-ca-cert", required_argument
, NULL
, OPT_BOOTSTRAP_CA_CERT
},
167 {"enable-dummy", optional_argument
, NULL
, OPT_ENABLE_DUMMY
},
168 {"disable-system", no_argument
, NULL
, OPT_DISABLE_SYSTEM
},
169 {"dpdk", required_argument
, NULL
, OPT_DPDK
},
172 char *short_options
= ovs_cmdl_long_options_to_short_options(long_options
);
177 c
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
);
187 ovs_print_version(0, 0);
191 want_mlockall
= true;
195 *unixctl_pathp
= optarg
;
199 DAEMON_OPTION_HANDLERS
200 STREAM_SSL_OPTION_HANDLERS
202 case OPT_PEER_CA_CERT
:
203 stream_ssl_set_peer_ca_cert_file(optarg
);
206 case OPT_BOOTSTRAP_CA_CERT
:
207 stream_ssl_set_ca_cert_file(optarg
, true);
210 case OPT_ENABLE_DUMMY
:
211 dummy_enable(optarg
);
214 case OPT_DISABLE_SYSTEM
:
215 dp_blacklist_provider("system");
222 ovs_fatal(0, "--dpdk must be given at beginning of command line.");
236 return xasprintf("unix:%s/db.sock", ovs_rundir());
239 return xstrdup(argv
[0]);
242 VLOG_FATAL("at most one non-option argument accepted; "
243 "use --help for usage");
250 printf("%s: Open vSwitch daemon\n"
251 "usage: %s [OPTIONS] [DATABASE]\n"
252 "where DATABASE is a socket on which ovsdb-server is listening\n"
253 " (default: \"unix:%s/db.sock\").\n",
254 program_name
, program_name
, ovs_rundir());
255 stream_usage("DATABASE", true, false, true);
258 printf("\nDPDK options:\n"
259 " --dpdk [VHOST] [DPDK] Initialize DPDK datapath.\n"
260 " where DPDK are options for initializing DPDK lib and VHOST is\n"
262 " option to override default character device name used for\n"
263 " for use with userspace vHost\n"
264 " -cuse_dev_name NAME\n"
266 " option to override default directory where vhost-user\n"
267 " sockets are created.\n"
268 " -vhost_sock_dir DIR\n"
271 printf("\nOther options:\n"
272 " --unixctl=SOCKET override default control socket name\n"
273 " -h, --help display this help message\n"
274 " -V, --version display version information\n");
279 ovs_vswitchd_exit(struct unixctl_conn
*conn
, int argc OVS_UNUSED
,
280 const char *argv
[] OVS_UNUSED
, void *exiting_
)
282 bool *exiting
= exiting_
;
284 unixctl_command_reply(conn
, NULL
);