]>
Commit | Line | Data |
---|---|---|
4515bdba PM |
1 | /* |
2 | * This is an example configuration file. | |
64ba9f7b | 3 | * FIXME: add all examples from docs here. |
4515bdba PM |
4 | */ |
5 | ||
6 | # Yet another comment | |
7 | ||
8 | router id 62.168.0.1; | |
9 | ||
60de3356 | 10 | define xyzzy = (120+10); |
4515bdba | 11 | |
92a72a4c OZ |
12 | |
13 | function mkpair(int a) | |
14 | { | |
15 | return (1, a); | |
16 | } | |
17 | ||
18 | function mkpath(int a; int b) | |
19 | { | |
20 | return [= a b 3 2 1 =]; | |
21 | } | |
22 | ||
2d496d20 | 23 | function callme(int arg1; int arg2) |
4515bdba PM |
24 | int local1; |
25 | int local2; | |
26 | int i; | |
27 | { | |
995e5894 | 28 | printn "Function callme called arguments ", arg1, " and ", arg2, ":" ; |
4515bdba PM |
29 | i = arg2; |
30 | ||
31 | case arg1 { | |
32 | 2: print "dva"; print "jeste jednou dva"; | |
33 | 3 .. 5: print "tri az pet"; | |
34 | else: print "neco jineho"; | |
35 | } | |
36 | } | |
37 | ||
2d496d20 PM |
38 | function fifteen() |
39 | { | |
40 | print "fifteen called"; | |
41 | return 15; | |
42 | } | |
43 | ||
77de6882 | 44 | function paths() |
cf186034 OZ |
45 | bgpmask pm1; |
46 | bgpmask pm2; | |
e399b6f6 | 47 | bgppath p2; |
9c400ec9 | 48 | clist l; |
77de6882 | 49 | { |
cf186034 OZ |
50 | pm1 = / 4 3 2 1 /; |
51 | pm2 = [= 4 3 2 1 =]; | |
52 | print "Testing path masks: ", pm1, " ", pm2; | |
e399b6f6 PM |
53 | p2 = prepend( + empty +, 1 ); |
54 | p2 = prepend( p2, 2 ); | |
55 | p2 = prepend( p2, 3 ); | |
56 | p2 = prepend( p2, 4 ); | |
57 | print "Testing paths: ", p2; | |
cf186034 | 58 | print "Should be true: ", p2 ~ pm1, " ", p2 ~ pm2; |
684c6f5a | 59 | print "4 = ", p2.len; |
e399b6f6 | 60 | p2 = prepend( p2, 5 ); |
cf186034 OZ |
61 | print "Should be false: ", p2 ~ pm1, " ", p2 ~ pm2; |
62 | print "Should be true: ", p2 ~ / ? 4 3 2 1 /, " ", p2, " ", / ? 4 3 2 1 /; | |
63 | print "Should be true: ", p2 ~ [= * 4 3 * 1 =], " ", p2, " ", [= * 4 3 * 1 =]; | |
92a72a4c | 64 | print "Should be true: ", p2 ~ [= (3+2) (2*2) 3 2 1 =], " ", p2 ~ mkpath(5, 4); |
684c6f5a | 65 | print "5 = ", p2.len; |
cf186034 OZ |
66 | |
67 | pm1 = [= 1 2 * 3 4 5 =]; | |
68 | p2 = prepend( + empty +, 5 ); | |
69 | p2 = prepend( p2, 4 ); | |
70 | p2 = prepend( p2, 3 ); | |
71 | p2 = prepend( p2, 3 ); | |
72 | p2 = prepend( p2, 2 ); | |
73 | p2 = prepend( p2, 1 ); | |
74 | print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1; | |
9c400ec9 PM |
75 | |
76 | l = - empty -; | |
77 | l = add( l, (1,2) ); | |
4444ed2b PM |
78 | l = add( l, (2,3) ); |
79 | print "Community list (1,2) (2,3) ", l; | |
2bd2de01 | 80 | print "Should be true: ", (2,3) ~ l; |
4444ed2b PM |
81 | l = delete( l, (2,3) ); |
82 | print "Community list (1,2) ", l; | |
2bd2de01 | 83 | print "Should be false: ", (2,3) ~ l; |
77de6882 PM |
84 | } |
85 | ||
94d9dfa4 PM |
86 | function bla() |
87 | { | |
88 | print "fifteen called"; | |
89 | return 15; | |
90 | } | |
91 | ||
cbfd671f PM |
92 | define four=4; |
93 | define onetwo=1.2.3.4; | |
94 | ||
4bb18dd2 PM |
95 | function __test1() |
96 | { | |
97 | if source ~ [ RTS_BGP, RTS_STATIC ] then { | |
98 | # ospf_metric1 = 65535; | |
99 | # ospf_metric2 = 1000; | |
100 | ospf_tag = 0x12345678; | |
101 | accept; | |
102 | } reject; | |
103 | } | |
104 | ||
105 | function __test2() | |
106 | { | |
107 | if source ~ [ RTS_BGP, RTS_STATIC ] then { | |
108 | # ospf_metric1 = 65535; | |
109 | # ospf_metric2 = 1000; | |
110 | ospf_tag = 0x12345678; | |
111 | accept; | |
112 | } reject; | |
113 | } | |
114 | ||
b1a597e0 OZ |
115 | function test_pxset(prefix set pxs) |
116 | { | |
117 | print " must be true: ", 10.0.0.0/8 ~ pxs, ",", 10.0.0.0/10 ~ pxs, ",", 10.0.0.0/12 ~ pxs, ",", | |
118 | 20.0.0.0/24 ~ pxs, ",", 20.0.40.0/24 ~ pxs, ",", 20.0.0.0/26 ~ pxs, ",", | |
119 | 20.0.100.0/26 ~ pxs, ",", 20.0.0.0/28 ~ pxs, ",", 20.0.255.0/28 ~ pxs; | |
120 | print " must be false: ", 10.0.0.0/7 ~ pxs, ",", 10.0.0.0/13 ~ pxs, ",", 10.0.0.0/16 ~ pxs, ",", | |
121 | 20.0.0.0/16 ~ pxs, ",", 20.0.0.0/23 ~ pxs, ",", 20.0.0.0/29 ~ pxs, ",", | |
122 | 11.0.0.0/10 ~ pxs, ",", 20.1.0.0/26 ~ pxs; | |
123 | } | |
124 | ||
94d9dfa4 | 125 | function __startup() |
4515bdba | 126 | int i; |
b1a597e0 | 127 | bool b; |
4515bdba PM |
128 | prefix px; |
129 | ip p; | |
b1a597e0 OZ |
130 | pair pp; |
131 | int set is; | |
132 | prefix set pxs; | |
133 | string s; | |
4515bdba PM |
134 | { |
135 | print "Testing filter language:"; | |
cbfd671f | 136 | i = four; |
c5a06f65 | 137 | i = 12*100 + 60/2 + i; |
4515bdba | 138 | i = ( i + 0 ); |
995e5894 | 139 | print " arithmetics: 1234 = ", i; |
4515bdba | 140 | printn " if statements "; |
995e5894 PM |
141 | print "what happens here?"; |
142 | printn "."; | |
143 | if (i = 4) then { print "*** FAIL: if 0"; quitbird; } else printn "."; | |
144 | # if !(i = 3) then { print "*** FAIL: if 0"; quitbird; } else printn "."; | |
4515bdba | 145 | if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; } |
995e5894 | 146 | # if 1 <= 1 then printn "."; else { print "*** FAIL: test 3"; } |
4515bdba | 147 | if 1234 < 1234 then { print "*** FAIL: test 4"; quitbird; } else print "ok"; |
b1a597e0 | 148 | is = [ 2, 3, 4, 7..11 ]; |
995e5894 | 149 | print " must be true: ", 1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ]; |
b1a597e0 | 150 | print " data types; must be true: ", 1.2.3.4 = 1.2.3.4, ",", 1 ~ [1,2,3], ",", 5 ~ [1..20], ",", 10 ~ is, ",", 2 ~ [ 1, 2, 3 ], ",", 5 ~ [ 4 .. 7 ], ",", 1.2.3.4 ~ [ 1.2.3.3..1.2.3.5 ], ",", 1.2.3.4 ~ 1.0.0.0/8, ",", 1.0.0.0/8 ~ 1.0.0.0/8, ",", 1.0.0.0/8 ~ [ 1.0.0.0/8+ ]; |
5f4aee76 | 151 | print " must be true: ", true && true, ",", true || false; |
995e5894 PM |
152 | |
153 | # print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2; | |
b1a597e0 | 154 | print " data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ is, ",", 1.2.3.4 ~ [ 1.2.3.3, 1.2.3.5 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1.0.0.0/9 ~ [ 1.0.0.0/8- ], ",", 1.2.0.0/17 ~ [ 1.0.0.0/8{ 15 , 16 } ], ",", true && false; |
4515bdba | 155 | |
455ca441 | 156 | px = 1.2.0.0/18; |
995e5894 | 157 | print "Testing prefixes: 1.2.0.0/18 = ", px; |
92a72a4c OZ |
158 | print " must be true: ", 192.168.0.0/16 ~ 192.168.0.0/16, " ", 192.168.0.0/17 ~ 192.168.0.0/16, " ", 192.168.254.0/24 ~ 192.168.0.0/16; |
159 | print " must be false: ", 192.168.0.0/15 ~ 192.168.0.0/16, " ", 192.160.0.0/17 ~ 192.168.0.0/16; | |
160 | ||
4515bdba | 161 | p = 127.1.2.3; |
995e5894 | 162 | print "Testing mask : 127.0.0.0 = ", p.mask(8); |
b1a597e0 OZ |
163 | |
164 | pp = (1, 2); | |
92a72a4c OZ |
165 | print "Testing pairs: (1,2) = ", (1,2), " = ", pp, " = ", (1,1+1), " = ", mkpair(2); |
166 | print " must be true: ", (1,2) = (1,1+1); | |
995e5894 | 167 | print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC; |
4515bdba | 168 | |
b1a597e0 OZ |
169 | s = "Hello"; |
170 | print "Testing string: ", s, " true: ", s ~ "Hell*", " false: ", s ~ "ell*"; | |
171 | ||
172 | b = true; | |
173 | print "Testing bool: ", b, ", ", !b; | |
a6c9f064 OF |
174 | |
175 | if ( b = true ) then print "Testing bool comparison b = true: ", b; | |
176 | else { print "*** FAIL: TRUE test failed" ; quitbird; } | |
b1a597e0 OZ |
177 | |
178 | pxs = [ 1.2.0.0/16, 1.4.0.0/16+]; | |
179 | print "Testing prefix sets: "; | |
180 | print pxs; | |
181 | print " must be true: ", 1.2.0.0/16 ~ pxs, ",", 1.4.0.0/16 ~ pxs, ",", 1.4.0.0/18 ~ pxs, ",", 1.4.0.0/32 ~ pxs; | |
182 | print " must be false: ", 1.1.0.0/16 ~ pxs, ",", 1.3.0.0/16 ~ pxs, ",", 1.2.0.0/15 ~ pxs, ",", 1.2.0.0/17 ~ pxs, ",", | |
183 | 1.2.0.0/32 ~ pxs, ",", 1.4.0.0/15 ~ pxs; | |
184 | ||
185 | test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]); | |
995e5894 | 186 | print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ]; |
4515bdba PM |
187 | |
188 | print "Testing functions..."; | |
189 | # callme ( 1, 2 ); | |
190 | callme ( 2, 2 ); | |
191 | callme ( 2, 2 ); | |
192 | callme ( 3, 2 ); | |
193 | callme ( 4, 2 ); | |
194 | callme ( 7, 2 ); | |
195 | ||
2d496d20 | 196 | i = fifteen(); |
995e5894 | 197 | print "Testing function calls: 15 = ", i; |
2d496d20 | 198 | |
77de6882 PM |
199 | paths(); |
200 | ||
cbfd671f PM |
201 | print "1.2.3.4 = ", onetwo; |
202 | ||
4515bdba PM |
203 | print "done"; |
204 | quitbird; | |
205 | # print "*** FAIL: this is unreachable"; | |
206 | } | |
207 | ||
208 | filter testf | |
209 | int j; | |
210 | { | |
995e5894 PM |
211 | print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source; |
212 | print "This route was from ", from; | |
4515bdba PM |
213 | j = 7; |
214 | j = 17; | |
2e18b87d | 215 | if rip_metric > 15 then { |
c7b43f33 PM |
216 | reject "RIP Metric is more than infinity"; |
217 | } | |
2e18b87d PM |
218 | rip_metric = 14; |
219 | unset(rip_metric); | |
4515bdba | 220 | |
c7b43f33 | 221 | accept "ok I take that"; |
4515bdba | 222 | } |
6be662d9 | 223 | |
a6c9f064 | 224 | eval __startup(); |