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 */
42 const char *shouldbe
; /* the string the path should parse to */
46 /* test segments to parse and validate, and use for other tests */
47 static struct test_segment
{
50 const u_int8_t data
[1024];
58 { ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_ROUTE_TARGET
,
59 0x1,0x2,0x3,0x4, 0x1,0x1 },
66 { ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_SITE_ORIGIN
,
67 0x1,0x2,0x3,0x4, 0x1,0x1},
74 { ECOMMUNITY_ENCODE_AS
, ECOMMUNITY_SITE_ORIGIN
,
75 0x5b,0xa0, 0x3a,0xde,0x68,0xb1 },
77 { "soo 23456:987654321" }
82 { ECOMMUNITY_ENCODE_AS4
, ECOMMUNITY_SITE_ORIGIN
,
83 0xa,0xa,0x5b,0xa0, 0x10,0xe1 },
85 { "soo 168450976:4321" }
87 { NULL
, NULL
, {0}, 0, { NULL
} }
91 /* validate the given aspath */
93 validate (struct ecommunity
*ecom
, const struct test_spec
*sp
)
96 struct ecommunity
*etmp
;
99 printf ("got:\n %s\n", ecommunity_str (ecom
));
100 str1
= ecommunity_ecom2str (ecom
, ECOMMUNITY_FORMAT_COMMUNITY_LIST
, 0);
101 etmp
= ecommunity_str2com (str1
, 0, 1);
103 str2
= ecommunity_ecom2str (etmp
, ECOMMUNITY_FORMAT_COMMUNITY_LIST
, 0);
107 if (strcmp (sp
->shouldbe
, str1
))
111 printf ("shouldbe: %s\n%s\n", str1
, sp
->shouldbe
);
113 if (!etmp
|| strcmp (str1
, str2
))
117 printf ("dogfood: in %s\n"
120 (etmp
&& str2
) ? str2
: "NULL");
122 ecommunity_free (&etmp
);
123 XFREE (MTYPE_ECOMMUNITY_STR
, str1
);
124 XFREE (MTYPE_ECOMMUNITY_STR
, str2
);
129 /* basic parsing test */
131 parse_test (struct test_segment
*t
)
133 struct ecommunity
*ecom
;
135 printf ("%s: %s\n", t
->name
, t
->desc
);
137 ecom
= ecommunity_parse ((u_int8_t
*)t
->data
, t
->len
);
139 printf ("ecom: %s\nvalidating...:\n", ecommunity_str (ecom
));
141 if (!validate (ecom
, &t
->sp
))
147 ecommunity_unintern (&ecom
);
156 while (test_segments
[i
].name
)
157 parse_test (&test_segments
[i
++]);
159 printf ("failures: %d\n", failed
);
160 //printf ("aspath count: %ld\n", aspath_count());
162 //return (failed + aspath_count());