netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [iproute2 0/3] Adding json support for showing htb&tbf classes
@ 2019-05-06 16:18 Nir Weiner
  2019-05-06 16:18 ` [iproute2 1/3] tc: jsonify htb qdisc parameters Nir Weiner
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Nir Weiner @ 2019-05-06 16:18 UTC (permalink / raw)
  To: netdev; +Cc: liran.alon, nir.weiner

Adding a json support for running the command 
tc -j class show dev <dev> 
for the htb kind and the tbf kind

Nir Weiner (3):
  tc: jsonify htb qdisc parameters
  tc: jsonify tbf qdisc parameters
  tc: jsonify class core

 tc/q_htb.c    | 19 ++++++++++---------
 tc/q_tbf.c    | 20 ++++++++++----------
 tc/tc_class.c | 29 +++++++++++++++++++----------
 3 files changed, 39 insertions(+), 29 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [iproute2 1/3] tc: jsonify htb qdisc parameters
  2019-05-06 16:18 [iproute2 0/3] Adding json support for showing htb&tbf classes Nir Weiner
@ 2019-05-06 16:18 ` Nir Weiner
  2019-05-06 16:18 ` [iproute2 2/3] tc: jsonify tbf " Nir Weiner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Nir Weiner @ 2019-05-06 16:18 UTC (permalink / raw)
  To: netdev; +Cc: liran.alon, nir.weiner

Add json output to htb qdisc parameters.

Fixes: f354fa6aa5ff05dd214a595e5159ef93a6ab1934
Acked-by: John Haxby <john.haxby@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
Signed-off-by: Nir Weiner <nir.weiner@oracle.com>
---
 tc/q_htb.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/tc/q_htb.c b/tc/q_htb.c
index 520522266e00..0e0f479d423f 100644
--- a/tc/q_htb.c
+++ b/tc/q_htb.c
@@ -299,16 +299,16 @@ 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_string(PRINT_ANY, "rate", "rate %s ", sprint_rate(rate64, b1));
 		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_string(PRINT_ANY, "ceil", "ceil %s ", sprint_rate(ceil64, b1));
 		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_string(PRINT_ANY, "linklayer", "linklayer %s ", sprint_linklayer(linklayer, b3));
 		if (show_details) {
 			fprintf(f, "burst %s/%u mpu %s ",
 				sprint_size(buffer, b1),
@@ -320,12 +320,13 @@ static int htb_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 				sprint_size(hopt->ceil.mpu, b2));
 			fprintf(f, "level %d ", (int)hopt->level);
 		} else {
-			fprintf(f, "burst %s ", sprint_size(buffer, b1));
-			fprintf(f, "cburst %s ", sprint_size(cbuffer, b1));
+			print_string(PRINT_ANY, "burst", "burst %s ", sprint_size(buffer, b1));
+			print_string(PRINT_ANY, "cburst", "cburst %s ", sprint_size(cbuffer, b1));
+		}
+		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]);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [iproute2 2/3] tc: jsonify tbf qdisc parameters
  2019-05-06 16:18 [iproute2 0/3] Adding json support for showing htb&tbf classes Nir Weiner
  2019-05-06 16:18 ` [iproute2 1/3] tc: jsonify htb qdisc parameters Nir Weiner
@ 2019-05-06 16:18 ` Nir Weiner
  2019-05-17 17:35   ` David Ahern
  2019-05-06 16:18 ` [iproute2 3/3] tc: jsonify class core Nir Weiner
  2019-05-06 16:22 ` [iproute2 0/3] Adding json support for showing htb&tbf classes Stephen Hemminger
  3 siblings, 1 reply; 7+ messages in thread
From: Nir Weiner @ 2019-05-06 16:18 UTC (permalink / raw)
  To: netdev; +Cc: liran.alon, nir.weiner

Add json output to tbf qdisc parameters.

Acked-by: John Haxby <john.haxby@oracle.com>
Signed-off-by: Nir Weiner <nir.weiner@oracle.com>
Suggested-by: Liran Alon <liran.alon@oracle.com>
---
 tc/q_tbf.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/tc/q_tbf.c b/tc/q_tbf.c
index b9465b20d2be..fd824e67e4f2 100644
--- a/tc/q_tbf.c
+++ b/tc/q_tbf.c
@@ -285,32 +285,32 @@ 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_string(PRINT_ANY, "rate", "rate %s ", sprint_rate(rate64, b1));
 	buffer = tc_calc_xmitsize(rate64, qopt->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_string(PRINT_ANY, "burst", "burst %s ", sprint_size(buffer, b1));
 	}
 	if (show_raw)
-		fprintf(f, "[%08x] ", qopt->buffer);
+		print_0xhex(PRINT_ANY, "buffer", "[%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_string(PRINT_ANY, "peakrate", "peakrate %s ", sprint_rate(prate64, b1));
 		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));
 			} else {
-				fprintf(f, "minburst %s ", sprint_size(mtu, b1));
+				print_string(PRINT_ANY, "minburst", "minburst %s ", sprint_size(mtu, b1));
 			}
 			if (show_raw)
-				fprintf(f, "[%08x] ", qopt->mtu);
+				print_0xhex(PRINT_ANY, "mtu", "[%08x] ", qopt->mtu);
 		}
 	}
 
@@ -322,16 +322,16 @@ static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
 			latency = lat2;
 	}
 	if (latency >= 0.0)
-		fprintf(f, "lat %s ", sprint_time(latency, b1));
+		print_string(PRINT_ANY, "lat", "lat %s ", sprint_time(latency, b1));
 	if (show_raw || latency < 0.0)
-		fprintf(f, "limit %s ", sprint_size(qopt->limit, b1));
+		print_string(PRINT_ANY, "limit", "limit %s ", sprint_size(qopt->limit, b1));
 
 	if (qopt->rate.overhead) {
-		fprintf(f, "overhead %d", qopt->rate.overhead);
+		print_int(PRINT_ANY, "overhead", "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_string(PRINT_ANY, "linklayer", "linklayer %s ", sprint_linklayer(linklayer, b3));
 
 	return 0;
 }
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [iproute2 3/3] tc: jsonify class core
  2019-05-06 16:18 [iproute2 0/3] Adding json support for showing htb&tbf classes Nir Weiner
  2019-05-06 16:18 ` [iproute2 1/3] tc: jsonify htb qdisc parameters Nir Weiner
  2019-05-06 16:18 ` [iproute2 2/3] tc: jsonify tbf " Nir Weiner
@ 2019-05-06 16:18 ` Nir Weiner
  2019-05-06 16:22 ` [iproute2 0/3] Adding json support for showing htb&tbf classes Stephen Hemminger
  3 siblings, 0 replies; 7+ messages in thread
From: Nir Weiner @ 2019-05-06 16:18 UTC (permalink / raw)
  To: netdev; +Cc: liran.alon, nir.weiner

Add json output to class core.

Acked-by: John Haxby <john.haxby@oracle.com>
Reviewed-by: Liran Alon <liran.alon@oracle.com>
Signed-off-by: Nir Weiner <nir.weiner@oracle.com>
---
 tc/tc_class.c | 29 +++++++++++++++++++----------
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/tc/tc_class.c b/tc/tc_class.c
index 7ac700d7ab31..68627f4fcc70 100644
--- a/tc/tc_class.c
+++ b/tc/tc_class.c
@@ -333,8 +333,10 @@ int print_class(struct nlmsghdr *n, void *arg)
 		return -1;
 	}
 
+	open_json_object(NULL);
+
 	if (n->nlmsg_type == RTM_DELTCLASS)
-		fprintf(fp, "deleted ");
+		print_bool(PRINT_ANY, "deleted", "deleted ", true);
 
 	abuf[0] = 0;
 	if (t->tcm_handle) {
@@ -343,42 +345,47 @@ int print_class(struct nlmsghdr *n, void *arg)
 		else
 			print_tc_classid(abuf, sizeof(abuf), t->tcm_handle);
 	}
-	fprintf(fp, "class %s %s ", rta_getattr_str(tb[TCA_KIND]), abuf);
+
+	print_string(PRINT_ANY, "kind", "class %s ", rta_getattr_str(tb[TCA_KIND]));
+	print_string(PRINT_ANY, "classid", "%s ", abuf);
 
 	if (filter_ifindex == 0)
-		fprintf(fp, "dev %s ", ll_index_to_name(t->tcm_ifindex));
+		print_string(PRINT_ANY, "dev", "dev %s ", ll_index_to_name(t->tcm_ifindex));
 
 	if (t->tcm_parent == TC_H_ROOT)
-		fprintf(fp, "root ");
+		print_bool(PRINT_ANY, "root", "root ", true);
 	else {
 		if (filter_qdisc)
 			print_tc_classid(abuf, sizeof(abuf), TC_H_MIN(t->tcm_parent));
 		else
 			print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
-		fprintf(fp, "parent %s ", abuf);
+		print_string(PRINT_ANY, "parent", "parent %s ", abuf);
 	}
 	if (t->tcm_info)
-		fprintf(fp, "leaf %x: ", t->tcm_info>>16);
+		print_uint(PRINT_ANY, "leaf", "leaf %x: ", t->tcm_info>>16);
 	q = get_qdisc_kind(RTA_DATA(tb[TCA_KIND]));
 	if (tb[TCA_OPTIONS]) {
+		open_json_object("options");
 		if (q && q->print_copt)
 			q->print_copt(q, fp, tb[TCA_OPTIONS]);
 		else
-			fprintf(fp, "[cannot parse class parameters]");
+			print_string(PRINT_FP, NULL, "[cannot parse class parameters]", NULL);
+		close_json_object();
 	}
-	fprintf(fp, "\n");
+	print_string(PRINT_FP, NULL, "\n", NULL);
 	if (show_stats) {
 		struct rtattr *xstats = NULL;
 
 		if (tb[TCA_STATS] || tb[TCA_STATS2]) {
 			print_tcstats_attr(fp, tb, " ", &xstats);
-			fprintf(fp, "\n");
+			print_string(PRINT_FP, NULL, "\n", NULL);
 		}
 		if (q && (xstats || tb[TCA_XSTATS]) && q->print_xstats) {
 			q->print_xstats(q, fp, xstats ? : tb[TCA_XSTATS]);
-			fprintf(fp, "\n");
+			print_string(PRINT_FP, NULL, "\n", NULL);
 		}
 	}
+	close_json_object();
 	fflush(fp);
 	return 0;
 }
@@ -450,10 +457,12 @@ static int tc_class_list(int argc, char **argv)
 		return 1;
 	}
 
+	new_json_obj(json);
 	if (rtnl_dump_filter(&rth, print_class, stdout) < 0) {
 		fprintf(stderr, "Dump terminated\n");
 		return 1;
 	}
+	delete_json_obj();
 
 	if (show_graph)
 		graph_cls_show(stdout, &buf[0], &root_cls_list, 0);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [iproute2 0/3] Adding json support for showing htb&tbf classes
  2019-05-06 16:18 [iproute2 0/3] Adding json support for showing htb&tbf classes Nir Weiner
                   ` (2 preceding siblings ...)
  2019-05-06 16:18 ` [iproute2 3/3] tc: jsonify class core Nir Weiner
@ 2019-05-06 16:22 ` Stephen Hemminger
  3 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2019-05-06 16:22 UTC (permalink / raw)
  To: Nir Weiner; +Cc: netdev, liran.alon

On Mon,  6 May 2019 19:18:37 +0300
Nir Weiner <nir.weiner@oracle.com> wrote:

> Adding a json support for running the command 
> tc -j class show dev <dev> 
> for the htb kind and the tbf kind
> 
> Nir Weiner (3):
>   tc: jsonify htb qdisc parameters
>   tc: jsonify tbf qdisc parameters
>   tc: jsonify class core
> 
>  tc/q_htb.c    | 19 ++++++++++---------
>  tc/q_tbf.c    | 20 ++++++++++----------
>  tc/tc_class.c | 29 +++++++++++++++++++----------
>  3 files changed, 39 insertions(+), 29 deletions(-)
> 

These should go to iproute2-next

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [iproute2 2/3] tc: jsonify tbf qdisc parameters
  2019-05-06 16:18 ` [iproute2 2/3] tc: jsonify tbf " Nir Weiner
@ 2019-05-17 17:35   ` David Ahern
  2019-05-17 17:57     ` Stephen Hemminger
  0 siblings, 1 reply; 7+ messages in thread
From: David Ahern @ 2019-05-17 17:35 UTC (permalink / raw)
  To: Nir Weiner, netdev; +Cc: liran.alon

On 5/6/19 10:18 AM, Nir Weiner wrote:

>  	if (prate64) {
> -		fprintf(f, "peakrate %s ", sprint_rate(prate64, b1));
> +		print_string(PRINT_ANY, "peakrate", "peakrate %s ", sprint_rate(prate64, b1));
>  		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));


The fprintf under show_details should be converted as well. This applies
to patch 1 as well.

And, please add example output to each patch.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [iproute2 2/3] tc: jsonify tbf qdisc parameters
  2019-05-17 17:35   ` David Ahern
@ 2019-05-17 17:57     ` Stephen Hemminger
  0 siblings, 0 replies; 7+ messages in thread
From: Stephen Hemminger @ 2019-05-17 17:57 UTC (permalink / raw)
  To: David Ahern; +Cc: Nir Weiner, netdev, liran.alon

On Fri, 17 May 2019 11:35:16 -0600
David Ahern <dsahern@gmail.com> wrote:

> On 5/6/19 10:18 AM, Nir Weiner wrote:
> 
> >  	if (prate64) {
> > -		fprintf(f, "peakrate %s ", sprint_rate(prate64, b1));
> > +		print_string(PRINT_ANY, "peakrate", "peakrate %s ", sprint_rate(prate64, b1));
> >  		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));  
> 
> 
> The fprintf under show_details should be converted as well. This applies
> to patch 1 as well.
> 
> And, please add example output to each patch.

One trick I used was scanning for all calls to fprintf(f and replacing them

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-05-17 17:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-06 16:18 [iproute2 0/3] Adding json support for showing htb&tbf classes Nir Weiner
2019-05-06 16:18 ` [iproute2 1/3] tc: jsonify htb qdisc parameters Nir Weiner
2019-05-06 16:18 ` [iproute2 2/3] tc: jsonify tbf " Nir Weiner
2019-05-17 17:35   ` David Ahern
2019-05-17 17:57     ` Stephen Hemminger
2019-05-06 16:18 ` [iproute2 3/3] tc: jsonify class core Nir Weiner
2019-05-06 16:22 ` [iproute2 0/3] Adding json support for showing htb&tbf classes Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).