[ovs-dev] [RFC v2 02/11] ovn: Add bridge mappings to ovn-controller.
Russell Bryant
rbryant at redhat.com
Thu Jul 16 22:06:10 UTC 2015
Add a new OVN configuration entry in the Open_vSwitch database called
"ovn-bridge-mappings". This allows the configuration of mappings
between a physical network name and an OVS bridge that provides
connectivity to that network.
For example, if you wanted to configure "physnet1" to map to "br-eth0"
and "physnet2" to map to "br-eth1", the configuration would be:
$ ovs-vsctl set open . \
> external-ids:ovn-bridge-mappings=physnet1:br-eth0,physnet2:br-eth1
In this patch, the configuration option is only parsed and validated
to make sure the referenced bridges actually exist. Later patches
will make use of the bridge mappings.
Signed-off-by: Russell Bryant <rbryant at redhat.com>
---
ovn/controller/ovn-controller.c | 61 ++++++++++++++++++++++++++++++++++++++++-
ovn/controller/ovn-controller.h | 7 +++++
2 files changed, 67 insertions(+), 1 deletion(-)
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index fda1534..31f66a9 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -33,6 +33,8 @@
#include "poll-loop.h"
#include "fatal-signal.h"
#include "lib/vswitch-idl.h"
+#include "hash.h"
+#include "hmap.h"
#include "smap.h"
#include "stream.h"
#include "stream-ssl.h"
@@ -85,6 +87,50 @@ get_bridge(struct controller_ctx *ctx, const char *name)
return NULL;
}
+static int
+parse_bridge_mappings(struct controller_ctx *ctx, const char *bridge_mappings_)
+{
+ char *cur, *next, *start;
+ int res = 0;
+
+ next = start = xstrdup(bridge_mappings_);
+
+ while ((cur = strsep(&next, ","))) {
+ char *network, *bridge = cur;
+ const struct ovsrec_bridge *ovs_bridge;
+
+ network = strsep(&bridge, ":");
+ if (!bridge || !*network || !*bridge) {
+ VLOG_ERR("Invalid ovn-bridge-mappings configuration: '%s'", bridge_mappings_);
+ res = -1;
+ break;
+ }
+
+ VLOG_DBG("Bridge mapping - network '%s' to bridge '%s'", network, bridge);
+
+ ovs_bridge = get_bridge(ctx, bridge);
+ if (!ovs_bridge) {
+ VLOG_WARN("Bridge '%s' not found for network '%s'", bridge, network);
+ res = -1;
+ break;
+ }
+
+ if (create_patch_ports(ctx, ovs_bridge)) {
+ VLOG_WARN("Failed to create patch ports between '%s' and '%s'",
+ ctx->br_int_name, bridge);
+ res = -1;
+ break;
+ }
+
+ smap_add(&ctx->localnet_mappings, network, bridge);
+ smap_add(&ctx->bridge_mappings, bridge, network);
+ }
+
+ free(start);
+
+ return res;
+}
+
/* Retrieve the OVN integration bridge from the "external-ids:ovn-bridge"
* key, the remote location from the "external-ids:ovn-remote" key, and
* the chassis name from the "external-ids:system-id" key in the
@@ -106,7 +152,7 @@ get_core_config(struct controller_ctx *ctx)
while (1) {
const struct ovsrec_bridge *br_int;
- const char *remote, *system_id, *br_int_name;
+ const char *remote, *system_id, *br_int_name, *bridge_mappings;
ovsdb_idl_run(ctx->ovs_idl);
@@ -135,6 +181,17 @@ get_core_config(struct controller_ctx *ctx)
goto try_again;
}
+ smap_init(&ctx->bridge_mappings);
+ smap_init(&ctx->localnet_mappings);
+ bridge_mappings = smap_get(&cfg->external_ids, "ovn-bridge-mappings");
+ if (bridge_mappings) {
+ int res = parse_bridge_mappings(ctx, bridge_mappings);
+ if (res) {
+ VLOG_INFO("Error parsing ovn-bridge-mappings. Waiting ...");
+ goto try_again;
+ }
+ }
+
ovnsb_remote = xstrdup(remote);
ctx->chassis_id = xstrdup(system_id);
return;
@@ -260,6 +317,8 @@ main(int argc, char *argv[])
free(ctx.chassis_id);
free(ovnsb_remote);
free(ovs_remote);
+ smap_destroy(&ctx.bridge_mappings);
+ smap_destroy(&ctx.localnet_mappings);
exit(retval);
}
diff --git a/ovn/controller/ovn-controller.h b/ovn/controller/ovn-controller.h
index 6f98658..98bf248 100644
--- a/ovn/controller/ovn-controller.h
+++ b/ovn/controller/ovn-controller.h
@@ -19,6 +19,8 @@
#include "ovn/lib/ovn-sb-idl.h"
+struct smap;
+
struct controller_ctx {
char *chassis_id; /* ID for this chassis. */
char *br_int_name; /* Name of local integration bridge. */
@@ -26,6 +28,11 @@ struct controller_ctx {
struct ovsdb_idl *ovs_idl;
const struct ovsrec_bridge *br_int;
+
+ /* Map bridges to local nets from ovn-bridge-mappings */
+ struct smap bridge_mappings;
+ /* Map local nets to bridges from ovn-bridge-mappings */
+ struct smap localnet_mappings;
};
static inline const struct sbrec_chassis *
--
2.4.3
More information about the dev
mailing list