[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180710210558.20278-20-stephen@networkplumber.org>
Date: Tue, 10 Jul 2018 14:05:46 -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 19/31] tc/tbf: implement JSON output format
From: Stephen Hemminger <sthemmin@...rosoft.com>
Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
tc/q_tbf.c | 48 ++++++++++++++++++++++++++----------------------
1 file changed, 26 insertions(+), 22 deletions(-)
diff --git a/tc/q_tbf.c b/tc/q_tbf.c
index b9465b20d2be..2695b4fb00e6 100644
--- a/tc/q_tbf.c
+++ b/tc/q_tbf.c
@@ -266,10 +266,6 @@ static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
double latency;
__u64 rate64 = 0, prate64 = 0;
- SPRINT_BUF(b1);
- SPRINT_BUF(b2);
- SPRINT_BUF(b3);
-
if (opt == NULL)
return 0;
@@ -285,53 +281,61 @@ static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (tb[TCA_TBF_RATE64] &&
RTA_PAYLOAD(tb[TCA_TBF_RATE64]) >= sizeof(rate64))
rate64 = rta_getattr_u64(tb[TCA_TBF_RATE64]);
- fprintf(f, "rate %s ", sprint_rate(rate64, b1));
+
+ print_rate("rate", "rate %s ", rate64);
buffer = tc_calc_xmitsize(rate64, qopt->buffer);
+ print_size("burst", "burst %s", buffer);
if (show_details) {
- fprintf(f, "burst %s/%u mpu %s ", sprint_size(buffer, b1),
- 1<<qopt->rate.cell_log, sprint_size(qopt->rate.mpu, b2));
- } else {
- fprintf(f, "burst %s ", sprint_size(buffer, b1));
+ print_uint(PRINT_ANY, "cell_log", "/%u",
+ 1 << qopt->rate.cell_log);
+ print_size("mpu", " mpu %s ", qopt->rate.mpu);
}
+
if (show_raw)
- fprintf(f, "[%08x] ", qopt->buffer);
+ print_0xhex(PRINT_FP, NULL, "[%08x] ", qopt->buffer);
+
prate64 = qopt->peakrate.rate;
if (tb[TCA_TBF_PRATE64] &&
RTA_PAYLOAD(tb[TCA_TBF_PRATE64]) >= sizeof(prate64))
prate64 = rta_getattr_u64(tb[TCA_TBF_PRATE64]);
+
if (prate64) {
- fprintf(f, "peakrate %s ", sprint_rate(prate64, b1));
+ print_rate("peakrate", "peakrate %s ", prate64);
if (qopt->mtu || qopt->peakrate.mpu) {
mtu = tc_calc_xmitsize(prate64, qopt->mtu);
if (show_details) {
- fprintf(f, "mtu %s/%u mpu %s ", sprint_size(mtu, b1),
- 1<<qopt->peakrate.cell_log, sprint_size(qopt->peakrate.mpu, b2));
+ print_size("mtu", "mtu %s", mtu);
+ print_uint(PRINT_FP, NULL, "/%u",
+ 1 << qopt->peakrate.cell_log);
+ print_size("peakrate", " mpu %s ", qopt->peakrate.mpu);
} else {
- fprintf(f, "minburst %s ", sprint_size(mtu, b1));
+ print_size("minburst", "minburst %s ", mtu);
}
if (show_raw)
- fprintf(f, "[%08x] ", qopt->mtu);
+ print_0xhex(PRINT_FP, NULL, "[%08x] ", qopt->mtu);
}
}
latency = TIME_UNITS_PER_SEC*(qopt->limit/(double)rate64) - tc_core_tick2time(qopt->buffer);
if (prate64) {
- double lat2 = TIME_UNITS_PER_SEC*(qopt->limit/(double)prate64) - tc_core_tick2time(qopt->mtu);
+ double lat2 = TIME_UNITS_PER_SEC*(qopt->limit/(double)prate64)
+ - tc_core_tick2time(qopt->mtu);
if (lat2 > latency)
latency = lat2;
}
+
if (latency >= 0.0)
- fprintf(f, "lat %s ", sprint_time(latency, b1));
+ print_time("latency", "lat %s ", latency);
if (show_raw || latency < 0.0)
- fprintf(f, "limit %s ", sprint_size(qopt->limit, b1));
+ print_size("limit", "limit %s ", qopt->limit);
+
+ if (qopt->rate.overhead)
+ print_uint(PRINT_ANY, "overhead", "overhead %u", qopt->rate.overhead);
- if (qopt->rate.overhead) {
- fprintf(f, "overhead %d", qopt->rate.overhead);
- }
linklayer = (qopt->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);
return 0;
}
--
2.18.0
Powered by blists - more mailing lists