Skip to content

Add bgp.role support to bgp.policy plugin#3429

Open
jbemmel wants to merge 3 commits into
ipspace:devfrom
jbemmel:feature/bgp-role-policy
Open

Add bgp.role support to bgp.policy plugin#3429
jbemmel wants to merge 3 commits into
ipspace:devfrom
jbemmel:feature/bgp-role-policy

Conversation

@jbemmel
Copy link
Copy Markdown
Collaborator

@jbemmel jbemmel commented May 29, 2026

Consolidate BGP role handling into bgp.policy as bgp.role and bgp.role_strict instead of a separate plugin, with FRR/BIRD support, tests, and documentation.

Replaces #3428

jbemmel and others added 3 commits May 29, 2026 16:04
Consolidate BGP role handling into bgp.policy as bgp.role and bgp.role_strict instead of a separate plugin, with FRR/BIRD support, tests, and documentation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Check device support first, inline role_strict validation, and restrict role application to EBGP neighbors only.

Co-authored-by: Cursor <cursoragent@cursor.com>
Only validate device support after confirming bgp.role or bgp.role_strict is configured, avoiding false errors on topologies using bgp.policy without roles.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown
Owner

@ipspace ipspace left a comment

Choose a reason for hiding this comment

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

The code needs to be cleaned up. Also, we're not running three integration tests for a simple feature. Squeeze whatever you want to have tested into one.

* Arista EOS and Aruba CX do not support node-level default local preference. Node-level **bgp.locpref** attribute (if specified) is thus applied to all interfaces that do not have an explicit **bgp.locpref** attribute. That might interfere with the **bgp.policy** interface attributes.
* FRR implements BGP Roles starting with release 8.4. BIRD implements them starting with release 2.0.11. On BIRD, BGP roles are rendered into the BGP module configuration file (`daemons/bird/bgp.j2`).

(plugin-bgp-policy-role)=
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I would move this section to the end (just before the "Sample Topologies")

api.node_config(node,_config_name) # Remember that we have to do extra configuration
_bgp.clear_bgp_session(node,ngb)

def _use_role_plugin_template(node: Box) -> bool:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This feels so wrong. Why would you ever hard-code a device into a plugin code?

"""Return False for the BIRD daemon (roles are rendered in daemons/bird/bgp.j2)."""
return not (node.get('_daemon') and node.device == 'bird')

def apply_role_attributes(node: Box, ngb: Box, intf: Box, topology: Box) -> bool:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This feels like duplicating a lot of functionality that should be already available elsewhere. If you want to ensure "role_strict" is only used when "role" is there, we could solve that in the generic validation code (if it's not there yet).


route_aggregation(ndata,topology)
_bgp.cleanup_neighbor_attributes(ndata,topology,_attr_list + [ 'policy' ])
_bgp.cleanup_neighbor_attributes(ndata,topology,_attr_list + _ROLE_ATTR_LIST + [ 'policy' ])
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It would be better to add role keywords into "_direct" or "_compound" attribute list? Is there a reason not to do it?

communities.append('extended')
if copy_locpref and not intf.get('bgp.locpref',False):
intf.bgp.locpref = ndata.bgp.locpref
apply_role_attributes(ndata,ngb,intf,topology)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It looks like the only reason you're dealing with roles as an exception is because of Bird template stuff. The easiest way to solve that is to have an empty template in the plugin directory.

@ipspace
Copy link
Copy Markdown
Owner

ipspace commented May 30, 2026

@jbemmel -- I understand you find it exciting to use AI to generate code, but I won't review the bloated results in the future (like the special "dealing with role" function). Please act as a sanity check on the code before submitting the PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants