]> git.ipfire.org Git - thirdparty/bird.git/blame - filter/test.conf
Priority for '||' and '&&' fixed.
[thirdparty/bird.git] / filter / test.conf
CommitLineData
4515bdba
PM
1/*
2 * This is an example configuration file.
64ba9f7b 3 * FIXME: add all examples from docs here.
4515bdba
PM
4 */
5
6# Yet another comment
7
8router id 62.168.0.1;
9
60de3356 10define xyzzy = (120+10);
4515bdba 11
92a72a4c
OZ
12
13function mkpair(int a)
14{
15 return (1, a);
16}
17
18function mkpath(int a; int b)
19{
20 return [= a b 3 2 1 =];
21}
22
2d496d20 23function callme(int arg1; int arg2)
4515bdba
PM
24int local1;
25int local2;
26int i;
27{
995e5894 28 printn "Function callme called arguments ", arg1, " and ", arg2, ":" ;
4515bdba
PM
29 i = arg2;
30
31 case arg1 {
32 2: print "dva"; print "jeste jednou dva";
33 3 .. 5: print "tri az pet";
34 else: print "neco jineho";
35 }
36}
37
2d496d20
PM
38function fifteen()
39{
40 print "fifteen called";
41 return 15;
42}
43
77de6882 44function paths()
cf186034
OZ
45bgpmask pm1;
46bgpmask pm2;
e399b6f6 47bgppath p2;
9c400ec9 48clist l;
77de6882 49{
cf186034
OZ
50 pm1 = / 4 3 2 1 /;
51 pm2 = [= 4 3 2 1 =];
52 print "Testing path masks: ", pm1, " ", pm2;
e399b6f6
PM
53 p2 = prepend( + empty +, 1 );
54 p2 = prepend( p2, 2 );
55 p2 = prepend( p2, 3 );
56 p2 = prepend( p2, 4 );
57 print "Testing paths: ", p2;
cf186034 58 print "Should be true: ", p2 ~ pm1, " ", p2 ~ pm2;
684c6f5a 59 print "4 = ", p2.len;
e399b6f6 60 p2 = prepend( p2, 5 );
cf186034
OZ
61 print "Should be false: ", p2 ~ pm1, " ", p2 ~ pm2;
62 print "Should be true: ", p2 ~ / ? 4 3 2 1 /, " ", p2, " ", / ? 4 3 2 1 /;
63 print "Should be true: ", p2 ~ [= * 4 3 * 1 =], " ", p2, " ", [= * 4 3 * 1 =];
92a72a4c 64 print "Should be true: ", p2 ~ [= (3+2) (2*2) 3 2 1 =], " ", p2 ~ mkpath(5, 4);
4cdd0784 65 print "Should be true: ", p2.len = 5, " ", p2.first = 5, " ", p2.last = 1;
684c6f5a 66 print "5 = ", p2.len;
cf186034
OZ
67
68 pm1 = [= 1 2 * 3 4 5 =];
69 p2 = prepend( + empty +, 5 );
70 p2 = prepend( p2, 4 );
71 p2 = prepend( p2, 3 );
72 p2 = prepend( p2, 3 );
73 p2 = prepend( p2, 2 );
74 p2 = prepend( p2, 1 );
75 print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1;
9c400ec9
PM
76
77 l = - empty -;
78 l = add( l, (1,2) );
4444ed2b
PM
79 l = add( l, (2,3) );
80 print "Community list (1,2) (2,3) ", l;
2bd2de01 81 print "Should be true: ", (2,3) ~ l;
4444ed2b
PM
82 l = delete( l, (2,3) );
83 print "Community list (1,2) ", l;
2bd2de01 84 print "Should be false: ", (2,3) ~ l;
77de6882
PM
85}
86
94d9dfa4
PM
87function bla()
88{
89 print "fifteen called";
90 return 15;
91}
92
cbfd671f
PM
93define four=4;
94define onetwo=1.2.3.4;
95
4bb18dd2
PM
96function __test1()
97{
98 if source ~ [ RTS_BGP, RTS_STATIC ] then {
99# ospf_metric1 = 65535;
100# ospf_metric2 = 1000;
101 ospf_tag = 0x12345678;
102 accept;
103 } reject;
104}
105
106function __test2()
107{
108 if source ~ [ RTS_BGP, RTS_STATIC ] then {
109# ospf_metric1 = 65535;
110# ospf_metric2 = 1000;
111 ospf_tag = 0x12345678;
112 accept;
113 } reject;
114}
115
b1a597e0
OZ
116function test_pxset(prefix set pxs)
117{
118 print " must be true: ", 10.0.0.0/8 ~ pxs, ",", 10.0.0.0/10 ~ pxs, ",", 10.0.0.0/12 ~ pxs, ",",
119 20.0.0.0/24 ~ pxs, ",", 20.0.40.0/24 ~ pxs, ",", 20.0.0.0/26 ~ pxs, ",",
120 20.0.100.0/26 ~ pxs, ",", 20.0.0.0/28 ~ pxs, ",", 20.0.255.0/28 ~ pxs;
121 print " must be false: ", 10.0.0.0/7 ~ pxs, ",", 10.0.0.0/13 ~ pxs, ",", 10.0.0.0/16 ~ pxs, ",",
122 20.0.0.0/16 ~ pxs, ",", 20.0.0.0/23 ~ pxs, ",", 20.0.0.0/29 ~ pxs, ",",
123 11.0.0.0/10 ~ pxs, ",", 20.1.0.0/26 ~ pxs;
124}
125
94d9dfa4 126function __startup()
4515bdba 127int i;
b1a597e0 128bool b;
4515bdba
PM
129prefix px;
130ip p;
b1a597e0
OZ
131pair pp;
132int set is;
133prefix set pxs;
134string s;
4515bdba
PM
135{
136 print "Testing filter language:";
cbfd671f 137 i = four;
c5a06f65 138 i = 12*100 + 60/2 + i;
4515bdba 139 i = ( i + 0 );
995e5894 140 print " arithmetics: 1234 = ", i;
4515bdba 141 printn " if statements ";
995e5894
PM
142 print "what happens here?";
143 printn ".";
144 if (i = 4) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
145# if !(i = 3) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
4515bdba 146 if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; }
995e5894 147# if 1 <= 1 then printn "."; else { print "*** FAIL: test 3"; }
4515bdba 148 if 1234 < 1234 then { print "*** FAIL: test 4"; quitbird; } else print "ok";
b1a597e0 149 is = [ 2, 3, 4, 7..11 ];
995e5894 150 print " must be true: ", 1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ];
b1a597e0 151 print " data types; must be true: ", 1.2.3.4 = 1.2.3.4, ",", 1 ~ [1,2,3], ",", 5 ~ [1..20], ",", 10 ~ is, ",", 2 ~ [ 1, 2, 3 ], ",", 5 ~ [ 4 .. 7 ], ",", 1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ], ",", 1.2.3.4 ~ 1.0.0.0/8, ",", 1.0.0.0/8 ~ 1.0.0.0/8, ",", 1.0.0.0/8 ~ [ 1.0.0.0/8+ ];
1960d203 152 print " must be true: ", true && true, ",", true || false, ",", ! false && ! false && true, ",", 1 < 2 && 1 != 3;
995e5894
PM
153
154# print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
b1a597e0 155 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;
4515bdba 156
455ca441 157 px = 1.2.0.0/18;
995e5894 158 print "Testing prefixes: 1.2.0.0/18 = ", px;
92a72a4c
OZ
159 print " must be true: ", 192.168.0.0/16 ~ 192.168.0.0/16, " ", 192.168.0.0/17 ~ 192.168.0.0/16, " ", 192.168.254.0/24 ~ 192.168.0.0/16;
160 print " must be false: ", 192.168.0.0/15 ~ 192.168.0.0/16, " ", 192.160.0.0/17 ~ 192.168.0.0/16;
161
4515bdba 162 p = 127.1.2.3;
995e5894 163 print "Testing mask : 127.0.0.0 = ", p.mask(8);
b1a597e0
OZ
164
165 pp = (1, 2);
92a72a4c
OZ
166 print "Testing pairs: (1,2) = ", (1,2), " = ", pp, " = ", (1,1+1), " = ", mkpair(2);
167 print " must be true: ", (1,2) = (1,1+1);
995e5894 168 print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC;
4515bdba 169
b1a597e0
OZ
170 s = "Hello";
171 print "Testing string: ", s, " true: ", s ~ "Hell*", " false: ", s ~ "ell*";
172
173 b = true;
174 print "Testing bool: ", b, ", ", !b;
a6c9f064
OF
175
176 if ( b = true ) then print "Testing bool comparison b = true: ", b;
177 else { print "*** FAIL: TRUE test failed" ; quitbird; }
b1a597e0
OZ
178
179 pxs = [ 1.2.0.0/16, 1.4.0.0/16+];
180 print "Testing prefix sets: ";
181 print pxs;
182 print " must be true: ", 1.2.0.0/16 ~ pxs, ",", 1.4.0.0/16 ~ pxs, ",", 1.4.0.0/18 ~ pxs, ",", 1.4.0.0/32 ~ pxs;
183 print " must be false: ", 1.1.0.0/16 ~ pxs, ",", 1.3.0.0/16 ~ pxs, ",", 1.2.0.0/15 ~ pxs, ",", 1.2.0.0/17 ~ pxs, ",",
184 1.2.0.0/32 ~ pxs, ",", 1.4.0.0/15 ~ pxs;
185
186 test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
995e5894 187 print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
4515bdba
PM
188
189 print "Testing functions...";
190# callme ( 1, 2 );
191 callme ( 2, 2 );
192 callme ( 2, 2 );
193 callme ( 3, 2 );
194 callme ( 4, 2 );
195 callme ( 7, 2 );
196
2d496d20 197 i = fifteen();
995e5894 198 print "Testing function calls: 15 = ", i;
2d496d20 199
77de6882
PM
200 paths();
201
cbfd671f
PM
202 print "1.2.3.4 = ", onetwo;
203
4515bdba
PM
204 print "done";
205 quitbird;
206# print "*** FAIL: this is unreachable";
207}
208
209filter testf
210int j;
211{
995e5894
PM
212 print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
213 print "This route was from ", from;
4515bdba
PM
214 j = 7;
215 j = 17;
2e18b87d 216 if rip_metric > 15 then {
c7b43f33
PM
217 reject "RIP Metric is more than infinity";
218 }
2e18b87d
PM
219 rip_metric = 14;
220 unset(rip_metric);
4515bdba 221
c7b43f33 222 accept "ok I take that";
4515bdba 223}
6be662d9 224
a6c9f064 225eval __startup();