blob: fb504f317f494ab5c804c3776f12ded7b239ad58 [file] [log] [blame]
paul1f377b02005-09-10 18:00:11 +00001#include <zebra.h>
2
3#include "vty.h"
4#include "stream.h"
5#include "privs.h"
6
7#include "bgpd/bgpd.h"
8#include "bgpd/bgp_aspath.h"
9
Paul Jakma0b2aa3a2007-10-14 22:32:21 +000010#define VT100_RESET "\x1b[0m"
11#define VT100_RED "\x1b[31m"
12#define VT100_GREEN "\x1b[32m"
13#define VT100_YELLOW "\x1b[33m"
14#define OK VT100_GREEN "OK" VT100_RESET
15#define FAILED VT100_RED "failed" VT100_RESET
16
paul1f377b02005-09-10 18:00:11 +000017/* need these to link in libbgp */
18struct zebra_privs_t *bgpd_privs = NULL;
19struct thread_master *master = NULL;
20
21static int failed = 0;
22
23/* specification for a test - what the results should be */
24struct test_spec
25{
26 const char *shouldbe; /* the string the path should parse to */
27 const char *shouldbe_delete_confed; /* ditto, but once confeds are deleted */
paul84771ee2005-10-11 03:48:28 +000028 const unsigned int hops; /* aspath_count_hops result */
29 const unsigned int confeds; /* aspath_count_confeds */
paul1f377b02005-09-10 18:00:11 +000030 const int private_as; /* whether the private_as check should pass or fail */
31#define NOT_ALL_PRIVATE 0
32#define ALL_PRIVATE 1
33 const as_t does_loop; /* an ASN which should trigger loop-check */
34 const as_t doesnt_loop; /* one which should not */
35 const as_t first; /* the first ASN, if there is one */
36#define NULL_ASN 0
37};
38
39
40/* test segments to parse and validate, and use for other tests */
41static struct test_segment {
42 const char *name;
43 const char *desc;
44 const u_char asdata[1024];
45 int len;
46 struct test_spec sp;
47} test_segments [] =
48{
49 { /* 0 */
50 "seq1",
51 "seq(8466,3,52737,4096)",
52 { 0x2,0x4, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00 },
53 10,
54 { "8466 3 52737 4096",
55 "8466 3 52737 4096",
56 4, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
57 },
58 { /* 1 */
59 "seq2",
60 "seq(8722) seq(4)",
61 { 0x2,0x1, 0x22,0x12,
62 0x2,0x1, 0x00,0x04 },
63 8,
64 { "8722 4",
65 "8722 4",
66 2, 0, NOT_ALL_PRIVATE, 4, 5, 8722, },
67 },
68 { /* 2 */
69 "seq3",
70 "seq(8466,3,52737,4096,8722,4)",
71 { 0x2,0x6, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00,
72 0x22,0x12, 0x00,0x04},
73 14,
74 { "8466 3 52737 4096 8722 4",
75 "8466 3 52737 4096 8722 4",
76 6, 0, NOT_ALL_PRIVATE, 3, 5, 8466 },
77 },
78 { /* 3 */
79 "seqset",
80 "seq(8482,51457) set(5204)",
81 { 0x2,0x2, 0x21,0x22, 0xc9,0x01,
82 0x1,0x1, 0x14,0x54 },
83 10,
84 { "8482 51457 {5204}",
85 "8482 51457 {5204}",
Paul Jakma1f742f22006-08-06 15:52:11 +000086 3, 0, NOT_ALL_PRIVATE, 5204, 51456, 8482},
paul1f377b02005-09-10 18:00:11 +000087 },
88 { /* 4 */
89 "seqset2",
90 "seq(8467, 59649) set(4196,48658) set(17322,30745)",
91 { 0x2,0x2, 0x21,0x13, 0xe9,0x01,
92 0x1,0x2, 0x10,0x64, 0xbe,0x12,
93 0x1,0x2, 0x43,0xaa, 0x78,0x19 },
94 18,
95 { "8467 59649 {4196,48658} {17322,30745}",
96 "8467 59649 {4196,48658} {17322,30745}",
97 4, 0, NOT_ALL_PRIVATE, 48658, 1, 8467},
98 },
99 { /* 5 */
100 "multi",
101 "seq(6435,59408,21665) set(2457,61697,4369), seq(1842,41590,51793)",
102 { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
103 0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11,
104 0x2,0x3, 0x07,0x32, 0xa2,0x76, 0xca,0x51 },
105 24,
106 { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
107 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
108 7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
109 },
110 { /* 6 */
111 "confed",
112 "confseq(123,456,789)",
113 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15 },
114 8,
115 { "(123 456 789)",
116 "",
117 0, 3, NOT_ALL_PRIVATE, 789, 1, NULL_ASN },
118 },
119 { /* 7 */
120 "confed2",
121 "confseq(123,456,789) confseq(111,222)",
122 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
123 0x3,0x2, 0x00,0x6f, 0x00,0xde },
124 14,
125 { "(123 456 789) (111 222)",
126 "",
127 0, 5, NOT_ALL_PRIVATE, 111, 1, NULL_ASN },
128 },
129 { /* 8 */
130 "confset",
131 "confset(456,123,789)",
132 { 0x4,0x3, 0x01,0xc8, 0x00,0x7b, 0x03,0x15 },
133 8,
134 { "[123,456,789]",
135 "[123,456,789]",
136 0, 1, NOT_ALL_PRIVATE, 123, 1, NULL_ASN },
137 },
138 { /* 9 */
139 "confmulti",
140 "confseq(123,456,789) confset(222,111) seq(8722) set(4196,48658)",
141 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
142 0x4,0x2, 0x00,0xde, 0x00,0x6f,
143 0x2,0x1, 0x22,0x12,
144 0x1,0x2, 0x10,0x64, 0xbe,0x12 },
145 24,
146 { "(123 456 789) [111,222] 8722 {4196,48658}",
147 "8722 {4196,48658}",
148 2, 4, NOT_ALL_PRIVATE, 123, 1, NULL_ASN },
149 },
150 { /* 10 */
151 "seq4",
152 "seq(8466,2,52737,4096,8722,4)",
153 { 0x2,0x6, 0x21,0x12, 0x00,0x02, 0xce,0x01, 0x10,0x00,
154 0x22,0x12, 0x00,0x04},
155 14,
156 { "8466 2 52737 4096 8722 4",
157 "8466 2 52737 4096 8722 4",
158 6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 },
159 },
160 { /* 11 */
161 "tripleseq1",
162 "seq(8466,2,52737) seq(4096,8722,4) seq(8722)",
163 { 0x2,0x3, 0x21,0x12, 0x00,0x02, 0xce,0x01,
164 0x2,0x3, 0x10,0x00, 0x22,0x12, 0x00,0x04,
165 0x2,0x1, 0x22,0x12},
166 20,
167 { "8466 2 52737 4096 8722 4 8722",
168 "8466 2 52737 4096 8722 4 8722",
169 7, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 },
170 },
171 { /* 12 */
172 "someprivate",
173 "seq(8466,64512,52737,65535)",
174 { 0x2,0x4, 0x21,0x12, 0xfc,0x00, 0xce,0x01, 0xff,0xff },
175 10,
176 { "8466 64512 52737 65535",
177 "8466 64512 52737 65535",
178 4, 0, NOT_ALL_PRIVATE, 65535, 4, 8466 },
179 },
180 { /* 13 */
181 "allprivate",
182 "seq(65534,64512,64513,65535)",
183 { 0x2,0x4, 0xff,0xfe, 0xfc,0x00, 0xfc,0x01, 0xff,0xff },
184 10,
185 { "65534 64512 64513 65535",
186 "65534 64512 64513 65535",
187 4, 0, ALL_PRIVATE, 65534, 4, 65534 },
188 },
189 { /* 14 */
190 "long",
191 "seq(8466,3,52737,4096,34285,<repeated 49 more times>)",
192 { 0x2,0xfa, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
193 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
194 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
195 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
196 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
197 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
198 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
199 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
200 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
201 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
202 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
203 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
204 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
205 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
206 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
207 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
208 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
209 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
210 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
211 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
212 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
213 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
214 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
215 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
216 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
217 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
218 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
219 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
220 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
221 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
222 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
223 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
224 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
225 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
226 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
227 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
228 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
229 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
230 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
231 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
232 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
233 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
234 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
235 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
236 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
237 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
238 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
239 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
240 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
241 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, },
242 502,
243 { "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
244 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
245 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
246 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
247 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
248 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
249 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
250 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
251 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
252 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
253 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
254 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
255 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
256 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
257 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
258 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
259 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
260 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
261 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
262 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
263 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
264 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
265 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
266 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
267 "8466 3 52737 4096 34285 8466 3 52737 4096 34285",
268
269 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
270 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
271 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
272 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
273 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
274 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
275 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
276 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
277 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
278 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
279 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
280 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
281 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
282 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
283 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
284 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
285 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
286 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
287 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
288 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
289 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
290 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
291 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
292 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
293 "8466 3 52737 4096 34285 8466 3 52737 4096 34285",
294 250, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
295 },
paul59064762005-11-23 02:48:14 +0000296 { /* 15 */
297 "seq1extra",
298 "seq(8466,3,52737,4096,3456)",
299 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 },
300 12,
301 { "8466 3 52737 4096 3456",
302 "8466 3 52737 4096 3456",
303 5, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
304 },
305 { /* 16 */
306 "empty",
307 "<empty>",
308 {},
309 0,
310 { "", "", 0, 0, 0, 0, 0, 0 },
311 },
Paul Jakma5d932f62006-03-30 13:42:50 +0000312 { /* 17 */
313 "redundantset",
314 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)",
315 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80,
316 0x1,0x4, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9 },
317 22,
318 {
319 /* We shouldn't ever /generate/ such paths. However, we should
320 * cope with them fine.
321 */
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000322 "8466 3 52737 4096 3456 {7099,8153}",
323 "8466 3 52737 4096 3456 {7099,8153}",
324 6, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
325 },
326 { /* 18 */
327 "reconcile_lead_asp",
328 "seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)",
329 { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
330 0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
331 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 },
332 24,
333 { "6435 59408 21665 {23456} 23456 23456 23456",
334 "6435 59408 21665 {23456} 23456 23456 23456",
335 7, 0, NOT_ALL_PRIVATE, 23456, 1, 6435 },
336 },
337 { /* 19 */
338 "reconcile_new_asp",
339 "set(2457,61697,4369), seq(1842,41591,51793)",
340 {
341 0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11,
342 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51 },
343 16,
344 { "{2457,4369,61697} 1842 41591 51793",
345 "{2457,4369,61697} 1842 41591 51793",
346 4, 0, NOT_ALL_PRIVATE, 51793, 1, 2457 },
347 },
348 { /* 20 */
349 "reconcile_confed",
350 "confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665)"
351 " set(23456,23456,23456), seq(23456,23456,23456)",
352 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
353 0x4,0x3, 0x01,0xc8, 0x00,0x7c, 0x03,0x14,
354 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
355 0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
356 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 },
357 40,
358 { "(123 456 789) [124,456,788] 6435 59408 21665"
359 " {23456} 23456 23456 23456",
360 "6435 59408 21665 {23456} 23456 23456 23456",
361 7, 4, NOT_ALL_PRIVATE, 23456, 1, 6435 },
362 },
363 { /* 21 */
364 "reconcile_start_trans",
365 "seq(23456,23456,23456) seq(6435,59408,21665)",
366 { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
367 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, },
368 16,
369 { "23456 23456 23456 6435 59408 21665",
370 "23456 23456 23456 6435 59408 21665",
371 6, 0, NOT_ALL_PRIVATE, 21665, 1, 23456 },
372 },
373 { /* 22 */
374 "reconcile_start_trans4",
375 "seq(1842,41591,51793) seq(6435,59408,21665)",
376 { 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51,
377 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, },
378 16,
379 { "1842 41591 51793 6435 59408 21665",
380 "1842 41591 51793 6435 59408 21665",
381 6, 0, NOT_ALL_PRIVATE, 41591, 1, 1842 },
382 },
383 { /* 23 */
384 "reconcile_start_trans_error",
385 "seq(23456,23456,23456) seq(6435,59408)",
386 { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
387 0x2,0x2, 0x19,0x23, 0xe8,0x10, },
388 14,
389 { "23456 23456 23456 6435 59408",
390 "23456 23456 23456 6435 59408",
391 5, 0, NOT_ALL_PRIVATE, 59408, 1, 23456 },
392 },
393 { /* 24 */
394 "redundantset2",
395 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)",
396 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80,
397 0x1,0x5, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9, 0x1b,0xbb,},
398 24,
399 {
400 /* We should weed out duplicate set members. */
401 "8466 3 52737 4096 3456 {7099,8153}",
402 "8466 3 52737 4096 3456 {7099,8153}",
Paul Jakma5d932f62006-03-30 13:42:50 +0000403 6, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
404 },
Paul Jakmad38e8d62008-02-23 16:57:03 +0000405 { /* 25 */
406 "zero-size overflow",
407 "#ASNs = 0, data = seq(8466 3 52737 4096 3456)",
408 { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 },
409 12,
410 { "", "",
411 0, 0, 0, 0, 0, 0 },
412 },
413 { /* 26 */
414 "zero-size overflow + valid segment",
415 "seq(#AS=0:8466 3 52737),seq(4096 3456)",
416 { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01,
417 0x2,0x2, 0x10,0x00, 0x0d,0x80 },
418 14
419 ,
420 { "", "",
421 0, 0, 0, 0, 0, 0 },
422 },
paul1f377b02005-09-10 18:00:11 +0000423 { NULL, NULL, {0}, 0, { NULL, 0, 0 } }
424};
425
426/* prepending tests */
427static struct tests {
428 const struct test_segment *test1;
429 const struct test_segment *test2;
430 struct test_spec sp;
431} prepend_tests[] =
432{
433 { &test_segments[0], &test_segments[1],
434 { "8466 3 52737 4096 8722 4",
435 "8466 3 52737 4096 8722 4",
436 6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 },
437 },
438 { &test_segments[1], &test_segments[3],
439 { "8722 4 8482 51457 {5204}",
440 "8722 4 8482 51457 {5204}",
441 5, 0, NOT_ALL_PRIVATE, 5204, 1, 8722 }
442 },
443 { &test_segments[3], &test_segments[4],
444 { "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
445 "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
446 7, 0, NOT_ALL_PRIVATE, 5204, 1, 8482 },
447 },
448 { &test_segments[4], &test_segments[5],
449 { "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
450 " {2457,4369,61697} 1842 41590 51793",
451 "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
452 " {2457,4369,61697} 1842 41590 51793",
453 11, 0, NOT_ALL_PRIVATE, 61697, 1, 8467 }
454 },
455 { &test_segments[5], &test_segments[6],
456 { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793 (123 456 789)",
457 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793 (123 456 789)",
458 7, 3, NOT_ALL_PRIVATE, 123, 1, 6435 },
459 },
460 { &test_segments[6], &test_segments[7],
461 { "(123 456 789) (123 456 789) (111 222)",
462 "",
463 0, 8, NOT_ALL_PRIVATE, 111, 1, 0 }
464 },
465 { &test_segments[7], &test_segments[8],
466 { "(123 456 789) (111 222) [123,456,789]",
467 "",
468 0, 6, NOT_ALL_PRIVATE, 111, 1, 0 }
469 },
470 { &test_segments[8], &test_segments[9],
471 { "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
472 "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
473 2, 5, NOT_ALL_PRIVATE, 456, 1, NULL_ASN },
474 },
475 { &test_segments[9], &test_segments[8],
476 { "(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]",
477 "8722 {4196,48658} [123,456,789]",
478 2, 5, NOT_ALL_PRIVATE, 48658, 1, NULL_ASN },
479 },
480 { &test_segments[14], &test_segments[11],
481 { "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
482 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
483 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
484 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
485 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
486 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
487 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
488 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
489 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
490 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
491 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
492 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
493 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
494 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
495 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
496 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
497 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
498 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
499 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
500 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
501 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
502 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
503 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
504 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
505 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
506 "8466 2 52737 4096 8722 4 8722",
507
508 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
509 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
510 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
511 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
512 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
513 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
514 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
515 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
516 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
517 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
518 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
519 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
520 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
521 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
522 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
523 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
524 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
525 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
526 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
527 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
528 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
529 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
530 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
531 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
532 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
533 "8466 2 52737 4096 8722 4 8722",
534 257, 0, NOT_ALL_PRIVATE, 4096, 1000, 8466 },
535 },
536 { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } },
537};
538
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000539struct tests reconcile_tests[] =
540{
541 { &test_segments[18], &test_segments[19],
542 { "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
543 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
544 7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
545 },
546 { &test_segments[19], &test_segments[18],
547 /* AS_PATH (19) has more hops than NEW_AS_PATH,
548 * so just AS_PATH should be used (though, this practice
549 * is bad imho).
550 */
551 { "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
552 "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
553 11, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
554 },
555 { &test_segments[20], &test_segments[19],
556 { "(123 456 789) [124,456,788] 6435 59408 21665"
557 " {2457,4369,61697} 1842 41591 51793",
558 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
559 7, 4, NOT_ALL_PRIVATE, 51793, 1, 6435 },
560 },
561 { &test_segments[21], &test_segments[22],
562 { "1842 41591 51793 6435 59408 21665",
563 "1842 41591 51793 6435 59408 21665",
564 6, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 },
565 },
566 { &test_segments[23], &test_segments[22],
567 { "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
568 "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
569 11, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 },
570 },
571 { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } },
572};
573
paul1f377b02005-09-10 18:00:11 +0000574struct tests aggregate_tests[] =
575{
paul1f377b02005-09-10 18:00:11 +0000576 { &test_segments[0], &test_segments[2],
577 { "8466 3 52737 4096 {4,8722}",
578 "8466 3 52737 4096 {4,8722}",
579 5, 0, NOT_ALL_PRIVATE, 4, 1, 8466 },
580 },
581 { &test_segments[2], &test_segments[0],
582 { "8466 3 52737 4096 {4,8722}",
583 "8466 3 52737 4096 {4,8722}",
584 5, 0, NOT_ALL_PRIVATE, 8722, 1, 8466 },
585 },
586 { &test_segments[2], &test_segments[10],
587 { "8466 {2,3,4,4096,8722,52737}",
588 "8466 {2,3,4,4096,8722,52737}",
589 2, 0, NOT_ALL_PRIVATE, 8722, 5, 8466 },
590 },
591 { &test_segments[10], &test_segments[2],
592 { "8466 {2,3,4,4096,8722,52737}",
593 "8466 {2,3,4,4096,8722,52737}",
594 2, 0, NOT_ALL_PRIVATE, 2, 20000, 8466 },
595 },
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000596
597 { &test_segments[5], &test_segments[18],
598 { "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
599 "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
600 4, 0, NOT_ALL_PRIVATE, 41590, 1, 6435 },
601 },
602
paul1f377b02005-09-10 18:00:11 +0000603 { NULL, NULL, { NULL, 0, 0} },
604};
605
606struct compare_tests
607{
608 int test_index1;
609 int test_index2;
610#define CMP_RES_YES 1
611#define CMP_RES_NO 0
612 char shouldbe_cmp;
613 char shouldbe_confed;
614} left_compare [] =
615{
616 { 0, 1, CMP_RES_NO, CMP_RES_NO },
617 { 0, 2, CMP_RES_YES, CMP_RES_NO },
618 { 0, 11, CMP_RES_YES, CMP_RES_NO },
paul59064762005-11-23 02:48:14 +0000619 { 0, 15, CMP_RES_YES, CMP_RES_NO },
620 { 0, 16, CMP_RES_NO, CMP_RES_NO },
paul1f377b02005-09-10 18:00:11 +0000621 { 1, 11, CMP_RES_NO, CMP_RES_NO },
622 { 6, 7, CMP_RES_NO, CMP_RES_YES },
623 { 6, 8, CMP_RES_NO, CMP_RES_NO },
624 { 7, 8, CMP_RES_NO, CMP_RES_NO },
625 { 1, 9, CMP_RES_YES, CMP_RES_NO },
626 { 0, 9, CMP_RES_NO, CMP_RES_NO },
627 { 3, 9, CMP_RES_NO, CMP_RES_NO },
628 { 0, 6, CMP_RES_NO, CMP_RES_NO },
629 { 1, 6, CMP_RES_NO, CMP_RES_NO },
630 { 0, 8, CMP_RES_NO, CMP_RES_NO },
631 { 1, 8, CMP_RES_NO, CMP_RES_NO },
632 { 11, 6, CMP_RES_NO, CMP_RES_NO },
633 { 11, 7, CMP_RES_NO, CMP_RES_NO },
634 { 11, 8, CMP_RES_NO, CMP_RES_NO },
635 { 9, 6, CMP_RES_NO, CMP_RES_YES },
636 { 9, 7, CMP_RES_NO, CMP_RES_YES },
637 { 9, 8, CMP_RES_NO, CMP_RES_NO },
638};
639
640/* make an aspath from a data stream */
641static struct aspath *
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000642make_aspath (const u_char *data, size_t len, int use32bit)
paul1f377b02005-09-10 18:00:11 +0000643{
644 struct stream *s = NULL;
645 struct aspath *as;
646
647 if (len)
648 {
649 s = stream_new (len);
650 stream_put (s, data, len);
651 }
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000652 as = aspath_parse (s, len, use32bit);
paul59064762005-11-23 02:48:14 +0000653
654 if (s)
655 stream_free (s);
paul1f377b02005-09-10 18:00:11 +0000656
657 return as;
658}
659
660static void
661printbytes (const u_char *bytes, int len)
662{
663 int i = 0;
664 while (i < len)
665 {
666 if (i % 2)
667 printf ("%02hhx%s", bytes[i], " ");
668 else
669 printf ("0x%02hhx", bytes[i]);
670 i++;
671 }
672 printf ("\n");
673}
674
675/* validate the given aspath */
676static int
677validate (struct aspath *as, const struct test_spec *sp)
678{
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000679 size_t bytes, bytes4;
paul1f377b02005-09-10 18:00:11 +0000680 int fails = 0;
681 const u_char *out;
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000682 static struct stream *s;
683 struct aspath *asinout, *asconfeddel, *asstr, *as4;
paul1f377b02005-09-10 18:00:11 +0000684
685 out = aspath_snmp_pathseg (as, &bytes);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000686 asinout = make_aspath (out, bytes, 0);
687
688 /* Excercise AS4 parsing a bit, with a dogfood test */
689 if (!s)
690 s = stream_new (4096);
691 bytes4 = aspath_put (s, as, 1);
692 as4 = make_aspath (STREAM_DATA(s), bytes4, 1);
paul1f377b02005-09-10 18:00:11 +0000693
694 asstr = aspath_str2aspath (sp->shouldbe);
695
696 asconfeddel = aspath_delete_confed_seq (aspath_dup (asinout));
697
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000698 printf ("got: %s\n", aspath_print(as));
699
paul1f377b02005-09-10 18:00:11 +0000700 /* the parsed path should match the specified 'shouldbe' string.
701 * We should pass the "eat our own dog food" test, be able to output
702 * this path and then input it again. Ie the path resulting from:
703 *
704 * aspath_parse(aspath_put(as))
705 *
706 * should:
707 *
708 * - also match the specified 'shouldbe' value
709 * - hash to same value as original path
710 * - have same hops and confed counts as original, and as the
711 * the specified counts
712 *
713 * aspath_str2aspath() and shouldbe should match
714 *
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000715 * We do the same for:
716 *
717 * aspath_parse(aspath_put(as,USE32BIT))
718 *
paul1f377b02005-09-10 18:00:11 +0000719 * Confederation related tests:
720 * - aspath_delete_confed_seq(aspath) should match shouldbe_confed
721 * - aspath_delete_confed_seq should be idempotent.
722 */
723 if (strcmp(aspath_print (as), sp->shouldbe)
724 /* hash validation */
725 || (aspath_key_make (as) != aspath_key_make (asinout))
726 /* by string */
727 || strcmp(aspath_print (asinout), sp->shouldbe)
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000728 /* By 4-byte parsing */
729 || strcmp(aspath_print (as4), sp->shouldbe)
paul1f377b02005-09-10 18:00:11 +0000730 /* by various path counts */
731 || (aspath_count_hops (as) != sp->hops)
732 || (aspath_count_confeds (as) != sp->confeds)
733 || (aspath_count_hops (asinout) != sp->hops)
734 || (aspath_count_confeds (asinout) != sp->confeds))
735 {
736 failed++;
737 fails++;
738 printf ("shouldbe:\n%s\n", sp->shouldbe);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000739 printf ("as4:\n%s\n", aspath_print (as4));
paul1f377b02005-09-10 18:00:11 +0000740 printf ("hash keys: in: %d out->in: %d\n",
741 aspath_key_make (as), aspath_key_make (asinout));
742 printf ("hops: %d, counted %d %d\n", sp->hops,
743 aspath_count_hops (as),
744 aspath_count_hops (asinout) );
745 printf ("confeds: %d, counted %d %d\n", sp->confeds,
746 aspath_count_confeds (as),
747 aspath_count_confeds (asinout));
748 printf ("out->in:\n%s\nbytes: ", aspath_print(asinout));
749 printbytes (out, bytes);
750 }
751 /* basic confed related tests */
752 if ((aspath_print (asconfeddel) == NULL
753 && sp->shouldbe_delete_confed != NULL)
754 || (aspath_print (asconfeddel) != NULL
755 && sp->shouldbe_delete_confed == NULL)
756 || strcmp(aspath_print (asconfeddel), sp->shouldbe_delete_confed)
757 /* delete_confed_seq should be idempotent */
758 || (aspath_key_make (asconfeddel)
759 != aspath_key_make (aspath_delete_confed_seq (asconfeddel))))
760 {
761 failed++;
762 fails++;
763 printf ("confed_del: %s\n", aspath_print (asconfeddel));
764 printf ("should be: %s\n", sp->shouldbe_delete_confed);
765 }
766 /* aspath_str2aspath test */
767 if ((aspath_print (asstr) == NULL && sp->shouldbe != NULL)
768 || (aspath_print (asstr) != NULL && sp->shouldbe == NULL)
769 || strcmp(aspath_print (asstr), sp->shouldbe))
770 {
771 failed++;
772 fails++;
773 printf ("asstr: %s\n", aspath_print (asstr));
774 }
775
776 /* loop, private and first as checks */
Paul Jakma1f742f22006-08-06 15:52:11 +0000777 if ((sp->does_loop && aspath_loop_check (as, sp->does_loop) == 0)
778 || (sp->doesnt_loop && aspath_loop_check (as, sp->doesnt_loop) != 0)
paul1f377b02005-09-10 18:00:11 +0000779 || (aspath_private_as_check (as) != sp->private_as)
780 || (aspath_firstas_check (as,sp->first)
781 && sp->first == 0))
782 {
783 failed++;
784 fails++;
785 printf ("firstas: %d, got %d\n", sp->first,
786 aspath_firstas_check (as,sp->first));
787 printf ("loop does: %d %d, doesnt: %d %d\n",
788 sp->does_loop, aspath_loop_check (as, sp->does_loop),
789 sp->doesnt_loop, aspath_loop_check (as, sp->doesnt_loop));
790 printf ("private check: %d %d\n", sp->private_as,
791 aspath_private_as_check (as));
792 }
793 aspath_unintern (asinout);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000794 aspath_unintern (as4);
795
paul6726f952006-01-16 12:06:00 +0000796 aspath_free (asconfeddel);
797 aspath_free (asstr);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000798 stream_reset (s);
paul6726f952006-01-16 12:06:00 +0000799
paul1f377b02005-09-10 18:00:11 +0000800 return fails;
paul1f377b02005-09-10 18:00:11 +0000801}
802
803static void
804empty_get_test ()
805{
806 struct aspath *as = aspath_empty_get ();
807 struct test_spec sp = { "", "", 0, 0, 0, 0, 0, 0 };
808
809 printf ("empty_get_test, as: %s\n",aspath_print (as));
810 if (!validate (as, &sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000811 printf ("%s\n", OK);
paul1f377b02005-09-10 18:00:11 +0000812 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000813 printf ("%s!\n", FAILED);
paul1f377b02005-09-10 18:00:11 +0000814
815 printf ("\n");
paul6726f952006-01-16 12:06:00 +0000816
817 aspath_free (as);
paul1f377b02005-09-10 18:00:11 +0000818}
819
820/* basic parsing test */
821static void
822parse_test (struct test_segment *t)
823{
824 struct aspath *asp;
825
826 printf ("%s: %s\n", t->name, t->desc);
827
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000828 asp = make_aspath (t->asdata, t->len, 0);
paul1f377b02005-09-10 18:00:11 +0000829
830 printf ("aspath: %s\nvalidating...:\n", aspath_print (asp));
831
832 if (!validate (asp, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000833 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +0000834 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000835 printf (FAILED "\n");
paul1f377b02005-09-10 18:00:11 +0000836
837 printf ("\n");
838 aspath_unintern (asp);
839}
840
841/* prepend testing */
Paul Jakma5d932f62006-03-30 13:42:50 +0000842static void
paul1f377b02005-09-10 18:00:11 +0000843prepend_test (struct tests *t)
844{
845 struct aspath *asp1, *asp2, *ascratch;
846
847 printf ("prepend %s: %s\n", t->test1->name, t->test1->desc);
848 printf ("to %s: %s\n", t->test2->name, t->test2->desc);
849
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000850 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
851 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
paul1f377b02005-09-10 18:00:11 +0000852
853 ascratch = aspath_dup (asp2);
854 aspath_unintern (asp2);
855
856 asp2 = aspath_prepend (asp1, ascratch);
857
858 printf ("aspath: %s\n", aspath_print (asp2));
859
860 if (!validate (asp2, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000861 printf ("%s\n", OK);
paul1f377b02005-09-10 18:00:11 +0000862 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000863 printf ("%s!\n", FAILED);
paul1f377b02005-09-10 18:00:11 +0000864
865 printf ("\n");
866 aspath_unintern (asp1);
867 aspath_free (asp2);
868}
869
870/* empty-prepend testing */
Paul Jakma5d932f62006-03-30 13:42:50 +0000871static void
paul1f377b02005-09-10 18:00:11 +0000872empty_prepend_test (struct test_segment *t)
873{
874 struct aspath *asp1, *asp2, *ascratch;
875
876 printf ("empty prepend %s: %s\n", t->name, t->desc);
877
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000878 asp1 = make_aspath (t->asdata, t->len, 0);
paul1f377b02005-09-10 18:00:11 +0000879 asp2 = aspath_empty ();
880
881 ascratch = aspath_dup (asp2);
882 aspath_unintern (asp2);
883
884 asp2 = aspath_prepend (asp1, ascratch);
885
886 printf ("aspath: %s\n", aspath_print (asp2));
887
888 if (!validate (asp2, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000889 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +0000890 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000891 printf (FAILED "!\n");
paul1f377b02005-09-10 18:00:11 +0000892
893 printf ("\n");
894 aspath_unintern (asp1);
895 aspath_free (asp2);
896}
897
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000898/* as2+as4 reconciliation testing */
899static void
900as4_reconcile_test (struct tests *t)
901{
902 struct aspath *asp1, *asp2, *ascratch;
903
904 printf ("reconciling %s:\n %s\n", t->test1->name, t->test1->desc);
905 printf ("with %s:\n %s\n", t->test2->name, t->test2->desc);
906
907 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
908 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
909
910 ascratch = aspath_reconcile_as4 (asp1, asp2);
911
912 if (!validate (ascratch, &t->sp))
913 printf (OK "\n");
914 else
915 printf (FAILED "!\n");
916
917 printf ("\n");
918 aspath_unintern (asp1);
919 aspath_unintern (asp2);
920 aspath_free (ascratch);
921}
922
923
paul1f377b02005-09-10 18:00:11 +0000924/* aggregation testing */
Paul Jakma5d932f62006-03-30 13:42:50 +0000925static void
paul1f377b02005-09-10 18:00:11 +0000926aggregate_test (struct tests *t)
927{
928 struct aspath *asp1, *asp2, *ascratch;
929
930 printf ("aggregate %s: %s\n", t->test1->name, t->test1->desc);
931 printf ("with %s: %s\n", t->test2->name, t->test2->desc);
932
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000933 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
934 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
paul1f377b02005-09-10 18:00:11 +0000935
936 ascratch = aspath_aggregate (asp1, asp2);
937
paul1f377b02005-09-10 18:00:11 +0000938 if (!validate (ascratch, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000939 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +0000940 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000941 printf (FAILED "!\n");
paul1f377b02005-09-10 18:00:11 +0000942
943 printf ("\n");
944 aspath_unintern (asp1);
945 aspath_unintern (asp2);
946 aspath_free (ascratch);
947/* aspath_unintern (ascratch);*/
948}
949
950/* cmp_left tests */
951static void
952cmp_test ()
953{
paul84771ee2005-10-11 03:48:28 +0000954 unsigned int i;
paul1f377b02005-09-10 18:00:11 +0000955#define CMP_TESTS_MAX \
956 (sizeof(left_compare) / sizeof (struct compare_tests))
957
958 for (i = 0; i < CMP_TESTS_MAX; i++)
959 {
960 struct test_segment *t1 = &test_segments[left_compare[i].test_index1];
961 struct test_segment *t2 = &test_segments[left_compare[i].test_index2];
962 struct aspath *asp1, *asp2;
963
964 printf ("left cmp %s: %s\n", t1->name, t1->desc);
965 printf ("and %s: %s\n", t2->name, t2->desc);
966
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000967 asp1 = make_aspath (t1->asdata, t1->len, 0);
968 asp2 = make_aspath (t2->asdata, t2->len, 0);
paul1f377b02005-09-10 18:00:11 +0000969
970 if (aspath_cmp_left (asp1, asp2) != left_compare[i].shouldbe_cmp
971 || aspath_cmp_left (asp2, asp1) != left_compare[i].shouldbe_cmp
972 || aspath_cmp_left_confed (asp1, asp2)
973 != left_compare[i].shouldbe_confed
974 || aspath_cmp_left_confed (asp2, asp1)
975 != left_compare[i].shouldbe_confed)
976 {
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000977 failed++;
978 printf (FAILED "\n");
paul1f377b02005-09-10 18:00:11 +0000979 printf ("result should be: cmp: %d, confed: %d\n",
980 left_compare[i].shouldbe_cmp,
981 left_compare[i].shouldbe_confed);
982 printf ("got: cmp %d, cmp_confed: %d\n",
983 aspath_cmp_left (asp1, asp2),
984 aspath_cmp_left_confed (asp1, asp2));
985 printf("path1: %s\npath2: %s\n", aspath_print (asp1),
986 aspath_print (asp2));
paul1f377b02005-09-10 18:00:11 +0000987 }
988 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000989 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +0000990
991 printf ("\n");
992 aspath_unintern (asp1);
993 aspath_unintern (asp2);
994 }
995}
996
997int
998main (void)
999{
1000 int i = 0;
1001 aspath_init();
1002 while (test_segments[i].name)
1003 {
1004 parse_test (&test_segments[i]);
1005 empty_prepend_test (&test_segments[i++]);
1006 }
1007
1008 i = 0;
1009 while (prepend_tests[i].test1)
1010 prepend_test (&prepend_tests[i++]);
1011
1012 i = 0;
1013 while (aggregate_tests[i].test1)
1014 aggregate_test (&aggregate_tests[i++]);
1015
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001016 i = 0;
1017
1018 while (reconcile_tests[i].test1)
1019 as4_reconcile_test (&reconcile_tests[i++]);
1020
1021 i = 0;
1022
paul1f377b02005-09-10 18:00:11 +00001023 cmp_test();
1024
1025 i = 0;
1026
1027 empty_get_test();
1028
1029 printf ("failures: %d\n", failed);
1030 printf ("aspath count: %ld\n", aspath_count());
1031
1032 return (failed + aspath_count());
1033}