]> git.ipfire.org Git - thirdparty/bird.git/blob - filter/test.conf
Filter: Add operators to pick community components
[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(format(NET_IP4) = "(enum 36)1");
384 bt_assert(format(NET_VPN6) = "(enum 36)4");
385
386 bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
387 bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
388 }
389
390 bt_test_suite(t_enum, "Testing enums");
391
392
393
394
395 /*
396 * Testing prefixes
397 * ----------------
398 */
399
400 define netdoc = 2001:db8::/32;
401
402 function t_prefix()
403 prefix px;
404 {
405 px = 1.2.0.0/18;
406 bt_assert(format(px) = "1.2.0.0/18");
407 bt_assert(192.168.0.0/16 ~ 192.168.0.0/16);
408 bt_assert(192.168.0.0/17 ~ 192.168.0.0/16);
409 bt_assert(192.168.254.0/24 ~ 192.168.0.0/16);
410 bt_assert(netdoc ~ 2001::/16);
411 bt_assert(192.168.0.0/15 !~ 192.168.0.0/16);
412 bt_assert(192.160.0.0/17 !~ 192.168.0.0/16);
413 bt_assert(px !~ netdoc);
414
415 bt_assert(1.2.3.4 ~ 1.0.0.0/8);
416 bt_assert(1.0.0.0/8 ~ 1.0.0.0/8);
417 }
418
419 bt_test_suite(t_prefix, "Testing prefixes");
420
421
422
423
424 /*
425 * Testing prefix sets
426 * -------------------
427 */
428
429 define net10 = 10.0.0.0/8;
430 define pxs2 = [ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ];
431
432 function test_pxset(prefix set pxs)
433 {
434 bt_assert(net10 ~ pxs);
435 bt_assert(10.0.0.0/10 ~ pxs);
436 bt_assert(10.0.0.0/12 ~ pxs);
437 bt_assert(20.0.0.0/24 ~ pxs);
438 bt_assert(20.0.40.0/24 ~ pxs);
439 bt_assert(20.0.0.0/26 ~ pxs);
440 bt_assert(20.0.100.0/26 ~ pxs);
441 bt_assert(20.0.0.0/28 ~ pxs);
442 bt_assert(20.0.255.0/28 ~ pxs);
443
444 bt_assert(10.0.0.0/7 !~ pxs);
445 bt_assert(10.0.0.0/13 !~ pxs);
446 bt_assert(10.0.0.0/16 !~ pxs);
447 bt_assert(20.0.0.0/16 !~ pxs);
448 bt_assert(20.0.0.0/23 !~ pxs);
449 bt_assert(20.0.0.0/29 !~ pxs);
450 bt_assert(11.0.0.0/10 !~ pxs);
451 bt_assert(20.1.0.0/26 !~ pxs);
452
453 bt_assert(1.0.0.0/8 ~ [ 1.0.0.0/8+ ]);
454 bt_assert(1.0.0.0/9 !~ [ 1.0.0.0/8- ]);
455 bt_assert(1.2.0.0/17 !~ [ 1.0.0.0/8{ 15 , 16 } ]);
456
457 bt_assert([ 10.0.0.0/8{ 15 , 17 } ] = [ 10.0.0.0/8{ 15 , 17 } ]);
458 }
459
460 function t_prefix_set()
461 prefix set pxs;
462 {
463 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} ];
464 bt_assert(format(pxs) = "[1.2.0.0/16{0.1.0.0}, 1.4.0.0/16{0.1.255.255}, 12.34.0.0/16{1.255.0.0}, 44.66.88.64/28{0.0.1.240}]");
465
466 bt_assert(1.2.0.0/16 ~ pxs);
467 bt_assert(1.4.0.0/16 ~ pxs);
468 bt_assert(1.4.0.0/18 ~ pxs);
469 bt_assert(1.4.0.0/32 ~ pxs);
470 bt_assert(1.1.0.0/16 !~ pxs);
471 bt_assert(1.3.0.0/16 !~ pxs);
472 bt_assert(1.2.0.0/15 !~ pxs);
473 bt_assert(1.2.0.0/17 !~ pxs);
474 bt_assert(1.2.0.0/32 !~ pxs);
475 bt_assert(1.4.0.0/15 !~ pxs);
476
477 test_pxset(pxs2);
478 test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
479
480 bt_assert(1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ]);
481 bt_assert([ 10.0.0.0/8{ 15 , 17 } ] != [ 11.0.0.0/8{ 15 , 17 } ]);
482 }
483
484 bt_test_suite(t_prefix_set, "Testing prefix sets");
485
486
487
488
489 /*
490 * Testing Prefix IPv6
491 * -------------------
492 */
493
494 function t_prefix6()
495 prefix px;
496 {
497 px = 1020::/18;
498 bt_assert(format(px) = "1020::/18");
499 bt_assert(1020:3040:5060:: ~ 1020:3040:5000::/40);
500 bt_assert(1020:3040::/32 ~ 1020:3040::/32);
501 bt_assert(1020:3040::/33 ~ 1020:3040::/32);
502 bt_assert(1020:3040:5060::/48 ~ 1020:3040::/32);
503 bt_assert(1020:3040::/31 !~ 1020:3040::/32);
504 bt_assert(1020:3041::/33 !~ 1020:3040::/32);
505 }
506
507 bt_test_suite(t_prefix6, "Testing prefix IPv6");
508
509
510
511
512 /*
513 * Testing prefix IPv6 sets
514 * ------------------------
515 */
516
517 function t_prefix6_set()
518 prefix set pxs;
519 {
520 bt_assert(1180::/16 ~ [ 1100::/8{15, 17} ]);
521 bt_assert(12::34 = 12::34);
522 bt_assert(12::34 ~ [ 12::33..12::35 ]);
523 bt_assert(1020::34 ~ 1000::/8);
524 bt_assert(1000::/8 ~ 1000::/8);
525 bt_assert(1000::/8 ~ [ 1000::/8+ ]);
526 bt_assert(12::34 !~ [ 12::33, 12::35 ]);
527 bt_assert(1000::/9 !~ [ 1000::/8- ]);
528 bt_assert(1000::/17 !~ [ 1000::/8{15, 16} ]);
529
530 pxs = [ 1102::/16, 1104::/16+];
531 bt_assert(1102::/16 ~ pxs);
532 bt_assert(1104::/16 ~ pxs);
533 bt_assert(1104::/18 ~ pxs);
534 bt_assert(1104::/32 ~ pxs);
535 bt_assert(1101::/16 !~ pxs);
536 bt_assert(1103::/16 !~ pxs);
537 bt_assert(1102::/15 !~ pxs);
538 bt_assert(1102::/17 !~ pxs);
539 bt_assert(1102::/32 !~ pxs);
540 bt_assert(1104::/15 !~ pxs);
541
542 pxs = ([ 1000::/16{8,12}, 2000::/16{24,28} ]);
543 bt_assert(format(pxs) = "[1000::/12{1f0::}, 2000::/16{0:1f0::}]");
544 bt_assert(1000::/8 ~ pxs);
545 bt_assert(1000::/10 ~ pxs);
546 bt_assert(1000::/12 ~ pxs);
547 bt_assert(2000::/24 ~ pxs);
548 bt_assert(2000:4000::/24 ~ pxs);
549 bt_assert(2000::/26 ~ pxs);
550 bt_assert(2000:8000::/26 ~ pxs);
551 bt_assert(2000::/28 ~ pxs);
552 bt_assert(2000:FFF0::/28 ~ pxs);
553 bt_assert(1000::/7 !~ pxs);
554 bt_assert(1000::/13 !~ pxs);
555 bt_assert(1000::/16 !~ pxs);
556 bt_assert(2000::/16 !~ pxs);
557 bt_assert(2000::/23 !~ pxs);
558 bt_assert(2000::/29 !~ pxs);
559 bt_assert(1100::/10 !~ pxs);
560 bt_assert(2010::/26 !~ pxs);
561 }
562
563 bt_test_suite(t_prefix6_set, "Testing prefix IPv6 sets");
564
565
566
567
568 function t_flowspec()
569 prefix p;
570 {
571 p = flow4 { dst 10.0.0.0/8; };
572 bt_assert(p !~ [ 10.0.0.0/8 ] );
573
574 bt_assert(format(flow4 { dst 10.0.0.0/8; proto = 23; }) = "flow4 { dst 10.0.0.0/8; proto 23; }");
575 bt_assert(format(flow6 { dst ::1/128; src ::2/127; }) = "flow6 { dst ::1/128; src ::2/127; }");
576 bt_assert(format(flow6 { next header false 42; }) = "flow6 { next header false 42; }");
577 bt_assert(format(flow6 { port 80; }) = "flow6 { port 80; }");
578 bt_assert(format(flow6 { dport > 24 && < 30 || 40..50,60..70,80 && >= 90; }) = "flow6 { dport > 24 && < 30 || 40..50,60..70,80 && >= 90; }");
579 bt_assert(format(flow6 { sport 0..0x400; }) = "flow6 { sport 0..1024; }");
580 bt_assert(format(flow6 { icmp type 80; }) = "flow6 { icmp type 80; }");
581 bt_assert(format(flow6 { icmp code 90; }) = "flow6 { icmp code 90; }");
582 bt_assert(format(flow6 { tcp flags 0x03/0x0f; }) = "flow6 { tcp flags 0x3/0x3 && 0x0/0xc; }");
583 bt_assert(format(flow6 { length 0..65535; }) = "flow6 { length 0..65535; }");
584 bt_assert(format(flow6 { dscp = 63; }) = "flow6 { dscp 63; }");
585 bt_assert(format(flow6 { fragment is_fragment || !first_fragment; }) = "flow6 { fragment is_fragment || !first_fragment; }");
586 bt_assert(format(flow6 { label 1000..2000; }) = "flow6 { label 1000..2000; }");
587 bt_assert(format(flow6 { }) = "flow6 { }");
588 }
589
590 bt_test_suite(t_flowspec, "Testing flowspec routes");
591
592
593
594
595 /*
596 * Testing Paths
597 * -------------
598 */
599
600 function mkpath(int a; int b)
601 {
602 return [= a b 3 2 1 =];
603 }
604
605 define set35 = [3 .. 5];
606
607 function t_path()
608 bgpmask pm1;
609 bgppath p2;
610 int set set12;
611 {
612 pm1 = [= 4 3 2 1 =];
613 set12 = [1, 2];
614
615 bt_assert(format(pm1) = "[= 4 3 2 1 =]");
616
617 bt_assert(+empty+ = +empty+);
618 bt_assert(10 !~ +empty+);
619
620 p2 = prepend( + empty +, 1 );
621 p2 = prepend( p2, 2 );
622 p2 = prepend( p2, 3 );
623 p2 = prepend( p2, 4 );
624
625 bt_assert(format(p2) = "(path 4 3 2 1)");
626 bt_assert(p2.len = 4);
627 bt_assert(p2 ~ pm1);
628 bt_assert(3 ~ p2);
629 bt_assert(p2 ~ [2, 10..20]);
630 bt_assert(p2 ~ [4, 10..20]);
631
632 p2 = prepend(p2, 5);
633 bt_assert(p2 !~ pm1);
634 bt_assert(10 !~ p2);
635 bt_assert(p2 !~ [8, ten..(2*ten)]);
636 bt_assert(p2 ~ [= * 4 3 * 1 =]);
637 bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
638 bt_assert(p2 ~ [= 5 [2, 4, 6] 3 [1..2] 1 =]);
639 bt_assert(p2 ~ [= 5 set35 3 set12 set12 =]);
640 bt_assert(p2 ~ mkpath(5, 4));
641
642 bt_assert(p2.len = 5);
643 bt_assert(p2.first = 5);
644 bt_assert(p2.last = 1);
645
646 bt_assert(p2.len = 5);
647 bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
648 bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
649
650 p2 = prepend( + empty +, 5 );
651 p2 = prepend( p2, 4 );
652 p2 = prepend( p2, 3 );
653 p2 = prepend( p2, 3 );
654 p2 = prepend( p2, 2 );
655 p2 = prepend( p2, 1 );
656
657 bt_assert(p2 !~ [= 1 2 3 4 5 =]);
658 bt_assert(p2 ~ [= 1 2 * 4 5 =]);
659 bt_assert(p2 ~ [= 1 2 * 3 4 5 =]);
660 bt_assert(p2 ~ [= 1 2 3+ 4 5 =]);
661 bt_assert(p2 ~ [= 1 2 3+ 4+ 5 =]);
662 bt_assert(p2 !~ [= 1 2 3+ 5+ 4 5 =]);
663 bt_assert(p2 !~ [= 1 2 3 3 5+ 4 5 =]);
664 bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
665 bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
666
667 bt_assert(format([= 1 2+ 3 =]) = "[= 1 2 + 3 =]");
668 }
669
670 bt_test_suite(t_path, "Testing paths");
671
672
673
674
675 /*
676 * Testing Community List
677 * ----------------------
678 */
679
680 define p23 = (2, 3);
681
682 function t_clist()
683 clist l;
684 clist l2;
685 clist r;
686 {
687 bt_assert((10, 20).asn = 10);
688 bt_assert((10, 20).data = 20);
689 bt_assert(p23.asn = 2);
690 bt_assert(p23.data = 3);
691
692 l = - empty -;
693 bt_assert(l !~ [(*,*)]);
694 bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
695
696 bt_assert(-empty- = -empty-);
697
698 l = add( l, (one,2) );
699 bt_assert(l ~ [(*,*)]);
700 l = add( l, (2,one+2) );
701 bt_assert(format(l) = "(clist (1,2) (2,3))");
702
703 bt_assert((2,3) ~ l);
704 bt_assert(l ~ [(1,*)]);
705 bt_assert(l ~ [p23]);
706 bt_assert(l ~ [(2,2..3)]);
707 bt_assert(l ~ [(1,1..2)]);
708 bt_assert(l ~ [(1,1)..(1,2)]);
709
710 l = add(l, (2,5));
711 l = add(l, (5,one));
712 l = add(l, (6,one));
713 l = add(l, (one,one));
714 l = delete(l, [(5,1),(6,one),(one,1)]);
715 l = delete(l, [(5,one),(6,one)]);
716 l = filter(l, [(1,*)]);
717 bt_assert(l = add(-empty-, (1,2)));
718
719 bt_assert((2,3) !~ l);
720 bt_assert(l !~ [(2,*)]);
721 bt_assert(l !~ [(one,3..6)]);
722 bt_assert(l ~ [(*,*)]);
723
724 l = add(l, (3,one));
725 l = add(l, (one+one+one,one+one));
726 l = add(l, (3,3));
727 l = add(l, (3,4));
728 l = add(l, (3,5));
729 l2 = filter(l, [(3,*)]);
730 l = delete(l, [(3,2..4)]);
731 bt_assert(l = add(add(add(-empty-, (1,2)), (3,1)), (3,5)));
732 bt_assert(l.len = 3);
733
734 l = add(l, (3,2));
735 l = add(l, (4,5));
736 bt_assert(l = add(add(add(add(add(-empty-, (1,2)), (3,1)), (3,5)), (3,2)), (4,5)));
737
738 bt_assert(l.len = 5);
739 bt_assert(l ~ [(*,2)]);
740 bt_assert(l ~ [(*,5)]);
741 bt_assert(l ~ [(*, one)]);
742 bt_assert(l !~ [(*,3)]);
743 bt_assert(l !~ [(*,(one+6))]);
744 bt_assert(l !~ [(*, (one+one+one))]);
745
746 l = delete(l, [(*,(one+onef(3)))]);
747 l = delete(l, [(*,(4+one))]);
748 bt_assert(l = add(-empty-, (3,1)));
749
750 l = delete(l, [(*,(onef(5)))]);
751 bt_assert(l = -empty-);
752
753 l2 = add(l2, (3,6));
754 l = filter(l2, [(3,1..4)]);
755 l2 = filter(l2, [(3,3..6)]);
756
757 # clist A (10,20,30)
758 bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
759 bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))");
760
761 # clist B (30,40,50)
762 bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
763 bt_assert(format(l2) = "(clist (3,3) (3,4) (3,5) (3,6))");
764
765 # clist A union B
766 r = add(l, l2);
767 bt_assert(r = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
768 bt_assert(format(r) = "(clist (3,1) (3,2) (3,3) (3,4) (3,5) (3,6))");
769
770 # clist A isect B
771 r = filter(l, l2);
772 bt_assert(r = add(add(-empty-, (3,3)), (3,4)));
773 bt_assert(format(r) = "(clist (3,3) (3,4))");
774
775 # clist A \ B
776 r = delete(l, l2);
777 bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
778 bt_assert(format(r) = "(clist (3,1) (3,2))");
779
780 # clist in c set
781 r = filter(l, [(3,1), (*,2)]);
782 bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
783 bt_assert(format(r) = "(clist (3,1) (3,2))");
784 }
785
786 bt_test_suite(t_clist, "Testing lists of communities");
787
788
789
790
791 /*
792 * Testing Extended Communities
793 * ----------------------------
794 */
795
796 function t_ec()
797 ec cc;
798 {
799 cc = (rt, 12345, 200000);
800 bt_assert(format(cc) = "(rt, 12345, 200000)");
801
802 bt_assert(cc = (rt, 12345, 200000));
803 bt_assert(cc < (rt, 12345, 200010));
804 bt_assert(cc != (rt, 12346, 200000));
805 bt_assert(cc != (ro, 12345, 200000));
806 bt_assert(!(cc > (rt, 12345, 200010)));
807
808 bt_assert(format((ro, 100000, 20000)) = "(ro, 100000, 20000)");
809 }
810
811 bt_test_suite(t_ec, "Testing extended communities");
812
813
814
815
816 /*
817 * Testing Extended Community List
818 * -------------------------------
819 */
820
821 function t_eclist()
822 eclist el;
823 eclist el2;
824 eclist r;
825 {
826 el = -- empty --;
827 el = add(el, (rt, 10, 20));
828 el = add(el, (ro, 10.20.30.40, 100));
829 el = add(el, (ro, 11.21.31.41.mask(16), 200));
830
831 bt_assert(--empty-- = --empty--);
832 bt_assert(((rt, 10, 20)) !~ --empty--);
833
834 bt_assert(format(el) = "(eclist (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200))");
835 bt_assert(el.len = 3);
836 el = delete(el, (rt, 10, 20));
837 el = delete(el, (rt, 10, 30));
838 bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
839 el = add(el, (unknown 2, ten, 1));
840 el = add(el, (unknown 5, ten, 1));
841 el = add(el, (rt, ten, one+one));
842 el = add(el, (rt, 10, 3));
843 el = add(el, (rt, 10, 4));
844 el = add(el, (rt, 10, 5));
845 el = add(el, (generic, 0x2000a, 3*ten));
846 el = delete(el, [(rt, 10, 2..ten)]);
847 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)));
848
849 el = filter(el, [(rt, 10, *)]);
850 bt_assert(el = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
851 bt_assert((rt, 10, 1) ~ el);
852 bt_assert(el ~ [(rt, 10, ten..40)]);
853 bt_assert((rt, 10, 20) !~ el);
854 bt_assert((ro, 10.20.30.40, 100) !~ el);
855 bt_assert(el !~ [(rt, 10, 35..40)]);
856 bt_assert(el !~ [(ro, 10, *)]);
857
858 el = add(el, (rt, 10, 40));
859 el2 = filter(el, [(rt, 10, 20..40)] );
860 el2 = add(el2, (rt, 10, 50));
861
862 # eclist A (1,30,40)
863 bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
864 bt_assert(format(el) = "(eclist (rt, 10, 1) (rt, 10, 30) (rt, 10, 40))");
865
866 # eclist B (30,40,50)
867 bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
868 bt_assert(format(el2) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50))");
869
870 # eclist A union B
871 r = add(el2, el);
872 bt_assert(r = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
873 bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50) (rt, 10, 1))");
874
875 # eclist A isect B
876 r = filter(el, el2);
877 bt_assert(r = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
878 bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40))");
879
880 # eclist A \ B
881 r = delete(el, el2);
882 bt_assert(r = add(--empty--, (rt, 10, 1)));
883 bt_assert(format(r) = "(eclist (rt, 10, 1))");
884
885 # eclist in ec set
886 r = filter(el, [(rt, 10, 1), (rt, 10, 25..30), (ro, 10, 40)]);
887 bt_assert(r = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
888 bt_assert(format(r) = "(eclist (rt, 10, 1) (rt, 10, 30))");
889 }
890
891 bt_test_suite(t_eclist, "Testing lists of extended communities");
892
893
894
895
896 /*
897 * Testing sets of Extended Communities
898 * ------------------------------------
899 */
900
901 define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
902
903 function t_ec_set()
904 ec set ecs;
905 {
906 ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
907 bt_assert(format(ecs) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
908 bt_assert(format(ecs2) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
909
910 bt_assert((rt, 10, 20) ~ ecs);
911 bt_assert((ro, 100000, 100) ~ ecs);
912 bt_assert((ro, 100000, 128) ~ ecs);
913 bt_assert((ro, 100000, 200) ~ ecs);
914 bt_assert((rt, 12345, 0) ~ ecs);
915 bt_assert((rt, 12345, 200000) ~ ecs);
916 bt_assert((rt, 12345, 4000000) ~ ecs);
917 bt_assert((ro, 10, 20) !~ ecs);
918 bt_assert((rt, 10, 21) !~ ecs);
919 bt_assert((ro, 100000, 99) !~ ecs);
920 bt_assert((ro, 12345, 10) !~ ecs);
921 bt_assert((rt, 12346, 0) !~ ecs);
922 bt_assert((ro, 0.1.134.160, 150) !~ ecs);
923 }
924
925 bt_test_suite(t_ec_set, "Testing sets of extended communities");
926
927
928
929
930 /*
931 * Testing Large Communities
932 * -------------------------
933 */
934
935 function mktrip(int a)
936 {
937 return (a, 2*a, 3*a);
938 }
939
940 function t_lclist()
941 lclist ll;
942 lclist ll2;
943 lclist r;
944 {
945 bt_assert(---empty--- = ---empty---);
946 bt_assert((10, 20, 30) !~ ---empty---);
947
948 bt_assert((10, 20, 30).asn = 10);
949 bt_assert((10, 20, 30).data1 = 20);
950 bt_assert((10, 20, 30).data2 = 30);
951
952 ll = --- empty ---;
953 ll = add(ll, (ten, 20, 30));
954 ll = add(ll, (1000, 2000, 3000));
955 ll = add(ll, mktrip(100000));
956 bt_assert(format(ll) = "(lclist (10, 20, 30) (1000, 2000, 3000) (100000, 200000, 300000))");
957 bt_assert(ll.len = 3);
958 bt_assert(ll = add(add(add(---empty---, (10, 20, 30)), (1000, 2000, 3000)), (100000, 200000, 300000)));
959
960 bt_assert(mktrip(1000) ~ ll);
961 bt_assert(mktrip(100) !~ ll);
962
963 ll = --- empty ---;
964 ll = add(ll, (10, 10, 10));
965 ll = add(ll, (20, 20, 20));
966 ll = add(ll, (30, 30, 30));
967
968 ll2 = --- empty ---;
969 ll2 = add(ll2, (20, 20, 20));
970 ll2 = add(ll2, (30, 30, 30));
971 ll2 = add(ll2, (40, 40, 40));
972
973 # lclist A (10, 20, 30)
974 bt_assert(format(ll) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30))");
975
976 # lclist B (20, 30, 40)
977 bt_assert(format(ll2) = "(lclist (20, 20, 20) (30, 30, 30) (40, 40, 40))");
978
979 # lclist A union B
980 r = add(ll, ll2);
981 bt_assert(r = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));
982 bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30) (40, 40, 40))");
983
984 # lclist A isect B
985 r = filter(ll, ll2);
986 bt_assert(r = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));
987 bt_assert(format(r) = "(lclist (20, 20, 20) (30, 30, 30))");
988
989 # lclist A \ B
990 r = delete(ll, ll2);
991 bt_assert(r = add(---empty---, (10, 10, 10)));
992 bt_assert(format(r) = "(lclist (10, 10, 10))");
993
994 # lclist in lc set
995 r = filter(ll, [(5..15, *, *), (20, 15..25, *)]);
996 bt_assert(r = add(add(---empty---, (10, 10, 10)), (20, 20, 20)));
997 bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20))");
998 }
999
1000 bt_test_suite(t_lclist, "Testing lists of large communities");
1001
1002
1003
1004
1005 /*
1006 * Testing sets of Large Communities
1007 * ---------------------------------
1008 */
1009
1010 function t_lclist_set()
1011 lclist ll;
1012 lc set lls;
1013 {
1014 ll = --- empty ---;
1015 ll = add(ll, (10, 20, 30));
1016 ll = add(ll, (1000, 2000, 3000));
1017 ll = add(ll, mktrip(100000));
1018
1019 bt_assert(ll ~ [(5,10,15), (10,20,30)]);
1020 bt_assert(ll ~ [(10,15..25,*)]);
1021 bt_assert(ll ~ [(ten, *, *)]);
1022
1023 bt_assert(ll !~ [(5,10,15), (10,21,30)]);
1024 bt_assert(ll !~ [(10,21..25,*)]);
1025 bt_assert(ll !~ [(11, *, *)]);
1026
1027 lls = [(10, 10, 10), (20, 20, 15..25), (30, 30, *), (40, 35..45, *), (50, *, *), (55..65, *, *)];
1028 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)]");
1029 bt_assert((10, 10, 10) ~ lls);
1030 bt_assert((20, 20, 25) ~ lls);
1031 bt_assert((20, 20, 26) !~ lls);
1032 bt_assert((30, 30, 0) ~ lls);
1033 bt_assert((40, 35, 40) ~ lls);
1034 bt_assert((40, 34, 40) !~ lls);
1035 bt_assert((50, 0, 0) ~ lls);
1036 bt_assert((60, 60, 60) ~ lls);
1037 bt_assert((70, 60, 60) !~ lls);
1038 }
1039
1040 bt_test_suite(t_lclist_set, "Testing sets of large communities");
1041
1042
1043
1044
1045 /*
1046 * Testing Route Distinguishers
1047 * ----------------------------
1048 */
1049
1050 function t_rd()
1051 rd x;
1052 {
1053 x = 12345:20000;
1054 bt_assert(format(x) = "12345:20000");
1055
1056 bt_assert(x = 12345:20000);
1057 bt_assert(x < 12345:20010);
1058 bt_assert(x != 12346:20000);
1059 bt_assert(x != 2:12345:20000);
1060 bt_assert(!(x > 12345:200010));
1061
1062 bt_assert(format(0:1:2) = "1:2");
1063 bt_assert(format(10.0.0.1:1000) = "10.0.0.1:1000");
1064 bt_assert(format(100000:20000) = "100000:20000");
1065 bt_assert(format(2:100000:20000) = "100000:20000");
1066 bt_assert(format(2:1000:1000) = "2:1000:1000");
1067 }
1068
1069 bt_test_suite(t_rd, "Testing route distinguishers");
1070
1071
1072
1073
1074 /*
1075 * Testing sets of Route Distinguishers
1076 * ------------------------------------
1077 */
1078
1079 function t_rd_set()
1080 rd set rds;
1081 {
1082 rds = [10:20, 100000:100..100000:200];
1083 bt_assert(format(rds) = "[10:20, 100000:100..100000:200]");
1084
1085 bt_assert(10:20 ~ rds);
1086 bt_assert(10:21 !~ rds);
1087 bt_assert(100000:90 !~ rds);
1088 bt_assert(100000:100 ~ rds);
1089 bt_assert(100000:128 ~ rds);
1090 bt_assert(100000:200 ~ rds);
1091 bt_assert(100010:150 !~ rds);
1092 }
1093
1094 bt_test_suite(t_rd_set, "Testing sets of route distinguishers");
1095
1096
1097
1098
1099 /*
1100 * Testing defined() function
1101 * --------------------------
1102 */
1103
1104 function test_undef(int a)
1105 int b;
1106 {
1107 if a = 3 then {
1108 b = 4;
1109 bt_assert(defined(b));
1110 }
1111 else {
1112 bt_assert(!defined(b));
1113 }
1114 }
1115
1116 function t_define()
1117 int i;
1118 {
1119 test_undef(2);
1120 test_undef(3);
1121 test_undef(2);
1122
1123 bt_assert(defined(1));
1124 bt_assert(defined(1.2.3.4));
1125 }
1126
1127 bt_test_suite(t_define, "Testing defined() function");
1128
1129
1130
1131
1132 /*
1133 * Testing calling functions
1134 * -------------------------
1135 */
1136
1137 function callme(int arg1; int arg2)
1138 int i;
1139 {
1140 case arg1 {
1141 1, 42: return 42;
1142 else: return arg1 * arg2;
1143 }
1144
1145 return 0;
1146 }
1147
1148 function callmeagain(int a; int b; int c)
1149 {
1150 return a + b + c;
1151 }
1152
1153 function fifteen()
1154 {
1155 return 15;
1156 }
1157
1158 function t_call_function()
1159 {
1160 bt_assert(fifteen() = 15);
1161
1162 bt_assert(callme(1, 2) = 42);
1163 bt_assert(callme(42, 2) = 42);
1164
1165 bt_assert(callme(2, 2) = 4);
1166 bt_assert(callme(3, 2) = 6);
1167 bt_assert(callme(4, 4) = 16);
1168 bt_assert(callme(7, 2) = 14);
1169 bt_assert(callmeagain(1, 2, 3) = 6);
1170 }
1171
1172 bt_test_suite(t_call_function, "Testing calling functions");
1173
1174
1175
1176
1177 /*
1178 * Test including another config file
1179 * ----------------------------------
1180 */
1181
1182 function t_include()
1183 int i;
1184 {
1185 i = 1;
1186 include "test.conf.inc";
1187 bt_assert(i = 42);
1188 }
1189
1190 bt_test_suite(t_include, "Testing including another config file");
1191
1192
1193
1194
1195 /*
1196 * Test if-else statement
1197 * ----------------------
1198 */
1199
1200 function t_if_else()
1201 int i;
1202 {
1203 /* Empty blocks regression test */
1204 if true then {}
1205 else {}
1206
1207 if true then
1208 bt_assert(true);
1209
1210 if false then
1211 bt_assert(false);
1212 else if true then
1213 bt_assert(true);
1214 else
1215 bt_assert(false);
1216
1217 /* Empty blocks regression test */
1218 if true then {}
1219 else {}
1220 }
1221
1222 bt_test_suite(t_if_else, "Testing if-else statement");
1223
1224
1225
1226
1227 /*
1228 * Unused functions -- testing only parsing
1229 * ----------------------------------------
1230 */
1231
1232 function __test1()
1233 {
1234 if source ~ [ RTS_BGP, RTS_STATIC ] then {
1235 # ospf_metric1 = 65535;
1236 # ospf_metric2 = 1000;
1237 ospf_tag = 0x12345678;
1238 accept;
1239 }
1240 reject;
1241 }
1242
1243 function __test2()
1244 {
1245 if source ~ [ RTS_BGP, RTS_STATIC ] then {
1246 # ospf_metric1 = 65535;
1247 # ospf_metric2 = 1000;
1248 ospf_tag = 0x12345678;
1249 accept;
1250 }
1251 reject;
1252 }
1253
1254 filter testf
1255 int j;
1256 {
1257 print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
1258 print "This route was from ", from;
1259 j = 7;
1260 j = 17;
1261 if rip_metric > 15 then {
1262 reject "RIP Metric is more than infinity";
1263 }
1264 rip_metric = 14;
1265 unset(rip_metric);
1266
1267 accept "ok I take that";
1268 }
1269
1270 filter roa_filter
1271 {
1272 if net ~ [ 10.0.0.0/8{16,24} ] || net ~ [ 2000::/3{16,96} ] then {
1273 accept;
1274 }
1275 reject;
1276 }
1277
1278 roa4 table r4;
1279 roa6 table r6;
1280
1281 protocol static
1282 {
1283 roa4 { table r4; import filter roa_filter; };
1284 route 10.110.0.0/16 max 16 as 1000;
1285 route 10.120.0.0/16 max 24 as 1000;
1286 route 10.130.0.0/16 max 24 as 2000;
1287 route 10.130.128.0/18 max 24 as 3000;
1288 }
1289
1290 protocol static
1291 {
1292 roa6 { table r6; import filter roa_filter; };
1293 route 2001:0db8:85a3:8a2e::/64 max 96 as 1000;
1294 }
1295
1296 function t_roa_check()
1297 prefix pfx;
1298 {
1299 bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
1300 bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
1301 bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
1302 bt_assert(roa_check(r4, 10.110.0.0/16, 2000) = ROA_INVALID);
1303 bt_assert(roa_check(r4, 10.110.32.0/20, 1000) = ROA_INVALID);
1304 bt_assert(roa_check(r4, 10.120.32.0/20, 1000) = ROA_VALID);
1305 bt_assert(roa_check(r4, 10.120.32.0/20, 2000) = ROA_INVALID);
1306 bt_assert(roa_check(r4, 10.120.32.32/28, 1000) = ROA_INVALID);
1307 bt_assert(roa_check(r4, 10.130.130.0/24, 1000) = ROA_INVALID);
1308 bt_assert(roa_check(r4, 10.130.130.0/24, 2000) = ROA_VALID);
1309 bt_assert(roa_check(r4, 10.130.30.0/24, 3000) = ROA_INVALID);
1310 bt_assert(roa_check(r4, 10.130.130.0/24, 3000) = ROA_VALID);
1311
1312 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1313 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1314 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e::/64, 1000) = ROA_VALID);
1315 bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1316
1317 bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
1318 bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
1319 bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
1320 bt_assert(roa_check(r4, 10.110.0.0/16, 2000) = ROA_INVALID);
1321 bt_assert(roa_check(r4, 10.110.32.0/20, 1000) = ROA_INVALID);
1322 bt_assert(roa_check(r4, 10.120.32.0/20, 1000) = ROA_VALID);
1323
1324 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1325 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1326 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e::/64, 1000) = ROA_VALID);
1327 bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1328
1329 bt_assert(roa_check(r4, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_UNKNOWN);
1330 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
1331
1332 bt_assert(roa_check(r4, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_UNKNOWN);
1333 bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
1334 bt_assert(roa_check(r4, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1335 bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
1336
1337 bt_assert(10.130.130.0/24 ~ 0.0.0.0/0);
1338 bt_assert(2001:0db8:85a3:8a2e::/64 ~ ::/0);
1339 bt_assert(10.130.130.0/24 !~ ::/0);
1340 bt_assert(2001:0db8:85a3:8a2e::/64 !~ 0.0.0.0/0);
1341
1342 pfx = 12.13.0.0/16 max 24 as 1234;
1343 bt_assert(pfx.len = 16);
1344 bt_assert(pfx.maxlen = 24);
1345 bt_assert(pfx.asn = 1234);
1346
1347 pfx = 1000::/8 max 32 as 1234;
1348 bt_assert(pfx.len = 8);
1349 bt_assert(pfx.maxlen = 32);
1350 bt_assert(pfx.asn = 1234);
1351 }
1352
1353 bt_test_suite(t_roa_check, "Testing ROA");
1354
1355
1356
1357
1358 filter vpn_filter
1359 {
1360 bt_assert(format(net) = "1:2 10.1.10.0/24");
1361 bt_assert(net.type = NET_VPN4);
1362 bt_assert(net.type != NET_IP4);
1363 bt_assert(net.type != NET_IP6);
1364 bt_assert(net.rd = 0:1:2);
1365
1366 case (net.type) {
1367 NET_IP4: print "IPV4";
1368 NET_IP6: print "IPV6";
1369 }
1370
1371 bt_check_assign(from, 10.20.30.40);
1372 bt_check_assign(gw, 55.55.55.44);
1373
1374 bgp_community.add((3,5));
1375 bgp_ext_community.add((ro, 135, 999));
1376 bgp_large_community.add((6464156, 89646354, 8675643));
1377
1378 accept;
1379 }
1380
1381 vpn4 table v4;
1382 vpn4 table v6;
1383
1384 protocol static
1385 {
1386 vpn4 { table v4; import filter vpn_filter; };
1387 route 0:1:2 10.1.10.0/24 unreachable;
1388 }
1389
1390 protocol static
1391 {
1392 ipv6 { import where false; };
1393 route fd01::/48 unreachable;
1394 }