blob: c12d07a59db44b8a8ae5465d2a7df9c857fed2a4 [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 },
paul1f377b02005-09-10 18:00:11 +0000405 { NULL, NULL, {0}, 0, { NULL, 0, 0 } }
406};
407
408/* prepending tests */
409static struct tests {
410 const struct test_segment *test1;
411 const struct test_segment *test2;
412 struct test_spec sp;
413} prepend_tests[] =
414{
415 { &test_segments[0], &test_segments[1],
416 { "8466 3 52737 4096 8722 4",
417 "8466 3 52737 4096 8722 4",
418 6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 },
419 },
420 { &test_segments[1], &test_segments[3],
421 { "8722 4 8482 51457 {5204}",
422 "8722 4 8482 51457 {5204}",
423 5, 0, NOT_ALL_PRIVATE, 5204, 1, 8722 }
424 },
425 { &test_segments[3], &test_segments[4],
426 { "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
427 "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
428 7, 0, NOT_ALL_PRIVATE, 5204, 1, 8482 },
429 },
430 { &test_segments[4], &test_segments[5],
431 { "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
432 " {2457,4369,61697} 1842 41590 51793",
433 "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
434 " {2457,4369,61697} 1842 41590 51793",
435 11, 0, NOT_ALL_PRIVATE, 61697, 1, 8467 }
436 },
437 { &test_segments[5], &test_segments[6],
438 { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793 (123 456 789)",
439 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793 (123 456 789)",
440 7, 3, NOT_ALL_PRIVATE, 123, 1, 6435 },
441 },
442 { &test_segments[6], &test_segments[7],
443 { "(123 456 789) (123 456 789) (111 222)",
444 "",
445 0, 8, NOT_ALL_PRIVATE, 111, 1, 0 }
446 },
447 { &test_segments[7], &test_segments[8],
448 { "(123 456 789) (111 222) [123,456,789]",
449 "",
450 0, 6, NOT_ALL_PRIVATE, 111, 1, 0 }
451 },
452 { &test_segments[8], &test_segments[9],
453 { "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
454 "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
455 2, 5, NOT_ALL_PRIVATE, 456, 1, NULL_ASN },
456 },
457 { &test_segments[9], &test_segments[8],
458 { "(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]",
459 "8722 {4196,48658} [123,456,789]",
460 2, 5, NOT_ALL_PRIVATE, 48658, 1, NULL_ASN },
461 },
462 { &test_segments[14], &test_segments[11],
463 { "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
464 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
465 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
466 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
467 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
468 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
469 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
470 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
471 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
472 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
473 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
474 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
475 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
476 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
477 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
478 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
479 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
480 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
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 2 52737 4096 8722 4 8722",
489
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 3 52737 4096 34285 8466 3 52737 4096 34285 "
507 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
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 2 52737 4096 8722 4 8722",
516 257, 0, NOT_ALL_PRIVATE, 4096, 1000, 8466 },
517 },
518 { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } },
519};
520
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000521struct tests reconcile_tests[] =
522{
523 { &test_segments[18], &test_segments[19],
524 { "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
525 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
526 7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
527 },
528 { &test_segments[19], &test_segments[18],
529 /* AS_PATH (19) has more hops than NEW_AS_PATH,
530 * so just AS_PATH should be used (though, this practice
531 * is bad imho).
532 */
533 { "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
534 "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
535 11, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
536 },
537 { &test_segments[20], &test_segments[19],
538 { "(123 456 789) [124,456,788] 6435 59408 21665"
539 " {2457,4369,61697} 1842 41591 51793",
540 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
541 7, 4, NOT_ALL_PRIVATE, 51793, 1, 6435 },
542 },
543 { &test_segments[21], &test_segments[22],
544 { "1842 41591 51793 6435 59408 21665",
545 "1842 41591 51793 6435 59408 21665",
546 6, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 },
547 },
548 { &test_segments[23], &test_segments[22],
549 { "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
550 "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
551 11, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 },
552 },
553 { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } },
554};
555
paul1f377b02005-09-10 18:00:11 +0000556struct tests aggregate_tests[] =
557{
paul1f377b02005-09-10 18:00:11 +0000558 { &test_segments[0], &test_segments[2],
559 { "8466 3 52737 4096 {4,8722}",
560 "8466 3 52737 4096 {4,8722}",
561 5, 0, NOT_ALL_PRIVATE, 4, 1, 8466 },
562 },
563 { &test_segments[2], &test_segments[0],
564 { "8466 3 52737 4096 {4,8722}",
565 "8466 3 52737 4096 {4,8722}",
566 5, 0, NOT_ALL_PRIVATE, 8722, 1, 8466 },
567 },
568 { &test_segments[2], &test_segments[10],
569 { "8466 {2,3,4,4096,8722,52737}",
570 "8466 {2,3,4,4096,8722,52737}",
571 2, 0, NOT_ALL_PRIVATE, 8722, 5, 8466 },
572 },
573 { &test_segments[10], &test_segments[2],
574 { "8466 {2,3,4,4096,8722,52737}",
575 "8466 {2,3,4,4096,8722,52737}",
576 2, 0, NOT_ALL_PRIVATE, 2, 20000, 8466 },
577 },
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000578
579 { &test_segments[5], &test_segments[18],
580 { "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
581 "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
582 4, 0, NOT_ALL_PRIVATE, 41590, 1, 6435 },
583 },
584
paul1f377b02005-09-10 18:00:11 +0000585 { NULL, NULL, { NULL, 0, 0} },
586};
587
588struct compare_tests
589{
590 int test_index1;
591 int test_index2;
592#define CMP_RES_YES 1
593#define CMP_RES_NO 0
594 char shouldbe_cmp;
595 char shouldbe_confed;
596} left_compare [] =
597{
598 { 0, 1, CMP_RES_NO, CMP_RES_NO },
599 { 0, 2, CMP_RES_YES, CMP_RES_NO },
600 { 0, 11, CMP_RES_YES, CMP_RES_NO },
paul59064762005-11-23 02:48:14 +0000601 { 0, 15, CMP_RES_YES, CMP_RES_NO },
602 { 0, 16, CMP_RES_NO, CMP_RES_NO },
paul1f377b02005-09-10 18:00:11 +0000603 { 1, 11, CMP_RES_NO, CMP_RES_NO },
604 { 6, 7, CMP_RES_NO, CMP_RES_YES },
605 { 6, 8, CMP_RES_NO, CMP_RES_NO },
606 { 7, 8, CMP_RES_NO, CMP_RES_NO },
607 { 1, 9, CMP_RES_YES, CMP_RES_NO },
608 { 0, 9, CMP_RES_NO, CMP_RES_NO },
609 { 3, 9, CMP_RES_NO, CMP_RES_NO },
610 { 0, 6, CMP_RES_NO, CMP_RES_NO },
611 { 1, 6, CMP_RES_NO, CMP_RES_NO },
612 { 0, 8, CMP_RES_NO, CMP_RES_NO },
613 { 1, 8, CMP_RES_NO, CMP_RES_NO },
614 { 11, 6, CMP_RES_NO, CMP_RES_NO },
615 { 11, 7, CMP_RES_NO, CMP_RES_NO },
616 { 11, 8, CMP_RES_NO, CMP_RES_NO },
617 { 9, 6, CMP_RES_NO, CMP_RES_YES },
618 { 9, 7, CMP_RES_NO, CMP_RES_YES },
619 { 9, 8, CMP_RES_NO, CMP_RES_NO },
620};
621
622/* make an aspath from a data stream */
623static struct aspath *
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000624make_aspath (const u_char *data, size_t len, int use32bit)
paul1f377b02005-09-10 18:00:11 +0000625{
626 struct stream *s = NULL;
627 struct aspath *as;
628
629 if (len)
630 {
631 s = stream_new (len);
632 stream_put (s, data, len);
633 }
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000634 as = aspath_parse (s, len, use32bit);
paul59064762005-11-23 02:48:14 +0000635
636 if (s)
637 stream_free (s);
paul1f377b02005-09-10 18:00:11 +0000638
639 return as;
640}
641
642static void
643printbytes (const u_char *bytes, int len)
644{
645 int i = 0;
646 while (i < len)
647 {
648 if (i % 2)
649 printf ("%02hhx%s", bytes[i], " ");
650 else
651 printf ("0x%02hhx", bytes[i]);
652 i++;
653 }
654 printf ("\n");
655}
656
657/* validate the given aspath */
658static int
659validate (struct aspath *as, const struct test_spec *sp)
660{
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000661 size_t bytes, bytes4;
paul1f377b02005-09-10 18:00:11 +0000662 int fails = 0;
663 const u_char *out;
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000664 static struct stream *s;
665 struct aspath *asinout, *asconfeddel, *asstr, *as4;
paul1f377b02005-09-10 18:00:11 +0000666
667 out = aspath_snmp_pathseg (as, &bytes);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000668 asinout = make_aspath (out, bytes, 0);
669
670 /* Excercise AS4 parsing a bit, with a dogfood test */
671 if (!s)
672 s = stream_new (4096);
673 bytes4 = aspath_put (s, as, 1);
674 as4 = make_aspath (STREAM_DATA(s), bytes4, 1);
paul1f377b02005-09-10 18:00:11 +0000675
676 asstr = aspath_str2aspath (sp->shouldbe);
677
678 asconfeddel = aspath_delete_confed_seq (aspath_dup (asinout));
679
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000680 printf ("got: %s\n", aspath_print(as));
681
paul1f377b02005-09-10 18:00:11 +0000682 /* the parsed path should match the specified 'shouldbe' string.
683 * We should pass the "eat our own dog food" test, be able to output
684 * this path and then input it again. Ie the path resulting from:
685 *
686 * aspath_parse(aspath_put(as))
687 *
688 * should:
689 *
690 * - also match the specified 'shouldbe' value
691 * - hash to same value as original path
692 * - have same hops and confed counts as original, and as the
693 * the specified counts
694 *
695 * aspath_str2aspath() and shouldbe should match
696 *
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000697 * We do the same for:
698 *
699 * aspath_parse(aspath_put(as,USE32BIT))
700 *
paul1f377b02005-09-10 18:00:11 +0000701 * Confederation related tests:
702 * - aspath_delete_confed_seq(aspath) should match shouldbe_confed
703 * - aspath_delete_confed_seq should be idempotent.
704 */
705 if (strcmp(aspath_print (as), sp->shouldbe)
706 /* hash validation */
707 || (aspath_key_make (as) != aspath_key_make (asinout))
708 /* by string */
709 || strcmp(aspath_print (asinout), sp->shouldbe)
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000710 /* By 4-byte parsing */
711 || strcmp(aspath_print (as4), sp->shouldbe)
paul1f377b02005-09-10 18:00:11 +0000712 /* by various path counts */
713 || (aspath_count_hops (as) != sp->hops)
714 || (aspath_count_confeds (as) != sp->confeds)
715 || (aspath_count_hops (asinout) != sp->hops)
716 || (aspath_count_confeds (asinout) != sp->confeds))
717 {
718 failed++;
719 fails++;
720 printf ("shouldbe:\n%s\n", sp->shouldbe);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000721 printf ("as4:\n%s\n", aspath_print (as4));
paul1f377b02005-09-10 18:00:11 +0000722 printf ("hash keys: in: %d out->in: %d\n",
723 aspath_key_make (as), aspath_key_make (asinout));
724 printf ("hops: %d, counted %d %d\n", sp->hops,
725 aspath_count_hops (as),
726 aspath_count_hops (asinout) );
727 printf ("confeds: %d, counted %d %d\n", sp->confeds,
728 aspath_count_confeds (as),
729 aspath_count_confeds (asinout));
730 printf ("out->in:\n%s\nbytes: ", aspath_print(asinout));
731 printbytes (out, bytes);
732 }
733 /* basic confed related tests */
734 if ((aspath_print (asconfeddel) == NULL
735 && sp->shouldbe_delete_confed != NULL)
736 || (aspath_print (asconfeddel) != NULL
737 && sp->shouldbe_delete_confed == NULL)
738 || strcmp(aspath_print (asconfeddel), sp->shouldbe_delete_confed)
739 /* delete_confed_seq should be idempotent */
740 || (aspath_key_make (asconfeddel)
741 != aspath_key_make (aspath_delete_confed_seq (asconfeddel))))
742 {
743 failed++;
744 fails++;
745 printf ("confed_del: %s\n", aspath_print (asconfeddel));
746 printf ("should be: %s\n", sp->shouldbe_delete_confed);
747 }
748 /* aspath_str2aspath test */
749 if ((aspath_print (asstr) == NULL && sp->shouldbe != NULL)
750 || (aspath_print (asstr) != NULL && sp->shouldbe == NULL)
751 || strcmp(aspath_print (asstr), sp->shouldbe))
752 {
753 failed++;
754 fails++;
755 printf ("asstr: %s\n", aspath_print (asstr));
756 }
757
758 /* loop, private and first as checks */
Paul Jakma1f742f22006-08-06 15:52:11 +0000759 if ((sp->does_loop && aspath_loop_check (as, sp->does_loop) == 0)
760 || (sp->doesnt_loop && aspath_loop_check (as, sp->doesnt_loop) != 0)
paul1f377b02005-09-10 18:00:11 +0000761 || (aspath_private_as_check (as) != sp->private_as)
762 || (aspath_firstas_check (as,sp->first)
763 && sp->first == 0))
764 {
765 failed++;
766 fails++;
767 printf ("firstas: %d, got %d\n", sp->first,
768 aspath_firstas_check (as,sp->first));
769 printf ("loop does: %d %d, doesnt: %d %d\n",
770 sp->does_loop, aspath_loop_check (as, sp->does_loop),
771 sp->doesnt_loop, aspath_loop_check (as, sp->doesnt_loop));
772 printf ("private check: %d %d\n", sp->private_as,
773 aspath_private_as_check (as));
774 }
775 aspath_unintern (asinout);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000776 aspath_unintern (as4);
777
paul6726f952006-01-16 12:06:00 +0000778 aspath_free (asconfeddel);
779 aspath_free (asstr);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000780 stream_reset (s);
paul6726f952006-01-16 12:06:00 +0000781
paul1f377b02005-09-10 18:00:11 +0000782 return fails;
paul1f377b02005-09-10 18:00:11 +0000783}
784
785static void
786empty_get_test ()
787{
788 struct aspath *as = aspath_empty_get ();
789 struct test_spec sp = { "", "", 0, 0, 0, 0, 0, 0 };
790
791 printf ("empty_get_test, as: %s\n",aspath_print (as));
792 if (!validate (as, &sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000793 printf ("%s\n", OK);
paul1f377b02005-09-10 18:00:11 +0000794 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000795 printf ("%s!\n", FAILED);
paul1f377b02005-09-10 18:00:11 +0000796
797 printf ("\n");
paul6726f952006-01-16 12:06:00 +0000798
799 aspath_free (as);
paul1f377b02005-09-10 18:00:11 +0000800}
801
802/* basic parsing test */
803static void
804parse_test (struct test_segment *t)
805{
806 struct aspath *asp;
807
808 printf ("%s: %s\n", t->name, t->desc);
809
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000810 asp = make_aspath (t->asdata, t->len, 0);
paul1f377b02005-09-10 18:00:11 +0000811
812 printf ("aspath: %s\nvalidating...:\n", aspath_print (asp));
813
814 if (!validate (asp, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000815 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +0000816 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000817 printf (FAILED "\n");
paul1f377b02005-09-10 18:00:11 +0000818
819 printf ("\n");
820 aspath_unintern (asp);
821}
822
823/* prepend testing */
Paul Jakma5d932f62006-03-30 13:42:50 +0000824static void
paul1f377b02005-09-10 18:00:11 +0000825prepend_test (struct tests *t)
826{
827 struct aspath *asp1, *asp2, *ascratch;
828
829 printf ("prepend %s: %s\n", t->test1->name, t->test1->desc);
830 printf ("to %s: %s\n", t->test2->name, t->test2->desc);
831
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000832 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
833 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
paul1f377b02005-09-10 18:00:11 +0000834
835 ascratch = aspath_dup (asp2);
836 aspath_unintern (asp2);
837
838 asp2 = aspath_prepend (asp1, ascratch);
839
840 printf ("aspath: %s\n", aspath_print (asp2));
841
842 if (!validate (asp2, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000843 printf ("%s\n", OK);
paul1f377b02005-09-10 18:00:11 +0000844 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000845 printf ("%s!\n", FAILED);
paul1f377b02005-09-10 18:00:11 +0000846
847 printf ("\n");
848 aspath_unintern (asp1);
849 aspath_free (asp2);
850}
851
852/* empty-prepend testing */
Paul Jakma5d932f62006-03-30 13:42:50 +0000853static void
paul1f377b02005-09-10 18:00:11 +0000854empty_prepend_test (struct test_segment *t)
855{
856 struct aspath *asp1, *asp2, *ascratch;
857
858 printf ("empty prepend %s: %s\n", t->name, t->desc);
859
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000860 asp1 = make_aspath (t->asdata, t->len, 0);
paul1f377b02005-09-10 18:00:11 +0000861 asp2 = aspath_empty ();
862
863 ascratch = aspath_dup (asp2);
864 aspath_unintern (asp2);
865
866 asp2 = aspath_prepend (asp1, ascratch);
867
868 printf ("aspath: %s\n", aspath_print (asp2));
869
870 if (!validate (asp2, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000871 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +0000872 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000873 printf (FAILED "!\n");
paul1f377b02005-09-10 18:00:11 +0000874
875 printf ("\n");
876 aspath_unintern (asp1);
877 aspath_free (asp2);
878}
879
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000880/* as2+as4 reconciliation testing */
881static void
882as4_reconcile_test (struct tests *t)
883{
884 struct aspath *asp1, *asp2, *ascratch;
885
886 printf ("reconciling %s:\n %s\n", t->test1->name, t->test1->desc);
887 printf ("with %s:\n %s\n", t->test2->name, t->test2->desc);
888
889 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
890 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
891
892 ascratch = aspath_reconcile_as4 (asp1, asp2);
893
894 if (!validate (ascratch, &t->sp))
895 printf (OK "\n");
896 else
897 printf (FAILED "!\n");
898
899 printf ("\n");
900 aspath_unintern (asp1);
901 aspath_unintern (asp2);
902 aspath_free (ascratch);
903}
904
905
paul1f377b02005-09-10 18:00:11 +0000906/* aggregation testing */
Paul Jakma5d932f62006-03-30 13:42:50 +0000907static void
paul1f377b02005-09-10 18:00:11 +0000908aggregate_test (struct tests *t)
909{
910 struct aspath *asp1, *asp2, *ascratch;
911
912 printf ("aggregate %s: %s\n", t->test1->name, t->test1->desc);
913 printf ("with %s: %s\n", t->test2->name, t->test2->desc);
914
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000915 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
916 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
paul1f377b02005-09-10 18:00:11 +0000917
918 ascratch = aspath_aggregate (asp1, asp2);
919
paul1f377b02005-09-10 18:00:11 +0000920 if (!validate (ascratch, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000921 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +0000922 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000923 printf (FAILED "!\n");
paul1f377b02005-09-10 18:00:11 +0000924
925 printf ("\n");
926 aspath_unintern (asp1);
927 aspath_unintern (asp2);
928 aspath_free (ascratch);
929/* aspath_unintern (ascratch);*/
930}
931
932/* cmp_left tests */
933static void
934cmp_test ()
935{
paul84771ee2005-10-11 03:48:28 +0000936 unsigned int i;
paul1f377b02005-09-10 18:00:11 +0000937#define CMP_TESTS_MAX \
938 (sizeof(left_compare) / sizeof (struct compare_tests))
939
940 for (i = 0; i < CMP_TESTS_MAX; i++)
941 {
942 struct test_segment *t1 = &test_segments[left_compare[i].test_index1];
943 struct test_segment *t2 = &test_segments[left_compare[i].test_index2];
944 struct aspath *asp1, *asp2;
945
946 printf ("left cmp %s: %s\n", t1->name, t1->desc);
947 printf ("and %s: %s\n", t2->name, t2->desc);
948
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000949 asp1 = make_aspath (t1->asdata, t1->len, 0);
950 asp2 = make_aspath (t2->asdata, t2->len, 0);
paul1f377b02005-09-10 18:00:11 +0000951
952 if (aspath_cmp_left (asp1, asp2) != left_compare[i].shouldbe_cmp
953 || aspath_cmp_left (asp2, asp1) != left_compare[i].shouldbe_cmp
954 || aspath_cmp_left_confed (asp1, asp2)
955 != left_compare[i].shouldbe_confed
956 || aspath_cmp_left_confed (asp2, asp1)
957 != left_compare[i].shouldbe_confed)
958 {
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000959 failed++;
960 printf (FAILED "\n");
paul1f377b02005-09-10 18:00:11 +0000961 printf ("result should be: cmp: %d, confed: %d\n",
962 left_compare[i].shouldbe_cmp,
963 left_compare[i].shouldbe_confed);
964 printf ("got: cmp %d, cmp_confed: %d\n",
965 aspath_cmp_left (asp1, asp2),
966 aspath_cmp_left_confed (asp1, asp2));
967 printf("path1: %s\npath2: %s\n", aspath_print (asp1),
968 aspath_print (asp2));
paul1f377b02005-09-10 18:00:11 +0000969 }
970 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000971 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +0000972
973 printf ("\n");
974 aspath_unintern (asp1);
975 aspath_unintern (asp2);
976 }
977}
978
979int
980main (void)
981{
982 int i = 0;
983 aspath_init();
984 while (test_segments[i].name)
985 {
986 parse_test (&test_segments[i]);
987 empty_prepend_test (&test_segments[i++]);
988 }
989
990 i = 0;
991 while (prepend_tests[i].test1)
992 prepend_test (&prepend_tests[i++]);
993
994 i = 0;
995 while (aggregate_tests[i].test1)
996 aggregate_test (&aggregate_tests[i++]);
997
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000998 i = 0;
999
1000 while (reconcile_tests[i].test1)
1001 as4_reconcile_test (&reconcile_tests[i++]);
1002
1003 i = 0;
1004
paul1f377b02005-09-10 18:00:11 +00001005 cmp_test();
1006
1007 i = 0;
1008
1009 empty_get_test();
1010
1011 printf ("failures: %d\n", failed);
1012 printf ("aspath count: %ld\n", aspath_count());
1013
1014 return (failed + aspath_count());
1015}