Adding json support for showing htb&tbf classes
Subsystems (2)
cover Adding json support for showing htb&tbf classes
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(-)
Signature · 1 line
2.17.1
PATCH 1/3 tc: jsonify htb qdisc parameters
Add json output to htb qdisc parameters.
--- tc/q_htb.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
tc/q_htb.c +10 -9
@@ -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 ]);
Signature · 1 line
2.17.1
PATCH 2/3 tc: jsonify tbf qdisc parameters
In reply to Nir WeinerAdd json output to tbf qdisc parameters.
--- tc/q_tbf.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
tc/q_tbf.c +10 -10
@@ -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 ; }
Signature · 1 line
2.17.1
Re: [iproute2 2/3] tc: jsonify tbf qdisc parameters
tc/q_tbf.c static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 308
Quoted 8 lines · Nir Weiner
tc/q_tbf.c +1
-1if (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.
Re: [iproute2 2/3] tc: jsonify tbf qdisc parameters
Quoted 15 lines · On Fri, 17 May 2019 11:35:16 -0600 David Ahern <[email protected]> wrote:
tc/q_tbf.c static int tbf_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) · line 308
Quoted 8 lines · Nir Weiner
tc/q_tbf.c +1
-1if (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_detailsshould be converted as well. This applies to patch 1 as well.
Quoted 1 line
And, please add example output to each patch.
One trick I used was scanning for all calls to fprintf(f and replacing them
PATCH 3/3 tc: jsonify class core
In reply to Nir WeinerAdd json output to class core.
--- tc/tc_class.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
tc/tc_class.c +19 -10
@@ -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 );
Signature · 1 line
2.17.1
Quoted 9 lines · On Mon, 6 May 2019 19:18:37 +0300 Nir Weiner <[email protected]> wrote:
Adding a json support for running the command
tc -j class show dev <dev>
for the htb kind and the tbf kindNir Weiner (3):
tc: jsonify htb qdisc parameters
tc: jsonify tbf qdisc parameters
tc: jsonify class core
Quoted 5 lines
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