[ovs-dev] [PATCH 1/4] ovn : Setup a controller for br-int

Babu Shanmugam bschanmu at redhat.com
Fri Oct 23 07:42:50 UTC 2015


This patch configures the ovs records for a new controller to br-int
and an endpoint for the new controller

Signed-off-by: Babu Shanmugam <bschanmu at redhat.com>
---
  ovn/controller/ovn-controller.c | 62 
+++++++++++++++++++++++++++++++++++++++--
  1 file changed, 59 insertions(+), 3 deletions(-)

diff --git a/ovn/controller/ovn-controller.c 
b/ovn/controller/ovn-controller.c
index 3f29b25..343de28 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -21,6 +21,7 @@
  #include <getopt.h>
  #include <signal.h>
  #include <stdlib.h>
+#include <unistd.h>
  #include <string.h>

  #include "command-line.h"
@@ -56,6 +57,7 @@ static unixctl_cb_func ct_zone_list;
  #define DEFAULT_BRIDGE_NAME "br-int"

  static void parse_options(int argc, char *argv[]);
+static char const *get_switch_controller_path(void);
  OVS_NO_RETURN static void usage(void);

  static char *ovs_remote;
@@ -100,10 +102,58 @@ get_bridge(struct ovsdb_idl *ovs_idl, const char 
*br_name)
      return NULL;
  }

+static char const *
+get_switch_controller_path(void)
+{
+    static char *path = NULL;
+
+    if (!path) {
+        path = xasprintf("%s/%s.%ld.sock",
+                         ovs_rundir(), "ovn-controller", (long int) 
getpid());
+    }
+    return path;
+}
+
+static void
+ovs_bridge_set_controller(struct controller_ctx *ctx,
+                          struct ovsrec_bridge const *br)
+{
+    struct ovsrec_controller *controller;
+    struct ovsdb_datum const *bctrl, *target;
+    bool set = false;
+    static char *proto = NULL;
+
+    if (!proto) {
+        proto = xasprintf("unix:%s", get_switch_controller_path());
+    }
+
+    if (!br || !ctx || !ctx->ovs_idl_txn || !ctx->ovs_idl) {
+        return;
+    }
+
+    bctrl = ovsrec_bridge_get_controller(br, OVSDB_TYPE_UUID);
+    if (bctrl && bctrl->n > 0) {
+        struct ovsrec_controller const *ctrler;
+
+        ctrler =
+            ovsrec_controller_get_for_uuid(ctx->ovs_idl, 
&bctrl->keys[0].uuid);
+        target = ovsrec_controller_get_target(ctrler, OVSDB_TYPE_STRING);
+        if (strcmp(target->keys[0].string, proto) != 0) {
+            set = true;
+        }
+    } else {
+        set = true;
+    }
+    if (set) {
+        controller = ovsrec_controller_insert(ctx->ovs_idl_txn);
+        ovsrec_controller_set_target(controller, proto);
+        ovsrec_bridge_set_controller(br, &controller, 1);
+    }
+}
+
  static const struct ovsrec_bridge *
  create_br_int(struct controller_ctx *ctx,
-              const struct ovsrec_open_vswitch *cfg,
-              const char *bridge_name)
+              const struct ovsrec_open_vswitch *cfg, const char 
*bridge_name)
  {
      if (!ctx->ovs_idl_txn) {
          return NULL;
@@ -158,8 +208,9 @@ get_br_int(struct controller_ctx *ctx)
      const struct ovsrec_bridge *br;
      br = get_bridge(ctx->ovs_idl, br_int_name);
      if (!br) {
-        return create_br_int(ctx, cfg, br_int_name);
+        br = create_br_int(ctx, cfg, br_int_name);
      }
+    ovs_bridge_set_controller(ctx, br);
      return br;
  }

@@ -246,6 +297,11 @@ main(int argc, char *argv[])
      ovsdb_idl_add_column(ovs_idl_loop.idl, &ovsrec_bridge_col_name);
      ovsdb_idl_add_column(ovs_idl_loop.idl, &ovsrec_bridge_col_fail_mode);
      ovsdb_idl_add_column(ovs_idl_loop.idl, 
&ovsrec_bridge_col_other_config);
+    ovsdb_idl_add_column(ovs_idl_loop.idl, &ovsrec_bridge_col_controller);
+    ovsdb_idl_add_table(ovs_idl_loop.idl, &ovsrec_table_controller);
+    ovsdb_idl_add_column(ovs_idl_loop.idl, &ovsrec_controller_col_target);
+    ovsdb_idl_add_column(ovs_idl_loop.idl,
+                         &ovsrec_controller_col_is_connected);
      chassis_register_ovs_idl(ovs_idl_loop.idl);
      encaps_register_ovs_idl(ovs_idl_loop.idl);
      binding_register_ovs_idl(ovs_idl_loop.idl);
-- 
1.9.1




More information about the dev mailing list