From: Justin Pettit Date: Wed, 16 Dec 2009 23:10:35 +0000 (-0800) Subject: ovs-vsctl: Add commands for modifying controller settings X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5aa006354872e40c227b601f0e0deb4fd72eb9f6;p=openvswitch ovs-vsctl: Add commands for modifying controller settings Adds the ability to configure the controller and fail-mode. --- diff --git a/utilities/ovs-vsctl.8.in b/utilities/ovs-vsctl.8.in index 17214bd9..16fd8497 100644 --- a/utilities/ovs-vsctl.8.in +++ b/utilities/ovs-vsctl.8.in @@ -4,6 +4,13 @@ . ns . IP "\\$1" .. +.de ST +. PP +. RS -0.15in +. I "\\$1" +. RE +. PP +.. .TH ovs\-vsctl 8 "November 2009" "Open vSwitch" "Open vSwitch Manual" .ds PN ovs\-vsctl . @@ -266,6 +273,73 @@ the output is the value for that \fIkey\fR or the empty string if \fIkey\fR is unset. If \fIkey\fR is omitted, the output is \fIkey\fB=\fIvalue\fR, one per line, for each key-value pair. . +.SS "OpenFlow Controller Connectivity" +. +\fBovs\-vswitchd\fR can perform all configured bridging and switching +locally, or it can be configured to connect a given bridge to an +external OpenFlow controller, such as NOX. +. +If a \fIbridge\fR argument is given, the settings apply only to the +specified bridge. Otherwise, they apply to the Open vSwitch instance, +and its configuration applies to any bridge that has not been explicitly +configured through a \fIbridge\fR argument. +. +.IP "\fBget\-controller\fR [\fIbridge\fR]" +Prints the configured controller target. +. +.IP "\fBdel\-controller\fR [\fIbridge\fR]" +Deletes the configured controller target. +. +.IP "\fBset\-controller\fR [\fIbridge\fR] \fItarget\fR" +Sets the configured controller target. The \fItarget\fR may use any of +the following forms: +. +.RS +.TP +\fBssl:\fIip\fR[\fB:\fIport\fR] +The specified SSL \fIport\fR (default: 6633) on the host at the given +\fIip\fR, which must be expressed as an IP address (not a DNS name). +SSL must be configured when this form is used (see \fBSSL +Configuration\fR, below). +. +.TP +\fBtcp:\fIip\fR[\fB:\fIport\fR] +The specified TCP \fIport\fR (default: 6633) on the host at the given +\fIip\fR, which must be expressed as an IP address (not a DNS name). +.TP +\fBunix:\fIfile\fR +The Unix domain server socket named \fIfile\fR. +.RE +.ST "Controller Failure Settings" +. +When a controller is configured, it is, ordinarily, responsible for +setting up all flows on the switch. Thus, if the connection to +the controller fails, no new network connections can be set up. If +the connection to the controller stays down long enough, no packets +can pass through the switch at all. +.ST +If the value is \fBstandalone\fR, or if neither of these settings +is set, \fBovs\-vswitchd\fR will take over +responsibility for setting up +flows when no message has been received from the controller for three +times the inactivity probe interval (xxx needs to be exposed). In this mode, +\fBovs\-vswitchd\fR causes the datapath to act like an ordinary +MAC-learning switch. \fBovs\-vswitchd\fR will continue to retry connecting +to the controller in the background and, when the connection succeeds, +it discontinues its standalone behavior. +.ST +If this option is set to \fBsecure\fR, \fBovs\-vswitchd\fR will not +set up flows on its own when the controller connection fails. +. +.IP "\fBget\-fail\-mode\fR [\fIbridge\fR]" +Prints the configured failure mode. +. +.IP "\fBdel\-fail\-mode\fR [\fIbridge\fR]" +Deletes the configured failure mode. +. +.IP "\fBset\-fail\-mode\fR [\fIbridge\fR] \fBstandalone\fR|\fBsecure\fR" +Sets the configured failure mode. +. .SH "EXAMPLES" Create a new bridge named br0 and add port eth0 to it: .IP diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c index 941e6b7c..852db3ae 100644 --- a/utilities/ovs-vsctl.c +++ b/utilities/ovs-vsctl.c @@ -296,6 +296,20 @@ usage(void) " iface-get-external-id IFACE" " list key-value pairs on IFACE\n" ); + printf("\nController commands:\n" + " get-controller [BRIDGE] " + "print the controller for BRIDGE\n" + " del-controller [BRIDGE] " + "delete the controller for BRIDGE\n" + " set-controller [BRIDGE] TARGET " + "set the controller for BRIDGE to TARGET\n" + " get-fail-mode [BRIDGE] " + "print the fail-mode for BRIDGE\n" + " del-fail-mode [BRIDGE] " + "delete the fail-mode for BRIDGE\n" + " set-fail-mode [BRIDGE] MODE " + "set the fail-mode for BRIDGE to MODE\n" + ); printf("\nOptions:\n" " --db=DATABASE " "connect to DATABASE\n" @@ -334,6 +348,7 @@ struct vsctl_context { struct vsctl_bridge { struct ovsrec_bridge *br_cfg; char *name; + struct ovsrec_controller *ctrl; struct vsctl_bridge *parent; int vlan; }; @@ -352,6 +367,7 @@ struct vsctl_info { struct shash bridges; struct shash ports; struct shash ifaces; + struct ovsrec_controller *ctrl; }; static struct ovsdb_idl_txn * @@ -370,6 +386,7 @@ add_bridge(struct vsctl_info *b, br->name = xstrdup(name); br->parent = parent; br->vlan = vlan; + br->ctrl = br_cfg->controller; shash_add(&b->bridges, br->name, br); return br; } @@ -433,6 +450,8 @@ get_info(const struct ovsrec_open_vswitch *ovs, struct vsctl_info *info) shash_init(&info->ports); shash_init(&info->ifaces); + info->ctrl = ovs->controller; + shash_init(&bridges); shash_init(&ports); for (i = 0; i < ovs->n_bridges; i++) { @@ -1197,6 +1216,177 @@ cmd_iface_get_external_id(struct vsctl_context *ctx) "", ctx->argc >= 3 ? ctx->argv[2] : NULL, &ctx->output); free_info(&info); } + +static void +cmd_get_controller(struct vsctl_context *ctx) +{ + struct vsctl_info info; + + get_info(ctx->ovs, &info); + + if (ctx->argc == 1) { + /* Return the controller from the "Open_vSwitch" table */ + if (info.ctrl) { + ds_put_format(&ctx->output, "%s\n", info.ctrl->target); + } + } else { + /* Return the controller for a particular bridge. */ + struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true); + + /* If no controller is explicitly defined for the requested + * bridge, fallback to the "Open_vSwitch" table's controller. */ + if (br->ctrl) { + ds_put_format(&ctx->output, "%s\n", br->ctrl->target); + } else if (info.ctrl) { + ds_put_format(&ctx->output, "%s\n", info.ctrl->target); + } + } + + free_info(&info); +} + +static void +cmd_del_controller(struct vsctl_context *ctx) +{ + struct vsctl_info info; + + get_info(ctx->ovs, &info); + + if (ctx->argc == 1) { + if (info.ctrl) { + ovsrec_controller_delete(info.ctrl); + ovsrec_open_vswitch_set_controller(ctx->ovs, NULL); + } + } else { + struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true); + + if (br->ctrl) { + ovsrec_controller_delete(br->ctrl); + ovsrec_bridge_set_controller(br->br_cfg, NULL); + } + } + + free_info(&info); +} + +static void +cmd_set_controller(struct vsctl_context *ctx) +{ + struct vsctl_info info; + struct ovsrec_controller *ctrl; + + get_info(ctx->ovs, &info); + + if (ctx->argc == 2) { + /* Set the controller in the "Open_vSwitch" table. */ + if (info.ctrl) { + ovsrec_controller_delete(info.ctrl); + } + ctrl = ovsrec_controller_insert(txn_from_openvswitch(ctx->ovs)); + ovsrec_controller_set_target(ctrl, ctx->argv[1]); + ovsrec_open_vswitch_set_controller(ctx->ovs, ctrl); + } else { + /* Set the controller for a particular bridge. */ + struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true); + + if (br->ctrl) { + ovsrec_controller_delete(br->ctrl); + } + ctrl = ovsrec_controller_insert(txn_from_openvswitch(ctx->ovs)); + ovsrec_controller_set_target(ctrl, ctx->argv[2]); + ovsrec_bridge_set_controller(br->br_cfg, ctrl); + } + + free_info(&info); +} + +static void +cmd_get_fail_mode(struct vsctl_context *ctx) +{ + struct vsctl_info info; + const char *fail_mode = NULL; + + get_info(ctx->ovs, &info); + + if (ctx->argc == 1) { + /* Return the fail-mode from the "Open_vSwitch" table */ + if (info.ctrl && info.ctrl->fail_mode) { + fail_mode = info.ctrl->fail_mode; + } + } else { + /* Return the fail-mode for a particular bridge. */ + struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true); + + /* If no controller or fail-mode is explicitly defined for the + * requested bridge, fallback to the "Open_vSwitch" table's + * setting. */ + if (br->ctrl && br->ctrl->fail_mode) { + fail_mode = br->ctrl->fail_mode; + } else if (info.ctrl && info.ctrl->fail_mode) { + fail_mode = info.ctrl->fail_mode; + } + } + + if (fail_mode && strlen(fail_mode)) { + ds_put_format(&ctx->output, "%s\n", info.ctrl->fail_mode); + } + + free_info(&info); +} + +static void +cmd_del_fail_mode(struct vsctl_context *ctx) +{ + struct vsctl_info info; + + get_info(ctx->ovs, &info); + + if (ctx->argc == 1) { + if (info.ctrl && info.ctrl->fail_mode) { + ovsrec_controller_set_fail_mode(info.ctrl, NULL); + } + } else { + struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true); + + if (br->ctrl && br->ctrl->fail_mode) { + ovsrec_controller_set_fail_mode(br->ctrl, NULL); + } + } + + free_info(&info); +} + +static void +cmd_set_fail_mode(struct vsctl_context *ctx) +{ + struct vsctl_info info; + const char *fail_mode; + + get_info(ctx->ovs, &info); + + fail_mode = (ctx->argc == 2) ? ctx->argv[1] : ctx->argv[2]; + + if (strcmp(fail_mode, "standalone") && strcmp(fail_mode, "secure")) { + vsctl_fatal("fail-mode must be \"standalone\" or \"secure\""); + } + + if (ctx->argc == 2) { + /* Set the fail-mode in the "Open_vSwitch" table. */ + if (!info.ctrl) { + vsctl_fatal("no controller declared"); + } + ovsrec_controller_set_fail_mode(info.ctrl, fail_mode); + } else { + struct vsctl_bridge *br = find_bridge(&info, ctx->argv[1], true); + + if (!br->ctrl) { + vsctl_fatal("no controller declared for %s", br->name); + } + ovsrec_controller_set_fail_mode(br->ctrl, fail_mode); + } + + free_info(&info); +} typedef void vsctl_handler_func(struct vsctl_context *); @@ -1389,6 +1579,14 @@ get_vsctl_handler(int argc, char *argv[], struct vsctl_context *ctx) {"iface-to-br", 1, 1, cmd_iface_to_br, ""}, {"iface-set-external-id", 2, 3, cmd_iface_set_external_id, ""}, {"iface-get-external-id", 1, 2, cmd_iface_get_external_id, ""}, + + /* Controller commands. */ + {"get-controller", 0, 1, cmd_get_controller, ""}, + {"del-controller", 0, 1, cmd_del_controller, ""}, + {"set-controller", 1, 2, cmd_set_controller, ""}, + {"get-fail-mode", 0, 1, cmd_get_fail_mode, ""}, + {"del-fail-mode", 0, 1, cmd_del_fail_mode, ""}, + {"set-fail-mode", 1, 2, cmd_set_fail_mode, ""}, }; const struct vsctl_command *p;