10 #include "bgpd/bgp_ecommunity.h"
12 /* need these to link in libbgp */
13 struct zebra_privs_t
*bgpd_privs
= NULL
;
14 struct thread_master
*master
= NULL
;
16 static int failed
= 0;
18 /* specification for a test - what the results should be */
21 const char *shouldbe
; /* the string the path should parse to */
25 /* test segments to parse and validate, and use for other tests */
26 static struct test_segment
{
29 const u_int8_t data
[1024];
37 { ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_ROUTE_TARGET
,
38 0x1,0x2,0x3,0x4, 0x1,0x1 },
45 { ECOMMUNITY_ENCODE_IP
, ECOMMUNITY_SITE_ORIGIN
,
46 0x1,0x2,0x3,0x4, 0x1,0x1},
53 { ECOMMUNITY_ENCODE_AS
, ECOMMUNITY_SITE_ORIGIN
,
54 0x5b,0xa0, 0x3a,0xde,0x68,0xb1 },
56 { "soo 23456:987654321" }
61 { ECOMMUNITY_ENCODE_AS4
, ECOMMUNITY_SITE_ORIGIN
,
62 0xa,0xa,0x5b,0xa0, 0x10,0xe1 },
64 { "soo 168450976:4321" }
66 { NULL
, NULL
, {0}, 0, { NULL
} }
70 /* validate the given aspath */
72 validate (struct ecommunity
*ecom
, const struct test_spec
*sp
)
75 struct ecommunity
*etmp
;
78 printf ("got:\n %s\n", ecommunity_str (ecom
));
79 str1
= ecommunity_ecom2str (ecom
, ECOMMUNITY_FORMAT_COMMUNITY_LIST
);
80 etmp
= ecommunity_str2com (str1
, 0, 1);
82 str2
= ecommunity_ecom2str (etmp
, ECOMMUNITY_FORMAT_COMMUNITY_LIST
);
86 if (strcmp (sp
->shouldbe
, str1
))
90 printf ("shouldbe: %s\n%s\n", str1
, sp
->shouldbe
);
92 if (!etmp
|| strcmp (str1
, str2
))
96 printf ("dogfood: in %s\n"
99 (etmp
&& str2
) ? str2
: "NULL");
101 ecommunity_free (&etmp
);
102 XFREE (MTYPE_ECOMMUNITY_STR
, str1
);
103 XFREE (MTYPE_ECOMMUNITY_STR
, str2
);
108 /* basic parsing test */
110 parse_test (struct test_segment
*t
)
112 struct ecommunity
*ecom
;
114 printf ("%s: %s\n", t
->name
, t
->desc
);
116 ecom
= ecommunity_parse (t
->data
, t
->len
);
118 printf ("ecom: %s\nvalidating...:\n", ecommunity_str (ecom
));
120 if (!validate (ecom
, &t
->sp
))
126 ecommunity_unintern (&ecom
);
135 while (test_segments
[i
].name
)
136 parse_test (&test_segments
[i
++]);
138 printf ("failures: %d\n", failed
);
139 //printf ("aspath count: %ld\n", aspath_count());
141 //return (failed + aspath_count());