2 * Copyright (C) 2007 Sun Microsystems, Inc.
4 * This file is part of Quagga.
6 * Quagga is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * Quagga is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "bgpd/bgpd.h"
30 #include "bgpd/bgp_ecommunity.h"
32 /* need these to link in libbgp */
33 struct zebra_privs_t
*bgpd_privs
= NULL
;
34 struct thread_master
*master
= NULL
;
36 static int failed
= 0;
38 /* specification for a test - what the results should be */
40 const char *shouldbe
; /* the string the path should parse to */
44 /* test segments to parse and validate, and use for other tests */
45 static struct test_segment
{
48 const uint8_t data
[1024];
51 } test_segments
[] = {{/* 0 */
54 {ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_ROUTE_TARGET
, 0x1, 0x2,
61 {ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_SITE_ORIGIN
, 0x1, 0x2,
68 {ECOMMUNITY_ENCODE_AS
, ECOMMUNITY_SITE_ORIGIN
, 0x5b, 0xa0,
69 0x3a, 0xde, 0x68, 0xb1},
71 {"soo 23456:987654321"}},
75 {ECOMMUNITY_ENCODE_AS4
, ECOMMUNITY_SITE_ORIGIN
, 0xa, 0xa,
76 0x5b, 0xa0, 0x10, 0xe1},
78 {"soo 168450976:4321"}},
79 {NULL
, NULL
, {0}, 0, {NULL
}}};
82 /* validate the given aspath */
83 static int validate(struct ecommunity
*ecom
, const struct test_spec
*sp
)
86 struct ecommunity
*etmp
;
89 printf("got:\n %s\n", ecommunity_str(ecom
));
90 str1
= ecommunity_ecom2str(ecom
, ECOMMUNITY_FORMAT_COMMUNITY_LIST
, 0);
91 etmp
= ecommunity_str2com(str1
, 0, 1);
93 str2
= ecommunity_ecom2str(etmp
,
94 ECOMMUNITY_FORMAT_COMMUNITY_LIST
, 0);
98 if (strcmp(sp
->shouldbe
, str1
)) {
101 printf("shouldbe: %s\n%s\n", str1
, sp
->shouldbe
);
103 if (!etmp
|| strcmp(str1
, str2
)) {
106 printf("dogfood: in %s\n"
108 str1
, (etmp
&& str2
) ? str2
: "NULL");
110 ecommunity_free(&etmp
);
111 XFREE(MTYPE_ECOMMUNITY_STR
, str1
);
112 XFREE(MTYPE_ECOMMUNITY_STR
, str2
);
117 /* basic parsing test */
118 static void parse_test(struct test_segment
*t
)
120 struct ecommunity
*ecom
;
122 printf("%s: %s\n", t
->name
, t
->desc
);
124 ecom
= ecommunity_parse((uint8_t *)t
->data
, t
->len
, 0);
126 printf("ecom: %s\nvalidating...:\n", ecommunity_str(ecom
));
128 if (!validate(ecom
, &t
->sp
))
134 ecommunity_unintern(&ecom
);
142 while (test_segments
[i
].name
)
143 parse_test(&test_segments
[i
++]);
145 printf("failures: %d\n", failed
);
146 // printf ("aspath count: %ld\n", aspath_count());
148 // return (failed + aspath_count());