]>
git.proxmox.com Git - mirror_frr.git/blob - tests/aspath_test.c
2 * Copyright (C) 2005 Sun Microsystems, Inc.
4 * This file is part of Quagga.
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
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.
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
30 #include "bgpd/bgpd.h"
31 #include "bgpd/bgp_aspath.h"
32 #include "bgpd/bgp_attr.h"
34 #define VT100_RESET "\x1b[0m"
35 #define VT100_RED "\x1b[31m"
36 #define VT100_GREEN "\x1b[32m"
37 #define VT100_YELLOW "\x1b[33m"
38 #define OK VT100_GREEN "OK" VT100_RESET
39 #define FAILED VT100_RED "failed" VT100_RESET
41 /* need these to link in libbgp */
42 struct zebra_privs_t
*bgpd_privs
= NULL
;
43 struct thread_master
*master
= NULL
;
45 static int failed
= 0;
47 /* specification for a test - what the results should be */
50 const char *shouldbe
; /* the string the path should parse to */
51 const char *shouldbe_delete_confed
; /* ditto, but once confeds are deleted */
52 const unsigned int hops
; /* aspath_count_hops result */
53 const unsigned int confeds
; /* aspath_count_confeds */
54 const int private_as
; /* whether the private_as check should pass or fail */
55 #define NOT_ALL_PRIVATE 0
57 const as_t does_loop
; /* an ASN which should trigger loop-check */
58 const as_t doesnt_loop
; /* one which should not */
59 const as_t first
; /* the first ASN, if there is one */
64 /* test segments to parse and validate, and use for other tests */
65 static struct test_segment
{
68 const u_char asdata
[1024];
75 "seq(8466,3,52737,4096)",
76 { 0x2,0x4, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00 },
78 { "8466 3 52737 4096",
80 4, 0, NOT_ALL_PRIVATE
, 4096, 4, 8466 },
90 2, 0, NOT_ALL_PRIVATE
, 4, 5, 8722, },
94 "seq(8466,3,52737,4096,8722,4)",
95 { 0x2,0x6, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00,
96 0x22,0x12, 0x00,0x04},
98 { "8466 3 52737 4096 8722 4",
99 "8466 3 52737 4096 8722 4",
100 6, 0, NOT_ALL_PRIVATE
, 3, 5, 8466 },
104 "seq(8482,51457) set(5204)",
105 { 0x2,0x2, 0x21,0x22, 0xc9,0x01,
106 0x1,0x1, 0x14,0x54 },
108 { "8482 51457 {5204}",
110 3, 0, NOT_ALL_PRIVATE
, 5204, 51456, 8482},
114 "seq(8467, 59649) set(4196,48658) set(17322,30745)",
115 { 0x2,0x2, 0x21,0x13, 0xe9,0x01,
116 0x1,0x2, 0x10,0x64, 0xbe,0x12,
117 0x1,0x2, 0x43,0xaa, 0x78,0x19 },
119 { "8467 59649 {4196,48658} {17322,30745}",
120 "8467 59649 {4196,48658} {17322,30745}",
121 4, 0, NOT_ALL_PRIVATE
, 48658, 1, 8467},
125 "seq(6435,59408,21665) set(2457,61697,4369), seq(1842,41590,51793)",
126 { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
127 0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11,
128 0x2,0x3, 0x07,0x32, 0xa2,0x76, 0xca,0x51 },
130 { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
131 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
132 7, 0, NOT_ALL_PRIVATE
, 51793, 1, 6435 },
136 "confseq(123,456,789)",
137 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15 },
141 0, 3, NOT_ALL_PRIVATE
, 789, 1, NULL_ASN
},
145 "confseq(123,456,789) confseq(111,222)",
146 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
147 0x3,0x2, 0x00,0x6f, 0x00,0xde },
149 { "(123 456 789) (111 222)",
151 0, 5, NOT_ALL_PRIVATE
, 111, 1, NULL_ASN
},
155 "confset(456,123,789)",
156 { 0x4,0x3, 0x01,0xc8, 0x00,0x7b, 0x03,0x15 },
160 0, 1, NOT_ALL_PRIVATE
, 123, 1, NULL_ASN
},
164 "confseq(123,456,789) confset(222,111) seq(8722) set(4196,48658)",
165 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
166 0x4,0x2, 0x00,0xde, 0x00,0x6f,
168 0x1,0x2, 0x10,0x64, 0xbe,0x12 },
170 { "(123 456 789) [111,222] 8722 {4196,48658}",
172 2, 4, NOT_ALL_PRIVATE
, 123, 1, NULL_ASN
},
176 "seq(8466,2,52737,4096,8722,4)",
177 { 0x2,0x6, 0x21,0x12, 0x00,0x02, 0xce,0x01, 0x10,0x00,
178 0x22,0x12, 0x00,0x04},
180 { "8466 2 52737 4096 8722 4",
181 "8466 2 52737 4096 8722 4",
182 6, 0, NOT_ALL_PRIVATE
, 4096, 1, 8466 },
186 "seq(8466,2,52737) seq(4096,8722,4) seq(8722)",
187 { 0x2,0x3, 0x21,0x12, 0x00,0x02, 0xce,0x01,
188 0x2,0x3, 0x10,0x00, 0x22,0x12, 0x00,0x04,
191 { "8466 2 52737 4096 8722 4 8722",
192 "8466 2 52737 4096 8722 4 8722",
193 7, 0, NOT_ALL_PRIVATE
, 4096, 1, 8466 },
197 "seq(8466,64512,52737,65535)",
198 { 0x2,0x4, 0x21,0x12, 0xfc,0x00, 0xce,0x01, 0xff,0xff },
200 { "8466 64512 52737 65535",
201 "8466 64512 52737 65535",
202 4, 0, NOT_ALL_PRIVATE
, 65535, 4, 8466 },
206 "seq(65534,64512,64513,65535)",
207 { 0x2,0x4, 0xff,0xfe, 0xfc,0x00, 0xfc,0x01, 0xff,0xff },
209 { "65534 64512 64513 65535",
210 "65534 64512 64513 65535",
211 4, 0, ALL_PRIVATE
, 65534, 4, 65534 },
215 "seq(8466,3,52737,4096,34285,<repeated 49 more times>)",
216 { 0x2,0xfa, 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 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed,
265 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x85,0xed, },
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 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
291 "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 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
317 "8466 3 52737 4096 34285 8466 3 52737 4096 34285",
318 250, 0, NOT_ALL_PRIVATE
, 4096, 4, 8466 },
322 "seq(8466,3,52737,4096,3456)",
323 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 },
325 { "8466 3 52737 4096 3456",
326 "8466 3 52737 4096 3456",
327 5, 0, NOT_ALL_PRIVATE
, 4096, 4, 8466 },
334 { "", "", 0, 0, 0, 0, 0, 0 },
338 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)",
339 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80,
340 0x1,0x4, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9 },
343 /* We shouldn't ever /generate/ such paths. However, we should
344 * cope with them fine.
346 "8466 3 52737 4096 3456 {7099,8153}",
347 "8466 3 52737 4096 3456 {7099,8153}",
348 6, 0, NOT_ALL_PRIVATE
, 4096, 4, 8466 },
351 "reconcile_lead_asp",
352 "seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)",
353 { 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
354 0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
355 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 },
357 { "6435 59408 21665 {23456} 23456 23456 23456",
358 "6435 59408 21665 {23456} 23456 23456 23456",
359 7, 0, NOT_ALL_PRIVATE
, 23456, 1, 6435 },
363 "set(2457,61697,4369), seq(1842,41591,51793)",
365 0x1,0x3, 0x09,0x99, 0xf1,0x01, 0x11,0x11,
366 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51 },
368 { "{2457,4369,61697} 1842 41591 51793",
369 "{2457,4369,61697} 1842 41591 51793",
370 4, 0, NOT_ALL_PRIVATE
, 51793, 1, 2457 },
374 "confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665)"
375 " set(23456,23456,23456), seq(23456,23456,23456)",
376 { 0x3,0x3, 0x00,0x7b, 0x01,0xc8, 0x03,0x15,
377 0x4,0x3, 0x01,0xc8, 0x00,0x7c, 0x03,0x14,
378 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1,
379 0x1,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
380 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0 },
382 { "(123 456 789) [124,456,788] 6435 59408 21665"
383 " {23456} 23456 23456 23456",
384 "6435 59408 21665 {23456} 23456 23456 23456",
385 7, 4, NOT_ALL_PRIVATE
, 23456, 1, 6435 },
388 "reconcile_start_trans",
389 "seq(23456,23456,23456) seq(6435,59408,21665)",
390 { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
391 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, },
393 { "23456 23456 23456 6435 59408 21665",
394 "23456 23456 23456 6435 59408 21665",
395 6, 0, NOT_ALL_PRIVATE
, 21665, 1, 23456 },
398 "reconcile_start_trans4",
399 "seq(1842,41591,51793) seq(6435,59408,21665)",
400 { 0x2,0x3, 0x07,0x32, 0xa2,0x77, 0xca,0x51,
401 0x2,0x3, 0x19,0x23, 0xe8,0x10, 0x54,0xa1, },
403 { "1842 41591 51793 6435 59408 21665",
404 "1842 41591 51793 6435 59408 21665",
405 6, 0, NOT_ALL_PRIVATE
, 41591, 1, 1842 },
408 "reconcile_start_trans_error",
409 "seq(23456,23456,23456) seq(6435,59408)",
410 { 0x2,0x3, 0x5b,0xa0, 0x5b,0xa0, 0x5b,0xa0,
411 0x2,0x2, 0x19,0x23, 0xe8,0x10, },
413 { "23456 23456 23456 6435 59408",
414 "23456 23456 23456 6435 59408",
415 5, 0, NOT_ALL_PRIVATE
, 59408, 1, 23456 },
419 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)",
420 { 0x2,0x5, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80,
421 0x1,0x5, 0x1b,0xbb, 0x1f,0xd9, 0x1f,0xd9, 0x1f,0xd9, 0x1b,0xbb,},
424 /* We should weed out duplicate set members. */
425 "8466 3 52737 4096 3456 {7099,8153}",
426 "8466 3 52737 4096 3456 {7099,8153}",
427 6, 0, NOT_ALL_PRIVATE
, 4096, 4, 8466 },
430 "zero-size overflow",
431 "#ASNs = 0, data = seq(8466 3 52737 4096 3456)",
432 { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01, 0x10,0x00, 0x0d,0x80 },
438 "zero-size overflow + valid segment",
439 "seq(#AS=0:8466 3 52737),seq(4096 3456)",
440 { 0x2,0x0, 0x21,0x12, 0x00,0x03, 0xce,0x01,
441 0x2,0x2, 0x10,0x00, 0x0d,0x80 },
448 "invalid segment type",
450 { 0x8,0x2, 0x10,0x00, 0x0d,0x80 },
455 }, { NULL
, NULL
, {0}, 0, { NULL
, 0, 0 } }
458 #define COMMON_ATTRS \
459 BGP_ATTR_FLAG_TRANS, \
463 BGP_ATTR_FLAG_TRANS, \
466 #define COMMON_ATTR_SIZE 11
469 static struct aspath_tests
{
471 const struct test_segment
*segment
;
472 const char *shouldbe
; /* String it should evaluate to */
473 const enum as4
{ AS4_DATA
, AS2_DATA
}
474 as4
; /* whether data should be as4 or not (ie as2) */
475 const int result
; /* expected result for bgp_attr_parse */
476 const int cap
; /* capabilities to set for peer */
477 const char attrheader
[1024];
479 const struct test_segment
*old_segment
;
494 COMMON_ATTR_SIZE
+ 3,
508 COMMON_ATTR_SIZE
+ 3,
522 COMMON_ATTR_SIZE
+ 3,
532 BGP_ATTR_FLAG_TRANS
|BGP_ATTR_FLAG_OPTIONAL
,
536 COMMON_ATTR_SIZE
+ 3,
540 "as4_path, with as2 format data",
546 BGP_ATTR_FLAG_TRANS
|BGP_ATTR_FLAG_OPTIONAL
,
550 COMMON_ATTR_SIZE
+ 3,
554 "as4, with incorrect attr length",
560 BGP_ATTR_FLAG_TRANS
|BGP_ATTR_FLAG_OPTIONAL
,
564 COMMON_ATTR_SIZE
+ 3,
568 "basic 4-byte as-path",
572 PEER_CAP_AS4_RCV
|PEER_CAP_AS4_ADV
,
578 COMMON_ATTR_SIZE
+ 3,
582 "4b AS_PATH: too short",
586 PEER_CAP_AS4_RCV
|PEER_CAP_AS4_ADV
,
592 COMMON_ATTR_SIZE
+ 3,
596 "4b AS_PATH: too long",
600 PEER_CAP_AS4_RCV
|PEER_CAP_AS4_ADV
,
606 COMMON_ATTR_SIZE
+ 3,
610 "4b AS_PATH: too long2",
614 PEER_CAP_AS4_RCV
|PEER_CAP_AS4_ADV
,
620 COMMON_ATTR_SIZE
+ 3,
624 "4b AS_PATH: bad flags",
628 PEER_CAP_AS4_RCV
|PEER_CAP_AS4_ADV
,
630 BGP_ATTR_FLAG_TRANS
|BGP_ATTR_FLAG_OPTIONAL
,
634 COMMON_ATTR_SIZE
+ 3,
638 "4b AS4_PATH w/o AS_PATH",
644 BGP_ATTR_FLAG_TRANS
|BGP_ATTR_FLAG_OPTIONAL
,
648 COMMON_ATTR_SIZE
+ 3,
652 "4b AS4_PATH: confed",
654 "8466 3 52737 4096 (123 456 789)",
658 BGP_ATTR_FLAG_TRANS
|BGP_ATTR_FLAG_OPTIONAL
,
662 COMMON_ATTR_SIZE
+ 3,
665 { NULL
, NULL
, NULL
, 0, 0, 0, { 0 }, 0 },
668 /* prepending tests */
669 static struct tests
{
670 const struct test_segment
*test1
;
671 const struct test_segment
*test2
;
676 { &test_segments
[0], &test_segments
[1],
677 { "8466 3 52737 4096 8722 4",
678 "8466 3 52737 4096 8722 4",
679 6, 0, NOT_ALL_PRIVATE
, 4096, 1, 8466 },
682 { &test_segments
[1], &test_segments
[3],
683 { "8722 4 8482 51457 {5204}",
684 "8722 4 8482 51457 {5204}",
685 5, 0, NOT_ALL_PRIVATE
, 5204, 1, 8722 }
688 { &test_segments
[3], &test_segments
[4],
689 { "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
690 "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
691 7, 0, NOT_ALL_PRIVATE
, 5204, 1, 8482 },
694 { &test_segments
[4], &test_segments
[5],
695 { "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
696 " {2457,4369,61697} 1842 41590 51793",
697 "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665"
698 " {2457,4369,61697} 1842 41590 51793",
699 11, 0, NOT_ALL_PRIVATE
, 61697, 1, 8467 }
702 { &test_segments
[5], &test_segments
[6],
703 { "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
704 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
705 7, 0, NOT_ALL_PRIVATE
, 1842, 1, 6435 },
708 { &test_segments
[6], &test_segments
[7],
709 { "(123 456 789) (123 456 789) (111 222)",
711 0, 8, NOT_ALL_PRIVATE
, 111, 1, 0 }
713 { &test_segments
[7], &test_segments
[8],
714 { "(123 456 789) (111 222) [123,456,789]",
716 0, 6, NOT_ALL_PRIVATE
, 111, 1, 0 }
718 { &test_segments
[8], &test_segments
[9],
719 { "[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
721 2, 5, NOT_ALL_PRIVATE
, 456, 1, NULL_ASN
},
723 { &test_segments
[9], &test_segments
[8],
724 { "(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]",
726 2, 5, NOT_ALL_PRIVATE
, 48658, 1, NULL_ASN
},
728 { &test_segments
[14], &test_segments
[11],
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 3 52737 4096 34285 8466 3 52737 4096 34285 "
753 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
754 "8466 2 52737 4096 8722 4 8722",
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 3 52737 4096 34285 8466 3 52737 4096 34285 "
780 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 "
781 "8466 2 52737 4096 8722 4 8722",
782 257, 0, NOT_ALL_PRIVATE
, 4096, 1000, 8466 },
784 { NULL
, NULL
, { NULL
, 0, 0, 0, 0, 0, 0, } },
787 struct tests reconcile_tests
[] =
789 { &test_segments
[18], &test_segments
[19],
790 { "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
791 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
792 7, 0, NOT_ALL_PRIVATE
, 51793, 1, 6435 },
794 { &test_segments
[19], &test_segments
[18],
795 /* AS_PATH (19) has more hops than NEW_AS_PATH,
796 * so just AS_PATH should be used (though, this practice
799 { "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
800 "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
801 11, 0, NOT_ALL_PRIVATE
, 51793, 1, 6435 },
803 { &test_segments
[20], &test_segments
[19],
804 { "(123 456 789) [124,456,788] 6435 59408 21665"
805 " {2457,4369,61697} 1842 41591 51793",
806 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
807 7, 4, NOT_ALL_PRIVATE
, 51793, 1, 6435 },
809 { &test_segments
[21], &test_segments
[22],
810 { "1842 41591 51793 6435 59408 21665",
811 "1842 41591 51793 6435 59408 21665",
812 6, 0, NOT_ALL_PRIVATE
, 51793, 1, 1842 },
814 { &test_segments
[23], &test_segments
[22],
815 { "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
816 "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
817 11, 0, NOT_ALL_PRIVATE
, 51793, 1, 1842 },
819 { NULL
, NULL
, { NULL
, 0, 0, 0, 0, 0, 0, } },
822 struct tests aggregate_tests
[] =
824 { &test_segments
[0], &test_segments
[2],
825 { "8466 3 52737 4096 {4,8722}",
826 "8466 3 52737 4096 {4,8722}",
827 5, 0, NOT_ALL_PRIVATE
, 4, 1, 8466 },
829 { &test_segments
[2], &test_segments
[0],
830 { "8466 3 52737 4096 {4,8722}",
831 "8466 3 52737 4096 {4,8722}",
832 5, 0, NOT_ALL_PRIVATE
, 8722, 1, 8466 },
834 { &test_segments
[2], &test_segments
[10],
835 { "8466 {2,3,4,4096,8722,52737}",
836 "8466 {2,3,4,4096,8722,52737}",
837 2, 0, NOT_ALL_PRIVATE
, 8722, 5, 8466 },
839 { &test_segments
[10], &test_segments
[2],
840 { "8466 {2,3,4,4096,8722,52737}",
841 "8466 {2,3,4,4096,8722,52737}",
842 2, 0, NOT_ALL_PRIVATE
, 2, 20000, 8466 },
845 { &test_segments
[5], &test_segments
[18],
846 { "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
847 "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
848 4, 0, NOT_ALL_PRIVATE
, 41590, 1, 6435 },
851 { NULL
, NULL
, { NULL
, 0, 0} },
858 #define CMP_RES_YES 1
861 char shouldbe_confed
;
864 { 0, 1, CMP_RES_NO
, CMP_RES_NO
},
865 { 0, 2, CMP_RES_YES
, CMP_RES_NO
},
866 { 0, 11, CMP_RES_YES
, CMP_RES_NO
},
867 { 0, 15, CMP_RES_YES
, CMP_RES_NO
},
868 { 0, 16, CMP_RES_NO
, CMP_RES_NO
},
869 { 1, 11, CMP_RES_NO
, CMP_RES_NO
},
870 { 6, 7, CMP_RES_NO
, CMP_RES_YES
},
871 { 6, 8, CMP_RES_NO
, CMP_RES_NO
},
872 { 7, 8, CMP_RES_NO
, CMP_RES_NO
},
873 { 1, 9, CMP_RES_YES
, CMP_RES_NO
},
874 { 0, 9, CMP_RES_NO
, CMP_RES_NO
},
875 { 3, 9, CMP_RES_NO
, CMP_RES_NO
},
876 { 0, 6, CMP_RES_NO
, CMP_RES_NO
},
877 { 1, 6, CMP_RES_NO
, CMP_RES_NO
},
878 { 0, 8, CMP_RES_NO
, CMP_RES_NO
},
879 { 1, 8, CMP_RES_NO
, CMP_RES_NO
},
880 { 11, 6, CMP_RES_NO
, CMP_RES_NO
},
881 { 11, 7, CMP_RES_NO
, CMP_RES_NO
},
882 { 11, 8, CMP_RES_NO
, CMP_RES_NO
},
883 { 9, 6, CMP_RES_NO
, CMP_RES_YES
},
884 { 9, 7, CMP_RES_NO
, CMP_RES_YES
},
885 { 9, 8, CMP_RES_NO
, CMP_RES_NO
},
888 /* make an aspath from a data stream */
889 static struct aspath
*
890 make_aspath (const u_char
*data
, size_t len
, int use32bit
)
892 struct stream
*s
= NULL
;
897 s
= stream_new (len
);
898 stream_put (s
, data
, len
);
900 as
= aspath_parse (s
, len
, use32bit
);
909 printbytes (const u_char
*bytes
, int len
)
915 printf ("%02hhx%s", bytes
[i
], " ");
917 printf ("0x%02hhx", bytes
[i
]);
923 /* validate the given aspath */
925 validate (struct aspath
*as
, const struct test_spec
*sp
)
927 size_t bytes
, bytes4
;
930 static struct stream
*s
;
931 struct aspath
*asinout
, *asconfeddel
, *asstr
, *as4
;
933 if (as
== NULL
&& sp
->shouldbe
== NULL
)
935 printf ("Correctly failed to parse\n");
939 out
= aspath_snmp_pathseg (as
, &bytes
);
940 asinout
= make_aspath (out
, bytes
, 0);
942 /* Excercise AS4 parsing a bit, with a dogfood test */
944 s
= stream_new (4096);
945 bytes4
= aspath_put (s
, as
, 1);
946 as4
= make_aspath (STREAM_DATA(s
), bytes4
, 1);
948 asstr
= aspath_str2aspath (sp
->shouldbe
);
950 asconfeddel
= aspath_delete_confed_seq (aspath_dup (asinout
));
952 printf ("got: %s\n", aspath_print(as
));
954 /* the parsed path should match the specified 'shouldbe' string.
955 * We should pass the "eat our own dog food" test, be able to output
956 * this path and then input it again. Ie the path resulting from:
958 * aspath_parse(aspath_put(as))
962 * - also match the specified 'shouldbe' value
963 * - hash to same value as original path
964 * - have same hops and confed counts as original, and as the
965 * the specified counts
967 * aspath_str2aspath() and shouldbe should match
969 * We do the same for:
971 * aspath_parse(aspath_put(as,USE32BIT))
973 * Confederation related tests:
974 * - aspath_delete_confed_seq(aspath) should match shouldbe_confed
975 * - aspath_delete_confed_seq should be idempotent.
977 if (strcmp(aspath_print (as
), sp
->shouldbe
)
978 /* hash validation */
979 || (aspath_key_make (as
) != aspath_key_make (asinout
))
981 || strcmp(aspath_print (asinout
), sp
->shouldbe
)
982 /* By 4-byte parsing */
983 || strcmp(aspath_print (as4
), sp
->shouldbe
)
984 /* by various path counts */
985 || (aspath_count_hops (as
) != sp
->hops
)
986 || (aspath_count_confeds (as
) != sp
->confeds
)
987 || (aspath_count_hops (asinout
) != sp
->hops
)
988 || (aspath_count_confeds (asinout
) != sp
->confeds
))
992 printf ("shouldbe:\n%s\n", sp
->shouldbe
);
993 printf ("as4:\n%s\n", aspath_print (as4
));
994 printf ("hash keys: in: %d out->in: %d\n",
995 aspath_key_make (as
), aspath_key_make (asinout
));
996 printf ("hops: %d, counted %d %d\n", sp
->hops
,
997 aspath_count_hops (as
),
998 aspath_count_hops (asinout
) );
999 printf ("confeds: %d, counted %d %d\n", sp
->confeds
,
1000 aspath_count_confeds (as
),
1001 aspath_count_confeds (asinout
));
1002 printf ("out->in:\n%s\nbytes: ", aspath_print(asinout
));
1003 printbytes (out
, bytes
);
1005 /* basic confed related tests */
1006 if ((aspath_print (asconfeddel
) == NULL
1007 && sp
->shouldbe_delete_confed
!= NULL
)
1008 || (aspath_print (asconfeddel
) != NULL
1009 && sp
->shouldbe_delete_confed
== NULL
)
1010 || strcmp(aspath_print (asconfeddel
), sp
->shouldbe_delete_confed
)
1011 /* delete_confed_seq should be idempotent */
1012 || (aspath_key_make (asconfeddel
)
1013 != aspath_key_make (aspath_delete_confed_seq (asconfeddel
))))
1017 printf ("as-path minus confeds is: %s\n", aspath_print (asconfeddel
));
1018 printf ("as-path minus confeds should be: %s\n", sp
->shouldbe_delete_confed
);
1020 /* aspath_str2aspath test */
1021 if ((aspath_print (asstr
) == NULL
&& sp
->shouldbe
!= NULL
)
1022 || (aspath_print (asstr
) != NULL
&& sp
->shouldbe
== NULL
)
1023 || strcmp(aspath_print (asstr
), sp
->shouldbe
))
1027 printf ("asstr: %s\n", aspath_print (asstr
));
1030 /* loop, private and first as checks */
1031 if ((sp
->does_loop
&& aspath_loop_check (as
, sp
->does_loop
) == 0)
1032 || (sp
->doesnt_loop
&& aspath_loop_check (as
, sp
->doesnt_loop
) != 0)
1033 || (aspath_private_as_check (as
) != sp
->private_as
)
1034 || (aspath_firstas_check (as
,sp
->first
)
1039 printf ("firstas: %d, got %d\n", sp
->first
,
1040 aspath_firstas_check (as
,sp
->first
));
1041 printf ("loop does: %d %d, doesnt: %d %d\n",
1042 sp
->does_loop
, aspath_loop_check (as
, sp
->does_loop
),
1043 sp
->doesnt_loop
, aspath_loop_check (as
, sp
->doesnt_loop
));
1044 printf ("private check: %d %d\n", sp
->private_as
,
1045 aspath_private_as_check (as
));
1047 aspath_unintern (&asinout
);
1048 aspath_unintern (&as4
);
1050 aspath_free (asconfeddel
);
1051 aspath_free (asstr
);
1060 struct aspath
*as
= aspath_empty_get ();
1061 struct test_spec sp
= { "", "", 0, 0, 0, 0, 0, 0 };
1063 printf ("empty_get_test, as: %s\n",aspath_print (as
));
1064 if (!validate (as
, &sp
))
1065 printf ("%s\n", OK
);
1067 printf ("%s!\n", FAILED
);
1074 /* basic parsing test */
1076 parse_test (struct test_segment
*t
)
1080 printf ("%s: %s\n", t
->name
, t
->desc
);
1082 asp
= make_aspath (t
->asdata
, t
->len
, 0);
1084 printf ("aspath: %s\nvalidating...:\n", aspath_print (asp
));
1086 if (!validate (asp
, &t
->sp
))
1089 printf (FAILED
"\n");
1094 aspath_unintern (&asp
);
1097 /* prepend testing */
1099 prepend_test (struct tests
*t
)
1101 struct aspath
*asp1
, *asp2
, *ascratch
;
1103 printf ("prepend %s: %s\n", t
->test1
->name
, t
->test1
->desc
);
1104 printf ("to %s: %s\n", t
->test2
->name
, t
->test2
->desc
);
1106 asp1
= make_aspath (t
->test1
->asdata
, t
->test1
->len
, 0);
1107 asp2
= make_aspath (t
->test2
->asdata
, t
->test2
->len
, 0);
1109 ascratch
= aspath_dup (asp2
);
1110 aspath_unintern (&asp2
);
1112 asp2
= aspath_prepend (asp1
, ascratch
);
1114 printf ("aspath: %s\n", aspath_print (asp2
));
1116 if (!validate (asp2
, &t
->sp
))
1117 printf ("%s\n", OK
);
1119 printf ("%s!\n", FAILED
);
1122 aspath_unintern (&asp1
);
1126 /* empty-prepend testing */
1128 empty_prepend_test (struct test_segment
*t
)
1130 struct aspath
*asp1
, *asp2
, *ascratch
;
1132 printf ("empty prepend %s: %s\n", t
->name
, t
->desc
);
1134 asp1
= make_aspath (t
->asdata
, t
->len
, 0);
1135 asp2
= aspath_empty ();
1137 ascratch
= aspath_dup (asp2
);
1138 aspath_unintern (&asp2
);
1140 asp2
= aspath_prepend (asp1
, ascratch
);
1142 printf ("aspath: %s\n", aspath_print (asp2
));
1144 if (!validate (asp2
, &t
->sp
))
1147 printf (FAILED
"!\n");
1151 aspath_unintern (&asp1
);
1155 /* as2+as4 reconciliation testing */
1157 as4_reconcile_test (struct tests
*t
)
1159 struct aspath
*asp1
, *asp2
, *ascratch
;
1161 printf ("reconciling %s:\n %s\n", t
->test1
->name
, t
->test1
->desc
);
1162 printf ("with %s:\n %s\n", t
->test2
->name
, t
->test2
->desc
);
1164 asp1
= make_aspath (t
->test1
->asdata
, t
->test1
->len
, 0);
1165 asp2
= make_aspath (t
->test2
->asdata
, t
->test2
->len
, 0);
1167 ascratch
= aspath_reconcile_as4 (asp1
, asp2
);
1169 if (!validate (ascratch
, &t
->sp
))
1172 printf (FAILED
"!\n");
1175 aspath_unintern (&asp1
);
1176 aspath_unintern (&asp2
);
1177 aspath_free (ascratch
);
1181 /* aggregation testing */
1183 aggregate_test (struct tests
*t
)
1185 struct aspath
*asp1
, *asp2
, *ascratch
;
1187 printf ("aggregate %s: %s\n", t
->test1
->name
, t
->test1
->desc
);
1188 printf ("with %s: %s\n", t
->test2
->name
, t
->test2
->desc
);
1190 asp1
= make_aspath (t
->test1
->asdata
, t
->test1
->len
, 0);
1191 asp2
= make_aspath (t
->test2
->asdata
, t
->test2
->len
, 0);
1193 ascratch
= aspath_aggregate (asp1
, asp2
);
1195 if (!validate (ascratch
, &t
->sp
))
1198 printf (FAILED
"!\n");
1201 aspath_unintern (&asp1
);
1202 aspath_unintern (&asp2
);
1203 aspath_free (ascratch
);
1204 /* aspath_unintern (ascratch);*/
1207 /* cmp_left tests */
1212 #define CMP_TESTS_MAX \
1213 (sizeof(left_compare) / sizeof (struct compare_tests))
1215 for (i
= 0; i
< CMP_TESTS_MAX
; i
++)
1217 struct test_segment
*t1
= &test_segments
[left_compare
[i
].test_index1
];
1218 struct test_segment
*t2
= &test_segments
[left_compare
[i
].test_index2
];
1219 struct aspath
*asp1
, *asp2
;
1221 printf ("left cmp %s: %s\n", t1
->name
, t1
->desc
);
1222 printf ("and %s: %s\n", t2
->name
, t2
->desc
);
1224 asp1
= make_aspath (t1
->asdata
, t1
->len
, 0);
1225 asp2
= make_aspath (t2
->asdata
, t2
->len
, 0);
1227 if (aspath_cmp_left (asp1
, asp2
) != left_compare
[i
].shouldbe_cmp
1228 || aspath_cmp_left (asp2
, asp1
) != left_compare
[i
].shouldbe_cmp
1229 || aspath_cmp_left_confed (asp1
, asp2
)
1230 != left_compare
[i
].shouldbe_confed
1231 || aspath_cmp_left_confed (asp2
, asp1
)
1232 != left_compare
[i
].shouldbe_confed
)
1235 printf (FAILED
"\n");
1236 printf ("result should be: cmp: %d, confed: %d\n",
1237 left_compare
[i
].shouldbe_cmp
,
1238 left_compare
[i
].shouldbe_confed
);
1239 printf ("got: cmp %d, cmp_confed: %d\n",
1240 aspath_cmp_left (asp1
, asp2
),
1241 aspath_cmp_left_confed (asp1
, asp2
));
1242 printf("path1: %s\npath2: %s\n", aspath_print (asp1
),
1243 aspath_print (asp2
));
1249 aspath_unintern (&asp1
);
1250 aspath_unintern (&asp2
);
1255 handle_attr_test (struct aspath_tests
*t
)
1257 struct bgp bgp
= { 0 };
1258 struct peer peer
= { 0 };
1259 struct attr attr
= { 0 };
1261 int initfail
= failed
;
1265 asp
= make_aspath (t
->segment
->asdata
, t
->segment
->len
, 0);
1267 peer
.ibuf
= stream_new (BGP_MAX_PACKET_SIZE
);
1268 peer
.obuf
= stream_fifo_new ();
1270 peer
.host
= (char *)"none";
1274 stream_write (peer
.ibuf
, t
->attrheader
, t
->len
);
1275 datalen
= aspath_put (peer
.ibuf
, asp
, t
->as4
== AS4_DATA
);
1278 char dummyaspath
[] = { BGP_ATTR_FLAG_TRANS
, BGP_ATTR_AS_PATH
,
1279 t
->old_segment
->len
};
1280 stream_write (peer
.ibuf
, dummyaspath
, sizeof (dummyaspath
));
1281 stream_write (peer
.ibuf
, t
->old_segment
->asdata
, t
->old_segment
->len
);
1282 datalen
+= sizeof (dummyaspath
) + t
->old_segment
->len
;
1285 ret
= bgp_attr_parse (&peer
, &attr
, t
->len
+ datalen
, NULL
, NULL
);
1287 if (ret
!= t
->result
)
1289 printf ("bgp_attr_parse returned %d, expected %d\n", ret
, t
->result
);
1290 printf ("datalen %zd\n", datalen
);
1296 if (t
->shouldbe
&& attr
.aspath
== NULL
)
1298 printf ("aspath is NULL, but should be: %s\n", t
->shouldbe
);
1301 if (t
->shouldbe
&& attr
.aspath
&& strcmp (attr
.aspath
->str
, t
->shouldbe
))
1303 printf ("attr str and 'shouldbe' mismatched!\n"
1306 attr
.aspath
->str
, t
->shouldbe
);
1309 if (!t
->shouldbe
&& attr
.aspath
)
1311 printf ("aspath should be NULL, but is: %s\n", attr
.aspath
->str
);
1317 aspath_unintern (&attr
.aspath
);
1319 aspath_unintern (&asp
);
1320 return failed
- initfail
;
1324 attr_test (struct aspath_tests
*t
)
1326 printf ("%s\n", t
->desc
);
1327 printf ("%s\n\n", handle_attr_test (t
) ? FAILED
: OK
);
1335 master
= bm
->master
;
1336 bgp_option_set (BGP_OPT_NO_LISTEN
);
1339 while (test_segments
[i
].name
)
1341 printf ("test %u\n", i
);
1342 parse_test (&test_segments
[i
]);
1343 empty_prepend_test (&test_segments
[i
++]);
1347 while (prepend_tests
[i
].test1
)
1349 printf ("prepend test %u\n", i
);
1350 prepend_test (&prepend_tests
[i
++]);
1354 while (aggregate_tests
[i
].test1
)
1356 printf ("aggregate test %u\n", i
);
1357 aggregate_test (&aggregate_tests
[i
++]);
1362 while (reconcile_tests
[i
].test1
)
1364 printf ("reconcile test %u\n", i
);
1365 as4_reconcile_test (&reconcile_tests
[i
++]);
1378 while (aspath_tests
[i
].desc
)
1380 printf ("aspath_attr test %d\n", i
);
1381 attr_test (&aspath_tests
[i
++]);
1384 printf ("failures: %d\n", failed
);
1385 printf ("aspath count: %ld\n", aspath_count());
1387 return (failed
+ aspath_count());