Currently ovn-controller uses default unix domain socket in Open Vswitch's
"run" directory to connect to OpenFlow switch. If
ovn-controller/ovsdb-server and vswitchd is running on different systems,
remote connection method needs to be provided.

Added configuration option to override default connection by using OVSDB
external-ids "ovn-ofswitch-remote". Using this external-id, desired tcp
or unix connection to OpenFlow switch can be specified.

Tested this by using tcp/unix method configured through external-id
"ovn-ofswitch-remote" and confirmed connection as flows getting updated in
Open vSwitch.

Signed-off-by: Jai Singh Rana <[email protected]>
---
 ovn/controller/ofctrl.c             |  6 +++++-
 ovn/controller/ofctrl.h             |  3 ++-
 ovn/controller/ovn-controller.8.xml | 10 ++++++++++
 ovn/controller/ovn-controller.c     | 36 ++++++++++++++++++++++++++++++++++--
 ovn/controller/pinctrl.c            |  6 +++++-
 ovn/controller/pinctrl.h            |  3 ++-
 6 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/ovn/controller/ofctrl.c b/ovn/controller/ofctrl.c
index 7164ff0..02deb6d 100644
--- a/ovn/controller/ofctrl.c
+++ b/ovn/controller/ofctrl.c
@@ -456,9 +456,13 @@ recv_S_UPDATE_FLOWS(const struct ofp_header *oh, enum 
ofptype type,
  * field for class OVN_GENEVE_CLASS, type OVN_GENEVE_TYPE.  If successful,
  * returns the MFF_* field ID for the option, otherwise returns 0. */
 enum mf_field_id
-ofctrl_run(const struct ovsrec_bridge *br_int, struct shash *pending_ct_zones)
+ofctrl_run(const struct ovsrec_bridge *br_int, struct shash *pending_ct_zones,
+           char *ovn_ofswitch_remote)
 {
     char *target = xasprintf("unix:%s/%s.mgmt", ovs_rundir(), br_int->name);
+    if (ovn_ofswitch_remote) {
+        target = xasprintf(ovn_ofswitch_remote);
+    }
     if (strcmp(target, rconn_get_target(swconn))) {
         VLOG_INFO("%s: connecting to switch", target);
         rconn_connect(swconn, target, target);
diff --git a/ovn/controller/ofctrl.h b/ovn/controller/ofctrl.h
index d83f6ae..6ed14f3 100644
--- a/ovn/controller/ofctrl.h
+++ b/ovn/controller/ofctrl.h
@@ -33,7 +33,8 @@ struct shash;
 /* Interface for OVN main loop. */
 void ofctrl_init(struct group_table *group_table);
 enum mf_field_id ofctrl_run(const struct ovsrec_bridge *br_int,
-                            struct shash *pending_ct_zones);
+                            struct shash *pending_ct_zones,
+                            char *ovn_ofswitch_remote);
 bool ofctrl_can_put(void);
 void ofctrl_put(struct hmap *flow_table, struct shash *pending_ct_zones,
                 int64_t nb_cfg);
diff --git a/ovn/controller/ovn-controller.8.xml 
b/ovn/controller/ovn-controller.8.xml
index 5641abc..9cad82c 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -151,6 +151,16 @@
         network interface card, enabling encapsulation checksum may incur
         performance loss. In such cases, encapsulation checksums can be 
disabled.
       </dd>
+
+      <dt><code>external_ids:ovn-ofswitch-remote</code></dt>
+      <dd>
+        <code>ovn-ofswitch-remote</code>
+        The OpenFLow connection method that this system can connect to reach
+        Open Vswitch using the <code>unix</code> or <code>tcp</code> forms
+        documented above for the <var>ovs-database</var>. If not configured,
+        default local unix domain socket file in the local Open vSwitch's
+        "run" directory is used.
+      </dd>
     </dl>
 
     <p>
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index da3e83a..6e8f3c3 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -327,6 +327,30 @@ get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
     }
 }
 
+/* Retrieves the OVN OpenFlow switch remote location from the
+ * "external-ids:ovn-ofswitch-remote" key in 'ovs_idl' and returns
+ *  a copy of it.
+ */
+static char *
+get_ovn_ofswitch_remote(struct ovsdb_idl *ovs_idl)
+{
+    ovsdb_idl_run(ovs_idl);
+
+    const struct ovsrec_open_vswitch *cfg
+        = ovsrec_open_vswitch_first(ovs_idl);
+    if (cfg) {
+        const char *remote =
+            smap_get(&cfg->external_ids, "ovn-ofswitch-remote");
+        if (remote) {
+            return xstrdup(remote);
+        }
+    }
+
+    VLOG_INFO("OVN OVSDB OpenFlow switch remote not specified."
+              "Using default unix domain socket.");
+    return NULL;
+}
+
 static void
 update_ct_zones(struct sset *lports, const struct hmap *local_datapaths,
                 struct simap *ct_zones, unsigned long *ct_zone_bitmap,
@@ -578,6 +602,9 @@ main(int argc, char *argv[])
     update_sb_monitors(ovnsb_idl_loop.idl, NULL, NULL, NULL);
     ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);
 
+    /* Get ovn connection method to OpenFlow switch. */
+    char *ovn_ofswitch_remote = get_ovn_ofswitch_remote(ovs_idl_loop.idl);
+
     /* Initialize connection tracking zones. */
     struct simap ct_zones = SIMAP_INITIALIZER(&ct_zones);
     struct shash pending_ct_zones = SHASH_INITIALIZER(&pending_ct_zones);
@@ -656,10 +683,12 @@ main(int argc, char *argv[])
             patch_run(&ctx, br_int, chassis);
 
             enum mf_field_id mff_ovn_geneve = ofctrl_run(br_int,
-                                                         &pending_ct_zones);
+                                                         &pending_ct_zones,
+                                                         ovn_ofswitch_remote);
 
             pinctrl_run(&ctx, &lports, br_int, chassis, &chassis_index,
-                        &local_datapaths, &active_tunnels);
+                        &local_datapaths, &active_tunnels,
+                        ovn_ofswitch_remote);
             update_ct_zones(&local_lports, &local_datapaths, &ct_zones,
                             ct_zone_bitmap, &pending_ct_zones);
             if (ctx.ovs_idl_txn) {
@@ -820,6 +849,9 @@ main(int argc, char *argv[])
 
     free(ovnsb_remote);
     free(ovs_remote);
+    if (ovn_ofswitch_remote) {
+        free(ovn_ofswitch_remote);
+    }
     service_stop();
 
     exit(retval);
diff --git a/ovn/controller/pinctrl.c b/ovn/controller/pinctrl.c
index 3d43631..ac6973c 100644
--- a/ovn/controller/pinctrl.c
+++ b/ovn/controller/pinctrl.c
@@ -1026,9 +1026,13 @@ pinctrl_run(struct controller_ctx *ctx, const struct 
lport_index *lports,
             const struct sbrec_chassis *chassis,
             const struct chassis_index *chassis_index,
             struct hmap *local_datapaths,
-            struct sset *active_tunnels)
+            struct sset *active_tunnels,
+            char *ovn_ofswitch_remote)
 {
     char *target = xasprintf("unix:%s/%s.mgmt", ovs_rundir(), br_int->name);
+    if (ovn_ofswitch_remote) {
+        target = xasprintf(ovn_ofswitch_remote);
+    }
     if (strcmp(target, rconn_get_target(swconn))) {
         VLOG_INFO("%s: connecting to switch", target);
         rconn_connect(swconn, target, target);
diff --git a/ovn/controller/pinctrl.h b/ovn/controller/pinctrl.h
index 913c170..0b8a278 100644
--- a/ovn/controller/pinctrl.h
+++ b/ovn/controller/pinctrl.h
@@ -33,7 +33,8 @@ void pinctrl_init(void);
 void pinctrl_run(struct controller_ctx *, const struct lport_index *,
                  const struct ovsrec_bridge *, const struct sbrec_chassis *,
                  const struct chassis_index *, struct hmap *local_datapaths,
-                 struct sset *active_tunnels);
+                 struct sset *active_tunnels,
+                 char *ovn_ofswitch_remote);
 void pinctrl_wait(struct controller_ctx *);
 void pinctrl_destroy(void);
 
-- 
1.8.3.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to