Quoting Stephen Hemminger <step...@networkplumber.org>:
On Thu, 15 Apr 2021 20:06:43 +0200
Paolo Lungaroni <paolo.lungar...@uniroma2.it> wrote:
+ if (is_json_context())
+ open_json_object("stats64");
+
+ if (tb[SEG6_LOCAL_CNT_PACKETS]) {
+ packets = rta_getattr_u64(tb[SEG6_LOCAL_CNT_PACKETS]);
+ if (is_json_context()) {
+ print_u64(PRINT_JSON, "packets", NULL, packets);
+ } else {
+ print_string(PRINT_FP, NULL, "%s ", "packets");
+ print_num(fp, 1, packets);
+ }
+ }
+
+ if (tb[SEG6_LOCAL_CNT_BYTES]) {
+ bytes = rta_getattr_u64(tb[SEG6_LOCAL_CNT_BYTES]);
+ if (is_json_context()) {
+ print_u64(PRINT_JSON, "bytes", NULL, bytes);
+ } else {
+ print_string(PRINT_FP, NULL, "%s ", "bytes");
+ print_num(fp, 1, bytes);
+ }
+ }
+
+ if (tb[SEG6_LOCAL_CNT_ERRORS]) {
+ errors = rta_getattr_u64(tb[SEG6_LOCAL_CNT_ERRORS]);
+ if (is_json_context()) {
+ print_u64(PRINT_JSON, "errors", NULL, errors);
+ } else {
+ print_string(PRINT_FP, NULL, "%s ", "errors");
+ print_num(fp, 1, errors);
+ }
+ }
+
+ if (is_json_context())
+ close_json_object();
The code would be cleaner with doing if (is_json_context()) once at
outer loop.
See print_vf_stats64.
Hi Stephen,
thank you for your suggestion. We will change the code as you suggest.
Paolo.