]> git.proxmox.com Git - ovs.git/blob - vtep/vtep-ctl.c
ovs-vsctl, vtep-ctl: Free 'args' string on exit.
[ovs.git] / vtep / vtep-ctl.c
1 /*
2 * Copyright (c) 2009, 2010, 2011, 2012, 2014, 2015, 2016, 2017 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <config.h>
18
19 #include <ctype.h>
20 #include <errno.h>
21 #include <float.h>
22 #include <getopt.h>
23 #include <inttypes.h>
24 #include <signal.h>
25 #include <stdarg.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29
30 #include "db-ctl-base.h"
31
32 #include "command-line.h"
33 #include "compiler.h"
34 #include "openvswitch/dynamic-string.h"
35 #include "fatal-signal.h"
36 #include "hash.h"
37 #include "openvswitch/json.h"
38 #include "ovsdb-data.h"
39 #include "ovsdb-idl.h"
40 #include "openvswitch/poll-loop.h"
41 #include "process.h"
42 #include "stream.h"
43 #include "stream-ssl.h"
44 #include "smap.h"
45 #include "sset.h"
46 #include "svec.h"
47 #include "vtep/vtep-idl.h"
48 #include "table.h"
49 #include "timeval.h"
50 #include "util.h"
51 #include "openvswitch/vconn.h"
52 #include "openvswitch/vlog.h"
53
54 VLOG_DEFINE_THIS_MODULE(vtep_ctl);
55
56 struct vtep_ctl_context;
57
58 /* --db: The database server to contact. */
59 static const char *db;
60
61 /* --oneline: Write each command's output as a single line? */
62 static bool oneline;
63
64 /* --dry-run: Do not commit any changes. */
65 static bool dry_run;
66
67 /* --timeout: Time to wait for a connection to 'db'. */
68 static int timeout;
69
70 /* Format for table output. */
71 static struct table_style table_style = TABLE_STYLE_DEFAULT;
72
73 /* The IDL we're using and the current transaction, if any.
74 * This is for use by vtep_ctl_exit() only, to allow it to clean up.
75 * Other code should use its context arguments. */
76 static struct ovsdb_idl *the_idl;
77 static struct ovsdb_idl_txn *the_idl_txn;
78
79 OVS_NO_RETURN static void vtep_ctl_exit(int status);
80 static void vtep_ctl_cmd_init(void);
81 OVS_NO_RETURN static void usage(void);
82 static void parse_options(int argc, char *argv[], struct shash *local_options);
83 static void run_prerequisites(struct ctl_command[], size_t n_commands,
84 struct ovsdb_idl *);
85 static bool do_vtep_ctl(const char *args, struct ctl_command *, size_t n,
86 struct ovsdb_idl *);
87 static struct vtep_ctl_lswitch *find_lswitch(struct vtep_ctl_context *,
88 const char *name,
89 bool must_exist);
90 static struct vtep_ctl_lrouter *find_lrouter(struct vtep_ctl_context *,
91 const char *name,
92 bool must_exist);
93
94 int
95 main(int argc, char *argv[])
96 {
97 struct ovsdb_idl *idl;
98 struct ctl_command *commands;
99 struct shash local_options;
100 unsigned int seqno;
101 size_t n_commands;
102 char *args;
103
104 set_program_name(argv[0]);
105 fatal_ignore_sigpipe();
106 vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
107 vlog_set_levels_from_string_assert("reconnect:warn");
108
109 vtep_ctl_cmd_init();
110
111 /* Log our arguments. This is often valuable for debugging systems. */
112 args = process_escape_args(argv);
113 VLOG(ctl_might_write_to_db(argv) ? VLL_INFO : VLL_DBG, "Called as %s", args);
114
115 /* Parse command line. */
116 shash_init(&local_options);
117 parse_options(argc, argv, &local_options);
118 commands = ctl_parse_commands(argc - optind, argv + optind, &local_options,
119 &n_commands);
120
121 if (timeout) {
122 time_alarm(timeout);
123 }
124
125 /* Initialize IDL. */
126 idl = the_idl = ovsdb_idl_create(db, &vteprec_idl_class, false, false);
127 run_prerequisites(commands, n_commands, idl);
128
129 /* Execute the commands.
130 *
131 * 'seqno' is the database sequence number for which we last tried to
132 * execute our transaction. There's no point in trying to commit more than
133 * once for any given sequence number, because if the transaction fails
134 * it's because the database changed and we need to obtain an up-to-date
135 * view of the database before we try the transaction again. */
136 seqno = ovsdb_idl_get_seqno(idl);
137 for (;;) {
138 ovsdb_idl_run(idl);
139 if (!ovsdb_idl_is_alive(idl)) {
140 int retval = ovsdb_idl_get_last_error(idl);
141 ctl_fatal("%s: database connection failed (%s)",
142 db, ovs_retval_to_string(retval));
143 }
144
145 if (seqno != ovsdb_idl_get_seqno(idl)) {
146 seqno = ovsdb_idl_get_seqno(idl);
147 if (do_vtep_ctl(args, commands, n_commands, idl)) {
148 free(args);
149 exit(EXIT_SUCCESS);
150 }
151 }
152
153 if (seqno == ovsdb_idl_get_seqno(idl)) {
154 ovsdb_idl_wait(idl);
155 poll_block();
156 }
157 }
158 }
159
160 static void
161 parse_options(int argc, char *argv[], struct shash *local_options)
162 {
163 enum {
164 OPT_DB = UCHAR_MAX + 1,
165 OPT_ONELINE,
166 OPT_NO_SYSLOG,
167 OPT_DRY_RUN,
168 OPT_PEER_CA_CERT,
169 OPT_LOCAL,
170 VLOG_OPTION_ENUMS,
171 TABLE_OPTION_ENUMS,
172 SSL_OPTION_ENUMS,
173 };
174 static const struct option global_long_options[] = {
175 {"db", required_argument, NULL, OPT_DB},
176 {"no-syslog", no_argument, NULL, OPT_NO_SYSLOG},
177 {"dry-run", no_argument, NULL, OPT_DRY_RUN},
178 {"oneline", no_argument, NULL, OPT_ONELINE},
179 {"timeout", required_argument, NULL, 't'},
180 {"help", no_argument, NULL, 'h'},
181 {"version", no_argument, NULL, 'V'},
182 VLOG_LONG_OPTIONS,
183 TABLE_LONG_OPTIONS,
184 STREAM_SSL_LONG_OPTIONS,
185 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
186 {NULL, 0, NULL, 0},
187 };
188 const int n_global_long_options = ARRAY_SIZE(global_long_options) - 1;
189 char *tmp, *short_options;
190
191 struct option *options;
192 size_t allocated_options;
193 size_t n_options;
194 size_t i;
195
196 tmp = ovs_cmdl_long_options_to_short_options(global_long_options);
197 short_options = xasprintf("+%s", tmp);
198 free(tmp);
199
200 /* We want to parse both global and command-specific options here, but
201 * getopt_long() isn't too convenient for the job. We copy our global
202 * options into a dynamic array, then append all of the command-specific
203 * options. */
204 options = xmemdup(global_long_options, sizeof global_long_options);
205 allocated_options = ARRAY_SIZE(global_long_options);
206 n_options = n_global_long_options;
207 ctl_add_cmd_options(&options, &n_options, &allocated_options, OPT_LOCAL);
208
209 for (;;) {
210 int idx;
211 int c;
212
213 c = getopt_long(argc, argv, short_options, options, &idx);
214 if (c == -1) {
215 break;
216 }
217
218 switch (c) {
219 case OPT_DB:
220 db = optarg;
221 break;
222
223 case OPT_ONELINE:
224 oneline = true;
225 break;
226
227 case OPT_NO_SYSLOG:
228 vlog_set_levels(&this_module, VLF_SYSLOG, VLL_WARN);
229 break;
230
231 case OPT_DRY_RUN:
232 dry_run = true;
233 break;
234
235 case OPT_LOCAL:
236 if (shash_find(local_options, options[idx].name)) {
237 ctl_fatal("'%s' option specified multiple times",
238 options[idx].name);
239 }
240 shash_add_nocopy(local_options,
241 xasprintf("--%s", options[idx].name),
242 nullable_xstrdup(optarg));
243 break;
244
245 case 'h':
246 usage();
247
248 case 'V':
249 ovs_print_version(0, 0);
250 printf("DB Schema %s\n", vteprec_get_db_version());
251 exit(EXIT_SUCCESS);
252
253 case 't':
254 timeout = strtoul(optarg, NULL, 10);
255 if (timeout < 0) {
256 ctl_fatal("value %s on -t or --timeout is invalid",
257 optarg);
258 }
259 break;
260
261 VLOG_OPTION_HANDLERS
262 TABLE_OPTION_HANDLERS(&table_style)
263
264 STREAM_SSL_OPTION_HANDLERS
265
266 case OPT_PEER_CA_CERT:
267 stream_ssl_set_peer_ca_cert_file(optarg);
268 break;
269
270 case '?':
271 exit(EXIT_FAILURE);
272
273 default:
274 abort();
275 }
276 }
277 free(short_options);
278
279 if (!db) {
280 db = ctl_default_db();
281 }
282
283 for (i = n_global_long_options; options[i].name; i++) {
284 free(CONST_CAST(char *, options[i].name));
285 }
286 free(options);
287 }
288
289 /* Frees the current transaction and the underlying IDL and then calls
290 * exit(status).
291 *
292 * Freeing the transaction and the IDL is not strictly necessary, but it makes
293 * for a clean memory leak report from valgrind in the normal case. That makes
294 * it easier to notice real memory leaks. */
295 static void
296 vtep_ctl_exit(int status)
297 {
298 if (the_idl_txn) {
299 ovsdb_idl_txn_abort(the_idl_txn);
300 ovsdb_idl_txn_destroy(the_idl_txn);
301 }
302 ovsdb_idl_destroy(the_idl);
303 exit(status);
304 }
305
306 static void
307 usage(void)
308 {
309 printf("\
310 %s: VTEP configuration utility\n\
311 usage: %s [OPTIONS] COMMAND [ARG...]\n\
312 \n\
313 VTEP commands:\n\
314 show print overview of database contents\n\
315 \n\
316 Manager commands:\n\
317 get-manager print the managers\n\
318 del-manager delete the managers\n\
319 set-manager TARGET... set the list of managers to TARGET...\n\
320 \n\
321 Physical Switch commands:\n\
322 add-ps PS create a new physical switch named PS\n\
323 del-ps PS delete PS and all of its ports\n\
324 list-ps print the names of all the physical switches\n\
325 ps-exists PS exit 2 if PS does not exist\n\
326 \n\
327 Port commands:\n\
328 list-ports PS print the names of all the ports on PS\n\
329 add-port PS PORT add network device PORT to PS\n\
330 del-port PS PORT delete PORT from PS\n\
331 \n\
332 Logical Switch commands:\n\
333 add-ls LS create a new logical switch named LS\n\
334 del-ls LS delete LS and all of its ports\n\
335 list-ls print the names of all the logical switches\n\
336 ls-exists LS exit 2 if LS does not exist\n\
337 bind-ls PS PORT VLAN LS bind LS to VLAN on PORT\n\
338 unbind-ls PS PORT VLAN unbind logical switch on VLAN from PORT\n\
339 list-bindings PS PORT list bindings for PORT on PS\n\
340 set-replication-mode LS MODE set replication mode on LS\n\
341 get-replication-mode LS get replication mode on LS\n\
342 \n\
343 Logical Router commands:\n\
344 add-lr LR create a new logical router named LR\n\
345 del-lr LR delete LR\n\
346 list-lr print the names of all the logical routers\n\
347 lr-exists LR exit 2 if LR does not exist\n\
348 \n\
349 MAC binding commands:\n\
350 add-ucast-local LS MAC [ENCAP] IP add ucast local entry in LS\n\
351 del-ucast-local LS MAC del ucast local entry from LS\n\
352 add-mcast-local LS MAC [ENCAP] IP add mcast local entry in LS\n\
353 del-mcast-local LS MAC [ENCAP] IP del mcast local entry from LS\n\
354 clear-local-macs LS clear local mac entries\n\
355 list-local-macs LS list local mac entries\n\
356 add-ucast-remote LS MAC [ENCAP] IP add ucast remote entry in LS\n\
357 del-ucast-remote LS MAC del ucast remote entry from LS\n\
358 add-mcast-remote LS MAC [ENCAP] IP add mcast remote entry in LS\n\
359 del-mcast-remote LS MAC [ENCAP] IP del mcast remote entry from LS\n\
360 clear-remote-macs LS clear remote mac entries\n\
361 list-remote-macs LS list remote mac entries\n\
362 \n\
363 %s\
364 \n\
365 Options:\n\
366 --db=DATABASE connect to DATABASE\n\
367 (default: %s)\n\
368 -t, --timeout=SECS wait at most SECS seconds\n\
369 --dry-run do not commit changes to database\n\
370 --oneline print exactly one line of output per command\n",
371 program_name, program_name, ctl_get_db_cmd_usage(), ctl_default_db());
372 table_usage();
373 vlog_usage();
374 printf("\
375 --no-syslog equivalent to --verbose=vtep_ctl:syslog:warn\n");
376 stream_usage("database", true, true, false);
377 printf("\n\
378 Other options:\n\
379 -h, --help display this help message\n\
380 -V, --version display version information\n");
381 exit(EXIT_SUCCESS);
382 }
383
384 \f
385 static struct cmd_show_table cmd_show_tables[] = {
386 {&vteprec_table_global,
387 NULL,
388 {&vteprec_global_col_managers,
389 &vteprec_global_col_switches,
390 NULL},
391 {NULL, NULL, NULL}
392 },
393
394 {&vteprec_table_manager,
395 &vteprec_manager_col_target,
396 {&vteprec_manager_col_is_connected,
397 NULL,
398 NULL},
399 {NULL, NULL, NULL}
400 },
401
402 {&vteprec_table_physical_switch,
403 &vteprec_physical_switch_col_name,
404 {&vteprec_physical_switch_col_management_ips,
405 &vteprec_physical_switch_col_tunnel_ips,
406 &vteprec_physical_switch_col_ports},
407 {NULL, NULL, NULL}
408 },
409
410 {&vteprec_table_physical_port,
411 &vteprec_physical_port_col_name,
412 {&vteprec_physical_port_col_vlan_bindings,
413 NULL,
414 NULL},
415 {NULL, NULL, NULL}
416 },
417
418 {&vteprec_table_logical_switch,
419 &vteprec_logical_switch_col_name,
420 {NULL,
421 NULL,
422 NULL},
423 {NULL, NULL, NULL}
424 },
425
426 {NULL, NULL, {NULL, NULL, NULL}, {NULL, NULL, NULL}}
427 };
428
429 /* vtep-ctl specific context. Inherits the 'struct ctl_context' as base. */
430 struct vtep_ctl_context {
431 struct ctl_context base;
432
433 /* Modifiable state. */
434 const struct vteprec_global *vtep_global;
435 bool verified_ports;
436
437 /* A cache of the contents of the database.
438 *
439 * A command that needs to use any of this information must first
440 * call vtep_ctl_context_populate_cache(). A command that changes
441 * anything that could invalidate the cache must either call
442 * vtep_ctl_context_invalidate_cache() or manually update the cache
443 * to maintain its correctness. */
444 bool cache_valid;
445 struct shash pswitches; /* Maps from physical switch name to
446 * struct vtep_ctl_pswitch. */
447 struct shash ports; /* Maps from port name to struct vtep_ctl_port. */
448
449 struct shash lswitches; /* Maps from logical switch name to
450 * struct vtep_ctl_lswitch. */
451 struct shash plocs; /* Maps from "<encap>+<dst_ip>" to
452 * struct vteprec_physical_locator. */
453 struct shash lrouters; /* Maps from logical router name to
454 * struct vtep_ctl_lrouter. */
455 };
456
457 /* Casts 'base' into 'struct vtep_ctl_context'. */
458 static struct vtep_ctl_context *
459 vtep_ctl_context_cast(struct ctl_context *base)
460 {
461 return CONTAINER_OF(base, struct vtep_ctl_context, base);
462 }
463
464 struct vtep_ctl_pswitch {
465 const struct vteprec_physical_switch *ps_cfg;
466 char *name;
467 struct ovs_list ports; /* Contains "struct vteprec_physical_port"s. */
468 };
469
470 struct vtep_ctl_port {
471 struct ovs_list ports_node; /* In struct vtep_ctl_pswitch's 'ports' list. */
472 const struct vteprec_physical_port *port_cfg;
473 struct vtep_ctl_pswitch *ps;
474 struct shash bindings; /* Maps from vlan to vtep_ctl_lswitch. */
475 };
476
477 struct vtep_ctl_lswitch {
478 const struct vteprec_logical_switch *ls_cfg;
479 char *name;
480 struct shash ucast_local; /* Maps from mac to vteprec_ucast_macs_local. */
481 struct shash ucast_remote; /* Maps from mac to vteprec_ucast_macs_remote.*/
482 struct shash mcast_local; /* Maps from mac to vtep_ctl_mcast_mac. */
483 struct shash mcast_remote; /* Maps from mac to vtep_ctl_mcast_mac. */
484 };
485
486 struct vtep_ctl_lrouter {
487 const struct vteprec_logical_router *lr_cfg;
488 char *name;
489 };
490
491 struct vtep_ctl_mcast_mac {
492 const struct vteprec_mcast_macs_local *local_cfg;
493 const struct vteprec_mcast_macs_remote *remote_cfg;
494
495 const struct vteprec_physical_locator_set *ploc_set_cfg;
496 struct ovs_list locators; /* Contains 'vtep_ctl_ploc's. */
497 };
498
499 struct vtep_ctl_ploc {
500 struct ovs_list locators_node; /* In struct vtep_ctl_ploc_set's 'locators'
501 list. */
502 const struct vteprec_physical_locator *ploc_cfg;
503 };
504
505 static void
506 verify_ports(struct vtep_ctl_context *vtepctl_ctx)
507 {
508 if (!vtepctl_ctx->verified_ports) {
509 const struct vteprec_physical_switch *ps;
510
511 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
512 VTEPREC_PHYSICAL_SWITCH_FOR_EACH (ps, vtepctl_ctx->base.idl) {
513 vteprec_physical_switch_verify_ports(ps);
514 }
515
516 vtepctl_ctx->verified_ports = true;
517 }
518 }
519
520 static struct vtep_ctl_port *
521 add_port_to_cache(struct vtep_ctl_context *vtepctl_ctx,
522 struct vtep_ctl_pswitch *ps,
523 struct vteprec_physical_port *port_cfg)
524 {
525 char *cache_name = xasprintf("%s+%s", ps->name, port_cfg->name);
526 struct vtep_ctl_port *port;
527
528 port = xmalloc(sizeof *port);
529 ovs_list_push_back(&ps->ports, &port->ports_node);
530 port->port_cfg = port_cfg;
531 port->ps = ps;
532 shash_add(&vtepctl_ctx->ports, cache_name, port);
533 free(cache_name);
534 shash_init(&port->bindings);
535
536 return port;
537 }
538
539 static void
540 del_cached_port(struct vtep_ctl_context *vtepctl_ctx,
541 struct vtep_ctl_port *port)
542 {
543 char *cache_name = xasprintf("%s+%s", port->ps->name, port->port_cfg->name);
544
545 ovs_list_remove(&port->ports_node);
546 shash_find_and_delete(&vtepctl_ctx->ports, cache_name);
547 vteprec_physical_port_delete(port->port_cfg);
548 shash_destroy(&port->bindings);
549 free(cache_name);
550 free(port);
551 }
552
553 static void
554 add_pswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
555 struct vteprec_physical_switch *ps_cfg)
556 {
557 struct vtep_ctl_pswitch *ps = xmalloc(sizeof *ps);
558 ps->ps_cfg = ps_cfg;
559 ps->name = xstrdup(ps_cfg->name);
560 ovs_list_init(&ps->ports);
561 shash_add(&vtepctl_ctx->pswitches, ps->name, ps);
562 }
563
564 static void
565 vtep_delete_pswitch(const struct vteprec_global *vtep_global,
566 const struct vteprec_physical_switch *ps)
567 {
568 struct vteprec_physical_switch **pswitches;
569 size_t i, n;
570
571 pswitches = xmalloc(sizeof *vtep_global->switches
572 * vtep_global->n_switches);
573 for (i = n = 0; i < vtep_global->n_switches; i++) {
574 if (vtep_global->switches[i] != ps) {
575 pswitches[n++] = vtep_global->switches[i];
576 }
577 }
578 vteprec_global_set_switches(vtep_global, pswitches, n);
579 free(pswitches);
580 }
581
582 static void
583 del_cached_pswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_pswitch *ps)
584 {
585 ovs_assert(ovs_list_is_empty(&ps->ports));
586 if (ps->ps_cfg) {
587 vteprec_physical_switch_delete(ps->ps_cfg);
588 vtep_delete_pswitch(ctx->vtep_global, ps->ps_cfg);
589 }
590 shash_find_and_delete(&ctx->pswitches, ps->name);
591 free(ps->name);
592 free(ps);
593 }
594
595 static struct vtep_ctl_lswitch *
596 add_lswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
597 const struct vteprec_logical_switch *ls_cfg)
598 {
599 struct vtep_ctl_lswitch *ls = xmalloc(sizeof *ls);
600 ls->ls_cfg = ls_cfg;
601 ls->name = xstrdup(ls_cfg->name);
602 shash_add(&vtepctl_ctx->lswitches, ls->name, ls);
603 shash_init(&ls->ucast_local);
604 shash_init(&ls->ucast_remote);
605 shash_init(&ls->mcast_local);
606 shash_init(&ls->mcast_remote);
607 return ls;
608 }
609
610 static void
611 del_cached_lswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_lswitch *ls)
612 {
613 if (ls->ls_cfg) {
614 vteprec_logical_switch_delete(ls->ls_cfg);
615 }
616 shash_find_and_delete(&ctx->lswitches, ls->name);
617 free(ls->name);
618 free(ls);
619 }
620
621 static void
622 commit_ls_bindings(struct vtep_ctl_port *port)
623 {
624 struct vteprec_logical_switch **binding_values;
625 int64_t *binding_keys;
626 size_t n_bindings;
627 struct shash_node *node;
628 int i;
629
630 n_bindings = shash_count(&port->bindings);
631 binding_keys = xmalloc(n_bindings * sizeof *binding_keys);
632 binding_values = xmalloc(n_bindings * sizeof *binding_values);
633
634 i = 0;
635 SHASH_FOR_EACH(node, &port->bindings) {
636 struct vtep_ctl_lswitch *ls_entry = node->data;
637
638 binding_keys[i] = strtoll(node->name, NULL, 0);
639 binding_values[i] = (struct vteprec_logical_switch *)ls_entry->ls_cfg;
640 i++;
641 }
642
643 vteprec_physical_port_set_vlan_bindings(port->port_cfg,
644 binding_keys, binding_values,
645 n_bindings);
646 free(binding_values);
647 free(binding_keys);
648 }
649
650 static void
651 add_ls_binding_to_cache(struct vtep_ctl_port *port,
652 const char *vlan,
653 struct vtep_ctl_lswitch *ls)
654 {
655 if (shash_find(&port->bindings, vlan)) {
656 ctl_fatal("multiple bindings for vlan %s", vlan);
657 }
658
659 shash_add(&port->bindings, vlan, ls);
660 }
661
662 static void
663 del_cached_ls_binding(struct vtep_ctl_port *port, const char *vlan)
664 {
665 if (!shash_find(&port->bindings, vlan)) {
666 ctl_fatal("no binding for vlan %s", vlan);
667 }
668
669 shash_find_and_delete(&port->bindings, vlan);
670 }
671
672 static struct vtep_ctl_lrouter *
673 add_lrouter_to_cache(struct vtep_ctl_context *vtepctl_ctx,
674 const struct vteprec_logical_router *lr_cfg)
675 {
676 struct vtep_ctl_lrouter *lr = xmalloc(sizeof *lr);
677 lr->lr_cfg = lr_cfg;
678 lr->name = xstrdup(lr_cfg->name);
679 shash_add(&vtepctl_ctx->lrouters, lr->name, lr);
680 return lr;
681 }
682
683 static void
684 del_cached_lrouter(struct vtep_ctl_context *ctx, struct vtep_ctl_lrouter *lr)
685 {
686 if (lr->lr_cfg) {
687 vteprec_logical_router_delete(lr->lr_cfg);
688 }
689 shash_find_and_delete(&ctx->lrouters, lr->name);
690 free(lr->name);
691 free(lr);
692 }
693
694 static struct vteprec_physical_locator *
695 find_ploc(struct vtep_ctl_context *vtepctl_ctx, const char *encap,
696 const char *dst_ip)
697 {
698 struct vteprec_physical_locator *ploc;
699 char *name = xasprintf("%s+%s", encap, dst_ip);
700
701 ovs_assert(vtepctl_ctx->cache_valid);
702
703 ploc = shash_find_data(&vtepctl_ctx->plocs, name);
704 free(name);
705
706 return ploc;
707 }
708
709 static void
710 add_ploc_to_cache(struct vtep_ctl_context *vtepctl_ctx,
711 struct vteprec_physical_locator *ploc)
712 {
713 char *name = xasprintf("%s+%s", ploc->encapsulation_type, ploc->dst_ip);
714 struct vteprec_physical_locator *orig_ploc;
715
716 orig_ploc = find_ploc(vtepctl_ctx, ploc->encapsulation_type, ploc->dst_ip);
717 if (!orig_ploc) {
718 shash_add(&vtepctl_ctx->plocs, name, ploc);
719 }
720
721 free(name);
722 }
723
724 static void
725 add_ploc_to_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
726 struct vteprec_physical_locator *ploc_cfg)
727 {
728 struct vtep_ctl_ploc *ploc;
729
730 ploc = xmalloc(sizeof *ploc);
731 ploc->ploc_cfg = ploc_cfg;
732 ovs_list_push_back(&mcast_mac->locators, &ploc->locators_node);
733 }
734
735 static void
736 del_ploc_from_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
737 struct vteprec_physical_locator *ploc_cfg)
738 {
739 struct vtep_ctl_ploc *ploc;
740
741 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
742 if (ploc->ploc_cfg == ploc_cfg) {
743 ovs_list_remove(&ploc->locators_node);
744 free(ploc);
745 return;
746 }
747 }
748 }
749
750 static struct vtep_ctl_mcast_mac *
751 add_mcast_mac_to_cache(struct vtep_ctl_context *vtepctl_ctx,
752 struct vtep_ctl_lswitch *ls, const char *mac,
753 struct vteprec_physical_locator_set *ploc_set_cfg,
754 bool local)
755 {
756 struct vtep_ctl_mcast_mac *mcast_mac;
757 struct shash *mcast_shash;
758 size_t i;
759
760 mcast_mac = xmalloc(sizeof *mcast_mac);
761 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
762
763 mcast_mac->ploc_set_cfg = ploc_set_cfg;
764 ovs_list_init(&mcast_mac->locators);
765 shash_add(mcast_shash, mac, mcast_mac);
766
767 for (i = 0; i < ploc_set_cfg->n_locators; i++) {
768 struct vteprec_physical_locator *ploc_cfg;
769
770 ploc_cfg = ploc_set_cfg->locators[i];
771 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
772 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
773 }
774
775 return mcast_mac;
776 }
777
778 static void
779 vtep_ctl_context_invalidate_cache(struct ctl_context *ctx)
780 {
781 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
782 struct shash_node *node;
783
784 if (!vtepctl_ctx->cache_valid) {
785 return;
786 }
787 vtepctl_ctx->cache_valid = false;
788
789 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
790 struct vtep_ctl_pswitch *ps = node->data;
791 free(ps->name);
792 free(ps);
793 }
794 shash_destroy(&vtepctl_ctx->pswitches);
795
796 SHASH_FOR_EACH (node, &vtepctl_ctx->ports) {
797 struct vtep_ctl_port *port = node->data;
798 shash_destroy(&port->bindings);
799 }
800 shash_destroy_free_data(&vtepctl_ctx->ports);
801
802 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
803 struct vtep_ctl_lswitch *ls = node->data;
804 struct shash_node *node2, *next_node2;
805
806 shash_destroy(&ls->ucast_local);
807 shash_destroy(&ls->ucast_remote);
808
809 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_local) {
810 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
811 struct vtep_ctl_ploc *ploc, *next_ploc;
812
813 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
814 &mcast_mac->locators) {
815 free(ploc);
816 }
817 free(mcast_mac);
818 }
819 shash_destroy(&ls->mcast_local);
820
821 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_remote) {
822 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
823 struct vtep_ctl_ploc *ploc, *next_ploc;
824
825 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
826 &mcast_mac->locators) {
827 free(ploc);
828 }
829 free(mcast_mac);
830 }
831 shash_destroy(&ls->mcast_remote);
832
833 free(ls->name);
834 free(ls);
835 }
836 shash_destroy(&vtepctl_ctx->lswitches);
837 shash_destroy(&vtepctl_ctx->plocs);
838
839 SHASH_FOR_EACH (node, &vtepctl_ctx->lrouters) {
840 struct vtep_ctl_lrouter *lr = node->data;
841 free(lr->name);
842 free(lr);
843 }
844 shash_destroy(&vtepctl_ctx->lrouters);
845 }
846
847 static void
848 pre_get_info(struct ctl_context *ctx)
849 {
850 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_switches);
851
852 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_name);
853 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_ports);
854 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_tunnels);
855
856 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_name);
857 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_vlan_bindings);
858
859 ovsdb_idl_add_column(ctx->idl, &vteprec_logical_switch_col_name);
860 ovsdb_idl_add_column(ctx->idl,
861 &vteprec_logical_switch_col_replication_mode);
862
863 ovsdb_idl_add_column(ctx->idl, &vteprec_logical_router_col_name);
864
865 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_MAC);
866 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_locator);
867 ovsdb_idl_add_column(ctx->idl,
868 &vteprec_ucast_macs_local_col_logical_switch);
869
870 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_MAC);
871 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_locator);
872 ovsdb_idl_add_column(ctx->idl,
873 &vteprec_ucast_macs_remote_col_logical_switch);
874
875 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_local_col_MAC);
876 ovsdb_idl_add_column(ctx->idl,
877 &vteprec_mcast_macs_local_col_locator_set);
878 ovsdb_idl_add_column(ctx->idl,
879 &vteprec_mcast_macs_local_col_logical_switch);
880
881 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_remote_col_MAC);
882 ovsdb_idl_add_column(ctx->idl,
883 &vteprec_mcast_macs_remote_col_locator_set);
884 ovsdb_idl_add_column(ctx->idl,
885 &vteprec_mcast_macs_remote_col_logical_switch);
886
887 ovsdb_idl_add_column(ctx->idl,
888 &vteprec_physical_locator_set_col_locators);
889
890 ovsdb_idl_add_column(ctx->idl,
891 &vteprec_physical_locator_col_dst_ip);
892 ovsdb_idl_add_column(ctx->idl,
893 &vteprec_physical_locator_col_encapsulation_type);
894
895 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_local);
896 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_remote);
897 }
898
899 static void
900 vtep_ctl_context_populate_cache(struct ctl_context *ctx)
901 {
902 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
903 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
904 const struct vteprec_logical_switch *ls_cfg;
905 const struct vteprec_logical_router *lr_cfg;
906 const struct vteprec_ucast_macs_local *ucast_local_cfg;
907 const struct vteprec_ucast_macs_remote *ucast_remote_cfg;
908 const struct vteprec_mcast_macs_local *mcast_local_cfg;
909 const struct vteprec_mcast_macs_remote *mcast_remote_cfg;
910 const struct vteprec_tunnel *tunnel_cfg;
911 struct sset pswitches, ports, lswitches;
912 struct sset lrouters;
913 size_t i;
914
915 if (vtepctl_ctx->cache_valid) {
916 /* Cache is already populated. */
917 return;
918 }
919 vtepctl_ctx->cache_valid = true;
920 shash_init(&vtepctl_ctx->pswitches);
921 shash_init(&vtepctl_ctx->ports);
922 shash_init(&vtepctl_ctx->lswitches);
923 shash_init(&vtepctl_ctx->plocs);
924 shash_init(&vtepctl_ctx->lrouters);
925
926 sset_init(&pswitches);
927 sset_init(&ports);
928 for (i = 0; i < vtep_global->n_switches; i++) {
929 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
930 size_t j;
931
932 if (!sset_add(&pswitches, ps_cfg->name)) {
933 VLOG_WARN("%s: database contains duplicate physical switch name",
934 ps_cfg->name);
935 continue;
936 }
937 add_pswitch_to_cache(vtepctl_ctx, ps_cfg);
938
939 for (j = 0; j < ps_cfg->n_ports; j++) {
940 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
941
942 if (!sset_add(&ports, port_cfg->name)) {
943 /* Duplicate port name. (We will warn about that later.) */
944 continue;
945 }
946 }
947 }
948 sset_destroy(&pswitches);
949 sset_destroy(&ports);
950
951 sset_init(&lswitches);
952 VTEPREC_LOGICAL_SWITCH_FOR_EACH (ls_cfg, ctx->idl) {
953 if (!sset_add(&lswitches, ls_cfg->name)) {
954 VLOG_WARN("%s: database contains duplicate logical switch name",
955 ls_cfg->name);
956 continue;
957 }
958 add_lswitch_to_cache(vtepctl_ctx, ls_cfg);
959 }
960 sset_destroy(&lswitches);
961
962 sset_init(&lrouters);
963 VTEPREC_LOGICAL_ROUTER_FOR_EACH (lr_cfg, ctx->idl) {
964 if (!sset_add(&lrouters, lr_cfg->name)) {
965 VLOG_WARN("%s: database contains duplicate logical router name",
966 lr_cfg->name);
967 continue;
968 }
969 add_lrouter_to_cache(vtepctl_ctx, lr_cfg);
970 }
971 sset_destroy(&lrouters);
972
973 VTEPREC_UCAST_MACS_LOCAL_FOR_EACH (ucast_local_cfg, ctx->idl) {
974 struct vtep_ctl_lswitch *ls;
975
976 if (!ucast_local_cfg->logical_switch) {
977 continue;
978 }
979 ls = find_lswitch(vtepctl_ctx, ucast_local_cfg->logical_switch->name,
980 false);
981 if (!ls) {
982 continue;
983 }
984
985 if (ucast_local_cfg->locator) {
986 add_ploc_to_cache(vtepctl_ctx, ucast_local_cfg->locator);
987 }
988
989 shash_add(&ls->ucast_local, ucast_local_cfg->MAC, ucast_local_cfg);
990 }
991
992 VTEPREC_UCAST_MACS_REMOTE_FOR_EACH (ucast_remote_cfg, ctx->idl) {
993 struct vtep_ctl_lswitch *ls;
994
995 if (!ucast_remote_cfg->logical_switch) {
996 continue;
997 }
998 ls = find_lswitch(vtepctl_ctx, ucast_remote_cfg->logical_switch->name,
999 false);
1000 if (!ls) {
1001 continue;
1002 }
1003
1004 if (ucast_remote_cfg->locator) {
1005 add_ploc_to_cache(vtepctl_ctx, ucast_remote_cfg->locator);
1006 }
1007
1008 shash_add(&ls->ucast_remote, ucast_remote_cfg->MAC, ucast_remote_cfg);
1009 }
1010
1011 VTEPREC_MCAST_MACS_LOCAL_FOR_EACH (mcast_local_cfg, ctx->idl) {
1012 struct vtep_ctl_mcast_mac *mcast_mac;
1013 struct vtep_ctl_lswitch *ls;
1014
1015 if (!mcast_local_cfg->logical_switch) {
1016 continue;
1017 }
1018 ls = find_lswitch(vtepctl_ctx, mcast_local_cfg->logical_switch->name,
1019 false);
1020 if (!ls) {
1021 continue;
1022 }
1023
1024 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_local_cfg->MAC,
1025 mcast_local_cfg->locator_set,
1026 true);
1027 mcast_mac->local_cfg = mcast_local_cfg;
1028 }
1029
1030 VTEPREC_MCAST_MACS_REMOTE_FOR_EACH (mcast_remote_cfg, ctx->idl) {
1031 struct vtep_ctl_mcast_mac *mcast_mac;
1032 struct vtep_ctl_lswitch *ls;
1033
1034 if (!mcast_remote_cfg->logical_switch) {
1035 continue;
1036 }
1037 ls = find_lswitch(vtepctl_ctx, mcast_remote_cfg->logical_switch->name,
1038 false);
1039 if (!ls) {
1040 continue;
1041 }
1042
1043 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_remote_cfg->MAC,
1044 mcast_remote_cfg->locator_set,
1045 false);
1046 mcast_mac->remote_cfg = mcast_remote_cfg;
1047 }
1048
1049 VTEPREC_TUNNEL_FOR_EACH (tunnel_cfg, ctx->idl) {
1050 if (tunnel_cfg->local) {
1051 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->local);
1052 }
1053 if (tunnel_cfg->remote) {
1054 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->remote);
1055 }
1056 }
1057
1058 sset_init(&pswitches);
1059 for (i = 0; i < vtep_global->n_switches; i++) {
1060 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
1061 struct vtep_ctl_pswitch *ps;
1062 size_t j;
1063
1064 if (!sset_add(&pswitches, ps_cfg->name)) {
1065 continue;
1066 }
1067 ps = shash_find_data(&vtepctl_ctx->pswitches, ps_cfg->name);
1068 for (j = 0; j < ps_cfg->n_ports; j++) {
1069 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
1070 struct vtep_ctl_port *port;
1071 size_t k;
1072
1073 port = shash_find_data(&vtepctl_ctx->ports, port_cfg->name);
1074 if (port) {
1075 if (port_cfg == port->port_cfg) {
1076 VLOG_WARN("%s: port is in multiple physical switches "
1077 "(%s and %s)",
1078 port_cfg->name, ps->name, port->ps->name);
1079 } else {
1080 /* Log as an error because this violates the database's
1081 * uniqueness constraints, so the database server shouldn't
1082 * have allowed it. */
1083 VLOG_ERR("%s: database contains duplicate port name",
1084 port_cfg->name);
1085 }
1086 continue;
1087 }
1088
1089 port = add_port_to_cache(vtepctl_ctx, ps, port_cfg);
1090
1091 for (k = 0; k < port_cfg->n_vlan_bindings; k++) {
1092 struct vtep_ctl_lswitch *ls;
1093 char *vlan;
1094
1095 vlan = xasprintf("%"PRId64, port_cfg->key_vlan_bindings[k]);
1096 if (shash_find(&port->bindings, vlan)) {
1097 ctl_fatal("multiple bindings for vlan %s", vlan);
1098 }
1099
1100 ls_cfg = port_cfg->value_vlan_bindings[k];
1101 ls = find_lswitch(vtepctl_ctx, ls_cfg->name, true);
1102
1103 shash_add_nocopy(&port->bindings, vlan, ls);
1104 }
1105 }
1106 }
1107 sset_destroy(&pswitches);
1108 }
1109
1110 static struct vtep_ctl_pswitch *
1111 find_pswitch(struct vtep_ctl_context *vtepctl_ctx, const char *name, bool must_exist)
1112 {
1113 struct vtep_ctl_pswitch *ps;
1114
1115 ovs_assert(vtepctl_ctx->cache_valid);
1116
1117 ps = shash_find_data(&vtepctl_ctx->pswitches, name);
1118 if (must_exist && !ps) {
1119 ctl_fatal("no physical switch named %s", name);
1120 }
1121 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
1122 return ps;
1123 }
1124
1125 static struct vtep_ctl_port *
1126 find_port(struct vtep_ctl_context *vtepctl_ctx, const char *ps_name,
1127 const char *port_name, bool must_exist)
1128 {
1129 char *cache_name = xasprintf("%s+%s", ps_name, port_name);
1130 struct vtep_ctl_port *port;
1131
1132 ovs_assert(vtepctl_ctx->cache_valid);
1133
1134 port = shash_find_data(&vtepctl_ctx->ports, cache_name);
1135 if (port && !strcmp(port_name, port->ps->name)) {
1136 port = NULL;
1137 }
1138 free(cache_name);
1139 if (must_exist && !port) {
1140 ctl_fatal("no port named %s", port_name);
1141 }
1142 verify_ports(vtepctl_ctx);
1143 return port;
1144 }
1145
1146 static void
1147 pswitch_insert_port(const struct vteprec_physical_switch *ps,
1148 struct vteprec_physical_port *port)
1149 {
1150 struct vteprec_physical_port **ports;
1151 size_t i;
1152
1153 ports = xmalloc(sizeof *ps->ports * (ps->n_ports + 1));
1154 for (i = 0; i < ps->n_ports; i++) {
1155 ports[i] = ps->ports[i];
1156 }
1157 ports[ps->n_ports] = port;
1158 vteprec_physical_switch_set_ports(ps, ports, ps->n_ports + 1);
1159 free(ports);
1160 }
1161
1162 static void
1163 pswitch_delete_port(const struct vteprec_physical_switch *ps,
1164 const struct vteprec_physical_port *port)
1165 {
1166 struct vteprec_physical_port **ports;
1167 size_t i, n;
1168
1169 ports = xmalloc(sizeof *ps->ports * ps->n_ports);
1170 for (i = n = 0; i < ps->n_ports; i++) {
1171 if (ps->ports[i] != port) {
1172 ports[n++] = ps->ports[i];
1173 }
1174 }
1175 vteprec_physical_switch_set_ports(ps, ports, n);
1176 free(ports);
1177 }
1178
1179 static void
1180 vtep_insert_pswitch(const struct vteprec_global *vtep_global,
1181 struct vteprec_physical_switch *ps)
1182 {
1183 struct vteprec_physical_switch **pswitches;
1184 size_t i;
1185
1186 pswitches = xmalloc(sizeof *vtep_global->switches
1187 * (vtep_global->n_switches + 1));
1188 for (i = 0; i < vtep_global->n_switches; i++) {
1189 pswitches[i] = vtep_global->switches[i];
1190 }
1191 pswitches[vtep_global->n_switches] = ps;
1192 vteprec_global_set_switches(vtep_global, pswitches,
1193 vtep_global->n_switches + 1);
1194 free(pswitches);
1195 }
1196
1197 static void
1198 cmd_add_ps(struct ctl_context *ctx)
1199 {
1200 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1201 const char *ps_name = ctx->argv[1];
1202 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1203 struct vteprec_physical_switch *ps;
1204
1205 vtep_ctl_context_populate_cache(ctx);
1206 if (find_pswitch(vtepctl_ctx, ps_name, false)) {
1207 if (!may_exist) {
1208 ctl_fatal("cannot create physical switch %s because it "
1209 "already exists", ps_name);
1210 }
1211 return;
1212 }
1213
1214 ps = vteprec_physical_switch_insert(ctx->txn);
1215 vteprec_physical_switch_set_name(ps, ps_name);
1216
1217 vtep_insert_pswitch(vtepctl_ctx->vtep_global, ps);
1218
1219 vtep_ctl_context_invalidate_cache(ctx);
1220 }
1221
1222 static void
1223 del_port(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_port *port)
1224 {
1225 pswitch_delete_port(port->ps->ps_cfg, port->port_cfg);
1226 del_cached_port(vtepctl_ctx, port);
1227 }
1228
1229 static void
1230 del_pswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_pswitch *ps)
1231 {
1232 struct vtep_ctl_port *port, *next_port;
1233
1234 LIST_FOR_EACH_SAFE (port, next_port, ports_node, &ps->ports) {
1235 del_port(vtepctl_ctx, port);
1236 }
1237
1238 del_cached_pswitch(vtepctl_ctx, ps);
1239 }
1240
1241 static void
1242 cmd_del_ps(struct ctl_context *ctx)
1243 {
1244 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1245 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1246 struct vtep_ctl_pswitch *ps;
1247
1248 vtep_ctl_context_populate_cache(ctx);
1249 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1250 if (ps) {
1251 del_pswitch(vtepctl_ctx, ps);
1252 }
1253 }
1254
1255 static void
1256 output_sorted(struct svec *svec, struct ds *output)
1257 {
1258 const char *name;
1259 size_t i;
1260
1261 svec_sort(svec);
1262 SVEC_FOR_EACH (i, name, svec) {
1263 ds_put_format(output, "%s\n", name);
1264 }
1265 }
1266
1267 static void
1268 cmd_list_ps(struct ctl_context *ctx)
1269 {
1270 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1271 struct shash_node *node;
1272 struct svec pswitches;
1273
1274 vtep_ctl_context_populate_cache(ctx);
1275
1276 svec_init(&pswitches);
1277 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
1278 struct vtep_ctl_pswitch *ps = node->data;
1279
1280 svec_add(&pswitches, ps->name);
1281 }
1282 output_sorted(&pswitches, &ctx->output);
1283 svec_destroy(&pswitches);
1284 }
1285
1286 static void
1287 cmd_ps_exists(struct ctl_context *ctx)
1288 {
1289 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1290
1291 vtep_ctl_context_populate_cache(ctx);
1292 if (!find_pswitch(vtepctl_ctx, ctx->argv[1], false)) {
1293 vtep_ctl_exit(2);
1294 }
1295 }
1296
1297 static void
1298 cmd_list_ports(struct ctl_context *ctx)
1299 {
1300 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1301 struct vtep_ctl_pswitch *ps;
1302 struct vtep_ctl_port *port;
1303 struct svec ports;
1304
1305 vtep_ctl_context_populate_cache(ctx);
1306 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1307 vteprec_physical_switch_verify_ports(ps->ps_cfg);
1308
1309 svec_init(&ports);
1310 LIST_FOR_EACH (port, ports_node, &ps->ports) {
1311 if (strcmp(port->port_cfg->name, ps->name)) {
1312 svec_add(&ports, port->port_cfg->name);
1313 }
1314 }
1315 output_sorted(&ports, &ctx->output);
1316 svec_destroy(&ports);
1317 }
1318
1319 static void
1320 add_port(struct ctl_context *ctx, const char *ps_name,
1321 const char *port_name, bool may_exist)
1322 {
1323 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1324 struct vtep_ctl_port *vtep_ctl_port;
1325 struct vtep_ctl_pswitch *ps;
1326 struct vteprec_physical_port *port;
1327
1328 vtep_ctl_context_populate_cache(ctx);
1329
1330 vtep_ctl_port = find_port(vtepctl_ctx, ps_name, port_name, false);
1331 if (vtep_ctl_port) {
1332 if (!may_exist) {
1333 ctl_fatal("cannot create a port named %s on %s because a "
1334 "port with that name already exists",
1335 port_name, ps_name);
1336 }
1337 return;
1338 }
1339
1340 ps = find_pswitch(vtepctl_ctx, ps_name, true);
1341
1342 port = vteprec_physical_port_insert(ctx->txn);
1343 vteprec_physical_port_set_name(port, port_name);
1344
1345 pswitch_insert_port(ps->ps_cfg, port);
1346
1347 add_port_to_cache(vtepctl_ctx, ps, port);
1348 }
1349
1350 static void
1351 cmd_add_port(struct ctl_context *ctx)
1352 {
1353 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1354
1355 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist);
1356 }
1357
1358 static void
1359 cmd_del_port(struct ctl_context *ctx)
1360 {
1361 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1362 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1363 struct vtep_ctl_port *port;
1364
1365 vtep_ctl_context_populate_cache(ctx);
1366
1367 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], must_exist);
1368 if (port) {
1369 if (ctx->argc == 3) {
1370 struct vtep_ctl_pswitch *ps;
1371
1372 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1373 if (port->ps != ps) {
1374 ctl_fatal("physical switch %s does not have a port %s",
1375 ctx->argv[1], ctx->argv[2]);
1376 }
1377 }
1378
1379 del_port(vtepctl_ctx, port);
1380 }
1381 }
1382
1383 static struct vtep_ctl_lswitch *
1384 find_lswitch(struct vtep_ctl_context *vtepctl_ctx,
1385 const char *name, bool must_exist)
1386 {
1387 struct vtep_ctl_lswitch *ls;
1388
1389 ovs_assert(vtepctl_ctx->cache_valid);
1390
1391 ls = shash_find_data(&vtepctl_ctx->lswitches, name);
1392 if (must_exist && !ls) {
1393 ctl_fatal("no logical switch named %s", name);
1394 }
1395 return ls;
1396 }
1397
1398 static void
1399 cmd_add_ls(struct ctl_context *ctx)
1400 {
1401 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1402 const char *ls_name = ctx->argv[1];
1403 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1404 struct vteprec_logical_switch *ls;
1405
1406 vtep_ctl_context_populate_cache(ctx);
1407 if (find_lswitch(vtepctl_ctx, ls_name, false)) {
1408 if (!may_exist) {
1409 ctl_fatal("cannot create logical switch %s because it "
1410 "already exists", ls_name);
1411 }
1412 return;
1413 }
1414
1415 ls = vteprec_logical_switch_insert(ctx->txn);
1416 vteprec_logical_switch_set_name(ls, ls_name);
1417
1418 vtep_ctl_context_invalidate_cache(ctx);
1419 }
1420
1421 static void
1422 del_lswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_lswitch *ls)
1423 {
1424 del_cached_lswitch(vtepctl_ctx, ls);
1425 }
1426
1427 static void
1428 cmd_del_ls(struct ctl_context *ctx)
1429 {
1430 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1431 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1432 struct vtep_ctl_lswitch *ls;
1433
1434 vtep_ctl_context_populate_cache(ctx);
1435 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1436 if (ls) {
1437 del_lswitch(vtepctl_ctx, ls);
1438 }
1439 }
1440
1441 static void
1442 cmd_list_ls(struct ctl_context *ctx)
1443 {
1444 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1445 struct shash_node *node;
1446 struct svec lswitches;
1447
1448 vtep_ctl_context_populate_cache(ctx);
1449
1450 svec_init(&lswitches);
1451 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
1452 struct vtep_ctl_lswitch *ls = node->data;
1453
1454 svec_add(&lswitches, ls->name);
1455 }
1456 output_sorted(&lswitches, &ctx->output);
1457 svec_destroy(&lswitches);
1458 }
1459
1460 static void
1461 cmd_ls_exists(struct ctl_context *ctx)
1462 {
1463 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1464
1465 vtep_ctl_context_populate_cache(ctx);
1466 if (!find_lswitch(vtepctl_ctx, ctx->argv[1], false)) {
1467 vtep_ctl_exit(2);
1468 }
1469 }
1470
1471 static void
1472 cmd_list_bindings(struct ctl_context *ctx)
1473 {
1474 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1475 const struct shash_node *node;
1476 struct vtep_ctl_port *port;
1477 struct svec bindings;
1478
1479 vtep_ctl_context_populate_cache(ctx);
1480 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1481
1482 svec_init(&bindings);
1483 SHASH_FOR_EACH (node, &port->bindings) {
1484 struct vtep_ctl_lswitch *lswitch = node->data;
1485 char *binding;
1486
1487 binding = xasprintf("%04lld %s", strtoll(node->name, NULL, 0),
1488 lswitch->name);
1489 svec_add_nocopy(&bindings, binding);
1490 }
1491 output_sorted(&bindings, &ctx->output);
1492 svec_destroy(&bindings);
1493 }
1494
1495 static void
1496 cmd_bind_ls(struct ctl_context *ctx)
1497 {
1498 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1499 struct vtep_ctl_lswitch *ls;
1500 struct vtep_ctl_port *port;
1501 const char *vlan;
1502
1503 vtep_ctl_context_populate_cache(ctx);
1504
1505 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1506 vlan = ctx->argv[3];
1507 ls = find_lswitch(vtepctl_ctx, ctx->argv[4], true);
1508
1509 add_ls_binding_to_cache(port, vlan, ls);
1510 commit_ls_bindings(port);
1511
1512 vtep_ctl_context_invalidate_cache(ctx);
1513 }
1514
1515 static void
1516 cmd_unbind_ls(struct ctl_context *ctx)
1517 {
1518 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1519 struct vtep_ctl_port *port;
1520 const char *vlan;
1521
1522 vtep_ctl_context_populate_cache(ctx);
1523
1524 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1525 vlan = ctx->argv[3];
1526
1527 del_cached_ls_binding(port, vlan);
1528 commit_ls_bindings(port);
1529
1530 vtep_ctl_context_invalidate_cache(ctx);
1531 }
1532
1533 static void
1534 cmd_set_replication_mode(struct ctl_context *ctx)
1535 {
1536 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1537 struct vtep_ctl_lswitch *ls;
1538 const char *ls_name = ctx->argv[1];
1539
1540 vtep_ctl_context_populate_cache(ctx);
1541
1542 if (strcmp(ctx->argv[2], "service_node") &&
1543 strcmp(ctx->argv[2], "source_node")) {
1544 ctl_fatal("Replication mode must be 'service_node' or 'source_node'");
1545 }
1546
1547 ls = find_lswitch(vtepctl_ctx, ls_name, true);
1548 vteprec_logical_switch_set_replication_mode(ls->ls_cfg, ctx->argv[2]);
1549
1550 vtep_ctl_context_invalidate_cache(ctx);
1551 }
1552
1553 static void
1554 cmd_get_replication_mode(struct ctl_context *ctx)
1555 {
1556 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1557 struct vtep_ctl_lswitch *ls;
1558 const char *ls_name = ctx->argv[1];
1559
1560 vtep_ctl_context_populate_cache(ctx);
1561
1562 ls = find_lswitch(vtepctl_ctx, ls_name, true);
1563 ds_put_format(&ctx->output, "%s\n", ls->ls_cfg->replication_mode);
1564 }
1565
1566 static struct vtep_ctl_lrouter *
1567 find_lrouter(struct vtep_ctl_context *vtepctl_ctx,
1568 const char *name, bool must_exist)
1569 {
1570 struct vtep_ctl_lrouter *lr;
1571
1572 ovs_assert(vtepctl_ctx->cache_valid);
1573
1574 lr = shash_find_data(&vtepctl_ctx->lrouters, name);
1575 if (must_exist && !lr) {
1576 ctl_fatal("no logical router named %s", name);
1577 }
1578 return lr;
1579 }
1580
1581 static void
1582 cmd_add_lr(struct ctl_context *ctx)
1583 {
1584 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1585 const char *lr_name = ctx->argv[1];
1586 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1587 struct vteprec_logical_router *lr;
1588
1589 vtep_ctl_context_populate_cache(ctx);
1590 if (find_lrouter(vtepctl_ctx, lr_name, false)) {
1591 if (!may_exist) {
1592 ctl_fatal("cannot create logical router %s because it "
1593 "already exists", lr_name);
1594 }
1595 return;
1596 }
1597
1598 lr = vteprec_logical_router_insert(ctx->txn);
1599 vteprec_logical_router_set_name(lr, lr_name);
1600
1601 vtep_ctl_context_invalidate_cache(ctx);
1602 }
1603
1604 static void
1605 del_lrouter(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_lrouter *lr)
1606 {
1607 del_cached_lrouter(vtepctl_ctx, lr);
1608 }
1609
1610 static void
1611 cmd_del_lr(struct ctl_context *ctx)
1612 {
1613 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1614 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1615 struct vtep_ctl_lrouter *lr;
1616
1617 vtep_ctl_context_populate_cache(ctx);
1618 lr = find_lrouter(vtepctl_ctx, ctx->argv[1], must_exist);
1619 if (lr) {
1620 del_lrouter(vtepctl_ctx, lr);
1621 }
1622 }
1623
1624 static void
1625 cmd_list_lr(struct ctl_context *ctx)
1626 {
1627 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1628 struct shash_node *node;
1629 struct svec lrouters;
1630
1631 vtep_ctl_context_populate_cache(ctx);
1632
1633 svec_init(&lrouters);
1634 SHASH_FOR_EACH (node, &vtepctl_ctx->lrouters) {
1635 struct vtep_ctl_lrouter *lr = node->data;
1636
1637 svec_add(&lrouters, lr->name);
1638 }
1639 output_sorted(&lrouters, &ctx->output);
1640 svec_destroy(&lrouters);
1641 }
1642
1643 static void
1644 cmd_lr_exists(struct ctl_context *ctx)
1645 {
1646 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1647
1648 vtep_ctl_context_populate_cache(ctx);
1649 if (!find_lrouter(vtepctl_ctx, ctx->argv[1], false)) {
1650 vtep_ctl_exit(2);
1651 }
1652 }
1653
1654 static void
1655 add_ucast_entry(struct ctl_context *ctx, bool local)
1656 {
1657 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1658 struct vtep_ctl_lswitch *ls;
1659 const char *mac;
1660 const char *encap;
1661 const char *dst_ip;
1662 struct vteprec_physical_locator *ploc_cfg;
1663
1664 vtep_ctl_context_populate_cache(ctx);
1665
1666 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1667 mac = ctx->argv[2];
1668
1669 if (ctx->argc == 4) {
1670 encap = "vxlan_over_ipv4";
1671 dst_ip = ctx->argv[3];
1672 } else {
1673 encap = ctx->argv[3];
1674 dst_ip = ctx->argv[4];
1675 }
1676
1677 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1678 if (!ploc_cfg) {
1679 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1680 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1681 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1682
1683 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1684 }
1685
1686 if (local) {
1687 struct vteprec_ucast_macs_local *ucast_cfg;
1688
1689 ucast_cfg = shash_find_data(&ls->ucast_local, mac);
1690 if (!ucast_cfg) {
1691 ucast_cfg = vteprec_ucast_macs_local_insert(ctx->txn);
1692 vteprec_ucast_macs_local_set_MAC(ucast_cfg, mac);
1693 vteprec_ucast_macs_local_set_logical_switch(ucast_cfg, ls->ls_cfg);
1694 shash_add(&ls->ucast_local, mac, ucast_cfg);
1695 }
1696 vteprec_ucast_macs_local_set_locator(ucast_cfg, ploc_cfg);
1697 } else {
1698 struct vteprec_ucast_macs_remote *ucast_cfg;
1699
1700 ucast_cfg = shash_find_data(&ls->ucast_remote, mac);
1701 if (!ucast_cfg) {
1702 ucast_cfg = vteprec_ucast_macs_remote_insert(ctx->txn);
1703 vteprec_ucast_macs_remote_set_MAC(ucast_cfg, mac);
1704 vteprec_ucast_macs_remote_set_logical_switch(ucast_cfg, ls->ls_cfg);
1705 shash_add(&ls->ucast_remote, mac, ucast_cfg);
1706 }
1707 vteprec_ucast_macs_remote_set_locator(ucast_cfg, ploc_cfg);
1708 }
1709
1710 vtep_ctl_context_invalidate_cache(ctx);
1711 }
1712
1713 static void
1714 cmd_add_ucast_local(struct ctl_context *ctx)
1715 {
1716 add_ucast_entry(ctx, true);
1717 }
1718
1719 static void
1720 cmd_add_ucast_remote(struct ctl_context *ctx)
1721 {
1722 add_ucast_entry(ctx, false);
1723 }
1724
1725 static void
1726 del_ucast_entry(struct ctl_context *ctx, bool local)
1727 {
1728 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1729 struct vtep_ctl_lswitch *ls;
1730 struct shash *ucast_shash;
1731 struct shash_node *node;
1732
1733 vtep_ctl_context_populate_cache(ctx);
1734
1735 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1736 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1737
1738 node = shash_find(ucast_shash, ctx->argv[2]);
1739 if (!node) {
1740 return;
1741 }
1742
1743 if (local) {
1744 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1745 vteprec_ucast_macs_local_delete(ucast_cfg);
1746 } else {
1747 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1748 vteprec_ucast_macs_remote_delete(ucast_cfg);
1749 }
1750 shash_delete(ucast_shash, node);
1751
1752 vtep_ctl_context_invalidate_cache(ctx);
1753 }
1754
1755 static void
1756 cmd_del_ucast_local(struct ctl_context *ctx)
1757 {
1758 del_ucast_entry(ctx, true);
1759 }
1760
1761 static void
1762 cmd_del_ucast_remote(struct ctl_context *ctx)
1763 {
1764 del_ucast_entry(ctx, false);
1765 }
1766
1767 static void
1768 commit_mcast_entries(struct vtep_ctl_mcast_mac *mcast_mac)
1769 {
1770 struct vtep_ctl_ploc *ploc;
1771 struct vteprec_physical_locator **locators = NULL;
1772 size_t n_locators;
1773 int i;
1774
1775 n_locators = ovs_list_size(&mcast_mac->locators);
1776 ovs_assert(n_locators);
1777
1778 locators = xmalloc(n_locators * sizeof *locators);
1779
1780 i = 0;
1781 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1782 locators[i] = (struct vteprec_physical_locator *)ploc->ploc_cfg;
1783 i++;
1784 }
1785
1786 vteprec_physical_locator_set_set_locators(mcast_mac->ploc_set_cfg,
1787 locators,
1788 n_locators);
1789
1790 free(locators);
1791 }
1792
1793 static void
1794 add_mcast_entry(struct ctl_context *ctx,
1795 struct vtep_ctl_lswitch *ls, const char *mac,
1796 const char *encap, const char *dst_ip, bool local)
1797 {
1798 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1799 struct shash *mcast_shash;
1800 struct vtep_ctl_mcast_mac *mcast_mac;
1801 struct vteprec_physical_locator *ploc_cfg;
1802 struct vteprec_physical_locator_set *ploc_set_cfg;
1803
1804 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1805
1806 /* Physical locator sets are immutable, so allocate a new one. */
1807 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1808
1809 mcast_mac = shash_find_data(mcast_shash, mac);
1810 if (!mcast_mac) {
1811 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mac, ploc_set_cfg,
1812 local);
1813
1814 if (local) {
1815 mcast_mac->local_cfg = vteprec_mcast_macs_local_insert(ctx->txn);
1816 vteprec_mcast_macs_local_set_MAC(mcast_mac->local_cfg, mac);
1817 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1818 ploc_set_cfg);
1819 vteprec_mcast_macs_local_set_logical_switch(mcast_mac->local_cfg,
1820 ls->ls_cfg);
1821 mcast_mac->remote_cfg = NULL;
1822 } else {
1823 mcast_mac->remote_cfg = vteprec_mcast_macs_remote_insert(ctx->txn);
1824 vteprec_mcast_macs_remote_set_MAC(mcast_mac->remote_cfg, mac);
1825 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1826 ploc_set_cfg);
1827 vteprec_mcast_macs_remote_set_logical_switch(mcast_mac->remote_cfg,
1828 ls->ls_cfg);
1829 mcast_mac->local_cfg = NULL;
1830 }
1831 } else {
1832 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1833 if (local) {
1834 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1835 ploc_set_cfg);
1836 } else {
1837 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1838 ploc_set_cfg);
1839 }
1840 }
1841
1842 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1843 if (!ploc_cfg) {
1844 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1845 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1846 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1847
1848 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1849 }
1850
1851 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
1852 commit_mcast_entries(mcast_mac);
1853 }
1854
1855 static void
1856 del_mcast_entry(struct ctl_context *ctx,
1857 struct vtep_ctl_lswitch *ls, const char *mac,
1858 const char *encap, const char *dst_ip, bool local)
1859 {
1860 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1861 struct vtep_ctl_mcast_mac *mcast_mac;
1862 struct shash *mcast_shash;
1863 struct vteprec_physical_locator *ploc_cfg;
1864 struct vteprec_physical_locator_set *ploc_set_cfg;
1865
1866 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1867
1868 mcast_mac = shash_find_data(mcast_shash, mac);
1869 if (!mcast_mac) {
1870 return;
1871 }
1872
1873 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1874 if (!ploc_cfg) {
1875 /* Couldn't find the physical locator, so just ignore. */
1876 return;
1877 }
1878
1879 /* Physical locator sets are immutable, so allocate a new one. */
1880 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1881 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1882
1883 del_ploc_from_mcast_mac(mcast_mac, ploc_cfg);
1884 if (ovs_list_is_empty(&mcast_mac->locators)) {
1885 struct shash_node *node = shash_find(mcast_shash, mac);
1886
1887 vteprec_physical_locator_set_delete(ploc_set_cfg);
1888
1889 if (local) {
1890 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1891 } else {
1892 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1893 }
1894
1895 free(node->data);
1896 shash_delete(mcast_shash, node);
1897 } else {
1898 if (local) {
1899 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1900 ploc_set_cfg);
1901 } else {
1902 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1903 ploc_set_cfg);
1904 }
1905 commit_mcast_entries(mcast_mac);
1906 }
1907 }
1908
1909 static void
1910 add_del_mcast_entry(struct ctl_context *ctx, bool add, bool local)
1911 {
1912 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1913 struct vtep_ctl_lswitch *ls;
1914 const char *mac;
1915 const char *encap;
1916 const char *dst_ip;
1917
1918 vtep_ctl_context_populate_cache(ctx);
1919
1920 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1921 mac = ctx->argv[2];
1922
1923 if (ctx->argc == 4) {
1924 encap = "vxlan_over_ipv4";
1925 dst_ip = ctx->argv[3];
1926 } else {
1927 encap = ctx->argv[3];
1928 dst_ip = ctx->argv[4];
1929 }
1930
1931 if (add) {
1932 add_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1933 } else {
1934 del_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1935 }
1936
1937 vtep_ctl_context_invalidate_cache(ctx);
1938 }
1939
1940 static void
1941 cmd_add_mcast_local(struct ctl_context *ctx)
1942 {
1943 add_del_mcast_entry(ctx, true, true);
1944 }
1945
1946 static void
1947 cmd_add_mcast_remote(struct ctl_context *ctx)
1948 {
1949 add_del_mcast_entry(ctx, true, false);
1950 }
1951
1952 static void
1953 cmd_del_mcast_local(struct ctl_context *ctx)
1954 {
1955 add_del_mcast_entry(ctx, false, true);
1956 }
1957
1958 static void
1959 cmd_del_mcast_remote(struct ctl_context *ctx)
1960 {
1961 add_del_mcast_entry(ctx, false, false);
1962 }
1963
1964 static void
1965 clear_macs(struct ctl_context *ctx, bool local)
1966 {
1967 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1968 struct vtep_ctl_lswitch *ls;
1969 const struct shash_node *node;
1970 struct shash *ucast_shash;
1971 struct shash *mcast_shash;
1972
1973 vtep_ctl_context_populate_cache(ctx);
1974 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1975
1976 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1977 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1978
1979 SHASH_FOR_EACH (node, ucast_shash) {
1980 if (local) {
1981 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1982 vteprec_ucast_macs_local_delete(ucast_cfg);
1983 } else {
1984 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1985 vteprec_ucast_macs_remote_delete(ucast_cfg);
1986 }
1987 }
1988
1989 SHASH_FOR_EACH (node, mcast_shash) {
1990 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1991 if (local) {
1992 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1993 } else {
1994 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1995 }
1996 }
1997
1998 vtep_ctl_context_invalidate_cache(ctx);
1999 }
2000
2001 static void
2002 cmd_clear_local_macs(struct ctl_context *ctx)
2003 {
2004 clear_macs(ctx, true);
2005 }
2006
2007 static void
2008 cmd_clear_remote_macs(struct ctl_context *ctx)
2009 {
2010 clear_macs(ctx, false);
2011 }
2012
2013 static void
2014 list_macs(struct ctl_context *ctx, bool local)
2015 {
2016 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
2017 struct vtep_ctl_lswitch *ls;
2018 const struct shash_node *node;
2019 struct shash *ucast_shash;
2020 struct svec ucast_macs;
2021 struct shash *mcast_shash;
2022 struct svec mcast_macs;
2023
2024 vtep_ctl_context_populate_cache(ctx);
2025 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
2026
2027 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
2028 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
2029
2030 svec_init(&ucast_macs);
2031 SHASH_FOR_EACH (node, ucast_shash) {
2032 struct vteprec_ucast_macs_local *ucast_local = node->data;
2033 struct vteprec_ucast_macs_remote *ucast_remote = node->data;
2034 struct vteprec_physical_locator *ploc_cfg;
2035 char *entry;
2036
2037 ploc_cfg = local ? ucast_local->locator : ucast_remote->locator;
2038
2039 entry = xasprintf(" %s -> %s/%s", node->name,
2040 ploc_cfg->encapsulation_type, ploc_cfg->dst_ip);
2041 svec_add_nocopy(&ucast_macs, entry);
2042 }
2043 ds_put_format(&ctx->output, "ucast-mac-%s\n", local ? "local" : "remote");
2044 output_sorted(&ucast_macs, &ctx->output);
2045 ds_put_char(&ctx->output, '\n');
2046 svec_destroy(&ucast_macs);
2047
2048 svec_init(&mcast_macs);
2049 SHASH_FOR_EACH (node, mcast_shash) {
2050 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
2051 struct vtep_ctl_ploc *ploc;
2052 char *entry;
2053
2054 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
2055 entry = xasprintf(" %s -> %s/%s", node->name,
2056 ploc->ploc_cfg->encapsulation_type,
2057 ploc->ploc_cfg->dst_ip);
2058 svec_add_nocopy(&mcast_macs, entry);
2059 }
2060 }
2061 ds_put_format(&ctx->output, "mcast-mac-%s\n", local ? "local" : "remote");
2062 output_sorted(&mcast_macs, &ctx->output);
2063 ds_put_char(&ctx->output, '\n');
2064 svec_destroy(&mcast_macs);
2065 }
2066
2067 static void
2068 cmd_list_local_macs(struct ctl_context *ctx)
2069 {
2070 list_macs(ctx, true);
2071 }
2072
2073 static void
2074 cmd_list_remote_macs(struct ctl_context *ctx)
2075 {
2076 list_macs(ctx, false);
2077 }
2078
2079 static void
2080 verify_managers(const struct vteprec_global *vtep_global)
2081 {
2082 size_t i;
2083
2084 vteprec_global_verify_managers(vtep_global);
2085
2086 for (i = 0; i < vtep_global->n_managers; ++i) {
2087 const struct vteprec_manager *mgr = vtep_global->managers[i];
2088
2089 vteprec_manager_verify_target(mgr);
2090 }
2091 }
2092
2093 static void
2094 pre_manager(struct ctl_context *ctx)
2095 {
2096 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_managers);
2097 ovsdb_idl_add_column(ctx->idl, &vteprec_manager_col_target);
2098 }
2099
2100 static void
2101 cmd_get_manager(struct ctl_context *ctx)
2102 {
2103 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
2104 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
2105 struct svec targets;
2106 size_t i;
2107
2108 verify_managers(vtep_global);
2109
2110 /* Print the targets in sorted order for reproducibility. */
2111 svec_init(&targets);
2112
2113 for (i = 0; i < vtep_global->n_managers; i++) {
2114 svec_add(&targets, vtep_global->managers[i]->target);
2115 }
2116
2117 svec_sort_unique(&targets);
2118 for (i = 0; i < targets.n; i++) {
2119 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
2120 }
2121 svec_destroy(&targets);
2122 }
2123
2124 static void
2125 delete_managers(const struct vtep_ctl_context *vtepctl_ctx)
2126 {
2127 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
2128 size_t i;
2129
2130 /* Delete Manager rows pointed to by 'managers' column. */
2131 for (i = 0; i < vtep_global->n_managers; i++) {
2132 vteprec_manager_delete(vtep_global->managers[i]);
2133 }
2134
2135 /* Delete 'Manager' row refs in 'managers' column. */
2136 vteprec_global_set_managers(vtep_global, NULL, 0);
2137 }
2138
2139 static void
2140 cmd_del_manager(struct ctl_context *ctx)
2141 {
2142 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
2143 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
2144
2145 verify_managers(vtep_global);
2146 delete_managers(vtepctl_ctx);
2147 }
2148
2149 static void
2150 insert_managers(struct vtep_ctl_context *vtepctl_ctx, char *targets[], size_t n)
2151 {
2152 struct vteprec_manager **managers;
2153 size_t i;
2154
2155 /* Insert each manager in a new row in Manager table. */
2156 managers = xmalloc(n * sizeof *managers);
2157 for (i = 0; i < n; i++) {
2158 if (stream_verify_name(targets[i]) && pstream_verify_name(targets[i])) {
2159 VLOG_WARN("target type \"%s\" is possibly erroneous", targets[i]);
2160 }
2161 managers[i] = vteprec_manager_insert(vtepctl_ctx->base.txn);
2162 vteprec_manager_set_target(managers[i], targets[i]);
2163 }
2164
2165 /* Store uuids of new Manager rows in 'managers' column. */
2166 vteprec_global_set_managers(vtepctl_ctx->vtep_global, managers, n);
2167 free(managers);
2168 }
2169
2170 static void
2171 cmd_set_manager(struct ctl_context *ctx)
2172 {
2173 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
2174 const size_t n = ctx->argc - 1;
2175
2176 verify_managers(vtepctl_ctx->vtep_global);
2177 delete_managers(vtepctl_ctx);
2178 insert_managers(vtepctl_ctx, &ctx->argv[1], n);
2179 }
2180
2181 /* Parameter commands. */
2182 static const struct ctl_table_class tables[VTEPREC_N_TABLES] = {
2183 [VTEPREC_TABLE_LOGICAL_SWITCH].row_ids[0]
2184 = {&vteprec_logical_switch_col_name, NULL, NULL},
2185
2186 [VTEPREC_TABLE_MANAGER].row_ids[0]
2187 = {&vteprec_manager_col_target, NULL, NULL},
2188
2189 [VTEPREC_TABLE_PHYSICAL_PORT].row_ids[0]
2190 = {&vteprec_physical_port_col_name, NULL, NULL},
2191
2192 [VTEPREC_TABLE_PHYSICAL_SWITCH].row_ids[0]
2193 = {&vteprec_physical_switch_col_name, NULL, NULL},
2194
2195 [VTEPREC_TABLE_LOGICAL_ROUTER].row_ids[0]
2196 = {&vteprec_logical_router_col_name, NULL, NULL},
2197 };
2198
2199 \f
2200 static void
2201 vtep_ctl_context_init_command(struct vtep_ctl_context *vtepctl_ctx,
2202 struct ctl_command *command)
2203 {
2204 ctl_context_init_command(&vtepctl_ctx->base, command);
2205 vtepctl_ctx->verified_ports = false;
2206
2207 }
2208
2209 static void
2210 vtep_ctl_context_init(struct vtep_ctl_context *vtepctl_ctx,
2211 struct ctl_command *command,
2212 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2213 const struct vteprec_global *vtep_global,
2214 struct ovsdb_symbol_table *symtab)
2215 {
2216 ctl_context_init(&vtepctl_ctx->base, command, idl, txn, symtab,
2217 vtep_ctl_context_invalidate_cache);
2218 if (command) {
2219 vtepctl_ctx->verified_ports = false;
2220 }
2221 vtepctl_ctx->vtep_global = vtep_global;
2222 vtepctl_ctx->cache_valid = false;
2223 }
2224
2225 static void
2226 vtep_ctl_context_done_command(struct vtep_ctl_context *vtepctl_ctx,
2227 struct ctl_command *command)
2228 {
2229 ctl_context_done_command(&vtepctl_ctx->base, command);
2230 }
2231
2232 static void
2233 vtep_ctl_context_done(struct vtep_ctl_context *vtepctl_ctx,
2234 struct ctl_command *command)
2235 {
2236 ctl_context_done(&vtepctl_ctx->base, command);
2237 }
2238
2239 static void
2240 run_prerequisites(struct ctl_command *commands, size_t n_commands,
2241 struct ovsdb_idl *idl)
2242 {
2243 struct ctl_command *c;
2244
2245 ovsdb_idl_add_table(idl, &vteprec_table_global);
2246 for (c = commands; c < &commands[n_commands]; c++) {
2247 if (c->syntax->prerequisites) {
2248 struct vtep_ctl_context vtepctl_ctx;
2249
2250 ds_init(&c->output);
2251 c->table = NULL;
2252
2253 vtep_ctl_context_init(&vtepctl_ctx, c, idl, NULL, NULL, NULL);
2254 (c->syntax->prerequisites)(&vtepctl_ctx.base);
2255 vtep_ctl_context_done(&vtepctl_ctx, c);
2256
2257 ovs_assert(!c->output.string);
2258 ovs_assert(!c->table);
2259 }
2260 }
2261 }
2262
2263 static bool
2264 do_vtep_ctl(const char *args, struct ctl_command *commands,
2265 size_t n_commands, struct ovsdb_idl *idl)
2266 {
2267 struct ovsdb_idl_txn *txn;
2268 const struct vteprec_global *vtep_global;
2269 enum ovsdb_idl_txn_status status;
2270 struct ovsdb_symbol_table *symtab;
2271 struct vtep_ctl_context vtepctl_ctx;
2272 struct ctl_command *c;
2273 struct shash_node *node;
2274 char *error = NULL;
2275
2276 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
2277 if (dry_run) {
2278 ovsdb_idl_txn_set_dry_run(txn);
2279 }
2280
2281 ovsdb_idl_txn_add_comment(txn, "vtep-ctl: %s", args);
2282
2283 vtep_global = vteprec_global_first(idl);
2284 if (!vtep_global) {
2285 /* XXX add verification that table is empty */
2286 vtep_global = vteprec_global_insert(txn);
2287 }
2288
2289 symtab = ovsdb_symbol_table_create();
2290 for (c = commands; c < &commands[n_commands]; c++) {
2291 ds_init(&c->output);
2292 c->table = NULL;
2293 }
2294 vtep_ctl_context_init(&vtepctl_ctx, NULL, idl, txn, vtep_global, symtab);
2295 for (c = commands; c < &commands[n_commands]; c++) {
2296 vtep_ctl_context_init_command(&vtepctl_ctx, c);
2297 if (c->syntax->run) {
2298 (c->syntax->run)(&vtepctl_ctx.base);
2299 }
2300 vtep_ctl_context_done_command(&vtepctl_ctx, c);
2301
2302 if (vtepctl_ctx.base.try_again) {
2303 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2304 goto try_again;
2305 }
2306 }
2307 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2308
2309 SHASH_FOR_EACH (node, &symtab->sh) {
2310 struct ovsdb_symbol *symbol = node->data;
2311 if (!symbol->created) {
2312 ctl_fatal("row id \"%s\" is referenced but never created "
2313 "(e.g. with \"-- --id=%s create ...\")",
2314 node->name, node->name);
2315 }
2316 if (!symbol->strong_ref) {
2317 if (!symbol->weak_ref) {
2318 VLOG_WARN("row id \"%s\" was created but no reference to it "
2319 "was inserted, so it will not actually appear in "
2320 "the database", node->name);
2321 } else {
2322 VLOG_WARN("row id \"%s\" was created but only a weak "
2323 "reference to it was inserted, so it will not "
2324 "actually appear in the database", node->name);
2325 }
2326 }
2327 }
2328
2329 status = ovsdb_idl_txn_commit_block(txn);
2330 if (status == TXN_UNCHANGED || status == TXN_SUCCESS) {
2331 for (c = commands; c < &commands[n_commands]; c++) {
2332 if (c->syntax->postprocess) {
2333 vtep_ctl_context_init(&vtepctl_ctx, c, idl, txn, vtep_global, symtab);
2334 (c->syntax->postprocess)(&vtepctl_ctx.base);
2335 vtep_ctl_context_done(&vtepctl_ctx, c);
2336 }
2337 }
2338 }
2339 error = xstrdup(ovsdb_idl_txn_get_error(txn));
2340 ovsdb_idl_txn_destroy(txn);
2341 txn = the_idl_txn = NULL;
2342
2343 switch (status) {
2344 case TXN_UNCOMMITTED:
2345 case TXN_INCOMPLETE:
2346 OVS_NOT_REACHED();
2347
2348 case TXN_ABORTED:
2349 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2350 ctl_fatal("transaction aborted");
2351
2352 case TXN_UNCHANGED:
2353 case TXN_SUCCESS:
2354 break;
2355
2356 case TXN_TRY_AGAIN:
2357 goto try_again;
2358
2359 case TXN_ERROR:
2360 ctl_fatal("transaction error: %s", error);
2361
2362 case TXN_NOT_LOCKED:
2363 /* Should not happen--we never call ovsdb_idl_set_lock(). */
2364 ctl_fatal("database not locked");
2365
2366 default:
2367 OVS_NOT_REACHED();
2368 }
2369 free(error);
2370
2371 ovsdb_symbol_table_destroy(symtab);
2372
2373 for (c = commands; c < &commands[n_commands]; c++) {
2374 struct ds *ds = &c->output;
2375
2376 if (c->table) {
2377 table_print(c->table, &table_style);
2378 } else if (oneline) {
2379 size_t j;
2380
2381 ds_chomp(ds, '\n');
2382 for (j = 0; j < ds->length; j++) {
2383 int ch = ds->string[j];
2384 switch (ch) {
2385 case '\n':
2386 fputs("\\n", stdout);
2387 break;
2388
2389 case '\\':
2390 fputs("\\\\", stdout);
2391 break;
2392
2393 default:
2394 putchar(ch);
2395 }
2396 }
2397 putchar('\n');
2398 } else {
2399 fputs(ds_cstr(ds), stdout);
2400 }
2401 ds_destroy(&c->output);
2402 table_destroy(c->table);
2403 free(c->table);
2404
2405 shash_destroy_free_data(&c->options);
2406 }
2407 free(commands);
2408
2409 ovsdb_idl_destroy(idl);
2410
2411 return true;
2412
2413 try_again:
2414 /* Our transaction needs to be rerun, or a prerequisite was not met. Free
2415 * resources and return so that the caller can try again. */
2416 if (txn) {
2417 ovsdb_idl_txn_abort(txn);
2418 ovsdb_idl_txn_destroy(txn);
2419 }
2420 ovsdb_symbol_table_destroy(symtab);
2421 for (c = commands; c < &commands[n_commands]; c++) {
2422 ds_destroy(&c->output);
2423 table_destroy(c->table);
2424 free(c->table);
2425 }
2426 free(error);
2427 return false;
2428 }
2429
2430 static const struct ctl_command_syntax vtep_commands[] = {
2431 /* Physical Switch commands. */
2432 {"add-ps", 1, 1, NULL, pre_get_info, cmd_add_ps, NULL, "--may-exist", RW},
2433 {"del-ps", 1, 1, NULL, pre_get_info, cmd_del_ps, NULL, "--if-exists", RW},
2434 {"list-ps", 0, 0, NULL, pre_get_info, cmd_list_ps, NULL, "", RO},
2435 {"ps-exists", 1, 1, NULL, pre_get_info, cmd_ps_exists, NULL, "", RO},
2436
2437 /* Port commands. */
2438 {"list-ports", 1, 1, NULL, pre_get_info, cmd_list_ports, NULL, "", RO},
2439 {"add-port", 2, 2, NULL, pre_get_info, cmd_add_port, NULL, "--may-exist",
2440 RW},
2441 {"del-port", 2, 2, NULL, pre_get_info, cmd_del_port, NULL, "--if-exists",
2442 RW},
2443
2444 /* Logical Switch commands. */
2445 {"add-ls", 1, 1, NULL, pre_get_info, cmd_add_ls, NULL, "--may-exist", RW},
2446 {"del-ls", 1, 1, NULL, pre_get_info, cmd_del_ls, NULL, "--if-exists", RW},
2447 {"list-ls", 0, 0, NULL, pre_get_info, cmd_list_ls, NULL, "", RO},
2448 {"ls-exists", 1, 1, NULL, pre_get_info, cmd_ls_exists, NULL, "", RO},
2449 {"list-bindings", 2, 2, NULL, pre_get_info, cmd_list_bindings, NULL, "", RO},
2450 {"bind-ls", 4, 4, NULL, pre_get_info, cmd_bind_ls, NULL, "", RO},
2451 {"unbind-ls", 3, 3, NULL, pre_get_info, cmd_unbind_ls, NULL, "", RO},
2452 {"set-replication-mode", 2, 2, "LS MODE", pre_get_info,
2453 cmd_set_replication_mode, NULL, "", RW},
2454 {"get-replication-mode", 1, 1, "LS", pre_get_info,
2455 cmd_get_replication_mode, NULL, "", RO},
2456
2457 /* Logical Router commands. */
2458 {"add-lr", 1, 1, NULL, pre_get_info, cmd_add_lr, NULL, "--may-exist", RW},
2459 {"del-lr", 1, 1, NULL, pre_get_info, cmd_del_lr, NULL, "--if-exists", RW},
2460 {"list-lr", 0, 0, NULL, pre_get_info, cmd_list_lr, NULL, "", RO},
2461 {"lr-exists", 1, 1, NULL, pre_get_info, cmd_lr_exists, NULL, "", RO},
2462
2463 /* MAC binding commands. */
2464 {"add-ucast-local", 3, 4, NULL, pre_get_info, cmd_add_ucast_local, NULL,
2465 "", RW},
2466 {"del-ucast-local", 2, 2, NULL, pre_get_info, cmd_del_ucast_local, NULL,
2467 "", RW},
2468 {"add-mcast-local", 3, 4, NULL, pre_get_info, cmd_add_mcast_local, NULL,
2469 "", RW},
2470 {"del-mcast-local", 3, 4, NULL, pre_get_info, cmd_del_mcast_local, NULL,
2471 "", RW},
2472 {"clear-local-macs", 1, 1, NULL, pre_get_info, cmd_clear_local_macs, NULL,
2473 "", RO},
2474 {"list-local-macs", 1, 1, NULL, pre_get_info, cmd_list_local_macs, NULL,
2475 "", RO},
2476 {"add-ucast-remote", 3, 4, NULL, pre_get_info, cmd_add_ucast_remote, NULL,
2477 "", RW},
2478 {"del-ucast-remote", 2, 2, NULL, pre_get_info, cmd_del_ucast_remote, NULL,
2479 "", RW},
2480 {"add-mcast-remote", 3, 4, NULL, pre_get_info, cmd_add_mcast_remote, NULL,
2481 "", RW},
2482 {"del-mcast-remote", 3, 4, NULL, pre_get_info, cmd_del_mcast_remote, NULL,
2483 "", RW},
2484 {"clear-remote-macs", 1, 1, NULL, pre_get_info, cmd_clear_remote_macs, NULL,
2485 "", RO},
2486 {"list-remote-macs", 1, 1, NULL, pre_get_info, cmd_list_remote_macs, NULL,
2487 "", RO},
2488
2489 /* Manager commands. */
2490 {"get-manager", 0, 0, NULL, pre_manager, cmd_get_manager, NULL, "", RO},
2491 {"del-manager", 0, 0, NULL, pre_manager, cmd_del_manager, NULL, "", RW},
2492 {"set-manager", 1, INT_MAX, NULL, pre_manager, cmd_set_manager, NULL, "",
2493 RW},
2494
2495 {NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, RO},
2496 };
2497
2498 /* Registers vsctl and common db commands. */
2499 static void
2500 vtep_ctl_cmd_init(void)
2501 {
2502 ctl_init(vteprec_table_classes, tables, cmd_show_tables, vtep_ctl_exit);
2503 ctl_register_commands(vtep_commands);
2504 }