Skip to content

Commit

Permalink
ofp-table: Better summarize table features and statistics.
Browse files Browse the repository at this point in the history
Before this patch, most dump-table-stats outputs would contain about
250 lines of the form:

  table #: ditto

With this patch, they have one line like this:

  tables 2...254: ditto

which is much easier to read.

Signed-off-by: Ben Pfaff <blp@ovn.org>
Acked-by: Justin Pettit <jpettit@ovn.org>
  • Loading branch information
blp committed Oct 26, 2018
1 parent df50117 commit 9d36d7d
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 66 deletions.
5 changes: 4 additions & 1 deletion include/openvswitch/ofp-table.h
Expand Up @@ -276,7 +276,10 @@ void ofputil_table_features_format(
const struct ofputil_table_features *prev_features,
const struct ofputil_table_stats *stats,
const struct ofputil_table_stats *prev_stats,
const struct ofputil_table_map *table_map);
const struct ofputil_table_map *table_map,
int *first_ditto, int *last_ditto);
void ofputil_table_features_format_finish(struct ds *,
int first_ditto, int last_ditto);

/* Abstract table stats.
*
Expand Down
11 changes: 7 additions & 4 deletions lib/ofp-print.c
Expand Up @@ -232,18 +232,19 @@ ofp_print_table_features_reply(struct ds *s, const struct ofp_header *oh,
struct ofpbuf b = ofpbuf_const_initializer(oh, ntohs(oh->length));

struct ofputil_table_features prev;
int first_ditto = -1, last_ditto = -1;
for (int i = 0; ; i++) {
struct ofputil_table_features tf;
int retval;

retval = ofputil_decode_table_features(&b, &tf, true);
if (retval) {
ofputil_table_features_format_finish(s, first_ditto, last_ditto);
return retval != EOF ? retval : 0;
}

ds_put_char(s, '\n');
ofputil_table_features_format(s, &tf, i ? &prev : NULL, NULL, NULL,
table_map);
table_map, &first_ditto, &last_ditto);
prev = tf;
}
}
Expand Down Expand Up @@ -574,21 +575,23 @@ ofp_print_table_stats_reply(struct ds *string, const struct ofp_header *oh,

struct ofputil_table_features prev_features;
struct ofputil_table_stats prev_stats;
int first_ditto = -1, last_ditto = -1;
for (int i = 0;; i++) {
struct ofputil_table_features features;
struct ofputil_table_stats stats;
int retval;

retval = ofputil_decode_table_stats_reply(&b, &stats, &features);
if (retval) {
ofputil_table_features_format_finish(string,
first_ditto, last_ditto);
return retval != EOF ? retval : 0;
}

ds_put_char(string, '\n');
ofputil_table_features_format(string,
&features, i ? &prev_features : NULL,
&stats, i ? &prev_stats : NULL,
table_map);
table_map, &first_ditto, &last_ditto);
prev_features = features;
prev_stats = stats;
}
Expand Down
42 changes: 35 additions & 7 deletions lib/ofp-table.c
Expand Up @@ -1395,21 +1395,31 @@ ofputil_table_features_format(
const struct ofputil_table_features *prev_features,
const struct ofputil_table_stats *stats,
const struct ofputil_table_stats *prev_stats,
const struct ofputil_table_map *table_map)
const struct ofputil_table_map *table_map,
int *first_ditto, int *last_ditto)
{
int i;
bool same_stats = !stats || (prev_stats
&& table_stats_equal(stats, prev_stats));
bool same_features = prev_features && table_features_equal(features,
prev_features);
if (same_stats && same_features && !features->name[0]) {
if (*first_ditto < 0) {
*first_ditto = features->table_id;
}
*last_ditto = features->table_id;
return;
}
ofputil_table_features_format_finish(s, *first_ditto, *last_ditto);
*first_ditto = -1;

ds_put_format(s, " table ");
ds_put_format(s, "\n table ");
ofputil_format_table(features->table_id, table_map, s);
if (features->name[0]) {
ds_put_format(s, " (\"%s\")", features->name);
}
ds_put_char(s, ':');

bool same_stats = prev_stats && table_stats_equal(stats, prev_stats);
bool same_features = prev_features && table_features_equal(features,
prev_features);
if ((!stats || same_stats) && same_features) {
if (same_stats && same_features) {
ds_put_cstr(s, " ditto");
return;
}
Expand Down Expand Up @@ -1479,6 +1489,8 @@ ofputil_table_features_format(
ds_put_cstr(s, " (same matching)\n");
} else {
ds_put_cstr(s, " matching:\n");

int i;
BITMAP_FOR_EACH_1 (i, MFF_N_IDS, features->match.bm) {
const struct mf_field *f = mf_from_id(i);
bool mask = bitmap_is_set(features->mask.bm, i);
Expand All @@ -1493,6 +1505,22 @@ ofputil_table_features_format(
}
}
}

void
ofputil_table_features_format_finish(struct ds *s,
int first_ditto, int last_ditto)
{
if (first_ditto < 0) {
return;
}

ds_put_char(s, '\n');
if (first_ditto == last_ditto) {
ds_put_format(s, " table %d: ditto\n", first_ditto);
} else {
ds_put_format(s, " tables %d...%d: ditto\n", first_ditto, last_ditto);
}
}

/* Table stats. */

Expand Down
56 changes: 26 additions & 30 deletions tests/ofproto-dpif.at
Expand Up @@ -8981,17 +8981,16 @@ AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl
NXST_FLOW reply:
])

(echo "OFPST_TABLE reply (OF1.3) (xid=0x2):
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br0], [0],
[OFPST_TABLE reply (OF1.3) (xid=0x2):
table 0:
active=1, lookup=0, matched=0

table 1:
active=0, lookup=0, matched=0
"
for i in `seq 2 253`; do
printf ' table %d: ditto\n' $i
done) > expout
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br0 ], [0], [expout])

tables 2...253: ditto
])

OVS_VSWITCHD_STOP
AT_CLEANUP
Expand Down Expand Up @@ -9027,26 +9026,24 @@ NXT_PACKET_IN (xid=0x0): cookie=0x0 total_len=14 in_port=1 (via no_match) data_l
vlan_tci=0x0000,dl_src=50:54:00:00:00:09,dl_dst=50:54:00:00:00:0a,dl_type=0x1234
])

(echo "OFPST_TABLE reply (OF1.3) (xid=0x2):
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br0], [0], [dnl
OFPST_TABLE reply (OF1.3) (xid=0x2):
table 0:
active=0, lookup=0, matched=0
"
for i in `seq 1 253`; do
printf ' table %d: ditto\n' $i
done) > expout
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br0 ], [0], [expout])

(echo "OFPST_TABLE reply (OF1.3) (xid=0x2):
tables 1...253: ditto
])

AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br1], [0], [dnl
OFPST_TABLE reply (OF1.3) (xid=0x2):
table 0:
active=0, lookup=3, matched=0

table 1:
active=0, lookup=0, matched=0
"
for i in `seq 2 253`; do
printf ' table %d: ditto\n' $i
done) > expout
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br1 ], [0], [expout])

tables 2...253: ditto
])

OVS_VSWITCHD_STOP
AT_CLEANUP
Expand Down Expand Up @@ -9138,18 +9135,18 @@ AT_CHECK([ovs-ofctl -O OpenFlow13 dump-flows br0 | ofctl_strip | sort], [0], [dn
OFPST_FLOW reply (OF1.3):
])

(echo "OFPST_TABLE reply (OF1.3) (xid=0x2):
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br0], [0], [dnl
OFPST_TABLE reply (OF1.3) (xid=0x2):
table 0:
active=1, lookup=3, matched=3

table 1: ditto

table 2:
active=0, lookup=0, matched=0
"
for i in `seq 3 253`; do
printf ' table %d: ditto\n' $i
done) > expout
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br0 ], [0], [expout])

tables 3...253: ditto
])

OVS_VSWITCHD_STOP
AT_CLEANUP
Expand Down Expand Up @@ -9188,7 +9185,8 @@ AT_CHECK([ovs-ofctl -O OpenFlow11 dump-flows br0 | ofctl_strip | sort], [0], [dn
OFPST_FLOW reply (OF1.1):
])

(echo "OFPST_TABLE reply (OF1.3) (xid=0x2):
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br0], [0], [dnl
OFPST_TABLE reply (OF1.3) (xid=0x2):
table 0:
active=0, lookup=3, matched=0

Expand All @@ -9197,11 +9195,9 @@ OFPST_FLOW reply (OF1.1):

table 2:
active=0, lookup=0, matched=0
"
for i in `seq 3 253`; do
printf ' table %d: ditto\n' $i
done) > expout
AT_CHECK([ovs-ofctl -O OpenFlow13 dump-tables br0 ], [0], [expout])

tables 3...253: ditto
])

OVS_VSWITCHD_STOP
AT_CLEANUP
Expand Down
25 changes: 5 additions & 20 deletions tests/ofproto.at
Expand Up @@ -2257,12 +2257,7 @@ head_table() {

' "$1"
}
ditto() {
for i in `seq $1 $2`; do
printf ' table %d: ditto\n' $i
done
}
(head_table; ditto 1 253) > expout
(head_table; echo ' tables 1...253: ditto') > expout
AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
# Change the configuration.
AT_CHECK(
Expand All @@ -2284,7 +2279,7 @@ AT_CHECK(
active=0, lookup=0, matched=0
max_entries=1000000
(same matching)
'; ditto 3 253) > expout
'; echo ' tables 3...253: ditto') > expout
AT_CHECK([ovs-ofctl dump-tables br0], [0], [expout])
OVS_VSWITCHD_STOP
AT_CLEANUP
Expand Down Expand Up @@ -2333,12 +2328,7 @@ head_table() {

'
}
ditto() {
for i in `seq $1 $2`; do
printf ' table %d: ditto\n' $i
done
}
(head_table; ditto 1 253) > expout
(head_table; echo ' tables 1...253: ditto') > expout
AT_CHECK([ovs-ofctl dump-tables br0 | strip_xids], [0], [expout])
OVS_VSWITCHD_STOP(["/240\.0\.0\.1/d"])
AT_CLEANUP
Expand Down Expand Up @@ -2397,11 +2387,6 @@ head_table() {

' "$1"
}
ditto() {
for i in `seq $1 $2`; do
printf ' table %d: ditto\n' $i
done
}
tail_table() {
printf ' table 253:
active=0, lookup=0, matched=0
Expand All @@ -2414,7 +2399,7 @@ tail_table() {
(same matching)
'
}
(head_table; ditto 1 252; tail_table) > expout
(head_table; printf ' tables 1...252: ditto\n\n'; tail_table) > expout
AT_CHECK([ovs-ofctl -O OpenFlow12 dump-tables br0], [0], [expout])
# Change the configuration.
AT_CHECK(
Expand Down Expand Up @@ -2442,7 +2427,7 @@ AT_CHECK(
max_entries=1000000
(same instructions)
(same matching)
'; ditto 3 252; tail_table) > expout
'; printf ' tables 3...252: ditto\n\n'; tail_table) > expout
AT_CHECK([ovs-ofctl -O OpenFlow12 dump-tables br0], [0], [expout])
OVS_VSWITCHD_STOP
AT_CLEANUP
Expand Down
13 changes: 9 additions & 4 deletions utilities/ovs-ofctl.c
Expand Up @@ -888,6 +888,8 @@ ofctl_dump_table_features(struct ovs_cmdl_context *ctx)
bool done = false;

struct ofputil_table_features prev;
int first_ditto = -1, last_ditto = -1;
struct ds s = DS_EMPTY_INITIALIZER;
int n = 0;

send_openflow_buffer(vconn, request);
Expand Down Expand Up @@ -922,12 +924,10 @@ ofctl_dump_table_features(struct ovs_cmdl_context *ctx)
break;
}

struct ds s = DS_EMPTY_INITIALIZER;
ofputil_table_features_format(
&s, &tf, n ? &prev : NULL, NULL, NULL,
tables_to_show(ctx->argv[1]));
puts(ds_cstr(&s));
ds_destroy(&s);
tables_to_show(ctx->argv[1]),
&first_ditto, &last_ditto);

prev = tf;
n++;
Expand All @@ -946,6 +946,11 @@ ofctl_dump_table_features(struct ovs_cmdl_context *ctx)
ofpbuf_delete(reply);
}

ofputil_table_features_format_finish(&s, first_ditto, last_ditto);
const char *p = ds_cstr(&s);
puts(p + (*p == '\n'));
ds_destroy(&s);

vconn_close(vconn);
}

Expand Down

0 comments on commit 9d36d7d

Please sign in to comment.