summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
Diffstat (limited to 'filter')
-rw-r--r--filter/test.conf998
1 files changed, 492 insertions, 506 deletions
diff --git a/filter/test.conf b/filter/test.conf
index a350e0fb..c926092c 100644
--- a/filter/test.conf
+++ b/filter/test.conf
@@ -29,329 +29,6 @@ function onef(int a)
/*
- * Testing empty lists/paths
- * -------------------------
- */
-
-function t_empty()
-{
- bt_assert(+empty+ = +empty+);
- bt_assert(+empty+ != -empty-);
- bt_assert(+empty+ != --empty--);
-
- bt_assert(-empty- = -empty-);
- bt_assert(-empty- != --empty--);
-
- bt_assert(--empty-- = --empty--);
-}
-
-bt_test_suite(t_empty, "Testing +empty+, -empty-, --empty--");
-
-
-
-
-/*
- * Testing Paths
- * -------------
- */
-
-function mkpath(int a; int b)
-{
- return [= a b 3 2 1 =];
-}
-
-function t_path()
-bgpmask pm1;
-bgpmask pm2;
-bgppath p2;
-{
- pm1 = / 4 3 2 1 /;
- pm2 = [= 4 3 2 1 =];
-
- p2 = prepend( + empty +, 1 );
- p2 = prepend( p2, 2 );
- p2 = prepend( p2, 3 );
- p2 = prepend( p2, 4 );
-
- bt_assert(format(p2) = "(path 4 3 2 1)");
- bt_assert(p2.len = 4);
- bt_assert(p2 ~ pm1);
- bt_assert(p2 ~ pm2);
- bt_assert(3 ~ p2);
- bt_assert(p2 ~ [2, 10..20]);
- bt_assert(p2 ~ [4, 10..20]);
-
- p2 = prepend(p2, 5);
- bt_assert(p2 !~ pm1);
- bt_assert(p2 !~ pm2);
- bt_assert(10 !~ p2);
- bt_assert(p2 !~ [8, ten..(2*ten)]);
- bt_assert(p2 ~ / ? 4 3 2 1 /);
- bt_assert(p2 ~ [= * 4 3 * 1 =]);
- bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
- bt_assert(p2 ~ mkpath(5, 4));
-
- bt_assert(p2.len = 5);
- bt_assert(p2.first = 5);
- bt_assert(p2.last = 1);
-
- bt_assert(p2.len = 5);
- bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
- bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
-
- pm1 = [= 1 2 * 3 4 5 =];
- p2 = prepend( + empty +, 5 );
- p2 = prepend( p2, 4 );
- p2 = prepend( p2, 3 );
- p2 = prepend( p2, 3 );
- p2 = prepend( p2, 2 );
- p2 = prepend( p2, 1 );
-
- bt_assert(p2 ~ pm1);
- bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
- bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
-}
-
-bt_test_suite(t_path, "Testing paths");
-
-
-
-
-/*
- * Testing Community List
- * ----------------------
- */
-
-define p23 = (2, 3);
-
-function t_community_list()
-clist l;
-clist l2;
-{
- /* XXX: add((x,y)) works as prepend */
-
- l = - empty -;
- bt_assert(l !~ [(*,*)]);
- bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
-
- l = add( l, (one,2) );
- bt_assert(l ~ [(*,*)]);
- l = add( l, (2,one+2) );
- bt_assert(format(l) = "(clist (1,2) (2,3))");
-
- bt_assert((2,3) ~ l);
- bt_assert(l ~ [(1,*)]);
- bt_assert(l ~ [p23]);
- bt_assert(l ~ [(2,2..3)]);
- bt_assert(l ~ [(1,1..2)]);
- bt_assert(l ~ [(1,1)..(1,2)]);
-
- l = add(l, (2,5));
- l = add(l, (5,one));
- l = add(l, (6,one));
- l = add(l, (one,one));
- l = delete(l, [(5,1),(6,one),(one,1)]);
- l = delete(l, [(5,one),(6,one)]);
- l = filter(l, [(1,*)]);
- bt_assert(l = add(-empty-, (1,2)));
-
- bt_assert((2,3) !~ l);
- bt_assert(l !~ [(2,*)]);
- bt_assert(l !~ [(one,3..6)]);
- bt_assert(l ~ [(*,*)]);
-
- l = add(l, (3,one));
- l = add(l, (one+one+one,one+one));
- l = add(l, (3,3));
- l = add(l, (3,4));
- l = add(l, (3,5));
- l2 = filter(l, [(3,*)]);
- l = delete(l, [(3,2..4)]);
- bt_assert(l = add(add(add(-empty-, (1,2)), (3,1)), (3,5)));
- bt_assert(l.len = 3);
-
- l = add(l, (3,2));
- l = add(l, (4,5));
- bt_assert(l = add(add(add(add(add(-empty-, (1,2)), (3,1)), (3,5)), (3,2)), (4,5)));
-
- bt_assert(l.len = 5);
- bt_assert(l ~ [(*,2)]);
- bt_assert(l ~ [(*,5)]);
- bt_assert(l ~ [(*, one)]);
- bt_assert(l !~ [(*,3)]);
- bt_assert(l !~ [(*,(one+6))]);
- bt_assert(l !~ [(*, (one+one+one))]);
-
- l = delete(l, [(*,(one+onef(3)))]);
- l = delete(l, [(*,(4+one))]);
- bt_assert(l = add(-empty-, (3,1)));
-
- l = delete(l, [(*,(onef(5)))]);
- bt_assert(l = -empty-);
-
- l2 = add(l2, (3,6));
- l = filter(l2, [(3,1..4)]);
- l2 = filter(l2, [(3,3..6)]);
-
- # lclist A (10,20,30)
- bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))");
- bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
-
- # lclist B (30,40,50)
- bt_assert(format(l2) = "(clist (3,3) (3,4) (3,5) (3,6))");
- bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
-
- # lclist A union B
- bt_assert(format(add(l, l2)) = "(clist (3,1) (3,2) (3,3) (3,4) (3,5) (3,6))");
- bt_assert(add(l, l2) = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
-
- # lclist A isect B
- bt_assert(format(filter(l, l2)) = "(clist (3,3) (3,4))");
- bt_assert(filter(l, l2) = add(add(-empty-, (3,3)), (3,4)));
-
- # lclist A \ B
- bt_assert(format(delete(l, l2)) = "(clist (3,1) (3,2))");
- bt_assert(delete(l, l2) = add(add(-empty-, (3,1)), (3,2)));
-}
-
-bt_test_suite(t_community_list, "Testing communities and lists");
-
-
-
-
-/*
- * Testing Extended Community List
- * -------------------------------
- */
-
-function t_extended_community_list()
-eclist el;
-eclist el2;
-{
- el = -- empty --;
- el = add(el, (rt, 10, 20));
- el = add(el, (ro, 10.20.30.40, 100));
- el = add(el, (ro, 11.21.31.41.mask(16), 200));
-
- bt_assert(format(el) = "(eclist (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200))");
- bt_assert(el.len = 3);
- el = delete(el, (rt, 10, 20));
- el = delete(el, (rt, 10, 30));
- bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
- el = add(el, (unknown 2, ten, 1));
- el = add(el, (unknown 5, ten, 1));
- el = add(el, (rt, ten, one+one));
- el = add(el, (rt, 10, 3));
- el = add(el, (rt, 10, 4));
- el = add(el, (rt, 10, 5));
- el = add(el, (generic, 0x2000a, 3*ten));
- el = delete(el, [(rt, 10, 2..ten)]);
- 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)));
-
- el = filter(el, [(rt, 10, *)]);
- bt_assert(el = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
- bt_assert((rt, 10, 1) ~ el);
- bt_assert(el ~ [(rt, 10, ten..40)]);
- bt_assert((rt, 10, 20) !~ el);
- bt_assert((ro, 10.20.30.40, 100) !~ el);
- bt_assert(el !~ [(rt, 10, 35..40)]);
- bt_assert(el !~ [(ro, 10, *)]);
-
- el = add(el, (rt, 10, 40));
- el2 = filter(el, [(rt, 10, 20..40)] );
- el2 = add(el2, (rt, 10, 50));
-
- # eclist A (1,30,40)
- bt_assert(format(el) = "(eclist (rt, 10, 1) (rt, 10, 30) (rt, 10, 40))");
- bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
-
- # eclist B (30,40,50)
- bt_assert(format(el2) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50))");
- bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
-
- # eclist A union B
- bt_assert(format(add(el2, el)) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50) (rt, 10, 1))");
- bt_assert(add(el2, el) = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
-
- # eclist A isect B
- bt_assert(format(filter(el, el2)) = "(eclist (rt, 10, 30) (rt, 10, 40))");
- bt_assert(filter(el, el2) = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
-
- # eclist A \ B
- bt_assert(format(delete(el, el2)) = "(eclist (rt, 10, 1))");
- bt_assert(delete(el, el2) = add(--empty--, (rt, 10, 1)));
-}
-
-bt_test_suite(t_extended_community_list, "Testing extended communities and lists");
-
-
-
-
-/*
- * Testing Long Communities
- * ------------------------
- */
-
-function mktrip(int a)
-{
- return (a, 2*a, 3*a);
-}
-
-function t_long_community_list()
-lclist ll;
-lclist ll2;
-{
- ll = --- empty ---;
- ll = add(ll, (ten, 20, 30));
- ll = add(ll, (1000, 2000, 3000));
- ll = add(ll, mktrip(100000));
- bt_assert(format(ll) = "(lclist (10, 20, 30) (1000, 2000, 3000) (100000, 200000, 300000))");
- bt_assert(ll.len = 3);
- bt_assert(ll = add(add(add(---empty---, (10, 20, 30)), (1000, 2000, 3000)), (100000, 200000, 300000)));
-
- bt_assert(mktrip(1000) ~ ll);
- bt_assert(mktrip(100) !~ ll);
-
- bt_assert(ll ~ [(5,10,15), (10,20,30)]);
- bt_assert(ll ~ [(10,15..25,*)]);
- bt_assert(ll ~ [(ten, *, *)]);
-
- bt_assert(ll !~ [(5,10,15), (10,21,30)]);
- bt_assert(ll !~ [(10,21..25,*)]);
- bt_assert(ll !~ [(11, *, *)]);
-
- ll2 = filter(ll, [(5..15, *, *), (100000, 500..500000, *)]);
- bt_assert(ll2 = add(add(---empty---, (10, 20, 30)), (100000, 200000, 300000)));
-
- ll = --- empty ---;
- ll = add(ll, (10, 10, 10));
- ll = add(ll, (20, 20, 20));
- ll = add(ll, (30, 30, 30));
-
- ll2 = --- empty ---;
- ll2 = add(ll2, (20, 20, 20));
- ll2 = add(ll2, (30, 30, 30));
- ll2 = add(ll2, (40, 40, 40));
-
- bt_assert(format(ll) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30))");
- bt_assert(format(ll2) = "(lclist (20, 20, 20) (30, 30, 30) (40, 40, 40))");
-
- bt_assert(format(add(ll, ll2)) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30) (40, 40, 40))");
- bt_assert(add(ll, ll2) = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));
-
- bt_assert(format(filter(ll, ll2)) = "(lclist (20, 20, 20) (30, 30, 30))");
- bt_assert(filter(ll, ll2) = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));
-
- bt_assert(format(delete(ll, ll2)) = "(lclist (10, 10, 10))");
- bt_assert(delete(ll, ll2) = add(---empty---, (10, 10, 10)));
-}
-
-bt_test_suite(t_long_community_list, "Testing long communities and lists");
-
-
-
-
-/*
* Testing defined() function
* --------------------------
*/
@@ -385,97 +62,93 @@ bt_test_suite(t_define, "Testing defined() function");
/*
- * Testing quads
- * -------------
+ * Testing calling functions
+ * -------------------------
*/
-function t_quad()
-quad qq;
+function callme(int arg1; int arg2)
+int i;
{
- qq = 1.2.3.4;
- bt_assert(format(qq) = "1.2.3.4");
- bt_assert(qq = 1.2.3.4);
- bt_assert(qq != 4.3.2.1);
-}
-
-bt_test_suite(t_quad, "Testing quads");
+ case arg1 {
+ 1, 42: return 42;
+ else: return arg1 * arg2;
+ }
+ return 0;
+}
+function fifteen()
+{
+ return 15;
+}
+function t_call_function()
+{
+ bt_assert(fifteen() = 15);
-/*
- * Testing sets of quads
- * ---------------------
- */
+ bt_assert(callme(1, 2) = 42);
+ bt_assert(callme(42, 2) = 42);
-function t_quad_set()
-quad qq;
-{
- qq = 1.2.3.4;
- bt_assert(qq ~ [1.2.3.4, 5.6.7.8]);
- bt_assert(qq !~ [1.2.1.1, 1.2.3.5]);
+ bt_assert(callme(2, 2) = 4);
+ bt_assert(callme(3, 2) = 6);
+ bt_assert(callme(4, 4) = 16);
+ bt_assert(callme(7, 2) = 14);
}
-bt_test_suite(t_quad_set, "Testing sets of quads");
+bt_test_suite(t_call_function, "Testing calling functions");
/*
- * Testing Extended Communities
- * ----------------------------
+ * Test including another config file
+ * ----------------------------------
*/
-function t_ec()
-ec cc;
+function t_include()
+int i;
{
- cc = (rt, 12345, 200000);
- bt_assert(format(cc) = "(rt, 12345, 200000)");
-
- bt_assert(cc = (rt, 12345, 200000));
- bt_assert(cc < (rt, 12345, 200010));
- bt_assert(cc != (rt, 12346, 200000));
- bt_assert(cc != (ro, 12345, 200000));
- bt_assert(!(cc > (rt, 12345, 200010)));
-
- bt_assert(format((ro, 100000, 20000)) = "(ro, 100000, 20000)");
+ i = 1;
+ include "test.conf.inc";
+ bt_assert(i = 42);
}
-bt_test_suite(t_ec, "Testing Extended Communities");
+bt_test_suite(t_include, "Testing including another config file");
/*
- * Testing sets of Extended Communities
- * ------------------------------------
+ * Testing boolean expressions
+ * ---------------------------
*/
-define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
-
-function t_ec_set()
-ec set ecs;
+function t_bool()
+bool b;
{
- ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
- bt_assert(format(ecs) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
- bt_assert(format(ecs2) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
+ b = true;
+ bt_assert(b);
+ bt_assert(!!b);
- bt_assert((rt, 10, 20) ~ ecs);
- bt_assert((ro, 100000, 100) ~ ecs);
- bt_assert((ro, 100000, 128) ~ ecs);
- bt_assert((ro, 100000, 200) ~ ecs);
- bt_assert((rt, 12345, 0) ~ ecs);
- bt_assert((rt, 12345, 200000) ~ ecs);
- bt_assert((rt, 12345, 4000000) ~ ecs);
- bt_assert((ro, 10, 20) !~ ecs);
- bt_assert((rt, 10, 21) !~ ecs);
- bt_assert((ro, 100000, 99) !~ ecs);
- bt_assert((ro, 12345, 10) !~ ecs);
- bt_assert((rt, 12346, 0) !~ ecs);
- bt_assert((ro, 0.1.134.160, 150) !~ ecs);
+ bt_assert(format(true) = "TRUE");
+ bt_assert(format(false) = "FALSE");
+
+ if ( b = true ) then
+ bt_assert(b);
+ else
+ bt_assert(false);
+
+ bt_assert(true && true);
+ bt_assert(true || false);
+ bt_assert(! false && ! false && true);
+ bt_assert(1 < 2 && 1 != 3);
+ bt_assert(true && true && ! false);
+ bt_assert(true || 1+"a");
+ bt_assert(!(false && 1+"a"));
+ bt_assert(!(true && false));
}
-bt_test_suite(t_ec_set, "Testing sets of Extended Communities");
+bt_test_suite(t_bool, "Testing boolean expressions");
@@ -500,6 +173,8 @@ int i;
i = (i + 0);
bt_assert(i = 1234);
+ bt_assert(format(i) = "1234");
+
if (i = 4) then
bt_assert(false);
else
@@ -604,57 +279,23 @@ bt_test_suite(t_int_set, "Testing sets of integers");
/*
- * Testing ip address
- * ------------------
- */
-
-define onetwo = 1.2.3.4;
-
-function t_ip()
-ip p;
-{
- p = 127.1.2.3;
- bt_assert(p.mask(8) = 127.0.0.0);
- bt_assert(1.2.3.4 = 1.2.3.4);
- bt_assert(1.2.3.4 = onetwo);
- bt_assert(format(onetwo) = "1.2.3.4");
-}
-
-bt_test_suite(t_ip, "Testing ip address");
-
-
-
-
-/*
- * Testing sets of ip address
- * --------------------------
- */
-
-function t_ip_set()
-{
- bt_assert(1.2.3.4 !~ [ 1.2.3.3, 1.2.3.5 ]);
- bt_assert(1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ]);
-}
-
-bt_test_suite(t_ip_set, "Testing sets of ip address");
-
-
-
-
-/*
- * Testing enums
- * -------------
+ * Testing string matching
+ * -----------------------
*/
-function t_enum()
+function t_string()
+string st;
{
- bt_assert(format(RTS_DUMMY) = "(enum 30)0"); /* XXX */
- bt_assert(format(RTS_STATIC) = "(enum 30)1"); /* XXX */
- bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
- bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
+ st = "Hello";
+ bt_assert(format(st) = "Hello");
+ bt_assert(st ~ "Hell*");
+ bt_assert(st ~ "?ello");
+ bt_assert(st ~ "Hello");
+ bt_assert(st ~ "Hell?");
+ bt_assert(st !~ "ell*");
}
-bt_test_suite(t_enum, "Testing enums");
+bt_test_suite(t_string, "Testing string matching");
@@ -734,55 +375,110 @@ bt_test_suite(t_pair_set, "Testing sets of pairs");
/*
- * Testing string matching
- * -----------------------
+ * Testing quads
+ * -------------
*/
-function t_string()
-string st;
+function t_quad()
+quad qq;
{
- st = "Hello";
- bt_assert(format(st) = "Hello");
- bt_assert(st ~ "Hell*");
- bt_assert(st ~ "?ello");
- bt_assert(st ~ "Hello");
- bt_assert(st ~ "Hell?");
- bt_assert(st !~ "ell*");
+ qq = 1.2.3.4;
+ bt_assert(format(qq) = "1.2.3.4");
+ bt_assert(qq = 1.2.3.4);
+ bt_assert(qq != 4.3.2.1);
}
-bt_test_suite(t_string, "Testing string matching");
+bt_test_suite(t_quad, "Testing quads");
/*
- * Testing boolean expressions
- * ---------------------------
+ * Testing sets of quads
+ * ---------------------
*/
-function t_bool()
-bool b;
+function t_quad_set()
+quad qq;
{
- b = true;
- bt_assert(b);
- bt_assert(!!b);
+ qq = 1.2.3.4;
+ bt_assert(qq ~ [1.2.3.4, 5.6.7.8]);
+ bt_assert(qq !~ [1.2.1.1, 1.2.3.5]);
+}
- if ( b = true ) then
- bt_assert(b);
- else
- bt_assert(false);
+bt_test_suite(t_quad_set, "Testing sets of quads");
- bt_assert(true && true);
- bt_assert(true || false);
- bt_assert(! false && ! false && true);
- bt_assert(1 < 2 && 1 != 3);
- bt_assert(true && true && ! false);
- bt_assert(true || 1+"a");
- bt_assert(!(false && 1+"a"));
- bt_assert(!(true && false));
+
+
+
+/*
+ * Testing ip address
+ * ------------------
+ */
+
+define onetwo = 1.2.3.4;
+
+function t_ip()
+ip p;
+{
+ p = 127.1.2.3;
+ bt_assert(p.mask(8) = 127.0.0.0);
+ bt_assert(1.2.3.4 = 1.2.3.4);
+ bt_assert(1.2.3.4 = onetwo);
+ bt_assert(format(p) = "127.1.2.3");
+
+ p = ::fffe:6:c0c:936d:88c7:35d3;
+ bt_assert(format(p) = "::fffe:6:c0c:936d:88c7:35d3");
}
-bt_test_suite(t_bool, "Testing boolean expressions");
+bt_test_suite(t_ip, "Testing ip address");
+
+
+
+
+/*
+ * Testing sets of ip address
+ * --------------------------
+ */
+
+define ip1222 = 1.2.2.2;
+
+function t_ip_set()
+ip set ips;
+{
+ ips = [ 1.1.1.0 .. 1.1.1.255, ip1222];
+ bt_assert(format(ips) = "[1.1.1.0..1.1.1.255, 1.2.2.2]");
+ bt_assert(1.1.1.0 ~ ips);
+ bt_assert(1.1.1.100 ~ ips);
+ bt_assert(1.2.2.2 ~ ips);
+ bt_assert(1.1.0.255 !~ ips);
+ bt_assert(1.1.2.0 !~ ips);
+ bt_assert(1.2.2.3 !~ ips);
+ bt_assert(192.168.1.1 !~ ips);
+
+ bt_assert(1.2.3.4 !~ [ 1.2.3.3, 1.2.3.5 ]);
+ bt_assert(1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ]);
+}
+
+bt_test_suite(t_ip_set, "Testing sets of ip address");
+
+
+
+
+/*
+ * Testing enums
+ * -------------
+ */
+
+function t_enum()
+{
+ bt_assert(format(RTS_DUMMY) = "(enum 30)0"); /* XXX */
+ bt_assert(format(RTS_STATIC) = "(enum 30)1"); /* XXX */
+ bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
+ bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
+}
+
+bt_test_suite(t_enum, "Testing enums");
@@ -852,7 +548,7 @@ function test_pxset(prefix set pxs)
bt_assert([ 10.0.0.0/8{ 15 , 17 } ] = [ 10.0.0.0/8{ 15 , 17 } ]);
}
-function t_prefix_sets()
+function t_prefix_set()
prefix set pxs;
{
pxs = [ 1.2.0.0/16, 1.4.0.0/16+];
@@ -875,91 +571,381 @@ prefix set pxs;
bt_assert([ 10.0.0.0/8{ 15 , 17 } ] != [ 11.0.0.0/8{ 15 , 17 } ]);
}
-bt_test_suite(t_prefix_sets, "Testing prefix sets");
+bt_test_suite(t_prefix_set, "Testing prefix sets");
/*
- * Testing IP sets
- * ---------------
+ * Testing Paths
+ * -------------
*/
-define ip1222 = 1.2.2.2;
+function mkpath(int a; int b)
+{
+ return [= a b 3 2 1 =];
+}
-function t_ip_sets()
-ip set ips;
+function t_path()
+bgpmask pm1;
+bgpmask pm2;
+bgppath p2;
{
- ips = [ 1.1.1.0 .. 1.1.1.255, ip1222];
- bt_assert(format(ips) = "[1.1.1.0..1.1.1.255, 1.2.2.2]");
- bt_assert(1.1.1.0 ~ ips);
- bt_assert(1.1.1.100 ~ ips);
- bt_assert(1.2.2.2 ~ ips);
- bt_assert(1.1.0.255 !~ ips);
- bt_assert(1.1.2.0 !~ ips);
- bt_assert(1.2.2.3 !~ ips);
- bt_assert(192.168.1.1 !~ ips);
+ pm1 = / 4 3 2 1 /;
+ pm2 = [= 4 3 2 1 =];
+
+ bt_assert(+empty+ = +empty+);
+ bt_assert(10 !~ +empty+);
+
+ p2 = prepend( + empty +, 1 );
+ p2 = prepend( p2, 2 );
+ p2 = prepend( p2, 3 );
+ p2 = prepend( p2, 4 );
+
+ bt_assert(format(p2) = "(path 4 3 2 1)");
+ bt_assert(p2.len = 4);
+ bt_assert(p2 ~ pm1);
+ bt_assert(p2 ~ pm2);
+ bt_assert(3 ~ p2);
+ bt_assert(p2 ~ [2, 10..20]);
+ bt_assert(p2 ~ [4, 10..20]);
+
+ p2 = prepend(p2, 5);
+ bt_assert(p2 !~ pm1);
+ bt_assert(p2 !~ pm2);
+ bt_assert(10 !~ p2);
+ bt_assert(p2 !~ [8, ten..(2*ten)]);
+ bt_assert(p2 ~ / ? 4 3 2 1 /);
+ bt_assert(p2 ~ [= * 4 3 * 1 =]);
+ bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
+ bt_assert(p2 ~ mkpath(5, 4));
+
+ bt_assert(p2.len = 5);
+ bt_assert(p2.first = 5);
+ bt_assert(p2.last = 1);
+
+ bt_assert(p2.len = 5);
+ bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 1), 2), 4), 5));
+ bt_assert(filter(p2, [1..3]) = prepend(prepend(prepend(+empty+, 1), 2), 3));
+
+ pm1 = [= 1 2 * 3 4 5 =];
+ p2 = prepend( + empty +, 5 );
+ p2 = prepend( p2, 4 );
+ p2 = prepend( p2, 3 );
+ p2 = prepend( p2, 3 );
+ p2 = prepend( p2, 2 );
+ p2 = prepend( p2, 1 );
+
+ bt_assert(p2 ~ pm1);
+ bt_assert(delete(p2, 3) = prepend(prepend(prepend(prepend(+empty+, 5), 4), 2), 1));
+ bt_assert(delete(p2, [4..5]) = prepend(prepend(prepend(prepend(+empty+, 3), 3), 2), 1));
}
-bt_test_suite(t_ip_sets, "Testing IP sets");
+bt_test_suite(t_path, "Testing paths");
/*
- * Testing calling functions
- * -------------------------
+ * Testing Community List
+ * ----------------------
*/
-function callme(int arg1; int arg2)
-int i;
+define p23 = (2, 3);
+
+function t_clist()
+clist l;
+clist l2;
{
- case arg1 {
- 1, 42: return 42;
- else: return arg1 * arg2;
- }
+ l = - empty -;
+ bt_assert(l !~ [(*,*)]);
+ bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
- return 0;
+ bt_assert(-empty- = -empty-);
+
+ l = add( l, (one,2) );
+ bt_assert(l ~ [(*,*)]);
+ l = add( l, (2,one+2) );
+ bt_assert(format(l) = "(clist (1,2) (2,3))");
+
+ bt_assert((2,3) ~ l);
+ bt_assert(l ~ [(1,*)]);
+ bt_assert(l ~ [p23]);
+ bt_assert(l ~ [(2,2..3)]);
+ bt_assert(l ~ [(1,1..2)]);
+ bt_assert(l ~ [(1,1)..(1,2)]);
+
+ l = add(l, (2,5));
+ l = add(l, (5,one));
+ l = add(l, (6,one));
+ l = add(l, (one,one));
+ l = delete(l, [(5,1),(6,one),(one,1)]);
+ l = delete(l, [(5,one),(6,one)]);
+ l = filter(l, [(1,*)]);
+ bt_assert(l = add(-empty-, (1,2)));
+
+ bt_assert((2,3) !~ l);
+ bt_assert(l !~ [(2,*)]);
+ bt_assert(l !~ [(one,3..6)]);
+ bt_assert(l ~ [(*,*)]);
+
+ l = add(l, (3,one));
+ l = add(l, (one+one+one,one+one));
+ l = add(l, (3,3));
+ l = add(l, (3,4));
+ l = add(l, (3,5));
+ l2 = filter(l, [(3,*)]);
+ l = delete(l, [(3,2..4)]);
+ bt_assert(l = add(add(add(-empty-, (1,2)), (3,1)), (3,5)));
+ bt_assert(l.len = 3);
+
+ l = add(l, (3,2));
+ l = add(l, (4,5));
+ bt_assert(l = add(add(add(add(add(-empty-, (1,2)), (3,1)), (3,5)), (3,2)), (4,5)));
+
+ bt_assert(l.len = 5);
+ bt_assert(l ~ [(*,2)]);
+ bt_assert(l ~ [(*,5)]);
+ bt_assert(l ~ [(*, one)]);
+ bt_assert(l !~ [(*,3)]);
+ bt_assert(l !~ [(*,(one+6))]);
+ bt_assert(l !~ [(*, (one+one+one))]);
+
+ l = delete(l, [(*,(one+onef(3)))]);
+ l = delete(l, [(*,(4+one))]);
+ bt_assert(l = add(-empty-, (3,1)));
+
+ l = delete(l, [(*,(onef(5)))]);
+ bt_assert(l = -empty-);
+
+ l2 = add(l2, (3,6));
+ l = filter(l2, [(3,1..4)]);
+ l2 = filter(l2, [(3,3..6)]);
+
+ # lclist A (10,20,30)
+ bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))");
+ bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
+
+ # lclist B (30,40,50)
+ bt_assert(format(l2) = "(clist (3,3) (3,4) (3,5) (3,6))");
+ bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
+
+ # lclist A union B
+ bt_assert(format(add(l, l2)) = "(clist (3,1) (3,2) (3,3) (3,4) (3,5) (3,6))");
+ bt_assert(add(l, l2) = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
+
+ # lclist A isect B
+ bt_assert(format(filter(l, l2)) = "(clist (3,3) (3,4))");
+ bt_assert(filter(l, l2) = add(add(-empty-, (3,3)), (3,4)));
+
+ # lclist A \ B
+ bt_assert(format(delete(l, l2)) = "(clist (3,1) (3,2))");
+ bt_assert(delete(l, l2) = add(add(-empty-, (3,1)), (3,2)));
}
-function fifteen()
+bt_test_suite(t_clist, "Testing lists of communities");
+
+
+
+
+/*
+ * Testing Extended Communities
+ * ----------------------------
+ */
+
+function t_ec()
+ec cc;
{
- return 15;
+ cc = (rt, 12345, 200000);
+ bt_assert(format(cc) = "(rt, 12345, 200000)");
+
+ bt_assert(cc = (rt, 12345, 200000));
+ bt_assert(cc < (rt, 12345, 200010));
+ bt_assert(cc != (rt, 12346, 200000));
+ bt_assert(cc != (ro, 12345, 200000));
+ bt_assert(!(cc > (rt, 12345, 200010)));
+
+ bt_assert(format((ro, 100000, 20000)) = "(ro, 100000, 20000)");
}
-function t_call_function()
+bt_test_suite(t_ec, "Testing extended communities");
+
+
+
+
+/*
+ * Testing Extended Community List
+ * -------------------------------
+ */
+
+function t_eclist()
+eclist el;
+eclist el2;
{
- bt_assert(fifteen() = 15);
+ el = -- empty --;
+ el = add(el, (rt, 10, 20));
+ el = add(el, (ro, 10.20.30.40, 100));
+ el = add(el, (ro, 11.21.31.41.mask(16), 200));
- bt_assert(callme(1, 2) = 42);
- bt_assert(callme(42, 2) = 42);
+ bt_assert(--empty-- = --empty--);
+ bt_assert(((rt, 10, 20)) !~ --empty--);
- bt_assert(callme(2, 2) = 4);
- bt_assert(callme(3, 2) = 6);
- bt_assert(callme(4, 4) = 16);
- bt_assert(callme(7, 2) = 14);
+ bt_assert(format(el) = "(eclist (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200))");
+ bt_assert(el.len = 3);
+ el = delete(el, (rt, 10, 20));
+ el = delete(el, (rt, 10, 30));
+ bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
+ el = add(el, (unknown 2, ten, 1));
+ el = add(el, (unknown 5, ten, 1));
+ el = add(el, (rt, ten, one+one));
+ el = add(el, (rt, 10, 3));
+ el = add(el, (rt, 10, 4));
+ el = add(el, (rt, 10, 5));
+ el = add(el, (generic, 0x2000a, 3*ten));
+ el = delete(el, [(rt, 10, 2..ten)]);
+ 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)));
+
+ el = filter(el, [(rt, 10, *)]);
+ bt_assert(el = add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)));
+ bt_assert((rt, 10, 1) ~ el);
+ bt_assert(el ~ [(rt, 10, ten..40)]);
+ bt_assert((rt, 10, 20) !~ el);
+ bt_assert((ro, 10.20.30.40, 100) !~ el);
+ bt_assert(el !~ [(rt, 10, 35..40)]);
+ bt_assert(el !~ [(ro, 10, *)]);
+
+ el = add(el, (rt, 10, 40));
+ el2 = filter(el, [(rt, 10, 20..40)] );
+ el2 = add(el2, (rt, 10, 50));
+
+ # eclist A (1,30,40)
+ bt_assert(format(el) = "(eclist (rt, 10, 1) (rt, 10, 30) (rt, 10, 40))");
+ bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
+
+ # eclist B (30,40,50)
+ bt_assert(format(el2) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50))");
+ bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
+
+ # eclist A union B
+ bt_assert(format(add(el2, el)) = "(eclist (rt, 10, 30) (rt, 10, 40) (rt, 10, 50) (rt, 10, 1))");
+ bt_assert(add(el2, el) = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
+
+ # eclist A isect B
+ bt_assert(format(filter(el, el2)) = "(eclist (rt, 10, 30) (rt, 10, 40))");
+ bt_assert(filter(el, el2) = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
+
+ # eclist A \ B
+ bt_assert(format(delete(el, el2)) = "(eclist (rt, 10, 1))");
+ bt_assert(delete(el, el2) = add(--empty--, (rt, 10, 1)));
}
-bt_test_suite(t_call_function, "Testing calling functions");
+bt_test_suite(t_eclist, "Testing lists of extended communities");
/*
- * Test including another config file
- * ----------------------------------
+ * Testing sets of Extended Communities
+ * ------------------------------------
*/
-function t_include()
-int i;
+define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
+
+function t_ec_set()
+ec set ecs;
{
- i = 1;
- include "test.conf.inc";
- bt_assert(i = 42);
+ ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
+ bt_assert(format(ecs) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
+ bt_assert(format(ecs2) = "[(rt, 10, 20), (rt, 12345, 0)..(rt, 12345, 4294967295), (ro, 100000, 100)..(ro, 100000, 200)]");
+
+ bt_assert((rt, 10, 20) ~ ecs);
+ bt_assert((ro, 100000, 100) ~ ecs);
+ bt_assert((ro, 100000, 128) ~ ecs);
+ bt_assert((ro, 100000, 200) ~ ecs);
+ bt_assert((rt, 12345, 0) ~ ecs);
+ bt_assert((rt, 12345, 200000) ~ ecs);
+ bt_assert((rt, 12345, 4000000) ~ ecs);
+ bt_assert((ro, 10, 20) !~ ecs);
+ bt_assert((rt, 10, 21) !~ ecs);
+ bt_assert((ro, 100000, 99) !~ ecs);
+ bt_assert((ro, 12345, 10) !~ ecs);
+ bt_assert((rt, 12346, 0) !~ ecs);
+ bt_assert((ro, 0.1.134.160, 150) !~ ecs);
}
-bt_test_suite(t_include, "Test including another config file");
+bt_test_suite(t_ec_set, "Testing sets of extended communities");
+
+
+
+
+/*
+ * Testing Long Communities
+ * ------------------------
+ */
+
+function mktrip(int a)
+{
+ return (a, 2*a, 3*a);
+}
+
+function t_lclist()
+lclist ll;
+lclist ll2;
+{
+ bt_assert(---empty--- = ---empty---);
+ bt_assert((10, 20, 30) !~ ---empty---);
+
+ ll = --- empty ---;
+ ll = add(ll, (ten, 20, 30));
+ ll = add(ll, (1000, 2000, 3000));
+ ll = add(ll, mktrip(100000));
+ bt_assert(format(ll) = "(lclist (10, 20, 30) (1000, 2000, 3000) (100000, 200000, 300000))");
+ bt_assert(ll.len = 3);
+ bt_assert(ll = add(add(add(---empty---, (10, 20, 30)), (1000, 2000, 3000)), (100000, 200000, 300000)));
+
+ bt_assert(mktrip(1000) ~ ll);
+ bt_assert(mktrip(100) !~ ll);
+
+ bt_assert(ll ~ [(5,10,15), (10,20,30)]);
+ bt_assert(ll ~ [(10,15..25,*)]);
+ bt_assert(ll ~ [(ten, *, *)]);
+
+ bt_assert(ll !~ [(5,10,15), (10,21,30)]);
+ bt_assert(ll !~ [(10,21..25,*)]);
+ bt_assert(ll !~ [(11, *, *)]);
+
+ ll2 = filter(ll, [(5..15, *, *), (100000, 500..500000, *)]);
+ bt_assert(ll2 = add(add(---empty---, (10, 20, 30)), (100000, 200000, 300000)));
+
+ ll = --- empty ---;
+ ll = add(ll, (10, 10, 10));
+ ll = add(ll, (20, 20, 20));
+ ll = add(ll, (30, 30, 30));
+
+ ll2 = --- empty ---;
+ ll2 = add(ll2, (20, 20, 20));
+ ll2 = add(ll2, (30, 30, 30));
+ ll2 = add(ll2, (40, 40, 40));
+
+ bt_assert(format(ll) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30))");
+ bt_assert(format(ll2) = "(lclist (20, 20, 20) (30, 30, 30) (40, 40, 40))");
+
+ bt_assert(format(add(ll, ll2)) = "(lclist (10, 10, 10) (20, 20, 20) (30, 30, 30) (40, 40, 40))");
+ bt_assert(add(ll, ll2) = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));
+
+ bt_assert(format(filter(ll, ll2)) = "(lclist (20, 20, 20) (30, 30, 30))");
+ bt_assert(filter(ll, ll2) = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));
+
+ bt_assert(format(delete(ll, ll2)) = "(lclist (10, 10, 10))");
+ bt_assert(delete(ll, ll2) = add(---empty---, (10, 10, 10)));
+}
+
+bt_test_suite(t_lclist, "Testing lists of long communities");
+
+
+
+/* t_lc_set */