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