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