2 * Copyright (c) 2009, 2010, 2011, 2012, 2014 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
30 #include "db-ctl-base.h"
32 #include "command-line.h"
34 #include "dynamic-string.h"
35 #include "fatal-signal.h"
38 #include "ovsdb-data.h"
39 #include "ovsdb-idl.h"
40 #include "poll-loop.h"
43 #include "stream-ssl.h"
47 #include "vtep/vtep-idl.h"
51 #include "openvswitch/vconn.h"
52 #include "openvswitch/vlog.h"
54 VLOG_DEFINE_THIS_MODULE(vtep_ctl);
56 struct vtep_ctl_context;
58 /* --db: The database server to contact. */
59 static const char *db;
61 /* --oneline: Write each command's output as a single line? */
64 /* --dry-run: Do not commit any changes. */
67 /* --timeout: Time to wait for a connection to 'db'. */
70 /* Format for table output. */
71 static struct table_style table_style = TABLE_STYLE_DEFAULT;
73 static void vtep_ctl_cmd_init(void);
74 OVS_NO_RETURN static void usage(void);
75 static void parse_options(int argc, char *argv[], struct shash *local_options);
76 static void run_prerequisites(struct ctl_command[], size_t n_commands,
78 static void do_vtep_ctl(const char *args, struct ctl_command *, size_t n,
80 static struct vtep_ctl_lswitch *find_lswitch(struct vtep_ctl_context *,
85 main(int argc, char *argv[])
87 extern struct vlog_module VLM_reconnect;
88 struct ovsdb_idl *idl;
89 struct ctl_command *commands;
90 struct shash local_options;
95 set_program_name(argv[0]);
96 fatal_ignore_sigpipe();
97 vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
98 vlog_set_levels(&VLM_reconnect, VLF_ANY_DESTINATION, VLL_WARN);
103 /* Log our arguments. This is often valuable for debugging systems. */
104 args = process_escape_args(argv);
105 VLOG(ctl_might_write_to_db(argv) ? VLL_INFO : VLL_DBG, "Called as %s", args);
107 /* Parse command line. */
108 shash_init(&local_options);
109 parse_options(argc, argv, &local_options);
110 commands = ctl_parse_commands(argc - optind, argv + optind, &local_options,
117 /* Initialize IDL. */
118 idl = the_idl = ovsdb_idl_create(db, &vteprec_idl_class, false, false);
119 run_prerequisites(commands, n_commands, idl);
121 /* Execute the commands.
123 * 'seqno' is the database sequence number for which we last tried to
124 * execute our transaction. There's no point in trying to commit more than
125 * once for any given sequence number, because if the transaction fails
126 * it's because the database changed and we need to obtain an up-to-date
127 * view of the database before we try the transaction again. */
128 seqno = ovsdb_idl_get_seqno(idl);
132 if (seqno != ovsdb_idl_get_seqno(idl)) {
133 seqno = ovsdb_idl_get_seqno(idl);
134 do_vtep_ctl(args, commands, n_commands, idl);
137 if (seqno == ovsdb_idl_get_seqno(idl)) {
145 parse_options(int argc, char *argv[], struct shash *local_options)
148 OPT_DB = UCHAR_MAX + 1,
157 static const struct option global_long_options[] = {
158 {"db", required_argument, NULL, OPT_DB},
159 {"no-syslog", no_argument, NULL, OPT_NO_SYSLOG},
160 {"dry-run", no_argument, NULL, OPT_DRY_RUN},
161 {"oneline", no_argument, NULL, OPT_ONELINE},
162 {"timeout", required_argument, NULL, 't'},
163 {"help", no_argument, NULL, 'h'},
164 {"version", no_argument, NULL, 'V'},
167 STREAM_SSL_LONG_OPTIONS,
168 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
171 const int n_global_long_options = ARRAY_SIZE(global_long_options) - 1;
172 char *tmp, *short_options;
174 struct option *options;
175 size_t allocated_options;
179 tmp = ovs_cmdl_long_options_to_short_options(global_long_options);
180 short_options = xasprintf("+%s", tmp);
183 /* We want to parse both global and command-specific options here, but
184 * getopt_long() isn't too convenient for the job. We copy our global
185 * options into a dynamic array, then append all of the command-specific
187 options = xmemdup(global_long_options, sizeof global_long_options);
188 allocated_options = ARRAY_SIZE(global_long_options);
189 n_options = n_global_long_options;
190 ctl_add_cmd_options(&options, &n_options, &allocated_options, OPT_LOCAL);
191 table_style.format = TF_LIST;
197 c = getopt_long(argc, argv, short_options, options, &idx);
212 vlog_set_levels(&VLM_vtep_ctl, VLF_SYSLOG, VLL_WARN);
220 if (shash_find(local_options, options[idx].name)) {
221 ctl_fatal("'%s' option specified multiple times",
224 shash_add_nocopy(local_options,
225 xasprintf("--%s", options[idx].name),
226 optarg ? xstrdup(optarg) : NULL);
233 ovs_print_version(0, 0);
234 printf("DB Schema %s\n", vteprec_get_db_version());
238 timeout = strtoul(optarg, NULL, 10);
240 ctl_fatal("value %s on -t or --timeout is invalid",
246 TABLE_OPTION_HANDLERS(&table_style)
248 STREAM_SSL_OPTION_HANDLERS
250 case OPT_PEER_CA_CERT:
251 stream_ssl_set_peer_ca_cert_file(optarg);
264 db = ctl_default_db();
267 for (i = n_global_long_options; options[i].name; i++) {
268 free(CONST_CAST(char *, options[i].name));
277 %s: VTEP configuration utility\n\
278 usage: %s [OPTIONS] COMMAND [ARG...]\n\
281 show print overview of database contents\n\
284 get-manager print the managers\n\
285 del-manager delete the managers\n\
286 set-manager TARGET... set the list of managers to TARGET...\n\
288 Physical Switch commands:\n\
289 add-ps PS create a new physical switch named PS\n\
290 del-ps PS delete PS and all of its ports\n\
291 list-ps print the names of all the physical switches\n\
292 ps-exists PS exit 2 if PS does not exist\n\
295 list-ports PS print the names of all the ports on PS\n\
296 add-port PS PORT add network device PORT to PS\n\
297 del-port PS PORT delete PORT from PS\n\
299 Logical Switch commands:\n\
300 add-ls LS create a new logical switch named LS\n\
301 del-ls LS delete LS and all of its ports\n\
302 list-ls print the names of all the logical switches\n\
303 ls-exists LS exit 2 if LS does not exist\n\
304 bind-ls PS PORT VLAN LS bind LS to VLAN on PORT\n\
305 unbind-ls PS PORT VLAN unbind logical switch on VLAN from PORT\n\
306 list-bindings PS PORT list bindings for PORT on PS\n\
308 MAC binding commands:\n\
309 add-ucast-local LS MAC [ENCAP] IP add ucast local entry in LS\n\
310 del-ucast-local LS MAC del ucast local entry from LS\n\
311 add-mcast-local LS MAC [ENCAP] IP add mcast local entry in LS\n\
312 del-mcast-local LS MAC [ENCAP] IP del mcast local entry from LS\n\
313 clear-local-macs LS clear local mac entries\n\
314 list-local-macs LS list local mac entries\n\
315 add-ucast-remote LS MAC [ENCAP] IP add ucast remote entry in LS\n\
316 del-ucast-remote LS MAC del ucast remote entry from LS\n\
317 add-mcast-remote LS MAC [ENCAP] IP add mcast remote entry in LS\n\
318 del-mcast-remote LS MAC [ENCAP] IP del mcast remote entry from LS\n\
319 clear-remote-macs LS clear remote mac entries\n\
320 list-remote-macs LS list remote mac entries\n\
325 --db=DATABASE connect to DATABASE\n\
327 -t, --timeout=SECS wait at most SECS seconds\n\
328 --dry-run do not commit changes to database\n\
329 --oneline print exactly one line of output per command\n",
330 program_name, program_name, ctl_get_db_cmd_usage(), ctl_default_db());
333 --no-syslog equivalent to --verbose=vtep_ctl:syslog:warn\n");
334 stream_usage("database", true, true, false);
337 -h, --help display this help message\n\
338 -V, --version display version information\n");
343 struct cmd_show_table cmd_show_tables[] = {
344 {&vteprec_table_global,
346 {&vteprec_global_col_managers,
347 &vteprec_global_col_switches,
351 {&vteprec_table_manager,
352 &vteprec_manager_col_target,
353 {&vteprec_manager_col_is_connected,
358 {&vteprec_table_physical_switch,
359 &vteprec_physical_switch_col_name,
360 {&vteprec_physical_switch_col_management_ips,
361 &vteprec_physical_switch_col_tunnel_ips,
362 &vteprec_physical_switch_col_ports},
365 {&vteprec_table_physical_port,
366 &vteprec_physical_port_col_name,
367 {&vteprec_physical_port_col_vlan_bindings,
372 {&vteprec_table_logical_switch,
373 &vteprec_logical_switch_col_name,
379 {NULL, NULL, {NULL, NULL, NULL}, false}
382 /* vtep-ctl specific context. Inherits the 'struct ctl_context' as base. */
383 struct vtep_ctl_context {
384 struct ctl_context base;
386 /* Modifiable state. */
387 const struct vteprec_global *vtep_global;
390 /* A cache of the contents of the database.
392 * A command that needs to use any of this information must first
393 * call vtep_ctl_context_populate_cache(). A command that changes
394 * anything that could invalidate the cache must either call
395 * vtep_ctl_context_invalidate_cache() or manually update the cache
396 * to maintain its correctness. */
398 struct shash pswitches; /* Maps from physical switch name to
399 * struct vtep_ctl_pswitch. */
400 struct shash ports; /* Maps from port name to struct vtep_ctl_port. */
402 struct shash lswitches; /* Maps from logical switch name to
403 * struct vtep_ctl_lswitch. */
404 struct shash plocs; /* Maps from "<encap>+<dst_ip>" to
405 * struct vteprec_physical_locator. */
408 /* Casts 'base' into 'strcut vtep_ctl_context'. */
409 static struct vtep_ctl_context *
410 vtep_ctl_context_cast(struct ctl_context *base)
412 return CONTAINER_OF(base, struct vtep_ctl_context, base);
415 struct vtep_ctl_pswitch {
416 const struct vteprec_physical_switch *ps_cfg;
418 struct ovs_list ports; /* Contains "struct vteprec_physical_port"s. */
421 struct vtep_ctl_port {
422 struct ovs_list ports_node; /* In struct vtep_ctl_pswitch's 'ports' list. */
423 const struct vteprec_physical_port *port_cfg;
424 struct vtep_ctl_pswitch *ps;
425 struct shash bindings; /* Maps from vlan to vtep_ctl_lswitch. */
428 struct vtep_ctl_lswitch {
429 const struct vteprec_logical_switch *ls_cfg;
431 struct shash ucast_local; /* Maps from mac to vteprec_ucast_macs_local. */
432 struct shash ucast_remote; /* Maps from mac to vteprec_ucast_macs_remote.*/
433 struct shash mcast_local; /* Maps from mac to vtep_ctl_mcast_mac. */
434 struct shash mcast_remote; /* Maps from mac to vtep_ctl_mcast_mac. */
437 struct vtep_ctl_mcast_mac {
438 const struct vteprec_mcast_macs_local *local_cfg;
439 const struct vteprec_mcast_macs_remote *remote_cfg;
441 const struct vteprec_physical_locator_set *ploc_set_cfg;
442 struct ovs_list locators; /* Contains 'vtep_ctl_ploc's. */
445 struct vtep_ctl_ploc {
446 struct ovs_list locators_node; /* In struct vtep_ctl_ploc_set's 'locators'
448 const struct vteprec_physical_locator *ploc_cfg;
452 verify_ports(struct vtep_ctl_context *vtepctl_ctx)
454 if (!vtepctl_ctx->verified_ports) {
455 const struct vteprec_physical_switch *ps;
457 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
458 VTEPREC_PHYSICAL_SWITCH_FOR_EACH (ps, vtepctl_ctx->base.idl) {
459 vteprec_physical_switch_verify_ports(ps);
462 vtepctl_ctx->verified_ports = true;
466 static struct vtep_ctl_port *
467 add_port_to_cache(struct vtep_ctl_context *vtepctl_ctx,
468 struct vtep_ctl_pswitch *ps,
469 struct vteprec_physical_port *port_cfg)
471 char *cache_name = xasprintf("%s+%s", ps->name, port_cfg->name);
472 struct vtep_ctl_port *port;
474 port = xmalloc(sizeof *port);
475 list_push_back(&ps->ports, &port->ports_node);
476 port->port_cfg = port_cfg;
478 shash_add(&vtepctl_ctx->ports, cache_name, port);
480 shash_init(&port->bindings);
486 del_cached_port(struct vtep_ctl_context *vtepctl_ctx,
487 struct vtep_ctl_port *port)
489 char *cache_name = xasprintf("%s+%s", port->ps->name, port->port_cfg->name);
491 list_remove(&port->ports_node);
492 shash_find_and_delete(&vtepctl_ctx->ports, cache_name);
493 vteprec_physical_port_delete(port->port_cfg);
498 static struct vtep_ctl_pswitch *
499 add_pswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
500 struct vteprec_physical_switch *ps_cfg)
502 struct vtep_ctl_pswitch *ps = xmalloc(sizeof *ps);
504 ps->name = xstrdup(ps_cfg->name);
505 list_init(&ps->ports);
506 shash_add(&vtepctl_ctx->pswitches, ps->name, ps);
511 vtep_delete_pswitch(const struct vteprec_global *vtep_global,
512 const struct vteprec_physical_switch *ps)
514 struct vteprec_physical_switch **pswitches;
517 pswitches = xmalloc(sizeof *vtep_global->switches
518 * vtep_global->n_switches);
519 for (i = n = 0; i < vtep_global->n_switches; i++) {
520 if (vtep_global->switches[i] != ps) {
521 pswitches[n++] = vtep_global->switches[i];
524 vteprec_global_set_switches(vtep_global, pswitches, n);
529 del_cached_pswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_pswitch *ps)
531 ovs_assert(list_is_empty(&ps->ports));
533 vteprec_physical_switch_delete(ps->ps_cfg);
534 vtep_delete_pswitch(ctx->vtep_global, ps->ps_cfg);
536 shash_find_and_delete(&ctx->pswitches, ps->name);
541 static struct vtep_ctl_lswitch *
542 add_lswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
543 const struct vteprec_logical_switch *ls_cfg)
545 struct vtep_ctl_lswitch *ls = xmalloc(sizeof *ls);
547 ls->name = xstrdup(ls_cfg->name);
548 shash_add(&vtepctl_ctx->lswitches, ls->name, ls);
549 shash_init(&ls->ucast_local);
550 shash_init(&ls->ucast_remote);
551 shash_init(&ls->mcast_local);
552 shash_init(&ls->mcast_remote);
557 del_cached_lswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_lswitch *ls)
560 vteprec_logical_switch_delete(ls->ls_cfg);
562 shash_find_and_delete(&ctx->lswitches, ls->name);
568 commit_ls_bindings(struct vtep_ctl_port *port)
570 struct vteprec_logical_switch **binding_values;
571 int64_t *binding_keys;
573 struct shash_node *node;
576 n_bindings = shash_count(&port->bindings);
577 binding_keys = xmalloc(n_bindings * sizeof *binding_keys);
578 binding_values = xmalloc(n_bindings * sizeof *binding_values);
581 SHASH_FOR_EACH(node, &port->bindings) {
582 struct vtep_ctl_lswitch *ls_entry = node->data;
584 binding_keys[i] = strtoll(node->name, NULL, 0);
585 binding_values[i] = (struct vteprec_logical_switch *)ls_entry->ls_cfg;
589 vteprec_physical_port_set_vlan_bindings(port->port_cfg,
590 binding_keys, binding_values,
592 free(binding_values);
597 add_ls_binding_to_cache(struct vtep_ctl_port *port,
599 struct vtep_ctl_lswitch *ls)
601 if (shash_find(&port->bindings, vlan)) {
602 ctl_fatal("multiple bindings for vlan %s", vlan);
605 shash_add(&port->bindings, vlan, ls);
609 del_cached_ls_binding(struct vtep_ctl_port *port, const char *vlan)
611 if (!shash_find(&port->bindings, vlan)) {
612 ctl_fatal("no binding for vlan %s", vlan);
615 shash_find_and_delete(&port->bindings, vlan);
618 static struct vteprec_physical_locator *
619 find_ploc(struct vtep_ctl_context *vtepctl_ctx, const char *encap,
622 struct vteprec_physical_locator *ploc;
623 char *name = xasprintf("%s+%s", encap, dst_ip);
625 ovs_assert(vtepctl_ctx->cache_valid);
627 ploc = shash_find_data(&vtepctl_ctx->plocs, name);
634 add_ploc_to_cache(struct vtep_ctl_context *vtepctl_ctx,
635 struct vteprec_physical_locator *ploc)
637 char *name = xasprintf("%s+%s", ploc->encapsulation_type, ploc->dst_ip);
638 struct vteprec_physical_locator *orig_ploc;
640 orig_ploc = find_ploc(vtepctl_ctx, ploc->encapsulation_type, ploc->dst_ip);
642 shash_add(&vtepctl_ctx->plocs, name, ploc);
649 add_ploc_to_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
650 struct vteprec_physical_locator *ploc_cfg)
652 struct vtep_ctl_ploc *ploc;
654 ploc = xmalloc(sizeof *ploc);
655 ploc->ploc_cfg = ploc_cfg;
656 list_push_back(&mcast_mac->locators, &ploc->locators_node);
660 del_ploc_from_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
661 struct vteprec_physical_locator *ploc_cfg)
663 struct vtep_ctl_ploc *ploc;
665 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
666 if (ploc->ploc_cfg == ploc_cfg) {
667 list_remove(&ploc->locators_node);
674 static struct vtep_ctl_mcast_mac *
675 add_mcast_mac_to_cache(struct vtep_ctl_context *vtepctl_ctx,
676 struct vtep_ctl_lswitch *ls, const char *mac,
677 struct vteprec_physical_locator_set *ploc_set_cfg,
680 struct vtep_ctl_mcast_mac *mcast_mac;
681 struct shash *mcast_shash;
684 mcast_mac = xmalloc(sizeof *mcast_mac);
685 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
687 mcast_mac->ploc_set_cfg = ploc_set_cfg;
688 list_init(&mcast_mac->locators);
689 shash_add(mcast_shash, mac, mcast_mac);
691 for (i = 0; i < ploc_set_cfg->n_locators; i++) {
692 struct vteprec_physical_locator *ploc_cfg;
694 ploc_cfg = ploc_set_cfg->locators[i];
695 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
696 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
703 vtep_ctl_context_invalidate_cache(struct ctl_context *ctx)
705 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
706 struct shash_node *node;
708 if (!vtepctl_ctx->cache_valid) {
711 vtepctl_ctx->cache_valid = false;
713 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
714 struct vtep_ctl_pswitch *ps = node->data;
718 shash_destroy(&vtepctl_ctx->pswitches);
720 SHASH_FOR_EACH (node, &vtepctl_ctx->ports) {
721 struct vtep_ctl_port *port = node->data;
722 shash_destroy(&port->bindings);
724 shash_destroy_free_data(&vtepctl_ctx->ports);
726 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
727 struct vtep_ctl_lswitch *ls = node->data;
728 struct shash_node *node2, *next_node2;
730 shash_destroy(&ls->ucast_local);
731 shash_destroy(&ls->ucast_remote);
733 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_local) {
734 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
735 struct vtep_ctl_ploc *ploc, *next_ploc;
737 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
738 &mcast_mac->locators) {
743 shash_destroy(&ls->mcast_local);
745 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_remote) {
746 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
747 struct vtep_ctl_ploc *ploc, *next_ploc;
749 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
750 &mcast_mac->locators) {
755 shash_destroy(&ls->mcast_remote);
760 shash_destroy(&vtepctl_ctx->lswitches);
761 shash_destroy(&vtepctl_ctx->plocs);
765 pre_get_info(struct ctl_context *ctx)
767 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_switches);
769 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_name);
770 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_ports);
771 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_tunnels);
773 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_name);
774 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_vlan_bindings);
776 ovsdb_idl_add_column(ctx->idl, &vteprec_logical_switch_col_name);
778 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_MAC);
779 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_locator);
780 ovsdb_idl_add_column(ctx->idl,
781 &vteprec_ucast_macs_local_col_logical_switch);
783 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_MAC);
784 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_locator);
785 ovsdb_idl_add_column(ctx->idl,
786 &vteprec_ucast_macs_remote_col_logical_switch);
788 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_local_col_MAC);
789 ovsdb_idl_add_column(ctx->idl,
790 &vteprec_mcast_macs_local_col_locator_set);
791 ovsdb_idl_add_column(ctx->idl,
792 &vteprec_mcast_macs_local_col_logical_switch);
794 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_remote_col_MAC);
795 ovsdb_idl_add_column(ctx->idl,
796 &vteprec_mcast_macs_remote_col_locator_set);
797 ovsdb_idl_add_column(ctx->idl,
798 &vteprec_mcast_macs_remote_col_logical_switch);
800 ovsdb_idl_add_column(ctx->idl,
801 &vteprec_physical_locator_set_col_locators);
803 ovsdb_idl_add_column(ctx->idl,
804 &vteprec_physical_locator_col_dst_ip);
805 ovsdb_idl_add_column(ctx->idl,
806 &vteprec_physical_locator_col_encapsulation_type);
808 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_local);
809 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_remote);
813 vtep_ctl_context_populate_cache(struct ctl_context *ctx)
815 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
816 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
817 const struct vteprec_logical_switch *ls_cfg;
818 const struct vteprec_ucast_macs_local *ucast_local_cfg;
819 const struct vteprec_ucast_macs_remote *ucast_remote_cfg;
820 const struct vteprec_mcast_macs_local *mcast_local_cfg;
821 const struct vteprec_mcast_macs_remote *mcast_remote_cfg;
822 const struct vteprec_tunnel *tunnel_cfg;
823 struct sset pswitches, ports, lswitches;
826 if (vtepctl_ctx->cache_valid) {
827 /* Cache is already populated. */
830 vtepctl_ctx->cache_valid = true;
831 shash_init(&vtepctl_ctx->pswitches);
832 shash_init(&vtepctl_ctx->ports);
833 shash_init(&vtepctl_ctx->lswitches);
834 shash_init(&vtepctl_ctx->plocs);
836 sset_init(&pswitches);
838 for (i = 0; i < vtep_global->n_switches; i++) {
839 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
840 struct vtep_ctl_pswitch *ps;
843 if (!sset_add(&pswitches, ps_cfg->name)) {
844 VLOG_WARN("%s: database contains duplicate physical switch name",
848 ps = add_pswitch_to_cache(vtepctl_ctx, ps_cfg);
853 for (j = 0; j < ps_cfg->n_ports; j++) {
854 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
856 if (!sset_add(&ports, port_cfg->name)) {
857 /* Duplicate port name. (We will warn about that later.) */
862 sset_destroy(&pswitches);
863 sset_destroy(&ports);
865 sset_init(&lswitches);
866 VTEPREC_LOGICAL_SWITCH_FOR_EACH (ls_cfg, ctx->idl) {
867 if (!sset_add(&lswitches, ls_cfg->name)) {
868 VLOG_WARN("%s: database contains duplicate logical switch name",
872 add_lswitch_to_cache(vtepctl_ctx, ls_cfg);
874 sset_destroy(&lswitches);
876 VTEPREC_UCAST_MACS_LOCAL_FOR_EACH (ucast_local_cfg, ctx->idl) {
877 struct vtep_ctl_lswitch *ls;
879 if (!ucast_local_cfg->logical_switch) {
882 ls = find_lswitch(vtepctl_ctx, ucast_local_cfg->logical_switch->name,
888 if (ucast_local_cfg->locator) {
889 add_ploc_to_cache(vtepctl_ctx, ucast_local_cfg->locator);
892 shash_add(&ls->ucast_local, ucast_local_cfg->MAC, ucast_local_cfg);
895 VTEPREC_UCAST_MACS_REMOTE_FOR_EACH (ucast_remote_cfg, ctx->idl) {
896 struct vtep_ctl_lswitch *ls;
898 if (!ucast_remote_cfg->logical_switch) {
901 ls = find_lswitch(vtepctl_ctx, ucast_remote_cfg->logical_switch->name,
907 if (ucast_remote_cfg->locator) {
908 add_ploc_to_cache(vtepctl_ctx, ucast_remote_cfg->locator);
911 shash_add(&ls->ucast_remote, ucast_remote_cfg->MAC, ucast_remote_cfg);
914 VTEPREC_MCAST_MACS_LOCAL_FOR_EACH (mcast_local_cfg, ctx->idl) {
915 struct vtep_ctl_mcast_mac *mcast_mac;
916 struct vtep_ctl_lswitch *ls;
918 if (!mcast_local_cfg->logical_switch) {
921 ls = find_lswitch(vtepctl_ctx, mcast_local_cfg->logical_switch->name,
927 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_local_cfg->MAC,
928 mcast_local_cfg->locator_set,
930 mcast_mac->local_cfg = mcast_local_cfg;
933 VTEPREC_MCAST_MACS_REMOTE_FOR_EACH (mcast_remote_cfg, ctx->idl) {
934 struct vtep_ctl_mcast_mac *mcast_mac;
935 struct vtep_ctl_lswitch *ls;
937 if (!mcast_remote_cfg->logical_switch) {
940 ls = find_lswitch(vtepctl_ctx, mcast_remote_cfg->logical_switch->name,
946 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_remote_cfg->MAC,
947 mcast_remote_cfg->locator_set,
949 mcast_mac->remote_cfg = mcast_remote_cfg;
952 VTEPREC_TUNNEL_FOR_EACH (tunnel_cfg, ctx->idl) {
953 if (tunnel_cfg->local) {
954 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->local);
956 if (tunnel_cfg->remote) {
957 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->remote);
961 sset_init(&pswitches);
962 for (i = 0; i < vtep_global->n_switches; i++) {
963 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
964 struct vtep_ctl_pswitch *ps;
967 if (!sset_add(&pswitches, ps_cfg->name)) {
970 ps = shash_find_data(&vtepctl_ctx->pswitches, ps_cfg->name);
971 for (j = 0; j < ps_cfg->n_ports; j++) {
972 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
973 struct vtep_ctl_port *port;
976 port = shash_find_data(&vtepctl_ctx->ports, port_cfg->name);
978 if (port_cfg == port->port_cfg) {
979 VLOG_WARN("%s: port is in multiple physical switches "
981 port_cfg->name, ps->name, port->ps->name);
983 /* Log as an error because this violates the database's
984 * uniqueness constraints, so the database server shouldn't
985 * have allowed it. */
986 VLOG_ERR("%s: database contains duplicate port name",
992 port = add_port_to_cache(vtepctl_ctx, ps, port_cfg);
994 for (k = 0; k < port_cfg->n_vlan_bindings; k++) {
995 struct vteprec_logical_switch *ls_cfg;
996 struct vtep_ctl_lswitch *ls;
999 vlan = xasprintf("%"PRId64, port_cfg->key_vlan_bindings[k]);
1000 if (shash_find(&port->bindings, vlan)) {
1001 ctl_fatal("multiple bindings for vlan %s", vlan);
1004 ls_cfg = port_cfg->value_vlan_bindings[k];
1005 ls = find_lswitch(vtepctl_ctx, ls_cfg->name, true);
1007 shash_add_nocopy(&port->bindings, vlan, ls);
1011 sset_destroy(&pswitches);
1014 static struct vtep_ctl_pswitch *
1015 find_pswitch(struct vtep_ctl_context *vtepctl_ctx, const char *name, bool must_exist)
1017 struct vtep_ctl_pswitch *ps;
1019 ovs_assert(vtepctl_ctx->cache_valid);
1021 ps = shash_find_data(&vtepctl_ctx->pswitches, name);
1022 if (must_exist && !ps) {
1023 ctl_fatal("no physical switch named %s", name);
1025 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
1029 static struct vtep_ctl_port *
1030 find_port(struct vtep_ctl_context *vtepctl_ctx, const char *ps_name,
1031 const char *port_name, bool must_exist)
1033 char *cache_name = xasprintf("%s+%s", ps_name, port_name);
1034 struct vtep_ctl_port *port;
1036 ovs_assert(vtepctl_ctx->cache_valid);
1038 port = shash_find_data(&vtepctl_ctx->ports, cache_name);
1039 if (port && !strcmp(port_name, port->ps->name)) {
1043 if (must_exist && !port) {
1044 ctl_fatal("no port named %s", port_name);
1046 verify_ports(vtepctl_ctx);
1051 pswitch_insert_port(const struct vteprec_physical_switch *ps,
1052 struct vteprec_physical_port *port)
1054 struct vteprec_physical_port **ports;
1057 ports = xmalloc(sizeof *ps->ports * (ps->n_ports + 1));
1058 for (i = 0; i < ps->n_ports; i++) {
1059 ports[i] = ps->ports[i];
1061 ports[ps->n_ports] = port;
1062 vteprec_physical_switch_set_ports(ps, ports, ps->n_ports + 1);
1067 pswitch_delete_port(const struct vteprec_physical_switch *ps,
1068 const struct vteprec_physical_port *port)
1070 struct vteprec_physical_port **ports;
1073 ports = xmalloc(sizeof *ps->ports * ps->n_ports);
1074 for (i = n = 0; i < ps->n_ports; i++) {
1075 if (ps->ports[i] != port) {
1076 ports[n++] = ps->ports[i];
1079 vteprec_physical_switch_set_ports(ps, ports, n);
1084 vtep_insert_pswitch(const struct vteprec_global *vtep_global,
1085 struct vteprec_physical_switch *ps)
1087 struct vteprec_physical_switch **pswitches;
1090 pswitches = xmalloc(sizeof *vtep_global->switches
1091 * (vtep_global->n_switches + 1));
1092 for (i = 0; i < vtep_global->n_switches; i++) {
1093 pswitches[i] = vtep_global->switches[i];
1095 pswitches[vtep_global->n_switches] = ps;
1096 vteprec_global_set_switches(vtep_global, pswitches,
1097 vtep_global->n_switches + 1);
1102 cmd_add_ps(struct ctl_context *ctx)
1104 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1105 const char *ps_name = ctx->argv[1];
1106 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1107 struct vteprec_physical_switch *ps;
1109 vtep_ctl_context_populate_cache(ctx);
1110 if (find_pswitch(vtepctl_ctx, ps_name, false)) {
1112 ctl_fatal("cannot create physical switch %s because it "
1113 "already exists", ps_name);
1118 ps = vteprec_physical_switch_insert(ctx->txn);
1119 vteprec_physical_switch_set_name(ps, ps_name);
1121 vtep_insert_pswitch(vtepctl_ctx->vtep_global, ps);
1123 vtep_ctl_context_invalidate_cache(ctx);
1127 del_port(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_port *port)
1129 pswitch_delete_port(port->ps->ps_cfg, port->port_cfg);
1130 del_cached_port(vtepctl_ctx, port);
1134 del_pswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_pswitch *ps)
1136 struct vtep_ctl_port *port, *next_port;
1138 LIST_FOR_EACH_SAFE (port, next_port, ports_node, &ps->ports) {
1139 del_port(vtepctl_ctx, port);
1142 del_cached_pswitch(vtepctl_ctx, ps);
1146 cmd_del_ps(struct ctl_context *ctx)
1148 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1149 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1150 struct vtep_ctl_pswitch *ps;
1152 vtep_ctl_context_populate_cache(ctx);
1153 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1155 del_pswitch(vtepctl_ctx, ps);
1160 output_sorted(struct svec *svec, struct ds *output)
1166 SVEC_FOR_EACH (i, name, svec) {
1167 ds_put_format(output, "%s\n", name);
1172 cmd_list_ps(struct ctl_context *ctx)
1174 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1175 struct shash_node *node;
1176 struct svec pswitches;
1178 vtep_ctl_context_populate_cache(ctx);
1180 svec_init(&pswitches);
1181 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
1182 struct vtep_ctl_pswitch *ps = node->data;
1184 svec_add(&pswitches, ps->name);
1186 output_sorted(&pswitches, &ctx->output);
1187 svec_destroy(&pswitches);
1191 cmd_ps_exists(struct ctl_context *ctx)
1193 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1195 vtep_ctl_context_populate_cache(ctx);
1196 if (!find_pswitch(vtepctl_ctx, ctx->argv[1], false)) {
1202 cmd_list_ports(struct ctl_context *ctx)
1204 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1205 struct vtep_ctl_pswitch *ps;
1206 struct vtep_ctl_port *port;
1209 vtep_ctl_context_populate_cache(ctx);
1210 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1211 vteprec_physical_switch_verify_ports(ps->ps_cfg);
1214 LIST_FOR_EACH (port, ports_node, &ps->ports) {
1215 if (strcmp(port->port_cfg->name, ps->name)) {
1216 svec_add(&ports, port->port_cfg->name);
1219 output_sorted(&ports, &ctx->output);
1220 svec_destroy(&ports);
1224 add_port(struct ctl_context *ctx, const char *ps_name,
1225 const char *port_name, bool may_exist)
1227 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1228 struct vtep_ctl_port *vtep_ctl_port;
1229 struct vtep_ctl_pswitch *ps;
1230 struct vteprec_physical_port *port;
1232 vtep_ctl_context_populate_cache(ctx);
1234 vtep_ctl_port = find_port(vtepctl_ctx, ps_name, port_name, false);
1235 if (vtep_ctl_port) {
1237 ctl_fatal("cannot create a port named %s on %s because a "
1238 "port with that name already exists",
1239 port_name, ps_name);
1244 ps = find_pswitch(vtepctl_ctx, ps_name, true);
1246 port = vteprec_physical_port_insert(ctx->txn);
1247 vteprec_physical_port_set_name(port, port_name);
1249 pswitch_insert_port(ps->ps_cfg, port);
1251 add_port_to_cache(vtepctl_ctx, ps, port);
1255 cmd_add_port(struct ctl_context *ctx)
1257 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1259 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist);
1263 cmd_del_port(struct ctl_context *ctx)
1265 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1266 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1267 struct vtep_ctl_port *port;
1269 vtep_ctl_context_populate_cache(ctx);
1271 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], must_exist);
1273 if (ctx->argc == 3) {
1274 struct vtep_ctl_pswitch *ps;
1276 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1277 if (port->ps != ps) {
1278 ctl_fatal("physical switch %s does not have a port %s",
1279 ctx->argv[1], ctx->argv[2]);
1283 del_port(vtepctl_ctx, port);
1287 static struct vtep_ctl_lswitch *
1288 find_lswitch(struct vtep_ctl_context *vtepctl_ctx,
1289 const char *name, bool must_exist)
1291 struct vtep_ctl_lswitch *ls;
1293 ovs_assert(vtepctl_ctx->cache_valid);
1295 ls = shash_find_data(&vtepctl_ctx->lswitches, name);
1296 if (must_exist && !ls) {
1297 ctl_fatal("no logical switch named %s", name);
1303 cmd_add_ls(struct ctl_context *ctx)
1305 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1306 const char *ls_name = ctx->argv[1];
1307 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1308 struct vteprec_logical_switch *ls;
1310 vtep_ctl_context_populate_cache(ctx);
1311 if (find_lswitch(vtepctl_ctx, ls_name, false)) {
1313 ctl_fatal("cannot create logical switch %s because it "
1314 "already exists", ls_name);
1319 ls = vteprec_logical_switch_insert(ctx->txn);
1320 vteprec_logical_switch_set_name(ls, ls_name);
1322 vtep_ctl_context_invalidate_cache(ctx);
1326 del_lswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_lswitch *ls)
1328 del_cached_lswitch(vtepctl_ctx, ls);
1332 cmd_del_ls(struct ctl_context *ctx)
1334 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1335 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1336 struct vtep_ctl_lswitch *ls;
1338 vtep_ctl_context_populate_cache(ctx);
1339 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1341 del_lswitch(vtepctl_ctx, ls);
1346 cmd_list_ls(struct ctl_context *ctx)
1348 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1349 struct shash_node *node;
1350 struct svec lswitches;
1352 vtep_ctl_context_populate_cache(ctx);
1354 svec_init(&lswitches);
1355 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
1356 struct vtep_ctl_lswitch *ls = node->data;
1358 svec_add(&lswitches, ls->name);
1360 output_sorted(&lswitches, &ctx->output);
1361 svec_destroy(&lswitches);
1365 cmd_ls_exists(struct ctl_context *ctx)
1367 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1369 vtep_ctl_context_populate_cache(ctx);
1370 if (!find_lswitch(vtepctl_ctx, ctx->argv[1], false)) {
1376 cmd_list_bindings(struct ctl_context *ctx)
1378 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1379 const struct shash_node *node;
1380 struct vtep_ctl_port *port;
1381 struct svec bindings;
1383 vtep_ctl_context_populate_cache(ctx);
1384 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1386 svec_init(&bindings);
1387 SHASH_FOR_EACH (node, &port->bindings) {
1388 struct vtep_ctl_lswitch *lswitch = node->data;
1391 binding = xasprintf("%04lld %s", strtoll(node->name, NULL, 0),
1393 svec_add_nocopy(&bindings, binding);
1395 output_sorted(&bindings, &ctx->output);
1396 svec_destroy(&bindings);
1400 cmd_bind_ls(struct ctl_context *ctx)
1402 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1403 struct vtep_ctl_lswitch *ls;
1404 struct vtep_ctl_port *port;
1407 vtep_ctl_context_populate_cache(ctx);
1409 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1410 vlan = ctx->argv[3];
1411 ls = find_lswitch(vtepctl_ctx, ctx->argv[4], true);
1413 add_ls_binding_to_cache(port, vlan, ls);
1414 commit_ls_bindings(port);
1416 vtep_ctl_context_invalidate_cache(ctx);
1420 cmd_unbind_ls(struct ctl_context *ctx)
1422 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1423 struct vtep_ctl_port *port;
1426 vtep_ctl_context_populate_cache(ctx);
1428 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1429 vlan = ctx->argv[3];
1431 del_cached_ls_binding(port, vlan);
1432 commit_ls_bindings(port);
1434 vtep_ctl_context_invalidate_cache(ctx);
1438 add_ucast_entry(struct ctl_context *ctx, bool local)
1440 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1441 struct vtep_ctl_lswitch *ls;
1445 struct vteprec_physical_locator *ploc_cfg;
1447 vtep_ctl_context_populate_cache(ctx);
1449 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1452 if (ctx->argc == 4) {
1453 encap = "vxlan_over_ipv4";
1454 dst_ip = ctx->argv[3];
1456 encap = ctx->argv[3];
1457 dst_ip = ctx->argv[4];
1460 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1462 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1463 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1464 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1466 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1470 struct vteprec_ucast_macs_local *ucast_cfg;
1472 ucast_cfg = shash_find_data(&ls->ucast_local, mac);
1474 ucast_cfg = vteprec_ucast_macs_local_insert(ctx->txn);
1475 vteprec_ucast_macs_local_set_MAC(ucast_cfg, mac);
1476 vteprec_ucast_macs_local_set_logical_switch(ucast_cfg, ls->ls_cfg);
1477 shash_add(&ls->ucast_local, mac, ucast_cfg);
1479 vteprec_ucast_macs_local_set_locator(ucast_cfg, ploc_cfg);
1481 struct vteprec_ucast_macs_remote *ucast_cfg;
1483 ucast_cfg = shash_find_data(&ls->ucast_remote, mac);
1485 ucast_cfg = vteprec_ucast_macs_remote_insert(ctx->txn);
1486 vteprec_ucast_macs_remote_set_MAC(ucast_cfg, mac);
1487 vteprec_ucast_macs_remote_set_logical_switch(ucast_cfg, ls->ls_cfg);
1488 shash_add(&ls->ucast_remote, mac, ucast_cfg);
1490 vteprec_ucast_macs_remote_set_locator(ucast_cfg, ploc_cfg);
1493 vtep_ctl_context_invalidate_cache(ctx);
1497 cmd_add_ucast_local(struct ctl_context *ctx)
1499 add_ucast_entry(ctx, true);
1503 cmd_add_ucast_remote(struct ctl_context *ctx)
1505 add_ucast_entry(ctx, false);
1509 del_ucast_entry(struct ctl_context *ctx, bool local)
1511 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1512 struct vtep_ctl_lswitch *ls;
1513 struct shash *ucast_shash;
1514 struct shash_node *node;
1516 vtep_ctl_context_populate_cache(ctx);
1518 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1519 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1521 node = shash_find(ucast_shash, ctx->argv[2]);
1527 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1528 vteprec_ucast_macs_local_delete(ucast_cfg);
1530 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1531 vteprec_ucast_macs_remote_delete(ucast_cfg);
1533 shash_delete(ucast_shash, node);
1535 vtep_ctl_context_invalidate_cache(ctx);
1539 cmd_del_ucast_local(struct ctl_context *ctx)
1541 del_ucast_entry(ctx, true);
1545 cmd_del_ucast_remote(struct ctl_context *ctx)
1547 del_ucast_entry(ctx, false);
1551 commit_mcast_entries(struct vtep_ctl_mcast_mac *mcast_mac)
1553 struct vtep_ctl_ploc *ploc;
1554 struct vteprec_physical_locator **locators = NULL;
1558 n_locators = list_size(&mcast_mac->locators);
1559 ovs_assert(n_locators);
1561 locators = xmalloc(n_locators * sizeof *locators);
1564 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1565 locators[i] = (struct vteprec_physical_locator *)ploc->ploc_cfg;
1569 vteprec_physical_locator_set_set_locators(mcast_mac->ploc_set_cfg,
1577 add_mcast_entry(struct ctl_context *ctx,
1578 struct vtep_ctl_lswitch *ls, const char *mac,
1579 const char *encap, const char *dst_ip, bool local)
1581 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1582 struct shash *mcast_shash;
1583 struct vtep_ctl_mcast_mac *mcast_mac;
1584 struct vteprec_physical_locator *ploc_cfg;
1585 struct vteprec_physical_locator_set *ploc_set_cfg;
1587 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1589 /* Physical locator sets are immutable, so allocate a new one. */
1590 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1592 mcast_mac = shash_find_data(mcast_shash, mac);
1594 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mac, ploc_set_cfg,
1598 mcast_mac->local_cfg = vteprec_mcast_macs_local_insert(ctx->txn);
1599 vteprec_mcast_macs_local_set_MAC(mcast_mac->local_cfg, mac);
1600 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1602 vteprec_mcast_macs_local_set_logical_switch(mcast_mac->local_cfg,
1604 mcast_mac->remote_cfg = NULL;
1606 mcast_mac->remote_cfg = vteprec_mcast_macs_remote_insert(ctx->txn);
1607 vteprec_mcast_macs_remote_set_MAC(mcast_mac->remote_cfg, mac);
1608 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1610 vteprec_mcast_macs_remote_set_logical_switch(mcast_mac->remote_cfg,
1612 mcast_mac->local_cfg = NULL;
1615 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1617 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1620 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1625 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1627 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1628 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1629 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1631 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1634 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
1635 commit_mcast_entries(mcast_mac);
1639 del_mcast_entry(struct ctl_context *ctx,
1640 struct vtep_ctl_lswitch *ls, const char *mac,
1641 const char *encap, const char *dst_ip, bool local)
1643 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1644 struct vtep_ctl_mcast_mac *mcast_mac;
1645 struct shash *mcast_shash;
1646 struct vteprec_physical_locator *ploc_cfg;
1647 struct vteprec_physical_locator_set *ploc_set_cfg;
1649 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1651 mcast_mac = shash_find_data(mcast_shash, mac);
1656 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1658 /* Couldn't find the physical locator, so just ignore. */
1662 /* Physical locator sets are immutable, so allocate a new one. */
1663 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1664 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1666 del_ploc_from_mcast_mac(mcast_mac, ploc_cfg);
1667 if (list_is_empty(&mcast_mac->locators)) {
1668 struct shash_node *node = shash_find(mcast_shash, mac);
1670 vteprec_physical_locator_set_delete(ploc_set_cfg);
1673 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1675 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1679 shash_delete(mcast_shash, node);
1682 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1685 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1688 commit_mcast_entries(mcast_mac);
1693 add_del_mcast_entry(struct ctl_context *ctx, bool add, bool local)
1695 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1696 struct vtep_ctl_lswitch *ls;
1701 vtep_ctl_context_populate_cache(ctx);
1703 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1706 if (ctx->argc == 4) {
1707 encap = "vxlan_over_ipv4";
1708 dst_ip = ctx->argv[3];
1710 encap = ctx->argv[3];
1711 dst_ip = ctx->argv[4];
1715 add_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1717 del_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1720 vtep_ctl_context_invalidate_cache(ctx);
1724 cmd_add_mcast_local(struct ctl_context *ctx)
1726 add_del_mcast_entry(ctx, true, true);
1730 cmd_add_mcast_remote(struct ctl_context *ctx)
1732 add_del_mcast_entry(ctx, true, false);
1736 cmd_del_mcast_local(struct ctl_context *ctx)
1738 add_del_mcast_entry(ctx, false, true);
1742 cmd_del_mcast_remote(struct ctl_context *ctx)
1744 add_del_mcast_entry(ctx, false, false);
1748 clear_macs(struct ctl_context *ctx, bool local)
1750 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1751 struct vtep_ctl_lswitch *ls;
1752 const struct shash_node *node;
1753 struct shash *ucast_shash;
1754 struct shash *mcast_shash;
1756 vtep_ctl_context_populate_cache(ctx);
1757 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1759 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1760 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1762 SHASH_FOR_EACH (node, ucast_shash) {
1764 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1765 vteprec_ucast_macs_local_delete(ucast_cfg);
1767 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1768 vteprec_ucast_macs_remote_delete(ucast_cfg);
1772 SHASH_FOR_EACH (node, mcast_shash) {
1773 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1775 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1777 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1781 vtep_ctl_context_invalidate_cache(ctx);
1785 cmd_clear_local_macs(struct ctl_context *ctx)
1787 clear_macs(ctx, true);
1791 cmd_clear_remote_macs(struct ctl_context *ctx)
1793 clear_macs(ctx, false);
1797 list_macs(struct ctl_context *ctx, bool local)
1799 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1800 struct vtep_ctl_lswitch *ls;
1801 const struct shash_node *node;
1802 struct shash *ucast_shash;
1803 struct svec ucast_macs;
1804 struct shash *mcast_shash;
1805 struct svec mcast_macs;
1807 vtep_ctl_context_populate_cache(ctx);
1808 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1810 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1811 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1813 svec_init(&ucast_macs);
1814 SHASH_FOR_EACH (node, ucast_shash) {
1815 struct vteprec_ucast_macs_local *ucast_local = node->data;
1816 struct vteprec_ucast_macs_remote *ucast_remote = node->data;
1817 struct vteprec_physical_locator *ploc_cfg;
1820 ploc_cfg = local ? ucast_local->locator : ucast_remote->locator;
1822 entry = xasprintf(" %s -> %s/%s", node->name,
1823 ploc_cfg->encapsulation_type, ploc_cfg->dst_ip);
1824 svec_add_nocopy(&ucast_macs, entry);
1826 ds_put_format(&ctx->output, "ucast-mac-%s\n", local ? "local" : "remote");
1827 output_sorted(&ucast_macs, &ctx->output);
1828 ds_put_char(&ctx->output, '\n');
1829 svec_destroy(&ucast_macs);
1831 svec_init(&mcast_macs);
1832 SHASH_FOR_EACH (node, mcast_shash) {
1833 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1834 struct vtep_ctl_ploc *ploc;
1837 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1838 entry = xasprintf(" %s -> %s/%s", node->name,
1839 ploc->ploc_cfg->encapsulation_type,
1840 ploc->ploc_cfg->dst_ip);
1841 svec_add_nocopy(&mcast_macs, entry);
1844 ds_put_format(&ctx->output, "mcast-mac-%s\n", local ? "local" : "remote");
1845 output_sorted(&mcast_macs, &ctx->output);
1846 ds_put_char(&ctx->output, '\n');
1847 svec_destroy(&mcast_macs);
1851 cmd_list_local_macs(struct ctl_context *ctx)
1853 list_macs(ctx, true);
1857 cmd_list_remote_macs(struct ctl_context *ctx)
1859 list_macs(ctx, false);
1863 verify_managers(const struct vteprec_global *vtep_global)
1867 vteprec_global_verify_managers(vtep_global);
1869 for (i = 0; i < vtep_global->n_managers; ++i) {
1870 const struct vteprec_manager *mgr = vtep_global->managers[i];
1872 vteprec_manager_verify_target(mgr);
1877 pre_manager(struct ctl_context *ctx)
1879 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_managers);
1880 ovsdb_idl_add_column(ctx->idl, &vteprec_manager_col_target);
1884 cmd_get_manager(struct ctl_context *ctx)
1886 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1887 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1888 struct svec targets;
1891 verify_managers(vtep_global);
1893 /* Print the targets in sorted order for reproducibility. */
1894 svec_init(&targets);
1896 for (i = 0; i < vtep_global->n_managers; i++) {
1897 svec_add(&targets, vtep_global->managers[i]->target);
1900 svec_sort_unique(&targets);
1901 for (i = 0; i < targets.n; i++) {
1902 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
1904 svec_destroy(&targets);
1908 delete_managers(const struct vtep_ctl_context *vtepctl_ctx)
1910 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1913 /* Delete Manager rows pointed to by 'managers' column. */
1914 for (i = 0; i < vtep_global->n_managers; i++) {
1915 vteprec_manager_delete(vtep_global->managers[i]);
1918 /* Delete 'Manager' row refs in 'managers' column. */
1919 vteprec_global_set_managers(vtep_global, NULL, 0);
1923 cmd_del_manager(struct ctl_context *ctx)
1925 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1926 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1928 verify_managers(vtep_global);
1929 delete_managers(vtepctl_ctx);
1933 insert_managers(struct vtep_ctl_context *vtepctl_ctx, char *targets[], size_t n)
1935 struct vteprec_manager **managers;
1938 /* Insert each manager in a new row in Manager table. */
1939 managers = xmalloc(n * sizeof *managers);
1940 for (i = 0; i < n; i++) {
1941 if (stream_verify_name(targets[i]) && pstream_verify_name(targets[i])) {
1942 VLOG_WARN("target type \"%s\" is possibly erroneous", targets[i]);
1944 managers[i] = vteprec_manager_insert(vtepctl_ctx->base.txn);
1945 vteprec_manager_set_target(managers[i], targets[i]);
1948 /* Store uuids of new Manager rows in 'managers' column. */
1949 vteprec_global_set_managers(vtepctl_ctx->vtep_global, managers, n);
1954 cmd_set_manager(struct ctl_context *ctx)
1956 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1957 const size_t n = ctx->argc - 1;
1959 verify_managers(vtepctl_ctx->vtep_global);
1960 delete_managers(vtepctl_ctx);
1961 insert_managers(vtepctl_ctx, &ctx->argv[1], n);
1964 /* Parameter commands. */
1965 static const struct ctl_table_class tables[] = {
1966 {&vteprec_table_global,
1967 {{&vteprec_table_global, NULL, NULL},
1968 {NULL, NULL, NULL}}},
1970 {&vteprec_table_logical_binding_stats,
1971 {{NULL, NULL, NULL},
1972 {NULL, NULL, NULL}}},
1974 {&vteprec_table_logical_switch,
1975 {{&vteprec_table_logical_switch, &vteprec_logical_switch_col_name, NULL},
1976 {NULL, NULL, NULL}}},
1978 {&vteprec_table_ucast_macs_local,
1979 {{NULL, NULL, NULL},
1980 {NULL, NULL, NULL}}},
1982 {&vteprec_table_ucast_macs_remote,
1983 {{NULL, NULL, NULL},
1984 {NULL, NULL, NULL}}},
1986 {&vteprec_table_mcast_macs_local,
1987 {{NULL, NULL, NULL},
1988 {NULL, NULL, NULL}}},
1990 {&vteprec_table_mcast_macs_remote,
1991 {{NULL, NULL, NULL},
1992 {NULL, NULL, NULL}}},
1994 {&vteprec_table_manager,
1995 {{&vteprec_table_manager, &vteprec_manager_col_target, NULL},
1996 {NULL, NULL, NULL}}},
1998 {&vteprec_table_physical_locator,
1999 {{NULL, NULL, NULL},
2000 {NULL, NULL, NULL}}},
2002 {&vteprec_table_physical_locator_set,
2003 {{NULL, NULL, NULL},
2004 {NULL, NULL, NULL}}},
2006 {&vteprec_table_physical_port,
2007 {{&vteprec_table_physical_port, &vteprec_physical_port_col_name, NULL},
2008 {NULL, NULL, NULL}}},
2010 {&vteprec_table_physical_switch,
2011 {{&vteprec_table_physical_switch, &vteprec_physical_switch_col_name, NULL},
2012 {NULL, NULL, NULL}}},
2014 {&vteprec_table_tunnel,
2015 {{NULL, NULL, NULL},
2016 {NULL, NULL, NULL}}},
2018 {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
2023 vtep_ctl_context_init_command(struct vtep_ctl_context *vtepctl_ctx,
2024 struct ctl_command *command)
2026 ctl_context_init_command(&vtepctl_ctx->base, command);
2027 vtepctl_ctx->verified_ports = false;
2032 vtep_ctl_context_init(struct vtep_ctl_context *vtepctl_ctx,
2033 struct ctl_command *command,
2034 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2035 const struct vteprec_global *vtep_global,
2036 struct ovsdb_symbol_table *symtab)
2038 ctl_context_init(&vtepctl_ctx->base, command, idl, txn, symtab,
2039 vtep_ctl_context_invalidate_cache);
2041 vtepctl_ctx->verified_ports = false;
2043 vtepctl_ctx->vtep_global = vtep_global;
2044 vtepctl_ctx->cache_valid = false;
2048 vtep_ctl_context_done_command(struct vtep_ctl_context *vtepctl_ctx,
2049 struct ctl_command *command)
2051 ctl_context_done_command(&vtepctl_ctx->base, command);
2055 vtep_ctl_context_done(struct vtep_ctl_context *vtepctl_ctx,
2056 struct ctl_command *command)
2058 ctl_context_done(&vtepctl_ctx->base, command);
2062 run_prerequisites(struct ctl_command *commands, size_t n_commands,
2063 struct ovsdb_idl *idl)
2065 struct ctl_command *c;
2067 ovsdb_idl_add_table(idl, &vteprec_table_global);
2068 for (c = commands; c < &commands[n_commands]; c++) {
2069 if (c->syntax->prerequisites) {
2070 struct vtep_ctl_context vtepctl_ctx;
2072 ds_init(&c->output);
2075 vtep_ctl_context_init(&vtepctl_ctx, c, idl, NULL, NULL, NULL);
2076 (c->syntax->prerequisites)(&vtepctl_ctx.base);
2077 vtep_ctl_context_done(&vtepctl_ctx, c);
2079 ovs_assert(!c->output.string);
2080 ovs_assert(!c->table);
2086 do_vtep_ctl(const char *args, struct ctl_command *commands,
2087 size_t n_commands, struct ovsdb_idl *idl)
2089 struct ovsdb_idl_txn *txn;
2090 const struct vteprec_global *vtep_global;
2091 enum ovsdb_idl_txn_status status;
2092 struct ovsdb_symbol_table *symtab;
2093 struct vtep_ctl_context vtepctl_ctx;
2094 struct ctl_command *c;
2095 struct shash_node *node;
2098 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
2100 ovsdb_idl_txn_set_dry_run(txn);
2103 ovsdb_idl_txn_add_comment(txn, "vtep-ctl: %s", args);
2105 vtep_global = vteprec_global_first(idl);
2107 /* XXX add verification that table is empty */
2108 vtep_global = vteprec_global_insert(txn);
2111 symtab = ovsdb_symbol_table_create();
2112 for (c = commands; c < &commands[n_commands]; c++) {
2113 ds_init(&c->output);
2116 vtep_ctl_context_init(&vtepctl_ctx, NULL, idl, txn, vtep_global, symtab);
2117 for (c = commands; c < &commands[n_commands]; c++) {
2118 vtep_ctl_context_init_command(&vtepctl_ctx, c);
2119 if (c->syntax->run) {
2120 (c->syntax->run)(&vtepctl_ctx.base);
2122 vtep_ctl_context_done_command(&vtepctl_ctx, c);
2124 if (vtepctl_ctx.base.try_again) {
2125 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2129 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2131 SHASH_FOR_EACH (node, &symtab->sh) {
2132 struct ovsdb_symbol *symbol = node->data;
2133 if (!symbol->created) {
2134 ctl_fatal("row id \"%s\" is referenced but never created "
2135 "(e.g. with \"-- --id=%s create ...\")",
2136 node->name, node->name);
2138 if (!symbol->strong_ref) {
2139 if (!symbol->weak_ref) {
2140 VLOG_WARN("row id \"%s\" was created but no reference to it "
2141 "was inserted, so it will not actually appear in "
2142 "the database", node->name);
2144 VLOG_WARN("row id \"%s\" was created but only a weak "
2145 "reference to it was inserted, so it will not "
2146 "actually appear in the database", node->name);
2151 status = ovsdb_idl_txn_commit_block(txn);
2152 if (status == TXN_UNCHANGED || status == TXN_SUCCESS) {
2153 for (c = commands; c < &commands[n_commands]; c++) {
2154 if (c->syntax->postprocess) {
2155 vtep_ctl_context_init(&vtepctl_ctx, c, idl, txn, vtep_global, symtab);
2156 (c->syntax->postprocess)(&vtepctl_ctx.base);
2157 vtep_ctl_context_done(&vtepctl_ctx, c);
2161 error = xstrdup(ovsdb_idl_txn_get_error(txn));
2162 ovsdb_idl_txn_destroy(txn);
2163 txn = the_idl_txn = NULL;
2166 case TXN_UNCOMMITTED:
2167 case TXN_INCOMPLETE:
2171 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2172 ctl_fatal("transaction aborted");
2182 ctl_fatal("transaction error: %s", error);
2184 case TXN_NOT_LOCKED:
2185 /* Should not happen--we never call ovsdb_idl_set_lock(). */
2186 ctl_fatal("database not locked");
2193 ovsdb_symbol_table_destroy(symtab);
2195 for (c = commands; c < &commands[n_commands]; c++) {
2196 struct ds *ds = &c->output;
2199 table_print(c->table, &table_style);
2200 } else if (oneline) {
2204 for (j = 0; j < ds->length; j++) {
2205 int ch = ds->string[j];
2208 fputs("\\n", stdout);
2212 fputs("\\\\", stdout);
2221 fputs(ds_cstr(ds), stdout);
2223 ds_destroy(&c->output);
2224 table_destroy(c->table);
2227 shash_destroy_free_data(&c->options);
2231 ovsdb_idl_destroy(idl);
2236 /* Our transaction needs to be rerun, or a prerequisite was not met. Free
2237 * resources and return so that the caller can try again. */
2239 ovsdb_idl_txn_abort(txn);
2240 ovsdb_idl_txn_destroy(txn);
2242 ovsdb_symbol_table_destroy(symtab);
2243 for (c = commands; c < &commands[n_commands]; c++) {
2244 ds_destroy(&c->output);
2245 table_destroy(c->table);
2251 static const struct ctl_command_syntax vtep_commands[] = {
2252 /* Physical Switch commands. */
2253 {"add-ps", 1, 1, NULL, pre_get_info, cmd_add_ps, NULL, "--may-exist", RW},
2254 {"del-ps", 1, 1, NULL, pre_get_info, cmd_del_ps, NULL, "--if-exists", RW},
2255 {"list-ps", 0, 0, NULL, pre_get_info, cmd_list_ps, NULL, "", RO},
2256 {"ps-exists", 1, 1, NULL, pre_get_info, cmd_ps_exists, NULL, "", RO},
2258 /* Port commands. */
2259 {"list-ports", 1, 1, NULL, pre_get_info, cmd_list_ports, NULL, "", RO},
2260 {"add-port", 2, 2, NULL, pre_get_info, cmd_add_port, NULL, "--may-exist",
2262 {"del-port", 2, 2, NULL, pre_get_info, cmd_del_port, NULL, "--if-exists",
2265 /* Logical Switch commands. */
2266 {"add-ls", 1, 1, NULL, pre_get_info, cmd_add_ls, NULL, "--may-exist", RW},
2267 {"del-ls", 1, 1, NULL, pre_get_info, cmd_del_ls, NULL, "--if-exists", RW},
2268 {"list-ls", 0, 0, NULL, pre_get_info, cmd_list_ls, NULL, "", RO},
2269 {"ls-exists", 1, 1, NULL, pre_get_info, cmd_ls_exists, NULL, "", RO},
2270 {"list-bindings", 2, 2, NULL, pre_get_info, cmd_list_bindings, NULL, "", RO},
2271 {"bind-ls", 4, 4, NULL, pre_get_info, cmd_bind_ls, NULL, "", RO},
2272 {"unbind-ls", 3, 3, NULL, pre_get_info, cmd_unbind_ls, NULL, "", RO},
2274 /* MAC binding commands. */
2275 {"add-ucast-local", 3, 4, NULL, pre_get_info, cmd_add_ucast_local, NULL,
2277 {"del-ucast-local", 2, 2, NULL, pre_get_info, cmd_del_ucast_local, NULL,
2279 {"add-mcast-local", 3, 4, NULL, pre_get_info, cmd_add_mcast_local, NULL,
2281 {"del-mcast-local", 3, 4, NULL, pre_get_info, cmd_del_mcast_local, NULL,
2283 {"clear-local-macs", 1, 1, NULL, pre_get_info, cmd_clear_local_macs, NULL,
2285 {"list-local-macs", 1, 1, NULL, pre_get_info, cmd_list_local_macs, NULL,
2287 {"add-ucast-remote", 3, 4, NULL, pre_get_info, cmd_add_ucast_remote, NULL,
2289 {"del-ucast-remote", 2, 2, NULL, pre_get_info, cmd_del_ucast_remote, NULL,
2291 {"add-mcast-remote", 3, 4, NULL, pre_get_info, cmd_add_mcast_remote, NULL,
2293 {"del-mcast-remote", 3, 4, NULL, pre_get_info, cmd_del_mcast_remote, NULL,
2295 {"clear-remote-macs", 1, 1, NULL, pre_get_info, cmd_clear_remote_macs, NULL,
2297 {"list-remote-macs", 1, 1, NULL, pre_get_info, cmd_list_remote_macs, NULL,
2300 /* Manager commands. */
2301 {"get-manager", 0, 0, NULL, pre_manager, cmd_get_manager, NULL, "", RO},
2302 {"del-manager", 0, 0, NULL, pre_manager, cmd_del_manager, NULL, "", RW},
2303 {"set-manager", 1, INT_MAX, NULL, pre_manager, cmd_set_manager, NULL, "",
2306 {NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, RO},
2309 /* Registers vsctl and common db commands. */
2311 vtep_ctl_cmd_init(void)
2314 ctl_register_commands(vtep_commands);