[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1e6420f9-6646-30b2-480e-82348b84be32@nvidia.com>
Date: Thu, 3 Jun 2021 19:04:33 +0300
From: Roi Dayan <roid@...dia.com>
To: Stephen Hemminger <stephen@...workplumber.org>
CC: David Ahern <dsahern@...il.com>, <netdev@...r.kernel.org>,
"Jamal Hadi Salim" <jhs@...atatu.com>,
Paul Blakey <paulb@...dia.com>
Subject: Re: [PATCH iproute2-next] police: Add support for json output
On 2021-06-03 6:40 PM, Stephen Hemminger wrote:
> On Thu, 3 Jun 2021 10:27:55 +0300
> Roi Dayan <roid@...dia.com> wrote:
>
>> On 2021-06-02 5:29 PM, David Ahern wrote:
>>> On 5/27/21 7:07 AM, Roi Dayan wrote:
>>>> @@ -300,13 +300,13 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
>>>> RTA_PAYLOAD(tb[TCA_POLICE_RATE64]) >= sizeof(rate64))
>>>> rate64 = rta_getattr_u64(tb[TCA_POLICE_RATE64]);
>>>>
>>>> - fprintf(f, " police 0x%x ", p->index);
>>>> + print_int(PRINT_ANY, "police", "police %d ", p->index);
>>>
>>> this changes the output format from hex to decimal.
>>>
>>
>> hmm thanks for the review. actually I see another issue with this.
>> I missed this but this should actually be split into "kind" and "index".
>> And index should be unsigned as the other actions.
>> so we should have kind printed at the top of the function even if arg
>> is null and index here.
>>
>> print_string(PRINT_ANY, "kind", "%s", "police");
>>
>> if (arg == NULL)
>>
>> return 0;
>> ...
>> print_uint(PRINT_ANY, "index", "\t index %u ", p->index);
>>
>>
>>
>> then the json output should be this
>>
>> "actions": [ {
>> "order": 1,
>> "kind": "police",
>> "index": 1,
>>
>>
>> i'll send v2.
>>
>>
>>>
>>>> tc_print_rate(PRINT_FP, NULL, "rate %s ", rate64);
>>>> buffer = tc_calc_xmitsize(rate64, p->burst);
>>>> print_size(PRINT_FP, NULL, "burst %s ", buffer);
>>>> print_size(PRINT_FP, NULL, "mtu %s ", p->mtu);
>>>> if (show_raw)
>>>> - fprintf(f, "[%08x] ", p->burst);
>>>> + print_hex(PRINT_FP, NULL, "[%08x] ", p->burst);
>>>>
>>>> prate64 = p->peakrate.rate;
>>>> if (tb[TCA_POLICE_PEAKRATE64] &&
>>>
>>>
>
> One useful check is to run your JSON output into python parser to be sure it is valid
>
I used jq to parse the output from tc.
jq gives an error on the original output, example:
parse error: Invalid numeric literal at line 15, column 38
and after the fix jq works and gives a nice colored output.
the fix i pointed out here is to match the dump like in other
actions. so instead of key police with value index it should be
key kind with value police and key index with the value index.
Powered by blists - more mailing lists