[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180710210558.20278-10-stephen@networkplumber.org>
Date: Tue, 10 Jul 2018 14:05:36 -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 09/31] tc/fq: support JSON output
From: Stephen Hemminger <sthemmin@...rosoft.com>
Output parameters optionally in JSON.
Signed-off-by: Stephen Hemminger <stephen@...workplumber.org>
---
tc/q_fq.c | 103 +++++++++++++++++++++++++++++++-----------------------
1 file changed, 60 insertions(+), 43 deletions(-)
diff --git a/tc/q_fq.c b/tc/q_fq.c
index f3dbf2ba0c6f..fa546c6ae500 100644
--- a/tc/q_fq.c
+++ b/tc/q_fq.c
@@ -233,14 +233,6 @@ static int fq_parse_opt(struct qdisc_util *qu, int argc, char **argv,
static int fq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
{
struct rtattr *tb[TCA_FQ_MAX + 1];
- unsigned int plimit, flow_plimit;
- unsigned int buckets_log;
- int pacing;
- unsigned int rate, quantum;
- unsigned int refill_delay;
- unsigned int orphan_mask;
-
- SPRINT_BUF(b1);
if (opt == NULL)
return 0;
@@ -249,65 +241,80 @@ static int fq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
if (tb[TCA_FQ_PLIMIT] &&
RTA_PAYLOAD(tb[TCA_FQ_PLIMIT]) >= sizeof(__u32)) {
- plimit = rta_getattr_u32(tb[TCA_FQ_PLIMIT]);
- fprintf(f, "limit %up ", plimit);
+ unsigned int plimit = rta_getattr_u32(tb[TCA_FQ_PLIMIT]);
+
+ print_uint(PRINT_ANY, "limit", "limit %up ", plimit);
}
if (tb[TCA_FQ_FLOW_PLIMIT] &&
RTA_PAYLOAD(tb[TCA_FQ_FLOW_PLIMIT]) >= sizeof(__u32)) {
- flow_plimit = rta_getattr_u32(tb[TCA_FQ_FLOW_PLIMIT]);
- fprintf(f, "flow_limit %up ", flow_plimit);
+ unsigned int flow_plimit = rta_getattr_u32(tb[TCA_FQ_FLOW_PLIMIT]);
+
+ print_uint(PRINT_ANY, "flow_limit",
+ "flow_limit %up ", flow_plimit);
}
if (tb[TCA_FQ_BUCKETS_LOG] &&
RTA_PAYLOAD(tb[TCA_FQ_BUCKETS_LOG]) >= sizeof(__u32)) {
- buckets_log = rta_getattr_u32(tb[TCA_FQ_BUCKETS_LOG]);
- fprintf(f, "buckets %u ", 1U << buckets_log);
+ unsigned int buckets_log = rta_getattr_u32(tb[TCA_FQ_BUCKETS_LOG]);
+
+ print_uint(PRINT_ANY, "buckets",
+ "buckets %u ", 1U << buckets_log);
}
if (tb[TCA_FQ_ORPHAN_MASK] &&
RTA_PAYLOAD(tb[TCA_FQ_ORPHAN_MASK]) >= sizeof(__u32)) {
- orphan_mask = rta_getattr_u32(tb[TCA_FQ_ORPHAN_MASK]);
- fprintf(f, "orphan_mask %u ", orphan_mask);
+ unsigned int orphan_mask = rta_getattr_u32(tb[TCA_FQ_ORPHAN_MASK]);
+
+ print_uint(PRINT_ANY, "orphan_mask",
+ "orphan_mask %u ", orphan_mask);
}
if (tb[TCA_FQ_RATE_ENABLE] &&
RTA_PAYLOAD(tb[TCA_FQ_RATE_ENABLE]) >= sizeof(int)) {
- pacing = rta_getattr_u32(tb[TCA_FQ_RATE_ENABLE]);
+ unsigned int pacing = rta_getattr_u32(tb[TCA_FQ_RATE_ENABLE]);
if (pacing == 0)
- fprintf(f, "nopacing ");
+ print_null(PRINT_ANY, "nopacing",
+ " nopacing ", NULL);
}
if (tb[TCA_FQ_QUANTUM] &&
RTA_PAYLOAD(tb[TCA_FQ_QUANTUM]) >= sizeof(__u32)) {
- quantum = rta_getattr_u32(tb[TCA_FQ_QUANTUM]);
- fprintf(f, "quantum %u ", quantum);
+ unsigned int quantum = rta_getattr_u32(tb[TCA_FQ_QUANTUM]);
+
+ print_uint(PRINT_ANY, "quantum",
+ "quantum %u ", quantum);
}
if (tb[TCA_FQ_INITIAL_QUANTUM] &&
RTA_PAYLOAD(tb[TCA_FQ_INITIAL_QUANTUM]) >= sizeof(__u32)) {
- quantum = rta_getattr_u32(tb[TCA_FQ_INITIAL_QUANTUM]);
- fprintf(f, "initial_quantum %u ", quantum);
+ unsigned int quantum = rta_getattr_u32(tb[TCA_FQ_INITIAL_QUANTUM]);
+
+ print_uint(PRINT_ANY, "initial_quantum",
+ "initial_quantum %u ", quantum);
}
if (tb[TCA_FQ_FLOW_MAX_RATE] &&
RTA_PAYLOAD(tb[TCA_FQ_FLOW_MAX_RATE]) >= sizeof(__u32)) {
- rate = rta_getattr_u32(tb[TCA_FQ_FLOW_MAX_RATE]);
+ unsigned int rate = rta_getattr_u32(tb[TCA_FQ_FLOW_MAX_RATE]);
if (rate != ~0U)
- fprintf(f, "maxrate %s ", sprint_rate(rate, b1));
+ print_rate("maxrate", "maxrate %s ", rate);
}
if (tb[TCA_FQ_FLOW_DEFAULT_RATE] &&
RTA_PAYLOAD(tb[TCA_FQ_FLOW_DEFAULT_RATE]) >= sizeof(__u32)) {
- rate = rta_getattr_u32(tb[TCA_FQ_FLOW_DEFAULT_RATE]);
+ unsigned int rate = rta_getattr_u32(tb[TCA_FQ_FLOW_DEFAULT_RATE]);
if (rate != 0)
- fprintf(f, "defrate %s ", sprint_rate(rate, b1));
+ print_rate("defrate", "defrate %s ", rate);
}
if (tb[TCA_FQ_LOW_RATE_THRESHOLD] &&
RTA_PAYLOAD(tb[TCA_FQ_LOW_RATE_THRESHOLD]) >= sizeof(__u32)) {
- rate = rta_getattr_u32(tb[TCA_FQ_LOW_RATE_THRESHOLD]);
+ unsigned int rate = rta_getattr_u32(tb[TCA_FQ_LOW_RATE_THRESHOLD]);
if (rate != 0)
- fprintf(f, "low_rate_threshold %s ", sprint_rate(rate, b1));
+ print_rate("low_rate_threshold",
+ "low_rate_threshold %s ", rate);
}
if (tb[TCA_FQ_FLOW_REFILL_DELAY] &&
RTA_PAYLOAD(tb[TCA_FQ_FLOW_REFILL_DELAY]) >= sizeof(__u32)) {
- refill_delay = rta_getattr_u32(tb[TCA_FQ_FLOW_REFILL_DELAY]);
- fprintf(f, "refill_delay %s ", sprint_time(refill_delay, b1));
+ unsigned int refill_delay = rta_getattr_u32(tb[TCA_FQ_FLOW_REFILL_DELAY]);
+
+ print_time("refill_delay",
+ "refill_delay %s ", refill_delay);
}
return 0;
@@ -326,29 +333,39 @@ static int fq_print_xstats(struct qdisc_util *qu, FILE *f,
st = RTA_DATA(xstats);
- fprintf(f, " %u flows (%u inactive, %u throttled)",
- st->flows, st->inactive_flows, st->throttled_flows);
+ print_uint(PRINT_ANY, "flows", " %u flows", st->flows);
+ print_uint(PRINT_ANY, "inactive", " (%u inactive,", st->inactive_flows);
+ print_uint(PRINT_ANY, "throttled", " %u throttled)", st->throttled_flows);
if (st->time_next_delayed_flow > 0)
- fprintf(f, ", next packet delay %llu ns", st->time_next_delayed_flow);
+ print_u64(PRINT_ANY, "next_delayed",
+ ", next packet delay %llu ns", st->time_next_delayed_flow);
- fprintf(f, "\n %llu gc, %llu highprio",
- st->gc_flows, st->highprio_packets);
+ print_string(PRINT_FP, NULL, "%s", _SL_);
+ print_u64(PRINT_ANY, "gc_flows", " %llu gc,", st->gc_flows);
+ print_u64(PRINT_ANY, "highprio", " %llu highprio", st->highprio_packets);
if (st->tcp_retrans)
- fprintf(f, ", %llu retrans", st->tcp_retrans);
+ print_u64(PRINT_ANY, "retrans",
+ ", %llu retrans", st->tcp_retrans);
- fprintf(f, ", %llu throttled", st->throttled);
+ print_uint(PRINT_ANY, "throttled", ", %llu throttled", st->throttled);
if (st->unthrottle_latency_ns)
- fprintf(f, ", %u ns latency", st->unthrottle_latency_ns);
+ print_uint(PRINT_ANY, "latency",
+ ", %u ns latency", st->unthrottle_latency_ns);
if (st->flows_plimit)
- fprintf(f, ", %llu flows_plimit", st->flows_plimit);
-
- if (st->pkts_too_long || st->allocation_errors)
- fprintf(f, "\n %llu too long pkts, %llu alloc errors\n",
- st->pkts_too_long, st->allocation_errors);
+ print_u64(PRINT_ANY, "plimit",
+ ", %llu flows_plimit", st->flows_plimit);
+
+ if (st->pkts_too_long || st->allocation_errors) {
+ print_string(PRINT_FP, NULL, "%s", _SL_);
+ print_u64(PRINT_ANY, "pkts_too_long",
+ " %llu too long pkts", st->pkts_too_long);
+ print_u64(PRINT_ANY, "alloc_errors",
+ ", %llu alloc errors", st->allocation_errors);
+ }
return 0;
}
--
2.18.0
Powered by blists - more mailing lists