Re: Take Specific Value Inside BGP Community

2024-02-20 Thread Ilham Maulana
Hi sir,

Thank you for the explanation

Your script works.

Just started using bird 6 month ago, and found out it is super cool.

Many thanks.


Best Regard,

On 20/02/2024 15:43:06, Alexander Zubkov  wrote:
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 mailto:ilhamsupernatu...@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 mailto:bird-us...@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

[5f622eb5-c189-4e05-8584-e4a1d2071a6b]


[6e8681c1-f1d3-45a8-97bb-365e7ee8f797]
[156a60bf-0c1a-4ddb-9b41-23525d390373]

Re: Take Specific Value Inside BGP Community

2024-02-20 Thread Alexander Zubkov via Bird-users
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 
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  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]


Re: Take Specific Value Inside BGP Community

2024-02-20 Thread Ilham Maulana
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  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

[5f622eb5-c189-4e05-8584-e4a1d2071a6b]


[6e8681c1-f1d3-45a8-97bb-365e7ee8f797]

Re: Take Specific Value Inside BGP Community

2024-02-19 Thread Erin Shepherd
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
> 5f622eb5-c189-4e05-8584-e4a1d2071a6b


Take Specific Value Inside BGP Community

2024-02-19 Thread Ilham Maulana
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
[5f622eb5-c189-4e05-8584-e4a1d2071a6b]