natesales / pathvector

Declarative routing platform that automates BGP route optimization and control plane configuration with secure and repeatable routing policy.
https://pathvector.io
MIT License
218 stars 28 forks source link

ASN Variable Usage throughout config #181

Closed CloudieLLC closed 1 year ago

CloudieLLC commented 1 year ago

This many not be applicable to most users, but say.. I've got a large community set for a each downstream user, for future usage etc. to avoid situations for human error, the ability to utilize a variable for asn: elsewhere for example.

  LXC_2021:
    asn: 123456
    as-set: AS123456
    listen6: 2602:fba1:100::1
    template: downstream_lxc_default
    filter-rpki: false
    add-on-import: 
      - 924:1123456 #From Downstream User
    neighbors:
      - 2602:fba1:100:beef::11:1

to

  LXC_2021:
    asn: 123456
    as-set: AS${asn}
    listen6: 2602:fba1:100::1
    template: downstream_lxc_default
    filter-rpki: false
    add-on-import: 
      - 924:1:${asn}#From Downstream User
    neighbors:
      - 2602:fba1:100:beef::11:1

This could be used for a number of things, later down the track etc. and just something to think about since i was sitting there rewriting my config file.

natesales commented 1 year ago

+1, I agree this is a useful feature. Pathvector already have template replacements (https://pathvector.io/docs/snippets) so will probably stick with the "<pathvector.$OPTION>" syntax.

natesales commented 1 year ago

I'm taking another look at this, and on second thought think it would be better left to a higher level component to manage the yaml config. Adding nonstandard meaning to the config is risky, and doing so would make the config more visually confusing and require validation that will add undue complexity to the config parser.

The reason template replacements are already present before rendering to BIRD is that there isn't another way to inject data between pathvector and BIRD, whereas the pathvector config file can be easily modified before running pathvector.

I'm considering this out of scope, but the same behavior should be doable with a templating engine like jinja2 and a quick python script. Happy to review a PR adding an example to the docs site!

rapdodge commented 1 year ago

Bumping this... This night (UTC+7), i was very bored, and i was thinking to make an control community things, and the barebone are like this

if (
    (LocalASN,NeighborASN,1) ~ bgp_large_community
)
then {
    bgp_path.prepend(LocalASN);
}
if (
    (LocalASN,NeighborASN,2) ~ bgp_large_community
)
then {
    bgp_path.prepend(LocalASN);
    bgp_path.prepend(LocalASN);
}
if (
    (LocalASN,NeighborASN,3) ~ bgp_large_community
)
then {
    bgp_path.prepend(LocalASN);
    bgp_path.prepend(LocalASN);
    bgp_path.prepend(LocalASN);
}
if (
    (LocalASN,NeighborASN,9) ~ bgp_large_community
)
then {
    reject;
}

I was thinking the same idea, i think it's nice to have LocalASN variable and the NeighborASN variable :)

Maybe listing the snippets (variables) too? :D