summaryrefslogtreecommitdiff
path: root/ofproto
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-03-15 09:46:39 -0700
committerBen Pfaff <blp@nicira.com>2011-03-16 14:57:56 -0700
commit195c8086244e33ec42fd9fc8354eaedfd849bbba (patch)
tree2b6abbef405fbc05c6db9f0c1ef4dd08ea67470c /ofproto
parent9b45d7f5db91cdb41eb0a2124d92885d3b3edcc9 (diff)
downloadopenvswitch-195c8086244e33ec42fd9fc8354eaedfd849bbba.tar.gz
ofproto: Remove controller discovery support.
I've never heard of anyone actually using controller discovery. It adds a great deal of code to the source tree, and a little bit of complication to ofproto, so this commit removes it.
Diffstat (limited to 'ofproto')
-rw-r--r--ofproto/automake.mk2
-rw-r--r--ofproto/discovery.c243
-rw-r--r--ofproto/discovery.h38
-rw-r--r--ofproto/ofproto.c90
-rw-r--r--ofproto/ofproto.h6
5 files changed, 13 insertions, 366 deletions
diff --git a/ofproto/automake.mk b/ofproto/automake.mk
index c6cb9dd49..6484a2695 100644
--- a/ofproto/automake.mk
+++ b/ofproto/automake.mk
@@ -9,8 +9,6 @@ noinst_LIBRARIES += ofproto/libofproto.a
ofproto_libofproto_a_SOURCES = \
ofproto/collectors.c \
ofproto/collectors.h \
- ofproto/discovery.c \
- ofproto/discovery.h \
ofproto/fail-open.c \
ofproto/fail-open.h \
ofproto/in-band.c \
diff --git a/ofproto/discovery.c b/ofproto/discovery.c
deleted file mode 100644
index ba489ffd8..000000000
--- a/ofproto/discovery.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <config.h>
-#include "discovery.h"
-#include <errno.h>
-#include <inttypes.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <regex.h>
-#include <stdlib.h>
-#include <string.h>
-#include "dhcp-client.h"
-#include "dhcp.h"
-#include "dpif.h"
-#include "netdev.h"
-#include "openflow/openflow.h"
-#include "packets.h"
-#include "stream-ssl.h"
-#include "vlog.h"
-
-VLOG_DEFINE_THIS_MODULE(discovery);
-
-struct discovery {
- char *dpif_name;
- char *re;
- bool update_resolv_conf;
- regex_t *regex;
- struct dhclient *dhcp;
- int n_changes;
-};
-
-static void modify_dhcp_request(struct dhcp_msg *, void *aux);
-static bool validate_dhcp_offer(const struct dhcp_msg *, void *aux);
-
-static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(60, 60);
-
-int
-discovery_create(const char *re, bool update_resolv_conf,
- struct dpif *dpif, struct discovery **discoveryp)
-{
- struct discovery *d;
- char local_name[IF_NAMESIZE];
- int error;
-
- d = xzalloc(sizeof *d);
-
- d->dpif_name = xstrdup(dpif_base_name(dpif));
-
- /* Controller regular expression. */
- error = discovery_set_accept_controller_re(d, re);
- if (error) {
- goto error_free;
- }
- d->update_resolv_conf = update_resolv_conf;
-
- /* Initialize DHCP client. */
- error = dpif_port_get_name(dpif, ODPP_LOCAL,
- local_name, sizeof local_name);
- if (error) {
- VLOG_ERR("%s: failed to query datapath local port: %s",
- d->dpif_name, strerror(error));
- goto error_regfree;
- }
- error = dhclient_create(local_name, modify_dhcp_request,
- validate_dhcp_offer, d, &d->dhcp);
- if (error) {
- VLOG_ERR("%s: failed to initialize DHCP client: %s",
- d->dpif_name, strerror(error));
- goto error_regfree;
- }
- dhclient_set_max_timeout(d->dhcp, 3);
- dhclient_init(d->dhcp, 0);
-
- *discoveryp = d;
- return 0;
-
-error_regfree:
- regfree(d->regex);
- free(d->regex);
-error_free:
- free(d->dpif_name);
- free(d);
- *discoveryp = 0;
- return error;
-}
-
-void
-discovery_destroy(struct discovery *d)
-{
- if (d) {
- free(d->re);
- regfree(d->regex);
- free(d->regex);
- dhclient_destroy(d->dhcp);
- free(d->dpif_name);
- free(d);
- }
-}
-
-bool
-discovery_get_update_resolv_conf(const struct discovery *d)
-{
- return d->update_resolv_conf;
-}
-
-void
-discovery_set_update_resolv_conf(struct discovery *d,
- bool update_resolv_conf)
-{
- d->update_resolv_conf = update_resolv_conf;
-}
-
-const char *
-discovery_get_accept_controller_re(const struct discovery *d)
-{
- return d->re;
-}
-
-int
-discovery_set_accept_controller_re(struct discovery *d, const char *re_)
-{
- regex_t *regex;
- int error;
- char *re;
-
- re = (!re_ ? xstrdup(stream_ssl_is_configured() ? "^ssl:.*" : "^tcp:.*")
- : re_[0] == '^' ? xstrdup(re_) : xasprintf("^%s", re_));
- regex = xmalloc(sizeof *regex);
- error = regcomp(regex, re, REG_NOSUB | REG_EXTENDED);
- if (error) {
- size_t length = regerror(error, regex, NULL, 0);
- char *buffer = xmalloc(length);
- regerror(error, regex, buffer, length);
- VLOG_WARN("%s: %s: %s", d->dpif_name, re, buffer);
- free(buffer);
- free(regex);
- free(re);
- return EINVAL;
- } else {
- if (d->regex) {
- regfree(d->regex);
- free(d->regex);
- }
- free(d->re);
-
- d->regex = regex;
- d->re = re;
- return 0;
- }
-}
-
-void
-discovery_question_connectivity(struct discovery *d)
-{
- if (d->dhcp) {
- dhclient_force_renew(d->dhcp, 15);
- }
-}
-
-bool
-discovery_run(struct discovery *d, char **controller_name)
-{
- if (!d->dhcp) {
- *controller_name = NULL;
- return true;
- }
-
- dhclient_run(d->dhcp);
- if (!dhclient_changed(d->dhcp)) {
- return false;
- }
-
- dhclient_configure_netdev(d->dhcp);
- if (d->update_resolv_conf) {
- dhclient_update_resolv_conf(d->dhcp);
- }
-
- if (dhclient_is_bound(d->dhcp)) {
- *controller_name = dhcp_msg_get_string(dhclient_get_config(d->dhcp),
- DHCP_CODE_OFP_CONTROLLER_VCONN);
- VLOG_INFO("%s: discovered controller %s",
- d->dpif_name, *controller_name);
- d->n_changes++;
- } else {
- *controller_name = NULL;
- if (d->n_changes) {
- VLOG_INFO("%s: discovered controller no longer available",
- d->dpif_name);
- d->n_changes++;
- }
- }
- return true;
-}
-
-void
-discovery_wait(struct discovery *d)
-{
- if (d->dhcp) {
- dhclient_wait(d->dhcp);
- }
-}
-
-static void
-modify_dhcp_request(struct dhcp_msg *msg, void *aux OVS_UNUSED)
-{
- dhcp_msg_put_string(msg, DHCP_CODE_VENDOR_CLASS, "OpenFlow");
-}
-
-static bool
-validate_dhcp_offer(const struct dhcp_msg *msg, void *d_)
-{
- const struct discovery *d = d_;
- char *vconn_name;
- bool accept;
-
- vconn_name = dhcp_msg_get_string(msg, DHCP_CODE_OFP_CONTROLLER_VCONN);
- if (!vconn_name) {
- VLOG_WARN_RL(&rl, "%s: rejecting DHCP offer missing controller vconn",
- d->dpif_name);
- return false;
- }
- accept = !regexec(d->regex, vconn_name, 0, NULL, 0);
- if (!accept) {
- VLOG_WARN_RL(&rl, "%s: rejecting controller vconn that fails to "
- "match %s", d->dpif_name, d->re);
- }
- free(vconn_name);
- return accept;
-}
diff --git a/ofproto/discovery.h b/ofproto/discovery.h
deleted file mode 100644
index 999a603f5..000000000
--- a/ofproto/discovery.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef DISCOVERY_H
-#define DISCOVERY_H 1
-
-#include <stdbool.h>
-
-struct dpif;
-struct discovery;
-struct settings;
-
-int discovery_create(const char *accept_controller_re, bool update_resolv_conf,
- struct dpif *, struct discovery **);
-void discovery_destroy(struct discovery *);
-bool discovery_get_update_resolv_conf(const struct discovery *);
-void discovery_set_update_resolv_conf(struct discovery *,
- bool update_resolv_conf);
-const char *discovery_get_accept_controller_re(const struct discovery *);
-int discovery_set_accept_controller_re(struct discovery *, const char *re);
-void discovery_question_connectivity(struct discovery *);
-bool discovery_run(struct discovery *, char **controller_name);
-void discovery_wait(struct discovery *);
-
-#endif /* discovery.h */
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index ffeb95248..f4b64f881 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -27,7 +27,6 @@
#include "byte-order.h"
#include "classifier.h"
#include "coverage.h"
-#include "discovery.h"
#include "dpif.h"
#include "dynamic-string.h"
#include "fail-open.h"
@@ -332,7 +331,6 @@ struct ofconn {
/* type == OFCONN_PRIMARY only. */
enum nx_role role; /* Role. */
struct hmap_node hmap_node; /* In struct ofproto's "controllers" map. */
- struct discovery *discovery; /* Controller discovery object, if enabled. */
enum ofproto_band band; /* In-band or out-of-band? */
};
@@ -544,81 +542,47 @@ ofproto_set_datapath_id(struct ofproto *p, uint64_t datapath_id)
}
}
-static bool
-is_discovery_controller(const struct ofproto_controller *c)
-{
- return !strcmp(c->target, "discover");
-}
-
-static bool
-is_in_band_controller(const struct ofproto_controller *c)
-{
- return is_discovery_controller(c) || c->band == OFPROTO_IN_BAND;
-}
-
/* Creates a new controller in 'ofproto'. Some of the settings are initially
* drawn from 'c', but update_controller() needs to be called later to finish
* the new ofconn's configuration. */
static void
add_controller(struct ofproto *ofproto, const struct ofproto_controller *c)
{
- struct discovery *discovery;
+ char *name = ofconn_make_name(ofproto, c->target);
struct ofconn *ofconn;
- if (is_discovery_controller(c)) {
- int error = discovery_create(c->accept_re, c->update_resolv_conf,
- ofproto->dpif, &discovery);
- if (error) {
- return;
- }
- } else {
- discovery = NULL;
- }
-
ofconn = ofconn_create(ofproto, rconn_create(5, 8), OFCONN_PRIMARY);
ofconn->pktbuf = pktbuf_create();
ofconn->miss_send_len = OFP_DEFAULT_MISS_SEND_LEN;
- if (discovery) {
- ofconn->discovery = discovery;
- } else {
- char *name = ofconn_make_name(ofproto, c->target);
- rconn_connect(ofconn->rconn, c->target, name);
- free(name);
- }
+ rconn_connect(ofconn->rconn, c->target, name);
hmap_insert(&ofproto->controllers, &ofconn->hmap_node,
hash_string(c->target, 0));
+
+ free(name);
}
/* Reconfigures 'ofconn' to match 'c'. This function cannot update an ofconn's
- * target or turn discovery on or off (these are done by creating new ofconns
- * and deleting old ones), but it can update the rest of an ofconn's
- * settings. */
+ * target (this is done by creating new ofconns and deleting old ones), but it
+ * can update the rest of an ofconn's settings. */
static void
update_controller(struct ofconn *ofconn, const struct ofproto_controller *c)
{
int probe_interval;
- ofconn->band = (is_in_band_controller(c)
- ? OFPROTO_IN_BAND : OFPROTO_OUT_OF_BAND);
+ ofconn->band = c->band;
rconn_set_max_backoff(ofconn->rconn, c->max_backoff);
probe_interval = c->probe_interval ? MAX(c->probe_interval, 5) : 0;
rconn_set_probe_interval(ofconn->rconn, probe_interval);
- if (ofconn->discovery) {
- discovery_set_update_resolv_conf(ofconn->discovery,
- c->update_resolv_conf);
- discovery_set_accept_controller_re(ofconn->discovery, c->accept_re);
- }
-
ofconn_set_rate_limit(ofconn, c->rate_limit, c->burst_limit);
}
static const char *
ofconn_get_target(const struct ofconn *ofconn)
{
- return ofconn->discovery ? "discover" : rconn_get_target(ofconn->rconn);
+ return rconn_get_target(ofconn->rconn);
}
static struct ofconn *
@@ -641,7 +605,6 @@ update_in_band_remotes(struct ofproto *ofproto)
const struct ofconn *ofconn;
struct sockaddr_in *addrs;
size_t max_addrs, n_addrs;
- bool discovery;
size_t i;
/* Allocate enough memory for as many remotes as we could possibly have. */
@@ -650,7 +613,6 @@ update_in_band_remotes(struct ofproto *ofproto)
n_addrs = 0;
/* Add all the remotes. */
- discovery = false;
HMAP_FOR_EACH (ofconn, hmap_node, &ofproto->controllers) {
struct sockaddr_in *sin = &addrs[n_addrs];
@@ -663,20 +625,13 @@ update_in_band_remotes(struct ofproto *ofproto)
sin->sin_port = rconn_get_remote_port(ofconn->rconn);
n_addrs++;
}
- if (ofconn->discovery) {
- discovery = true;
- }
}
for (i = 0; i < ofproto->n_extra_remotes; i++) {
addrs[n_addrs++] = ofproto->extra_in_band_remotes[i];
}
- /* Create or update or destroy in-band.
- *
- * Ordinarily we only enable in-band if there's at least one remote
- * address, but discovery needs the in-band rules for DHCP to be installed
- * even before we know any remote addresses. */
- if (n_addrs || discovery) {
+ /* Create or update or destroy in-band. */
+ if (n_addrs) {
if (!ofproto->in_band) {
in_band_create(ofproto, ofproto->dpif, &ofproto->in_band);
}
@@ -738,7 +693,7 @@ ofproto_set_controllers(struct ofproto *p,
for (i = 0; i < n_controllers; i++) {
const struct ofproto_controller *c = &controllers[i];
- if (!vconn_verify_name(c->target) || !strcmp(c->target, "discover")) {
+ if (!vconn_verify_name(c->target)) {
if (!find_controller_by_target(p, c->target)) {
add_controller(p, c);
}
@@ -1821,7 +1776,6 @@ ofconn_destroy(struct ofconn *ofconn)
if (ofconn->type == OFCONN_PRIMARY) {
hmap_remove(&ofconn->ofproto->controllers, &ofconn->hmap_node);
}
- discovery_destroy(ofconn->discovery);
list_remove(&ofconn->node);
rconn_destroy(ofconn->rconn);
@@ -1838,23 +1792,6 @@ ofconn_run(struct ofconn *ofconn)
int iteration;
size_t i;
- if (ofconn->discovery) {
- char *controller_name;
- if (rconn_is_connectivity_questionable(ofconn->rconn)) {
- discovery_question_connectivity(ofconn->discovery);
- }
- if (discovery_run(ofconn->discovery, &controller_name)) {
- if (controller_name) {
- char *ofconn_name = ofconn_make_name(p, controller_name);
- rconn_connect(ofconn->rconn, controller_name, ofconn_name);
- free(ofconn_name);
- free(controller_name);
- } else {
- rconn_disconnect(ofconn->rconn);
- }
- }
- }
-
for (i = 0; i < N_SCHEDULERS; i++) {
pinsched_run(ofconn->schedulers[i], do_send_packet_in, ofconn);
}
@@ -1877,7 +1814,7 @@ ofconn_run(struct ofconn *ofconn)
}
}
- if (!ofconn->discovery && !rconn_is_alive(ofconn->rconn)) {
+ if (!rconn_is_alive(ofconn->rconn)) {
ofconn_destroy(ofconn);
}
}
@@ -1887,9 +1824,6 @@ ofconn_wait(struct ofconn *ofconn)
{
int i;
- if (ofconn->discovery) {
- discovery_wait(ofconn->discovery);
- }
for (i = 0; i < N_SCHEDULERS; i++) {
pinsched_wait(ofconn->schedulers[i]);
}
diff --git a/ofproto/ofproto.h b/ofproto/ofproto.h
index a32b9b911..93763b5c5 100644
--- a/ofproto/ofproto.h
+++ b/ofproto/ofproto.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,10 +81,6 @@ struct ofproto_controller {
int probe_interval; /* Max idle time before probing, in seconds. */
enum ofproto_band band; /* In-band or out-of-band? */
- /* Discovery options. */
- char *accept_re; /* Regexp for acceptable controllers. */
- bool update_resolv_conf; /* Update /etc/resolv.conf? */
-
/* OpenFlow packet-in rate-limiting. */
int rate_limit; /* Max packet-in rate in packets per second. */
int burst_limit; /* Limit on accumulating packet credits. */