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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "frr_pthread.h"
30 #include "bgpd/bgpd.c"
31 #include "bgpd/bgp_aspath.h"
32 #include "bgpd/bgp_attr.h"
33 #include "bgpd/bgp_packet.h"
35 #define VT100_RESET "\x1b[0m"
36 #define VT100_RED "\x1b[31m"
37 #define VT100_GREEN "\x1b[32m"
38 #define VT100_YELLOW "\x1b[33m"
39 #define OK VT100_GREEN "OK" VT100_RESET
40 #define FAILED VT100_RED "failed" VT100_RESET
42 /* need these to link in libbgp */
43 struct zebra_privs_t bgpd_privs
= {};
44 struct thread_master
*master
= NULL
;
46 static int failed
= 0;
48 /* 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
53 const unsigned int hops
; /* aspath_count_hops result */
54 const unsigned int confeds
; /* aspath_count_confeds */
55 const int private_as
; /* whether the private_as check should pass or
57 #define NOT_ALL_PRIVATE 0
59 const as_t does_loop
; /* an ASN which should trigger loop-check */
60 const as_t doesnt_loop
; /* one which should not */
61 const as_t first
; /* the first ASN, if there is one */
66 /* test segments to parse and validate, and use for other tests */
67 static struct test_segment
{
70 const uint8_t asdata
[1024];
77 "seq(8466,3,52737,4096)",
78 {0x2, 0x4, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00},
80 {"8466 3 52737 4096", "8466 3 52737 4096", 4, 0,
81 NOT_ALL_PRIVATE
, 4096, 4, 8466},
87 {0x2, 0x1, 0x22, 0x12, 0x2, 0x1, 0x00, 0x04},
90 "8722 4", "8722 4", 2, 0, NOT_ALL_PRIVATE
, 4, 5, 8722,
96 "seq(8466,3,52737,4096,8722,4)",
97 {0x2, 0x6, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x22,
100 {"8466 3 52737 4096 8722 4", "8466 3 52737 4096 8722 4", 6, 0,
101 NOT_ALL_PRIVATE
, 3, 5, 8466},
106 "seq(8482,51457) set(5204)",
107 {0x2, 0x2, 0x21, 0x22, 0xc9, 0x01, 0x1, 0x1, 0x14, 0x54},
109 {"8482 51457 {5204}", "8482 51457 {5204}", 3, 0,
110 NOT_ALL_PRIVATE
, 5204, 51456, 8482},
115 "seq(8467, 59649) set(4196,48658) set(17322,30745)",
116 {0x2, 0x2, 0x21, 0x13, 0xe9, 0x01, 0x1, 0x2, 0x10, 0x64, 0xbe,
117 0x12, 0x1, 0x2, 0x43, 0xaa, 0x78, 0x19},
119 {"8467 59649 {4196,48658} {17322,30745}",
120 "8467 59649 {4196,48658} {17322,30745}", 4, 0, NOT_ALL_PRIVATE
,
126 "seq(6435,59408,21665) set(2457,61697,4369), seq(1842,41590,51793)",
127 {0x2, 0x3, 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1,
128 0x1, 0x3, 0x09, 0x99, 0xf1, 0x01, 0x11, 0x11,
129 0x2, 0x3, 0x07, 0x32, 0xa2, 0x76, 0xca, 0x51},
131 {"6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
132 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", 7, 0,
133 NOT_ALL_PRIVATE
, 51793, 1, 6435},
138 "confseq(123,456,789)",
139 {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15},
141 {"(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,
156 "confset(456,123,789)",
157 {0x4, 0x3, 0x01, 0xc8, 0x00, 0x7b, 0x03, 0x15},
159 {"[123,456,789]", "", 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, 0x2, 0x1,
167 0x22, 0x12, 0x1, 0x2, 0x10, 0x64, 0xbe, 0x12},
169 {"(123 456 789) [111,222] 8722 {4196,48658}",
170 "8722 {4196,48658}", 2, 4, NOT_ALL_PRIVATE
, 123, 1, NULL_ASN
},
175 "seq(8466,2,52737,4096,8722,4)",
176 {0x2, 0x6, 0x21, 0x12, 0x00, 0x02, 0xce, 0x01, 0x10, 0x00, 0x22,
179 {"8466 2 52737 4096 8722 4", "8466 2 52737 4096 8722 4", 6, 0,
180 NOT_ALL_PRIVATE
, 4096, 1, 8466},
185 "seq(8466,2,52737) seq(4096,8722,4) seq(8722)",
186 {0x2, 0x3, 0x21, 0x12, 0x00, 0x02, 0xce, 0x01, 0x2, 0x3,
187 0x10, 0x00, 0x22, 0x12, 0x00, 0x04, 0x2, 0x1, 0x22, 0x12},
189 {"8466 2 52737 4096 8722 4 8722",
190 "8466 2 52737 4096 8722 4 8722", 7, 0, NOT_ALL_PRIVATE
, 4096,
196 "seq(8466,64512,52737,65535)",
197 {0x2, 0x4, 0x21, 0x12, 0xfc, 0x00, 0xce, 0x01, 0xff, 0xff},
199 {"8466 64512 52737 65535", "8466 64512 52737 65535", 4, 0,
200 NOT_ALL_PRIVATE
, 65535, 4, 8466},
205 "seq(65534,64512,64513,65535)",
206 {0x2, 0x4, 0xff, 0xfe, 0xfc, 0x00, 0xfc, 0x01, 0xff, 0xff},
208 {"65534 64512 64513 65535", "65534 64512 64513 65535", 4, 0,
209 ALL_PRIVATE
, 65534, 4, 65534},
214 "seq(8466,3,52737,4096,34285,<repeated 49 more times>)",
216 0x2, 0xfa, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
217 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
218 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
219 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
220 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
221 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
222 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
223 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
224 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
225 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
226 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
227 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
228 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
229 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
230 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
231 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
232 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
233 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
234 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
235 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
236 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
237 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
238 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
239 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
240 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
241 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
242 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
243 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
244 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
245 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
246 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
247 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
248 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
249 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
250 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
251 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
252 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
253 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
254 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
255 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
256 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
257 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
258 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
259 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
260 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
261 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12,
262 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21,
263 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
264 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85,
265 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00,
266 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10,
267 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
268 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce,
269 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03,
270 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00,
271 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed,
274 {"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",
276 "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",
277 250, 0, NOT_ALL_PRIVATE
, 4096, 4, 8466},
282 "seq(8466,3,52737,4096,3456)",
283 {0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x0d,
286 {"8466 3 52737 4096 3456", "8466 3 52737 4096 3456", 5, 0,
287 NOT_ALL_PRIVATE
, 4096, 4, 8466},
295 {"", "", 0, 0, 0, 0, 0, 0},
300 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)",
301 {0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
302 0x10, 0x00, 0x0d, 0x80, 0x1, 0x4, 0x1b, 0xbb,
303 0x1f, 0xd9, 0x1f, 0xd9, 0x1f, 0xd9},
305 {/* We shouldn't ever /generate/ such paths. However, we should
306 * cope with them fine.
308 "8466 3 52737 4096 3456 {7099,8153}",
309 "8466 3 52737 4096 3456 {7099,8153}", 6, 0, NOT_ALL_PRIVATE
,
314 "reconcile_lead_asp",
315 "seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)",
316 {0x2, 0x3, 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1,
317 0x1, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0,
318 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0},
320 {"6435 59408 21665 {23456} 23456 23456 23456",
321 "6435 59408 21665 {23456} 23456 23456 23456", 7, 0,
322 NOT_ALL_PRIVATE
, 23456, 1, 6435},
327 "set(2457,61697,4369), seq(1842,41591,51793)",
328 {0x1, 0x3, 0x09, 0x99, 0xf1, 0x01, 0x11, 0x11, 0x2, 0x3, 0x07,
329 0x32, 0xa2, 0x77, 0xca, 0x51},
331 {"{2457,4369,61697} 1842 41591 51793",
332 "{2457,4369,61697} 1842 41591 51793", 4, 0, NOT_ALL_PRIVATE
,
338 "confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)",
339 {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, 0x4, 0x3,
340 0x01, 0xc8, 0x00, 0x7c, 0x03, 0x14, 0x2, 0x3, 0x19, 0x23,
341 0xe8, 0x10, 0x54, 0xa1, 0x1, 0x3, 0x5b, 0xa0, 0x5b, 0xa0,
342 0x5b, 0xa0, 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0},
344 {"(123 456 789) [124,456,788] 6435 59408 21665 {23456} 23456 23456 23456",
345 "6435 59408 21665 {23456} 23456 23456 23456", 7, 4,
346 NOT_ALL_PRIVATE
, 23456, 1, 6435},
350 "reconcile_start_trans",
351 "seq(23456,23456,23456) seq(6435,59408,21665)",
353 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0, 0x2, 0x3,
354 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1,
357 {"23456 23456 23456 6435 59408 21665",
358 "23456 23456 23456 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE
,
363 "reconcile_start_trans4",
364 "seq(1842,41591,51793) seq(6435,59408,21665)",
366 0x2, 0x3, 0x07, 0x32, 0xa2, 0x77, 0xca, 0x51, 0x2, 0x3,
367 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1,
370 {"1842 41591 51793 6435 59408 21665",
371 "1842 41591 51793 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE
,
376 "reconcile_start_trans_error",
377 "seq(23456,23456,23456) seq(6435,59408)",
379 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0, 0x2, 0x2,
380 0x19, 0x23, 0xe8, 0x10,
383 {"23456 23456 23456 6435 59408", "23456 23456 23456 6435 59408",
384 5, 0, NOT_ALL_PRIVATE
, 59408, 1, 23456},
389 "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)",
391 0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01,
392 0x10, 0x00, 0x0d, 0x80, 0x1, 0x5, 0x1b, 0xbb,
393 0x1f, 0xd9, 0x1f, 0xd9, 0x1f, 0xd9, 0x1b, 0xbb,
396 {/* We should weed out duplicate set members. */
397 "8466 3 52737 4096 3456 {7099,8153}",
398 "8466 3 52737 4096 3456 {7099,8153}", 6, 0, NOT_ALL_PRIVATE
,
403 "zero-size overflow",
404 "#ASNs = 0, data = seq(8466 3 52737 4096 3456)",
405 {0x2, 0x0, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x0d,
408 {NULL
, NULL
, 0, 0, 0, 0, 0, 0},
412 "zero-size overflow + valid segment",
413 "seq(#AS=0:8466 3 52737),seq(4096 3456)",
414 {0x2, 0x0, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x2, 0x2, 0x10,
417 {NULL
, NULL
, 0, 0, 0, 0, 0, 0},
421 "invalid segment type",
423 {0x8, 0x2, 0x10, 0x00, 0x0d, 0x80},
425 {NULL
, NULL
, 0, 0, 0, 0, 0, 0},
430 "seq(8466,3,52737,0,4096)",
438 {"8466 3 52737 0 4096", "8466 3 52737 0 4096", 5, 0,
439 NOT_ALL_PRIVATE
, 4096, 4, 8466},
441 {NULL
, NULL
, {0}, 0, {NULL
, 0, 0}}};
443 #define COMMON_ATTRS \
444 BGP_ATTR_FLAG_TRANS, BGP_ATTR_ORIGIN, 1, BGP_ORIGIN_EGP, \
445 BGP_ATTR_FLAG_TRANS, BGP_ATTR_NEXT_HOP, 4, 192, 0, 2, 0
446 #define COMMON_ATTR_SIZE 11
449 static struct aspath_tests
{
451 const struct test_segment
*segment
;
452 const char *shouldbe
; /* String it should evaluate to */
456 } as4
; /* whether data should be as4 or not (ie as2) */
457 const int result
; /* expected result for bgp_attr_parse */
458 const int cap
; /* capabilities to set for peer */
459 const char attrheader
[1024];
461 const struct test_segment
*old_segment
;
477 COMMON_ATTR_SIZE
+ 3,
493 COMMON_ATTR_SIZE
+ 3,
509 COMMON_ATTR_SIZE
+ 3,
521 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
525 COMMON_ATTR_SIZE
+ 3,
529 "as4_path, with as2 format data",
537 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
541 COMMON_ATTR_SIZE
+ 3,
545 "as4, with incorrect attr length",
553 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
557 COMMON_ATTR_SIZE
+ 3,
561 "basic 4-byte as-path",
566 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
573 COMMON_ATTR_SIZE
+ 3,
577 "4b AS_PATH: too short",
582 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
589 COMMON_ATTR_SIZE
+ 3,
593 "4b AS_PATH: too long",
598 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
605 COMMON_ATTR_SIZE
+ 3,
609 "4b AS_PATH: too long2",
614 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
621 COMMON_ATTR_SIZE
+ 3,
625 "4b AS_PATH: bad flags",
630 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
633 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
637 COMMON_ATTR_SIZE
+ 3,
641 "4b AS4_PATH w/o AS_PATH",
649 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
653 COMMON_ATTR_SIZE
+ 3,
657 "4b AS4_PATH: confed",
659 "8466 3 52737 4096 (123 456 789)",
665 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
669 COMMON_ATTR_SIZE
+ 3,
674 "4b AS4_PATH: BGP_AS_ZERO",
676 "8466 3 52737 0 4096",
679 PEER_CAP_AS4_RCV
| PEER_CAP_AS4_ADV
,
682 BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_OPTIONAL
,
686 COMMON_ATTR_SIZE
+ 3,
688 {NULL
, NULL
, NULL
, 0, 0, 0, {0}, 0},
691 /* prepending tests */
692 static struct tests
{
693 const struct test_segment
*test1
;
694 const struct test_segment
*test2
;
696 } prepend_tests
[] = {
701 {"8466 3 52737 4096 8722 4", "8466 3 52737 4096 8722 4", 6, 0,
702 NOT_ALL_PRIVATE
, 4096, 1, 8466},
707 {"8722 4 8482 51457 {5204}", "8722 4 8482 51457 {5204}", 5, 0,
708 NOT_ALL_PRIVATE
, 5204, 1, 8722}},
713 {"8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}",
714 "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", 7,
715 0, NOT_ALL_PRIVATE
, 5204, 1, 8482},
720 {"8467 59649 {4196,48658} {17322,30745} 6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
721 "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
722 11, 0, NOT_ALL_PRIVATE
, 61697, 1, 8467}},
727 {"6435 59408 21665 {2457,4369,61697} 1842 41590 51793",
728 "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", 7, 0,
729 NOT_ALL_PRIVATE
, 1842, 1, 6435},
734 {"(123 456 789) (123 456 789) (111 222)", "", 0, 8, NOT_ALL_PRIVATE
,
738 {"(123 456 789) (111 222) [123,456,789]", "", 0, 6, NOT_ALL_PRIVATE
,
743 {"[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}",
744 "8722 {4196,48658}", 2, 5, NOT_ALL_PRIVATE
, 456, 1, NULL_ASN
},
749 {"(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]",
750 "8722 {4196,48658}", 2, 5, NOT_ALL_PRIVATE
, 48658, 1,
756 {"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",
758 "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",
759 257, 0, NOT_ALL_PRIVATE
, 4096, 1000, 8466},
764 NULL
, 0, 0, 0, 0, 0, 0,
768 struct tests reconcile_tests
[] = {
772 {"6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
773 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", 7, 0,
774 NOT_ALL_PRIVATE
, 51793, 1, 6435},
779 /* AS_PATH (19) has more hops than NEW_AS_PATH,
780 * so just AS_PATH should be used (though, this practice
783 {"{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
784 "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456",
785 11, 0, NOT_ALL_PRIVATE
, 51793, 1, 6435},
790 {"(123 456 789) [124,456,788] 6435 59408 21665 {2457,4369,61697} 1842 41591 51793",
791 "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", 7, 4,
792 NOT_ALL_PRIVATE
, 51793, 1, 6435},
797 {"1842 41591 51793 6435 59408 21665",
798 "1842 41591 51793 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE
,
804 {"23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
805 "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665",
806 11, 0, NOT_ALL_PRIVATE
, 51793, 1, 1842},
811 NULL
, 0, 0, 0, 0, 0, 0,
815 struct tests aggregate_tests
[] = {
819 {"8466 3 52737 4096 {4,8722}", "8466 3 52737 4096 {4,8722}", 5,
820 0, NOT_ALL_PRIVATE
, 4, 1, 8466},
825 {"8466 3 52737 4096 {4,8722}", "8466 3 52737 4096 {4,8722}", 5,
826 0, NOT_ALL_PRIVATE
, 8722, 1, 8466},
831 {"8466 {2,3,4,4096,8722,52737}", "8466 {2,3,4,4096,8722,52737}",
832 2, 0, NOT_ALL_PRIVATE
, 8722, 5, 8466},
837 {"8466 {2,3,4,4096,8722,52737}", "8466 {2,3,4,4096,8722,52737}",
838 2, 0, NOT_ALL_PRIVATE
, 2, 20000, 8466},
844 {"6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}",
845 "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", 4,
846 0, NOT_ALL_PRIVATE
, 41590, 1, 6435},
849 {NULL
, NULL
, {NULL
, 0, 0}},
852 struct compare_tests
{
855 #define CMP_RES_YES 1
858 char shouldbe_confed
;
860 {0, 1, CMP_RES_NO
, CMP_RES_NO
}, {0, 2, CMP_RES_YES
, CMP_RES_NO
},
861 {0, 11, CMP_RES_YES
, CMP_RES_NO
}, {0, 15, CMP_RES_YES
, CMP_RES_NO
},
862 {0, 16, CMP_RES_NO
, CMP_RES_NO
}, {1, 11, CMP_RES_NO
, CMP_RES_NO
},
863 {6, 7, CMP_RES_NO
, CMP_RES_YES
}, {6, 8, CMP_RES_NO
, CMP_RES_NO
},
864 {7, 8, CMP_RES_NO
, CMP_RES_NO
}, {1, 9, CMP_RES_YES
, CMP_RES_NO
},
865 {0, 9, CMP_RES_NO
, CMP_RES_NO
}, {3, 9, CMP_RES_NO
, CMP_RES_NO
},
866 {0, 6, CMP_RES_NO
, CMP_RES_NO
}, {1, 6, CMP_RES_NO
, CMP_RES_NO
},
867 {0, 8, CMP_RES_NO
, CMP_RES_NO
}, {1, 8, CMP_RES_NO
, CMP_RES_NO
},
868 {11, 6, CMP_RES_NO
, CMP_RES_NO
}, {11, 7, CMP_RES_NO
, CMP_RES_NO
},
869 {11, 8, CMP_RES_NO
, CMP_RES_NO
}, {9, 6, CMP_RES_NO
, CMP_RES_YES
},
870 {9, 7, CMP_RES_NO
, CMP_RES_YES
}, {9, 8, CMP_RES_NO
, CMP_RES_NO
},
873 /* make an aspath from a data stream */
874 static struct aspath
*make_aspath(const uint8_t *data
, size_t len
, int use32bit
)
876 struct stream
*s
= NULL
;
881 stream_put(s
, data
, len
);
883 as
= aspath_parse(s
, len
, use32bit
);
891 static void printbytes(const uint8_t *bytes
, int len
)
896 printf("%02hhx%s", bytes
[i
], " ");
898 printf("0x%02hhx", bytes
[i
]);
904 /* validate the given aspath */
905 static int validate(struct aspath
*as
, const struct test_spec
*sp
)
907 size_t bytes
, bytes4
;
910 static struct stream
*s
;
911 struct aspath
*asinout
, *asconfeddel
, *asstr
, *as4
;
913 if (as
== NULL
&& sp
->shouldbe
== NULL
) {
914 printf("Correctly failed to parse\n");
918 out
= aspath_snmp_pathseg(as
, &bytes
);
919 asinout
= make_aspath(out
, bytes
, 0);
921 /* Excercise AS4 parsing a bit, with a dogfood test */
923 s
= stream_new(BGP_MAX_PACKET_SIZE
);
924 bytes4
= aspath_put(s
, as
, 1);
925 as4
= make_aspath(STREAM_DATA(s
), bytes4
, 1);
927 asstr
= aspath_str2aspath(sp
->shouldbe
);
929 asconfeddel
= aspath_delete_confed_seq(aspath_dup(asinout
));
931 printf("got: %s\n", aspath_print(as
));
933 /* the parsed path should match the specified 'shouldbe' string.
934 * We should pass the "eat our own dog food" test, be able to output
935 * this path and then input it again. Ie the path resulting from:
937 * aspath_parse(aspath_put(as))
941 * - also match the specified 'shouldbe' value
942 * - hash to same value as original path
943 * - have same hops and confed counts as original, and as the
944 * the specified counts
946 * aspath_str2aspath() and shouldbe should match
948 * We do the same for:
950 * aspath_parse(aspath_put(as,USE32BIT))
952 * Confederation related tests:
953 * - aspath_delete_confed_seq(aspath) should match shouldbe_confed
954 * - aspath_delete_confed_seq should be idempotent.
956 if (strcmp(aspath_print(as
), sp
->shouldbe
)
957 /* hash validation */
958 || (aspath_key_make(as
) != aspath_key_make(asinout
))
960 || strcmp(aspath_print(asinout
), sp
->shouldbe
)
961 /* By 4-byte parsing */
962 || strcmp(aspath_print(as4
), sp
->shouldbe
)
963 /* by various path counts */
964 || (aspath_count_hops(as
) != sp
->hops
)
965 || (aspath_count_confeds(as
) != sp
->confeds
)
966 || (aspath_count_hops(asinout
) != sp
->hops
)
967 || (aspath_count_confeds(asinout
) != sp
->confeds
)) {
970 printf("shouldbe:\n%s\n", sp
->shouldbe
);
971 printf("as4:\n%s\n", aspath_print(as4
));
972 printf("hash keys: in: %d out->in: %d\n", aspath_key_make(as
),
973 aspath_key_make(asinout
));
974 printf("hops: %d, counted %d %d\n", sp
->hops
,
975 aspath_count_hops(as
), aspath_count_hops(asinout
));
976 printf("confeds: %d, counted %d %d\n", sp
->confeds
,
977 aspath_count_confeds(as
), aspath_count_confeds(asinout
));
978 printf("out->in:\n%s\nbytes: ", aspath_print(asinout
));
979 printbytes(out
, bytes
);
981 /* basic confed related tests */
982 if ((aspath_print(asconfeddel
) == NULL
983 && sp
->shouldbe_delete_confed
!= NULL
)
984 || (aspath_print(asconfeddel
) != NULL
985 && sp
->shouldbe_delete_confed
== NULL
)
986 || strcmp(aspath_print(asconfeddel
), sp
->shouldbe_delete_confed
)
987 /* delete_confed_seq should be idempotent */
988 || (aspath_key_make(asconfeddel
)
989 != aspath_key_make(aspath_delete_confed_seq(asconfeddel
)))) {
992 printf("as-path minus confeds is: %s\n",
993 aspath_print(asconfeddel
));
994 printf("as-path minus confeds should be: %s\n",
995 sp
->shouldbe_delete_confed
);
997 /* aspath_str2aspath test */
998 if ((aspath_print(asstr
) == NULL
&& sp
->shouldbe
!= NULL
)
999 || (aspath_print(asstr
) != NULL
&& sp
->shouldbe
== NULL
)
1000 || strcmp(aspath_print(asstr
), sp
->shouldbe
)) {
1003 printf("asstr: %s\n", aspath_print(asstr
));
1006 /* loop, private and first as checks */
1007 if ((sp
->does_loop
&& aspath_loop_check(as
, sp
->does_loop
) == 0)
1008 || (sp
->doesnt_loop
&& aspath_loop_check(as
, sp
->doesnt_loop
) != 0)
1009 || (aspath_private_as_check(as
) != sp
->private_as
)
1010 || (aspath_firstas_check(as
, sp
->first
) && sp
->first
== 0)) {
1013 printf("firstas: %d, got %d\n", sp
->first
,
1014 aspath_firstas_check(as
, sp
->first
));
1015 printf("loop does: %d %d, doesn't: %d %d\n", sp
->does_loop
,
1016 aspath_loop_check(as
, sp
->does_loop
), sp
->doesnt_loop
,
1017 aspath_loop_check(as
, sp
->doesnt_loop
));
1018 printf("private check: %d %d\n", sp
->private_as
,
1019 aspath_private_as_check(as
));
1021 aspath_unintern(&asinout
);
1022 aspath_unintern(&as4
);
1024 aspath_free(asconfeddel
);
1031 static void empty_get_test(void)
1033 struct aspath
*as
= aspath_empty_get();
1034 struct test_spec sp
= {"", "", 0, 0, 0, 0, 0, 0};
1036 printf("empty_get_test, as: %s\n", aspath_print(as
));
1037 if (!validate(as
, &sp
))
1040 printf("%s!\n", FAILED
);
1047 /* basic parsing test */
1048 static void parse_test(struct test_segment
*t
)
1052 printf("%s: %s\n", t
->name
, t
->desc
);
1054 asp
= make_aspath(t
->asdata
, t
->len
, 0);
1056 printf("aspath: %s\nvalidating...:\n", aspath_print(asp
));
1058 if (!validate(asp
, &t
->sp
))
1061 printf(FAILED
"\n");
1065 aspath_unintern(&asp
);
1068 /* prepend testing */
1069 static void prepend_test(struct tests
*t
)
1071 struct aspath
*asp1
, *asp2
, *ascratch
;
1073 printf("prepend %s: %s\n", t
->test1
->name
, t
->test1
->desc
);
1074 printf("to %s: %s\n", t
->test2
->name
, t
->test2
->desc
);
1076 asp1
= make_aspath(t
->test1
->asdata
, t
->test1
->len
, 0);
1077 asp2
= make_aspath(t
->test2
->asdata
, t
->test2
->len
, 0);
1079 ascratch
= aspath_dup(asp2
);
1080 aspath_unintern(&asp2
);
1082 asp2
= aspath_prepend(asp1
, ascratch
);
1084 printf("aspath: %s\n", aspath_print(asp2
));
1086 if (!validate(asp2
, &t
->sp
))
1089 printf("%s!\n", FAILED
);
1092 aspath_unintern(&asp1
);
1096 /* empty-prepend testing */
1097 static void empty_prepend_test(struct test_segment
*t
)
1099 struct aspath
*asp1
, *asp2
, *ascratch
;
1101 printf("empty prepend %s: %s\n", t
->name
, t
->desc
);
1103 asp1
= make_aspath(t
->asdata
, t
->len
, 0);
1104 asp2
= aspath_empty();
1106 ascratch
= aspath_dup(asp2
);
1107 aspath_unintern(&asp2
);
1109 asp2
= aspath_prepend(asp1
, ascratch
);
1111 printf("aspath: %s\n", aspath_print(asp2
));
1113 if (!validate(asp2
, &t
->sp
))
1116 printf(FAILED
"!\n");
1119 aspath_unintern(&asp1
);
1123 /* as2+as4 reconciliation testing */
1124 static void as4_reconcile_test(struct tests
*t
)
1126 struct aspath
*asp1
, *asp2
, *ascratch
;
1128 printf("reconciling %s:\n %s\n", t
->test1
->name
, t
->test1
->desc
);
1129 printf("with %s:\n %s\n", t
->test2
->name
, t
->test2
->desc
);
1131 asp1
= make_aspath(t
->test1
->asdata
, t
->test1
->len
, 0);
1132 asp2
= make_aspath(t
->test2
->asdata
, t
->test2
->len
, 0);
1134 ascratch
= aspath_reconcile_as4(asp1
, asp2
);
1136 if (!validate(ascratch
, &t
->sp
))
1139 printf(FAILED
"!\n");
1142 aspath_unintern(&asp1
);
1143 aspath_unintern(&asp2
);
1144 aspath_free(ascratch
);
1148 /* aggregation testing */
1149 static void aggregate_test(struct tests
*t
)
1151 struct aspath
*asp1
, *asp2
, *ascratch
;
1153 printf("aggregate %s: %s\n", t
->test1
->name
, t
->test1
->desc
);
1154 printf("with %s: %s\n", t
->test2
->name
, t
->test2
->desc
);
1156 asp1
= make_aspath(t
->test1
->asdata
, t
->test1
->len
, 0);
1157 asp2
= make_aspath(t
->test2
->asdata
, t
->test2
->len
, 0);
1159 ascratch
= aspath_aggregate(asp1
, asp2
);
1161 if (!validate(ascratch
, &t
->sp
))
1164 printf(FAILED
"!\n");
1167 aspath_unintern(&asp1
);
1168 aspath_unintern(&asp2
);
1169 aspath_free(ascratch
);
1170 /* aspath_unintern (ascratch);*/
1173 /* cmp_left tests */
1174 static void cmp_test(void)
1177 #define CMP_TESTS_MAX (sizeof(left_compare) / sizeof(struct compare_tests))
1179 for (i
= 0; i
< CMP_TESTS_MAX
; i
++) {
1180 struct test_segment
*t1
=
1181 &test_segments
[left_compare
[i
].test_index1
];
1182 struct test_segment
*t2
=
1183 &test_segments
[left_compare
[i
].test_index2
];
1184 struct aspath
*asp1
, *asp2
;
1186 printf("left cmp %s: %s\n", t1
->name
, t1
->desc
);
1187 printf("and %s: %s\n", t2
->name
, t2
->desc
);
1189 asp1
= make_aspath(t1
->asdata
, t1
->len
, 0);
1190 asp2
= make_aspath(t2
->asdata
, t2
->len
, 0);
1192 if (aspath_cmp_left(asp1
, asp2
) != left_compare
[i
].shouldbe_cmp
1193 || aspath_cmp_left(asp2
, asp1
)
1194 != left_compare
[i
].shouldbe_cmp
1195 || aspath_cmp_left_confed(asp1
, asp2
)
1196 != left_compare
[i
].shouldbe_confed
1197 || aspath_cmp_left_confed(asp2
, asp1
)
1198 != left_compare
[i
].shouldbe_confed
) {
1200 printf(FAILED
"\n");
1201 printf("result should be: cmp: %d, confed: %d\n",
1202 left_compare
[i
].shouldbe_cmp
,
1203 left_compare
[i
].shouldbe_confed
);
1204 printf("got: cmp %d, cmp_confed: %d\n",
1205 aspath_cmp_left(asp1
, asp2
),
1206 aspath_cmp_left_confed(asp1
, asp2
));
1207 printf("path1: %s\npath2: %s\n", aspath_print(asp1
),
1208 aspath_print(asp2
));
1213 aspath_unintern(&asp1
);
1214 aspath_unintern(&asp2
);
1218 static int handle_attr_test(struct aspath_tests
*t
)
1220 struct bgp bgp
= {0};
1221 struct peer peer
= {0};
1222 struct attr attr
= {0};
1224 int initfail
= failed
;
1228 asp
= make_aspath(t
->segment
->asdata
, t
->segment
->len
, 0);
1230 peer
.curr
= stream_new(BGP_MAX_PACKET_SIZE
);
1231 peer
.obuf
= stream_fifo_new();
1233 peer
.host
= (char *)"none";
1236 peer
.max_packet_size
= BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE
;
1238 stream_write(peer
.curr
, t
->attrheader
, t
->len
);
1239 datalen
= aspath_put(peer
.curr
, asp
, t
->as4
== AS4_DATA
);
1240 if (t
->old_segment
) {
1241 char dummyaspath
[] = {BGP_ATTR_FLAG_TRANS
, BGP_ATTR_AS_PATH
,
1242 t
->old_segment
->len
};
1243 stream_write(peer
.curr
, dummyaspath
, sizeof(dummyaspath
));
1244 stream_write(peer
.curr
, t
->old_segment
->asdata
,
1245 t
->old_segment
->len
);
1246 datalen
+= sizeof(dummyaspath
) + t
->old_segment
->len
;
1249 ret
= bgp_attr_parse(&peer
, &attr
, t
->len
+ datalen
, NULL
, NULL
);
1251 if (ret
!= t
->result
) {
1252 printf("bgp_attr_parse returned %d, expected %d\n", ret
,
1254 printf("datalen %zd\n", datalen
);
1260 if (t
->shouldbe
&& attr
.aspath
== NULL
) {
1261 printf("aspath is NULL, but should be: %s\n", t
->shouldbe
);
1264 if (t
->shouldbe
&& attr
.aspath
1265 && strcmp(attr
.aspath
->str
, t
->shouldbe
)) {
1266 printf("attr str and 'shouldbe' mismatched!\n"
1269 attr
.aspath
->str
, t
->shouldbe
);
1272 if (!t
->shouldbe
&& attr
.aspath
) {
1273 printf("aspath should be NULL, but is: %s\n", attr
.aspath
->str
);
1278 aspath_unintern(&attr
.aspath
);
1279 aspath_unintern(&asp
);
1280 return failed
- initfail
;
1283 static void attr_test(struct aspath_tests
*t
)
1285 printf("%s\n", t
->desc
);
1286 printf("%s\n\n", handle_attr_test(t
) ? FAILED
: OK
);
1293 bgp_master_init(thread_master_create(NULL
), BGP_SOCKET_SNDBUF_SIZE
,
1295 master
= bm
->master
;
1296 bgp_option_set(BGP_OPT_NO_LISTEN
);
1299 while (test_segments
[i
].name
) {
1300 printf("test %u\n", i
);
1301 parse_test(&test_segments
[i
]);
1302 empty_prepend_test(&test_segments
[i
++]);
1306 while (prepend_tests
[i
].test1
) {
1307 printf("prepend test %u\n", i
);
1308 prepend_test(&prepend_tests
[i
++]);
1312 while (aggregate_tests
[i
].test1
) {
1313 printf("aggregate test %u\n", i
);
1314 aggregate_test(&aggregate_tests
[i
++]);
1319 while (reconcile_tests
[i
].test1
) {
1320 printf("reconcile test %u\n", i
);
1321 as4_reconcile_test(&reconcile_tests
[i
++]);
1335 bgp_pthreads_init();
1336 bgp_pth_ka
->running
= true;
1338 while (aspath_tests
[i
].desc
) {
1339 printf("aspath_attr test %d\n", i
);
1340 attr_test(&aspath_tests
[i
++]);
1343 printf("failures: %d\n", failed
);
1344 printf("aspath count: %ld\n", aspath_count());
1346 return (failed
+ aspath_count());