]> git.ipfire.org Git - thirdparty/bird.git/blob - filter/test.conf
Added && and ||.
[thirdparty/bird.git] / filter / test.conf
1 /*
2 * This is an example configuration file.
3 */
4
5 # Yet another comment
6
7 router id 62.168.0.1;
8
9 define xyzzy = (120+10);
10
11 function callme(int arg1; int arg2)
12 int local1;
13 int local2;
14 int i;
15 {
16 printn "Function callme called arguments ", arg1, " and ", arg2, ":" ;
17 i = arg2;
18
19 case arg1 {
20 2: print "dva"; print "jeste jednou dva";
21 3 .. 5: print "tri az pet";
22 else: print "neco jineho";
23 }
24 }
25
26 function fifteen()
27 {
28 print "fifteen called";
29 return 15;
30 }
31
32 function paths()
33 bgpmask p;
34 bgppath p2;
35 clist l;
36 {
37 p = / 4 3 2 1 /;
38 print "Testing path masks: ", p;
39 p2 = prepend( + empty +, 1 );
40 p2 = prepend( p2, 2 );
41 p2 = prepend( p2, 3 );
42 p2 = prepend( p2, 4 );
43 print "Testing paths: ", p2;
44 print "Should be true: ", p2 ~ p;
45 print "4 = ", p2.len;
46 p2 = prepend( p2, 5 );
47 print "Should be false: ", p2 ~ p;
48 print "Should be true: ", p2 ~ / ? 4 3 2 1 /, p2, / ? 4 3 2 1 /;
49 print "Should be true: ", p2 ~ / ? 4 3 ? 1 /, p2, / ? 4 3 ? 1 /;
50 print "5 = ", p2.len;
51
52 l = - empty -;
53 l = add( l, (1,2) );
54 l = add( l, (2,3) );
55 print "Community list (1,2) (2,3) ", l;
56 print "Should be true: ", (2,3) ~ l;
57 l = delete( l, (2,3) );
58 print "Community list (1,2) ", l;
59 print "Should be false: ", (2,3) ~ l;
60 }
61
62 function bla()
63 {
64 print "fifteen called";
65 return 15;
66 }
67
68 define four=4;
69 define onetwo=1.2.3.4;
70
71 function __startup()
72 int i;
73 prefix px;
74 ip p;
75 {
76 print "Testing filter language:";
77 i = four;
78 i = 12*100 + 60/2 + i;
79 i = ( i + 0 );
80 print " arithmetics: 1234 = ", i;
81 printn " if statements ";
82 print "what happens here?";
83 printn ".";
84 if (i = 4) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
85 # if !(i = 3) then { print "*** FAIL: if 0"; quitbird; } else printn ".";
86 if 1234 = i then printn "."; else { print "*** FAIL: if 1 else"; }
87 # if 1 <= 1 then printn "."; else { print "*** FAIL: test 3"; }
88 if 1234 < 1234 then { print "*** FAIL: test 4"; quitbird; } else print "ok";
89 print " must be true: ", 1.2.0.0/16 ~ [ 1.0.0.0/8{ 15 , 17 } ];
90 print " data types; must be true: ", 1.2.3.4 = 1.2.3.4, ",", 1 ~ [1,2,3], ",", 5 ~ [1..20], ",", 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+ ];
91 print " must be true: ", true && true, ",", true || false;
92
93 # print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
94 print " data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ [ 2, 3, 4, 7..11 ], ",", 1.2.3.4 ~ [ 1.2.3.3, 1.2.3.5 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1.0.0.0/8 ~ [ 1.0.0.0/8- ], ",", 1.2.0.0/17 ~ [ 1.0.0.0/8{ 15 , 16 } ], ",", true && false;
95
96 px = 1.2.0.0/18;
97 print "Testing prefixes: 1.2.0.0/18 = ", px;
98 p = 127.1.2.3;
99 print "Testing mask : 127.0.0.0 = ", p.mask(8);
100 print "Testing pairs: (1,2) = ", (1,2);
101 print "Testing enums: ", RTS_DUMMY, " ", RTS_STATIC;
102
103 print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
104
105 print "Testing functions...";
106 # callme ( 1, 2 );
107 callme ( 2, 2 );
108 callme ( 2, 2 );
109 callme ( 3, 2 );
110 callme ( 4, 2 );
111 callme ( 7, 2 );
112
113 i = fifteen();
114 print "Testing function calls: 15 = ", i;
115
116 paths();
117
118 print "1.2.3.4 = ", onetwo;
119
120 print "done";
121 quitbird;
122 # print "*** FAIL: this is unreachable";
123 }
124
125 function __test1()
126 {
127 print bgp_path ~ / 65000 /;
128 }
129
130 function __test2()
131 {
132 print bgp_path ~ / 65000 /;
133 }
134
135 filter testf
136 int j;
137 {
138 print "Heya, filtering route to ", net.ip, " prefixlen ", net.len, " source ", source;
139 print "This route was from ", from;
140 j = 7;
141 j = 17;
142 if rip_metric > 15 then {
143 reject "RIP Metric is more than infinity";
144 }
145 rip_metric = 14;
146 unset(rip_metric);
147
148 accept "ok I take that";
149 }
150
151 eval __startup();