9 #include "bgpd/bgp_ecommunity.h"
11 /* need these to link in libbgp */
12 struct zebra_privs_t
*bgpd_privs
= NULL
;
13 struct thread_master
*master
= NULL
;
15 static int failed
= 0;
17 /* specification for a test - what the results should be */
20 const char *shouldbe
; /* the string the path should parse to */
24 /* test segments to parse and validate, and use for other tests */
25 static struct test_segment
{
28 const u_char data
[1024];
36 { ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_ROUTE_TARGET
,
37 0x1,0x2,0x3,0x4, 0x1,0x1 },
44 { ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_SITE_ORIGIN
,
45 0x1,0x2,0x3,0x4, 0x1,0x1},
52 { ECOMMUNITY_ENCODE_AS
, ECOMMUNITY_SITE_ORIGIN
,
53 0x5b,0xa0, 0x3a,0xde,0x68,0xb1 },
55 { "soo 23456:987654321" }
60 { ECOMMUNITY_ENCODE_AS4
, ECOMMUNITY_SITE_ORIGIN
,
61 0xa,0xa,0x5b,0xa0, 0x10,0xe1 },
63 { "soo 168450976:4321" }
65 { NULL
, NULL
, {0}, 0, { NULL
} }
69 /* validate the given aspath */
71 validate (struct ecommunity
*ecom
, const struct test_spec
*sp
)
74 struct ecommunity
*etmp
;
77 printf ("got:\n %s\n", ecommunity_str (ecom
));
78 str1
= ecommunity_ecom2str (ecom
, ECOMMUNITY_FORMAT_COMMUNITY_LIST
);
79 etmp
= ecommunity_str2com (str1
, 0, 1);
81 str2
= ecommunity_ecom2str (etmp
, ECOMMUNITY_FORMAT_COMMUNITY_LIST
);
85 if (strcmp (sp
->shouldbe
, str1
))
89 printf ("shouldbe: %s\n%s\n", str1
, sp
->shouldbe
);
91 if (!etmp
|| strcmp (str1
, str2
))
95 printf ("dogfood: in %s\n"
98 (etmp
&& str2
) ? str2
: "NULL");
100 ecommunity_free (etmp
);
101 XFREE (MTYPE_ECOMMUNITY_STR
, str1
);
102 XFREE (MTYPE_ECOMMUNITY_STR
, str2
);
107 /* basic parsing test */
109 parse_test (struct test_segment
*t
)
111 struct ecommunity
*ecom
;
113 printf ("%s: %s\n", t
->name
, t
->desc
);
115 ecom
= ecommunity_parse (t
->data
, t
->len
);
117 printf ("ecom: %s\nvalidating...:\n", ecommunity_str (ecom
));
119 if (!validate (ecom
, &t
->sp
))
125 ecommunity_unintern (ecom
);
134 while (test_segments
[i
].name
)
135 parse_test (&test_segments
[i
++]);
137 printf ("failures: %d\n", failed
);
138 //printf ("aspath count: %ld\n", aspath_count());
140 //return (failed + aspath_count());