Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pbr: fix nexthop-group json output #16949

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chiragshah6
Copy link
Member

  • JSON format is changed. currently json output returns as array format, in which we cannot add extra attributes under it. so, we modified the JSON format into dict.
  • Added nhgCount into vtysh "show pbr nexthop-groups json".
  • Addressed interface-name & vrf-id issues. currently, "vrfId" is mapped with interface name.

supported commands:

show pbr nexthop-groups json
show pbr nexthop-groups <nh-grp> json

Testing:

Before fix:

leaf12# show pbr nexthop-groups json
[
  {
    "id":10001,
    "name":"nh-grp-2",
    "valid":true,
    "installed":false,
    "nexthops":[
      {
        "nexthop":"12.10.10.1",
        "vrfId":"swp1", ====> wrongly mapped
        "valid":true
      }
    ]
  },
  {
    "id":10000,
    "name":"nh-grp-1",
    "valid":false,
    "installed":false,
    "nexthops":[
      {
        "nexthop":"11.10.10.1",
        "vrfId":"lo", ====> wrongly mapped
        "valid":false
      }
    ]
  }
]

After fix:

leaf11# show pbr nexthop-groups nh-grp-1 json
{
  "10000":{
    "id":10000,
    "name":"nh-grp-1",
    "valid":false,
    "installed":false,
    "nexthops":[
      {
        "nexthop":"11.10.10.1",
        "valid":false
      },
      {
        "nexthop":"2.2.2.1",
        "interfaceName":"swp1",
        "vrfId":0,
        "valid":false
      }
    ]
  },
  "nhgCount":1
}

Signed-off-by: Sindhu Parvathi Gopinathan's [email protected]

 - JSON format is changed.
	currently json output returns as array format,
        in which we cannot add extra attributes under it.
   	so, we modified the JSON format into dict.
 - Added nhgCount into vtysh "show pbr nexthop-groups json".
 - Addressed interface-name & vrf-id issues.
	currently, "vrfId" is mapped with interface name.

supported commands:

```
show pbr nexthop-groups json
show pbr nexthop-groups <nh-grp> json
```

Ticket:#3963583

Issue: 3963583

Testing:

Before fix:

leaf12# show pbr nexthop-groups json
[
  {
    "id":10001,
    "name":"nh-grp-2",
    "valid":true,
    "installed":false,
    "nexthops":[
      {
        "nexthop":"12.10.10.1",
        "vrfId":"swp1", ====> wrongly mapped
        "valid":true
      }
    ]
  },
  {
    "id":10000,
    "name":"nh-grp-1",
    "valid":false,
    "installed":false,
    "nexthops":[
      {
        "nexthop":"11.10.10.1",
        "vrfId":"lo", ====> wrongly mapped
        "valid":false
      }
    ]
  }
]

After fix:

leaf11# show pbr nexthop-groups nh-grp-1 json
{
  "10000":{
    "id":10000,
    "name":"nh-grp-1",
    "valid":false,
    "installed":false,
    "nexthops":[
      {
        "nexthop":"11.10.10.1",
        "valid":false
      },
      {
        "nexthop":"2.2.2.1",
        "interfaceName":"swp1",
        "vrfId":0,
        "valid":false
      }
    ]
  },
  "nhgCount":1
}

Signed-off-by: Sindhu Parvathi Gopinathan's <[email protected]>
@chiragshah6 chiragshah6 changed the title pbr: format change in nexthop-group json output pbr: fix nexthop-group json output Sep 27, 2024
@@ -1080,24 +1080,27 @@ void nexthop_group_json_nexthop(json_object *j, const struct nexthop *nh)

switch (nh->type) {
case NEXTHOP_TYPE_IFINDEX:
json_object_string_add(j, "nexthop",
json_object_string_add(j, "interfaceName",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is pretty clearly a fix - it should be a separate commit (and maybe even a separate PR, given the release freeze?)

pbr_nht_json_nexthop_group(j, word);

pbr_nht_json_nexthop_group(j, word, &pbr_nhg_count);
json_object_int_add(j, "nhgCount", pbr_nhg_count);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit confusing: first, it seems like the count of objects in the collection (whether an array or a dict) should be pretty easy to find? and second, it's confusing to have a dict where some keys are the string form of nhg ids, and their objects are nhg objects, but some other keys are ... entirely different, and key entirely different objects.

Copy link
Member

@ton31337 ton31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change of JSON, correct? Before/After is absolutely broken in terms of parsing JSON fundamentally. Should we take care of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants