blob: 0aa3e47e719db9cd27b054a7ac4ccb9ee077226b [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, \
David Lamparter14363712015-02-04 07:26:03 +0100460 BGP_ORIGIN_EGP, \
461 BGP_ATTR_FLAG_TRANS, \
462 BGP_ATTR_NEXT_HOP, \
463 4, 192, 0, 2, 0
464#define COMMON_ATTR_SIZE 11
David Lamparterc68f6d92014-10-30 06:42:00 +0100465
Paul Jakma50ef5652010-11-27 23:14:02 +0000466/* */
467static struct aspath_tests {
468 const char *desc;
469 const struct test_segment *segment;
470 const char *shouldbe; /* String it should evaluate to */
471 const enum as4 { AS4_DATA, AS2_DATA }
472 as4; /* whether data should be as4 or not (ie as2) */
473 const int result; /* expected result for bgp_attr_parse */
474 const int cap; /* capabilities to set for peer */
475 const char attrheader [1024];
476 size_t len;
David Lamparter1cb9cf02013-01-22 23:39:17 +0100477 const struct test_segment *old_segment;
Paul Jakma50ef5652010-11-27 23:14:02 +0000478} aspath_tests [] =
479{
480 /* 0 */
481 {
482 "basic test",
483 &test_segments[0],
484 "8466 3 52737 4096",
485 AS2_DATA, 0,
486 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100487 { COMMON_ATTRS,
488 BGP_ATTR_FLAG_TRANS,
489 BGP_ATTR_AS_PATH,
Paul Jakma50ef5652010-11-27 23:14:02 +0000490 10,
491 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100492 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000493 },
494 /* 1 */
495 {
496 "length too short",
497 &test_segments[0],
498 "8466 3 52737 4096",
499 AS2_DATA, -1,
500 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100501 { COMMON_ATTRS,
502 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000503 BGP_ATTR_AS_PATH,
504 8,
505 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100506 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000507 },
508 /* 2 */
509 {
510 "length too long",
511 &test_segments[0],
512 "8466 3 52737 4096",
513 AS2_DATA, -1,
514 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100515 { COMMON_ATTRS,
516 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000517 BGP_ATTR_AS_PATH,
518 12,
519 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100520 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000521 },
522 /* 3 */
523 {
524 "incorrect flag",
525 &test_segments[0],
526 "8466 3 52737 4096",
527 AS2_DATA, -1,
528 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100529 { COMMON_ATTRS,
530 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000531 BGP_ATTR_AS_PATH,
532 10,
533 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100534 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000535 },
536 /* 4 */
537 {
538 "as4_path, with as2 format data",
539 &test_segments[0],
540 "8466 3 52737 4096",
541 AS2_DATA, -1,
542 0,
David Lamparterc68f6d92014-10-30 06:42:00 +0100543 { COMMON_ATTRS,
544 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000545 BGP_ATTR_AS4_PATH,
546 10,
547 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100548 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000549 },
550 /* 5 */
551 {
552 "as4, with incorrect attr length",
553 &test_segments[0],
554 "8466 3 52737 4096",
555 AS4_DATA, -1,
556 PEER_CAP_AS4_RCV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100557 { COMMON_ATTRS,
558 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000559 BGP_ATTR_AS4_PATH,
560 10,
561 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100562 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000563 },
564 /* 6 */
565 {
566 "basic 4-byte as-path",
567 &test_segments[0],
568 "8466 3 52737 4096",
569 AS4_DATA, 0,
570 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100571 { COMMON_ATTRS,
572 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000573 BGP_ATTR_AS_PATH,
574 18,
575 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100576 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000577 },
578 /* 7 */
579 {
580 "4b AS_PATH: too short",
581 &test_segments[0],
582 "8466 3 52737 4096",
583 AS4_DATA, -1,
584 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100585 { COMMON_ATTRS,
586 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000587 BGP_ATTR_AS_PATH,
588 16,
589 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100590 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000591 },
592 /* 8 */
593 {
594 "4b AS_PATH: too long",
595 &test_segments[0],
596 "8466 3 52737 4096",
597 AS4_DATA, -1,
598 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100599 { COMMON_ATTRS,
600 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000601 BGP_ATTR_AS_PATH,
602 20,
603 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100604 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000605 },
606 /* 9 */
607 {
608 "4b AS_PATH: too long2",
609 &test_segments[0],
610 "8466 3 52737 4096",
611 AS4_DATA, -1,
612 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100613 { COMMON_ATTRS,
614 BGP_ATTR_FLAG_TRANS,
Paul Jakma50ef5652010-11-27 23:14:02 +0000615 BGP_ATTR_AS_PATH,
616 22,
617 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100618 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000619 },
620 /* 10 */
621 {
622 "4b AS_PATH: bad flags",
623 &test_segments[0],
624 "8466 3 52737 4096",
625 AS4_DATA, -1,
626 PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100627 { COMMON_ATTRS,
628 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000629 BGP_ATTR_AS_PATH,
630 18,
631 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100632 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000633 },
634 /* 11 */
635 {
David Lamparter1cb9cf02013-01-22 23:39:17 +0100636 "4b AS4_PATH w/o AS_PATH",
Paul Jakma50ef5652010-11-27 23:14:02 +0000637 &test_segments[6],
David Lamparter1cb9cf02013-01-22 23:39:17 +0100638 NULL,
David Lamparterc68f6d92014-10-30 06:42:00 +0100639 AS4_DATA, -1,
Paul Jakma50ef5652010-11-27 23:14:02 +0000640 PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100641 { COMMON_ATTRS,
642 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
Paul Jakma50ef5652010-11-27 23:14:02 +0000643 BGP_ATTR_AS4_PATH,
644 14,
645 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100646 COMMON_ATTR_SIZE + 3,
Paul Jakma50ef5652010-11-27 23:14:02 +0000647 },
David Lamparter1cb9cf02013-01-22 23:39:17 +0100648 /* 12 */
649 {
650 "4b AS4_PATH: confed",
651 &test_segments[6],
652 "8466 3 52737 4096 (123 456 789)",
653 AS4_DATA, 0,
654 PEER_CAP_AS4_ADV,
David Lamparterc68f6d92014-10-30 06:42:00 +0100655 { COMMON_ATTRS,
656 BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
David Lamparter1cb9cf02013-01-22 23:39:17 +0100657 BGP_ATTR_AS4_PATH,
658 14,
659 },
David Lamparterc68f6d92014-10-30 06:42:00 +0100660 COMMON_ATTR_SIZE + 3,
David Lamparter1cb9cf02013-01-22 23:39:17 +0100661 &test_segments[0],
662 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000663 { NULL, NULL, NULL, 0, 0, 0, { 0 }, 0 },
paul1f377b02005-09-10 18:00:11 +0000664};
665
666/* prepending tests */
667static struct tests {
668 const struct test_segment *test1;
669 const struct test_segment *test2;
670 struct test_spec sp;
671} prepend_tests[] =
672{
Paul Jakma50ef5652010-11-27 23:14:02 +0000673 /* 0 */
paul1f377b02005-09-10 18:00:11 +0000674 { &test_segments[0], &test_segments[1],
675 { "8466 3 52737 4096 8722 4",
676 "8466 3 52737 4096 8722 4",
677 6, 0, NOT_ALL_PRIVATE, 4096, 1, 8466 },
678 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000679 /* 1 */
paul1f377b02005-09-10 18:00:11 +0000680 { &test_segments[1], &test_segments[3],
681 { "8722 4 8482 51457 {5204}",
682 "8722 4 8482 51457 {5204}",
683 5, 0, NOT_ALL_PRIVATE, 5204, 1, 8722 }
684 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000685 /* 2 */
paul1f377b02005-09-10 18:00:11 +0000686 { &test_segments[3], &test_segments[4],
687 { "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
688 "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
689 7, 0, NOT_ALL_PRIVATE, 5204, 1, 8482 },
690 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000691 /* 3 */
paul1f377b02005-09-10 18:00:11 +0000692 { &test_segments[4], &test_segments[5],
693 { "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
694 " {2457,4369,61697} 1842 41590 51793",
695 "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
696 " {2457,4369,61697} 1842 41590 51793",
697 11, 0, NOT_ALL_PRIVATE, 61697, 1, 8467 }
698 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000699 /* 4 */
paul1f377b02005-09-10 18:00:11 +0000700 { &test_segments[5], &test_segments[6],
Paul Jakma50ef5652010-11-27 23:14:02 +0000701 { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
702 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
703 7, 0, NOT_ALL_PRIVATE, 1842, 1, 6435 },
paul1f377b02005-09-10 18:00:11 +0000704 },
Paul Jakma50ef5652010-11-27 23:14:02 +0000705 /* 5 */
paul1f377b02005-09-10 18:00:11 +0000706 { &test_segments[6], &test_segments[7],
707 { "(123 456 789) (123 456 789) (111 222)",
708 "",
709 0, 8, NOT_ALL_PRIVATE, 111, 1, 0 }
710 },
711 { &test_segments[7], &test_segments[8],
712 { "(123 456 789) (111 222) [123,456,789]",
713 "",
714 0, 6, NOT_ALL_PRIVATE, 111, 1, 0 }
715 },
716 { &test_segments[8], &test_segments[9],
717 { "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
718 "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
719 2, 5, NOT_ALL_PRIVATE, 456, 1, NULL_ASN },
720 },
721 { &test_segments[9], &test_segments[8],
722 { "(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]",
723 "8722 {4196,48658} [123,456,789]",
724 2, 5, NOT_ALL_PRIVATE, 48658, 1, NULL_ASN },
725 },
726 { &test_segments[14], &test_segments[11],
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 3 52737 4096 34285 8466 3 52737 4096 34285 "
750 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
751 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
752 "8466 2 52737 4096 8722 4 8722",
753
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 3 52737 4096 34285 8466 3 52737 4096 34285 "
777 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
778 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
779 "8466 2 52737 4096 8722 4 8722",
780 257, 0, NOT_ALL_PRIVATE, 4096, 1000, 8466 },
781 },
782 { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } },
783};
784
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000785struct tests reconcile_tests[] =
786{
787 { &test_segments[18], &test_segments[19],
788 { "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
789 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
790 7, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
791 },
792 { &test_segments[19], &test_segments[18],
793 /* AS_PATH (19) has more hops than NEW_AS_PATH,
794 * so just AS_PATH should be used (though, this practice
795 * is bad imho).
796 */
797 { "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
798 "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
799 11, 0, NOT_ALL_PRIVATE, 51793, 1, 6435 },
800 },
801 { &test_segments[20], &test_segments[19],
802 { "(123 456 789) [124,456,788] 6435 59408 21665"
803 " {2457,4369,61697} 1842 41591 51793",
804 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
805 7, 4, NOT_ALL_PRIVATE, 51793, 1, 6435 },
806 },
807 { &test_segments[21], &test_segments[22],
808 { "1842 41591 51793 6435 59408 21665",
809 "1842 41591 51793 6435 59408 21665",
810 6, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 },
811 },
812 { &test_segments[23], &test_segments[22],
813 { "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
814 "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
815 11, 0, NOT_ALL_PRIVATE, 51793, 1, 1842 },
816 },
817 { NULL, NULL, { NULL, 0, 0, 0, 0, 0, 0, } },
818};
819
paul1f377b02005-09-10 18:00:11 +0000820struct tests aggregate_tests[] =
821{
paul1f377b02005-09-10 18:00:11 +0000822 { &test_segments[0], &test_segments[2],
823 { "8466 3 52737 4096 {4,8722}",
824 "8466 3 52737 4096 {4,8722}",
825 5, 0, NOT_ALL_PRIVATE, 4, 1, 8466 },
826 },
827 { &test_segments[2], &test_segments[0],
828 { "8466 3 52737 4096 {4,8722}",
829 "8466 3 52737 4096 {4,8722}",
830 5, 0, NOT_ALL_PRIVATE, 8722, 1, 8466 },
831 },
832 { &test_segments[2], &test_segments[10],
833 { "8466 {2,3,4,4096,8722,52737}",
834 "8466 {2,3,4,4096,8722,52737}",
835 2, 0, NOT_ALL_PRIVATE, 8722, 5, 8466 },
836 },
837 { &test_segments[10], &test_segments[2],
838 { "8466 {2,3,4,4096,8722,52737}",
839 "8466 {2,3,4,4096,8722,52737}",
840 2, 0, NOT_ALL_PRIVATE, 2, 20000, 8466 },
841 },
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000842
843 { &test_segments[5], &test_segments[18],
844 { "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
845 "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
846 4, 0, NOT_ALL_PRIVATE, 41590, 1, 6435 },
847 },
848
paul1f377b02005-09-10 18:00:11 +0000849 { NULL, NULL, { NULL, 0, 0} },
850};
851
852struct compare_tests
853{
854 int test_index1;
855 int test_index2;
856#define CMP_RES_YES 1
857#define CMP_RES_NO 0
858 char shouldbe_cmp;
859 char shouldbe_confed;
860} left_compare [] =
861{
862 { 0, 1, CMP_RES_NO, CMP_RES_NO },
863 { 0, 2, CMP_RES_YES, CMP_RES_NO },
864 { 0, 11, CMP_RES_YES, CMP_RES_NO },
paul59064762005-11-23 02:48:14 +0000865 { 0, 15, CMP_RES_YES, CMP_RES_NO },
866 { 0, 16, CMP_RES_NO, CMP_RES_NO },
paul1f377b02005-09-10 18:00:11 +0000867 { 1, 11, CMP_RES_NO, CMP_RES_NO },
868 { 6, 7, CMP_RES_NO, CMP_RES_YES },
869 { 6, 8, CMP_RES_NO, CMP_RES_NO },
870 { 7, 8, CMP_RES_NO, CMP_RES_NO },
871 { 1, 9, CMP_RES_YES, CMP_RES_NO },
872 { 0, 9, CMP_RES_NO, CMP_RES_NO },
873 { 3, 9, CMP_RES_NO, CMP_RES_NO },
874 { 0, 6, CMP_RES_NO, CMP_RES_NO },
875 { 1, 6, CMP_RES_NO, CMP_RES_NO },
876 { 0, 8, CMP_RES_NO, CMP_RES_NO },
877 { 1, 8, CMP_RES_NO, CMP_RES_NO },
878 { 11, 6, CMP_RES_NO, CMP_RES_NO },
879 { 11, 7, CMP_RES_NO, CMP_RES_NO },
880 { 11, 8, CMP_RES_NO, CMP_RES_NO },
881 { 9, 6, CMP_RES_NO, CMP_RES_YES },
882 { 9, 7, CMP_RES_NO, CMP_RES_YES },
883 { 9, 8, CMP_RES_NO, CMP_RES_NO },
884};
885
886/* make an aspath from a data stream */
887static struct aspath *
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000888make_aspath (const u_char *data, size_t len, int use32bit)
paul1f377b02005-09-10 18:00:11 +0000889{
890 struct stream *s = NULL;
891 struct aspath *as;
892
893 if (len)
894 {
895 s = stream_new (len);
896 stream_put (s, data, len);
897 }
Paul Jakma50ef5652010-11-27 23:14:02 +0000898 as = aspath_parse (s, len, use32bit);
paul59064762005-11-23 02:48:14 +0000899
900 if (s)
901 stream_free (s);
paul1f377b02005-09-10 18:00:11 +0000902
903 return as;
904}
905
906static void
907printbytes (const u_char *bytes, int len)
908{
909 int i = 0;
910 while (i < len)
911 {
912 if (i % 2)
913 printf ("%02hhx%s", bytes[i], " ");
914 else
915 printf ("0x%02hhx", bytes[i]);
916 i++;
917 }
918 printf ("\n");
919}
920
921/* validate the given aspath */
922static int
923validate (struct aspath *as, const struct test_spec *sp)
924{
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000925 size_t bytes, bytes4;
paul1f377b02005-09-10 18:00:11 +0000926 int fails = 0;
927 const u_char *out;
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000928 static struct stream *s;
929 struct aspath *asinout, *asconfeddel, *asstr, *as4;
paul1f377b02005-09-10 18:00:11 +0000930
Paul Jakmab881c702010-11-23 16:35:42 +0000931 if (as == NULL && sp->shouldbe == NULL)
932 {
933 printf ("Correctly failed to parse\n");
934 return fails;
935 }
936
paul1f377b02005-09-10 18:00:11 +0000937 out = aspath_snmp_pathseg (as, &bytes);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000938 asinout = make_aspath (out, bytes, 0);
939
940 /* Excercise AS4 parsing a bit, with a dogfood test */
941 if (!s)
942 s = stream_new (4096);
943 bytes4 = aspath_put (s, as, 1);
944 as4 = make_aspath (STREAM_DATA(s), bytes4, 1);
paul1f377b02005-09-10 18:00:11 +0000945
946 asstr = aspath_str2aspath (sp->shouldbe);
947
948 asconfeddel = aspath_delete_confed_seq (aspath_dup (asinout));
949
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000950 printf ("got: %s\n", aspath_print(as));
951
paul1f377b02005-09-10 18:00:11 +0000952 /* the parsed path should match the specified 'shouldbe' string.
953 * We should pass the "eat our own dog food" test, be able to output
954 * this path and then input it again. Ie the path resulting from:
955 *
956 * aspath_parse(aspath_put(as))
957 *
958 * should:
959 *
960 * - also match the specified 'shouldbe' value
961 * - hash to same value as original path
962 * - have same hops and confed counts as original, and as the
963 * the specified counts
964 *
965 * aspath_str2aspath() and shouldbe should match
966 *
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000967 * We do the same for:
968 *
969 * aspath_parse(aspath_put(as,USE32BIT))
970 *
paul1f377b02005-09-10 18:00:11 +0000971 * Confederation related tests:
972 * - aspath_delete_confed_seq(aspath) should match shouldbe_confed
973 * - aspath_delete_confed_seq should be idempotent.
974 */
975 if (strcmp(aspath_print (as), sp->shouldbe)
976 /* hash validation */
977 || (aspath_key_make (as) != aspath_key_make (asinout))
978 /* by string */
979 || strcmp(aspath_print (asinout), sp->shouldbe)
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000980 /* By 4-byte parsing */
981 || strcmp(aspath_print (as4), sp->shouldbe)
paul1f377b02005-09-10 18:00:11 +0000982 /* by various path counts */
983 || (aspath_count_hops (as) != sp->hops)
984 || (aspath_count_confeds (as) != sp->confeds)
985 || (aspath_count_hops (asinout) != sp->hops)
986 || (aspath_count_confeds (asinout) != sp->confeds))
987 {
988 failed++;
989 fails++;
990 printf ("shouldbe:\n%s\n", sp->shouldbe);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +0000991 printf ("as4:\n%s\n", aspath_print (as4));
paul1f377b02005-09-10 18:00:11 +0000992 printf ("hash keys: in: %d out->in: %d\n",
993 aspath_key_make (as), aspath_key_make (asinout));
994 printf ("hops: %d, counted %d %d\n", sp->hops,
995 aspath_count_hops (as),
996 aspath_count_hops (asinout) );
997 printf ("confeds: %d, counted %d %d\n", sp->confeds,
998 aspath_count_confeds (as),
999 aspath_count_confeds (asinout));
1000 printf ("out->in:\n%s\nbytes: ", aspath_print(asinout));
1001 printbytes (out, bytes);
1002 }
1003 /* basic confed related tests */
1004 if ((aspath_print (asconfeddel) == NULL
1005 && sp->shouldbe_delete_confed != NULL)
1006 || (aspath_print (asconfeddel) != NULL
1007 && sp->shouldbe_delete_confed == NULL)
1008 || strcmp(aspath_print (asconfeddel), sp->shouldbe_delete_confed)
1009 /* delete_confed_seq should be idempotent */
1010 || (aspath_key_make (asconfeddel)
1011 != aspath_key_make (aspath_delete_confed_seq (asconfeddel))))
1012 {
1013 failed++;
1014 fails++;
1015 printf ("confed_del: %s\n", aspath_print (asconfeddel));
1016 printf ("should be: %s\n", sp->shouldbe_delete_confed);
1017 }
1018 /* aspath_str2aspath test */
1019 if ((aspath_print (asstr) == NULL && sp->shouldbe != NULL)
1020 || (aspath_print (asstr) != NULL && sp->shouldbe == NULL)
1021 || strcmp(aspath_print (asstr), sp->shouldbe))
1022 {
1023 failed++;
1024 fails++;
1025 printf ("asstr: %s\n", aspath_print (asstr));
1026 }
1027
1028 /* loop, private and first as checks */
Paul Jakma1f742f22006-08-06 15:52:11 +00001029 if ((sp->does_loop && aspath_loop_check (as, sp->does_loop) == 0)
1030 || (sp->doesnt_loop && aspath_loop_check (as, sp->doesnt_loop) != 0)
paul1f377b02005-09-10 18:00:11 +00001031 || (aspath_private_as_check (as) != sp->private_as)
1032 || (aspath_firstas_check (as,sp->first)
1033 && sp->first == 0))
1034 {
1035 failed++;
1036 fails++;
1037 printf ("firstas: %d, got %d\n", sp->first,
1038 aspath_firstas_check (as,sp->first));
1039 printf ("loop does: %d %d, doesnt: %d %d\n",
1040 sp->does_loop, aspath_loop_check (as, sp->does_loop),
1041 sp->doesnt_loop, aspath_loop_check (as, sp->doesnt_loop));
1042 printf ("private check: %d %d\n", sp->private_as,
1043 aspath_private_as_check (as));
1044 }
Paul Jakma1dba2542012-05-01 16:20:33 +01001045 aspath_unintern (&asinout);
1046 aspath_unintern (&as4);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001047
paul6726f952006-01-16 12:06:00 +00001048 aspath_free (asconfeddel);
1049 aspath_free (asstr);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001050 stream_reset (s);
paul6726f952006-01-16 12:06:00 +00001051
paul1f377b02005-09-10 18:00:11 +00001052 return fails;
paul1f377b02005-09-10 18:00:11 +00001053}
1054
1055static void
1056empty_get_test ()
1057{
1058 struct aspath *as = aspath_empty_get ();
1059 struct test_spec sp = { "", "", 0, 0, 0, 0, 0, 0 };
1060
1061 printf ("empty_get_test, as: %s\n",aspath_print (as));
1062 if (!validate (as, &sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001063 printf ("%s\n", OK);
paul1f377b02005-09-10 18:00:11 +00001064 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001065 printf ("%s!\n", FAILED);
paul1f377b02005-09-10 18:00:11 +00001066
1067 printf ("\n");
paul6726f952006-01-16 12:06:00 +00001068
1069 aspath_free (as);
paul1f377b02005-09-10 18:00:11 +00001070}
1071
1072/* basic parsing test */
1073static void
1074parse_test (struct test_segment *t)
1075{
1076 struct aspath *asp;
1077
1078 printf ("%s: %s\n", t->name, t->desc);
1079
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001080 asp = make_aspath (t->asdata, t->len, 0);
Paul Jakmab881c702010-11-23 16:35:42 +00001081
paul1f377b02005-09-10 18:00:11 +00001082 printf ("aspath: %s\nvalidating...:\n", aspath_print (asp));
1083
1084 if (!validate (asp, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001085 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +00001086 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001087 printf (FAILED "\n");
paul1f377b02005-09-10 18:00:11 +00001088
1089 printf ("\n");
Paul Jakmab881c702010-11-23 16:35:42 +00001090
1091 if (asp)
Paul Jakma1dba2542012-05-01 16:20:33 +01001092 aspath_unintern (&asp);
paul1f377b02005-09-10 18:00:11 +00001093}
1094
1095/* prepend testing */
Paul Jakma5d932f62006-03-30 13:42:50 +00001096static void
paul1f377b02005-09-10 18:00:11 +00001097prepend_test (struct tests *t)
1098{
1099 struct aspath *asp1, *asp2, *ascratch;
1100
1101 printf ("prepend %s: %s\n", t->test1->name, t->test1->desc);
1102 printf ("to %s: %s\n", t->test2->name, t->test2->desc);
1103
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001104 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
1105 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
paul1f377b02005-09-10 18:00:11 +00001106
1107 ascratch = aspath_dup (asp2);
Paul Jakma1dba2542012-05-01 16:20:33 +01001108 aspath_unintern (&asp2);
paul1f377b02005-09-10 18:00:11 +00001109
1110 asp2 = aspath_prepend (asp1, ascratch);
1111
1112 printf ("aspath: %s\n", aspath_print (asp2));
1113
1114 if (!validate (asp2, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001115 printf ("%s\n", OK);
paul1f377b02005-09-10 18:00:11 +00001116 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001117 printf ("%s!\n", FAILED);
paul1f377b02005-09-10 18:00:11 +00001118
1119 printf ("\n");
Paul Jakma1dba2542012-05-01 16:20:33 +01001120 aspath_unintern (&asp1);
paul1f377b02005-09-10 18:00:11 +00001121 aspath_free (asp2);
1122}
1123
1124/* empty-prepend testing */
Paul Jakma5d932f62006-03-30 13:42:50 +00001125static void
paul1f377b02005-09-10 18:00:11 +00001126empty_prepend_test (struct test_segment *t)
1127{
1128 struct aspath *asp1, *asp2, *ascratch;
1129
1130 printf ("empty prepend %s: %s\n", t->name, t->desc);
1131
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001132 asp1 = make_aspath (t->asdata, t->len, 0);
paul1f377b02005-09-10 18:00:11 +00001133 asp2 = aspath_empty ();
1134
1135 ascratch = aspath_dup (asp2);
Paul Jakma1dba2542012-05-01 16:20:33 +01001136 aspath_unintern (&asp2);
paul1f377b02005-09-10 18:00:11 +00001137
1138 asp2 = aspath_prepend (asp1, ascratch);
1139
1140 printf ("aspath: %s\n", aspath_print (asp2));
1141
1142 if (!validate (asp2, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001143 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +00001144 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001145 printf (FAILED "!\n");
paul1f377b02005-09-10 18:00:11 +00001146
1147 printf ("\n");
Paul Jakmab881c702010-11-23 16:35:42 +00001148 if (asp1)
Paul Jakma1dba2542012-05-01 16:20:33 +01001149 aspath_unintern (&asp1);
paul1f377b02005-09-10 18:00:11 +00001150 aspath_free (asp2);
1151}
1152
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001153/* as2+as4 reconciliation testing */
1154static void
1155as4_reconcile_test (struct tests *t)
1156{
1157 struct aspath *asp1, *asp2, *ascratch;
1158
1159 printf ("reconciling %s:\n %s\n", t->test1->name, t->test1->desc);
1160 printf ("with %s:\n %s\n", t->test2->name, t->test2->desc);
1161
1162 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
1163 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
1164
1165 ascratch = aspath_reconcile_as4 (asp1, asp2);
1166
1167 if (!validate (ascratch, &t->sp))
1168 printf (OK "\n");
1169 else
1170 printf (FAILED "!\n");
1171
1172 printf ("\n");
Paul Jakma1dba2542012-05-01 16:20:33 +01001173 aspath_unintern (&asp1);
1174 aspath_unintern (&asp2);
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001175 aspath_free (ascratch);
1176}
1177
1178
paul1f377b02005-09-10 18:00:11 +00001179/* aggregation testing */
Paul Jakma5d932f62006-03-30 13:42:50 +00001180static void
paul1f377b02005-09-10 18:00:11 +00001181aggregate_test (struct tests *t)
1182{
1183 struct aspath *asp1, *asp2, *ascratch;
1184
1185 printf ("aggregate %s: %s\n", t->test1->name, t->test1->desc);
1186 printf ("with %s: %s\n", t->test2->name, t->test2->desc);
1187
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001188 asp1 = make_aspath (t->test1->asdata, t->test1->len, 0);
1189 asp2 = make_aspath (t->test2->asdata, t->test2->len, 0);
paul1f377b02005-09-10 18:00:11 +00001190
1191 ascratch = aspath_aggregate (asp1, asp2);
1192
paul1f377b02005-09-10 18:00:11 +00001193 if (!validate (ascratch, &t->sp))
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001194 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +00001195 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001196 printf (FAILED "!\n");
paul1f377b02005-09-10 18:00:11 +00001197
1198 printf ("\n");
Paul Jakma1dba2542012-05-01 16:20:33 +01001199 aspath_unintern (&asp1);
1200 aspath_unintern (&asp2);
paul1f377b02005-09-10 18:00:11 +00001201 aspath_free (ascratch);
1202/* aspath_unintern (ascratch);*/
1203}
1204
1205/* cmp_left tests */
1206static void
1207cmp_test ()
1208{
paul84771ee2005-10-11 03:48:28 +00001209 unsigned int i;
paul1f377b02005-09-10 18:00:11 +00001210#define CMP_TESTS_MAX \
1211 (sizeof(left_compare) / sizeof (struct compare_tests))
1212
1213 for (i = 0; i < CMP_TESTS_MAX; i++)
1214 {
1215 struct test_segment *t1 = &test_segments[left_compare[i].test_index1];
1216 struct test_segment *t2 = &test_segments[left_compare[i].test_index2];
1217 struct aspath *asp1, *asp2;
1218
1219 printf ("left cmp %s: %s\n", t1->name, t1->desc);
1220 printf ("and %s: %s\n", t2->name, t2->desc);
1221
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001222 asp1 = make_aspath (t1->asdata, t1->len, 0);
1223 asp2 = make_aspath (t2->asdata, t2->len, 0);
paul1f377b02005-09-10 18:00:11 +00001224
1225 if (aspath_cmp_left (asp1, asp2) != left_compare[i].shouldbe_cmp
1226 || aspath_cmp_left (asp2, asp1) != left_compare[i].shouldbe_cmp
1227 || aspath_cmp_left_confed (asp1, asp2)
1228 != left_compare[i].shouldbe_confed
1229 || aspath_cmp_left_confed (asp2, asp1)
1230 != left_compare[i].shouldbe_confed)
1231 {
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001232 failed++;
1233 printf (FAILED "\n");
paul1f377b02005-09-10 18:00:11 +00001234 printf ("result should be: cmp: %d, confed: %d\n",
1235 left_compare[i].shouldbe_cmp,
1236 left_compare[i].shouldbe_confed);
1237 printf ("got: cmp %d, cmp_confed: %d\n",
1238 aspath_cmp_left (asp1, asp2),
1239 aspath_cmp_left_confed (asp1, asp2));
1240 printf("path1: %s\npath2: %s\n", aspath_print (asp1),
1241 aspath_print (asp2));
paul1f377b02005-09-10 18:00:11 +00001242 }
1243 else
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001244 printf (OK "\n");
paul1f377b02005-09-10 18:00:11 +00001245
1246 printf ("\n");
Paul Jakma1dba2542012-05-01 16:20:33 +01001247 aspath_unintern (&asp1);
1248 aspath_unintern (&asp2);
paul1f377b02005-09-10 18:00:11 +00001249 }
1250}
Paul Jakma50ef5652010-11-27 23:14:02 +00001251
1252static int
1253handle_attr_test (struct aspath_tests *t)
1254{
1255 struct bgp bgp = { 0 };
1256 struct peer peer = { 0 };
1257 struct attr attr = { 0 };
1258 int ret;
1259 int initfail = failed;
1260 struct aspath *asp;
1261 size_t datalen;
1262
1263 asp = make_aspath (t->segment->asdata, t->segment->len, 0);
1264
1265 peer.ibuf = stream_new (BGP_MAX_PACKET_SIZE);
1266 peer.obuf = stream_fifo_new ();
1267 peer.bgp = &bgp;
1268 peer.host = (char *)"none";
1269 peer.fd = -1;
1270 peer.cap = t->cap;
1271
1272 stream_write (peer.ibuf, t->attrheader, t->len);
1273 datalen = aspath_put (peer.ibuf, asp, t->as4 == AS4_DATA);
David Lamparter1cb9cf02013-01-22 23:39:17 +01001274 if (t->old_segment)
1275 {
1276 char dummyaspath[] = { BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH,
1277 t->old_segment->len };
1278 stream_write (peer.ibuf, dummyaspath, sizeof (dummyaspath));
1279 stream_write (peer.ibuf, t->old_segment->asdata, t->old_segment->len);
1280 datalen += sizeof (dummyaspath) + t->old_segment->len;
1281 }
Paul Jakma50ef5652010-11-27 23:14:02 +00001282
1283 ret = bgp_attr_parse (&peer, &attr, t->len + datalen, NULL, NULL);
1284
1285 if (ret != t->result)
1286 {
1287 printf ("bgp_attr_parse returned %d, expected %d\n", ret, t->result);
Paul Jakma1dba2542012-05-01 16:20:33 +01001288 printf ("datalen %zd\n", datalen);
Paul Jakma50ef5652010-11-27 23:14:02 +00001289 failed++;
1290 }
1291 if (ret != 0)
1292 goto out;
1293
David Lamparter1cb9cf02013-01-22 23:39:17 +01001294 if (t->shouldbe && attr.aspath == NULL)
Paul Jakma50ef5652010-11-27 23:14:02 +00001295 {
David Lamparter1cb9cf02013-01-22 23:39:17 +01001296 printf ("aspath is NULL, but should be: %s\n", t->shouldbe);
Paul Jakma50ef5652010-11-27 23:14:02 +00001297 failed++;
1298 }
David Lamparter1cb9cf02013-01-22 23:39:17 +01001299 if (t->shouldbe && attr.aspath && strcmp (attr.aspath->str, t->shouldbe))
Paul Jakma50ef5652010-11-27 23:14:02 +00001300 {
1301 printf ("attr str and 'shouldbe' mismatched!\n"
1302 "attr str: %s\n"
1303 "shouldbe: %s\n",
1304 attr.aspath->str, t->shouldbe);
1305 failed++;
1306 }
David Lamparter1cb9cf02013-01-22 23:39:17 +01001307 if (!t->shouldbe && attr.aspath)
1308 {
1309 printf ("aspath should be NULL, but is: %s\n", attr.aspath->str);
1310 failed++;
1311 }
Paul Jakma50ef5652010-11-27 23:14:02 +00001312
1313out:
1314 if (attr.aspath)
Paul Jakma1dba2542012-05-01 16:20:33 +01001315 aspath_unintern (&attr.aspath);
Paul Jakma50ef5652010-11-27 23:14:02 +00001316 if (asp)
Paul Jakma1dba2542012-05-01 16:20:33 +01001317 aspath_unintern (&asp);
Paul Jakma50ef5652010-11-27 23:14:02 +00001318 return failed - initfail;
1319}
1320
1321static void
1322attr_test (struct aspath_tests *t)
1323{
1324 printf ("%s\n", t->desc);
1325 printf ("%s\n\n", handle_attr_test (t) ? FAILED : OK);
1326}
1327
paul1f377b02005-09-10 18:00:11 +00001328int
1329main (void)
1330{
1331 int i = 0;
Paul Jakma50ef5652010-11-27 23:14:02 +00001332 bgp_master_init ();
1333 master = bm->master;
Paul Jakmac9e4f862012-06-14 10:42:39 +01001334 bgp_option_set (BGP_OPT_NO_LISTEN);
Paul Jakma50ef5652010-11-27 23:14:02 +00001335 bgp_attr_init ();
1336
paul1f377b02005-09-10 18:00:11 +00001337 while (test_segments[i].name)
1338 {
Paul Jakma50ef5652010-11-27 23:14:02 +00001339 printf ("test %u\n", i);
paul1f377b02005-09-10 18:00:11 +00001340 parse_test (&test_segments[i]);
1341 empty_prepend_test (&test_segments[i++]);
1342 }
1343
1344 i = 0;
1345 while (prepend_tests[i].test1)
Paul Jakma50ef5652010-11-27 23:14:02 +00001346 {
1347 printf ("prepend test %u\n", i);
1348 prepend_test (&prepend_tests[i++]);
1349 }
paul1f377b02005-09-10 18:00:11 +00001350
1351 i = 0;
1352 while (aggregate_tests[i].test1)
Paul Jakma50ef5652010-11-27 23:14:02 +00001353 {
1354 printf ("aggregate test %u\n", i);
1355 aggregate_test (&aggregate_tests[i++]);
1356 }
paul1f377b02005-09-10 18:00:11 +00001357
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001358 i = 0;
1359
1360 while (reconcile_tests[i].test1)
Paul Jakma50ef5652010-11-27 23:14:02 +00001361 {
1362 printf ("reconcile test %u\n", i);
1363 as4_reconcile_test (&reconcile_tests[i++]);
1364 }
Paul Jakma0b2aa3a2007-10-14 22:32:21 +00001365
1366 i = 0;
1367
paul1f377b02005-09-10 18:00:11 +00001368 cmp_test();
1369
1370 i = 0;
1371
1372 empty_get_test();
1373
Paul Jakma50ef5652010-11-27 23:14:02 +00001374 i = 0;
1375
1376 while (aspath_tests[i].desc)
1377 {
1378 printf ("aspath_attr test %d\n", i);
1379 attr_test (&aspath_tests[i++]);
1380 }
1381
paul1f377b02005-09-10 18:00:11 +00001382 printf ("failures: %d\n", failed);
1383 printf ("aspath count: %ld\n", aspath_count());
1384
1385 return (failed + aspath_count());
1386}