2 * Copyright (c) 2009, 2010 Nicira Networks.
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 "command-line.h"
33 #include "dynamic-string.h"
35 #include "ovsdb-data.h"
36 #include "ovsdb-idl.h"
37 #include "poll-loop.h"
39 #include "stream-ssl.h"
41 #include "vswitchd/vswitch-idl.h"
46 #define THIS_MODULE VLM_vsctl
48 /* vsctl_fatal() also logs the error, so it is preferred in this file. */
49 #define ovs_fatal please_use_vsctl_fatal_instead_of_ovs_fatal
53 typedef void vsctl_handler_func(struct vsctl_context *);
55 struct vsctl_command_syntax {
59 vsctl_handler_func *run;
60 vsctl_handler_func *postprocess;
64 struct vsctl_command {
65 /* Data that remains constant after initialization. */
66 const struct vsctl_command_syntax *syntax;
71 /* Data modified by commands. */
75 /* --db: The database server to contact. */
76 static const char *db;
78 /* --oneline: Write each command's output as a single line? */
81 /* --dry-run: Do not commit any changes. */
84 /* --no-wait: Wait for ovs-vswitchd to reload its configuration? */
85 static bool wait_for_reload = true;
87 /* --timeout: Time to wait for a connection to 'db'. */
88 static int timeout = 5;
90 /* All supported commands. */
91 static const struct vsctl_command_syntax all_commands[];
93 /* The IDL we're using and the current transaction, if any.
94 * This is for use by vsctl_exit() only, to allow it to clean up.
95 * Other code should use its context arguments. */
96 static struct ovsdb_idl *the_idl;
97 static struct ovsdb_idl_txn *the_idl_txn;
99 static void vsctl_exit(int status) NO_RETURN;
100 static void vsctl_fatal(const char *, ...) PRINTF_FORMAT(1, 2) NO_RETURN;
101 static char *default_db(void);
102 static void usage(void) NO_RETURN;
103 static void parse_options(int argc, char *argv[]);
105 static struct vsctl_command *parse_commands(int argc, char *argv[],
106 size_t *n_commandsp);
107 static void parse_command(int argc, char *argv[], struct vsctl_command *);
108 static void do_vsctl(const char *args,
109 struct vsctl_command *, size_t n_commands,
112 static const struct vsctl_table_class *get_table(const char *table_name);
113 static void set_column(const struct vsctl_table_class *,
114 const struct ovsdb_idl_row *, const char *arg,
115 struct ovsdb_symbol_table *);
119 main(int argc, char *argv[])
121 struct ovsdb_idl *idl;
123 struct vsctl_command *commands;
128 set_program_name(argv[0]);
129 signal(SIGPIPE, SIG_IGN);
132 vlog_set_levels(VLM_ANY_MODULE, VLF_CONSOLE, VLL_WARN);
133 vlog_set_levels(VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN);
136 /* Log our arguments. This is often valuable for debugging systems. */
137 args = process_escape_args(argv);
138 VLOG_INFO("Called as %s", args);
140 /* Parse command line. */
141 parse_options(argc, argv);
142 commands = parse_commands(argc - optind, argv + optind, &n_commands);
148 /* Now execute the commands. */
149 idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class);
150 seqno = ovsdb_idl_get_seqno(idl);
153 unsigned int new_seqno;
156 new_seqno = ovsdb_idl_get_seqno(idl);
157 if (new_seqno != seqno) {
159 vsctl_fatal("too many database inconsistency failures");
161 do_vsctl(args, commands, n_commands, idl);
171 parse_options(int argc, char *argv[])
174 OPT_DB = UCHAR_MAX + 1,
182 static struct option long_options[] = {
183 {"db", required_argument, 0, OPT_DB},
184 {"no-syslog", no_argument, 0, OPT_NO_SYSLOG},
185 {"no-wait", no_argument, 0, OPT_NO_WAIT},
186 {"dry-run", no_argument, 0, OPT_DRY_RUN},
187 {"oneline", no_argument, 0, OPT_ONELINE},
188 {"timeout", required_argument, 0, 't'},
189 {"help", no_argument, 0, 'h'},
190 {"version", no_argument, 0, 'V'},
193 STREAM_SSL_LONG_OPTIONS
194 {"peer-ca-cert", required_argument, 0, OPT_PEER_CA_CERT},
203 c = getopt_long(argc, argv, "+v::hVt:", long_options, NULL);
218 vlog_set_levels(VLM_vsctl, VLF_SYSLOG, VLL_WARN);
222 wait_for_reload = false;
233 OVS_PRINT_VERSION(0, 0);
237 timeout = strtoul(optarg, NULL, 10);
239 vsctl_fatal("value %s on -t or --timeout is invalid",
247 STREAM_SSL_OPTION_HANDLERS
249 case OPT_PEER_CA_CERT:
250 stream_ssl_set_peer_ca_cert_file(optarg);
267 static struct vsctl_command *
268 parse_commands(int argc, char *argv[], size_t *n_commandsp)
270 struct vsctl_command *commands;
271 size_t n_commands, allocated_commands;
275 n_commands = allocated_commands = 0;
277 for (start = i = 0; i <= argc; i++) {
278 if (i == argc || !strcmp(argv[i], "--")) {
280 if (n_commands >= allocated_commands) {
281 struct vsctl_command *c;
283 commands = x2nrealloc(commands, &allocated_commands,
285 for (c = commands; c < &commands[n_commands]; c++) {
286 shash_moved(&c->options);
289 parse_command(i - start, &argv[start],
290 &commands[n_commands++]);
296 vsctl_fatal("missing command name (use --help for help)");
298 *n_commandsp = n_commands;
303 parse_command(int argc, char *argv[], struct vsctl_command *command)
305 const struct vsctl_command_syntax *p;
308 shash_init(&command->options);
309 for (i = 0; i < argc; i++) {
310 const char *option = argv[i];
314 if (option[0] != '-') {
318 equals = strchr(option, '=');
320 key = xmemdup0(option, equals - option);
321 value = xstrdup(equals + 1);
323 key = xstrdup(option);
327 if (shash_find(&command->options, key)) {
328 vsctl_fatal("'%s' option specified multiple times", argv[i]);
330 shash_add_nocopy(&command->options, key, value);
333 vsctl_fatal("missing command name");
336 for (p = all_commands; p->name; p++) {
337 if (!strcmp(p->name, argv[i])) {
338 struct shash_node *node;
341 SHASH_FOR_EACH (node, &command->options) {
342 const char *s = strstr(p->options, node->name);
343 int end = s ? s[strlen(node->name)] : EOF;
345 if (end != '=' && end != ',' && end != ' ' && end != '\0') {
346 vsctl_fatal("'%s' command has no '%s' option",
347 argv[i], node->name);
349 if ((end == '=') != (node->data != NULL)) {
351 vsctl_fatal("missing argument to '%s' option on '%s' "
352 "command", node->name, argv[i]);
354 vsctl_fatal("'%s' option on '%s' does not accept an "
355 "argument", node->name, argv[i]);
360 n_arg = argc - i - 1;
361 if (n_arg < p->min_args) {
362 vsctl_fatal("'%s' command requires at least %d arguments",
363 p->name, p->min_args);
364 } else if (n_arg > p->max_args) {
367 for (j = i + 1; j < argc; j++) {
368 if (argv[j][0] == '-') {
369 vsctl_fatal("'%s' command takes at most %d arguments "
370 "(note that options must precede command "
371 "names and follow a \"--\" argument)",
372 p->name, p->max_args);
376 vsctl_fatal("'%s' command takes at most %d arguments",
377 p->name, p->max_args);
380 command->argc = n_arg + 1;
381 command->argv = &argv[i];
387 vsctl_fatal("unknown command '%s'; use --help for help", argv[i]);
391 vsctl_fatal(const char *format, ...)
396 va_start(args, format);
397 message = xvasprintf(format, args);
400 vlog_set_levels(VLM_vsctl, VLF_CONSOLE, VLL_EMER);
401 VLOG_ERR("%s", message);
402 ovs_error(0, "%s", message);
403 vsctl_exit(EXIT_FAILURE);
406 /* Frees the current transaction and the underlying IDL and then calls
409 * Freeing the transaction and the IDL is not strictly necessary, but it makes
410 * for a clean memory leak report from valgrind in the normal case. That makes
411 * it easier to notice real memory leaks. */
413 vsctl_exit(int status)
416 ovsdb_idl_txn_abort(the_idl_txn);
417 ovsdb_idl_txn_destroy(the_idl_txn);
419 ovsdb_idl_destroy(the_idl);
427 %s: ovs-vswitchd management utility\n\
428 usage: %s [OPTIONS] COMMAND [ARG...]\n\
431 add-br BRIDGE create a new bridge named BRIDGE\n\
432 add-br BRIDGE PARENT VLAN create new fake BRIDGE in PARENT on VLAN\n\
433 del-br BRIDGE delete BRIDGE and all of its ports\n\
434 list-br print the names of all the bridges\n\
435 br-exists BRIDGE test whether BRIDGE exists\n\
436 br-to-vlan BRIDGE print the VLAN which BRIDGE is on\n\
437 br-to-parent BRIDGE print the parent of BRIDGE\n\
438 br-set-external-id BRIDGE KEY VALUE set KEY on BRIDGE to VALUE\n\
439 br-set-external-id BRIDGE KEY unset KEY on BRIDGE\n\
440 br-get-external-id BRIDGE KEY print value of KEY on BRIDGE\n\
441 br-get-external-id BRIDGE list key-value pairs on BRIDGE\n\
444 list-ports BRIDGE print the names of all the ports on BRIDGE\n\
445 add-port BRIDGE PORT add network device PORT to BRIDGE\n\
446 add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES\n\
447 del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE\n\
448 port-to-br PORT print name of bridge that contains PORT\n\
449 A bond is considered to be a single port.\n\
451 Interface commands (a bond consists of multiple interfaces):\n\
452 list-ifaces BRIDGE print the names of all interfaces on BRIDGE\n\
453 iface-to-br IFACE print name of bridge that contains IFACE\n\
455 Controller commands:\n\
456 get-controller [BRIDGE] print the controller for BRIDGE\n\
457 del-controller [BRIDGE] delete the controller for BRIDGE\n\
458 set-controller [BRIDGE] TARGET set the controller for BRIDGE to TARGET\n\
459 get-fail-mode [BRIDGE] print the fail-mode for BRIDGE\n\
460 del-fail-mode [BRIDGE] delete the fail-mode for BRIDGE\n\
461 set-fail-mode [BRIDGE] MODE set the fail-mode for BRIDGE to MODE\n\
464 get-ssl print the SSL configuration\n\
465 del-ssl delete the SSL configuration\n\
466 set-ssl PRIV-KEY CERT CA-CERT set the SSL configuration\n\
469 emer-reset reset switch to known good state\n\
471 Database commands:\n\
472 list TBL [REC] list RECord (or all records) in TBL\n\
473 get TBL REC COL[:KEY] print values of COLumns in RECORD in TBL\n\
474 set TBL REC COL[:KEY]=VALUE set COLumn values in RECord in TBL\n\
475 add TBL REC COL [KEY=]VALUE add (KEY=)VALUE to COLumn in RECord in TBL\n\
476 remove TBL REC COL [KEY=]VALUE remove (KEY=)VALUE from COLumn\n\
477 clear TBL REC COL clear values from COLumn in RECord in TBL\n\
478 create TBL COL[:KEY]=VALUE create and initialize new record\n\
479 destroy TBL REC delete REC from TBL\n\
480 Potentially unsafe database commands require --force option.\n\
483 --db=DATABASE connect to DATABASE\n\
485 --oneline print exactly one line of output per command\n",
486 program_name, program_name, default_db());
490 -h, --help display this help message\n\
491 -V, --version display version information\n");
500 def = xasprintf("unix:%s/db.sock", ovs_rundir);
505 struct vsctl_context {
509 struct shash options;
511 /* Modifiable state. */
513 struct ovsdb_idl *idl;
514 struct ovsdb_idl_txn *txn;
515 struct ovsdb_symbol_table *symtab;
516 const struct ovsrec_open_vswitch *ovs;
519 struct vsctl_bridge {
520 struct ovsrec_bridge *br_cfg;
522 struct ovsrec_controller **ctrl;
524 struct vsctl_bridge *parent;
529 struct ovsrec_port *port_cfg;
530 struct vsctl_bridge *bridge;
534 struct ovsrec_interface *iface_cfg;
535 struct vsctl_port *port;
539 struct shash bridges;
542 struct ovsrec_controller **ctrl;
547 vsctl_context_to_string(const struct vsctl_context *ctx)
549 const struct shash_node *node;
555 SHASH_FOR_EACH (node, &ctx->options) {
556 svec_add(&words, node->name);
558 for (i = 0; i < ctx->argc; i++) {
559 svec_add(&words, ctx->argv[i]);
561 svec_terminate(&words);
563 s = process_escape_args(words.names);
565 svec_destroy(&words);
570 static struct vsctl_bridge *
571 add_bridge(struct vsctl_info *b,
572 struct ovsrec_bridge *br_cfg, const char *name,
573 struct vsctl_bridge *parent, int vlan)
575 struct vsctl_bridge *br = xmalloc(sizeof *br);
577 br->name = xstrdup(name);
581 br->ctrl = parent->br_cfg->controller;
582 br->n_ctrl = parent->br_cfg->n_controller;
584 br->ctrl = br_cfg->controller;
585 br->n_ctrl = br_cfg->n_controller;
587 shash_add(&b->bridges, br->name, br);
592 port_is_fake_bridge(const struct ovsrec_port *port_cfg)
594 return (port_cfg->fake_bridge
596 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095);
599 static struct vsctl_bridge *
600 find_vlan_bridge(struct vsctl_info *info,
601 struct vsctl_bridge *parent, int vlan)
603 struct shash_node *node;
605 SHASH_FOR_EACH (node, &info->bridges) {
606 struct vsctl_bridge *br = node->data;
607 if (br->parent == parent && br->vlan == vlan) {
616 free_info(struct vsctl_info *info)
618 struct shash_node *node;
620 SHASH_FOR_EACH (node, &info->bridges) {
621 struct vsctl_bridge *bridge = node->data;
625 shash_destroy(&info->bridges);
627 shash_destroy_free_data(&info->ports);
628 shash_destroy_free_data(&info->ifaces);
632 get_info(const struct ovsrec_open_vswitch *ovs, struct vsctl_info *info)
634 struct shash bridges, ports;
637 shash_init(&info->bridges);
638 shash_init(&info->ports);
639 shash_init(&info->ifaces);
641 info->ctrl = ovs->controller;
642 info->n_ctrl = ovs->n_controller;
644 shash_init(&bridges);
646 for (i = 0; i < ovs->n_bridges; i++) {
647 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
648 struct vsctl_bridge *br;
651 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
652 VLOG_WARN("%s: database contains duplicate bridge name",
656 br = add_bridge(info, br_cfg, br_cfg->name, NULL, 0);
661 for (j = 0; j < br_cfg->n_ports; j++) {
662 struct ovsrec_port *port_cfg = br_cfg->ports[j];
664 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
665 VLOG_WARN("%s: database contains duplicate port name",
670 if (port_is_fake_bridge(port_cfg)
671 && shash_add_once(&bridges, port_cfg->name, NULL)) {
672 add_bridge(info, NULL, port_cfg->name, br, *port_cfg->tag);
676 shash_destroy(&bridges);
677 shash_destroy(&ports);
679 shash_init(&bridges);
681 for (i = 0; i < ovs->n_bridges; i++) {
682 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
683 struct vsctl_bridge *br;
686 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
689 br = shash_find_data(&info->bridges, br_cfg->name);
690 for (j = 0; j < br_cfg->n_ports; j++) {
691 struct ovsrec_port *port_cfg = br_cfg->ports[j];
692 struct vsctl_port *port;
695 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
699 if (port_is_fake_bridge(port_cfg)
700 && !shash_add_once(&bridges, port_cfg->name, NULL)) {
704 port = xmalloc(sizeof *port);
705 port->port_cfg = port_cfg;
707 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095) {
708 port->bridge = find_vlan_bridge(info, br, *port_cfg->tag);
715 shash_add(&info->ports, port_cfg->name, port);
717 for (k = 0; k < port_cfg->n_interfaces; k++) {
718 struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k];
719 struct vsctl_iface *iface;
721 if (shash_find(&info->ifaces, iface_cfg->name)) {
722 VLOG_WARN("%s: database contains duplicate interface name",
727 iface = xmalloc(sizeof *iface);
728 iface->iface_cfg = iface_cfg;
730 shash_add(&info->ifaces, iface_cfg->name, iface);
734 shash_destroy(&bridges);
735 shash_destroy(&ports);
739 check_conflicts(struct vsctl_info *info, const char *name,
742 struct vsctl_iface *iface;
743 struct vsctl_port *port;
745 if (shash_find(&info->bridges, name)) {
746 vsctl_fatal("%s because a bridge named %s already exists",
750 port = shash_find_data(&info->ports, name);
752 vsctl_fatal("%s because a port named %s already exists on "
753 "bridge %s", msg, name, port->bridge->name);
756 iface = shash_find_data(&info->ifaces, name);
758 vsctl_fatal("%s because an interface named %s already exists "
759 "on bridge %s", msg, name, iface->port->bridge->name);
765 static struct vsctl_bridge *
766 find_bridge(struct vsctl_info *info, const char *name, bool must_exist)
768 struct vsctl_bridge *br = shash_find_data(&info->bridges, name);
769 if (must_exist && !br) {
770 vsctl_fatal("no bridge named %s", name);
775 static struct vsctl_bridge *
776 find_real_bridge(struct vsctl_info *info, const char *name, bool must_exist)
778 struct vsctl_bridge *br = find_bridge(info, name, must_exist);
779 if (br && br->parent) {
780 vsctl_fatal("%s is a fake bridge", name);
785 static struct vsctl_port *
786 find_port(struct vsctl_info *info, const char *name, bool must_exist)
788 struct vsctl_port *port = shash_find_data(&info->ports, name);
789 if (port && !strcmp(name, port->bridge->name)) {
792 if (must_exist && !port) {
793 vsctl_fatal("no port named %s", name);
798 static struct vsctl_iface *
799 find_iface(struct vsctl_info *info, const char *name, bool must_exist)
801 struct vsctl_iface *iface = shash_find_data(&info->ifaces, name);
802 if (iface && !strcmp(name, iface->port->bridge->name)) {
805 if (must_exist && !iface) {
806 vsctl_fatal("no interface named %s", name);
812 bridge_insert_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
814 struct ovsrec_port **ports;
817 ports = xmalloc(sizeof *br->ports * (br->n_ports + 1));
818 for (i = 0; i < br->n_ports; i++) {
819 ports[i] = br->ports[i];
821 ports[br->n_ports] = port;
822 ovsrec_bridge_set_ports(br, ports, br->n_ports + 1);
827 bridge_delete_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
829 struct ovsrec_port **ports;
832 ports = xmalloc(sizeof *br->ports * br->n_ports);
833 for (i = n = 0; i < br->n_ports; i++) {
834 if (br->ports[i] != port) {
835 ports[n++] = br->ports[i];
838 ovsrec_bridge_set_ports(br, ports, n);
843 ovs_insert_bridge(const struct ovsrec_open_vswitch *ovs,
844 struct ovsrec_bridge *bridge)
846 struct ovsrec_bridge **bridges;
849 bridges = xmalloc(sizeof *ovs->bridges * (ovs->n_bridges + 1));
850 for (i = 0; i < ovs->n_bridges; i++) {
851 bridges[i] = ovs->bridges[i];
853 bridges[ovs->n_bridges] = bridge;
854 ovsrec_open_vswitch_set_bridges(ovs, bridges, ovs->n_bridges + 1);
859 ovs_delete_bridge(const struct ovsrec_open_vswitch *ovs,
860 struct ovsrec_bridge *bridge)
862 struct ovsrec_bridge **bridges;
865 bridges = xmalloc(sizeof *ovs->bridges * ovs->n_bridges);
866 for (i = n = 0; i < ovs->n_bridges; i++) {
867 if (ovs->bridges[i] != bridge) {
868 bridges[n++] = ovs->bridges[i];
871 ovsrec_open_vswitch_set_bridges(ovs, bridges, n);
876 cmd_init(struct vsctl_context *ctx OVS_UNUSED)
881 cmd_emer_reset(struct vsctl_context *ctx)
883 const struct ovsdb_idl *idl = ctx->idl;
884 const struct ovsrec_bridge *br;
885 const struct ovsrec_port *port;
886 const struct ovsrec_interface *iface;
887 const struct ovsrec_mirror *mirror, *next_mirror;
888 const struct ovsrec_controller *ctrl, *next_ctrl;
889 const struct ovsrec_netflow *nf, *next_nf;
890 const struct ovsrec_ssl *ssl, *next_ssl;
891 const struct ovsrec_sflow *sflow, *next_sflow;
894 /* Reset the Open_vSwitch table. */
895 ovsrec_open_vswitch_set_managers(ctx->ovs, NULL, 0);
896 ovsrec_open_vswitch_set_controller(ctx->ovs, NULL, 0);
897 ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL);
899 OVSREC_BRIDGE_FOR_EACH (br, idl) {
901 char *hw_key = "hwaddr";
904 ovsrec_bridge_set_controller(br, NULL, 0);
905 ovsrec_bridge_set_mirrors(br, NULL, 0);
906 ovsrec_bridge_set_netflow(br, NULL);
907 ovsrec_bridge_set_sflow(br, NULL);
908 ovsrec_bridge_set_flood_vlans(br, NULL, 0);
910 /* We only want to save the "hwaddr" key from other_config. */
911 for (i=0; i < br->n_other_config; i++) {
912 if (!strcmp(br->key_other_config[i], hw_key)) {
913 hw_val = br->value_other_config[i];
918 char *val = xstrdup(hw_val);
919 ovsrec_bridge_set_other_config(br, &hw_key, &val, 1);
922 ovsrec_bridge_set_other_config(br, NULL, NULL, 0);
926 OVSREC_PORT_FOR_EACH (port, idl) {
927 ovsrec_port_set_other_config(port, NULL, NULL, 0);
930 OVSREC_INTERFACE_FOR_EACH (iface, idl) {
931 /* xxx What do we do about gre/patch devices created by mgr? */
933 ovsrec_interface_set_ingress_policing_rate(iface, 0);
934 ovsrec_interface_set_ingress_policing_burst(iface, 0);
937 OVSREC_MIRROR_FOR_EACH_SAFE (mirror, next_mirror, idl) {
938 ovsrec_mirror_delete(mirror);
941 OVSREC_CONTROLLER_FOR_EACH_SAFE (ctrl, next_ctrl, idl) {
942 ovsrec_controller_delete(ctrl);
945 OVSREC_NETFLOW_FOR_EACH_SAFE (nf, next_nf, idl) {
946 ovsrec_netflow_delete(nf);
949 OVSREC_SSL_FOR_EACH_SAFE (ssl, next_ssl, idl) {
950 ovsrec_ssl_delete(ssl);
953 OVSREC_SFLOW_FOR_EACH_SAFE (sflow, next_sflow, idl) {
954 ovsrec_sflow_delete(sflow);
959 cmd_add_br(struct vsctl_context *ctx)
961 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
962 const char *br_name, *parent_name;
963 struct vsctl_info info;
966 br_name = ctx->argv[1];
967 if (ctx->argc == 2) {
970 } else if (ctx->argc == 4) {
971 parent_name = ctx->argv[2];
972 vlan = atoi(ctx->argv[3]);
973 if (vlan < 1 || vlan > 4095) {
974 vsctl_fatal("%s: vlan must be between 1 and 4095", ctx->argv[0]);
977 vsctl_fatal("'%s' command takes exactly 1 or 3 arguments",
981 get_info(ctx->ovs, &info);
983 struct vsctl_bridge *br;
985 br = find_bridge(&info, br_name, false);
989 vsctl_fatal("\"--may-exist add-br %s\" but %s is "
990 "a VLAN bridge for VLAN %d",
991 br_name, br_name, br->vlan);
995 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
996 "is not a VLAN bridge",
997 br_name, parent_name, vlan, br_name);
998 } else if (strcmp(br->parent->name, parent_name)) {
999 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
1000 "has the wrong parent %s",
1001 br_name, parent_name, vlan,
1002 br_name, br->parent->name);
1003 } else if (br->vlan != vlan) {
1004 vsctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
1005 "is a VLAN bridge for the wrong VLAN %d",
1006 br_name, parent_name, vlan, br_name, br->vlan);
1012 check_conflicts(&info, br_name,
1013 xasprintf("cannot create a bridge named %s", br_name));
1016 struct ovsrec_port *port;
1017 struct ovsrec_interface *iface;
1018 struct ovsrec_bridge *br;
1020 iface = ovsrec_interface_insert(ctx->txn);
1021 ovsrec_interface_set_name(iface, br_name);
1023 port = ovsrec_port_insert(ctx->txn);
1024 ovsrec_port_set_name(port, br_name);
1025 ovsrec_port_set_interfaces(port, &iface, 1);
1027 br = ovsrec_bridge_insert(ctx->txn);
1028 ovsrec_bridge_set_name(br, br_name);
1029 ovsrec_bridge_set_ports(br, &port, 1);
1031 ovs_insert_bridge(ctx->ovs, br);
1033 struct vsctl_bridge *parent;
1034 struct ovsrec_port *port;
1035 struct ovsrec_interface *iface;
1036 struct ovsrec_bridge *br;
1039 parent = find_bridge(&info, parent_name, false);
1040 if (parent && parent->vlan) {
1041 vsctl_fatal("cannot create bridge with fake bridge as parent");
1044 vsctl_fatal("parent bridge %s does not exist", parent_name);
1046 br = parent->br_cfg;
1048 iface = ovsrec_interface_insert(ctx->txn);
1049 ovsrec_interface_set_name(iface, br_name);
1050 ovsrec_interface_set_type(iface, "internal");
1052 port = ovsrec_port_insert(ctx->txn);
1053 ovsrec_port_set_name(port, br_name);
1054 ovsrec_port_set_interfaces(port, &iface, 1);
1055 ovsrec_port_set_fake_bridge(port, true);
1056 ovsrec_port_set_tag(port, &tag, 1);
1058 bridge_insert_port(br, port);
1065 del_port(struct vsctl_info *info, struct vsctl_port *port)
1067 struct shash_node *node;
1069 SHASH_FOR_EACH (node, &info->ifaces) {
1070 struct vsctl_iface *iface = node->data;
1071 if (iface->port == port) {
1072 ovsrec_interface_delete(iface->iface_cfg);
1075 ovsrec_port_delete(port->port_cfg);
1077 bridge_delete_port((port->bridge->parent
1078 ? port->bridge->parent->br_cfg
1079 : port->bridge->br_cfg), port->port_cfg);
1083 cmd_del_br(struct vsctl_context *ctx)
1085 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1086 struct vsctl_bridge *bridge;
1087 struct vsctl_info info;
1089 get_info(ctx->ovs, &info);
1090 bridge = find_bridge(&info, ctx->argv[1], must_exist);
1092 struct shash_node *node;
1094 SHASH_FOR_EACH (node, &info.ports) {
1095 struct vsctl_port *port = node->data;
1096 if (port->bridge == bridge || port->bridge->parent == bridge
1097 || !strcmp(port->port_cfg->name, bridge->name)) {
1098 del_port(&info, port);
1101 if (bridge->br_cfg) {
1102 ovsrec_bridge_delete(bridge->br_cfg);
1103 ovs_delete_bridge(ctx->ovs, bridge->br_cfg);
1110 output_sorted(struct svec *svec, struct ds *output)
1116 SVEC_FOR_EACH (i, name, svec) {
1117 ds_put_format(output, "%s\n", name);
1122 cmd_list_br(struct vsctl_context *ctx)
1124 struct shash_node *node;
1125 struct vsctl_info info;
1126 struct svec bridges;
1128 get_info(ctx->ovs, &info);
1130 svec_init(&bridges);
1131 SHASH_FOR_EACH (node, &info.bridges) {
1132 struct vsctl_bridge *br = node->data;
1133 svec_add(&bridges, br->name);
1135 output_sorted(&bridges, &ctx->output);
1136 svec_destroy(&bridges);
1142 cmd_br_exists(struct vsctl_context *ctx)
1144 struct vsctl_info info;
1146 get_info(ctx->ovs, &info);
1147 if (!find_bridge(&info, ctx->argv[1], false)) {
1153 /* Returns true if 'b_prefix' (of length 'b_prefix_len') concatenated with 'b'
1154 * equals 'a', false otherwise. */
1156 key_matches(const char *a,
1157 const char *b_prefix, size_t b_prefix_len, const char *b)
1159 return !strncmp(a, b_prefix, b_prefix_len) && !strcmp(a + b_prefix_len, b);
1163 set_external_id(char **old_keys, char **old_values, size_t old_n,
1164 char *key, char *value,
1165 char ***new_keysp, char ***new_valuesp, size_t *new_np)
1172 new_keys = xmalloc(sizeof *new_keys * (old_n + 1));
1173 new_values = xmalloc(sizeof *new_values * (old_n + 1));
1175 for (i = 0; i < old_n; i++) {
1176 if (strcmp(key, old_keys[i])) {
1177 new_keys[new_n] = old_keys[i];
1178 new_values[new_n] = old_values[i];
1183 new_keys[new_n] = key;
1184 new_values[new_n] = value;
1187 *new_keysp = new_keys;
1188 *new_valuesp = new_values;
1193 cmd_br_set_external_id(struct vsctl_context *ctx)
1195 struct vsctl_info info;
1196 struct vsctl_bridge *bridge;
1197 char **keys, **values;
1200 get_info(ctx->ovs, &info);
1201 bridge = find_bridge(&info, ctx->argv[1], true);
1202 if (bridge->br_cfg) {
1203 set_external_id(bridge->br_cfg->key_external_ids,
1204 bridge->br_cfg->value_external_ids,
1205 bridge->br_cfg->n_external_ids,
1206 ctx->argv[2], ctx->argc >= 4 ? ctx->argv[3] : NULL,
1207 &keys, &values, &n);
1208 ovsrec_bridge_set_external_ids(bridge->br_cfg, keys, values, n);
1210 char *key = xasprintf("fake-bridge-%s", ctx->argv[2]);
1211 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1212 set_external_id(port->port_cfg->key_external_ids,
1213 port->port_cfg->value_external_ids,
1214 port->port_cfg->n_external_ids,
1215 key, ctx->argc >= 4 ? ctx->argv[3] : NULL,
1216 &keys, &values, &n);
1217 ovsrec_port_set_external_ids(port->port_cfg, keys, values, n);
1227 get_external_id(char **keys, char **values, size_t n,
1228 const char *prefix, const char *key,
1231 size_t prefix_len = strlen(prefix);
1236 for (i = 0; i < n; i++) {
1237 if (!key && !strncmp(keys[i], prefix, prefix_len)) {
1238 svec_add_nocopy(&svec, xasprintf("%s=%s",
1239 keys[i] + prefix_len, values[i]));
1240 } else if (key_matches(keys[i], prefix, prefix_len, key)) {
1241 svec_add(&svec, values[i]);
1245 output_sorted(&svec, output);
1246 svec_destroy(&svec);
1250 cmd_br_get_external_id(struct vsctl_context *ctx)
1252 struct vsctl_info info;
1253 struct vsctl_bridge *bridge;
1255 get_info(ctx->ovs, &info);
1256 bridge = find_bridge(&info, ctx->argv[1], true);
1257 if (bridge->br_cfg) {
1258 get_external_id(bridge->br_cfg->key_external_ids,
1259 bridge->br_cfg->value_external_ids,
1260 bridge->br_cfg->n_external_ids,
1261 "", ctx->argc >= 3 ? ctx->argv[2] : NULL,
1264 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1265 get_external_id(port->port_cfg->key_external_ids,
1266 port->port_cfg->value_external_ids,
1267 port->port_cfg->n_external_ids,
1268 "fake-bridge-", ctx->argc >= 3 ? ctx->argv[2] : NULL, &ctx->output);
1275 cmd_list_ports(struct vsctl_context *ctx)
1277 struct vsctl_bridge *br;
1278 struct shash_node *node;
1279 struct vsctl_info info;
1282 get_info(ctx->ovs, &info);
1283 br = find_bridge(&info, ctx->argv[1], true);
1286 SHASH_FOR_EACH (node, &info.ports) {
1287 struct vsctl_port *port = node->data;
1289 if (strcmp(port->port_cfg->name, br->name) && br == port->bridge) {
1290 svec_add(&ports, port->port_cfg->name);
1293 output_sorted(&ports, &ctx->output);
1294 svec_destroy(&ports);
1300 add_port(struct vsctl_context *ctx,
1301 const char *br_name, const char *port_name,
1302 bool may_exist, bool fake_iface,
1303 char *iface_names[], int n_ifaces,
1304 char *settings[], int n_settings)
1306 struct vsctl_info info;
1307 struct vsctl_bridge *bridge;
1308 struct ovsrec_interface **ifaces;
1309 struct ovsrec_port *port;
1312 get_info(ctx->ovs, &info);
1314 struct vsctl_port *port;
1316 port = find_port(&info, port_name, false);
1318 struct svec want_names, have_names;
1321 svec_init(&want_names);
1322 for (i = 0; i < n_ifaces; i++) {
1323 svec_add(&want_names, iface_names[i]);
1325 svec_sort(&want_names);
1327 svec_init(&have_names);
1328 for (i = 0; i < port->port_cfg->n_interfaces; i++) {
1329 svec_add(&have_names, port->port_cfg->interfaces[i]->name);
1331 svec_sort(&have_names);
1333 if (strcmp(port->bridge->name, br_name)) {
1334 char *command = vsctl_context_to_string(ctx);
1335 vsctl_fatal("\"%s\" but %s is actually attached to bridge %s",
1336 command, port_name, port->bridge->name);
1339 if (!svec_equal(&want_names, &have_names)) {
1340 char *have_names_string = svec_join(&have_names, ", ", "");
1341 char *command = vsctl_context_to_string(ctx);
1343 vsctl_fatal("\"%s\" but %s actually has interface(s) %s",
1344 command, port_name, have_names_string);
1347 svec_destroy(&want_names);
1348 svec_destroy(&have_names);
1353 check_conflicts(&info, port_name,
1354 xasprintf("cannot create a port named %s", port_name));
1355 for (i = 0; i < n_ifaces; i++) {
1356 check_conflicts(&info, iface_names[i],
1357 xasprintf("cannot create an interface named %s",
1360 bridge = find_bridge(&info, br_name, true);
1362 ifaces = xmalloc(n_ifaces * sizeof *ifaces);
1363 for (i = 0; i < n_ifaces; i++) {
1364 ifaces[i] = ovsrec_interface_insert(ctx->txn);
1365 ovsrec_interface_set_name(ifaces[i], iface_names[i]);
1368 port = ovsrec_port_insert(ctx->txn);
1369 ovsrec_port_set_name(port, port_name);
1370 ovsrec_port_set_interfaces(port, ifaces, n_ifaces);
1371 ovsrec_port_set_bond_fake_iface(port, fake_iface);
1375 int64_t tag = bridge->vlan;
1376 ovsrec_port_set_tag(port, &tag, 1);
1379 for (i = 0; i < n_settings; i++) {
1380 set_column(get_table("Port"), &port->header_, settings[i],
1384 bridge_insert_port((bridge->parent ? bridge->parent->br_cfg
1385 : bridge->br_cfg), port);
1391 cmd_add_port(struct vsctl_context *ctx)
1393 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
1395 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist, false,
1396 &ctx->argv[2], 1, &ctx->argv[3], ctx->argc - 3);
1400 cmd_add_bond(struct vsctl_context *ctx)
1402 bool may_exist = shash_find(&ctx->options, "--may-exist") != 0;
1403 bool fake_iface = shash_find(&ctx->options, "--fake-iface");
1407 n_ifaces = ctx->argc - 3;
1408 for (i = 3; i < ctx->argc; i++) {
1409 if (strchr(ctx->argv[i], '=')) {
1415 vsctl_fatal("add-bond requires at least 2 interfaces, but only "
1416 "%d were specified", n_ifaces);
1419 add_port(ctx, ctx->argv[1], ctx->argv[2], may_exist, fake_iface,
1420 &ctx->argv[3], n_ifaces,
1421 &ctx->argv[n_ifaces + 3], ctx->argc - 3 - n_ifaces);
1425 cmd_del_port(struct vsctl_context *ctx)
1427 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1428 bool with_iface = shash_find(&ctx->options, "--with-iface") != NULL;
1429 struct vsctl_port *port;
1430 struct vsctl_info info;
1432 get_info(ctx->ovs, &info);
1434 port = find_port(&info, ctx->argv[ctx->argc - 1], must_exist);
1436 const char *target = ctx->argv[ctx->argc - 1];
1437 struct vsctl_iface *iface;
1439 port = find_port(&info, target, false);
1441 iface = find_iface(&info, target, false);
1446 if (must_exist && !port) {
1447 vsctl_fatal("no port or interface named %s", target);
1452 if (ctx->argc == 3) {
1453 struct vsctl_bridge *bridge;
1455 bridge = find_bridge(&info, ctx->argv[1], true);
1456 if (port->bridge != bridge) {
1457 if (port->bridge->parent == bridge) {
1458 vsctl_fatal("bridge %s does not have a port %s (although "
1459 "its parent bridge %s does)",
1460 ctx->argv[1], ctx->argv[2],
1461 bridge->parent->name);
1463 vsctl_fatal("bridge %s does not have a port %s",
1464 ctx->argv[1], ctx->argv[2]);
1469 del_port(&info, port);
1476 cmd_port_to_br(struct vsctl_context *ctx)
1478 struct vsctl_port *port;
1479 struct vsctl_info info;
1481 get_info(ctx->ovs, &info);
1482 port = find_port(&info, ctx->argv[1], true);
1483 ds_put_format(&ctx->output, "%s\n", port->bridge->name);
1488 cmd_br_to_vlan(struct vsctl_context *ctx)
1490 struct vsctl_bridge *bridge;
1491 struct vsctl_info info;
1493 get_info(ctx->ovs, &info);
1494 bridge = find_bridge(&info, ctx->argv[1], true);
1495 ds_put_format(&ctx->output, "%d\n", bridge->vlan);
1500 cmd_br_to_parent(struct vsctl_context *ctx)
1502 struct vsctl_bridge *bridge;
1503 struct vsctl_info info;
1505 get_info(ctx->ovs, &info);
1506 bridge = find_bridge(&info, ctx->argv[1], true);
1507 if (bridge->parent) {
1508 bridge = bridge->parent;
1510 ds_put_format(&ctx->output, "%s\n", bridge->name);
1515 cmd_list_ifaces(struct vsctl_context *ctx)
1517 struct vsctl_bridge *br;
1518 struct shash_node *node;
1519 struct vsctl_info info;
1522 get_info(ctx->ovs, &info);
1523 br = find_bridge(&info, ctx->argv[1], true);
1526 SHASH_FOR_EACH (node, &info.ifaces) {
1527 struct vsctl_iface *iface = node->data;
1529 if (strcmp(iface->iface_cfg->name, br->name)
1530 && br == iface->port->bridge) {
1531 svec_add(&ifaces, iface->iface_cfg->name);
1534 output_sorted(&ifaces, &ctx->output);
1535 svec_destroy(&ifaces);
1541 cmd_iface_to_br(struct vsctl_context *ctx)
1543 struct vsctl_iface *iface;
1544 struct vsctl_info info;
1546 get_info(ctx->ovs, &info);
1547 iface = find_iface(&info, ctx->argv[1], true);
1548 ds_put_format(&ctx->output, "%s\n", iface->port->bridge->name);
1552 /* Print targets of the 'n_controllers' in 'controllers' on the output for
1555 print_controllers(struct vsctl_context *ctx,
1556 struct ovsrec_controller **controllers,
1557 size_t n_controllers)
1559 /* Print the targets in sorted order for reproducibility. */
1560 struct svec targets;
1563 svec_init(&targets);
1564 for (i = 0; i < n_controllers; i++) {
1565 svec_add(&targets, controllers[i]->target);
1568 svec_sort(&targets);
1569 for (i = 0; i < targets.n; i++) {
1570 ds_put_format(&ctx->output, "%s\n", targets.names[i]);
1572 svec_destroy(&targets);
1576 cmd_get_controller(struct vsctl_context *ctx)
1578 struct vsctl_info info;
1580 get_info(ctx->ovs, &info);
1582 if (ctx->argc == 1 || !strcmp(ctx->argv[1], "default")) {
1583 print_controllers(ctx, info.ctrl, info.n_ctrl);
1585 struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true);
1587 print_controllers(ctx, br->ctrl, br->n_ctrl);
1589 print_controllers(ctx, info.ctrl, info.n_ctrl);
1597 delete_controllers(struct ovsrec_controller **controllers,
1598 size_t n_controllers)
1602 for (i = 0; i < n_controllers; i++) {
1603 ovsrec_controller_delete(controllers[i]);
1608 cmd_del_controller(struct vsctl_context *ctx)
1610 struct vsctl_info info;
1612 get_info(ctx->ovs, &info);
1614 if (ctx->argc == 1 || !strcmp(ctx->argv[1], "default")) {
1616 delete_controllers(info.ctrl, info.n_ctrl);
1617 ovsrec_open_vswitch_set_controller(ctx->ovs, NULL, 0);
1620 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1622 delete_controllers(br->ctrl, br->n_ctrl);
1623 ovsrec_bridge_set_controller(br->br_cfg, NULL, 0);
1630 static struct ovsrec_controller **
1631 insert_controllers(struct ovsdb_idl_txn *txn, char *targets[], size_t n)
1633 struct ovsrec_controller **controllers;
1636 controllers = xmalloc(n * sizeof *controllers);
1637 for (i = 0; i < n; i++) {
1638 controllers[i] = ovsrec_controller_insert(txn);
1639 ovsrec_controller_set_target(controllers[i], targets[i]);
1646 set_default_controllers(struct vsctl_context *ctx, char *targets[], size_t n)
1648 struct ovsrec_controller **controllers;
1650 delete_controllers(ctx->ovs->controller, ctx->ovs->n_controller);
1652 controllers = insert_controllers(ctx->txn, targets, n);
1653 ovsrec_open_vswitch_set_controller(ctx->ovs, controllers, n);
1658 cmd_set_controller(struct vsctl_context *ctx)
1660 struct vsctl_info info;
1662 get_info(ctx->ovs, &info);
1664 if (ctx->argc == 2) {
1665 /* Set one controller in the "Open_vSwitch" table. */
1666 set_default_controllers(ctx, &ctx->argv[1], 1);
1667 } else if (!strcmp(ctx->argv[1], "default")) {
1668 /* Set one or more controllers in the "Open_vSwitch" table. */
1669 set_default_controllers(ctx, &ctx->argv[2], ctx->argc - 2);
1671 /* Set one or more controllers for a particular bridge. */
1672 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1673 struct ovsrec_controller **controllers;
1676 delete_controllers(br->ctrl, br->n_ctrl);
1679 controllers = insert_controllers(ctx->txn, &ctx->argv[2], n);
1680 ovsrec_bridge_set_controller(br->br_cfg, controllers, n);
1688 get_fail_mode(struct ovsrec_controller **controllers, size_t n_controllers)
1690 const char *fail_mode;
1694 for (i = 0; i < n_controllers; i++) {
1695 const char *s = controllers[i]->fail_mode;
1697 if (!strcmp(s, "secure")) {
1709 cmd_get_fail_mode(struct vsctl_context *ctx)
1711 struct vsctl_info info;
1712 const char *fail_mode = NULL;
1714 get_info(ctx->ovs, &info);
1716 if (ctx->argc == 1 || !strcmp(ctx->argv[1], "default")) {
1717 /* Return the fail-mode from the "Open_vSwitch" table */
1718 fail_mode = get_fail_mode(info.ctrl, info.n_ctrl);
1720 /* Return the fail-mode for a particular bridge. */
1721 struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true);
1723 /* If no controller is defined for the requested bridge, fallback to
1724 * the "Open_vSwitch" table's controller. */
1725 fail_mode = (br->n_ctrl
1726 ? get_fail_mode(br->ctrl, br->n_ctrl)
1727 : get_fail_mode(info.ctrl, info.n_ctrl));
1730 if (fail_mode && strlen(fail_mode)) {
1731 ds_put_format(&ctx->output, "%s\n", fail_mode);
1738 set_fail_mode(struct ovsrec_controller **controllers, size_t n_controllers,
1739 const char *fail_mode)
1743 for (i = 0; i < n_controllers; i++) {
1744 ovsrec_controller_set_fail_mode(controllers[i], fail_mode);
1749 cmd_del_fail_mode(struct vsctl_context *ctx)
1751 struct vsctl_info info;
1753 get_info(ctx->ovs, &info);
1755 if (ctx->argc == 1 || !strcmp(ctx->argv[1], "default")) {
1756 set_fail_mode(info.ctrl, info.n_ctrl, NULL);
1758 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1760 set_fail_mode(br->ctrl, br->n_ctrl, NULL);
1767 cmd_set_fail_mode(struct vsctl_context *ctx)
1769 struct vsctl_info info;
1771 const char *fail_mode;
1773 get_info(ctx->ovs, &info);
1775 if (ctx->argc == 2) {
1777 fail_mode = ctx->argv[1];
1779 bridge = ctx->argv[1];
1780 fail_mode = ctx->argv[2];
1783 if (strcmp(fail_mode, "standalone") && strcmp(fail_mode, "secure")) {
1784 vsctl_fatal("fail-mode must be \"standalone\" or \"secure\"");
1787 if (!strcmp(bridge, "default")) {
1788 /* Set the fail-mode in the "Open_vSwitch" table. */
1790 vsctl_fatal("no controller declared");
1792 set_fail_mode(info.ctrl, info.n_ctrl, fail_mode);
1794 struct vsctl_bridge *br = find_real_bridge(&info, bridge, true);
1797 vsctl_fatal("no controller declared for %s", br->name);
1799 set_fail_mode(br->ctrl, br->n_ctrl, fail_mode);
1806 cmd_get_ssl(struct vsctl_context *ctx)
1808 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1811 ds_put_format(&ctx->output, "Private key: %s\n", ssl->private_key);
1812 ds_put_format(&ctx->output, "Certificate: %s\n", ssl->certificate);
1813 ds_put_format(&ctx->output, "CA Certificate: %s\n", ssl->ca_cert);
1814 ds_put_format(&ctx->output, "Bootstrap: %s\n",
1815 ssl->bootstrap_ca_cert ? "true" : "false");
1820 cmd_del_ssl(struct vsctl_context *ctx)
1822 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1825 ovsrec_ssl_delete(ssl);
1826 ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL);
1831 cmd_set_ssl(struct vsctl_context *ctx)
1833 bool bootstrap = shash_find(&ctx->options, "--bootstrap");
1834 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1837 ovsrec_ssl_delete(ssl);
1839 ssl = ovsrec_ssl_insert(ctx->txn);
1841 ovsrec_ssl_set_private_key(ssl, ctx->argv[1]);
1842 ovsrec_ssl_set_certificate(ssl, ctx->argv[2]);
1843 ovsrec_ssl_set_ca_cert(ssl, ctx->argv[3]);
1845 ovsrec_ssl_set_bootstrap_ca_cert(ssl, bootstrap);
1847 ovsrec_open_vswitch_set_ssl(ctx->ovs, ssl);
1850 /* Parameter commands. */
1852 struct vsctl_row_id {
1853 const struct ovsdb_idl_table_class *table;
1854 const struct ovsdb_idl_column *name_column;
1855 const struct ovsdb_idl_column *uuid_column;
1858 struct vsctl_table_class {
1859 struct ovsdb_idl_table_class *class;
1860 struct vsctl_row_id row_ids[2];
1863 static const struct vsctl_table_class tables[] = {
1864 {&ovsrec_table_bridge,
1865 {{&ovsrec_table_bridge, &ovsrec_bridge_col_name, NULL},
1866 {NULL, NULL, NULL}}},
1868 {&ovsrec_table_controller,
1869 {{&ovsrec_table_bridge,
1870 &ovsrec_bridge_col_name,
1871 &ovsrec_bridge_col_controller},
1872 {&ovsrec_table_open_vswitch,
1874 &ovsrec_open_vswitch_col_controller}}},
1876 {&ovsrec_table_interface,
1877 {{&ovsrec_table_interface, &ovsrec_interface_col_name, NULL},
1878 {NULL, NULL, NULL}}},
1880 {&ovsrec_table_mirror,
1881 {{&ovsrec_table_mirror, &ovsrec_mirror_col_name, NULL},
1882 {NULL, NULL, NULL}}},
1884 {&ovsrec_table_netflow,
1885 {{&ovsrec_table_bridge,
1886 &ovsrec_bridge_col_name,
1887 &ovsrec_bridge_col_netflow},
1888 {NULL, NULL, NULL}}},
1890 {&ovsrec_table_open_vswitch,
1891 {{&ovsrec_table_open_vswitch, NULL, NULL},
1892 {NULL, NULL, NULL}}},
1894 {&ovsrec_table_port,
1895 {{&ovsrec_table_port, &ovsrec_port_col_name, NULL},
1896 {NULL, NULL, NULL}}},
1899 {{&ovsrec_table_port, &ovsrec_port_col_name, &ovsrec_port_col_qos},
1900 {NULL, NULL, NULL}}},
1902 {&ovsrec_table_queue,
1903 {{NULL, NULL, NULL},
1904 {NULL, NULL, NULL}}},
1907 {{&ovsrec_table_open_vswitch, NULL, &ovsrec_open_vswitch_col_ssl}}},
1909 {&ovsrec_table_sflow,
1910 {{&ovsrec_table_bridge,
1911 &ovsrec_bridge_col_name,
1912 &ovsrec_bridge_col_sflow},
1913 {NULL, NULL, NULL}}},
1915 {NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
1919 die_if_error(char *error)
1922 vsctl_fatal("%s", error);
1927 to_lower_and_underscores(unsigned c)
1929 return c == '-' ? '_' : tolower(c);
1933 score_partial_match(const char *name, const char *s)
1937 if (!strcmp(name, s)) {
1940 for (score = 0; ; score++, name++, s++) {
1941 if (to_lower_and_underscores(*name) != to_lower_and_underscores(*s)) {
1943 } else if (*name == '\0') {
1944 return UINT_MAX - 1;
1947 return *s == '\0' ? score : 0;
1950 static const struct vsctl_table_class *
1951 get_table(const char *table_name)
1953 const struct vsctl_table_class *table;
1954 const struct vsctl_table_class *best_match = NULL;
1955 unsigned int best_score = 0;
1957 for (table = tables; table->class; table++) {
1958 unsigned int score = score_partial_match(table->class->name,
1960 if (score > best_score) {
1963 } else if (score == best_score) {
1969 } else if (best_score) {
1970 vsctl_fatal("multiple table names match \"%s\"", table_name);
1972 vsctl_fatal("unknown table \"%s\"", table_name);
1976 static const struct ovsdb_idl_row *
1977 get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table,
1978 const struct vsctl_row_id *id, const char *record_id)
1980 const struct ovsdb_idl_row *referrer, *final;
1986 if (!id->name_column) {
1987 if (strcmp(record_id, ".")) {
1990 referrer = ovsdb_idl_first_row(ctx->idl, id->table);
1991 if (!referrer || ovsdb_idl_next_row(referrer)) {
1995 const struct ovsdb_idl_row *row;
1996 unsigned int best_score = 0;
1998 /* It might make sense to relax this assertion. */
1999 assert(id->name_column->type.key.type == OVSDB_TYPE_STRING);
2002 for (row = ovsdb_idl_first_row(ctx->idl, id->table);
2003 row != NULL && best_score != UINT_MAX;
2004 row = ovsdb_idl_next_row(row))
2006 struct ovsdb_datum name;
2008 ovsdb_idl_txn_read(row, id->name_column, &name);
2010 unsigned int score = score_partial_match(name.keys[0].string,
2012 if (score > best_score) {
2015 } else if (score == best_score) {
2019 ovsdb_datum_destroy(&name, &id->name_column->type);
2021 if (best_score && !referrer) {
2022 vsctl_fatal("multiple rows in %s match \"%s\"",
2023 table->class->name, record_id);
2031 if (id->uuid_column) {
2032 struct ovsdb_datum uuid;
2034 assert(id->uuid_column->type.key.type == OVSDB_TYPE_UUID);
2035 assert(id->uuid_column->type.value.type == OVSDB_TYPE_VOID);
2037 ovsdb_idl_txn_read(referrer, id->uuid_column, &uuid);
2039 final = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class,
2040 &uuid.keys[0].uuid);
2042 ovsdb_datum_destroy(&uuid, &id->uuid_column->type);
2050 static const struct ovsdb_idl_row *
2051 get_row(struct vsctl_context *ctx,
2052 const struct vsctl_table_class *table, const char *record_id)
2054 const struct ovsdb_idl_row *row;
2057 if (uuid_from_string(&uuid, record_id)) {
2058 row = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class, &uuid);
2062 for (i = 0; i < ARRAY_SIZE(table->row_ids); i++) {
2063 row = get_row_by_id(ctx, table, &table->row_ids[i], record_id);
2072 static const struct ovsdb_idl_row *
2073 must_get_row(struct vsctl_context *ctx,
2074 const struct vsctl_table_class *table, const char *record_id)
2076 const struct ovsdb_idl_row *row = get_row(ctx, table, record_id);
2078 vsctl_fatal("no row \"%s\" in table %s",
2079 record_id, table->class->name);
2085 get_column(const struct vsctl_table_class *table, const char *column_name,
2086 const struct ovsdb_idl_column **columnp)
2088 const struct ovsdb_idl_column *best_match = NULL;
2089 unsigned int best_score = 0;
2092 for (i = 0; i < table->class->n_columns; i++) {
2093 const struct ovsdb_idl_column *column = &table->class->columns[i];
2094 unsigned int score = score_partial_match(column->name, column_name);
2095 if (score > best_score) {
2096 best_match = column;
2098 } else if (score == best_score) {
2103 *columnp = best_match;
2106 } else if (best_score) {
2107 return xasprintf("%s contains more than one column whose name "
2108 "matches \"%s\"", table->class->name, column_name);
2110 return xasprintf("%s does not contain a column whose name matches "
2111 "\"%s\"", table->class->name, column_name);
2115 static char * WARN_UNUSED_RESULT
2116 parse_column_key_value(const char *arg, const struct vsctl_table_class *table,
2117 const struct ovsdb_idl_column **columnp,
2118 char **keyp, char **valuep)
2120 const char *p = arg;
2123 assert(columnp || keyp);
2131 /* Parse column name. */
2135 error = ovsdb_token_parse(&p, &column_name);
2139 if (column_name[0] == '\0') {
2141 error = xasprintf("%s: missing column name", arg);
2144 error = get_column(table, column_name, columnp);
2151 /* Parse key string. */
2152 if (*p == ':' || !columnp) {
2156 error = xasprintf("%s: key not accepted here", arg);
2159 error = ovsdb_token_parse(&p, keyp);
2167 /* Parse value string. */
2170 error = xasprintf("%s: value not accepted here", arg);
2173 *valuep = xstrdup(p + 1);
2179 error = xasprintf("%s: trailing garbage \"%s\" in argument",
2202 cmd_get(struct vsctl_context *ctx)
2204 bool if_exists = shash_find(&ctx->options, "--if-exists");
2205 const char *table_name = ctx->argv[1];
2206 const char *record_id = ctx->argv[2];
2207 const struct vsctl_table_class *table;
2208 const struct ovsdb_idl_row *row;
2209 struct ds *out = &ctx->output;
2212 table = get_table(table_name);
2213 row = must_get_row(ctx, table, record_id);
2214 for (i = 3; i < ctx->argc; i++) {
2215 const struct ovsdb_idl_column *column;
2216 struct ovsdb_datum datum;
2219 die_if_error(parse_column_key_value(ctx->argv[i], table,
2220 &column, &key_string, NULL));
2222 ovsdb_idl_txn_read(row, column, &datum);
2224 union ovsdb_atom key;
2227 if (column->type.value.type == OVSDB_TYPE_VOID) {
2228 vsctl_fatal("cannot specify key to get for non-map column %s",
2232 die_if_error(ovsdb_atom_from_string(&key,
2234 key_string, ctx->symtab));
2236 idx = ovsdb_datum_find_key(&datum, &key,
2237 column->type.key.type);
2238 if (idx == UINT_MAX) {
2240 vsctl_fatal("no key \"%s\" in %s record \"%s\" column %s",
2241 key_string, table->class->name, record_id,
2245 ovsdb_atom_to_string(&datum.values[idx],
2246 column->type.value.type, out);
2248 ovsdb_atom_destroy(&key, column->type.key.type);
2250 ovsdb_datum_to_string(&datum, &column->type, out);
2252 ds_put_char(out, '\n');
2253 ovsdb_datum_destroy(&datum, &column->type);
2260 list_record(const struct vsctl_table_class *table,
2261 const struct ovsdb_idl_row *row, struct ds *out)
2265 ds_put_format(out, "%-20s: "UUID_FMT"\n", "_uuid",
2266 UUID_ARGS(&row->uuid));
2267 for (i = 0; i < table->class->n_columns; i++) {
2268 const struct ovsdb_idl_column *column = &table->class->columns[i];
2269 struct ovsdb_datum datum;
2271 ovsdb_idl_txn_read(row, column, &datum);
2273 ds_put_format(out, "%-20s: ", column->name);
2274 ovsdb_datum_to_string(&datum, &column->type, out);
2275 ds_put_char(out, '\n');
2277 ovsdb_datum_destroy(&datum, &column->type);
2282 cmd_list(struct vsctl_context *ctx)
2284 const char *table_name = ctx->argv[1];
2285 const struct vsctl_table_class *table;
2286 struct ds *out = &ctx->output;
2289 table = get_table(table_name);
2290 if (ctx->argc > 2) {
2291 for (i = 2; i < ctx->argc; i++) {
2293 ds_put_char(out, '\n');
2295 list_record(table, must_get_row(ctx, table, ctx->argv[i]), out);
2298 const struct ovsdb_idl_row *row;
2301 for (row = ovsdb_idl_first_row(ctx->idl, table->class), first = true;
2303 row = ovsdb_idl_next_row(row), first = false) {
2305 ds_put_char(out, '\n');
2307 list_record(table, row, out);
2313 set_column(const struct vsctl_table_class *table,
2314 const struct ovsdb_idl_row *row, const char *arg,
2315 struct ovsdb_symbol_table *symtab)
2317 const struct ovsdb_idl_column *column;
2318 char *key_string, *value_string;
2321 error = parse_column_key_value(arg, table, &column, &key_string,
2323 die_if_error(error);
2324 if (!value_string) {
2325 vsctl_fatal("%s: missing value", arg);
2329 union ovsdb_atom key, value;
2330 struct ovsdb_datum old, new;
2332 if (column->type.value.type == OVSDB_TYPE_VOID) {
2333 vsctl_fatal("cannot specify key to set for non-map column %s",
2337 die_if_error(ovsdb_atom_from_string(&key, &column->type.key,
2338 key_string, symtab));
2339 die_if_error(ovsdb_atom_from_string(&value, &column->type.value,
2340 value_string, symtab));
2342 ovsdb_datum_init_empty(&new);
2343 ovsdb_datum_add_unsafe(&new, &key, &value, &column->type);
2345 ovsdb_atom_destroy(&key, column->type.key.type);
2346 ovsdb_atom_destroy(&value, column->type.value.type);
2348 ovsdb_idl_txn_read(row, column, &old);
2349 ovsdb_datum_union(&old, &new, &column->type, true);
2350 ovsdb_idl_txn_write(row, column, &old);
2352 ovsdb_datum_destroy(&new, &column->type);
2354 struct ovsdb_datum datum;
2356 die_if_error(ovsdb_datum_from_string(&datum, &column->type,
2357 value_string, symtab));
2358 ovsdb_idl_txn_write(row, column, &datum);
2366 cmd_set(struct vsctl_context *ctx)
2368 const char *table_name = ctx->argv[1];
2369 const char *record_id = ctx->argv[2];
2370 const struct vsctl_table_class *table;
2371 const struct ovsdb_idl_row *row;
2374 table = get_table(table_name);
2375 row = must_get_row(ctx, table, record_id);
2376 for (i = 3; i < ctx->argc; i++) {
2377 set_column(table, row, ctx->argv[i], ctx->symtab);
2382 cmd_add(struct vsctl_context *ctx)
2384 const char *table_name = ctx->argv[1];
2385 const char *record_id = ctx->argv[2];
2386 const char *column_name = ctx->argv[3];
2387 const struct vsctl_table_class *table;
2388 const struct ovsdb_idl_column *column;
2389 const struct ovsdb_idl_row *row;
2390 const struct ovsdb_type *type;
2391 struct ovsdb_datum old;
2394 table = get_table(table_name);
2395 row = must_get_row(ctx, table, record_id);
2396 die_if_error(get_column(table, column_name, &column));
2398 type = &column->type;
2399 ovsdb_idl_txn_read(row, column, &old);
2400 for (i = 4; i < ctx->argc; i++) {
2401 struct ovsdb_type add_type;
2402 struct ovsdb_datum add;
2406 add_type.n_max = UINT_MAX;
2407 die_if_error(ovsdb_datum_from_string(&add, &add_type, ctx->argv[i],
2409 ovsdb_datum_union(&old, &add, type, false);
2410 ovsdb_datum_destroy(&add, type);
2412 if (old.n > type->n_max) {
2413 vsctl_fatal("\"add\" operation would put %u %s in column %s of "
2414 "table %s but the maximum number is %u",
2416 type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
2417 column->name, table->class->name, type->n_max);
2419 ovsdb_idl_txn_write(row, column, &old);
2423 cmd_remove(struct vsctl_context *ctx)
2425 const char *table_name = ctx->argv[1];
2426 const char *record_id = ctx->argv[2];
2427 const char *column_name = ctx->argv[3];
2428 const struct vsctl_table_class *table;
2429 const struct ovsdb_idl_column *column;
2430 const struct ovsdb_idl_row *row;
2431 const struct ovsdb_type *type;
2432 struct ovsdb_datum old;
2435 table = get_table(table_name);
2436 row = must_get_row(ctx, table, record_id);
2437 die_if_error(get_column(table, column_name, &column));
2439 type = &column->type;
2440 ovsdb_idl_txn_read(row, column, &old);
2441 for (i = 4; i < ctx->argc; i++) {
2442 struct ovsdb_type rm_type;
2443 struct ovsdb_datum rm;
2448 rm_type.n_max = UINT_MAX;
2449 error = ovsdb_datum_from_string(&rm, &rm_type,
2450 ctx->argv[i], ctx->symtab);
2451 if (error && ovsdb_type_is_map(&rm_type)) {
2453 rm_type.value.type = OVSDB_TYPE_VOID;
2454 die_if_error(ovsdb_datum_from_string(&rm, &rm_type,
2455 ctx->argv[i], ctx->symtab));
2457 ovsdb_datum_subtract(&old, type, &rm, &rm_type);
2458 ovsdb_datum_destroy(&rm, &rm_type);
2460 if (old.n < type->n_min) {
2461 vsctl_fatal("\"remove\" operation would put %u %s in column %s of "
2462 "table %s but the minimum number is %u",
2464 type->value.type == OVSDB_TYPE_VOID ? "values" : "pairs",
2465 column->name, table->class->name, type->n_min);
2467 ovsdb_idl_txn_write(row, column, &old);
2471 cmd_clear(struct vsctl_context *ctx)
2473 const char *table_name = ctx->argv[1];
2474 const char *record_id = ctx->argv[2];
2475 const struct vsctl_table_class *table;
2476 const struct ovsdb_idl_row *row;
2479 table = get_table(table_name);
2480 row = must_get_row(ctx, table, record_id);
2481 for (i = 3; i < ctx->argc; i++) {
2482 const struct ovsdb_idl_column *column;
2483 const struct ovsdb_type *type;
2484 struct ovsdb_datum datum;
2486 die_if_error(get_column(table, ctx->argv[i], &column));
2488 type = &column->type;
2489 if (type->n_min > 0) {
2490 vsctl_fatal("\"clear\" operation cannot be applied to column %s "
2491 "of table %s, which is not allowed to be empty",
2492 column->name, table->class->name);
2495 ovsdb_datum_init_empty(&datum);
2496 ovsdb_idl_txn_write(row, column, &datum);
2501 cmd_create(struct vsctl_context *ctx)
2503 const char *id = shash_find_data(&ctx->options, "--id");
2504 const char *table_name = ctx->argv[1];
2505 const struct vsctl_table_class *table;
2506 const struct ovsdb_idl_row *row;
2507 const struct uuid *uuid;
2511 struct ovsdb_symbol *symbol;
2514 vsctl_fatal("row id \"%s\" does not begin with \"@\"", id);
2517 symbol = ovsdb_symbol_table_insert(ctx->symtab, id);
2519 vsctl_fatal("row id \"%s\" may only be used to insert a single "
2522 symbol->used = true;
2524 uuid = &symbol->uuid;
2529 table = get_table(table_name);
2530 row = ovsdb_idl_txn_insert(ctx->txn, table->class, uuid);
2531 for (i = 2; i < ctx->argc; i++) {
2532 set_column(table, row, ctx->argv[i], ctx->symtab);
2534 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(&row->uuid));
2537 /* This function may be used as the 'postprocess' function for commands that
2538 * insert new rows into the database. It expects that the command's 'run'
2539 * function prints the UUID reported by ovsdb_idl_txn_insert() as the command's
2540 * sole output. It replaces that output by the row's permanent UUID assigned
2541 * by the database server and appends a new-line.
2543 * Currently we use this only for "create", because the higher-level commands
2544 * are supposed to be independent of the actual structure of the vswitch
2547 post_create(struct vsctl_context *ctx)
2549 const struct uuid *real;
2552 uuid_from_string(&dummy, ds_cstr(&ctx->output));
2553 real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy);
2555 ds_clear(&ctx->output);
2556 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(real));
2558 ds_put_char(&ctx->output, '\n');
2562 cmd_destroy(struct vsctl_context *ctx)
2564 bool must_exist = !shash_find(&ctx->options, "--if-exists");
2565 const char *table_name = ctx->argv[1];
2566 const struct vsctl_table_class *table;
2569 table = get_table(table_name);
2570 for (i = 2; i < ctx->argc; i++) {
2571 const struct ovsdb_idl_row *row;
2573 row = (must_exist ? must_get_row : get_row)(ctx, table, ctx->argv[i]);
2575 ovsdb_idl_txn_delete(row);
2580 static struct json *
2581 where_uuid_equals(const struct uuid *uuid)
2584 json_array_create_1(
2585 json_array_create_3(
2586 json_string_create("_uuid"),
2587 json_string_create("=="),
2588 json_array_create_2(
2589 json_string_create("uuid"),
2590 json_string_create_nocopy(
2591 xasprintf(UUID_FMT, UUID_ARGS(uuid))))));
2595 vsctl_context_init(struct vsctl_context *ctx, struct vsctl_command *command,
2596 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2597 const struct ovsrec_open_vswitch *ovs,
2598 struct ovsdb_symbol_table *symtab)
2600 ctx->argc = command->argc;
2601 ctx->argv = command->argv;
2602 ctx->options = command->options;
2604 ds_swap(&ctx->output, &command->output);
2608 ctx->symtab = symtab;
2612 vsctl_context_done(struct vsctl_context *ctx, struct vsctl_command *command)
2614 ds_swap(&ctx->output, &command->output);
2618 do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
2619 struct ovsdb_idl *idl)
2621 struct ovsdb_idl_txn *txn;
2622 const struct ovsrec_open_vswitch *ovs;
2623 enum ovsdb_idl_txn_status status;
2624 struct ovsdb_symbol_table *symtab;
2626 struct vsctl_command *c;
2627 int64_t next_cfg = 0;
2630 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
2632 ovsdb_idl_txn_set_dry_run(txn);
2635 ovsdb_idl_txn_add_comment(txn, "ovs-vsctl: %s", args);
2637 ovs = ovsrec_open_vswitch_first(idl);
2639 /* XXX add verification that table is empty */
2640 ovs = ovsrec_open_vswitch_insert(txn);
2643 if (wait_for_reload) {
2644 struct json *where = where_uuid_equals(&ovs->header_.uuid);
2645 ovsdb_idl_txn_increment(txn, "Open_vSwitch", "next_cfg", where);
2646 json_destroy(where);
2649 symtab = ovsdb_symbol_table_create();
2650 for (c = commands; c < &commands[n_commands]; c++) {
2651 struct vsctl_context ctx;
2653 ds_init(&c->output);
2654 vsctl_context_init(&ctx, c, idl, txn, ovs, symtab);
2655 (c->syntax->run)(&ctx);
2656 vsctl_context_done(&ctx, c);
2659 status = ovsdb_idl_txn_commit_block(txn);
2660 if (wait_for_reload && status == TXN_SUCCESS) {
2661 next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
2663 if (status == TXN_UNCHANGED || status == TXN_SUCCESS) {
2664 for (c = commands; c < &commands[n_commands]; c++) {
2665 if (c->syntax->postprocess) {
2666 struct vsctl_context ctx;
2668 vsctl_context_init(&ctx, c, idl, txn, ovs, symtab);
2669 (c->syntax->postprocess)(&ctx);
2670 vsctl_context_done(&ctx, c);
2674 error = xstrdup(ovsdb_idl_txn_get_error(txn));
2675 ovsdb_idl_txn_destroy(txn);
2678 unused = ovsdb_symbol_table_find_unused(symtab);
2680 vsctl_fatal("row id \"%s\" is referenced but never created (e.g. "
2681 "with \"-- --id=%s create ...\")", unused, unused);
2683 ovsdb_symbol_table_destroy(symtab);
2686 case TXN_INCOMPLETE:
2690 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2691 vsctl_fatal("transaction aborted");
2698 for (c = commands; c < &commands[n_commands]; c++) {
2699 ds_destroy(&c->output);
2705 vsctl_fatal("transaction error: %s", error);
2712 for (c = commands; c < &commands[n_commands]; c++) {
2713 struct ds *ds = &c->output;
2714 struct shash_node *node;
2720 for (j = 0; j < ds->length; j++) {
2721 int c = ds->string[j];
2724 fputs("\\n", stdout);
2728 fputs("\\\\", stdout);
2737 fputs(ds_cstr(ds), stdout);
2739 ds_destroy(&c->output);
2741 SHASH_FOR_EACH (node, &c->options) {
2744 shash_destroy(&c->options);
2748 if (wait_for_reload && status != TXN_UNCHANGED) {
2750 const struct ovsrec_open_vswitch *ovs;
2753 OVSREC_OPEN_VSWITCH_FOR_EACH (ovs, idl) {
2754 if (ovs->cur_cfg >= next_cfg) {
2758 ovsdb_idl_wait(idl);
2763 ovsdb_idl_destroy(idl);
2768 static const struct vsctl_command_syntax all_commands[] = {
2769 /* Open vSwitch commands. */
2770 {"init", 0, 0, cmd_init, NULL, ""},
2772 /* Bridge commands. */
2773 {"add-br", 1, 3, cmd_add_br, NULL, "--may-exist"},
2774 {"del-br", 1, 1, cmd_del_br, NULL, "--if-exists"},
2775 {"list-br", 0, 0, cmd_list_br, NULL, ""},
2776 {"br-exists", 1, 1, cmd_br_exists, NULL, ""},
2777 {"br-to-vlan", 1, 1, cmd_br_to_vlan, NULL, ""},
2778 {"br-to-parent", 1, 1, cmd_br_to_parent, NULL, ""},
2779 {"br-set-external-id", 2, 3, cmd_br_set_external_id, NULL, ""},
2780 {"br-get-external-id", 1, 2, cmd_br_get_external_id, NULL, ""},
2782 /* Port commands. */
2783 {"list-ports", 1, 1, cmd_list_ports, NULL, ""},
2784 {"add-port", 2, INT_MAX, cmd_add_port, NULL, "--may-exist"},
2785 {"add-bond", 4, INT_MAX, cmd_add_bond, NULL, "--may-exist,--fake-iface"},
2786 {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists,--with-iface"},
2787 {"port-to-br", 1, 1, cmd_port_to_br, NULL, ""},
2789 /* Interface commands. */
2790 {"list-ifaces", 1, 1, cmd_list_ifaces, NULL, ""},
2791 {"iface-to-br", 1, 1, cmd_iface_to_br, NULL, ""},
2793 /* Controller commands. */
2794 {"get-controller", 0, 1, cmd_get_controller, NULL, ""},
2795 {"del-controller", 0, 1, cmd_del_controller, NULL, ""},
2796 {"set-controller", 1, INT_MAX, cmd_set_controller, NULL, ""},
2797 {"get-fail-mode", 0, 1, cmd_get_fail_mode, NULL, ""},
2798 {"del-fail-mode", 0, 1, cmd_del_fail_mode, NULL, ""},
2799 {"set-fail-mode", 1, 2, cmd_set_fail_mode, NULL, ""},
2802 {"get-ssl", 0, 0, cmd_get_ssl, NULL, ""},
2803 {"del-ssl", 0, 0, cmd_del_ssl, NULL, ""},
2804 {"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"},
2806 /* Switch commands. */
2807 {"emer-reset", 0, 0, cmd_emer_reset, NULL, ""},
2809 /* Parameter commands. */
2810 {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"},
2811 {"list", 1, INT_MAX, cmd_list, NULL, ""},
2812 {"set", 3, INT_MAX, cmd_set, NULL, ""},
2813 {"add", 4, INT_MAX, cmd_add, NULL, ""},
2814 {"remove", 4, INT_MAX, cmd_remove, NULL, ""},
2815 {"clear", 3, INT_MAX, cmd_clear, NULL, ""},
2816 {"create", 2, INT_MAX, cmd_create, post_create, "--id="},
2817 {"destroy", 1, INT_MAX, cmd_destroy, NULL, "--if-exists"},
2819 {NULL, 0, 0, NULL, NULL, NULL},