From: Justin Pettit <jpet...@nicira.com> 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 <jpet...@nicira.com> Signed-off-by: Ben Pfaff <b...@nicira.com> --- ovn/controller/bindings.c | 33 +++---------------------------- ovn/controller/ovn-controller.c | 44 ++++++++++++++++++++++++++++++++++++++--- ovn/controller/ovn-controller.h | 5 ++++- 3 files changed, 48 insertions(+), 34 deletions(-) diff --git a/ovn/controller/bindings.c b/ovn/controller/bindings.c index 746110e..dcaee6c 100644 --- a/ovn/controller/bindings.c +++ b/ovn/controller/bindings.c @@ -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; } diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c index cfc562c..12931b5 100644 --- a/ovn/controller/ovn-controller.c +++ b/ovn/controller/ovn-controller.c @@ -46,6 +46,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); @@ -66,8 +68,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) @@ -82,10 +99,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) { @@ -114,7 +144,7 @@ int main(int argc, char *argv[]) { struct unixctl_server *unixctl; - struct controller_ctx ctx = { .chassis_name = NULL }; + struct controller_ctx ctx = { .chassis_name = NULL, .br_int_name = NULL }; bool exiting; int retval; @@ -163,6 +193,14 @@ main(int argc, char *argv[]) ovsdb_idl_run(ctx.ovs_idl); ovsdb_idl_run(ctx.ovnsb_idl); + 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)", diff --git a/ovn/controller/ovn-controller.h b/ovn/controller/ovn-controller.h index c701edc..e22c265 100644 --- a/ovn/controller/ovn-controller.h +++ b/ovn/controller/ovn-controller.h @@ -18,9 +18,12 @@ #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 */ -- 2.1.3 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev