2 * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
30 #include "db-ctl-base.h"
32 #include "command-line.h"
35 #include "openvswitch/dynamic-string.h"
36 #include "fatal-signal.h"
38 #include "openvswitch/json.h"
39 #include "ovsdb-data.h"
40 #include "ovsdb-idl.h"
41 #include "openvswitch/poll-loop.h"
44 #include "stream-ssl.h"
48 #include "lib/vswitch-idl.h"
52 #include "openvswitch/vconn.h"
53 #include "openvswitch/vlog.h"
55 VLOG_DEFINE_THIS_MODULE(vsctl
);
59 /* --db: The database server to contact. */
60 static const char *db
;
62 /* --oneline: Write each command's output as a single line? */
65 /* --dry-run: Do not commit any changes. */
68 /* --no-wait: Wait for ovs-vswitchd to reload its configuration? */
69 static bool wait_for_reload
= true;
71 /* --timeout: Time to wait for a connection to 'db'. */
74 /* --retry: If true, ovs-vsctl will retry connecting to the database forever.
75 * If false and --db says to use an active connection method (e.g. "unix:",
76 * "tcp:", "ssl:"), then ovs-vsctl will try to connect once and exit with an
77 * error if the database server cannot be contacted (e.g. ovsdb-server is not
80 * Regardless of this setting, --timeout always limits how long ovs-vsctl will
84 /* Format for table output. */
85 static struct table_style table_style
= TABLE_STYLE_DEFAULT
;
87 static void vsctl_cmd_init(void);
89 /* The IDL we're using and the current transaction, if any.
90 * This is for use by vsctl_exit() only, to allow it to clean up.
91 * Other code should use its context arguments. */
92 static struct ovsdb_idl
*the_idl
;
93 static struct ovsdb_idl_txn
*the_idl_txn
;
94 OVS_NO_RETURN
static void vsctl_exit(int status
);
96 OVS_NO_RETURN
static void usage(void);
97 static void parse_options(int argc
, char *argv
[], struct shash
*local_options
);
98 static void run_prerequisites(struct ctl_command
[], size_t n_commands
,
100 static bool do_vsctl(const char *args
, struct ctl_command
*, size_t n
,
103 /* post_db_reload_check frame work is to allow ovs-vsctl to do additional
104 * checks after OVSDB transactions are successfully recorded and reload by
107 * For example, When a new interface is added to OVSDB, ovs-vswitchd will
108 * either store a positive values on successful implementing the new
109 * interface, or -1 on failure.
111 * Unless --no-wait command line option is specified,
112 * post_db_reload_do_checks() is called right after any configuration
113 * changes is picked up (i.e. reload) by ovs-vswitchd. Any error detected
114 * post OVSDB reload is reported as ovs-vsctl errors. OVS-vswitchd logs
115 * more detailed messages about those errors.
117 * Current implementation only check for Post OVSDB reload failures on new
118 * interface additions with 'add-br' and 'add-port' commands.
120 * post_db_reload_expect_iface()
122 * keep track of interfaces to be checked post OVSDB reload. */
123 static void post_db_reload_check_init(void);
124 static void post_db_reload_do_checks(const struct vsctl_context
*);
125 static void post_db_reload_expect_iface(const struct ovsrec_interface
*);
127 static struct uuid
*neoteric_ifaces
;
128 static size_t n_neoteric_ifaces
;
129 static size_t allocated_neoteric_ifaces
;
132 main(int argc
, char *argv
[])
134 struct ovsdb_idl
*idl
;
135 struct ctl_command
*commands
;
136 struct shash local_options
;
140 set_program_name(argv
[0]);
141 fatal_ignore_sigpipe();
142 vlog_set_levels(NULL
, VLF_CONSOLE
, VLL_WARN
);
143 vlog_set_levels_from_string_assert("reconnect:warn");
147 /* Parse command line. */
148 char *args
= process_escape_args(argv
);
149 shash_init(&local_options
);
150 parse_options(argc
, argv
, &local_options
);
151 commands
= ctl_parse_commands(argc
- optind
, argv
+ optind
, &local_options
,
153 VLOG(ctl_might_write_to_db(commands
, n_commands
) ? VLL_INFO
: VLL_DBG
,
154 "Called as %s", args
);
160 /* Initialize IDL. */
161 idl
= the_idl
= ovsdb_idl_create(db
, &ovsrec_idl_class
, false, retry
);
162 run_prerequisites(commands
, n_commands
, idl
);
164 /* Execute the commands.
166 * 'seqno' is the database sequence number for which we last tried to
167 * execute our transaction. There's no point in trying to commit more than
168 * once for any given sequence number, because if the transaction fails
169 * it's because the database changed and we need to obtain an up-to-date
170 * view of the database before we try the transaction again. */
171 seqno
= ovsdb_idl_get_seqno(idl
);
174 if (!ovsdb_idl_is_alive(idl
)) {
175 int retval
= ovsdb_idl_get_last_error(idl
);
176 ctl_fatal("%s: database connection failed (%s)",
177 db
, ovs_retval_to_string(retval
));
180 if (seqno
!= ovsdb_idl_get_seqno(idl
)) {
181 seqno
= ovsdb_idl_get_seqno(idl
);
182 if (do_vsctl(args
, commands
, n_commands
, idl
)) {
188 if (seqno
== ovsdb_idl_get_seqno(idl
)) {
196 parse_options(int argc
, char *argv
[], struct shash
*local_options
)
199 OPT_DB
= UCHAR_MAX
+ 1,
204 OPT_BOOTSTRAP_CA_CERT
,
214 static const struct option global_long_options
[] = {
215 {"db", required_argument
, NULL
, OPT_DB
},
216 {"no-syslog", no_argument
, NULL
, OPT_NO_SYSLOG
},
217 {"no-wait", no_argument
, NULL
, OPT_NO_WAIT
},
218 {"dry-run", no_argument
, NULL
, OPT_DRY_RUN
},
219 {"oneline", no_argument
, NULL
, OPT_ONELINE
},
220 {"timeout", required_argument
, NULL
, 't'},
221 {"retry", no_argument
, NULL
, OPT_RETRY
},
222 {"help", no_argument
, NULL
, 'h'},
223 {"commands", no_argument
, NULL
, OPT_COMMANDS
},
224 {"options", no_argument
, NULL
, OPT_OPTIONS
},
225 {"version", no_argument
, NULL
, 'V'},
228 STREAM_SSL_LONG_OPTIONS
,
229 {"bootstrap-ca-cert", required_argument
, NULL
, OPT_BOOTSTRAP_CA_CERT
},
230 {"peer-ca-cert", required_argument
, NULL
, OPT_PEER_CA_CERT
},
233 const int n_global_long_options
= ARRAY_SIZE(global_long_options
) - 1;
234 char *tmp
, *short_options
;
236 struct option
*options
;
237 size_t allocated_options
;
241 tmp
= ovs_cmdl_long_options_to_short_options(global_long_options
);
242 short_options
= xasprintf("+%s", tmp
);
245 /* We want to parse both global and command-specific options here, but
246 * getopt_long() isn't too convenient for the job. We copy our global
247 * options into a dynamic array, then append all of the command-specific
249 options
= xmemdup(global_long_options
, sizeof global_long_options
);
250 allocated_options
= ARRAY_SIZE(global_long_options
);
251 n_options
= n_global_long_options
;
252 ctl_add_cmd_options(&options
, &n_options
, &allocated_options
, OPT_LOCAL
);
258 c
= getopt_long(argc
, argv
, short_options
, options
, &idx
);
273 vlog_set_levels(&this_module
, VLF_SYSLOG
, VLL_WARN
);
277 wait_for_reload
= false;
285 if (shash_find(local_options
, options
[idx
].name
)) {
286 ctl_fatal("'%s' option specified multiple times",
289 shash_add_nocopy(local_options
,
290 xasprintf("--%s", options
[idx
].name
),
291 nullable_xstrdup(optarg
));
298 ctl_print_commands();
302 ctl_print_options(global_long_options
);
306 ovs_print_version(0, 0);
307 printf("DB Schema %s\n", ovsrec_get_db_version());
311 timeout
= strtoul(optarg
, NULL
, 10);
313 ctl_fatal("value %s on -t or --timeout is invalid",
323 TABLE_OPTION_HANDLERS(&table_style
)
325 STREAM_SSL_OPTION_HANDLERS
327 case OPT_PEER_CA_CERT
:
328 stream_ssl_set_peer_ca_cert_file(optarg
);
331 case OPT_BOOTSTRAP_CA_CERT
:
332 stream_ssl_set_ca_cert_file(optarg
, true);
345 db
= ctl_default_db();
348 for (i
= n_global_long_options
; options
[i
].name
; i
++) {
349 free(CONST_CAST(char *, options
[i
].name
));
358 %s: ovs-vswitchd management utility\n\
359 usage: %s [OPTIONS] COMMAND [ARG...]\n\
361 Open vSwitch commands:\n\
362 init initialize database, if not yet initialized\n\
363 show print overview of database contents\n\
364 emer-reset reset configuration to clean state\n\
367 add-br BRIDGE create a new bridge named BRIDGE\n\
368 add-br BRIDGE PARENT VLAN create new fake BRIDGE in PARENT on VLAN\n\
369 del-br BRIDGE delete BRIDGE and all of its ports\n\
370 list-br print the names of all the bridges\n\
371 br-exists BRIDGE exit 2 if BRIDGE does not exist\n\
372 br-to-vlan BRIDGE print the VLAN which BRIDGE is on\n\
373 br-to-parent BRIDGE print the parent of BRIDGE\n\
374 br-set-external-id BRIDGE KEY VALUE set KEY on BRIDGE to VALUE\n\
375 br-set-external-id BRIDGE KEY unset KEY on BRIDGE\n\
376 br-get-external-id BRIDGE KEY print value of KEY on BRIDGE\n\
377 br-get-external-id BRIDGE list key-value pairs on BRIDGE\n\
379 Port commands (a bond is considered to be a single port):\n\
380 list-ports BRIDGE print the names of all the ports on BRIDGE\n\
381 add-port BRIDGE PORT add network device PORT to BRIDGE\n\
382 add-bond BRIDGE PORT IFACE... add bonded port PORT in BRIDGE from IFACES\n\
383 del-port [BRIDGE] PORT delete PORT (which may be bonded) from BRIDGE\n\
384 port-to-br PORT print name of bridge that contains PORT\n\
386 Interface commands (a bond consists of multiple interfaces):\n\
387 list-ifaces BRIDGE print the names of all interfaces on BRIDGE\n\
388 iface-to-br IFACE print name of bridge that contains IFACE\n\
390 Controller commands:\n\
391 get-controller BRIDGE print the controllers for BRIDGE\n\
392 del-controller BRIDGE delete the controllers for BRIDGE\n\
393 [--inactivity-probe=MSECS]\n\
394 set-controller BRIDGE TARGET... set the controllers for BRIDGE\n\
395 get-fail-mode BRIDGE print the fail-mode for BRIDGE\n\
396 del-fail-mode BRIDGE delete the fail-mode for BRIDGE\n\
397 set-fail-mode BRIDGE MODE set the fail-mode for BRIDGE to MODE\n\
400 get-manager print the managers\n\
401 del-manager delete the managers\n\
402 [--inactivity-probe=MSECS]\n\
403 set-manager TARGET... set the list of managers to TARGET...\n\
406 get-ssl print the SSL configuration\n\
407 del-ssl delete the SSL configuration\n\
408 set-ssl PRIV-KEY CERT CA-CERT set the SSL configuration\n\
410 Auto Attach commands:\n\
411 add-aa-mapping BRIDGE I-SID VLAN add Auto Attach mapping to BRIDGE\n\
412 del-aa-mapping BRIDGE I-SID VLAN delete Auto Attach mapping VLAN from BRIDGE\n\
413 get-aa-mapping BRIDGE get Auto Attach mappings from BRIDGE\n\
416 emer-reset reset switch to known good state\n\
422 --db=DATABASE connect to DATABASE\n\
424 --no-wait do not wait for ovs-vswitchd to reconfigure\n\
425 --retry keep trying to connect to server forever\n\
426 -t, --timeout=SECS wait at most SECS seconds for ovs-vswitchd\n\
427 --dry-run do not commit changes to database\n\
428 --oneline print exactly one line of output per command\n",
429 program_name
, program_name
, ctl_get_db_cmd_usage(),
430 ctl_list_db_tables_usage(), ctl_default_db());
434 --no-syslog equivalent to --verbose=vsctl:syslog:warn\n");
435 stream_usage("database", true, true, true);
438 -h, --help display this help message\n\
439 -V, --version display version information\n");
444 /* ovs-vsctl specific context. Inherits the 'struct ctl_context' as base. */
445 struct vsctl_context
{
446 struct ctl_context base
;
448 /* Modifiable state. */
449 const struct ovsrec_open_vswitch
*ovs
;
452 /* A cache of the contents of the database.
454 * A command that needs to use any of this information must first call
455 * vsctl_context_populate_cache(). A command that changes anything that
456 * could invalidate the cache must either call
457 * vsctl_context_invalidate_cache() or manually update the cache to
458 * maintain its correctness. */
460 struct shash bridges
; /* Maps from bridge name to struct vsctl_bridge. */
461 struct shash ports
; /* Maps from port name to struct vsctl_port. */
462 struct shash ifaces
; /* Maps from port name to struct vsctl_iface. */
465 struct vsctl_bridge
{
466 struct ovsrec_bridge
*br_cfg
;
468 struct ovs_list ports
; /* Contains "struct vsctl_port"s. */
470 /* VLAN ("fake") bridge support.
472 * Use 'parent != NULL' to detect a fake bridge, because 'vlan' can be 0
474 struct hmap children
; /* VLAN bridges indexed by 'vlan'. */
475 struct hmap_node children_node
; /* Node in parent's 'children' hmap. */
476 struct vsctl_bridge
*parent
; /* Real bridge, or NULL. */
477 int vlan
; /* VLAN VID (0...4095), or 0. */
481 struct ovs_list ports_node
; /* In struct vsctl_bridge's 'ports' list. */
482 struct ovs_list ifaces
; /* Contains "struct vsctl_iface"s. */
483 struct ovsrec_port
*port_cfg
;
484 struct vsctl_bridge
*bridge
;
488 struct ovs_list ifaces_node
; /* In struct vsctl_port's 'ifaces' list. */
489 struct ovsrec_interface
*iface_cfg
;
490 struct vsctl_port
*port
;
493 /* Casts 'base' into 'struct vsctl_context'. */
494 static struct vsctl_context
*
495 vsctl_context_cast(struct ctl_context
*base
)
497 return CONTAINER_OF(base
, struct vsctl_context
, base
);
500 static struct vsctl_bridge
*find_vlan_bridge(struct vsctl_bridge
*parent
,
504 vsctl_context_to_string(const struct ctl_context
*ctx
)
506 const struct shash_node
*node
;
512 SHASH_FOR_EACH (node
, &ctx
->options
) {
513 svec_add(&words
, node
->name
);
515 for (i
= 0; i
< ctx
->argc
; i
++) {
516 svec_add(&words
, ctx
->argv
[i
]);
518 svec_terminate(&words
);
520 s
= process_escape_args(words
.names
);
522 svec_destroy(&words
);
528 verify_ports(struct vsctl_context
*vsctl_ctx
)
530 if (!vsctl_ctx
->verified_ports
) {
531 const struct ovsrec_bridge
*bridge
;
532 const struct ovsrec_port
*port
;
534 ovsrec_open_vswitch_verify_bridges(vsctl_ctx
->ovs
);
535 OVSREC_BRIDGE_FOR_EACH (bridge
, vsctl_ctx
->base
.idl
) {
536 ovsrec_bridge_verify_ports(bridge
);
538 OVSREC_PORT_FOR_EACH (port
, vsctl_ctx
->base
.idl
) {
539 ovsrec_port_verify_interfaces(port
);
542 vsctl_ctx
->verified_ports
= true;
546 static struct vsctl_bridge
*
547 add_bridge_to_cache(struct vsctl_context
*vsctl_ctx
,
548 struct ovsrec_bridge
*br_cfg
, const char *name
,
549 struct vsctl_bridge
*parent
, int vlan
)
551 struct vsctl_bridge
*br
= xmalloc(sizeof *br
);
553 br
->name
= xstrdup(name
);
554 ovs_list_init(&br
->ports
);
557 hmap_init(&br
->children
);
559 struct vsctl_bridge
*conflict
= find_vlan_bridge(parent
, vlan
);
561 VLOG_WARN("%s: bridge has multiple VLAN bridges (%s and %s) "
562 "for VLAN %d, but only one is allowed",
563 parent
->name
, name
, conflict
->name
, vlan
);
565 hmap_insert(&parent
->children
, &br
->children_node
,
569 shash_add(&vsctl_ctx
->bridges
, br
->name
, br
);
574 ovs_delete_bridge(const struct ovsrec_open_vswitch
*ovs
,
575 struct ovsrec_bridge
*bridge
)
577 struct ovsrec_bridge
**bridges
;
580 bridges
= xmalloc(sizeof *ovs
->bridges
* ovs
->n_bridges
);
581 for (i
= n
= 0; i
< ovs
->n_bridges
; i
++) {
582 if (ovs
->bridges
[i
] != bridge
) {
583 bridges
[n
++] = ovs
->bridges
[i
];
586 ovsrec_open_vswitch_set_bridges(ovs
, bridges
, n
);
591 del_cached_bridge(struct vsctl_context
*vsctl_ctx
, struct vsctl_bridge
*br
)
593 ovs_assert(ovs_list_is_empty(&br
->ports
));
594 ovs_assert(hmap_is_empty(&br
->children
));
596 hmap_remove(&br
->parent
->children
, &br
->children_node
);
599 ovsrec_bridge_delete(br
->br_cfg
);
600 ovs_delete_bridge(vsctl_ctx
->ovs
, br
->br_cfg
);
602 shash_find_and_delete(&vsctl_ctx
->bridges
, br
->name
);
603 hmap_destroy(&br
->children
);
609 port_is_fake_bridge(const struct ovsrec_port
*port_cfg
)
611 return (port_cfg
->fake_bridge
613 && *port_cfg
->tag
>= 0 && *port_cfg
->tag
<= 4095);
616 static struct vsctl_bridge
*
617 find_vlan_bridge(struct vsctl_bridge
*parent
, int vlan
)
619 struct vsctl_bridge
*child
;
621 HMAP_FOR_EACH_IN_BUCKET (child
, children_node
, hash_int(vlan
, 0),
623 if (child
->vlan
== vlan
) {
631 static struct vsctl_port
*
632 add_port_to_cache(struct vsctl_context
*vsctl_ctx
, struct vsctl_bridge
*parent
,
633 struct ovsrec_port
*port_cfg
)
635 struct vsctl_port
*port
;
638 && *port_cfg
->tag
>= 0 && *port_cfg
->tag
<= 4095) {
639 struct vsctl_bridge
*vlan_bridge
;
641 vlan_bridge
= find_vlan_bridge(parent
, *port_cfg
->tag
);
643 parent
= vlan_bridge
;
647 port
= xmalloc(sizeof *port
);
648 ovs_list_push_back(&parent
->ports
, &port
->ports_node
);
649 ovs_list_init(&port
->ifaces
);
650 port
->port_cfg
= port_cfg
;
651 port
->bridge
= parent
;
652 shash_add(&vsctl_ctx
->ports
, port_cfg
->name
, port
);
658 del_cached_port(struct vsctl_context
*vsctl_ctx
, struct vsctl_port
*port
)
660 ovs_assert(ovs_list_is_empty(&port
->ifaces
));
661 ovs_list_remove(&port
->ports_node
);
662 shash_find_and_delete(&vsctl_ctx
->ports
, port
->port_cfg
->name
);
663 ovsrec_port_delete(port
->port_cfg
);
667 static struct vsctl_iface
*
668 add_iface_to_cache(struct vsctl_context
*vsctl_ctx
, struct vsctl_port
*parent
,
669 struct ovsrec_interface
*iface_cfg
)
671 struct vsctl_iface
*iface
;
673 iface
= xmalloc(sizeof *iface
);
674 ovs_list_push_back(&parent
->ifaces
, &iface
->ifaces_node
);
675 iface
->iface_cfg
= iface_cfg
;
676 iface
->port
= parent
;
677 shash_add(&vsctl_ctx
->ifaces
, iface_cfg
->name
, iface
);
683 del_cached_iface(struct vsctl_context
*vsctl_ctx
, struct vsctl_iface
*iface
)
685 ovs_list_remove(&iface
->ifaces_node
);
686 shash_find_and_delete(&vsctl_ctx
->ifaces
, iface
->iface_cfg
->name
);
687 ovsrec_interface_delete(iface
->iface_cfg
);
692 vsctl_context_invalidate_cache(struct ctl_context
*ctx
)
694 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
695 struct shash_node
*node
;
697 if (!vsctl_ctx
->cache_valid
) {
700 vsctl_ctx
->cache_valid
= false;
702 SHASH_FOR_EACH (node
, &vsctl_ctx
->bridges
) {
703 struct vsctl_bridge
*bridge
= node
->data
;
704 hmap_destroy(&bridge
->children
);
708 shash_destroy(&vsctl_ctx
->bridges
);
710 shash_destroy_free_data(&vsctl_ctx
->ports
);
711 shash_destroy_free_data(&vsctl_ctx
->ifaces
);
715 pre_get_info(struct ctl_context
*ctx
)
717 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_open_vswitch_col_bridges
);
719 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_name
);
720 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_controller
);
721 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_fail_mode
);
722 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_ports
);
724 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_port_col_name
);
725 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_port_col_fake_bridge
);
726 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_port_col_tag
);
727 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_port_col_interfaces
);
729 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_interface_col_name
);
731 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_interface_col_ofport
);
732 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_interface_col_error
);
736 vsctl_context_populate_cache(struct ctl_context
*ctx
)
738 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
739 const struct ovsrec_open_vswitch
*ovs
= vsctl_ctx
->ovs
;
740 struct sset bridges
, ports
;
743 if (vsctl_ctx
->cache_valid
) {
744 /* Cache is already populated. */
747 vsctl_ctx
->cache_valid
= true;
748 shash_init(&vsctl_ctx
->bridges
);
749 shash_init(&vsctl_ctx
->ports
);
750 shash_init(&vsctl_ctx
->ifaces
);
754 for (i
= 0; i
< ovs
->n_bridges
; i
++) {
755 struct ovsrec_bridge
*br_cfg
= ovs
->bridges
[i
];
756 struct vsctl_bridge
*br
;
759 if (!sset_add(&bridges
, br_cfg
->name
)) {
760 VLOG_WARN("%s: database contains duplicate bridge name",
764 br
= add_bridge_to_cache(vsctl_ctx
, br_cfg
, br_cfg
->name
, NULL
, 0);
766 for (j
= 0; j
< br_cfg
->n_ports
; j
++) {
767 struct ovsrec_port
*port_cfg
= br_cfg
->ports
[j
];
769 if (!sset_add(&ports
, port_cfg
->name
)) {
770 /* Duplicate port name. (We will warn about that later.) */
774 if (port_is_fake_bridge(port_cfg
)
775 && sset_add(&bridges
, port_cfg
->name
)) {
776 add_bridge_to_cache(vsctl_ctx
, NULL
, port_cfg
->name
, br
,
781 sset_destroy(&bridges
);
782 sset_destroy(&ports
);
785 for (i
= 0; i
< ovs
->n_bridges
; i
++) {
786 struct ovsrec_bridge
*br_cfg
= ovs
->bridges
[i
];
787 struct vsctl_bridge
*br
;
790 if (!sset_add(&bridges
, br_cfg
->name
)) {
793 br
= shash_find_data(&vsctl_ctx
->bridges
, br_cfg
->name
);
794 for (j
= 0; j
< br_cfg
->n_ports
; j
++) {
795 struct ovsrec_port
*port_cfg
= br_cfg
->ports
[j
];
796 struct vsctl_port
*port
;
799 port
= shash_find_data(&vsctl_ctx
->ports
, port_cfg
->name
);
801 if (port_cfg
== port
->port_cfg
) {
802 VLOG_WARN("%s: port is in multiple bridges (%s and %s)",
803 port_cfg
->name
, br
->name
, port
->bridge
->name
);
805 /* Log as an error because this violates the database's
806 * uniqueness constraints, so the database server shouldn't
807 * have allowed it. */
808 VLOG_ERR("%s: database contains duplicate port name",
814 if (port_is_fake_bridge(port_cfg
)
815 && !sset_add(&bridges
, port_cfg
->name
)) {
819 port
= add_port_to_cache(vsctl_ctx
, br
, port_cfg
);
820 for (k
= 0; k
< port_cfg
->n_interfaces
; k
++) {
821 struct ovsrec_interface
*iface_cfg
= port_cfg
->interfaces
[k
];
822 struct vsctl_iface
*iface
;
824 iface
= shash_find_data(&vsctl_ctx
->ifaces
, iface_cfg
->name
);
826 if (iface_cfg
== iface
->iface_cfg
) {
827 VLOG_WARN("%s: interface is in multiple ports "
830 iface
->port
->port_cfg
->name
,
831 port
->port_cfg
->name
);
833 /* Log as an error because this violates the database's
834 * uniqueness constraints, so the database server
835 * shouldn't have allowed it. */
836 VLOG_ERR("%s: database contains duplicate interface "
837 "name", iface_cfg
->name
);
842 add_iface_to_cache(vsctl_ctx
, port
, iface_cfg
);
846 sset_destroy(&bridges
);
850 check_conflicts(struct vsctl_context
*vsctl_ctx
, const char *name
,
853 struct vsctl_iface
*iface
;
854 struct vsctl_port
*port
;
856 verify_ports(vsctl_ctx
);
858 if (shash_find(&vsctl_ctx
->bridges
, name
)) {
859 ctl_fatal("%s because a bridge named %s already exists",
863 port
= shash_find_data(&vsctl_ctx
->ports
, name
);
865 ctl_fatal("%s because a port named %s already exists on "
866 "bridge %s", msg
, name
, port
->bridge
->name
);
869 iface
= shash_find_data(&vsctl_ctx
->ifaces
, name
);
871 ctl_fatal("%s because an interface named %s already exists "
872 "on bridge %s", msg
, name
, iface
->port
->bridge
->name
);
878 static struct vsctl_bridge
*
879 find_bridge(struct vsctl_context
*vsctl_ctx
, const char *name
, bool must_exist
)
881 struct vsctl_bridge
*br
;
883 ovs_assert(vsctl_ctx
->cache_valid
);
885 br
= shash_find_data(&vsctl_ctx
->bridges
, name
);
886 if (must_exist
&& !br
) {
887 ctl_fatal("no bridge named %s", name
);
889 ovsrec_open_vswitch_verify_bridges(vsctl_ctx
->ovs
);
893 static struct vsctl_bridge
*
894 find_real_bridge(struct vsctl_context
*vsctl_ctx
,
895 const char *name
, bool must_exist
)
897 struct vsctl_bridge
*br
= find_bridge(vsctl_ctx
, name
, must_exist
);
898 if (br
&& br
->parent
) {
899 ctl_fatal("%s is a fake bridge", name
);
904 static struct vsctl_port
*
905 find_port(struct vsctl_context
*vsctl_ctx
, const char *name
, bool must_exist
)
907 struct vsctl_port
*port
;
909 ovs_assert(vsctl_ctx
->cache_valid
);
911 port
= shash_find_data(&vsctl_ctx
->ports
, name
);
912 if (port
&& !strcmp(name
, port
->bridge
->name
)) {
915 if (must_exist
&& !port
) {
916 ctl_fatal("no port named %s", name
);
918 verify_ports(vsctl_ctx
);
922 static struct vsctl_iface
*
923 find_iface(struct vsctl_context
*vsctl_ctx
, const char *name
, bool must_exist
)
925 struct vsctl_iface
*iface
;
927 ovs_assert(vsctl_ctx
->cache_valid
);
929 iface
= shash_find_data(&vsctl_ctx
->ifaces
, name
);
930 if (iface
&& !strcmp(name
, iface
->port
->bridge
->name
)) {
933 if (must_exist
&& !iface
) {
934 ctl_fatal("no interface named %s", name
);
936 verify_ports(vsctl_ctx
);
941 bridge_insert_port(struct ovsrec_bridge
*br
, struct ovsrec_port
*port
)
943 struct ovsrec_port
**ports
;
946 ports
= xmalloc(sizeof *br
->ports
* (br
->n_ports
+ 1));
947 for (i
= 0; i
< br
->n_ports
; i
++) {
948 ports
[i
] = br
->ports
[i
];
950 ports
[br
->n_ports
] = port
;
951 ovsrec_bridge_set_ports(br
, ports
, br
->n_ports
+ 1);
956 bridge_delete_port(struct ovsrec_bridge
*br
, struct ovsrec_port
*port
)
958 struct ovsrec_port
**ports
;
961 ports
= xmalloc(sizeof *br
->ports
* br
->n_ports
);
962 for (i
= n
= 0; i
< br
->n_ports
; i
++) {
963 if (br
->ports
[i
] != port
) {
964 ports
[n
++] = br
->ports
[i
];
967 ovsrec_bridge_set_ports(br
, ports
, n
);
972 ovs_insert_bridge(const struct ovsrec_open_vswitch
*ovs
,
973 struct ovsrec_bridge
*bridge
)
975 struct ovsrec_bridge
**bridges
;
978 bridges
= xmalloc(sizeof *ovs
->bridges
* (ovs
->n_bridges
+ 1));
979 for (i
= 0; i
< ovs
->n_bridges
; i
++) {
980 bridges
[i
] = ovs
->bridges
[i
];
982 bridges
[ovs
->n_bridges
] = bridge
;
983 ovsrec_open_vswitch_set_bridges(ovs
, bridges
, ovs
->n_bridges
+ 1);
988 cmd_init(struct ctl_context
*ctx OVS_UNUSED
)
992 static struct cmd_show_table cmd_show_tables
[] = {
993 {&ovsrec_table_open_vswitch
,
995 {&ovsrec_open_vswitch_col_manager_options
,
996 &ovsrec_open_vswitch_col_bridges
,
997 &ovsrec_open_vswitch_col_ovs_version
},
1001 {&ovsrec_table_bridge
,
1002 &ovsrec_bridge_col_name
,
1003 {&ovsrec_bridge_col_controller
,
1004 &ovsrec_bridge_col_fail_mode
,
1005 &ovsrec_bridge_col_ports
},
1009 {&ovsrec_table_port
,
1010 &ovsrec_port_col_name
,
1011 {&ovsrec_port_col_tag
,
1012 &ovsrec_port_col_trunks
,
1013 &ovsrec_port_col_interfaces
},
1017 {&ovsrec_table_interface
,
1018 &ovsrec_interface_col_name
,
1019 {&ovsrec_interface_col_type
,
1020 &ovsrec_interface_col_options
,
1021 &ovsrec_interface_col_error
,
1022 &ovsrec_interface_col_bfd_status
},
1026 {&ovsrec_table_controller
,
1027 &ovsrec_controller_col_target
,
1028 {&ovsrec_controller_col_is_connected
,
1034 {&ovsrec_table_manager
,
1035 &ovsrec_manager_col_target
,
1036 {&ovsrec_manager_col_is_connected
,
1042 {NULL
, NULL
, {NULL
, NULL
, NULL
}, {NULL
, NULL
, NULL
}}
1046 pre_cmd_emer_reset(struct ctl_context
*ctx
)
1048 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_open_vswitch_col_manager_options
);
1049 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_open_vswitch_col_ssl
);
1051 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_controller
);
1052 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_fail_mode
);
1053 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_mirrors
);
1054 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_netflow
);
1055 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_sflow
);
1056 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_ipfix
);
1057 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_flood_vlans
);
1058 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_other_config
);
1060 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_port_col_other_config
);
1062 ovsdb_idl_add_column(ctx
->idl
,
1063 &ovsrec_interface_col_ingress_policing_rate
);
1064 ovsdb_idl_add_column(ctx
->idl
,
1065 &ovsrec_interface_col_ingress_policing_burst
);
1069 cmd_emer_reset(struct ctl_context
*ctx
)
1071 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1072 const struct ovsdb_idl
*idl
= ctx
->idl
;
1073 const struct ovsrec_bridge
*br
;
1074 const struct ovsrec_port
*port
;
1075 const struct ovsrec_interface
*iface
;
1076 const struct ovsrec_mirror
*mirror
, *next_mirror
;
1077 const struct ovsrec_controller
*ctrl
, *next_ctrl
;
1078 const struct ovsrec_manager
*mgr
, *next_mgr
;
1079 const struct ovsrec_netflow
*nf
, *next_nf
;
1080 const struct ovsrec_ssl
*ssl
, *next_ssl
;
1081 const struct ovsrec_sflow
*sflow
, *next_sflow
;
1082 const struct ovsrec_ipfix
*ipfix
, *next_ipfix
;
1083 const struct ovsrec_flow_sample_collector_set
*fscset
, *next_fscset
;
1085 /* Reset the Open_vSwitch table. */
1086 ovsrec_open_vswitch_set_manager_options(vsctl_ctx
->ovs
, NULL
, 0);
1087 ovsrec_open_vswitch_set_ssl(vsctl_ctx
->ovs
, NULL
);
1089 OVSREC_BRIDGE_FOR_EACH (br
, idl
) {
1092 ovsrec_bridge_set_controller(br
, NULL
, 0);
1093 ovsrec_bridge_set_fail_mode(br
, NULL
);
1094 ovsrec_bridge_set_mirrors(br
, NULL
, 0);
1095 ovsrec_bridge_set_netflow(br
, NULL
);
1096 ovsrec_bridge_set_sflow(br
, NULL
);
1097 ovsrec_bridge_set_ipfix(br
, NULL
);
1098 ovsrec_bridge_set_flood_vlans(br
, NULL
, 0);
1100 /* We only want to save the "hwaddr" key from other_config. */
1101 hwaddr
= smap_get(&br
->other_config
, "hwaddr");
1103 const struct smap smap
= SMAP_CONST1(&smap
, "hwaddr", hwaddr
);
1104 ovsrec_bridge_set_other_config(br
, &smap
);
1106 ovsrec_bridge_set_other_config(br
, NULL
);
1110 OVSREC_PORT_FOR_EACH (port
, idl
) {
1111 ovsrec_port_set_other_config(port
, NULL
);
1114 OVSREC_INTERFACE_FOR_EACH (iface
, idl
) {
1115 /* xxx What do we do about gre/patch devices created by mgr? */
1117 ovsrec_interface_set_ingress_policing_rate(iface
, 0);
1118 ovsrec_interface_set_ingress_policing_burst(iface
, 0);
1121 OVSREC_MIRROR_FOR_EACH_SAFE (mirror
, next_mirror
, idl
) {
1122 ovsrec_mirror_delete(mirror
);
1125 OVSREC_CONTROLLER_FOR_EACH_SAFE (ctrl
, next_ctrl
, idl
) {
1126 ovsrec_controller_delete(ctrl
);
1129 OVSREC_MANAGER_FOR_EACH_SAFE (mgr
, next_mgr
, idl
) {
1130 ovsrec_manager_delete(mgr
);
1133 OVSREC_NETFLOW_FOR_EACH_SAFE (nf
, next_nf
, idl
) {
1134 ovsrec_netflow_delete(nf
);
1137 OVSREC_SSL_FOR_EACH_SAFE (ssl
, next_ssl
, idl
) {
1138 ovsrec_ssl_delete(ssl
);
1141 OVSREC_SFLOW_FOR_EACH_SAFE (sflow
, next_sflow
, idl
) {
1142 ovsrec_sflow_delete(sflow
);
1145 OVSREC_IPFIX_FOR_EACH_SAFE (ipfix
, next_ipfix
, idl
) {
1146 ovsrec_ipfix_delete(ipfix
);
1149 OVSREC_FLOW_SAMPLE_COLLECTOR_SET_FOR_EACH_SAFE (fscset
, next_fscset
, idl
) {
1150 ovsrec_flow_sample_collector_set_delete(fscset
);
1153 vsctl_context_invalidate_cache(ctx
);
1157 cmd_add_br(struct ctl_context
*ctx
)
1159 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1160 bool may_exist
= shash_find(&ctx
->options
, "--may-exist") != NULL
;
1161 const char *br_name
, *parent_name
;
1162 struct ovsrec_interface
*iface
;
1165 br_name
= ctx
->argv
[1];
1167 ctl_fatal("bridge name must not be empty string");
1169 if (ctx
->argc
== 2) {
1172 } else if (ctx
->argc
== 4) {
1173 parent_name
= ctx
->argv
[2];
1174 vlan
= atoi(ctx
->argv
[3]);
1175 if (vlan
< 0 || vlan
> 4095) {
1176 ctl_fatal("%s: vlan must be between 0 and 4095", ctx
->argv
[0]);
1179 ctl_fatal("'%s' command takes exactly 1 or 3 arguments",
1183 vsctl_context_populate_cache(ctx
);
1185 struct vsctl_bridge
*br
;
1187 br
= find_bridge(vsctl_ctx
, br_name
, false);
1191 ctl_fatal("\"--may-exist add-br %s\" but %s is "
1192 "a VLAN bridge for VLAN %d",
1193 br_name
, br_name
, br
->vlan
);
1197 ctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
1198 "is not a VLAN bridge",
1199 br_name
, parent_name
, vlan
, br_name
);
1200 } else if (strcmp(br
->parent
->name
, parent_name
)) {
1201 ctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
1202 "has the wrong parent %s",
1203 br_name
, parent_name
, vlan
,
1204 br_name
, br
->parent
->name
);
1205 } else if (br
->vlan
!= vlan
) {
1206 ctl_fatal("\"--may-exist add-br %s %s %d\" but %s "
1207 "is a VLAN bridge for the wrong VLAN %d",
1208 br_name
, parent_name
, vlan
, br_name
, br
->vlan
);
1214 check_conflicts(vsctl_ctx
, br_name
,
1215 xasprintf("cannot create a bridge named %s", br_name
));
1218 struct ovsrec_port
*port
;
1219 struct ovsrec_bridge
*br
;
1221 iface
= ovsrec_interface_insert(ctx
->txn
);
1222 ovsrec_interface_set_name(iface
, br_name
);
1223 ovsrec_interface_set_type(iface
, "internal");
1225 port
= ovsrec_port_insert(ctx
->txn
);
1226 ovsrec_port_set_name(port
, br_name
);
1227 ovsrec_port_set_interfaces(port
, &iface
, 1);
1229 br
= ovsrec_bridge_insert(ctx
->txn
);
1230 ovsrec_bridge_set_name(br
, br_name
);
1231 ovsrec_bridge_set_ports(br
, &port
, 1);
1233 ovs_insert_bridge(vsctl_ctx
->ovs
, br
);
1235 struct vsctl_bridge
*conflict
;
1236 struct vsctl_bridge
*parent
;
1237 struct ovsrec_port
*port
;
1238 struct ovsrec_bridge
*br
;
1241 parent
= find_bridge(vsctl_ctx
, parent_name
, false);
1242 if (parent
&& parent
->parent
) {
1243 ctl_fatal("cannot create bridge with fake bridge as parent");
1246 ctl_fatal("parent bridge %s does not exist", parent_name
);
1248 conflict
= find_vlan_bridge(parent
, vlan
);
1250 ctl_fatal("bridge %s already has a child VLAN bridge %s "
1251 "on VLAN %d", parent_name
, conflict
->name
, vlan
);
1253 br
= parent
->br_cfg
;
1255 iface
= ovsrec_interface_insert(ctx
->txn
);
1256 ovsrec_interface_set_name(iface
, br_name
);
1257 ovsrec_interface_set_type(iface
, "internal");
1259 port
= ovsrec_port_insert(ctx
->txn
);
1260 ovsrec_port_set_name(port
, br_name
);
1261 ovsrec_port_set_interfaces(port
, &iface
, 1);
1262 ovsrec_port_set_fake_bridge(port
, true);
1263 ovsrec_port_set_tag(port
, &tag
, 1);
1265 bridge_insert_port(br
, port
);
1268 post_db_reload_expect_iface(iface
);
1269 vsctl_context_invalidate_cache(ctx
);
1273 del_port(struct vsctl_context
*vsctl_ctx
, struct vsctl_port
*port
)
1275 struct vsctl_iface
*iface
, *next_iface
;
1277 bridge_delete_port((port
->bridge
->parent
1278 ? port
->bridge
->parent
->br_cfg
1279 : port
->bridge
->br_cfg
), port
->port_cfg
);
1281 LIST_FOR_EACH_SAFE (iface
, next_iface
, ifaces_node
, &port
->ifaces
) {
1282 del_cached_iface(vsctl_ctx
, iface
);
1284 del_cached_port(vsctl_ctx
, port
);
1288 del_bridge(struct vsctl_context
*vsctl_ctx
, struct vsctl_bridge
*br
)
1290 struct vsctl_bridge
*child
, *next_child
;
1291 struct vsctl_port
*port
, *next_port
;
1292 const struct ovsrec_flow_sample_collector_set
*fscset
, *next_fscset
;
1294 HMAP_FOR_EACH_SAFE (child
, next_child
, children_node
, &br
->children
) {
1295 del_bridge(vsctl_ctx
, child
);
1298 LIST_FOR_EACH_SAFE (port
, next_port
, ports_node
, &br
->ports
) {
1299 del_port(vsctl_ctx
, port
);
1302 OVSREC_FLOW_SAMPLE_COLLECTOR_SET_FOR_EACH_SAFE (fscset
, next_fscset
,
1303 vsctl_ctx
->base
.idl
) {
1304 if (fscset
->bridge
== br
->br_cfg
) {
1305 ovsrec_flow_sample_collector_set_delete(fscset
);
1309 del_cached_bridge(vsctl_ctx
, br
);
1313 cmd_del_br(struct ctl_context
*ctx
)
1315 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1316 bool must_exist
= !shash_find(&ctx
->options
, "--if-exists");
1317 struct vsctl_bridge
*bridge
;
1319 vsctl_context_populate_cache(ctx
);
1320 bridge
= find_bridge(vsctl_ctx
, ctx
->argv
[1], must_exist
);
1322 del_bridge(vsctl_ctx
, bridge
);
1327 output_sorted(struct svec
*svec
, struct ds
*output
)
1333 SVEC_FOR_EACH (i
, name
, svec
) {
1334 ds_put_format(output
, "%s\n", name
);
1339 cmd_list_br(struct ctl_context
*ctx
)
1341 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1342 struct shash_node
*node
;
1343 struct svec bridges
;
1344 bool real
= shash_find(&ctx
->options
, "--real");
1345 bool fake
= shash_find(&ctx
->options
, "--fake");
1347 /* If neither fake nor real were requested, return both. */
1348 if (!real
&& !fake
) {
1352 vsctl_context_populate_cache(ctx
);
1354 svec_init(&bridges
);
1355 SHASH_FOR_EACH (node
, &vsctl_ctx
->bridges
) {
1356 struct vsctl_bridge
*br
= node
->data
;
1358 if (br
->parent
? fake
: real
) {
1359 svec_add(&bridges
, br
->name
);
1362 output_sorted(&bridges
, &ctx
->output
);
1363 svec_destroy(&bridges
);
1367 cmd_br_exists(struct ctl_context
*ctx
)
1369 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1371 vsctl_context_populate_cache(ctx
);
1372 if (!find_bridge(vsctl_ctx
, ctx
->argv
[1], false)) {
1378 set_external_id(struct smap
*old
, struct smap
*new,
1379 char *key
, char *value
)
1381 smap_clone(new, old
);
1384 smap_replace(new, key
, value
);
1386 smap_remove(new, key
);
1391 pre_cmd_br_set_external_id(struct ctl_context
*ctx
)
1394 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_external_ids
);
1395 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_port_col_external_ids
);
1399 cmd_br_set_external_id(struct ctl_context
*ctx
)
1401 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1402 struct vsctl_bridge
*bridge
;
1405 vsctl_context_populate_cache(ctx
);
1406 bridge
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1407 if (bridge
->br_cfg
) {
1409 set_external_id(&bridge
->br_cfg
->external_ids
, &new, ctx
->argv
[2],
1410 ctx
->argc
>= 4 ? ctx
->argv
[3] : NULL
);
1411 ovsrec_bridge_verify_external_ids(bridge
->br_cfg
);
1412 ovsrec_bridge_set_external_ids(bridge
->br_cfg
, &new);
1414 char *key
= xasprintf("fake-bridge-%s", ctx
->argv
[2]);
1415 struct vsctl_port
*port
= shash_find_data(&vsctl_ctx
->ports
,
1417 set_external_id(&port
->port_cfg
->external_ids
, &new,
1418 key
, ctx
->argc
>= 4 ? ctx
->argv
[3] : NULL
);
1419 ovsrec_port_verify_external_ids(port
->port_cfg
);
1420 ovsrec_port_set_external_ids(port
->port_cfg
, &new);
1427 get_external_id(struct smap
*smap
, const char *prefix
, const char *key
,
1431 char *prefix_key
= xasprintf("%s%s", prefix
, key
);
1432 const char *value
= smap_get(smap
, prefix_key
);
1435 ds_put_format(output
, "%s\n", value
);
1439 const struct smap_node
**sorted
= smap_sort(smap
);
1440 size_t prefix_len
= strlen(prefix
);
1443 for (i
= 0; i
< smap_count(smap
); i
++) {
1444 const struct smap_node
*node
= sorted
[i
];
1445 if (!strncmp(node
->key
, prefix
, prefix_len
)) {
1446 ds_put_format(output
, "%s=%s\n", node
->key
+ prefix_len
,
1455 pre_cmd_br_get_external_id(struct ctl_context
*ctx
)
1457 pre_cmd_br_set_external_id(ctx
);
1461 cmd_br_get_external_id(struct ctl_context
*ctx
)
1463 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1464 struct vsctl_bridge
*bridge
;
1466 vsctl_context_populate_cache(ctx
);
1468 bridge
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1469 if (bridge
->br_cfg
) {
1470 ovsrec_bridge_verify_external_ids(bridge
->br_cfg
);
1471 get_external_id(&bridge
->br_cfg
->external_ids
, "",
1472 ctx
->argc
>= 3 ? ctx
->argv
[2] : NULL
, &ctx
->output
);
1474 struct vsctl_port
*port
= shash_find_data(&vsctl_ctx
->ports
,
1476 ovsrec_port_verify_external_ids(port
->port_cfg
);
1477 get_external_id(&port
->port_cfg
->external_ids
, "fake-bridge-",
1478 ctx
->argc
>= 3 ? ctx
->argv
[2] : NULL
, &ctx
->output
);
1483 cmd_list_ports(struct ctl_context
*ctx
)
1485 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1486 struct vsctl_bridge
*br
;
1487 struct vsctl_port
*port
;
1490 vsctl_context_populate_cache(ctx
);
1491 br
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1492 ovsrec_bridge_verify_ports(br
->br_cfg
? br
->br_cfg
: br
->parent
->br_cfg
);
1495 LIST_FOR_EACH (port
, ports_node
, &br
->ports
) {
1496 if (strcmp(port
->port_cfg
->name
, br
->name
)) {
1497 svec_add(&ports
, port
->port_cfg
->name
);
1500 output_sorted(&ports
, &ctx
->output
);
1501 svec_destroy(&ports
);
1505 add_port(struct ctl_context
*ctx
,
1506 const char *br_name
, const char *port_name
,
1507 bool may_exist
, bool fake_iface
,
1508 char *iface_names
[], int n_ifaces
,
1509 char *settings
[], int n_settings
)
1511 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1512 struct vsctl_bridge
*bridge
;
1513 struct ovsrec_interface
**ifaces
;
1514 struct ovsrec_port
*port
;
1517 if (!port_name
[0]) {
1518 ctl_fatal("port name must not be empty string");
1520 for (i
= 0; i
< n_ifaces
; i
++) {
1521 if (!iface_names
[i
][0]) {
1522 ctl_fatal("interface name must not be empty string");
1526 vsctl_context_populate_cache(ctx
);
1528 struct vsctl_port
*vsctl_port
;
1530 vsctl_port
= find_port(vsctl_ctx
, port_name
, false);
1532 struct svec want_names
, have_names
;
1534 svec_init(&want_names
);
1535 for (i
= 0; i
< n_ifaces
; i
++) {
1536 svec_add(&want_names
, iface_names
[i
]);
1538 svec_sort(&want_names
);
1540 svec_init(&have_names
);
1541 for (i
= 0; i
< vsctl_port
->port_cfg
->n_interfaces
; i
++) {
1542 svec_add(&have_names
,
1543 vsctl_port
->port_cfg
->interfaces
[i
]->name
);
1545 svec_sort(&have_names
);
1547 if (strcmp(vsctl_port
->bridge
->name
, br_name
)) {
1548 char *command
= vsctl_context_to_string(ctx
);
1549 ctl_fatal("\"%s\" but %s is actually attached to bridge %s",
1550 command
, port_name
, vsctl_port
->bridge
->name
);
1553 if (!svec_equal(&want_names
, &have_names
)) {
1554 char *have_names_string
= svec_join(&have_names
, ", ", "");
1555 char *command
= vsctl_context_to_string(ctx
);
1557 ctl_fatal("\"%s\" but %s actually has interface(s) %s",
1558 command
, port_name
, have_names_string
);
1561 svec_destroy(&want_names
);
1562 svec_destroy(&have_names
);
1567 check_conflicts(vsctl_ctx
, port_name
,
1568 xasprintf("cannot create a port named %s", port_name
));
1569 for (i
= 0; i
< n_ifaces
; i
++) {
1570 check_conflicts(vsctl_ctx
, iface_names
[i
],
1571 xasprintf("cannot create an interface named %s",
1574 bridge
= find_bridge(vsctl_ctx
, br_name
, true);
1576 ifaces
= xmalloc(n_ifaces
* sizeof *ifaces
);
1577 for (i
= 0; i
< n_ifaces
; i
++) {
1578 ifaces
[i
] = ovsrec_interface_insert(ctx
->txn
);
1579 ovsrec_interface_set_name(ifaces
[i
], iface_names
[i
]);
1580 post_db_reload_expect_iface(ifaces
[i
]);
1583 port
= ovsrec_port_insert(ctx
->txn
);
1584 ovsrec_port_set_name(port
, port_name
);
1585 ovsrec_port_set_interfaces(port
, ifaces
, n_ifaces
);
1586 ovsrec_port_set_bond_fake_iface(port
, fake_iface
);
1588 if (bridge
->parent
) {
1589 int64_t tag
= bridge
->vlan
;
1590 ovsrec_port_set_tag(port
, &tag
, 1);
1593 for (i
= 0; i
< n_settings
; i
++) {
1594 ctl_set_column("Port", &port
->header_
, settings
[i
],
1598 bridge_insert_port((bridge
->parent
? bridge
->parent
->br_cfg
1599 : bridge
->br_cfg
), port
);
1601 struct vsctl_port
*vsctl_port
= add_port_to_cache(vsctl_ctx
, bridge
, port
);
1602 for (i
= 0; i
< n_ifaces
; i
++) {
1603 add_iface_to_cache(vsctl_ctx
, vsctl_port
, ifaces
[i
]);
1609 cmd_add_port(struct ctl_context
*ctx
)
1611 bool may_exist
= shash_find(&ctx
->options
, "--may-exist") != NULL
;
1613 add_port(ctx
, ctx
->argv
[1], ctx
->argv
[2], may_exist
, false,
1614 &ctx
->argv
[2], 1, &ctx
->argv
[3], ctx
->argc
- 3);
1618 cmd_add_bond(struct ctl_context
*ctx
)
1620 bool may_exist
= shash_find(&ctx
->options
, "--may-exist") != NULL
;
1621 bool fake_iface
= shash_find(&ctx
->options
, "--fake-iface");
1625 n_ifaces
= ctx
->argc
- 3;
1626 for (i
= 3; i
< ctx
->argc
; i
++) {
1627 if (strchr(ctx
->argv
[i
], '=')) {
1633 ctl_fatal("add-bond requires at least 2 interfaces, but only "
1634 "%d were specified", n_ifaces
);
1637 add_port(ctx
, ctx
->argv
[1], ctx
->argv
[2], may_exist
, fake_iface
,
1638 &ctx
->argv
[3], n_ifaces
,
1639 &ctx
->argv
[n_ifaces
+ 3], ctx
->argc
- 3 - n_ifaces
);
1643 cmd_add_bond_iface(struct ctl_context
*ctx
)
1645 vsctl_context_populate_cache(ctx
);
1647 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1648 bool may_exist
= shash_find(&ctx
->options
, "--may-exist") != NULL
;
1649 struct vsctl_port
*port
= find_port(vsctl_ctx
, ctx
->argv
[1], true);
1651 const char *iface_name
= ctx
->argv
[2];
1653 struct vsctl_iface
*iface
= find_iface(vsctl_ctx
, iface_name
, false);
1655 if (iface
->port
== port
) {
1658 char *command
= vsctl_context_to_string(ctx
);
1659 ctl_fatal("\"%s\" but %s is actually attached to port %s",
1660 command
, iface_name
, iface
->port
->port_cfg
->name
);
1663 check_conflicts(vsctl_ctx
, iface_name
,
1664 xasprintf("cannot create an interface named %s",
1667 struct ovsrec_interface
*iface
= ovsrec_interface_insert(ctx
->txn
);
1668 ovsrec_interface_set_name(iface
, iface_name
);
1669 ovsrec_port_update_interfaces_addvalue(port
->port_cfg
, iface
);
1670 post_db_reload_expect_iface(iface
);
1671 add_iface_to_cache(vsctl_ctx
, port
, iface
);
1675 cmd_del_bond_iface(struct ctl_context
*ctx
)
1677 vsctl_context_populate_cache(ctx
);
1679 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1680 const char *iface_name
= ctx
->argv
[ctx
->argc
- 1];
1681 bool must_exist
= !shash_find(&ctx
->options
, "--if-exists");
1682 struct vsctl_iface
*iface
= find_iface(vsctl_ctx
, iface_name
, must_exist
);
1684 ovs_assert(!must_exist
);
1688 const char *port_name
= ctx
->argc
> 2 ? ctx
->argv
[1] : NULL
;
1690 struct vsctl_port
*port
= find_port(vsctl_ctx
, port_name
, true);
1691 if (iface
->port
!= port
) {
1692 ctl_fatal("port %s does not have an interface %s",
1693 port_name
, iface_name
);
1697 if (ovs_list_is_short(&iface
->port
->ifaces
)) {
1698 ctl_fatal("cannot delete last interface from port %s",
1699 iface
->port
->port_cfg
->name
);
1702 ovsrec_port_update_interfaces_delvalue(iface
->port
->port_cfg
,
1704 del_cached_iface(vsctl_ctx
, iface
);
1708 cmd_del_port(struct ctl_context
*ctx
)
1710 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1711 bool must_exist
= !shash_find(&ctx
->options
, "--if-exists");
1712 bool with_iface
= shash_find(&ctx
->options
, "--with-iface") != NULL
;
1713 const char *target
= ctx
->argv
[ctx
->argc
- 1];
1714 struct vsctl_port
*port
;
1716 vsctl_context_populate_cache(ctx
);
1717 if (find_bridge(vsctl_ctx
, target
, false)) {
1719 ctl_fatal("cannot delete port %s because it is the local port "
1720 "for bridge %s (deleting this port requires deleting "
1721 "the entire bridge)", target
, target
);
1724 } else if (!with_iface
) {
1725 port
= find_port(vsctl_ctx
, target
, must_exist
);
1727 struct vsctl_iface
*iface
;
1729 port
= find_port(vsctl_ctx
, target
, false);
1731 iface
= find_iface(vsctl_ctx
, target
, false);
1736 if (must_exist
&& !port
) {
1737 ctl_fatal("no port or interface named %s", target
);
1742 if (ctx
->argc
== 3) {
1743 struct vsctl_bridge
*bridge
;
1745 bridge
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1746 if (port
->bridge
!= bridge
) {
1747 if (port
->bridge
->parent
== bridge
) {
1748 ctl_fatal("bridge %s does not have a port %s (although "
1749 "its child bridge %s does)",
1750 ctx
->argv
[1], ctx
->argv
[2],
1751 port
->bridge
->name
);
1753 ctl_fatal("bridge %s does not have a port %s",
1754 ctx
->argv
[1], ctx
->argv
[2]);
1759 del_port(vsctl_ctx
, port
);
1764 cmd_port_to_br(struct ctl_context
*ctx
)
1766 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1767 struct vsctl_port
*port
;
1769 vsctl_context_populate_cache(ctx
);
1771 port
= find_port(vsctl_ctx
, ctx
->argv
[1], true);
1772 ds_put_format(&ctx
->output
, "%s\n", port
->bridge
->name
);
1776 cmd_br_to_vlan(struct ctl_context
*ctx
)
1778 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1779 struct vsctl_bridge
*bridge
;
1781 vsctl_context_populate_cache(ctx
);
1783 bridge
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1784 ds_put_format(&ctx
->output
, "%d\n", bridge
->vlan
);
1788 cmd_br_to_parent(struct ctl_context
*ctx
)
1790 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1791 struct vsctl_bridge
*bridge
;
1793 vsctl_context_populate_cache(ctx
);
1795 bridge
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1796 if (bridge
->parent
) {
1797 bridge
= bridge
->parent
;
1799 ds_put_format(&ctx
->output
, "%s\n", bridge
->name
);
1803 cmd_list_ifaces(struct ctl_context
*ctx
)
1805 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1806 struct vsctl_bridge
*br
;
1807 struct vsctl_port
*port
;
1810 vsctl_context_populate_cache(ctx
);
1812 br
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1813 verify_ports(vsctl_ctx
);
1816 LIST_FOR_EACH (port
, ports_node
, &br
->ports
) {
1817 struct vsctl_iface
*iface
;
1819 LIST_FOR_EACH (iface
, ifaces_node
, &port
->ifaces
) {
1820 if (strcmp(iface
->iface_cfg
->name
, br
->name
)) {
1821 svec_add(&ifaces
, iface
->iface_cfg
->name
);
1825 output_sorted(&ifaces
, &ctx
->output
);
1826 svec_destroy(&ifaces
);
1830 cmd_iface_to_br(struct ctl_context
*ctx
)
1832 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1833 struct vsctl_iface
*iface
;
1835 vsctl_context_populate_cache(ctx
);
1837 iface
= find_iface(vsctl_ctx
, ctx
->argv
[1], true);
1838 ds_put_format(&ctx
->output
, "%s\n", iface
->port
->bridge
->name
);
1842 verify_controllers(struct ovsrec_bridge
*bridge
)
1846 ovsrec_bridge_verify_controller(bridge
);
1847 for (i
= 0; i
< bridge
->n_controller
; i
++) {
1848 ovsrec_controller_verify_target(bridge
->controller
[i
]);
1853 pre_controller(struct ctl_context
*ctx
)
1857 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_controller_col_target
);
1858 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_controller_col_inactivity_probe
);
1862 cmd_get_controller(struct ctl_context
*ctx
)
1864 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1865 struct vsctl_bridge
*br
;
1866 struct svec targets
;
1869 vsctl_context_populate_cache(ctx
);
1871 br
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1875 verify_controllers(br
->br_cfg
);
1877 /* Print the targets in sorted order for reproducibility. */
1878 svec_init(&targets
);
1879 for (i
= 0; i
< br
->br_cfg
->n_controller
; i
++) {
1880 svec_add(&targets
, br
->br_cfg
->controller
[i
]->target
);
1883 svec_sort(&targets
);
1884 for (i
= 0; i
< targets
.n
; i
++) {
1885 ds_put_format(&ctx
->output
, "%s\n", targets
.names
[i
]);
1887 svec_destroy(&targets
);
1891 delete_controllers(struct ovsrec_controller
**controllers
,
1892 size_t n_controllers
)
1896 for (i
= 0; i
< n_controllers
; i
++) {
1897 ovsrec_controller_delete(controllers
[i
]);
1902 cmd_del_controller(struct ctl_context
*ctx
)
1904 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1905 struct ovsrec_bridge
*br
;
1907 vsctl_context_populate_cache(ctx
);
1909 br
= find_real_bridge(vsctl_ctx
, ctx
->argv
[1], true)->br_cfg
;
1910 verify_controllers(br
);
1912 if (br
->controller
) {
1913 delete_controllers(br
->controller
, br
->n_controller
);
1914 ovsrec_bridge_set_controller(br
, NULL
, 0);
1918 static struct ovsrec_controller
**
1919 insert_controllers(struct ctl_context
*ctx
, char *targets
[], size_t n
)
1921 struct ovsrec_controller
**controllers
;
1923 const char *inactivity_probe
= shash_find_data(&ctx
->options
,
1924 "--inactivity-probe");
1926 controllers
= xmalloc(n
* sizeof *controllers
);
1927 for (i
= 0; i
< n
; i
++) {
1928 if (vconn_verify_name(targets
[i
]) && pvconn_verify_name(targets
[i
])) {
1929 VLOG_WARN("target type \"%s\" is possibly erroneous", targets
[i
]);
1931 controllers
[i
] = ovsrec_controller_insert(ctx
->txn
);
1932 ovsrec_controller_set_target(controllers
[i
], targets
[i
]);
1933 if (inactivity_probe
) {
1934 int64_t msecs
= atoll(inactivity_probe
);
1935 ovsrec_controller_set_inactivity_probe(controllers
[i
], &msecs
, 1);
1943 cmd_set_controller(struct ctl_context
*ctx
)
1945 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1946 struct ovsrec_controller
**controllers
;
1947 struct ovsrec_bridge
*br
;
1950 vsctl_context_populate_cache(ctx
);
1952 br
= find_real_bridge(vsctl_ctx
, ctx
->argv
[1], true)->br_cfg
;
1953 verify_controllers(br
);
1955 delete_controllers(br
->controller
, br
->n_controller
);
1958 controllers
= insert_controllers(ctx
, &ctx
->argv
[2], n
);
1959 ovsrec_bridge_set_controller(br
, controllers
, n
);
1964 cmd_get_fail_mode(struct ctl_context
*ctx
)
1966 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1967 struct vsctl_bridge
*br
;
1968 const char *fail_mode
;
1970 vsctl_context_populate_cache(ctx
);
1971 br
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1976 ovsrec_bridge_verify_fail_mode(br
->br_cfg
);
1978 fail_mode
= br
->br_cfg
->fail_mode
;
1979 if (fail_mode
&& strlen(fail_mode
)) {
1980 ds_put_format(&ctx
->output
, "%s\n", fail_mode
);
1985 cmd_del_fail_mode(struct ctl_context
*ctx
)
1987 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
1988 struct vsctl_bridge
*br
;
1990 vsctl_context_populate_cache(ctx
);
1992 br
= find_real_bridge(vsctl_ctx
, ctx
->argv
[1], true);
1994 ovsrec_bridge_set_fail_mode(br
->br_cfg
, NULL
);
1998 cmd_set_fail_mode(struct ctl_context
*ctx
)
2000 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2001 struct vsctl_bridge
*br
;
2002 const char *fail_mode
= ctx
->argv
[2];
2004 vsctl_context_populate_cache(ctx
);
2006 br
= find_real_bridge(vsctl_ctx
, ctx
->argv
[1], true);
2008 if (strcmp(fail_mode
, "standalone") && strcmp(fail_mode
, "secure")) {
2009 ctl_fatal("fail-mode must be \"standalone\" or \"secure\"");
2012 ovsrec_bridge_set_fail_mode(br
->br_cfg
, fail_mode
);
2016 verify_managers(const struct ovsrec_open_vswitch
*ovs
)
2020 ovsrec_open_vswitch_verify_manager_options(ovs
);
2022 for (i
= 0; i
< ovs
->n_manager_options
; ++i
) {
2023 const struct ovsrec_manager
*mgr
= ovs
->manager_options
[i
];
2025 ovsrec_manager_verify_target(mgr
);
2030 pre_manager(struct ctl_context
*ctx
)
2032 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_open_vswitch_col_manager_options
);
2033 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_manager_col_target
);
2034 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_manager_col_inactivity_probe
);
2038 cmd_get_manager(struct ctl_context
*ctx
)
2040 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2041 const struct ovsrec_open_vswitch
*ovs
= vsctl_ctx
->ovs
;
2042 struct svec targets
;
2045 verify_managers(ovs
);
2047 /* Print the targets in sorted order for reproducibility. */
2048 svec_init(&targets
);
2050 for (i
= 0; i
< ovs
->n_manager_options
; i
++) {
2051 svec_add(&targets
, ovs
->manager_options
[i
]->target
);
2054 svec_sort_unique(&targets
);
2055 for (i
= 0; i
< targets
.n
; i
++) {
2056 ds_put_format(&ctx
->output
, "%s\n", targets
.names
[i
]);
2058 svec_destroy(&targets
);
2062 delete_managers(const struct ovsrec_open_vswitch
*ovs
)
2066 /* Delete Manager rows pointed to by 'manager_options' column. */
2067 for (i
= 0; i
< ovs
->n_manager_options
; i
++) {
2068 ovsrec_manager_delete(ovs
->manager_options
[i
]);
2071 /* Delete 'Manager' row refs in 'manager_options' column. */
2072 ovsrec_open_vswitch_set_manager_options(ovs
, NULL
, 0);
2076 cmd_del_manager(struct ctl_context
*ctx
)
2078 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2079 const struct ovsrec_open_vswitch
*ovs
= vsctl_ctx
->ovs
;
2081 verify_managers(ovs
);
2082 delete_managers(ovs
);
2086 insert_managers(struct vsctl_context
*vsctl_ctx
, char *targets
[], size_t n
,
2087 struct shash
*options
)
2089 struct ovsrec_manager
**managers
;
2091 const char *inactivity_probe
= shash_find_data(options
,
2092 "--inactivity-probe");
2094 /* Insert each manager in a new row in Manager table. */
2095 managers
= xmalloc(n
* sizeof *managers
);
2096 for (i
= 0; i
< n
; i
++) {
2097 if (stream_verify_name(targets
[i
]) && pstream_verify_name(targets
[i
])) {
2098 VLOG_WARN("target type \"%s\" is possibly erroneous", targets
[i
]);
2100 managers
[i
] = ovsrec_manager_insert(vsctl_ctx
->base
.txn
);
2101 ovsrec_manager_set_target(managers
[i
], targets
[i
]);
2102 if (inactivity_probe
) {
2103 int64_t msecs
= atoll(inactivity_probe
);
2104 ovsrec_manager_set_inactivity_probe(managers
[i
], &msecs
, 1);
2108 /* Store uuids of new Manager rows in 'manager_options' column. */
2109 ovsrec_open_vswitch_set_manager_options(vsctl_ctx
->ovs
, managers
, n
);
2114 cmd_set_manager(struct ctl_context
*ctx
)
2116 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2117 const size_t n
= ctx
->argc
- 1;
2119 verify_managers(vsctl_ctx
->ovs
);
2120 delete_managers(vsctl_ctx
->ovs
);
2121 insert_managers(vsctl_ctx
, &ctx
->argv
[1], n
, &ctx
->options
);
2125 pre_cmd_get_ssl(struct ctl_context
*ctx
)
2127 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_open_vswitch_col_ssl
);
2129 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_ssl_col_private_key
);
2130 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_ssl_col_certificate
);
2131 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_ssl_col_ca_cert
);
2132 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_ssl_col_bootstrap_ca_cert
);
2136 cmd_get_ssl(struct ctl_context
*ctx
)
2138 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2139 struct ovsrec_ssl
*ssl
= vsctl_ctx
->ovs
->ssl
;
2141 ovsrec_open_vswitch_verify_ssl(vsctl_ctx
->ovs
);
2143 ovsrec_ssl_verify_private_key(ssl
);
2144 ovsrec_ssl_verify_certificate(ssl
);
2145 ovsrec_ssl_verify_ca_cert(ssl
);
2146 ovsrec_ssl_verify_bootstrap_ca_cert(ssl
);
2148 ds_put_format(&ctx
->output
, "Private key: %s\n", ssl
->private_key
);
2149 ds_put_format(&ctx
->output
, "Certificate: %s\n", ssl
->certificate
);
2150 ds_put_format(&ctx
->output
, "CA Certificate: %s\n", ssl
->ca_cert
);
2151 ds_put_format(&ctx
->output
, "Bootstrap: %s\n",
2152 ssl
->bootstrap_ca_cert
? "true" : "false");
2157 pre_cmd_del_ssl(struct ctl_context
*ctx
)
2159 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_open_vswitch_col_ssl
);
2163 cmd_del_ssl(struct ctl_context
*ctx
)
2165 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2166 struct ovsrec_ssl
*ssl
= vsctl_ctx
->ovs
->ssl
;
2169 ovsrec_open_vswitch_verify_ssl(vsctl_ctx
->ovs
);
2170 ovsrec_ssl_delete(ssl
);
2171 ovsrec_open_vswitch_set_ssl(vsctl_ctx
->ovs
, NULL
);
2176 pre_cmd_set_ssl(struct ctl_context
*ctx
)
2178 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_open_vswitch_col_ssl
);
2182 cmd_set_ssl(struct ctl_context
*ctx
)
2184 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2185 bool bootstrap
= shash_find(&ctx
->options
, "--bootstrap");
2186 struct ovsrec_ssl
*ssl
= vsctl_ctx
->ovs
->ssl
;
2188 ovsrec_open_vswitch_verify_ssl(vsctl_ctx
->ovs
);
2190 ovsrec_ssl_delete(ssl
);
2192 ssl
= ovsrec_ssl_insert(ctx
->txn
);
2194 ovsrec_ssl_set_private_key(ssl
, ctx
->argv
[1]);
2195 ovsrec_ssl_set_certificate(ssl
, ctx
->argv
[2]);
2196 ovsrec_ssl_set_ca_cert(ssl
, ctx
->argv
[3]);
2198 ovsrec_ssl_set_bootstrap_ca_cert(ssl
, bootstrap
);
2200 ovsrec_open_vswitch_set_ssl(vsctl_ctx
->ovs
, ssl
);
2204 autoattach_insert_mapping(struct ovsrec_autoattach
*aa
,
2208 int64_t *key_mappings
, *value_mappings
;
2211 key_mappings
= xmalloc(sizeof *aa
->key_mappings
* (aa
->n_mappings
+ 1));
2212 value_mappings
= xmalloc(sizeof *aa
->value_mappings
* (aa
->n_mappings
+ 1));
2214 for (i
= 0; i
< aa
->n_mappings
; i
++) {
2215 key_mappings
[i
] = aa
->key_mappings
[i
];
2216 value_mappings
[i
] = aa
->value_mappings
[i
];
2218 key_mappings
[aa
->n_mappings
] = isid
;
2219 value_mappings
[aa
->n_mappings
] = vlan
;
2221 ovsrec_autoattach_set_mappings(aa
, key_mappings
, value_mappings
,
2222 aa
->n_mappings
+ 1);
2225 free(value_mappings
);
2229 cmd_add_aa_mapping(struct ctl_context
*ctx
)
2231 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2232 struct vsctl_bridge
*br
;
2236 isid
= strtoull(ctx
->argv
[2], &nptr
, 10);
2237 if (nptr
== ctx
->argv
[2] || nptr
== NULL
) {
2238 ctl_fatal("Invalid argument %s", ctx
->argv
[2]);
2242 vlan
= strtoull(ctx
->argv
[3], &nptr
, 10);
2243 if (nptr
== ctx
->argv
[3] || nptr
== NULL
) {
2244 ctl_fatal("Invalid argument %s", ctx
->argv
[3]);
2248 vsctl_context_populate_cache(ctx
);
2250 br
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
2256 if (!br
->br_cfg
->auto_attach
) {
2257 struct ovsrec_autoattach
*aa
= ovsrec_autoattach_insert(ctx
->txn
);
2258 ovsrec_bridge_set_auto_attach(br
->br_cfg
, aa
);
2260 autoattach_insert_mapping(br
->br_cfg
->auto_attach
, isid
, vlan
);
2265 del_aa_mapping(struct ovsrec_autoattach
*aa
,
2269 int64_t *key_mappings
, *value_mappings
;
2272 key_mappings
= xmalloc(sizeof *aa
->key_mappings
* (aa
->n_mappings
));
2273 value_mappings
= xmalloc(sizeof *value_mappings
* (aa
->n_mappings
));
2275 for (i
= n
= 0; i
< aa
->n_mappings
; i
++) {
2276 if (aa
->key_mappings
[i
] != isid
&& aa
->value_mappings
[i
] != vlan
) {
2277 key_mappings
[n
] = aa
->key_mappings
[i
];
2278 value_mappings
[n
++] = aa
->value_mappings
[i
];
2282 ovsrec_autoattach_set_mappings(aa
, key_mappings
, value_mappings
, n
);
2285 free(value_mappings
);
2289 cmd_del_aa_mapping(struct ctl_context
*ctx
)
2291 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2292 struct vsctl_bridge
*br
;
2296 isid
= strtoull(ctx
->argv
[2], &nptr
, 10);
2297 if (nptr
== ctx
->argv
[2] || nptr
== NULL
) {
2298 ctl_fatal("Invalid argument %s", ctx
->argv
[2]);
2302 vlan
= strtoull(ctx
->argv
[3], &nptr
, 10);
2303 if (nptr
== ctx
->argv
[3] || nptr
== NULL
) {
2304 ctl_fatal("Invalid argument %s", ctx
->argv
[3]);
2308 vsctl_context_populate_cache(ctx
);
2310 br
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
2315 if (br
->br_cfg
&& br
->br_cfg
->auto_attach
&&
2316 br
->br_cfg
->auto_attach
->key_mappings
&&
2317 br
->br_cfg
->auto_attach
->value_mappings
) {
2320 for (i
= 0; i
< br
->br_cfg
->auto_attach
->n_mappings
; i
++) {
2321 if (br
->br_cfg
->auto_attach
->key_mappings
[i
] == isid
&&
2322 br
->br_cfg
->auto_attach
->value_mappings
[i
] == vlan
) {
2323 del_aa_mapping(br
->br_cfg
->auto_attach
, isid
, vlan
);
2331 pre_aa_mapping(struct ctl_context
*ctx
)
2335 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_bridge_col_auto_attach
);
2336 ovsdb_idl_add_column(ctx
->idl
, &ovsrec_autoattach_col_mappings
);
2340 verify_auto_attach(struct ovsrec_bridge
*bridge
)
2343 ovsrec_bridge_verify_auto_attach(bridge
);
2345 if (bridge
->auto_attach
) {
2346 ovsrec_autoattach_verify_mappings(bridge
->auto_attach
);
2352 cmd_get_aa_mapping(struct ctl_context
*ctx
)
2354 struct vsctl_context
*vsctl_ctx
= vsctl_context_cast(ctx
);
2355 struct vsctl_bridge
*br
;
2357 vsctl_context_populate_cache(ctx
);
2359 br
= find_bridge(vsctl_ctx
, ctx
->argv
[1], true);
2364 verify_auto_attach(br
->br_cfg
);
2366 if (br
->br_cfg
&& br
->br_cfg
->auto_attach
&&
2367 br
->br_cfg
->auto_attach
->key_mappings
&&
2368 br
->br_cfg
->auto_attach
->value_mappings
) {
2371 for (i
= 0; i
< br
->br_cfg
->auto_attach
->n_mappings
; i
++) {
2372 ds_put_format(&ctx
->output
, "%"PRId64
" %"PRId64
"\n",
2373 br
->br_cfg
->auto_attach
->key_mappings
[i
],
2374 br
->br_cfg
->auto_attach
->value_mappings
[i
]);
2380 static const struct ctl_table_class tables
[OVSREC_N_TABLES
] = {
2381 [OVSREC_TABLE_BRIDGE
].row_ids
[0] = {&ovsrec_bridge_col_name
, NULL
, NULL
},
2383 [OVSREC_TABLE_CONTROLLER
].row_ids
[0]
2384 = {&ovsrec_bridge_col_name
, NULL
, &ovsrec_bridge_col_controller
},
2386 [OVSREC_TABLE_INTERFACE
].row_ids
[0]
2387 = {&ovsrec_interface_col_name
, NULL
, NULL
},
2389 [OVSREC_TABLE_MIRROR
].row_ids
[0] = {&ovsrec_mirror_col_name
, NULL
, NULL
},
2391 [OVSREC_TABLE_MANAGER
].row_ids
[0]
2392 = {&ovsrec_manager_col_target
, NULL
, NULL
},
2394 [OVSREC_TABLE_NETFLOW
].row_ids
[0]
2395 = {&ovsrec_bridge_col_name
, NULL
, &ovsrec_bridge_col_netflow
},
2397 [OVSREC_TABLE_PORT
].row_ids
[0] = {&ovsrec_port_col_name
, NULL
, NULL
},
2399 [OVSREC_TABLE_QOS
].row_ids
[0]
2400 = {&ovsrec_port_col_name
, NULL
, &ovsrec_port_col_qos
},
2402 [OVSREC_TABLE_SFLOW
].row_ids
[0]
2403 = {&ovsrec_bridge_col_name
, NULL
, &ovsrec_bridge_col_sflow
},
2405 [OVSREC_TABLE_FLOW_TABLE
].row_ids
[0]
2406 = {&ovsrec_flow_table_col_name
, NULL
, NULL
},
2408 [OVSREC_TABLE_IPFIX
].row_ids
[0]
2409 = {&ovsrec_bridge_col_name
, NULL
, &ovsrec_bridge_col_ipfix
},
2411 [OVSREC_TABLE_AUTOATTACH
].row_ids
[0]
2412 = {&ovsrec_bridge_col_name
, NULL
, &ovsrec_bridge_col_auto_attach
},
2414 [OVSREC_TABLE_FLOW_SAMPLE_COLLECTOR_SET
].row_ids
[0]
2415 = {&ovsrec_flow_sample_collector_set_col_id
, NULL
, NULL
},
2419 post_db_reload_check_init(void)
2421 n_neoteric_ifaces
= 0;
2425 post_db_reload_expect_iface(const struct ovsrec_interface
*iface
)
2427 if (n_neoteric_ifaces
>= allocated_neoteric_ifaces
) {
2428 neoteric_ifaces
= x2nrealloc(neoteric_ifaces
,
2429 &allocated_neoteric_ifaces
,
2430 sizeof *neoteric_ifaces
);
2432 neoteric_ifaces
[n_neoteric_ifaces
++] = iface
->header_
.uuid
;
2436 post_db_reload_do_checks(const struct vsctl_context
*vsctl_ctx
)
2438 bool print_error
= false;
2441 for (i
= 0; i
< n_neoteric_ifaces
; i
++) {
2442 const struct uuid
*uuid
;
2444 uuid
= ovsdb_idl_txn_get_insert_uuid(vsctl_ctx
->base
.txn
,
2445 &neoteric_ifaces
[i
]);
2447 const struct ovsrec_interface
*iface
;
2449 iface
= ovsrec_interface_get_for_uuid(vsctl_ctx
->base
.idl
, uuid
);
2450 if (iface
&& (!iface
->ofport
|| *iface
->ofport
== -1)) {
2451 if (iface
->error
&& *iface
->error
) {
2452 ovs_error(0, "Error detected while setting up '%s': %s. "
2453 "See ovs-vswitchd log for details.",
2454 iface
->name
, iface
->error
);
2456 ovs_error(0, "Error detected while setting up '%s'. "
2457 "See ovs-vswitchd log for details.",
2466 ovs_error(0, "The default log directory is \"%s\".", ovs_logdir());
2472 vsctl_context_init_command(struct vsctl_context
*vsctl_ctx
,
2473 struct ctl_command
*command
)
2475 ctl_context_init_command(&vsctl_ctx
->base
, command
);
2476 vsctl_ctx
->verified_ports
= false;
2480 vsctl_context_init(struct vsctl_context
*vsctl_ctx
,
2481 struct ctl_command
*command
, struct ovsdb_idl
*idl
,
2482 struct ovsdb_idl_txn
*txn
,
2483 const struct ovsrec_open_vswitch
*ovs
,
2484 struct ovsdb_symbol_table
*symtab
)
2486 ctl_context_init(&vsctl_ctx
->base
, command
, idl
, txn
, symtab
,
2487 vsctl_context_invalidate_cache
);
2489 vsctl_ctx
->verified_ports
= false;
2491 vsctl_ctx
->ovs
= ovs
;
2492 vsctl_ctx
->cache_valid
= false;
2496 vsctl_context_done_command(struct vsctl_context
*vsctl_ctx
,
2497 struct ctl_command
*command
)
2499 ctl_context_done_command(&vsctl_ctx
->base
, command
);
2503 vsctl_context_done(struct vsctl_context
*vsctl_ctx
,
2504 struct ctl_command
*command
)
2506 ctl_context_done(&vsctl_ctx
->base
, command
);
2510 run_prerequisites(struct ctl_command
*commands
, size_t n_commands
,
2511 struct ovsdb_idl
*idl
)
2513 struct ctl_command
*c
;
2515 ovsdb_idl_add_table(idl
, &ovsrec_table_open_vswitch
);
2516 if (wait_for_reload
) {
2517 ovsdb_idl_add_column(idl
, &ovsrec_open_vswitch_col_cur_cfg
);
2519 for (c
= commands
; c
< &commands
[n_commands
]; c
++) {
2520 if (c
->syntax
->prerequisites
) {
2521 struct vsctl_context vsctl_ctx
;
2523 ds_init(&c
->output
);
2526 vsctl_context_init(&vsctl_ctx
, c
, idl
, NULL
, NULL
, NULL
);
2527 (c
->syntax
->prerequisites
)(&vsctl_ctx
.base
);
2528 vsctl_context_done(&vsctl_ctx
, c
);
2530 ovs_assert(!c
->output
.string
);
2531 ovs_assert(!c
->table
);
2537 vsctl_parent_process_info(void)
2543 parent_pid
= getppid();
2546 /* Retrive the command line of the parent process, except the init
2547 * process since /proc/0 does not exist. */
2552 procfile
= xasprintf("/proc/%d/cmdline", parent_pid
);
2554 f
= fopen(procfile
, "r");
2561 ds_put_cstr(&s
, "init");
2564 ds_put_format(&s
, " (pid %d)", parent_pid
);
2565 return ds_steal_cstr(&s
);
2572 do_vsctl(const char *args
, struct ctl_command
*commands
, size_t n_commands
,
2573 struct ovsdb_idl
*idl
)
2575 struct ovsdb_idl_txn
*txn
;
2576 const struct ovsrec_open_vswitch
*ovs
;
2577 enum ovsdb_idl_txn_status status
;
2578 struct ovsdb_symbol_table
*symtab
;
2579 struct vsctl_context vsctl_ctx
;
2580 struct ctl_command
*c
;
2581 struct shash_node
*node
;
2582 int64_t next_cfg
= 0;
2584 char *ppid_info
= NULL
;
2586 txn
= the_idl_txn
= ovsdb_idl_txn_create(idl
);
2588 ovsdb_idl_txn_set_dry_run(txn
);
2591 ppid_info
= vsctl_parent_process_info();
2593 ovsdb_idl_txn_add_comment(txn
, "ovs-vsctl (invoked by %s): %s",
2597 ovsdb_idl_txn_add_comment(txn
, "ovs-vsctl: %s", args
);
2600 ovs
= ovsrec_open_vswitch_first(idl
);
2602 /* XXX add verification that table is empty */
2603 ovs
= ovsrec_open_vswitch_insert(txn
);
2606 if (wait_for_reload
) {
2607 ovsdb_idl_txn_increment(txn
, &ovs
->header_
,
2608 &ovsrec_open_vswitch_col_next_cfg
, false);
2611 post_db_reload_check_init();
2612 symtab
= ovsdb_symbol_table_create();
2613 for (c
= commands
; c
< &commands
[n_commands
]; c
++) {
2614 ds_init(&c
->output
);
2617 vsctl_context_init(&vsctl_ctx
, NULL
, idl
, txn
, ovs
, symtab
);
2618 for (c
= commands
; c
< &commands
[n_commands
]; c
++) {
2619 vsctl_context_init_command(&vsctl_ctx
, c
);
2620 if (c
->syntax
->run
) {
2621 (c
->syntax
->run
)(&vsctl_ctx
.base
);
2623 vsctl_context_done_command(&vsctl_ctx
, c
);
2625 if (vsctl_ctx
.base
.try_again
) {
2626 vsctl_context_done(&vsctl_ctx
, NULL
);
2630 vsctl_context_done(&vsctl_ctx
, NULL
);
2632 SHASH_FOR_EACH (node
, &symtab
->sh
) {
2633 struct ovsdb_symbol
*symbol
= node
->data
;
2634 if (!symbol
->created
) {
2635 ctl_fatal("row id \"%s\" is referenced but never created (e.g. "
2636 "with \"-- --id=%s create ...\")",
2637 node
->name
, node
->name
);
2639 if (!symbol
->strong_ref
) {
2640 if (!symbol
->weak_ref
) {
2641 VLOG_WARN("row id \"%s\" was created but no reference to it "
2642 "was inserted, so it will not actually appear in "
2643 "the database", node
->name
);
2645 VLOG_WARN("row id \"%s\" was created but only a weak "
2646 "reference to it was inserted, so it will not "
2647 "actually appear in the database", node
->name
);
2652 status
= ovsdb_idl_txn_commit_block(txn
);
2653 if (wait_for_reload
&& status
== TXN_SUCCESS
) {
2654 next_cfg
= ovsdb_idl_txn_get_increment_new_value(txn
);
2656 if (status
== TXN_UNCHANGED
|| status
== TXN_SUCCESS
) {
2657 for (c
= commands
; c
< &commands
[n_commands
]; c
++) {
2658 if (c
->syntax
->postprocess
) {
2659 vsctl_context_init(&vsctl_ctx
, c
, idl
, txn
, ovs
, symtab
);
2660 (c
->syntax
->postprocess
)(&vsctl_ctx
.base
);
2661 vsctl_context_done(&vsctl_ctx
, c
);
2665 error
= xstrdup(ovsdb_idl_txn_get_error(txn
));
2668 case TXN_UNCOMMITTED
:
2669 case TXN_INCOMPLETE
:
2673 /* Should not happen--we never call ovsdb_idl_txn_abort(). */
2674 ctl_fatal("transaction aborted");
2684 ctl_fatal("transaction error: %s", error
);
2686 case TXN_NOT_LOCKED
:
2687 /* Should not happen--we never call ovsdb_idl_set_lock(). */
2688 ctl_fatal("database not locked");
2695 ovsdb_symbol_table_destroy(symtab
);
2697 for (c
= commands
; c
< &commands
[n_commands
]; c
++) {
2698 struct ds
*ds
= &c
->output
;
2701 table_print(c
->table
, &table_style
);
2702 } else if (oneline
) {
2706 for (j
= 0; j
< ds
->length
; j
++) {
2707 int ch
= ds
->string
[j
];
2710 fputs("\\n", stdout
);
2714 fputs("\\\\", stdout
);
2723 fputs(ds_cstr(ds
), stdout
);
2725 ds_destroy(&c
->output
);
2726 table_destroy(c
->table
);
2729 shash_destroy_free_data(&c
->options
);
2733 if (wait_for_reload
&& status
!= TXN_UNCHANGED
) {
2734 /* Even, if --retry flag was not specified, ovs-vsctl still
2735 * has to retry to establish OVSDB connection, if wait_for_reload
2736 * was set. Otherwise, ovs-vsctl would end up waiting forever
2737 * until cur_cfg would be updated. */
2738 ovsdb_idl_enable_reconnect(idl
);
2741 OVSREC_OPEN_VSWITCH_FOR_EACH (ovs
, idl
) {
2742 if (ovs
->cur_cfg
>= next_cfg
) {
2743 post_db_reload_do_checks(&vsctl_ctx
);
2747 ovsdb_idl_wait(idl
);
2752 ovsdb_idl_txn_destroy(txn
);
2753 ovsdb_idl_destroy(idl
);
2758 /* Our transaction needs to be rerun, or a prerequisite was not met. Free
2759 * resources and return so that the caller can try again. */
2760 ovsdb_idl_txn_abort(txn
);
2761 ovsdb_idl_txn_destroy(txn
);
2764 ovsdb_symbol_table_destroy(symtab
);
2765 for (c
= commands
; c
< &commands
[n_commands
]; c
++) {
2766 ds_destroy(&c
->output
);
2767 table_destroy(c
->table
);
2774 /* Frees the current transaction and the underlying IDL and then calls
2777 * Freeing the transaction and the IDL is not strictly necessary, but it makes
2778 * for a clean memory leak report from valgrind in the normal case. That makes
2779 * it easier to notice real memory leaks. */
2781 vsctl_exit(int status
)
2784 ovsdb_idl_txn_abort(the_idl_txn
);
2785 ovsdb_idl_txn_destroy(the_idl_txn
);
2787 ovsdb_idl_destroy(the_idl
);
2792 * Developers who add new commands to the 'struct ctl_command_syntax' must
2793 * define the 'arguments' member of the struct. The following keywords are
2794 * available for composing the argument format:
2796 * TABLE RECORD BRIDGE PARENT PORT
2797 * KEY VALUE ARG KEY=VALUE ?KEY=VALUE
2798 * IFACE SYSIFACE COLUMN COLUMN?:KEY COLUMN?:KEY=VALUE
2799 * MODE CA-CERT CERTIFICATE PRIVATE-KEY
2800 * TARGET NEW-* (e.g. NEW-PORT)
2802 * For argument types not listed above, just uses 'ARG' as place holder.
2804 * Encloses the keyword with '[]' if it is optional. Appends '...' to
2805 * keyword or enclosed keyword to indicate that the argument can be specified
2809 static const struct ctl_command_syntax vsctl_commands
[] = {
2810 /* Open vSwitch commands. */
2811 {"init", 0, 0, "", NULL
, cmd_init
, NULL
, "", RW
},
2813 /* Bridge commands. */
2814 {"add-br", 1, 3, "NEW-BRIDGE [PARENT] [NEW-VLAN]", pre_get_info
,
2815 cmd_add_br
, NULL
, "--may-exist", RW
},
2816 {"del-br", 1, 1, "BRIDGE", pre_get_info
, cmd_del_br
,
2817 NULL
, "--if-exists", RW
},
2818 {"list-br", 0, 0, "", pre_get_info
, cmd_list_br
, NULL
, "--real,--fake",
2820 {"br-exists", 1, 1, "BRIDGE", pre_get_info
, cmd_br_exists
, NULL
, "", RO
},
2821 {"br-to-vlan", 1, 1, "BRIDGE", pre_get_info
, cmd_br_to_vlan
, NULL
, "",
2823 {"br-to-parent", 1, 1, "BRIDGE", pre_get_info
, cmd_br_to_parent
, NULL
,
2825 {"br-set-external-id", 2, 3, "BRIDGE KEY [VALUE]",
2826 pre_cmd_br_set_external_id
, cmd_br_set_external_id
, NULL
, "", RW
},
2827 {"br-get-external-id", 1, 2, "BRIDGE [KEY]", pre_cmd_br_get_external_id
,
2828 cmd_br_get_external_id
, NULL
, "", RO
},
2830 /* Port commands. */
2831 {"list-ports", 1, 1, "BRIDGE", pre_get_info
, cmd_list_ports
, NULL
, "",
2833 {"add-port", 2, INT_MAX
, "BRIDGE NEW-PORT [COLUMN[:KEY]=VALUE]...",
2834 pre_get_info
, cmd_add_port
, NULL
, "--may-exist", RW
},
2835 {"del-port", 1, 2, "[BRIDGE] PORT|IFACE", pre_get_info
, cmd_del_port
, NULL
,
2836 "--if-exists,--with-iface", RW
},
2837 {"port-to-br", 1, 1, "PORT", pre_get_info
, cmd_port_to_br
, NULL
, "", RO
},
2839 /* Bond commands. */
2840 {"add-bond", 4, INT_MAX
,
2841 "BRIDGE BOND IFACE... [COLUMN[:KEY]=VALUE]...", pre_get_info
,
2842 cmd_add_bond
, NULL
, "--may-exist,--fake-iface", RW
},
2843 {"add-bond-iface", 2, 2, "BOND IFACE", pre_get_info
, cmd_add_bond_iface
,
2844 NULL
, "--may-exist", RW
},
2845 {"del-bond-iface", 1, 2, "[BOND] IFACE", pre_get_info
, cmd_del_bond_iface
,
2846 NULL
, "--if-exists", RW
},
2848 /* Interface commands. */
2849 {"list-ifaces", 1, 1, "BRIDGE", pre_get_info
, cmd_list_ifaces
, NULL
, "",
2851 {"iface-to-br", 1, 1, "IFACE", pre_get_info
, cmd_iface_to_br
, NULL
, "",
2854 /* Controller commands. */
2855 {"get-controller", 1, 1, "BRIDGE", pre_controller
, cmd_get_controller
,
2857 {"del-controller", 1, 1, "BRIDGE", pre_controller
, cmd_del_controller
,
2859 {"set-controller", 1, INT_MAX
, "BRIDGE TARGET...", pre_controller
,
2860 cmd_set_controller
, NULL
, "--inactivity-probe=", RW
},
2861 {"get-fail-mode", 1, 1, "BRIDGE", pre_get_info
, cmd_get_fail_mode
, NULL
,
2863 {"del-fail-mode", 1, 1, "BRIDGE", pre_get_info
, cmd_del_fail_mode
, NULL
,
2865 {"set-fail-mode", 2, 2, "BRIDGE MODE", pre_get_info
, cmd_set_fail_mode
,
2868 /* Manager commands. */
2869 {"get-manager", 0, 0, "", pre_manager
, cmd_get_manager
, NULL
, "", RO
},
2870 {"del-manager", 0, 0, "", pre_manager
, cmd_del_manager
, NULL
, "", RW
},
2871 {"set-manager", 1, INT_MAX
, "TARGET...", pre_manager
, cmd_set_manager
,
2872 NULL
, "--inactivity-probe=", RW
},
2875 {"get-ssl", 0, 0, "", pre_cmd_get_ssl
, cmd_get_ssl
, NULL
, "", RO
},
2876 {"del-ssl", 0, 0, "", pre_cmd_del_ssl
, cmd_del_ssl
, NULL
, "", RW
},
2877 {"set-ssl", 3, 3, "PRIVATE-KEY CERTIFICATE CA-CERT", pre_cmd_set_ssl
,
2878 cmd_set_ssl
, NULL
, "--bootstrap", RW
},
2880 /* Auto Attach commands. */
2881 {"add-aa-mapping", 3, 3, "BRIDGE ARG ARG", pre_aa_mapping
, cmd_add_aa_mapping
,
2883 {"del-aa-mapping", 3, 3, "BRIDGE ARG ARG", pre_aa_mapping
, cmd_del_aa_mapping
,
2885 {"get-aa-mapping", 1, 1, "BRIDGE", pre_aa_mapping
, cmd_get_aa_mapping
,
2888 /* Switch commands. */
2889 {"emer-reset", 0, 0, "", pre_cmd_emer_reset
, cmd_emer_reset
, NULL
, "", RW
},
2891 {NULL
, 0, 0, NULL
, NULL
, NULL
, NULL
, NULL
, RO
},
2894 /* Registers vsctl and common db commands. */
2896 vsctl_cmd_init(void)
2898 ctl_init(&ovsrec_idl_class
, ovsrec_table_classes
, tables
, cmd_show_tables
,
2900 ctl_register_commands(vsctl_commands
);