]> git.ipfire.org Git - thirdparty/bird.git/blame - filter/test.conf
Some cleanups.
[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);
684c6f5a 65 print "5 = ", p2.len;
cf186034
OZ
66
67 pm1 = [= 1 2 * 3 4 5 =];
68 p2 = prepend( + empty +, 5 );
69 p2 = prepend( p2, 4 );
70 p2 = prepend( p2, 3 );
71 p2 = prepend( p2, 3 );
72 p2 = prepend( p2, 2 );
73 p2 = prepend( p2, 1 );
74 print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1;
9c400ec9
PM
75
76 l = - empty -;
77 l = add( l, (1,2) );
4444ed2b
PM
78 l = add( l, (2,3) );
79 print "Community list (1,2) (2,3) ", l;
2bd2de01 80 print "Should be true: ", (2,3) ~ l;
4444ed2b
PM
81 l = delete( l, (2,3) );
82 print "Community list (1,2) ", l;
2bd2de01 83 print "Should be false: ", (2,3) ~ l;
77de6882
PM
84}
85
94d9dfa4
PM
86function bla()
87{
88 print "fifteen called";
89 return 15;
90}
91
cbfd671f
PM
92define four=4;
93define onetwo=1.2.3.4;
94
4bb18dd2
PM
95function __test1()
96{
97 if source ~ [ RTS_BGP, RTS_STATIC ] then {
98# ospf_metric1 = 65535;
99# ospf_metric2 = 1000;
100 ospf_tag = 0x12345678;
101 accept;
102 } reject;
103}
104
105function __test2()
106{
107 if source ~ [ RTS_BGP, RTS_STATIC ] then {
108# ospf_metric1 = 65535;
109# ospf_metric2 = 1000;
110 ospf_tag = 0x12345678;
111 accept;
112 } reject;
113}
114
b1a597e0
OZ
115function test_pxset(prefix set pxs)
116{
117 print " must be true: ", 10.0.0.0/8 ~ pxs, ",", 10.0.0.0/10 ~ pxs, ",", 10.0.0.0/12 ~ pxs, ",",
118 20.0.0.0/24 ~ pxs, ",", 20.0.40.0/24 ~ pxs, ",", 20.0.0.0/26 ~ pxs, ",",
119 20.0.100.0/26 ~ pxs, ",", 20.0.0.0/28 ~ pxs, ",", 20.0.255.0/28 ~ pxs;
120 print " must be false: ", 10.0.0.0/7 ~ pxs, ",", 10.0.0.0/13 ~ pxs, ",", 10.0.0.0/16 ~ pxs, ",",
121 20.0.0.0/16 ~ pxs, ",", 20.0.0.0/23 ~ pxs, ",", 20.0.0.0/29 ~ pxs, ",",
122 11.0.0.0/10 ~ pxs, ",", 20.1.0.0/26 ~ pxs;
123}
124
94d9dfa4 125function __startup()
4515bdba 126int i;
b1a597e0 127bool b;
4515bdba
PM
128prefix px;
129ip p;
b1a597e0
OZ
130pair pp;
131int set is;
132prefix set pxs;
133string s;
4515bdba
PM
134{
135 print "Testing filter language:";
cbfd671f 136 i = four;
c5a06f65 137 i = 12*100 + 60/2 + i;
4515bdba 138 i = ( i + 0 );
995e5894 139 print " arithmetics: 1234 = ", i;
4515bdba 140 printn " if statements ";
995e5894
PM
141 print "what happens here?";
142 printn ".";
143 if (i = 4) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
144# if !(i = 3) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
4515bdba 145 if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; }
995e5894 146# if 1 <= 1 then printn "."; else { print "*** FAIL: test 3"; }
4515bdba 147 if 1234 < 1234 then { print "*** FAIL: test 4"; quitbird; } else print "ok";
b1a597e0 148 is = [ 2, 3, 4, 7..11 ];
995e5894 149 print " must be true: ", 1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ];
b1a597e0 150 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+ ];
5f4aee76 151 print " must be true: ", true && true, ",", true || false;
995e5894
PM
152
153# print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
b1a597e0 154 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 155
455ca441 156 px = 1.2.0.0/18;
995e5894 157 print "Testing prefixes: 1.2.0.0/18 = ", px;
92a72a4c
OZ
158 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;
159 print " must be false: ", 192.168.0.0/15 ~ 192.168.0.0/16, " ", 192.160.0.0/17 ~ 192.168.0.0/16;
160
4515bdba 161 p = 127.1.2.3;
995e5894 162 print "Testing mask : 127.0.0.0 = ", p.mask(8);
b1a597e0
OZ
163
164 pp = (1, 2);
92a72a4c
OZ
165 print "Testing pairs: (1,2) = ", (1,2), " = ", pp, " = ", (1,1+1), " = ", mkpair(2);
166 print " must be true: ", (1,2) = (1,1+1);
995e5894 167 print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC;
4515bdba 168
b1a597e0
OZ
169 s = "Hello";
170 print "Testing string: ", s, " true: ", s ~ "Hell*", " false: ", s ~ "ell*";
171
172 b = true;
173 print "Testing bool: ", b, ", ", !b;
a6c9f064
OF
174
175 if ( b = true ) then print "Testing bool comparison b = true: ", b;
176 else { print "*** FAIL: TRUE test failed" ; quitbird; }
b1a597e0
OZ
177
178 pxs = [ 1.2.0.0/16, 1.4.0.0/16+];
179 print "Testing prefix sets: ";
180 print pxs;
181 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;
182 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, ",",
183 1.2.0.0/32 ~ pxs, ",", 1.4.0.0/15 ~ pxs;
184
185 test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
995e5894 186 print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
4515bdba
PM
187
188 print "Testing functions...";
189# callme ( 1, 2 );
190 callme ( 2, 2 );
191 callme ( 2, 2 );
192 callme ( 3, 2 );
193 callme ( 4, 2 );
194 callme ( 7, 2 );
195
2d496d20 196 i = fifteen();
995e5894 197 print "Testing function calls: 15 = ", i;
2d496d20 198
77de6882
PM
199 paths();
200
cbfd671f
PM
201 print "1.2.3.4 = ", onetwo;
202
4515bdba
PM
203 print "done";
204 quitbird;
205# print "*** FAIL: this is unreachable";
206}
207
208filter testf
209int j;
210{
995e5894
PM
211 print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
212 print "This route was from ", from;
4515bdba
PM
213 j = 7;
214 j = 17;
2e18b87d 215 if rip_metric > 15 then {
c7b43f33
PM
216 reject "RIP Metric is more than infinity";
217 }
2e18b87d
PM
218 rip_metric = 14;
219 unset(rip_metric);
4515bdba 220
c7b43f33 221 accept "ok I take that";
4515bdba 222}
6be662d9 223
a6c9f064 224eval __startup();