[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180710210558.20278-31-stephen@networkplumber.org>
Date: Tue, 10 Jul 2018 14:05:57 -0700
From: Stephen Hemminger <stephen@...workplumber.org>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <sthemmin@...rosoft.com>,
Stephen Hemminger <stephen@...workplumber.org>
Subject: [PATCH v2 iproute2-next 30/31] tc/htb: implement JSON output
From: Stephen Hemminger <sthemmin@...rosoft.com>
Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
tc/q_htb.c | 53 ++++++++++++++++++++++++++++++-----------------------
1 file changed, 30 insertions(+), 23 deletions(-)
diff --git a/tc/q_htb.c b/tc/q_htb.c
index 7d5f6ce44773..e7026ad017a4 100644
--- a/tc/q_htb.c
+++ b/tc/q_htb.c
@@ -278,8 +278,6 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
__u64 rate64, ceil64;
SPRINT_BUF(b1);
- SPRINT_BUF(b2);
- SPRINT_BUF(b3);
if (opt == NULL)
return 0;
@@ -308,34 +306,39 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
RTA_PAYLOAD(tb[TCA_HTB_CEIL64]) >= sizeof(ceil64))
ceil64 = rta_getattr_u64(tb[TCA_HTB_CEIL64]);
- fprintf(f, "rate %s ", sprint_rate(rate64, b1));
+ print_rate("rate", "rate %s ", rate64);
if (hopt->rate.overhead)
- fprintf(f, "overhead %u ", hopt->rate.overhead);
+ print_uint(PRINT_ANY, "overhead", "overhead %u ", hopt->rate.overhead);
buffer = tc_calc_xmitsize(rate64, hopt->buffer);
- fprintf(f, "ceil %s ", sprint_rate(ceil64, b1));
+ print_rate("ceil", "ceil %s ", ceil64);
cbuffer = tc_calc_xmitsize(ceil64, hopt->cbuffer);
linklayer = (hopt->rate.linklayer & TC_LINKLAYER_MASK);
if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
- fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b3));
+ print_linklayer("linklayer", "linklayer %s ", linklayer);
+
if (show_details) {
- fprintf(f, "burst %s/%u mpu %s ",
- sprint_size(buffer, b1),
- 1<<hopt->rate.cell_log,
- sprint_size(hopt->rate.mpu, b2));
- fprintf(f, "cburst %s/%u mpu %s ",
- sprint_size(cbuffer, b1),
- 1<<hopt->ceil.cell_log,
- sprint_size(hopt->ceil.mpu, b2));
- fprintf(f, "level %d ", (int)hopt->level);
+ print_size("burst", "burst %s", buffer);
+ print_uint(PRINT_ANY, "rate_log", "/%u", 1u << hopt->rate.cell_log);
+ print_size("rate_mpu", " mpu %s ", hopt->rate.mpu);
+
+ print_size("cburst", "cburst %s", cbuffer);
+ print_uint(PRINT_ANY, "ceil_log", "/%u", 1u << hopt->ceil.cell_log);
+ print_size("ceil_mpu", " mpu %s ", hopt->ceil.mpu);
+ print_uint(PRINT_ANY, "level", "level %u ", hopt->level);
} else {
- fprintf(f, "burst %s ", sprint_size(buffer, b1));
- fprintf(f, "cburst %s ", sprint_size(cbuffer, b1));
+ print_size("burst", "burst %s ", buffer);
+ print_size("cburst", "cburst %s", cbuffer);
+ }
+
+ if (show_raw) {
+ print_0xhex(PRINT_ANY, "buffer",
+ "buffer [%08x]", hopt->buffer);
+ print_0xhex(PRINT_ANY, "cbuffer",
+ " cbuffer [%08x] ", hopt->cbuffer);
}
- if (show_raw)
- fprintf(f, "buffer [%08x] cbuffer [%08x] ",
- hopt->buffer, hopt->cbuffer);
}
+
if (tb[TCA_HTB_INIT]) {
gopt = RTA_DATA(tb[TCA_HTB_INIT]);
if (RTA_PAYLOAD(tb[TCA_HTB_INIT]) < sizeof(*gopt)) return -1;
@@ -370,9 +373,13 @@ static int htb_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstat
return -1;
st = RTA_DATA(xstats);
- fprintf(f, " lended: %u borrowed: %u giants: %u\n",
- st->lends, st->borrows, st->giants);
- fprintf(f, " tokens: %d ctokens: %d\n", st->tokens, st->ctokens);
+ print_uint(PRINT_ANY, "lended", " lended: %u", st->lends);
+ print_uint(PRINT_ANY, "borrowed", " borrowed: %u", st->borrows);
+ print_uint(PRINT_ANY, "giants", " giants: %u", st->giants);
+
+ print_string(PRINT_FP, NULL, "%s", _SL_);
+ print_int(PRINT_ANY, "tokens", " tokens: %d", st->tokens);
+ print_int(PRINT_ANY, "ctokens", " ctokens: %d", st->ctokens);
return 0;
}
--
2.18.0
Powered by blists - more mailing lists