Skip to content

bgpd: support brief json for bgp v4 and v6 neighbors route - #21414

Merged
riw777 merged 3 commits into
FRRouting:masterfrom
hnattamaisub:brief_bgp_neigh
May 13, 2026
Merged

bgpd: support brief json for bgp v4 and v6 neighbors route#21414
riw777 merged 3 commits into
FRRouting:masterfrom
hnattamaisub:brief_bgp_neigh

Conversation

@hnattamaisub

@hnattamaisub hnattamaisub commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

brief-json support is added for show bgp v4 and v6 unicast neighbour routes.

Commands supported:
show bgp vrf ipv4 unicast neighbors routes brief json
show bgp vrf ipv6 unicast neighbors routes brief json

cpe1# show bgp vrf default ipv6 unicast neighbors 2001:db8:10::2 routes json brief
{
"routes": { "2001:db8:2::/64": {
"pathCount":1
,"multiPathCount":1
,"flags": {"bestPathExists":true,"fibInstalled":false,"fibWaitForInstall":false,"fibSuppress":false,"fibInstallFailed":false}
} ,"2001:db8:10::/64": {
"pathCount":1
,"multiPathCount":0
,"flags": {"bestPathExists":false,"fibInstalled":true,"fibWaitForInstall":false,"fibSuppress":false,"fibInstallFailed":false}
} } , "totalRoutes": 2, "totalPaths": 5,"numRoutes":2
}
cpe1#
cpe1# show bgp vrf default ipv6 unicast neighbors 2001:db8:10::2 routes json
{
"vrfId": 0,
"vrfName": "default",
"tableVersion": 4,
"routerId": "172.16.255.1",
"defaultLocPrf": 100,
"localAS": 65000,
"routes": { "2001:db8:2::/64": [{"valid":true,"bestpath":true,"selectionReason":"First path received","pathFrom":"internal","prefix":"2001:db8:2::","prefixLen":64,"network":"2001:db8:2::/64","version":3,"metric":0,"locPrf":100,"weight":0,"peerId":"2001:db8:10::2","path":"","origin":"incomplete","nexthops":[{"ip":"2001:db8:10::2","hostname":"cpe2","afi":"ipv6","scope":"global","linkLocalOnly":false,"length":32},{"ip":"fe80::c00b:65ff:feab:769f","hostname":"cpe2","afi":"ipv6","scope":"link-local","used":true}]}]
,"2001:db8:10::/64": [{"valid":true,"pathFrom":"internal","prefix":"2001:db8:10::","prefixLen":64,"network":"2001:db8:10::/64","version":2,"metric":0,"locPrf":100,"weight":0,"peerId":"2001:db8:10::2","path":"","origin":"incomplete","nexthops":[{"ip":"2001:db8:10::2","hostname":"cpe2","afi":"ipv6","scope":"global","linkLocalOnly":false,"length":32},{"ip":"fe80::c00b:65ff:feab:769f","hostname":"cpe2","afi":"ipv6","scope":"link-local","used":true}]}]
} , "totalRoutes": 2, "totalPaths": 5,"numRoutes":2
}
cpe1#
pe1# show bgp vrf RED ipv4 unicast neighbors 192.168.1.1 routes json brief
{
"routes": { "10.0.0.0/24": {
"pathCount":1
,"multiPathCount":2
,"flags": {"bestPathExists":true,"fibInstalled":false,"fibWaitForInstall":false,"fibSuppress":false,"fibInstallFailed":false}
} ,"172.16.255.1/32": {
"pathCount":1
,"multiPathCount":2
,"flags": {"bestPathExists":true,"fibInstalled":false,"fibWaitForInstall":false,"fibSuppress":false,"fibInstallFailed":false}
} ,"192.168.1.0/24": {
"pathCount":1
,"multiPathCount":2
,"flags": {"bestPathExists":true,"fibInstalled":false,"fibWaitForInstall":false,"fibSuppress":false,"fibInstallFailed":false}
} ,"192.168.2.0/24": {
"pathCount":1
,"multiPathCount":2
,"flags": {"bestPathExists":true,"fibInstalled":false,"fibWaitForInstall":false,"fibSuppress":false,"fibInstallFailed":false}
} } , "totalRoutes": 4, "totalPaths": 12,"numRoutes":4
}
pe1#

pe1# show bgp vrf RED ipv4 unicast neighbors 192.168.1.1 routes json
{
"vrfId": 4,
"vrfName": "RED",
"tableVersion": 12,
"routerId": "192.168.1.2",
"defaultLocPrf": 100,
"localAS": 65001,
"routes": { "10.0.0.0/24": [{"valid":true,"bestpath":true,"selectionReason":"Peer Type","multipath":true,"pathFrom":"external","prefix":"10.0.0.0","prefixLen":24,"network":"10.0.0.0/24","version":9,"metric":0,"weight":0,"peerId":"192.168.1.1","path":"65000","origin":"incomplete","nexthops":[{"ip":"192.168.1.1","hostname":"cpe1","afi":"ipv4","used":true}]}]
,"172.16.255.1/32": [{"valid":true,"bestpath":true,"selectionReason":"Peer Type","multipath":true,"pathFrom":"external","prefix":"172.16.255.1","prefixLen":32,"network":"172.16.255.1/32","version":11,"metric":0,"weight":0,"peerId":"192.168.1.1","path":"65000","origin":"incomplete","nexthops":[{"ip":"192.168.1.1","hostname":"cpe1","afi":"ipv4","used":true}]}]
,"192.168.1.0/24": [{"valid":true,"bestpath":true,"selectionReason":"Peer Type","multipath":true,"pathFrom":"external","prefix":"192.168.1.0","prefixLen":24,"network":"192.168.1.0/24","version":12,"metric":0,"weight":0,"peerId":"192.168.1.1","path":"65000","origin":"incomplete","nexthops":[{"ip":"192.168.1.1","hostname":"cpe1","afi":"ipv4","used":true}]}]
,"192.168.2.0/24": [{"valid":true,"bestpath":true,"selectionReason":"Peer Type","multipath":true,"pathFrom":"external","prefix":"192.168.2.0","prefixLen":24,"network":"192.168.2.0/24","version":10,"weight":0,"peerId":"192.168.1.1","path":"65000","origin":"incomplete","nexthops":[{"ip":"192.168.1.1","hostname":"cpe1","afi":"ipv4","used":true}]}]
} , "totalRoutes": 4, "totalPaths": 12,"numRoutes":4
}
pe1#

@greptile-apps

greptile-apps Bot commented Mar 31, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds json brief support to show bgp [vrf] [ipv4|ipv6] unicast neighbors <peer> routes, mirroring the existing brief output already available for advertised-routes. It threads a new brief parameter through bgp_show_neighbor_route β†’ bgp_show, converts the handler from DEFUN to DEFPY to capture the boolean flags automatically, and also fixes a pre-existing raw-JSON formatting bug (missing leading commas on fibInstalled/fibWaitForInstall fields) and adds fibInstallFailed: false to the non-suppress code path.

  • The topology test suite is extended with four new topotests (IPv4 full-JSON, IPv4 brief-JSON, IPv6 full-JSON, IPv6 brief-JSON) and the existing topology is expanded with dual-stack IPv6 BGP sessions so both address families can be exercised.
  • Existing test_bgp_soo_ipv4_advertised_routes_brief_json expected values are updated to reflect the additional paths introduced by the new iBGP IPv6 session between cpe1 and cpe2.

Confidence Score: 5/5

This PR is safe to merge; the new brief-JSON path is self-contained and the previously reported flap-statistics/dampened-routes null-dereference is guarded by a runtime sh_type check.

The core change correctly threads brief through the call chain, the DEFUN→DEFPY conversion removes the now-redundant use_json() call while preserving the established argc-- pattern, and the bgp_fib_flags_info comma/fibInstallFailed fixes resolve real raw-JSON malformation. The four new topotests cover both address families in both full and brief modes, and the topology config additions are consistent.

No files require special attention.

Important Files Changed

Filename Overview
bgpd/bgp_route.c Converts show_ip_bgp_neighbor_routes from DEFUN to DEFPY to add brief$brief capture; threads brief through bgp_show_neighbor_route; fixes missing commas in raw-JSON FIB flags output; adds fibInstallFailed:false for non-suppress path; guards brief against flap-statistics/dampened-routes at runtime.
tests/topotests/bgp_soo/test_bgp_soo.py Adds four new topotests for the new brief-JSON feature; uses json_cmp None convention correctly to assert bestpath key absence for non-best-path routes; updates path-count expectations for existing IPv4 test to match expanded topology.
tests/topotests/bgp_soo/cpe1/bgpd.conf Adds IPv6 iBGP/eBGP neighbors and ipv6 unicast address-family to cpe1 to enable dual-stack topotests.
tests/topotests/bgp_soo/pe1/bgpd.conf Adds IPv6 unicast/VPN address-families and IPv6 CE neighbor for the VRF RED topology needed for the IPv6 neighbor-routes tests.
doc/user/bgp.rst Adds CLI reference entry for the new brief JSON neighbor routes command with accurate description of valid sub-command combinations.
tests/topotests/bgp_soo/cpe2/bgpd.conf Adds the matching IPv6 iBGP neighbor (2001:db8:10::1) on cpe2's IPv6 unicast address-family.
tests/topotests/bgp_soo/cpe1/zebra.conf Adds IPv6 addresses and ipv6 forwarding to cpe1 interfaces.
tests/topotests/bgp_soo/cpe2/zebra.conf Adds IPv6 address to cpe2-eth1 for the dual-stack link to cpe1.
tests/topotests/bgp_soo/pe1/zebra.conf Adds IPv6 address to pe1-eth0 (VRF RED) and enables ipv6 forwarding.

Sequence Diagram

sequenceDiagram
    participant U as User (vtysh)
    participant D as DEFPY handler show_ip_bgp_neighbor_routes
    participant N as bgp_show_neighbor_route
    participant S as bgp_show / bgp_show_table
    participant F as bgp_fib_flags_info

    U->>D: show bgp vrf RED ipv4 unicast neighbors X routes json brief
    D->>D: "uj=true, brief=true, argc--"
    D->>D: "argv_find routes -> sh_type=bgp_show_type_neighbor"
    D->>D: "brief && sh_type==neighbor -> OK"
    D->>N: "bgp_show_neighbor_route(..., uj=true, brief=true)"
    N->>N: SET_FLAG(show_flags, BGP_SHOW_OPT_JSON)
    N->>S: "bgp_show(..., show_flags, brief=true)"
    S->>S: "use_json && brief -> json_paths=NULL"
    loop per dest prefix
        S->>F: bgp_fib_flags_info(vty, bgp, dest, json_flags, best_selected)
        F-->>S: populate json_flags object
        S-->>S: emit brief JSON: pathCount, multiPathCount, flags
    end
    S-->>U: "{routes:{...},totalRoutes:N,totalPaths:M,numRoutes:N}"
Loading

Reviews (4): Last reviewed commit: "tests: Enhanced tests to validate new co..." | Re-trigger Greptile

Comment thread bgpd/bgp_route.c Outdated
@frrbot frrbot Bot added the tests Topotests, make check, etc label Apr 1, 2026
@github-actions github-actions Bot added size/L and removed size/M labels Apr 1, 2026
@hnattamaisub
hnattamaisub marked this pull request as ready for review April 1, 2026 14:58
Comment thread bgpd/bgp_route.c Outdated
@hnattamaisub
hnattamaisub force-pushed the brief_bgp_neigh branch 5 times, most recently from e35da60 to 9840507 Compare April 2, 2026 05:56
@hnattamaisub

Copy link
Copy Markdown
Contributor Author

ci:rerun

Comment thread bgpd/bgp_route.c Outdated
Comment thread bgpd/bgp_route.c
@hnattamaisub

Copy link
Copy Markdown
Contributor Author

@ton31337 I have addressed all the comments, if there is no concern , can we please merge this? Thanks.

@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@hnattamaisub
hnattamaisub force-pushed the brief_bgp_neigh branch 2 times, most recently from 7bfe9c7 to e04b56c Compare April 21, 2026 14:34
@hnattamaisub

Copy link
Copy Markdown
Contributor Author

@greptileai review

Comment thread bgpd/bgp_route.c Outdated
@riw777

riw777 commented Apr 29, 2026

Copy link
Copy Markdown
Member

@greptileai can you verify all your comments have been addressed?

@greptile-apps

greptile-apps Bot commented Apr 29, 2026

Copy link
Copy Markdown

Most comments have been addressed, but there's one outstanding concern:

Addressed:

  • βœ… P1: brief breaking flap-statistics/dampened-routes JSON β€” the guard at bgp_route.c:17770-17774 correctly blocks brief for non-routes show types
  • βœ… ton31337's comments (move brief under json, undo AFI/SAFI cmd string changes)

Not fully resolved:

  • ⚠️ P1: fibSuppress breaking schema change (thread on bgp_route.c:13524-13546) β€” you confirmed this is intentional, but that's the problem. An intentional removal of fibSuppress and conditional-only emission of fibInstalled/fibWaitForInstall is a breaking change to an existing JSON schema. The added docs in bgp.rst only document the new brief option; there's no mention that the FIB flags output has changed for existing (non-brief) callers too.

This change to bgp_fib_flags_info affects all brief JSON output. If it's intentional, it needs at minimum a sentence in the docs noting that fibInstalled, fibWaitForInstall, and fibSuppress are now only emitted when suppress-fib-pending is configured, rather than always being present as false. Otherwise consumers relying on the old schema will silently break.

brief-json support is added for show bgp v4 and v6 unicast neighbour
routes.

Commands supported:
show bgp vrf <vrf> ipv4 unicast neighbors <neigh> routes json brief
show bgp vrf <vrf> ipv6 unicast neighbors <neigh> routes json brief

Signed-off-by: harini <hnattamaisub@nvidia.com>
Signed-off-by: harini <hnattamaisub@nvidia.com>
show bgp vrf <> ipv4 unicast neighbors routes brief json
show bgp vrf <>ipv6 unicast neighbors routes brief json

Signed-off-by: harini <hnattamaisub@nvidia.com>

@riw777 riw777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good to me at this point ... just waiting on @ton31337 's comments

@hnattamaisub

Copy link
Copy Markdown
Contributor Author

@ton31337 All the comments are addressed, please help in re-review and merging this , thanks

@ton31337

Copy link
Copy Markdown
Member

@greptileai rereview

@riw777
riw777 merged commit 6a47f4e into FRRouting:master May 13, 2026
24 checks passed
@hnattamaisub
hnattamaisub deleted the brief_bgp_neigh branch June 23, 2026 04:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bgp documentation master rebase PR needs rebase size/L tests Topotests, make check, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants