2 * Copyright (c) 2009, 2010, 2011, 2012, 2014, 2015 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 /* The IDL we're using and the current transaction, if any.
74 * This is for use by vtep_ctl_exit() only, to allow it to clean up.
75 * Other code should use its context arguments. */
76 static struct ovsdb_idl *the_idl;
77 static struct ovsdb_idl_txn *the_idl_txn;
79 OVS_NO_RETURN static void vtep_ctl_exit(int status);
80 static void vtep_ctl_cmd_init(void);
81 OVS_NO_RETURN static void usage(void);
82 static void parse_options(int argc, char *argv[], struct shash *local_options);
83 static void run_prerequisites(struct ctl_command[], size_t n_commands,
85 static void do_vtep_ctl(const char *args, struct ctl_command *, size_t n,
87 static struct vtep_ctl_lswitch *find_lswitch(struct vtep_ctl_context *,
92 main(int argc, char *argv[])
94 extern struct vlog_module VLM_reconnect;
95 struct ovsdb_idl *idl;
96 struct ctl_command *commands;
97 struct shash local_options;
102 set_program_name(argv[0]);
103 fatal_ignore_sigpipe();
104 vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
105 vlog_set_levels(&VLM_reconnect, VLF_ANY_DESTINATION, VLL_WARN);
110 /* Log our arguments. This is often valuable for debugging systems. */
111 args = process_escape_args(argv);
112 VLOG(ctl_might_write_to_db(argv) ? VLL_INFO : VLL_DBG, "Called as %s", args);
114 /* Parse command line. */
115 shash_init(&local_options);
116 parse_options(argc, argv, &local_options);
117 commands = ctl_parse_commands(argc - optind, argv + optind, &local_options,
124 /* Initialize IDL. */
125 idl = the_idl = ovsdb_idl_create(db, &vteprec_idl_class, false, false);
126 run_prerequisites(commands, n_commands, idl);
128 /* Execute the commands.
130 * 'seqno' is the database sequence number for which we last tried to
131 * execute our transaction. There's no point in trying to commit more than
132 * once for any given sequence number, because if the transaction fails
133 * it's because the database changed and we need to obtain an up-to-date
134 * view of the database before we try the transaction again. */
135 seqno = ovsdb_idl_get_seqno(idl);
139 if (seqno != ovsdb_idl_get_seqno(idl)) {
140 seqno = ovsdb_idl_get_seqno(idl);
141 do_vtep_ctl(args, commands, n_commands, idl);
144 if (seqno == ovsdb_idl_get_seqno(idl)) {
152 parse_options(int argc, char *argv[], struct shash *local_options)
155 OPT_DB = UCHAR_MAX + 1,
164 static const struct option global_long_options[] = {
165 {"db", required_argument, NULL, OPT_DB},
166 {"no-syslog", no_argument, NULL, OPT_NO_SYSLOG},
167 {"dry-run", no_argument, NULL, OPT_DRY_RUN},
168 {"oneline", no_argument, NULL, OPT_ONELINE},
169 {"timeout", required_argument, NULL, 't'},
170 {"help", no_argument, NULL, 'h'},
171 {"version", no_argument, NULL, 'V'},
174 STREAM_SSL_LONG_OPTIONS,
175 {"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
178 const int n_global_long_options = ARRAY_SIZE(global_long_options) - 1;
179 char *tmp, *short_options;
181 struct option *options;
182 size_t allocated_options;
186 tmp = ovs_cmdl_long_options_to_short_options(global_long_options);
187 short_options = xasprintf("+%s", tmp);
190 /* We want to parse both global and command-specific options here, but
191 * getopt_long() isn't too convenient for the job. We copy our global
192 * options into a dynamic array, then append all of the command-specific
194 options = xmemdup(global_long_options, sizeof global_long_options);
195 allocated_options = ARRAY_SIZE(global_long_options);
196 n_options = n_global_long_options;
197 ctl_add_cmd_options(&options, &n_options, &allocated_options, OPT_LOCAL);
198 table_style.format = TF_LIST;
204 c = getopt_long(argc, argv, short_options, options, &idx);
219 vlog_set_levels(&VLM_vtep_ctl, VLF_SYSLOG, VLL_WARN);
227 if (shash_find(local_options, options[idx].name)) {
228 ctl_fatal("'%s' option specified multiple times",
231 shash_add_nocopy(local_options,
232 xasprintf("--%s", options[idx].name),
233 optarg ? xstrdup(optarg) : NULL);
240 ovs_print_version(0, 0);
241 printf("DB Schema %s\n", vteprec_get_db_version());
245 timeout = strtoul(optarg, NULL, 10);
247 ctl_fatal("value %s on -t or --timeout is invalid",
253 TABLE_OPTION_HANDLERS(&table_style)
255 STREAM_SSL_OPTION_HANDLERS
257 case OPT_PEER_CA_CERT:
258 stream_ssl_set_peer_ca_cert_file(optarg);
271 db = ctl_default_db();
274 for (i = n_global_long_options; options[i].name; i++) {
275 free(CONST_CAST(char *, options[i].name));
280 /* Frees the current transaction and the underlying IDL and then calls
283 * Freeing the transaction and the IDL is not strictly necessary, but it makes
284 * for a clean memory leak report from valgrind in the normal case. That makes
285 * it easier to notice real memory leaks. */
287 vtep_ctl_exit(int status)
290 ovsdb_idl_txn_abort(the_idl_txn);
291 ovsdb_idl_txn_destroy(the_idl_txn);
293 ovsdb_idl_destroy(the_idl);
301 %s: VTEP configuration utility\n\
302 usage: %s [OPTIONS] COMMAND [ARG...]\n\
305 show print overview of database contents\n\
308 get-manager print the managers\n\
309 del-manager delete the managers\n\
310 set-manager TARGET... set the list of managers to TARGET...\n\
312 Physical Switch commands:\n\
313 add-ps PS create a new physical switch named PS\n\
314 del-ps PS delete PS and all of its ports\n\
315 list-ps print the names of all the physical switches\n\
316 ps-exists PS exit 2 if PS does not exist\n\
319 list-ports PS print the names of all the ports on PS\n\
320 add-port PS PORT add network device PORT to PS\n\
321 del-port PS PORT delete PORT from PS\n\
323 Logical Switch commands:\n\
324 add-ls LS create a new logical switch named LS\n\
325 del-ls LS delete LS and all of its ports\n\
326 list-ls print the names of all the logical switches\n\
327 ls-exists LS exit 2 if LS does not exist\n\
328 bind-ls PS PORT VLAN LS bind LS to VLAN on PORT\n\
329 unbind-ls PS PORT VLAN unbind logical switch on VLAN from PORT\n\
330 list-bindings PS PORT list bindings for PORT on PS\n\
332 MAC binding commands:\n\
333 add-ucast-local LS MAC [ENCAP] IP add ucast local entry in LS\n\
334 del-ucast-local LS MAC del ucast local entry from LS\n\
335 add-mcast-local LS MAC [ENCAP] IP add mcast local entry in LS\n\
336 del-mcast-local LS MAC [ENCAP] IP del mcast local entry from LS\n\
337 clear-local-macs LS clear local mac entries\n\
338 list-local-macs LS list local mac entries\n\
339 add-ucast-remote LS MAC [ENCAP] IP add ucast remote entry in LS\n\
340 del-ucast-remote LS MAC del ucast remote entry from LS\n\
341 add-mcast-remote LS MAC [ENCAP] IP add mcast remote entry in LS\n\
342 del-mcast-remote LS MAC [ENCAP] IP del mcast remote entry from LS\n\
343 clear-remote-macs LS clear remote mac entries\n\
344 list-remote-macs LS list remote mac entries\n\
349 --db=DATABASE connect to DATABASE\n\
351 -t, --timeout=SECS wait at most SECS seconds\n\
352 --dry-run do not commit changes to database\n\
353 --oneline print exactly one line of output per command\n",
354 program_name, program_name, ctl_get_db_cmd_usage(), ctl_default_db());
357 --no-syslog equivalent to --verbose=vtep_ctl:syslog:warn\n");
358 stream_usage("database", true, true, false);
361 -h, --help display this help message\n\
362 -V, --version display version information\n");
367 static struct cmd_show_table cmd_show_tables[] = {
368 {&vteprec_table_global,
370 {&vteprec_global_col_managers,
371 &vteprec_global_col_switches,
376 {&vteprec_table_manager,
377 &vteprec_manager_col_target,
378 {&vteprec_manager_col_is_connected,
384 {&vteprec_table_physical_switch,
385 &vteprec_physical_switch_col_name,
386 {&vteprec_physical_switch_col_management_ips,
387 &vteprec_physical_switch_col_tunnel_ips,
388 &vteprec_physical_switch_col_ports},
392 {&vteprec_table_physical_port,
393 &vteprec_physical_port_col_name,
394 {&vteprec_physical_port_col_vlan_bindings,
400 {&vteprec_table_logical_switch,
401 &vteprec_logical_switch_col_name,
408 {NULL, NULL, {NULL, NULL, NULL}, {NULL, NULL, NULL}}
411 /* vtep-ctl specific context. Inherits the 'struct ctl_context' as base. */
412 struct vtep_ctl_context {
413 struct ctl_context base;
415 /* Modifiable state. */
416 const struct vteprec_global *vtep_global;
419 /* A cache of the contents of the database.
421 * A command that needs to use any of this information must first
422 * call vtep_ctl_context_populate_cache(). A command that changes
423 * anything that could invalidate the cache must either call
424 * vtep_ctl_context_invalidate_cache() or manually update the cache
425 * to maintain its correctness. */
427 struct shash pswitches; /* Maps from physical switch name to
428 * struct vtep_ctl_pswitch. */
429 struct shash ports; /* Maps from port name to struct vtep_ctl_port. */
431 struct shash lswitches; /* Maps from logical switch name to
432 * struct vtep_ctl_lswitch. */
433 struct shash plocs; /* Maps from "<encap>+<dst_ip>" to
434 * struct vteprec_physical_locator. */
437 /* Casts 'base' into 'strcut vtep_ctl_context'. */
438 static struct vtep_ctl_context *
439 vtep_ctl_context_cast(struct ctl_context *base)
441 return CONTAINER_OF(base, struct vtep_ctl_context, base);
444 struct vtep_ctl_pswitch {
445 const struct vteprec_physical_switch *ps_cfg;
447 struct ovs_list ports; /* Contains "struct vteprec_physical_port"s. */
450 struct vtep_ctl_port {
451 struct ovs_list ports_node; /* In struct vtep_ctl_pswitch's 'ports' list. */
452 const struct vteprec_physical_port *port_cfg;
453 struct vtep_ctl_pswitch *ps;
454 struct shash bindings; /* Maps from vlan to vtep_ctl_lswitch. */
457 struct vtep_ctl_lswitch {
458 const struct vteprec_logical_switch *ls_cfg;
460 struct shash ucast_local; /* Maps from mac to vteprec_ucast_macs_local. */
461 struct shash ucast_remote; /* Maps from mac to vteprec_ucast_macs_remote.*/
462 struct shash mcast_local; /* Maps from mac to vtep_ctl_mcast_mac. */
463 struct shash mcast_remote; /* Maps from mac to vtep_ctl_mcast_mac. */
466 struct vtep_ctl_mcast_mac {
467 const struct vteprec_mcast_macs_local *local_cfg;
468 const struct vteprec_mcast_macs_remote *remote_cfg;
470 const struct vteprec_physical_locator_set *ploc_set_cfg;
471 struct ovs_list locators; /* Contains 'vtep_ctl_ploc's. */
474 struct vtep_ctl_ploc {
475 struct ovs_list locators_node; /* In struct vtep_ctl_ploc_set's 'locators'
477 const struct vteprec_physical_locator *ploc_cfg;
481 verify_ports(struct vtep_ctl_context *vtepctl_ctx)
483 if (!vtepctl_ctx->verified_ports) {
484 const struct vteprec_physical_switch *ps;
486 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
487 VTEPREC_PHYSICAL_SWITCH_FOR_EACH (ps, vtepctl_ctx->base.idl) {
488 vteprec_physical_switch_verify_ports(ps);
491 vtepctl_ctx->verified_ports = true;
495 static struct vtep_ctl_port *
496 add_port_to_cache(struct vtep_ctl_context *vtepctl_ctx,
497 struct vtep_ctl_pswitch *ps,
498 struct vteprec_physical_port *port_cfg)
500 char *cache_name = xasprintf("%s+%s", ps->name, port_cfg->name);
501 struct vtep_ctl_port *port;
503 port = xmalloc(sizeof *port);
504 list_push_back(&ps->ports, &port->ports_node);
505 port->port_cfg = port_cfg;
507 shash_add(&vtepctl_ctx->ports, cache_name, port);
509 shash_init(&port->bindings);
515 del_cached_port(struct vtep_ctl_context *vtepctl_ctx,
516 struct vtep_ctl_port *port)
518 char *cache_name = xasprintf("%s+%s", port->ps->name, port->port_cfg->name);
520 list_remove(&port->ports_node);
521 shash_find_and_delete(&vtepctl_ctx->ports, cache_name);
522 vteprec_physical_port_delete(port->port_cfg);
528 add_pswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
529 struct vteprec_physical_switch *ps_cfg)
531 struct vtep_ctl_pswitch *ps = xmalloc(sizeof *ps);
533 ps->name = xstrdup(ps_cfg->name);
534 list_init(&ps->ports);
535 shash_add(&vtepctl_ctx->pswitches, ps->name, ps);
539 vtep_delete_pswitch(const struct vteprec_global *vtep_global,
540 const struct vteprec_physical_switch *ps)
542 struct vteprec_physical_switch **pswitches;
545 pswitches = xmalloc(sizeof *vtep_global->switches
546 * vtep_global->n_switches);
547 for (i = n = 0; i < vtep_global->n_switches; i++) {
548 if (vtep_global->switches[i] != ps) {
549 pswitches[n++] = vtep_global->switches[i];
552 vteprec_global_set_switches(vtep_global, pswitches, n);
557 del_cached_pswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_pswitch *ps)
559 ovs_assert(list_is_empty(&ps->ports));
561 vteprec_physical_switch_delete(ps->ps_cfg);
562 vtep_delete_pswitch(ctx->vtep_global, ps->ps_cfg);
564 shash_find_and_delete(&ctx->pswitches, ps->name);
569 static struct vtep_ctl_lswitch *
570 add_lswitch_to_cache(struct vtep_ctl_context *vtepctl_ctx,
571 const struct vteprec_logical_switch *ls_cfg)
573 struct vtep_ctl_lswitch *ls = xmalloc(sizeof *ls);
575 ls->name = xstrdup(ls_cfg->name);
576 shash_add(&vtepctl_ctx->lswitches, ls->name, ls);
577 shash_init(&ls->ucast_local);
578 shash_init(&ls->ucast_remote);
579 shash_init(&ls->mcast_local);
580 shash_init(&ls->mcast_remote);
585 del_cached_lswitch(struct vtep_ctl_context *ctx, struct vtep_ctl_lswitch *ls)
588 vteprec_logical_switch_delete(ls->ls_cfg);
590 shash_find_and_delete(&ctx->lswitches, ls->name);
596 commit_ls_bindings(struct vtep_ctl_port *port)
598 struct vteprec_logical_switch **binding_values;
599 int64_t *binding_keys;
601 struct shash_node *node;
604 n_bindings = shash_count(&port->bindings);
605 binding_keys = xmalloc(n_bindings * sizeof *binding_keys);
606 binding_values = xmalloc(n_bindings * sizeof *binding_values);
609 SHASH_FOR_EACH(node, &port->bindings) {
610 struct vtep_ctl_lswitch *ls_entry = node->data;
612 binding_keys[i] = strtoll(node->name, NULL, 0);
613 binding_values[i] = (struct vteprec_logical_switch *)ls_entry->ls_cfg;
617 vteprec_physical_port_set_vlan_bindings(port->port_cfg,
618 binding_keys, binding_values,
620 free(binding_values);
625 add_ls_binding_to_cache(struct vtep_ctl_port *port,
627 struct vtep_ctl_lswitch *ls)
629 if (shash_find(&port->bindings, vlan)) {
630 ctl_fatal("multiple bindings for vlan %s", vlan);
633 shash_add(&port->bindings, vlan, ls);
637 del_cached_ls_binding(struct vtep_ctl_port *port, const char *vlan)
639 if (!shash_find(&port->bindings, vlan)) {
640 ctl_fatal("no binding for vlan %s", vlan);
643 shash_find_and_delete(&port->bindings, vlan);
646 static struct vteprec_physical_locator *
647 find_ploc(struct vtep_ctl_context *vtepctl_ctx, const char *encap,
650 struct vteprec_physical_locator *ploc;
651 char *name = xasprintf("%s+%s", encap, dst_ip);
653 ovs_assert(vtepctl_ctx->cache_valid);
655 ploc = shash_find_data(&vtepctl_ctx->plocs, name);
662 add_ploc_to_cache(struct vtep_ctl_context *vtepctl_ctx,
663 struct vteprec_physical_locator *ploc)
665 char *name = xasprintf("%s+%s", ploc->encapsulation_type, ploc->dst_ip);
666 struct vteprec_physical_locator *orig_ploc;
668 orig_ploc = find_ploc(vtepctl_ctx, ploc->encapsulation_type, ploc->dst_ip);
670 shash_add(&vtepctl_ctx->plocs, name, ploc);
677 add_ploc_to_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
678 struct vteprec_physical_locator *ploc_cfg)
680 struct vtep_ctl_ploc *ploc;
682 ploc = xmalloc(sizeof *ploc);
683 ploc->ploc_cfg = ploc_cfg;
684 list_push_back(&mcast_mac->locators, &ploc->locators_node);
688 del_ploc_from_mcast_mac(struct vtep_ctl_mcast_mac *mcast_mac,
689 struct vteprec_physical_locator *ploc_cfg)
691 struct vtep_ctl_ploc *ploc;
693 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
694 if (ploc->ploc_cfg == ploc_cfg) {
695 list_remove(&ploc->locators_node);
702 static struct vtep_ctl_mcast_mac *
703 add_mcast_mac_to_cache(struct vtep_ctl_context *vtepctl_ctx,
704 struct vtep_ctl_lswitch *ls, const char *mac,
705 struct vteprec_physical_locator_set *ploc_set_cfg,
708 struct vtep_ctl_mcast_mac *mcast_mac;
709 struct shash *mcast_shash;
712 mcast_mac = xmalloc(sizeof *mcast_mac);
713 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
715 mcast_mac->ploc_set_cfg = ploc_set_cfg;
716 list_init(&mcast_mac->locators);
717 shash_add(mcast_shash, mac, mcast_mac);
719 for (i = 0; i < ploc_set_cfg->n_locators; i++) {
720 struct vteprec_physical_locator *ploc_cfg;
722 ploc_cfg = ploc_set_cfg->locators[i];
723 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
724 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
731 vtep_ctl_context_invalidate_cache(struct ctl_context *ctx)
733 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
734 struct shash_node *node;
736 if (!vtepctl_ctx->cache_valid) {
739 vtepctl_ctx->cache_valid = false;
741 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
742 struct vtep_ctl_pswitch *ps = node->data;
746 shash_destroy(&vtepctl_ctx->pswitches);
748 SHASH_FOR_EACH (node, &vtepctl_ctx->ports) {
749 struct vtep_ctl_port *port = node->data;
750 shash_destroy(&port->bindings);
752 shash_destroy_free_data(&vtepctl_ctx->ports);
754 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
755 struct vtep_ctl_lswitch *ls = node->data;
756 struct shash_node *node2, *next_node2;
758 shash_destroy(&ls->ucast_local);
759 shash_destroy(&ls->ucast_remote);
761 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_local) {
762 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
763 struct vtep_ctl_ploc *ploc, *next_ploc;
765 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
766 &mcast_mac->locators) {
771 shash_destroy(&ls->mcast_local);
773 SHASH_FOR_EACH_SAFE (node2, next_node2, &ls->mcast_remote) {
774 struct vtep_ctl_mcast_mac *mcast_mac = node2->data;
775 struct vtep_ctl_ploc *ploc, *next_ploc;
777 LIST_FOR_EACH_SAFE (ploc, next_ploc, locators_node,
778 &mcast_mac->locators) {
783 shash_destroy(&ls->mcast_remote);
788 shash_destroy(&vtepctl_ctx->lswitches);
789 shash_destroy(&vtepctl_ctx->plocs);
793 pre_get_info(struct ctl_context *ctx)
795 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_switches);
797 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_name);
798 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_ports);
799 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_switch_col_tunnels);
801 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_name);
802 ovsdb_idl_add_column(ctx->idl, &vteprec_physical_port_col_vlan_bindings);
804 ovsdb_idl_add_column(ctx->idl, &vteprec_logical_switch_col_name);
806 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_MAC);
807 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_local_col_locator);
808 ovsdb_idl_add_column(ctx->idl,
809 &vteprec_ucast_macs_local_col_logical_switch);
811 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_MAC);
812 ovsdb_idl_add_column(ctx->idl, &vteprec_ucast_macs_remote_col_locator);
813 ovsdb_idl_add_column(ctx->idl,
814 &vteprec_ucast_macs_remote_col_logical_switch);
816 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_local_col_MAC);
817 ovsdb_idl_add_column(ctx->idl,
818 &vteprec_mcast_macs_local_col_locator_set);
819 ovsdb_idl_add_column(ctx->idl,
820 &vteprec_mcast_macs_local_col_logical_switch);
822 ovsdb_idl_add_column(ctx->idl, &vteprec_mcast_macs_remote_col_MAC);
823 ovsdb_idl_add_column(ctx->idl,
824 &vteprec_mcast_macs_remote_col_locator_set);
825 ovsdb_idl_add_column(ctx->idl,
826 &vteprec_mcast_macs_remote_col_logical_switch);
828 ovsdb_idl_add_column(ctx->idl,
829 &vteprec_physical_locator_set_col_locators);
831 ovsdb_idl_add_column(ctx->idl,
832 &vteprec_physical_locator_col_dst_ip);
833 ovsdb_idl_add_column(ctx->idl,
834 &vteprec_physical_locator_col_encapsulation_type);
836 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_local);
837 ovsdb_idl_add_column(ctx->idl, &vteprec_tunnel_col_remote);
841 vtep_ctl_context_populate_cache(struct ctl_context *ctx)
843 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
844 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
845 const struct vteprec_logical_switch *ls_cfg;
846 const struct vteprec_ucast_macs_local *ucast_local_cfg;
847 const struct vteprec_ucast_macs_remote *ucast_remote_cfg;
848 const struct vteprec_mcast_macs_local *mcast_local_cfg;
849 const struct vteprec_mcast_macs_remote *mcast_remote_cfg;
850 const struct vteprec_tunnel *tunnel_cfg;
851 struct sset pswitches, ports, lswitches;
854 if (vtepctl_ctx->cache_valid) {
855 /* Cache is already populated. */
858 vtepctl_ctx->cache_valid = true;
859 shash_init(&vtepctl_ctx->pswitches);
860 shash_init(&vtepctl_ctx->ports);
861 shash_init(&vtepctl_ctx->lswitches);
862 shash_init(&vtepctl_ctx->plocs);
864 sset_init(&pswitches);
866 for (i = 0; i < vtep_global->n_switches; i++) {
867 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
870 if (!sset_add(&pswitches, ps_cfg->name)) {
871 VLOG_WARN("%s: database contains duplicate physical switch name",
875 add_pswitch_to_cache(vtepctl_ctx, ps_cfg);
877 for (j = 0; j < ps_cfg->n_ports; j++) {
878 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
880 if (!sset_add(&ports, port_cfg->name)) {
881 /* Duplicate port name. (We will warn about that later.) */
886 sset_destroy(&pswitches);
887 sset_destroy(&ports);
889 sset_init(&lswitches);
890 VTEPREC_LOGICAL_SWITCH_FOR_EACH (ls_cfg, ctx->idl) {
891 if (!sset_add(&lswitches, ls_cfg->name)) {
892 VLOG_WARN("%s: database contains duplicate logical switch name",
896 add_lswitch_to_cache(vtepctl_ctx, ls_cfg);
898 sset_destroy(&lswitches);
900 VTEPREC_UCAST_MACS_LOCAL_FOR_EACH (ucast_local_cfg, ctx->idl) {
901 struct vtep_ctl_lswitch *ls;
903 if (!ucast_local_cfg->logical_switch) {
906 ls = find_lswitch(vtepctl_ctx, ucast_local_cfg->logical_switch->name,
912 if (ucast_local_cfg->locator) {
913 add_ploc_to_cache(vtepctl_ctx, ucast_local_cfg->locator);
916 shash_add(&ls->ucast_local, ucast_local_cfg->MAC, ucast_local_cfg);
919 VTEPREC_UCAST_MACS_REMOTE_FOR_EACH (ucast_remote_cfg, ctx->idl) {
920 struct vtep_ctl_lswitch *ls;
922 if (!ucast_remote_cfg->logical_switch) {
925 ls = find_lswitch(vtepctl_ctx, ucast_remote_cfg->logical_switch->name,
931 if (ucast_remote_cfg->locator) {
932 add_ploc_to_cache(vtepctl_ctx, ucast_remote_cfg->locator);
935 shash_add(&ls->ucast_remote, ucast_remote_cfg->MAC, ucast_remote_cfg);
938 VTEPREC_MCAST_MACS_LOCAL_FOR_EACH (mcast_local_cfg, ctx->idl) {
939 struct vtep_ctl_mcast_mac *mcast_mac;
940 struct vtep_ctl_lswitch *ls;
942 if (!mcast_local_cfg->logical_switch) {
945 ls = find_lswitch(vtepctl_ctx, mcast_local_cfg->logical_switch->name,
951 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_local_cfg->MAC,
952 mcast_local_cfg->locator_set,
954 mcast_mac->local_cfg = mcast_local_cfg;
957 VTEPREC_MCAST_MACS_REMOTE_FOR_EACH (mcast_remote_cfg, ctx->idl) {
958 struct vtep_ctl_mcast_mac *mcast_mac;
959 struct vtep_ctl_lswitch *ls;
961 if (!mcast_remote_cfg->logical_switch) {
964 ls = find_lswitch(vtepctl_ctx, mcast_remote_cfg->logical_switch->name,
970 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mcast_remote_cfg->MAC,
971 mcast_remote_cfg->locator_set,
973 mcast_mac->remote_cfg = mcast_remote_cfg;
976 VTEPREC_TUNNEL_FOR_EACH (tunnel_cfg, ctx->idl) {
977 if (tunnel_cfg->local) {
978 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->local);
980 if (tunnel_cfg->remote) {
981 add_ploc_to_cache(vtepctl_ctx, tunnel_cfg->remote);
985 sset_init(&pswitches);
986 for (i = 0; i < vtep_global->n_switches; i++) {
987 struct vteprec_physical_switch *ps_cfg = vtep_global->switches[i];
988 struct vtep_ctl_pswitch *ps;
991 if (!sset_add(&pswitches, ps_cfg->name)) {
994 ps = shash_find_data(&vtepctl_ctx->pswitches, ps_cfg->name);
995 for (j = 0; j < ps_cfg->n_ports; j++) {
996 struct vteprec_physical_port *port_cfg = ps_cfg->ports[j];
997 struct vtep_ctl_port *port;
1000 port = shash_find_data(&vtepctl_ctx->ports, port_cfg->name);
1002 if (port_cfg == port->port_cfg) {
1003 VLOG_WARN("%s: port is in multiple physical switches "
1005 port_cfg->name, ps->name, port->ps->name);
1007 /* Log as an error because this violates the database's
1008 * uniqueness constraints, so the database server shouldn't
1009 * have allowed it. */
1010 VLOG_ERR("%s: database contains duplicate port name",
1016 port = add_port_to_cache(vtepctl_ctx, ps, port_cfg);
1018 for (k = 0; k < port_cfg->n_vlan_bindings; k++) {
1019 struct vteprec_logical_switch *ls_cfg;
1020 struct vtep_ctl_lswitch *ls;
1023 vlan = xasprintf("%"PRId64, port_cfg->key_vlan_bindings[k]);
1024 if (shash_find(&port->bindings, vlan)) {
1025 ctl_fatal("multiple bindings for vlan %s", vlan);
1028 ls_cfg = port_cfg->value_vlan_bindings[k];
1029 ls = find_lswitch(vtepctl_ctx, ls_cfg->name, true);
1031 shash_add_nocopy(&port->bindings, vlan, ls);
1035 sset_destroy(&pswitches);
1038 static struct vtep_ctl_pswitch *
1039 find_pswitch(struct vtep_ctl_context *vtepctl_ctx, const char *name, bool must_exist)
1041 struct vtep_ctl_pswitch *ps;
1043 ovs_assert(vtepctl_ctx->cache_valid);
1045 ps = shash_find_data(&vtepctl_ctx->pswitches, name);
1046 if (must_exist && !ps) {
1047 ctl_fatal("no physical switch named %s", name);
1049 vteprec_global_verify_switches(vtepctl_ctx->vtep_global);
1053 static struct vtep_ctl_port *
1054 find_port(struct vtep_ctl_context *vtepctl_ctx, const char *ps_name,
1055 const char *port_name, bool must_exist)
1057 char *cache_name = xasprintf("%s+%s", ps_name, port_name);
1058 struct vtep_ctl_port *port;
1060 ovs_assert(vtepctl_ctx->cache_valid);
1062 port = shash_find_data(&vtepctl_ctx->ports, cache_name);
1063 if (port && !strcmp(port_name, port->ps->name)) {
1067 if (must_exist && !port) {
1068 ctl_fatal("no port named %s", port_name);
1070 verify_ports(vtepctl_ctx);
1075 pswitch_insert_port(const struct vteprec_physical_switch *ps,
1076 struct vteprec_physical_port *port)
1078 struct vteprec_physical_port **ports;
1081 ports = xmalloc(sizeof *ps->ports * (ps->n_ports + 1));
1082 for (i = 0; i < ps->n_ports; i++) {
1083 ports[i] = ps->ports[i];
1085 ports[ps->n_ports] = port;
1086 vteprec_physical_switch_set_ports(ps, ports, ps->n_ports + 1);
1091 pswitch_delete_port(const struct vteprec_physical_switch *ps,
1092 const struct vteprec_physical_port *port)
1094 struct vteprec_physical_port **ports;
1097 ports = xmalloc(sizeof *ps->ports * ps->n_ports);
1098 for (i = n = 0; i < ps->n_ports; i++) {
1099 if (ps->ports[i] != port) {
1100 ports[n++] = ps->ports[i];
1103 vteprec_physical_switch_set_ports(ps, ports, n);
1108 vtep_insert_pswitch(const struct vteprec_global *vtep_global,
1109 struct vteprec_physical_switch *ps)
1111 struct vteprec_physical_switch **pswitches;
1114 pswitches = xmalloc(sizeof *vtep_global->switches
1115 * (vtep_global->n_switches + 1));
1116 for (i = 0; i < vtep_global->n_switches; i++) {
1117 pswitches[i] = vtep_global->switches[i];
1119 pswitches[vtep_global->n_switches] = ps;
1120 vteprec_global_set_switches(vtep_global, pswitches,
1121 vtep_global->n_switches + 1);
1126 cmd_add_ps(struct ctl_context *ctx)
1128 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1129 const char *ps_name = ctx->argv[1];
1130 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1131 struct vteprec_physical_switch *ps;
1133 vtep_ctl_context_populate_cache(ctx);
1134 if (find_pswitch(vtepctl_ctx, ps_name, false)) {
1136 ctl_fatal("cannot create physical switch %s because it "
1137 "already exists", ps_name);
1142 ps = vteprec_physical_switch_insert(ctx->txn);
1143 vteprec_physical_switch_set_name(ps, ps_name);
1145 vtep_insert_pswitch(vtepctl_ctx->vtep_global, ps);
1147 vtep_ctl_context_invalidate_cache(ctx);
1151 del_port(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_port *port)
1153 pswitch_delete_port(port->ps->ps_cfg, port->port_cfg);
1154 del_cached_port(vtepctl_ctx, port);
1158 del_pswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_pswitch *ps)
1160 struct vtep_ctl_port *port, *next_port;
1162 LIST_FOR_EACH_SAFE (port, next_port, ports_node, &ps->ports) {
1163 del_port(vtepctl_ctx, port);
1166 del_cached_pswitch(vtepctl_ctx, ps);
1170 cmd_del_ps(struct ctl_context *ctx)
1172 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1173 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1174 struct vtep_ctl_pswitch *ps;
1176 vtep_ctl_context_populate_cache(ctx);
1177 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1179 del_pswitch(vtepctl_ctx, ps);
1184 output_sorted(struct svec *svec, struct ds *output)
1190 SVEC_FOR_EACH (i, name, svec) {
1191 ds_put_format(output, "%s\n", name);
1196 cmd_list_ps(struct ctl_context *ctx)
1198 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1199 struct shash_node *node;
1200 struct svec pswitches;
1202 vtep_ctl_context_populate_cache(ctx);
1204 svec_init(&pswitches);
1205 SHASH_FOR_EACH (node, &vtepctl_ctx->pswitches) {
1206 struct vtep_ctl_pswitch *ps = node->data;
1208 svec_add(&pswitches, ps->name);
1210 output_sorted(&pswitches, &ctx->output);
1211 svec_destroy(&pswitches);
1215 cmd_ps_exists(struct ctl_context *ctx)
1217 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1219 vtep_ctl_context_populate_cache(ctx);
1220 if (!find_pswitch(vtepctl_ctx, ctx->argv[1], false)) {
1226 cmd_list_ports(struct ctl_context *ctx)
1228 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1229 struct vtep_ctl_pswitch *ps;
1230 struct vtep_ctl_port *port;
1233 vtep_ctl_context_populate_cache(ctx);
1234 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1235 vteprec_physical_switch_verify_ports(ps->ps_cfg);
1238 LIST_FOR_EACH (port, ports_node, &ps->ports) {
1239 if (strcmp(port->port_cfg->name, ps->name)) {
1240 svec_add(&ports, port->port_cfg->name);
1243 output_sorted(&ports, &ctx->output);
1244 svec_destroy(&ports);
1248 add_port(struct ctl_context *ctx, const char *ps_name,
1249 const char *port_name, bool may_exist)
1251 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1252 struct vtep_ctl_port *vtep_ctl_port;
1253 struct vtep_ctl_pswitch *ps;
1254 struct vteprec_physical_port *port;
1256 vtep_ctl_context_populate_cache(ctx);
1258 vtep_ctl_port = find_port(vtepctl_ctx, ps_name, port_name, false);
1259 if (vtep_ctl_port) {
1261 ctl_fatal("cannot create a port named %s on %s because a "
1262 "port with that name already exists",
1263 port_name, ps_name);
1268 ps = find_pswitch(vtepctl_ctx, ps_name, true);
1270 port = vteprec_physical_port_insert(ctx->txn);
1271 vteprec_physical_port_set_name(port, port_name);
1273 pswitch_insert_port(ps->ps_cfg, port);
1275 add_port_to_cache(vtepctl_ctx, ps, port);
1279 cmd_add_port(struct ctl_context *ctx)
1281 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1283 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist);
1287 cmd_del_port(struct ctl_context *ctx)
1289 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1290 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1291 struct vtep_ctl_port *port;
1293 vtep_ctl_context_populate_cache(ctx);
1295 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], must_exist);
1297 if (ctx->argc == 3) {
1298 struct vtep_ctl_pswitch *ps;
1300 ps = find_pswitch(vtepctl_ctx, ctx->argv[1], true);
1301 if (port->ps != ps) {
1302 ctl_fatal("physical switch %s does not have a port %s",
1303 ctx->argv[1], ctx->argv[2]);
1307 del_port(vtepctl_ctx, port);
1311 static struct vtep_ctl_lswitch *
1312 find_lswitch(struct vtep_ctl_context *vtepctl_ctx,
1313 const char *name, bool must_exist)
1315 struct vtep_ctl_lswitch *ls;
1317 ovs_assert(vtepctl_ctx->cache_valid);
1319 ls = shash_find_data(&vtepctl_ctx->lswitches, name);
1320 if (must_exist && !ls) {
1321 ctl_fatal("no logical switch named %s", name);
1327 cmd_add_ls(struct ctl_context *ctx)
1329 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1330 const char *ls_name = ctx->argv[1];
1331 bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
1332 struct vteprec_logical_switch *ls;
1334 vtep_ctl_context_populate_cache(ctx);
1335 if (find_lswitch(vtepctl_ctx, ls_name, false)) {
1337 ctl_fatal("cannot create logical switch %s because it "
1338 "already exists", ls_name);
1343 ls = vteprec_logical_switch_insert(ctx->txn);
1344 vteprec_logical_switch_set_name(ls, ls_name);
1346 vtep_ctl_context_invalidate_cache(ctx);
1350 del_lswitch(struct vtep_ctl_context *vtepctl_ctx, struct vtep_ctl_lswitch *ls)
1352 del_cached_lswitch(vtepctl_ctx, ls);
1356 cmd_del_ls(struct ctl_context *ctx)
1358 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1359 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1360 struct vtep_ctl_lswitch *ls;
1362 vtep_ctl_context_populate_cache(ctx);
1363 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], must_exist);
1365 del_lswitch(vtepctl_ctx, ls);
1370 cmd_list_ls(struct ctl_context *ctx)
1372 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1373 struct shash_node *node;
1374 struct svec lswitches;
1376 vtep_ctl_context_populate_cache(ctx);
1378 svec_init(&lswitches);
1379 SHASH_FOR_EACH (node, &vtepctl_ctx->lswitches) {
1380 struct vtep_ctl_lswitch *ls = node->data;
1382 svec_add(&lswitches, ls->name);
1384 output_sorted(&lswitches, &ctx->output);
1385 svec_destroy(&lswitches);
1389 cmd_ls_exists(struct ctl_context *ctx)
1391 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1393 vtep_ctl_context_populate_cache(ctx);
1394 if (!find_lswitch(vtepctl_ctx, ctx->argv[1], false)) {
1400 cmd_list_bindings(struct ctl_context *ctx)
1402 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1403 const struct shash_node *node;
1404 struct vtep_ctl_port *port;
1405 struct svec bindings;
1407 vtep_ctl_context_populate_cache(ctx);
1408 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1410 svec_init(&bindings);
1411 SHASH_FOR_EACH (node, &port->bindings) {
1412 struct vtep_ctl_lswitch *lswitch = node->data;
1415 binding = xasprintf("%04lld %s", strtoll(node->name, NULL, 0),
1417 svec_add_nocopy(&bindings, binding);
1419 output_sorted(&bindings, &ctx->output);
1420 svec_destroy(&bindings);
1424 cmd_bind_ls(struct ctl_context *ctx)
1426 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1427 struct vtep_ctl_lswitch *ls;
1428 struct vtep_ctl_port *port;
1431 vtep_ctl_context_populate_cache(ctx);
1433 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1434 vlan = ctx->argv[3];
1435 ls = find_lswitch(vtepctl_ctx, ctx->argv[4], true);
1437 add_ls_binding_to_cache(port, vlan, ls);
1438 commit_ls_bindings(port);
1440 vtep_ctl_context_invalidate_cache(ctx);
1444 cmd_unbind_ls(struct ctl_context *ctx)
1446 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1447 struct vtep_ctl_port *port;
1450 vtep_ctl_context_populate_cache(ctx);
1452 port = find_port(vtepctl_ctx, ctx->argv[1], ctx->argv[2], true);
1453 vlan = ctx->argv[3];
1455 del_cached_ls_binding(port, vlan);
1456 commit_ls_bindings(port);
1458 vtep_ctl_context_invalidate_cache(ctx);
1462 add_ucast_entry(struct ctl_context *ctx, bool local)
1464 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1465 struct vtep_ctl_lswitch *ls;
1469 struct vteprec_physical_locator *ploc_cfg;
1471 vtep_ctl_context_populate_cache(ctx);
1473 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1476 if (ctx->argc == 4) {
1477 encap = "vxlan_over_ipv4";
1478 dst_ip = ctx->argv[3];
1480 encap = ctx->argv[3];
1481 dst_ip = ctx->argv[4];
1484 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1486 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1487 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1488 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1490 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1494 struct vteprec_ucast_macs_local *ucast_cfg;
1496 ucast_cfg = shash_find_data(&ls->ucast_local, mac);
1498 ucast_cfg = vteprec_ucast_macs_local_insert(ctx->txn);
1499 vteprec_ucast_macs_local_set_MAC(ucast_cfg, mac);
1500 vteprec_ucast_macs_local_set_logical_switch(ucast_cfg, ls->ls_cfg);
1501 shash_add(&ls->ucast_local, mac, ucast_cfg);
1503 vteprec_ucast_macs_local_set_locator(ucast_cfg, ploc_cfg);
1505 struct vteprec_ucast_macs_remote *ucast_cfg;
1507 ucast_cfg = shash_find_data(&ls->ucast_remote, mac);
1509 ucast_cfg = vteprec_ucast_macs_remote_insert(ctx->txn);
1510 vteprec_ucast_macs_remote_set_MAC(ucast_cfg, mac);
1511 vteprec_ucast_macs_remote_set_logical_switch(ucast_cfg, ls->ls_cfg);
1512 shash_add(&ls->ucast_remote, mac, ucast_cfg);
1514 vteprec_ucast_macs_remote_set_locator(ucast_cfg, ploc_cfg);
1517 vtep_ctl_context_invalidate_cache(ctx);
1521 cmd_add_ucast_local(struct ctl_context *ctx)
1523 add_ucast_entry(ctx, true);
1527 cmd_add_ucast_remote(struct ctl_context *ctx)
1529 add_ucast_entry(ctx, false);
1533 del_ucast_entry(struct ctl_context *ctx, bool local)
1535 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1536 struct vtep_ctl_lswitch *ls;
1537 struct shash *ucast_shash;
1538 struct shash_node *node;
1540 vtep_ctl_context_populate_cache(ctx);
1542 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1543 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1545 node = shash_find(ucast_shash, ctx->argv[2]);
1551 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1552 vteprec_ucast_macs_local_delete(ucast_cfg);
1554 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1555 vteprec_ucast_macs_remote_delete(ucast_cfg);
1557 shash_delete(ucast_shash, node);
1559 vtep_ctl_context_invalidate_cache(ctx);
1563 cmd_del_ucast_local(struct ctl_context *ctx)
1565 del_ucast_entry(ctx, true);
1569 cmd_del_ucast_remote(struct ctl_context *ctx)
1571 del_ucast_entry(ctx, false);
1575 commit_mcast_entries(struct vtep_ctl_mcast_mac *mcast_mac)
1577 struct vtep_ctl_ploc *ploc;
1578 struct vteprec_physical_locator **locators = NULL;
1582 n_locators = list_size(&mcast_mac->locators);
1583 ovs_assert(n_locators);
1585 locators = xmalloc(n_locators * sizeof *locators);
1588 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1589 locators[i] = (struct vteprec_physical_locator *)ploc->ploc_cfg;
1593 vteprec_physical_locator_set_set_locators(mcast_mac->ploc_set_cfg,
1601 add_mcast_entry(struct ctl_context *ctx,
1602 struct vtep_ctl_lswitch *ls, const char *mac,
1603 const char *encap, const char *dst_ip, bool local)
1605 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1606 struct shash *mcast_shash;
1607 struct vtep_ctl_mcast_mac *mcast_mac;
1608 struct vteprec_physical_locator *ploc_cfg;
1609 struct vteprec_physical_locator_set *ploc_set_cfg;
1611 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1613 /* Physical locator sets are immutable, so allocate a new one. */
1614 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1616 mcast_mac = shash_find_data(mcast_shash, mac);
1618 mcast_mac = add_mcast_mac_to_cache(vtepctl_ctx, ls, mac, ploc_set_cfg,
1622 mcast_mac->local_cfg = vteprec_mcast_macs_local_insert(ctx->txn);
1623 vteprec_mcast_macs_local_set_MAC(mcast_mac->local_cfg, mac);
1624 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1626 vteprec_mcast_macs_local_set_logical_switch(mcast_mac->local_cfg,
1628 mcast_mac->remote_cfg = NULL;
1630 mcast_mac->remote_cfg = vteprec_mcast_macs_remote_insert(ctx->txn);
1631 vteprec_mcast_macs_remote_set_MAC(mcast_mac->remote_cfg, mac);
1632 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1634 vteprec_mcast_macs_remote_set_logical_switch(mcast_mac->remote_cfg,
1636 mcast_mac->local_cfg = NULL;
1639 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1641 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1644 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1649 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1651 ploc_cfg = vteprec_physical_locator_insert(ctx->txn);
1652 vteprec_physical_locator_set_dst_ip(ploc_cfg, dst_ip);
1653 vteprec_physical_locator_set_encapsulation_type(ploc_cfg, encap);
1655 add_ploc_to_cache(vtepctl_ctx, ploc_cfg);
1658 add_ploc_to_mcast_mac(mcast_mac, ploc_cfg);
1659 commit_mcast_entries(mcast_mac);
1663 del_mcast_entry(struct ctl_context *ctx,
1664 struct vtep_ctl_lswitch *ls, const char *mac,
1665 const char *encap, const char *dst_ip, bool local)
1667 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1668 struct vtep_ctl_mcast_mac *mcast_mac;
1669 struct shash *mcast_shash;
1670 struct vteprec_physical_locator *ploc_cfg;
1671 struct vteprec_physical_locator_set *ploc_set_cfg;
1673 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1675 mcast_mac = shash_find_data(mcast_shash, mac);
1680 ploc_cfg = find_ploc(vtepctl_ctx, encap, dst_ip);
1682 /* Couldn't find the physical locator, so just ignore. */
1686 /* Physical locator sets are immutable, so allocate a new one. */
1687 ploc_set_cfg = vteprec_physical_locator_set_insert(ctx->txn);
1688 mcast_mac->ploc_set_cfg = ploc_set_cfg;
1690 del_ploc_from_mcast_mac(mcast_mac, ploc_cfg);
1691 if (list_is_empty(&mcast_mac->locators)) {
1692 struct shash_node *node = shash_find(mcast_shash, mac);
1694 vteprec_physical_locator_set_delete(ploc_set_cfg);
1697 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1699 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1703 shash_delete(mcast_shash, node);
1706 vteprec_mcast_macs_local_set_locator_set(mcast_mac->local_cfg,
1709 vteprec_mcast_macs_remote_set_locator_set(mcast_mac->remote_cfg,
1712 commit_mcast_entries(mcast_mac);
1717 add_del_mcast_entry(struct ctl_context *ctx, bool add, bool local)
1719 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1720 struct vtep_ctl_lswitch *ls;
1725 vtep_ctl_context_populate_cache(ctx);
1727 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1730 if (ctx->argc == 4) {
1731 encap = "vxlan_over_ipv4";
1732 dst_ip = ctx->argv[3];
1734 encap = ctx->argv[3];
1735 dst_ip = ctx->argv[4];
1739 add_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1741 del_mcast_entry(ctx, ls, mac, encap, dst_ip, local);
1744 vtep_ctl_context_invalidate_cache(ctx);
1748 cmd_add_mcast_local(struct ctl_context *ctx)
1750 add_del_mcast_entry(ctx, true, true);
1754 cmd_add_mcast_remote(struct ctl_context *ctx)
1756 add_del_mcast_entry(ctx, true, false);
1760 cmd_del_mcast_local(struct ctl_context *ctx)
1762 add_del_mcast_entry(ctx, false, true);
1766 cmd_del_mcast_remote(struct ctl_context *ctx)
1768 add_del_mcast_entry(ctx, false, false);
1772 clear_macs(struct ctl_context *ctx, bool local)
1774 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1775 struct vtep_ctl_lswitch *ls;
1776 const struct shash_node *node;
1777 struct shash *ucast_shash;
1778 struct shash *mcast_shash;
1780 vtep_ctl_context_populate_cache(ctx);
1781 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1783 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1784 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1786 SHASH_FOR_EACH (node, ucast_shash) {
1788 struct vteprec_ucast_macs_local *ucast_cfg = node->data;
1789 vteprec_ucast_macs_local_delete(ucast_cfg);
1791 struct vteprec_ucast_macs_remote *ucast_cfg = node->data;
1792 vteprec_ucast_macs_remote_delete(ucast_cfg);
1796 SHASH_FOR_EACH (node, mcast_shash) {
1797 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1799 vteprec_mcast_macs_local_delete(mcast_mac->local_cfg);
1801 vteprec_mcast_macs_remote_delete(mcast_mac->remote_cfg);
1805 vtep_ctl_context_invalidate_cache(ctx);
1809 cmd_clear_local_macs(struct ctl_context *ctx)
1811 clear_macs(ctx, true);
1815 cmd_clear_remote_macs(struct ctl_context *ctx)
1817 clear_macs(ctx, false);
1821 list_macs(struct ctl_context *ctx, bool local)
1823 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1824 struct vtep_ctl_lswitch *ls;
1825 const struct shash_node *node;
1826 struct shash *ucast_shash;
1827 struct svec ucast_macs;
1828 struct shash *mcast_shash;
1829 struct svec mcast_macs;
1831 vtep_ctl_context_populate_cache(ctx);
1832 ls = find_lswitch(vtepctl_ctx, ctx->argv[1], true);
1834 ucast_shash = local ? &ls->ucast_local : &ls->ucast_remote;
1835 mcast_shash = local ? &ls->mcast_local : &ls->mcast_remote;
1837 svec_init(&ucast_macs);
1838 SHASH_FOR_EACH (node, ucast_shash) {
1839 struct vteprec_ucast_macs_local *ucast_local = node->data;
1840 struct vteprec_ucast_macs_remote *ucast_remote = node->data;
1841 struct vteprec_physical_locator *ploc_cfg;
1844 ploc_cfg = local ? ucast_local->locator : ucast_remote->locator;
1846 entry = xasprintf(" %s -> %s/%s", node->name,
1847 ploc_cfg->encapsulation_type, ploc_cfg->dst_ip);
1848 svec_add_nocopy(&ucast_macs, entry);
1850 ds_put_format(&ctx->output, "ucast-mac-%s\n", local ? "local" : "remote");
1851 output_sorted(&ucast_macs, &ctx->output);
1852 ds_put_char(&ctx->output, '\n');
1853 svec_destroy(&ucast_macs);
1855 svec_init(&mcast_macs);
1856 SHASH_FOR_EACH (node, mcast_shash) {
1857 struct vtep_ctl_mcast_mac *mcast_mac = node->data;
1858 struct vtep_ctl_ploc *ploc;
1861 LIST_FOR_EACH (ploc, locators_node, &mcast_mac->locators) {
1862 entry = xasprintf(" %s -> %s/%s", node->name,
1863 ploc->ploc_cfg->encapsulation_type,
1864 ploc->ploc_cfg->dst_ip);
1865 svec_add_nocopy(&mcast_macs, entry);
1868 ds_put_format(&ctx->output, "mcast-mac-%s\n", local ? "local" : "remote");
1869 output_sorted(&mcast_macs, &ctx->output);
1870 ds_put_char(&ctx->output, '\n');
1871 svec_destroy(&mcast_macs);
1875 cmd_list_local_macs(struct ctl_context *ctx)
1877 list_macs(ctx, true);
1881 cmd_list_remote_macs(struct ctl_context *ctx)
1883 list_macs(ctx, false);
1887 verify_managers(const struct vteprec_global *vtep_global)
1891 vteprec_global_verify_managers(vtep_global);
1893 for (i = 0; i < vtep_global->n_managers; ++i) {
1894 const struct vteprec_manager *mgr = vtep_global->managers[i];
1896 vteprec_manager_verify_target(mgr);
1901 pre_manager(struct ctl_context *ctx)
1903 ovsdb_idl_add_column(ctx->idl, &vteprec_global_col_managers);
1904 ovsdb_idl_add_column(ctx->idl, &vteprec_manager_col_target);
1908 cmd_get_manager(struct ctl_context *ctx)
1910 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1911 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1912 struct svec targets;
1915 verify_managers(vtep_global);
1917 /* Print the targets in sorted order for reproducibility. */
1918 svec_init(&targets);
1920 for (i = 0; i < vtep_global->n_managers; i++) {
1921 svec_add(&targets, vtep_global->managers[i]->target);
1924 svec_sort_unique(&targets);
1925 for (i = 0; i < targets.n; i++) {
1926 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
1928 svec_destroy(&targets);
1932 delete_managers(const struct vtep_ctl_context *vtepctl_ctx)
1934 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1937 /* Delete Manager rows pointed to by 'managers' column. */
1938 for (i = 0; i < vtep_global->n_managers; i++) {
1939 vteprec_manager_delete(vtep_global->managers[i]);
1942 /* Delete 'Manager' row refs in 'managers' column. */
1943 vteprec_global_set_managers(vtep_global, NULL, 0);
1947 cmd_del_manager(struct ctl_context *ctx)
1949 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1950 const struct vteprec_global *vtep_global = vtepctl_ctx->vtep_global;
1952 verify_managers(vtep_global);
1953 delete_managers(vtepctl_ctx);
1957 insert_managers(struct vtep_ctl_context *vtepctl_ctx, char *targets[], size_t n)
1959 struct vteprec_manager **managers;
1962 /* Insert each manager in a new row in Manager table. */
1963 managers = xmalloc(n * sizeof *managers);
1964 for (i = 0; i < n; i++) {
1965 if (stream_verify_name(targets[i]) && pstream_verify_name(targets[i])) {
1966 VLOG_WARN("target type \"%s\" is possibly erroneous", targets[i]);
1968 managers[i] = vteprec_manager_insert(vtepctl_ctx->base.txn);
1969 vteprec_manager_set_target(managers[i], targets[i]);
1972 /* Store uuids of new Manager rows in 'managers' column. */
1973 vteprec_global_set_managers(vtepctl_ctx->vtep_global, managers, n);
1978 cmd_set_manager(struct ctl_context *ctx)
1980 struct vtep_ctl_context *vtepctl_ctx = vtep_ctl_context_cast(ctx);
1981 const size_t n = ctx->argc - 1;
1983 verify_managers(vtepctl_ctx->vtep_global);
1984 delete_managers(vtepctl_ctx);
1985 insert_managers(vtepctl_ctx, &ctx->argv[1], n);
1988 /* Parameter commands. */
1989 static const struct ctl_table_class tables[] = {
1990 {&vteprec_table_global,
1991 {{&vteprec_table_global, NULL, NULL},
1992 {NULL, NULL, NULL}}},
1994 {&vteprec_table_logical_binding_stats,
1995 {{NULL, NULL, NULL},
1996 {NULL, NULL, NULL}}},
1998 {&vteprec_table_logical_switch,
1999 {{&vteprec_table_logical_switch, &vteprec_logical_switch_col_name, NULL},
2000 {NULL, NULL, NULL}}},
2002 {&vteprec_table_ucast_macs_local,
2003 {{NULL, NULL, NULL},
2004 {NULL, NULL, NULL}}},
2006 {&vteprec_table_ucast_macs_remote,
2007 {{NULL, NULL, NULL},
2008 {NULL, NULL, NULL}}},
2010 {&vteprec_table_mcast_macs_local,
2011 {{NULL, NULL, NULL},
2012 {NULL, NULL, NULL}}},
2014 {&vteprec_table_mcast_macs_remote,
2015 {{NULL, NULL, NULL},
2016 {NULL, NULL, NULL}}},
2018 {&vteprec_table_manager,
2019 {{&vteprec_table_manager, &vteprec_manager_col_target, NULL},
2020 {NULL, NULL, NULL}}},
2022 {&vteprec_table_physical_locator,
2023 {{NULL, NULL, NULL},
2024 {NULL, NULL, NULL}}},
2026 {&vteprec_table_physical_locator_set,
2027 {{NULL, NULL, NULL},
2028 {NULL, NULL, NULL}}},
2030 {&vteprec_table_physical_port,
2031 {{&vteprec_table_physical_port, &vteprec_physical_port_col_name, NULL},
2032 {NULL, NULL, NULL}}},
2034 {&vteprec_table_physical_switch,
2035 {{&vteprec_table_physical_switch, &vteprec_physical_switch_col_name, NULL},
2036 {NULL, NULL, NULL}}},
2038 {&vteprec_table_tunnel,
2039 {{NULL, NULL, NULL},
2040 {NULL, NULL, NULL}}},
2042 {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
2047 vtep_ctl_context_init_command(struct vtep_ctl_context *vtepctl_ctx,
2048 struct ctl_command *command)
2050 ctl_context_init_command(&vtepctl_ctx->base, command);
2051 vtepctl_ctx->verified_ports = false;
2056 vtep_ctl_context_init(struct vtep_ctl_context *vtepctl_ctx,
2057 struct ctl_command *command,
2058 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2059 const struct vteprec_global *vtep_global,
2060 struct ovsdb_symbol_table *symtab)
2062 ctl_context_init(&vtepctl_ctx->base, command, idl, txn, symtab,
2063 vtep_ctl_context_invalidate_cache);
2065 vtepctl_ctx->verified_ports = false;
2067 vtepctl_ctx->vtep_global = vtep_global;
2068 vtepctl_ctx->cache_valid = false;
2072 vtep_ctl_context_done_command(struct vtep_ctl_context *vtepctl_ctx,
2073 struct ctl_command *command)
2075 ctl_context_done_command(&vtepctl_ctx->base, command);
2079 vtep_ctl_context_done(struct vtep_ctl_context *vtepctl_ctx,
2080 struct ctl_command *command)
2082 ctl_context_done(&vtepctl_ctx->base, command);
2086 run_prerequisites(struct ctl_command *commands, size_t n_commands,
2087 struct ovsdb_idl *idl)
2089 struct ctl_command *c;
2091 ovsdb_idl_add_table(idl, &vteprec_table_global);
2092 for (c = commands; c < &commands[n_commands]; c++) {
2093 if (c->syntax->prerequisites) {
2094 struct vtep_ctl_context vtepctl_ctx;
2096 ds_init(&c->output);
2099 vtep_ctl_context_init(&vtepctl_ctx, c, idl, NULL, NULL, NULL);
2100 (c->syntax->prerequisites)(&vtepctl_ctx.base);
2101 vtep_ctl_context_done(&vtepctl_ctx, c);
2103 ovs_assert(!c->output.string);
2104 ovs_assert(!c->table);
2110 do_vtep_ctl(const char *args, struct ctl_command *commands,
2111 size_t n_commands, struct ovsdb_idl *idl)
2113 struct ovsdb_idl_txn *txn;
2114 const struct vteprec_global *vtep_global;
2115 enum ovsdb_idl_txn_status status;
2116 struct ovsdb_symbol_table *symtab;
2117 struct vtep_ctl_context vtepctl_ctx;
2118 struct ctl_command *c;
2119 struct shash_node *node;
2122 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
2124 ovsdb_idl_txn_set_dry_run(txn);
2127 ovsdb_idl_txn_add_comment(txn, "vtep-ctl: %s", args);
2129 vtep_global = vteprec_global_first(idl);
2131 /* XXX add verification that table is empty */
2132 vtep_global = vteprec_global_insert(txn);
2135 symtab = ovsdb_symbol_table_create();
2136 for (c = commands; c < &commands[n_commands]; c++) {
2137 ds_init(&c->output);
2140 vtep_ctl_context_init(&vtepctl_ctx, NULL, idl, txn, vtep_global, symtab);
2141 for (c = commands; c < &commands[n_commands]; c++) {
2142 vtep_ctl_context_init_command(&vtepctl_ctx, c);
2143 if (c->syntax->run) {
2144 (c->syntax->run)(&vtepctl_ctx.base);
2146 vtep_ctl_context_done_command(&vtepctl_ctx, c);
2148 if (vtepctl_ctx.base.try_again) {
2149 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2153 vtep_ctl_context_done(&vtepctl_ctx, NULL);
2155 SHASH_FOR_EACH (node, &symtab->sh) {
2156 struct ovsdb_symbol *symbol = node->data;
2157 if (!symbol->created) {
2158 ctl_fatal("row id \"%s\" is referenced but never created "
2159 "(e.g. with \"-- --id=%s create ...\")",
2160 node->name, node->name);
2162 if (!symbol->strong_ref) {
2163 if (!symbol->weak_ref) {
2164 VLOG_WARN("row id \"%s\" was created but no reference to it "
2165 "was inserted, so it will not actually appear in "
2166 "the database", node->name);
2168 VLOG_WARN("row id \"%s\" was created but only a weak "
2169 "reference to it was inserted, so it will not "
2170 "actually appear in the database", node->name);
2175 status = ovsdb_idl_txn_commit_block(txn);
2176 if (status == TXN_UNCHANGED || status == TXN_SUCCESS) {
2177 for (c = commands; c < &commands[n_commands]; c++) {
2178 if (c->syntax->postprocess) {
2179 vtep_ctl_context_init(&vtepctl_ctx, c, idl, txn, vtep_global, symtab);
2180 (c->syntax->postprocess)(&vtepctl_ctx.base);
2181 vtep_ctl_context_done(&vtepctl_ctx, c);
2185 error = xstrdup(ovsdb_idl_txn_get_error(txn));
2186 ovsdb_idl_txn_destroy(txn);
2187 txn = the_idl_txn = NULL;
2190 case TXN_UNCOMMITTED:
2191 case TXN_INCOMPLETE:
2195 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2196 ctl_fatal("transaction aborted");
2206 ctl_fatal("transaction error: %s", error);
2208 case TXN_NOT_LOCKED:
2209 /* Should not happen--we never call ovsdb_idl_set_lock(). */
2210 ctl_fatal("database not locked");
2217 ovsdb_symbol_table_destroy(symtab);
2219 for (c = commands; c < &commands[n_commands]; c++) {
2220 struct ds *ds = &c->output;
2223 table_print(c->table, &table_style);
2224 } else if (oneline) {
2228 for (j = 0; j < ds->length; j++) {
2229 int ch = ds->string[j];
2232 fputs("\\n", stdout);
2236 fputs("\\\\", stdout);
2245 fputs(ds_cstr(ds), stdout);
2247 ds_destroy(&c->output);
2248 table_destroy(c->table);
2251 shash_destroy_free_data(&c->options);
2255 ovsdb_idl_destroy(idl);
2260 /* Our transaction needs to be rerun, or a prerequisite was not met. Free
2261 * resources and return so that the caller can try again. */
2263 ovsdb_idl_txn_abort(txn);
2264 ovsdb_idl_txn_destroy(txn);
2266 ovsdb_symbol_table_destroy(symtab);
2267 for (c = commands; c < &commands[n_commands]; c++) {
2268 ds_destroy(&c->output);
2269 table_destroy(c->table);
2275 static const struct ctl_command_syntax vtep_commands[] = {
2276 /* Physical Switch commands. */
2277 {"add-ps", 1, 1, NULL, pre_get_info, cmd_add_ps, NULL, "--may-exist", RW},
2278 {"del-ps", 1, 1, NULL, pre_get_info, cmd_del_ps, NULL, "--if-exists", RW},
2279 {"list-ps", 0, 0, NULL, pre_get_info, cmd_list_ps, NULL, "", RO},
2280 {"ps-exists", 1, 1, NULL, pre_get_info, cmd_ps_exists, NULL, "", RO},
2282 /* Port commands. */
2283 {"list-ports", 1, 1, NULL, pre_get_info, cmd_list_ports, NULL, "", RO},
2284 {"add-port", 2, 2, NULL, pre_get_info, cmd_add_port, NULL, "--may-exist",
2286 {"del-port", 2, 2, NULL, pre_get_info, cmd_del_port, NULL, "--if-exists",
2289 /* Logical Switch commands. */
2290 {"add-ls", 1, 1, NULL, pre_get_info, cmd_add_ls, NULL, "--may-exist", RW},
2291 {"del-ls", 1, 1, NULL, pre_get_info, cmd_del_ls, NULL, "--if-exists", RW},
2292 {"list-ls", 0, 0, NULL, pre_get_info, cmd_list_ls, NULL, "", RO},
2293 {"ls-exists", 1, 1, NULL, pre_get_info, cmd_ls_exists, NULL, "", RO},
2294 {"list-bindings", 2, 2, NULL, pre_get_info, cmd_list_bindings, NULL, "", RO},
2295 {"bind-ls", 4, 4, NULL, pre_get_info, cmd_bind_ls, NULL, "", RO},
2296 {"unbind-ls", 3, 3, NULL, pre_get_info, cmd_unbind_ls, NULL, "", RO},
2298 /* MAC binding commands. */
2299 {"add-ucast-local", 3, 4, NULL, pre_get_info, cmd_add_ucast_local, NULL,
2301 {"del-ucast-local", 2, 2, NULL, pre_get_info, cmd_del_ucast_local, NULL,
2303 {"add-mcast-local", 3, 4, NULL, pre_get_info, cmd_add_mcast_local, NULL,
2305 {"del-mcast-local", 3, 4, NULL, pre_get_info, cmd_del_mcast_local, NULL,
2307 {"clear-local-macs", 1, 1, NULL, pre_get_info, cmd_clear_local_macs, NULL,
2309 {"list-local-macs", 1, 1, NULL, pre_get_info, cmd_list_local_macs, NULL,
2311 {"add-ucast-remote", 3, 4, NULL, pre_get_info, cmd_add_ucast_remote, NULL,
2313 {"del-ucast-remote", 2, 2, NULL, pre_get_info, cmd_del_ucast_remote, NULL,
2315 {"add-mcast-remote", 3, 4, NULL, pre_get_info, cmd_add_mcast_remote, NULL,
2317 {"del-mcast-remote", 3, 4, NULL, pre_get_info, cmd_del_mcast_remote, NULL,
2319 {"clear-remote-macs", 1, 1, NULL, pre_get_info, cmd_clear_remote_macs, NULL,
2321 {"list-remote-macs", 1, 1, NULL, pre_get_info, cmd_list_remote_macs, NULL,
2324 /* Manager commands. */
2325 {"get-manager", 0, 0, NULL, pre_manager, cmd_get_manager, NULL, "", RO},
2326 {"del-manager", 0, 0, NULL, pre_manager, cmd_del_manager, NULL, "", RW},
2327 {"set-manager", 1, INT_MAX, NULL, pre_manager, cmd_set_manager, NULL, "",
2330 {NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, RO},
2333 /* Registers vsctl and common db commands. */
2335 vtep_ctl_cmd_init(void)
2337 ctl_init(tables, cmd_show_tables, vtep_ctl_exit);
2338 ctl_register_commands(vtep_commands);