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