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_tunnel_ips,
361 &vteprec_physical_switch_col_ports,
365 {&vteprec_table_physical_port,
366 &vteprec_physical_port_col_name,
367 {&vteprec_physical_port_col_vlan_bindings,
372 {NULL, NULL, {NULL, NULL, NULL}, false}
375 /* vtep-ctl specific context. Inherits the 'struct ctl_context' as base. */
376 struct vtep_ctl_context {
377 struct ctl_context base;
379 /* Modifiable state. */
380 const struct vteprec_global *vtep_global;
383 /* A cache of the contents of the database.
385 * A command that needs to use any of this information must first
386 * call vtep_ctl_context_populate_cache(). A command that changes
387 * anything that could invalidate the cache must either call
388 * vtep_ctl_context_invalidate_cache() or manually update the cache
389 * to maintain its correctness. */
391 struct shash pswitches; /* Maps from physical switch name to
392 * struct vtep_ctl_pswitch. */
393 struct shash ports; /* Maps from port name to struct vtep_ctl_port. */
395 struct shash lswitches; /* Maps from logical switch name to
396 * struct vtep_ctl_lswitch. */
397 struct shash plocs; /* Maps from "<encap>+<dst_ip>" to
398 * struct vteprec_physical_locator. */
401 /* Casts 'base' into 'strcut vtep_ctl_context'. */
402 static struct vtep_ctl_context *
403 vtep_ctl_context_cast(struct ctl_context *base)
405 return CONTAINER_OF(base, struct vtep_ctl_context, base);
408 struct vtep_ctl_pswitch {
409 const struct vteprec_physical_switch *ps_cfg;
411 struct ovs_list ports; /* Contains "struct vteprec_physical_port"s. */
414 struct vtep_ctl_port {
415 struct ovs_list ports_node; /* In struct vtep_ctl_pswitch's 'ports' list. */
416 const struct vteprec_physical_port *port_cfg;
417 struct vtep_ctl_pswitch *ps;
418 struct shash bindings; /* Maps from vlan to vtep_ctl_lswitch. */
421 struct vtep_ctl_lswitch {
422 const struct vteprec_logical_switch *ls_cfg;
424 struct shash ucast_local; /* Maps from mac to vteprec_ucast_macs_local. */
425 struct shash ucast_remote; /* Maps from mac to vteprec_ucast_macs_remote.*/
426 struct shash mcast_local; /* Maps from mac to vtep_ctl_mcast_mac. */
427 struct shash mcast_remote; /* Maps from mac to vtep_ctl_mcast_mac. */
430 struct vtep_ctl_mcast_mac {
431 const struct vteprec_mcast_macs_local *local_cfg;
432 const struct vteprec_mcast_macs_remote *remote_cfg;
434 const struct vteprec_physical_locator_set *ploc_set_cfg;
435 struct ovs_list locators; /* Contains 'vtep_ctl_ploc's. */
438 struct vtep_ctl_ploc {
439 struct ovs_list locators_node; /* In struct vtep_ctl_ploc_set's 'locators'
441 const struct vteprec_physical_locator *ploc_cfg;
445 verify_ports(struct vtep_ctl_context *vtepctl_ctx)
447 if (!vtepctl_ctx->verified_ports) {
448 const struct vteprec_physical_switch *ps;
450 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
451 VTEPREC_PHYSICAL_SWITCH_FOR_EACH (ps, vtepctl_ctx->base.idl) {
452 vteprec_physical_switch_verify_ports(ps);
455 vtepctl_ctx->verified_ports = true;
459 static struct vtep_ctl_port *
460 add_port_to_cache(struct vtep_ctl_context *vtepctl_ctx,
461 struct vtep_ctl_pswitch *ps,
462 struct vteprec_physical_port *port_cfg)
464 char *cache_name = xasprintf("%s+%s", ps->name, port_cfg->name);
465 struct vtep_ctl_port *port;
467 port = xmalloc(sizeof *port);
468 list_push_back(&ps->ports, &port->ports_node);
469 port->port_cfg = port_cfg;
471 shash_add(&vtepctl_ctx->ports, cache_name, port);
473 shash_init(&port->bindings);
479 del_cached_port(struct vtep_ctl_context *vtepctl_ctx,
480 struct vtep_ctl_port *port)
482 char *cache_name = xasprintf("%s+%s", port->ps->name, port->port_cfg->name);
484 list_remove(&port->ports_node);
485 shash_find_and_delete(&vtepctl_ctx->ports, cache_name);
486 vteprec_physical_port_delete(port->port_cfg);
491 static struct vtep_ctl_pswitch *
492 add_pswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
493 struct vteprec_physical_switch *ps_cfg)
495 struct vtep_ctl_pswitch *ps = xmalloc(sizeof *ps);
497 ps->name = xstrdup(ps_cfg->name);
498 list_init(&ps->ports);
499 shash_add(&vtepctl_ctx->pswitches, ps->name, ps);
504 vtep_delete_pswitch(const struct vteprec_global *vtep_global,
505 const struct vteprec_physical_switch *ps)
507 struct vteprec_physical_switch **pswitches;
510 pswitches = xmalloc(sizeof *vtep_global->switches
511 * vtep_global->n_switches);
512 for (i = n = 0; i < vtep_global->n_switches; i++) {
513 if (vtep_global->switches[i] != ps) {
514 pswitches[n++] = vtep_global->switches[i];
517 vteprec_global_set_switches(vtep_global, pswitches, n);
522 del_cached_pswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_pswitch *ps)
524 ovs_assert(list_is_empty(&ps->ports));
526 vteprec_physical_switch_delete(ps->ps_cfg);
527 vtep_delete_pswitch(ctx->vtep_global, ps->ps_cfg);
529 shash_find_and_delete(&ctx->pswitches, ps->name);
534 static struct vtep_ctl_lswitch *
535 add_lswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
536 const struct vteprec_logical_switch *ls_cfg)
538 struct vtep_ctl_lswitch *ls = xmalloc(sizeof *ls);
540 ls->name = xstrdup(ls_cfg->name);
541 shash_add(&vtepctl_ctx->lswitches, ls->name, ls);
542 shash_init(&ls->ucast_local);
543 shash_init(&ls->ucast_remote);
544 shash_init(&ls->mcast_local);
545 shash_init(&ls->mcast_remote);
550 del_cached_lswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_lswitch *ls)
553 vteprec_logical_switch_delete(ls->ls_cfg);
555 shash_find_and_delete(&ctx->lswitches, ls->name);
561 commit_ls_bindings(struct vtep_ctl_port *port)
563 struct vteprec_logical_switch **binding_values;
564 int64_t *binding_keys;
566 struct shash_node *node;
569 n_bindings = shash_count(&port->bindings);
570 binding_keys = xmalloc(n_bindings * sizeof *binding_keys);
571 binding_values = xmalloc(n_bindings * sizeof *binding_values);
574 SHASH_FOR_EACH(node, &port->bindings) {
575 struct vtep_ctl_lswitch *ls_entry = node->data;
577 binding_keys[i] = strtoll(node->name, NULL, 0);
578 binding_values[i] = (struct vteprec_logical_switch *)ls_entry->ls_cfg;
582 vteprec_physical_port_set_vlan_bindings(port->port_cfg,
583 binding_keys, binding_values,
585 free(binding_values);
590 add_ls_binding_to_cache(struct vtep_ctl_port *port,
592 struct vtep_ctl_lswitch *ls)
594 if (shash_find(&port->bindings, vlan)) {
595 ctl_fatal("multiple bindings for vlan %s", vlan);
598 shash_add(&port->bindings, vlan, ls);
602 del_cached_ls_binding(struct vtep_ctl_port *port, const char *vlan)
604 if (!shash_find(&port->bindings, vlan)) {
605 ctl_fatal("no binding for vlan %s", vlan);
608 shash_find_and_delete(&port->bindings, vlan);
611 static struct vteprec_physical_locator *
612 find_ploc(struct vtep_ctl_context *vtepctl_ctx, const char *encap,
615 struct vteprec_physical_locator *ploc;
616 char *name = xasprintf("%s+%s", encap, dst_ip);
618 ovs_assert(vtepctl_ctx->cache_valid);
620 ploc = shash_find_data(&vtepctl_ctx->plocs, name);
627 add_ploc_to_cache(struct vtep_ctl_context *vtepctl_ctx,
628 struct vteprec_physical_locator *ploc)
630 char *name = xasprintf("%s+%s", ploc->encapsulation_type, ploc->dst_ip);
631 struct vteprec_physical_locator *orig_ploc;
633 orig_ploc = find_ploc(vtepctl_ctx, ploc->encapsulation_type, ploc->dst_ip);
635 shash_add(&vtepctl_ctx->plocs, name, ploc);
642 add_ploc_to_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
643 struct vteprec_physical_locator *ploc_cfg)
645 struct vtep_ctl_ploc *ploc;
647 ploc = xmalloc(sizeof *ploc);
648 ploc->ploc_cfg = ploc_cfg;
649 list_push_back(&mcast_mac->locators, &ploc->locators_node);
653 del_ploc_from_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
654 struct vteprec_physical_locator *ploc_cfg)
656 struct vtep_ctl_ploc *ploc;
658 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
659 if (ploc->ploc_cfg == ploc_cfg) {
660 list_remove(&ploc->locators_node);
667 static struct vtep_ctl_mcast_mac *
668 add_mcast_mac_to_cache(struct vtep_ctl_context *vtepctl_ctx,
669 struct vtep_ctl_lswitch *ls, const char *mac,
670 struct vteprec_physical_locator_set *ploc_set_cfg,
673 struct vtep_ctl_mcast_mac *mcast_mac;
674 struct shash *mcast_shash;
677 mcast_mac = xmalloc(sizeof *mcast_mac);
678 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
680 mcast_mac->ploc_set_cfg = ploc_set_cfg;
681 list_init(&mcast_mac->locators);
682 shash_add(mcast_shash, mac, mcast_mac);
684 for (i = 0; i < ploc_set_cfg->n_locators; i++) {
685 struct vteprec_physical_locator *ploc_cfg;
687 ploc_cfg = ploc_set_cfg->locators[i];
688 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
689 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
696 vtep_ctl_context_invalidate_cache(struct ctl_context *ctx)
698 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
699 struct shash_node *node;
701 if (!vtepctl_ctx->cache_valid) {
704 vtepctl_ctx->cache_valid = false;
706 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
707 struct vtep_ctl_pswitch *ps = node->data;
711 shash_destroy(&vtepctl_ctx->pswitches);
713 SHASH_FOR_EACH (node, &vtepctl_ctx->ports) {
714 struct vtep_ctl_port *port = node->data;
715 shash_destroy(&port->bindings);
717 shash_destroy_free_data(&vtepctl_ctx->ports);
719 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
720 struct vtep_ctl_lswitch *ls = node->data;
721 struct shash_node *node2, *next_node2;
723 shash_destroy(&ls->ucast_local);
724 shash_destroy(&ls->ucast_remote);
726 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_local) {
727 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
728 struct vtep_ctl_ploc *ploc, *next_ploc;
730 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
731 &mcast_mac->locators) {
736 shash_destroy(&ls->mcast_local);
738 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_remote) {
739 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
740 struct vtep_ctl_ploc *ploc, *next_ploc;
742 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
743 &mcast_mac->locators) {
748 shash_destroy(&ls->mcast_remote);
753 shash_destroy(&vtepctl_ctx->lswitches);
754 shash_destroy(&vtepctl_ctx->plocs);
758 pre_get_info(struct ctl_context *ctx)
760 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_switches);
762 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_name);
763 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_ports);
764 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_tunnels);
766 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_name);
767 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_vlan_bindings);
769 ovsdb_idl_add_column(ctx->idl, &vteprec_logical_switch_col_name);
771 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_MAC);
772 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_locator);
773 ovsdb_idl_add_column(ctx->idl,
774 &vteprec_ucast_macs_local_col_logical_switch);
776 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_MAC);
777 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_locator);
778 ovsdb_idl_add_column(ctx->idl,
779 &vteprec_ucast_macs_remote_col_logical_switch);
781 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_local_col_MAC);
782 ovsdb_idl_add_column(ctx->idl,
783 &vteprec_mcast_macs_local_col_locator_set);
784 ovsdb_idl_add_column(ctx->idl,
785 &vteprec_mcast_macs_local_col_logical_switch);
787 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_remote_col_MAC);
788 ovsdb_idl_add_column(ctx->idl,
789 &vteprec_mcast_macs_remote_col_locator_set);
790 ovsdb_idl_add_column(ctx->idl,
791 &vteprec_mcast_macs_remote_col_logical_switch);
793 ovsdb_idl_add_column(ctx->idl,
794 &vteprec_physical_locator_set_col_locators);
796 ovsdb_idl_add_column(ctx->idl,
797 &vteprec_physical_locator_col_dst_ip);
798 ovsdb_idl_add_column(ctx->idl,
799 &vteprec_physical_locator_col_encapsulation_type);
801 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_local);
802 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_remote);
806 vtep_ctl_context_populate_cache(struct ctl_context *ctx)
808 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
809 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
810 const struct vteprec_logical_switch *ls_cfg;
811 const struct vteprec_ucast_macs_local *ucast_local_cfg;
812 const struct vteprec_ucast_macs_remote *ucast_remote_cfg;
813 const struct vteprec_mcast_macs_local *mcast_local_cfg;
814 const struct vteprec_mcast_macs_remote *mcast_remote_cfg;
815 const struct vteprec_tunnel *tunnel_cfg;
816 struct sset pswitches, ports, lswitches;
819 if (vtepctl_ctx->cache_valid) {
820 /* Cache is already populated. */
823 vtepctl_ctx->cache_valid = true;
824 shash_init(&vtepctl_ctx->pswitches);
825 shash_init(&vtepctl_ctx->ports);
826 shash_init(&vtepctl_ctx->lswitches);
827 shash_init(&vtepctl_ctx->plocs);
829 sset_init(&pswitches);
831 for (i = 0; i < vtep_global->n_switches; i++) {
832 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
833 struct vtep_ctl_pswitch *ps;
836 if (!sset_add(&pswitches, ps_cfg->name)) {
837 VLOG_WARN("%s: database contains duplicate physical switch name",
841 ps = add_pswitch_to_cache(vtepctl_ctx, ps_cfg);
846 for (j = 0; j < ps_cfg->n_ports; j++) {
847 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
849 if (!sset_add(&ports, port_cfg->name)) {
850 /* Duplicate port name. (We will warn about that later.) */
855 sset_destroy(&pswitches);
856 sset_destroy(&ports);
858 sset_init(&lswitches);
859 VTEPREC_LOGICAL_SWITCH_FOR_EACH (ls_cfg, ctx->idl) {
860 if (!sset_add(&lswitches, ls_cfg->name)) {
861 VLOG_WARN("%s: database contains duplicate logical switch name",
865 add_lswitch_to_cache(vtepctl_ctx, ls_cfg);
867 sset_destroy(&lswitches);
869 VTEPREC_UCAST_MACS_LOCAL_FOR_EACH (ucast_local_cfg, ctx->idl) {
870 struct vtep_ctl_lswitch *ls;
872 if (!ucast_local_cfg->logical_switch) {
875 ls = find_lswitch(vtepctl_ctx, ucast_local_cfg->logical_switch->name,
881 if (ucast_local_cfg->locator) {
882 add_ploc_to_cache(vtepctl_ctx, ucast_local_cfg->locator);
885 shash_add(&ls->ucast_local, ucast_local_cfg->MAC, ucast_local_cfg);
888 VTEPREC_UCAST_MACS_REMOTE_FOR_EACH (ucast_remote_cfg, ctx->idl) {
889 struct vtep_ctl_lswitch *ls;
891 if (!ucast_remote_cfg->logical_switch) {
894 ls = find_lswitch(vtepctl_ctx, ucast_remote_cfg->logical_switch->name,
900 if (ucast_remote_cfg->locator) {
901 add_ploc_to_cache(vtepctl_ctx, ucast_remote_cfg->locator);
904 shash_add(&ls->ucast_remote, ucast_remote_cfg->MAC, ucast_remote_cfg);
907 VTEPREC_MCAST_MACS_LOCAL_FOR_EACH (mcast_local_cfg, ctx->idl) {
908 struct vtep_ctl_mcast_mac *mcast_mac;
909 struct vtep_ctl_lswitch *ls;
911 if (!mcast_local_cfg->logical_switch) {
914 ls = find_lswitch(vtepctl_ctx, mcast_local_cfg->logical_switch->name,
920 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_local_cfg->MAC,
921 mcast_local_cfg->locator_set,
923 mcast_mac->local_cfg = mcast_local_cfg;
926 VTEPREC_MCAST_MACS_REMOTE_FOR_EACH (mcast_remote_cfg, ctx->idl) {
927 struct vtep_ctl_mcast_mac *mcast_mac;
928 struct vtep_ctl_lswitch *ls;
930 if (!mcast_remote_cfg->logical_switch) {
933 ls = find_lswitch(vtepctl_ctx, mcast_remote_cfg->logical_switch->name,
939 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_remote_cfg->MAC,
940 mcast_remote_cfg->locator_set,
942 mcast_mac->remote_cfg = mcast_remote_cfg;
945 VTEPREC_TUNNEL_FOR_EACH (tunnel_cfg, ctx->idl) {
946 if (tunnel_cfg->local) {
947 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->local);
949 if (tunnel_cfg->remote) {
950 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->remote);
954 sset_init(&pswitches);
955 for (i = 0; i < vtep_global->n_switches; i++) {
956 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
957 struct vtep_ctl_pswitch *ps;
960 if (!sset_add(&pswitches, ps_cfg->name)) {
963 ps = shash_find_data(&vtepctl_ctx->pswitches, ps_cfg->name);
964 for (j = 0; j < ps_cfg->n_ports; j++) {
965 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
966 struct vtep_ctl_port *port;
969 port = shash_find_data(&vtepctl_ctx->ports, port_cfg->name);
971 if (port_cfg == port->port_cfg) {
972 VLOG_WARN("%s: port is in multiple physical switches "
974 port_cfg->name, ps->name, port->ps->name);
976 /* Log as an error because this violates the database's
977 * uniqueness constraints, so the database server shouldn't
978 * have allowed it. */
979 VLOG_ERR("%s: database contains duplicate port name",
985 port = add_port_to_cache(vtepctl_ctx, ps, port_cfg);
987 for (k = 0; k < port_cfg->n_vlan_bindings; k++) {
988 struct vteprec_logical_switch *ls_cfg;
989 struct vtep_ctl_lswitch *ls;
992 vlan = xasprintf("%"PRId64, port_cfg->key_vlan_bindings[k]);
993 if (shash_find(&port->bindings, vlan)) {
994 ctl_fatal("multiple bindings for vlan %s", vlan);
997 ls_cfg = port_cfg->value_vlan_bindings[k];
998 ls = find_lswitch(vtepctl_ctx, ls_cfg->name, true);
1000 shash_add_nocopy(&port->bindings, vlan, ls);
1004 sset_destroy(&pswitches);
1007 static struct vtep_ctl_pswitch *
1008 find_pswitch(struct vtep_ctl_context *vtepctl_ctx, const char *name, bool must_exist)
1010 struct vtep_ctl_pswitch *ps;
1012 ovs_assert(vtepctl_ctx->cache_valid);
1014 ps = shash_find_data(&vtepctl_ctx->pswitches, name);
1015 if (must_exist && !ps) {
1016 ctl_fatal("no physical switch named %s", name);
1018 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
1022 static struct vtep_ctl_port *
1023 find_port(struct vtep_ctl_context *vtepctl_ctx, const char *ps_name,
1024 const char *port_name, bool must_exist)
1026 char *cache_name = xasprintf("%s+%s", ps_name, port_name);
1027 struct vtep_ctl_port *port;
1029 ovs_assert(vtepctl_ctx->cache_valid);
1031 port = shash_find_data(&vtepctl_ctx->ports, cache_name);
1032 if (port && !strcmp(port_name, port->ps->name)) {
1036 if (must_exist && !port) {
1037 ctl_fatal("no port named %s", port_name);
1039 verify_ports(vtepctl_ctx);
1044 pswitch_insert_port(const struct vteprec_physical_switch *ps,
1045 struct vteprec_physical_port *port)
1047 struct vteprec_physical_port **ports;
1050 ports = xmalloc(sizeof *ps->ports * (ps->n_ports + 1));
1051 for (i = 0; i < ps->n_ports; i++) {
1052 ports[i] = ps->ports[i];
1054 ports[ps->n_ports] = port;
1055 vteprec_physical_switch_set_ports(ps, ports, ps->n_ports + 1);
1060 pswitch_delete_port(const struct vteprec_physical_switch *ps,
1061 const struct vteprec_physical_port *port)
1063 struct vteprec_physical_port **ports;
1066 ports = xmalloc(sizeof *ps->ports * ps->n_ports);
1067 for (i = n = 0; i < ps->n_ports; i++) {
1068 if (ps->ports[i] != port) {
1069 ports[n++] = ps->ports[i];
1072 vteprec_physical_switch_set_ports(ps, ports, n);
1077 vtep_insert_pswitch(const struct vteprec_global *vtep_global,
1078 struct vteprec_physical_switch *ps)
1080 struct vteprec_physical_switch **pswitches;
1083 pswitches = xmalloc(sizeof *vtep_global->switches
1084 * (vtep_global->n_switches + 1));
1085 for (i = 0; i < vtep_global->n_switches; i++) {
1086 pswitches[i] = vtep_global->switches[i];
1088 pswitches[vtep_global->n_switches] = ps;
1089 vteprec_global_set_switches(vtep_global, pswitches,
1090 vtep_global->n_switches + 1);
1095 cmd_add_ps(struct ctl_context *ctx)
1097 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1098 const char *ps_name = ctx->argv[1];
1099 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1100 struct vteprec_physical_switch *ps;
1102 vtep_ctl_context_populate_cache(ctx);
1103 if (find_pswitch(vtepctl_ctx, ps_name, false)) {
1105 ctl_fatal("cannot create physical switch %s because it "
1106 "already exists", ps_name);
1111 ps = vteprec_physical_switch_insert(ctx->txn);
1112 vteprec_physical_switch_set_name(ps, ps_name);
1114 vtep_insert_pswitch(vtepctl_ctx->vtep_global, ps);
1116 vtep_ctl_context_invalidate_cache(ctx);
1120 del_port(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_port *port)
1122 pswitch_delete_port(port->ps->ps_cfg, port->port_cfg);
1123 del_cached_port(vtepctl_ctx, port);
1127 del_pswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_pswitch *ps)
1129 struct vtep_ctl_port *port, *next_port;
1131 LIST_FOR_EACH_SAFE (port, next_port, ports_node, &ps->ports) {
1132 del_port(vtepctl_ctx, port);
1135 del_cached_pswitch(vtepctl_ctx, ps);
1139 cmd_del_ps(struct ctl_context *ctx)
1141 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1142 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1143 struct vtep_ctl_pswitch *ps;
1145 vtep_ctl_context_populate_cache(ctx);
1146 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1148 del_pswitch(vtepctl_ctx, ps);
1153 output_sorted(struct svec *svec, struct ds *output)
1159 SVEC_FOR_EACH (i, name, svec) {
1160 ds_put_format(output, "%s\n", name);
1165 cmd_list_ps(struct ctl_context *ctx)
1167 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1168 struct shash_node *node;
1169 struct svec pswitches;
1171 vtep_ctl_context_populate_cache(ctx);
1173 svec_init(&pswitches);
1174 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
1175 struct vtep_ctl_pswitch *ps = node->data;
1177 svec_add(&pswitches, ps->name);
1179 output_sorted(&pswitches, &ctx->output);
1180 svec_destroy(&pswitches);
1184 cmd_ps_exists(struct ctl_context *ctx)
1186 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1188 vtep_ctl_context_populate_cache(ctx);
1189 if (!find_pswitch(vtepctl_ctx, ctx->argv[1], false)) {
1195 cmd_list_ports(struct ctl_context *ctx)
1197 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1198 struct vtep_ctl_pswitch *ps;
1199 struct vtep_ctl_port *port;
1202 vtep_ctl_context_populate_cache(ctx);
1203 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1204 vteprec_physical_switch_verify_ports(ps->ps_cfg);
1207 LIST_FOR_EACH (port, ports_node, &ps->ports) {
1208 if (strcmp(port->port_cfg->name, ps->name)) {
1209 svec_add(&ports, port->port_cfg->name);
1212 output_sorted(&ports, &ctx->output);
1213 svec_destroy(&ports);
1217 add_port(struct ctl_context *ctx, const char *ps_name,
1218 const char *port_name, bool may_exist)
1220 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1221 struct vtep_ctl_port *vtep_ctl_port;
1222 struct vtep_ctl_pswitch *ps;
1223 struct vteprec_physical_port *port;
1225 vtep_ctl_context_populate_cache(ctx);
1227 vtep_ctl_port = find_port(vtepctl_ctx, ps_name, port_name, false);
1228 if (vtep_ctl_port) {
1230 ctl_fatal("cannot create a port named %s on %s because a "
1231 "port with that name already exists",
1232 port_name, ps_name);
1237 ps = find_pswitch(vtepctl_ctx, ps_name, true);
1239 port = vteprec_physical_port_insert(ctx->txn);
1240 vteprec_physical_port_set_name(port, port_name);
1242 pswitch_insert_port(ps->ps_cfg, port);
1244 add_port_to_cache(vtepctl_ctx, ps, port);
1248 cmd_add_port(struct ctl_context *ctx)
1250 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1252 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist);
1256 cmd_del_port(struct ctl_context *ctx)
1258 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1259 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1260 struct vtep_ctl_port *port;
1262 vtep_ctl_context_populate_cache(ctx);
1264 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], must_exist);
1266 if (ctx->argc == 3) {
1267 struct vtep_ctl_pswitch *ps;
1269 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1270 if (port->ps != ps) {
1271 ctl_fatal("physical switch %s does not have a port %s",
1272 ctx->argv[1], ctx->argv[2]);
1276 del_port(vtepctl_ctx, port);
1280 static struct vtep_ctl_lswitch *
1281 find_lswitch(struct vtep_ctl_context *vtepctl_ctx,
1282 const char *name, bool must_exist)
1284 struct vtep_ctl_lswitch *ls;
1286 ovs_assert(vtepctl_ctx->cache_valid);
1288 ls = shash_find_data(&vtepctl_ctx->lswitches, name);
1289 if (must_exist && !ls) {
1290 ctl_fatal("no logical switch named %s", name);
1296 cmd_add_ls(struct ctl_context *ctx)
1298 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1299 const char *ls_name = ctx->argv[1];
1300 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1301 struct vteprec_logical_switch *ls;
1303 vtep_ctl_context_populate_cache(ctx);
1304 if (find_lswitch(vtepctl_ctx, ls_name, false)) {
1306 ctl_fatal("cannot create logical switch %s because it "
1307 "already exists", ls_name);
1312 ls = vteprec_logical_switch_insert(ctx->txn);
1313 vteprec_logical_switch_set_name(ls, ls_name);
1315 vtep_ctl_context_invalidate_cache(ctx);
1319 del_lswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_lswitch *ls)
1321 del_cached_lswitch(vtepctl_ctx, ls);
1325 cmd_del_ls(struct ctl_context *ctx)
1327 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1328 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1329 struct vtep_ctl_lswitch *ls;
1331 vtep_ctl_context_populate_cache(ctx);
1332 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1334 del_lswitch(vtepctl_ctx, ls);
1339 cmd_list_ls(struct ctl_context *ctx)
1341 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1342 struct shash_node *node;
1343 struct svec lswitches;
1345 vtep_ctl_context_populate_cache(ctx);
1347 svec_init(&lswitches);
1348 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
1349 struct vtep_ctl_lswitch *ls = node->data;
1351 svec_add(&lswitches, ls->name);
1353 output_sorted(&lswitches, &ctx->output);
1354 svec_destroy(&lswitches);
1358 cmd_ls_exists(struct ctl_context *ctx)
1360 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1362 vtep_ctl_context_populate_cache(ctx);
1363 if (!find_lswitch(vtepctl_ctx, ctx->argv[1], false)) {
1369 cmd_list_bindings(struct ctl_context *ctx)
1371 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1372 const struct shash_node *node;
1373 struct vtep_ctl_port *port;
1374 struct svec bindings;
1376 vtep_ctl_context_populate_cache(ctx);
1377 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1379 svec_init(&bindings);
1380 SHASH_FOR_EACH (node, &port->bindings) {
1381 struct vtep_ctl_lswitch *lswitch = node->data;
1384 binding = xasprintf("%04lld %s", strtoll(node->name, NULL, 0),
1386 svec_add_nocopy(&bindings, binding);
1388 output_sorted(&bindings, &ctx->output);
1389 svec_destroy(&bindings);
1393 cmd_bind_ls(struct ctl_context *ctx)
1395 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1396 struct vtep_ctl_lswitch *ls;
1397 struct vtep_ctl_port *port;
1400 vtep_ctl_context_populate_cache(ctx);
1402 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1403 vlan = ctx->argv[3];
1404 ls = find_lswitch(vtepctl_ctx, ctx->argv[4], true);
1406 add_ls_binding_to_cache(port, vlan, ls);
1407 commit_ls_bindings(port);
1409 vtep_ctl_context_invalidate_cache(ctx);
1413 cmd_unbind_ls(struct ctl_context *ctx)
1415 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1416 struct vtep_ctl_port *port;
1419 vtep_ctl_context_populate_cache(ctx);
1421 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1422 vlan = ctx->argv[3];
1424 del_cached_ls_binding(port, vlan);
1425 commit_ls_bindings(port);
1427 vtep_ctl_context_invalidate_cache(ctx);
1431 add_ucast_entry(struct ctl_context *ctx, bool local)
1433 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1434 struct vtep_ctl_lswitch *ls;
1438 struct vteprec_physical_locator *ploc_cfg;
1440 vtep_ctl_context_populate_cache(ctx);
1442 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1445 if (ctx->argc == 4) {
1446 encap = "vxlan_over_ipv4";
1447 dst_ip = ctx->argv[3];
1449 encap = ctx->argv[3];
1450 dst_ip = ctx->argv[4];
1453 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1455 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1456 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1457 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1459 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1463 struct vteprec_ucast_macs_local *ucast_cfg;
1465 ucast_cfg = shash_find_data(&ls->ucast_local, mac);
1467 ucast_cfg = vteprec_ucast_macs_local_insert(ctx->txn);
1468 vteprec_ucast_macs_local_set_MAC(ucast_cfg, mac);
1469 vteprec_ucast_macs_local_set_logical_switch(ucast_cfg, ls->ls_cfg);
1470 shash_add(&ls->ucast_local, mac, ucast_cfg);
1472 vteprec_ucast_macs_local_set_locator(ucast_cfg, ploc_cfg);
1474 struct vteprec_ucast_macs_remote *ucast_cfg;
1476 ucast_cfg = shash_find_data(&ls->ucast_remote, mac);
1478 ucast_cfg = vteprec_ucast_macs_remote_insert(ctx->txn);
1479 vteprec_ucast_macs_remote_set_MAC(ucast_cfg, mac);
1480 vteprec_ucast_macs_remote_set_logical_switch(ucast_cfg, ls->ls_cfg);
1481 shash_add(&ls->ucast_remote, mac, ucast_cfg);
1483 vteprec_ucast_macs_remote_set_locator(ucast_cfg, ploc_cfg);
1486 vtep_ctl_context_invalidate_cache(ctx);
1490 cmd_add_ucast_local(struct ctl_context *ctx)
1492 add_ucast_entry(ctx, true);
1496 cmd_add_ucast_remote(struct ctl_context *ctx)
1498 add_ucast_entry(ctx, false);
1502 del_ucast_entry(struct ctl_context *ctx, bool local)
1504 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1505 struct vtep_ctl_lswitch *ls;
1506 struct shash *ucast_shash;
1507 struct shash_node *node;
1509 vtep_ctl_context_populate_cache(ctx);
1511 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1512 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1514 node = shash_find(ucast_shash, ctx->argv[2]);
1520 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1521 vteprec_ucast_macs_local_delete(ucast_cfg);
1523 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1524 vteprec_ucast_macs_remote_delete(ucast_cfg);
1526 shash_delete(ucast_shash, node);
1528 vtep_ctl_context_invalidate_cache(ctx);
1532 cmd_del_ucast_local(struct ctl_context *ctx)
1534 del_ucast_entry(ctx, true);
1538 cmd_del_ucast_remote(struct ctl_context *ctx)
1540 del_ucast_entry(ctx, false);
1544 commit_mcast_entries(struct vtep_ctl_mcast_mac *mcast_mac)
1546 struct vtep_ctl_ploc *ploc;
1547 struct vteprec_physical_locator **locators = NULL;
1551 n_locators = list_size(&mcast_mac->locators);
1552 ovs_assert(n_locators);
1554 locators = xmalloc(n_locators * sizeof *locators);
1557 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1558 locators[i] = (struct vteprec_physical_locator *)ploc->ploc_cfg;
1562 vteprec_physical_locator_set_set_locators(mcast_mac->ploc_set_cfg,
1570 add_mcast_entry(struct ctl_context *ctx,
1571 struct vtep_ctl_lswitch *ls, const char *mac,
1572 const char *encap, const char *dst_ip, bool local)
1574 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1575 struct shash *mcast_shash;
1576 struct vtep_ctl_mcast_mac *mcast_mac;
1577 struct vteprec_physical_locator *ploc_cfg;
1578 struct vteprec_physical_locator_set *ploc_set_cfg;
1580 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1582 /* Physical locator sets are immutable, so allocate a new one. */
1583 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1585 mcast_mac = shash_find_data(mcast_shash, mac);
1587 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mac, ploc_set_cfg,
1591 mcast_mac->local_cfg = vteprec_mcast_macs_local_insert(ctx->txn);
1592 vteprec_mcast_macs_local_set_MAC(mcast_mac->local_cfg, mac);
1593 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1595 vteprec_mcast_macs_local_set_logical_switch(mcast_mac->local_cfg,
1597 mcast_mac->remote_cfg = NULL;
1599 mcast_mac->remote_cfg = vteprec_mcast_macs_remote_insert(ctx->txn);
1600 vteprec_mcast_macs_remote_set_MAC(mcast_mac->remote_cfg, mac);
1601 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1603 vteprec_mcast_macs_remote_set_logical_switch(mcast_mac->remote_cfg,
1605 mcast_mac->local_cfg = NULL;
1608 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1610 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1613 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1618 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1620 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1621 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1622 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1624 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1627 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
1628 commit_mcast_entries(mcast_mac);
1632 del_mcast_entry(struct ctl_context *ctx,
1633 struct vtep_ctl_lswitch *ls, const char *mac,
1634 const char *encap, const char *dst_ip, bool local)
1636 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1637 struct vtep_ctl_mcast_mac *mcast_mac;
1638 struct shash *mcast_shash;
1639 struct vteprec_physical_locator *ploc_cfg;
1640 struct vteprec_physical_locator_set *ploc_set_cfg;
1642 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1644 mcast_mac = shash_find_data(mcast_shash, mac);
1649 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1651 /* Couldn't find the physical locator, so just ignore. */
1655 /* Physical locator sets are immutable, so allocate a new one. */
1656 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1657 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1659 del_ploc_from_mcast_mac(mcast_mac, ploc_cfg);
1660 if (list_is_empty(&mcast_mac->locators)) {
1661 struct shash_node *node = shash_find(mcast_shash, mac);
1663 vteprec_physical_locator_set_delete(ploc_set_cfg);
1666 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1668 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1672 shash_delete(mcast_shash, node);
1675 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1678 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1681 commit_mcast_entries(mcast_mac);
1686 add_del_mcast_entry(struct ctl_context *ctx, bool add, bool local)
1688 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1689 struct vtep_ctl_lswitch *ls;
1694 vtep_ctl_context_populate_cache(ctx);
1696 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1699 if (ctx->argc == 4) {
1700 encap = "vxlan_over_ipv4";
1701 dst_ip = ctx->argv[3];
1703 encap = ctx->argv[3];
1704 dst_ip = ctx->argv[4];
1708 add_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1710 del_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1713 vtep_ctl_context_invalidate_cache(ctx);
1717 cmd_add_mcast_local(struct ctl_context *ctx)
1719 add_del_mcast_entry(ctx, true, true);
1723 cmd_add_mcast_remote(struct ctl_context *ctx)
1725 add_del_mcast_entry(ctx, true, false);
1729 cmd_del_mcast_local(struct ctl_context *ctx)
1731 add_del_mcast_entry(ctx, false, true);
1735 cmd_del_mcast_remote(struct ctl_context *ctx)
1737 add_del_mcast_entry(ctx, false, false);
1741 clear_macs(struct ctl_context *ctx, bool local)
1743 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1744 struct vtep_ctl_lswitch *ls;
1745 const struct shash_node *node;
1746 struct shash *ucast_shash;
1747 struct shash *mcast_shash;
1749 vtep_ctl_context_populate_cache(ctx);
1750 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1752 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1753 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1755 SHASH_FOR_EACH (node, ucast_shash) {
1757 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1758 vteprec_ucast_macs_local_delete(ucast_cfg);
1760 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1761 vteprec_ucast_macs_remote_delete(ucast_cfg);
1765 SHASH_FOR_EACH (node, mcast_shash) {
1766 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1768 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1770 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1774 vtep_ctl_context_invalidate_cache(ctx);
1778 cmd_clear_local_macs(struct ctl_context *ctx)
1780 clear_macs(ctx, true);
1784 cmd_clear_remote_macs(struct ctl_context *ctx)
1786 clear_macs(ctx, false);
1790 list_macs(struct ctl_context *ctx, bool local)
1792 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1793 struct vtep_ctl_lswitch *ls;
1794 const struct shash_node *node;
1795 struct shash *ucast_shash;
1796 struct svec ucast_macs;
1797 struct shash *mcast_shash;
1798 struct svec mcast_macs;
1800 vtep_ctl_context_populate_cache(ctx);
1801 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1803 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1804 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1806 svec_init(&ucast_macs);
1807 SHASH_FOR_EACH (node, ucast_shash) {
1808 struct vteprec_ucast_macs_local *ucast_local = node->data;
1809 struct vteprec_ucast_macs_remote *ucast_remote = node->data;
1810 struct vteprec_physical_locator *ploc_cfg;
1813 ploc_cfg = local ? ucast_local->locator : ucast_remote->locator;
1815 entry = xasprintf(" %s -> %s/%s", node->name,
1816 ploc_cfg->encapsulation_type, ploc_cfg->dst_ip);
1817 svec_add_nocopy(&ucast_macs, entry);
1819 ds_put_format(&ctx->output, "ucast-mac-%s\n", local ? "local" : "remote");
1820 output_sorted(&ucast_macs, &ctx->output);
1821 ds_put_char(&ctx->output, '\n');
1822 svec_destroy(&ucast_macs);
1824 svec_init(&mcast_macs);
1825 SHASH_FOR_EACH (node, mcast_shash) {
1826 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1827 struct vtep_ctl_ploc *ploc;
1830 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1831 entry = xasprintf(" %s -> %s/%s", node->name,
1832 ploc->ploc_cfg->encapsulation_type,
1833 ploc->ploc_cfg->dst_ip);
1834 svec_add_nocopy(&mcast_macs, entry);
1837 ds_put_format(&ctx->output, "mcast-mac-%s\n", local ? "local" : "remote");
1838 output_sorted(&mcast_macs, &ctx->output);
1839 ds_put_char(&ctx->output, '\n');
1840 svec_destroy(&mcast_macs);
1844 cmd_list_local_macs(struct ctl_context *ctx)
1846 list_macs(ctx, true);
1850 cmd_list_remote_macs(struct ctl_context *ctx)
1852 list_macs(ctx, false);
1856 verify_managers(const struct vteprec_global *vtep_global)
1860 vteprec_global_verify_managers(vtep_global);
1862 for (i = 0; i < vtep_global->n_managers; ++i) {
1863 const struct vteprec_manager *mgr = vtep_global->managers[i];
1865 vteprec_manager_verify_target(mgr);
1870 pre_manager(struct ctl_context *ctx)
1872 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_managers);
1873 ovsdb_idl_add_column(ctx->idl, &vteprec_manager_col_target);
1877 cmd_get_manager(struct ctl_context *ctx)
1879 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1880 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1881 struct svec targets;
1884 verify_managers(vtep_global);
1886 /* Print the targets in sorted order for reproducibility. */
1887 svec_init(&targets);
1889 for (i = 0; i < vtep_global->n_managers; i++) {
1890 svec_add(&targets, vtep_global->managers[i]->target);
1893 svec_sort_unique(&targets);
1894 for (i = 0; i < targets.n; i++) {
1895 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
1897 svec_destroy(&targets);
1901 delete_managers(const struct vtep_ctl_context *vtepctl_ctx)
1903 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1906 /* Delete Manager rows pointed to by 'managers' column. */
1907 for (i = 0; i < vtep_global->n_managers; i++) {
1908 vteprec_manager_delete(vtep_global->managers[i]);
1911 /* Delete 'Manager' row refs in 'managers' column. */
1912 vteprec_global_set_managers(vtep_global, NULL, 0);
1916 cmd_del_manager(struct ctl_context *ctx)
1918 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1919 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1921 verify_managers(vtep_global);
1922 delete_managers(vtepctl_ctx);
1926 insert_managers(struct vtep_ctl_context *vtepctl_ctx, char *targets[], size_t n)
1928 struct vteprec_manager **managers;
1931 /* Insert each manager in a new row in Manager table. */
1932 managers = xmalloc(n * sizeof *managers);
1933 for (i = 0; i < n; i++) {
1934 if (stream_verify_name(targets[i]) && pstream_verify_name(targets[i])) {
1935 VLOG_WARN("target type \"%s\" is possibly erroneous", targets[i]);
1937 managers[i] = vteprec_manager_insert(vtepctl_ctx->base.txn);
1938 vteprec_manager_set_target(managers[i], targets[i]);
1941 /* Store uuids of new Manager rows in 'managers' column. */
1942 vteprec_global_set_managers(vtepctl_ctx->vtep_global, managers, n);
1947 cmd_set_manager(struct ctl_context *ctx)
1949 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1950 const size_t n = ctx->argc - 1;
1952 verify_managers(vtepctl_ctx->vtep_global);
1953 delete_managers(vtepctl_ctx);
1954 insert_managers(vtepctl_ctx, &ctx->argv[1], n);
1957 /* Parameter commands. */
1958 const struct ctl_table_class tables[] = {
1959 {&vteprec_table_global,
1960 {{&vteprec_table_global, NULL, NULL},
1961 {NULL, NULL, NULL}}},
1963 {&vteprec_table_logical_binding_stats,
1964 {{NULL, NULL, NULL},
1965 {NULL, NULL, NULL}}},
1967 {&vteprec_table_logical_switch,
1968 {{&vteprec_table_logical_switch, &vteprec_logical_switch_col_name, NULL},
1969 {NULL, NULL, NULL}}},
1971 {&vteprec_table_ucast_macs_local,
1972 {{NULL, NULL, NULL},
1973 {NULL, NULL, NULL}}},
1975 {&vteprec_table_ucast_macs_remote,
1976 {{NULL, NULL, NULL},
1977 {NULL, NULL, NULL}}},
1979 {&vteprec_table_mcast_macs_local,
1980 {{NULL, NULL, NULL},
1981 {NULL, NULL, NULL}}},
1983 {&vteprec_table_mcast_macs_remote,
1984 {{NULL, NULL, NULL},
1985 {NULL, NULL, NULL}}},
1987 {&vteprec_table_manager,
1988 {{&vteprec_table_manager, &vteprec_manager_col_target, NULL},
1989 {NULL, NULL, NULL}}},
1991 {&vteprec_table_physical_locator,
1992 {{NULL, NULL, NULL},
1993 {NULL, NULL, NULL}}},
1995 {&vteprec_table_physical_locator_set,
1996 {{NULL, NULL, NULL},
1997 {NULL, NULL, NULL}}},
1999 {&vteprec_table_physical_port,
2000 {{&vteprec_table_physical_port, &vteprec_physical_port_col_name, NULL},
2001 {NULL, NULL, NULL}}},
2003 {&vteprec_table_physical_switch,
2004 {{&vteprec_table_physical_switch, &vteprec_physical_switch_col_name, NULL},
2005 {NULL, NULL, NULL}}},
2007 {&vteprec_table_tunnel,
2008 {{NULL, NULL, NULL},
2009 {NULL, NULL, NULL}}},
2011 {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
2016 vtep_ctl_context_init_command(struct vtep_ctl_context *vtepctl_ctx,
2017 struct ctl_command *command)
2019 ctl_context_init_command(&vtepctl_ctx->base, command);
2020 vtepctl_ctx->verified_ports = false;
2025 vtep_ctl_context_init(struct vtep_ctl_context *vtepctl_ctx,
2026 struct ctl_command *command,
2027 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2028 const struct vteprec_global *vtep_global,
2029 struct ovsdb_symbol_table *symtab)
2031 ctl_context_init(&vtepctl_ctx->base, command, idl, txn, symtab,
2032 vtep_ctl_context_invalidate_cache);
2034 vtepctl_ctx->verified_ports = false;
2036 vtepctl_ctx->vtep_global = vtep_global;
2037 vtepctl_ctx->cache_valid = false;
2041 vtep_ctl_context_done_command(struct vtep_ctl_context *vtepctl_ctx,
2042 struct ctl_command *command)
2044 ctl_context_done_command(&vtepctl_ctx->base, command);
2048 vtep_ctl_context_done(struct vtep_ctl_context *vtepctl_ctx,
2049 struct ctl_command *command)
2051 ctl_context_done(&vtepctl_ctx->base, command);
2055 run_prerequisites(struct ctl_command *commands, size_t n_commands,
2056 struct ovsdb_idl *idl)
2058 struct ctl_command *c;
2060 ovsdb_idl_add_table(idl, &vteprec_table_global);
2061 for (c = commands; c < &commands[n_commands]; c++) {
2062 if (c->syntax->prerequisites) {
2063 struct vtep_ctl_context vtepctl_ctx;
2065 ds_init(&c->output);
2068 vtep_ctl_context_init(&vtepctl_ctx, c, idl, NULL, NULL, NULL);
2069 (c->syntax->prerequisites)(&vtepctl_ctx.base);
2070 vtep_ctl_context_done(&vtepctl_ctx, c);
2072 ovs_assert(!c->output.string);
2073 ovs_assert(!c->table);
2079 do_vtep_ctl(const char *args, struct ctl_command *commands,
2080 size_t n_commands, struct ovsdb_idl *idl)
2082 struct ovsdb_idl_txn *txn;
2083 const struct vteprec_global *vtep_global;
2084 enum ovsdb_idl_txn_status status;
2085 struct ovsdb_symbol_table *symtab;
2086 struct vtep_ctl_context vtepctl_ctx;
2087 struct ctl_command *c;
2088 struct shash_node *node;
2091 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
2093 ovsdb_idl_txn_set_dry_run(txn);
2096 ovsdb_idl_txn_add_comment(txn, "vtep-ctl: %s", args);
2098 vtep_global = vteprec_global_first(idl);
2100 /* XXX add verification that table is empty */
2101 vtep_global = vteprec_global_insert(txn);
2104 symtab = ovsdb_symbol_table_create();
2105 for (c = commands; c < &commands[n_commands]; c++) {
2106 ds_init(&c->output);
2109 vtep_ctl_context_init(&vtepctl_ctx, NULL, idl, txn, vtep_global, symtab);
2110 for (c = commands; c < &commands[n_commands]; c++) {
2111 vtep_ctl_context_init_command(&vtepctl_ctx, c);
2112 if (c->syntax->run) {
2113 (c->syntax->run)(&vtepctl_ctx.base);
2115 vtep_ctl_context_done_command(&vtepctl_ctx, c);
2117 if (vtepctl_ctx.base.try_again) {
2118 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2122 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2124 SHASH_FOR_EACH (node, &symtab->sh) {
2125 struct ovsdb_symbol *symbol = node->data;
2126 if (!symbol->created) {
2127 ctl_fatal("row id \"%s\" is referenced but never created "
2128 "(e.g. with \"-- --id=%s create ...\")",
2129 node->name, node->name);
2131 if (!symbol->strong_ref) {
2132 if (!symbol->weak_ref) {
2133 VLOG_WARN("row id \"%s\" was created but no reference to it "
2134 "was inserted, so it will not actually appear in "
2135 "the database", node->name);
2137 VLOG_WARN("row id \"%s\" was created but only a weak "
2138 "reference to it was inserted, so it will not "
2139 "actually appear in the database", node->name);
2144 status = ovsdb_idl_txn_commit_block(txn);
2145 if (status == TXN_UNCHANGED || status == TXN_SUCCESS) {
2146 for (c = commands; c < &commands[n_commands]; c++) {
2147 if (c->syntax->postprocess) {
2148 vtep_ctl_context_init(&vtepctl_ctx, c, idl, txn, vtep_global, symtab);
2149 (c->syntax->postprocess)(&vtepctl_ctx.base);
2150 vtep_ctl_context_done(&vtepctl_ctx, c);
2154 error = xstrdup(ovsdb_idl_txn_get_error(txn));
2155 ovsdb_idl_txn_destroy(txn);
2156 txn = the_idl_txn = NULL;
2159 case TXN_UNCOMMITTED:
2160 case TXN_INCOMPLETE:
2164 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2165 ctl_fatal("transaction aborted");
2175 ctl_fatal("transaction error: %s", error);
2177 case TXN_NOT_LOCKED:
2178 /* Should not happen--we never call ovsdb_idl_set_lock(). */
2179 ctl_fatal("database not locked");
2186 ovsdb_symbol_table_destroy(symtab);
2188 for (c = commands; c < &commands[n_commands]; c++) {
2189 struct ds *ds = &c->output;
2192 table_print(c->table, &table_style);
2193 } else if (oneline) {
2197 for (j = 0; j < ds->length; j++) {
2198 int ch = ds->string[j];
2201 fputs("\\n", stdout);
2205 fputs("\\\\", stdout);
2214 fputs(ds_cstr(ds), stdout);
2216 ds_destroy(&c->output);
2217 table_destroy(c->table);
2220 shash_destroy_free_data(&c->options);
2224 ovsdb_idl_destroy(idl);
2229 /* Our transaction needs to be rerun, or a prerequisite was not met. Free
2230 * resources and return so that the caller can try again. */
2232 ovsdb_idl_txn_abort(txn);
2233 ovsdb_idl_txn_destroy(txn);
2235 ovsdb_symbol_table_destroy(symtab);
2236 for (c = commands; c < &commands[n_commands]; c++) {
2237 ds_destroy(&c->output);
2238 table_destroy(c->table);
2244 static const struct ctl_command_syntax vtep_commands[] = {
2245 /* Physical Switch commands. */
2246 {"add-ps", 1, 1, NULL, pre_get_info, cmd_add_ps, NULL, "--may-exist", RW},
2247 {"del-ps", 1, 1, NULL, pre_get_info, cmd_del_ps, NULL, "--if-exists", RW},
2248 {"list-ps", 0, 0, NULL, pre_get_info, cmd_list_ps, NULL, "", RO},
2249 {"ps-exists", 1, 1, NULL, pre_get_info, cmd_ps_exists, NULL, "", RO},
2251 /* Port commands. */
2252 {"list-ports", 1, 1, NULL, pre_get_info, cmd_list_ports, NULL, "", RO},
2253 {"add-port", 2, 2, NULL, pre_get_info, cmd_add_port, NULL, "--may-exist",
2255 {"del-port", 2, 2, NULL, pre_get_info, cmd_del_port, NULL, "--if-exists",
2258 /* Logical Switch commands. */
2259 {"add-ls", 1, 1, NULL, pre_get_info, cmd_add_ls, NULL, "--may-exist", RW},
2260 {"del-ls", 1, 1, NULL, pre_get_info, cmd_del_ls, NULL, "--if-exists", RW},
2261 {"list-ls", 0, 0, NULL, pre_get_info, cmd_list_ls, NULL, "", RO},
2262 {"ls-exists", 1, 1, NULL, pre_get_info, cmd_ls_exists, NULL, "", RO},
2263 {"list-bindings", 2, 2, NULL, pre_get_info, cmd_list_bindings, NULL, "", RO},
2264 {"bind-ls", 4, 4, NULL, pre_get_info, cmd_bind_ls, NULL, "", RO},
2265 {"unbind-ls", 3, 3, NULL, pre_get_info, cmd_unbind_ls, NULL, "", RO},
2267 /* MAC binding commands. */
2268 {"add-ucast-local", 3, 4, NULL, pre_get_info, cmd_add_ucast_local, NULL,
2270 {"del-ucast-local", 2, 2, NULL, pre_get_info, cmd_del_ucast_local, NULL,
2272 {"add-mcast-local", 3, 4, NULL, pre_get_info, cmd_add_mcast_local, NULL,
2274 {"del-mcast-local", 3, 4, NULL, pre_get_info, cmd_del_mcast_local, NULL,
2276 {"clear-local-macs", 1, 1, NULL, pre_get_info, cmd_clear_local_macs, NULL,
2278 {"list-local-macs", 1, 1, NULL, pre_get_info, cmd_list_local_macs, NULL,
2280 {"add-ucast-remote", 3, 4, NULL, pre_get_info, cmd_add_ucast_remote, NULL,
2282 {"del-ucast-remote", 2, 2, NULL, pre_get_info, cmd_del_ucast_remote, NULL,
2284 {"add-mcast-remote", 3, 4, NULL, pre_get_info, cmd_add_mcast_remote, NULL,
2286 {"del-mcast-remote", 3, 4, NULL, pre_get_info, cmd_del_mcast_remote, NULL,
2288 {"clear-remote-macs", 1, 1, NULL, pre_get_info, cmd_clear_remote_macs, NULL,
2290 {"list-remote-macs", 1, 1, NULL, pre_get_info, cmd_list_remote_macs, NULL,
2293 /* Manager commands. */
2294 {"get-manager", 0, 0, NULL, pre_manager, cmd_get_manager, NULL, "", RO},
2295 {"del-manager", 0, 0, NULL, pre_manager, cmd_del_manager, NULL, "", RW},
2296 {"set-manager", 1, INT_MAX, NULL, pre_manager, cmd_set_manager, NULL, "",
2299 {NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, RO},
2302 /* Registers vsctl and common db commands. */
2304 vtep_ctl_cmd_init(void)
2307 ctl_register_commands(vtep_commands);