blob: 71a3102229166f05ab3e18bf3797333114111d32 [file] [log] [blame]
Paul Jakma010ebbb2014-09-16 11:53:49 +01001/*
2 * Copyright (C) 2005 Sun Microsystems, Inc.
3 *
4 * This file is part of Quagga.
5 *
6 * Quagga is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * Quagga is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Quagga; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
paul1f377b02005-09-10 18:00:11 +000022#include <zebra.h>
23
24#include "vty.h"
25#include "stream.h"
26#include "privs.h"
27
28#include "bgpd/bgpd.h"
29#include "bgpd/bgp_aspath.h"
Paul Jakma50ef5652010-11-27 23:14:02 +000030#include "bgpd/bgp_attr.h"
paul1f377b02005-09-10 18:00:11 +000031
Paul Jakma0b2aa3a2007-10-14 22:32:21 +000032#define VT100_RESET "\x1b[0m"
33#define VT100_RED "\x1b[31m"
34#define VT100_GREEN "\x1b[32m"
35#define VT100_YELLOW "\x1b[33m"
36#define OK VT100_GREEN "OK" VT100_RESET
37#define FAILED VT100_RED "failed" VT100_RESET
38
paul1f377b02005-09-10 18:00:11 +000039/* need these to link in libbgp */
40struct zebra_privs_t *bgpd_privs = NULL;
41struct thread_master *master = NULL;
42
43static int failed = 0;
44
45/* specification for a test - what the results should be */
46struct test_spec
47{
48 const char *shouldbe; /* the string the path should parse to */
49 const char *shouldbe_delete_confed; /* ditto, but once confeds are deleted */
paul84771ee2005-10-11 03:48:28 +000050 const unsigned int hops; /* aspath_count_hops result */
51 const unsigned int confeds; /* aspath_count_confeds */
paul1f377b02005-09-10 18:00:11 +000052 const int private_as; /* whether the private_as check should pass or fail */
53#define NOT_ALL_PRIVATE 0
54#define ALL_PRIVATE 1
55 const as_t does_loop; /* an ASN which should trigger loop-check */
56 const as_t doesnt_loop; /* one which should not */
57 const as_t first; /* the first ASN, if there is one */
58#define NULL_ASN 0
59};
60
61
62/* test segments to parse and validate, and use for other tests */
63static struct test_segment {
64 const char *name;
65 const char *desc;
66 const u_char asdata[1024];
67 int len;
68 struct test_spec sp;
69} test_segments [] =
70{
71 { /* 0 */
72 "seq1",
73 "seq(8466,3,52737,4096)",
74 { 0x2,0x4, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00 },
75 10,
76 { "8466 3 52737 4096",
77 "8466 3 52737 4096",
78 4, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
79 },
80 { /* 1 */
81 "seq2",
82 "seq(8722) seq(4)",
83 { 0x2,0x1, 0x22,0x12,
84 0x2,0x1, 0x00,0x04 },
85 8,
86 { "8722 4",
87 "8722 4",
88 2, 0, NOT_ALL_PRIVATE, 4, 5, 8722, },
89 },
90 { /* 2 */
91 "seq3",
92 "seq(8466,3,52737,4096,8722,4)",
93 { 0x2,0x6, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00,
94 0x22,0x12, 0x00,0x04},
95 14,
96 { "8466 3 52737 4096 8722 4",
97 "8466 3 52737 4096 8722 4",
98 6, 0, NOT_ALL_PRIVATE, 3, 5, 8466 },
99 },
100 { /* 3 */
101 "seqset",
102 "seq(8482,51457) set(5204)",
103 { 0x2,0x2, 0x21,0x22, 0xc9,0x01,
104 0x1,0x1, 0x14,0x54 },
105 10,
106 { "8482 51457 {5204}",
107 "8482 51457 {5204}",
Paul Jakma1f742f22006-08-06 15:52:11 +0000108 3, 0, NOT_ALL_PRIVATE, 5204, 51456, 8482},
paul1f377b02005-09-10 18:00:11 +0000109 },
110 { /* 4 */
111 "seqset2",
112 "seq(8467, 59649) set(4196,48658) set(17322,30745)",
113 { 0x2,0x2, 0x21,0x13, 0xe9,0x01,
114 0x1,0x2, 0x10,0x64, 0xbe,0x12,
115 0x1,0x2, 0x43,0xaa, 0x78,0x19 },
116 18,
117 { "8467 59649 {4196,48658} {17322,30745}",
118 "8467 59649 {4196,48658} {17322,30745}",
119 4, 0, NOT_ALL_PRIVATE, 48658, 1, 8467},
120 },
121 { /* 5 */
122 "multi",
123 "seq(6435,59408,21665) set(2457,61697,4369), seq(1842,41590,51793)",
124 { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
125 0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11,
126 0x2,0x3, 0x07,0x32, 0xa2,0x76, 0xca,0x51 },
127 24,
128 { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
129 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
130 7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
131 },
132 { /* 6 */
133 "confed",
134 "confseq(123,456,789)",
135 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15 },
136 8,
137 { "(123 456 789)",
138 "",
139 0, 3, NOT_ALL_PRIVATE, 789, 1, NULL_ASN },
140 },
141 { /* 7 */
142 "confed2",
143 "confseq(123,456,789) confseq(111,222)",
144 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
145 0x3,0x2, 0x00,0x6f, 0x00,0xde },
146 14,
147 { "(123 456 789) (111 222)",
148 "",
149 0, 5, NOT_ALL_PRIVATE, 111, 1, NULL_ASN },
150 },
151 { /* 8 */
152 "confset",
153 "confset(456,123,789)",
154 { 0x4,0x3, 0x01,0xc8, 0x00,0x7b, 0x03,0x15 },
155 8,
156 { "[123,456,789]",
157 "[123,456,789]",
158 0, 1, NOT_ALL_PRIVATE, 123, 1, NULL_ASN },
159 },
160 { /* 9 */
161 "confmulti",
162 "confseq(123,456,789) confset(222,111) seq(8722) set(4196,48658)",
163 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
164 0x4,0x2, 0x00,0xde, 0x00,0x6f,
165 0x2,0x1, 0x22,0x12,
166 0x1,0x2, 0x10,0x64, 0xbe,0x12 },
167 24,
168 { "(123 456 789) [111,222] 8722 {4196,48658}",
169 "8722 {4196,48658}",
170 2, 4, NOT_ALL_PRIVATE, 123, 1, NULL_ASN },
171 },
172 { /* 10 */
173 "seq4",
174 "seq(8466,2,52737,4096,8722,4)",
175 { 0x2,0x6, 0x21,0x12, 0x00,0x02, 0xce,0x01, 0x10,0x00,
176 0x22,0x12, 0x00,0x04},
177 14,
178 { "8466 2 52737 4096 8722 4",
179 "8466 2 52737 4096 8722 4",
180 6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 },
181 },
182 { /* 11 */
183 "tripleseq1",
184 "seq(8466,2,52737) seq(4096,8722,4) seq(8722)",
185 { 0x2,0x3, 0x21,0x12, 0x00,0x02, 0xce,0x01,
186 0x2,0x3, 0x10,0x00, 0x22,0x12, 0x00,0x04,
187 0x2,0x1, 0x22,0x12},
188 20,
189 { "8466 2 52737 4096 8722 4 8722",
190 "8466 2 52737 4096 8722 4 8722",
191 7, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 },
192 },
193 { /* 12 */
194 "someprivate",
195 "seq(8466,64512,52737,65535)",
196 { 0x2,0x4, 0x21,0x12, 0xfc,0x00, 0xce,0x01, 0xff,0xff },
197 10,
198 { "8466 64512 52737 65535",
199 "8466 64512 52737 65535",
200 4, 0, NOT_ALL_PRIVATE, 65535, 4, 8466 },
201 },
202 { /* 13 */
203 "allprivate",
204 "seq(65534,64512,64513,65535)",
205 { 0x2,0x4, 0xff,0xfe, 0xfc,0x00, 0xfc,0x01, 0xff,0xff },
206 10,
207 { "65534 64512 64513 65535",
208 "65534 64512 64513 65535",
209 4, 0, ALL_PRIVATE, 65534, 4, 65534 },
210 },
211 { /* 14 */
212 "long",
213 "seq(8466,3,52737,4096,34285,<repeated 49 more times>)",
214 { 0x2,0xfa, 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 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
243 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
244 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
245 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
246 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
247 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
248 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
249 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
250 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
251 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
252 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
253 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
254 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
255 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
256 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
257 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
258 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
259 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
260 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
261 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
262 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
263 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, },
264 502,
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 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
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
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 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
295 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
296 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
297 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
298 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
299 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
300 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
301 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
302 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
303 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
304 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
305 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
306 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
307 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
308 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
309 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
310 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
311 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
312 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
313 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
314 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
315 "8466 3 52737 4096 34285 8466 3 52737 4096 34285",
316 250, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
317 },
paul59064762005-11-23 02:48:14 +0000318 { /* 15 */
319 "seq1extra",
320 "seq(8466,3,52737,4096,3456)",
321 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 },
322 12,
323 { "8466 3 52737 4096 3456",
324 "8466 3 52737 4096 3456",
325 5, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
326 },
327 { /* 16 */
328 "empty",
329 "<empty>",
330 {},
331 0,
332 { "", "", 0, 0, 0, 0, 0, 0 },
333 },
Paul Jakma5d932f62006-03-30 13:42:50 +0000334 { /* 17 */
335 "redundantset",
336 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)",
337 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80,
338 0x1,0x4, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9 },
339 22,
340 {
341 /* We shouldn't ever /generate/ such paths. However, we should
342 * cope with them fine.
343 */
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000344 "8466 3 52737 4096 3456 {7099,8153}",
345 "8466 3 52737 4096 3456 {7099,8153}",
346 6, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
347 },
348 { /* 18 */
349 "reconcile_lead_asp",
350 "seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)",
351 { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
352 0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
353 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 },
354 24,
355 { "6435 59408 21665 {23456} 23456 23456 23456",
356 "6435 59408 21665 {23456} 23456 23456 23456",
357 7, 0, NOT_ALL_PRIVATE, 23456, 1, 6435 },
358 },
359 { /* 19 */
360 "reconcile_new_asp",
361 "set(2457,61697,4369), seq(1842,41591,51793)",
362 {
363 0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11,
364 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51 },
365 16,
366 { "{2457,4369,61697} 1842 41591 51793",
367 "{2457,4369,61697} 1842 41591 51793",
368 4, 0, NOT_ALL_PRIVATE, 51793, 1, 2457 },
369 },
370 { /* 20 */
371 "reconcile_confed",
372 "confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665)"
373 " set(23456,23456,23456), seq(23456,23456,23456)",
374 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
375 0x4,0x3, 0x01,0xc8, 0x00,0x7c, 0x03,0x14,
376 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
377 0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
378 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 },
379 40,
380 { "(123 456 789) [124,456,788] 6435 59408 21665"
381 " {23456} 23456 23456 23456",
382 "6435 59408 21665 {23456} 23456 23456 23456",
383 7, 4, NOT_ALL_PRIVATE, 23456, 1, 6435 },
384 },
385 { /* 21 */
386 "reconcile_start_trans",
387 "seq(23456,23456,23456) seq(6435,59408,21665)",
388 { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
389 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, },
390 16,
391 { "23456 23456 23456 6435 59408 21665",
392 "23456 23456 23456 6435 59408 21665",
393 6, 0, NOT_ALL_PRIVATE, 21665, 1, 23456 },
394 },
395 { /* 22 */
396 "reconcile_start_trans4",
397 "seq(1842,41591,51793) seq(6435,59408,21665)",
398 { 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51,
399 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, },
400 16,
401 { "1842 41591 51793 6435 59408 21665",
402 "1842 41591 51793 6435 59408 21665",
403 6, 0, NOT_ALL_PRIVATE, 41591, 1, 1842 },
404 },
405 { /* 23 */
406 "reconcile_start_trans_error",
407 "seq(23456,23456,23456) seq(6435,59408)",
408 { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
409 0x2,0x2, 0x19,0x23, 0xe8,0x10, },
410 14,
411 { "23456 23456 23456 6435 59408",
412 "23456 23456 23456 6435 59408",
413 5, 0, NOT_ALL_PRIVATE, 59408, 1, 23456 },
414 },
415 { /* 24 */
416 "redundantset2",
417 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)",
418 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80,
419 0x1,0x5, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9, 0x1b,0xbb,},
420 24,
421 {
422 /* We should weed out duplicate set members. */
423 "8466 3 52737 4096 3456 {7099,8153}",
424 "8466 3 52737 4096 3456 {7099,8153}",
Paul Jakma5d932f62006-03-30 13:42:50 +0000425 6, 0, NOT_ALL_PRIVATE, 4096, 4, 8466 },
426 },
Paul Jakmad38e8d62008-02-23 16:57:03 +0000427 { /* 25 */
428 "zero-size overflow",
429 "#ASNs = 0, data = seq(8466 3 52737 4096 3456)",
430 { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 },
431 12,
Paul Jakmab881c702010-11-23 16:35:42 +0000432 { NULL, NULL,
Paul Jakmad38e8d62008-02-23 16:57:03 +0000433 0, 0, 0, 0, 0, 0 },
434 },
435 { /* 26 */
436 "zero-size overflow + valid segment",
437 "seq(#AS=0:8466 3 52737),seq(4096 3456)",
438 { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01,
439 0x2,0x2, 0x10,0x00, 0x0d,0x80 },
440 14
441 ,
Paul Jakmab881c702010-11-23 16:35:42 +0000442 { NULL, NULL,
Paul Jakmad38e8d62008-02-23 16:57:03 +0000443 0, 0, 0, 0, 0, 0 },
444 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000445 { /* 27 */
446 "invalid segment type",
447 "type=8(4096 3456)",
448 { 0x8,0x2, 0x10,0x00, 0x0d,0x80 },
449 14
450 ,
Paul Jakmab881c702010-11-23 16:35:42 +0000451 { NULL, NULL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000452 0, 0, 0, 0, 0, 0 },
453 }, { NULL, NULL, {0}, 0, { NULL, 0, 0 } }
454};
455
David Lamparterc68f6d92014-10-30 06:42:00 +0100456#define COMMON_ATTRS \
457 BGP_ATTR_FLAG_TRANS, \
458 BGP_ATTR_ORIGIN, \
459 1, \
460 BGP_ORIGIN_EGP
461#define COMMON_ATTR_SIZE 4
462
Paul Jakma50ef5652010-11-27 23:14:02 +0000463/* */
464static struct aspath_tests {
465 const char *desc;
466 const struct test_segment *segment;
467 const char *shouldbe; /* String it should evaluate to */
468 const enum as4 { AS4_DATA, AS2_DATA }
469 as4; /* whether data should be as4 or not (ie as2) */
470 const int result; /* expected result for bgp_attr_parse */
471 const int cap; /* capabilities to set for peer */
472 const char attrheader [1024];
473 size_t len;
David Lamparter1cb9cf02013-01-22 23:39:17 +0100474 const struct test_segment *old_segment;
Paul Jakma50ef5652010-11-27 23:14:02 +0000475} aspath_tests [] =
476{
477 /* 0 */
478 {
479 "basic test",
480 &test_segments[0],
481 "8466 3 52737 4096",
482 AS2_DATA, 0,
483 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100484 { COMMON_ATTRS,
485 BGP_ATTR_FLAG_TRANS,
486 BGP_ATTR_AS_PATH,
Paul Jakma50ef5652010-11-27 23:14:02 +0000487 10,
488 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100489 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000490 },
491 /* 1 */
492 {
493 "length too short",
494 &test_segments[0],
495 "8466 3 52737 4096",
496 AS2_DATA, -1,
497 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100498 { COMMON_ATTRS,
499 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000500 BGP_ATTR_AS_PATH,
501 8,
502 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100503 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000504 },
505 /* 2 */
506 {
507 "length too long",
508 &test_segments[0],
509 "8466 3 52737 4096",
510 AS2_DATA, -1,
511 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100512 { COMMON_ATTRS,
513 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000514 BGP_ATTR_AS_PATH,
515 12,
516 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100517 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000518 },
519 /* 3 */
520 {
521 "incorrect flag",
522 &test_segments[0],
523 "8466 3 52737 4096",
524 AS2_DATA, -1,
525 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100526 { COMMON_ATTRS,
527 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000528 BGP_ATTR_AS_PATH,
529 10,
530 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100531 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000532 },
533 /* 4 */
534 {
535 "as4_path, with as2 format data",
536 &test_segments[0],
537 "8466 3 52737 4096",
538 AS2_DATA, -1,
539 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100540 { COMMON_ATTRS,
541 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000542 BGP_ATTR_AS4_PATH,
543 10,
544 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100545 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000546 },
547 /* 5 */
548 {
549 "as4, with incorrect attr length",
550 &test_segments[0],
551 "8466 3 52737 4096",
552 AS4_DATA, -1,
553 PEER_CAP_AS4_RCV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100554 { COMMON_ATTRS,
555 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000556 BGP_ATTR_AS4_PATH,
557 10,
558 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100559 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000560 },
561 /* 6 */
562 {
563 "basic 4-byte as-path",
564 &test_segments[0],
565 "8466 3 52737 4096",
566 AS4_DATA, 0,
567 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100568 { COMMON_ATTRS,
569 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000570 BGP_ATTR_AS_PATH,
571 18,
572 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100573 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000574 },
575 /* 7 */
576 {
577 "4b AS_PATH: too short",
578 &test_segments[0],
579 "8466 3 52737 4096",
580 AS4_DATA, -1,
581 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100582 { COMMON_ATTRS,
583 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000584 BGP_ATTR_AS_PATH,
585 16,
586 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100587 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000588 },
589 /* 8 */
590 {
591 "4b AS_PATH: too long",
592 &test_segments[0],
593 "8466 3 52737 4096",
594 AS4_DATA, -1,
595 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100596 { COMMON_ATTRS,
597 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000598 BGP_ATTR_AS_PATH,
599 20,
600 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100601 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000602 },
603 /* 9 */
604 {
605 "4b AS_PATH: too long2",
606 &test_segments[0],
607 "8466 3 52737 4096",
608 AS4_DATA, -1,
609 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100610 { COMMON_ATTRS,
611 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000612 BGP_ATTR_AS_PATH,
613 22,
614 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100615 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000616 },
617 /* 10 */
618 {
619 "4b AS_PATH: bad flags",
620 &test_segments[0],
621 "8466 3 52737 4096",
622 AS4_DATA, -1,
623 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100624 { COMMON_ATTRS,
625 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000626 BGP_ATTR_AS_PATH,
627 18,
628 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100629 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000630 },
631 /* 11 */
632 {
David Lamparter1cb9cf02013-01-22 23:39:17 +0100633 "4b AS4_PATH w/o AS_PATH",
Paul Jakma50ef5652010-11-27 23:14:02 +0000634 &test_segments[6],
David Lamparter1cb9cf02013-01-22 23:39:17 +0100635 NULL,
David Lamparterc68f6d92014-10-30 06:42:00 +0100636 AS4_DATA, -1,
Paul Jakma50ef5652010-11-27 23:14:02 +0000637 PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100638 { COMMON_ATTRS,
639 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000640 BGP_ATTR_AS4_PATH,
641 14,
642 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100643 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000644 },
David Lamparter1cb9cf02013-01-22 23:39:17 +0100645 /* 12 */
646 {
647 "4b AS4_PATH: confed",
648 &test_segments[6],
649 "8466 3 52737 4096 (123 456 789)",
650 AS4_DATA, 0,
651 PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100652 { COMMON_ATTRS,
653 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
David Lamparter1cb9cf02013-01-22 23:39:17 +0100654 BGP_ATTR_AS4_PATH,
655 14,
656 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100657 COMMON_ATTR_SIZE + 3,
David Lamparter1cb9cf02013-01-22 23:39:17 +0100658 &test_segments[0],
659 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000660 { NULL, NULL, NULL, 0, 0, 0, { 0 }, 0 },
paul1f377b02005-09-10 18:00:11 +0000661};
662
663/* prepending tests */
664static struct tests {
665 const struct test_segment *test1;
666 const struct test_segment *test2;
667 struct test_spec sp;
668} prepend_tests[] =
669{
Paul Jakma50ef5652010-11-27 23:14:02 +0000670 /* 0 */
paul1f377b02005-09-10 18:00:11 +0000671 { &test_segments[0], &test_segments[1],
672 { "8466 3 52737 4096 8722 4",
673 "8466 3 52737 4096 8722 4",
674 6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 },
675 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000676 /* 1 */
paul1f377b02005-09-10 18:00:11 +0000677 { &test_segments[1], &test_segments[3],
678 { "8722 4 8482 51457 {5204}",
679 "8722 4 8482 51457 {5204}",
680 5, 0, NOT_ALL_PRIVATE, 5204, 1, 8722 }
681 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000682 /* 2 */
paul1f377b02005-09-10 18:00:11 +0000683 { &test_segments[3], &test_segments[4],
684 { "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
685 "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
686 7, 0, NOT_ALL_PRIVATE, 5204, 1, 8482 },
687 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000688 /* 3 */
paul1f377b02005-09-10 18:00:11 +0000689 { &test_segments[4], &test_segments[5],
690 { "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
691 " {2457,4369,61697} 1842 41590 51793",
692 "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
693 " {2457,4369,61697} 1842 41590 51793",
694 11, 0, NOT_ALL_PRIVATE, 61697, 1, 8467 }
695 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000696 /* 4 */
paul1f377b02005-09-10 18:00:11 +0000697 { &test_segments[5], &test_segments[6],
Paul Jakma50ef5652010-11-27 23:14:02 +0000698 { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
699 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
700 7, 0, NOT_ALL_PRIVATE, 1842, 1, 6435 },
paul1f377b02005-09-10 18:00:11 +0000701 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000702 /* 5 */
paul1f377b02005-09-10 18:00:11 +0000703 { &test_segments[6], &test_segments[7],
704 { "(123 456 789) (123 456 789) (111 222)",
705 "",
706 0, 8, NOT_ALL_PRIVATE, 111, 1, 0 }
707 },
708 { &test_segments[7], &test_segments[8],
709 { "(123 456 789) (111 222) [123,456,789]",
710 "",
711 0, 6, NOT_ALL_PRIVATE, 111, 1, 0 }
712 },
713 { &test_segments[8], &test_segments[9],
714 { "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
715 "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
716 2, 5, NOT_ALL_PRIVATE, 456, 1, NULL_ASN },
717 },
718 { &test_segments[9], &test_segments[8],
719 { "(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]",
720 "8722 {4196,48658} [123,456,789]",
721 2, 5, NOT_ALL_PRIVATE, 48658, 1, NULL_ASN },
722 },
723 { &test_segments[14], &test_segments[11],
724 { "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
725 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
726 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
727 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
728 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
729 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
730 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
731 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
732 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
733 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
734 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
735 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
736 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
737 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
738 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
739 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
740 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
741 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
742 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
743 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
744 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
745 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
746 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
747 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
748 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
749 "8466 2 52737 4096 8722 4 8722",
750
751 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
752 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
753 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
754 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
755 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
756 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
757 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
758 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
759 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
760 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
761 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
762 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
763 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
764 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
765 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
766 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
767 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
768 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
769 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
770 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
771 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
772 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
773 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
774 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
775 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
776 "8466 2 52737 4096 8722 4 8722",
777 257, 0, NOT_ALL_PRIVATE, 4096, 1000, 8466 },
778 },
779 { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } },
780};
781
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000782struct tests reconcile_tests[] =
783{
784 { &test_segments[18], &test_segments[19],
785 { "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
786 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
787 7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
788 },
789 { &test_segments[19], &test_segments[18],
790 /* AS_PATH (19) has more hops than NEW_AS_PATH,
791 * so just AS_PATH should be used (though, this practice
792 * is bad imho).
793 */
794 { "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
795 "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
796 11, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
797 },
798 { &test_segments[20], &test_segments[19],
799 { "(123 456 789) [124,456,788] 6435 59408 21665"
800 " {2457,4369,61697} 1842 41591 51793",
801 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
802 7, 4, NOT_ALL_PRIVATE, 51793, 1, 6435 },
803 },
804 { &test_segments[21], &test_segments[22],
805 { "1842 41591 51793 6435 59408 21665",
806 "1842 41591 51793 6435 59408 21665",
807 6, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 },
808 },
809 { &test_segments[23], &test_segments[22],
810 { "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
811 "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
812 11, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 },
813 },
814 { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } },
815};
816
paul1f377b02005-09-10 18:00:11 +0000817struct tests aggregate_tests[] =
818{
paul1f377b02005-09-10 18:00:11 +0000819 { &test_segments[0], &test_segments[2],
820 { "8466 3 52737 4096 {4,8722}",
821 "8466 3 52737 4096 {4,8722}",
822 5, 0, NOT_ALL_PRIVATE, 4, 1, 8466 },
823 },
824 { &test_segments[2], &test_segments[0],
825 { "8466 3 52737 4096 {4,8722}",
826 "8466 3 52737 4096 {4,8722}",
827 5, 0, NOT_ALL_PRIVATE, 8722, 1, 8466 },
828 },
829 { &test_segments[2], &test_segments[10],
830 { "8466 {2,3,4,4096,8722,52737}",
831 "8466 {2,3,4,4096,8722,52737}",
832 2, 0, NOT_ALL_PRIVATE, 8722, 5, 8466 },
833 },
834 { &test_segments[10], &test_segments[2],
835 { "8466 {2,3,4,4096,8722,52737}",
836 "8466 {2,3,4,4096,8722,52737}",
837 2, 0, NOT_ALL_PRIVATE, 2, 20000, 8466 },
838 },
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000839
840 { &test_segments[5], &test_segments[18],
841 { "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
842 "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
843 4, 0, NOT_ALL_PRIVATE, 41590, 1, 6435 },
844 },
845
paul1f377b02005-09-10 18:00:11 +0000846 { NULL, NULL, { NULL, 0, 0} },
847};
848
849struct compare_tests
850{
851 int test_index1;
852 int test_index2;
853#define CMP_RES_YES 1
854#define CMP_RES_NO 0
855 char shouldbe_cmp;
856 char shouldbe_confed;
857} left_compare [] =
858{
859 { 0, 1, CMP_RES_NO, CMP_RES_NO },
860 { 0, 2, CMP_RES_YES, CMP_RES_NO },
861 { 0, 11, CMP_RES_YES, CMP_RES_NO },
paul59064762005-11-23 02:48:14 +0000862 { 0, 15, CMP_RES_YES, CMP_RES_NO },
863 { 0, 16, CMP_RES_NO, CMP_RES_NO },
paul1f377b02005-09-10 18:00:11 +0000864 { 1, 11, CMP_RES_NO, CMP_RES_NO },
865 { 6, 7, CMP_RES_NO, CMP_RES_YES },
866 { 6, 8, CMP_RES_NO, CMP_RES_NO },
867 { 7, 8, CMP_RES_NO, CMP_RES_NO },
868 { 1, 9, CMP_RES_YES, CMP_RES_NO },
869 { 0, 9, CMP_RES_NO, CMP_RES_NO },
870 { 3, 9, CMP_RES_NO, CMP_RES_NO },
871 { 0, 6, CMP_RES_NO, CMP_RES_NO },
872 { 1, 6, CMP_RES_NO, CMP_RES_NO },
873 { 0, 8, CMP_RES_NO, CMP_RES_NO },
874 { 1, 8, CMP_RES_NO, CMP_RES_NO },
875 { 11, 6, CMP_RES_NO, CMP_RES_NO },
876 { 11, 7, CMP_RES_NO, CMP_RES_NO },
877 { 11, 8, CMP_RES_NO, CMP_RES_NO },
878 { 9, 6, CMP_RES_NO, CMP_RES_YES },
879 { 9, 7, CMP_RES_NO, CMP_RES_YES },
880 { 9, 8, CMP_RES_NO, CMP_RES_NO },
881};
882
883/* make an aspath from a data stream */
884static struct aspath *
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000885make_aspath (const u_char *data, size_t len, int use32bit)
paul1f377b02005-09-10 18:00:11 +0000886{
887 struct stream *s = NULL;
888 struct aspath *as;
889
890 if (len)
891 {
892 s = stream_new (len);
893 stream_put (s, data, len);
894 }
Paul Jakma50ef5652010-11-27 23:14:02 +0000895 as = aspath_parse (s, len, use32bit);
paul59064762005-11-23 02:48:14 +0000896
897 if (s)
898 stream_free (s);
paul1f377b02005-09-10 18:00:11 +0000899
900 return as;
901}
902
903static void
904printbytes (const u_char *bytes, int len)
905{
906 int i = 0;
907 while (i < len)
908 {
909 if (i % 2)
910 printf ("%02hhx%s", bytes[i], " ");
911 else
912 printf ("0x%02hhx", bytes[i]);
913 i++;
914 }
915 printf ("\n");
916}
917
918/* validate the given aspath */
919static int
920validate (struct aspath *as, const struct test_spec *sp)
921{
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000922 size_t bytes, bytes4;
paul1f377b02005-09-10 18:00:11 +0000923 int fails = 0;
924 const u_char *out;
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000925 static struct stream *s;
926 struct aspath *asinout, *asconfeddel, *asstr, *as4;
paul1f377b02005-09-10 18:00:11 +0000927
Paul Jakmab881c702010-11-23 16:35:42 +0000928 if (as == NULL && sp->shouldbe == NULL)
929 {
930 printf ("Correctly failed to parse\n");
931 return fails;
932 }
933
paul1f377b02005-09-10 18:00:11 +0000934 out = aspath_snmp_pathseg (as, &bytes);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000935 asinout = make_aspath (out, bytes, 0);
936
937 /* Excercise AS4 parsing a bit, with a dogfood test */
938 if (!s)
939 s = stream_new (4096);
940 bytes4 = aspath_put (s, as, 1);
941 as4 = make_aspath (STREAM_DATA(s), bytes4, 1);
paul1f377b02005-09-10 18:00:11 +0000942
943 asstr = aspath_str2aspath (sp->shouldbe);
944
945 asconfeddel = aspath_delete_confed_seq (aspath_dup (asinout));
946
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000947 printf ("got: %s\n", aspath_print(as));
948
paul1f377b02005-09-10 18:00:11 +0000949 /* the parsed path should match the specified 'shouldbe' string.
950 * We should pass the "eat our own dog food" test, be able to output
951 * this path and then input it again. Ie the path resulting from:
952 *
953 * aspath_parse(aspath_put(as))
954 *
955 * should:
956 *
957 * - also match the specified 'shouldbe' value
958 * - hash to same value as original path
959 * - have same hops and confed counts as original, and as the
960 * the specified counts
961 *
962 * aspath_str2aspath() and shouldbe should match
963 *
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000964 * We do the same for:
965 *
966 * aspath_parse(aspath_put(as,USE32BIT))
967 *
paul1f377b02005-09-10 18:00:11 +0000968 * Confederation related tests:
969 * - aspath_delete_confed_seq(aspath) should match shouldbe_confed
970 * - aspath_delete_confed_seq should be idempotent.
971 */
972 if (strcmp(aspath_print (as), sp->shouldbe)
973 /* hash validation */
974 || (aspath_key_make (as) != aspath_key_make (asinout))
975 /* by string */
976 || strcmp(aspath_print (asinout), sp->shouldbe)
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000977 /* By 4-byte parsing */
978 || strcmp(aspath_print (as4), sp->shouldbe)
paul1f377b02005-09-10 18:00:11 +0000979 /* by various path counts */
980 || (aspath_count_hops (as) != sp->hops)
981 || (aspath_count_confeds (as) != sp->confeds)
982 || (aspath_count_hops (asinout) != sp->hops)
983 || (aspath_count_confeds (asinout) != sp->confeds))
984 {
985 failed++;
986 fails++;
987 printf ("shouldbe:\n%s\n", sp->shouldbe);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000988 printf ("as4:\n%s\n", aspath_print (as4));
paul1f377b02005-09-10 18:00:11 +0000989 printf ("hash keys: in: %d out->in: %d\n",
990 aspath_key_make (as), aspath_key_make (asinout));
991 printf ("hops: %d, counted %d %d\n", sp->hops,
992 aspath_count_hops (as),
993 aspath_count_hops (asinout) );
994 printf ("confeds: %d, counted %d %d\n", sp->confeds,
995 aspath_count_confeds (as),
996 aspath_count_confeds (asinout));
997 printf ("out->in:\n%s\nbytes: ", aspath_print(asinout));
998 printbytes (out, bytes);
999 }
1000 /* basic confed related tests */
1001 if ((aspath_print (asconfeddel) == NULL
1002 && sp->shouldbe_delete_confed != NULL)
1003 || (aspath_print (asconfeddel) != NULL
1004 && sp->shouldbe_delete_confed == NULL)
1005 || strcmp(aspath_print (asconfeddel), sp->shouldbe_delete_confed)
1006 /* delete_confed_seq should be idempotent */
1007 || (aspath_key_make (asconfeddel)
1008 != aspath_key_make (aspath_delete_confed_seq (asconfeddel))))
1009 {
1010 failed++;
1011 fails++;
1012 printf ("confed_del: %s\n", aspath_print (asconfeddel));
1013 printf ("should be: %s\n", sp->shouldbe_delete_confed);
1014 }
1015 /* aspath_str2aspath test */
1016 if ((aspath_print (asstr) == NULL && sp->shouldbe != NULL)
1017 || (aspath_print (asstr) != NULL && sp->shouldbe == NULL)
1018 || strcmp(aspath_print (asstr), sp->shouldbe))
1019 {
1020 failed++;
1021 fails++;
1022 printf ("asstr: %s\n", aspath_print (asstr));
1023 }
1024
1025 /* loop, private and first as checks */
Paul Jakma1f742f22006-08-06 15:52:11 +00001026 if ((sp->does_loop && aspath_loop_check (as, sp->does_loop) == 0)
1027 || (sp->doesnt_loop && aspath_loop_check (as, sp->doesnt_loop) != 0)
paul1f377b02005-09-10 18:00:11 +00001028 || (aspath_private_as_check (as) != sp->private_as)
1029 || (aspath_firstas_check (as,sp->first)
1030 && sp->first == 0))
1031 {
1032 failed++;
1033 fails++;
1034 printf ("firstas: %d, got %d\n", sp->first,
1035 aspath_firstas_check (as,sp->first));
1036 printf ("loop does: %d %d, doesnt: %d %d\n",
1037 sp->does_loop, aspath_loop_check (as, sp->does_loop),
1038 sp->doesnt_loop, aspath_loop_check (as, sp->doesnt_loop));
1039 printf ("private check: %d %d\n", sp->private_as,
1040 aspath_private_as_check (as));
1041 }
Paul Jakma1dba2542012-05-01 16:20:33 +01001042 aspath_unintern (&asinout);
1043 aspath_unintern (&as4);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001044
paul6726f952006-01-16 12:06:00 +00001045 aspath_free (asconfeddel);
1046 aspath_free (asstr);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001047 stream_reset (s);
paul6726f952006-01-16 12:06:00 +00001048
paul1f377b02005-09-10 18:00:11 +00001049 return fails;
paul1f377b02005-09-10 18:00:11 +00001050}
1051
1052static void
1053empty_get_test ()
1054{
1055 struct aspath *as = aspath_empty_get ();
1056 struct test_spec sp = { "", "", 0, 0, 0, 0, 0, 0 };
1057
1058 printf ("empty_get_test, as: %s\n",aspath_print (as));
1059 if (!validate (as, &sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001060 printf ("%s\n", OK);
paul1f377b02005-09-10 18:00:11 +00001061 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001062 printf ("%s!\n", FAILED);
paul1f377b02005-09-10 18:00:11 +00001063
1064 printf ("\n");
paul6726f952006-01-16 12:06:00 +00001065
1066 aspath_free (as);
paul1f377b02005-09-10 18:00:11 +00001067}
1068
1069/* basic parsing test */
1070static void
1071parse_test (struct test_segment *t)
1072{
1073 struct aspath *asp;
1074
1075 printf ("%s: %s\n", t->name, t->desc);
1076
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001077 asp = make_aspath (t->asdata, t->len, 0);
Paul Jakmab881c702010-11-23 16:35:42 +00001078
paul1f377b02005-09-10 18:00:11 +00001079 printf ("aspath: %s\nvalidating...:\n", aspath_print (asp));
1080
1081 if (!validate (asp, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001082 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +00001083 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001084 printf (FAILED "\n");
paul1f377b02005-09-10 18:00:11 +00001085
1086 printf ("\n");
Paul Jakmab881c702010-11-23 16:35:42 +00001087
1088 if (asp)
Paul Jakma1dba2542012-05-01 16:20:33 +01001089 aspath_unintern (&asp);
paul1f377b02005-09-10 18:00:11 +00001090}
1091
1092/* prepend testing */
Paul Jakma5d932f62006-03-30 13:42:50 +00001093static void
paul1f377b02005-09-10 18:00:11 +00001094prepend_test (struct tests *t)
1095{
1096 struct aspath *asp1, *asp2, *ascratch;
1097
1098 printf ("prepend %s: %s\n", t->test1->name, t->test1->desc);
1099 printf ("to %s: %s\n", t->test2->name, t->test2->desc);
1100
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001101 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
1102 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
paul1f377b02005-09-10 18:00:11 +00001103
1104 ascratch = aspath_dup (asp2);
Paul Jakma1dba2542012-05-01 16:20:33 +01001105 aspath_unintern (&asp2);
paul1f377b02005-09-10 18:00:11 +00001106
1107 asp2 = aspath_prepend (asp1, ascratch);
1108
1109 printf ("aspath: %s\n", aspath_print (asp2));
1110
1111 if (!validate (asp2, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001112 printf ("%s\n", OK);
paul1f377b02005-09-10 18:00:11 +00001113 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001114 printf ("%s!\n", FAILED);
paul1f377b02005-09-10 18:00:11 +00001115
1116 printf ("\n");
Paul Jakma1dba2542012-05-01 16:20:33 +01001117 aspath_unintern (&asp1);
paul1f377b02005-09-10 18:00:11 +00001118 aspath_free (asp2);
1119}
1120
1121/* empty-prepend testing */
Paul Jakma5d932f62006-03-30 13:42:50 +00001122static void
paul1f377b02005-09-10 18:00:11 +00001123empty_prepend_test (struct test_segment *t)
1124{
1125 struct aspath *asp1, *asp2, *ascratch;
1126
1127 printf ("empty prepend %s: %s\n", t->name, t->desc);
1128
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001129 asp1 = make_aspath (t->asdata, t->len, 0);
paul1f377b02005-09-10 18:00:11 +00001130 asp2 = aspath_empty ();
1131
1132 ascratch = aspath_dup (asp2);
Paul Jakma1dba2542012-05-01 16:20:33 +01001133 aspath_unintern (&asp2);
paul1f377b02005-09-10 18:00:11 +00001134
1135 asp2 = aspath_prepend (asp1, ascratch);
1136
1137 printf ("aspath: %s\n", aspath_print (asp2));
1138
1139 if (!validate (asp2, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001140 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +00001141 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001142 printf (FAILED "!\n");
paul1f377b02005-09-10 18:00:11 +00001143
1144 printf ("\n");
Paul Jakmab881c702010-11-23 16:35:42 +00001145 if (asp1)
Paul Jakma1dba2542012-05-01 16:20:33 +01001146 aspath_unintern (&asp1);
paul1f377b02005-09-10 18:00:11 +00001147 aspath_free (asp2);
1148}
1149
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001150/* as2+as4 reconciliation testing */
1151static void
1152as4_reconcile_test (struct tests *t)
1153{
1154 struct aspath *asp1, *asp2, *ascratch;
1155
1156 printf ("reconciling %s:\n %s\n", t->test1->name, t->test1->desc);
1157 printf ("with %s:\n %s\n", t->test2->name, t->test2->desc);
1158
1159 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
1160 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
1161
1162 ascratch = aspath_reconcile_as4 (asp1, asp2);
1163
1164 if (!validate (ascratch, &t->sp))
1165 printf (OK "\n");
1166 else
1167 printf (FAILED "!\n");
1168
1169 printf ("\n");
Paul Jakma1dba2542012-05-01 16:20:33 +01001170 aspath_unintern (&asp1);
1171 aspath_unintern (&asp2);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001172 aspath_free (ascratch);
1173}
1174
1175
paul1f377b02005-09-10 18:00:11 +00001176/* aggregation testing */
Paul Jakma5d932f62006-03-30 13:42:50 +00001177static void
paul1f377b02005-09-10 18:00:11 +00001178aggregate_test (struct tests *t)
1179{
1180 struct aspath *asp1, *asp2, *ascratch;
1181
1182 printf ("aggregate %s: %s\n", t->test1->name, t->test1->desc);
1183 printf ("with %s: %s\n", t->test2->name, t->test2->desc);
1184
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001185 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
1186 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
paul1f377b02005-09-10 18:00:11 +00001187
1188 ascratch = aspath_aggregate (asp1, asp2);
1189
paul1f377b02005-09-10 18:00:11 +00001190 if (!validate (ascratch, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001191 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +00001192 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001193 printf (FAILED "!\n");
paul1f377b02005-09-10 18:00:11 +00001194
1195 printf ("\n");
Paul Jakma1dba2542012-05-01 16:20:33 +01001196 aspath_unintern (&asp1);
1197 aspath_unintern (&asp2);
paul1f377b02005-09-10 18:00:11 +00001198 aspath_free (ascratch);
1199/* aspath_unintern (ascratch);*/
1200}
1201
1202/* cmp_left tests */
1203static void
1204cmp_test ()
1205{
paul84771ee2005-10-11 03:48:28 +00001206 unsigned int i;
paul1f377b02005-09-10 18:00:11 +00001207#define CMP_TESTS_MAX \
1208 (sizeof(left_compare) / sizeof (struct compare_tests))
1209
1210 for (i = 0; i < CMP_TESTS_MAX; i++)
1211 {
1212 struct test_segment *t1 = &test_segments[left_compare[i].test_index1];
1213 struct test_segment *t2 = &test_segments[left_compare[i].test_index2];
1214 struct aspath *asp1, *asp2;
1215
1216 printf ("left cmp %s: %s\n", t1->name, t1->desc);
1217 printf ("and %s: %s\n", t2->name, t2->desc);
1218
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001219 asp1 = make_aspath (t1->asdata, t1->len, 0);
1220 asp2 = make_aspath (t2->asdata, t2->len, 0);
paul1f377b02005-09-10 18:00:11 +00001221
1222 if (aspath_cmp_left (asp1, asp2) != left_compare[i].shouldbe_cmp
1223 || aspath_cmp_left (asp2, asp1) != left_compare[i].shouldbe_cmp
1224 || aspath_cmp_left_confed (asp1, asp2)
1225 != left_compare[i].shouldbe_confed
1226 || aspath_cmp_left_confed (asp2, asp1)
1227 != left_compare[i].shouldbe_confed)
1228 {
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001229 failed++;
1230 printf (FAILED "\n");
paul1f377b02005-09-10 18:00:11 +00001231 printf ("result should be: cmp: %d, confed: %d\n",
1232 left_compare[i].shouldbe_cmp,
1233 left_compare[i].shouldbe_confed);
1234 printf ("got: cmp %d, cmp_confed: %d\n",
1235 aspath_cmp_left (asp1, asp2),
1236 aspath_cmp_left_confed (asp1, asp2));
1237 printf("path1: %s\npath2: %s\n", aspath_print (asp1),
1238 aspath_print (asp2));
paul1f377b02005-09-10 18:00:11 +00001239 }
1240 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001241 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +00001242
1243 printf ("\n");
Paul Jakma1dba2542012-05-01 16:20:33 +01001244 aspath_unintern (&asp1);
1245 aspath_unintern (&asp2);
paul1f377b02005-09-10 18:00:11 +00001246 }
1247}
Paul Jakma50ef5652010-11-27 23:14:02 +00001248
1249static int
1250handle_attr_test (struct aspath_tests *t)
1251{
1252 struct bgp bgp = { 0 };
1253 struct peer peer = { 0 };
1254 struct attr attr = { 0 };
1255 int ret;
1256 int initfail = failed;
1257 struct aspath *asp;
1258 size_t datalen;
1259
1260 asp = make_aspath (t->segment->asdata, t->segment->len, 0);
1261
1262 peer.ibuf = stream_new (BGP_MAX_PACKET_SIZE);
1263 peer.obuf = stream_fifo_new ();
1264 peer.bgp = &bgp;
1265 peer.host = (char *)"none";
1266 peer.fd = -1;
1267 peer.cap = t->cap;
1268
1269 stream_write (peer.ibuf, t->attrheader, t->len);
1270 datalen = aspath_put (peer.ibuf, asp, t->as4 == AS4_DATA);
David Lamparter1cb9cf02013-01-22 23:39:17 +01001271 if (t->old_segment)
1272 {
1273 char dummyaspath[] = { BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH,
1274 t->old_segment->len };
1275 stream_write (peer.ibuf, dummyaspath, sizeof (dummyaspath));
1276 stream_write (peer.ibuf, t->old_segment->asdata, t->old_segment->len);
1277 datalen += sizeof (dummyaspath) + t->old_segment->len;
1278 }
Paul Jakma50ef5652010-11-27 23:14:02 +00001279
1280 ret = bgp_attr_parse (&peer, &attr, t->len + datalen, NULL, NULL);
1281
1282 if (ret != t->result)
1283 {
1284 printf ("bgp_attr_parse returned %d, expected %d\n", ret, t->result);
Paul Jakma1dba2542012-05-01 16:20:33 +01001285 printf ("datalen %zd\n", datalen);
Paul Jakma50ef5652010-11-27 23:14:02 +00001286 failed++;
1287 }
1288 if (ret != 0)
1289 goto out;
1290
David Lamparter1cb9cf02013-01-22 23:39:17 +01001291 if (t->shouldbe && attr.aspath == NULL)
Paul Jakma50ef5652010-11-27 23:14:02 +00001292 {
David Lamparter1cb9cf02013-01-22 23:39:17 +01001293 printf ("aspath is NULL, but should be: %s\n", t->shouldbe);
Paul Jakma50ef5652010-11-27 23:14:02 +00001294 failed++;
1295 }
David Lamparter1cb9cf02013-01-22 23:39:17 +01001296 if (t->shouldbe && attr.aspath && strcmp (attr.aspath->str, t->shouldbe))
Paul Jakma50ef5652010-11-27 23:14:02 +00001297 {
1298 printf ("attr str and 'shouldbe' mismatched!\n"
1299 "attr str: %s\n"
1300 "shouldbe: %s\n",
1301 attr.aspath->str, t->shouldbe);
1302 failed++;
1303 }
David Lamparter1cb9cf02013-01-22 23:39:17 +01001304 if (!t->shouldbe && attr.aspath)
1305 {
1306 printf ("aspath should be NULL, but is: %s\n", attr.aspath->str);
1307 failed++;
1308 }
Paul Jakma50ef5652010-11-27 23:14:02 +00001309
1310out:
1311 if (attr.aspath)
Paul Jakma1dba2542012-05-01 16:20:33 +01001312 aspath_unintern (&attr.aspath);
Paul Jakma50ef5652010-11-27 23:14:02 +00001313 if (asp)
Paul Jakma1dba2542012-05-01 16:20:33 +01001314 aspath_unintern (&asp);
Paul Jakma50ef5652010-11-27 23:14:02 +00001315 return failed - initfail;
1316}
1317
1318static void
1319attr_test (struct aspath_tests *t)
1320{
1321 printf ("%s\n", t->desc);
1322 printf ("%s\n\n", handle_attr_test (t) ? FAILED : OK);
1323}
1324
paul1f377b02005-09-10 18:00:11 +00001325int
1326main (void)
1327{
1328 int i = 0;
Paul Jakma50ef5652010-11-27 23:14:02 +00001329 bgp_master_init ();
1330 master = bm->master;
Paul Jakmac9e4f862012-06-14 10:42:39 +01001331 bgp_option_set (BGP_OPT_NO_LISTEN);
Paul Jakma50ef5652010-11-27 23:14:02 +00001332 bgp_attr_init ();
1333
paul1f377b02005-09-10 18:00:11 +00001334 while (test_segments[i].name)
1335 {
Paul Jakma50ef5652010-11-27 23:14:02 +00001336 printf ("test %u\n", i);
paul1f377b02005-09-10 18:00:11 +00001337 parse_test (&test_segments[i]);
1338 empty_prepend_test (&test_segments[i++]);
1339 }
1340
1341 i = 0;
1342 while (prepend_tests[i].test1)
Paul Jakma50ef5652010-11-27 23:14:02 +00001343 {
1344 printf ("prepend test %u\n", i);
1345 prepend_test (&prepend_tests[i++]);
1346 }
paul1f377b02005-09-10 18:00:11 +00001347
1348 i = 0;
1349 while (aggregate_tests[i].test1)
Paul Jakma50ef5652010-11-27 23:14:02 +00001350 {
1351 printf ("aggregate test %u\n", i);
1352 aggregate_test (&aggregate_tests[i++]);
1353 }
paul1f377b02005-09-10 18:00:11 +00001354
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001355 i = 0;
1356
1357 while (reconcile_tests[i].test1)
Paul Jakma50ef5652010-11-27 23:14:02 +00001358 {
1359 printf ("reconcile test %u\n", i);
1360 as4_reconcile_test (&reconcile_tests[i++]);
1361 }
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001362
1363 i = 0;
1364
paul1f377b02005-09-10 18:00:11 +00001365 cmp_test();
1366
1367 i = 0;
1368
1369 empty_get_test();
1370
Paul Jakma50ef5652010-11-27 23:14:02 +00001371 i = 0;
1372
1373 while (aspath_tests[i].desc)
1374 {
1375 printf ("aspath_attr test %d\n", i);
1376 attr_test (&aspath_tests[i++]);
1377 }
1378
paul1f377b02005-09-10 18:00:11 +00001379 printf ("failures: %d\n", failed);
1380 printf ("aspath count: %ld\n", aspath_count());
1381
1382 return (failed + aspath_count());
1383}