]>
Commit | Line | Data |
---|---|---|
d62a17ae | 1 | /* |
46f4a4d2 PJ |
2 | * Copyright (C) 2005 Sun Microsystems, Inc. |
3 | * | |
4 | * This file is part of Quagga. | |
5 | * | |
6 | * Quagga is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License as published by the | |
8 | * Free Software Foundation; either version 2, or (at your option) any | |
9 | * later version. | |
10 | * | |
11 | * Quagga is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
896014f4 DL |
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 | |
46f4a4d2 PJ |
19 | */ |
20 | ||
1f377b02 | 21 | #include <zebra.h> |
22 | ||
23 | #include "vty.h" | |
24 | #include "stream.h" | |
25 | #include "privs.h" | |
3f9c7369 | 26 | #include "queue.h" |
039f3a34 | 27 | #include "filter.h" |
1f377b02 | 28 | |
29 | #include "bgpd/bgpd.h" | |
30 | #include "bgpd/bgp_aspath.h" | |
50ef565e | 31 | #include "bgpd/bgp_attr.h" |
1f377b02 | 32 | |
0b2aa3a0 PJ |
33 | #define VT100_RESET "\x1b[0m" |
34 | #define VT100_RED "\x1b[31m" | |
35 | #define VT100_GREEN "\x1b[32m" | |
36 | #define VT100_YELLOW "\x1b[33m" | |
37 | #define OK VT100_GREEN "OK" VT100_RESET | |
38 | #define FAILED VT100_RED "failed" VT100_RESET | |
39 | ||
1f377b02 | 40 | /* need these to link in libbgp */ |
41 | struct zebra_privs_t *bgpd_privs = NULL; | |
42 | struct thread_master *master = NULL; | |
43 | ||
44 | static int failed = 0; | |
45 | ||
46 | /* specification for a test - what the results should be */ | |
d62a17ae | 47 | struct test_spec { |
48 | const char *shouldbe; /* the string the path should parse to */ | |
49 | const char *shouldbe_delete_confed; /* ditto, but once confeds are | |
50 | deleted */ | |
51 | const unsigned int hops; /* aspath_count_hops result */ | |
52 | const unsigned int confeds; /* aspath_count_confeds */ | |
9d303b37 DL |
53 | const int private_as; /* whether the private_as check should pass or |
54 | fail */ | |
1f377b02 | 55 | #define NOT_ALL_PRIVATE 0 |
56 | #define ALL_PRIVATE 1 | |
d62a17ae | 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 */ | |
1f377b02 | 60 | #define NULL_ASN 0 |
61 | }; | |
62 | ||
63 | ||
64 | /* test segments to parse and validate, and use for other tests */ | |
65 | static struct test_segment { | |
d62a17ae | 66 | const char *name; |
67 | const char *desc; | |
68 | const u_char asdata[1024]; | |
69 | int len; | |
70 | struct test_spec sp; | |
71 | } test_segments[] = { | |
72 | { | |
73 | /* 0 */ | |
74 | "seq1", | |
75 | "seq(8466,3,52737,4096)", | |
76 | {0x2, 0x4, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00}, | |
77 | 10, | |
78 | {"8466 3 52737 4096", "8466 3 52737 4096", 4, 0, | |
79 | NOT_ALL_PRIVATE, 4096, 4, 8466}, | |
80 | }, | |
81 | { | |
82 | /* 1 */ | |
83 | "seq2", | |
84 | "seq(8722) seq(4)", | |
85 | {0x2, 0x1, 0x22, 0x12, 0x2, 0x1, 0x00, 0x04}, | |
86 | 8, | |
87 | { | |
9d303b37 | 88 | "8722 4", "8722 4", 2, 0, NOT_ALL_PRIVATE, 4, 5, 8722, |
d62a17ae | 89 | }, |
90 | }, | |
91 | { | |
92 | /* 2 */ | |
93 | "seq3", | |
94 | "seq(8466,3,52737,4096,8722,4)", | |
95 | {0x2, 0x6, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x22, | |
96 | 0x12, 0x00, 0x04}, | |
97 | 14, | |
98 | {"8466 3 52737 4096 8722 4", "8466 3 52737 4096 8722 4", 6, 0, | |
99 | NOT_ALL_PRIVATE, 3, 5, 8466}, | |
100 | }, | |
101 | { | |
102 | /* 3 */ | |
103 | "seqset", | |
104 | "seq(8482,51457) set(5204)", | |
105 | {0x2, 0x2, 0x21, 0x22, 0xc9, 0x01, 0x1, 0x1, 0x14, 0x54}, | |
106 | 10, | |
107 | {"8482 51457 {5204}", "8482 51457 {5204}", 3, 0, | |
108 | NOT_ALL_PRIVATE, 5204, 51456, 8482}, | |
109 | }, | |
110 | { | |
111 | /* 4 */ | |
112 | "seqset2", | |
113 | "seq(8467, 59649) set(4196,48658) set(17322,30745)", | |
114 | {0x2, 0x2, 0x21, 0x13, 0xe9, 0x01, 0x1, 0x2, 0x10, 0x64, 0xbe, | |
115 | 0x12, 0x1, 0x2, 0x43, 0xaa, 0x78, 0x19}, | |
116 | 18, | |
117 | {"8467 59649 {4196,48658} {17322,30745}", | |
118 | "8467 59649 {4196,48658} {17322,30745}", 4, 0, NOT_ALL_PRIVATE, | |
119 | 48658, 1, 8467}, | |
120 | }, | |
121 | { | |
122 | /* 5 */ | |
123 | "multi", | |
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}, | |
128 | 24, | |
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}, | |
132 | }, | |
133 | { | |
134 | /* 6 */ | |
135 | "confed", | |
136 | "confseq(123,456,789)", | |
137 | {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15}, | |
138 | 8, | |
139 | {"(123 456 789)", "", 0, 3, NOT_ALL_PRIVATE, 789, 1, NULL_ASN}, | |
140 | }, | |
141 | { | |
142 | /* 7 */ | |
143 | "confed2", | |
144 | "confseq(123,456,789) confseq(111,222)", | |
145 | {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, 0x3, 0x2, 0x00, | |
146 | 0x6f, 0x00, 0xde}, | |
147 | 14, | |
148 | {"(123 456 789) (111 222)", "", 0, 5, NOT_ALL_PRIVATE, 111, 1, | |
149 | NULL_ASN}, | |
150 | }, | |
151 | { | |
152 | /* 8 */ | |
153 | "confset", | |
154 | "confset(456,123,789)", | |
155 | {0x4, 0x3, 0x01, 0xc8, 0x00, 0x7b, 0x03, 0x15}, | |
156 | 8, | |
157 | {"[123,456,789]", "", 0, 1, NOT_ALL_PRIVATE, 123, 1, NULL_ASN}, | |
158 | }, | |
159 | { | |
160 | /* 9 */ | |
161 | "confmulti", | |
162 | "confseq(123,456,789) confset(222,111) seq(8722) set(4196,48658)", | |
163 | {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, | |
164 | 0x4, 0x2, 0x00, 0xde, 0x00, 0x6f, 0x2, 0x1, | |
165 | 0x22, 0x12, 0x1, 0x2, 0x10, 0x64, 0xbe, 0x12}, | |
166 | 24, | |
167 | {"(123 456 789) [111,222] 8722 {4196,48658}", | |
168 | "8722 {4196,48658}", 2, 4, NOT_ALL_PRIVATE, 123, 1, NULL_ASN}, | |
169 | }, | |
170 | { | |
171 | /* 10 */ | |
172 | "seq4", | |
173 | "seq(8466,2,52737,4096,8722,4)", | |
174 | {0x2, 0x6, 0x21, 0x12, 0x00, 0x02, 0xce, 0x01, 0x10, 0x00, 0x22, | |
175 | 0x12, 0x00, 0x04}, | |
176 | 14, | |
177 | {"8466 2 52737 4096 8722 4", "8466 2 52737 4096 8722 4", 6, 0, | |
178 | NOT_ALL_PRIVATE, 4096, 1, 8466}, | |
179 | }, | |
180 | { | |
181 | /* 11 */ | |
182 | "tripleseq1", | |
183 | "seq(8466,2,52737) seq(4096,8722,4) seq(8722)", | |
184 | {0x2, 0x3, 0x21, 0x12, 0x00, 0x02, 0xce, 0x01, 0x2, 0x3, | |
185 | 0x10, 0x00, 0x22, 0x12, 0x00, 0x04, 0x2, 0x1, 0x22, 0x12}, | |
186 | 20, | |
187 | {"8466 2 52737 4096 8722 4 8722", | |
188 | "8466 2 52737 4096 8722 4 8722", 7, 0, NOT_ALL_PRIVATE, 4096, | |
189 | 1, 8466}, | |
190 | }, | |
191 | { | |
192 | /* 12 */ | |
193 | "someprivate", | |
194 | "seq(8466,64512,52737,65535)", | |
195 | {0x2, 0x4, 0x21, 0x12, 0xfc, 0x00, 0xce, 0x01, 0xff, 0xff}, | |
196 | 10, | |
197 | {"8466 64512 52737 65535", "8466 64512 52737 65535", 4, 0, | |
198 | NOT_ALL_PRIVATE, 65535, 4, 8466}, | |
199 | }, | |
200 | { | |
201 | /* 13 */ | |
202 | "allprivate", | |
203 | "seq(65534,64512,64513,65535)", | |
204 | {0x2, 0x4, 0xff, 0xfe, 0xfc, 0x00, 0xfc, 0x01, 0xff, 0xff}, | |
205 | 10, | |
206 | {"65534 64512 64513 65535", "65534 64512 64513 65535", 4, 0, | |
207 | ALL_PRIVATE, 65534, 4, 65534}, | |
208 | }, | |
209 | { | |
210 | /* 14 */ | |
211 | "long", | |
212 | "seq(8466,3,52737,4096,34285,<repeated 49 more times>)", | |
213 | { | |
214 | 0x2, 0xfa, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, | |
215 | 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, | |
216 | 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, | |
217 | 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, | |
218 | 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, | |
219 | 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, | |
220 | 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, | |
221 | 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, | |
222 | 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, | |
223 | 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, | |
224 | 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, | |
225 | 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, | |
226 | 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, | |
227 | 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, | |
228 | 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, | |
229 | 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, | |
230 | 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, | |
231 | 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, | |
232 | 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, | |
233 | 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, | |
234 | 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, | |
235 | 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, | |
236 | 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, | |
237 | 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, | |
238 | 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, | |
239 | 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, | |
240 | 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, | |
241 | 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, | |
242 | 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, | |
243 | 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, | |
244 | 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, | |
245 | 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, | |
246 | 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, | |
247 | 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, | |
248 | 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, | |
249 | 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, | |
250 | 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, | |
251 | 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, | |
252 | 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, | |
253 | 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, | |
254 | 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, | |
255 | 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, | |
256 | 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, | |
257 | 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, | |
258 | 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, | |
259 | 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, | |
260 | 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, | |
261 | 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, | |
262 | 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, | |
263 | 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, | |
264 | 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, | |
265 | 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, | |
266 | 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, 0xce, | |
267 | 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, 0x03, | |
268 | 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, 0x21, 0x12, 0x00, | |
269 | 0x03, 0xce, 0x01, 0x10, 0x00, 0x85, 0xed, | |
270 | }, | |
271 | 502, | |
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 " | |
292 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
293 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
294 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
295 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
296 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285", | |
50ef565e | 297 | |
d62a17ae | 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 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
319 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
320 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
321 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
322 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285", | |
323 | 250, 0, NOT_ALL_PRIVATE, 4096, 4, 8466}, | |
324 | }, | |
325 | { | |
326 | /* 15 */ | |
327 | "seq1extra", | |
328 | "seq(8466,3,52737,4096,3456)", | |
329 | {0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x0d, | |
330 | 0x80}, | |
331 | 12, | |
332 | {"8466 3 52737 4096 3456", "8466 3 52737 4096 3456", 5, 0, | |
333 | NOT_ALL_PRIVATE, 4096, 4, 8466}, | |
334 | }, | |
335 | { | |
336 | /* 16 */ | |
337 | "empty", | |
338 | "<empty>", | |
339 | {}, | |
340 | 0, | |
341 | {"", "", 0, 0, 0, 0, 0, 0}, | |
342 | }, | |
343 | { | |
344 | /* 17 */ | |
345 | "redundantset", | |
346 | "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153)", | |
347 | {0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, | |
348 | 0x10, 0x00, 0x0d, 0x80, 0x1, 0x4, 0x1b, 0xbb, | |
349 | 0x1f, 0xd9, 0x1f, 0xd9, 0x1f, 0xd9}, | |
350 | 22, | |
351 | {/* We shouldn't ever /generate/ such paths. However, we should | |
352 | * cope with them fine. | |
353 | */ | |
354 | "8466 3 52737 4096 3456 {7099,8153}", | |
355 | "8466 3 52737 4096 3456 {7099,8153}", 6, 0, NOT_ALL_PRIVATE, | |
356 | 4096, 4, 8466}, | |
357 | }, | |
358 | { | |
359 | /* 18 */ | |
360 | "reconcile_lead_asp", | |
361 | "seq(6435,59408,21665) set(23456,23456,23456), seq(23456,23456,23456)", | |
362 | {0x2, 0x3, 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1, | |
363 | 0x1, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0, | |
364 | 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0}, | |
365 | 24, | |
366 | {"6435 59408 21665 {23456} 23456 23456 23456", | |
367 | "6435 59408 21665 {23456} 23456 23456 23456", 7, 0, | |
368 | NOT_ALL_PRIVATE, 23456, 1, 6435}, | |
369 | }, | |
370 | { | |
371 | /* 19 */ | |
372 | "reconcile_new_asp", | |
373 | "set(2457,61697,4369), seq(1842,41591,51793)", | |
374 | {0x1, 0x3, 0x09, 0x99, 0xf1, 0x01, 0x11, 0x11, 0x2, 0x3, 0x07, | |
375 | 0x32, 0xa2, 0x77, 0xca, 0x51}, | |
376 | 16, | |
377 | {"{2457,4369,61697} 1842 41591 51793", | |
378 | "{2457,4369,61697} 1842 41591 51793", 4, 0, NOT_ALL_PRIVATE, | |
379 | 51793, 1, 2457}, | |
380 | }, | |
381 | { | |
382 | /* 20 */ | |
383 | "reconcile_confed", | |
384 | "confseq(123,456,789) confset(456,124,788) seq(6435,59408,21665)" | |
385 | " set(23456,23456,23456), seq(23456,23456,23456)", | |
386 | {0x3, 0x3, 0x00, 0x7b, 0x01, 0xc8, 0x03, 0x15, 0x4, 0x3, | |
387 | 0x01, 0xc8, 0x00, 0x7c, 0x03, 0x14, 0x2, 0x3, 0x19, 0x23, | |
388 | 0xe8, 0x10, 0x54, 0xa1, 0x1, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, | |
389 | 0x5b, 0xa0, 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0}, | |
390 | 40, | |
391 | {"(123 456 789) [124,456,788] 6435 59408 21665" | |
392 | " {23456} 23456 23456 23456", | |
393 | "6435 59408 21665 {23456} 23456 23456 23456", 7, 4, | |
394 | NOT_ALL_PRIVATE, 23456, 1, 6435}, | |
395 | }, | |
396 | { | |
397 | /* 21 */ | |
398 | "reconcile_start_trans", | |
399 | "seq(23456,23456,23456) seq(6435,59408,21665)", | |
400 | { | |
9d303b37 DL |
401 | 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0, 0x2, 0x3, |
402 | 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1, | |
d62a17ae | 403 | }, |
404 | 16, | |
405 | {"23456 23456 23456 6435 59408 21665", | |
406 | "23456 23456 23456 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE, | |
407 | 21665, 1, 23456}, | |
408 | }, | |
409 | { | |
410 | /* 22 */ | |
411 | "reconcile_start_trans4", | |
412 | "seq(1842,41591,51793) seq(6435,59408,21665)", | |
413 | { | |
9d303b37 DL |
414 | 0x2, 0x3, 0x07, 0x32, 0xa2, 0x77, 0xca, 0x51, 0x2, 0x3, |
415 | 0x19, 0x23, 0xe8, 0x10, 0x54, 0xa1, | |
d62a17ae | 416 | }, |
417 | 16, | |
418 | {"1842 41591 51793 6435 59408 21665", | |
419 | "1842 41591 51793 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE, | |
420 | 41591, 1, 1842}, | |
421 | }, | |
422 | { | |
423 | /* 23 */ | |
424 | "reconcile_start_trans_error", | |
425 | "seq(23456,23456,23456) seq(6435,59408)", | |
426 | { | |
9d303b37 DL |
427 | 0x2, 0x3, 0x5b, 0xa0, 0x5b, 0xa0, 0x5b, 0xa0, 0x2, 0x2, |
428 | 0x19, 0x23, 0xe8, 0x10, | |
d62a17ae | 429 | }, |
430 | 14, | |
431 | {"23456 23456 23456 6435 59408", "23456 23456 23456 6435 59408", | |
432 | 5, 0, NOT_ALL_PRIVATE, 59408, 1, 23456}, | |
433 | }, | |
434 | { | |
435 | /* 24 */ | |
436 | "redundantset2", | |
437 | "seq(8466,3,52737,4096,3456) set(7099,8153,8153,8153,7099)", | |
438 | { | |
439 | 0x2, 0x5, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, | |
440 | 0x10, 0x00, 0x0d, 0x80, 0x1, 0x5, 0x1b, 0xbb, | |
441 | 0x1f, 0xd9, 0x1f, 0xd9, 0x1f, 0xd9, 0x1b, 0xbb, | |
442 | }, | |
443 | 24, | |
444 | {/* We should weed out duplicate set members. */ | |
445 | "8466 3 52737 4096 3456 {7099,8153}", | |
446 | "8466 3 52737 4096 3456 {7099,8153}", 6, 0, NOT_ALL_PRIVATE, | |
447 | 4096, 4, 8466}, | |
448 | }, | |
449 | { | |
450 | /* 25 */ | |
451 | "zero-size overflow", | |
452 | "#ASNs = 0, data = seq(8466 3 52737 4096 3456)", | |
453 | {0x2, 0x0, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x10, 0x00, 0x0d, | |
454 | 0x80}, | |
455 | 12, | |
456 | {NULL, NULL, 0, 0, 0, 0, 0, 0}, | |
457 | }, | |
458 | { | |
459 | /* 26 */ | |
460 | "zero-size overflow + valid segment", | |
461 | "seq(#AS=0:8466 3 52737),seq(4096 3456)", | |
462 | {0x2, 0x0, 0x21, 0x12, 0x00, 0x03, 0xce, 0x01, 0x2, 0x2, 0x10, | |
463 | 0x00, 0x0d, 0x80}, | |
464 | 14, | |
465 | {NULL, NULL, 0, 0, 0, 0, 0, 0}, | |
466 | }, | |
467 | { | |
468 | /* 27 */ | |
469 | "invalid segment type", | |
470 | "type=8(4096 3456)", | |
471 | {0x8, 0x2, 0x10, 0x00, 0x0d, 0x80}, | |
472 | 14, | |
473 | {NULL, NULL, 0, 0, 0, 0, 0, 0}, | |
474 | }, | |
475 | {NULL, NULL, {0}, 0, {NULL, 0, 0}}}; | |
476 | ||
477 | #define COMMON_ATTRS \ | |
478 | BGP_ATTR_FLAG_TRANS, BGP_ATTR_ORIGIN, 1, BGP_ORIGIN_EGP, \ | |
479 | BGP_ATTR_FLAG_TRANS, BGP_ATTR_NEXT_HOP, 4, 192, 0, 2, 0 | |
75ee619c | 480 | #define COMMON_ATTR_SIZE 11 |
0b1e756b | 481 | |
50ef565e PJ |
482 | /* */ |
483 | static struct aspath_tests { | |
d62a17ae | 484 | const char *desc; |
485 | const struct test_segment *segment; | |
486 | const char *shouldbe; /* String it should evaluate to */ | |
487 | const enum as4 { | |
488 | AS4_DATA, | |
489 | AS2_DATA | |
490 | } as4; /* whether data should be as4 or not (ie as2) */ | |
491 | const int result; /* expected result for bgp_attr_parse */ | |
492 | const int cap; /* capabilities to set for peer */ | |
493 | const char attrheader[1024]; | |
494 | size_t len; | |
495 | const struct test_segment *old_segment; | |
496 | } aspath_tests[] = { | |
497 | /* 0 */ | |
498 | { | |
499 | "basic test", | |
500 | &test_segments[0], | |
501 | "8466 3 52737 4096", | |
502 | AS2_DATA, | |
503 | 0, | |
504 | 0, | |
505 | { | |
9d303b37 | 506 | COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 10, |
d62a17ae | 507 | }, |
508 | COMMON_ATTR_SIZE + 3, | |
509 | }, | |
510 | /* 1 */ | |
511 | { | |
512 | "length too short", | |
513 | &test_segments[0], | |
514 | "8466 3 52737 4096", | |
515 | AS2_DATA, | |
516 | -1, | |
517 | 0, | |
518 | { | |
9d303b37 | 519 | COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 8, |
d62a17ae | 520 | }, |
521 | COMMON_ATTR_SIZE + 3, | |
522 | }, | |
523 | /* 2 */ | |
524 | { | |
525 | "length too long", | |
526 | &test_segments[0], | |
527 | "8466 3 52737 4096", | |
528 | AS2_DATA, | |
529 | -1, | |
530 | 0, | |
531 | { | |
9d303b37 | 532 | COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 12, |
d62a17ae | 533 | }, |
534 | COMMON_ATTR_SIZE + 3, | |
535 | }, | |
536 | /* 3 */ | |
537 | { | |
538 | "incorrect flag", | |
539 | &test_segments[0], | |
540 | "8466 3 52737 4096", | |
541 | AS2_DATA, | |
542 | -1, | |
543 | 0, | |
544 | { | |
545 | COMMON_ATTRS, | |
546 | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, | |
9d303b37 | 547 | BGP_ATTR_AS_PATH, 10, |
d62a17ae | 548 | }, |
549 | COMMON_ATTR_SIZE + 3, | |
550 | }, | |
551 | /* 4 */ | |
552 | { | |
553 | "as4_path, with as2 format data", | |
554 | &test_segments[0], | |
555 | "8466 3 52737 4096", | |
556 | AS2_DATA, | |
557 | -1, | |
558 | 0, | |
559 | { | |
560 | COMMON_ATTRS, | |
561 | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, | |
9d303b37 | 562 | BGP_ATTR_AS4_PATH, 10, |
d62a17ae | 563 | }, |
564 | COMMON_ATTR_SIZE + 3, | |
565 | }, | |
566 | /* 5 */ | |
567 | { | |
568 | "as4, with incorrect attr length", | |
569 | &test_segments[0], | |
570 | "8466 3 52737 4096", | |
571 | AS4_DATA, | |
572 | -1, | |
573 | PEER_CAP_AS4_RCV, | |
574 | { | |
575 | COMMON_ATTRS, | |
576 | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, | |
9d303b37 | 577 | BGP_ATTR_AS4_PATH, 10, |
d62a17ae | 578 | }, |
579 | COMMON_ATTR_SIZE + 3, | |
580 | }, | |
581 | /* 6 */ | |
582 | { | |
583 | "basic 4-byte as-path", | |
584 | &test_segments[0], | |
585 | "8466 3 52737 4096", | |
586 | AS4_DATA, | |
587 | 0, | |
588 | PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, | |
589 | { | |
9d303b37 | 590 | COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 18, |
d62a17ae | 591 | }, |
592 | COMMON_ATTR_SIZE + 3, | |
593 | }, | |
594 | /* 7 */ | |
595 | { | |
596 | "4b AS_PATH: too short", | |
597 | &test_segments[0], | |
598 | "8466 3 52737 4096", | |
599 | AS4_DATA, | |
600 | -1, | |
601 | PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, | |
602 | { | |
9d303b37 | 603 | COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 16, |
d62a17ae | 604 | }, |
605 | COMMON_ATTR_SIZE + 3, | |
606 | }, | |
607 | /* 8 */ | |
608 | { | |
609 | "4b AS_PATH: too long", | |
610 | &test_segments[0], | |
611 | "8466 3 52737 4096", | |
612 | AS4_DATA, | |
613 | -1, | |
614 | PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, | |
615 | { | |
9d303b37 | 616 | COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 20, |
d62a17ae | 617 | }, |
618 | COMMON_ATTR_SIZE + 3, | |
619 | }, | |
620 | /* 9 */ | |
621 | { | |
622 | "4b AS_PATH: too long2", | |
623 | &test_segments[0], | |
624 | "8466 3 52737 4096", | |
625 | AS4_DATA, | |
626 | -1, | |
627 | PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, | |
628 | { | |
9d303b37 | 629 | COMMON_ATTRS, BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 22, |
d62a17ae | 630 | }, |
631 | COMMON_ATTR_SIZE + 3, | |
632 | }, | |
633 | /* 10 */ | |
634 | { | |
635 | "4b AS_PATH: bad flags", | |
636 | &test_segments[0], | |
637 | "8466 3 52737 4096", | |
638 | AS4_DATA, | |
639 | -1, | |
640 | PEER_CAP_AS4_RCV | PEER_CAP_AS4_ADV, | |
641 | { | |
642 | COMMON_ATTRS, | |
643 | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, | |
9d303b37 | 644 | BGP_ATTR_AS_PATH, 18, |
d62a17ae | 645 | }, |
646 | COMMON_ATTR_SIZE + 3, | |
647 | }, | |
648 | /* 11 */ | |
649 | { | |
650 | "4b AS4_PATH w/o AS_PATH", | |
651 | &test_segments[6], | |
652 | NULL, | |
653 | AS4_DATA, | |
654 | -1, | |
655 | PEER_CAP_AS4_ADV, | |
656 | { | |
657 | COMMON_ATTRS, | |
658 | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, | |
9d303b37 | 659 | BGP_ATTR_AS4_PATH, 14, |
d62a17ae | 660 | }, |
661 | COMMON_ATTR_SIZE + 3, | |
662 | }, | |
663 | /* 12 */ | |
664 | { | |
665 | "4b AS4_PATH: confed", | |
666 | &test_segments[6], | |
667 | "8466 3 52737 4096 (123 456 789)", | |
668 | AS4_DATA, | |
669 | 0, | |
670 | PEER_CAP_AS4_ADV, | |
671 | { | |
672 | COMMON_ATTRS, | |
673 | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_OPTIONAL, | |
9d303b37 | 674 | BGP_ATTR_AS4_PATH, 14, |
d62a17ae | 675 | }, |
676 | COMMON_ATTR_SIZE + 3, | |
677 | &test_segments[0], | |
678 | }, | |
679 | {NULL, NULL, NULL, 0, 0, 0, {0}, 0}, | |
1f377b02 | 680 | }; |
681 | ||
682 | /* prepending tests */ | |
683 | static struct tests { | |
d62a17ae | 684 | const struct test_segment *test1; |
685 | const struct test_segment *test2; | |
686 | struct test_spec sp; | |
687 | } prepend_tests[] = { | |
688 | /* 0 */ | |
689 | { | |
690 | &test_segments[0], | |
691 | &test_segments[1], | |
692 | {"8466 3 52737 4096 8722 4", "8466 3 52737 4096 8722 4", 6, 0, | |
693 | NOT_ALL_PRIVATE, 4096, 1, 8466}, | |
694 | }, | |
695 | /* 1 */ | |
696 | {&test_segments[1], | |
697 | &test_segments[3], | |
698 | {"8722 4 8482 51457 {5204}", "8722 4 8482 51457 {5204}", 5, 0, | |
699 | NOT_ALL_PRIVATE, 5204, 1, 8722}}, | |
700 | /* 2 */ | |
701 | { | |
702 | &test_segments[3], | |
703 | &test_segments[4], | |
704 | {"8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", | |
705 | "8482 51457 {5204} 8467 59649 {4196,48658} {17322,30745}", 7, | |
706 | 0, NOT_ALL_PRIVATE, 5204, 1, 8482}, | |
707 | }, | |
708 | /* 3 */ | |
709 | {&test_segments[4], | |
710 | &test_segments[5], | |
711 | {"8467 59649 {4196,48658} {17322,30745} 6435 59408 21665" | |
712 | " {2457,4369,61697} 1842 41590 51793", | |
713 | "8467 59649 {4196,48658} {17322,30745} 6435 59408 21665" | |
714 | " {2457,4369,61697} 1842 41590 51793", | |
715 | 11, 0, NOT_ALL_PRIVATE, 61697, 1, 8467}}, | |
716 | /* 4 */ | |
717 | { | |
718 | &test_segments[5], | |
719 | &test_segments[6], | |
720 | {"6435 59408 21665 {2457,4369,61697} 1842 41590 51793", | |
721 | "6435 59408 21665 {2457,4369,61697} 1842 41590 51793", 7, 0, | |
722 | NOT_ALL_PRIVATE, 1842, 1, 6435}, | |
723 | }, | |
724 | /* 5 */ | |
725 | {&test_segments[6], | |
726 | &test_segments[7], | |
727 | {"(123 456 789) (123 456 789) (111 222)", "", 0, 8, NOT_ALL_PRIVATE, | |
728 | 111, 1, 0}}, | |
729 | {&test_segments[7], | |
730 | &test_segments[8], | |
731 | {"(123 456 789) (111 222) [123,456,789]", "", 0, 6, NOT_ALL_PRIVATE, | |
732 | 111, 1, 0}}, | |
733 | { | |
734 | &test_segments[8], | |
735 | &test_segments[9], | |
736 | {"[123,456,789] (123 456 789) [111,222] 8722 {4196,48658}", | |
737 | "8722 {4196,48658}", 2, 5, NOT_ALL_PRIVATE, 456, 1, NULL_ASN}, | |
738 | }, | |
739 | { | |
740 | &test_segments[9], | |
741 | &test_segments[8], | |
742 | {"(123 456 789) [111,222] 8722 {4196,48658} [123,456,789]", | |
743 | "8722 {4196,48658}", 2, 5, NOT_ALL_PRIVATE, 48658, 1, | |
744 | NULL_ASN}, | |
745 | }, | |
746 | { | |
747 | &test_segments[14], | |
748 | &test_segments[11], | |
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 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
755 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
756 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
757 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
758 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
759 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
760 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
761 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
762 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
763 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
764 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
765 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
766 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
767 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
768 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
769 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
770 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
771 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
772 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
773 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
774 | "8466 2 52737 4096 8722 4 8722", | |
775 | ||
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 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
782 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
783 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
784 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
785 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
786 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
787 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
788 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
789 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
790 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
791 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
792 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
793 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
794 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
795 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
796 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
797 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
798 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
799 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
800 | "8466 3 52737 4096 34285 8466 3 52737 4096 34285 " | |
801 | "8466 2 52737 4096 8722 4 8722", | |
802 | 257, 0, NOT_ALL_PRIVATE, 4096, 1000, 8466}, | |
803 | }, | |
804 | {NULL, | |
805 | NULL, | |
806 | { | |
9d303b37 | 807 | NULL, 0, 0, 0, 0, 0, 0, |
d62a17ae | 808 | }}, |
1f377b02 | 809 | }; |
810 | ||
d62a17ae | 811 | struct tests reconcile_tests[] = { |
812 | { | |
813 | &test_segments[18], | |
814 | &test_segments[19], | |
815 | {"6435 59408 21665 {2457,4369,61697} 1842 41591 51793", | |
816 | "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", 7, 0, | |
817 | NOT_ALL_PRIVATE, 51793, 1, 6435}, | |
818 | }, | |
819 | { | |
820 | &test_segments[19], | |
821 | &test_segments[18], | |
822 | /* AS_PATH (19) has more hops than NEW_AS_PATH, | |
823 | * so just AS_PATH should be used (though, this practice | |
824 | * is bad imho). | |
825 | */ | |
826 | {"{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456", | |
827 | "{2457,4369,61697} 1842 41591 51793 6435 59408 21665 {23456} 23456 23456 23456", | |
828 | 11, 0, NOT_ALL_PRIVATE, 51793, 1, 6435}, | |
829 | }, | |
830 | { | |
831 | &test_segments[20], | |
832 | &test_segments[19], | |
833 | {"(123 456 789) [124,456,788] 6435 59408 21665" | |
834 | " {2457,4369,61697} 1842 41591 51793", | |
835 | "6435 59408 21665 {2457,4369,61697} 1842 41591 51793", 7, 4, | |
836 | NOT_ALL_PRIVATE, 51793, 1, 6435}, | |
837 | }, | |
838 | { | |
839 | &test_segments[21], | |
840 | &test_segments[22], | |
841 | {"1842 41591 51793 6435 59408 21665", | |
842 | "1842 41591 51793 6435 59408 21665", 6, 0, NOT_ALL_PRIVATE, | |
843 | 51793, 1, 1842}, | |
844 | }, | |
845 | { | |
846 | &test_segments[23], | |
847 | &test_segments[22], | |
848 | {"23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665", | |
849 | "23456 23456 23456 6435 59408 1842 41591 51793 6435 59408 21665", | |
850 | 11, 0, NOT_ALL_PRIVATE, 51793, 1, 1842}, | |
851 | }, | |
852 | {NULL, | |
853 | NULL, | |
854 | { | |
9d303b37 | 855 | NULL, 0, 0, 0, 0, 0, 0, |
d62a17ae | 856 | }}, |
0b2aa3a0 | 857 | }; |
d62a17ae | 858 | |
859 | struct tests aggregate_tests[] = { | |
860 | { | |
861 | &test_segments[0], | |
862 | &test_segments[2], | |
863 | {"8466 3 52737 4096 {4,8722}", "8466 3 52737 4096 {4,8722}", 5, | |
864 | 0, NOT_ALL_PRIVATE, 4, 1, 8466}, | |
865 | }, | |
866 | { | |
867 | &test_segments[2], | |
868 | &test_segments[0], | |
869 | {"8466 3 52737 4096 {4,8722}", "8466 3 52737 4096 {4,8722}", 5, | |
870 | 0, NOT_ALL_PRIVATE, 8722, 1, 8466}, | |
871 | }, | |
872 | { | |
873 | &test_segments[2], | |
874 | &test_segments[10], | |
875 | {"8466 {2,3,4,4096,8722,52737}", "8466 {2,3,4,4096,8722,52737}", | |
876 | 2, 0, NOT_ALL_PRIVATE, 8722, 5, 8466}, | |
877 | }, | |
878 | { | |
879 | &test_segments[10], | |
880 | &test_segments[2], | |
881 | {"8466 {2,3,4,4096,8722,52737}", "8466 {2,3,4,4096,8722,52737}", | |
882 | 2, 0, NOT_ALL_PRIVATE, 2, 20000, 8466}, | |
883 | }, | |
884 | ||
885 | { | |
886 | &test_segments[5], | |
887 | &test_segments[18], | |
888 | {"6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", | |
889 | "6435 59408 21665 {1842,2457,4369,23456,41590,51793,61697}", 4, | |
890 | 0, NOT_ALL_PRIVATE, 41590, 1, 6435}, | |
891 | }, | |
892 | ||
893 | {NULL, NULL, {NULL, 0, 0}}, | |
1f377b02 | 894 | }; |
895 | ||
d62a17ae | 896 | struct compare_tests { |
897 | int test_index1; | |
898 | int test_index2; | |
1f377b02 | 899 | #define CMP_RES_YES 1 |
900 | #define CMP_RES_NO 0 | |
d62a17ae | 901 | char shouldbe_cmp; |
902 | char shouldbe_confed; | |
903 | } left_compare[] = { | |
904 | {0, 1, CMP_RES_NO, CMP_RES_NO}, {0, 2, CMP_RES_YES, CMP_RES_NO}, | |
905 | {0, 11, CMP_RES_YES, CMP_RES_NO}, {0, 15, CMP_RES_YES, CMP_RES_NO}, | |
906 | {0, 16, CMP_RES_NO, CMP_RES_NO}, {1, 11, CMP_RES_NO, CMP_RES_NO}, | |
907 | {6, 7, CMP_RES_NO, CMP_RES_YES}, {6, 8, CMP_RES_NO, CMP_RES_NO}, | |
908 | {7, 8, CMP_RES_NO, CMP_RES_NO}, {1, 9, CMP_RES_YES, CMP_RES_NO}, | |
909 | {0, 9, CMP_RES_NO, CMP_RES_NO}, {3, 9, CMP_RES_NO, CMP_RES_NO}, | |
910 | {0, 6, CMP_RES_NO, CMP_RES_NO}, {1, 6, CMP_RES_NO, CMP_RES_NO}, | |
911 | {0, 8, CMP_RES_NO, CMP_RES_NO}, {1, 8, CMP_RES_NO, CMP_RES_NO}, | |
912 | {11, 6, CMP_RES_NO, CMP_RES_NO}, {11, 7, CMP_RES_NO, CMP_RES_NO}, | |
913 | {11, 8, CMP_RES_NO, CMP_RES_NO}, {9, 6, CMP_RES_NO, CMP_RES_YES}, | |
914 | {9, 7, CMP_RES_NO, CMP_RES_YES}, {9, 8, CMP_RES_NO, CMP_RES_NO}, | |
1f377b02 | 915 | }; |
916 | ||
917 | /* make an aspath from a data stream */ | |
d62a17ae | 918 | static struct aspath *make_aspath(const u_char *data, size_t len, int use32bit) |
1f377b02 | 919 | { |
d62a17ae | 920 | struct stream *s = NULL; |
921 | struct aspath *as; | |
922 | ||
923 | if (len) { | |
924 | s = stream_new(len); | |
925 | stream_put(s, data, len); | |
926 | } | |
927 | as = aspath_parse(s, len, use32bit); | |
928 | ||
929 | if (s) | |
930 | stream_free(s); | |
931 | ||
932 | return as; | |
1f377b02 | 933 | } |
934 | ||
d62a17ae | 935 | static void printbytes(const u_char *bytes, int len) |
1f377b02 | 936 | { |
d62a17ae | 937 | int i = 0; |
938 | while (i < len) { | |
939 | if (i % 2) | |
940 | printf("%02hhx%s", bytes[i], " "); | |
941 | else | |
942 | printf("0x%02hhx", bytes[i]); | |
943 | i++; | |
944 | } | |
945 | printf("\n"); | |
946 | } | |
1f377b02 | 947 | |
948 | /* validate the given aspath */ | |
d62a17ae | 949 | static int validate(struct aspath *as, const struct test_spec *sp) |
1f377b02 | 950 | { |
d62a17ae | 951 | size_t bytes, bytes4; |
952 | int fails = 0; | |
953 | const u_char *out; | |
954 | static struct stream *s; | |
955 | struct aspath *asinout, *asconfeddel, *asstr, *as4; | |
956 | ||
957 | if (as == NULL && sp->shouldbe == NULL) { | |
958 | printf("Correctly failed to parse\n"); | |
959 | return fails; | |
960 | } | |
961 | ||
962 | out = aspath_snmp_pathseg(as, &bytes); | |
963 | asinout = make_aspath(out, bytes, 0); | |
964 | ||
965 | /* Excercise AS4 parsing a bit, with a dogfood test */ | |
966 | if (!s) | |
967 | s = stream_new(4096); | |
968 | bytes4 = aspath_put(s, as, 1); | |
969 | as4 = make_aspath(STREAM_DATA(s), bytes4, 1); | |
970 | ||
971 | asstr = aspath_str2aspath(sp->shouldbe); | |
972 | ||
973 | asconfeddel = aspath_delete_confed_seq(aspath_dup(asinout)); | |
974 | ||
975 | printf("got: %s\n", aspath_print(as)); | |
976 | ||
977 | /* the parsed path should match the specified 'shouldbe' string. | |
978 | * We should pass the "eat our own dog food" test, be able to output | |
979 | * this path and then input it again. Ie the path resulting from: | |
980 | * | |
981 | * aspath_parse(aspath_put(as)) | |
982 | * | |
983 | * should: | |
984 | * | |
985 | * - also match the specified 'shouldbe' value | |
986 | * - hash to same value as original path | |
987 | * - have same hops and confed counts as original, and as the | |
988 | * the specified counts | |
989 | * | |
990 | * aspath_str2aspath() and shouldbe should match | |
991 | * | |
992 | * We do the same for: | |
993 | * | |
994 | * aspath_parse(aspath_put(as,USE32BIT)) | |
995 | * | |
996 | * Confederation related tests: | |
997 | * - aspath_delete_confed_seq(aspath) should match shouldbe_confed | |
998 | * - aspath_delete_confed_seq should be idempotent. | |
999 | */ | |
1000 | if (strcmp(aspath_print(as), sp->shouldbe) | |
1001 | /* hash validation */ | |
1002 | || (aspath_key_make(as) != aspath_key_make(asinout)) | |
1003 | /* by string */ | |
1004 | || strcmp(aspath_print(asinout), sp->shouldbe) | |
1005 | /* By 4-byte parsing */ | |
1006 | || strcmp(aspath_print(as4), sp->shouldbe) | |
1007 | /* by various path counts */ | |
1008 | || (aspath_count_hops(as) != sp->hops) | |
1009 | || (aspath_count_confeds(as) != sp->confeds) | |
1010 | || (aspath_count_hops(asinout) != sp->hops) | |
1011 | || (aspath_count_confeds(asinout) != sp->confeds)) { | |
1012 | failed++; | |
1013 | fails++; | |
1014 | printf("shouldbe:\n%s\n", sp->shouldbe); | |
1015 | printf("as4:\n%s\n", aspath_print(as4)); | |
1016 | printf("hash keys: in: %d out->in: %d\n", aspath_key_make(as), | |
1017 | aspath_key_make(asinout)); | |
1018 | printf("hops: %d, counted %d %d\n", sp->hops, | |
1019 | aspath_count_hops(as), aspath_count_hops(asinout)); | |
1020 | printf("confeds: %d, counted %d %d\n", sp->confeds, | |
1021 | aspath_count_confeds(as), aspath_count_confeds(asinout)); | |
1022 | printf("out->in:\n%s\nbytes: ", aspath_print(asinout)); | |
1023 | printbytes(out, bytes); | |
1024 | } | |
1025 | /* basic confed related tests */ | |
1026 | if ((aspath_print(asconfeddel) == NULL | |
1027 | && sp->shouldbe_delete_confed != NULL) | |
1028 | || (aspath_print(asconfeddel) != NULL | |
1029 | && sp->shouldbe_delete_confed == NULL) | |
1030 | || strcmp(aspath_print(asconfeddel), sp->shouldbe_delete_confed) | |
1031 | /* delete_confed_seq should be idempotent */ | |
1032 | || (aspath_key_make(asconfeddel) | |
1033 | != aspath_key_make(aspath_delete_confed_seq(asconfeddel)))) { | |
1034 | failed++; | |
1035 | fails++; | |
1036 | printf("as-path minus confeds is: %s\n", | |
1037 | aspath_print(asconfeddel)); | |
1038 | printf("as-path minus confeds should be: %s\n", | |
1039 | sp->shouldbe_delete_confed); | |
1040 | } | |
1041 | /* aspath_str2aspath test */ | |
1042 | if ((aspath_print(asstr) == NULL && sp->shouldbe != NULL) | |
1043 | || (aspath_print(asstr) != NULL && sp->shouldbe == NULL) | |
1044 | || strcmp(aspath_print(asstr), sp->shouldbe)) { | |
1045 | failed++; | |
1046 | fails++; | |
1047 | printf("asstr: %s\n", aspath_print(asstr)); | |
1048 | } | |
1049 | ||
1050 | /* loop, private and first as checks */ | |
1051 | if ((sp->does_loop && aspath_loop_check(as, sp->does_loop) == 0) | |
1052 | || (sp->doesnt_loop && aspath_loop_check(as, sp->doesnt_loop) != 0) | |
1053 | || (aspath_private_as_check(as) != sp->private_as) | |
1054 | || (aspath_firstas_check(as, sp->first) && sp->first == 0)) { | |
1055 | failed++; | |
1056 | fails++; | |
1057 | printf("firstas: %d, got %d\n", sp->first, | |
1058 | aspath_firstas_check(as, sp->first)); | |
1059 | printf("loop does: %d %d, doesnt: %d %d\n", sp->does_loop, | |
1060 | aspath_loop_check(as, sp->does_loop), sp->doesnt_loop, | |
1061 | aspath_loop_check(as, sp->doesnt_loop)); | |
1062 | printf("private check: %d %d\n", sp->private_as, | |
1063 | aspath_private_as_check(as)); | |
1064 | } | |
1065 | aspath_unintern(&asinout); | |
1066 | aspath_unintern(&as4); | |
1067 | ||
1068 | aspath_free(asconfeddel); | |
1069 | aspath_free(asstr); | |
1070 | stream_reset(s); | |
1071 | ||
1072 | return fails; | |
1f377b02 | 1073 | } |
1074 | ||
d62a17ae | 1075 | static void empty_get_test() |
1f377b02 | 1076 | { |
d62a17ae | 1077 | struct aspath *as = aspath_empty_get(); |
1078 | struct test_spec sp = {"", "", 0, 0, 0, 0, 0, 0}; | |
1079 | ||
1080 | printf("empty_get_test, as: %s\n", aspath_print(as)); | |
1081 | if (!validate(as, &sp)) | |
1082 | printf("%s\n", OK); | |
1083 | else | |
1084 | printf("%s!\n", FAILED); | |
1085 | ||
1086 | printf("\n"); | |
1087 | ||
1088 | aspath_free(as); | |
1f377b02 | 1089 | } |
1090 | ||
1091 | /* basic parsing test */ | |
d62a17ae | 1092 | static void parse_test(struct test_segment *t) |
1f377b02 | 1093 | { |
d62a17ae | 1094 | struct aspath *asp; |
1095 | ||
1096 | printf("%s: %s\n", t->name, t->desc); | |
1097 | ||
1098 | asp = make_aspath(t->asdata, t->len, 0); | |
1099 | ||
1100 | printf("aspath: %s\nvalidating...:\n", aspath_print(asp)); | |
1101 | ||
1102 | if (!validate(asp, &t->sp)) | |
1103 | printf(OK "\n"); | |
1104 | else | |
1105 | printf(FAILED "\n"); | |
1106 | ||
1107 | printf("\n"); | |
1108 | ||
1109 | if (asp) | |
1110 | aspath_unintern(&asp); | |
1f377b02 | 1111 | } |
1112 | ||
1113 | /* prepend testing */ | |
d62a17ae | 1114 | static void prepend_test(struct tests *t) |
1f377b02 | 1115 | { |
d62a17ae | 1116 | struct aspath *asp1, *asp2, *ascratch; |
1117 | ||
1118 | printf("prepend %s: %s\n", t->test1->name, t->test1->desc); | |
1119 | printf("to %s: %s\n", t->test2->name, t->test2->desc); | |
1120 | ||
1121 | asp1 = make_aspath(t->test1->asdata, t->test1->len, 0); | |
1122 | asp2 = make_aspath(t->test2->asdata, t->test2->len, 0); | |
1123 | ||
1124 | ascratch = aspath_dup(asp2); | |
1125 | aspath_unintern(&asp2); | |
1126 | ||
1127 | asp2 = aspath_prepend(asp1, ascratch); | |
1128 | ||
1129 | printf("aspath: %s\n", aspath_print(asp2)); | |
1130 | ||
1131 | if (!validate(asp2, &t->sp)) | |
1132 | printf("%s\n", OK); | |
1133 | else | |
1134 | printf("%s!\n", FAILED); | |
1135 | ||
1136 | printf("\n"); | |
1137 | aspath_unintern(&asp1); | |
1138 | aspath_free(asp2); | |
1f377b02 | 1139 | } |
1140 | ||
1141 | /* empty-prepend testing */ | |
d62a17ae | 1142 | static void empty_prepend_test(struct test_segment *t) |
1f377b02 | 1143 | { |
d62a17ae | 1144 | struct aspath *asp1, *asp2, *ascratch; |
1145 | ||
1146 | printf("empty prepend %s: %s\n", t->name, t->desc); | |
1147 | ||
1148 | asp1 = make_aspath(t->asdata, t->len, 0); | |
1149 | asp2 = aspath_empty(); | |
1150 | ||
1151 | ascratch = aspath_dup(asp2); | |
1152 | aspath_unintern(&asp2); | |
1153 | ||
1154 | asp2 = aspath_prepend(asp1, ascratch); | |
1155 | ||
1156 | printf("aspath: %s\n", aspath_print(asp2)); | |
1157 | ||
1158 | if (!validate(asp2, &t->sp)) | |
1159 | printf(OK "\n"); | |
1160 | else | |
1161 | printf(FAILED "!\n"); | |
1162 | ||
1163 | printf("\n"); | |
1164 | if (asp1) | |
1165 | aspath_unintern(&asp1); | |
1166 | aspath_free(asp2); | |
1f377b02 | 1167 | } |
1168 | ||
0b2aa3a0 | 1169 | /* as2+as4 reconciliation testing */ |
d62a17ae | 1170 | static void as4_reconcile_test(struct tests *t) |
0b2aa3a0 | 1171 | { |
d62a17ae | 1172 | struct aspath *asp1, *asp2, *ascratch; |
1173 | ||
1174 | printf("reconciling %s:\n %s\n", t->test1->name, t->test1->desc); | |
1175 | printf("with %s:\n %s\n", t->test2->name, t->test2->desc); | |
1176 | ||
1177 | asp1 = make_aspath(t->test1->asdata, t->test1->len, 0); | |
1178 | asp2 = make_aspath(t->test2->asdata, t->test2->len, 0); | |
1179 | ||
1180 | ascratch = aspath_reconcile_as4(asp1, asp2); | |
1181 | ||
1182 | if (!validate(ascratch, &t->sp)) | |
1183 | printf(OK "\n"); | |
1184 | else | |
1185 | printf(FAILED "!\n"); | |
1186 | ||
1187 | printf("\n"); | |
1188 | aspath_unintern(&asp1); | |
1189 | aspath_unintern(&asp2); | |
1190 | aspath_free(ascratch); | |
0b2aa3a0 PJ |
1191 | } |
1192 | ||
1193 | ||
1f377b02 | 1194 | /* aggregation testing */ |
d62a17ae | 1195 | static void aggregate_test(struct tests *t) |
1f377b02 | 1196 | { |
d62a17ae | 1197 | struct aspath *asp1, *asp2, *ascratch; |
1198 | ||
1199 | printf("aggregate %s: %s\n", t->test1->name, t->test1->desc); | |
1200 | printf("with %s: %s\n", t->test2->name, t->test2->desc); | |
1201 | ||
1202 | asp1 = make_aspath(t->test1->asdata, t->test1->len, 0); | |
1203 | asp2 = make_aspath(t->test2->asdata, t->test2->len, 0); | |
1204 | ||
1205 | ascratch = aspath_aggregate(asp1, asp2); | |
1206 | ||
1207 | if (!validate(ascratch, &t->sp)) | |
1208 | printf(OK "\n"); | |
1209 | else | |
1210 | printf(FAILED "!\n"); | |
1211 | ||
1212 | printf("\n"); | |
1213 | aspath_unintern(&asp1); | |
1214 | aspath_unintern(&asp2); | |
1215 | aspath_free(ascratch); | |
1216 | /* aspath_unintern (ascratch);*/ | |
1f377b02 | 1217 | } |
1218 | ||
1219 | /* cmp_left tests */ | |
d62a17ae | 1220 | static void cmp_test() |
1f377b02 | 1221 | { |
d62a17ae | 1222 | unsigned int i; |
1223 | #define CMP_TESTS_MAX (sizeof(left_compare) / sizeof(struct compare_tests)) | |
1224 | ||
1225 | for (i = 0; i < CMP_TESTS_MAX; i++) { | |
1226 | struct test_segment *t1 = | |
1227 | &test_segments[left_compare[i].test_index1]; | |
1228 | struct test_segment *t2 = | |
1229 | &test_segments[left_compare[i].test_index2]; | |
1230 | struct aspath *asp1, *asp2; | |
1231 | ||
1232 | printf("left cmp %s: %s\n", t1->name, t1->desc); | |
1233 | printf("and %s: %s\n", t2->name, t2->desc); | |
1234 | ||
1235 | asp1 = make_aspath(t1->asdata, t1->len, 0); | |
1236 | asp2 = make_aspath(t2->asdata, t2->len, 0); | |
1237 | ||
1238 | if (aspath_cmp_left(asp1, asp2) != left_compare[i].shouldbe_cmp | |
1239 | || aspath_cmp_left(asp2, asp1) | |
1240 | != left_compare[i].shouldbe_cmp | |
1241 | || aspath_cmp_left_confed(asp1, asp2) | |
1242 | != left_compare[i].shouldbe_confed | |
1243 | || aspath_cmp_left_confed(asp2, asp1) | |
1244 | != left_compare[i].shouldbe_confed) { | |
1245 | failed++; | |
1246 | printf(FAILED "\n"); | |
1247 | printf("result should be: cmp: %d, confed: %d\n", | |
1248 | left_compare[i].shouldbe_cmp, | |
1249 | left_compare[i].shouldbe_confed); | |
1250 | printf("got: cmp %d, cmp_confed: %d\n", | |
1251 | aspath_cmp_left(asp1, asp2), | |
1252 | aspath_cmp_left_confed(asp1, asp2)); | |
1253 | printf("path1: %s\npath2: %s\n", aspath_print(asp1), | |
1254 | aspath_print(asp2)); | |
1255 | } else | |
1256 | printf(OK "\n"); | |
1257 | ||
1258 | printf("\n"); | |
1259 | aspath_unintern(&asp1); | |
1260 | aspath_unintern(&asp2); | |
1261 | } | |
1f377b02 | 1262 | } |
50ef565e | 1263 | |
d62a17ae | 1264 | static int handle_attr_test(struct aspath_tests *t) |
50ef565e | 1265 | { |
d62a17ae | 1266 | struct bgp bgp = {0}; |
1267 | struct peer peer = {0}; | |
1268 | struct attr attr = {0}; | |
1269 | int ret; | |
1270 | int initfail = failed; | |
1271 | struct aspath *asp; | |
1272 | size_t datalen; | |
1273 | ||
1274 | asp = make_aspath(t->segment->asdata, t->segment->len, 0); | |
1275 | ||
1276 | peer.ibuf = stream_new(BGP_MAX_PACKET_SIZE); | |
1277 | peer.obuf = stream_fifo_new(); | |
1278 | peer.bgp = &bgp; | |
1279 | peer.host = (char *)"none"; | |
1280 | peer.fd = -1; | |
1281 | peer.cap = t->cap; | |
1282 | ||
1283 | stream_write(peer.ibuf, t->attrheader, t->len); | |
1284 | datalen = aspath_put(peer.ibuf, asp, t->as4 == AS4_DATA); | |
1285 | if (t->old_segment) { | |
1286 | char dummyaspath[] = {BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, | |
1287 | t->old_segment->len}; | |
1288 | stream_write(peer.ibuf, dummyaspath, sizeof(dummyaspath)); | |
1289 | stream_write(peer.ibuf, t->old_segment->asdata, | |
1290 | t->old_segment->len); | |
1291 | datalen += sizeof(dummyaspath) + t->old_segment->len; | |
1292 | } | |
1293 | ||
1294 | ret = bgp_attr_parse(&peer, &attr, t->len + datalen, NULL, NULL); | |
1295 | ||
1296 | if (ret != t->result) { | |
1297 | printf("bgp_attr_parse returned %d, expected %d\n", ret, | |
1298 | t->result); | |
1299 | printf("datalen %zd\n", datalen); | |
1300 | failed++; | |
1301 | } | |
1302 | if (ret != 0) | |
1303 | goto out; | |
1304 | ||
1305 | if (t->shouldbe && attr.aspath == NULL) { | |
1306 | printf("aspath is NULL, but should be: %s\n", t->shouldbe); | |
1307 | failed++; | |
1308 | } | |
1309 | if (t->shouldbe && attr.aspath | |
1310 | && strcmp(attr.aspath->str, t->shouldbe)) { | |
1311 | printf("attr str and 'shouldbe' mismatched!\n" | |
1312 | "attr str: %s\n" | |
1313 | "shouldbe: %s\n", | |
1314 | attr.aspath->str, t->shouldbe); | |
1315 | failed++; | |
1316 | } | |
1317 | if (!t->shouldbe && attr.aspath) { | |
1318 | printf("aspath should be NULL, but is: %s\n", attr.aspath->str); | |
1319 | failed++; | |
1320 | } | |
50ef565e PJ |
1321 | |
1322 | out: | |
d62a17ae | 1323 | if (attr.aspath) |
1324 | aspath_unintern(&attr.aspath); | |
1325 | if (asp) | |
1326 | aspath_unintern(&asp); | |
1327 | return failed - initfail; | |
50ef565e PJ |
1328 | } |
1329 | ||
d62a17ae | 1330 | static void attr_test(struct aspath_tests *t) |
50ef565e | 1331 | { |
d62a17ae | 1332 | printf("%s\n", t->desc); |
1333 | printf("%s\n\n", handle_attr_test(t) ? FAILED : OK); | |
50ef565e PJ |
1334 | } |
1335 | ||
d62a17ae | 1336 | int main(void) |
1f377b02 | 1337 | { |
d62a17ae | 1338 | int i = 0; |
1339 | qobj_init(); | |
1340 | bgp_master_init(thread_master_create(NULL)); | |
1341 | master = bm->master; | |
1342 | bgp_option_set(BGP_OPT_NO_LISTEN); | |
1343 | bgp_attr_init(); | |
1344 | ||
1345 | while (test_segments[i].name) { | |
1346 | printf("test %u\n", i); | |
1347 | parse_test(&test_segments[i]); | |
1348 | empty_prepend_test(&test_segments[i++]); | |
1349 | } | |
1350 | ||
1351 | i = 0; | |
1352 | while (prepend_tests[i].test1) { | |
1353 | printf("prepend test %u\n", i); | |
1354 | prepend_test(&prepend_tests[i++]); | |
1355 | } | |
1356 | ||
1357 | i = 0; | |
1358 | while (aggregate_tests[i].test1) { | |
1359 | printf("aggregate test %u\n", i); | |
1360 | aggregate_test(&aggregate_tests[i++]); | |
1361 | } | |
1362 | ||
1363 | i = 0; | |
1364 | ||
1365 | while (reconcile_tests[i].test1) { | |
1366 | printf("reconcile test %u\n", i); | |
1367 | as4_reconcile_test(&reconcile_tests[i++]); | |
1368 | } | |
1369 | ||
1370 | i = 0; | |
1371 | ||
1372 | cmp_test(); | |
1373 | ||
1374 | i = 0; | |
1375 | ||
1376 | empty_get_test(); | |
1377 | ||
1378 | i = 0; | |
1379 | ||
1380 | while (aspath_tests[i].desc) { | |
1381 | printf("aspath_attr test %d\n", i); | |
1382 | attr_test(&aspath_tests[i++]); | |
1383 | } | |
1384 | ||
1385 | printf("failures: %d\n", failed); | |
1386 | printf("aspath count: %ld\n", aspath_count()); | |
1387 | ||
1388 | return (failed + aspath_count()); | |
1f377b02 | 1389 | } |