community features request

Oleg lego12239 at yandex.ru
Wed Mar 7 12:45:42 CET 2012


  Hi, list.

  I have the next situation. I want to filter our AS communities in an input
filter. So, i made the next function for this:

function filter_communities(pair set allowed)
clist comm;
pair set def_allowed;
bool is_empty;
{
        def_allowed = [(myas,1000), (myas,1001), (myas,1002)];
        if ( (0,0) ~ allowed ) then
                allowed = def_allowed;
        comm = filter(bgp_community, allowed);
        bgp_community.delete([(myas,*)]);
        is_empty = true;
        if (( (myas,1000) ~ comm ) &&
            ( (myas,1000) ~ allowed )) then {
                is_empty = false;
                bgp_community.add((myas,1000));
        }
        if (( (myas,1001) ~ comm ) &&
            ( (myas,1001) ~ allowed )) then {
                is_empty = false;
                bgp_community.add((myas,1001));
        }
        if (( (myas,1002) ~ comm ) &&
            ( (myas,1002) ~ allowed )) then {
                is_empty = false;
                bgp_community.add((myas,1002));
        }
        if (( is_empty ) && ( (myas,1000) ~ allowed )) then
                bgp_community.add((myas,1000));
}

Code overview:

We have some allowed communities passed in function as a parameter (if we
pass [(0,0)], then it treats like a NULL and default communities list is
applied (def_allowed)). At first, we delete all not allowed our AS communities
from bgp_community, but preserve not our AS communities. Then we insert
default community (myas,1000), if we have no our AS community at all and 
(myas,1000) is allowed.

So, what's wrong. It works fine, but the code seems some strange:

1. If we have empty clist or empty pair set constructions, we can do
     if ( allowed = [] ) then
   instead of hack with (0,0) community;
2. add(C,P) cann't get pair set like delete(C,P) do and
3. we have incompatible types clist and pair set (Why? Why cann't pair set
   be modifiable?). So we cann't simply do
     comm = filter(bgp_community, allowed);
     bgp_community.delete([(51230,*)]);
     bgp_community.add(comm);
   instead of tons of lines.

So, if all of above would be true, we could write:

function filter_communities(pair set allowed)
pair set comm;
pair set def_allowed;
{
        def_allowed = [(myas,1000), (myas,1001), (myas,1002)];
        if ( allowed = [] ) then
                allowed = def_allowed;
        comm = filter(bgp_community, allowed);
        bgp_community.delete([(myas,*)]);
	bgp_community.add(comm);
        if (( comm = [] ) && ( (myas,1000) ~ allowed )) then
                bgp_community.add((myas,1000));
}

May be i do something wrong and my code can be simplified?

Thanks.



More information about the Bird-users mailing list