1 /* Copyright (c) 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.
24 #include "command-line.h"
28 #include "dynamic-string.h"
29 #include "fatal-signal.h"
30 #include "poll-loop.h"
32 #include "stream-ssl.h"
35 #include "openvswitch/vconn.h"
36 #include "openvswitch/vlog.h"
37 #include "ovn/lib/ovn-sb-idl.h"
38 #include "vtep/vtep-idl.h"
42 #include "ovn-controller-vtep.h"
44 static unixctl_cb_func ovn_controller_vtep_exit;
46 static void parse_options(int argc, char *argv[]);
47 OVS_NO_RETURN static void usage(void);
49 static char *vtep_remote;
50 static char *ovnsb_remote;
51 static char *default_db_;
54 main(int argc, char *argv[])
56 struct unixctl_server *unixctl;
60 ovs_cmdl_proctitle_init(argc, argv);
61 set_program_name(argv[0]);
62 service_start(&argc, &argv);
63 parse_options(argc, argv);
64 fatal_ignore_sigpipe();
68 retval = unixctl_server_create(NULL, &unixctl);
72 unixctl_command_register("exit", "", 0, 0, ovn_controller_vtep_exit,
80 /* Connect to VTEP database. */
81 struct ovsdb_idl_loop vtep_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
82 ovsdb_idl_create(vtep_remote, &vteprec_idl_class, true, true));
83 ovsdb_idl_get_initial_snapshot(vtep_idl_loop.idl);
85 /* Connect to OVN SB database. */
86 struct ovsdb_idl_loop ovnsb_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
87 ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
88 ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);
93 struct controller_vtep_ctx ctx = {
94 .vtep_idl = vtep_idl_loop.idl,
95 .vtep_idl_txn = ovsdb_idl_loop_run(&vtep_idl_loop),
96 .ovnsb_idl = ovnsb_idl_loop.idl,
97 .ovnsb_idl_txn = ovsdb_idl_loop_run(&ovnsb_idl_loop),
102 unixctl_server_run(unixctl);
104 unixctl_server_wait(unixctl);
106 poll_immediate_wake();
108 ovsdb_idl_loop_commit_and_wait(&vtep_idl_loop);
109 ovsdb_idl_loop_commit_and_wait(&ovnsb_idl_loop);
111 if (should_service_stop()) {
116 /* It's time to exit. Clean up the databases. */
119 struct controller_vtep_ctx ctx = {
120 .vtep_idl = vtep_idl_loop.idl,
121 .vtep_idl_txn = ovsdb_idl_loop_run(&vtep_idl_loop),
122 .ovnsb_idl = ovnsb_idl_loop.idl,
123 .ovnsb_idl_txn = ovsdb_idl_loop_run(&ovnsb_idl_loop),
126 /* Run all of the cleanup functions, even if one of them returns false.
127 * We're done if all of them return true. */
128 done = binding_cleanup(&ctx);
129 done = gateway_cleanup(&ctx) && done;
131 poll_immediate_wake();
134 ovsdb_idl_loop_commit_and_wait(&vtep_idl_loop);
135 ovsdb_idl_loop_commit_and_wait(&ovnsb_idl_loop);
139 unixctl_server_destroy(unixctl);
141 ovsdb_idl_loop_destroy(&vtep_idl_loop);
142 ovsdb_idl_loop_destroy(&ovnsb_idl_loop);
156 default_db_ = xasprintf("unix:%s/db.sock", ovs_rundir());
162 parse_options(int argc, char *argv[])
165 OPT_PEER_CA_CERT = UCHAR_MAX + 1,
170 static struct option long_options[] = {
171 {"ovnsb-db", required_argument, NULL, 'd'},
172 {"vtep-db", required_argument, NULL, 'D'},
173 {"help", no_argument, NULL, 'h'},
174 {"version", no_argument, NULL, 'V'},
177 STREAM_SSL_LONG_OPTIONS,
178 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
181 char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
186 c = getopt_long(argc, argv, short_options, long_options, NULL);
193 ovnsb_remote = xstrdup(optarg);
197 vtep_remote = xstrdup(optarg);
204 ovs_print_version(OFP13_VERSION, OFP13_VERSION);
208 DAEMON_OPTION_HANDLERS
209 STREAM_SSL_OPTION_HANDLERS
211 case OPT_PEER_CA_CERT:
212 stream_ssl_set_peer_ca_cert_file(optarg);
228 ovnsb_remote = xstrdup(default_db());
232 vtep_remote = xstrdup(default_db());
240 %s: OVN controller VTEP\n\
241 usage %s [OPTIONS]\n\
244 --vtep-db=DATABASE connect to vtep database at DATABASE\n\
246 --ovnsb-db=DATABASE connect to ovn-sb database at DATABASE\n\
248 -h, --help display this help message\n\
249 -o, --options list available options\n\
250 -V, --version display version information\n\
251 ", program_name, program_name, default_db(), default_db());
252 stream_usage("database", true, false, false);
260 ovn_controller_vtep_exit(struct unixctl_conn *conn, int argc OVS_UNUSED,
261 const char *argv[] OVS_UNUSED, void *exiting_)
263 bool *exiting = exiting_;
266 unixctl_command_reply(conn, NULL);