1 /* Copyright (c) 2009 Nicira Networks
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.
24 #include "command-line.h"
30 #include "jsonrpc-server.h"
31 #include "leak-checker.h"
33 #include "ovsdb-error.h"
34 #include "poll-loop.h"
44 #define THIS_MODULE VLM_ovsdb_server
46 static const struct jsonrpc_server_cbs ovsdb_jsonrpc_cbs;
48 static void parse_options(int argc, char *argv[], char **file_namep,
49 struct svec *active, struct svec *passive);
50 static void usage(void) NO_RETURN;
53 main(int argc, char *argv[])
55 struct unixctl_server *unixctl;
56 struct ovsdb_jsonrpc_server *jsonrpc;
57 struct svec active, passive;
58 struct ovsdb_error *error;
65 set_program_name(argv[0]);
66 register_fault_handlers();
69 signal(SIGPIPE, SIG_IGN);
72 parse_options(argc, argv, &file_name, &active, &passive);
74 error = ovsdb_file_open(file_name, false, &db);
76 ovs_fatal(0, "%s", ovsdb_error_to_string(error));
79 jsonrpc = ovsdb_jsonrpc_server_create(db);
80 SVEC_FOR_EACH (i, name, &active) {
81 ovsdb_jsonrpc_server_connect(jsonrpc, name);
83 SVEC_FOR_EACH (i, name, &passive) {
84 retval = ovsdb_jsonrpc_server_listen(jsonrpc, name);
86 ovs_fatal(retval, "failed to listen on %s", name);
89 svec_destroy(&active);
90 svec_destroy(&passive);
92 die_if_already_running();
95 retval = unixctl_server_create(NULL, &unixctl);
97 ovs_fatal(retval, "could not listen for control connections");
101 ovsdb_jsonrpc_server_run(jsonrpc);
102 unixctl_server_run(unixctl);
103 ovsdb_trigger_run(db, time_msec());
105 ovsdb_jsonrpc_server_wait(jsonrpc);
106 unixctl_server_wait(unixctl);
107 ovsdb_trigger_wait(db, time_msec());
115 parse_options(int argc, char *argv[], char **file_namep,
116 struct svec *active, struct svec *passive)
119 OPT_DUMMY = UCHAR_MAX + 1,
123 LEAK_CHECKER_OPTION_ENUMS
125 static struct option long_options[] = {
126 {"connect", required_argument, 0, OPT_CONNECT},
127 {"listen", required_argument, 0, OPT_LISTEN},
128 {"help", no_argument, 0, 'h'},
129 {"version", no_argument, 0, 'V'},
132 LEAK_CHECKER_LONG_OPTIONS,
135 char *short_options = long_options_to_short_options(long_options);
142 c = getopt_long(argc, argv, short_options, long_options, NULL);
149 svec_add(active, optarg);
153 svec_add(passive, optarg);
160 OVS_PRINT_VERSION(0, 0);
164 DAEMON_OPTION_HANDLERS
165 LEAK_CHECKER_OPTION_HANDLERS
180 ovs_fatal(0, "database file is only non-option argument; "
181 "use --help for usage");
184 *file_namep = argv[0];
190 printf("%s: Open vSwitch database server\n"
191 "usage: %s [OPTIONS] DATABASE\n"
192 "where DATABASE is a database file in ovsdb format.\n",
193 program_name, program_name);
194 printf("\nJSON-RPC options (may be specified any number of times):\n"
195 " --connect=REMOTE make active connection to REMOTE\n"
196 " --listen=LOCAL passively listen on LOCAL\n");
197 stream_usage("JSON-RPC", true, true);
200 printf("\nOther options:\n"
201 " -h, --help display this help message\n"
202 " -V, --version display version information\n");
203 leak_checker_usage();