On Fri, May 08, 2015 at 11:35:33PM +0200, Pavlos Parissis wrote:
> Hi,
> 
> For each ip_prefix I advertize I need to add a BGP community in the form
> of  (ASN,<RouterID>).
> I have the following mapping between IPs and RouterIDs
> 
> ip_prefix, RouterID
> 10.10.10.1, 1
> 10.10.10.2, 2
> 10.10.10.3, 3
> 10.10.10.4, 1
> 10.10.10.5, 2
> 10.10.10.6, 3
> .....
> 
> So, inside a function I need to express the following
> lookup_community_router_id() {
>    return some_kind_of_dict_structure(net.ip)
> }
> 
> and the use it in a filter/function
> filter {
>    bgp.community((1111, lookup_community_router_id(net)));
>    accept;
> }
> 
> Is this possible?

Hi

Surprisingly, it is possible - you could use big case expression which
returns appropriate value. As case uses the same implementation as sets,
it will be fairly efficient:

function lookup(ip val)
{
    case val {
        10.10.10.1: return 1;
        10.10.10.2: return 2;
        ...
    }
  return 0;
}


-- 
Elen sila lumenn' omentielvo

Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org)
OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net)
"To err is human -- to blame it on a computer is even more so."

Attachment: signature.asc
Description: Digital signature

Reply via email to