]> git.proxmox.com Git - ovs.git/blame - vswitchd/ovs-vswitchd.c
dpif-netdev: Add DPDK netdev.
[ovs.git] / vswitchd / ovs-vswitchd.c
CommitLineData
ecb229be 1/* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
064af421 2 *
a14bc59f
BP
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:
064af421 6 *
a14bc59f 7 * http://www.apache.org/licenses/LICENSE-2.0
064af421 8 *
a14bc59f
BP
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.
064af421
BP
14 */
15
16#include <config.h>
17
064af421
BP
18#include <errno.h>
19#include <getopt.h>
20#include <limits.h>
21#include <signal.h>
22#include <stdlib.h>
23#include <string.h>
86a06318
BP
24#ifdef HAVE_MLOCKALL
25#include <sys/mman.h>
26#endif
064af421
BP
27
28#include "bridge.h"
064af421
BP
29#include "command-line.h"
30#include "compiler.h"
31#include "daemon.h"
80df177a 32#include "dirs.h"
579a77e0 33#include "dpif.h"
614c4892 34#include "dummy.h"
8a777cf6 35#include "fatal-signal.h"
0d085684 36#include "memory.h"
8b61709d 37#include "netdev.h"
3021ea60 38#include "openflow/openflow.h"
76343538 39#include "ovsdb-idl.h"
064af421 40#include "poll-loop.h"
0d085684 41#include "simap.h"
fe55ad15 42#include "stream-ssl.h"
76343538 43#include "stream.h"
064af421
BP
44#include "svec.h"
45#include "timeval.h"
46#include "unixctl.h"
47#include "util.h"
064af421 48#include "vconn.h"
5136ce49 49#include "vlog.h"
eaa67ba8 50#include "lib/vswitch-idl.h"
8a9562d2 51#include "lib/netdev-dpdk.h"
064af421 52
d98e6007 53VLOG_DEFINE_THIS_MODULE(vswitchd);
064af421 54
908ff19a
BP
55/* --mlockall: If set, locks all process memory into physical RAM, preventing
56 * the kernel from paging any of its memory to disk. */
57static bool want_mlockall;
58
9e15c889
BP
59static unixctl_cb_func ovs_vswitchd_exit;
60
3542148e 61static char *parse_options(int argc, char *argv[], char **unixctl_path);
064af421 62static void usage(void) NO_RETURN;
064af421
BP
63
64int
65main(int argc, char *argv[])
66{
3542148e 67 char *unixctl_path = NULL;
064af421 68 struct unixctl_server *unixctl;
80df177a 69 char *remote;
c5187f17 70 bool exiting;
064af421
BP
71 int retval;
72
73 set_program_name(argv[0]);
8a9562d2
PS
74 retval = dpdk_init(argc,argv);
75 argc -= retval;
76 argv += retval;
77
78 proctitle_init(argc, argv);
42dd41ef 79 service_start(&argc, &argv);
3542148e 80 remote = parse_options(argc, argv, &unixctl_path);
8a777cf6 81 fatal_ignore_sigpipe();
bd76d25d 82 ovsrec_init();
064af421 83
95440284 84 daemonize_start();
064af421 85
908ff19a
BP
86 if (want_mlockall) {
87#ifdef HAVE_MLOCKALL
88 if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
10a89ef0 89 VLOG_ERR("mlockall failed: %s", ovs_strerror(errno));
908ff19a
BP
90 }
91#else
92 VLOG_ERR("mlockall not supported on this system");
93#endif
94 }
95
3542148e 96 retval = unixctl_server_create(unixctl_path, &unixctl);
064af421 97 if (retval) {
4d12270a 98 exit(EXIT_FAILURE);
064af421 99 }
0e15264f 100 unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting);
064af421 101
c5187f17 102 bridge_init(remote);
80df177a
BP
103 free(remote);
104
9e15c889
BP
105 exiting = false;
106 while (!exiting) {
0d085684
BP
107 memory_run();
108 if (memory_should_report()) {
109 struct simap usage;
110
111 simap_init(&usage);
112 bridge_get_memory_usage(&usage);
113 memory_report(&usage);
114 simap_destroy(&usage);
115 }
c5187f17 116 bridge_run();
064af421 117 unixctl_server_run(unixctl);
8b61709d 118 netdev_run();
064af421 119
0d085684 120 memory_wait();
c5187f17 121 bridge_wait();
064af421 122 unixctl_server_wait(unixctl);
8b61709d 123 netdev_wait();
6d37aaf1
BP
124 if (exiting) {
125 poll_immediate_wake();
126 }
064af421 127 poll_block();
42dd41ef
GS
128 if (should_service_stop()) {
129 exiting = true;
130 }
064af421 131 }
ee45ad81
BP
132 bridge_exit();
133 unixctl_server_destroy(unixctl);
42dd41ef 134 service_stop();
064af421
BP
135
136 return 0;
137}
138
80df177a 139static char *
3542148e 140parse_options(int argc, char *argv[], char **unixctl_pathp)
064af421
BP
141{
142 enum {
143 OPT_PEER_CA_CERT = UCHAR_MAX + 1,
86a06318 144 OPT_MLOCKALL,
3542148e 145 OPT_UNIXCTL,
064af421 146 VLOG_OPTION_ENUMS,
614c4892 147 OPT_BOOTSTRAP_CA_CERT,
8274ae95 148 OPT_ENABLE_DUMMY,
579a77e0 149 OPT_DISABLE_SYSTEM,
ecb229be 150 OPT_ENABLE_OF14,
8a9562d2
PS
151 DAEMON_OPTION_ENUMS,
152 OPT_DPDK,
064af421 153 };
07fc4ed3 154 static const struct option long_options[] = {
e3c17733
BP
155 {"help", no_argument, NULL, 'h'},
156 {"version", no_argument, NULL, 'V'},
157 {"mlockall", no_argument, NULL, OPT_MLOCKALL},
3542148e 158 {"unixctl", required_argument, NULL, OPT_UNIXCTL},
064af421
BP
159 DAEMON_LONG_OPTIONS,
160 VLOG_LONG_OPTIONS,
bf8f2167 161 STREAM_SSL_LONG_OPTIONS,
e3c17733
BP
162 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
163 {"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
0cbfe35d 164 {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
579a77e0 165 {"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM},
ecb229be 166 {"enable-of14", no_argument, NULL, OPT_ENABLE_OF14},
8a9562d2 167 {"dpdk", required_argument, NULL, OPT_DPDK},
e3c17733 168 {NULL, 0, NULL, 0},
064af421
BP
169 };
170 char *short_options = long_options_to_short_options(long_options);
064af421
BP
171
172 for (;;) {
173 int c;
174
175 c = getopt_long(argc, argv, short_options, long_options, NULL);
176 if (c == -1) {
177 break;
178 }
179
180 switch (c) {
064af421
BP
181 case 'h':
182 usage();
183
184 case 'V':
87ea5e5e 185 ovs_print_version(OFP10_VERSION, OFP10_VERSION);
064af421
BP
186 exit(EXIT_SUCCESS);
187
86a06318 188 case OPT_MLOCKALL:
908ff19a 189 want_mlockall = true;
86a06318
BP
190 break;
191
3542148e
AL
192 case OPT_UNIXCTL:
193 *unixctl_pathp = optarg;
194 break;
195
064af421
BP
196 VLOG_OPTION_HANDLERS
197 DAEMON_OPTION_HANDLERS
fe55ad15
BP
198 STREAM_SSL_OPTION_HANDLERS
199
064af421 200 case OPT_PEER_CA_CERT:
fe55ad15 201 stream_ssl_set_peer_ca_cert_file(optarg);
064af421 202 break;
6f61c75b
BP
203
204 case OPT_BOOTSTRAP_CA_CERT:
205 stream_ssl_set_ca_cert_file(optarg, true);
206 break;
064af421 207
614c4892 208 case OPT_ENABLE_DUMMY:
0cbfe35d 209 dummy_enable(optarg && !strcmp(optarg, "override"));
614c4892
BP
210 break;
211
579a77e0
EJ
212 case OPT_DISABLE_SYSTEM:
213 dp_blacklist_provider("system");
214 break;
215
ecb229be
BP
216 case OPT_ENABLE_OF14:
217 bridge_enable_of14();
218 break;
219
064af421
BP
220 case '?':
221 exit(EXIT_FAILURE);
222
8a9562d2
PS
223 case OPT_DPDK:
224 break;
225
064af421
BP
226 default:
227 abort();
228 }
229 }
230 free(short_options);
231
232 argc -= optind;
233 argv += optind;
234
80df177a
BP
235 switch (argc) {
236 case 0:
237 return xasprintf("unix:%s/db.sock", ovs_rundir());
238
239 case 1:
240 return xstrdup(argv[0]);
241
242 default:
243 VLOG_FATAL("at most one non-option argument accepted; "
279c9e03 244 "use --help for usage");
064af421 245 }
064af421
BP
246}
247
248static void
249usage(void)
250{
f30f26be 251 printf("%s: Open vSwitch daemon\n"
80df177a
BP
252 "usage: %s [OPTIONS] [DATABASE]\n"
253 "where DATABASE is a socket on which ovsdb-server is listening\n"
254 " (default: \"unix:%s/db.sock\").\n",
255 program_name, program_name, ovs_rundir());
9467fe62 256 stream_usage("DATABASE", true, false, true);
064af421
BP
257 daemon_usage();
258 vlog_usage();
0b8b6f71 259 printf("\nOther options:\n"
3542148e 260 " --unixctl=SOCKET override default control socket name\n"
ecb229be 261 " --enable-of14 allow enabling OF1.4 (unsafely!)\n"
064af421
BP
262 " -h, --help display this help message\n"
263 " -V, --version display version information\n");
064af421
BP
264 exit(EXIT_SUCCESS);
265}
9e15c889
BP
266
267static void
0e15264f
BP
268ovs_vswitchd_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
269 const char *argv[] OVS_UNUSED, void *exiting_)
9e15c889
BP
270{
271 bool *exiting = exiting_;
272 *exiting = true;
bde9f75d 273 unixctl_command_reply(conn, NULL);
9e15c889 274}