-
Notifications
You must be signed in to change notification settings - Fork 1.4k
bgpd: Support for new "show bgp <vrf> bestpath [json]" show command #20616
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
base: master
Are you sure you want to change the base?
Conversation
Greptile OverviewGreptile SummaryThis PR implements a new BGP show command Key Changes:
Issues Found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant VTY as VTY Shell
participant CMD as show_bgp_vrf_bestpath_cmd
participant Helper as bgp_show_bestpath()
participant BGP as BGP Instance
User->>VTY: show bgp [vrf VRFNAME] bestpath [json]
VTY->>CMD: Execute command
alt No VRF specified or VRF=all
CMD->>BGP: Get all BGP instances from bm->bgp
loop For each BGP instance
CMD->>BGP: Check inst_type (skip VIEW types)
CMD->>Helper: bgp_show_bestpath(vty, bgp, json_vrf)
Helper->>BGP: Read flags (ASPATH_IGNORE, MED_CONFED, etc.)
Helper->>BGP: Read lb_handling config
Helper-->>CMD: Format output (text or JSON)
end
CMD->>VTY: Output all VRFs (with "vrfs" wrapper in JSON)
else Single VRF specified
CMD->>BGP: bgp_lookup_by_name(name) or bgp_get_default()
alt BGP instance not found
CMD->>VTY: Error: "Specified BGP instance not found"
else BGP instance found
CMD->>Helper: bgp_show_bestpath(vty, bgp, json_vrf)
Helper->>BGP: Read flags and config
Helper-->>CMD: Format output
CMD->>VTY: Output single VRF (direct VRF key in JSON)
end
end
VTY-->>User: Display bestpath criteria
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, 1 comment
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED) || | ||
| CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) { | ||
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)) | ||
| vty_out(vty, " BGP bestpath MED set to: confed\n"); | ||
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) | ||
| vty_out(vty, " BGP bestpath MED set to: missing-as-worst\n"); | ||
| else | ||
| vty_out(vty, " BGP bestpath MED is Enabled\n"); | ||
| } else { | ||
| vty_out(vty, " BGP bestpath MED is Disabled\n"); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the else clause on line 12356 is misplaced - it only applies to the inner if statement checking BGP_FLAG_MED_MISSING_AS_WORST, not both MED conditions. When only BGP_FLAG_MED_CONFED is set (without BGP_FLAG_MED_MISSING_AS_WORST), the output will incorrectly print both "confed" and "MED is Enabled"
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED) || | |
| CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) { | |
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)) | |
| vty_out(vty, " BGP bestpath MED set to: confed\n"); | |
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) | |
| vty_out(vty, " BGP bestpath MED set to: missing-as-worst\n"); | |
| else | |
| vty_out(vty, " BGP bestpath MED is Enabled\n"); | |
| } else { | |
| vty_out(vty, " BGP bestpath MED is Disabled\n"); | |
| } | |
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED) || | |
| CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) { | |
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)) | |
| vty_out(vty, " BGP bestpath MED set to: confed\n"); | |
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) | |
| vty_out(vty, " BGP bestpath MED set to: missing-as-worst\n"); | |
| } else { | |
| vty_out(vty, " BGP bestpath MED is Disabled\n"); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: bgpd/bgp_vty.c
Line: 12350:12360
Comment:
the `else` clause on line 12356 is misplaced - it only applies to the inner `if` statement checking `BGP_FLAG_MED_MISSING_AS_WORST`, not both MED conditions. When only `BGP_FLAG_MED_CONFED` is set (without `BGP_FLAG_MED_MISSING_AS_WORST`), the output will incorrectly print both "confed" and "MED is Enabled"
```suggestion
if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED) ||
CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) {
if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED))
vty_out(vty, " BGP bestpath MED set to: confed\n");
if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
vty_out(vty, " BGP bestpath MED set to: missing-as-worst\n");
} else {
vty_out(vty, " BGP bestpath MED is Disabled\n");
}
```
How can I resolve this? If you propose a fix, please make it concise.| CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)); | ||
|
|
||
| if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW) | ||
| json_object_string_add(bestpath, "linkBandwidth", "ignore"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of things here:
the key sounds like a bandwidth number, but it's really a type of handling, isn't it? Maybe the key should be "linkBwHandling" or something like that?
repeating the string_add calls feels a bit cut-and-paste: try using the logic to set a const char *, and then just have one call to string_add that uses the key?
|
|
||
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED) || | ||
| CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST)) { | ||
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the cascade of tests would be clearer if it were:
if (both flags)
;
else if (flag_1)
;
else if (flag_2)
;
else
; /* disabled case */
| CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_ROUTER_ID)); | ||
|
|
||
| json_object_boolean_add(bestpath, "medConfed", | ||
| CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the MED output is different between vty and json - any reason why? that is, the json doesn't have the equivalent of "enabled", it just has the individual flags.
ton31337
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Documentation is missing;
- Can we use more descriptive "naming" for non-JSON output?
| json_object_boolean_add(bestpath, "asPathConfed", | ||
| CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_CONFED)); | ||
|
|
||
| if (CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check seems unnecessary..
| json_object_boolean_add(bestpath, "medConfed", | ||
| CHECK_FLAG(bgp->flags, BGP_FLAG_MED_CONFED)); | ||
|
|
||
| json_object_boolean_add(bestpath, "medMissingASWorst", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
medMissingAsWorst
| json_object_string_add(bestpath, "linkBandwidth", | ||
| "default-weight-for-missing"); | ||
| else | ||
| json_object_string_add(bestpath, "linkBandwidth", "ecmp(default)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we drop this (default)?
| vty_out(vty, "Best Path Selection Criteria:\n"); | ||
| vty_out(vty, " AS path ignore is %s\n", | ||
| CHECK_FLAG(bgp->flags, BGP_FLAG_ASPATH_IGNORE) ? "Enabled" : "Disabled"); | ||
| vty_out(vty, " AS path confed is %s\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we name it "normally"? Like Include confederation AS numbers or so?
| DEFPY(show_bgp_vrf_bestpath, show_bgp_vrf_bestpath_cmd, | ||
| "show bgp [vrf VRFNAME$vrf_name] bestpath [json]", | ||
| SHOW_STR BGP_STR "Show BGP VRFs\n" | ||
| "Specific VRF name\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align, please.
Add test to verify that 'show bgp bestpath json' command returns the correct bestpath selection criteria in JSON format. Signed-off-by: Soumya Roy <[email protected]>
VTY output -
leaf11# show bgp vrf default bestpath
VRF default
Best Path Selection Criteria:
AS path ignore is Disabled
AS path confed is Disabled
AS path multi-path-relax is Enabled
Peer type relax is Disabled
Compare router ID is Disabled
BGP bestpath MED is disabled
Link Bandwidth handling set to: ecmp(default)
Always compare MED is Disabled
Deterministic MED is Enabled
leaf11# show bgp bestpath
VRF default
Best Path Selection Criteria:
AS path ignore is Disabled
AS path confed is Disabled
AS path multi-path-relax is Enabled
Peer type relax is Disabled
Compare router ID is Disabled
BGP bestpath MED is disabled
Link Bandwidth handling set to: ecmp(default)
Always compare MED is Disabled
Deterministic MED is Enabled
leaf11#
JSON output -
leaf11# show bgp bestpath json
{
"vrfs":{
"default":{
"bestPath":{
"asPathIgnore":false,
"asPathConfed":false,
"asPathMultiPathRelaxEnabled":true,
"peerTypeRelax":false,
"compareRouterId":false,
"medConfed":false,
"medMissingASWorst":false,
"linkBandwidth":"ecmp(default)",
"alwaysCompareMed":false,
"deterministicMed":true
}
}
}
}
leaf11# show bgp vrf default bestpath json
{
"default":{
"bestPath":{
"asPathIgnore":false,
"asPathConfed":false,
"asPathMultiPathRelaxEnabled":true,
"peerTypeRelax":false,
"compareRouterId":false,
"medConfed":false,
"medMissingASWorst":false,
"linkBandwidth":"ecmp(default)",
"alwaysCompareMed":false,
"deterministicMed":true
}
}
}
Ticket: #4445780
Signed-off-by: Aprathi K [email protected]
d3ede32 to
9e3bb1a
Compare
| if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) | ||
| continue; | ||
|
|
||
| name = (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) ? VRF_DEFAULT_NAME : bgp->name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bgp->name is always non-NULL meaning that it has "default", right? Why we need this check?
bgpd: Support for new "show bgp bestpath [json]" show command.