From patchwork Sun Jan 1 11:04:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guoshuai Li X-Patchwork-Id: 710000 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3try6V23Fdz9sCM for ; Sun, 1 Jan 2017 22:05:21 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 93F31BD5; Sun, 1 Jan 2017 11:05:16 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 8E0DCBCB for ; Sun, 1 Jan 2017 11:05:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtp2203-239.mail.aliyun.com (smtp2203-239.mail.aliyun.com [121.197.203.239]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id 8AAAFD5 for ; Sun, 1 Jan 2017 11:05:10 +0000 (UTC) X-Alimail-AntiSpam: AC=CONTINUE; BC=0.08181234|-1; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03302; MF=ligs@dtdream.com; NM=1; PH=DS; RN=2; RT=2; SR=0; TI=SMTPD_---.7NTC2it_1483268700; Received: from localhost.localdomain(mailfrom:ligs@dtdream.com ip:111.198.29.132) by smtp.aliyun-inc.com(10.147.41.199); Sun, 01 Jan 2017 19:05:01 +0800 From: Guoshuai Li To: ovs-dev@openvswitch.org Date: Sun, 1 Jan 2017 19:04:55 +0800 Message-Id: <20170101110455.9464-1-ligs@dtdream.com> X-Mailer: git-send-email 2.10.1.windows.1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH] python: Add TCP/SSL probes for OVSDB python lib X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org stream_or_pstream_needs_probes always return 0. This causes TCP/SSL connection not be probed, and no reconnect when the connection is aborted Signed-off-by: Guoshuai Li --- python/ovs/stream.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/python/ovs/stream.py b/python/ovs/stream.py index cd57eb3..e74985f 100644 --- a/python/ovs/stream.py +++ b/python/ovs/stream.py @@ -31,16 +31,18 @@ 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 connectivity. 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 + """ True 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 was dropped. Returns False if probes + aren't needed, and None if 'name' is invalid""" + + cls = Stream._find_method(name) + if cls: + return cls.needs_probes() + elif PassiveStream.is_valid_name(name): + return PassiveStream.needs_probes(name) else: - return -1 + return None class Stream(object): @@ -288,6 +290,10 @@ class Stream(object): class PassiveStream(object): @staticmethod + def needs_probes(name): + return False if name.startswith("punix:") else True + + @staticmethod def is_valid_name(name): """Returns True if 'name' is a passive stream name in the form "TYPE:ARGS" and TYPE is a supported passive stream type (currently @@ -391,6 +397,10 @@ Passive %s connection methods: class UnixStream(Stream): @staticmethod + def needs_probes(): + return False + + @staticmethod def _open(suffix, dscp): connect_path = suffix return ovs.socket_util.make_unix_socket(socket.SOCK_STREAM, @@ -402,6 +412,10 @@ Stream.register_method("unix", UnixStream) class TCPStream(Stream): @staticmethod + def needs_probes(): + return True + + @staticmethod def _open(suffix, dscp): error, sock = ovs.socket_util.inet_open_active(socket.SOCK_STREAM, suffix, 0, dscp) @@ -414,6 +428,9 @@ Stream.register_method("tcp", TCPStream) class SSLStream(Stream): + @staticmethod + def needs_probes(): + return True @staticmethod def verify_cb(conn, cert, errnum, depth, ok):