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