2 * Copyright (C) 2008 Sun Microsystems, Inc.
4 * This file is part of Quagga.
6 * Quagga is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * Quagga is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Quagga; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 #include "bgpd/bgpd.h"
31 #include "bgpd/bgp_attr.h"
32 #include "bgpd/bgp_open.h"
33 #include "bgpd/bgp_debug.h"
34 #include "bgpd/bgp_route.h"
35 #include "bgpd/bgp_packet.h"
36 #include "bgpd/bgp_mplsvpn.h"
37 #include "bgpd/bgp_nexthop.h"
39 #define VT100_RESET "\x1b[0m"
40 #define VT100_RED "\x1b[31m"
41 #define VT100_GREEN "\x1b[32m"
42 #define VT100_YELLOW "\x1b[33m"
49 /* need these to link in libbgp */
50 struct zebra_privs_t *bgpd_privs = NULL;
51 struct thread_master *master = NULL;
53 static int failed = 0;
56 /* test segments to parse and validate, and use for other tests */
57 static struct test_segment {
60 const u_char data[1024];
62 #define SHOULD_PARSE 0
64 int parses; /* whether it should parse or not */
66 /* AFI/SAFI validation */
72 } mp_reach_segments [] =
75 "IPV6 MP Reach, global nexthop, 1 NLRI",
77 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
78 /* nexthop bytes */ 16,
79 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2,
80 0xaa, 0xbb, 0xcc, 0xdd,
82 0xa1, 0xa2, 0xa3, 0xa4,
83 /* SNPA (defunct, MBZ) */ 0x0,
84 /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
88 AFI_IP6, SAFI_UNICAST, VALID_AFI,
91 "IPV6 MP Reach, global nexthop, 2 NLRIs",
93 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
94 /* nexthop bytes */ 16,
95 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* ffee:102:... */
96 0xaa, 0xbb, 0xcc, 0xdd,
98 0xa1, 0xa2, 0xa3, 0xa4,
99 /* SNPA (defunct, MBZ) */ 0x0,
100 /* NLRI tuples */ 32,
101 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
103 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
106 (4 + 16 + 1 + 5 + 9),
108 AFI_IP6, SAFI_UNICAST, VALID_AFI,
111 "IPV6 MP Reach, global nexthop, 2 NLRIs + default",
113 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
114 /* nexthop bytes */ 16,
115 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2,
116 0xaa, 0xbb, 0xcc, 0xdd,
118 0xa1, 0xa2, 0xa3, 0xa4,
119 /* SNPA (defunct, MBZ) */ 0x0,
120 /* NLRI tuples */ 32,
121 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
123 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
127 (4 + 16 + 1 + 5 + 9 + 1),
129 AFI_IP6, SAFI_UNICAST, VALID_AFI,
132 "IPV6 MP Reach, global+local nexthops, 2 NLRIs + default",
134 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
135 /* nexthop bytes */ 32,
136 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
137 0xaa, 0xbb, 0xcc, 0xdd,
139 0xa1, 0xa2, 0xa3, 0xa4,
140 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
142 0x2, 0x10, 0x2, 0xff,
144 /* SNPA (defunct, MBZ) */ 0x0,
145 /* NLRI tuples */ 32,
146 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
148 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
152 (4 + 32 + 1 + 5 + 9 + 1),
154 AFI_IP6, SAFI_UNICAST, VALID_AFI,
157 "IPV6 MP Reach, inappropriate nexthop length",
159 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
160 /* nexthop bytes */ 4,
161 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
162 0xaa, 0xbb, 0xcc, 0xdd,
164 0xa1, 0xa2, 0xa3, 0xa4,
165 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
167 0x2, 0x10, 0x2, 0xff,
169 /* SNPA (defunct, MBZ) */ 0x0,
170 /* NLRI tuples */ 32,
171 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
173 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
177 (4 + 32 + 1 + 5 + 9 + 1),
179 AFI_IP6, SAFI_UNICAST, VALID_AFI,
182 "IPV6 MP Reach, invalid nexthop length",
184 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
185 /* nexthop bytes */ 5,
186 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
187 0xaa, 0xbb, 0xcc, 0xdd,
189 0xa1, 0xa2, 0xa3, 0xa4,
190 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
192 0x2, 0x10, 0x2, 0xff,
194 /* SNPA (defunct, MBZ) */ 0x0,
195 /* NLRI tuples */ 32,
196 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
198 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
202 (4 + 32 + 1 + 5 + 9 + 1),
204 AFI_IP6, SAFI_UNICAST, VALID_AFI,
207 "IPV6 MP Reach, nexthop length overflow",
209 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
210 /* nexthop bytes */ 32,
211 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
212 0xaa, 0xbb, 0xcc, 0xdd,
214 0xa1, 0xa2, 0xa3, 0xa4,
218 AFI_IP6, SAFI_UNICAST, VALID_AFI,
221 "IPV6 MP Reach, nexthop length short",
223 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
224 /* nexthop bytes */ 16,
225 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
226 0xaa, 0xbb, 0xcc, 0xdd,
228 0xa1, 0xa2, 0xa3, 0xa4,
229 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
231 0x2, 0x10, 0x2, 0xff,
233 /* SNPA (defunct, MBZ) */ 0x0,
234 /* NLRI tuples */ 32,
235 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
237 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
241 (4 + 32 + 1 + 5 + 9 + 1),
243 AFI_IP6, SAFI_UNICAST, VALID_AFI,
246 "IPV6 MP Reach, NLRI bitlen overflow",
248 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
249 /* nexthop bytes */ 32,
250 /* Nexthop (global) */ 0xff, 0xfe, 0x1, 0x2, /* fffe:102:... */
251 0xaa, 0xbb, 0xcc, 0xdd,
253 0xa1, 0xa2, 0xa3, 0xa4,
254 /* Nexthop (local) */ 0xfe, 0x80, 0x0, 0x0, /* fe80::210:2ff:.. */
256 0x2, 0x10, 0x2, 0xff,
258 /* SNPA (defunct, MBZ) */ 0x0,
259 /* NLRI tuples */ 120,
260 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
262 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
266 (4 + 32 + 1 + 5 + 9 + 1),
268 AFI_IP6, SAFI_UNICAST, VALID_AFI,
271 "IPv4 MP Reach, 2 NLRIs + default",
273 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
274 /* nexthop bytes */ 4,
275 /* Nexthop */ 192, 168, 0, 1,
276 /* SNPA (defunct, MBZ) */ 0x0,
277 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
278 17, 10, 2, 3, /* 10.2.3/17 */
281 (4 + 4 + 1 + 3 + 4 + 1),
283 AFI_IP, SAFI_UNICAST, VALID_AFI,
286 "IPv4 MP Reach, nexthop lenth overflow",
288 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
289 /* nexthop bytes */ 32,
290 /* Nexthop */ 192, 168, 0, 1,
291 /* SNPA (defunct, MBZ) */ 0x0,
292 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
293 17, 10, 2, 3, /* 10.2.3/17 */
296 (4 + 4 + 1 + 3 + 4 + 1),
298 AFI_IP, SAFI_UNICAST, VALID_AFI,
301 "IPv4 MP Reach, nlri lenth overflow",
303 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
304 /* nexthop bytes */ 4,
305 /* Nexthop */ 192, 168, 0, 1,
306 /* SNPA (defunct, MBZ) */ 0x0,
307 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
311 (4 + 4 + 1 + 3 + 2 + 1),
313 AFI_IP, SAFI_UNICAST, VALID_AFI,
316 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs",
318 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
319 /* nexthop bytes */ 12,
320 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
322 /* Nexthop */ 192, 168, 0, 1,
323 /* SNPA (defunct, MBZ) */ 0x0,
324 /* NLRI tuples */ 88 + 16,
327 0, 0, /* RD_TYPE_AS */
328 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
331 0xff, 0, 0, /* tag */
333 0, 0, /* RD_TYPE_IP */
334 192, 168, 0, 1, /* IPv4 */
335 10, 2, 3, /* 10.2.3/17 */
337 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
339 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
341 { "IPv4-VPNv4-bogus-plen",
342 "IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len",
344 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
345 /* nexthop bytes */ 12,
348 /* Nexthop */ 192, 168, 0, 1,
349 /* SNPA (defunct, MBZ) */ 0x0,
350 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
351 17, 10, 2, 3, /* 10.2.3/17 */
354 (3 + 1 + 3*4 + 1 + 3 + 4 + 1),
356 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
358 { "IPv4-VPNv4-plen1-short",
359 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short",
361 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
362 /* nexthop bytes */ 12,
363 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
365 /* Nexthop */ 192, 168, 0, 1,
366 /* SNPA (defunct, MBZ) */ 0x0,
367 /* NLRI tuples */ 88 + 1,
370 0, 0, /* RD_TYPE_AS */
371 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
374 0xff, 0, 0, /* tag */
376 0, 0, /* RD_TYPE_IP */
377 192, 168, 0, 1, /* IPv4 */
378 10, 2, 3, /* 10.2.3/17 */
380 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
382 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
384 { "IPv4-VPNv4-plen1-long",
385 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long",
387 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
388 /* nexthop bytes */ 12,
389 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
391 /* Nexthop */ 192, 168, 0, 1,
392 /* SNPA (defunct, MBZ) */ 0x0,
393 /* NLRI tuples */ 88 + 32,
396 0, 0, /* RD_TYPE_AS */
397 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
400 0xff, 0, 0, /* tag */
402 0, 0, /* RD_TYPE_IP */
403 192, 168, 0, 1, /* IPv4 */
404 10, 2, 3, /* 10.2.3/17 */
406 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
408 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
410 { "IPv4-VPNv4-plenn-long",
411 "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long",
413 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
414 /* nexthop bytes */ 12,
415 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
417 /* Nexthop */ 192, 168, 0, 1,
418 /* SNPA (defunct, MBZ) */ 0x0,
419 /* NLRI tuples */ 88 + 16,
422 0, 0, /* RD_TYPE_AS */
423 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
426 0xff, 0, 0, /* tag */
428 0, 0, /* RD_TYPE_IP */
429 192, 168, 0, 1, /* IPv4 */
430 10, 2, 3, /* 10.2.3/17 */
433 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1),
435 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
437 { "IPv4-VPNv4-plenn-short",
438 "IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short",
440 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
441 /* nexthop bytes */ 12,
442 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
444 /* Nexthop */ 192, 168, 0, 1,
445 /* SNPA (defunct, MBZ) */ 0x0,
446 /* NLRI tuples */ 88 + 16,
449 0, 0, /* RD_TYPE_AS */
450 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
453 0xff, 0, 0, /* tag */
455 0, 0, /* RD_TYPE_IP */
456 192, 168, 0, 1, /* IPv4 */
457 10, 2, 3, /* 10.2.3/17 */
459 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
461 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
463 { "IPv4-VPNv4-bogus-rd-type",
464 "IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)",
466 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
467 /* nexthop bytes */ 12,
468 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
470 /* Nexthop */ 192, 168, 0, 1,
471 /* SNPA (defunct, MBZ) */ 0x0,
472 /* NLRI tuples */ 88 + 16,
475 0xff, 0, /* Bogus RD */
476 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
479 0xff, 0, 0, /* tag */
481 0, 0, /* RD_TYPE_IP */
482 192, 168, 0, 1, /* IPv4 */
483 10, 2, 3, /* 10.2.3/17 */
485 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3)),
487 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
489 { "IPv4-VPNv4-0-nlri",
490 "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus",
492 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
493 /* nexthop bytes */ 12,
494 /* RD */ 0, 0, 0, 0, /* RD defined to be 0 */
496 /* Nexthop */ 192, 168, 0, 1,
497 /* SNPA (defunct, MBZ) */ 0x0,
498 /* NLRI tuples */ 88 + 16,
501 0, 0, /* RD_TYPE_AS */
502 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
505 0xff, 0, 0, /* tag */
507 0, 0, /* RD_TYPE_IP */
508 192, 168, 0, 1, /* IPv4 */
509 10, 2, 3, /* 10.2.3/17 */
510 0 /* 0/0, bogus for vpnv4 ?? */
512 (4 + 12 + 1 + (1+3+8+2) + (1+3+8+3) + 1),
514 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
519 "IPv6, global nexthop, 1 default NLRI",
521 /* AFI / SAFI */ 0x0, 0x2, 0x1,
522 /* nexthop bytes */ 0x20,
523 /* Nexthop (global) */ 0x20, 0x01, 0x04, 0x70,
524 0x00, 0x01, 0x00, 0x06,
525 0x00, 0x00, 0x00, 0x00,
526 0x00, 0x00, 0x00, 0x01,
527 /* Nexthop (local) */ 0xfe, 0x80, 0x00, 0x00,
528 0x00, 0x00, 0x00, 0x00,
529 0x02, 0x0c, 0xdb, 0xff,
530 0xfe, 0xfe, 0xeb, 0x00,
531 /* SNPA (defunct, MBZ) */ 0,
532 /* NLRI tuples */ /* Should have 0 here for ::/0, but dont */
536 AFI_IP6, SAFI_UNICAST, VALID_AFI,
539 { NULL, NULL, {0}, 0, 0}
542 /* MP_UNREACH_NLRI tests */
543 static struct test_segment mp_unreach_segments [] =
546 "IPV6 MP Unreach, 1 NLRI",
548 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
549 /* NLRI tuples */ 32, 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
553 AFI_IP6, SAFI_UNICAST, VALID_AFI,
556 "IPV6 MP Unreach, 2 NLRIs",
558 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
559 /* NLRI tuples */ 32,
560 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
562 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
567 AFI_IP6, SAFI_UNICAST, VALID_AFI,
569 { "IPv6-unreach-default",
570 "IPV6 MP Unreach, 2 NLRIs + default",
572 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
573 /* NLRI tuples */ 32,
574 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
576 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
582 AFI_IP6, SAFI_UNICAST, VALID_AFI,
584 { "IPv6-unreach-nlri",
585 "IPV6 MP Unreach, NLRI bitlen overflow",
587 /* AFI / SAFI */ 0x0, AFI_IP6, SAFI_UNICAST,
588 /* NLRI tuples */ 120,
589 0xff, 0xfe, 0x1, 0x2, /* fffe:102::/32 */
591 0xff, 0xfe, 0x0, 0x1, /* fffe:1:2:3::/64 */
597 AFI_IP6, SAFI_UNICAST, VALID_AFI,
600 "IPv4 MP Unreach, 2 NLRIs + default",
602 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
603 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
604 17, 10, 2, 3, /* 10.2.3/17 */
609 AFI_IP, SAFI_UNICAST, VALID_AFI,
611 { "IPv4-unreach-nlrilen",
612 "IPv4 MP Unreach, nlri length overflow",
614 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_UNICAST,
615 /* NLRI tuples */ 16, 10, 1, /* 10.1/16 */
621 AFI_IP, SAFI_UNICAST, VALID_AFI,
623 { "IPv4-unreach-VPNv4",
624 "IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs",
626 /* AFI / SAFI */ 0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
627 /* NLRI tuples */ 88 + 16,
630 0, 0, /* RD_TYPE_AS */
631 0, 2, 0, 0xff, 3, 4, /* AS(2):val(4) */
634 0xff, 0, 0, /* tag */
636 0, 0, /* RD_TYPE_IP */
637 192, 168, 0, 1, /* IPv4 */
638 10, 2, 3, /* 10.2.3/17 */
640 (3 + (1+3+8+2) + (1+3+8+3)),
642 AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
644 { NULL, NULL, {0}, 0, 0}
647 /* nlri_parse indicates 0 on successful parse, and -1 otherwise.
648 * attr_parse indicates BGP_ATTR_PARSE_PROCEED/0 on success,
649 * and BGP_ATTR_PARSE_ERROR/-1 or lower negative ret on err.
652 handle_result (struct peer *peer, struct test_segment *t,
653 int parse_ret, int nlri_ret)
655 int oldfailed = failed;
659 safi_t safi = t->safi;
661 if (bgp_afi_safi_valid_indices (t->afi, &safi) != t->afi_valid)
664 printf ("MP: %u/%u (%u): recv %u, nego %u\n",
665 t->afi, t->safi, safi,
666 peer->afc_recv[t->afi][safi],
667 peer->afc_nego[t->afi][safi]);
670 printf ("mp attr parsed?: %s\n", parse_ret ? "no" : "yes");
672 printf ("nrli parsed?: %s\n", nlri_ret ? "no" : "yes");
673 printf ("should parse?: %s\n", t->parses ? "no" : "yes");
675 if ((parse_ret != 0 || nlri_ret != 0) != (t->parses != 0))
680 printf ("%s", (failed > oldfailed) ? VT100_RED "failed!" VT100_RESET
681 : VT100_GREEN "OK" VT100_RESET);
683 printf ("%s", (failed > oldfailed) ? "failed!" : "OK" );
686 printf (" (%u)", failed);
691 /* basic parsing test */
693 parse_test (struct peer *peer, struct test_segment *t, int type)
695 int parse_ret = 0, nlri_ret = 0;
696 struct attr attr = { };
697 struct bgp_nlri nlri = { };
698 struct bgp_attr_parser_args attr_args = {
704 .flags = BGP_ATTR_FLAG_OPTIONAL,
705 .startp = BGP_INPUT_PNT (peer),
707 #define RANDOM_FUZZ 35
709 stream_reset (peer->ibuf);
710 stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
711 stream_set_getp (peer->ibuf, RANDOM_FUZZ);
713 stream_write (peer->ibuf, t->data, t->len);
715 printf ("%s: %s\n", t->name, t->desc);
717 if (type == BGP_ATTR_MP_REACH_NLRI)
718 parse_ret = bgp_mp_reach_parse (&attr_args, &nlri);
720 parse_ret = bgp_mp_unreach_parse (&attr_args, &nlri);
722 if (parse_ret == 0 && t->afi_valid == VALID_AFI)
723 assert (nlri.afi == t->afi && nlri.safi == t->safi);
727 if (type == BGP_ATTR_MP_REACH_NLRI)
728 nlri_ret = bgp_nlri_parse (peer, &attr, &nlri);
730 nlri_ret = bgp_nlri_parse (peer, NULL, &nlri);
733 handle_result (peer, t, parse_ret, nlri_ret);
736 static struct bgp *bgp;
737 static as_t asn = 100;
745 conf_bgp_debug_fsm = -1UL;
746 conf_bgp_debug_events = -1UL;
747 conf_bgp_debug_packet = -1UL;
748 conf_bgp_debug_normal = -1UL;
749 conf_bgp_debug_as4 = -1UL;
750 term_bgp_debug_fsm = -1UL;
751 term_bgp_debug_events = -1UL;
752 term_bgp_debug_packet = -1UL;
753 term_bgp_debug_normal = -1UL;
754 term_bgp_debug_as4 = -1UL;
756 master = thread_master_create ();
758 bgp_option_set (BGP_OPT_NO_LISTEN);
763 if (fileno (stdout) >= 0)
764 tty = isatty (fileno (stdout));
766 if (bgp_get (&bgp, &asn, NULL))
769 peer = peer_create_accept (bgp);
770 peer->host = (char *)"foo";
771 peer->status = Established;
773 for (i = AFI_IP; i < AFI_MAX; i++)
774 for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
777 peer->afc_adv[i][j] = 1;
781 while (mp_reach_segments[i].name)
782 parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI);
785 while (mp_unreach_segments[i].name)
786 parse_test (peer, &mp_unreach_segments[i++], BGP_ATTR_MP_UNREACH_NLRI);
788 printf ("failures: %d\n", failed);