Configure ovn-controller SB probe_timer on the fly and disable other unix 
domain socket based connections
    
    There are four sessions established from ovn-controller to the following:
    OVN Southbound — JSONRPC based
    Local ovsdb — JSONRPC based
    Local vswitchd — openflow based from ofctrl
    Local vswitchd — openflow based from pinctrl
    
    All of these sessions have their own probe_interval, and currently only one
    [SB] of them can be configured using ovn-vsctl command, and that is not
    effective on the fly —in other words, ovn-controller has to be restarted to
    use that probe_timer value. For the rest, probe timers need to be disabled
    as they are over unix domain socket. ovsdb was already doing that.
    
    This patch will take care of disabling probe timer for ofctrl and pictrl,
    and make sure SB timer changes take effect on the fly.
    
    Using NB database’s external-id, SB timer settings are stored, here is how 
to
    set it:
    ovs-vsctl --no-wait set open_vswitch . \
               external-ids:ovn-remote-probe-interval=7000
    
    Signed-off-by: Nirapada Ghosh <ngh...@us.ibm.com>

diff --git a/lib/rconn.c b/lib/rconn.c
index 6de4c63..3ebe0e8 100644
--- a/lib/rconn.c
+++ b/lib/rconn.c
@@ -324,6 +324,15 @@ rconn_get_probe_interval(const struct rconn *rc)
     return rc->probe_interval;
 }
 
+/* For unix domain socket, target starts with "unix:", the following function 
returns
+ * True when the argument indicates that it is unix domain socket
+ */
+static inline bool
+unix_domain_socket(const char *target)
+{
+   return (!(strncmp(target,"unix:",5)));
+}
+
 /* Drops any existing connection on 'rc', then sets up 'rc' to connect to
  * 'target' and reconnect as needed.  'target' should be a remote OpenFlow
  * target in a form acceptable to vconn_open().
@@ -339,6 +348,9 @@ rconn_connect(struct rconn *rc, const char *target, const 
char *name)
     rconn_disconnect__(rc);
     rconn_set_target__(rc, target, name);
     rc->reliable = true;
+    if (unix_domain_socket(target)) {
+       rc->probe_interval =0; /* we do not need probe_timer for unix domain 
sockets */
+    }
     reconnect(rc);
     ovs_mutex_unlock(&rc->mutex);
 }
@@ -461,6 +473,7 @@ reconnect(struct rconn *rc)
     if (!retval) {
         rc->backoff_deadline = time_now() + rc->backoff;
         state_transition(rc, S_CONNECTING);
+        VLOG_INFO("connected with probe-interval %d", rc->probe_interval);
     } else {
         VLOG_WARN("%s: connection failed (%s)",
                   rc->name, ovs_strerror(retval));
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 6027011..cfb7b0f 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -52,16 +52,52 @@
 
 VLOG_DEFINE_THIS_MODULE(main);
 
+static void set_probe_timer_if_changed(const struct ovsrec_open_vswitch *cfg,
+                                       const struct ovsdb_idl *sb_idl);
+static bool extract_probe_timer(const struct ovsrec_open_vswitch *cfg,
+                                char *key_name,
+                                int *ret_value_ptr);
+
 static unixctl_cb_func ovn_controller_exit;
 static unixctl_cb_func ct_zone_list;
 
 #define DEFAULT_BRIDGE_NAME "br-int"
+#define DEFAULT_PROBE_INTERVAL 5
 
 static void parse_options(int argc, char *argv[]);
 OVS_NO_RETURN static void usage(void);
 
 static char *ovs_remote;
 
+/* Given key_name, the following function retrieves probe_timer value from the
+ * configuration passed, this configuration comes from the "external-ids"
+ * which were configured via ovs-vsctl command.
+ *
+ * cfg: Holding the external-id values read from NB database.
+ * keyname: Name to extract the value for.
+ * ret_value_ptr: Pointer to integer location where the value read
+ * should be copied.
+ * The function returns true if success, keeps the original
+ * value of ret_value_ptr intact in case of a failure.
+ */
+static bool
+extract_probe_timer(const struct ovsrec_open_vswitch *cfg,
+                    char *key_name,
+                    int *ret_value_ptr)
+{
+    const char *probe_interval= smap_get(&cfg->external_ids, key_name);
+    int ret_value_temp=0; /* Temporary location to hold the value, in case of
+                           * failure, str_to_int() sets the ret_value_temp to 
0,
+                           * which is a valid value for us */
+    if ((!probe_interval) ||  (!str_to_int(probe_interval, 10, 
&ret_value_temp)))  {
+        VLOG_WARN("OVN OVSDB invalid remote probe interval:%s for %s",
+                 probe_interval, key_name);
+        return false;
+    }
+    *ret_value_ptr = ret_value_temp;
+    return true;
+}
+
 const struct sbrec_chassis *
 get_chassis(struct ovsdb_idl *ovnsb_idl, const char *chassis_id)
 {
@@ -198,30 +234,27 @@ get_ovnsb_remote(struct ovsdb_idl *ovs_idl)
     }
 }
 
-/* Retrieves the OVN Southbound remote's json session probe interval from the
- * "external-ids:ovn-remote-probe-interval" key in 'ovs_idl' and returns it.
- *
- * This function must be called after get_ovnsb_remote(). */
-static bool
-get_ovnsb_remote_probe_interval(struct ovsdb_idl *ovs_idl, int *value)
+/* If SB probe timer is changed using ovs-vsctl command, this function
+ * will set those probe timers on the fly.
+ * cfg: Holding the external-id values read from southbound DB.
+ * sb_idl: pointer to the ovs_idl connection to OVN southbound.
+ */
+static void
+set_probe_timer_if_changed(const struct ovsrec_open_vswitch *cfg,
+                           const struct ovsdb_idl *sb_idl
+                          )
 {
-    const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_first(ovs_idl);
-    if (!cfg) {
-        return false;
+    static int probe_int_sb = DEFAULT_PROBE_INTERVAL * 1000;
+    int probe_int_sb_new = probe_int_sb;
+
+    extract_probe_timer(cfg, "ovn-remote-probe-interval", &probe_int_sb_new);
+    if (probe_int_sb_new != probe_int_sb) {
+        ovsdb_idl_set_probe_interval(sb_idl, probe_int_sb_new);
+        VLOG_INFO("OVN SB probe interval changed %d->%d ",
+                  probe_int_sb,
+                  probe_int_sb_new);
+        probe_int_sb = probe_int_sb_new;
     }
-
-    const char *probe_interval =
-        smap_get(&cfg->external_ids, "ovn-remote-probe-interval");
-    if (probe_interval) {
-        if (str_to_int(probe_interval, 10, value)) {
-            return true;
-        }
-
-        VLOG_WARN("Invalid value for OVN remote probe interval: %s",
-                  probe_interval);
-    }
-
-    return false;
 }
 
 int
@@ -258,6 +291,7 @@ main(int argc, char *argv[])
      * default, so modules must register their interest explicitly.  */
     struct ovsdb_idl_loop ovs_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
         ovsdb_idl_create(ovs_remote, &ovsrec_idl_class, false, true));
+    VLOG_INFO("ovs_idl_loop OVSDB %p",ovs_idl_loop.idl);
     ovsdb_idl_add_table(ovs_idl_loop.idl, &ovsrec_table_open_vswitch);
     ovsdb_idl_add_column(ovs_idl_loop.idl,
                          &ovsrec_open_vswitch_col_external_ids);
@@ -286,11 +320,14 @@ main(int argc, char *argv[])
     struct ovsdb_idl_loop ovnsb_idl_loop = OVSDB_IDL_LOOP_INITIALIZER(
         ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
     ovsdb_idl_get_initial_snapshot(ovnsb_idl_loop.idl);
+    VLOG_INFO("ovs_idl_loop SB %p",ovnsb_idl_loop.idl);
 
-    int probe_interval = 0;
-    if (get_ovnsb_remote_probe_interval(ovs_idl_loop.idl, &probe_interval)) {
-        ovsdb_idl_set_probe_interval(ovnsb_idl_loop.idl, probe_interval);
+    const struct ovsrec_open_vswitch *cfg =
+        ovsrec_open_vswitch_first(ovs_idl_loop.idl);
+    if (!cfg) {
+        return false;
     }
+    set_probe_timer_if_changed(cfg,ovnsb_idl_loop.idl);
 
     /* Initialize connection tracking zones. */
     struct simap ct_zones = SIMAP_INITIALIZER(&ct_zones);
@@ -308,6 +345,7 @@ main(int argc, char *argv[])
             .ovnsb_idl = ovnsb_idl_loop.idl,
             .ovnsb_idl_txn = ovsdb_idl_loop_run(&ovnsb_idl_loop),
         };
+        set_probe_timer_if_changed(cfg,ovnsb_idl_loop.idl);
 
         /* Contains "struct local_datpath" nodes whose hash values are the
          * tunnel_key of datapaths with at least one local port binding. */

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to