diff options
author | Ben Pfaff <blp@ovn.org> | 2017-06-13 17:09:05 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-06-14 12:50:23 -0700 |
commit | 1b3758c36e88fd261377726f9ab958a0be53f2ca (patch) | |
tree | 12b68e5006754b9a43edc337e537cf25b6181377 /lib/ofp-print.c | |
parent | 89cf41eca75e28b85423c04f0ed7665a0f160a26 (diff) | |
download | openvswitch-1b3758c36e88fd261377726f9ab958a0be53f2ca.tar.gz |
ovs-ofctl: New option "--no-stats" for "ovs-ofctl dump-flows".
It's pretty common to want to omit statistics from output, to make it
easier to read. This commit adds an ovs-ofctl option to make that easy.
A lot of the OVS internal tests could use this, too, in place of
ofctl_strip. This commit adopts it for a subset.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Aaron Conole <aconole@redhat.com>
Diffstat (limited to 'lib/ofp-print.c')
-rw-r--r-- | lib/ofp-print.c | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/lib/ofp-print.c b/lib/ofp-print.c index 423df3102..b1c412ea4 100644 --- a/lib/ofp-print.c +++ b/lib/ofp-print.c @@ -1682,21 +1682,34 @@ ofp_print_flow_stats_request(struct ds *string, const struct ofp_header *oh, match_format(&fsr.match, port_map, string, OFP_DEFAULT_PRIORITY); } +/* Appends a textual form of 'fs' to 'string', translating port numbers to + * names using 'port_map' (if provided). If 'show_stats' is true, the output + * includes the flow duration, packet and byte counts, and its idle and hard + * ages, otherwise they are omitted. */ void ofp_print_flow_stats(struct ds *string, const struct ofputil_flow_stats *fs, - const struct ofputil_port_map *port_map) + const struct ofputil_port_map *port_map, bool show_stats) { - ds_put_format(string, " %scookie=%s0x%"PRIx64", %sduration=%s", - colors.param, colors.end, ntohll(fs->cookie), - colors.param, colors.end); - - ofp_print_duration(string, fs->duration_sec, fs->duration_nsec); - ds_put_format(string, ", %stable=%s%"PRIu8", ", - colors.special, colors.end, fs->table_id); - ds_put_format(string, "%sn_packets=%s%"PRIu64", ", - colors.param, colors.end, fs->packet_count); - ds_put_format(string, "%sn_bytes=%s%"PRIu64", ", - colors.param, colors.end, fs->byte_count); + if (show_stats || fs->cookie) { + ds_put_format(string, "%scookie=%s0x%"PRIx64", ", + colors.param, colors.end, ntohll(fs->cookie)); + } + if (show_stats) { + ds_put_format(string, "%sduration=%s", colors.param, colors.end); + ofp_print_duration(string, fs->duration_sec, fs->duration_nsec); + ds_put_cstr(string, ", "); + } + + if (show_stats || fs->table_id) { + ds_put_format(string, "%stable=%s%"PRIu8", ", + colors.special, colors.end, fs->table_id); + } + if (show_stats) { + ds_put_format(string, "%sn_packets=%s%"PRIu64", ", + colors.param, colors.end, fs->packet_count); + ds_put_format(string, "%sn_bytes=%s%"PRIu64", ", + colors.param, colors.end, fs->byte_count); + } if (fs->idle_timeout != OFP_FLOW_PERMANENT) { ds_put_format(string, "%sidle_timeout=%s%"PRIu16", ", colors.param, colors.end, fs->idle_timeout); @@ -1712,17 +1725,20 @@ ofp_print_flow_stats(struct ds *string, const struct ofputil_flow_stats *fs, ds_put_format(string, "%simportance=%s%"PRIu16", ", colors.param, colors.end, fs->importance); } - if (fs->idle_age >= 0) { + if (show_stats && fs->idle_age >= 0) { ds_put_format(string, "%sidle_age=%s%d, ", colors.param, colors.end, fs->idle_age); } - if (fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) { + if (show_stats && fs->hard_age >= 0 && fs->hard_age != fs->duration_sec) { ds_put_format(string, "%shard_age=%s%d, ", colors.param, colors.end, fs->hard_age); } + /* Print the match, followed by a space (but omit the space if the match + * was an empty string). */ + size_t length = string->length; match_format(&fs->match, port_map, string, fs->priority); - if (string->string[string->length - 1] != ' ') { + if (string->length != length) { ds_put_char(string, ' '); } @@ -1749,8 +1765,8 @@ ofp_print_flow_stats_reply(struct ds *string, const struct ofp_header *oh, } break; } - ds_put_char(string, '\n'); - ofp_print_flow_stats(string, &fs, port_map); + ds_put_cstr(string, "\n "); + ofp_print_flow_stats(string, &fs, port_map, true); } ofpbuf_uninit(&ofpacts); } |