Take Specific Value Inside BGP Community

Alexander Zubkov green at qrator.net
Tue Feb 20 09:42:39 CET 2024


Hi,

This statement is wrong:

peeras = ([(65535, 1000, *)].data2);

You try to pick "data2" from the communty set (= comunity filter). Filter
itself does not contain values. You need to apply it to some community list
first. Still you'll get a community list as a result. But you can pick
"data2" only from a single community. If you have or expect only one
community matching the filter and can ignore other values, you can use
min/max operators to take a single community from the list. But be aware
that an empty list will yield you an error here, so you need to check fist
that there is something there. Please also pay attention that you use a
legacy syntax for definition of block variables and function.

Not sure that I fully got you idea, but you can check this piece of code:

if (bgp_large_community ~ [(65535, 1000, *)]) then {
    int peeras = filter(bgp_large_community, [(65535, 1000, *)]).min.data2;
    bgp_large_community.delete([(65535, *, *)]);
    bgp_large_community.add(( 64512, 101, peeras ));
    accept; # not sure if it is good to accept/reject in a function
}

Regards,
Alexander


On Tue, Feb 20, 2024 at 9:12 AM Ilham Maulana <ilhamsupernatural at gmail.com>
wrote:

> Hi,
>
> Thanks for the reply.
>
> Here's what i'm going to do.
> --------------------------
> function is_to_some_ixp_comm()
> int *peeras*;
> {
>     peeras = ([(65535, 1000, *)]*.data2*);
>
>     if bgp_large_community ~ ([( 65535,1000,*peeras*)]) then {
>         bgp_large_community.delete([(65535,*,*)]);
>         bgp_large_community.add (( 64512,101,*peeras* ));
>         accept;
>     }
> }
> -------------------------------------
> i want to copy third community value from if statement, and adding it
> another community.
> but that function gives me error.
>
>  *No methods defined for type set*
>
> is that possible using bird?
>
> Thanks.
>
> On 20/02/2024 07:45:30, Erin Shepherd <bird-users at erinshepherd.net> wrote:
> It's a bit non-obvious, but you can do this with a loop. For example we
> basically replicate the Euro-IX routeserver announcement control
> communities inside our network, and we use the following function to
> translate them when exporting routes to a (supporting) route server
>
> # Translate Euro-IX common communities for use by a route server
> function translate_routeserver_communities(
>   int dest_asn
> )
> {
>   lclist announce_controls = filter(bgp_large_community, [(OURAS, 0..1,
> *)]);
>   for lc c in announce_controls do {
>     bgp_large_community.add((dest_asn, c.data1, c.data2));
>   }
>
>   lclist prepends = filter(bgp_large_community, [(OURAS, 101..103, *)]);
>   for lc c in prepends do {
>     bgp_large_community.add((dest_asn, c.data1, c.data2));
>   }
> }
>
> (I think we could combine those into one with a filter(bgp_large_community,
> [(OURAS, 0..1, *), (OURAS, 101..103, *)])? This code originally looked
> slightly different and at the time combining these wasn't posible.
>
> Note that this doesn't strip the input communities - we do that as a
> separate step later where we strip all non-informational communities
>
> - Erin
>
> On Tue, 20 Feb 2024, at 00:30, Ilham Maulana wrote:
>
> Hi,
>
>
> Is it possible in bird to copy specific value inside BGP Community?
>
> Example:
>
> Route 1, Community (a,b,*c*) -> inbound
> Route 2, Community (a,b,*d*) -> inbound
> --
> Route 1, Community (k,l,*c*) -> outbound
> Route 2, Community (k,l,*d*) -> outbound
>
> The specific value I want to preserve is c and d, and it is dynamic
> variable.
>
> whatever c and d inbound, copy to c and d outbound.
>
> Thanks.
> Ilham
> [image: 5f622eb5-c189-4e05-8584-e4a1d2071a6b]
>
>
> [image: 6e8681c1-f1d3-45a8-97bb-365e7ee8f797]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://trubka.network.cz/pipermail/bird-users/attachments/20240220/d4e1c5e4/attachment.htm>


More information about the Bird-users mailing list