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
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_ecommunity.h"
33 /* need these to link in libbgp */
34 struct zebra_privs_t
*bgpd_privs
= NULL
;
35 struct thread_master
*master
= NULL
;
37 static int failed
= 0;
39 /* specification for a test - what the results should be */
41 const char *shouldbe
; /* the string the path should parse to */
45 /* test segments to parse and validate, and use for other tests */
46 static struct test_segment
{
49 const u_int8_t data
[1024];
52 } test_segments
[] = {{/* 0 */
55 {ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_ROUTE_TARGET
, 0x1, 0x2,
62 {ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_SITE_ORIGIN
, 0x1, 0x2,
69 {ECOMMUNITY_ENCODE_AS
, ECOMMUNITY_SITE_ORIGIN
, 0x5b, 0xa0,
70 0x3a, 0xde, 0x68, 0xb1},
72 {"soo 23456:987654321"}},
76 {ECOMMUNITY_ENCODE_AS4
, ECOMMUNITY_SITE_ORIGIN
, 0xa, 0xa,
77 0x5b, 0xa0, 0x10, 0xe1},
79 {"soo 168450976:4321"}},
80 {NULL
, NULL
, {0}, 0, {NULL
}}};
83 /* validate the given aspath */
84 static int validate(struct ecommunity
*ecom
, const struct test_spec
*sp
)
87 struct ecommunity
*etmp
;
90 printf("got:\n %s\n", ecommunity_str(ecom
));
91 str1
= ecommunity_ecom2str(ecom
, ECOMMUNITY_FORMAT_COMMUNITY_LIST
, 0);
92 etmp
= ecommunity_str2com(str1
, 0, 1);
94 str2
= ecommunity_ecom2str(etmp
,
95 ECOMMUNITY_FORMAT_COMMUNITY_LIST
, 0);
99 if (strcmp(sp
->shouldbe
, str1
)) {
102 printf("shouldbe: %s\n%s\n", str1
, sp
->shouldbe
);
104 if (!etmp
|| strcmp(str1
, str2
)) {
107 printf("dogfood: in %s\n"
109 str1
, (etmp
&& str2
) ? str2
: "NULL");
111 ecommunity_free(&etmp
);
112 XFREE(MTYPE_ECOMMUNITY_STR
, str1
);
113 XFREE(MTYPE_ECOMMUNITY_STR
, str2
);
118 /* basic parsing test */
119 static void parse_test(struct test_segment
*t
)
121 struct ecommunity
*ecom
;
123 printf("%s: %s\n", t
->name
, t
->desc
);
125 ecom
= ecommunity_parse((u_int8_t
*)t
->data
, t
->len
);
127 printf("ecom: %s\nvalidating...:\n", ecommunity_str(ecom
));
129 if (!validate(ecom
, &t
->sp
))
135 ecommunity_unintern(&ecom
);
143 while (test_segments
[i
].name
)
144 parse_test(&test_segments
[i
++]);
146 printf("failures: %d\n", failed
);
147 // printf ("aspath count: %ld\n", aspath_count());
149 // return (failed + aspath_count());