Skip to content

Commit

Permalink
unixctl: Log commands received and their replies (at debug level).
Browse files Browse the repository at this point in the history
These commands are also visible through the "jsonrpc" module, but turning
up the log level there also exposes a lot of OVSDB traffic that usually
isn't interesting.

Also, enable this logging for the tests.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Justin Pettit <[email protected]>
  • Loading branch information
blp committed Mar 7, 2016
1 parent 0c0afad commit bb33845
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 17 additions & 1 deletion lib/unixctl.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -151,6 +151,13 @@ unixctl_command_reply__(struct unixctl_conn *conn,
reply = jsonrpc_create_error(body_json, conn->request_id);
}

if (VLOG_IS_DBG_ENABLED()) {
char *id = json_to_string(conn->request_id, 0);
VLOG_DBG("replying with %s, id=%s: \"%s\"",
success ? "success" : "error", id, body);
free(id);
}

/* If jsonrpc_send() returns an error, the run loop will take care of the
* problem eventually. */
jsonrpc_send(conn->rpc, reply);
Expand Down Expand Up @@ -268,6 +275,15 @@ process_command(struct unixctl_conn *conn, struct jsonrpc_msg *request)
COVERAGE_INC(unixctl_received);
conn->request_id = json_clone(request->id);

if (VLOG_IS_DBG_ENABLED()) {
char *params_s = json_to_string(request->params, 0);
char *id_s = json_to_string(request->id, 0);
VLOG_DBG("received request %s%s, id=%s",
request->method, params_s, id_s);
free(params_s);
free(id_s);
}

params = json_array(request->params);
command = shash_find_data(&commands, request->method);
if (!command) {
Expand Down
4 changes: 2 additions & 2 deletions tests/ofproto-macros.at
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sim_add () {
as $1 ovs-vsctl --no-wait -- init || return 1

# Start ovs-vswitchd
as $1 start_daemon ovs-vswitchd --enable-dummy=system -vvconn -vofproto_dpif
as $1 start_daemon ovs-vswitchd --enable-dummy=system -vvconn -vofproto_dpif -vunixctl
}

# "as $1" sets the OVS_*DIR environment variables to point to $ovs_base/$1.
Expand Down Expand Up @@ -272,7 +272,7 @@ m4_define([_OVS_VSWITCHD_START],
AT_CHECK([ovs-vsctl --no-wait init])

dnl Start ovs-vswitchd.
AT_CHECK([ovs-vswitchd $1 --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif], [0], [], [stderr])
AT_CHECK([ovs-vswitchd $1 --detach --no-chdir --pidfile --log-file -vvconn -vofproto_dpif -vunixctl], [0], [], [stderr])
AT_CAPTURE_FILE([ovs-vswitchd.log])
on_exit "kill `cat ovs-vswitchd.pid`"
AT_CHECK([[sed < stderr '
Expand Down

0 comments on commit bb33845

Please sign in to comment.