File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / bird / filter / test6.conf
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Aug 22 12:33:54 2017 UTC (6 years, 10 months ago) by misho
Branches: bird, MAIN
CVS tags: v1_6_8p3, v1_6_3p0, v1_6_3, HEAD
bird 1.6.3

    1: /*
    2:  *	This is an example configuration file.
    3:  *	FIXME: add all examples from docs here.
    4:  */
    5: 
    6: # Yet another comment
    7: 
    8: router id 62.168.0.1;
    9: 
   10: define xyzzy = (120+10);
   11: 
   12: function callme(int arg1; int arg2)
   13: int local1;
   14: int local2;
   15: int i;
   16: {
   17: 	printn "Function callme called arguments ", arg1, " and ", arg2, ":" ;
   18: 	i = arg2;
   19: 
   20: 	case arg1 {
   21: 	2: print "dva"; print "jeste jednou dva";
   22: 	3 .. 5: print "tri az pet";
   23: 	else: print "neco jineho";
   24: 	}	
   25: }
   26: 
   27: function fifteen()
   28: {
   29: 	print "fifteen called";
   30: 	return 15;
   31: }
   32: 
   33: function paths()
   34: bgpmask pm1;
   35: bgpmask pm2;
   36: bgppath p2;
   37: clist l;
   38: {
   39: 	pm1 =  / 4 3 2 1 /;
   40: 	pm2 = [= 4 3 2 1 =];
   41: 	print "Testing path masks: ", pm1, " ", pm2;
   42: 	p2 = prepend( + empty +, 1 );
   43: 	p2 = prepend( p2, 2 );
   44: 	p2 = prepend( p2, 3 );
   45: 	p2 = prepend( p2, 4 );
   46: 	print "Testing paths: ", p2;
   47: 	print "Should be true: ", p2 ~ pm1, " ", p2 ~ pm2;
   48: 	print "4 = ", p2.len;
   49: 	p2 = prepend( p2, 5 );
   50: 	print "Should be false: ", p2 ~ pm1, " ", p2 ~ pm2;
   51: 	print "Should be true: ", p2 ~  / ? 4 3 2 1 /,  " ", p2, " ",  / ? 4 3 2 1 /;
   52: 	print "Should be true: ", p2 ~ [= * 4 3 * 1 =], " ", p2, " ", [= * 4 3 * 1 =];
   53: 	print "5 = ", p2.len;
   54: 	
   55: 	pm1 = [= 1 2 * 3 4 5 =];
   56: 	p2 = prepend( + empty +, 5 );
   57: 	p2 = prepend( p2, 4 );
   58: 	p2 = prepend( p2, 3 );
   59: 	p2 = prepend( p2, 3 );
   60: 	p2 = prepend( p2, 2 );
   61: 	p2 = prepend( p2, 1 );
   62: 	print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1;
   63: 
   64: 	l = - empty -;
   65: 	l = add( l, (1,2) );
   66: 	l = add( l, (2,3) );
   67: 	print "Community list (1,2) (2,3) ", l;
   68: 	print "Should be true: ", (2,3) ~ l;
   69: 	l = delete( l, (2,3) );
   70: 	print "Community list (1,2) ", l;
   71: 	print "Should be false: ", (2,3) ~ l;
   72: }
   73: 
   74: function bla()
   75: {
   76: 	print "fifteen called";
   77: 	return 15;
   78: }
   79: 
   80: define four=4;
   81: 
   82: function test_pxset(prefix set pxs)
   83: {
   84: 	print "  must be true:  ",	1000::/8  ~ pxs, ",", 1000::/10  ~ pxs, ",", 1000::/12 ~ pxs, ",",
   85: 					2000::/24 ~ pxs, ",", 2000:4000::/24 ~ pxs, ",", 2000::/26 ~ pxs, ",",
   86: 					2000:8000::/26 ~ pxs, ",", 2000::/28 ~ pxs, ",", 2000:FFF0::/28 ~ pxs;
   87: 	print "  must be false: ",	1000::/7 ~ pxs,  ",", 1000::/13 ~ pxs, ",", 1000::/16 ~ pxs, ",",
   88: 					2000::/16 ~ pxs, ",", 2000::/23 ~ pxs, ",", 2000::/29 ~ pxs, ",",
   89: 					1100::/10 ~ pxs, ",", 2010::/26 ~ pxs;
   90: }
   91: 
   92: function __startup() 
   93: int i;
   94: bool b;
   95: prefix px;
   96: ip p;
   97: pair pp;
   98: int set is;
   99: prefix set pxs;
  100: string s;
  101: { 
  102: 	print "Testing filter language:";
  103: 	i = four; 
  104: 	i = 12*100 + 60/2 + i; 
  105: 	i = ( i + 0 );
  106: 	print "  arithmetics: 1234 = ", i;
  107: 	printn "  if statements ";
  108: 	print "what happens here?";
  109: 	printn ".";
  110: 	if (i = 4) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
  111: #	if !(i = 3) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
  112: 	if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; }
  113: #	if 1 <= 1 then printn "."; else { print "*** FAIL: test 3"; }
  114: 	if 1234 < 1234 then { print "*** FAIL: test 4"; quitbird; } else print "ok";
  115: 	is = [ 2, 3, 4, 7..11 ];
  116: 	print "  must be true: ", 1180::/16 ~ [ 1100::/8{ 15 , 17 } ];
  117: 	print "  data types; must be true: ", 12::34 = 12::34, ",", 1 ~ [1,2,3], ",", 5 ~ [1..20], ",", 10 ~ is, ",", 2 ~ [ 1, 2, 3 ], ",", 5 ~ [ 4 .. 7 ], ",", 12::34 ~ [ 12::33..12::35 ], ",", 1020::34 ~ 1000::/8, ",", 1000::/8 ~ 1000::/8, ",", 1000::/8 ~ [ 1000::/8+ ];
  118: 	print "  must be true: ", true && true, ",", true || false;
  119: 
  120: #	print "  must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
  121: 	print "  data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ is, ",", 12::34 ~ [ 12::33, 12::35 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1000::/9 ~ [ 1000::/8- ], ",", 1000::/17 ~ [ 1000::/8{ 15 , 16 } ], ",", true && false;
  122: 
  123: 	px = 1020::/18;
  124: 	print "Testing prefixes: 1020::/18 = ", px;
  125: 	p = 1234:5678::;
  126: 	print "Testing mask : 1200:: = ", p.mask(8);
  127: 	
  128: 	pp = (1, 2);
  129: 	print "Testing pairs: (1,2) = ", (1,2), " = ", pp;
  130: 	print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC;
  131: 
  132: 	s = "Hello";
  133: 	print "Testing string: ", s, " true: ", s ~ "Hell*", " false: ", s ~ "ell*";
  134: 	
  135: 	b = true;
  136: 	print "Testing bool: ", b, ", ", !b;
  137: 	
  138: 	pxs = [ 1102::/16, 1104::/16+];
  139: 	print "Testing prefix sets: ";
  140: 	print pxs;
  141: 	print "  must be true:  ",	1102::/16 ~ pxs, ",", 1104::/16 ~ pxs, ",", 1104::/18 ~ pxs, ",", 1104::/32 ~ pxs;
  142: 	print "  must be false: ",	1101::/16 ~ pxs, ",", 1103::/16 ~ pxs, ",", 1102::/15 ~ pxs, ",", 1102::/17 ~ pxs, ",",
  143: 					1102::/32 ~ pxs, ",", 1104::/15 ~ pxs;
  144: 
  145: 	test_pxset([ 1000::/16{8,12}, 2000::/16{24,28} ]);
  146: 	print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
  147: 
  148: 	print "Testing functions...";
  149: #	callme ( 1, 2 );
  150: 	callme ( 2, 2 );
  151: 	callme ( 2, 2 );
  152: 	callme ( 3, 2 );
  153: 	callme ( 4, 2 );
  154: 	callme ( 7, 2 );
  155: 
  156: 	i = fifteen();
  157: 	print "Testing function calls: 15 = ", i;
  158: 
  159: 	paths();
  160: 
  161: 	print "done";
  162: 	quitbird;
  163: #	print "*** FAIL: this is unreachable"; 
  164: }
  165: 
  166: filter testf 
  167: int j; 
  168: { 
  169: 	print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
  170: 	print "This route was from ", from;
  171: 	j = 7;
  172: 	j = 17;
  173: 	if rip_metric > 15 then {
  174:  		reject "RIP Metric is more than infinity";
  175: 	}
  176: 	rip_metric = 14;
  177: 	unset(rip_metric);
  178: 		
  179: 	accept "ok I take that";
  180: }
  181: 
  182: eval __startup();

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>