Statistics
| Branch: | Revision:

iof-bird-daemon / filter / test.conf @ 9b0a0ba9

History | View | Annotate | Download (18.7 KB)

1
/*
2
 *	This is unit testing configuration file for testing filters
3
 *
4
 *	FIXME: add all examples from docs here.
5
 */
6

    
7
router id 62.168.0.1;
8

    
9
/* We have to setup any protocol */
10
protocol static { ipv4; }
11

    
12

    
13

    
14

    
15
/*
16
 * 	Common definitions and functions
17
 * 	--------------------------------
18
 */
19

    
20
define one = 1;
21
define ten = 10;
22

    
23
function onef(int a)
24
{
25
	return 1;
26
}
27

    
28

    
29

    
30

    
31
/*
32
 * 	Testing empty lists/paths
33
 * 	-------------------------
34
 */
35

    
36
function t_empty()
37
{
38
	bt_assert(+empty+ = +empty+);
39
	bt_assert(+empty+ != -empty-);
40
	bt_assert(+empty+ != --empty--);
41

    
42
	bt_assert(-empty- = -empty-);
43
	bt_assert(-empty- != --empty--);
44

    
45
	bt_assert(--empty-- = --empty--);
46
}
47

    
48
bt_test_suite(t_empty, "Testing +empty+, -empty-, --empty--");
49

    
50

    
51

    
52

    
53
/*
54
 * 	Testing Paths
55
 * 	-------------
56
 */
57

    
58
function mkpath(int a; int b)
59
{
60
	return [= a b 3 2 1 =];
61
}
62

    
63
function t_path()
64
bgpmask pm1;
65
bgpmask pm2;
66
bgppath p2;
67
{
68
	pm1 =  / 4 3 2 1 /;
69
	pm2 = [= 4 3 2 1 =];
70

    
71
	p2 = prepend( + empty +, 1 );
72
	p2 = prepend( p2, 2 );
73
	p2 = prepend( p2, 3 );
74
	p2 = prepend( p2, 4 );
75

    
76
	print "Testing paths: ", p2;
77
	bt_assert(p2.len = 4);
78
	bt_assert(p2 ~ pm1);
79
	bt_assert(p2 ~ pm2);
80
	bt_assert(3 ~ p2);
81
	bt_assert(p2 ~ [2, 10..20]);
82
	bt_assert(p2 ~ [4, 10..20]);
83

    
84
	p2 = prepend(p2, 5);
85
	bt_assert(p2 !~ pm1);
86
	bt_assert(p2 !~ pm2);
87
	bt_assert(10 !~ p2);
88
	bt_assert(p2 !~ [8, ten..(2*ten)]);
89
	bt_assert(p2 ~  / ? 4 3 2 1 /);
90
	bt_assert(p2 ~ [= * 4 3 * 1 =]);
91
	bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
92
	bt_assert(p2 ~ mkpath(5, 4));
93

    
94
	bt_assert(p2.len = 5);
95
	bt_assert(p2.first = 5);
96
	bt_assert(p2.last = 1);
97

    
98
	bt_assert(p2.len = 5);
99
	bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
100
	bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
101

    
102
	pm1 = [= 1 2 * 3 4 5 =];
103
	p2 = prepend( + empty +, 5 );
104
	p2 = prepend( p2, 4 );
105
	p2 = prepend( p2, 3 );
106
	p2 = prepend( p2, 3 );
107
	p2 = prepend( p2, 2 );
108
	p2 = prepend( p2, 1 );
109

    
110
	bt_assert(p2 ~ pm1);
111
	bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
112
	bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
113
}
114

    
115
bt_test_suite(t_path, "Testing paths");
116

    
117

    
118

    
119

    
120
/*
121
 * 	Testing Community List
122
 *	----------------------
123
 */
124

    
125
define p23 = (2, 3);
126

    
127
function t_community_list()
128
clist l;
129
clist l2;
130
{
131
	/* XXX: add((x,y)) works as prepend */
132

    
133
	l = - empty -;
134
	bt_assert(l !~ [(*,*)]);
135
	bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
136

    
137
	l = add( l, (one,2) );
138
	bt_assert(l ~ [(*,*)]);
139
	l = add( l, (2,one+2) );
140
	print "Community list (1,2) (2,3) ", l;
141

    
142
	bt_assert((2,3) ~ l);
143
	bt_assert(l ~ [(1,*)]);
144
	bt_assert(l ~ [p23]);
145
	bt_assert(l ~ [(2,2..3)]);
146
	bt_assert(l ~ [(1,1..2)]);
147
	bt_assert(l ~ [(1,1)..(1,2)]);
148

    
149
	l = add(l, (2,5));
150
	l = add(l, (5,one));
151
	l = add(l, (6,one));
152
	l = add(l, (one,one));
153
	l = delete(l, [(5,1),(6,one),(one,1)]);
154
	l = delete(l, [(5,one),(6,one)]);
155
	l = filter(l, [(1,*)]);
156
	bt_assert(l = add(-empty-, (1,2)));
157

    
158
	bt_assert((2,3) !~ l);
159
	bt_assert(l !~ [(2,*)]);
160
	bt_assert(l !~ [(one,3..6)]);
161
	bt_assert(l ~ [(*,*)]);
162

    
163
	l = add(l, (3,one));
164
	l = add(l, (one+one+one,one+one));
165
	l = add(l, (3,3));
166
	l = add(l, (3,4));
167
	l = add(l, (3,5));
168
	l2 = filter(l, [(3,*)]);
169
	l = delete(l, [(3,2..4)]);
170
	bt_assert(l = add(add(add(-empty-, (1,2)), (3,1)), (3,5)));
171
	bt_assert(l.len = 3);
172

    
173
	l = add(l, (3,2));
174
	l = add(l, (4,5));
175
	bt_assert(l = add(add(add(add(add(-empty-, (1,2)), (3,1)), (3,5)), (3,2)), (4,5)));
176

    
177
	bt_assert(l.len = 5);
178
	bt_assert(l ~ [(*,2)]);
179
	bt_assert(l ~ [(*,5)]);
180
	bt_assert(l ~ [(*, one)]);
181
	bt_assert(l !~ [(*,3)]);
182
	bt_assert(l !~ [(*,(one+6))]);
183
	bt_assert(l !~ [(*, (one+one+one))]);
184

    
185
	l = delete(l, [(*,(one+onef(3)))]);
186
	l = delete(l, [(*,(4+one))]);
187
	bt_assert(l = add(-empty-, (3,1)));
188

    
189
	l = delete(l, [(*,(onef(5)))]);
190
	bt_assert(l = -empty-);
191

    
192
	l2 = add(l2, (3,6));
193
	l = filter(l2, [(3,1..4)]);
194
	l2 = filter(l2, [(3,3..6)]);
195

    
196
	print "clist A (1..4): ", l;
197
	bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
198

    
199
	print "clist B (3..6): ", l2;
200
	bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
201

    
202
	print "clist A union B: ", add( l, l2 );
203
	bt_assert(add(l, l2) = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
204

    
205
	print "clist A isect B: ", filter( l, l2 );
206
	bt_assert(filter(l, l2) = add(add(-empty-, (3,3)), (3,4)));
207

    
208
	print "clist A \ B: ", delete( l, l2 );
209
	bt_assert(delete(l, l2) = add(add(-empty-, (3,1)), (3,2)));
210
}
211

    
212
bt_test_suite(t_community_list, "Testing communities and lists");
213

    
214

    
215

    
216

    
217
/*
218
 * 	Testing Extended Community List
219
 * 	-------------------------------
220
 */
221

    
222
function t_extended_community_list()
223
eclist el;
224
eclist el2;
225
{
226
	el = -- empty --;
227
	el = add(el, (rt, 10, 20));
228
	el = add(el, (ro, 10.20.30.40, 100));
229
	el = add(el, (ro, 11.21.31.41.mask(16), 200));
230

    
231
	print "EC list (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200):";
232
	print el;
233
	bt_assert(el.len = 3);
234
	el = delete(el, (rt, 10, 20));
235
	el = delete(el, (rt, 10, 30));
236
	bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
237
	el = add(el, (unknown 2, ten, 1));
238
	el = add(el, (unknown 5, ten, 1));
239
	el = add(el, (rt, ten, one+one));
240
	el = add(el, (rt, 10, 3));
241
	el = add(el, (rt, 10, 4));
242
	el = add(el, (rt, 10, 5));
243
	el = add(el, (generic, 0x2000a, 3*ten));
244
	el = delete(el, [(rt, 10, 2..ten)]);
245
	bt_assert(el = add(add(add(add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)), (rt, 10, 1)), (unknown 5, 10, 1)), (rt, 10, 30)));
246

    
247
	el = filter(el, [(rt, 10, *)]);
248
	bt_assert(el = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
249
	bt_assert((rt, 10, 1) ~ el);
250
	bt_assert(el ~ [(rt, 10, ten..40)]);
251
	bt_assert((rt, 10, 20) !~ el);
252
	bt_assert((ro, 10.20.30.40, 100) !~ el);
253
	bt_assert(el !~ [(rt, 10, 35..40)]);
254
	bt_assert(el !~ [(ro, 10, *)]);
255

    
256
	el = add(el, (rt, 10, 40));
257
	el2 = filter(el, [(rt, 10, 20..40)] );
258
	el2 = add(el2, (rt, 10, 50));
259

    
260
	print "eclist A (1,30,40): ", el;
261
	bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
262

    
263
	print "eclist B (30,40,50): ", el2;
264
	bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
265

    
266
	print "eclist A union B: ", add(el2, el);
267
	bt_assert(add(el2, el) =  add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
268

    
269
	print "eclist A isect B: ", filter(el, el2);
270
	bt_assert(filter(el, el2) = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
271

    
272
	print "eclist A \ B: ", delete(el, el2);
273
	bt_assert(delete(el, el2) = add(--empty--, (rt, 10, 1)));
274
}
275

    
276
bt_test_suite(t_extended_community_list, "Testing extended communities and lists");
277

    
278

    
279

    
280

    
281
/*
282
 * 	Testing defined() function
283
 * 	--------------------------
284
 */
285

    
286
function test_undef(int a)
287
int b;
288
{
289
	if a = 3 then {
290
		b = 4;
291
		bt_assert(defined(b));
292
	}
293
	else {
294
		bt_assert(!defined(b));
295
	}
296
}
297

    
298
function t_define()
299
int i;
300
{
301
	test_undef(2);
302
	test_undef(3);
303
	test_undef(2);
304

    
305
	bt_assert(defined(1));
306
	bt_assert(defined(1.2.3.4));
307
}
308

    
309
bt_test_suite(t_define, "Testing defined() function");
310

    
311

    
312

    
313

    
314
/*
315
 * 	Testing quads
316
 * 	-------------
317
 */
318

    
319
function t_quad()
320
quad qq;
321
{
322
	qq = 1.2.3.4;
323
	print "Testinq quad: 1.2.3.4 = ", qq;
324
	bt_assert(qq = 1.2.3.4);
325
	bt_assert(qq != 4.3.2.1);
326
}
327

    
328
bt_test_suite(t_quad, "Testing quads");
329

    
330

    
331

    
332

    
333
/*
334
 * 	Testing sets of quads
335
 * 	---------------------
336
 */
337

    
338
function t_quad_set()
339
quad qq;
340
{
341
	qq = 1.2.3.4;
342
	bt_assert(qq ~ [1.2.3.4, 5.6.7.8]);
343
	bt_assert(qq !~ [1.2.1.1, 1.2.3.5]);
344
}
345

    
346
bt_test_suite(t_quad_set, "Testing sets of quads");
347

    
348

    
349

    
350

    
351
/*
352
 * 	Testing Extended Communities
353
 * 	----------------------------
354
 */
355

    
356
function t_ec()
357
ec cc;
358
{
359
	cc = (rt, 12345, 200000);
360
	print "Testing EC: ", cc;
361

    
362
	bt_assert(cc = (rt, 12345, 200000));
363
	bt_assert(cc < (rt, 12345, 200010));
364
	bt_assert(cc != (rt, 12346, 200000));
365
	bt_assert(cc != (ro, 12345, 200000));
366
	bt_assert(!(cc > (rt, 12345, 200010)));
367

    
368
	print "Testing EC: (ro, 100000, 20000) = ", (ro, 100000, 20000);
369
}
370

    
371
bt_test_suite(t_ec, "Testing Extended Communities");
372

    
373

    
374

    
375

    
376
/*
377
 * 	Testing sets of Extended Communities
378
 * 	------------------------------------
379
 */
380

    
381
define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
382

    
383
function t_ec_set()
384
ec set ecs;
385
{
386
	ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
387
	print "EC set (rt, 10, 20) (ro, 100000, 100..200), (rt, 12345, *):";
388
	print ecs;
389
	print ecs2;
390

    
391
	bt_assert((rt, 10, 20) ~ ecs);
392
	bt_assert((ro, 100000, 100) ~ ecs);
393
	bt_assert((ro, 100000, 128) ~ ecs);
394
	bt_assert((ro, 100000, 200) ~ ecs);
395
	bt_assert((rt, 12345, 0) ~ ecs);
396
	bt_assert((rt, 12345, 200000) ~ ecs);
397
	bt_assert((rt, 12345, 4000000) ~ ecs);
398
	bt_assert((ro, 10, 20) !~ ecs);
399
	bt_assert((rt, 10, 21) !~ ecs);
400
	bt_assert((ro, 100000, 99) !~ ecs);
401
	bt_assert((ro, 12345, 10) !~ ecs);
402
	bt_assert((rt, 12346, 0) !~ ecs);
403
	bt_assert((ro, 0.1.134.160, 150) !~ ecs);
404
}
405

    
406
bt_test_suite(t_ec_set, "Testing sets of Extended Communities");
407

    
408

    
409

    
410

    
411
/*
412
 *	Testing integers
413
 *	----------------
414
 */
415

    
416
define four = 4;
417
define xyzzy = (120+10);
418
define '1a-a1' = (xyzzy-100);
419

    
420
function t_int()
421
int i;
422
{
423
	bt_assert(xyzzy = 130);
424
	bt_assert('1a-a1' = 30);
425

    
426
	i = four;
427
	i = 12*100 + 60/2 + i;
428
	i = (i + 0);
429
	bt_assert(i = 1234);
430

    
431
	if (i = 4) then
432
		bt_assert(false);
433
	else
434
		bt_assert(true);
435

    
436
	if !(i = 3) then
437
		bt_assert(true);
438
	else
439
		bt_assert(false);
440

    
441
	if 1234 = i then
442
		bt_assert(true);
443
	else
444
		bt_assert(false);
445

    
446
	if 1 <= 1 then
447
		bt_assert(true);
448
	else
449
		bt_assert(false);
450

    
451
	if 1234 < 1234 then
452
		bt_assert(false);
453
	else
454
		bt_assert(true);
455

    
456
	i = 4200000000;
457
	bt_assert(i = 4200000000);
458
	bt_assert(i > 4100000000);
459
	bt_assert(!(i > 4250000000));
460

    
461
	bt_assert(1 = 1);
462
	bt_assert(!(1 != 1));
463

    
464
	bt_assert(1 != 2);
465
	bt_assert(1 <= 2);
466

    
467
	bt_assert(1 != "a");
468
	bt_assert(1 != (0,1));
469
}
470

    
471
bt_test_suite(t_int, "Testing integers");
472

    
473

    
474

    
475

    
476
/*
477
 * 	Testing sets of integers
478
 * 	------------------------
479
 */
480

    
481
define is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
482
define is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
483
define is3 = [5, 17, 2, 11, 8, 15, 3, 19];
484

    
485
function t_int_set()
486
int set is;
487
{
488
	bt_assert(1 ~ [1,2,3]);
489
	bt_assert(5 ~ [1..20]);
490
	bt_assert(2 ~ [ 1, 2, 3 ]);
491
	bt_assert(5 ~ [ 4 .. 7 ]);
492
	bt_assert(1 !~ [ 2, 3, 4 ]);
493

    
494
	is = [ 2, 3, 4, 7..11 ];
495
	bt_assert(10 ~ is);
496
	bt_assert(5 !~ is);
497

    
498
	bt_assert(1 ~ is1);
499
	bt_assert(3 ~ is1);
500
	bt_assert(5 ~ is1);
501
	bt_assert((one+2) ~ is1);
502
	bt_assert(2 ~ is2);
503
	bt_assert(2 ~ is3);
504
	bt_assert(4 !~ is1);
505
	bt_assert(4 !~ is2);
506
	bt_assert(4 !~ is3);
507
	bt_assert(10 !~ is1);
508
	bt_assert(10 !~ is2);
509
	bt_assert(10 !~ is3);
510
	bt_assert(15 ~ is1);
511
	bt_assert(15 ~ is2);
512
	bt_assert(15 ~ is3);
513
	bt_assert(18 !~ is1);
514
	bt_assert(18 !~ is2);
515
	bt_assert(18 !~ is3);
516
	bt_assert(19 ~ is1);
517
	bt_assert(19 ~ is2);
518
	bt_assert(19 ~ is3);
519
	bt_assert(20 !~ is1);
520
	bt_assert(20 !~ is2);
521
	bt_assert(20 !~ is3);
522

    
523
	bt_assert([1,2] != [1,3]);
524
	bt_assert([1,4..10,20] = [1,4..10,20]);
525

    
526
	print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
527
}
528

    
529
bt_test_suite(t_int_set, "Testing sets of integers");
530

    
531

    
532

    
533

    
534
/*
535
 * 	Testing ip address
536
 * 	------------------
537
 */
538

    
539
define onetwo = 1.2.3.4;
540

    
541
function t_ip()
542
ip p;
543
{
544
	p = 127.1.2.3;
545
	bt_assert(p.mask(8) = 127.0.0.0);
546
	bt_assert(1.2.3.4 = 1.2.3.4);
547
	bt_assert(1.2.3.4 = onetwo);
548
	print "1.2.3.4 = ", onetwo;
549
}
550

    
551
bt_test_suite(t_ip, "Testing ip address");
552

    
553

    
554

    
555

    
556
/*
557
 * 	Testing sets of ip address
558
 * 	--------------------------
559
 */
560

    
561
function t_ip_set()
562
{
563
	bt_assert(1.2.3.4 !~ [ 1.2.3.3, 1.2.3.5 ]);
564
	bt_assert(1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ]);
565
}
566

    
567
bt_test_suite(t_ip_set, "Testing sets of ip address");
568

    
569

    
570

    
571

    
572
/*
573
 *	Testing enums
574
 *	-------------
575
 */
576

    
577
function t_enum()
578
{
579
	print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC;
580
	bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
581
	bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
582
}
583

    
584
bt_test_suite(t_enum, "Testing enums");
585

    
586

    
587

    
588

    
589
/*
590
 * 	Testing pairs
591
 * 	-------------
592
 */
593

    
594
function 'mkpair-a'(int a)
595
{
596
	return (1, a);
597
}
598

    
599
function t_pair()
600
pair pp;
601
{
602
	pp = (1, 2);
603
	bt_assert((1,2) = pp);
604
	bt_assert((1,1+1) = pp);
605
	bt_assert('mkpair-a'(2) = pp);
606
	bt_assert((1,2) = (1,1+1));
607
	bt_assert(((1,2) < (2,2)));
608
	bt_assert(!((1,1) > (1,1)));
609
}
610

    
611
bt_test_suite(t_pair, "Testing pairs");
612

    
613

    
614

    
615

    
616
/*
617
 * 	Testing sets of pairs
618
 * 	---------------------
619
 */
620

    
621
function t_pair_set()
622
pair pp;
623
pair set ps;
624
{
625
	pp = (1, 2);
626
	ps = [(1,(one+one)), (3,4)..(4,8), (5,*), (6,3..6)];
627
	print "Pair set: ", ps;
628
	bt_assert(pp ~ ps);
629
	bt_assert((3,5) ~ ps);
630
	bt_assert((4,1) ~ ps);
631
	bt_assert((5,4) ~ ps);
632
	bt_assert((5,65535) ~ ps);
633
	bt_assert((6,4) ~ ps);
634
	bt_assert((3, 10000) ~ ps);
635
	bt_assert((3,3) !~ ps);
636
	bt_assert((4,9) !~ ps);
637
	bt_assert((4,65535) !~ ps);
638
	bt_assert((6,2) !~ ps);
639
	bt_assert((6,6+one) !~ ps);
640
	bt_assert(((one+6),2) !~ ps);
641
	bt_assert((1,1) !~ ps);
642

    
643
	ps = [(20..150, 200..300), (50100..50200, 1000..50000), (*, 5+5)];
644
	print "Pair set: ", ps;
645
	bt_assert((100,200) ~ ps);
646
	bt_assert((150,300) ~ ps);
647
	bt_assert((50180,1200) ~ ps);
648
	bt_assert((50110,49000) ~ ps);
649
	bt_assert((0,10) ~ ps);
650
	bt_assert((64000,10) ~ ps);
651
	bt_assert((20,199) !~ ps);
652
	bt_assert((151,250) !~ ps);
653
	bt_assert((50050,2000) !~ ps);
654
	bt_assert((50150,50050) !~ ps);
655
	bt_assert((10,9) !~ ps);
656
	bt_assert((65535,11) !~ ps);
657
}
658

    
659
bt_test_suite(t_pair_set, "Testing sets of pairs");
660

    
661

    
662

    
663

    
664
/*
665
 * 	Testing string matching
666
 * 	-----------------------
667
 */
668

    
669
function t_string()
670
string st;
671
{
672
	st = "Hello";
673
	print "Testing string: ", st;
674
	bt_assert(st ~ "Hell*");
675
	bt_assert(st ~ "?ello");
676
	bt_assert(st ~ "Hello");
677
	bt_assert(st ~ "Hell?");
678
	bt_assert(st !~ "ell*");
679
}
680

    
681
bt_test_suite(t_string, "Testing string matching");
682

    
683

    
684

    
685

    
686
/*
687
 * 	Testing boolean expressions
688
 * 	---------------------------
689
 */
690

    
691
function t_bool()
692
bool b;
693
{
694
	b = true;
695
	bt_assert(b);
696
	bt_assert(!!b);
697

    
698
	if ( b = true ) then
699
		bt_assert(b);
700
	else
701
		bt_assert(false);
702

    
703
	bt_assert(true && true);
704
	bt_assert(true || false);
705
	bt_assert(! false && ! false && true);
706
	bt_assert(1 < 2 && 1 != 3);
707
	bt_assert(true && true && ! false);
708
	bt_assert(true || 1+"a");
709
	bt_assert(!(false && 1+"a"));
710
	bt_assert(!(true && false));
711
}
712

    
713
bt_test_suite(t_bool, "Testing boolean expressions");
714

    
715

    
716

    
717

    
718
/*
719
 * 	Testing prefixes
720
 * 	----------------
721
 */
722

    
723
define netdoc = 2001:db8::/32;
724

    
725
function t_prefix()
726
prefix px;
727
{
728
	px = 1.2.0.0/18;
729
	print "Testing prefixes: 1.2.0.0/18 = ", px;
730
	bt_assert(192.168.0.0/16 ~ 192.168.0.0/16);
731
	bt_assert(192.168.0.0/17 ~ 192.168.0.0/16);
732
	bt_assert(192.168.254.0/24 ~ 192.168.0.0/16);
733
	bt_assert(netdoc ~ 2001::/16);
734
	bt_assert(192.168.0.0/15 !~ 192.168.0.0/16);
735
	bt_assert(192.160.0.0/17 !~ 192.168.0.0/16);
736
	bt_assert(px !~ netdoc);
737

    
738
	bt_assert(1.2.3.4 ~ 1.0.0.0/8);
739
	bt_assert(1.0.0.0/8 ~ 1.0.0.0/8);
740
}
741

    
742
bt_test_suite(t_prefix, "Testing prefixes");
743

    
744

    
745

    
746

    
747
/*
748
 *	Testing prefix sets
749
 *	-------------------
750
 */
751

    
752
define net10 = 10.0.0.0/8;
753
define pxs2 = [ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ];
754

    
755
function test_pxset(prefix set pxs)
756
{
757
	print pxs;
758

    
759
	bt_assert(net10  ~ pxs);
760
	bt_assert(10.0.0.0/10  ~ pxs);
761
	bt_assert(10.0.0.0/12 ~ pxs);
762
	bt_assert(20.0.0.0/24 ~ pxs);
763
	bt_assert(20.0.40.0/24 ~ pxs);
764
	bt_assert(20.0.0.0/26 ~ pxs);
765
	bt_assert(20.0.100.0/26 ~ pxs);
766
	bt_assert(20.0.0.0/28 ~ pxs);
767
	bt_assert(20.0.255.0/28 ~ pxs);
768

    
769
	bt_assert(10.0.0.0/7 !~ pxs);
770
	bt_assert(10.0.0.0/13 !~ pxs);
771
	bt_assert(10.0.0.0/16 !~ pxs);
772
	bt_assert(20.0.0.0/16 !~ pxs);
773
	bt_assert(20.0.0.0/23 !~ pxs);
774
	bt_assert(20.0.0.0/29 !~ pxs);
775
	bt_assert(11.0.0.0/10 !~ pxs);
776
	bt_assert(20.1.0.0/26 !~ pxs);
777

    
778
	bt_assert(1.0.0.0/8 ~ [ 1.0.0.0/8+ ]);
779
	bt_assert(1.0.0.0/9 !~ [ 1.0.0.0/8- ]);
780
	bt_assert(1.2.0.0/17 !~ [ 1.0.0.0/8{ 15 , 16 } ]);
781

    
782
	bt_assert([ 10.0.0.0/8{ 15 , 17 } ] = [ 10.0.0.0/8{ 15 , 17 } ]);
783
}
784

    
785
function t_prefix_sets()
786
prefix set pxs;
787
{
788
	pxs = [ 1.2.0.0/16, 1.4.0.0/16+];
789
	print "Testing prefix sets: ", pxs;
790
	bt_assert(1.2.0.0/16 ~ pxs);
791
	bt_assert(1.4.0.0/16 ~ pxs);
792
	bt_assert(1.4.0.0/18 ~ pxs);
793
	bt_assert(1.4.0.0/32 ~ pxs);
794
	bt_assert(1.1.0.0/16 !~ pxs);
795
	bt_assert(1.3.0.0/16 !~ pxs);
796
	bt_assert(1.2.0.0/15 !~ pxs);
797
	bt_assert(1.2.0.0/17 !~ pxs);
798
	bt_assert(1.2.0.0/32 !~ pxs);
799
	bt_assert(1.4.0.0/15 !~ pxs);
800

    
801
	test_pxset(pxs2);
802
	test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
803

    
804
	bt_assert(1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ]);
805
	bt_assert([ 10.0.0.0/8{ 15 , 17 } ] != [ 11.0.0.0/8{ 15 , 17 } ]);
806
}
807

    
808
bt_test_suite(t_prefix_sets, "Testing prefix sets");
809

    
810

    
811

    
812

    
813
/*
814
 * 	Testing IP sets
815
 * 	---------------
816
 */
817

    
818
define ip1222 = 1.2.2.2;
819

    
820
function t_ip_sets()
821
ip set ips;
822
{
823
	ips = [ 1.1.1.0 .. 1.1.1.255, ip1222];
824
	print "Testing IP sets: ", ips;
825
	bt_assert(1.1.1.0 ~ ips);
826
	bt_assert(1.1.1.100 ~ ips);
827
	bt_assert(1.2.2.2 ~ ips);
828
	bt_assert(1.1.0.255 !~ ips);
829
	bt_assert(1.1.2.0  !~ ips);
830
	bt_assert(1.2.2.3 !~ ips);
831
	bt_assert(192.168.1.1 !~ ips);
832
}
833

    
834
bt_test_suite(t_ip_sets, "Testing IP sets");
835

    
836

    
837

    
838

    
839
/*
840
 *	 Testing calling functions
841
 *	 -------------------------
842
 */
843

    
844
function callme(int arg1; int arg2)
845
int i;
846
{
847
	case arg1 {
848
	1, 42: return 42;
849
	else: return arg1 * arg2;
850
	}
851

    
852
	return 0;
853
}
854

    
855
function fifteen()
856
{
857
	return 15;
858
}
859

    
860
function t_call_function()
861
{
862
	bt_assert(fifteen() = 15);
863

    
864
	bt_assert(callme(1, 2) = 42);
865
	bt_assert(callme(42, 2) = 42);
866

    
867
	bt_assert(callme(2, 2) = 4);
868
	bt_assert(callme(3, 2) = 6);
869
	bt_assert(callme(4, 4) = 16);
870
	bt_assert(callme(7, 2) = 14);
871
}
872

    
873
bt_test_suite(t_call_function, "Testing calling functions");
874

    
875

    
876

    
877

    
878
/*
879
 * 	Test including another config file
880
 * 	----------------------------------
881
 */
882

    
883
function t_include()
884
int i;
885
{
886
  print "Testing include";
887
  i = 1;
888
  include "test.conf.inc";
889
  bt_assert(i = 42);
890
}
891

    
892
bt_test_suite(t_include, "Test including another config file");
893

    
894

    
895

    
896

    
897
/*
898
 *	Unused functions -- testing only parsing
899
 *	----------------------------------------
900
 */
901

    
902
function __test1()
903
{
904
	if source ~ [ RTS_BGP, RTS_STATIC ] then {
905
#		ospf_metric1 = 65535;
906
#		ospf_metric2 = 1000;
907
		ospf_tag = 0x12345678;
908
		accept;
909
	}
910
	reject;
911
}
912

    
913
function __test2()
914
{
915
	if source ~ [ RTS_BGP, RTS_STATIC ] then {
916
#		ospf_metric1 = 65535;
917
#		ospf_metric2 = 1000;
918
		ospf_tag = 0x12345678;
919
		accept;
920
	}
921
	reject;
922
}
923

    
924
filter testf
925
int j;
926
{
927
	print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
928
	print "This route was from ", from;
929
	j = 7;
930
	j = 17;
931
	if rip_metric > 15 then {
932
		reject "RIP Metric is more than infinity";
933
	}
934
	rip_metric = 14;
935
	unset(rip_metric);
936

    
937
	accept "ok I take that";
938
}
939

    
940
/*
941
roa table rl
942
{
943
	roa 10.110.0.0/16 max 16 as 1000;
944
	roa 10.120.0.0/16 max 24 as 1000;
945
	roa 10.130.0.0/16 max 24 as 2000;
946
	roa 10.130.128.0/18 max 24 as 3000;
947
}
948

    
949
function test_roa()
950
{
951
	# cannot be tested in __startup(), sorry
952
	print "Testing ROA";
953
	print "Should be true: ", roa_check(rl, 10.10.0.0/16, 1000) = ROA_UNKNOWN,
954
	      " ", roa_check(rl, 10.0.0.0/8, 1000) = ROA_UNKNOWN,
955
	      " ", roa_check(rl, 10.110.0.0/16, 1000) = ROA_VALID,
956
	      " ", roa_check(rl, 10.110.0.0/16, 2000) = ROA_INVALID,
957
	      " ", roa_check(rl, 10.110.32.0/20, 1000) = ROA_INVALID,
958
	      " ", roa_check(rl, 10.120.32.0/20, 1000) = ROA_VALID;
959
	print "Should be true: ", roa_check(rl, 10.120.32.0/20, 2000) = ROA_INVALID,
960
	      " ", roa_check(rl, 10.120.32.32/28, 1000) = ROA_INVALID,
961
	      " ", roa_check(rl, 10.130.130.0/24, 1000) = ROA_INVALID,
962
	      " ", roa_check(rl, 10.130.130.0/24, 2000) = ROA_VALID,
963
	      " ", roa_check(rl, 10.130.30.0/24, 3000) = ROA_INVALID,
964
	      " ", roa_check(rl, 10.130.130.0/24, 3000) = ROA_VALID;
965
}
966
*/