[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180710210558.20278-23-stephen@networkplumber.org>
Date: Tue, 10 Jul 2018 14:05:49 -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 22/31] tc/pie: implement JSON output
From: Stephen Hemminger <sthemmin@...rosoft.com>
Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
tc/q_pie.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/tc/q_pie.c b/tc/q_pie.c
index f7924ef5e76c..086785588d64 100644
--- a/tc/q_pie.c
+++ b/tc/q_pie.c
@@ -135,8 +135,6 @@ static int pie_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
unsigned int ecn;
unsigned int bytemode;
- SPRINT_BUF(b1);
-
if (opt == NULL)
return 0;
@@ -145,40 +143,40 @@ static int pie_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (tb[TCA_PIE_LIMIT] &&
RTA_PAYLOAD(tb[TCA_PIE_LIMIT]) >= sizeof(__u32)) {
limit = rta_getattr_u32(tb[TCA_PIE_LIMIT]);
- fprintf(f, "limit %up ", limit);
+ print_uint(PRINT_ANY, "limit", "limit %up ", limit);
}
if (tb[TCA_PIE_TARGET] &&
RTA_PAYLOAD(tb[TCA_PIE_TARGET]) >= sizeof(__u32)) {
target = rta_getattr_u32(tb[TCA_PIE_TARGET]);
- fprintf(f, "target %s ", sprint_time(target, b1));
+ print_time("target", "target %s ", target);
}
if (tb[TCA_PIE_TUPDATE] &&
RTA_PAYLOAD(tb[TCA_PIE_TUPDATE]) >= sizeof(__u32)) {
tupdate = rta_getattr_u32(tb[TCA_PIE_TUPDATE]);
- fprintf(f, "tupdate %s ", sprint_time(tupdate, b1));
+ print_time("tupdate", "tupdate %s ", tupdate);
}
if (tb[TCA_PIE_ALPHA] &&
RTA_PAYLOAD(tb[TCA_PIE_ALPHA]) >= sizeof(__u32)) {
alpha = rta_getattr_u32(tb[TCA_PIE_ALPHA]);
- fprintf(f, "alpha %u ", alpha);
+ print_uint(PRINT_ANY, "alpha", "alpha %u ", alpha);
}
if (tb[TCA_PIE_BETA] &&
RTA_PAYLOAD(tb[TCA_PIE_BETA]) >= sizeof(__u32)) {
beta = rta_getattr_u32(tb[TCA_PIE_BETA]);
- fprintf(f, "beta %u ", beta);
+ print_uint(PRINT_ANY, "beta", "beta %u ", beta);
}
if (tb[TCA_PIE_ECN] && RTA_PAYLOAD(tb[TCA_PIE_ECN]) >= sizeof(__u32)) {
ecn = rta_getattr_u32(tb[TCA_PIE_ECN]);
if (ecn)
- fprintf(f, "ecn ");
+ print_null(PRINT_ANY, "ecn", "ecn ", NULL);
}
if (tb[TCA_PIE_BYTEMODE] &&
RTA_PAYLOAD(tb[TCA_PIE_BYTEMODE]) >= sizeof(__u32)) {
bytemode = rta_getattr_u32(tb[TCA_PIE_BYTEMODE]);
if (bytemode)
- fprintf(f, "bytemode ");
+ print_null(PRINT_ANY, "bytemode", "bytemode ", NULL);
}
return 0;
@@ -197,12 +195,17 @@ static int pie_print_xstats(struct qdisc_util *qu, FILE *f,
st = RTA_DATA(xstats);
/*prob is returned as a fracion of maximum integer value */
- fprintf(f, "prob %f delay %uus avg_dq_rate %u\n",
- (double)st->prob / (double)0xffffffff, st->delay,
- st->avg_dq_rate);
- fprintf(f, "pkts_in %u overlimit %u dropped %u maxq %u ecn_mark %u\n",
- st->packets_in, st->overlimit, st->dropped, st->maxq,
- st->ecn_mark);
+ print_float(PRINT_ANY, "prob", "prob %f",
+ (double)st->prob / (double)0xffffffff);
+ print_uint(PRINT_ANY, "delay", " delay %uus", st->delay);
+ print_uint(PRINT_ANY, "avg_dq_rate", " avg_dq_rate %u", st->avg_dq_rate);
+ print_string(PRINT_FP, NULL, "%s", _SL_);
+
+ print_uint(PRINT_ANY, "packets_in", "pkts_in %u", st->packets_in);
+ print_uint(PRINT_ANY, "overlimit", " overlimit %u", st->overlimit);
+ print_uint(PRINT_ANY, "dropped", " dropped %u", st->dropped);
+ print_uint(PRINT_ANY, "maxq", " maxq %u", st->maxq);
+ print_uint(PRINT_ANY, "ecn_mark", " ecn_mark %u", st->ecn_mark);
return 0;
}
--
2.18.0
Powered by blists - more mailing lists