[ovs-dev,v2] Introduce ovs-appctl command to monitor HVs sb connection status
diff mbox series

Message ID 4198f2348c1dd5798e4ff65eb38dcc315d4bed8e.1532962898.git.lorenzo.bianconi@redhat.com
State Superseded
Headers show
Series
  • [ovs-dev,v2] Introduce ovs-appctl command to monitor HVs sb connection status
Related show

Commit Message

Lorenzo Bianconi July 30, 2018, 3:10 p.m. UTC
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 <aginwala@ebay.com>
Signed-off-by: aginwala <aginwala@ebay.com>
Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
---
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(+)

Comments

Mark Michelson July 30, 2018, 3:16 p.m. UTC | #1
Looks good to me. Ship it!

Acked-by: Mark Michelson <mmichels@redhat.com>

On 07/30/2018 11:10 AM, Lorenzo Bianconi wrote:
> 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 <aginwala@ebay.com>
> Signed-off-by: aginwala <aginwala@ebay.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
> 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</code>.
>         </p>
>         </dd>
> +
> +      <dt><code>connection-status</code></dt>
> +      <dd>
> +        Show OVN SBDB connection status for the chassis.
> +      </dd>
>         </dl>
>       </p>
>   
> 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
>
Jakub Sitnicki July 31, 2018, 8:56 a.m. UTC | #2
On Mon, 30 Jul 2018 17:10:23 +0200
Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:

> 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 <aginwala@ebay.com>
> Signed-off-by: aginwala <aginwala@ebay.com>
> Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> ---
> 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);
> +}
> +

This won't play well with changes proposed in:

  https://patchwork.ozlabs.org/patch/931134/

As the patch description mentions, 'session' can now be null, while
jsonrpc_session_is_connected() expects it to be nonnull.

>  /* 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</code>.
>        </p>
>        </dd>
> +
> +      <dt><code>connection-status</code></dt>
> +      <dd>
> +        Show OVN SBDB connection status for the chassis.
> +      </dd>
>        </dl>
>      </p>
>  
> 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
Lorenzo Bianconi July 31, 2018, 9:23 a.m. UTC | #3
On Jul 31, Jakub Sitnicki wrote:
> On Mon, 30 Jul 2018 17:10:23 +0200
> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> wrote:
> 
> > 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 <aginwala@ebay.com>
> > Signed-off-by: aginwala <aginwala@ebay.com>
> > Signed-off-by: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
> > ---
> > 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);
> > +}
> > +
> 
> This won't play well with changes proposed in:
> 
>   https://patchwork.ozlabs.org/patch/931134/
> 
> As the patch description mentions, 'session' can now be null, while
> jsonrpc_session_is_connected() expects it to be nonnull.

Good catch!! I will fix it in v3, thx

Regards,
Lorenzo

> 
> >  /* 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</code>.
> >        </p>
> >        </dd>
> > +
> > +      <dt><code>connection-status</code></dt>
> > +      <dd>
> > +        Show OVN SBDB connection status for the chassis.
> > +      </dd>
> >        </dl>
> >      </p>
> >  
> > 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
>

Patch
diff mbox series

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</code>.
       </p>
       </dd>
+
+      <dt><code>connection-status</code></dt>
+      <dd>
+        Show OVN SBDB connection status for the chassis.
+      </dd>
       </dl>
     </p>
 
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