[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210418013622.Horde.YlORJ7iYejhVF1yzgb2Eahq@webmail.uniroma2.it>
Date: Sun, 18 Apr 2021 01:36:22 +0200
From: Paolo Lungaroni <paolo.lungaroni@...roma2.it>
To: Stephen Hemminger <stephen@...workplumber.org>
Cc: David Ahern <dsahern@...nel.org>, netdev@...r.kernel.org,
Jakub Kicinski <kuba@...nel.org>,
Stefano Salsano <stefano.salsano@...roma2.it>,
Ahmed Abdelsalam <ahabdels.dev@...il.com>,
Andrea Mayer <andrea.mayer@...roma2.it>,
Paolo Lungaroni <paolo.lungaroni@...roma2.it>
Subject: Re: [RFC iproute2-next v2] seg6: add counters support for SRv6
Behaviors
Quoting Stephen Hemminger <stephen@...workplumber.org>:
> On Thu, 15 Apr 2021 20:06:43 +0200
> Paolo Lungaroni <paolo.lungaroni@...roma2.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.
Powered by blists - more mailing lists