ovn-controller: Make integration bridge config part of general context.
authorJustin Pettit <jpettit@nicira.com>
Fri, 24 Apr 2015 22:44:58 +0000 (15:44 -0700)
committerJustin Pettit <jpettit@nicira.com>
Fri, 1 May 2015 06:08:12 +0000 (23:08 -0700)
The integration bridge will be needed by other components soon, so make
it part of the general ovn-controller context.

Signed-off-by: Justin Pettit <jpettit@nicira.com>
Acked-by: Russell Bryant <rbryant@redhat.com>
Acked-by: Ben Pfaff <blp@nicira.com>
ovn/controller/bindings.c
ovn/controller/ovn-controller.c
ovn/controller/ovn-controller.h

index 746110e..dcaee6c 100644 (file)
@@ -25,8 +25,6 @@
 
 VLOG_DEFINE_THIS_MODULE(bindings);
 
-#define DEFAULT_BRIDGE_NAME "br-int"
-
 void
 bindings_init(struct controller_ctx *ctx)
 {
@@ -49,39 +47,14 @@ bindings_init(struct controller_ctx *ctx)
 static void
 get_local_iface_ids(struct controller_ctx *ctx, struct sset *lports)
 {
-    const struct ovsrec_open_vswitch *cfg;
-    const struct ovsrec_bridge *bridge_rec;
-    const char *bridge_name;
     int i;
 
-    cfg = ovsrec_open_vswitch_first(ctx->ovs_idl);
-    if (!cfg) {
-        VLOG_INFO("No Open_vSwitch row defined.");
-        return;
-    }
-
-    bridge_name = smap_get(&cfg->external_ids, "ovn-bridge");
-    if (!bridge_name) {
-        bridge_name = DEFAULT_BRIDGE_NAME;
-    }
-
-    OVSREC_BRIDGE_FOR_EACH(bridge_rec, ctx->ovs_idl) {
-        if (!strcmp(bridge_rec->name, bridge_name)) {
-            break;
-        }
-    }
-
-    if (!bridge_rec) {
-        VLOG_INFO("Could not find bridge '%s'", bridge_name);
-        return;
-    }
-
-    for (i = 0; i < bridge_rec->n_ports; i++) {
-        const struct ovsrec_port *port_rec = bridge_rec->ports[i];
+    for (i = 0; i < ctx->br_int->n_ports; i++) {
+        const struct ovsrec_port *port_rec = ctx->br_int->ports[i];
         const char *iface_id;
         int j;
 
-        if (!strcmp(port_rec->name, bridge_rec->name)) {
+        if (!strcmp(port_rec->name, ctx->br_int_name)) {
             continue;
         }
 
index 44a4d5e..743e6bf 100644 (file)
@@ -45,6 +45,8 @@ VLOG_DEFINE_THIS_MODULE(main);
 
 static unixctl_cb_func ovn_controller_exit;
 
+#define DEFAULT_BRIDGE_NAME "br-int"
+
 static void parse_options(int argc, char *argv[]);
 OVS_NO_RETURN static void usage(void);
 
@@ -65,8 +67,23 @@ get_initial_snapshot(struct ovsdb_idl *idl)
     }
 }
 
-/* Retrieve the OVN remote location from the "external-ids:ovn-remote"
- * key and the chassis name from the "external-ids:system-id" key in the
+static const struct ovsrec_bridge *
+get_bridge(struct controller_ctx *ctx, const char *name)
+{
+    const struct ovsrec_bridge *br;
+
+    OVSREC_BRIDGE_FOR_EACH(br, ctx->ovs_idl) {
+        if (!strcmp(br->name, name)) {
+            return br;
+        }
+    }
+
+    return NULL;
+}
+
+/* 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
  * Open_vSwitch table of the OVS database instance. */
 static void
 get_core_config(struct controller_ctx *ctx)
@@ -81,10 +98,23 @@ get_core_config(struct controller_ctx *ctx)
     }
 
     while (1) {
+        const struct ovsrec_bridge *br_int;
         const char *remote, *system_id;
 
         ovsdb_idl_run(ctx->ovs_idl);
 
+        ctx->br_int_name = smap_get(&cfg->external_ids, "ovn-bridge");
+        if (!ctx->br_int_name) {
+            ctx->br_int_name = DEFAULT_BRIDGE_NAME;
+        }
+
+        br_int = get_bridge(ctx, ctx->br_int_name);
+        if (!br_int) {
+            VLOG_INFO("Integration bridge '%s' does not exist.  Waiting...",
+                      ctx->br_int_name);
+            goto try_again;
+        }
+
         /* xxx This does not support changing OVN Southbound OVSDB mid-run. */
         remote = smap_get(&cfg->external_ids, "ovn-remote");
         if (!remote) {
@@ -161,6 +191,16 @@ main(int argc, char *argv[])
         ovsdb_idl_run(ctx.ovs_idl);
         ovsdb_idl_run(ctx.ovnsb_idl);
 
+        /* xxx If run into any surprising changes, we exit.  We should
+         * xxx handle this more gracefully. */
+        ctx.br_int = get_bridge(&ctx, ctx.br_int_name);
+        if (!ctx.br_int) {
+            VLOG_ERR("Integration bridge '%s' disappeared",
+                     ctx.br_int_name);
+            retval = EXIT_FAILURE;
+            break;
+        }
+
         if (!ovsdb_idl_is_alive(ctx.ovnsb_idl)) {
             int retval = ovsdb_idl_get_last_error(ctx.ovnsb_idl);
             VLOG_ERR("%s: database connection failed (%s)",
index c701edc..e22c265 100644 (file)
 #define OVN_CONTROLLER_H 1
 
 struct controller_ctx {
-    char *chassis_name;
+    char *chassis_name;             /* Name for this chassis. */
+    const char *br_int_name;        /* Name of local integration bridge. */
     struct ovsdb_idl *ovnsb_idl;
     struct ovsdb_idl *ovs_idl;
+
+    const struct ovsrec_bridge *br_int;
 };
 
 #endif /* ovn/ovn-controller.h */