From: Ben Pfaff Date: Wed, 8 Feb 2012 00:17:13 +0000 (-0800) Subject: ovs-ofctl: Add --timestamp option to print time for each received packet. X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0c9560b7ded6d556762f9fd74ffd9fdfac12afc0;p=sliver-openvswitch.git ovs-ofctl: Add --timestamp option to print time for each received packet. Suggestion #9347. Suggested-by: Alan Shieh Signed-off-by: Ben Pfaff --- diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in index 8de6af947..48ff7afe9 100644 --- a/utilities/ovs-ofctl.8.in +++ b/utilities/ovs-ofctl.8.in @@ -1202,6 +1202,10 @@ will insist on the selected format. If the switch does not support the requested format, \fBovs\-ofctl\fR will report a fatal error. This option only affects the \fBmonitor\fR command. . +.IP "\fB\-\-timestamp\fR" +Print a timestamp before each received packet. This option only +affects the \fBmonitor\fR and \fBsnoop\fR commands. +. .IP "\fB\-m\fR" .IQ "\fB\-\-more\fR" Increases the verbosity of OpenFlow messages printed and logged by diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c index d2efd7f23..bf7a2c126 100644 --- a/utilities/ovs-ofctl.c +++ b/utilities/ovs-ofctl.c @@ -79,6 +79,10 @@ static int preferred_packet_in_format = -1; /* -m, --more: Additional verbosity for ofp-print functions. */ static int verbosity; +/* --timestamp: Print a timestamp before each received packet on "monitor" and + * "snoop" command? */ +static bool timestamp; + static const struct command all_commands[]; static void usage(void) NO_RETURN; @@ -100,6 +104,7 @@ parse_options(int argc, char *argv[]) enum { OPT_STRICT = UCHAR_MAX + 1, OPT_READD, + OPT_TIMESTAMP, DAEMON_OPTION_ENUMS, VLOG_OPTION_ENUMS }; @@ -110,6 +115,7 @@ parse_options(int argc, char *argv[]) {"flow-format", required_argument, NULL, 'F'}, {"packet-in-format", required_argument, NULL, 'P'}, {"more", no_argument, NULL, 'm'}, + {"timestamp", no_argument, NULL, OPT_TIMESTAMP}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, DAEMON_LONG_OPTIONS, @@ -173,6 +179,10 @@ parse_options(int argc, char *argv[]) readd = true; break; + case OPT_TIMESTAMP: + timestamp = true; + break; + DAEMON_OPTION_HANDLERS VLOG_OPTION_HANDLERS STREAM_SSL_OPTION_HANDLERS @@ -231,6 +241,7 @@ usage(void) " -F, --flow-format=FORMAT force particular flow format\n" " -P, --packet-in-format=FRMT force particular packet in format\n" " -m, --more be more verbose printing OpenFlow\n" + " --timestamp (monitor, snoop) print timestamps\n" " -t, --timeout=SECS give up after SECS seconds\n" " -h, --help display this help message\n" " -V, --version display version information\n"); @@ -991,6 +1002,13 @@ monitor_vconn(struct vconn *vconn) msg_type = ((const struct ofp_header *) b->data)->type; run(retval, "vconn_recv"); + if (timestamp) { + time_t now = time_wall(); + char s[32]; + + strftime(s, sizeof s, "%Y-%m-%d %H:%M:%S: ", localtime(&now)); + fputs(s, stderr); + } ofp_print(stderr, b->data, b->size, verbosity + 2); ofpbuf_delete(b);