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);
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);
510 vtep_delete_pswitch(const struct vteprec_global *vtep_global,
511 const struct vteprec_physical_switch *ps)
513 struct vteprec_physical_switch **pswitches;
516 pswitches = xmalloc(sizeof *vtep_global->switches
517 * vtep_global->n_switches);
518 for (i = n = 0; i < vtep_global->n_switches; i++) {
519 if (vtep_global->switches[i] != ps) {
520 pswitches[n++] = vtep_global->switches[i];
523 vteprec_global_set_switches(vtep_global, pswitches, n);
528 del_cached_pswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_pswitch *ps)
530 ovs_assert(list_is_empty(&ps->ports));
532 vteprec_physical_switch_delete(ps->ps_cfg);
533 vtep_delete_pswitch(ctx->vtep_global, ps->ps_cfg);
535 shash_find_and_delete(&ctx->pswitches, ps->name);
540 static struct vtep_ctl_lswitch *
541 add_lswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
542 const struct vteprec_logical_switch *ls_cfg)
544 struct vtep_ctl_lswitch *ls = xmalloc(sizeof *ls);
546 ls->name = xstrdup(ls_cfg->name);
547 shash_add(&vtepctl_ctx->lswitches, ls->name, ls);
548 shash_init(&ls->ucast_local);
549 shash_init(&ls->ucast_remote);
550 shash_init(&ls->mcast_local);
551 shash_init(&ls->mcast_remote);
556 del_cached_lswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_lswitch *ls)
559 vteprec_logical_switch_delete(ls->ls_cfg);
561 shash_find_and_delete(&ctx->lswitches, ls->name);
567 commit_ls_bindings(struct vtep_ctl_port *port)
569 struct vteprec_logical_switch **binding_values;
570 int64_t *binding_keys;
572 struct shash_node *node;
575 n_bindings = shash_count(&port->bindings);
576 binding_keys = xmalloc(n_bindings * sizeof *binding_keys);
577 binding_values = xmalloc(n_bindings * sizeof *binding_values);
580 SHASH_FOR_EACH(node, &port->bindings) {
581 struct vtep_ctl_lswitch *ls_entry = node->data;
583 binding_keys[i] = strtoll(node->name, NULL, 0);
584 binding_values[i] = (struct vteprec_logical_switch *)ls_entry->ls_cfg;
588 vteprec_physical_port_set_vlan_bindings(port->port_cfg,
589 binding_keys, binding_values,
591 free(binding_values);
596 add_ls_binding_to_cache(struct vtep_ctl_port *port,
598 struct vtep_ctl_lswitch *ls)
600 if (shash_find(&port->bindings, vlan)) {
601 ctl_fatal("multiple bindings for vlan %s", vlan);
604 shash_add(&port->bindings, vlan, ls);
608 del_cached_ls_binding(struct vtep_ctl_port *port, const char *vlan)
610 if (!shash_find(&port->bindings, vlan)) {
611 ctl_fatal("no binding for vlan %s", vlan);
614 shash_find_and_delete(&port->bindings, vlan);
617 static struct vteprec_physical_locator *
618 find_ploc(struct vtep_ctl_context *vtepctl_ctx, const char *encap,
621 struct vteprec_physical_locator *ploc;
622 char *name = xasprintf("%s+%s", encap, dst_ip);
624 ovs_assert(vtepctl_ctx->cache_valid);
626 ploc = shash_find_data(&vtepctl_ctx->plocs, name);
633 add_ploc_to_cache(struct vtep_ctl_context *vtepctl_ctx,
634 struct vteprec_physical_locator *ploc)
636 char *name = xasprintf("%s+%s", ploc->encapsulation_type, ploc->dst_ip);
637 struct vteprec_physical_locator *orig_ploc;
639 orig_ploc = find_ploc(vtepctl_ctx, ploc->encapsulation_type, ploc->dst_ip);
641 shash_add(&vtepctl_ctx->plocs, name, ploc);
648 add_ploc_to_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
649 struct vteprec_physical_locator *ploc_cfg)
651 struct vtep_ctl_ploc *ploc;
653 ploc = xmalloc(sizeof *ploc);
654 ploc->ploc_cfg = ploc_cfg;
655 list_push_back(&mcast_mac->locators, &ploc->locators_node);
659 del_ploc_from_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
660 struct vteprec_physical_locator *ploc_cfg)
662 struct vtep_ctl_ploc *ploc;
664 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
665 if (ploc->ploc_cfg == ploc_cfg) {
666 list_remove(&ploc->locators_node);
673 static struct vtep_ctl_mcast_mac *
674 add_mcast_mac_to_cache(struct vtep_ctl_context *vtepctl_ctx,
675 struct vtep_ctl_lswitch *ls, const char *mac,
676 struct vteprec_physical_locator_set *ploc_set_cfg,
679 struct vtep_ctl_mcast_mac *mcast_mac;
680 struct shash *mcast_shash;
683 mcast_mac = xmalloc(sizeof *mcast_mac);
684 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
686 mcast_mac->ploc_set_cfg = ploc_set_cfg;
687 list_init(&mcast_mac->locators);
688 shash_add(mcast_shash, mac, mcast_mac);
690 for (i = 0; i < ploc_set_cfg->n_locators; i++) {
691 struct vteprec_physical_locator *ploc_cfg;
693 ploc_cfg = ploc_set_cfg->locators[i];
694 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
695 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
702 vtep_ctl_context_invalidate_cache(struct ctl_context *ctx)
704 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
705 struct shash_node *node;
707 if (!vtepctl_ctx->cache_valid) {
710 vtepctl_ctx->cache_valid = false;
712 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
713 struct vtep_ctl_pswitch *ps = node->data;
717 shash_destroy(&vtepctl_ctx->pswitches);
719 SHASH_FOR_EACH (node, &vtepctl_ctx->ports) {
720 struct vtep_ctl_port *port = node->data;
721 shash_destroy(&port->bindings);
723 shash_destroy_free_data(&vtepctl_ctx->ports);
725 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
726 struct vtep_ctl_lswitch *ls = node->data;
727 struct shash_node *node2, *next_node2;
729 shash_destroy(&ls->ucast_local);
730 shash_destroy(&ls->ucast_remote);
732 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_local) {
733 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
734 struct vtep_ctl_ploc *ploc, *next_ploc;
736 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
737 &mcast_mac->locators) {
742 shash_destroy(&ls->mcast_local);
744 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_remote) {
745 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
746 struct vtep_ctl_ploc *ploc, *next_ploc;
748 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
749 &mcast_mac->locators) {
754 shash_destroy(&ls->mcast_remote);
759 shash_destroy(&vtepctl_ctx->lswitches);
760 shash_destroy(&vtepctl_ctx->plocs);
764 pre_get_info(struct ctl_context *ctx)
766 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_switches);
768 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_name);
769 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_ports);
770 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_tunnels);
772 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_name);
773 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_vlan_bindings);
775 ovsdb_idl_add_column(ctx->idl, &vteprec_logical_switch_col_name);
777 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_MAC);
778 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_locator);
779 ovsdb_idl_add_column(ctx->idl,
780 &vteprec_ucast_macs_local_col_logical_switch);
782 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_MAC);
783 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_locator);
784 ovsdb_idl_add_column(ctx->idl,
785 &vteprec_ucast_macs_remote_col_logical_switch);
787 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_local_col_MAC);
788 ovsdb_idl_add_column(ctx->idl,
789 &vteprec_mcast_macs_local_col_locator_set);
790 ovsdb_idl_add_column(ctx->idl,
791 &vteprec_mcast_macs_local_col_logical_switch);
793 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_remote_col_MAC);
794 ovsdb_idl_add_column(ctx->idl,
795 &vteprec_mcast_macs_remote_col_locator_set);
796 ovsdb_idl_add_column(ctx->idl,
797 &vteprec_mcast_macs_remote_col_logical_switch);
799 ovsdb_idl_add_column(ctx->idl,
800 &vteprec_physical_locator_set_col_locators);
802 ovsdb_idl_add_column(ctx->idl,
803 &vteprec_physical_locator_col_dst_ip);
804 ovsdb_idl_add_column(ctx->idl,
805 &vteprec_physical_locator_col_encapsulation_type);
807 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_local);
808 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_remote);
812 vtep_ctl_context_populate_cache(struct ctl_context *ctx)
814 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
815 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
816 const struct vteprec_logical_switch *ls_cfg;
817 const struct vteprec_ucast_macs_local *ucast_local_cfg;
818 const struct vteprec_ucast_macs_remote *ucast_remote_cfg;
819 const struct vteprec_mcast_macs_local *mcast_local_cfg;
820 const struct vteprec_mcast_macs_remote *mcast_remote_cfg;
821 const struct vteprec_tunnel *tunnel_cfg;
822 struct sset pswitches, ports, lswitches;
825 if (vtepctl_ctx->cache_valid) {
826 /* Cache is already populated. */
829 vtepctl_ctx->cache_valid = true;
830 shash_init(&vtepctl_ctx->pswitches);
831 shash_init(&vtepctl_ctx->ports);
832 shash_init(&vtepctl_ctx->lswitches);
833 shash_init(&vtepctl_ctx->plocs);
835 sset_init(&pswitches);
837 for (i = 0; i < vtep_global->n_switches; i++) {
838 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
841 if (!sset_add(&pswitches, ps_cfg->name)) {
842 VLOG_WARN("%s: database contains duplicate physical switch name",
846 add_pswitch_to_cache(vtepctl_ctx, ps_cfg);
848 for (j = 0; j < ps_cfg->n_ports; j++) {
849 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
851 if (!sset_add(&ports, port_cfg->name)) {
852 /* Duplicate port name. (We will warn about that later.) */
857 sset_destroy(&pswitches);
858 sset_destroy(&ports);
860 sset_init(&lswitches);
861 VTEPREC_LOGICAL_SWITCH_FOR_EACH (ls_cfg, ctx->idl) {
862 if (!sset_add(&lswitches, ls_cfg->name)) {
863 VLOG_WARN("%s: database contains duplicate logical switch name",
867 add_lswitch_to_cache(vtepctl_ctx, ls_cfg);
869 sset_destroy(&lswitches);
871 VTEPREC_UCAST_MACS_LOCAL_FOR_EACH (ucast_local_cfg, ctx->idl) {
872 struct vtep_ctl_lswitch *ls;
874 if (!ucast_local_cfg->logical_switch) {
877 ls = find_lswitch(vtepctl_ctx, ucast_local_cfg->logical_switch->name,
883 if (ucast_local_cfg->locator) {
884 add_ploc_to_cache(vtepctl_ctx, ucast_local_cfg->locator);
887 shash_add(&ls->ucast_local, ucast_local_cfg->MAC, ucast_local_cfg);
890 VTEPREC_UCAST_MACS_REMOTE_FOR_EACH (ucast_remote_cfg, ctx->idl) {
891 struct vtep_ctl_lswitch *ls;
893 if (!ucast_remote_cfg->logical_switch) {
896 ls = find_lswitch(vtepctl_ctx, ucast_remote_cfg->logical_switch->name,
902 if (ucast_remote_cfg->locator) {
903 add_ploc_to_cache(vtepctl_ctx, ucast_remote_cfg->locator);
906 shash_add(&ls->ucast_remote, ucast_remote_cfg->MAC, ucast_remote_cfg);
909 VTEPREC_MCAST_MACS_LOCAL_FOR_EACH (mcast_local_cfg, ctx->idl) {
910 struct vtep_ctl_mcast_mac *mcast_mac;
911 struct vtep_ctl_lswitch *ls;
913 if (!mcast_local_cfg->logical_switch) {
916 ls = find_lswitch(vtepctl_ctx, mcast_local_cfg->logical_switch->name,
922 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_local_cfg->MAC,
923 mcast_local_cfg->locator_set,
925 mcast_mac->local_cfg = mcast_local_cfg;
928 VTEPREC_MCAST_MACS_REMOTE_FOR_EACH (mcast_remote_cfg, ctx->idl) {
929 struct vtep_ctl_mcast_mac *mcast_mac;
930 struct vtep_ctl_lswitch *ls;
932 if (!mcast_remote_cfg->logical_switch) {
935 ls = find_lswitch(vtepctl_ctx, mcast_remote_cfg->logical_switch->name,
941 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_remote_cfg->MAC,
942 mcast_remote_cfg->locator_set,
944 mcast_mac->remote_cfg = mcast_remote_cfg;
947 VTEPREC_TUNNEL_FOR_EACH (tunnel_cfg, ctx->idl) {
948 if (tunnel_cfg->local) {
949 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->local);
951 if (tunnel_cfg->remote) {
952 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->remote);
956 sset_init(&pswitches);
957 for (i = 0; i < vtep_global->n_switches; i++) {
958 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
959 struct vtep_ctl_pswitch *ps;
962 if (!sset_add(&pswitches, ps_cfg->name)) {
965 ps = shash_find_data(&vtepctl_ctx->pswitches, ps_cfg->name);
966 for (j = 0; j < ps_cfg->n_ports; j++) {
967 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
968 struct vtep_ctl_port *port;
971 port = shash_find_data(&vtepctl_ctx->ports, port_cfg->name);
973 if (port_cfg == port->port_cfg) {
974 VLOG_WARN("%s: port is in multiple physical switches "
976 port_cfg->name, ps->name, port->ps->name);
978 /* Log as an error because this violates the database's
979 * uniqueness constraints, so the database server shouldn't
980 * have allowed it. */
981 VLOG_ERR("%s: database contains duplicate port name",
987 port = add_port_to_cache(vtepctl_ctx, ps, port_cfg);
989 for (k = 0; k < port_cfg->n_vlan_bindings; k++) {
990 struct vteprec_logical_switch *ls_cfg;
991 struct vtep_ctl_lswitch *ls;
994 vlan = xasprintf("%"PRId64, port_cfg->key_vlan_bindings[k]);
995 if (shash_find(&port->bindings, vlan)) {
996 ctl_fatal("multiple bindings for vlan %s", vlan);
999 ls_cfg = port_cfg->value_vlan_bindings[k];
1000 ls = find_lswitch(vtepctl_ctx, ls_cfg->name, true);
1002 shash_add_nocopy(&port->bindings, vlan, ls);
1006 sset_destroy(&pswitches);
1009 static struct vtep_ctl_pswitch *
1010 find_pswitch(struct vtep_ctl_context *vtepctl_ctx, const char *name, bool must_exist)
1012 struct vtep_ctl_pswitch *ps;
1014 ovs_assert(vtepctl_ctx->cache_valid);
1016 ps = shash_find_data(&vtepctl_ctx->pswitches, name);
1017 if (must_exist && !ps) {
1018 ctl_fatal("no physical switch named %s", name);
1020 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
1024 static struct vtep_ctl_port *
1025 find_port(struct vtep_ctl_context *vtepctl_ctx, const char *ps_name,
1026 const char *port_name, bool must_exist)
1028 char *cache_name = xasprintf("%s+%s", ps_name, port_name);
1029 struct vtep_ctl_port *port;
1031 ovs_assert(vtepctl_ctx->cache_valid);
1033 port = shash_find_data(&vtepctl_ctx->ports, cache_name);
1034 if (port && !strcmp(port_name, port->ps->name)) {
1038 if (must_exist && !port) {
1039 ctl_fatal("no port named %s", port_name);
1041 verify_ports(vtepctl_ctx);
1046 pswitch_insert_port(const struct vteprec_physical_switch *ps,
1047 struct vteprec_physical_port *port)
1049 struct vteprec_physical_port **ports;
1052 ports = xmalloc(sizeof *ps->ports * (ps->n_ports + 1));
1053 for (i = 0; i < ps->n_ports; i++) {
1054 ports[i] = ps->ports[i];
1056 ports[ps->n_ports] = port;
1057 vteprec_physical_switch_set_ports(ps, ports, ps->n_ports + 1);
1062 pswitch_delete_port(const struct vteprec_physical_switch *ps,
1063 const struct vteprec_physical_port *port)
1065 struct vteprec_physical_port **ports;
1068 ports = xmalloc(sizeof *ps->ports * ps->n_ports);
1069 for (i = n = 0; i < ps->n_ports; i++) {
1070 if (ps->ports[i] != port) {
1071 ports[n++] = ps->ports[i];
1074 vteprec_physical_switch_set_ports(ps, ports, n);
1079 vtep_insert_pswitch(const struct vteprec_global *vtep_global,
1080 struct vteprec_physical_switch *ps)
1082 struct vteprec_physical_switch **pswitches;
1085 pswitches = xmalloc(sizeof *vtep_global->switches
1086 * (vtep_global->n_switches + 1));
1087 for (i = 0; i < vtep_global->n_switches; i++) {
1088 pswitches[i] = vtep_global->switches[i];
1090 pswitches[vtep_global->n_switches] = ps;
1091 vteprec_global_set_switches(vtep_global, pswitches,
1092 vtep_global->n_switches + 1);
1097 cmd_add_ps(struct ctl_context *ctx)
1099 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1100 const char *ps_name = ctx->argv[1];
1101 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1102 struct vteprec_physical_switch *ps;
1104 vtep_ctl_context_populate_cache(ctx);
1105 if (find_pswitch(vtepctl_ctx, ps_name, false)) {
1107 ctl_fatal("cannot create physical switch %s because it "
1108 "already exists", ps_name);
1113 ps = vteprec_physical_switch_insert(ctx->txn);
1114 vteprec_physical_switch_set_name(ps, ps_name);
1116 vtep_insert_pswitch(vtepctl_ctx->vtep_global, ps);
1118 vtep_ctl_context_invalidate_cache(ctx);
1122 del_port(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_port *port)
1124 pswitch_delete_port(port->ps->ps_cfg, port->port_cfg);
1125 del_cached_port(vtepctl_ctx, port);
1129 del_pswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_pswitch *ps)
1131 struct vtep_ctl_port *port, *next_port;
1133 LIST_FOR_EACH_SAFE (port, next_port, ports_node, &ps->ports) {
1134 del_port(vtepctl_ctx, port);
1137 del_cached_pswitch(vtepctl_ctx, ps);
1141 cmd_del_ps(struct ctl_context *ctx)
1143 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1144 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1145 struct vtep_ctl_pswitch *ps;
1147 vtep_ctl_context_populate_cache(ctx);
1148 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1150 del_pswitch(vtepctl_ctx, ps);
1155 output_sorted(struct svec *svec, struct ds *output)
1161 SVEC_FOR_EACH (i, name, svec) {
1162 ds_put_format(output, "%s\n", name);
1167 cmd_list_ps(struct ctl_context *ctx)
1169 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1170 struct shash_node *node;
1171 struct svec pswitches;
1173 vtep_ctl_context_populate_cache(ctx);
1175 svec_init(&pswitches);
1176 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
1177 struct vtep_ctl_pswitch *ps = node->data;
1179 svec_add(&pswitches, ps->name);
1181 output_sorted(&pswitches, &ctx->output);
1182 svec_destroy(&pswitches);
1186 cmd_ps_exists(struct ctl_context *ctx)
1188 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1190 vtep_ctl_context_populate_cache(ctx);
1191 if (!find_pswitch(vtepctl_ctx, ctx->argv[1], false)) {
1197 cmd_list_ports(struct ctl_context *ctx)
1199 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1200 struct vtep_ctl_pswitch *ps;
1201 struct vtep_ctl_port *port;
1204 vtep_ctl_context_populate_cache(ctx);
1205 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1206 vteprec_physical_switch_verify_ports(ps->ps_cfg);
1209 LIST_FOR_EACH (port, ports_node, &ps->ports) {
1210 if (strcmp(port->port_cfg->name, ps->name)) {
1211 svec_add(&ports, port->port_cfg->name);
1214 output_sorted(&ports, &ctx->output);
1215 svec_destroy(&ports);
1219 add_port(struct ctl_context *ctx, const char *ps_name,
1220 const char *port_name, bool may_exist)
1222 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1223 struct vtep_ctl_port *vtep_ctl_port;
1224 struct vtep_ctl_pswitch *ps;
1225 struct vteprec_physical_port *port;
1227 vtep_ctl_context_populate_cache(ctx);
1229 vtep_ctl_port = find_port(vtepctl_ctx, ps_name, port_name, false);
1230 if (vtep_ctl_port) {
1232 ctl_fatal("cannot create a port named %s on %s because a "
1233 "port with that name already exists",
1234 port_name, ps_name);
1239 ps = find_pswitch(vtepctl_ctx, ps_name, true);
1241 port = vteprec_physical_port_insert(ctx->txn);
1242 vteprec_physical_port_set_name(port, port_name);
1244 pswitch_insert_port(ps->ps_cfg, port);
1246 add_port_to_cache(vtepctl_ctx, ps, port);
1250 cmd_add_port(struct ctl_context *ctx)
1252 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1254 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist);
1258 cmd_del_port(struct ctl_context *ctx)
1260 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1261 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1262 struct vtep_ctl_port *port;
1264 vtep_ctl_context_populate_cache(ctx);
1266 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], must_exist);
1268 if (ctx->argc == 3) {
1269 struct vtep_ctl_pswitch *ps;
1271 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1272 if (port->ps != ps) {
1273 ctl_fatal("physical switch %s does not have a port %s",
1274 ctx->argv[1], ctx->argv[2]);
1278 del_port(vtepctl_ctx, port);
1282 static struct vtep_ctl_lswitch *
1283 find_lswitch(struct vtep_ctl_context *vtepctl_ctx,
1284 const char *name, bool must_exist)
1286 struct vtep_ctl_lswitch *ls;
1288 ovs_assert(vtepctl_ctx->cache_valid);
1290 ls = shash_find_data(&vtepctl_ctx->lswitches, name);
1291 if (must_exist && !ls) {
1292 ctl_fatal("no logical switch named %s", name);
1298 cmd_add_ls(struct ctl_context *ctx)
1300 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1301 const char *ls_name = ctx->argv[1];
1302 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1303 struct vteprec_logical_switch *ls;
1305 vtep_ctl_context_populate_cache(ctx);
1306 if (find_lswitch(vtepctl_ctx, ls_name, false)) {
1308 ctl_fatal("cannot create logical switch %s because it "
1309 "already exists", ls_name);
1314 ls = vteprec_logical_switch_insert(ctx->txn);
1315 vteprec_logical_switch_set_name(ls, ls_name);
1317 vtep_ctl_context_invalidate_cache(ctx);
1321 del_lswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_lswitch *ls)
1323 del_cached_lswitch(vtepctl_ctx, ls);
1327 cmd_del_ls(struct ctl_context *ctx)
1329 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1330 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1331 struct vtep_ctl_lswitch *ls;
1333 vtep_ctl_context_populate_cache(ctx);
1334 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1336 del_lswitch(vtepctl_ctx, ls);
1341 cmd_list_ls(struct ctl_context *ctx)
1343 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1344 struct shash_node *node;
1345 struct svec lswitches;
1347 vtep_ctl_context_populate_cache(ctx);
1349 svec_init(&lswitches);
1350 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
1351 struct vtep_ctl_lswitch *ls = node->data;
1353 svec_add(&lswitches, ls->name);
1355 output_sorted(&lswitches, &ctx->output);
1356 svec_destroy(&lswitches);
1360 cmd_ls_exists(struct ctl_context *ctx)
1362 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1364 vtep_ctl_context_populate_cache(ctx);
1365 if (!find_lswitch(vtepctl_ctx, ctx->argv[1], false)) {
1371 cmd_list_bindings(struct ctl_context *ctx)
1373 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1374 const struct shash_node *node;
1375 struct vtep_ctl_port *port;
1376 struct svec bindings;
1378 vtep_ctl_context_populate_cache(ctx);
1379 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1381 svec_init(&bindings);
1382 SHASH_FOR_EACH (node, &port->bindings) {
1383 struct vtep_ctl_lswitch *lswitch = node->data;
1386 binding = xasprintf("%04lld %s", strtoll(node->name, NULL, 0),
1388 svec_add_nocopy(&bindings, binding);
1390 output_sorted(&bindings, &ctx->output);
1391 svec_destroy(&bindings);
1395 cmd_bind_ls(struct ctl_context *ctx)
1397 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1398 struct vtep_ctl_lswitch *ls;
1399 struct vtep_ctl_port *port;
1402 vtep_ctl_context_populate_cache(ctx);
1404 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1405 vlan = ctx->argv[3];
1406 ls = find_lswitch(vtepctl_ctx, ctx->argv[4], true);
1408 add_ls_binding_to_cache(port, vlan, ls);
1409 commit_ls_bindings(port);
1411 vtep_ctl_context_invalidate_cache(ctx);
1415 cmd_unbind_ls(struct ctl_context *ctx)
1417 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1418 struct vtep_ctl_port *port;
1421 vtep_ctl_context_populate_cache(ctx);
1423 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1424 vlan = ctx->argv[3];
1426 del_cached_ls_binding(port, vlan);
1427 commit_ls_bindings(port);
1429 vtep_ctl_context_invalidate_cache(ctx);
1433 add_ucast_entry(struct ctl_context *ctx, bool local)
1435 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1436 struct vtep_ctl_lswitch *ls;
1440 struct vteprec_physical_locator *ploc_cfg;
1442 vtep_ctl_context_populate_cache(ctx);
1444 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1447 if (ctx->argc == 4) {
1448 encap = "vxlan_over_ipv4";
1449 dst_ip = ctx->argv[3];
1451 encap = ctx->argv[3];
1452 dst_ip = ctx->argv[4];
1455 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1457 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1458 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1459 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1461 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1465 struct vteprec_ucast_macs_local *ucast_cfg;
1467 ucast_cfg = shash_find_data(&ls->ucast_local, mac);
1469 ucast_cfg = vteprec_ucast_macs_local_insert(ctx->txn);
1470 vteprec_ucast_macs_local_set_MAC(ucast_cfg, mac);
1471 vteprec_ucast_macs_local_set_logical_switch(ucast_cfg, ls->ls_cfg);
1472 shash_add(&ls->ucast_local, mac, ucast_cfg);
1474 vteprec_ucast_macs_local_set_locator(ucast_cfg, ploc_cfg);
1476 struct vteprec_ucast_macs_remote *ucast_cfg;
1478 ucast_cfg = shash_find_data(&ls->ucast_remote, mac);
1480 ucast_cfg = vteprec_ucast_macs_remote_insert(ctx->txn);
1481 vteprec_ucast_macs_remote_set_MAC(ucast_cfg, mac);
1482 vteprec_ucast_macs_remote_set_logical_switch(ucast_cfg, ls->ls_cfg);
1483 shash_add(&ls->ucast_remote, mac, ucast_cfg);
1485 vteprec_ucast_macs_remote_set_locator(ucast_cfg, ploc_cfg);
1488 vtep_ctl_context_invalidate_cache(ctx);
1492 cmd_add_ucast_local(struct ctl_context *ctx)
1494 add_ucast_entry(ctx, true);
1498 cmd_add_ucast_remote(struct ctl_context *ctx)
1500 add_ucast_entry(ctx, false);
1504 del_ucast_entry(struct ctl_context *ctx, bool local)
1506 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1507 struct vtep_ctl_lswitch *ls;
1508 struct shash *ucast_shash;
1509 struct shash_node *node;
1511 vtep_ctl_context_populate_cache(ctx);
1513 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1514 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1516 node = shash_find(ucast_shash, ctx->argv[2]);
1522 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1523 vteprec_ucast_macs_local_delete(ucast_cfg);
1525 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1526 vteprec_ucast_macs_remote_delete(ucast_cfg);
1528 shash_delete(ucast_shash, node);
1530 vtep_ctl_context_invalidate_cache(ctx);
1534 cmd_del_ucast_local(struct ctl_context *ctx)
1536 del_ucast_entry(ctx, true);
1540 cmd_del_ucast_remote(struct ctl_context *ctx)
1542 del_ucast_entry(ctx, false);
1546 commit_mcast_entries(struct vtep_ctl_mcast_mac *mcast_mac)
1548 struct vtep_ctl_ploc *ploc;
1549 struct vteprec_physical_locator **locators = NULL;
1553 n_locators = list_size(&mcast_mac->locators);
1554 ovs_assert(n_locators);
1556 locators = xmalloc(n_locators * sizeof *locators);
1559 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1560 locators[i] = (struct vteprec_physical_locator *)ploc->ploc_cfg;
1564 vteprec_physical_locator_set_set_locators(mcast_mac->ploc_set_cfg,
1572 add_mcast_entry(struct ctl_context *ctx,
1573 struct vtep_ctl_lswitch *ls, const char *mac,
1574 const char *encap, const char *dst_ip, bool local)
1576 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1577 struct shash *mcast_shash;
1578 struct vtep_ctl_mcast_mac *mcast_mac;
1579 struct vteprec_physical_locator *ploc_cfg;
1580 struct vteprec_physical_locator_set *ploc_set_cfg;
1582 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1584 /* Physical locator sets are immutable, so allocate a new one. */
1585 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1587 mcast_mac = shash_find_data(mcast_shash, mac);
1589 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mac, ploc_set_cfg,
1593 mcast_mac->local_cfg = vteprec_mcast_macs_local_insert(ctx->txn);
1594 vteprec_mcast_macs_local_set_MAC(mcast_mac->local_cfg, mac);
1595 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1597 vteprec_mcast_macs_local_set_logical_switch(mcast_mac->local_cfg,
1599 mcast_mac->remote_cfg = NULL;
1601 mcast_mac->remote_cfg = vteprec_mcast_macs_remote_insert(ctx->txn);
1602 vteprec_mcast_macs_remote_set_MAC(mcast_mac->remote_cfg, mac);
1603 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1605 vteprec_mcast_macs_remote_set_logical_switch(mcast_mac->remote_cfg,
1607 mcast_mac->local_cfg = NULL;
1610 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1612 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1615 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1620 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1622 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1623 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1624 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1626 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1629 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
1630 commit_mcast_entries(mcast_mac);
1634 del_mcast_entry(struct ctl_context *ctx,
1635 struct vtep_ctl_lswitch *ls, const char *mac,
1636 const char *encap, const char *dst_ip, bool local)
1638 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1639 struct vtep_ctl_mcast_mac *mcast_mac;
1640 struct shash *mcast_shash;
1641 struct vteprec_physical_locator *ploc_cfg;
1642 struct vteprec_physical_locator_set *ploc_set_cfg;
1644 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1646 mcast_mac = shash_find_data(mcast_shash, mac);
1651 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1653 /* Couldn't find the physical locator, so just ignore. */
1657 /* Physical locator sets are immutable, so allocate a new one. */
1658 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1659 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1661 del_ploc_from_mcast_mac(mcast_mac, ploc_cfg);
1662 if (list_is_empty(&mcast_mac->locators)) {
1663 struct shash_node *node = shash_find(mcast_shash, mac);
1665 vteprec_physical_locator_set_delete(ploc_set_cfg);
1668 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1670 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1674 shash_delete(mcast_shash, node);
1677 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1680 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1683 commit_mcast_entries(mcast_mac);
1688 add_del_mcast_entry(struct ctl_context *ctx, bool add, bool local)
1690 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1691 struct vtep_ctl_lswitch *ls;
1696 vtep_ctl_context_populate_cache(ctx);
1698 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1701 if (ctx->argc == 4) {
1702 encap = "vxlan_over_ipv4";
1703 dst_ip = ctx->argv[3];
1705 encap = ctx->argv[3];
1706 dst_ip = ctx->argv[4];
1710 add_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1712 del_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1715 vtep_ctl_context_invalidate_cache(ctx);
1719 cmd_add_mcast_local(struct ctl_context *ctx)
1721 add_del_mcast_entry(ctx, true, true);
1725 cmd_add_mcast_remote(struct ctl_context *ctx)
1727 add_del_mcast_entry(ctx, true, false);
1731 cmd_del_mcast_local(struct ctl_context *ctx)
1733 add_del_mcast_entry(ctx, false, true);
1737 cmd_del_mcast_remote(struct ctl_context *ctx)
1739 add_del_mcast_entry(ctx, false, false);
1743 clear_macs(struct ctl_context *ctx, bool local)
1745 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1746 struct vtep_ctl_lswitch *ls;
1747 const struct shash_node *node;
1748 struct shash *ucast_shash;
1749 struct shash *mcast_shash;
1751 vtep_ctl_context_populate_cache(ctx);
1752 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1754 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1755 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1757 SHASH_FOR_EACH (node, ucast_shash) {
1759 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1760 vteprec_ucast_macs_local_delete(ucast_cfg);
1762 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1763 vteprec_ucast_macs_remote_delete(ucast_cfg);
1767 SHASH_FOR_EACH (node, mcast_shash) {
1768 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1770 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1772 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1776 vtep_ctl_context_invalidate_cache(ctx);
1780 cmd_clear_local_macs(struct ctl_context *ctx)
1782 clear_macs(ctx, true);
1786 cmd_clear_remote_macs(struct ctl_context *ctx)
1788 clear_macs(ctx, false);
1792 list_macs(struct ctl_context *ctx, bool local)
1794 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1795 struct vtep_ctl_lswitch *ls;
1796 const struct shash_node *node;
1797 struct shash *ucast_shash;
1798 struct svec ucast_macs;
1799 struct shash *mcast_shash;
1800 struct svec mcast_macs;
1802 vtep_ctl_context_populate_cache(ctx);
1803 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1805 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1806 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1808 svec_init(&ucast_macs);
1809 SHASH_FOR_EACH (node, ucast_shash) {
1810 struct vteprec_ucast_macs_local *ucast_local = node->data;
1811 struct vteprec_ucast_macs_remote *ucast_remote = node->data;
1812 struct vteprec_physical_locator *ploc_cfg;
1815 ploc_cfg = local ? ucast_local->locator : ucast_remote->locator;
1817 entry = xasprintf(" %s -> %s/%s", node->name,
1818 ploc_cfg->encapsulation_type, ploc_cfg->dst_ip);
1819 svec_add_nocopy(&ucast_macs, entry);
1821 ds_put_format(&ctx->output, "ucast-mac-%s\n", local ? "local" : "remote");
1822 output_sorted(&ucast_macs, &ctx->output);
1823 ds_put_char(&ctx->output, '\n');
1824 svec_destroy(&ucast_macs);
1826 svec_init(&mcast_macs);
1827 SHASH_FOR_EACH (node, mcast_shash) {
1828 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1829 struct vtep_ctl_ploc *ploc;
1832 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1833 entry = xasprintf(" %s -> %s/%s", node->name,
1834 ploc->ploc_cfg->encapsulation_type,
1835 ploc->ploc_cfg->dst_ip);
1836 svec_add_nocopy(&mcast_macs, entry);
1839 ds_put_format(&ctx->output, "mcast-mac-%s\n", local ? "local" : "remote");
1840 output_sorted(&mcast_macs, &ctx->output);
1841 ds_put_char(&ctx->output, '\n');
1842 svec_destroy(&mcast_macs);
1846 cmd_list_local_macs(struct ctl_context *ctx)
1848 list_macs(ctx, true);
1852 cmd_list_remote_macs(struct ctl_context *ctx)
1854 list_macs(ctx, false);
1858 verify_managers(const struct vteprec_global *vtep_global)
1862 vteprec_global_verify_managers(vtep_global);
1864 for (i = 0; i < vtep_global->n_managers; ++i) {
1865 const struct vteprec_manager *mgr = vtep_global->managers[i];
1867 vteprec_manager_verify_target(mgr);
1872 pre_manager(struct ctl_context *ctx)
1874 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_managers);
1875 ovsdb_idl_add_column(ctx->idl, &vteprec_manager_col_target);
1879 cmd_get_manager(struct ctl_context *ctx)
1881 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1882 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1883 struct svec targets;
1886 verify_managers(vtep_global);
1888 /* Print the targets in sorted order for reproducibility. */
1889 svec_init(&targets);
1891 for (i = 0; i < vtep_global->n_managers; i++) {
1892 svec_add(&targets, vtep_global->managers[i]->target);
1895 svec_sort_unique(&targets);
1896 for (i = 0; i < targets.n; i++) {
1897 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
1899 svec_destroy(&targets);
1903 delete_managers(const struct vtep_ctl_context *vtepctl_ctx)
1905 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1908 /* Delete Manager rows pointed to by 'managers' column. */
1909 for (i = 0; i < vtep_global->n_managers; i++) {
1910 vteprec_manager_delete(vtep_global->managers[i]);
1913 /* Delete 'Manager' row refs in 'managers' column. */
1914 vteprec_global_set_managers(vtep_global, NULL, 0);
1918 cmd_del_manager(struct ctl_context *ctx)
1920 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1921 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1923 verify_managers(vtep_global);
1924 delete_managers(vtepctl_ctx);
1928 insert_managers(struct vtep_ctl_context *vtepctl_ctx, char *targets[], size_t n)
1930 struct vteprec_manager **managers;
1933 /* Insert each manager in a new row in Manager table. */
1934 managers = xmalloc(n * sizeof *managers);
1935 for (i = 0; i < n; i++) {
1936 if (stream_verify_name(targets[i]) && pstream_verify_name(targets[i])) {
1937 VLOG_WARN("target type \"%s\" is possibly erroneous", targets[i]);
1939 managers[i] = vteprec_manager_insert(vtepctl_ctx->base.txn);
1940 vteprec_manager_set_target(managers[i], targets[i]);
1943 /* Store uuids of new Manager rows in 'managers' column. */
1944 vteprec_global_set_managers(vtepctl_ctx->vtep_global, managers, n);
1949 cmd_set_manager(struct ctl_context *ctx)
1951 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1952 const size_t n = ctx->argc - 1;
1954 verify_managers(vtepctl_ctx->vtep_global);
1955 delete_managers(vtepctl_ctx);
1956 insert_managers(vtepctl_ctx, &ctx->argv[1], n);
1959 /* Parameter commands. */
1960 static const struct ctl_table_class tables[] = {
1961 {&vteprec_table_global,
1962 {{&vteprec_table_global, NULL, NULL},
1963 {NULL, NULL, NULL}}},
1965 {&vteprec_table_logical_binding_stats,
1966 {{NULL, NULL, NULL},
1967 {NULL, NULL, NULL}}},
1969 {&vteprec_table_logical_switch,
1970 {{&vteprec_table_logical_switch, &vteprec_logical_switch_col_name, NULL},
1971 {NULL, NULL, NULL}}},
1973 {&vteprec_table_ucast_macs_local,
1974 {{NULL, NULL, NULL},
1975 {NULL, NULL, NULL}}},
1977 {&vteprec_table_ucast_macs_remote,
1978 {{NULL, NULL, NULL},
1979 {NULL, NULL, NULL}}},
1981 {&vteprec_table_mcast_macs_local,
1982 {{NULL, NULL, NULL},
1983 {NULL, NULL, NULL}}},
1985 {&vteprec_table_mcast_macs_remote,
1986 {{NULL, NULL, NULL},
1987 {NULL, NULL, NULL}}},
1989 {&vteprec_table_manager,
1990 {{&vteprec_table_manager, &vteprec_manager_col_target, NULL},
1991 {NULL, NULL, NULL}}},
1993 {&vteprec_table_physical_locator,
1994 {{NULL, NULL, NULL},
1995 {NULL, NULL, NULL}}},
1997 {&vteprec_table_physical_locator_set,
1998 {{NULL, NULL, NULL},
1999 {NULL, NULL, NULL}}},
2001 {&vteprec_table_physical_port,
2002 {{&vteprec_table_physical_port, &vteprec_physical_port_col_name, NULL},
2003 {NULL, NULL, NULL}}},
2005 {&vteprec_table_physical_switch,
2006 {{&vteprec_table_physical_switch, &vteprec_physical_switch_col_name, NULL},
2007 {NULL, NULL, NULL}}},
2009 {&vteprec_table_tunnel,
2010 {{NULL, NULL, NULL},
2011 {NULL, NULL, NULL}}},
2013 {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
2018 vtep_ctl_context_init_command(struct vtep_ctl_context *vtepctl_ctx,
2019 struct ctl_command *command)
2021 ctl_context_init_command(&vtepctl_ctx->base, command);
2022 vtepctl_ctx->verified_ports = false;
2027 vtep_ctl_context_init(struct vtep_ctl_context *vtepctl_ctx,
2028 struct ctl_command *command,
2029 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2030 const struct vteprec_global *vtep_global,
2031 struct ovsdb_symbol_table *symtab)
2033 ctl_context_init(&vtepctl_ctx->base, command, idl, txn, symtab,
2034 vtep_ctl_context_invalidate_cache);
2036 vtepctl_ctx->verified_ports = false;
2038 vtepctl_ctx->vtep_global = vtep_global;
2039 vtepctl_ctx->cache_valid = false;
2043 vtep_ctl_context_done_command(struct vtep_ctl_context *vtepctl_ctx,
2044 struct ctl_command *command)
2046 ctl_context_done_command(&vtepctl_ctx->base, command);
2050 vtep_ctl_context_done(struct vtep_ctl_context *vtepctl_ctx,
2051 struct ctl_command *command)
2053 ctl_context_done(&vtepctl_ctx->base, command);
2057 run_prerequisites(struct ctl_command *commands, size_t n_commands,
2058 struct ovsdb_idl *idl)
2060 struct ctl_command *c;
2062 ovsdb_idl_add_table(idl, &vteprec_table_global);
2063 for (c = commands; c < &commands[n_commands]; c++) {
2064 if (c->syntax->prerequisites) {
2065 struct vtep_ctl_context vtepctl_ctx;
2067 ds_init(&c->output);
2070 vtep_ctl_context_init(&vtepctl_ctx, c, idl, NULL, NULL, NULL);
2071 (c->syntax->prerequisites)(&vtepctl_ctx.base);
2072 vtep_ctl_context_done(&vtepctl_ctx, c);
2074 ovs_assert(!c->output.string);
2075 ovs_assert(!c->table);
2081 do_vtep_ctl(const char *args, struct ctl_command *commands,
2082 size_t n_commands, struct ovsdb_idl *idl)
2084 struct ovsdb_idl_txn *txn;
2085 const struct vteprec_global *vtep_global;
2086 enum ovsdb_idl_txn_status status;
2087 struct ovsdb_symbol_table *symtab;
2088 struct vtep_ctl_context vtepctl_ctx;
2089 struct ctl_command *c;
2090 struct shash_node *node;
2093 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
2095 ovsdb_idl_txn_set_dry_run(txn);
2098 ovsdb_idl_txn_add_comment(txn, "vtep-ctl: %s", args);
2100 vtep_global = vteprec_global_first(idl);
2102 /* XXX add verification that table is empty */
2103 vtep_global = vteprec_global_insert(txn);
2106 symtab = ovsdb_symbol_table_create();
2107 for (c = commands; c < &commands[n_commands]; c++) {
2108 ds_init(&c->output);
2111 vtep_ctl_context_init(&vtepctl_ctx, NULL, idl, txn, vtep_global, symtab);
2112 for (c = commands; c < &commands[n_commands]; c++) {
2113 vtep_ctl_context_init_command(&vtepctl_ctx, c);
2114 if (c->syntax->run) {
2115 (c->syntax->run)(&vtepctl_ctx.base);
2117 vtep_ctl_context_done_command(&vtepctl_ctx, c);
2119 if (vtepctl_ctx.base.try_again) {
2120 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2124 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2126 SHASH_FOR_EACH (node, &symtab->sh) {
2127 struct ovsdb_symbol *symbol = node->data;
2128 if (!symbol->created) {
2129 ctl_fatal("row id \"%s\" is referenced but never created "
2130 "(e.g. with \"-- --id=%s create ...\")",
2131 node->name, node->name);
2133 if (!symbol->strong_ref) {
2134 if (!symbol->weak_ref) {
2135 VLOG_WARN("row id \"%s\" was created but no reference to it "
2136 "was inserted, so it will not actually appear in "
2137 "the database", node->name);
2139 VLOG_WARN("row id \"%s\" was created but only a weak "
2140 "reference to it was inserted, so it will not "
2141 "actually appear in the database", node->name);
2146 status = ovsdb_idl_txn_commit_block(txn);
2147 if (status == TXN_UNCHANGED || status == TXN_SUCCESS) {
2148 for (c = commands; c < &commands[n_commands]; c++) {
2149 if (c->syntax->postprocess) {
2150 vtep_ctl_context_init(&vtepctl_ctx, c, idl, txn, vtep_global, symtab);
2151 (c->syntax->postprocess)(&vtepctl_ctx.base);
2152 vtep_ctl_context_done(&vtepctl_ctx, c);
2156 error = xstrdup(ovsdb_idl_txn_get_error(txn));
2157 ovsdb_idl_txn_destroy(txn);
2158 txn = the_idl_txn = NULL;
2161 case TXN_UNCOMMITTED:
2162 case TXN_INCOMPLETE:
2166 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2167 ctl_fatal("transaction aborted");
2177 ctl_fatal("transaction error: %s", error);
2179 case TXN_NOT_LOCKED:
2180 /* Should not happen--we never call ovsdb_idl_set_lock(). */
2181 ctl_fatal("database not locked");
2188 ovsdb_symbol_table_destroy(symtab);
2190 for (c = commands; c < &commands[n_commands]; c++) {
2191 struct ds *ds = &c->output;
2194 table_print(c->table, &table_style);
2195 } else if (oneline) {
2199 for (j = 0; j < ds->length; j++) {
2200 int ch = ds->string[j];
2203 fputs("\\n", stdout);
2207 fputs("\\\\", stdout);
2216 fputs(ds_cstr(ds), stdout);
2218 ds_destroy(&c->output);
2219 table_destroy(c->table);
2222 shash_destroy_free_data(&c->options);
2226 ovsdb_idl_destroy(idl);
2231 /* Our transaction needs to be rerun, or a prerequisite was not met. Free
2232 * resources and return so that the caller can try again. */
2234 ovsdb_idl_txn_abort(txn);
2235 ovsdb_idl_txn_destroy(txn);
2237 ovsdb_symbol_table_destroy(symtab);
2238 for (c = commands; c < &commands[n_commands]; c++) {
2239 ds_destroy(&c->output);
2240 table_destroy(c->table);
2246 static const struct ctl_command_syntax vtep_commands[] = {
2247 /* Physical Switch commands. */
2248 {"add-ps", 1, 1, NULL, pre_get_info, cmd_add_ps, NULL, "--may-exist", RW},
2249 {"del-ps", 1, 1, NULL, pre_get_info, cmd_del_ps, NULL, "--if-exists", RW},
2250 {"list-ps", 0, 0, NULL, pre_get_info, cmd_list_ps, NULL, "", RO},
2251 {"ps-exists", 1, 1, NULL, pre_get_info, cmd_ps_exists, NULL, "", RO},
2253 /* Port commands. */
2254 {"list-ports", 1, 1, NULL, pre_get_info, cmd_list_ports, NULL, "", RO},
2255 {"add-port", 2, 2, NULL, pre_get_info, cmd_add_port, NULL, "--may-exist",
2257 {"del-port", 2, 2, NULL, pre_get_info, cmd_del_port, NULL, "--if-exists",
2260 /* Logical Switch commands. */
2261 {"add-ls", 1, 1, NULL, pre_get_info, cmd_add_ls, NULL, "--may-exist", RW},
2262 {"del-ls", 1, 1, NULL, pre_get_info, cmd_del_ls, NULL, "--if-exists", RW},
2263 {"list-ls", 0, 0, NULL, pre_get_info, cmd_list_ls, NULL, "", RO},
2264 {"ls-exists", 1, 1, NULL, pre_get_info, cmd_ls_exists, NULL, "", RO},
2265 {"list-bindings", 2, 2, NULL, pre_get_info, cmd_list_bindings, NULL, "", RO},
2266 {"bind-ls", 4, 4, NULL, pre_get_info, cmd_bind_ls, NULL, "", RO},
2267 {"unbind-ls", 3, 3, NULL, pre_get_info, cmd_unbind_ls, NULL, "", RO},
2269 /* MAC binding commands. */
2270 {"add-ucast-local", 3, 4, NULL, pre_get_info, cmd_add_ucast_local, NULL,
2272 {"del-ucast-local", 2, 2, NULL, pre_get_info, cmd_del_ucast_local, NULL,
2274 {"add-mcast-local", 3, 4, NULL, pre_get_info, cmd_add_mcast_local, NULL,
2276 {"del-mcast-local", 3, 4, NULL, pre_get_info, cmd_del_mcast_local, NULL,
2278 {"clear-local-macs", 1, 1, NULL, pre_get_info, cmd_clear_local_macs, NULL,
2280 {"list-local-macs", 1, 1, NULL, pre_get_info, cmd_list_local_macs, NULL,
2282 {"add-ucast-remote", 3, 4, NULL, pre_get_info, cmd_add_ucast_remote, NULL,
2284 {"del-ucast-remote", 2, 2, NULL, pre_get_info, cmd_del_ucast_remote, NULL,
2286 {"add-mcast-remote", 3, 4, NULL, pre_get_info, cmd_add_mcast_remote, NULL,
2288 {"del-mcast-remote", 3, 4, NULL, pre_get_info, cmd_del_mcast_remote, NULL,
2290 {"clear-remote-macs", 1, 1, NULL, pre_get_info, cmd_clear_remote_macs, NULL,
2292 {"list-remote-macs", 1, 1, NULL, pre_get_info, cmd_list_remote_macs, NULL,
2295 /* Manager commands. */
2296 {"get-manager", 0, 0, NULL, pre_manager, cmd_get_manager, NULL, "", RO},
2297 {"del-manager", 0, 0, NULL, pre_manager, cmd_del_manager, NULL, "", RW},
2298 {"set-manager", 1, INT_MAX, NULL, pre_manager, cmd_set_manager, NULL, "",
2301 {NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, RO},
2304 /* Registers vsctl and common db commands. */
2306 vtep_ctl_cmd_init(void)
2309 ctl_register_commands(vtep_commands);