diff options
author | Thomas Haller <thaller@redhat.com> | 2015-08-14 13:25:27 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-08-14 13:25:31 (GMT) |
commit | c38022898abbd75e0ea824a2c4edf73075dfa109 (patch) | |
tree | ba3f905d07cace205fd35bee2a0c2ebfbce69daf | |
parent | d0406d3838d4e70f19dcac1747decd7dd9b7435c (diff) | |
parent | 6871a3b6acc93e4323722d954da445fdc1f3cda6 (diff) | |
download | libnl-c38022898abbd75e0ea824a2c4edf73075dfa109.zip libnl-c38022898abbd75e0ea824a2c4edf73075dfa109.tar.gz libnl-c38022898abbd75e0ea824a2c4edf73075dfa109.tar.bz2 |
lib/route: merge fixes to dump_details
http://lists.infradead.org/pipermail/libnl/2015-July/001933.html
http://lists.infradead.org/pipermail/libnl/2015-July/001932.html
http://lists.infradead.org/pipermail/libnl/2015-July/001931.html
Signed-off-by: Thomas Haller <thaller@redhat.com>
-rw-r--r-- | lib/route/qdisc.c | 2 | ||||
-rw-r--r-- | lib/route/qdisc/netem.c | 68 | ||||
-rw-r--r-- | lib/route/tc.c | 40 |
3 files changed, 81 insertions, 29 deletions
diff --git a/lib/route/qdisc.c b/lib/route/qdisc.c index b8b6fa5..775d4cb 100644 --- a/lib/route/qdisc.c +++ b/lib/route/qdisc.c @@ -520,7 +520,7 @@ static void qdisc_dump_details(struct rtnl_tc *tc, struct nl_dump_params *p) { struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) tc; - nl_dump(p, "refcnt %u ", qdisc->q_info); + nl_dump(p, "refcnt %u", qdisc->q_info); } static struct rtnl_tc_type_ops qdisc_ops = { diff --git a/lib/route/qdisc/netem.c b/lib/route/qdisc/netem.c index 06d9fe8..abca855 100644 --- a/lib/route/qdisc/netem.c +++ b/lib/route/qdisc/netem.c @@ -29,8 +29,8 @@ /** @cond SKIP */ #define SCH_NETEM_ATTR_LATENCY 0x0001 #define SCH_NETEM_ATTR_LIMIT 0x0002 -#define SCH_NETEM_ATTR_LOSS 0x0004 -#define SCH_NETEM_ATTR_GAP 0x0008 +#define SCH_NETEM_ATTR_LOSS 0x0004 +#define SCH_NETEM_ATTR_GAP 0x0008 #define SCH_NETEM_ATTR_DUPLICATE 0x0010 #define SCH_NETEM_ATTR_JITTER 0x0020 #define SCH_NETEM_ATTR_DELAY_CORR 0x0040 @@ -40,7 +40,7 @@ #define SCH_NETEM_ATTR_RO_CORR 0x0400 #define SCH_NETEM_ATTR_CORRUPT_PROB 0x0800 #define SCH_NETEM_ATTR_CORRUPT_CORR 0x1000 -#define SCH_NETEM_ATTR_DIST 0x2000 +#define SCH_NETEM_ATTR_DIST 0x2000 /** @endcond */ static struct nla_policy netem_policy[TCA_NETEM_MAX+1] = { @@ -141,8 +141,65 @@ static void netem_dump_line(struct rtnl_tc *tc, void *data, { struct rtnl_netem *netem = data; - if (netem) - nl_dump(p, "limit %d", netem->qnm_limit); + if (netem) { + if (netem->qnm_mask & SCH_NETEM_ATTR_LIMIT && netem->qnm_limit > 0) + nl_dump(p, " limit %dpkts", netem->qnm_limit); + else + nl_dump(p, " no limit"); + } +} + +static void netem_dump_details(struct rtnl_tc *tc, void *data, + struct nl_dump_params *p) +{ + struct rtnl_netem *netem = data; + char buf[32]; + + if (netem) { + if (netem->qnm_mask & SCH_NETEM_ATTR_LATENCY && netem->qnm_latency > 0) { + nl_msec2str(nl_ticks2us(netem->qnm_latency) / 1000, buf, sizeof(buf)); + nl_dump(p, " latency %s", buf); + + if (netem->qnm_mask & SCH_NETEM_ATTR_JITTER && netem->qnm_jitter > 0) { + nl_msec2str(nl_ticks2us(netem->qnm_jitter) / 1000, buf, sizeof(buf)); + nl_dump(p, " jitter %s", buf); + + if (netem->qnm_mask & SCH_NETEM_ATTR_DELAY_CORR && netem->qnm_corr.nmc_delay > 0) + nl_dump(p, " %d%", netem->qnm_corr.nmc_delay); + } + } + + if (netem->qnm_mask & SCH_NETEM_ATTR_LOSS && netem->qnm_loss > 0) { + nl_dump(p, " loss %d%", netem->qnm_loss); + + if (netem->qnm_mask & SCH_NETEM_ATTR_LOSS_CORR && netem->qnm_corr.nmc_loss > 0) + nl_dump(p, " %d%", netem->qnm_corr.nmc_loss); + } + + if (netem->qnm_mask & SCH_NETEM_ATTR_DUPLICATE && netem->qnm_duplicate > 0) { + nl_dump(p, " duplicate %d%", netem->qnm_duplicate); + + if (netem->qnm_mask & SCH_NETEM_ATTR_DUP_CORR && netem->qnm_corr.nmc_duplicate > 0) + nl_dump(p, " %d%", netem->qnm_corr.nmc_duplicate); + } + + if (netem->qnm_mask & SCH_NETEM_ATTR_RO_PROB && netem->qnm_ro.nmro_probability > 0) { + nl_dump(p, " reorder %d%", netem->qnm_ro.nmro_probability); + + if (netem->qnm_mask & SCH_NETEM_ATTR_RO_CORR && netem->qnm_ro.nmro_correlation > 0) + nl_dump(p, " %d%", netem->qnm_ro.nmro_correlation); + + if (netem->qnm_mask & SCH_NETEM_ATTR_GAP && netem->qnm_gap > 0) + nl_dump(p, " gap %d", netem->qnm_gap); + } + + if (netem->qnm_mask & SCH_NETEM_ATTR_CORRUPT_PROB && netem->qnm_crpt.nmcr_probability > 0) { + nl_dump(p, " reorder %d%", netem->qnm_crpt.nmcr_probability); + + if (netem->qnm_mask & SCH_NETEM_ATTR_CORRUPT_CORR && netem->qnm_crpt.nmcr_correlation > 0) + nl_dump(p, " %d%", netem->qnm_crpt.nmcr_correlation); + } + } } static int netem_msg_fill_raw(struct rtnl_tc *tc, void *data, @@ -892,6 +949,7 @@ static struct rtnl_tc_ops netem_ops = { .to_msg_parser = netem_msg_parser, .to_free_data = netem_free_data, .to_dump[NL_DUMP_LINE] = netem_dump_line, + .to_dump[NL_DUMP_DETAILS] = netem_dump_details, .to_msg_fill_raw = netem_msg_fill_raw, }; diff --git a/lib/route/tc.c b/lib/route/tc.c index b3f4ac3..35daf15 100644 --- a/lib/route/tc.c +++ b/lib/route/tc.c @@ -903,39 +903,33 @@ void rtnl_tc_dump_details(struct nl_object *obj, struct nl_dump_params *p) void rtnl_tc_dump_stats(struct nl_object *obj, struct nl_dump_params *p) { struct rtnl_tc *tc = TC_CAST(obj); - char *unit, fmt[64]; + char *unit; float res; rtnl_tc_dump_details(OBJ_CAST(tc), p); - strcpy(fmt, " %7.2f %s %10u %10u %10u %10u %10u\n"); - - nl_dump_line(p, - " Stats: bytes packets drops overlimits" \ - " qlen backlog\n"); + nl_dump_line(p, + " stats: %-14s %-10s %-10s %-10s %-10s %-10s\n", + "bytes", "packets", "drops", "overlimits", "qlen", "backlog"); res = nl_cancel_down_bytes(tc->tc_stats[RTNL_TC_BYTES], &unit); - if (*unit == 'B') - fmt[11] = '9'; - nl_dump_line(p, fmt, res, unit, - tc->tc_stats[RTNL_TC_PACKETS], - tc->tc_stats[RTNL_TC_DROPS], - tc->tc_stats[RTNL_TC_OVERLIMITS], - tc->tc_stats[RTNL_TC_QLEN], - tc->tc_stats[RTNL_TC_BACKLOG]); + nl_dump_line(p, + " %10.2f %3s %10u %-10u %-10u %-10u %-10u\n", + res, unit, + tc->tc_stats[RTNL_TC_PACKETS], + tc->tc_stats[RTNL_TC_DROPS], + tc->tc_stats[RTNL_TC_OVERLIMITS], + tc->tc_stats[RTNL_TC_QLEN], + tc->tc_stats[RTNL_TC_BACKLOG]); res = nl_cancel_down_bytes(tc->tc_stats[RTNL_TC_RATE_BPS], &unit); - strcpy(fmt, " %7.2f %s/s%9u pps"); - - if (*unit == 'B') - fmt[11] = '9'; - - nl_dump_line(p, fmt, res, unit, tc->tc_stats[RTNL_TC_RATE_PPS]); - - tc_dump(tc, NL_DUMP_LINE, p); - nl_dump(p, "\n"); + nl_dump_line(p, + " %10.2f %3s/s %10u/s\n", + res, + unit, + tc->tc_stats[RTNL_TC_RATE_PPS]); } int rtnl_tc_compare(struct nl_object *aobj, struct nl_object *bobj, |