Statistics
| Branch: | Revision:

iof-bird-daemon / filter / test.conf @ 42a0c054

History | View | Annotate | Download (12.8 KB)

1

    
2
/*
3
 *	This is an example configuration file.
4
 *	FIXME: add all examples from docs here.
5
 */
6

    
7
# Yet another comment
8

    
9
router id 62.168.0.1;
10

    
11
define xyzzy = (120+10);
12
define '1a-a1' = (20+10);
13
define one = 1;
14
define ten = 10;
15

    
16
function onef(int a)
17
{
18
	return 1;
19
}
20

    
21

    
22
function 'mkpair-a'(int a)
23
{
24
	return (1, a);
25
}
26

    
27
function mkpath(int a; int b)
28
{
29
	return [= a b 3 2 1 =];
30
}
31

    
32
function callme(int arg1; int arg2)
33
int local1;
34
int local2;
35
int i;
36
{
37
	printn "Function callme called arguments ", arg1, " and ", arg2, ": " ;
38
	i = arg2;
39

    
40
	case arg1 {
41
	11, 1, 111: printn "jedna, "; printn "jedna";
42
	(one+onef(2)): printn "dva, "; printn "jeste jednou dva";
43
	(2+one) .. 5: if arg2 < 3 then printn "tri az pet";
44
	else: printn "neco jineho";
45
	}
46
	print;
47
}
48

    
49
function fifteen()
50
{
51
	print "fifteen called";
52
	return 15;
53
}
54

    
55
function paths()
56
bgpmask pm1;
57
bgpmask pm2;
58
bgppath p2;
59
clist l;
60
eclist el;
61
{
62
	pm1 =  / 4 3 2 1 /;
63
	pm2 = [= 4 3 2 1 =];
64
	print "Testing path masks: ", pm1, " ", pm2;
65
	p2 = prepend( + empty +, 1 );
66
	p2 = prepend( p2, 2 );
67
	p2 = prepend( p2, 3 );
68
	p2 = prepend( p2, 4 );
69
	print "Testing paths: ", p2;
70
	print "Should be true: ", p2 ~ pm1, " ", p2 ~ pm2;
71
	print "4 = ", p2.len;
72
	p2 = prepend( p2, 5 );
73
	print "Should be false: ", p2 ~ pm1, " ", p2 ~ pm2;
74
	print "Should be true: ", p2 ~  / ? 4 3 2 1 /,  " ", p2, " ",  / ? 4 3 2 1 /;
75
	print "Should be true: ", p2 ~ [= * 4 3 * 1 =], " ", p2, " ", [= * 4 3 * 1 =];
76
	print "Should be true: ", p2 ~ [= (3+2) (2*2) 3 2 1 =], " ", p2 ~ mkpath(5, 4);
77
	print "Should be true: ", p2.len = 5, " ", p2.first = 5, " ", p2.last = 1;
78
	print "5 = ", p2.len;
79
	
80
	pm1 = [= 1 2 * 3 4 5 =];
81
	p2 = prepend( + empty +, 5 );
82
	p2 = prepend( p2, 4 );
83
	p2 = prepend( p2, 3 );
84
	p2 = prepend( p2, 3 );
85
	p2 = prepend( p2, 2 );
86
	p2 = prepend( p2, 1 );
87
	print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1;
88

    
89
	l = - empty -;
90
	print "Should be false in this special case: ", l ~ [(*,*)];
91
	l = add( l, (one,2) );
92
	print "Should be always true: ", l ~ [(*,*)];
93
	l = add( l, (2,one+2) );
94
	print "Community list (1,2) (2,3) ", l;
95
	print "Should be true: ", (2,3) ~ l, " ", l ~ [(1,*)], " ", l ~ [(2,3)]," ", l ~ [(2,2..3)], " ", l ~ [(1,1..2)], " ", l ~ [(1,1)..(1,2)];
96
	l = add( l, (2,5) );
97
	l = add( l, (5,one) );
98
	l = add( l, (6,one) );
99
	l = add( l, (one,one) );
100
	l = delete( l, [(5,1),(6,one),(one,1)] );
101
	l = delete( l, [(5,one),(6,one)] );
102
	l = filter( l, [(1,*)] );
103
	print "Community list (1,2) ", l;
104
	print "Should be false: ", (2,3) ~ l, " ", l ~ [(2,*)], " ", l ~ [(one,3..6)];
105
	print "Should be always true: ", l ~ [(*,*)];
106
	l = add( l, (3,one) );
107
	l = add( l, (one+one+one,one+one) );
108
	l = add( l, (3,3) );
109
	l = add( l, (3,4) );
110
	l = add( l, (3,5) );
111
	l = delete( l, [(3,2..4)] );
112
	print "Community list (1,2) (3,1) (3,5) ", l;
113
	l = add( l, (3,2) );
114
	l = add( l, (4,5) );
115
	print "Community list (1,2) (3,1) (3,2) (3,5) (4,5) ", l;
116
	print "Should be true: ", l ~ [(*,2)], " ", l ~ [(*,5)], " ", l ~ [(*, one)];
117
	print "Should be false: ", l ~ [(*,3)], " ", l ~ [(*,(one+6))], " ", l ~ [(*, (one+one+one))];
118
	l = delete( l, [(*,(one+onef(3)))] );
119
	l = delete( l, [(*,(4+one))] );
120
	print "Community list (3,1) ", l;
121
	l = delete( l, [(*,(onef(5)))] );
122
	print "Community list empty ", l;
123

    
124
	el = -- empty --;
125
	el = add(el, (rt, 10, 20));
126
	el = add(el, (ro, 10.20.30.40, 100));
127
	el = add(el, (ro, 11.21.31.41.mask(16), 200));
128
	print "EC list (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200):";
129
	print el;
130
	el = delete(el, (rt, 10, 20));
131
	el = delete(el, (rt, 10, 30));
132
	el = add(el, (unknown 2, ten, 1));
133
	el = add(el, (unknown 5, ten, 1));
134
	el = add(el, (rt, ten, one+one));
135
	el = add(el, (rt, 10, 3));
136
	el = add(el, (rt, 10, 4));
137
	el = add(el, (rt, 10, 5));
138
	el = add(el, (generic, 0x2000a, 3*ten));
139
	el = delete(el, [(rt, 10, 2..ten)]);
140
	print "EC list (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200) (rt, 10, 1) (unknown 0x5, 10, 1) (rt, 10, 30):";
141
	print el;
142
	el = filter(el, [(rt, 10, *)]);
143
	print "EC list (rt, 10, 1) (rt, 10, 30): ", el;
144
	print "Testing EC list, true: ", (rt, 10, 1) ~ el, " ", el ~ [(rt, 10, ten..40)];
145
	print "Testing EC list, false: ", (rt, 10, 20) ~ el, " ", (ro, 10.20.30.40, 100) ~ el, " ", el ~ [(rt, 10, 35..40)], " ", el ~ [(ro, 10, *)];
146
}
147

    
148
function bla()
149
{
150
	print "fifteen called";
151
	return 15;
152
}
153

    
154
define four=4;
155
define onetwo=1.2.3.4;
156

    
157
function __test1()
158
{
159
        if source ~ [ RTS_BGP, RTS_STATIC ] then {                     
160
#                       ospf_metric1 = 65535;                                                                     
161
#                       ospf_metric2 = 1000;                                            
162
                        ospf_tag = 0x12345678;                              
163
                        accept;                                             
164
        }                                                                                                                                                                                                                reject;                                                                                                                                                                                          
165
}
166

    
167
function __test2()
168
{
169
        if source ~ [ RTS_BGP, RTS_STATIC ] then {                     
170
#                       ospf_metric1 = 65535;                                                                     
171
#                       ospf_metric2 = 1000;                                            
172
                        ospf_tag = 0x12345678;                              
173
                        accept;                                             
174
                }                                                                                                                                                                                                                reject;                                                                                                                                                                                          
175
}
176

    
177
function test_pxset(prefix set pxs)
178
{
179
	print pxs;
180
	print "  must be true:  ",	10.0.0.0/8  ~ pxs, ",", 10.0.0.0/10  ~ pxs, ",", 10.0.0.0/12 ~ pxs, ",",
181
					20.0.0.0/24 ~ pxs, ",", 20.0.40.0/24 ~ pxs, ",", 20.0.0.0/26 ~ pxs, ",",
182
					20.0.100.0/26 ~ pxs, ",", 20.0.0.0/28 ~ pxs, ",", 20.0.255.0/28 ~ pxs;
183
	print "  must be false: ",	10.0.0.0/7 ~ pxs,  ",", 10.0.0.0/13 ~ pxs, ",", 10.0.0.0/16 ~ pxs, ",",
184
					20.0.0.0/16 ~ pxs, ",", 20.0.0.0/23 ~ pxs, ",", 20.0.0.0/29 ~ pxs, ",",
185
					11.0.0.0/10 ~ pxs, ",", 20.1.0.0/26 ~ pxs;
186
}
187

    
188
function test_undef(int a)
189
int b;
190
{
191
	if a = 3
192
	then b = 4;
193
	print "Defined: ", a, " ", b, " ", defined(b);
194
}
195

    
196
function __startup() 
197
int i;
198
bool b;
199
prefix px;
200
ip p;
201
pair pp;
202
quad qq;
203
ec cc;
204
int set is;
205
int set is1;
206
int set is2;
207
int set is3;
208
pair set ps;
209
ec set ecs;
210
prefix set pxs;
211
string s;
212
{
213
	print "1a-a1 = 30: ", '1a-a1'; 
214
	print "Testing filter language:";
215
	i = four; 
216
	i = 12*100 + 60/2 + i; 
217
	i = ( i + 0 );
218
	print "  arithmetics: 1234 = ", i;
219
	printn "  if statements ";
220
	print "what happens here?";
221
	printn ".";
222
	if (i = 4) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
223
#	if !(i = 3) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
224
	if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; }
225
#	if 1 <= 1 then printn "."; else { print "*** FAIL: test 3"; }
226
	if 1234 < 1234 then { print "*** FAIL: test 4"; quitbird; } else print "ok";
227
	is = [ 2, 3, 4, 7..11 ];
228
	print "  must be true: ", 1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ];
229
	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+ ];
230
	print "  must be true: ", true && true, ",", true || false, ",", ! false && ! false && true, ",", 1 < 2 && 1 != 3, ",", true && true && ! false, ",", true || 1+"a", ",", !(false && 1+"a");
231

    
232
	print "  must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
233
	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;
234

    
235
	is1 = [ 1, 5, 8, 11, 15, 17, 19];
236

    
237
	is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
238
	is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
239
	is3 = [5, 17, 2, 11, 8, 15, 3, 19];
240

    
241
	print "  must be true:  ", 1 ~ is1, "  ", 3 ~ is1, "  ", 5 ~ is1;
242
	print "  must be true:  ", (one+2) ~ is1, "  ", 2 ~ is2, "  ", 2 ~ is3;
243
	print "  must be false: ", 4 ~ is1, " ", 4 ~ is2, " ", 4 ~ is3;
244
	print "  must be false: ", 10 ~ is1, " ", 10 ~ is2, " ", 10 ~ is3;
245
	print "  must be true:  ", 15 ~ is1, "  ", 15 ~ is2, "  ", 15 ~ is3;
246
	print "  must be false: ", 18 ~ is1, " ", 18 ~ is2, " ", 18 ~ is3;
247
	print "  must be true:  ", 19 ~ is1, "  ", 19 ~ is2, "  ", 19 ~ is3;
248
	print "  must be false: ", 20 ~ is1, " ", 20 ~ is2, " ", 20 ~ is3;
249

    
250
	px = 1.2.0.0/18;
251
	print "Testing prefixes: 1.2.0.0/18 = ", px;
252
	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;
253
	print "  must be false: ",	192.168.0.0/15 ~ 192.168.0.0/16, " ", 192.160.0.0/17 ~ 192.168.0.0/16;
254

    
255
	p = 127.1.2.3;
256
	print "Testing mask : 127.0.0.0 = ", p.mask(8);
257
	
258
	pp = (1, 2);
259
	print "Testing pairs: (1,2) = ", (1,2), " = ", pp, " = ", (1,1+1), " = ", 'mkpair-a'(2);
260
	print "  must be true:  ", (1,2) = (1,1+1);
261
	print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC, " ",
262
		", true: ", RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE],
263
		", false: ", RTS_BGP ~ [RTS_STATIC, RTS_DEVICE];
264

    
265
	ps = [(1,(one+one)), (3,4)..(4,8), (5,*), (6,3..6)];
266
	print "Pair set: ", ps;
267
	print "Testing pair set, true:  ", pp ~ ps,  "  ", (3,5) ~ ps, "  ", (4,1) ~ ps, "  ", (5,4) ~ ps, "  ", (5,65535) ~ ps, "  ", (6,4) ~ ps, "  ", (3, 10000) ~ ps;
268
	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, " ", (1,1) ~ ps;
269

    
270
	ps = [(20..150, 200..300), (50100..50200, 1000..50000), (*, 5+5)];
271
	print "Pair set: .. too long ..";
272
	print "Testing pair set, true:  ", (100,200) ~ ps,  "  ", (150,300) ~ ps, "  ", (50180,1200) ~ ps, "  ", (50110,49000) ~ ps, "  ", (0,10) ~ ps, "  ", (64000,10) ~ ps;
273
	print "Testing pair set, false: ", (20,199) ~ ps, " ", (151,250) ~ ps, " ", (50050,2000) ~ ps, " ", (50150,50050) ~ ps, " ", (10,9) ~ ps, " ", (65535,11) ~ ps ;
274

    
275
	qq = 1.2.3.4;
276
	print "Testinq quad: 1.2.3.4 = ", qq,
277
		", true: ", qq = 1.2.3.4, " ", qq ~ [1.2.3.4, 5.6.7.8],
278
		", false: ", qq = 4.3.2.1, " ", qq ~ [1.2.1.1, 1.2.3.5];
279

    
280
	cc = (rt, 12345, 200000);
281
	print "Testing EC: (rt, 12345, 200000) = ", cc;
282
	print "Testing EC: (ro, 100000, 20000) = ", (ro, 100000, 20000);
283
	print "Testing EC: (rt, 10.20.30.40, 20000) = ", (rt, 10.20.30.40, 20000);
284
	print "  true: ", cc = (rt, 12345, 200000), " ", cc < (rt, 12345, 200010),
285
		", false: ", cc = (rt, 12346, 200000), " ", cc = (ro, 12345, 200000), " ",  cc > (rt, 12345, 200010);
286

    
287
	ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
288
	print "EC set: ", ecs;
289
	print "Testing EC set, true:  ",  (rt, 10, 20) ~ ecs, "  ", (ro, 100000, 100) ~ ecs, "  ", (ro, 100000, 200) ~ ecs,
290
		"  ", (rt, 12345, 0) ~ ecs, "  ", cc ~ ecs,  "  ", (rt, 12345, 4000000) ~ ecs;
291
	print "Testing EC set, false: ", (ro, 10, 20) ~ ecs, " ", (rt, 10, 21) ~ ecs, " ", (ro, 100000, 99) ~ ecs,
292
		" ", (ro, 12345, 10) ~ ecs, " ", (rt, 12346, 0) ~ ecs, " ", (ro, 0.1.134.160, 150) ~ ecs;
293

    
294
	s = "Hello";
295
	print "Testing string: ", s, " true: ", s ~ "Hell*", " false: ", s ~ "ell*";
296
	
297
	b = true;
298
	print "Testing bool: ", b, ", ", !b;
299

    
300
        if ( b = true ) then print "Testing bool comparison b = true: ", b;
301
	else { print "*** FAIL: TRUE test failed" ; quitbird; }
302
	
303
	pxs = [ 1.2.0.0/16, 1.4.0.0/16+];
304
	print "Testing prefix sets: ";
305
	print pxs;
306
	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;
307
	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, ",",
308
					1.2.0.0/32 ~ pxs, ",", 1.4.0.0/15 ~ pxs;
309

    
310
	test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
311
	print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
312

    
313
	print "Testing functions...";
314
	callme ( 1, 2 );
315
	callme ( 2, 2 );
316
	callme ( 2, 2 );
317
	callme ( 3, 2 );
318
	callme ( 4, 4 );
319
	callme ( 7, 2 );
320

    
321
	i = fifteen();
322
	print "Testing function calls: 15 = ", i;
323

    
324
	paths();
325

    
326
	print "1.2.3.4 = ", onetwo;
327

    
328
	test_undef(2);
329
	test_undef(3);
330
	test_undef(2);
331

    
332
	print "done";
333
	quitbird;
334
#	print "*** FAIL: this is unreachable"; 
335
}
336

    
337
filter testf 
338
int j; 
339
{ 
340
	print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
341
	print "This route was from ", from;
342
	j = 7;
343
	j = 17;
344
	if rip_metric > 15 then {
345
 		reject "RIP Metric is more than infinity";
346
	}
347
	rip_metric = 14;
348
	unset(rip_metric);
349
		
350
	accept "ok I take that";
351
}
352

    
353
eval __startup();