summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Bryant <russell@ovn.org>2016-03-28 15:10:21 -0400
committerRussell Bryant <russell@ovn.org>2016-03-29 10:28:16 -0700
commit4250ee37d23c601e84e2db12e317dc4bc9e75d0c (patch)
treed877a203c838f1b2a5b8c808d1581fc7599bdc3a
parentd87e05ff94b7de0db39ce3c589036236041ac8fc (diff)
downloadopenvswitch-4250ee37d23c601e84e2db12e317dc4bc9e75d0c.tar.gz
ovn: Add ovn-bridge-mappings to Chassis external_ids.
Publish ovn-controller's local bridge mappings configuration in the external_ids column of the Chassis table. Having this information available for reading is useful to applications integrating with OVN. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
-rw-r--r--ovn/controller/chassis.c24
-rw-r--r--ovn/ovn-sb.xml7
-rw-r--r--tests/ovn-controller.at13
3 files changed, 44 insertions, 0 deletions
diff --git a/ovn/controller/chassis.c b/ovn/controller/chassis.c
index 52c9993c2..d40181b72 100644
--- a/ovn/controller/chassis.c
+++ b/ovn/controller/chassis.c
@@ -18,6 +18,7 @@
#include "chassis.h"
+#include "lib/smap.h"
#include "lib/vswitch-idl.h"
#include "openvswitch/dynamic-string.h"
#include "openvswitch/vlog.h"
@@ -55,6 +56,13 @@ pop_tunnel_name(uint32_t *type)
OVS_NOT_REACHED();
}
+static const char *
+get_bridge_mappings(const struct smap *ext_ids)
+{
+ const char *bridge_mappings = smap_get(ext_ids, "ovn-bridge-mappings");
+ return bridge_mappings ? bridge_mappings : "";
+}
+
void
chassis_run(struct controller_ctx *ctx, const char *chassis_id)
{
@@ -102,6 +110,8 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
hostname = hostname_;
}
+ const char *bridge_mappings = get_bridge_mappings(&cfg->external_ids);
+
const struct sbrec_chassis *chassis_rec
= get_chassis(ctx->ovnsb_idl, chassis_id);
@@ -110,6 +120,17 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
sbrec_chassis_set_hostname(chassis_rec, hostname);
}
+ const char *chassis_bridge_mappings
+ = get_bridge_mappings(&chassis_rec->external_ids);
+ if (strcmp(bridge_mappings, chassis_bridge_mappings)) {
+ struct smap new_ids;
+ smap_clone(&new_ids, &chassis_rec->external_ids);
+ smap_replace(&new_ids, "ovn-bridge-mappings", bridge_mappings);
+ sbrec_chassis_verify_external_ids(chassis_rec);
+ sbrec_chassis_set_external_ids(chassis_rec, &new_ids);
+ smap_destroy(&new_ids);
+ }
+
/* Compare desired tunnels against those currently in the database. */
uint32_t cur_tunnels = 0;
bool same = true;
@@ -145,9 +166,12 @@ chassis_run(struct controller_ctx *ctx, const char *chassis_id)
chassis_id);
if (!chassis_rec) {
+ struct smap ext_ids = SMAP_CONST1(&ext_ids, "ovn-bridge-mappings",
+ bridge_mappings);
chassis_rec = sbrec_chassis_insert(ctx->ovnsb_idl_txn);
sbrec_chassis_set_name(chassis_rec, chassis_id);
sbrec_chassis_set_hostname(chassis_rec, hostname);
+ sbrec_chassis_set_external_ids(chassis_rec, &ext_ids);
}
int n_encaps = count_1bits(req_tunnels);
diff --git a/ovn/ovn-sb.xml b/ovn/ovn-sb.xml
index d68f3f6b9..321bf5b53 100644
--- a/ovn/ovn-sb.xml
+++ b/ovn/ovn-sb.xml
@@ -172,6 +172,13 @@
ovn-controller-vtep will leave this column empty.
</column>
+ <column name="external_ids" key="ovn-bridge-mappings">
+ <code>ovn-controller</code> populates this key with the set of bridge
+ mappings it has been configured to use. Other applications should treat
+ this key as read-only. See <code>ovn-controller</code>(8) for more
+ information.
+ </column>
+
<group title="Common Columns">
The overall purpose of these columns is described under <code>Common
Columns</code> at the beginning of this document.
diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
index 971ea1e04..4bee3ca41 100644
--- a/tests/ovn-controller.at
+++ b/tests/ovn-controller.at
@@ -46,11 +46,23 @@ patch
diff -u stdout expout >/dev/null])
}
+# Make sure that the configured bridge mappings in the Open_vSwitch db
+# is mirrored into the Chassis record in the OVN_Southbound db.
+check_bridge_mappings () {
+ local_mappings=$1
+ sysid=$(ovs-vsctl get Open_vSwitch . external_ids:system-id)
+ chassis_mappings=$(ovn-sbctl get Chassis ${sysid} external_ids:ovn-bridge-mappings | sed -e 's/\"//g')
+ echo $local_mappings
+ echo $chassis_mappings
+ AT_CHECK([test "${local_mappings}" = "${chassis_mappings}"])
+}
+
# Initially there should be no patch ports.
check_patches
# Configure two ovn-bridge mappings, but no patch ports should be created yet
AT_CHECK([ovs-vsctl set Open_vSwitch . external-ids:ovn-bridge-mappings=physnet1:br-eth0,physnet2:br-eth1])
+check_bridge_mappings "physnet1:br-eth0,physnet2:br-eth1"
check_patches
# Create a localnet port, but we should still have no patch ports, as they
@@ -94,6 +106,7 @@ check_patches \
# Delete the mapping and the ovn-bridge-mapping patch ports should go away;
# the ones from the logical patch port remain.
AT_CHECK([ovs-vsctl remove Open_vSwitch . external-ids ovn-bridge-mappings])
+check_bridge_mappings
check_patches \
'br-int patch-foo-to-bar patch-bar-to-foo' \
'br-int patch-bar-to-foo patch-foo-to-bar'