Skip to content

Commit

Permalink
Introduce ovs-appctl command to monitor HVs sb connection status
Browse files Browse the repository at this point in the history
Add 'connection-status' command to ovs-appctl utility in order to check
if a given chassis is currently connected to SB db

Acked-by: Mark Michelson <[email protected]>
Co-authored-by: aginwala <[email protected]>
Signed-off-by: aginwala <[email protected]>
Signed-off-by: Lorenzo Bianconi <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
2 people authored and blp committed Jul 31, 2018
1 parent d2f4419 commit 82b261b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ovsdb-idl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 idl->session && 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
Expand Down
1 change: 1 addition & 0 deletions lib/ovsdb-idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions ovn/controller/ovn-controller.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@
0x800</code>.
</p>
</dd>

<dt><code>connection-status</code></dt>
<dd>
Show OVN SBDB connection status for the chassis.
</dd>
</dl>
</p>

Expand Down
17 changes: 17 additions & 0 deletions ovn/controller/ovn-controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ static unixctl_cb_func ct_zone_list;
static unixctl_cb_func meter_table_list;
static unixctl_cb_func group_table_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
Expand Down Expand Up @@ -594,6 +595,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
Expand Down Expand Up @@ -1122,3 +1126,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_)
{
const char *result = "not connected";
const struct ovsdb_idl *idl = idl_;

if (ovsdb_idl_is_connected(idl)) {
result = "connected";
}
unixctl_command_reply(conn, result);
}
34 changes: 34 additions & 0 deletions tests/ovn-controller.at
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 82b261b

Please sign in to comment.