ovn: Add ovn-bridge-mappings to Chassis external_ids.
authorRussell Bryant <russell@ovn.org>
Mon, 28 Mar 2016 19:10:21 +0000 (15:10 -0400)
committerRussell Bryant <russell@ovn.org>
Tue, 29 Mar 2016 17:28:16 +0000 (10:28 -0700)
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>
ovn/controller/chassis.c
ovn/ovn-sb.xml
tests/ovn-controller.at

index 52c9993..d40181b 100644 (file)
@@ -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);
index d68f3f6..321bf5b 100644 (file)
       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.
index 971ea1e..4bee3ca 100644 (file)
@@ -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'