]> git.ipfire.org Git - thirdparty/bird.git/blob - filter/test.conf
Merge branch 'master' into mq-filter-stack
[thirdparty/bird.git] / filter / test.conf
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 device { }
11
12
13
14 /*
15 * Common definitions and functions
16 * --------------------------------
17 */
18
19 define one = 1;
20 define ten = 10;
21
22 function onef(int a)
23 {
24 return 1;
25 }
26
27 function twof(int a)
28 {
29 return 2;
30 }
31
32 function oneg(int a)
33 {
34 return 1;
35 }
36
37 bt_test_same(onef, onef, 1);
38 bt_test_same(onef, oneg, 1);
39 bt_test_same(onef, twof, 0);
40
41 /*
42 * Testing boolean expressions
43 * ---------------------------
44 */
45
46 function t_bool()
47 bool b;
48 {
49 b = true;
50 bt_assert(b);
51 bt_assert(!!b);
52
53 bt_assert(format(true) = "TRUE");
54 bt_assert(format(false) = "FALSE");
55
56 if ( b = true ) then
57 bt_assert(b);
58 else
59 bt_assert(false);
60
61 bt_assert(true && true);
62 bt_assert(true || false);
63 bt_assert(! false && ! false && true);
64 bt_assert(1 < 2 && 1 != 3);
65 bt_assert(true && true && ! false);
66 bt_assert(true || 1+"a");
67 bt_assert(!(false && 1+"a"));
68 bt_assert(!(true && false));
69 }
70
71 bt_test_suite(t_bool, "Testing boolean expressions");
72
73
74
75 /*
76 * Testing integers
77 * ----------------
78 */
79
80 define four = 4;
81 define xyzzy = (120+10);
82 define '1a-a1' = (xyzzy-100);
83
84 function t_int()
85 int i;
86 {
87 bt_assert(xyzzy = 130);
88 bt_assert('1a-a1' = 30);
89
90 i = four;
91 i = 12*100 + 60/2 + i;
92 i = (i + 0);
93 bt_assert(i = 1234);
94
95 bt_assert(format(i) = "1234");
96
97 i = 4200000000;
98 bt_assert(i = 4200000000);
99 bt_assert(i > 4100000000);
100 bt_assert(!(i > 4250000000));
101
102 bt_assert(1 = 1);
103 bt_assert(!(1 != 1));
104
105 bt_assert(1 != 2);
106 bt_assert(1 <= 2);
107
108 bt_assert(1 != "a");
109 bt_assert(1 != (0,1));
110
111 bt_assert(!(i = 4));
112 bt_assert(1 <= 1);
113 bt_assert(!(1234 < 1234));
114 }
115
116 bt_test_suite(t_int, "Testing integers");
117
118
119
120
121 /*
122 * Testing sets of integers
123 * ------------------------
124 */
125
126 define is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
127 define is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
128 define is3 = [5, 17, 2, 11, 8, 15, 3, 19];
129
130 function t_int_set()
131 int set is;
132 {
133 bt_assert(1 ~ [1,2,3]);
134 bt_assert(5 ~ [1..20]);
135 bt_assert(2 ~ [ 1, 2, 3 ]);
136 bt_assert(5 ~ [ 4 .. 7 ]);
137 bt_assert(1 !~ [ 2, 3, 4 ]);
138 bt_assert(999 !~ [ 666, 333 ]);
139
140 is = [ 2, 3, 4, 7..11 ];
141 bt_assert(10 ~ is);
142 bt_assert(5 !~ is);
143
144 bt_assert(1 ~ is1);
145 bt_assert(3 ~ is1);
146 bt_assert(5 ~ is1);
147 bt_assert((one+2) ~ is1);
148 bt_assert(2 ~ is2);
149 bt_assert(2 ~ is3);
150 bt_assert(4 !~ is1);
151 bt_assert(4 !~ is2);
152 bt_assert(4 !~ is3);
153 bt_assert(10 !~ is1);
154 bt_assert(10 !~ is2);
155 bt_assert(10 !~ is3);
156 bt_assert(15 ~ is1);
157 bt_assert(15 ~ is2);
158 bt_assert(15 ~ is3);
159 bt_assert(18 !~ is1);
160 bt_assert(18 !~ is2);
161 bt_assert(18 !~ is3);
162 bt_assert(19 ~ is1);
163 bt_assert(19 ~ is2);
164 bt_assert(19 ~ is3);
165 bt_assert(20 !~ is1);
166 bt_assert(20 !~ is2);
167 bt_assert(20 !~ is3);
168
169 bt_assert([1,2] != [1,3]);
170 bt_assert([1,4..10,20] = [1,4..10,20]);
171
172 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]");
173 }
174
175 bt_test_suite(t_int_set, "Testing sets of integers");
176
177
178
179
180 /*
181 * Testing string matching
182 * -----------------------
183 */
184
185 function t_string()
186 string st;
187 {
188 st = "Hello";
189 bt_assert(format(st) = "Hello");
190 bt_assert(st ~ "Hell*");
191 bt_assert(st ~ "?ello");
192 bt_assert(st ~ "Hello");
193 bt_assert(st ~ "Hell?");
194 bt_assert(st !~ "ell*");
195 }
196
197 bt_test_suite(t_string, "Testing string matching");
198
199
200
201
202 /*
203 * Testing pairs
204 * -------------
205 */
206
207 function 'mkpair-a'(int a)
208 {
209 return (1, a);
210 }
211
212 function t_pair()
213 pair pp;
214 {
215 pp = (1, 2);
216 bt_assert(format(pp) = "(1,2)");
217 bt_assert((1,2) = pp);
218 bt_assert((1,1+1) = pp);
219 bt_assert('mkpair-a'(2) = pp);
220 bt_assert((1,2) = (1,1+1));
221 bt_assert(((1,2) < (2,2)));
222 bt_assert(!((1,1) > (1,1)));
223 }
224
225 bt_test_suite(t_pair, "Testing pairs");
226
227
228
229
230 /*
231 * Testing sets of pairs
232 * ---------------------
233 */
234
235 function t_pair_set()
236 pair pp;
237 pair set ps;
238 {
239 pp = (1, 2);
240 ps = [(1,(one+one)), (3,4)..(4,8), (5,*), (6,3..6)];
241 bt_assert(format(ps) = "[(1,2), (3,4)..(4,8), (5,0)..(5,65535), (6,3)..(6,6)]");
242 bt_assert(pp ~ ps);
243 bt_assert((3,5) ~ ps);
244 bt_assert((4,1) ~ ps);
245 bt_assert((5,4) ~ ps);
246 bt_assert((5,65535) ~ ps);
247 bt_assert((6,4) ~ ps);
248 bt_assert((3, 10000) ~ ps);
249 bt_assert((3,3) !~ ps);
250 bt_assert((4,9) !~ ps);
251 bt_assert((4,65535) !~ ps);
252 bt_assert((6,2) !~ ps);
253 bt_assert((6,6+one) !~ ps);
254 bt_assert(((one+6),2) !~ ps);
255 bt_assert((1,1) !~ ps);
256
257 ps = [(20..150, 200..300), (50100..50200, 1000..50000), (*, 5+5)];
258 bt_assert((100,200) ~ ps);
259 bt_assert((150,300) ~ ps);
260 bt_assert((50180,1200) ~ ps);
261 bt_assert((50110,49000) ~ ps);
262 bt_assert((0,10) ~ ps);
263 bt_assert((64000,10) ~ ps);
264 bt_assert((20,199) !~ ps);
265 bt_assert((151,250) !~ ps);
266 bt_assert((50050,2000) !~ ps);
267 bt_assert((50150,50050) !~ ps);
268 bt_assert((10,9) !~ ps);
269 bt_assert((65535,11) !~ ps);
270 }
271
272 bt_test_suite(t_pair_set, "Testing sets of pairs");
273
274
275
276
277 /*
278 * Testing quads
279 * -------------
280 */
281
282 function t_quad()
283 quad qq;
284 {
285 qq = 1.2.3.4;
286 bt_assert(format(qq) = "1.2.3.4");
287 bt_assert(qq = 1.2.3.4);
288 bt_assert(qq != 4.3.2.1);
289 }
290
291 bt_test_suite(t_quad, "Testing quads");
292
293
294
295
296 /*
297 * Testing sets of quads
298 * ---------------------
299 */
300
301 function t_quad_set()
302 quad qq;
303 {
304 qq = 1.2.3.4;
305 bt_assert(qq ~ [1.2.3.4, 5.6.7.8]);
306 bt_assert(qq !~ [1.2.1.1, 1.2.3.5]);
307 }
308
309 bt_test_suite(t_quad_set, "Testing sets of quads");
310
311
312
313
314 /*
315 * Testing ip address
316 * ------------------
317 */
318
319 define onetwo = 1.2.3.4;
320
321 function t_ip()
322 ip p;
323 {
324 p = 127.1.2.3;
325 bt_assert(p.is_v4);
326 bt_assert(p.mask(8) = 127.0.0.0);
327 bt_assert(1.2.3.4 = 1.2.3.4);
328 bt_assert(1.2.3.4 = onetwo);
329 bt_assert(format(p) = "127.1.2.3");
330
331 p = ::fffe:6:c0c:936d:88c7:35d3;
332 bt_assert(!p.is_v4);
333 bt_assert(format(p) = "::fffe:6:c0c:936d:88c7:35d3");
334
335 p = 1234:5678::;
336 bt_assert(!p.is_v4);
337 bt_assert(p.mask(24) = 1234:5600::);
338 }
339
340 bt_test_suite(t_ip, "Testing ip address");
341
342
343
344
345 /*
346 * Testing sets of ip address
347 * --------------------------
348 */
349
350 define ip1222 = 1.2.2.2;
351
352 function t_ip_set()
353 ip set ips;
354 {
355 ips = [ 1.1.1.0 .. 1.1.1.255, ip1222];
356 bt_assert(format(ips) = "[1.1.1.0..1.1.1.255, 1.2.2.2]");
357 bt_assert(1.1.1.0 ~ ips);
358 bt_assert(1.1.1.100 ~ ips);
359 bt_assert(1.2.2.2 ~ ips);
360 bt_assert(1.1.0.255 !~ ips);
361 bt_assert(1.1.2.0 !~ ips);
362 bt_assert(1.2.2.3 !~ ips);
363 bt_assert(192.168.1.1 !~ ips);
364
365 bt_assert(1.2.3.4 !~ [ 1.2.3.3, 1.2.3.5 ]);
366 bt_assert(1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ]);
367 }
368
369 bt_test_suite(t_ip_set, "Testing sets of ip address");
370
371
372
373
374 /*
375 * Testing enums
376 * -------------
377 */
378
379 function t_enum()
380 {
381 bt_assert(format(RTS_DUMMY) = "(enum 30)0");
382 bt_assert(format(RTS_STATIC) = "(enum 30)1");
383 bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
384 bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
385 }
386
387 bt_test_suite(t_enum, "Testing enums");
388
389
390
391
392 /*
393 * Testing prefixes
394 * ----------------
395 */
396
397 define netdoc = 2001:db8::/32;
398
399 function t_prefix()
400 prefix px;
401 {
402 px = 1.2.0.0/18;
403 bt_assert(format(px) = "1.2.0.0/18");
404 bt_assert(192.168.0.0/16 ~ 192.168.0.0/16);
405 bt_assert(192.168.0.0/17 ~ 192.168.0.0/16);
406 bt_assert(192.168.254.0/24 ~ 192.168.0.0/16);
407 bt_assert(netdoc ~ 2001::/16);
408 bt_assert(192.168.0.0/15 !~ 192.168.0.0/16);
409 bt_assert(192.160.0.0/17 !~ 192.168.0.0/16);
410 bt_assert(px !~ netdoc);
411
412 bt_assert(1.2.3.4 ~ 1.0.0.0/8);
413 bt_assert(1.0.0.0/8 ~ 1.0.0.0/8);
414 }
415
416 bt_test_suite(t_prefix, "Testing prefixes");
417
418
419
420
421 /*
422 * Testing prefix sets
423 * -------------------
424 */
425
426 define net10 = 10.0.0.0/8;
427 define pxs2 = [ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ];
428
429 function test_pxset(prefix set pxs)
430 {
431 bt_assert(net10 ~ pxs);
432 bt_assert(10.0.0.0/10 ~ pxs);
433 bt_assert(10.0.0.0/12 ~ pxs);
434 bt_assert(20.0.0.0/24 ~ pxs);
435 bt_assert(20.0.40.0/24 ~ pxs);
436 bt_assert(20.0.0.0/26 ~ pxs);
437 bt_assert(20.0.100.0/26 ~ pxs);
438 bt_assert(20.0.0.0/28 ~ pxs);
439 bt_assert(20.0.255.0/28 ~ pxs);
440
441 bt_assert(10.0.0.0/7 !~ pxs);
442 bt_assert(10.0.0.0/13 !~ pxs);
443 bt_assert(10.0.0.0/16 !~ pxs);
444 bt_assert(20.0.0.0/16 !~ pxs);
445 bt_assert(20.0.0.0/23 !~ pxs);
446 bt_assert(20.0.0.0/29 !~ pxs);
447 bt_assert(11.0.0.0/10 !~ pxs);
448 bt_assert(20.1.0.0/26 !~ pxs);
449
450 bt_assert(1.0.0.0/8 ~ [ 1.0.0.0/8+ ]);
451 bt_assert(1.0.0.0/9 !~ [ 1.0.0.0/8- ]);
452 bt_assert(1.2.0.0/17 !~ [ 1.0.0.0/8{ 15 , 16 } ]);
453
454 bt_assert([ 10.0.0.0/8{ 15 , 17 } ] = [ 10.0.0.0/8{ 15 , 17 } ]);
455 }
456
457 function t_prefix_set()
458 prefix set pxs;
459 {
460 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} ];
461 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}]");
462 bt_assert(1.2.0.0/16 ~ pxs);
463 bt_assert(1.4.0.0/16 ~ pxs);
464 bt_assert(1.4.0.0/18 ~ pxs);
465 bt_assert(1.4.0.0/32 ~ pxs);
466 bt_assert(1.1.0.0/16 !~ pxs);
467 bt_assert(1.3.0.0/16 !~ pxs);
468 bt_assert(1.2.0.0/15 !~ pxs);
469 bt_assert(1.2.0.0/17 !~ pxs);
470 bt_assert(1.2.0.0/32 !~ pxs);
471 bt_assert(1.4.0.0/15 !~ pxs);
472
473 test_pxset(pxs2);
474 test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
475
476 bt_assert(1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ]);
477 bt_assert([ 10.0.0.0/8{ 15 , 17 } ] != [ 11.0.0.0/8{ 15 , 17 } ]);
478 }
479
480 bt_test_suite(t_prefix_set, "Testing prefix sets");
481
482
483
484
485 /*
486 * Testing Prefix IPv6
487 * -------------------
488 */
489
490 function t_prefix6()
491 prefix px;
492 {
493 px = 1020::/18;
494 bt_assert(format(px) = "1020::/18");
495 bt_assert(1020:3040:5060:: ~ 1020:3040:5000::/40);
496 bt_assert(1020:3040::/32 ~ 1020:3040::/32);
497 bt_assert(1020:3040::/33 ~ 1020:3040::/32);
498 bt_assert(1020:3040:5060::/48 ~ 1020:3040::/32);
499 bt_assert(1020:3040::/31 !~ 1020:3040::/32);
500 bt_assert(1020:3041::/33 !~ 1020:3040::/32);
501 }
502
503 bt_test_suite(t_prefix6, "Testing prefix IPv6");
504
505
506
507
508 /*
509 * Testing prefix IPv6 sets
510 * ------------------------
511 */
512
513 function t_prefix6_set()
514 prefix set pxs;
515 {
516 bt_assert(1180::/16 ~ [ 1100::/8{15, 17} ]);
517 bt_assert(12::34 = 12::34);
518 bt_assert(12::34 ~ [ 12::33..12::35 ]);
519 bt_assert(1020::34 ~ 1000::/8);
520 bt_assert(1000::/8 ~ 1000::/8);
521 bt_assert(1000::/8 ~ [ 1000::/8+ ]);
522 bt_assert(12::34 !~ [ 12::33, 12::35 ]);
523 bt_assert(1000::/9 !~ [ 1000::/8- ]);
524 bt_assert(1000::/17 !~ [ 1000::/8{15, 16} ]);
525
526 pxs = [ 1102::/16, 1104::/16+];
527 bt_assert(1102::/16 ~ pxs);
528 bt_assert(1104::/16 ~ pxs);
529 bt_assert(1104::/18 ~ pxs);
530 bt_assert(1104::/32 ~ pxs);
531 bt_assert(1101::/16 !~ pxs);
532 bt_assert(1103::/16 !~ pxs);
533 bt_assert(1102::/15 !~ pxs);
534 bt_assert(1102::/17 !~ pxs);
535 bt_assert(1102::/32 !~ pxs);
536 bt_assert(1104::/15 !~ pxs);
537
538 pxs = ([ 1000::/16{8,12}, 2000::/16{24,28} ]);
539 bt_assert(format(pxs) = "[1000::/12{1f0::}, 2000::/16{0:1f0::}]");
540 bt_assert(1000::/8 ~ pxs);
541 bt_assert(1000::/10 ~ pxs);
542 bt_assert(1000::/12 ~ pxs);
543 bt_assert(2000::/24 ~ pxs);
544 bt_assert(2000:4000::/24 ~ pxs);
545 bt_assert(2000::/26 ~ pxs);
546 bt_assert(2000:8000::/26 ~ pxs);
547 bt_assert(2000::/28 ~ pxs);
548 bt_assert(2000:FFF0::/28 ~ pxs);
549 bt_assert(1000::/7 !~ pxs);
550 bt_assert(1000::/13 !~ pxs);
551 bt_assert(1000::/16 !~ pxs);
552 bt_assert(2000::/16 !~ pxs);
553 bt_assert(2000::/23 !~ pxs);
554 bt_assert(2000::/29 !~ pxs);
555 bt_assert(1100::/10 !~ pxs);
556 bt_assert(2010::/26 !~ pxs);
557 }
558
559 bt_test_suite(t_prefix6_set, "Testing prefix IPv6 sets");
560
561
562
563
564 function t_flowspec()
565 prefix p;
566 {
567 p = flow4 { dst 10.0.0.0/8; };
568 bt_assert(p !~ [ 10.0.0.0/8 ] );
569
570 bt_assert(format(flow4 { dst 10.0.0.0/8; proto = 23; }) = "flow4 { dst 10.0.0.0/8; proto 23; }");
571 bt_assert(format(flow6 { dst ::1/128; src ::2/127; }) = "flow6 { dst ::1/128; src ::2/127; }");
572 bt_assert(format(flow6 { next header false 42; }) = "flow6 { next header false 42; }");
573 bt_assert(format(flow6 { port 80; }) = "flow6 { port 80; }");
574 bt_assert(format(flow6 { dport > 24 && < 30 || 40..50,60..70,80 && >= 90; }) = "flow6 { dport > 24 && < 30 || 40..50,60..70,80 && >= 90; }");
575 bt_assert(format(flow6 { sport 0..0x400; }) = "flow6 { sport 0..1024; }");
576 bt_assert(format(flow6 { icmp type 80; }) = "flow6 { icmp type 80; }");
577 bt_assert(format(flow6 { icmp code 90; }) = "flow6 { icmp code 90; }");
578 bt_assert(format(flow6 { tcp flags 0x03/0x0f; }) = "flow6 { tcp flags 0x3/0x3,0x0/0xc; }");
579 bt_assert(format(flow6 { length 0..65535; }) = "flow6 { length 0..65535; }");
580 bt_assert(format(flow6 { dscp = 63; }) = "flow6 { dscp 63; }");
581 bt_assert(format(flow6 { fragment is_fragment || !first_fragment; }) = "flow6 { fragment is_fragment || !first_fragment; }");
582 bt_assert(format(flow6 { }) = "flow6 { }");
583 }
584
585 bt_test_suite(t_flowspec, "Testing flowspec routes");
586
587
588
589
590 /*
591 * Testing Paths
592 * -------------
593 */
594
595 function mkpath(int a; int b)
596 {
597 return [= a b 3 2 1 =];
598 }
599
600 function t_path()
601 bgpmask pm1;
602 bgppath p2;
603 {
604 pm1 = [= 4 3 2 1 =];
605
606 bt_assert(format(pm1) = "[= 4 3 2 1 =]");
607
608 bt_assert(+empty+ = +empty+);
609 bt_assert(10 !~ +empty+);
610
611 p2 = prepend( + empty +, 1 );
612 p2 = prepend( p2, 2 );
613 p2 = prepend( p2, 3 );
614 p2 = prepend( p2, 4 );
615
616 bt_assert(format(p2) = "(path 4 3 2 1)");
617 bt_assert(p2.len = 4);
618 bt_assert(p2 ~ pm1);
619 bt_assert(3 ~ p2);
620 bt_assert(p2 ~ [2, 10..20]);
621 bt_assert(p2 ~ [4, 10..20]);
622
623 p2 = prepend(p2, 5);
624 bt_assert(p2 !~ pm1);
625 bt_assert(10 !~ p2);
626 bt_assert(p2 !~ [8, ten..(2*ten)]);
627 bt_assert(p2 ~ [= * 4 3 * 1 =]);
628 bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
629 bt_assert(p2 ~ mkpath(5, 4));
630
631 bt_assert(p2.len = 5);
632 bt_assert(p2.first = 5);
633 bt_assert(p2.last = 1);
634
635 bt_assert(p2.len = 5);
636 bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
637 bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
638
639 pm1 = [= 1 2 * 3 4 5 =];
640 p2 = prepend( + empty +, 5 );
641 p2 = prepend( p2, 4 );
642 p2 = prepend( p2, 3 );
643 p2 = prepend( p2, 3 );
644 p2 = prepend( p2, 2 );
645 p2 = prepend( p2, 1 );
646
647 bt_assert(p2 ~ pm1);
648 bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
649 bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
650 }
651
652 bt_test_suite(t_path, "Testing paths");
653
654
655
656
657 /*
658 * Testing Community List
659 * ----------------------
660 */
661
662 define p23 = (2, 3);
663
664 function t_clist()
665 clist l;
666 clist l2;
667 clist r;
668 {
669 l = - empty -;
670 bt_assert(l !~ [(*,*)]);
671 bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
672
673 bt_assert(-empty- = -empty-);
674
675 l = add( l, (one,2) );
676 bt_assert(l ~ [(*,*)]);
677 l = add( l, (2,one+2) );
678 bt_assert(format(l) = "(clist (1,2) (2,3))");
679
680 bt_assert((2,3) ~ l);
681 bt_assert(l ~ [(1,*)]);
682 bt_assert(l ~ [p23]);
683 bt_assert(l ~ [(2,2..3)]);
684 bt_assert(l ~ [(1,1..2)]);
685 bt_assert(l ~ [(1,1)..(1,2)]);
686
687 l = add(l, (2,5));
688 l = add(l, (5,one));
689 l = add(l, (6,one));
690 l = add(l, (one,one));
691 l = delete(l, [(5,1),(6,one),(one,1)]);
692 l = delete(l, [(5,one),(6,one)]);
693 l = filter(l, [(1,*)]);
694 bt_assert(l = add(-empty-, (1,2)));
695
696 bt_assert((2,3) !~ l);
697 bt_assert(l !~ [(2,*)]);
698 bt_assert(l !~ [(one,3..6)]);
699 bt_assert(l ~ [(*,*)]);
700
701 l = add(l, (3,one));
702 l = add(l, (one+one+one,one+one));
703 l = add(l, (3,3));
704 l = add(l, (3,4));
705 l = add(l, (3,5));
706 l2 = filter(l, [(3,*)]);
707 l = delete(l, [(3,2..4)]);
708 bt_assert(l = add(add(add(-empty-, (1,2)), (3,1)), (3,5)));
709 bt_assert(l.len = 3);
710
711 l = add(l, (3,2));
712 l = add(l, (4,5));
713 bt_assert(l = add(add(add(add(add(-empty-, (1,2)), (3,1)), (3,5)), (3,2)), (4,5)));
714
715 bt_assert(l.len = 5);
716 bt_assert(l ~ [(*,2)]);
717 bt_assert(l ~ [(*,5)]);
718 bt_assert(l ~ [(*, one)]);
719 bt_assert(l !~ [(*,3)]);
720 bt_assert(l !~ [(*,(one+6))]);
721 bt_assert(l !~ [(*, (one+one+one))]);
722
723 l = delete(l, [(*,(one+onef(3)))]);
724 l = delete(l, [(*,(4+one))]);
725 bt_assert(l = add(-empty-, (3,1)));
726
727 l = delete(l, [(*,(onef(5)))]);
728 bt_assert(l = -empty-);
729
730 l2 = add(l2, (3,6));
731 l = filter(l2, [(3,1..4)]);
732 l2 = filter(l2, [(3,3..6)]);
733
734 # clist A (10,20,30)
735 bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
736 bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))");
737
738 # clist B (30,40,50)
739 bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
740 bt_assert(format(l2) = "(clist (3,3) (3,4) (3,5) (3,6))");
741
742 # clist A union B
743 r = add(l, l2);
744 bt_assert(r = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
745 bt_assert(format(r) = "(clist (3,1) (3,2) (3,3) (3,4) (3,5) (3,6))");
746
747 # clist A isect B
748 r = filter(l, l2);
749 bt_assert(r = add(add(-empty-, (3,3)), (3,4)));
750 bt_assert(format(r) = "(clist (3,3) (3,4))");
751
752 # clist A \ B
753 r = delete(l, l2);
754 bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
755 bt_assert(format(r) = "(clist (3,1) (3,2))");
756
757 # clist in c set
758 r = filter(l, [(3,1), (*,2)]);
759 bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
760 bt_assert(format(r) = "(clist (3,1) (3,2))");
761 }
762
763 bt_test_suite(t_clist, "Testing lists of communities");
764
765
766
767
768 /*
769 * Testing Extended Communities
770 * ----------------------------
771 */
772
773 function t_ec()
774 ec cc;
775 {
776 cc = (rt, 12345, 200000);
777 bt_assert(format(cc) = "(rt, 12345, 200000)");
778
779 bt_assert(cc = (rt, 12345, 200000));
780 bt_assert(cc < (rt, 12345, 200010));
781 bt_assert(cc != (rt, 12346, 200000));
782 bt_assert(cc != (ro, 12345, 200000));
783 bt_assert(!(cc > (rt, 12345, 200010)));
784
785 bt_assert(format((ro, 100000, 20000)) = "(ro, 100000, 20000)");
786 }
787
788 bt_test_suite(t_ec, "Testing extended communities");
789
790
791
792
793 /*
794 * Testing Extended Community List
795 * -------------------------------
796 */
797
798 function t_eclist()
799 eclist el;
800 eclist el2;
801 eclist r;
802 {
803 el = -- empty --;
804 el = add(el, (rt, 10, 20));
805 el = add(el, (ro, 10.20.30.40, 100));
806 el = add(el, (ro, 11.21.31.41.mask(16), 200));
807
808 bt_assert(--empty-- = --empty--);
809 bt_assert(((rt, 10, 20)) !~ --empty--);
810
811 bt_assert(format(el) = "(eclist (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200))");
812 bt_assert(el.len = 3);
813 el = delete(el, (rt, 10, 20));
814 el = delete(el, (rt, 10, 30));
815 bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
816 el = add(el, (unknown 2, ten, 1));
817 el = add(el, (unknown 5, ten, 1));
818 el = add(el, (rt, ten, one+one));
819 el = add(el, (rt, 10, 3));
820 el = add(el, (rt, 10, 4));
821 el = add(el, (rt, 10, 5));
822 el = add(el, (generic, 0x2000a, 3*ten));
823 el = delete(el, [(rt, 10, 2..ten)]);
824 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)));
825
826 el = filter(el, [(rt, 10, *)]);
827 bt_assert(el = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
828 bt_assert((rt, 10, 1) ~ el);
829 bt_assert(el ~ [(rt, 10, ten..40)]);
830 bt_assert((rt, 10, 20) !~ el);
831 bt_assert((ro, 10.20.30.40, 100) !~ el);
832 bt_assert(el !~ [(rt, 10, 35..40)]);
833 bt_assert(el !~ [(ro, 10, *)]);
834
835 el = add(el, (rt, 10, 40));
836 el2 = filter(el, [(rt, 10, 20..40)] );
837 el2 = add(el2, (rt, 10, 50));
838
839 # eclist A (1,30,40)
840 bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
841 bt_assert(format(el) = "(eclist (rt, 10, 1) (rt, 10, 30) (rt, 10, 40))");
842
843 # eclist B (30,40,50)
844 bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
845 bt_assert(format(el2) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50))");
846
847 # eclist A union B
848 r = add(el2, el);
849 bt_assert(r = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
850 bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50) (rt, 10, 1))");
851
852 # eclist A isect B
853 r = filter(el, el2);
854 bt_assert(r = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
855 bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40))");
856
857 # eclist A \ B
858 r = delete(el, el2);
859 bt_assert(r = add(--empty--, (rt, 10, 1)));
860 bt_assert(format(r) = "(eclist (rt, 10, 1))");
861
862 # eclist in ec set
863 r = filter(el, [(rt, 10, 1), (rt, 10, 25..30), (ro, 10, 40)]);
864 bt_assert(r = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
865 bt_assert(format(r) = "(eclist (rt, 10, 1) (rt, 10, 30))");
866 }
867
868 bt_test_suite(t_eclist, "Testing lists of extended communities");
869
870
871
872
873 /*
874 * Testing sets of Extended Communities
875 * ------------------------------------
876 */
877
878 define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
879
880 function t_ec_set()
881 ec set ecs;
882 {
883 ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
884 bt_assert(format(ecs) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
885 bt_assert(format(ecs2) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
886
887 bt_assert((rt, 10, 20) ~ ecs);
888 bt_assert((ro, 100000, 100) ~ ecs);
889 bt_assert((ro, 100000, 128) ~ ecs);
890 bt_assert((ro, 100000, 200) ~ ecs);
891 bt_assert((rt, 12345, 0) ~ ecs);
892 bt_assert((rt, 12345, 200000) ~ ecs);
893 bt_assert((rt, 12345, 4000000) ~ ecs);
894 bt_assert((ro, 10, 20) !~ ecs);
895 bt_assert((rt, 10, 21) !~ ecs);
896 bt_assert((ro, 100000, 99) !~ ecs);
897 bt_assert((ro, 12345, 10) !~ ecs);
898 bt_assert((rt, 12346, 0) !~ ecs);
899 bt_assert((ro, 0.1.134.160, 150) !~ ecs);
900 }
901
902 bt_test_suite(t_ec_set, "Testing sets of extended communities");
903
904
905
906
907 /*
908 * Testing Large Communities
909 * -------------------------
910 */
911
912 function mktrip(int a)
913 {
914 return (a, 2*a, 3*a);
915 }
916
917 function t_lclist()
918 lclist ll;
919 lclist ll2;
920 lclist r;
921 {
922 bt_assert(---empty--- = ---empty---);
923 bt_assert((10, 20, 30) !~ ---empty---);
924
925 ll = --- empty ---;
926 ll = add(ll, (ten, 20, 30));
927 ll = add(ll, (1000, 2000, 3000));
928 ll = add(ll, mktrip(100000));
929 bt_assert(format(ll) = "(lclist (10, 20, 30) (1000, 2000, 3000) (100000, 200000, 300000))");
930 bt_assert(ll.len = 3);
931 bt_assert(ll = add(add(add(---empty---, (10, 20, 30)), (1000, 2000, 3000)), (100000, 200000, 300000)));
932
933 bt_assert(mktrip(1000) ~ ll);
934 bt_assert(mktrip(100) !~ ll);
935
936 ll = --- empty ---;
937 ll = add(ll, (10, 10, 10));
938 ll = add(ll, (20, 20, 20));
939 ll = add(ll, (30, 30, 30));
940
941 ll2 = --- empty ---;
942 ll2 = add(ll2, (20, 20, 20));
943 ll2 = add(ll2, (30, 30, 30));
944 ll2 = add(ll2, (40, 40, 40));
945
946 # lclist A (10, 20, 30)
947 bt_assert(format(ll) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30))");
948
949 # lclist B (20, 30, 40)
950 bt_assert(format(ll2) = "(lclist (20, 20, 20) (30, 30, 30) (40, 40, 40))");
951
952 # lclist A union B
953 r = add(ll, ll2);
954 bt_assert(r = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));
955 bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30) (40, 40, 40))");
956
957 # lclist A isect B
958 r = filter(ll, ll2);
959 bt_assert(r = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));
960 bt_assert(format(r) = "(lclist (20, 20, 20) (30, 30, 30))");
961
962 # lclist A \ B
963 r = delete(ll, ll2);
964 bt_assert(r = add(---empty---, (10, 10, 10)));
965 bt_assert(format(r) = "(lclist (10, 10, 10))");
966
967 # lclist in lc set
968 r = filter(ll, [(5..15, *, *), (20, 15..25, *)]);
969 bt_assert(r = add(add(---empty---, (10, 10, 10)), (20, 20, 20)));
970 bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20))");
971 }
972
973 bt_test_suite(t_lclist, "Testing lists of large communities");
974
975
976
977
978 /*
979 * Testing sets of Large Communities
980 * ---------------------------------
981 */
982
983 function t_lclist_set()
984 lclist ll;
985 lc set lls;
986 {
987 ll = --- empty ---;
988 ll = add(ll, (10, 20, 30));
989 ll = add(ll, (1000, 2000, 3000));
990 ll = add(ll, mktrip(100000));
991
992 bt_assert(ll ~ [(5,10,15), (10,20,30)]);
993 bt_assert(ll ~ [(10,15..25,*)]);
994 bt_assert(ll ~ [(ten, *, *)]);
995
996 bt_assert(ll !~ [(5,10,15), (10,21,30)]);
997 bt_assert(ll !~ [(10,21..25,*)]);
998 bt_assert(ll !~ [(11, *, *)]);
999
1000 lls = [(10, 10, 10), (20, 20, 15..25), (30, 30, *), (40, 35..45, *), (50, *, *), (55..65, *, *)];
1001 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)]");
1002 bt_assert((10, 10, 10) ~ lls);
1003 bt_assert((20, 20, 25) ~ lls);
1004 bt_assert((20, 20, 26) !~ lls);
1005 bt_assert((30, 30, 0) ~ lls);
1006 bt_assert((40, 35, 40) ~ lls);
1007 bt_assert((40, 34, 40) !~ lls);
1008 bt_assert((50, 0, 0) ~ lls);
1009 bt_assert((60, 60, 60) ~ lls);
1010 bt_assert((70, 60, 60) !~ lls);
1011 }
1012
1013 bt_test_suite(t_lclist_set, "Testing sets of large communities");
1014
1015
1016
1017
1018 /*
1019 * Testing Route Distinguishers
1020 * ----------------------------
1021 */
1022
1023 function t_rd()
1024 rd x;
1025 {
1026 x = 12345:20000;
1027 bt_assert(format(x) = "12345:20000");
1028
1029 bt_assert(x = 12345:20000);
1030 bt_assert(x < 12345:20010);
1031 bt_assert(x != 12346:20000);
1032 bt_assert(x != 2:12345:20000);
1033 bt_assert(!(x > 12345:200010));
1034
1035 bt_assert(format(10.0.0.1:1000) = "10.0.0.1:1000");
1036 bt_assert(format(100000:20000) = "100000:20000");
1037 bt_assert(format(2:100000:20000) = "100000:20000");
1038 bt_assert(format(2:1000:1000) = "2:1000:1000");
1039 }
1040
1041 bt_test_suite(t_rd, "Testing route distinguishers");
1042
1043
1044
1045
1046 /*
1047 * Testing sets of Route Distinguishers
1048 * ------------------------------------
1049 */
1050
1051 function t_rd_set()
1052 rd set rds;
1053 {
1054 rds = [10:20, 100000:100..100000:200];
1055 bt_assert(format(rds) = "[10:20, 100000:100..100000:200]");
1056
1057 bt_assert(10:20 ~ rds);
1058 bt_assert(10:21 !~ rds);
1059 bt_assert(100000:90 !~ rds);
1060 bt_assert(100000:100 ~ rds);
1061 bt_assert(100000:128 ~ rds);
1062 bt_assert(100000:200 ~ rds);
1063 bt_assert(100010:150 !~ rds);
1064 }
1065
1066 bt_test_suite(t_rd_set, "Testing sets of route distinguishers");
1067
1068
1069
1070
1071 /*
1072 * Testing defined() function
1073 * --------------------------
1074 */
1075
1076 function test_undef(int a)
1077 int b;
1078 {
1079 if a = 3 then {
1080 b = 4;
1081 bt_assert(defined(b));
1082 }
1083 else {
1084 bt_assert(!defined(b));
1085 }
1086 }
1087
1088 function t_define()
1089 int i;
1090 {
1091 test_undef(2);
1092 test_undef(3);
1093 test_undef(2);
1094
1095 bt_assert(defined(1));
1096 bt_assert(defined(1.2.3.4));
1097 }
1098
1099 bt_test_suite(t_define, "Testing defined() function");
1100
1101
1102
1103
1104 /*
1105 * Testing calling functions
1106 * -------------------------
1107 */
1108
1109 function callme(int arg1; int arg2)
1110 int i;
1111 {
1112 case arg1 {
1113 1, 42: return 42;
1114 else: return arg1 * arg2;
1115 }
1116
1117 return 0;
1118 }
1119
1120 function callmeagain(int a; int b; int c)
1121 {
1122 return a + b + c;
1123 }
1124
1125 function fifteen()
1126 {
1127 return 15;
1128 }
1129
1130 function t_call_function()
1131 {
1132 bt_assert(fifteen() = 15);
1133
1134 bt_assert(callme(1, 2) = 42);
1135 bt_assert(callme(42, 2) = 42);
1136
1137 bt_assert(callme(2, 2) = 4);
1138 bt_assert(callme(3, 2) = 6);
1139 bt_assert(callme(4, 4) = 16);
1140 bt_assert(callme(7, 2) = 14);
1141 bt_assert(callmeagain(1, 2, 3) = 6);
1142 }
1143
1144 bt_test_suite(t_call_function, "Testing calling functions");
1145
1146
1147
1148
1149 /*
1150 * Test including another config file
1151 * ----------------------------------
1152 */
1153
1154 function t_include()
1155 int i;
1156 {
1157 i = 1;
1158 include "test.conf.inc";
1159 bt_assert(i = 42);
1160 }
1161
1162 bt_test_suite(t_include, "Testing including another config file");
1163
1164
1165
1166
1167 /*
1168 * Test if-else statement
1169 * ----------------------
1170 */
1171
1172 function t_if_else()
1173 int i;
1174 {
1175 if true then
1176 bt_assert(true);
1177
1178 if false then
1179 bt_assert(false);
1180 else if true then
1181 bt_assert(true);
1182 else
1183 bt_assert(false);
1184 }
1185
1186 bt_test_suite(t_if_else, "Testing if-else statement");
1187
1188
1189
1190
1191 /*
1192 * Unused functions -- testing only parsing
1193 * ----------------------------------------
1194 */
1195
1196 function __test1()
1197 {
1198 if source ~ [ RTS_BGP, RTS_STATIC ] then {
1199 # ospf_metric1 = 65535;
1200 # ospf_metric2 = 1000;
1201 ospf_tag = 0x12345678;
1202 accept;
1203 }
1204 reject;
1205 }
1206
1207 function __test2()
1208 {
1209 if source ~ [ RTS_BGP, RTS_STATIC ] then {
1210 # ospf_metric1 = 65535;
1211 # ospf_metric2 = 1000;
1212 ospf_tag = 0x12345678;
1213 accept;
1214 }
1215 reject;
1216 }
1217
1218 filter testf
1219 int j;
1220 {
1221 print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
1222 print "This route was from ", from;
1223 j = 7;
1224 j = 17;
1225 if rip_metric > 15 then {
1226 reject "RIP Metric is more than infinity";
1227 }
1228 rip_metric = 14;
1229 unset(rip_metric);
1230
1231 accept "ok I take that";
1232 }
1233
1234 filter roa_filter
1235 {
1236 if net ~ [ 10.0.0.0/8{16,24}, 2000::/3{16,96} ] then {
1237 accept;
1238 }
1239 reject;
1240 }
1241
1242 roa4 table r4;
1243 roa6 table r6;
1244
1245 protocol static
1246 {
1247 roa4 { table r4; import filter roa_filter; };
1248 route 10.110.0.0/16 max 16 as 1000;
1249 route 10.120.0.0/16 max 24 as 1000;
1250 route 10.130.0.0/16 max 24 as 2000;
1251 route 10.130.128.0/18 max 24 as 3000;
1252 }
1253
1254 protocol static
1255 {
1256 roa6 { table r6; import filter roa_filter; };
1257 route 2001:0db8:85a3:8a2e::/64 max 96 as 1000;
1258 }
1259
1260 function test_roa_check()
1261 prefix pfx;
1262 {
1263 # cannot be tested in __startup(), sorry
1264 bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
1265 bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
1266 bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
1267 bt_assert(roa_check(r4, 10.110.0.0/16, 2000) = ROA_INVALID);
1268 bt_assert(roa_check(r4, 10.110.32.0/20, 1000) = ROA_INVALID);
1269 bt_assert(roa_check(r4, 10.120.32.0/20, 1000) = ROA_VALID);
1270 bt_assert(roa_check(r4, 10.120.32.0/20, 2000) = ROA_INVALID);
1271 bt_assert(roa_check(r4, 10.120.32.32/28, 1000) = ROA_INVALID);
1272 bt_assert(roa_check(r4, 10.130.130.0/24, 1000) = ROA_INVALID);
1273 bt_assert(roa_check(r4, 10.130.130.0/24, 2000) = ROA_VALID);
1274 bt_assert(roa_check(r4, 10.130.30.0/24, 3000) = ROA_INVALID);
1275 bt_assert(roa_check(r4, 10.130.130.0/24, 3000) = ROA_VALID);
1276
1277 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1278 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1279 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e::/64, 1000) = ROA_VALID);
1280 bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1281
1282 bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
1283 bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
1284 bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
1285 bt_assert(roa_check(r4, 10.110.0.0/16, 2000) = ROA_INVALID);
1286 bt_assert(roa_check(r4, 10.110.32.0/20, 1000) = ROA_INVALID);
1287 bt_assert(roa_check(r4, 10.120.32.0/20, 1000) = ROA_VALID);
1288
1289 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1290 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1291 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e::/64, 1000) = ROA_VALID);
1292 bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1293
1294 bt_assert(roa_check(r4, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_UNKNOWN);
1295 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1296
1297 bt_assert(roa_check(r4, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_UNKNOWN);
1298 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1299 bt_assert(roa_check(r4, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1300 bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1301
1302 bt_assert(10.130.130.0/24 ~ 0.0.0.0/0);
1303 bt_assert(2001:0db8:85a3:8a2e::/64 ~ ::/0);
1304 bt_assert(10.130.130.0/24 !~ ::/0);
1305 bt_assert(2001:0db8:85a3:8a2e::/64 !~ 0.0.0.0/0);
1306
1307 pfx = 12.13.0.0/16 max 24 as 1234;
1308 bt_assert(pfx.len = 16);
1309 bt_assert(pfx.maxlen = 24);
1310 bt_assert(pfx.asn = 1234);
1311
1312 pfx = 1000::/8 max 32 as 1234;
1313 bt_assert(pfx.len = 8);
1314 bt_assert(pfx.maxlen = 32);
1315 bt_assert(pfx.asn = 1234);
1316 }
1317
1318 bt_test_suite(test_roa_check, "Testing ROA");
1319
1320 /*
1321 * Testing Mixed Net Types
1322 * -----------------------
1323 */
1324
1325 function t_mixed_prefix()
1326 prefix set pxs;
1327 prefix set pxt;
1328 {
1329 pxs = [ 98.45.0.0/16, 128.128.0.0/12+, 2200::/42-, ::ffff:d000:0/100{98,102}];
1330 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::}]");
1331 bt_assert(::fe00:0:0/88 !~ pxs);
1332 bt_assert(::fffe:0:0/95 !~ pxs);
1333 bt_assert(::ffff:d800:0/101 ~ pxs);
1334 bt_assert(216.0.0.0/5 ~ pxs);
1335 bt_assert(212.0.0.0/6 ~ pxs);
1336 bt_assert(212.0.0.0/7 !~ pxs);
1337 bt_assert(::ffff:8080:8080/121 ~ pxs);
1338 bt_assert(::/0 ~ pxs);
1339 bt_assert(0.0.0.0/0 !~ pxs);
1340 bt_assert(128.135.64.17/32 ~ pxs);
1341
1342 # pxt = [ 0:1:2 10.1.10.0/24, 0:5:10000 10.1.10.0/24 ];
1343 # print pxt;
1344
1345 bt_assert(format(NET_IP4) = "(enum 36)1"); ## if (net.type = NET_IP4) ...
1346 bt_assert(format(NET_VPN6) = "(enum 36)4");
1347 bt_assert(format(0:1:2) = "1:2");
1348 }
1349
1350 bt_test_suite(t_mixed_prefix, "Testing mixed net types");
1351
1352
1353 filter vpn_filter
1354 {
1355 bt_assert(format(net) = "1:2 10.1.10.0/24");
1356 bt_assert(net.type = NET_VPN4);
1357 bt_assert(net.type != NET_IP4);
1358 bt_assert(net.type != NET_IP6);
1359 bt_assert(net.rd = 0:1:2);
1360
1361 case (net.type) {
1362 NET_IP4: print "IPV4";
1363 NET_IP6: print "IPV6";
1364 }
1365
1366 bt_check_assign(from, 10.20.30.40);
1367 bt_check_assign(gw, 55.55.55.44);
1368
1369 bgp_community.add((3,5));
1370 bgp_ext_community.add((ro, 135, 999));
1371 bgp_large_community.add((6464156, 89646354, 8675643));
1372
1373 accept;
1374 }
1375
1376 vpn4 table v4;
1377 vpn4 table v6;
1378
1379 protocol static
1380 {
1381 vpn4 { table v4; import filter vpn_filter; };
1382 route 0:1:2 10.1.10.0/24 unreachable;
1383 }
1384
1385 protocol static
1386 {
1387 ipv6 { import where false; };
1388 route fd01::/48 unreachable;
1389 }