Documentation update and improvement of tests related to expressions in sets.

This commit is contained in:
Ondrej Filip 2010-08-03 17:35:34 +02:00
parent e0e8c04a83
commit 946dc15c92
2 changed files with 19 additions and 6 deletions

View file

@ -706,9 +706,21 @@ incompatible with each other (that is to prevent you from shooting in the foot).
Filters recognize four types of sets. Sets are similar to strings: you can pass them around
but you can't modify them. Literals of type <cf>int set</cf> look like <cf>
[ 1, 2, 5..7 ]</cf>. As you can see, both simple values and ranges are permitted in
sets. For pair sets, expressions like <cf/(123,*)/ can be used to denote ranges (in
sets.
For pair sets, expressions like <cf/(123,*)/ can be used to denote ranges (in
that case <cf/(123,0)..(123,65535)/). You can also use <cf/(123,5..100/ for range
<cf/(123,5)..(123,100)/.
You can also use expressions for both, pair sets and int sets. However it must
be possible to evaluate these expressions before daemon boots. So you can use
only constants inside them. E.g.
<code>
define one=1;
int set odds;
pair set ps;
odds = [ one, (2+1), (6-one), (2*2*2-1), 9, 11 ];
ps = [ (1,(one+one)), (3,4)..(4,8), (5,*), (6,3..6) ];
</code>
Sets of prefixes are special: their literals does not allow ranges, but allows
prefix patterns that are written as <cf><M>ipaddress</M>/<M>pxlen</M>{<M>low</M>,<M>high</M>}</cf>.

View file

@ -183,11 +183,12 @@ string s;
print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
print " data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ is, ",", 1.2.3.4 ~ [ 1.2.3.3, 1.2.3.5 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1.0.0.0/9 ~ [ 1.0.0.0/8- ], ",", 1.2.0.0/17 ~ [ 1.0.0.0/8{ 15 , 16 } ], ",", true && false;
is1 = [2, 3, 5, 8, 11, 15, 17, 19];
is1 = [one, (2+1), (6-one), 8, 11, 15, 17, 19];
is2 = [19, 17, 15, 11, 8, 5, 3, 2];
is3 = [5, 17, 2, 11, 8, 15, 3, 19];
print " must be true: ", 2 ~ is1, " ", 2 ~ is2, " ", 2 ~ is3;
print " must be true: ", 1 ~ is1, " ", 3 ~ is1, " ", 5 ~ is1;
print " must be true: ", (one+2) ~ is1, " ", 2 ~ is2, " ", 2 ~ is3;
print " must be false: ", 4 ~ is1, " ", 4 ~ is2, " ", 4 ~ is3;
print " must be false: ", 10 ~ is1, " ", 10 ~ is2, " ", 10 ~ is3;
print " must be true: ", 15 ~ is1, " ", 15 ~ is2, " ", 15 ~ is3;
@ -210,9 +211,9 @@ string s;
", true: ", RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE],
", false: ", RTS_BGP ~ [RTS_STATIC, RTS_DEVICE];
ps = [(1,2), (3,4)..(4,8), (5,*)];
print "Testing pair set, true: ", pp ~ ps, " ", (3,5) ~ ps, " ", (4,1) ~ ps, " ", (5,4) ~ ps, " ", (5,65535) ~ ps;
print "Testing pair set, false: ", (3,3) ~ ps, " ", (4,9) ~ ps, " ", (4,65535) ~ ps, " ", (6,0) ~ ps ;
ps = [(1,(one+one)), (3,4)..(4,8), (5,*), (6,3..6)];
print "Testing pair set, true: ", pp ~ ps, " ", (3,5) ~ ps, " ", (4,1) ~ ps, " ", (5,4) ~ ps, " ", (5,65535) ~ ps, " ", (6,4) ~ ps;
print "Testing pair set, false: ", (3,3) ~ ps, " ", (4,9) ~ ps, " ", (4,65535) ~ ps, " ", (6,2) ~ ps, " ", (6,(6+one)) ~ ps, " ", ((one+6),2) ~ ps ;
qq = 1.2.3.4;
print "Testinq quad: 1.2.3.4 = ", qq,