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.
31 #include "command-line.h"
34 #include "dynamic-string.h"
36 #include "ovsdb-data.h"
37 #include "ovsdb-idl.h"
38 #include "poll-loop.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,
113 main(int argc, char *argv[])
115 struct ovsdb_idl *idl;
117 struct vsctl_command *commands;
122 set_program_name(argv[0]);
123 signal(SIGPIPE, SIG_IGN);
126 vlog_set_levels(VLM_ANY_MODULE, VLF_CONSOLE, VLL_WARN);
127 vlog_set_levels(VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN);
129 /* Log our arguments. This is often valuable for debugging systems. */
130 args = process_escape_args(argv);
131 VLOG_INFO("Called as %s", args);
133 /* Parse command line. */
134 parse_options(argc, argv);
135 commands = parse_commands(argc - optind, argv + optind, &n_commands);
141 /* Do basic command syntax checking. */
143 /* Now execute the commands. */
144 idl = the_idl = ovsdb_idl_create(db, &ovsrec_idl_class);
145 seqno = ovsdb_idl_get_seqno(idl);
148 unsigned int new_seqno;
151 new_seqno = ovsdb_idl_get_seqno(idl);
152 if (new_seqno != seqno) {
154 vsctl_fatal("too many database inconsistency failures");
156 do_vsctl(args, commands, n_commands, idl);
166 parse_options(int argc, char *argv[])
169 OPT_DB = UCHAR_MAX + 1,
176 static struct option long_options[] = {
177 {"db", required_argument, 0, OPT_DB},
178 {"no-syslog", no_argument, 0, OPT_NO_SYSLOG},
179 {"no-wait", no_argument, 0, OPT_NO_WAIT},
180 {"dry-run", no_argument, 0, OPT_DRY_RUN},
181 {"oneline", no_argument, 0, OPT_ONELINE},
182 {"timeout", required_argument, 0, 't'},
183 {"help", no_argument, 0, 'h'},
184 {"version", no_argument, 0, 'V'},
193 c = getopt_long(argc, argv, "+v::hVt:", long_options, NULL);
208 vlog_set_levels(VLM_vsctl, VLF_SYSLOG, VLL_WARN);
212 wait_for_reload = false;
223 OVS_PRINT_VERSION(0, 0);
227 timeout = strtoul(optarg, NULL, 10);
229 vsctl_fatal("value %s on -t or --timeout is invalid",
249 static struct vsctl_command *
250 parse_commands(int argc, char *argv[], size_t *n_commandsp)
252 struct vsctl_command *commands;
253 size_t n_commands, allocated_commands;
257 n_commands = allocated_commands = 0;
259 for (start = i = 0; i <= argc; i++) {
260 if (i == argc || !strcmp(argv[i], "--")) {
262 if (n_commands >= allocated_commands) {
263 struct vsctl_command *c;
265 commands = x2nrealloc(commands, &allocated_commands,
267 for (c = commands; c < &commands[n_commands]; c++) {
268 shash_moved(&c->options);
271 parse_command(i - start, &argv[start],
272 &commands[n_commands++]);
278 vsctl_fatal("missing command name (use --help for help)");
280 *n_commandsp = n_commands;
285 parse_command(int argc, char *argv[], struct vsctl_command *command)
287 const struct vsctl_command_syntax *p;
290 shash_init(&command->options);
291 for (i = 0; i < argc; i++) {
292 if (argv[i][0] != '-') {
295 if (!shash_add_once(&command->options, argv[i], NULL)) {
296 vsctl_fatal("'%s' option specified multiple times", argv[i]);
300 vsctl_fatal("missing command name");
303 for (p = all_commands; p->name; p++) {
304 if (!strcmp(p->name, argv[i])) {
305 struct shash_node *node;
308 SHASH_FOR_EACH (node, &command->options) {
309 const char *s = strstr(p->options, node->name);
310 int end = s ? s[strlen(node->name)] : EOF;
311 if (end != ',' && end != ' ' && end != '\0') {
312 vsctl_fatal("'%s' command has no '%s' option",
313 argv[i], node->name);
317 n_arg = argc - i - 1;
318 if (n_arg < p->min_args) {
319 vsctl_fatal("'%s' command requires at least %d arguments",
320 p->name, p->min_args);
321 } else if (n_arg > p->max_args) {
322 vsctl_fatal("'%s' command takes at most %d arguments",
323 p->name, p->max_args);
326 command->argc = n_arg + 1;
327 command->argv = &argv[i];
333 vsctl_fatal("unknown command '%s'; use --help for help", argv[i]);
337 vsctl_fatal(const char *format, ...)
342 va_start(args, format);
343 message = xvasprintf(format, args);
346 vlog_set_levels(VLM_vsctl, VLF_CONSOLE, VLL_EMER);
347 VLOG_ERR("%s", message);
348 ovs_error(0, "%s", message);
349 vsctl_exit(EXIT_FAILURE);
352 /* Frees the current transaction and the underlying IDL and then calls
355 * Freeing the transaction and the IDL is not strictly necessary, but it makes
356 * for a clean memory leak report from valgrind in the normal case. That makes
357 * it easier to notice real memory leaks. */
359 vsctl_exit(int status)
362 ovsdb_idl_txn_abort(the_idl_txn);
363 ovsdb_idl_txn_destroy(the_idl_txn);
365 ovsdb_idl_destroy(the_idl);
373 %s: ovs-vswitchd management utility\n\
374 usage: %s [OPTIONS] COMMAND [ARG...]\n\
377 add-br BRIDGE create a new bridge named BRIDGE\n\
378 add-br BRIDGE PARENT VLAN create new fake BRIDGE in PARENT on VLAN\n\
379 del-br BRIDGE delete BRIDGE and all of its ports\n\
380 list-br print the names of all the bridges\n\
381 br-exists BRIDGE test whether BRIDGE exists\n\
382 br-to-vlan BRIDGE print the VLAN which BRIDGE is on\n\
383 br-to-parent BRIDGE print the parent of BRIDGE\n\
384 br-set-external-id BRIDGE KEY VALUE set KEY on BRIDGE to VALUE\n\
385 br-set-external-id BRIDGE KEY unset KEY on BRIDGE\n\
386 br-get-external-id BRIDGE KEY print value of KEY on BRIDGE\n\
387 br-get-external-id BRIDGE list key-value pairs on BRIDGE\n\
390 list-ports BRIDGE print the names of all the ports on BRIDGE\n\
391 add-port BRIDGE PORT add network device PORT to BRIDGE\n\
392 add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES\n\
393 del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE\n\
394 port-to-br PORT print name of bridge that contains PORT\n\
395 A bond is considered to be a single port.\n\
397 Interface commands (a bond consists of multiple interfaces):\n\
398 list-ifaces BRIDGE print the names of all interfaces on BRIDGE\n\
399 iface-to-br IFACE print name of bridge that contains IFACE\n\
401 Controller commands:\n\
402 get-controller [BRIDGE] print the controller for BRIDGE\n\
403 del-controller [BRIDGE] delete the controller for BRIDGE\n\
404 set-controller [BRIDGE] TARGET set the controller for BRIDGE to TARGET\n\
405 get-fail-mode [BRIDGE] print the fail-mode for BRIDGE\n\
406 del-fail-mode [BRIDGE] delete the fail-mode for BRIDGE\n\
407 set-fail-mode [BRIDGE] MODE set the fail-mode for BRIDGE to MODE\n\
410 get-ssl print the SSL configuration\n\
411 del-ssl delete the SSL configuration\n\
412 set-ssl PRIV-KEY CERT CA-CERT set the SSL configuration\n\
414 Database commands:\n\
415 list TBL [REC] list RECord (or all records) in TBL\n\
416 get TBL REC COL[:KEY] print values of COLumns in RECORD in TBL\n\
417 set TBL REC COL[:KEY]=VALUE set COLumn values in RECord in TBL\n\
418 add TBL REC COL [KEY=]VALUE add (KEY=)VALUE to COLumn in RECord in TBL\n\
419 remove TBL REC COL [KEY=]VALUE remove (KEY=)VALUE from COLumn\n\
420 clear TBL REC COL clear values from COLumn in RECord in TBL\n\
421 create TBL COL[:KEY]=VALUE create and initialize new record\n\
422 destroy TBL REC delete REC from TBL\n\
423 Potentially unsafe database commands require --force option.\n\
426 --db=DATABASE connect to DATABASE\n\
428 --oneline print exactly one line of output per command\n",
429 program_name, program_name, default_db());
433 -h, --help display this help message\n\
434 -V, --version display version information\n");
443 def = xasprintf("unix:%s/ovsdb-server", ovs_rundir);
448 struct vsctl_context {
452 struct shash options;
454 /* Modifiable state. */
456 struct ovsdb_idl *idl;
457 struct ovsdb_idl_txn *txn;
458 const struct ovsrec_open_vswitch *ovs;
461 struct vsctl_bridge {
462 struct ovsrec_bridge *br_cfg;
464 struct ovsrec_controller *ctrl;
465 struct vsctl_bridge *parent;
470 struct ovsrec_port *port_cfg;
471 struct vsctl_bridge *bridge;
475 struct ovsrec_interface *iface_cfg;
476 struct vsctl_port *port;
480 struct shash bridges;
483 struct ovsrec_controller *ctrl;
486 static struct vsctl_bridge *
487 add_bridge(struct vsctl_info *b,
488 struct ovsrec_bridge *br_cfg, const char *name,
489 struct vsctl_bridge *parent, int vlan)
491 struct vsctl_bridge *br = xmalloc(sizeof *br);
493 br->name = xstrdup(name);
496 br->ctrl = parent ? parent->br_cfg->controller : br_cfg->controller;
497 shash_add(&b->bridges, br->name, br);
502 port_is_fake_bridge(const struct ovsrec_port *port_cfg)
504 return (port_cfg->fake_bridge
506 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095);
509 static struct vsctl_bridge *
510 find_vlan_bridge(struct vsctl_info *info,
511 struct vsctl_bridge *parent, int vlan)
513 struct shash_node *node;
515 SHASH_FOR_EACH (node, &info->bridges) {
516 struct vsctl_bridge *br = node->data;
517 if (br->parent == parent && br->vlan == vlan) {
526 free_info(struct vsctl_info *info)
528 struct shash_node *node;
530 SHASH_FOR_EACH (node, &info->bridges) {
531 struct vsctl_bridge *bridge = node->data;
535 shash_destroy(&info->bridges);
537 SHASH_FOR_EACH (node, &info->ports) {
538 struct vsctl_port *port = node->data;
541 shash_destroy(&info->ports);
543 SHASH_FOR_EACH (node, &info->ifaces) {
544 struct vsctl_iface *iface = node->data;
547 shash_destroy(&info->ifaces);
551 get_info(const struct ovsrec_open_vswitch *ovs, struct vsctl_info *info)
553 struct shash bridges, ports;
556 shash_init(&info->bridges);
557 shash_init(&info->ports);
558 shash_init(&info->ifaces);
560 info->ctrl = ovs->controller;
562 shash_init(&bridges);
564 for (i = 0; i < ovs->n_bridges; i++) {
565 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
566 struct vsctl_bridge *br;
569 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
570 VLOG_WARN("%s: database contains duplicate bridge name",
574 br = add_bridge(info, br_cfg, br_cfg->name, NULL, 0);
579 for (j = 0; j < br_cfg->n_ports; j++) {
580 struct ovsrec_port *port_cfg = br_cfg->ports[j];
582 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
583 VLOG_WARN("%s: database contains duplicate port name",
588 if (port_is_fake_bridge(port_cfg)
589 && shash_add_once(&bridges, port_cfg->name, NULL)) {
590 add_bridge(info, NULL, port_cfg->name, br, *port_cfg->tag);
594 shash_destroy(&bridges);
595 shash_destroy(&ports);
597 shash_init(&bridges);
599 for (i = 0; i < ovs->n_bridges; i++) {
600 struct ovsrec_bridge *br_cfg = ovs->bridges[i];
601 struct vsctl_bridge *br;
604 if (!shash_add_once(&bridges, br_cfg->name, NULL)) {
607 br = shash_find_data(&info->bridges, br_cfg->name);
608 for (j = 0; j < br_cfg->n_ports; j++) {
609 struct ovsrec_port *port_cfg = br_cfg->ports[j];
610 struct vsctl_port *port;
613 if (!shash_add_once(&ports, port_cfg->name, NULL)) {
617 if (port_is_fake_bridge(port_cfg)
618 && !shash_add_once(&bridges, port_cfg->name, NULL)) {
622 port = xmalloc(sizeof *port);
623 port->port_cfg = port_cfg;
625 && *port_cfg->tag >= 1 && *port_cfg->tag <= 4095) {
626 port->bridge = find_vlan_bridge(info, br, *port_cfg->tag);
633 shash_add(&info->ports, port_cfg->name, port);
635 for (k = 0; k < port_cfg->n_interfaces; k++) {
636 struct ovsrec_interface *iface_cfg = port_cfg->interfaces[k];
637 struct vsctl_iface *iface;
639 if (shash_find(&info->ifaces, iface_cfg->name)) {
640 VLOG_WARN("%s: database contains duplicate interface name",
645 iface = xmalloc(sizeof *iface);
646 iface->iface_cfg = iface_cfg;
648 shash_add(&info->ifaces, iface_cfg->name, iface);
652 shash_destroy(&bridges);
653 shash_destroy(&ports);
657 check_conflicts(struct vsctl_info *info, const char *name,
660 struct vsctl_iface *iface;
661 struct vsctl_port *port;
663 if (shash_find(&info->bridges, name)) {
664 vsctl_fatal("%s because a bridge named %s already exists",
668 port = shash_find_data(&info->ports, name);
670 vsctl_fatal("%s because a port named %s already exists on "
671 "bridge %s", msg, name, port->bridge->name);
674 iface = shash_find_data(&info->ifaces, name);
676 vsctl_fatal("%s because an interface named %s already exists "
677 "on bridge %s", msg, name, iface->port->bridge->name);
683 static struct vsctl_bridge *
684 find_bridge(struct vsctl_info *info, const char *name, bool must_exist)
686 struct vsctl_bridge *br = shash_find_data(&info->bridges, name);
687 if (must_exist && !br) {
688 vsctl_fatal("no bridge named %s", name);
693 static struct vsctl_bridge *
694 find_real_bridge(struct vsctl_info *info, const char *name, bool must_exist)
696 struct vsctl_bridge *br = find_bridge(info, name, must_exist);
697 if (br && br->parent) {
698 vsctl_fatal("%s is a fake bridge", name);
703 static struct vsctl_port *
704 find_port(struct vsctl_info *info, const char *name, bool must_exist)
706 struct vsctl_port *port = shash_find_data(&info->ports, name);
707 if (port && !strcmp(name, port->bridge->name)) {
710 if (must_exist && !port) {
711 vsctl_fatal("no port named %s", name);
716 static struct vsctl_iface *
717 find_iface(struct vsctl_info *info, const char *name, bool must_exist)
719 struct vsctl_iface *iface = shash_find_data(&info->ifaces, name);
720 if (iface && !strcmp(name, iface->port->bridge->name)) {
723 if (must_exist && !iface) {
724 vsctl_fatal("no interface named %s", name);
730 bridge_insert_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
732 struct ovsrec_port **ports;
735 ports = xmalloc(sizeof *br->ports * (br->n_ports + 1));
736 for (i = 0; i < br->n_ports; i++) {
737 ports[i] = br->ports[i];
739 ports[br->n_ports] = port;
740 ovsrec_bridge_set_ports(br, ports, br->n_ports + 1);
745 bridge_delete_port(struct ovsrec_bridge *br, struct ovsrec_port *port)
747 struct ovsrec_port **ports;
750 ports = xmalloc(sizeof *br->ports * br->n_ports);
751 for (i = n = 0; i < br->n_ports; i++) {
752 if (br->ports[i] != port) {
753 ports[n++] = br->ports[i];
756 ovsrec_bridge_set_ports(br, ports, n);
761 ovs_insert_bridge(const struct ovsrec_open_vswitch *ovs,
762 struct ovsrec_bridge *bridge)
764 struct ovsrec_bridge **bridges;
767 bridges = xmalloc(sizeof *ovs->bridges * (ovs->n_bridges + 1));
768 for (i = 0; i < ovs->n_bridges; i++) {
769 bridges[i] = ovs->bridges[i];
771 bridges[ovs->n_bridges] = bridge;
772 ovsrec_open_vswitch_set_bridges(ovs, bridges, ovs->n_bridges + 1);
777 ovs_delete_bridge(const struct ovsrec_open_vswitch *ovs,
778 struct ovsrec_bridge *bridge)
780 struct ovsrec_bridge **bridges;
783 bridges = xmalloc(sizeof *ovs->bridges * ovs->n_bridges);
784 for (i = n = 0; i < ovs->n_bridges; i++) {
785 if (ovs->bridges[i] != bridge) {
786 bridges[n++] = ovs->bridges[i];
789 ovsrec_open_vswitch_set_bridges(ovs, bridges, n);
794 cmd_init(struct vsctl_context *ctx UNUSED)
799 cmd_add_br(struct vsctl_context *ctx)
801 const char *br_name = ctx->argv[1];
802 struct vsctl_info info;
804 get_info(ctx->ovs, &info);
805 check_conflicts(&info, br_name,
806 xasprintf("cannot create a bridge named %s", br_name));
808 if (ctx->argc == 2) {
809 struct ovsrec_bridge *br;
810 struct ovsrec_port *port;
811 struct ovsrec_interface *iface;
813 iface = ovsrec_interface_insert(ctx->txn);
814 ovsrec_interface_set_name(iface, br_name);
816 port = ovsrec_port_insert(ctx->txn);
817 ovsrec_port_set_name(port, br_name);
818 ovsrec_port_set_interfaces(port, &iface, 1);
820 br = ovsrec_bridge_insert(ctx->txn);
821 ovsrec_bridge_set_name(br, br_name);
822 ovsrec_bridge_set_ports(br, &port, 1);
824 ovs_insert_bridge(ctx->ovs, br);
825 } else if (ctx->argc == 3) {
826 vsctl_fatal("'%s' command takes exactly 1 or 3 arguments",
828 } else if (ctx->argc == 4) {
829 const char *parent_name = ctx->argv[2];
830 int vlan = atoi(ctx->argv[3]);
831 struct ovsrec_bridge *br;
832 struct vsctl_bridge *parent;
833 struct ovsrec_port *port;
834 struct ovsrec_interface *iface;
837 if (vlan < 1 || vlan > 4095) {
838 vsctl_fatal("%s: vlan must be between 1 and 4095", ctx->argv[0]);
841 parent = find_bridge(&info, parent_name, false);
842 if (parent && parent->vlan) {
843 vsctl_fatal("cannot create bridge with fake bridge as parent");
846 vsctl_fatal("parent bridge %s does not exist", parent_name);
850 iface = ovsrec_interface_insert(ctx->txn);
851 ovsrec_interface_set_name(iface, br_name);
852 ovsrec_interface_set_type(iface, "internal");
854 port = ovsrec_port_insert(ctx->txn);
855 ovsrec_port_set_name(port, br_name);
856 ovsrec_port_set_interfaces(port, &iface, 1);
857 ovsrec_port_set_fake_bridge(port, true);
858 ovsrec_port_set_tag(port, &tag, 1);
860 bridge_insert_port(br, port);
869 del_port(struct vsctl_info *info, struct vsctl_port *port)
871 struct shash_node *node;
873 SHASH_FOR_EACH (node, &info->ifaces) {
874 struct vsctl_iface *iface = node->data;
875 if (iface->port == port) {
876 ovsrec_interface_delete(iface->iface_cfg);
879 ovsrec_port_delete(port->port_cfg);
881 bridge_delete_port((port->bridge->parent
882 ? port->bridge->parent->br_cfg
883 : port->bridge->br_cfg), port->port_cfg);
887 cmd_del_br(struct vsctl_context *ctx)
889 bool must_exist = !shash_find(&ctx->options, "--if-exists");
890 struct vsctl_bridge *bridge;
891 struct vsctl_info info;
893 get_info(ctx->ovs, &info);
894 bridge = find_bridge(&info, ctx->argv[1], must_exist);
896 struct shash_node *node;
898 SHASH_FOR_EACH (node, &info.ports) {
899 struct vsctl_port *port = node->data;
900 if (port->bridge == bridge
901 || !strcmp(port->port_cfg->name, bridge->name)) {
902 del_port(&info, port);
905 if (bridge->br_cfg) {
906 ovsrec_bridge_delete(bridge->br_cfg);
907 ovs_delete_bridge(ctx->ovs, bridge->br_cfg);
914 output_sorted(struct svec *svec, struct ds *output)
920 SVEC_FOR_EACH (i, name, svec) {
921 ds_put_format(output, "%s\n", name);
926 cmd_list_br(struct vsctl_context *ctx)
928 struct shash_node *node;
929 struct vsctl_info info;
932 get_info(ctx->ovs, &info);
935 SHASH_FOR_EACH (node, &info.bridges) {
936 struct vsctl_bridge *br = node->data;
937 svec_add(&bridges, br->name);
939 output_sorted(&bridges, &ctx->output);
940 svec_destroy(&bridges);
946 cmd_br_exists(struct vsctl_context *ctx)
948 struct vsctl_info info;
950 get_info(ctx->ovs, &info);
951 if (!find_bridge(&info, ctx->argv[1], false)) {
957 /* Returns true if 'b_prefix' (of length 'b_prefix_len') concatenated with 'b'
958 * equals 'a', false otherwise. */
960 key_matches(const char *a,
961 const char *b_prefix, size_t b_prefix_len, const char *b)
963 return !strncmp(a, b_prefix, b_prefix_len) && !strcmp(a + b_prefix_len, b);
967 set_external_id(char **old_keys, char **old_values, size_t old_n,
968 char *key, char *value,
969 char ***new_keysp, char ***new_valuesp, size_t *new_np)
976 new_keys = xmalloc(sizeof *new_keys * (old_n + 1));
977 new_values = xmalloc(sizeof *new_values * (old_n + 1));
979 for (i = 0; i < old_n; i++) {
980 if (strcmp(key, old_keys[i])) {
981 new_keys[new_n] = old_keys[i];
982 new_values[new_n] = old_values[i];
987 new_keys[new_n] = key;
988 new_values[new_n] = value;
991 *new_keysp = new_keys;
992 *new_valuesp = new_values;
997 cmd_br_set_external_id(struct vsctl_context *ctx)
999 struct vsctl_info info;
1000 struct vsctl_bridge *bridge;
1001 char **keys, **values;
1004 get_info(ctx->ovs, &info);
1005 bridge = find_bridge(&info, ctx->argv[1], true);
1006 if (bridge->br_cfg) {
1007 set_external_id(bridge->br_cfg->key_external_ids,
1008 bridge->br_cfg->value_external_ids,
1009 bridge->br_cfg->n_external_ids,
1010 ctx->argv[2], ctx->argc >= 4 ? ctx->argv[3] : NULL,
1011 &keys, &values, &n);
1012 ovsrec_bridge_set_external_ids(bridge->br_cfg, keys, values, n);
1014 char *key = xasprintf("fake-bridge-%s", ctx->argv[2]);
1015 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1016 set_external_id(port->port_cfg->key_external_ids,
1017 port->port_cfg->value_external_ids,
1018 port->port_cfg->n_external_ids,
1019 key, ctx->argc >= 4 ? ctx->argv[3] : NULL,
1020 &keys, &values, &n);
1021 ovsrec_port_set_external_ids(port->port_cfg, keys, values, n);
1031 get_external_id(char **keys, char **values, size_t n,
1032 const char *prefix, const char *key,
1035 size_t prefix_len = strlen(prefix);
1040 for (i = 0; i < n; i++) {
1041 if (!key && !strncmp(keys[i], prefix, prefix_len)) {
1042 svec_add_nocopy(&svec, xasprintf("%s=%s",
1043 keys[i] + prefix_len, values[i]));
1044 } else if (key_matches(keys[i], prefix, prefix_len, key)) {
1045 svec_add(&svec, values[i]);
1049 output_sorted(&svec, output);
1050 svec_destroy(&svec);
1054 cmd_br_get_external_id(struct vsctl_context *ctx)
1056 struct vsctl_info info;
1057 struct vsctl_bridge *bridge;
1059 get_info(ctx->ovs, &info);
1060 bridge = find_bridge(&info, ctx->argv[1], true);
1061 if (bridge->br_cfg) {
1062 get_external_id(bridge->br_cfg->key_external_ids,
1063 bridge->br_cfg->value_external_ids,
1064 bridge->br_cfg->n_external_ids,
1065 "", ctx->argc >= 3 ? ctx->argv[2] : NULL,
1068 struct vsctl_port *port = shash_find_data(&info.ports, ctx->argv[1]);
1069 get_external_id(port->port_cfg->key_external_ids,
1070 port->port_cfg->value_external_ids,
1071 port->port_cfg->n_external_ids,
1072 "fake-bridge-", ctx->argc >= 3 ? ctx->argv[2] : NULL, &ctx->output);
1079 cmd_list_ports(struct vsctl_context *ctx)
1081 struct vsctl_bridge *br;
1082 struct shash_node *node;
1083 struct vsctl_info info;
1086 get_info(ctx->ovs, &info);
1087 br = find_bridge(&info, ctx->argv[1], true);
1090 SHASH_FOR_EACH (node, &info.ports) {
1091 struct vsctl_port *port = node->data;
1093 if (strcmp(port->port_cfg->name, br->name) && br == port->bridge) {
1094 svec_add(&ports, port->port_cfg->name);
1097 output_sorted(&ports, &ctx->output);
1098 svec_destroy(&ports);
1104 add_port(struct vsctl_context *ctx,
1105 const char *br_name, const char *port_name, bool fake_iface,
1106 char *iface_names[], int n_ifaces)
1108 struct vsctl_info info;
1109 struct vsctl_bridge *bridge;
1110 struct ovsrec_interface **ifaces;
1111 struct ovsrec_port *port;
1114 get_info(ctx->ovs, &info);
1115 check_conflicts(&info, port_name,
1116 xasprintf("cannot create a port named %s", port_name));
1117 /* XXX need to check for conflicts on interfaces too */
1118 bridge = find_bridge(&info, br_name, true);
1120 ifaces = xmalloc(n_ifaces * sizeof *ifaces);
1121 for (i = 0; i < n_ifaces; i++) {
1122 ifaces[i] = ovsrec_interface_insert(ctx->txn);
1123 ovsrec_interface_set_name(ifaces[i], iface_names[i]);
1126 port = ovsrec_port_insert(ctx->txn);
1127 ovsrec_port_set_name(port, port_name);
1128 ovsrec_port_set_interfaces(port, ifaces, n_ifaces);
1129 ovsrec_port_set_bond_fake_iface(port, fake_iface);
1133 int64_t tag = bridge->vlan;
1134 ovsrec_port_set_tag(port, &tag, 1);
1137 bridge_insert_port((bridge->parent ? bridge->parent->br_cfg
1138 : bridge->br_cfg), port);
1144 cmd_add_port(struct vsctl_context *ctx)
1146 add_port(ctx, ctx->argv[1], ctx->argv[2], false, &ctx->argv[2], 1);
1150 cmd_add_bond(struct vsctl_context *ctx)
1152 bool fake_iface = shash_find(&ctx->options, "--fake-iface");
1154 add_port(ctx, ctx->argv[1], ctx->argv[2], fake_iface,
1155 &ctx->argv[3], ctx->argc - 3);
1159 cmd_del_port(struct vsctl_context *ctx)
1161 bool must_exist = !shash_find(&ctx->options, "--if-exists");
1162 struct vsctl_info info;
1164 get_info(ctx->ovs, &info);
1165 if (ctx->argc == 2) {
1166 struct vsctl_port *port = find_port(&info, ctx->argv[1], must_exist);
1168 del_port(&info, port);
1170 } else if (ctx->argc == 3) {
1171 struct vsctl_bridge *bridge = find_bridge(&info, ctx->argv[1], true);
1172 struct vsctl_port *port = find_port(&info, ctx->argv[2], must_exist);
1175 if (port->bridge == bridge) {
1176 del_port(&info, port);
1177 } else if (port->bridge->parent == bridge) {
1178 vsctl_fatal("bridge %s does not have a port %s (although its "
1179 "parent bridge %s does)",
1180 ctx->argv[1], ctx->argv[2], bridge->parent->name);
1182 vsctl_fatal("bridge %s does not have a port %s",
1183 ctx->argv[1], ctx->argv[2]);
1191 cmd_port_to_br(struct vsctl_context *ctx)
1193 struct vsctl_port *port;
1194 struct vsctl_info info;
1196 get_info(ctx->ovs, &info);
1197 port = find_port(&info, ctx->argv[1], true);
1198 ds_put_format(&ctx->output, "%s\n", port->bridge->name);
1203 cmd_br_to_vlan(struct vsctl_context *ctx)
1205 struct vsctl_bridge *bridge;
1206 struct vsctl_info info;
1208 get_info(ctx->ovs, &info);
1209 bridge = find_bridge(&info, ctx->argv[1], true);
1210 ds_put_format(&ctx->output, "%d\n", bridge->vlan);
1215 cmd_br_to_parent(struct vsctl_context *ctx)
1217 struct vsctl_bridge *bridge;
1218 struct vsctl_info info;
1220 get_info(ctx->ovs, &info);
1221 bridge = find_bridge(&info, ctx->argv[1], true);
1222 if (bridge->parent) {
1223 bridge = bridge->parent;
1225 ds_put_format(&ctx->output, "%s\n", bridge->name);
1230 cmd_list_ifaces(struct vsctl_context *ctx)
1232 struct vsctl_bridge *br;
1233 struct shash_node *node;
1234 struct vsctl_info info;
1237 get_info(ctx->ovs, &info);
1238 br = find_bridge(&info, ctx->argv[1], true);
1241 SHASH_FOR_EACH (node, &info.ifaces) {
1242 struct vsctl_iface *iface = node->data;
1244 if (strcmp(iface->iface_cfg->name, br->name)
1245 && br == iface->port->bridge) {
1246 svec_add(&ifaces, iface->iface_cfg->name);
1249 output_sorted(&ifaces, &ctx->output);
1250 svec_destroy(&ifaces);
1256 cmd_iface_to_br(struct vsctl_context *ctx)
1258 struct vsctl_iface *iface;
1259 struct vsctl_info info;
1261 get_info(ctx->ovs, &info);
1262 iface = find_iface(&info, ctx->argv[1], true);
1263 ds_put_format(&ctx->output, "%s\n", iface->port->bridge->name);
1268 cmd_get_controller(struct vsctl_context *ctx)
1270 struct vsctl_info info;
1272 get_info(ctx->ovs, &info);
1274 if (ctx->argc == 1) {
1275 /* Return the controller from the "Open_vSwitch" table */
1277 ds_put_format(&ctx->output, "%s\n", info.ctrl->target);
1280 /* Return the controller for a particular bridge. */
1281 struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true);
1283 /* If no controller is explicitly defined for the requested
1284 * bridge, fallback to the "Open_vSwitch" table's controller. */
1286 ds_put_format(&ctx->output, "%s\n", br->ctrl->target);
1287 } else if (info.ctrl) {
1288 ds_put_format(&ctx->output, "%s\n", info.ctrl->target);
1296 cmd_del_controller(struct vsctl_context *ctx)
1298 struct vsctl_info info;
1300 get_info(ctx->ovs, &info);
1302 if (ctx->argc == 1) {
1304 ovsrec_controller_delete(info.ctrl);
1305 ovsrec_open_vswitch_set_controller(ctx->ovs, NULL);
1308 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1311 ovsrec_controller_delete(br->ctrl);
1312 ovsrec_bridge_set_controller(br->br_cfg, NULL);
1320 cmd_set_controller(struct vsctl_context *ctx)
1322 struct vsctl_info info;
1323 struct ovsrec_controller *ctrl;
1325 get_info(ctx->ovs, &info);
1327 if (ctx->argc == 2) {
1328 /* Set the controller in the "Open_vSwitch" table. */
1330 ovsrec_controller_delete(info.ctrl);
1332 ctrl = ovsrec_controller_insert(ctx->txn);
1333 ovsrec_controller_set_target(ctrl, ctx->argv[1]);
1334 ovsrec_open_vswitch_set_controller(ctx->ovs, ctrl);
1336 /* Set the controller for a particular bridge. */
1337 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1340 ovsrec_controller_delete(br->ctrl);
1342 ctrl = ovsrec_controller_insert(ctx->txn);
1343 ovsrec_controller_set_target(ctrl, ctx->argv[2]);
1344 ovsrec_bridge_set_controller(br->br_cfg, ctrl);
1351 cmd_get_fail_mode(struct vsctl_context *ctx)
1353 struct vsctl_info info;
1354 const char *fail_mode = NULL;
1356 get_info(ctx->ovs, &info);
1358 if (ctx->argc == 1) {
1359 /* Return the fail-mode from the "Open_vSwitch" table */
1360 if (info.ctrl && info.ctrl->fail_mode) {
1361 fail_mode = info.ctrl->fail_mode;
1364 /* Return the fail-mode for a particular bridge. */
1365 struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true);
1367 /* If no controller or fail-mode is explicitly defined for the
1368 * requested bridge, fallback to the "Open_vSwitch" table's
1370 if (br->ctrl && br->ctrl->fail_mode) {
1371 fail_mode = br->ctrl->fail_mode;
1372 } else if (info.ctrl && info.ctrl->fail_mode) {
1373 fail_mode = info.ctrl->fail_mode;
1377 if (fail_mode && strlen(fail_mode)) {
1378 ds_put_format(&ctx->output, "%s\n", fail_mode);
1385 cmd_del_fail_mode(struct vsctl_context *ctx)
1387 struct vsctl_info info;
1389 get_info(ctx->ovs, &info);
1391 if (ctx->argc == 1) {
1392 if (info.ctrl && info.ctrl->fail_mode) {
1393 ovsrec_controller_set_fail_mode(info.ctrl, NULL);
1396 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1398 if (br->ctrl && br->ctrl->fail_mode) {
1399 ovsrec_controller_set_fail_mode(br->ctrl, NULL);
1407 cmd_set_fail_mode(struct vsctl_context *ctx)
1409 struct vsctl_info info;
1410 const char *fail_mode;
1412 get_info(ctx->ovs, &info);
1414 fail_mode = (ctx->argc == 2) ? ctx->argv[1] : ctx->argv[2];
1416 if (strcmp(fail_mode, "standalone") && strcmp(fail_mode, "secure")) {
1417 vsctl_fatal("fail-mode must be \"standalone\" or \"secure\"");
1420 if (ctx->argc == 2) {
1421 /* Set the fail-mode in the "Open_vSwitch" table. */
1423 vsctl_fatal("no controller declared");
1425 ovsrec_controller_set_fail_mode(info.ctrl, fail_mode);
1427 struct vsctl_bridge *br = find_real_bridge(&info, ctx->argv[1], true);
1430 vsctl_fatal("no controller declared for %s", br->name);
1432 ovsrec_controller_set_fail_mode(br->ctrl, fail_mode);
1439 cmd_get_ssl(struct vsctl_context *ctx)
1441 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1444 ds_put_format(&ctx->output, "Private key: %s\n", ssl->private_key);
1445 ds_put_format(&ctx->output, "Certificate: %s\n", ssl->certificate);
1446 ds_put_format(&ctx->output, "CA Certificate: %s\n", ssl->ca_cert);
1447 ds_put_format(&ctx->output, "Bootstrap: %s\n",
1448 ssl->bootstrap_ca_cert ? "true" : "false");
1453 cmd_del_ssl(struct vsctl_context *ctx)
1455 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1458 ovsrec_ssl_delete(ssl);
1459 ovsrec_open_vswitch_set_ssl(ctx->ovs, NULL);
1464 cmd_set_ssl(struct vsctl_context *ctx)
1466 bool bootstrap = shash_find(&ctx->options, "--bootstrap");
1467 struct ovsrec_ssl *ssl = ctx->ovs->ssl;
1470 ovsrec_ssl_delete(ssl);
1472 ssl = ovsrec_ssl_insert(ctx->txn);
1474 ovsrec_ssl_set_private_key(ssl, ctx->argv[1]);
1475 ovsrec_ssl_set_certificate(ssl, ctx->argv[2]);
1476 ovsrec_ssl_set_ca_cert(ssl, ctx->argv[3]);
1478 ovsrec_ssl_set_bootstrap_ca_cert(ssl, bootstrap);
1480 ovsrec_open_vswitch_set_ssl(ctx->ovs, ssl);
1483 /* Parameter commands. */
1485 /* POSIX extended regular expression for an 8-bit unsigned decimal integer. */
1486 #define OCTET_RE "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])"
1488 /* POSIX extended regular expression for an IP address. */
1489 #define IP_RE "("OCTET_RE"\\."OCTET_RE"\\."OCTET_RE"\\."OCTET_RE")"
1491 /* POSIX extended regular expression for a netmask. */
1492 #define NETMASK_RE \
1493 "255.255.255."NETMASK_END_RE"|" \
1494 "255.255."NETMASK_END_RE".0|" \
1495 "255."NETMASK_END_RE".0.0|" \
1496 NETMASK_END_RE".0.0.0"
1497 #define NETMASK_END_RE "(255|254|252|248|240|224|192|128|0)"
1499 /* POSIX extended regular expression for an Ethernet address. */
1500 #define XX_RE "[0-9a-fA-F][0-9a-fA-F]"
1501 #define MAC_RE XX_RE":"XX_RE":"XX_RE":"XX_RE":"XX_RE":"XX_RE
1503 /* POSIX extended regular expression for a TCP or UDP port number. */
1507 "[1-9][0-9][0-9]|" \
1508 "[1-9][0-9][0-9][0-9]|" \
1509 "[1-5][0-9][0-9][0-9][0-9]|" \
1510 "6[1-4][0-9][0-9][0-9]|" \
1511 "65[1-4][0-9][0-9]|" \
1516 VSCF_READONLY = 1 << 0,
1517 VSCF_HIDDEN = 1 << 1
1520 struct vsctl_column {
1521 struct ovsdb_idl_column *idl;
1523 const char *constraint;
1526 static const struct vsctl_column bridge_columns[] = {
1527 {&ovsrec_bridge_col_controller, VSCF_READONLY, NULL},
1528 {&ovsrec_bridge_col_datapath_id, VSCF_READONLY, NULL},
1529 {&ovsrec_bridge_col_datapath_type, VSCF_READONLY, NULL},
1530 {&ovsrec_bridge_col_external_ids, 0, NULL},
1531 {&ovsrec_bridge_col_flood_vlans, 0, "[1,4095]"},
1532 {&ovsrec_bridge_col_mirrors, VSCF_READONLY, NULL},
1533 {&ovsrec_bridge_col_name, VSCF_READONLY, NULL},
1534 {&ovsrec_bridge_col_netflow, VSCF_READONLY, NULL},
1535 {&ovsrec_bridge_col_other_config, 0, NULL},
1536 {&ovsrec_bridge_col_ports, VSCF_READONLY, NULL},
1540 static const struct vsctl_column controller_columns[] = {
1541 {&ovsrec_controller_col_connection_mode, 0, "in-band|out-of-band"},
1542 {&ovsrec_controller_col_controller_burst_limit, 0, "[25,]"},
1543 {&ovsrec_controller_col_controller_rate_limit, 0, "[100,]"},
1544 {&ovsrec_controller_col_discover_accept_regex, 0, NULL},
1545 {&ovsrec_controller_col_discover_update_resolv_conf, 0, NULL},
1546 {&ovsrec_controller_col_fail_mode, 0, "standalone|secure"},
1547 {&ovsrec_controller_col_inactivity_probe, 0, "[5000,]"},
1548 {&ovsrec_controller_col_local_gateway, 0, IP_RE},
1549 {&ovsrec_controller_col_local_ip, 0, IP_RE},
1550 {&ovsrec_controller_col_local_netmask, 0, NETMASK_RE},
1551 {&ovsrec_controller_col_max_backoff, 0, "[1000,]"},
1552 {&ovsrec_controller_col_target, 0, NULL},
1556 static const struct vsctl_column interface_columns[] = {
1557 {&ovsrec_interface_col_external_ids, 0, NULL},
1558 {&ovsrec_interface_col_ingress_policing_burst, 0, "[10,]"},
1559 {&ovsrec_interface_col_ingress_policing_rate, 0, "[100,]"},
1560 {&ovsrec_interface_col_mac, 0, MAC_RE},
1561 {&ovsrec_interface_col_name, VSCF_READONLY, NULL},
1562 {&ovsrec_interface_col_ofport, VSCF_READONLY, NULL},
1563 {&ovsrec_interface_col_options, 0, NULL},
1564 {&ovsrec_interface_col_type, VSCF_READONLY, NULL},
1568 static const struct vsctl_column mirror_columns[] = {
1569 {&ovsrec_mirror_col_name, VSCF_READONLY, NULL},
1570 {&ovsrec_mirror_col_output_port, 0, "Port"},
1571 {&ovsrec_mirror_col_output_vlan, 0, "[1,4095]"},
1572 {&ovsrec_mirror_col_select_dst_port, 0, "Port"},
1573 {&ovsrec_mirror_col_select_src_port, 0, "Port"},
1574 {&ovsrec_mirror_col_select_vlan, 0, "[1,4095]"},
1578 static const struct vsctl_column netflow_columns[] = {
1579 {&ovsrec_netflow_col_active_timeout, 0, "[-1,]"},
1580 {&ovsrec_netflow_col_add_id_to_interface, 0, NULL},
1581 {&ovsrec_netflow_col_engine_id, 0, "[0,255]"},
1582 {&ovsrec_netflow_col_engine_type, 0, "[0,255]"},
1583 {&ovsrec_netflow_col_targets, 0, IP_RE":"PORT_RE},
1587 static const struct vsctl_column open_vswitch_columns[] = {
1588 {&ovsrec_open_vswitch_col_bridges, VSCF_READONLY, NULL},
1589 {&ovsrec_open_vswitch_col_controller, VSCF_READONLY, NULL},
1590 {&ovsrec_open_vswitch_col_cur_cfg, VSCF_HIDDEN, NULL},
1591 {&ovsrec_open_vswitch_col_managers, 0, "p?(ssl|tcp|unix):.*"},
1592 {&ovsrec_open_vswitch_col_next_cfg, VSCF_HIDDEN, NULL},
1593 {&ovsrec_open_vswitch_col_ssl, VSCF_READONLY, NULL},
1597 static const struct vsctl_column port_columns[] = {
1598 {&ovsrec_port_col_bond_downdelay, 0, "[0,]"},
1599 {&ovsrec_port_col_bond_fake_iface, VSCF_READONLY, NULL},
1600 {&ovsrec_port_col_bond_updelay, 0, "[0,]"},
1601 {&ovsrec_port_col_external_ids, 0, NULL},
1602 {&ovsrec_port_col_fake_bridge, VSCF_READONLY, NULL},
1603 {&ovsrec_port_col_interfaces, VSCF_READONLY, NULL},
1604 {&ovsrec_port_col_mac, 0, MAC_RE},
1605 {&ovsrec_port_col_name, VSCF_READONLY, NULL},
1606 {&ovsrec_port_col_other_config, 0, NULL},
1607 {&ovsrec_port_col_tag, 0, "[0,4095]"},
1608 {&ovsrec_port_col_trunks, 0, "[0,4095]"},
1612 static const struct vsctl_column ssl_columns[] = {
1613 {&ovsrec_ssl_col_bootstrap_ca_cert, 0, NULL},
1614 {&ovsrec_ssl_col_ca_cert, 0, NULL},
1615 {&ovsrec_ssl_col_certificate, 0, NULL},
1616 {&ovsrec_ssl_col_private_key, 0, NULL},
1620 struct vsctl_row_id {
1621 const struct ovsdb_idl_table_class *table;
1622 const struct ovsdb_idl_column *name_column;
1623 const struct ovsdb_idl_column *uuid_column;
1626 struct vsctl_table_class {
1627 struct ovsdb_idl_table_class *class;
1628 const struct vsctl_column *columns;
1629 struct vsctl_row_id row_ids[2];
1632 static const struct vsctl_table_class tables[] = {
1633 {&ovsrec_table_bridge, bridge_columns,
1634 {{&ovsrec_table_bridge, &ovsrec_bridge_col_name, NULL},
1635 {NULL, NULL, NULL}}},
1637 {&ovsrec_table_controller, controller_columns,
1638 {{&ovsrec_table_bridge,
1639 &ovsrec_bridge_col_name,
1640 &ovsrec_bridge_col_controller},
1641 {&ovsrec_table_open_vswitch,
1643 &ovsrec_open_vswitch_col_controller}}},
1645 {&ovsrec_table_interface, interface_columns,
1646 {{&ovsrec_table_interface, &ovsrec_interface_col_name, NULL},
1647 {NULL, NULL, NULL}}},
1649 {&ovsrec_table_mirror, mirror_columns,
1650 {{&ovsrec_table_mirror, &ovsrec_mirror_col_name, NULL},
1651 {NULL, NULL, NULL}}},
1653 {&ovsrec_table_netflow, netflow_columns,
1654 {{&ovsrec_table_bridge,
1655 &ovsrec_bridge_col_name,
1656 &ovsrec_bridge_col_netflow},
1657 {NULL, NULL, NULL}}},
1659 {&ovsrec_table_open_vswitch, open_vswitch_columns,
1660 {{&ovsrec_table_open_vswitch, NULL, NULL},
1661 {NULL, NULL, NULL}}},
1663 {&ovsrec_table_port, port_columns,
1664 {{&ovsrec_table_port, &ovsrec_port_col_name, NULL},
1665 {NULL, NULL, NULL}}},
1667 {&ovsrec_table_ssl, ssl_columns,
1668 {{&ovsrec_table_open_vswitch, NULL, &ovsrec_open_vswitch_col_ssl}}},
1670 {NULL, NULL, {{NULL, NULL, NULL}, {NULL, NULL, NULL}}}
1674 die_if_error(char *error)
1677 vsctl_fatal("%s", error);
1682 to_lower_and_underscores(unsigned c)
1684 return c == '-' ? '_' : tolower(c);
1688 score_partial_match(const char *name, const char *s)
1692 if (!strcmp(name, s)) {
1695 for (score = 0; ; score++, name++, s++) {
1696 if (to_lower_and_underscores(*name) != to_lower_and_underscores(*s)) {
1698 } else if (*name == '\0') {
1699 return UINT_MAX - 1;
1702 return *s == '\0' ? score : 0;
1705 static const struct vsctl_table_class *
1706 get_table(const char *table_name)
1708 const struct vsctl_table_class *table;
1709 const struct vsctl_table_class *best_match = NULL;
1710 unsigned int best_score = 0;
1712 for (table = tables; table->class; table++) {
1713 unsigned int score = score_partial_match(table->class->name,
1715 if (score > best_score) {
1718 } else if (score == best_score) {
1724 } else if (best_score) {
1725 vsctl_fatal("multiple table names match \"%s\"", table_name);
1727 vsctl_fatal("unknown table \"%s\"", table_name);
1731 static const struct ovsdb_idl_row *
1732 get_row_by_id(struct vsctl_context *ctx, const struct vsctl_table_class *table,
1733 const struct vsctl_row_id *id, const char *record_id)
1735 const struct ovsdb_idl_row *referrer, *final;
1741 if (!id->name_column) {
1742 if (strcmp(record_id, ".")) {
1745 referrer = ovsdb_idl_first_row(ctx->idl, id->table);
1746 if (!referrer || ovsdb_idl_next_row(referrer)) {
1750 const struct ovsdb_idl_row *row;
1751 unsigned int best_score = 0;
1753 /* It might make sense to relax this assertion. */
1754 assert(id->name_column->type.key_type == OVSDB_TYPE_STRING);
1757 for (row = ovsdb_idl_first_row(ctx->idl, id->table);
1758 row != NULL && best_score != UINT_MAX;
1759 row = ovsdb_idl_next_row(row))
1761 struct ovsdb_datum name;
1763 ovsdb_idl_txn_read(row, id->name_column, &name);
1765 unsigned int score = score_partial_match(name.keys[0].string,
1767 if (score > best_score) {
1770 } else if (score == best_score) {
1774 ovsdb_datum_destroy(&name, &id->name_column->type);
1776 if (best_score && !referrer) {
1777 vsctl_fatal("multiple rows in %s match \"%s\"",
1778 table->class->name, record_id);
1786 if (id->uuid_column) {
1787 struct ovsdb_datum uuid;
1789 assert(id->uuid_column->type.key_type == OVSDB_TYPE_UUID);
1790 assert(id->uuid_column->type.value_type == OVSDB_TYPE_VOID);
1792 ovsdb_idl_txn_read(referrer, id->uuid_column, &uuid);
1794 final = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class,
1795 &uuid.keys[0].uuid);
1797 ovsdb_datum_destroy(&uuid, &id->uuid_column->type);
1805 static const struct ovsdb_idl_row *
1806 get_row(struct vsctl_context *ctx,
1807 const struct vsctl_table_class *table, const char *record_id)
1809 const struct ovsdb_idl_row *row;
1812 if (uuid_from_string(&uuid, record_id)) {
1813 row = ovsdb_idl_get_row_for_uuid(ctx->idl, table->class, &uuid);
1817 for (i = 0; i < ARRAY_SIZE(table->row_ids); i++) {
1818 row = get_row_by_id(ctx, table, &table->row_ids[i], record_id);
1827 static const struct ovsdb_idl_row *
1828 must_get_row(struct vsctl_context *ctx,
1829 const struct vsctl_table_class *table, const char *record_id)
1831 const struct ovsdb_idl_row *row = get_row(ctx, table, record_id);
1833 vsctl_fatal("no row \"%s\" in table %s",
1834 record_id, table->class->name);
1840 get_column(const struct vsctl_table_class *table, const char *column_name,
1841 const struct vsctl_column **columnp)
1843 const struct vsctl_column *column;
1844 const struct vsctl_column *best_match = NULL;
1845 unsigned int best_score = 0;
1847 for (column = table->columns; column->idl; column++) {
1848 if (!(column->flags & VSCF_HIDDEN)) {
1849 unsigned int score = score_partial_match(column->idl->name,
1851 if (score > best_score) {
1852 best_match = column;
1854 } else if (score == best_score) {
1860 *columnp = best_match;
1863 } else if (best_score) {
1864 return xasprintf("%s contains more than one column whose name "
1865 "matches \"%s\"", table->class->name, column_name);
1867 return xasprintf("%s does not contain a column whose name matches "
1868 "\"%s\"", table->class->name, column_name);
1872 static char * WARN_UNUSED_RESULT
1873 parse_column_key_value(const char *arg, const struct vsctl_table_class *table,
1874 const struct vsctl_column **columnp,
1875 char **keyp, char **valuep)
1877 const char *p = arg;
1880 assert(columnp || keyp);
1888 /* Parse column name. */
1892 error = ovsdb_token_parse(&p, &column_name);
1896 if (column_name[0] == '\0') {
1898 error = xasprintf("%s: missing column name", arg);
1901 error = get_column(table, column_name, columnp);
1908 /* Parse key string. */
1909 if (*p == ':' || !columnp) {
1913 error = xasprintf("%s: key not accepted here", arg);
1916 error = ovsdb_token_parse(&p, keyp);
1924 /* Parse value string. */
1927 error = xasprintf("%s: value not accepted here", arg);
1930 *valuep = xstrdup(p + 1);
1936 error = xasprintf("%s: trailing garbage \"%s\" in argument",
1959 cmd_get(struct vsctl_context *ctx)
1961 bool if_exists = shash_find(&ctx->options, "--if-exists");
1962 const char *table_name = ctx->argv[1];
1963 const char *record_id = ctx->argv[2];
1964 const struct vsctl_table_class *table;
1965 const struct ovsdb_idl_row *row;
1966 struct ds *out = &ctx->output;
1969 table = get_table(table_name);
1970 row = must_get_row(ctx, table, record_id);
1971 for (i = 3; i < ctx->argc; i++) {
1972 const struct vsctl_column *column;
1973 struct ovsdb_datum datum;
1976 die_if_error(parse_column_key_value(ctx->argv[i], table,
1977 &column, &key_string, NULL));
1979 ovsdb_idl_txn_read(row, column->idl, &datum);
1981 union ovsdb_atom key;
1984 if (column->idl->type.value_type == OVSDB_TYPE_VOID) {
1985 vsctl_fatal("cannot specify key to get for non-map column %s",
1989 die_if_error(ovsdb_atom_from_string(&key,
1990 column->idl->type.key_type,
1993 idx = ovsdb_datum_find_key(&datum, &key,
1994 column->idl->type.key_type);
1995 if (idx == UINT_MAX) {
1997 vsctl_fatal("no key \"%s\" in %s record \"%s\" column %s",
1998 key_string, table->class->name, record_id,
2002 ovsdb_atom_to_string(&datum.values[idx],
2003 column->idl->type.value_type, out);
2005 ovsdb_atom_destroy(&key, column->idl->type.key_type);
2007 ovsdb_datum_to_string(&datum, &column->idl->type, out);
2009 ds_put_char(out, '\n');
2010 ovsdb_datum_destroy(&datum, &column->idl->type);
2017 list_record(const struct vsctl_table_class *table,
2018 const struct ovsdb_idl_row *row, struct ds *out)
2020 const struct vsctl_column *column;
2022 ds_put_format(out, "%-20s (RO): "UUID_FMT"\n", "_uuid",
2023 UUID_ARGS(&row->uuid));
2024 for (column = table->columns; column->idl; column++) {
2025 struct ovsdb_datum datum;
2027 if (column->flags & VSCF_HIDDEN) {
2031 ovsdb_idl_txn_read(row, column->idl, &datum);
2033 ds_put_format(out, "%-20s (%s): ", column->idl->name,
2034 column->flags & VSCF_READONLY ? "RO" : "RW");
2035 ovsdb_datum_to_string(&datum, &column->idl->type, out);
2036 ds_put_char(out, '\n');
2038 ovsdb_datum_destroy(&datum, &column->idl->type);
2043 cmd_list(struct vsctl_context *ctx)
2045 const char *table_name = ctx->argv[1];
2046 const struct vsctl_table_class *table;
2047 struct ds *out = &ctx->output;
2050 table = get_table(table_name);
2051 if (ctx->argc > 2) {
2052 for (i = 2; i < ctx->argc; i++) {
2054 ds_put_char(out, '\n');
2056 list_record(table, must_get_row(ctx, table, ctx->argv[i]), out);
2059 const struct ovsdb_idl_row *row;
2062 for (row = ovsdb_idl_first_row(ctx->idl, table->class), first = true;
2064 row = ovsdb_idl_next_row(row), first = false) {
2066 ds_put_char(out, '\n');
2068 list_record(table, row, out);
2074 check_string_constraint(const struct ovsdb_datum *datum,
2075 const char *constraint)
2082 regex = xasprintf("^%s$", constraint);
2083 retval = regcomp(&re, regex, REG_NOSUB | REG_EXTENDED);
2085 size_t length = regerror(retval, &re, NULL, 0);
2086 char *buffer = xmalloc(length);
2087 regerror(retval, &re, buffer, length);
2088 vsctl_fatal("internal error compiling regular expression %s: %s",
2092 for (i = 0; i < datum->n; i++) {
2093 const char *key = datum->keys[i].string;
2094 if (regexec(&re, key, 0, NULL, 0)) {
2095 vsctl_fatal("%s is not valid (it does not match %s)", key, regex);
2103 check_integer_constraint(const struct ovsdb_datum *datum,
2104 const char *constraint)
2110 sscanf(constraint, "[%"SCNd64",%"SCNd64"]%n", &min, &max, &n);
2112 sscanf(constraint, "[%"SCNd64",]%n", &min, &n);
2114 sscanf(constraint, "[,%"SCNd64"]%n", &max, &n);
2116 VLOG_DBG("internal error: bad integer contraint \"%s\"",
2127 for (i = 0; i < datum->n; i++) {
2128 int64_t value = datum->keys[i].integer;
2129 if (value < min || value > max) {
2130 if (max == INT64_MAX) {
2131 vsctl_fatal("%"PRId64" is less than the minimum "
2132 "allowed value %"PRId64, value, min);
2133 } else if (min == INT64_MIN) {
2134 vsctl_fatal("%"PRId64" is greater than the maximum "
2135 "allowed value %"PRId64, value, max);
2137 vsctl_fatal("%"PRId64" is outside the valid range %"PRId64" "
2138 "to %"PRId64" (inclusive)", value, min, max);
2145 check_constraint(const struct ovsdb_datum *datum,
2146 const struct ovsdb_type *type, const char *constraint)
2148 if (constraint && datum->n) {
2149 if (type->key_type == OVSDB_TYPE_STRING) {
2150 check_string_constraint(datum, constraint);
2151 } else if (type->key_type == OVSDB_TYPE_INTEGER) {
2152 check_integer_constraint(datum, constraint);
2158 set_column(const struct vsctl_table_class *table,
2159 const struct ovsdb_idl_row *row,
2160 const char *arg, bool force)
2162 const struct vsctl_column *column;
2163 char *key_string, *value_string;
2166 error = parse_column_key_value(arg, table, &column, &key_string,
2168 die_if_error(error);
2169 if (column->flags & VSCF_READONLY && !force) {
2170 vsctl_fatal("%s: cannot modify read-only column %s in table %s",
2171 arg, column->idl->name, table->class->name);
2173 if (!value_string) {
2174 vsctl_fatal("%s: missing value", arg);
2178 union ovsdb_atom key, value;
2179 struct ovsdb_datum old, new;
2181 if (column->idl->type.value_type == OVSDB_TYPE_VOID) {
2182 vsctl_fatal("cannot specify key to set for non-map column %s",
2186 die_if_error(ovsdb_atom_from_string(&key,
2187 column->idl->type.key_type,
2189 die_if_error(ovsdb_atom_from_string(&value,
2190 column->idl->type.value_type,
2193 ovsdb_datum_init_empty(&new);
2194 ovsdb_datum_add_unsafe(&new, &key, &value, &column->idl->type);
2196 ovsdb_atom_destroy(&key, column->idl->type.key_type);
2197 ovsdb_atom_destroy(&value, column->idl->type.value_type);
2199 ovsdb_idl_txn_read(row, column->idl, &old);
2200 ovsdb_datum_union(&old, &new, &column->idl->type, true);
2201 ovsdb_idl_txn_write(row, column->idl, &old);
2203 ovsdb_datum_destroy(&new, &column->idl->type);
2205 struct ovsdb_datum datum;
2207 die_if_error(ovsdb_datum_from_string(&datum, &column->idl->type,
2210 check_constraint(&datum, &column->idl->type,
2211 column->constraint);
2213 ovsdb_idl_txn_write(row, column->idl, &datum);
2221 cmd_set(struct vsctl_context *ctx)
2223 bool force = shash_find(&ctx->options, "--force");
2224 const char *table_name = ctx->argv[1];
2225 const char *record_id = ctx->argv[2];
2226 const struct vsctl_table_class *table;
2227 const struct ovsdb_idl_row *row;
2230 table = get_table(table_name);
2231 row = must_get_row(ctx, table, record_id);
2232 for (i = 3; i < ctx->argc; i++) {
2233 set_column(table, row, ctx->argv[i], force);
2238 cmd_add(struct vsctl_context *ctx)
2240 bool force = shash_find(&ctx->options, "--force");
2241 const char *table_name = ctx->argv[1];
2242 const char *record_id = ctx->argv[2];
2243 const char *column_name = ctx->argv[3];
2244 const struct vsctl_table_class *table;
2245 const struct vsctl_column *column;
2246 const struct ovsdb_idl_row *row;
2247 const struct ovsdb_type *type;
2248 struct ovsdb_datum old;
2251 table = get_table(table_name);
2252 row = must_get_row(ctx, table, record_id);
2253 die_if_error(get_column(table, column_name, &column));
2254 if (column->flags & VSCF_READONLY && !force) {
2255 vsctl_fatal("cannot modify read-only column %s in table %s",
2256 column->idl->name, table->class->name);
2259 type = &column->idl->type;
2260 ovsdb_idl_txn_read(row, column->idl, &old);
2261 for (i = 4; i < ctx->argc; i++) {
2262 struct ovsdb_type add_type;
2263 struct ovsdb_datum add;
2267 add_type.n_max = UINT_MAX;
2268 die_if_error(ovsdb_datum_from_string(&add, &add_type, ctx->argv[i]));
2269 ovsdb_datum_union(&old, &add, type, false);
2270 ovsdb_datum_destroy(&add, type);
2272 if (old.n > type->n_max) {
2273 vsctl_fatal("\"add\" operation would put %u %s in column %s of "
2274 "table %s but the maximum number is %u",
2276 type->value_type == OVSDB_TYPE_VOID ? "values" : "pairs",
2277 column->idl->name, table->class->name, type->n_max);
2279 ovsdb_idl_txn_write(row, column->idl, &old);
2283 cmd_remove(struct vsctl_context *ctx)
2285 bool force = shash_find(&ctx->options, "--force");
2286 const char *table_name = ctx->argv[1];
2287 const char *record_id = ctx->argv[2];
2288 const char *column_name = ctx->argv[3];
2289 const struct vsctl_table_class *table;
2290 const struct vsctl_column *column;
2291 const struct ovsdb_idl_row *row;
2292 const struct ovsdb_type *type;
2293 struct ovsdb_datum old;
2296 table = get_table(table_name);
2297 row = must_get_row(ctx, table, record_id);
2298 die_if_error(get_column(table, column_name, &column));
2299 if (column->flags & VSCF_READONLY && !force) {
2300 vsctl_fatal("cannot modify read-only column %s in table %s",
2301 column->idl->name, table->class->name);
2304 type = &column->idl->type;
2305 ovsdb_idl_txn_read(row, column->idl, &old);
2306 for (i = 4; i < ctx->argc; i++) {
2307 struct ovsdb_type rm_type;
2308 struct ovsdb_datum rm;
2313 rm_type.n_max = UINT_MAX;
2314 error = ovsdb_datum_from_string(&rm, &rm_type, ctx->argv[i]);
2315 if (error && ovsdb_type_is_map(&rm_type)) {
2317 rm_type.value_type = OVSDB_TYPE_VOID;
2318 die_if_error(ovsdb_datum_from_string(&rm, &rm_type, ctx->argv[i]));
2320 ovsdb_datum_subtract(&old, type, &rm, &rm_type);
2321 ovsdb_datum_destroy(&rm, &rm_type);
2323 if (old.n < type->n_min) {
2324 vsctl_fatal("\"remove\" operation would put %u %s in column %s of "
2325 "table %s but the minimun number is %u",
2327 type->value_type == OVSDB_TYPE_VOID ? "values" : "pairs",
2328 column->idl->name, table->class->name, type->n_min);
2330 ovsdb_idl_txn_write(row, column->idl, &old);
2334 cmd_clear(struct vsctl_context *ctx)
2336 bool force = shash_find(&ctx->options, "--force");
2337 const char *table_name = ctx->argv[1];
2338 const char *record_id = ctx->argv[2];
2339 const struct vsctl_table_class *table;
2340 const struct ovsdb_idl_row *row;
2343 table = get_table(table_name);
2344 row = must_get_row(ctx, table, record_id);
2345 for (i = 3; i < ctx->argc; i++) {
2346 const struct vsctl_column *column;
2347 const struct ovsdb_type *type;
2348 struct ovsdb_datum datum;
2350 die_if_error(get_column(table, ctx->argv[i], &column));
2352 type = &column->idl->type;
2353 if (column->flags & VSCF_READONLY && !force) {
2354 vsctl_fatal("cannot modify read-only column %s in table %s",
2355 column->idl->name, table->class->name);
2356 } else if (type->n_min > 0) {
2357 vsctl_fatal("\"clear\" operation cannot be applied to column %s "
2358 "of table %s, which is not allowed to be empty",
2359 column->idl->name, table->class->name);
2362 ovsdb_datum_init_empty(&datum);
2363 ovsdb_idl_txn_write(row, column->idl, &datum);
2368 cmd_create(struct vsctl_context *ctx)
2370 bool force = shash_find(&ctx->options, "--force");
2371 const char *table_name = ctx->argv[1];
2372 const struct vsctl_table_class *table;
2373 const struct ovsdb_idl_row *row;
2377 vsctl_fatal("\"create\" requires --force");
2380 table = get_table(table_name);
2381 row = ovsdb_idl_txn_insert(ctx->txn, table->class);
2382 for (i = 2; i < ctx->argc; i++) {
2383 set_column(table, row, ctx->argv[i], force);
2385 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(&row->uuid));
2388 /* This function may be used as the 'postprocess' function for commands that
2389 * insert new rows into the database. It expects that the command's 'run'
2390 * function prints the UUID reported by ovsdb_idl_txn_insert() as the command's
2391 * sole output. It replaces that output by the row's permanent UUID assigned
2392 * by the database server and appends a new-line.
2394 * Currently we use this only for "create", because the higher-level commands
2395 * are supposed to be independent of the actual structure of the vswitch
2398 post_create(struct vsctl_context *ctx)
2400 const struct uuid *real;
2403 uuid_from_string(&dummy, ds_cstr(&ctx->output));
2404 real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy);
2406 ds_clear(&ctx->output);
2407 ds_put_format(&ctx->output, UUID_FMT, UUID_ARGS(real));
2409 ds_put_char(&ctx->output, '\n');
2413 cmd_destroy(struct vsctl_context *ctx)
2415 bool force = shash_find(&ctx->options, "--force");
2416 bool must_exist = !shash_find(&ctx->options, "--if-exists");
2417 const char *table_name = ctx->argv[1];
2418 const struct vsctl_table_class *table;
2422 vsctl_fatal("\"destroy\" requires --force");
2425 table = get_table(table_name);
2426 for (i = 2; i < ctx->argc; i++) {
2427 const struct ovsdb_idl_row *row;
2429 row = (must_exist ? must_get_row : get_row)(ctx, table, ctx->argv[i]);
2431 ovsdb_idl_txn_delete(row);
2436 static struct json *
2437 where_uuid_equals(const struct uuid *uuid)
2440 json_array_create_1(
2441 json_array_create_3(
2442 json_string_create("_uuid"),
2443 json_string_create("=="),
2444 json_array_create_2(
2445 json_string_create("uuid"),
2446 json_string_create_nocopy(
2447 xasprintf(UUID_FMT, UUID_ARGS(uuid))))));
2451 vsctl_context_init(struct vsctl_context *ctx, struct vsctl_command *command,
2452 struct ovsdb_idl *idl, struct ovsdb_idl_txn *txn,
2453 const struct ovsrec_open_vswitch *ovs)
2455 ctx->argc = command->argc;
2456 ctx->argv = command->argv;
2457 ctx->options = command->options;
2459 ds_swap(&ctx->output, &command->output);
2467 vsctl_context_done(struct vsctl_context *ctx, struct vsctl_command *command)
2469 ds_swap(&ctx->output, &command->output);
2473 do_vsctl(const char *args, struct vsctl_command *commands, size_t n_commands,
2474 struct ovsdb_idl *idl)
2476 struct ovsdb_idl_txn *txn;
2477 const struct ovsrec_open_vswitch *ovs;
2478 enum ovsdb_idl_txn_status status;
2479 struct vsctl_command *c;
2480 int64_t next_cfg = 0;
2483 txn = the_idl_txn = ovsdb_idl_txn_create(idl);
2485 ovsdb_idl_txn_set_dry_run(txn);
2488 comment = xasprintf("ovs-vsctl: %s", args);
2489 ovsdb_idl_txn_add_comment(txn, comment);
2492 ovs = ovsrec_open_vswitch_first(idl);
2494 /* XXX add verification that table is empty */
2495 ovs = ovsrec_open_vswitch_insert(txn);
2498 if (wait_for_reload) {
2499 struct json *where = where_uuid_equals(&ovs->header_.uuid);
2500 ovsdb_idl_txn_increment(txn, "Open_vSwitch", "next_cfg", where);
2501 json_destroy(where);
2504 for (c = commands; c < &commands[n_commands]; c++) {
2505 struct vsctl_context ctx;
2507 ds_init(&c->output);
2508 vsctl_context_init(&ctx, c, idl, txn, ovs);
2509 (c->syntax->run)(&ctx);
2510 vsctl_context_done(&ctx, c);
2513 while ((status = ovsdb_idl_txn_commit(txn)) == TXN_INCOMPLETE) {
2515 ovsdb_idl_wait(idl);
2516 ovsdb_idl_txn_wait(txn);
2519 if (wait_for_reload && status == TXN_SUCCESS) {
2520 next_cfg = ovsdb_idl_txn_get_increment_new_value(txn);
2522 for (c = commands; c < &commands[n_commands]; c++) {
2523 if (c->syntax->postprocess) {
2524 struct vsctl_context ctx;
2526 vsctl_context_init(&ctx, c, idl, txn, ovs);
2527 (c->syntax->postprocess)(&ctx);
2528 vsctl_context_done(&ctx, c);
2531 ovsdb_idl_txn_destroy(txn);
2535 case TXN_INCOMPLETE:
2539 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2540 vsctl_fatal("transaction aborted");
2547 for (c = commands; c < &commands[n_commands]; c++) {
2548 ds_destroy(&c->output);
2553 vsctl_fatal("transaction error");
2559 for (c = commands; c < &commands[n_commands]; c++) {
2560 struct ds *ds = &c->output;
2565 for (j = 0; j < ds->length; j++) {
2566 int c = ds->string[j];
2569 fputs("\\n", stdout);
2573 fputs("\\\\", stdout);
2582 fputs(ds_cstr(ds), stdout);
2584 ds_destroy(&c->output);
2585 shash_destroy(&c->options);
2589 if (wait_for_reload && status != TXN_UNCHANGED) {
2591 const struct ovsrec_open_vswitch *ovs;
2594 OVSREC_OPEN_VSWITCH_FOR_EACH (ovs, idl) {
2595 if (ovs->cur_cfg >= next_cfg) {
2599 ovsdb_idl_wait(idl);
2604 ovsdb_idl_destroy(idl);
2609 static const struct vsctl_command_syntax all_commands[] = {
2610 /* Open vSwitch commands. */
2611 {"init", 0, 0, cmd_init, NULL, ""},
2613 /* Bridge commands. */
2614 {"add-br", 1, 3, cmd_add_br, NULL, ""},
2615 {"del-br", 1, 1, cmd_del_br, NULL, "--if-exists"},
2616 {"list-br", 0, 0, cmd_list_br, NULL, ""},
2617 {"br-exists", 1, 1, cmd_br_exists, NULL, ""},
2618 {"br-to-vlan", 1, 1, cmd_br_to_vlan, NULL, ""},
2619 {"br-to-parent", 1, 1, cmd_br_to_parent, NULL, ""},
2620 {"br-set-external-id", 2, 3, cmd_br_set_external_id, NULL, ""},
2621 {"br-get-external-id", 1, 2, cmd_br_get_external_id, NULL, ""},
2623 /* Port commands. */
2624 {"list-ports", 1, 1, cmd_list_ports, NULL, ""},
2625 {"add-port", 2, 2, cmd_add_port, NULL, ""},
2626 {"add-bond", 4, INT_MAX, cmd_add_bond, NULL, "--fake-iface"},
2627 {"del-port", 1, 2, cmd_del_port, NULL, "--if-exists"},
2628 {"port-to-br", 1, 1, cmd_port_to_br, NULL, ""},
2630 /* Interface commands. */
2631 {"list-ifaces", 1, 1, cmd_list_ifaces, NULL, ""},
2632 {"iface-to-br", 1, 1, cmd_iface_to_br, NULL, ""},
2634 /* Controller commands. */
2635 {"get-controller", 0, 1, cmd_get_controller, NULL, ""},
2636 {"del-controller", 0, 1, cmd_del_controller, NULL, ""},
2637 {"set-controller", 1, 2, cmd_set_controller, NULL, ""},
2638 {"get-fail-mode", 0, 1, cmd_get_fail_mode, NULL, ""},
2639 {"del-fail-mode", 0, 1, cmd_del_fail_mode, NULL, ""},
2640 {"set-fail-mode", 1, 2, cmd_set_fail_mode, NULL, ""},
2643 {"get-ssl", 0, 0, cmd_get_ssl, NULL, ""},
2644 {"del-ssl", 0, 0, cmd_del_ssl, NULL, ""},
2645 {"set-ssl", 3, 3, cmd_set_ssl, NULL, "--bootstrap"},
2647 /* Parameter commands. */
2648 {"get", 3, INT_MAX, cmd_get, NULL, "--if-exists"},
2649 {"list", 1, INT_MAX, cmd_list, NULL, ""},
2650 {"set", 3, INT_MAX, cmd_set, NULL, "--force"},
2651 {"add", 4, INT_MAX, cmd_add, NULL, "--force"},
2652 {"remove", 4, INT_MAX, cmd_remove, NULL, "--force"},
2653 {"clear", 3, INT_MAX, cmd_clear, NULL, "--force"},
2654 {"create", 2, INT_MAX, cmd_create, post_create, "--force"},
2655 {"destroy", 1, INT_MAX, cmd_destroy, NULL, "--force,--if-exists"},
2657 {NULL, 0, 0, NULL, NULL, NULL},