Statistics
| Branch: | Revision:

iof-bird / bird-2.0.1 / filter / test.conf @ 6b3f1a54

History | View | Annotate | Download (29.6 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 boolean expressions
33
 * 	---------------------------
34
 */
35

    
36
function t_bool()
37
bool b;
38
{
39
	b = true;
40
	bt_assert(b);
41
	bt_assert(!!b);
42

    
43
	bt_assert(format(true)  = "TRUE");
44
	bt_assert(format(false) = "FALSE");
45

    
46
	if ( b = true ) then
47
		bt_assert(b);
48
	else
49
		bt_assert(false);
50

    
51
	bt_assert(true && true);
52
	bt_assert(true || false);
53
	bt_assert(! false && ! false && true);
54
	bt_assert(1 < 2 && 1 != 3);
55
	bt_assert(true && true && ! false);
56
	bt_assert(true || 1+"a");
57
	bt_assert(!(false && 1+"a"));
58
	bt_assert(!(true && false));
59
}
60

    
61
bt_test_suite(t_bool, "Testing boolean expressions");
62

    
63

    
64

    
65

    
66
/*
67
 *	Testing integers
68
 *	----------------
69
 */
70

    
71
define four = 4;
72
define xyzzy = (120+10);
73
define '1a-a1' = (xyzzy-100);
74

    
75
function t_int()
76
int i;
77
{
78
	bt_assert(xyzzy = 130);
79
	bt_assert('1a-a1' = 30);
80

    
81
	i = four;
82
	i = 12*100 + 60/2 + i;
83
	i = (i + 0);
84
	bt_assert(i = 1234);
85

    
86
	bt_assert(format(i) = "1234");
87

    
88
	i = 4200000000;
89
	bt_assert(i = 4200000000);
90
	bt_assert(i > 4100000000);
91
	bt_assert(!(i > 4250000000));
92

    
93
	bt_assert(1 = 1);
94
	bt_assert(!(1 != 1));
95

    
96
	bt_assert(1 != 2);
97
	bt_assert(1 <= 2);
98

    
99
	bt_assert(1 != "a");
100
	bt_assert(1 != (0,1));
101

    
102
	bt_assert(!(i = 4));
103
	bt_assert(1 <= 1);
104
	bt_assert(!(1234 < 1234));
105
}
106

    
107
bt_test_suite(t_int, "Testing integers");
108

    
109

    
110

    
111

    
112
/*
113
 * 	Testing sets of integers
114
 * 	------------------------
115
 */
116

    
117
define is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
118
define is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
119
define is3 = [5, 17, 2, 11, 8, 15, 3, 19];
120

    
121
function t_int_set()
122
int set is;
123
{
124
	bt_assert(1 ~ [1,2,3]);
125
	bt_assert(5 ~ [1..20]);
126
	bt_assert(2 ~ [ 1, 2, 3 ]);
127
	bt_assert(5 ~ [ 4 .. 7 ]);
128
	bt_assert(1 !~ [ 2, 3, 4 ]);
129

    
130
	is = [ 2, 3, 4, 7..11 ];
131
	bt_assert(10 ~ is);
132
	bt_assert(5 !~ is);
133

    
134
	bt_assert(1 ~ is1);
135
	bt_assert(3 ~ is1);
136
	bt_assert(5 ~ is1);
137
	bt_assert((one+2) ~ is1);
138
	bt_assert(2 ~ is2);
139
	bt_assert(2 ~ is3);
140
	bt_assert(4 !~ is1);
141
	bt_assert(4 !~ is2);
142
	bt_assert(4 !~ is3);
143
	bt_assert(10 !~ is1);
144
	bt_assert(10 !~ is2);
145
	bt_assert(10 !~ is3);
146
	bt_assert(15 ~ is1);
147
	bt_assert(15 ~ is2);
148
	bt_assert(15 ~ is3);
149
	bt_assert(18 !~ is1);
150
	bt_assert(18 !~ is2);
151
	bt_assert(18 !~ is3);
152
	bt_assert(19 ~ is1);
153
	bt_assert(19 ~ is2);
154
	bt_assert(19 ~ is3);
155
	bt_assert(20 !~ is1);
156
	bt_assert(20 !~ is2);
157
	bt_assert(20 !~ is3);
158

    
159
	bt_assert([1,2] != [1,3]);
160
	bt_assert([1,4..10,20] = [1,4..10,20]);
161

    
162
	bt_assert(format([ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ]) = "[1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5]");
163
}
164

    
165
bt_test_suite(t_int_set, "Testing sets of integers");
166

    
167

    
168

    
169

    
170
/*
171
 * 	Testing string matching
172
 * 	-----------------------
173
 */
174

    
175
function t_string()
176
string st;
177
{
178
	st = "Hello";
179
	bt_assert(format(st) = "Hello");
180
	bt_assert(st ~ "Hell*");
181
	bt_assert(st ~ "?ello");
182
	bt_assert(st ~ "Hello");
183
	bt_assert(st ~ "Hell?");
184
	bt_assert(st !~ "ell*");
185
}
186

    
187
bt_test_suite(t_string, "Testing string matching");
188

    
189

    
190

    
191

    
192
/*
193
 * 	Testing pairs
194
 * 	-------------
195
 */
196

    
197
function 'mkpair-a'(int a)
198
{
199
	return (1, a);
200
}
201

    
202
function t_pair()
203
pair pp;
204
{
205
	pp = (1, 2);
206
	bt_assert(format(pp) = "(1,2)");
207
	bt_assert((1,2) = pp);
208
	bt_assert((1,1+1) = pp);
209
	bt_assert('mkpair-a'(2) = pp);
210
	bt_assert((1,2) = (1,1+1));
211
	bt_assert(((1,2) < (2,2)));
212
	bt_assert(!((1,1) > (1,1)));
213
}
214

    
215
bt_test_suite(t_pair, "Testing pairs");
216

    
217

    
218

    
219

    
220
/*
221
 * 	Testing sets of pairs
222
 * 	---------------------
223
 */
224

    
225
function t_pair_set()
226
pair pp;
227
pair set ps;
228
{
229
	pp = (1, 2);
230
	ps = [(1,(one+one)), (3,4)..(4,8), (5,*), (6,3..6)];
231
	bt_assert(format(ps) = "[(1,2), (3,4)..(4,8), (5,0)..(5,65535), (6,3)..(6,6)]");
232
	bt_assert(pp ~ ps);
233
	bt_assert((3,5) ~ ps);
234
	bt_assert((4,1) ~ ps);
235
	bt_assert((5,4) ~ ps);
236
	bt_assert((5,65535) ~ ps);
237
	bt_assert((6,4) ~ ps);
238
	bt_assert((3, 10000) ~ ps);
239
	bt_assert((3,3) !~ ps);
240
	bt_assert((4,9) !~ ps);
241
	bt_assert((4,65535) !~ ps);
242
	bt_assert((6,2) !~ ps);
243
	bt_assert((6,6+one) !~ ps);
244
	bt_assert(((one+6),2) !~ ps);
245
	bt_assert((1,1) !~ ps);
246

    
247
	ps = [(20..150, 200..300), (50100..50200, 1000..50000), (*, 5+5)];
248
	bt_assert((100,200) ~ ps);
249
	bt_assert((150,300) ~ ps);
250
	bt_assert((50180,1200) ~ ps);
251
	bt_assert((50110,49000) ~ ps);
252
	bt_assert((0,10) ~ ps);
253
	bt_assert((64000,10) ~ ps);
254
	bt_assert((20,199) !~ ps);
255
	bt_assert((151,250) !~ ps);
256
	bt_assert((50050,2000) !~ ps);
257
	bt_assert((50150,50050) !~ ps);
258
	bt_assert((10,9) !~ ps);
259
	bt_assert((65535,11) !~ ps);
260
}
261

    
262
bt_test_suite(t_pair_set, "Testing sets of pairs");
263

    
264

    
265

    
266

    
267
/*
268
 * 	Testing quads
269
 * 	-------------
270
 */
271

    
272
function t_quad()
273
quad qq;
274
{
275
	qq = 1.2.3.4;
276
	bt_assert(format(qq) = "1.2.3.4");
277
	bt_assert(qq = 1.2.3.4);
278
	bt_assert(qq != 4.3.2.1);
279
}
280

    
281
bt_test_suite(t_quad, "Testing quads");
282

    
283

    
284

    
285

    
286
/*
287
 * 	Testing sets of quads
288
 * 	---------------------
289
 */
290

    
291
function t_quad_set()
292
quad qq;
293
{
294
	qq = 1.2.3.4;
295
	bt_assert(qq ~ [1.2.3.4, 5.6.7.8]);
296
	bt_assert(qq !~ [1.2.1.1, 1.2.3.5]);
297
}
298

    
299
bt_test_suite(t_quad_set, "Testing sets of quads");
300

    
301

    
302

    
303

    
304
/*
305
 * 	Testing ip address
306
 * 	------------------
307
 */
308

    
309
define onetwo = 1.2.3.4;
310

    
311
function t_ip()
312
ip p;
313
{
314
	p = 127.1.2.3;
315
	bt_assert(p.is_v4);
316
	bt_assert(p.mask(8) = 127.0.0.0);
317
	bt_assert(1.2.3.4 = 1.2.3.4);
318
	bt_assert(1.2.3.4 = onetwo);
319
	bt_assert(format(p) = "127.1.2.3");
320

    
321
	p = ::fffe:6:c0c:936d:88c7:35d3;
322
	bt_assert(!p.is_v4);
323
	bt_assert(format(p) = "::fffe:6:c0c:936d:88c7:35d3");
324

    
325
	p = 1234:5678::;
326
	bt_assert(!p.is_v4);
327
	bt_assert(p.mask(24) = 1234:5600::);
328
}
329

    
330
bt_test_suite(t_ip, "Testing ip address");
331

    
332

    
333

    
334

    
335
/*
336
 * 	Testing sets of ip address
337
 * 	--------------------------
338
 */
339

    
340
define ip1222 = 1.2.2.2;
341

    
342
function t_ip_set()
343
ip set ips;
344
{
345
	ips = [ 1.1.1.0 .. 1.1.1.255, ip1222];
346
	bt_assert(format(ips) = "[1.1.1.0..1.1.1.255, 1.2.2.2]");
347
	bt_assert(1.1.1.0 ~ ips);
348
	bt_assert(1.1.1.100 ~ ips);
349
	bt_assert(1.2.2.2 ~ ips);
350
	bt_assert(1.1.0.255 !~ ips);
351
	bt_assert(1.1.2.0  !~ ips);
352
	bt_assert(1.2.2.3 !~ ips);
353
	bt_assert(192.168.1.1 !~ ips);
354

    
355
	bt_assert(1.2.3.4 !~ [ 1.2.3.3, 1.2.3.5 ]);
356
	bt_assert(1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ]);
357
}
358

    
359
bt_test_suite(t_ip_set, "Testing sets of ip address");
360

    
361

    
362

    
363

    
364
/*
365
 *	Testing enums
366
 *	-------------
367
 */
368

    
369
function t_enum()
370
{
371
	bt_assert(format(RTS_DUMMY)  = "(enum 30)0");
372
	bt_assert(format(RTS_STATIC) = "(enum 30)1");
373
	bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
374
	bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
375
}
376

    
377
bt_test_suite(t_enum, "Testing enums");
378

    
379

    
380

    
381

    
382
/*
383
 * 	Testing prefixes
384
 * 	----------------
385
 */
386

    
387
define netdoc = 2001:db8::/32;
388

    
389
function t_prefix()
390
prefix px;
391
{
392
	px = 1.2.0.0/18;
393
	bt_assert(format(px) = "1.2.0.0/18");
394
	bt_assert(192.168.0.0/16 ~ 192.168.0.0/16);
395
	bt_assert(192.168.0.0/17 ~ 192.168.0.0/16);
396
	bt_assert(192.168.254.0/24 ~ 192.168.0.0/16);
397
	bt_assert(netdoc ~ 2001::/16);
398
	bt_assert(192.168.0.0/15 !~ 192.168.0.0/16);
399
	bt_assert(192.160.0.0/17 !~ 192.168.0.0/16);
400
	bt_assert(px !~ netdoc);
401

    
402
	bt_assert(1.2.3.4 ~ 1.0.0.0/8);
403
	bt_assert(1.0.0.0/8 ~ 1.0.0.0/8);
404
}
405

    
406
bt_test_suite(t_prefix, "Testing prefixes");
407

    
408

    
409

    
410

    
411
/*
412
 *	Testing prefix sets
413
 *	-------------------
414
 */
415

    
416
define net10 = 10.0.0.0/8;
417
define pxs2 = [ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ];
418

    
419
function test_pxset(prefix set pxs)
420
{
421
	bt_assert(net10  ~ pxs);
422
	bt_assert(10.0.0.0/10  ~ pxs);
423
	bt_assert(10.0.0.0/12 ~ pxs);
424
	bt_assert(20.0.0.0/24 ~ pxs);
425
	bt_assert(20.0.40.0/24 ~ pxs);
426
	bt_assert(20.0.0.0/26 ~ pxs);
427
	bt_assert(20.0.100.0/26 ~ pxs);
428
	bt_assert(20.0.0.0/28 ~ pxs);
429
	bt_assert(20.0.255.0/28 ~ pxs);
430

    
431
	bt_assert(10.0.0.0/7 !~ pxs);
432
	bt_assert(10.0.0.0/13 !~ pxs);
433
	bt_assert(10.0.0.0/16 !~ pxs);
434
	bt_assert(20.0.0.0/16 !~ pxs);
435
	bt_assert(20.0.0.0/23 !~ pxs);
436
	bt_assert(20.0.0.0/29 !~ pxs);
437
	bt_assert(11.0.0.0/10 !~ pxs);
438
	bt_assert(20.1.0.0/26 !~ pxs);
439

    
440
	bt_assert(1.0.0.0/8 ~ [ 1.0.0.0/8+ ]);
441
	bt_assert(1.0.0.0/9 !~ [ 1.0.0.0/8- ]);
442
	bt_assert(1.2.0.0/17 !~ [ 1.0.0.0/8{ 15 , 16 } ]);
443

    
444
	bt_assert([ 10.0.0.0/8{ 15 , 17 } ] = [ 10.0.0.0/8{ 15 , 17 } ]);
445
}
446

    
447
function t_prefix_set()
448
prefix set pxs;
449
{
450
	pxs = [ 1.2.0.0/16, 1.4.0.0/16+, 44.66.88.64/30{24,28}, 12.34.56.0/24{8,16} ];
451
	bt_assert(format(pxs) = "[1.2.0.0/112{::0.1.0.0}, 1.4.0.0/112{::0.1.255.255}, 12.34.0.0/112{::1.255.0.0}, 44.66.88.64/124{::1f0}]");
452
	bt_assert(1.2.0.0/16 ~ pxs);
453
	bt_assert(1.4.0.0/16 ~ pxs);
454
	bt_assert(1.4.0.0/18 ~ pxs);
455
	bt_assert(1.4.0.0/32 ~ pxs);
456
	bt_assert(1.1.0.0/16 !~ pxs);
457
	bt_assert(1.3.0.0/16 !~ pxs);
458
	bt_assert(1.2.0.0/15 !~ pxs);
459
	bt_assert(1.2.0.0/17 !~ pxs);
460
	bt_assert(1.2.0.0/32 !~ pxs);
461
	bt_assert(1.4.0.0/15 !~ pxs);
462

    
463
	test_pxset(pxs2);
464
	test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
465

    
466
	bt_assert(1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ]);
467
	bt_assert([ 10.0.0.0/8{ 15 , 17 } ] != [ 11.0.0.0/8{ 15 , 17 } ]);
468
}
469

    
470
bt_test_suite(t_prefix_set, "Testing prefix sets");
471

    
472

    
473

    
474

    
475
/*
476
 * 	Testing Prefix IPv6
477
 * 	-------------------
478
 */
479

    
480
function t_prefix6()
481
prefix px;
482
{
483
	px = 1020::/18;
484
	bt_assert(format(px) = "1020::/18");
485
	bt_assert(1020:3040:5060:: ~ 1020:3040:5000::/40);
486
	bt_assert(1020:3040::/32 ~ 1020:3040::/32);
487
	bt_assert(1020:3040::/33 ~ 1020:3040::/32);
488
	bt_assert(1020:3040:5060::/48 ~ 1020:3040::/32);
489
	bt_assert(1020:3040::/31 !~ 1020:3040::/32);
490
	bt_assert(1020:3041::/33 !~ 1020:3040::/32);
491
}
492

    
493
bt_test_suite(t_prefix6, "Testing prefix IPv6");
494

    
495

    
496

    
497

    
498
/*
499
 *	Testing prefix IPv6 sets
500
 *	------------------------
501
 */
502

    
503
function t_prefix6_set()
504
prefix set pxs;
505
{
506
	bt_assert(1180::/16 ~ [ 1100::/8{15, 17} ]);
507
	bt_assert(12::34 = 12::34);
508
	bt_assert(12::34 ~ [ 12::33..12::35 ]);
509
	bt_assert(1020::34 ~ 1000::/8);
510
	bt_assert(1000::/8 ~ 1000::/8);
511
	bt_assert(1000::/8 ~ [ 1000::/8+ ]);
512
	bt_assert(12::34 !~ [ 12::33, 12::35 ]);
513
	bt_assert(1000::/9 !~ [ 1000::/8- ]);
514
	bt_assert(1000::/17 !~ [ 1000::/8{15, 16} ]);
515

    
516
	pxs = [ 1102::/16, 1104::/16+];
517
	bt_assert(1102::/16  ~ pxs);
518
	bt_assert(1104::/16  ~ pxs);
519
	bt_assert(1104::/18  ~ pxs);
520
	bt_assert(1104::/32  ~ pxs);
521
	bt_assert(1101::/16 !~ pxs);
522
	bt_assert(1103::/16 !~ pxs);
523
	bt_assert(1102::/15 !~ pxs);
524
	bt_assert(1102::/17 !~ pxs);
525
	bt_assert(1102::/32 !~ pxs);
526
	bt_assert(1104::/15 !~ pxs);
527

    
528
	pxs = ([ 1000::/16{8,12}, 2000::/16{24,28} ]);
529
	bt_assert(format(pxs) = "[1000::/12{1f0::}, 2000::/16{0:1f0::}]");
530
	bt_assert(1000::/8  ~ pxs);
531
	bt_assert(1000::/10 ~ pxs);
532
	bt_assert(1000::/12 ~ pxs);
533
	bt_assert(2000::/24 ~ pxs);
534
	bt_assert(2000:4000::/24 ~ pxs);
535
	bt_assert(2000::/26 ~ pxs);
536
	bt_assert(2000:8000::/26 ~ pxs);
537
	bt_assert(2000::/28 ~ pxs);
538
	bt_assert(2000:FFF0::/28 ~ pxs);
539
	bt_assert(1000::/7  !~ pxs);
540
	bt_assert(1000::/13 !~ pxs);
541
	bt_assert(1000::/16 !~ pxs);
542
	bt_assert(2000::/16 !~ pxs);
543
	bt_assert(2000::/23 !~ pxs);
544
	bt_assert(2000::/29 !~ pxs);
545
	bt_assert(1100::/10 !~ pxs);
546
	bt_assert(2010::/26 !~ pxs);
547
}
548

    
549
bt_test_suite(t_prefix6_set, "Testing prefix IPv6 sets");
550

    
551

    
552

    
553

    
554
function t_flowspec()
555
prefix p;
556
{
557
	p = flow4 { dst 10.0.0.0/8; };
558
	bt_assert(p !~ [ 10.0.0.0/8 ] );
559

    
560
	bt_assert(format(flow4 { dst 10.0.0.0/8; proto = 23; }) = "flow4 { dst 10.0.0.0/8; proto 23; }");
561
	bt_assert(format(flow6 { dst ::1/128; src ::2/127; }) = "flow6 { dst ::1/128; src ::2/127; }");
562
	bt_assert(format(flow6 { next header false 42; }) = "flow6 { next header false 42; }");
563
	bt_assert(format(flow6 { port 80; }) = "flow6 { port 80; }");
564
	bt_assert(format(flow6 { dport > 24 && < 30 || 40..50,60..70,80 && >= 90; }) = "flow6 { dport > 24 && < 30 || 40..50,60..70,80 && >= 90; }");
565
	bt_assert(format(flow6 { sport 0..0x400; }) = "flow6 { sport 0..1024; }");
566
	bt_assert(format(flow6 { icmp type 80; }) = "flow6 { icmp type 80; }");
567
	bt_assert(format(flow6 { icmp code 90; }) = "flow6 { icmp code 90; }");
568
	bt_assert(format(flow6 { tcp flags 0x03/0x0f; }) = "flow6 { tcp flags 0x3/0x3,0x0/0xc; }");
569
	bt_assert(format(flow6 { length 0..65535; }) = "flow6 { length 0..65535; }");
570
	bt_assert(format(flow6 { dscp = 63; }) = "flow6 { dscp 63; }");
571
	bt_assert(format(flow6 { fragment is_fragment || !first_fragment; }) = "flow6 { fragment is_fragment || !first_fragment; }");
572
	bt_assert(format(flow6 { }) = "flow6 { }");
573
}
574

    
575
bt_test_suite(t_flowspec, "Testing flowspec routes");
576

    
577

    
578

    
579

    
580
/*
581
 * 	Testing Paths
582
 * 	-------------
583
 */
584

    
585
function mkpath(int a; int b)
586
{
587
	return [= a b 3 2 1 =];
588
}
589

    
590
function t_path()
591
bgpmask pm1;
592
bgppath p2;
593
{
594
	pm1 = [= 4 3 2 1 =];
595

    
596
	bt_assert(format(pm1) = "[= 4 3 2 1 =]");
597

    
598
	bt_assert(+empty+ = +empty+);
599
	bt_assert(10 !~ +empty+);
600

    
601
	p2 = prepend( + empty +, 1 );
602
	p2 = prepend( p2, 2 );
603
	p2 = prepend( p2, 3 );
604
	p2 = prepend( p2, 4 );
605

    
606
	bt_assert(format(p2) = "(path 4 3 2 1)");
607
	bt_assert(p2.len = 4);
608
	bt_assert(p2 ~ pm1);
609
	bt_assert(3 ~ p2);
610
	bt_assert(p2 ~ [2, 10..20]);
611
	bt_assert(p2 ~ [4, 10..20]);
612

    
613
	p2 = prepend(p2, 5);
614
	bt_assert(p2 !~ pm1);
615
	bt_assert(10 !~ p2);
616
	bt_assert(p2 !~ [8, ten..(2*ten)]);
617
	bt_assert(p2 ~ [= * 4 3 * 1 =]);
618
	bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
619
	bt_assert(p2 ~ mkpath(5, 4));
620

    
621
	bt_assert(p2.len = 5);
622
	bt_assert(p2.first = 5);
623
	bt_assert(p2.last = 1);
624

    
625
	bt_assert(p2.len = 5);
626
	bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
627
	bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
628

    
629
	pm1 = [= 1 2 * 3 4 5 =];
630
	p2 = prepend( + empty +, 5 );
631
	p2 = prepend( p2, 4 );
632
	p2 = prepend( p2, 3 );
633
	p2 = prepend( p2, 3 );
634
	p2 = prepend( p2, 2 );
635
	p2 = prepend( p2, 1 );
636

    
637
	bt_assert(p2 ~ pm1);
638
	bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
639
	bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
640
}
641

    
642
bt_test_suite(t_path, "Testing paths");
643

    
644

    
645

    
646

    
647
/*
648
 * 	Testing Community List
649
 *	----------------------
650
 */
651

    
652
define p23 = (2, 3);
653

    
654
function t_clist()
655
clist l;
656
clist l2;
657
clist r;
658
{
659
	l = - empty -;
660
	bt_assert(l !~ [(*,*)]);
661
	bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
662

    
663
	bt_assert(-empty- = -empty-);
664

    
665
	l = add( l, (one,2) );
666
	bt_assert(l ~ [(*,*)]);
667
	l = add( l, (2,one+2) );
668
	bt_assert(format(l) = "(clist (1,2) (2,3))");
669

    
670
	bt_assert((2,3) ~ l);
671
	bt_assert(l ~ [(1,*)]);
672
	bt_assert(l ~ [p23]);
673
	bt_assert(l ~ [(2,2..3)]);
674
	bt_assert(l ~ [(1,1..2)]);
675
	bt_assert(l ~ [(1,1)..(1,2)]);
676

    
677
	l = add(l, (2,5));
678
	l = add(l, (5,one));
679
	l = add(l, (6,one));
680
	l = add(l, (one,one));
681
	l = delete(l, [(5,1),(6,one),(one,1)]);
682
	l = delete(l, [(5,one),(6,one)]);
683
	l = filter(l, [(1,*)]);
684
	bt_assert(l = add(-empty-, (1,2)));
685

    
686
	bt_assert((2,3) !~ l);
687
	bt_assert(l !~ [(2,*)]);
688
	bt_assert(l !~ [(one,3..6)]);
689
	bt_assert(l ~ [(*,*)]);
690

    
691
	l = add(l, (3,one));
692
	l = add(l, (one+one+one,one+one));
693
	l = add(l, (3,3));
694
	l = add(l, (3,4));
695
	l = add(l, (3,5));
696
	l2 = filter(l, [(3,*)]);
697
	l = delete(l, [(3,2..4)]);
698
	bt_assert(l = add(add(add(-empty-, (1,2)), (3,1)), (3,5)));
699
	bt_assert(l.len = 3);
700

    
701
	l = add(l, (3,2));
702
	l = add(l, (4,5));
703
	bt_assert(l = add(add(add(add(add(-empty-, (1,2)), (3,1)), (3,5)), (3,2)), (4,5)));
704

    
705
	bt_assert(l.len = 5);
706
	bt_assert(l ~ [(*,2)]);
707
	bt_assert(l ~ [(*,5)]);
708
	bt_assert(l ~ [(*, one)]);
709
	bt_assert(l !~ [(*,3)]);
710
	bt_assert(l !~ [(*,(one+6))]);
711
	bt_assert(l !~ [(*, (one+one+one))]);
712

    
713
	l = delete(l, [(*,(one+onef(3)))]);
714
	l = delete(l, [(*,(4+one))]);
715
	bt_assert(l = add(-empty-, (3,1)));
716

    
717
	l = delete(l, [(*,(onef(5)))]);
718
	bt_assert(l = -empty-);
719

    
720
	l2 = add(l2, (3,6));
721
	l = filter(l2, [(3,1..4)]);
722
	l2 = filter(l2, [(3,3..6)]);
723

    
724
	#  clist A (10,20,30)
725
	bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
726
	bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))");
727

    
728
	#  clist B (30,40,50)
729
	bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
730
	bt_assert(format(l2) = "(clist (3,3) (3,4) (3,5) (3,6))");
731

    
732
	#  clist A union B
733
	r = add(l, l2);
734
	bt_assert(r = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
735
	bt_assert(format(r) = "(clist (3,1) (3,2) (3,3) (3,4) (3,5) (3,6))");
736

    
737
	#  clist A isect B
738
	r = filter(l, l2);
739
	bt_assert(r = add(add(-empty-, (3,3)), (3,4)));
740
	bt_assert(format(r) = "(clist (3,3) (3,4))");
741

    
742
	#  clist A \ B
743
	r = delete(l, l2);
744
	bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
745
	bt_assert(format(r) = "(clist (3,1) (3,2))");
746

    
747
	#  clist in c set
748
	r = filter(l, [(3,1), (*,2)]);
749
	bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
750
	bt_assert(format(r) = "(clist (3,1) (3,2))");
751
}
752

    
753
bt_test_suite(t_clist, "Testing lists of communities");
754

    
755

    
756

    
757

    
758
/*
759
 * 	Testing Extended Communities
760
 * 	----------------------------
761
 */
762

    
763
function t_ec()
764
ec cc;
765
{
766
	cc = (rt, 12345, 200000);
767
	bt_assert(format(cc) = "(rt, 12345, 200000)");
768

    
769
	bt_assert(cc = (rt, 12345, 200000));
770
	bt_assert(cc < (rt, 12345, 200010));
771
	bt_assert(cc != (rt, 12346, 200000));
772
	bt_assert(cc != (ro, 12345, 200000));
773
	bt_assert(!(cc > (rt, 12345, 200010)));
774

    
775
	bt_assert(format((ro, 100000, 20000)) = "(ro, 100000, 20000)");
776
}
777

    
778
bt_test_suite(t_ec, "Testing extended communities");
779

    
780

    
781

    
782

    
783
/*
784
 * 	Testing Extended Community List
785
 * 	-------------------------------
786
 */
787

    
788
function t_eclist()
789
eclist el;
790
eclist el2;
791
eclist r;
792
{
793
	el = -- empty --;
794
	el = add(el, (rt, 10, 20));
795
	el = add(el, (ro, 10.20.30.40, 100));
796
	el = add(el, (ro, 11.21.31.41.mask(16), 200));
797

    
798
	bt_assert(--empty-- = --empty--);
799
	bt_assert(((rt, 10, 20)) !~ --empty--);
800

    
801
	bt_assert(format(el) = "(eclist (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200))");
802
	bt_assert(el.len = 3);
803
	el = delete(el, (rt, 10, 20));
804
	el = delete(el, (rt, 10, 30));
805
	bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
806
	el = add(el, (unknown 2, ten, 1));
807
	el = add(el, (unknown 5, ten, 1));
808
	el = add(el, (rt, ten, one+one));
809
	el = add(el, (rt, 10, 3));
810
	el = add(el, (rt, 10, 4));
811
	el = add(el, (rt, 10, 5));
812
	el = add(el, (generic, 0x2000a, 3*ten));
813
	el = delete(el, [(rt, 10, 2..ten)]);
814
	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)));
815

    
816
	el = filter(el, [(rt, 10, *)]);
817
	bt_assert(el = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
818
	bt_assert((rt, 10, 1) ~ el);
819
	bt_assert(el ~ [(rt, 10, ten..40)]);
820
	bt_assert((rt, 10, 20) !~ el);
821
	bt_assert((ro, 10.20.30.40, 100) !~ el);
822
	bt_assert(el !~ [(rt, 10, 35..40)]);
823
	bt_assert(el !~ [(ro, 10, *)]);
824

    
825
	el = add(el, (rt, 10, 40));
826
	el2 = filter(el, [(rt, 10, 20..40)] );
827
	el2 = add(el2, (rt, 10, 50));
828

    
829
	#  eclist A (1,30,40)
830
	bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
831
	bt_assert(format(el) = "(eclist (rt, 10, 1) (rt, 10, 30) (rt, 10, 40))");
832

    
833
	#  eclist B (30,40,50)
834
	bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
835
	bt_assert(format(el2) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50))");
836

    
837
	#  eclist A union B
838
	r = add(el2, el);
839
	bt_assert(r = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
840
	bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50) (rt, 10, 1))");
841

    
842
	#  eclist A isect B
843
	r = filter(el, el2);
844
	bt_assert(r = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
845
	bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40))");
846

    
847
	#  eclist A \ B
848
	r = delete(el, el2);
849
	bt_assert(r = add(--empty--, (rt, 10, 1)));
850
	bt_assert(format(r) = "(eclist (rt, 10, 1))");
851

    
852
	#  eclist in ec set
853
	r = filter(el, [(rt, 10, 1), (rt, 10, 25..30), (ro, 10, 40)]);
854
	bt_assert(r = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
855
	bt_assert(format(r) = "(eclist (rt, 10, 1) (rt, 10, 30))");
856
}
857

    
858
bt_test_suite(t_eclist, "Testing lists of extended communities");
859

    
860

    
861

    
862

    
863
/*
864
 * 	Testing sets of Extended Communities
865
 * 	------------------------------------
866
 */
867

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

    
870
function t_ec_set()
871
ec set ecs;
872
{
873
	ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
874
	bt_assert(format(ecs)  = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
875
	bt_assert(format(ecs2) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
876

    
877
	bt_assert((rt, 10, 20) ~ ecs);
878
	bt_assert((ro, 100000, 100) ~ ecs);
879
	bt_assert((ro, 100000, 128) ~ ecs);
880
	bt_assert((ro, 100000, 200) ~ ecs);
881
	bt_assert((rt, 12345, 0) ~ ecs);
882
	bt_assert((rt, 12345, 200000) ~ ecs);
883
	bt_assert((rt, 12345, 4000000) ~ ecs);
884
	bt_assert((ro, 10, 20) !~ ecs);
885
	bt_assert((rt, 10, 21) !~ ecs);
886
	bt_assert((ro, 100000, 99) !~ ecs);
887
	bt_assert((ro, 12345, 10) !~ ecs);
888
	bt_assert((rt, 12346, 0) !~ ecs);
889
	bt_assert((ro, 0.1.134.160, 150) !~ ecs);
890
}
891

    
892
bt_test_suite(t_ec_set, "Testing sets of extended communities");
893

    
894

    
895

    
896

    
897
/*
898
 * 	Testing Large Communities
899
 * 	-------------------------
900
 */
901

    
902
function mktrip(int a)
903
{
904
	return (a, 2*a, 3*a);
905
}
906

    
907
function t_lclist()
908
lclist ll;
909
lclist ll2;
910
lclist r;
911
{
912
	bt_assert(---empty--- = ---empty---);
913
	bt_assert((10, 20, 30) !~ ---empty---);
914

    
915
	ll = --- empty ---;
916
	ll = add(ll, (ten, 20, 30));
917
	ll = add(ll, (1000, 2000, 3000));
918
	ll = add(ll, mktrip(100000));
919
	bt_assert(format(ll) = "(lclist (10, 20, 30) (1000, 2000, 3000) (100000, 200000, 300000))");
920
	bt_assert(ll.len = 3);
921
	bt_assert(ll = add(add(add(---empty---, (10, 20, 30)), (1000, 2000, 3000)), (100000, 200000, 300000)));
922

    
923
	bt_assert(mktrip(1000) ~ ll);
924
	bt_assert(mktrip(100) !~ ll);
925

    
926
	ll = --- empty ---;
927
	ll = add(ll, (10, 10, 10));
928
	ll = add(ll, (20, 20, 20));
929
	ll = add(ll, (30, 30, 30));
930

    
931
	ll2 = --- empty ---;
932
	ll2 = add(ll2, (20, 20, 20));
933
	ll2 = add(ll2, (30, 30, 30));
934
	ll2 = add(ll2, (40, 40, 40));
935

    
936
	#  lclist A (10, 20, 30)
937
	bt_assert(format(ll) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30))");
938

    
939
	#  lclist B (20, 30, 40)
940
	bt_assert(format(ll2) = "(lclist (20, 20, 20) (30, 30, 30) (40, 40, 40))");
941

    
942
	#  lclist A union B
943
	r = add(ll, ll2);
944
	bt_assert(r = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));
945
	bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30) (40, 40, 40))");
946

    
947
	#  lclist A isect B
948
	r = filter(ll, ll2);
949
	bt_assert(r = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));
950
	bt_assert(format(r) = "(lclist (20, 20, 20) (30, 30, 30))");
951

    
952
	#  lclist A \ B
953
	r = delete(ll, ll2);
954
	bt_assert(r = add(---empty---, (10, 10, 10)));
955
	bt_assert(format(r) = "(lclist (10, 10, 10))");
956

    
957
	#  lclist in lc set
958
	r = filter(ll, [(5..15, *, *), (20, 15..25, *)]);
959
	bt_assert(r = add(add(---empty---, (10, 10, 10)), (20, 20, 20)));
960
	bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20))");
961
}
962

    
963
bt_test_suite(t_lclist, "Testing lists of large communities");
964

    
965

    
966

    
967

    
968
/*
969
 * 	Testing sets of Large Communities
970
 * 	---------------------------------
971
 */
972

    
973
function t_lclist_set()
974
lclist ll;
975
lc set lls;
976
{
977
	ll = --- empty ---;
978
	ll = add(ll, (10, 20, 30));
979
	ll = add(ll, (1000, 2000, 3000));
980
	ll = add(ll, mktrip(100000));
981

    
982
	bt_assert(ll ~ [(5,10,15), (10,20,30)]);
983
	bt_assert(ll ~ [(10,15..25,*)]);
984
	bt_assert(ll ~ [(ten, *, *)]);
985

    
986
	bt_assert(ll !~ [(5,10,15), (10,21,30)]);
987
	bt_assert(ll !~ [(10,21..25,*)]);
988
	bt_assert(ll !~ [(11, *, *)]);
989

    
990
	lls = [(10, 10, 10), (20, 20, 15..25), (30, 30, *), (40, 35..45, *), (50, *, *), (55..65, *, *)];
991
	bt_assert(format(lls) = "[(10, 10, 10), (20, 20, 15)..(20, 20, 25), (30, 30, 0)..(30, 30, 4294967295), (40, 35, 0)..(40, 45, 4294967295), (50, 0, 0)..(50, 4294967295, 4294967295), (55, 0, 0)..(65, 4294967295, 4294967295)]");
992
	bt_assert((10, 10, 10)  ~ lls);
993
	bt_assert((20, 20, 25)  ~ lls);
994
	bt_assert((20, 20, 26) !~ lls);
995
	bt_assert((30, 30,  0)  ~ lls);
996
	bt_assert((40, 35, 40)  ~ lls);
997
	bt_assert((40, 34, 40) !~ lls);
998
	bt_assert((50,  0,  0)  ~ lls);
999
	bt_assert((60, 60, 60)  ~ lls);
1000
	bt_assert((70, 60, 60) !~ lls);
1001
}
1002

    
1003
bt_test_suite(t_lclist_set, "Testing sets of large communities");
1004

    
1005

    
1006

    
1007

    
1008
/*
1009
 * 	Testing defined() function
1010
 * 	--------------------------
1011
 */
1012

    
1013
function test_undef(int a)
1014
int b;
1015
{
1016
	if a = 3 then {
1017
		b = 4;
1018
		bt_assert(defined(b));
1019
	}
1020
	else {
1021
		bt_assert(!defined(b));
1022
	}
1023
}
1024

    
1025
function t_define()
1026
int i;
1027
{
1028
	test_undef(2);
1029
	test_undef(3);
1030
	test_undef(2);
1031

    
1032
	bt_assert(defined(1));
1033
	bt_assert(defined(1.2.3.4));
1034
}
1035

    
1036
bt_test_suite(t_define, "Testing defined() function");
1037

    
1038

    
1039

    
1040

    
1041
/*
1042
 *	 Testing calling functions
1043
 *	 -------------------------
1044
 */
1045

    
1046
function callme(int arg1; int arg2)
1047
int i;
1048
{
1049
	case arg1 {
1050
	1, 42: return 42;
1051
	else: return arg1 * arg2;
1052
	}
1053

    
1054
	return 0;
1055
}
1056

    
1057
function fifteen()
1058
{
1059
	return 15;
1060
}
1061

    
1062
function t_call_function()
1063
{
1064
	bt_assert(fifteen() = 15);
1065

    
1066
	bt_assert(callme(1, 2) = 42);
1067
	bt_assert(callme(42, 2) = 42);
1068

    
1069
	bt_assert(callme(2, 2) = 4);
1070
	bt_assert(callme(3, 2) = 6);
1071
	bt_assert(callme(4, 4) = 16);
1072
	bt_assert(callme(7, 2) = 14);
1073
}
1074

    
1075
bt_test_suite(t_call_function, "Testing calling functions");
1076

    
1077

    
1078

    
1079

    
1080
/*
1081
 * 	Test including another config file
1082
 * 	----------------------------------
1083
 */
1084

    
1085
function t_include()
1086
int i;
1087
{
1088
  i = 1;
1089
  include "test.conf.inc";
1090
  bt_assert(i = 42);
1091
}
1092

    
1093
bt_test_suite(t_include, "Testing including another config file");
1094

    
1095

    
1096

    
1097

    
1098
/*
1099
 * 	Test if-else statement
1100
 * 	----------------------
1101
 */
1102

    
1103
function t_if_else()
1104
int i;
1105
{
1106
	if true then
1107
		bt_assert(true);
1108

    
1109
	if false then
1110
		bt_assert(false);
1111
	else if true then
1112
		bt_assert(true);
1113
	else
1114
		bt_assert(false);
1115
}
1116

    
1117
bt_test_suite(t_if_else, "Testing if-else statement");
1118

    
1119

    
1120

    
1121

    
1122
/*
1123
 *	Unused functions -- testing only parsing
1124
 *	----------------------------------------
1125
 */
1126

    
1127
function __test1()
1128
{
1129
	if source ~ [ RTS_BGP, RTS_STATIC ] then {
1130
#		ospf_metric1 = 65535;
1131
#		ospf_metric2 = 1000;
1132
		ospf_tag = 0x12345678;
1133
		accept;
1134
	}
1135
	reject;
1136
}
1137

    
1138
function __test2()
1139
{
1140
	if source ~ [ RTS_BGP, RTS_STATIC ] then {
1141
#		ospf_metric1 = 65535;
1142
#		ospf_metric2 = 1000;
1143
		ospf_tag = 0x12345678;
1144
		accept;
1145
	}
1146
	reject;
1147
}
1148

    
1149
filter testf
1150
int j;
1151
{
1152
	print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
1153
	print "This route was from ", from;
1154
	j = 7;
1155
	j = 17;
1156
	if rip_metric > 15 then {
1157
		reject "RIP Metric is more than infinity";
1158
	}
1159
	rip_metric = 14;
1160
	unset(rip_metric);
1161

    
1162
	accept "ok I take that";
1163
}
1164

    
1165
filter roa_filter
1166
{
1167
	if net ~ [ 10.0.0.0/8{16,24}, 2000::/3{16,96} ] then {
1168
		accept;
1169
	}
1170
	reject;
1171
}
1172

    
1173
roa4 table r4;
1174
roa6 table r6;
1175

    
1176
protocol static
1177
{
1178
	roa4 { table r4; import filter roa_filter; };
1179
	route 10.110.0.0/16 max 16 as 1000;
1180
	route 10.120.0.0/16 max 24 as 1000;
1181
	route 10.130.0.0/16 max 24 as 2000;
1182
	route 10.130.128.0/18 max 24 as 3000;
1183
}
1184

    
1185
protocol static
1186
{
1187
  roa6 { table r6; import filter roa_filter; };
1188
  route 2001:0db8:85a3:8a2e::/64 max 96 as 1000;
1189
}
1190

    
1191
function test_roa_check()
1192
prefix pfx;
1193
{
1194
	# cannot be tested in __startup(), sorry
1195
	bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
1196
	bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
1197
	bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
1198
	bt_assert(roa_check(r4, 10.110.0.0/16, 2000) = ROA_INVALID);
1199
	bt_assert(roa_check(r4, 10.110.32.0/20, 1000) = ROA_INVALID);
1200
	bt_assert(roa_check(r4, 10.120.32.0/20, 1000) = ROA_VALID);
1201
	bt_assert(roa_check(r4, 10.120.32.0/20, 2000) = ROA_INVALID);
1202
	bt_assert(roa_check(r4, 10.120.32.32/28, 1000) = ROA_INVALID);
1203
	bt_assert(roa_check(r4, 10.130.130.0/24, 1000) = ROA_INVALID);
1204
	bt_assert(roa_check(r4, 10.130.130.0/24, 2000) = ROA_VALID);
1205
	bt_assert(roa_check(r4, 10.130.30.0/24, 3000) = ROA_INVALID);
1206
	bt_assert(roa_check(r4, 10.130.130.0/24, 3000) = ROA_VALID);
1207

    
1208
	bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1209
	bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1210
	bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e::/64, 1000) = ROA_VALID);
1211
	bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1212

    
1213
	bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
1214
	bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
1215
	bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
1216
	bt_assert(roa_check(r4, 10.110.0.0/16, 2000) = ROA_INVALID);
1217
	bt_assert(roa_check(r4, 10.110.32.0/20, 1000) = ROA_INVALID);
1218
	bt_assert(roa_check(r4, 10.120.32.0/20, 1000) = ROA_VALID);
1219

    
1220
	bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1221
	bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1222
	bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e::/64, 1000) = ROA_VALID);
1223
	bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1224

    
1225
	bt_assert(roa_check(r4, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_UNKNOWN);
1226
	bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1227

    
1228
	bt_assert(roa_check(r4, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_UNKNOWN);
1229
	bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1230
	bt_assert(roa_check(r4, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1231
	bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1232

    
1233
	bt_assert(10.130.130.0/24 ~ 0.0.0.0/0);
1234
	bt_assert(2001:0db8:85a3:8a2e::/64 ~ ::/0);
1235
	bt_assert(10.130.130.0/24 !~ ::/0);
1236
	bt_assert(2001:0db8:85a3:8a2e::/64 !~ 0.0.0.0/0);
1237

    
1238
	pfx = 12.13.0.0/16 max 24 as 1234;
1239
	bt_assert(pfx.len = 16);
1240
	bt_assert(pfx.maxlen = 24);
1241
	bt_assert(pfx.asn = 1234);
1242

    
1243
	pfx = 1000::/8 max 32 as 1234;
1244
	bt_assert(pfx.len = 8);
1245
	bt_assert(pfx.maxlen = 32);
1246
	bt_assert(pfx.asn = 1234);
1247
}
1248

    
1249
bt_test_suite(test_roa_check, "Testing ROA");
1250

    
1251
/*
1252
 *      Testing Mixed Net Types
1253
 *      -----------------------
1254
 */
1255

    
1256
function t_mixed_prefix()
1257
prefix set pxs;
1258
prefix set pxt;
1259
{
1260
	pxs = [ 98.45.0.0/16, 128.128.0.0/12+, 2200::/42-, ::ffff:d000:0/100{98,102}];
1261
	bt_assert(format(pxs) = "[::/0, ::/2{c000::}, 98.45.0.0/112{::0.1.0.0}, 128.128.0.0/108{::0.31.255.255}, 208.0.0.0/100{::124.0.0.0}, 2200::/42{ffff:ffff:ffc0::}]");
1262
	bt_assert(::fe00:0:0/88  !~ pxs);
1263
	bt_assert(::fffe:0:0/95  !~ pxs);
1264
	bt_assert(::ffff:d800:0/101 ~ pxs);
1265
	bt_assert(216.0.0.0/5 ~ pxs);
1266
	bt_assert(212.0.0.0/6 ~ pxs);
1267
	bt_assert(212.0.0.0/7 !~ pxs);
1268
	bt_assert(::ffff:8080:8080/121 ~ pxs);
1269
	bt_assert(::/0 ~ pxs);
1270
	bt_assert(0.0.0.0/0 !~ pxs);
1271
	bt_assert(128.135.64.17/32 ~ pxs);
1272

    
1273
#	pxt = [ 0:1:2 10.1.10.0/24, 0:5:10000 10.1.10.0/24 ];
1274
#	print pxt;
1275

    
1276
	bt_assert(format(NET_IP4) = "(enum 36)1"); ## if (net.type = NET_IP4) ...
1277
	bt_assert(format(NET_VPN6) = "(enum 36)4");
1278
	bt_assert(format(0:1:2) = "1:2");
1279
}
1280

    
1281
bt_test_suite(t_mixed_prefix, "Testing mixed net types");
1282

    
1283

    
1284
filter vpn_filter
1285
{
1286
	bt_assert(format(net) = "0:1:2 10.1.10.0/24");
1287
	bt_assert(net.type = NET_VPN4);
1288
	bt_assert(net.type != NET_IP4);
1289
	bt_assert(net.type != NET_IP6);
1290
	bt_assert(net.rd = 0:1:2);
1291

    
1292
	case (net.type) {
1293
	  NET_IP4: print "IPV4";
1294
	  NET_IP6: print "IPV6";
1295
	}
1296

    
1297
	accept;
1298
}
1299

    
1300
vpn4 table v4;
1301
vpn4 table v6;
1302

    
1303
protocol static
1304
{
1305
	vpn4 { table v4; import filter vpn_filter; };
1306
	route 0:1:2 10.1.10.0/24 unreachable;
1307
}