1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2005 Sun Microsystems, Inc.
13 #include "frr_pthread.h"
15 #include "bgpd/bgpd.c"
16 #include "bgpd/bgp_aspath.h"
17 #include "bgpd/bgp_attr.h"
18 #include "bgpd/bgp_packet.h"
20 #define VT100_RESET "\x1b[0m"
21 #define VT100_RED "\x1b[31m"
22 #define VT100_GREEN "\x1b[32m"
23 #define VT100_YELLOW "\x1b[33m"
24 #define OK VT100_GREEN "OK" VT100_RESET
25 #define FAILED VT100_RED "failed" VT100_RESET
27 /* need these to link in libbgp */
28 struct zebra_privs_t bgpd_privs
= {};
29 struct thread_master
*master
= NULL
;
31 static int failed
= 0;
33 /* specification for a test - what the results should be */
35 const char *shouldbe
; /* the string the path should parse to */
36 const char *shouldbe_delete_confed
; /* ditto, but once confeds are
38 const unsigned int hops
; /* aspath_count_hops result */
39 const unsigned int confeds
; /* aspath_count_confeds */
40 const int private_as
; /* whether the private_as check should pass or
42 #define NOT_ALL_PRIVATE 0
44 const as_t does_loop
; /* an ASN which should trigger loop-check */
45 const as_t doesnt_loop
; /* one which should not */
46 const as_t first
; /* the first ASN, if there is one */
51 /* test segments to parse and validate, and use for other tests */
52 static struct test_segment
{
55 const uint8_t asdata
[1024];
58 enum asnotation_mode asnotation
;
63 "seq(8466,3,52737,4096)",
64 {0x2, 0x4, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00},
66 {"8466 3 52737 4096", "8466 3 52737 4096", 4, 0,
67 NOT_ALL_PRIVATE
, 4096, 4, 8466},
74 {0x2, 0x1, 0x22, 0x12, 0x2, 0x1, 0x00, 0x04},
91 "seq(8466,3,52737,4096,8722,4)",
92 {0x2, 0x6, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x22,
95 {"8466 3 52737 4096 8722 4", "8466 3 52737 4096 8722 4", 6, 0,
96 NOT_ALL_PRIVATE
, 3, 5, 8466},
102 "seq(8482,51457) set(5204)",
103 {0x2, 0x2, 0x21, 0x22, 0xc9, 0x01, 0x1, 0x1, 0x14, 0x54},
105 {"8482 51457 {5204}", "8482 51457 {5204}", 3, 0,
106 NOT_ALL_PRIVATE
, 5204, 51456, 8482},
112 "seq(8467, 59649) set(4196,48658) set(17322,30745)",
113 {0x2, 0x2, 0x21, 0x13, 0xe9, 0x01, 0x1, 0x2, 0x10, 0x64, 0xbe,
114 0x12, 0x1, 0x2, 0x43, 0xaa, 0x78, 0x19},
116 {"8467 59649 {4196,48658} {17322,30745}",
117 "8467 59649 {4196,48658} {17322,30745}", 4, 0, NOT_ALL_PRIVATE
,
124 "seq(6435,59408,21665) set(2457,61697,4369), seq(1842,41590,51793)",
125 {0x2, 0x3, 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1,
126 0x1, 0x3, 0x09, 0x99, 0xf1, 0x01, 0x11, 0x11,
127 0x2, 0x3, 0x07, 0x32, 0xa2, 0x76, 0xca, 0x51},
129 {"6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
130 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", 7, 0,
131 NOT_ALL_PRIVATE
, 51793, 1, 6435},
137 "confseq(123,456,789)",
138 {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15},
140 {"(123 456 789)", "", 0, 3, NOT_ALL_PRIVATE
, 789, 1, NULL_ASN
},
146 "confseq(123,456,789) confseq(111,222)",
147 {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, 0x3, 0x2, 0x00,
150 {"(123 456 789) (111 222)", "", 0, 5, NOT_ALL_PRIVATE
, 111, 1,
157 "confset(456,123,789)",
158 {0x4, 0x3, 0x01, 0xc8, 0x00, 0x7b, 0x03, 0x15},
160 {"[123,456,789]", "", 0, 1, NOT_ALL_PRIVATE
, 123, 1, NULL_ASN
},
166 "confseq(123,456,789) confset(222,111) seq(8722) set(4196,48658)",
167 {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15,
168 0x4, 0x2, 0x00, 0xde, 0x00, 0x6f, 0x2, 0x1,
169 0x22, 0x12, 0x1, 0x2, 0x10, 0x64, 0xbe, 0x12},
171 {"(123 456 789) [111,222] 8722 {4196,48658}",
172 "8722 {4196,48658}", 2, 4, NOT_ALL_PRIVATE
, 123, 1, NULL_ASN
},
178 "seq(8466,2,52737,4096,8722,4)",
179 {0x2, 0x6, 0x21, 0x12, 0x00, 0x02, 0xce, 0x01, 0x10, 0x00, 0x22,
182 {"8466 2 52737 4096 8722 4", "8466 2 52737 4096 8722 4", 6, 0,
183 NOT_ALL_PRIVATE
, 4096, 1, 8466},
189 "seq(8466,2,52737) seq(4096,8722,4) seq(8722)",
190 {0x2, 0x3, 0x21, 0x12, 0x00, 0x02, 0xce, 0x01, 0x2, 0x3,
191 0x10, 0x00, 0x22, 0x12, 0x00, 0x04, 0x2, 0x1, 0x22, 0x12},
193 {"8466 2 52737 4096 8722 4 8722",
194 "8466 2 52737 4096 8722 4 8722", 7, 0, NOT_ALL_PRIVATE
, 4096,
201 "seq(8466,64512,52737,65535)",
202 {0x2, 0x4, 0x21, 0x12, 0xfc, 0x00, 0xce, 0x01, 0xff, 0xff},
204 {"8466 64512 52737 65535", "8466 64512 52737 65535", 4, 0,
205 NOT_ALL_PRIVATE
, 65535, 4, 8466},
211 "seq(65534,64512,64513,65535)",
212 {0x2, 0x4, 0xff, 0xfe, 0xfc, 0x00, 0xfc, 0x01, 0xff, 0xff},
214 {"65534 64512 64513 65535", "65534 64512 64513 65535", 4, 0,
215 ALL_PRIVATE
, 65534, 4, 65534},
221 "seq(8466,3,52737,4096,34285,<repeated 49 more times>)",
223 0x2, 0xfa, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
224 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
225 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
226 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
227 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
228 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
229 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
230 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
231 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
232 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
233 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
234 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
235 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
236 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
237 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
238 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
239 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
240 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
241 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
242 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
243 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
244 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
245 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
246 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
247 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
248 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
249 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
250 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
251 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
252 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
253 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
254 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
255 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
256 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
257 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
258 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
259 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
260 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
261 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
262 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
263 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
264 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
265 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
266 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
267 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
268 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
269 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
270 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
271 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
272 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
273 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
274 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
275 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
276 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
277 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
278 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
281 {"8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285",
283 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285",
284 250, 0, NOT_ALL_PRIVATE
, 4096, 4, 8466},
290 "seq(8466,3,52737,4096,3456)",
291 {0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x0d,
294 {"8466 3 52737 4096 3456", "8466 3 52737 4096 3456", 5, 0,
295 NOT_ALL_PRIVATE
, 4096, 4, 8466},
304 {"", "", 0, 0, 0, 0, 0, 0},
310 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)",
311 {0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
312 0x10, 0x00, 0x0d, 0x80, 0x1, 0x4, 0x1b, 0xbb,
313 0x1f, 0xd9, 0x1f, 0xd9, 0x1f, 0xd9},
315 {/* We shouldn't ever /generate/ such paths. However, we should
316 * cope with them fine.
318 "8466 3 52737 4096 3456 {7099,8153}",
319 "8466 3 52737 4096 3456 {7099,8153}", 6, 0, NOT_ALL_PRIVATE
,
325 "reconcile_lead_asp",
326 "seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)",
327 {0x2, 0x3, 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1,
328 0x1, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0,
329 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0},
331 {"6435 59408 21665 {23456} 23456 23456 23456",
332 "6435 59408 21665 {23456} 23456 23456 23456", 7, 0,
333 NOT_ALL_PRIVATE
, 23456, 1, 6435},
339 "set(2457,61697,4369), seq(1842,41591,51793)",
340 {0x1, 0x3, 0x09, 0x99, 0xf1, 0x01, 0x11, 0x11, 0x2, 0x3, 0x07,
341 0x32, 0xa2, 0x77, 0xca, 0x51},
343 {"{2457,4369,61697} 1842 41591 51793",
344 "{2457,4369,61697} 1842 41591 51793", 4, 0, NOT_ALL_PRIVATE
,
351 "confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)",
352 {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, 0x4, 0x3,
353 0x01, 0xc8, 0x00, 0x7c, 0x03, 0x14, 0x2, 0x3, 0x19, 0x23,
354 0xe8, 0x10, 0x54, 0xa1, 0x1, 0x3, 0x5b, 0xa0, 0x5b, 0xa0,
355 0x5b, 0xa0, 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0},
357 {"(123 456 789) [124,456,788] 6435 59408 21665 {23456} 23456 23456 23456",
358 "6435 59408 21665 {23456} 23456 23456 23456", 7, 4,
359 NOT_ALL_PRIVATE
, 23456, 1, 6435},
364 "reconcile_start_trans",
365 "seq(23456,23456,23456) seq(6435,59408,21665)",
385 {"23456 23456 23456 6435 59408 21665",
386 "23456 23456 23456 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE
,
392 "reconcile_start_trans4",
393 "seq(1842,41591,51793) seq(6435,59408,21665)",
413 {"1842 41591 51793 6435 59408 21665",
414 "1842 41591 51793 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE
,
420 "reconcile_start_trans_error",
421 "seq(23456,23456,23456) seq(6435,59408)",
439 {"23456 23456 23456 6435 59408", "23456 23456 23456 6435 59408",
440 5, 0, NOT_ALL_PRIVATE
, 59408, 1, 23456},
446 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)",
448 0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
449 0x10, 0x00, 0x0d, 0x80, 0x1, 0x5, 0x1b, 0xbb,
450 0x1f, 0xd9, 0x1f, 0xd9, 0x1f, 0xd9, 0x1b, 0xbb,
453 {/* We should weed out duplicate set members. */
454 "8466 3 52737 4096 3456 {7099,8153}",
455 "8466 3 52737 4096 3456 {7099,8153}", 6, 0, NOT_ALL_PRIVATE
,
461 "zero-size overflow",
462 "#ASNs = 0, data = seq(8466 3 52737 4096 3456)",
463 {0x2, 0x0, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x0d,
466 {NULL
, NULL
, 0, 0, 0, 0, 0, 0},
471 "zero-size overflow + valid segment",
472 "seq(#AS=0:8466 3 52737),seq(4096 3456)",
473 {0x2, 0x0, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x2, 0x2, 0x10,
476 {NULL
, NULL
, 0, 0, 0, 0, 0, 0},
481 "invalid segment type",
483 {0x8, 0x2, 0x10, 0x00, 0x0d, 0x80},
485 {NULL
, NULL
, 0, 0, 0, 0, 0, 0},
491 "seq(8466,3,52737,0,4096)",
492 {0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x00, 0x00, 0x10,
495 {"8466 3 52737 0 4096", "8466 3 52737 0 4096", 5, 0,
496 NOT_ALL_PRIVATE
, 4096, 4, 8466},
502 "seq(0.8466,0.3,0.52737,0.4096,0.8722,0.4)",
503 {0x2, 0x6, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x22,
506 {"0.8466 0.3 0.52737 0.4096 0.8722 0.4",
507 "0.8466 0.3 0.52737 0.4096 0.8722 0.4", 6, 0, NOT_ALL_PRIVATE
,
514 "confseq(0.123,0.456,0.789) confset(0.222,0.111) seq(0.8722) set(0.4196,0.48658)",
515 {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15,
516 0x4, 0x2, 0x00, 0xde, 0x00, 0x6f, 0x2, 0x1,
517 0x22, 0x12, 0x1, 0x2, 0x10, 0x64, 0xbe, 0x12},
519 {"(0.123 0.456 0.789) [0.111,0.222] 0.8722 {0.4196,0.48658}",
520 "0.8722 {0.4196,0.48658}", 2, 4, NOT_ALL_PRIVATE
, 123, 1,
526 "someprivate asdot+",
527 "seq(0.8466,0.64512,0.52737,0.65535)",
528 {0x2, 0x4, 0x21, 0x12, 0xfc, 0x00, 0xce, 0x01, 0xff, 0xff},
530 {"0.8466 0.64512 0.52737 0.65535",
531 "0.8466 0.64512 0.52737 0.65535", 4, 0, NOT_ALL_PRIVATE
, 65535,
537 "BGP_AS_ZERO asdot+",
538 "seq(0.8466,0.3,0.52737,0.0,0.4096)",
539 {0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x00, 0x00, 0x10,
542 {"0.8466 0.3 0.52737 0.0 0.4096",
543 "0.8466 0.3 0.52737 0.0 0.4096", 5, 0, NOT_ALL_PRIVATE
, 4096,
547 {NULL
, NULL
, {0}, 0, {NULL
, 0, 0}}};
549 #define COMMON_ATTRS \
550 BGP_ATTR_FLAG_TRANS, BGP_ATTR_ORIGIN, 1, BGP_ORIGIN_EGP, \
551 BGP_ATTR_FLAG_TRANS, BGP_ATTR_NEXT_HOP, 4, 192, 0, 2, 0
552 #define COMMON_ATTR_SIZE 11
555 static struct aspath_tests
{
557 const struct test_segment
*segment
;
558 const char *shouldbe
; /* String it should evaluate to */
562 } as4
; /* whether data should be as4 or not (ie as2) */
563 const int result
; /* expected result for bgp_attr_parse */
564 const int cap
; /* capabilities to set for peer */
565 const char attrheader
[1024];
567 const struct test_segment
*old_segment
;
583 COMMON_ATTR_SIZE
+ 3,
599 COMMON_ATTR_SIZE
+ 3,
615 COMMON_ATTR_SIZE
+ 3,
627 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
631 COMMON_ATTR_SIZE
+ 3,
635 "as4_path, with as2 format data",
643 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
647 COMMON_ATTR_SIZE
+ 3,
651 "as4, with incorrect attr length",
659 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
663 COMMON_ATTR_SIZE
+ 3,
667 "basic 4-byte as-path",
672 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
679 COMMON_ATTR_SIZE
+ 3,
683 "4b AS_PATH: too short",
688 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
695 COMMON_ATTR_SIZE
+ 3,
699 "4b AS_PATH: too long",
704 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
711 COMMON_ATTR_SIZE
+ 3,
715 "4b AS_PATH: too long2",
720 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
727 COMMON_ATTR_SIZE
+ 3,
731 "4b AS_PATH: bad flags",
736 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
739 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
743 COMMON_ATTR_SIZE
+ 3,
747 "4b AS4_PATH w/o AS_PATH",
755 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
759 COMMON_ATTR_SIZE
+ 3,
763 "4b AS4_PATH: confed",
765 "8466 3 52737 4096 (123 456 789)",
771 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
775 COMMON_ATTR_SIZE
+ 3,
780 "4b AS4_PATH: BGP_AS_ZERO",
782 "8466 3 52737 0 4096",
785 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
788 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
792 COMMON_ATTR_SIZE
+ 3,
794 {NULL
, NULL
, NULL
, 0, 0, 0, {0}, 0},
797 /* prepending tests */
798 static struct tests
{
799 const struct test_segment
*test1
;
800 const struct test_segment
*test2
;
802 } prepend_tests
[] = {
807 {"8466 3 52737 4096 8722 4", "8466 3 52737 4096 8722 4", 6, 0,
808 NOT_ALL_PRIVATE
, 4096, 1, 8466},
813 {"8722 4 8482 51457 {5204}", "8722 4 8482 51457 {5204}", 5, 0,
814 NOT_ALL_PRIVATE
, 5204, 1, 8722}},
819 {"8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
820 "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", 7,
821 0, NOT_ALL_PRIVATE
, 5204, 1, 8482},
826 {"8467 59649 {4196,48658} {17322,30745} 6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
827 "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
828 11, 0, NOT_ALL_PRIVATE
, 61697, 1, 8467}},
833 {"6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
834 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", 7, 0,
835 NOT_ALL_PRIVATE
, 1842, 1, 6435},
840 {"(123 456 789) (123 456 789) (111 222)", "", 0, 8, NOT_ALL_PRIVATE
,
844 {"(123 456 789) (111 222) [123,456,789]", "", 0, 6, NOT_ALL_PRIVATE
,
849 {"[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
850 "8722 {4196,48658}", 2, 5, NOT_ALL_PRIVATE
, 456, 1, NULL_ASN
},
855 {"(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]",
856 "8722 {4196,48658}", 2, 5, NOT_ALL_PRIVATE
, 48658, 1,
862 {"8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 2 52737 4096 8722 4 8722",
864 "8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 3 52737 4096 34285 8466 2 52737 4096 8722 4 8722",
865 257, 0, NOT_ALL_PRIVATE
, 4096, 1000, 8466},
870 NULL
, 0, 0, 0, 0, 0, 0,
874 struct tests reconcile_tests
[] = {
878 {"6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
879 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", 7, 0,
880 NOT_ALL_PRIVATE
, 51793, 1, 6435},
885 /* AS_PATH (19) has more hops than NEW_AS_PATH,
886 * so just AS_PATH should be used (though, this practice
889 {"{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
890 "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
891 11, 0, NOT_ALL_PRIVATE
, 51793, 1, 6435},
896 {"(123 456 789) [124,456,788] 6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
897 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", 7, 4,
898 NOT_ALL_PRIVATE
, 51793, 1, 6435},
903 {"1842 41591 51793 6435 59408 21665",
904 "1842 41591 51793 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE
,
910 {"23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
911 "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
912 11, 0, NOT_ALL_PRIVATE
, 51793, 1, 1842},
917 NULL
, 0, 0, 0, 0, 0, 0,
921 struct tests aggregate_tests
[] = {
925 {"8466 3 52737 4096 {4,8722}", "8466 3 52737 4096 {4,8722}", 5,
926 0, NOT_ALL_PRIVATE
, 4, 1, 8466},
931 {"8466 3 52737 4096 {4,8722}", "8466 3 52737 4096 {4,8722}", 5,
932 0, NOT_ALL_PRIVATE
, 8722, 1, 8466},
937 {"8466 {2,3,4,4096,8722,52737}", "8466 {2,3,4,4096,8722,52737}",
938 2, 0, NOT_ALL_PRIVATE
, 8722, 5, 8466},
943 {"8466 {2,3,4,4096,8722,52737}", "8466 {2,3,4,4096,8722,52737}",
944 2, 0, NOT_ALL_PRIVATE
, 2, 20000, 8466},
950 {"6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
951 "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", 4,
952 0, NOT_ALL_PRIVATE
, 41590, 1, 6435},
955 {NULL
, NULL
, {NULL
, 0, 0}},
958 struct compare_tests
{
961 #define CMP_RES_YES 1
964 char shouldbe_confed
;
966 {0, 1, CMP_RES_NO
, CMP_RES_NO
}, {0, 2, CMP_RES_YES
, CMP_RES_NO
},
967 {0, 11, CMP_RES_YES
, CMP_RES_NO
}, {0, 15, CMP_RES_YES
, CMP_RES_NO
},
968 {0, 16, CMP_RES_NO
, CMP_RES_NO
}, {1, 11, CMP_RES_NO
, CMP_RES_NO
},
969 {6, 7, CMP_RES_NO
, CMP_RES_YES
}, {6, 8, CMP_RES_NO
, CMP_RES_NO
},
970 {7, 8, CMP_RES_NO
, CMP_RES_NO
}, {1, 9, CMP_RES_YES
, CMP_RES_NO
},
971 {0, 9, CMP_RES_NO
, CMP_RES_NO
}, {3, 9, CMP_RES_NO
, CMP_RES_NO
},
972 {0, 6, CMP_RES_NO
, CMP_RES_NO
}, {1, 6, CMP_RES_NO
, CMP_RES_NO
},
973 {0, 8, CMP_RES_NO
, CMP_RES_NO
}, {1, 8, CMP_RES_NO
, CMP_RES_NO
},
974 {11, 6, CMP_RES_NO
, CMP_RES_NO
}, {11, 7, CMP_RES_NO
, CMP_RES_NO
},
975 {11, 8, CMP_RES_NO
, CMP_RES_NO
}, {9, 6, CMP_RES_NO
, CMP_RES_YES
},
976 {9, 7, CMP_RES_NO
, CMP_RES_YES
}, {9, 8, CMP_RES_NO
, CMP_RES_NO
},
979 /* make an aspath from a data stream */
980 static struct aspath
*make_aspath(const uint8_t *data
, size_t len
, int use32bit
,
981 enum asnotation_mode asnotation
)
983 struct stream
*s
= NULL
;
987 stream_put(s
, data
, len
);
989 as
= aspath_parse(s
, len
, use32bit
, asnotation
);
997 static void printbytes(const uint8_t *bytes
, int len
)
1002 printf("%02hhx%s", bytes
[i
], " ");
1004 printf("0x%02hhx", bytes
[i
]);
1010 /* validate the given aspath */
1011 static int validate(struct aspath
*as
, const struct test_spec
*sp
)
1013 size_t bytes
, bytes4
;
1016 static struct stream
*s
;
1017 struct aspath
*asinout
, *asconfeddel
, *asstr
, *as4
;
1019 if (as
== NULL
&& sp
->shouldbe
== NULL
) {
1020 printf("Correctly failed to parse\n");
1024 out
= aspath_snmp_pathseg(as
, &bytes
);
1025 asinout
= make_aspath(out
, bytes
, 0, as
->asnotation
);
1026 /* Excercise AS4 parsing a bit, with a dogfood test */
1028 s
= stream_new(BGP_MAX_PACKET_SIZE
);
1029 bytes4
= aspath_put(s
, as
, 1);
1030 as4
= make_aspath(STREAM_DATA(s
), bytes4
, 1, as
->asnotation
);
1032 asn_relax_as_zero(true);
1033 asstr
= aspath_str2aspath(sp
->shouldbe
, as
->asnotation
);
1034 asn_relax_as_zero(false);
1036 asconfeddel
= aspath_delete_confed_seq(aspath_dup(asinout
));
1038 printf("got: %s\n", aspath_print(as
));
1040 /* the parsed path should match the specified 'shouldbe' string.
1041 * We should pass the "eat our own dog food" test, be able to output
1042 * this path and then input it again. Ie the path resulting from:
1044 * aspath_parse(aspath_put(as))
1048 * - also match the specified 'shouldbe' value
1049 * - hash to same value as original path
1050 * - have same hops and confed counts as original, and as the
1051 * the specified counts
1053 * aspath_str2aspath() and shouldbe should match
1055 * We do the same for:
1057 * aspath_parse(aspath_put(as,USE32BIT))
1059 * Confederation related tests:
1060 * - aspath_delete_confed_seq(aspath) should match shouldbe_confed
1061 * - aspath_delete_confed_seq should be idempotent.
1063 if (strcmp(aspath_print(as
), sp
->shouldbe
)
1064 /* hash validation */
1065 || (aspath_key_make(as
) != aspath_key_make(asinout
))
1067 || strcmp(aspath_print(asinout
), sp
->shouldbe
)
1068 /* By 4-byte parsing */
1069 || strcmp(aspath_print(as4
), sp
->shouldbe
)
1070 /* by various path counts */
1071 || (aspath_count_hops(as
) != sp
->hops
)
1072 || (aspath_count_confeds(as
) != sp
->confeds
)
1073 || (aspath_count_hops(asinout
) != sp
->hops
)
1074 || (aspath_count_confeds(asinout
) != sp
->confeds
)) {
1077 printf("shouldbe:\n%s\n", sp
->shouldbe
);
1078 printf("as4:\n%s\n", aspath_print(as4
));
1079 printf("hash keys: in: %d out->in: %d\n", aspath_key_make(as
),
1080 aspath_key_make(asinout
));
1081 printf("hops: %d, counted %d %d\n", sp
->hops
,
1082 aspath_count_hops(as
), aspath_count_hops(asinout
));
1083 printf("confeds: %d, counted %d %d\n", sp
->confeds
,
1084 aspath_count_confeds(as
), aspath_count_confeds(asinout
));
1085 printf("out->in:\n%s\nbytes: ", aspath_print(asinout
));
1086 printbytes(out
, bytes
);
1088 /* basic confed related tests */
1089 if ((aspath_print(asconfeddel
) == NULL
1090 && sp
->shouldbe_delete_confed
!= NULL
)
1091 || (aspath_print(asconfeddel
) != NULL
1092 && sp
->shouldbe_delete_confed
== NULL
)
1093 || strcmp(aspath_print(asconfeddel
), sp
->shouldbe_delete_confed
)
1094 /* delete_confed_seq should be idempotent */
1095 || (aspath_key_make(asconfeddel
)
1096 != aspath_key_make(aspath_delete_confed_seq(asconfeddel
)))) {
1099 printf("as-path minus confeds is: %s\n",
1100 aspath_print(asconfeddel
));
1101 printf("as-path minus confeds should be: %s\n",
1102 sp
->shouldbe_delete_confed
);
1104 /* aspath_str2aspath test */
1105 if ((aspath_print(asstr
) == NULL
&& sp
->shouldbe
!= NULL
)
1106 || (aspath_print(asstr
) != NULL
&& sp
->shouldbe
== NULL
)
1107 || strcmp(aspath_print(asstr
), sp
->shouldbe
)) {
1110 printf("asstr: %s\n", aspath_print(asstr
));
1113 /* loop, private and first as checks */
1114 if ((sp
->does_loop
&& aspath_loop_check(as
, sp
->does_loop
) == 0)
1115 || (sp
->doesnt_loop
&& aspath_loop_check(as
, sp
->doesnt_loop
) != 0)
1116 || (aspath_private_as_check(as
) != sp
->private_as
)
1117 || (aspath_firstas_check(as
, sp
->first
) && sp
->first
== 0)) {
1120 printf("firstas: %d, got %d\n", sp
->first
,
1121 aspath_firstas_check(as
, sp
->first
));
1122 printf("loop does: %d %d, doesn't: %d %d\n", sp
->does_loop
,
1123 aspath_loop_check(as
, sp
->does_loop
), sp
->doesnt_loop
,
1124 aspath_loop_check(as
, sp
->doesnt_loop
));
1125 printf("private check: %d %d\n", sp
->private_as
,
1126 aspath_private_as_check(as
));
1128 aspath_unintern(&asinout
);
1129 aspath_unintern(&as4
);
1131 aspath_free(asconfeddel
);
1138 static void empty_get_test(void)
1140 struct aspath
*as
= aspath_empty_get();
1141 struct test_spec sp
= {"", "", 0, 0, 0, 0, 0, 0};
1143 printf("empty_get_test, as: %s\n", aspath_print(as
));
1144 if (!validate(as
, &sp
))
1147 printf("%s!\n", FAILED
);
1154 /* basic parsing test */
1155 static void parse_test(struct test_segment
*t
)
1159 printf("%s: %s\n", t
->name
, t
->desc
);
1161 asp
= make_aspath(t
->asdata
, t
->len
, 0, t
->asnotation
);
1163 printf("aspath: %s\nvalidating...:\n", aspath_print(asp
));
1165 if (!validate(asp
, &t
->sp
))
1168 printf(FAILED
"\n");
1172 aspath_unintern(&asp
);
1175 /* prepend testing */
1176 static void prepend_test(struct tests
*t
)
1178 struct aspath
*asp1
, *asp2
, *ascratch
;
1180 printf("prepend %s: %s\n", t
->test1
->name
, t
->test1
->desc
);
1181 printf("to %s: %s\n", t
->test2
->name
, t
->test2
->desc
);
1183 asp1
= make_aspath(t
->test1
->asdata
, t
->test1
->len
, 0,
1185 asp2
= make_aspath(t
->test2
->asdata
, t
->test2
->len
, 0,
1188 ascratch
= aspath_dup(asp2
);
1189 aspath_unintern(&asp2
);
1191 asp2
= aspath_prepend(asp1
, ascratch
);
1193 printf("aspath: %s\n", aspath_print(asp2
));
1195 if (!validate(asp2
, &t
->sp
))
1198 printf("%s!\n", FAILED
);
1201 aspath_unintern(&asp1
);
1205 /* empty-prepend testing */
1206 static void empty_prepend_test(struct test_segment
*t
)
1208 struct aspath
*asp1
, *asp2
, *ascratch
;
1210 printf("empty prepend %s: %s\n", t
->name
, t
->desc
);
1212 asp1
= make_aspath(t
->asdata
, t
->len
, 0, t
->asnotation
);
1213 asp2
= aspath_empty(t
->asnotation
);
1215 ascratch
= aspath_dup(asp2
);
1216 aspath_unintern(&asp2
);
1218 asp2
= aspath_prepend(asp1
, ascratch
);
1220 printf("aspath: %s\n", aspath_print(asp2
));
1222 if (!validate(asp2
, &t
->sp
))
1225 printf(FAILED
"!\n");
1228 aspath_unintern(&asp1
);
1232 /* as2+as4 reconciliation testing */
1233 static void as4_reconcile_test(struct tests
*t
)
1235 struct aspath
*asp1
, *asp2
, *ascratch
;
1237 printf("reconciling %s:\n %s\n", t
->test1
->name
, t
->test1
->desc
);
1238 printf("with %s:\n %s\n", t
->test2
->name
, t
->test2
->desc
);
1240 asp1
= make_aspath(t
->test1
->asdata
, t
->test1
->len
, 0,
1242 asp2
= make_aspath(t
->test2
->asdata
, t
->test2
->len
, 0,
1245 ascratch
= aspath_reconcile_as4(asp1
, asp2
);
1247 if (!validate(ascratch
, &t
->sp
))
1250 printf(FAILED
"!\n");
1253 aspath_unintern(&asp1
);
1254 aspath_unintern(&asp2
);
1255 aspath_free(ascratch
);
1259 /* aggregation testing */
1260 static void aggregate_test(struct tests
*t
)
1262 struct aspath
*asp1
, *asp2
, *ascratch
;
1264 printf("aggregate %s: %s\n", t
->test1
->name
, t
->test1
->desc
);
1265 printf("with %s: %s\n", t
->test2
->name
, t
->test2
->desc
);
1267 asp1
= make_aspath(t
->test1
->asdata
, t
->test1
->len
, 0,
1269 asp2
= make_aspath(t
->test2
->asdata
, t
->test2
->len
, 0,
1272 ascratch
= aspath_aggregate(asp1
, asp2
);
1274 if (!validate(ascratch
, &t
->sp
))
1277 printf(FAILED
"!\n");
1280 aspath_unintern(&asp1
);
1281 aspath_unintern(&asp2
);
1282 aspath_free(ascratch
);
1283 /* aspath_unintern (ascratch);*/
1286 /* cmp_left tests */
1287 static void cmp_test(void)
1290 #define CMP_TESTS_MAX (sizeof(left_compare) / sizeof(struct compare_tests))
1292 for (i
= 0; i
< CMP_TESTS_MAX
; i
++) {
1293 struct test_segment
*t1
=
1294 &test_segments
[left_compare
[i
].test_index1
];
1295 struct test_segment
*t2
=
1296 &test_segments
[left_compare
[i
].test_index2
];
1297 struct aspath
*asp1
, *asp2
;
1299 printf("left cmp %s: %s\n", t1
->name
, t1
->desc
);
1300 printf("and %s: %s\n", t2
->name
, t2
->desc
);
1302 asp1
= make_aspath(t1
->asdata
, t1
->len
, 0, ASNOTATION_PLAIN
);
1303 asp2
= make_aspath(t2
->asdata
, t2
->len
, 0, ASNOTATION_PLAIN
);
1305 if (aspath_cmp_left(asp1
, asp2
) != left_compare
[i
].shouldbe_cmp
1306 || aspath_cmp_left(asp2
, asp1
)
1307 != left_compare
[i
].shouldbe_cmp
1308 || aspath_cmp_left_confed(asp1
, asp2
)
1309 != left_compare
[i
].shouldbe_confed
1310 || aspath_cmp_left_confed(asp2
, asp1
)
1311 != left_compare
[i
].shouldbe_confed
) {
1313 printf(FAILED
"\n");
1314 printf("result should be: cmp: %d, confed: %d\n",
1315 left_compare
[i
].shouldbe_cmp
,
1316 left_compare
[i
].shouldbe_confed
);
1317 printf("got: cmp %d, cmp_confed: %d\n",
1318 aspath_cmp_left(asp1
, asp2
),
1319 aspath_cmp_left_confed(asp1
, asp2
));
1320 printf("path1: %s\npath2: %s\n", aspath_print(asp1
),
1321 aspath_print(asp2
));
1326 aspath_unintern(&asp1
);
1327 aspath_unintern(&asp2
);
1331 static int handle_attr_test(struct aspath_tests
*t
)
1333 struct bgp bgp
= {0};
1334 struct peer peer
= {0};
1335 struct attr attr
= {0};
1337 int initfail
= failed
;
1341 asp
= make_aspath(t
->segment
->asdata
, t
->segment
->len
, 0,
1342 t
->segment
->asnotation
);
1343 bgp
.asnotation
= t
->segment
->asnotation
;
1345 peer
.curr
= stream_new(BGP_MAX_PACKET_SIZE
);
1346 peer
.obuf
= stream_fifo_new();
1348 peer
.host
= (char *)"none";
1351 peer
.max_packet_size
= BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE
;
1353 stream_write(peer
.curr
, t
->attrheader
, t
->len
);
1354 datalen
= aspath_put(peer
.curr
, asp
, t
->as4
== AS4_DATA
);
1355 if (t
->old_segment
) {
1356 char dummyaspath
[] = {BGP_ATTR_FLAG_TRANS
, BGP_ATTR_AS_PATH
,
1357 t
->old_segment
->len
};
1358 stream_write(peer
.curr
, dummyaspath
, sizeof(dummyaspath
));
1359 stream_write(peer
.curr
, t
->old_segment
->asdata
,
1360 t
->old_segment
->len
);
1361 datalen
+= sizeof(dummyaspath
) + t
->old_segment
->len
;
1364 ret
= bgp_attr_parse(&peer
, &attr
, t
->len
+ datalen
, NULL
, NULL
);
1366 if (ret
!= t
->result
) {
1367 printf("bgp_attr_parse returned %d, expected %d\n", ret
,
1369 printf("datalen %zd\n", datalen
);
1375 if (t
->shouldbe
&& attr
.aspath
== NULL
) {
1376 printf("aspath is NULL, but should be: %s\n", t
->shouldbe
);
1379 if (t
->shouldbe
&& attr
.aspath
1380 && strcmp(attr
.aspath
->str
, t
->shouldbe
)) {
1381 printf("attr str and 'shouldbe' mismatched!\n"
1384 attr
.aspath
->str
, t
->shouldbe
);
1387 if (!t
->shouldbe
&& attr
.aspath
) {
1388 printf("aspath should be NULL, but is: %s\n", attr
.aspath
->str
);
1393 aspath_unintern(&attr
.aspath
);
1394 aspath_unintern(&asp
);
1395 return failed
- initfail
;
1398 static void attr_test(struct aspath_tests
*t
)
1400 printf("%s\n", t
->desc
);
1401 printf("%s\n\n", handle_attr_test(t
) ? FAILED
: OK
);
1408 bgp_master_init(thread_master_create(NULL
), BGP_SOCKET_SNDBUF_SIZE
,
1410 master
= bm
->master
;
1411 bgp_option_set(BGP_OPT_NO_LISTEN
);
1414 while (test_segments
[i
].name
) {
1415 printf("test %u\n", i
);
1416 parse_test(&test_segments
[i
]);
1417 empty_prepend_test(&test_segments
[i
++]);
1421 while (prepend_tests
[i
].test1
) {
1422 printf("prepend test %u\n", i
);
1423 prepend_test(&prepend_tests
[i
++]);
1427 while (aggregate_tests
[i
].test1
) {
1428 printf("aggregate test %u\n", i
);
1429 aggregate_test(&aggregate_tests
[i
++]);
1434 while (reconcile_tests
[i
].test1
) {
1435 printf("reconcile test %u\n", i
);
1436 as4_reconcile_test(&reconcile_tests
[i
++]);
1450 bgp_pthreads_init();
1451 bgp_pth_ka
->running
= true;
1453 while (aspath_tests
[i
].desc
) {
1454 printf("aspath_attr test %d\n", i
);
1455 attr_test(&aspath_tests
[i
++]);
1458 printf("failures: %d\n", failed
);
1459 printf("aspath count: %ld\n", aspath_count());
1461 return (failed
+ aspath_count());