Annotation of embedaddon/bird2/filter/test.conf, revision 1.1
1.1 ! misho 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: define set35 = [3 .. 5];
! 601:
! 602: function t_path()
! 603: bgpmask pm1;
! 604: bgppath p2;
! 605: int set set12;
! 606: {
! 607: pm1 = [= 4 3 2 1 =];
! 608: set12 = [1, 2];
! 609:
! 610: bt_assert(format(pm1) = "[= 4 3 2 1 =]");
! 611:
! 612: bt_assert(+empty+ = +empty+);
! 613: bt_assert(10 !~ +empty+);
! 614:
! 615: p2 = prepend( + empty +, 1 );
! 616: p2 = prepend( p2, 2 );
! 617: p2 = prepend( p2, 3 );
! 618: p2 = prepend( p2, 4 );
! 619:
! 620: bt_assert(format(p2) = "(path 4 3 2 1)");
! 621: bt_assert(p2.len = 4);
! 622: bt_assert(p2 ~ pm1);
! 623: bt_assert(3 ~ p2);
! 624: bt_assert(p2 ~ [2, 10..20]);
! 625: bt_assert(p2 ~ [4, 10..20]);
! 626:
! 627: p2 = prepend(p2, 5);
! 628: bt_assert(p2 !~ pm1);
! 629: bt_assert(10 !~ p2);
! 630: bt_assert(p2 !~ [8, ten..(2*ten)]);
! 631: bt_assert(p2 ~ [= * 4 3 * 1 =]);
! 632: bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
! 633: bt_assert(p2 ~ [= 5 [2, 4, 6] 3 [1..2] 1 =]);
! 634: bt_assert(p2 ~ [= 5 set35 3 set12 set12 =]);
! 635: bt_assert(p2 ~ mkpath(5, 4));
! 636:
! 637: bt_assert(p2.len = 5);
! 638: bt_assert(p2.first = 5);
! 639: bt_assert(p2.last = 1);
! 640:
! 641: bt_assert(p2.len = 5);
! 642: bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
! 643: bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
! 644:
! 645: pm1 = [= 1 2 * 3 4 5 =];
! 646: p2 = prepend( + empty +, 5 );
! 647: p2 = prepend( p2, 4 );
! 648: p2 = prepend( p2, 3 );
! 649: p2 = prepend( p2, 3 );
! 650: p2 = prepend( p2, 2 );
! 651: p2 = prepend( p2, 1 );
! 652:
! 653: bt_assert(p2 ~ pm1);
! 654: bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
! 655: bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
! 656: }
! 657:
! 658: bt_test_suite(t_path, "Testing paths");
! 659:
! 660:
! 661:
! 662:
! 663: /*
! 664: * Testing Community List
! 665: * ----------------------
! 666: */
! 667:
! 668: define p23 = (2, 3);
! 669:
! 670: function t_clist()
! 671: clist l;
! 672: clist l2;
! 673: clist r;
! 674: {
! 675: l = - empty -;
! 676: bt_assert(l !~ [(*,*)]);
! 677: bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
! 678:
! 679: bt_assert(-empty- = -empty-);
! 680:
! 681: l = add( l, (one,2) );
! 682: bt_assert(l ~ [(*,*)]);
! 683: l = add( l, (2,one+2) );
! 684: bt_assert(format(l) = "(clist (1,2) (2,3))");
! 685:
! 686: bt_assert((2,3) ~ l);
! 687: bt_assert(l ~ [(1,*)]);
! 688: bt_assert(l ~ [p23]);
! 689: bt_assert(l ~ [(2,2..3)]);
! 690: bt_assert(l ~ [(1,1..2)]);
! 691: bt_assert(l ~ [(1,1)..(1,2)]);
! 692:
! 693: l = add(l, (2,5));
! 694: l = add(l, (5,one));
! 695: l = add(l, (6,one));
! 696: l = add(l, (one,one));
! 697: l = delete(l, [(5,1),(6,one),(one,1)]);
! 698: l = delete(l, [(5,one),(6,one)]);
! 699: l = filter(l, [(1,*)]);
! 700: bt_assert(l = add(-empty-, (1,2)));
! 701:
! 702: bt_assert((2,3) !~ l);
! 703: bt_assert(l !~ [(2,*)]);
! 704: bt_assert(l !~ [(one,3..6)]);
! 705: bt_assert(l ~ [(*,*)]);
! 706:
! 707: l = add(l, (3,one));
! 708: l = add(l, (one+one+one,one+one));
! 709: l = add(l, (3,3));
! 710: l = add(l, (3,4));
! 711: l = add(l, (3,5));
! 712: l2 = filter(l, [(3,*)]);
! 713: l = delete(l, [(3,2..4)]);
! 714: bt_assert(l = add(add(add(-empty-, (1,2)), (3,1)), (3,5)));
! 715: bt_assert(l.len = 3);
! 716:
! 717: l = add(l, (3,2));
! 718: l = add(l, (4,5));
! 719: bt_assert(l = add(add(add(add(add(-empty-, (1,2)), (3,1)), (3,5)), (3,2)), (4,5)));
! 720:
! 721: bt_assert(l.len = 5);
! 722: bt_assert(l ~ [(*,2)]);
! 723: bt_assert(l ~ [(*,5)]);
! 724: bt_assert(l ~ [(*, one)]);
! 725: bt_assert(l !~ [(*,3)]);
! 726: bt_assert(l !~ [(*,(one+6))]);
! 727: bt_assert(l !~ [(*, (one+one+one))]);
! 728:
! 729: l = delete(l, [(*,(one+onef(3)))]);
! 730: l = delete(l, [(*,(4+one))]);
! 731: bt_assert(l = add(-empty-, (3,1)));
! 732:
! 733: l = delete(l, [(*,(onef(5)))]);
! 734: bt_assert(l = -empty-);
! 735:
! 736: l2 = add(l2, (3,6));
! 737: l = filter(l2, [(3,1..4)]);
! 738: l2 = filter(l2, [(3,3..6)]);
! 739:
! 740: # clist A (10,20,30)
! 741: bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
! 742: bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))");
! 743:
! 744: # clist B (30,40,50)
! 745: bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
! 746: bt_assert(format(l2) = "(clist (3,3) (3,4) (3,5) (3,6))");
! 747:
! 748: # clist A union B
! 749: r = add(l, l2);
! 750: bt_assert(r = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
! 751: bt_assert(format(r) = "(clist (3,1) (3,2) (3,3) (3,4) (3,5) (3,6))");
! 752:
! 753: # clist A isect B
! 754: r = filter(l, l2);
! 755: bt_assert(r = add(add(-empty-, (3,3)), (3,4)));
! 756: bt_assert(format(r) = "(clist (3,3) (3,4))");
! 757:
! 758: # clist A \ B
! 759: r = delete(l, l2);
! 760: bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
! 761: bt_assert(format(r) = "(clist (3,1) (3,2))");
! 762:
! 763: # clist in c set
! 764: r = filter(l, [(3,1), (*,2)]);
! 765: bt_assert(r = add(add(-empty-, (3,1)), (3,2)));
! 766: bt_assert(format(r) = "(clist (3,1) (3,2))");
! 767: }
! 768:
! 769: bt_test_suite(t_clist, "Testing lists of communities");
! 770:
! 771:
! 772:
! 773:
! 774: /*
! 775: * Testing Extended Communities
! 776: * ----------------------------
! 777: */
! 778:
! 779: function t_ec()
! 780: ec cc;
! 781: {
! 782: cc = (rt, 12345, 200000);
! 783: bt_assert(format(cc) = "(rt, 12345, 200000)");
! 784:
! 785: bt_assert(cc = (rt, 12345, 200000));
! 786: bt_assert(cc < (rt, 12345, 200010));
! 787: bt_assert(cc != (rt, 12346, 200000));
! 788: bt_assert(cc != (ro, 12345, 200000));
! 789: bt_assert(!(cc > (rt, 12345, 200010)));
! 790:
! 791: bt_assert(format((ro, 100000, 20000)) = "(ro, 100000, 20000)");
! 792: }
! 793:
! 794: bt_test_suite(t_ec, "Testing extended communities");
! 795:
! 796:
! 797:
! 798:
! 799: /*
! 800: * Testing Extended Community List
! 801: * -------------------------------
! 802: */
! 803:
! 804: function t_eclist()
! 805: eclist el;
! 806: eclist el2;
! 807: eclist r;
! 808: {
! 809: el = -- empty --;
! 810: el = add(el, (rt, 10, 20));
! 811: el = add(el, (ro, 10.20.30.40, 100));
! 812: el = add(el, (ro, 11.21.31.41.mask(16), 200));
! 813:
! 814: bt_assert(--empty-- = --empty--);
! 815: bt_assert(((rt, 10, 20)) !~ --empty--);
! 816:
! 817: bt_assert(format(el) = "(eclist (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200))");
! 818: bt_assert(el.len = 3);
! 819: el = delete(el, (rt, 10, 20));
! 820: el = delete(el, (rt, 10, 30));
! 821: bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
! 822: el = add(el, (unknown 2, ten, 1));
! 823: el = add(el, (unknown 5, ten, 1));
! 824: el = add(el, (rt, ten, one+one));
! 825: el = add(el, (rt, 10, 3));
! 826: el = add(el, (rt, 10, 4));
! 827: el = add(el, (rt, 10, 5));
! 828: el = add(el, (generic, 0x2000a, 3*ten));
! 829: el = delete(el, [(rt, 10, 2..ten)]);
! 830: 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)));
! 831:
! 832: el = filter(el, [(rt, 10, *)]);
! 833: bt_assert(el = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
! 834: bt_assert((rt, 10, 1) ~ el);
! 835: bt_assert(el ~ [(rt, 10, ten..40)]);
! 836: bt_assert((rt, 10, 20) !~ el);
! 837: bt_assert((ro, 10.20.30.40, 100) !~ el);
! 838: bt_assert(el !~ [(rt, 10, 35..40)]);
! 839: bt_assert(el !~ [(ro, 10, *)]);
! 840:
! 841: el = add(el, (rt, 10, 40));
! 842: el2 = filter(el, [(rt, 10, 20..40)] );
! 843: el2 = add(el2, (rt, 10, 50));
! 844:
! 845: # eclist A (1,30,40)
! 846: bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
! 847: bt_assert(format(el) = "(eclist (rt, 10, 1) (rt, 10, 30) (rt, 10, 40))");
! 848:
! 849: # eclist B (30,40,50)
! 850: bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
! 851: bt_assert(format(el2) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50))");
! 852:
! 853: # eclist A union B
! 854: r = add(el2, el);
! 855: bt_assert(r = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
! 856: bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50) (rt, 10, 1))");
! 857:
! 858: # eclist A isect B
! 859: r = filter(el, el2);
! 860: bt_assert(r = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
! 861: bt_assert(format(r) = "(eclist (rt, 10, 30) (rt, 10, 40))");
! 862:
! 863: # eclist A \ B
! 864: r = delete(el, el2);
! 865: bt_assert(r = add(--empty--, (rt, 10, 1)));
! 866: bt_assert(format(r) = "(eclist (rt, 10, 1))");
! 867:
! 868: # eclist in ec set
! 869: r = filter(el, [(rt, 10, 1), (rt, 10, 25..30), (ro, 10, 40)]);
! 870: bt_assert(r = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
! 871: bt_assert(format(r) = "(eclist (rt, 10, 1) (rt, 10, 30))");
! 872: }
! 873:
! 874: bt_test_suite(t_eclist, "Testing lists of extended communities");
! 875:
! 876:
! 877:
! 878:
! 879: /*
! 880: * Testing sets of Extended Communities
! 881: * ------------------------------------
! 882: */
! 883:
! 884: define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
! 885:
! 886: function t_ec_set()
! 887: ec set ecs;
! 888: {
! 889: ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
! 890: bt_assert(format(ecs) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
! 891: bt_assert(format(ecs2) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
! 892:
! 893: bt_assert((rt, 10, 20) ~ ecs);
! 894: bt_assert((ro, 100000, 100) ~ ecs);
! 895: bt_assert((ro, 100000, 128) ~ ecs);
! 896: bt_assert((ro, 100000, 200) ~ ecs);
! 897: bt_assert((rt, 12345, 0) ~ ecs);
! 898: bt_assert((rt, 12345, 200000) ~ ecs);
! 899: bt_assert((rt, 12345, 4000000) ~ ecs);
! 900: bt_assert((ro, 10, 20) !~ ecs);
! 901: bt_assert((rt, 10, 21) !~ ecs);
! 902: bt_assert((ro, 100000, 99) !~ ecs);
! 903: bt_assert((ro, 12345, 10) !~ ecs);
! 904: bt_assert((rt, 12346, 0) !~ ecs);
! 905: bt_assert((ro, 0.1.134.160, 150) !~ ecs);
! 906: }
! 907:
! 908: bt_test_suite(t_ec_set, "Testing sets of extended communities");
! 909:
! 910:
! 911:
! 912:
! 913: /*
! 914: * Testing Large Communities
! 915: * -------------------------
! 916: */
! 917:
! 918: function mktrip(int a)
! 919: {
! 920: return (a, 2*a, 3*a);
! 921: }
! 922:
! 923: function t_lclist()
! 924: lclist ll;
! 925: lclist ll2;
! 926: lclist r;
! 927: {
! 928: bt_assert(---empty--- = ---empty---);
! 929: bt_assert((10, 20, 30) !~ ---empty---);
! 930:
! 931: ll = --- empty ---;
! 932: ll = add(ll, (ten, 20, 30));
! 933: ll = add(ll, (1000, 2000, 3000));
! 934: ll = add(ll, mktrip(100000));
! 935: bt_assert(format(ll) = "(lclist (10, 20, 30) (1000, 2000, 3000) (100000, 200000, 300000))");
! 936: bt_assert(ll.len = 3);
! 937: bt_assert(ll = add(add(add(---empty---, (10, 20, 30)), (1000, 2000, 3000)), (100000, 200000, 300000)));
! 938:
! 939: bt_assert(mktrip(1000) ~ ll);
! 940: bt_assert(mktrip(100) !~ ll);
! 941:
! 942: ll = --- empty ---;
! 943: ll = add(ll, (10, 10, 10));
! 944: ll = add(ll, (20, 20, 20));
! 945: ll = add(ll, (30, 30, 30));
! 946:
! 947: ll2 = --- empty ---;
! 948: ll2 = add(ll2, (20, 20, 20));
! 949: ll2 = add(ll2, (30, 30, 30));
! 950: ll2 = add(ll2, (40, 40, 40));
! 951:
! 952: # lclist A (10, 20, 30)
! 953: bt_assert(format(ll) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30))");
! 954:
! 955: # lclist B (20, 30, 40)
! 956: bt_assert(format(ll2) = "(lclist (20, 20, 20) (30, 30, 30) (40, 40, 40))");
! 957:
! 958: # lclist A union B
! 959: r = add(ll, ll2);
! 960: bt_assert(r = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));
! 961: bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30) (40, 40, 40))");
! 962:
! 963: # lclist A isect B
! 964: r = filter(ll, ll2);
! 965: bt_assert(r = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));
! 966: bt_assert(format(r) = "(lclist (20, 20, 20) (30, 30, 30))");
! 967:
! 968: # lclist A \ B
! 969: r = delete(ll, ll2);
! 970: bt_assert(r = add(---empty---, (10, 10, 10)));
! 971: bt_assert(format(r) = "(lclist (10, 10, 10))");
! 972:
! 973: # lclist in lc set
! 974: r = filter(ll, [(5..15, *, *), (20, 15..25, *)]);
! 975: bt_assert(r = add(add(---empty---, (10, 10, 10)), (20, 20, 20)));
! 976: bt_assert(format(r) = "(lclist (10, 10, 10) (20, 20, 20))");
! 977: }
! 978:
! 979: bt_test_suite(t_lclist, "Testing lists of large communities");
! 980:
! 981:
! 982:
! 983:
! 984: /*
! 985: * Testing sets of Large Communities
! 986: * ---------------------------------
! 987: */
! 988:
! 989: function t_lclist_set()
! 990: lclist ll;
! 991: lc set lls;
! 992: {
! 993: ll = --- empty ---;
! 994: ll = add(ll, (10, 20, 30));
! 995: ll = add(ll, (1000, 2000, 3000));
! 996: ll = add(ll, mktrip(100000));
! 997:
! 998: bt_assert(ll ~ [(5,10,15), (10,20,30)]);
! 999: bt_assert(ll ~ [(10,15..25,*)]);
! 1000: bt_assert(ll ~ [(ten, *, *)]);
! 1001:
! 1002: bt_assert(ll !~ [(5,10,15), (10,21,30)]);
! 1003: bt_assert(ll !~ [(10,21..25,*)]);
! 1004: bt_assert(ll !~ [(11, *, *)]);
! 1005:
! 1006: lls = [(10, 10, 10), (20, 20, 15..25), (30, 30, *), (40, 35..45, *), (50, *, *), (55..65, *, *)];
! 1007: 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)]");
! 1008: bt_assert((10, 10, 10) ~ lls);
! 1009: bt_assert((20, 20, 25) ~ lls);
! 1010: bt_assert((20, 20, 26) !~ lls);
! 1011: bt_assert((30, 30, 0) ~ lls);
! 1012: bt_assert((40, 35, 40) ~ lls);
! 1013: bt_assert((40, 34, 40) !~ lls);
! 1014: bt_assert((50, 0, 0) ~ lls);
! 1015: bt_assert((60, 60, 60) ~ lls);
! 1016: bt_assert((70, 60, 60) !~ lls);
! 1017: }
! 1018:
! 1019: bt_test_suite(t_lclist_set, "Testing sets of large communities");
! 1020:
! 1021:
! 1022:
! 1023:
! 1024: /*
! 1025: * Testing Route Distinguishers
! 1026: * ----------------------------
! 1027: */
! 1028:
! 1029: function t_rd()
! 1030: rd x;
! 1031: {
! 1032: x = 12345:20000;
! 1033: bt_assert(format(x) = "12345:20000");
! 1034:
! 1035: bt_assert(x = 12345:20000);
! 1036: bt_assert(x < 12345:20010);
! 1037: bt_assert(x != 12346:20000);
! 1038: bt_assert(x != 2:12345:20000);
! 1039: bt_assert(!(x > 12345:200010));
! 1040:
! 1041: bt_assert(format(10.0.0.1:1000) = "10.0.0.1:1000");
! 1042: bt_assert(format(100000:20000) = "100000:20000");
! 1043: bt_assert(format(2:100000:20000) = "100000:20000");
! 1044: bt_assert(format(2:1000:1000) = "2:1000:1000");
! 1045: }
! 1046:
! 1047: bt_test_suite(t_rd, "Testing route distinguishers");
! 1048:
! 1049:
! 1050:
! 1051:
! 1052: /*
! 1053: * Testing sets of Route Distinguishers
! 1054: * ------------------------------------
! 1055: */
! 1056:
! 1057: function t_rd_set()
! 1058: rd set rds;
! 1059: {
! 1060: rds = [10:20, 100000:100..100000:200];
! 1061: bt_assert(format(rds) = "[10:20, 100000:100..100000:200]");
! 1062:
! 1063: bt_assert(10:20 ~ rds);
! 1064: bt_assert(10:21 !~ rds);
! 1065: bt_assert(100000:90 !~ rds);
! 1066: bt_assert(100000:100 ~ rds);
! 1067: bt_assert(100000:128 ~ rds);
! 1068: bt_assert(100000:200 ~ rds);
! 1069: bt_assert(100010:150 !~ rds);
! 1070: }
! 1071:
! 1072: bt_test_suite(t_rd_set, "Testing sets of route distinguishers");
! 1073:
! 1074:
! 1075:
! 1076:
! 1077: /*
! 1078: * Testing defined() function
! 1079: * --------------------------
! 1080: */
! 1081:
! 1082: function test_undef(int a)
! 1083: int b;
! 1084: {
! 1085: if a = 3 then {
! 1086: b = 4;
! 1087: bt_assert(defined(b));
! 1088: }
! 1089: else {
! 1090: bt_assert(!defined(b));
! 1091: }
! 1092: }
! 1093:
! 1094: function t_define()
! 1095: int i;
! 1096: {
! 1097: test_undef(2);
! 1098: test_undef(3);
! 1099: test_undef(2);
! 1100:
! 1101: bt_assert(defined(1));
! 1102: bt_assert(defined(1.2.3.4));
! 1103: }
! 1104:
! 1105: bt_test_suite(t_define, "Testing defined() function");
! 1106:
! 1107:
! 1108:
! 1109:
! 1110: /*
! 1111: * Testing calling functions
! 1112: * -------------------------
! 1113: */
! 1114:
! 1115: function callme(int arg1; int arg2)
! 1116: int i;
! 1117: {
! 1118: case arg1 {
! 1119: 1, 42: return 42;
! 1120: else: return arg1 * arg2;
! 1121: }
! 1122:
! 1123: return 0;
! 1124: }
! 1125:
! 1126: function callmeagain(int a; int b; int c)
! 1127: {
! 1128: return a + b + c;
! 1129: }
! 1130:
! 1131: function fifteen()
! 1132: {
! 1133: return 15;
! 1134: }
! 1135:
! 1136: function t_call_function()
! 1137: {
! 1138: bt_assert(fifteen() = 15);
! 1139:
! 1140: bt_assert(callme(1, 2) = 42);
! 1141: bt_assert(callme(42, 2) = 42);
! 1142:
! 1143: bt_assert(callme(2, 2) = 4);
! 1144: bt_assert(callme(3, 2) = 6);
! 1145: bt_assert(callme(4, 4) = 16);
! 1146: bt_assert(callme(7, 2) = 14);
! 1147: bt_assert(callmeagain(1, 2, 3) = 6);
! 1148: }
! 1149:
! 1150: bt_test_suite(t_call_function, "Testing calling functions");
! 1151:
! 1152:
! 1153:
! 1154:
! 1155: /*
! 1156: * Test including another config file
! 1157: * ----------------------------------
! 1158: */
! 1159:
! 1160: function t_include()
! 1161: int i;
! 1162: {
! 1163: i = 1;
! 1164: include "test.conf.inc";
! 1165: bt_assert(i = 42);
! 1166: }
! 1167:
! 1168: bt_test_suite(t_include, "Testing including another config file");
! 1169:
! 1170:
! 1171:
! 1172:
! 1173: /*
! 1174: * Test if-else statement
! 1175: * ----------------------
! 1176: */
! 1177:
! 1178: function t_if_else()
! 1179: int i;
! 1180: {
! 1181: /* Empty blocks regression test */
! 1182: if true then {}
! 1183: else {}
! 1184:
! 1185: if true then
! 1186: bt_assert(true);
! 1187:
! 1188: if false then
! 1189: bt_assert(false);
! 1190: else if true then
! 1191: bt_assert(true);
! 1192: else
! 1193: bt_assert(false);
! 1194:
! 1195: /* Empty blocks regression test */
! 1196: if true then {}
! 1197: else {}
! 1198: }
! 1199:
! 1200: bt_test_suite(t_if_else, "Testing if-else statement");
! 1201:
! 1202:
! 1203:
! 1204:
! 1205: /*
! 1206: * Unused functions -- testing only parsing
! 1207: * ----------------------------------------
! 1208: */
! 1209:
! 1210: function __test1()
! 1211: {
! 1212: if source ~ [ RTS_BGP, RTS_STATIC ] then {
! 1213: # ospf_metric1 = 65535;
! 1214: # ospf_metric2 = 1000;
! 1215: ospf_tag = 0x12345678;
! 1216: accept;
! 1217: }
! 1218: reject;
! 1219: }
! 1220:
! 1221: function __test2()
! 1222: {
! 1223: if source ~ [ RTS_BGP, RTS_STATIC ] then {
! 1224: # ospf_metric1 = 65535;
! 1225: # ospf_metric2 = 1000;
! 1226: ospf_tag = 0x12345678;
! 1227: accept;
! 1228: }
! 1229: reject;
! 1230: }
! 1231:
! 1232: filter testf
! 1233: int j;
! 1234: {
! 1235: print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
! 1236: print "This route was from ", from;
! 1237: j = 7;
! 1238: j = 17;
! 1239: if rip_metric > 15 then {
! 1240: reject "RIP Metric is more than infinity";
! 1241: }
! 1242: rip_metric = 14;
! 1243: unset(rip_metric);
! 1244:
! 1245: accept "ok I take that";
! 1246: }
! 1247:
! 1248: filter roa_filter
! 1249: {
! 1250: if net ~ [ 10.0.0.0/8{16,24}, 2000::/3{16,96} ] then {
! 1251: accept;
! 1252: }
! 1253: reject;
! 1254: }
! 1255:
! 1256: roa4 table r4;
! 1257: roa6 table r6;
! 1258:
! 1259: protocol static
! 1260: {
! 1261: roa4 { table r4; import filter roa_filter; };
! 1262: route 10.110.0.0/16 max 16 as 1000;
! 1263: route 10.120.0.0/16 max 24 as 1000;
! 1264: route 10.130.0.0/16 max 24 as 2000;
! 1265: route 10.130.128.0/18 max 24 as 3000;
! 1266: }
! 1267:
! 1268: protocol static
! 1269: {
! 1270: roa6 { table r6; import filter roa_filter; };
! 1271: route 2001:0db8:85a3:8a2e::/64 max 96 as 1000;
! 1272: }
! 1273:
! 1274: function test_roa_check()
! 1275: prefix pfx;
! 1276: {
! 1277: # cannot be tested in __startup(), sorry
! 1278: bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
! 1279: bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
! 1280: bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
! 1281: bt_assert(roa_check(r4, 10.110.0.0/16, 2000) = ROA_INVALID);
! 1282: bt_assert(roa_check(r4, 10.110.32.0/20, 1000) = ROA_INVALID);
! 1283: bt_assert(roa_check(r4, 10.120.32.0/20, 1000) = ROA_VALID);
! 1284: bt_assert(roa_check(r4, 10.120.32.0/20, 2000) = ROA_INVALID);
! 1285: bt_assert(roa_check(r4, 10.120.32.32/28, 1000) = ROA_INVALID);
! 1286: bt_assert(roa_check(r4, 10.130.130.0/24, 1000) = ROA_INVALID);
! 1287: bt_assert(roa_check(r4, 10.130.130.0/24, 2000) = ROA_VALID);
! 1288: bt_assert(roa_check(r4, 10.130.30.0/24, 3000) = ROA_INVALID);
! 1289: bt_assert(roa_check(r4, 10.130.130.0/24, 3000) = ROA_VALID);
! 1290:
! 1291: bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
! 1292: bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
! 1293: bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e::/64, 1000) = ROA_VALID);
! 1294: bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
! 1295:
! 1296: bt_assert(roa_check(r4, 10.10.0.0/16, 1000) = ROA_UNKNOWN);
! 1297: bt_assert(roa_check(r4, 10.0.0.0/8, 1000) = ROA_UNKNOWN);
! 1298: bt_assert(roa_check(r4, 10.110.0.0/16, 1000) = ROA_VALID);
! 1299: bt_assert(roa_check(r4, 10.110.0.0/16, 2000) = ROA_INVALID);
! 1300: bt_assert(roa_check(r4, 10.110.32.0/20, 1000) = ROA_INVALID);
! 1301: bt_assert(roa_check(r4, 10.120.32.0/20, 1000) = ROA_VALID);
! 1302:
! 1303: bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
! 1304: bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
! 1305: bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e::/64, 1000) = ROA_VALID);
! 1306: bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
! 1307:
! 1308: bt_assert(roa_check(r4, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_UNKNOWN);
! 1309: bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/97, 1000) = ROA_INVALID);
! 1310:
! 1311: bt_assert(roa_check(r4, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_UNKNOWN);
! 1312: bt_assert(roa_check(r6, 2001:0db8:85a3:8a2e:1234::/80, 1000) = ROA_VALID);
! 1313: bt_assert(roa_check(r4, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
! 1314: bt_assert(roa_check(r6, 2001:0db8:85a3::/48, 1000) = ROA_UNKNOWN);
! 1315:
! 1316: bt_assert(10.130.130.0/24 ~ 0.0.0.0/0);
! 1317: bt_assert(2001:0db8:85a3:8a2e::/64 ~ ::/0);
! 1318: bt_assert(10.130.130.0/24 !~ ::/0);
! 1319: bt_assert(2001:0db8:85a3:8a2e::/64 !~ 0.0.0.0/0);
! 1320:
! 1321: pfx = 12.13.0.0/16 max 24 as 1234;
! 1322: bt_assert(pfx.len = 16);
! 1323: bt_assert(pfx.maxlen = 24);
! 1324: bt_assert(pfx.asn = 1234);
! 1325:
! 1326: pfx = 1000::/8 max 32 as 1234;
! 1327: bt_assert(pfx.len = 8);
! 1328: bt_assert(pfx.maxlen = 32);
! 1329: bt_assert(pfx.asn = 1234);
! 1330: }
! 1331:
! 1332: bt_test_suite(test_roa_check, "Testing ROA");
! 1333:
! 1334: /*
! 1335: * Testing Mixed Net Types
! 1336: * -----------------------
! 1337: */
! 1338:
! 1339: function t_mixed_prefix()
! 1340: prefix set pxs;
! 1341: prefix set pxt;
! 1342: {
! 1343: pxs = [ 98.45.0.0/16, 128.128.0.0/12+, 2200::/42-, ::ffff:d000:0/100{98,102}];
! 1344: 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::}]");
! 1345: bt_assert(::fe00:0:0/88 !~ pxs);
! 1346: bt_assert(::fffe:0:0/95 !~ pxs);
! 1347: bt_assert(::ffff:d800:0/101 ~ pxs);
! 1348: bt_assert(216.0.0.0/5 ~ pxs);
! 1349: bt_assert(212.0.0.0/6 ~ pxs);
! 1350: bt_assert(212.0.0.0/7 !~ pxs);
! 1351: bt_assert(::ffff:8080:8080/121 ~ pxs);
! 1352: bt_assert(::/0 ~ pxs);
! 1353: bt_assert(0.0.0.0/0 !~ pxs);
! 1354: bt_assert(128.135.64.17/32 ~ pxs);
! 1355:
! 1356: # pxt = [ 0:1:2 10.1.10.0/24, 0:5:10000 10.1.10.0/24 ];
! 1357: # print pxt;
! 1358:
! 1359: bt_assert(format(NET_IP4) = "(enum 36)1"); ## if (net.type = NET_IP4) ...
! 1360: bt_assert(format(NET_VPN6) = "(enum 36)4");
! 1361: bt_assert(format(0:1:2) = "1:2");
! 1362: }
! 1363:
! 1364: bt_test_suite(t_mixed_prefix, "Testing mixed net types");
! 1365:
! 1366:
! 1367: filter vpn_filter
! 1368: {
! 1369: bt_assert(format(net) = "1:2 10.1.10.0/24");
! 1370: bt_assert(net.type = NET_VPN4);
! 1371: bt_assert(net.type != NET_IP4);
! 1372: bt_assert(net.type != NET_IP6);
! 1373: bt_assert(net.rd = 0:1:2);
! 1374:
! 1375: case (net.type) {
! 1376: NET_IP4: print "IPV4";
! 1377: NET_IP6: print "IPV6";
! 1378: }
! 1379:
! 1380: bt_check_assign(from, 10.20.30.40);
! 1381: bt_check_assign(gw, 55.55.55.44);
! 1382:
! 1383: bgp_community.add((3,5));
! 1384: bgp_ext_community.add((ro, 135, 999));
! 1385: bgp_large_community.add((6464156, 89646354, 8675643));
! 1386:
! 1387: accept;
! 1388: }
! 1389:
! 1390: vpn4 table v4;
! 1391: vpn4 table v6;
! 1392:
! 1393: protocol static
! 1394: {
! 1395: vpn4 { table v4; import filter vpn_filter; };
! 1396: route 0:1:2 10.1.10.0/24 unreachable;
! 1397: }
! 1398:
! 1399: protocol static
! 1400: {
! 1401: ipv6 { import where false; };
! 1402: route fd01::/48 unreachable;
! 1403: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>