Skip to content

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

Draft
jbemmel wants to merge 8 commits into
ipspace:devfrom
jbemmel:feature/bgp-role-policy
Draft

Add bgp.role support to bgp.policy plugin#3429
jbemmel wants to merge 8 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 (with optional bgp.role.strict) instead of a separate plugin, with FRR/BIRD support, tests, and documentation.

Replaces #3428

New proposed attribute structure would benefit from core validation changes - see #3430.

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.

Comment thread docs/plugins/bgp.policy.md Outdated
Comment thread netsim/extra/bgp.policy/plugin.py Outdated
Comment thread netsim/extra/bgp.policy/plugin.py Outdated
"""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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've refactored the PR to propose the following structure:

bgp.role: customer

or

bgp.role:
  name: customer
  strict: true

The must_be_bgp_role etc validation functions could be replaced by more generic validation code (some sub cases of user defined type validation aren't implemented, see #3430

Comment thread netsim/extra/bgp.policy/plugin.py Outdated
Comment thread netsim/extra/bgp.policy/plugin.py Outdated
@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.

@jbemmel jbemmel marked this pull request as draft June 1, 2026 13:14
jbemmel and others added 4 commits June 1, 2026 08:44
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>
Replace bgp.role_strict with an optional strict flag inside bgp.role,
normalize neighbors to a role dictionary, add global defaults.bgp.role.strict
inheritance, and merge the three integration tests into 70-bgp-roles.yml.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jbemmel jbemmel force-pushed the feature/bgp-role-policy branch from d4b9333 to 0ce91d1 Compare June 1, 2026 13:44

_requires = [ 'bgp' ]
_requires = [ 'bgp' ]
_execute_after = [ 'bgp.session' ]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

AI added this following documented comments - let me know if you prefer to leave it out

jbemmel and others added 4 commits June 1, 2026 09:11
Define bgp_role_name once in plugin defaults and extend validate.py so
type: and _alt_types references resolve user-defined schemas; drop the
custom must_be_bgp_role validator and stop propagating defaults.bgp.role.

Co-authored-by: Cursor <cursoragent@cursor.com>
Remove unused modules import and avoid a # type: comment that mypy
misread when resolving user-defined attribute types.

Co-authored-by: Cursor <cursoragent@cursor.com>
Stock _alt_types only invoke registered must_be_* functions (see ipspace#3430).
Register bgp_role and bgp_role_strict in bgp.policy; keep valid_values in
defaults.yml via a YAML anchor.

Co-authored-by: Cursor <cursoragent@cursor.com>
Merge inherited role onto the interface before apply_policy_attributes;
drop the separate role.attr list and special-case neighbor handling.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jbemmel jbemmel marked this pull request as ready for review June 1, 2026 18:47
@jbemmel jbemmel marked this pull request as draft June 3, 2026 18:44
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