From patchwork Mon Jul 30 15:10:23 2018
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Lorenzo Bianconi
X-Patchwork-Id: 951030
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Authentication-Results: ozlabs.org;
spf=pass (mailfrom) smtp.mailfrom=openvswitch.org
(client-ip=140.211.169.12; helo=mail.linuxfoundation.org;
envelope-from=ovs-dev-bounces@openvswitch.org;
receiver=)
Authentication-Results: ozlabs.org;
dmarc=fail (p=none dis=none) header.from=redhat.com
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 41fNL23Hmdz9ryl
for ;
Tue, 31 Jul 2018 01:10:34 +1000 (AEST)
Received: from mail.linux-foundation.org (localhost [127.0.0.1])
by mail.linuxfoundation.org (Postfix) with ESMTP id 309F7CD0;
Mon, 30 Jul 2018 15:10:31 +0000 (UTC)
X-Original-To: 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 4861BCC8
for ; Mon, 30 Jul 2018 15:10:30 +0000 (UTC)
X-Greylist: whitelisted by SQLgrey-1.7.6
Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com
[209.85.221.66])
by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 94EE3792
for ; Mon, 30 Jul 2018 15:10:29 +0000 (UTC)
Received: by mail-wr1-f66.google.com with SMTP id r16-v6so13273721wrt.11
for ; Mon, 30 Jul 2018 08:10:29 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
:references;
bh=mBbFLK/4CAqp3VeUx59cLmRVS+2Yaxh3p5dwTHGNRL0=;
b=HClhSCBfpmE6eK9BdbFzU5fJuVxm5iggqBxZhlH+wN/sUTcLfaYXlWbIuzgtrRWBm+
1NLz7pTuKaf2+76SXYi33iji2oog6GCuOaukzGVZvRQk0BfwRr0IGtk0pkV1747m/rm/
a2dJx5WEiF5S2spQGzfvKUpqjFyoHBzRnneems1HmBoXocZb+e5Rh7b5dnE+6xXduFQ/
k+U/fGKD34WjTVrkmc8xbU9Pji2CVr+KdopMao2EVPIyfJJqiJpaIrH193GOD2ZMeDlK
5nx7myYaE4R+pPdk4caK1bB3cL5VmU3PJMuYSA5E4TfV3Qnc5jUCZ2Dzd95J2/yOMofG
MfWA==
X-Gm-Message-State: AOUpUlHLykXwuqf7q1bui5cBM0D5NzCMH2wZ6OJXzQ1m2UsvlpsunY+K
Xx68t0xDWnJQ/6oTd5NnhmNHavnfOcI=
X-Google-Smtp-Source:
AAOMgpcPk7HqF0ordYkkrwercuyeYSiplpi7bAOv+zn7fHMiYu8NyRliw3M15GHQlnK8WhVB/zbkAg==
X-Received: by 2002:adf:fec8:: with SMTP id
q8-v6mr18353266wrs.164.1532963427972;
Mon, 30 Jul 2018 08:10:27 -0700 (PDT)
Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com.
[149.6.153.186]) by smtp.gmail.com with ESMTPSA id
b2-v6sm1371503wmh.3.2018.07.30.08.10.27
(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);
Mon, 30 Jul 2018 08:10:27 -0700 (PDT)
From: Lorenzo Bianconi
To: dev@openvswitch.org
Date: Mon, 30 Jul 2018 17:10:23 +0200
Message-Id:
<4198f2348c1dd5798e4ff65eb38dcc315d4bed8e.1532962898.git.lorenzo.bianconi@redhat.com>
X-Mailer: git-send-email 2.17.1
In-Reply-To:
References:
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE
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 v2] Introduce ovs-appctl command to monitor HVs sb
connection status
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
Add 'connection-status' command to ovs-appctl utility in order to check
if a given chassis is currently connected to SB db
Co-authored-by: aginwala
Signed-off-by: aginwala
Signed-off-by: Lorenzo Bianconi
Acked-by: Mark Michelson
---
Changes since v1:
- add unit tests for ovs-appctl -t ovn-controller connection-status
command
- use jsonrpc_session_is_connected() in ovsdb_idl_is_connected routine
---
lib/ovsdb-idl.c | 6 +++++
lib/ovsdb-idl.h | 1 +
ovn/controller/ovn-controller.8.xml | 5 +++++
ovn/controller/ovn-controller.c | 17 +++++++++++++++
tests/ovn-controller.at | 34 +++++++++++++++++++++++++++++
5 files changed, 63 insertions(+)
diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c
index ae0a55c3a..f181ae831 100644
--- a/lib/ovsdb-idl.c
+++ b/lib/ovsdb-idl.c
@@ -922,6 +922,12 @@ ovsdb_idl_is_alive(const struct ovsdb_idl *idl)
idl->state != IDL_S_ERROR;
}
+bool
+ovsdb_idl_is_connected(const struct ovsdb_idl *idl)
+{
+ return jsonrpc_session_is_connected(idl->session);
+}
+
/* Returns the last error reported on a connection by 'idl'. The return value
* is 0 only if no connection made by 'idl' has ever encountered an error and
* a negative response to a schema request has never been received. See
diff --git a/lib/ovsdb-idl.h b/lib/ovsdb-idl.h
index ea18b22f5..5f933b628 100644
--- a/lib/ovsdb-idl.h
+++ b/lib/ovsdb-idl.h
@@ -80,6 +80,7 @@ void ovsdb_idl_force_reconnect(struct ovsdb_idl *);
void ovsdb_idl_verify_write_only(struct ovsdb_idl *);
bool ovsdb_idl_is_alive(const struct ovsdb_idl *);
+bool ovsdb_idl_is_connected(const struct ovsdb_idl *idl);
int ovsdb_idl_get_last_error(const struct ovsdb_idl *);
void ovsdb_idl_set_probe_interval(const struct ovsdb_idl *, int probe_interval);
diff --git a/ovn/controller/ovn-controller.8.xml b/ovn/controller/ovn-controller.8.xml
index 0eff2113f..0861edbc4 100644
--- a/ovn/controller/ovn-controller.8.xml
+++ b/ovn/controller/ovn-controller.8.xml
@@ -388,6 +388,11 @@
0x800.
+
+ connection-status
+
+ Show OVN SBDB connection status for the chassis.
+
diff --git a/ovn/controller/ovn-controller.c b/ovn/controller/ovn-controller.c
index 6ee72a9fa..3338d3318 100644
--- a/ovn/controller/ovn-controller.c
+++ b/ovn/controller/ovn-controller.c
@@ -66,6 +66,7 @@ VLOG_DEFINE_THIS_MODULE(main);
static unixctl_cb_func ovn_controller_exit;
static unixctl_cb_func ct_zone_list;
static unixctl_cb_func inject_pkt;
+static unixctl_cb_func ovn_controller_conn_show;
#define DEFAULT_BRIDGE_NAME "br-int"
#define DEFAULT_PROBE_INTERVAL_MSEC 5000
@@ -588,6 +589,9 @@ main(int argc, char *argv[])
ovsdb_idl_create(ovnsb_remote, &sbrec_idl_class, true, true));
ovsdb_idl_set_leader_only(ovnsb_idl_loop.idl, false);
+ unixctl_command_register("connection-status", "", 0, 0,
+ ovn_controller_conn_show, ovnsb_idl_loop.idl);
+
struct ovsdb_idl_index *sbrec_chassis_by_name
= chassis_index_create(ovnsb_idl_loop.idl);
struct ovsdb_idl_index *sbrec_multicast_group_by_name_datapath
@@ -1061,3 +1065,16 @@ update_probe_interval(const struct ovsrec_open_vswitch_table *ovs_table,
ovsdb_idl_set_probe_interval(ovnsb_idl, interval);
}
+
+static void
+ovn_controller_conn_show(struct unixctl_conn *conn, int argc OVS_UNUSED,
+ const char *argv[] OVS_UNUSED, void *idl_)
+{
+ char *result = "not connected";
+ struct ovsdb_idl *idl = idl_;
+
+ if (idl && ovsdb_idl_is_connected(idl)) {
+ result = "connected";
+ }
+ unixctl_command_reply(conn, result);
+}
diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
index ecc6a50da..13e88a0cc 100644
--- a/tests/ovn-controller.at
+++ b/tests/ovn-controller.at
@@ -228,3 +228,37 @@ as ovn-sb
OVS_APP_EXIT_AND_WAIT([ovsdb-server])
AT_CLEANUP
+
+# Check ovn-controller connection status to Southbound database
+AT_SETUP([ovn-controller - check sbdb connection])
+AT_KEYWORDS([ovn])
+ovn_init_db ovn-sb
+
+net_add n1
+sim_add hv
+as hv
+ovs-vsctl \
+ -- add-br br-phys \
+ -- add-br br-eth0 \
+ -- add-br br-eth1 \
+ -- add-br br-eth2
+ovn_attach n1 br-phys 192.168.0.1
+
+check_sbdb_connection () {
+ test "$(ovs-appctl -t ovn-controller connection-status)" = "$1"
+}
+
+OVS_WAIT_UNTIL([check_sbdb_connection connected])
+
+ovs-vsctl set open . external_ids:ovn-remote=tcp:192.168.0.10:6642
+OVS_WAIT_UNTIL([check_sbdb_connection 'not connected'])
+
+# reset the remote for clean-up
+ovs-vsctl set open . external_ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock
+# Gracefully terminate daemons
+OVN_CLEANUP_SBOX([hv])
+OVN_CLEANUP_VSWITCH([main])
+as ovn-sb
+OVS_APP_EXIT_AND_WAIT([ovsdb-server])
+
+AT_CLEANUP