]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
tc: red: JSON-ify RED output
authorJakub Kicinski <jakub.kicinski@netronome.com>
Fri, 26 Jan 2018 19:27:56 +0000 (11:27 -0800)
committerDavid Ahern <dsahern@gmail.com>
Fri, 26 Jan 2018 20:59:55 +0000 (12:59 -0800)
Make JSON output work with RED Qdiscs.  Float/double printing
helpers have to be added/uncommented to print the probability.
Since TC stats in general are not split out to a separate object
the xstats printed by this patch are not separated either.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
include/json_print.h
lib/json_print.c
lib/json_writer.c
tc/q_red.c

index dc4d2bb3ba59a70e8eeeb2e8be9228dbcab245c2..2ca7830adbd6cfb6f89e690a419fa7da35894e56 100644 (file)
@@ -64,6 +64,7 @@ _PRINT_FUNC(hu, unsigned short);
 _PRINT_FUNC(hex, unsigned int);
 _PRINT_FUNC(0xhex, unsigned int);
 _PRINT_FUNC(lluint, unsigned long long int);
+_PRINT_FUNC(float, double);
 #undef _PRINT_FUNC
 
 #endif /* _JSON_PRINT_H_ */
index aa527af652c57e4c559d934156d7fbddebc9a5a2..6518ba98f5bf8cc0875fa089dcfa2fa7e185f121 100644 (file)
@@ -120,6 +120,7 @@ _PRINT_FUNC(int, int);
 _PRINT_FUNC(hu, unsigned short);
 _PRINT_FUNC(uint, uint64_t);
 _PRINT_FUNC(lluint, unsigned long long int);
+_PRINT_FUNC(float, double);
 #undef _PRINT_FUNC
 
 void print_color_string(enum output_type type,
index 6b77d288cce2b3f1dfeb46d55c9a8ad81afd26a1..f3eeaf7bc4791f64d871486de85c7b273540c9ae 100644 (file)
@@ -209,12 +209,10 @@ void jsonw_float_fmt(json_writer_t *self, const char *fmt, double num)
        jsonw_printf(self, fmt, num);
 }
 
-#ifdef notused
 void jsonw_float(json_writer_t *self, double num)
 {
        jsonw_printf(self, "%g", num);
 }
-#endif
 
 void jsonw_hu(json_writer_t *self, unsigned short num)
 {
@@ -249,13 +247,11 @@ void jsonw_bool_field(json_writer_t *self, const char *prop, bool val)
        jsonw_bool(self, val);
 }
 
-#ifdef notused
 void jsonw_float_field(json_writer_t *self, const char *prop, double val)
 {
        jsonw_name(self, prop);
        jsonw_float(self, val);
 }
-#endif
 
 void jsonw_float_field_fmt(json_writer_t *self,
                           const char *prop,
index 1949558f14f9d3e1ae8d0a6a55b6da8017785a9d..40ba7c3e07c174a61dd0780e021fddad914d25a3 100644 (file)
@@ -183,23 +183,34 @@ static int red_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt)
            RTA_PAYLOAD(tb[TCA_RED_MAX_P]) >= sizeof(__u32))
                max_P = rta_getattr_u32(tb[TCA_RED_MAX_P]);
 
-       fprintf(f, "limit %s min %s max %s ",
-               sprint_size(qopt->limit, b1),
-               sprint_size(qopt->qth_min, b2),
-               sprint_size(qopt->qth_max, b3));
+       print_uint(PRINT_JSON, "limit", NULL, qopt->limit);
+       print_string(PRINT_FP, NULL, "limit %s ", sprint_size(qopt->limit, b1));
+       print_uint(PRINT_JSON, "min", NULL, qopt->qth_min);
+       print_string(PRINT_FP, NULL, "min %s ", sprint_size(qopt->qth_min, b2));
+       print_uint(PRINT_JSON, "max", NULL, qopt->qth_max);
+       print_string(PRINT_FP, NULL, "max %s ", sprint_size(qopt->qth_max, b3));
+
        if (qopt->flags & TC_RED_ECN)
-               fprintf(f, "ecn ");
+               print_bool(PRINT_ANY, "ecn", "ecn ", true);
+       else
+               print_bool(PRINT_ANY, "ecn", NULL, false);
        if (qopt->flags & TC_RED_HARDDROP)
-               fprintf(f, "harddrop ");
+               print_bool(PRINT_ANY, "harddrop", "harddrop ", true);
+       else
+               print_bool(PRINT_ANY, "harddrop", NULL, false);
        if (qopt->flags & TC_RED_ADAPTATIVE)
-               fprintf(f, "adaptive ");
+               print_bool(PRINT_ANY, "adaptive", "adaptive ", true);
+       else
+               print_bool(PRINT_ANY, "adaptive", NULL, false);
        if (show_details) {
-               fprintf(f, "ewma %u ", qopt->Wlog);
+               print_uint(PRINT_ANY, "ewma", "ewma %u ", qopt->Wlog);
                if (max_P)
-                       fprintf(f, "probability %lg ", max_P / pow(2, 32));
+                       print_float(PRINT_ANY, "probability",
+                                   "probability %lg ", max_P / pow(2, 32));
                else
-                       fprintf(f, "Plog %u ", qopt->Plog);
-               fprintf(f, "Scell_log %u", qopt->Scell_log);
+                       print_uint(PRINT_ANY, "Plog", "Plog %u ", qopt->Plog);
+               print_uint(PRINT_ANY, "Scell_log", "Scell_log %u",
+                          qopt->Scell_log);
        }
        return 0;
 }
@@ -216,10 +227,10 @@ static int red_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstat
                return -1;
 
        st = RTA_DATA(xstats);
-       fprintf(f, "  marked %u early %u pdrop %u other %u",
-               st->marked, st->early, st->pdrop, st->other);
-       return 0;
-
+       print_uint(PRINT_ANY, "marked", "  marked %u ", st->marked);
+       print_uint(PRINT_ANY, "early", "early %u ", st->early);
+       print_uint(PRINT_ANY, "pdrop", "pdrop %u ", st->pdrop);
+       print_uint(PRINT_ANY, "other", "other %u ", st->other);
 #endif
        return 0;
 }