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.
Hello, On Wed, Mar 07, 2012 at 03:45:42PM +0400, Oleg wrote:
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:
Principles of community processing in your case is difficult for me to understand. I've never used such complicated logic. But I hope I have answer at least on the one of your questions:
1. If we have empty clist or empty pair set constructions, we can do if ( allowed = [] ) then instead of hack with (0,0) community;
Try negation: if ! (bgp_community ~ [ (0,0) .. (65535,65535) ]) then { ... } -- Alexander Shikov Technical Staff, Digital Telecom IX
On Wed, Mar 07, 2012 at 03:47:52PM +0200, Alexander Shikov wrote:
Hello,
On Wed, Mar 07, 2012 at 03:45:42PM +0400, Oleg wrote:
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:
Principles of community processing in your case is difficult for me to understand. I've never used such complicated logic. But I hope I have answer at least on the one of your questions:
1. If we have empty clist or empty pair set constructions, we can do if ( allowed = [] ) then instead of hack with (0,0) community;
Try negation: if ! (bgp_community ~ [ (0,0) .. (65535,65535) ]) then { ... }
with bgp_community this solution works, but with allowed variable doesn't. In syslog i see the next error: filters, line 49: ~ applied on unknown type pair
On Wed, Mar 07, 2012 at 03:47:52PM +0200, Alexander Shikov wrote:
Hello,
Try negation: if ! (bgp_community ~ [ (0,0) .. (65535,65535) ]) then { ... }
This works with clist, but not with pair set. When i do if ! (allowed ~ [(0,0)..(65535,65535)]) then { ... } i see the next error in log: filters, line 49: ~ applied on unknown type pair
On Wed, Mar 07, 2012 at 03:45:42PM +0400, Oleg wrote:
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;
You could have empty pair set (like pair set my_null; my_null = []), but pair set comparison is not implemented.
2. add(C,P) cann't get pair set like delete(C,P) do and
That is because 'delete' is just overloaded, there are two pairs of operations: add/delete pair delete/filter pair set.
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.
Main reason is that pair sets contain intervals and wild cards and are represented using balanced trees for efficient matching, their construction is done in parse-time and not in run-time during matching so it is faster (and modifying would require re-construction or rebalancing, which is notrivial), while clist is just a list of pairs. This is also a reason why set algebra (conjunction. disjunction, negation) is not implemented for (pair) sets, it have to be done in parse-time, but current filtering code is based on just run-time execution.
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?
The code: comm = filter(bgp_community, allowed); bgp_community.delete([(myas,*)]); bgp_community.add(comm); could be done if comm would be clist and adding clist to clist would be implemented (which i could add, this is simple). Another way how to do this is even simpler: def_allowed = [(myas,1000), (myas,1001), (myas,1002), (0..myas-1,*), (myas+1..65535,*)]; bgp_community.filter(def_allowed); But in that case you have to also add (0..myas-1,*), (myas+1..65535,*) to 'allowed' pair set by caller. -- Elen sila lumenn' omentielvo Ondrej 'SanTiago' Zajicek (email: santiago@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."
On Thu, Mar 08, 2012 at 12:07:33PM +0100, Ondrej Zajicek wrote:
On Wed, Mar 07, 2012 at 03:45:42PM +0400, Oleg wrote:
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;
You could have empty pair set (like pair set my_null; my_null = []), but pair set comparison is not implemented.
Is it hard to implement? Do you plan to implement it :-)?
2. add(C,P) cann't get pair set like delete(C,P) do and
That is because 'delete' is just overloaded, there are two pairs of operations:
add/delete pair
delete/filter pair set.
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.
Main reason is that pair sets contain intervals and wild cards and are represented using balanced trees for efficient matching, their construction is done in parse-time and not in run-time during matching so it is faster (and modifying would require re-construction or rebalancing, which is notrivial), while clist is just a list of pairs.
This is also a reason why set algebra (conjunction. disjunction, negation) is not implemented for (pair) sets, it have to be done in parse-time, but current filtering code is based on just run-time execution.
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?
The code: comm = filter(bgp_community, allowed); bgp_community.delete([(myas,*)]); bgp_community.add(comm);
could be done if comm would be clist and adding clist to clist would be implemented (which i could add, this is simple).
This would be nice! I'm ready to git-pull :-).
Another way how to do this is even simpler:
def_allowed = [(myas,1000), (myas,1001), (myas,1002), (0..myas-1,*), (myas+1..65535,*)]; bgp_community.filter(def_allowed);
I thought about it, but this:
But in that case you have to also add (0..myas-1,*), (myas+1..65535,*) to 'allowed' pair set by caller.
would make function call more intricate, thus i discard this way.
On Fri, Mar 09, 2012 at 12:53:32AM +0400, Oleg wrote:
The code: comm = filter(bgp_community, allowed); bgp_community.delete([(myas,*)]); bgp_community.add(comm);
could be done if comm would be clist and adding clist to clist would be implemented (which i could add, this is simple).
This would be nice! I'm ready to git-pull :-).
Implemented in commit 0888a737b045b48106edbd28ba3cd62fcc8c191e, Also allows number ~ bgppath match. -- Elen sila lumenn' omentielvo Ondrej 'SanTiago' Zajicek (email: santiago@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."
On Mon, Mar 19, 2012 at 12:43:40PM +0100, Ondrej Zajicek wrote:
On Fri, Mar 09, 2012 at 12:53:32AM +0400, Oleg wrote:
The code: comm = filter(bgp_community, allowed); bgp_community.delete([(myas,*)]); bgp_community.add(comm);
could be done if comm would be clist and adding clist to clist would be implemented (which i could add, this is simple).
This would be nice! I'm ready to git-pull :-).
Implemented in commit 0888a737b045b48106edbd28ba3cd62fcc8c191e,
Also allows number ~ bgppath match.
It works! Now my function is: function filter_communities(pair set allowed) clist comm; pair set def_allowed; { 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,*)]); bgp_community.add(comm); if ! ( comm ~ [(0,0)..(65535,65535)] ) then if ( (myas,1000) ~ allowed ) then bgp_community.add((myas,1000)); } One question. Is "! ( comm ~ [(0,0)..(65535,65535)] )" construction fast?
On Tue, Mar 20, 2012 at 12:37:51AM +0400, Oleg wrote:
One question. Is "! ( comm ~ [(0,0)..(65535,65535)] )" construction fast?
Yes, it is. BTW, you could write it as !(comm ~ [(*,*)]). -- Elen sila lumenn' omentielvo Ondrej 'SanTiago' Zajicek (email: santiago@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."
participants (3)
-
Alexander Shikov -
Oleg -
Ondrej Zajicek