key/value structure

Ondrej Zajicek santiago at crfreenet.org
Sat May 9 01:32:19 CEST 2015


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: santiago at 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."
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://trubka.network.cz/pipermail/bird-users/attachments/20150509/8e99f2e3/attachment.asc>


More information about the Bird-users mailing list