1999-11-11 13:55:39 +00:00
|
|
|
/*
|
2016-11-09 15:36:34 +00:00
|
|
|
* This is unit testing configuration file for testing filters
|
|
|
|
*
|
2000-06-02 08:01:12 +00:00
|
|
|
* FIXME: add all examples from docs here.
|
1999-11-11 13:55:39 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
router id 62.168.0.1;
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
/* We have to setup any protocol */
|
|
|
|
protocol static { ipv4; }
|
|
|
|
|
1999-11-11 13:55:39 +00:00
|
|
|
|
2014-10-02 09:02:14 +00:00
|
|
|
|
2015-12-24 14:52:03 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
/*
|
|
|
|
* Common definitions and functions
|
|
|
|
* --------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
define one = 1;
|
|
|
|
define ten = 10;
|
2015-12-24 14:52:03 +00:00
|
|
|
|
2011-03-26 13:18:56 +00:00
|
|
|
function onef(int a)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-01 17:32:41 +00:00
|
|
|
|
|
|
|
|
2016-10-01 10:50:29 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
/*
|
|
|
|
* Testing empty lists/paths
|
|
|
|
* -------------------------
|
|
|
|
*/
|
2009-06-01 17:32:41 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function t_empty()
|
1999-11-11 13:55:39 +00:00
|
|
|
{
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(+empty+ = +empty+);
|
|
|
|
bt_assert(+empty+ != -empty-);
|
|
|
|
bt_assert(+empty+ != --empty--);
|
1999-11-11 13:55:39 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(-empty- = -empty-);
|
|
|
|
bt_assert(-empty- != --empty--);
|
1999-11-11 13:55:39 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(--empty-- = --empty--);
|
2000-02-25 11:15:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_empty, "Testing +empty+, -empty-, --empty--");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-24 14:52:03 +00:00
|
|
|
/*
|
2016-11-09 15:36:34 +00:00
|
|
|
* Testing Paths
|
|
|
|
* -------------
|
|
|
|
*/
|
2012-03-18 16:32:30 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function mkpath(int a; int b)
|
2012-03-18 16:32:30 +00:00
|
|
|
{
|
2016-11-09 15:36:34 +00:00
|
|
|
return [= a b 3 2 1 =];
|
2012-03-18 16:32:30 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function t_path()
|
2009-03-14 11:43:10 +00:00
|
|
|
bgpmask pm1;
|
|
|
|
bgpmask pm2;
|
2000-04-17 10:42:28 +00:00
|
|
|
bgppath p2;
|
2000-04-12 12:10:37 +00:00
|
|
|
{
|
2009-03-14 11:43:10 +00:00
|
|
|
pm1 = / 4 3 2 1 /;
|
2016-11-09 15:36:34 +00:00
|
|
|
pm2 = [= 4 3 2 1 =];
|
|
|
|
|
2000-04-17 10:42:28 +00:00
|
|
|
p2 = prepend( + empty +, 1 );
|
|
|
|
p2 = prepend( p2, 2 );
|
|
|
|
p2 = prepend( p2, 3 );
|
|
|
|
p2 = prepend( p2, 4 );
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
print "Testing paths: ", p2;
|
|
|
|
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));
|
2013-10-05 18:12:28 +00:00
|
|
|
|
2009-03-14 11:43:10 +00:00
|
|
|
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 );
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
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 */
|
2000-04-17 11:34:38 +00:00
|
|
|
|
2010-04-09 15:42:39 +00:00
|
|
|
l = - empty -;
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(l !~ [(*,*)]);
|
|
|
|
bt_assert((l ~ [(*,*)]) != (l !~ [(*,*)]));
|
|
|
|
|
2010-08-03 13:14:26 +00:00
|
|
|
l = add( l, (one,2) );
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(l ~ [(*,*)]);
|
2010-08-03 13:14:26 +00:00
|
|
|
l = add( l, (2,one+2) );
|
2000-04-17 11:42:08 +00:00
|
|
|
print "Community list (1,2) (2,3) ", l;
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
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)]);
|
|
|
|
|
2012-03-15 19:42:29 +00:00
|
|
|
print "clist A (1..4): ", l;
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)));
|
|
|
|
|
2012-03-15 19:42:29 +00:00
|
|
|
print "clist B (3..6): ", l2;
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(l2 = add(add(add(add(-empty-, (3,3)), (3,4)), (3,5)), (3,6)));
|
|
|
|
|
|
|
|
print "clist A union B: ", add( l, l2 );
|
|
|
|
bt_assert(add(l, l2) = add(add(add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4)), (3,5)), (3,6)));
|
|
|
|
|
2012-03-15 19:42:29 +00:00
|
|
|
print "clist A isect B: ", filter( l, l2 );
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(filter(l, l2) = add(add(-empty-, (3,3)), (3,4)));
|
|
|
|
|
2016-10-18 11:06:05 +00:00
|
|
|
print "clist A \ B: ", delete( l, l2 );
|
2016-11-09 15:36:34 +00:00
|
|
|
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
|
|
|
|
* -------------------------------
|
|
|
|
*/
|
2011-08-12 19:03:43 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function t_extended_community_list()
|
|
|
|
eclist el;
|
|
|
|
eclist el2;
|
|
|
|
{
|
2011-08-12 19:03:43 +00:00
|
|
|
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));
|
2016-11-09 15:36:34 +00:00
|
|
|
|
2011-08-12 19:03:43 +00:00
|
|
|
print "EC list (rt, 10, 20) (ro, 10.20.30.40, 100) (ro, 11.21.0.0, 200):";
|
|
|
|
print el;
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(el.len = 3);
|
2011-08-12 19:03:43 +00:00
|
|
|
el = delete(el, (rt, 10, 20));
|
|
|
|
el = delete(el, (rt, 10, 30));
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(el = add(add(--empty--, (ro, 10.20.30.40, 100)), (ro, 11.21.0.0, 200)));
|
2011-08-12 19:03:43 +00:00
|
|
|
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)]);
|
2016-11-09 15:36:34 +00:00
|
|
|
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)));
|
|
|
|
|
2011-08-12 19:03:43 +00:00
|
|
|
el = filter(el, [(rt, 10, *)]);
|
2016-11-09 15:36:34 +00:00
|
|
|
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, *)]);
|
|
|
|
|
2012-03-15 19:42:29 +00:00
|
|
|
el = add(el, (rt, 10, 40));
|
|
|
|
el2 = filter(el, [(rt, 10, 20..40)] );
|
|
|
|
el2 = add(el2, (rt, 10, 50));
|
2016-11-09 15:36:34 +00:00
|
|
|
|
2012-03-15 19:42:29 +00:00
|
|
|
print "eclist A (1,30,40): ", el;
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(el = add(add(add(--empty--, (rt, 10, 1)), (rt, 10, 30)), (rt, 10, 40)));
|
|
|
|
|
2012-03-15 19:42:29 +00:00
|
|
|
print "eclist B (30,40,50): ", el2;
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(el2 = add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)));
|
|
|
|
|
|
|
|
print "eclist A union B: ", add(el2, el);
|
|
|
|
bt_assert(add(el2, el) = add(add(add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)), (rt, 10, 50)), (rt, 10, 1)));
|
|
|
|
|
|
|
|
print "eclist A isect B: ", filter(el, el2);
|
|
|
|
bt_assert(filter(el, el2) = add(add(--empty--, (rt, 10, 30)), (rt, 10, 40)));
|
|
|
|
|
|
|
|
print "eclist A \ B: ", delete(el, el2);
|
|
|
|
bt_assert(delete(el, el2) = add(--empty--, (rt, 10, 1)));
|
2000-04-26 07:31:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_extended_community_list, "Testing extended communities and lists");
|
2000-05-15 12:19:26 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-09 18:08:25 +00:00
|
|
|
/*
|
|
|
|
* 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));
|
|
|
|
print "LC list (10, 20, 30) (1000, 2000, 3000) (100000, 200000, 300000)";
|
|
|
|
print ll;
|
|
|
|
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));
|
|
|
|
|
|
|
|
print "lclist A (10,20,30): ", ll;
|
|
|
|
print "lclist B (30,40,50): ", ll2;
|
|
|
|
|
|
|
|
print "lclist A union B: ", add(ll, ll2);
|
|
|
|
bt_assert(add(ll, ll2) = add(add(add(add(---empty---, (10,10,10)), (20,20,20)), (30,30,30)), (40,40,40)));
|
|
|
|
|
|
|
|
print "lclist A isect B: ", filter(ll, ll2);
|
|
|
|
bt_assert(filter(ll, ll2) = add(add(---empty---, (20, 20, 20)), (30, 30, 30)));
|
|
|
|
|
|
|
|
print "lclist A \ B: ", delete(ll, ll2);
|
|
|
|
bt_assert(delete(ll, ll2) = add(---empty---, (10, 10, 10)));
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_test_suite(t_long_community_list, "Testing long communities and lists");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
/*
|
|
|
|
* Testing defined() function
|
|
|
|
* --------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function test_undef(int a)
|
|
|
|
int b;
|
2000-06-08 16:57:41 +00:00
|
|
|
{
|
2016-11-09 15:36:34 +00:00
|
|
|
if a = 3 then {
|
|
|
|
b = 4;
|
|
|
|
bt_assert(defined(b));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bt_assert(!defined(b));
|
2016-06-30 13:00:47 +00:00
|
|
|
}
|
2000-06-08 16:57:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function t_define()
|
|
|
|
int i;
|
2000-06-08 16:57:41 +00:00
|
|
|
{
|
2016-11-09 15:36:34 +00:00
|
|
|
test_undef(2);
|
|
|
|
test_undef(3);
|
|
|
|
test_undef(2);
|
|
|
|
|
|
|
|
bt_assert(defined(1));
|
|
|
|
bt_assert(defined(1.2.3.4));
|
2000-06-08 16:57:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_define, "Testing defined() function");
|
2016-06-30 13:00:47 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing quads
|
|
|
|
* -------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function t_quad()
|
|
|
|
quad qq;
|
2009-03-31 10:55:57 +00:00
|
|
|
{
|
2016-11-09 15:36:34 +00:00
|
|
|
qq = 1.2.3.4;
|
|
|
|
print "Testinq quad: 1.2.3.4 = ", qq;
|
|
|
|
bt_assert(qq = 1.2.3.4);
|
|
|
|
bt_assert(qq != 4.3.2.1);
|
2009-03-31 10:55:57 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_quad, "Testing quads");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing sets of quads
|
|
|
|
* ---------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function t_quad_set()
|
|
|
|
quad qq;
|
2010-03-19 08:41:18 +00:00
|
|
|
{
|
2016-11-09 15:36:34 +00:00
|
|
|
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]);
|
2010-03-19 08:41:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_quad_set, "Testing sets of quads");
|
2013-07-25 20:33:57 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing Extended Communities
|
|
|
|
* ----------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function t_ec()
|
|
|
|
ec cc;
|
|
|
|
{
|
|
|
|
cc = (rt, 12345, 200000);
|
|
|
|
print "Testing EC: ", cc;
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
print "Testing EC: (ro, 100000, 20000) = ", (ro, 100000, 20000);
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_test_suite(t_ec, "Testing Extended Communities");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing sets of Extended Communities
|
|
|
|
* ------------------------------------
|
|
|
|
*/
|
2013-07-25 20:33:57 +00:00
|
|
|
|
|
|
|
define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function t_ec_set()
|
|
|
|
ec set ecs;
|
|
|
|
{
|
|
|
|
ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
|
|
|
|
print "EC set (rt, 10, 20) (ro, 100000, 100..200), (rt, 12345, *):";
|
|
|
|
print ecs;
|
|
|
|
print ecs2;
|
|
|
|
|
|
|
|
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_ec_set, "Testing sets of Extended Communities");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing integers
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
define four = 4;
|
|
|
|
define xyzzy = (120+10);
|
|
|
|
define '1a-a1' = (xyzzy-100);
|
2013-07-25 20:33:57 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function t_int()
|
1999-11-11 13:55:39 +00:00
|
|
|
int i;
|
2016-11-09 15:36:34 +00:00
|
|
|
{
|
|
|
|
bt_assert(xyzzy = 130);
|
|
|
|
bt_assert('1a-a1' = 30);
|
|
|
|
|
|
|
|
i = four;
|
|
|
|
i = 12*100 + 60/2 + i;
|
|
|
|
i = (i + 0);
|
|
|
|
bt_assert(i = 1234);
|
|
|
|
|
|
|
|
if (i = 4) then
|
|
|
|
bt_assert(false);
|
|
|
|
else
|
|
|
|
bt_assert(true);
|
|
|
|
|
|
|
|
if !(i = 3) then
|
|
|
|
bt_assert(true);
|
|
|
|
else
|
|
|
|
bt_assert(false);
|
|
|
|
|
|
|
|
if 1234 = i then
|
|
|
|
bt_assert(true);
|
|
|
|
else
|
|
|
|
bt_assert(false);
|
|
|
|
|
|
|
|
if 1 <= 1 then
|
|
|
|
bt_assert(true);
|
|
|
|
else
|
|
|
|
bt_assert(false);
|
|
|
|
|
|
|
|
if 1234 < 1234 then
|
|
|
|
bt_assert(false);
|
|
|
|
else
|
|
|
|
bt_assert(true);
|
|
|
|
|
|
|
|
i = 4200000000;
|
|
|
|
bt_assert(i = 4200000000);
|
|
|
|
bt_assert(i > 4100000000);
|
|
|
|
bt_assert(!(i > 4250000000));
|
|
|
|
|
|
|
|
bt_assert(1 = 1);
|
|
|
|
bt_assert(!(1 != 1));
|
|
|
|
|
|
|
|
bt_assert(1 != 2);
|
|
|
|
bt_assert(1 <= 2);
|
|
|
|
|
|
|
|
bt_assert(1 != "a");
|
|
|
|
bt_assert(1 != (0,1));
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_test_suite(t_int, "Testing integers");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing sets of integers
|
|
|
|
* ------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
define is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
|
|
|
|
define is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
|
|
|
|
define is3 = [5, 17, 2, 11, 8, 15, 3, 19];
|
|
|
|
|
|
|
|
function t_int_set()
|
2009-03-31 10:55:57 +00:00
|
|
|
int set is;
|
2010-02-10 11:30:14 +00:00
|
|
|
{
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(1 ~ [1,2,3]);
|
|
|
|
bt_assert(5 ~ [1..20]);
|
|
|
|
bt_assert(2 ~ [ 1, 2, 3 ]);
|
|
|
|
bt_assert(5 ~ [ 4 .. 7 ]);
|
|
|
|
bt_assert(1 !~ [ 2, 3, 4 ]);
|
|
|
|
|
2009-03-31 10:55:57 +00:00
|
|
|
is = [ 2, 3, 4, 7..11 ];
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(10 ~ is);
|
|
|
|
bt_assert(5 !~ is);
|
|
|
|
|
|
|
|
bt_assert(1 ~ is1);
|
|
|
|
bt_assert(3 ~ is1);
|
|
|
|
bt_assert(5 ~ is1);
|
|
|
|
bt_assert((one+2) ~ is1);
|
|
|
|
bt_assert(2 ~ is2);
|
|
|
|
bt_assert(2 ~ is3);
|
|
|
|
bt_assert(4 !~ is1);
|
|
|
|
bt_assert(4 !~ is2);
|
|
|
|
bt_assert(4 !~ is3);
|
|
|
|
bt_assert(10 !~ is1);
|
|
|
|
bt_assert(10 !~ is2);
|
|
|
|
bt_assert(10 !~ is3);
|
|
|
|
bt_assert(15 ~ is1);
|
|
|
|
bt_assert(15 ~ is2);
|
|
|
|
bt_assert(15 ~ is3);
|
|
|
|
bt_assert(18 !~ is1);
|
|
|
|
bt_assert(18 !~ is2);
|
|
|
|
bt_assert(18 !~ is3);
|
|
|
|
bt_assert(19 ~ is1);
|
|
|
|
bt_assert(19 ~ is2);
|
|
|
|
bt_assert(19 ~ is3);
|
|
|
|
bt_assert(20 !~ is1);
|
|
|
|
bt_assert(20 !~ is2);
|
|
|
|
bt_assert(20 !~ is3);
|
|
|
|
|
|
|
|
bt_assert([1,2] != [1,3]);
|
|
|
|
bt_assert([1,4..10,20] = [1,4..10,20]);
|
2013-10-02 12:41:37 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
|
|
|
|
}
|
2013-10-02 12:41:37 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_int_set, "Testing sets of integers");
|
2000-03-09 14:47:43 +00:00
|
|
|
|
1999-11-11 13:55:39 +00:00
|
|
|
|
2010-02-17 20:53:07 +00:00
|
|
|
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
/*
|
|
|
|
* Testing ip address
|
|
|
|
* ------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
define onetwo = 1.2.3.4;
|
2009-06-01 17:32:41 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function t_ip()
|
|
|
|
ip p;
|
|
|
|
{
|
1999-11-11 13:55:39 +00:00
|
|
|
p = 127.1.2.3;
|
2016-11-09 15:36:34 +00:00
|
|
|
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);
|
|
|
|
print "1.2.3.4 = ", onetwo;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
2015-12-24 14:52:03 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing enums
|
|
|
|
* -------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function t_enum()
|
|
|
|
{
|
|
|
|
print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC;
|
|
|
|
bt_assert(RTS_STATIC ~ [RTS_STATIC, RTS_DEVICE]);
|
|
|
|
bt_assert(RTS_BGP !~ [RTS_STATIC, RTS_DEVICE]);
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_test_suite(t_enum, "Testing enums");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing pairs
|
|
|
|
* -------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function 'mkpair-a'(int a)
|
|
|
|
{
|
|
|
|
return (1, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
function t_pair()
|
|
|
|
pair pp;
|
|
|
|
{
|
2009-03-31 10:55:57 +00:00
|
|
|
pp = (1, 2);
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert((1,2) = pp);
|
|
|
|
bt_assert((1,1+1) = pp);
|
|
|
|
bt_assert('mkpair-a'(2) = pp);
|
|
|
|
bt_assert((1,2) = (1,1+1));
|
|
|
|
bt_assert(((1,2) < (2,2)));
|
|
|
|
bt_assert(!((1,1) > (1,1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_test_suite(t_pair, "Testing pairs");
|
|
|
|
|
|
|
|
|
2010-03-29 17:29:03 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing sets of pairs
|
|
|
|
* ---------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function t_pair_set()
|
|
|
|
pair pp;
|
|
|
|
pair set ps;
|
|
|
|
{
|
|
|
|
pp = (1, 2);
|
2010-08-03 15:35:34 +00:00
|
|
|
ps = [(1,(one+one)), (3,4)..(4,8), (5,*), (6,3..6)];
|
2010-09-20 11:01:01 +00:00
|
|
|
print "Pair set: ", ps;
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(pp ~ ps);
|
|
|
|
bt_assert((3,5) ~ ps);
|
|
|
|
bt_assert((4,1) ~ ps);
|
|
|
|
bt_assert((5,4) ~ ps);
|
|
|
|
bt_assert((5,65535) ~ ps);
|
|
|
|
bt_assert((6,4) ~ ps);
|
|
|
|
bt_assert((3, 10000) ~ ps);
|
|
|
|
bt_assert((3,3) !~ ps);
|
|
|
|
bt_assert((4,9) !~ ps);
|
|
|
|
bt_assert((4,65535) !~ ps);
|
|
|
|
bt_assert((6,2) !~ ps);
|
|
|
|
bt_assert((6,6+one) !~ ps);
|
|
|
|
bt_assert(((one+6),2) !~ ps);
|
|
|
|
bt_assert((1,1) !~ ps);
|
2011-05-06 20:00:54 +00:00
|
|
|
|
|
|
|
ps = [(20..150, 200..300), (50100..50200, 1000..50000), (*, 5+5)];
|
2016-11-09 15:36:34 +00:00
|
|
|
print "Pair set: ", ps;
|
|
|
|
bt_assert((100,200) ~ ps);
|
|
|
|
bt_assert((150,300) ~ ps);
|
|
|
|
bt_assert((50180,1200) ~ ps);
|
|
|
|
bt_assert((50110,49000) ~ ps);
|
|
|
|
bt_assert((0,10) ~ ps);
|
|
|
|
bt_assert((64000,10) ~ ps);
|
|
|
|
bt_assert((20,199) !~ ps);
|
|
|
|
bt_assert((151,250) !~ ps);
|
|
|
|
bt_assert((50050,2000) !~ ps);
|
|
|
|
bt_assert((50150,50050) !~ ps);
|
|
|
|
bt_assert((10,9) !~ ps);
|
|
|
|
bt_assert((65535,11) !~ ps);
|
|
|
|
}
|
2010-03-29 17:29:03 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_pair_set, "Testing sets of pairs");
|
2010-03-29 17:29:03 +00:00
|
|
|
|
2011-08-12 19:03:43 +00:00
|
|
|
|
1999-11-11 13:55:39 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing string matching
|
|
|
|
* -----------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function t_string()
|
|
|
|
string st;
|
|
|
|
{
|
2013-11-22 20:58:43 +00:00
|
|
|
st = "Hello";
|
2016-11-09 15:36:34 +00:00
|
|
|
print "Testing string: ", st;
|
|
|
|
bt_assert(st ~ "Hell*");
|
|
|
|
bt_assert(st ~ "?ello");
|
|
|
|
bt_assert(st ~ "Hello");
|
|
|
|
bt_assert(st ~ "Hell?");
|
|
|
|
bt_assert(st !~ "ell*");
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_test_suite(t_string, "Testing string matching");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing boolean expressions
|
|
|
|
* ---------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function t_bool()
|
|
|
|
bool b;
|
|
|
|
{
|
2009-03-31 10:55:57 +00:00
|
|
|
b = true;
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(b);
|
|
|
|
bt_assert(!!b);
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2009-05-28 11:37:04 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_bool, "Testing boolean expressions");
|
2013-11-20 12:30:00 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing prefixes
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
define netdoc = 2001:db8::/32;
|
|
|
|
|
|
|
|
function t_prefix()
|
|
|
|
prefix px;
|
|
|
|
{
|
|
|
|
px = 1.2.0.0/18;
|
|
|
|
print "Testing prefixes: 1.2.0.0/18 = ", px;
|
|
|
|
bt_assert(192.168.0.0/16 ~ 192.168.0.0/16);
|
|
|
|
bt_assert(192.168.0.0/17 ~ 192.168.0.0/16);
|
|
|
|
bt_assert(192.168.254.0/24 ~ 192.168.0.0/16);
|
|
|
|
bt_assert(netdoc ~ 2001::/16);
|
|
|
|
bt_assert(192.168.0.0/15 !~ 192.168.0.0/16);
|
|
|
|
bt_assert(192.160.0.0/17 !~ 192.168.0.0/16);
|
|
|
|
bt_assert(px !~ netdoc);
|
|
|
|
|
|
|
|
bt_assert(1.2.3.4 ~ 1.0.0.0/8);
|
|
|
|
bt_assert(1.0.0.0/8 ~ 1.0.0.0/8);
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_test_suite(t_prefix, "Testing prefixes");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing prefix sets
|
|
|
|
* -------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
define net10 = 10.0.0.0/8;
|
|
|
|
define pxs2 = [ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ];
|
|
|
|
|
|
|
|
function test_pxset(prefix set pxs)
|
|
|
|
{
|
2009-03-31 10:55:57 +00:00
|
|
|
print pxs;
|
2016-11-09 15:36:34 +00:00
|
|
|
|
|
|
|
bt_assert(net10 ~ pxs);
|
|
|
|
bt_assert(10.0.0.0/10 ~ pxs);
|
|
|
|
bt_assert(10.0.0.0/12 ~ pxs);
|
|
|
|
bt_assert(20.0.0.0/24 ~ pxs);
|
|
|
|
bt_assert(20.0.40.0/24 ~ pxs);
|
|
|
|
bt_assert(20.0.0.0/26 ~ pxs);
|
|
|
|
bt_assert(20.0.100.0/26 ~ pxs);
|
|
|
|
bt_assert(20.0.0.0/28 ~ pxs);
|
|
|
|
bt_assert(20.0.255.0/28 ~ pxs);
|
|
|
|
|
|
|
|
bt_assert(10.0.0.0/7 !~ pxs);
|
|
|
|
bt_assert(10.0.0.0/13 !~ pxs);
|
|
|
|
bt_assert(10.0.0.0/16 !~ pxs);
|
|
|
|
bt_assert(20.0.0.0/16 !~ pxs);
|
|
|
|
bt_assert(20.0.0.0/23 !~ pxs);
|
|
|
|
bt_assert(20.0.0.0/29 !~ pxs);
|
|
|
|
bt_assert(11.0.0.0/10 !~ pxs);
|
|
|
|
bt_assert(20.1.0.0/26 !~ pxs);
|
|
|
|
|
|
|
|
bt_assert(1.0.0.0/8 ~ [ 1.0.0.0/8+ ]);
|
|
|
|
bt_assert(1.0.0.0/9 !~ [ 1.0.0.0/8- ]);
|
|
|
|
bt_assert(1.2.0.0/17 !~ [ 1.0.0.0/8{ 15 , 16 } ]);
|
|
|
|
|
|
|
|
bt_assert([ 10.0.0.0/8{ 15 , 17 } ] = [ 10.0.0.0/8{ 15 , 17 } ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function t_prefix_sets()
|
|
|
|
prefix set pxs;
|
|
|
|
{
|
|
|
|
pxs = [ 1.2.0.0/16, 1.4.0.0/16+];
|
|
|
|
print "Testing prefix sets: ", pxs;
|
|
|
|
bt_assert(1.2.0.0/16 ~ pxs);
|
|
|
|
bt_assert(1.4.0.0/16 ~ pxs);
|
|
|
|
bt_assert(1.4.0.0/18 ~ pxs);
|
|
|
|
bt_assert(1.4.0.0/32 ~ pxs);
|
|
|
|
bt_assert(1.1.0.0/16 !~ pxs);
|
|
|
|
bt_assert(1.3.0.0/16 !~ pxs);
|
|
|
|
bt_assert(1.2.0.0/15 !~ pxs);
|
|
|
|
bt_assert(1.2.0.0/17 !~ pxs);
|
|
|
|
bt_assert(1.2.0.0/32 !~ pxs);
|
|
|
|
bt_assert(1.4.0.0/15 !~ pxs);
|
2009-03-31 10:55:57 +00:00
|
|
|
|
2013-07-25 20:33:57 +00:00
|
|
|
test_pxset(pxs2);
|
2009-03-31 10:55:57 +00:00
|
|
|
test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
|
1999-11-11 13:55:39 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_assert(1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ]);
|
|
|
|
bt_assert([ 10.0.0.0/8{ 15 , 17 } ] != [ 11.0.0.0/8{ 15 , 17 } ]);
|
|
|
|
}
|
1999-11-11 13:55:39 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_prefix_sets, "Testing prefix sets");
|
2000-02-25 11:15:26 +00:00
|
|
|
|
2000-04-12 12:10:37 +00:00
|
|
|
|
2000-05-15 12:19:26 +00:00
|
|
|
|
2013-11-20 12:30:00 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
/*
|
|
|
|
* Testing IP sets
|
|
|
|
* ---------------
|
|
|
|
*/
|
2010-03-19 08:41:18 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
define ip1222 = 1.2.2.2;
|
2011-09-11 19:21:47 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
function t_ip_sets()
|
|
|
|
ip set ips;
|
|
|
|
{
|
|
|
|
ips = [ 1.1.1.0 .. 1.1.1.255, ip1222];
|
|
|
|
print "Testing IP sets: ", ips;
|
|
|
|
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);
|
1999-11-11 13:55:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
bt_test_suite(t_ip_sets, "Testing IP sets");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Testing calling functions
|
|
|
|
* -------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function callme(int arg1; int arg2)
|
|
|
|
int i;
|
|
|
|
{
|
|
|
|
case arg1 {
|
|
|
|
1, 42: return 42;
|
|
|
|
else: return arg1 * arg2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fifteen()
|
|
|
|
{
|
|
|
|
return 15;
|
|
|
|
}
|
|
|
|
|
|
|
|
function t_call_function()
|
|
|
|
{
|
|
|
|
bt_assert(fifteen() = 15);
|
|
|
|
|
|
|
|
bt_assert(callme(1, 2) = 42);
|
|
|
|
bt_assert(callme(42, 2) = 42);
|
|
|
|
|
|
|
|
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_call_function, "Testing calling functions");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Test including another config file
|
|
|
|
* ----------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function t_include()
|
|
|
|
int i;
|
|
|
|
{
|
|
|
|
print "Testing include";
|
|
|
|
i = 1;
|
|
|
|
include "test.conf.inc";
|
|
|
|
bt_assert(i = 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_test_suite(t_include, "Test including another config file");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unused functions -- testing only parsing
|
|
|
|
* ----------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
function __test1()
|
|
|
|
{
|
|
|
|
if source ~ [ RTS_BGP, RTS_STATIC ] then {
|
|
|
|
# ospf_metric1 = 65535;
|
|
|
|
# ospf_metric2 = 1000;
|
|
|
|
ospf_tag = 0x12345678;
|
|
|
|
accept;
|
|
|
|
}
|
|
|
|
reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
function __test2()
|
|
|
|
{
|
|
|
|
if source ~ [ RTS_BGP, RTS_STATIC ] then {
|
|
|
|
# ospf_metric1 = 65535;
|
|
|
|
# ospf_metric2 = 1000;
|
|
|
|
ospf_tag = 0x12345678;
|
|
|
|
accept;
|
|
|
|
}
|
|
|
|
reject;
|
|
|
|
}
|
|
|
|
|
|
|
|
filter testf
|
|
|
|
int j;
|
|
|
|
{
|
2000-03-09 14:47:43 +00:00
|
|
|
print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
|
|
|
|
print "This route was from ", from;
|
1999-11-11 13:55:39 +00:00
|
|
|
j = 7;
|
|
|
|
j = 17;
|
1999-12-08 12:51:26 +00:00
|
|
|
if rip_metric > 15 then {
|
2016-06-30 13:00:47 +00:00
|
|
|
reject "RIP Metric is more than infinity";
|
1999-11-18 14:01:36 +00:00
|
|
|
}
|
1999-12-08 12:51:26 +00:00
|
|
|
rip_metric = 14;
|
|
|
|
unset(rip_metric);
|
2016-11-09 15:36:34 +00:00
|
|
|
|
1999-11-18 14:01:36 +00:00
|
|
|
accept "ok I take that";
|
1999-11-11 13:55:39 +00:00
|
|
|
}
|
2000-05-15 12:07:09 +00:00
|
|
|
|
2016-11-09 15:36:34 +00:00
|
|
|
/*
|
|
|
|
roa table rl
|
|
|
|
{
|
|
|
|
roa 10.110.0.0/16 max 16 as 1000;
|
|
|
|
roa 10.120.0.0/16 max 24 as 1000;
|
|
|
|
roa 10.130.0.0/16 max 24 as 2000;
|
|
|
|
roa 10.130.128.0/18 max 24 as 3000;
|
|
|
|
}
|
|
|
|
|
|
|
|
function test_roa()
|
|
|
|
{
|
|
|
|
# cannot be tested in __startup(), sorry
|
|
|
|
print "Testing ROA";
|
|
|
|
print "Should be true: ", roa_check(rl, 10.10.0.0/16, 1000) = ROA_UNKNOWN,
|
|
|
|
" ", roa_check(rl, 10.0.0.0/8, 1000) = ROA_UNKNOWN,
|
|
|
|
" ", roa_check(rl, 10.110.0.0/16, 1000) = ROA_VALID,
|
|
|
|
" ", roa_check(rl, 10.110.0.0/16, 2000) = ROA_INVALID,
|
|
|
|
" ", roa_check(rl, 10.110.32.0/20, 1000) = ROA_INVALID,
|
|
|
|
" ", roa_check(rl, 10.120.32.0/20, 1000) = ROA_VALID;
|
|
|
|
print "Should be true: ", roa_check(rl, 10.120.32.0/20, 2000) = ROA_INVALID,
|
|
|
|
" ", roa_check(rl, 10.120.32.32/28, 1000) = ROA_INVALID,
|
|
|
|
" ", roa_check(rl, 10.130.130.0/24, 1000) = ROA_INVALID,
|
|
|
|
" ", roa_check(rl, 10.130.130.0/24, 2000) = ROA_VALID,
|
|
|
|
" ", roa_check(rl, 10.130.30.0/24, 3000) = ROA_INVALID,
|
|
|
|
" ", roa_check(rl, 10.130.130.0/24, 3000) = ROA_VALID;
|
|
|
|
}
|
|
|
|
*/
|