stream: By default disable probing on unix sockets.
authorEthan Jackson <ethan@nicira.com>
Thu, 12 Apr 2012 03:18:34 +0000 (20:18 -0700)
committerEthan Jackson <ethan@nicira.com>
Thu, 12 Apr 2012 07:43:22 +0000 (00:43 -0700)
There isn't a lot of value in sending inactivity probes on unix
sockets.  This patch changes the default to disable them.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
13 files changed:
lib/jsonrpc.c
lib/stream-fd.c
lib/stream-provider.h
lib/stream-ssl.c
lib/stream-tcp.c
lib/stream-unix.c
lib/stream.c
lib/stream.h
ovsdb/jsonrpc-server.c
ovsdb/jsonrpc-server.h
ovsdb/ovsdb-server.c
python/ovs/jsonrpc.py
python/ovs/stream.py

index fa3362d17d8610dba45ca21f2bb47a135b936e2d..e95db8afc8e38d8121f903ce833c60eeeea8a475 100644 (file)
@@ -764,6 +764,10 @@ jsonrpc_session_open(const char *name)
         reconnect_set_passive(s->reconnect, true, time_msec());
     }
 
+    if (!stream_or_pstream_needs_probes(name)) {
+        reconnect_set_probe_interval(s->reconnect, 0);
+    }
+
     return s;
 }
 
index 38dba7c71211923dfab685751154fa94c8cb8b77..4113e3fc1693c33fa521392c78d71b417b55538d 100644 (file)
@@ -150,6 +150,7 @@ fd_wait(struct stream *stream, enum stream_wait_type wait)
 
 static const struct stream_class stream_fd_class = {
     "fd",                       /* name */
+    false,                      /* needs_probes */
     NULL,                       /* open */
     fd_close,                   /* close */
     fd_connect,                 /* connect */
@@ -255,6 +256,7 @@ pfd_wait(struct pstream *pstream)
 
 static struct pstream_class fd_pstream_class = {
     "pstream",
+    false,
     NULL,
     pfd_close,
     pfd_accept,
index 77d0a10601c25c50d80d4db478a51df978631229..3decb5a8a81eac63e3ebc7442539763a8eb78f56 100644 (file)
@@ -54,6 +54,11 @@ struct stream_class {
     /* Prefix for connection names, e.g. "tcp", "ssl", "unix". */
     const char *name;
 
+    /* True if this stream needs periodic probes to verify connectivty.  For
+     * streams which need probes, it can take a long time to notice the
+     * connection was dropped. */
+    bool needs_probes;
+
     /* Attempts to connect to a peer.  'name' is the full connection name
      * provided by the user, e.g. "tcp:1.2.3.4".  This name is useful for error
      * messages but must not be modified.
@@ -151,6 +156,11 @@ struct pstream_class {
     /* Prefix for connection names, e.g. "ptcp", "pssl", "punix". */
     const char *name;
 
+    /* True if this pstream needs periodic probes to verify connectivty.  For
+     * pstreams which need probes, it can take a long time to notice the
+     * connection was dropped. */
+    bool needs_probes;
+
     /* Attempts to start listening for stream connections.  'name' is the full
      * connection name provided by the user, e.g. "ptcp:1234".  This name is
      * useful for error messages but must not be modified.
index 5463388ea5159e5cc987feb223ee52f02f02060f..ad572d3523c7a77d337498ab14a620e6dfbde90f 100644 (file)
@@ -755,6 +755,7 @@ ssl_wait(struct stream *stream, enum stream_wait_type wait)
 
 const struct stream_class ssl_stream_class = {
     "ssl",                      /* name */
+    true,                       /* needs_probes */
     ssl_open,                   /* open */
     ssl_close,                  /* close */
     ssl_connect,                /* connect */
@@ -861,6 +862,7 @@ pssl_wait(struct pstream *pstream)
 
 const struct pstream_class pssl_pstream_class = {
     "pssl",
+    true,
     pssl_open,
     pssl_close,
     pssl_accept,
index c7a2ee2e8dcf6dc2fbacdc694a7515da55a60814..9762f88ed630b5c563f149572d6dfa724df7eee3 100644 (file)
@@ -86,6 +86,7 @@ tcp_open(const char *name, char *suffix, struct stream **streamp, uint8_t dscp)
 
 const struct stream_class tcp_stream_class = {
     "tcp",                      /* name */
+    true,                       /* needs_probes */
     tcp_open,                   /* open */
     NULL,                       /* close */
     NULL,                       /* connect */
@@ -137,6 +138,7 @@ ptcp_accept(int fd, const struct sockaddr *sa, size_t sa_len,
 
 const struct pstream_class ptcp_pstream_class = {
     "ptcp",
+    true,
     ptcp_open,
     NULL,
     NULL,
index a9d76f2572050a56a9857909485c68f4df20e8ba..40ef012486e70ee6242892284201d5dacd211b38 100644 (file)
@@ -57,6 +57,7 @@ unix_open(const char *name, char *suffix, struct stream **streamp,
 
 const struct stream_class unix_stream_class = {
     "unix",                     /* name */
+    false,                      /* needs_probes */
     unix_open,                  /* open */
     NULL,                       /* close */
     NULL,                       /* connect */
@@ -113,6 +114,7 @@ punix_accept(int fd, const struct sockaddr *sa, size_t sa_len,
 
 const struct pstream_class punix_pstream_class = {
     "punix",
+    false,
     punix_open,
     NULL,
     NULL,
index 2f418c42ae22b36f160ba0d59d2ded3ee246bc77..eabace8a4ea72ad82fc54bc2657540ade09b99f4 100644 (file)
@@ -489,6 +489,25 @@ pstream_verify_name(const char *name)
     return pstream_lookup_class(name, &class);
 }
 
+/* Returns 1 if the stream or pstream specified by 'name' needs periodic probes
+ * to verify connectivity.  For [p]streams which need probes, it can take a
+ * long time to notice the connection has been dropped.  Returns 0 if the
+ * stream or pstream does not need probes, and -1 if 'name' is not valid. */
+int
+stream_or_pstream_needs_probes(const char *name)
+{
+    const struct pstream_class *pclass;
+    const struct stream_class *class;
+
+    if (!stream_lookup_class(name, &class)) {
+        return class->needs_probes;
+    } else if (!pstream_lookup_class(name, &pclass)) {
+        return pclass->needs_probes;
+    } else {
+        return -1;
+    }
+}
+
 /* Attempts to start listening for remote stream connections.  'name' is a
  * connection name in the form "TYPE:ARGS", where TYPE is an passive stream
  * class's name and ARGS are stream class-specific.
index c1f3adb6b33ddbdc38ff26dadbd2f0a662d8d418..bd3901747ba28bc75fdde7b1a4fb204c69a95e42 100644 (file)
@@ -82,6 +82,7 @@ bool stream_parse_target_with_default_ports(const char *target,
                                            uint16_t default_tcp_port,
                                            uint16_t default_ssl_port,
                                            struct sockaddr_in *sin);
+int stream_or_pstream_needs_probes(const char *name);
 
 /* Error reporting. */
 
index 1848bb989363994f5dc1786acf473212ab985703..88656b9656f0f62a8a6a59101275755235d5f36a 100644 (file)
@@ -127,11 +127,13 @@ ovsdb_jsonrpc_server_destroy(struct ovsdb_jsonrpc_server *svr)
 }
 
 struct ovsdb_jsonrpc_options *
-ovsdb_jsonrpc_default_options(void)
+ovsdb_jsonrpc_default_options(const char *target)
 {
     struct ovsdb_jsonrpc_options *options = xzalloc(sizeof *options);
-    options->probe_interval = RECONNECT_DEFAULT_PROBE_INTERVAL;
     options->max_backoff = RECONNECT_DEFAULT_MAX_BACKOFF;
+    options->probe_interval = (stream_or_pstream_needs_probes(target)
+                               ? RECONNECT_DEFAULT_PROBE_INTERVAL
+                               : 0);
     return options;
 }
 
index c5ea6faf2f021eb10691b837193ad31e619769c2..344ed9da20699d39335c8e8a2af0e1295a9daa83 100644 (file)
@@ -30,7 +30,8 @@ struct ovsdb_jsonrpc_options {
     int probe_interval;         /* Max idle time before probing, in msec. */
     int dscp;                   /* Dscp value for manager connections */
 };
-struct ovsdb_jsonrpc_options *ovsdb_jsonrpc_default_options(void);
+struct ovsdb_jsonrpc_options *
+ovsdb_jsonrpc_default_options(const char *target);
 
 void ovsdb_jsonrpc_server_set_remotes(struct ovsdb_jsonrpc_server *,
                                       const struct shash *);
index 776bbb258ba1c60a31078fd399e56a61f96d9ac1..699401813eec3f47136fa94ab57d0330143af0f7 100644 (file)
@@ -276,7 +276,7 @@ add_remote(struct shash *remotes, const char *target)
 
     options = shash_find_data(remotes, target);
     if (!options) {
-        options = ovsdb_jsonrpc_default_options();
+        options = ovsdb_jsonrpc_default_options(target);
         shash_add(remotes, target, options);
     }
 
index 5f90b3962d21f7b5da0a121773a9cf7cf6876e4b..b72af77cfcc6e5c95d88ff33726f22731c9107f5 100644 (file)
@@ -372,6 +372,9 @@ class Session(object):
         if ovs.stream.PassiveStream.is_valid_name(name):
             reconnect.set_passive(True, ovs.timeval.msec())
 
+        if ovs.stream.stream_or_pstream_needs_probes(name):
+            reconnect.set_probe_interval(0)
+
         return Session(reconnect, None)
 
     @staticmethod
index 08c6293adf5a94f8b4d085b100fa849bfb641645..e2adaa5b0faa4c94394294454d13263aab7d9f83 100644 (file)
@@ -24,6 +24,19 @@ import ovs.vlog
 vlog = ovs.vlog.Vlog("stream")
 
 
+def stream_or_pstream_needs_probes(name):
+    """ 1 if the stream or pstream specified by 'name' needs periodic probes to
+    verify connectivty.  For [p]streams which need probes, it can take a long
+    time to notice the connection was dropped.  Returns 0 if probes aren't
+    needed, and -1 if 'name' is invalid"""
+
+    if PassiveStream.is_valid_name(name) or Stream.is_valid_name(name):
+        # Only unix and punix are supported currently.
+        return 0
+    else:
+        return -1
+
+
 class Stream(object):
     """Bidirectional byte stream.  Currently only Unix domain sockets
     are implemented."""