--- embedaddon/quagga/tests/aspath_test.c 2012/02/21 17:26:11 1.1.1.1 +++ embedaddon/quagga/tests/aspath_test.c 2016/11/02 10:09:12 1.1.1.3 @@ -1,8 +1,30 @@ +/* + * Copyright (C) 2005 Sun Microsystems, Inc. + * + * This file is part of Quagga. + * + * Quagga is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * Quagga is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Quagga; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + #include #include "vty.h" #include "stream.h" #include "privs.h" +#include "filter.h" #include "bgpd/bgpd.h" #include "bgpd/bgp_aspath.h" @@ -432,6 +454,16 @@ static struct test_segment { }, { NULL, NULL, {0}, 0, { NULL, 0, 0 } } }; +#define COMMON_ATTRS \ + BGP_ATTR_FLAG_TRANS, \ + BGP_ATTR_ORIGIN, \ + 1, \ + BGP_ORIGIN_EGP, \ + BGP_ATTR_FLAG_TRANS, \ + BGP_ATTR_NEXT_HOP, \ + 4, 192, 0, 2, 0 +#define COMMON_ATTR_SIZE 11 + /* */ static struct aspath_tests { const char *desc; @@ -443,6 +475,7 @@ static struct aspath_tests { const int cap; /* capabilities to set for peer */ const char attrheader [1024]; size_t len; + const struct test_segment *old_segment; } aspath_tests [] = { /* 0 */ @@ -452,11 +485,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS2_DATA, 0, 0, - { BGP_ATTR_FLAG_TRANS, - BGP_ATTR_AS_PATH, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS, + BGP_ATTR_AS_PATH, 10, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 1 */ { @@ -465,11 +499,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS2_DATA, -1, 0, - { BGP_ATTR_FLAG_TRANS, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 8, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 2 */ { @@ -478,11 +513,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS2_DATA, -1, 0, - { BGP_ATTR_FLAG_TRANS, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 12, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 3 */ { @@ -491,11 +527,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS2_DATA, -1, 0, - { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, BGP_ATTR_AS_PATH, 10, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 4 */ { @@ -504,11 +541,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS2_DATA, -1, 0, - { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, BGP_ATTR_AS4_PATH, 10, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 5 */ { @@ -517,11 +555,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS4_DATA, -1, PEER_CAP_AS4_RCV, - { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, BGP_ATTR_AS4_PATH, 10, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 6 */ { @@ -530,11 +569,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS4_DATA, 0, PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, - { BGP_ATTR_FLAG_TRANS, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 18, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 7 */ { @@ -543,11 +583,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS4_DATA, -1, PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, - { BGP_ATTR_FLAG_TRANS, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 16, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 8 */ { @@ -556,11 +597,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS4_DATA, -1, PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, - { BGP_ATTR_FLAG_TRANS, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 20, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 9 */ { @@ -569,11 +611,12 @@ static struct aspath_tests { "8466 3 52737 4096", AS4_DATA, -1, PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, - { BGP_ATTR_FLAG_TRANS, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, 22, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 10 */ { @@ -582,25 +625,42 @@ static struct aspath_tests { "8466 3 52737 4096", AS4_DATA, -1, PEER_CAP_AS4_RCV|PEER_CAP_AS4_ADV, - { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, BGP_ATTR_AS_PATH, 18, }, - 3, + COMMON_ATTR_SIZE + 3, }, /* 11 */ { - "4b AS_PATH: confed", + "4b AS4_PATH w/o AS_PATH", &test_segments[6], - "8466 3 52737 4096", + NULL, AS4_DATA, -1, PEER_CAP_AS4_ADV, - { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, BGP_ATTR_AS4_PATH, 14, }, - 3, + COMMON_ATTR_SIZE + 3, }, + /* 12 */ + { + "4b AS4_PATH: confed", + &test_segments[6], + "8466 3 52737 4096 (123 456 789)", + AS4_DATA, 0, + PEER_CAP_AS4_ADV, + { COMMON_ATTRS, + BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL, + BGP_ATTR_AS4_PATH, + 14, + }, + COMMON_ATTR_SIZE + 3, + &test_segments[0], + }, { NULL, NULL, NULL, 0, 0, 0, { 0 }, 0 }, }; @@ -983,8 +1043,8 @@ validate (struct aspath *as, const struct test_spec *s printf ("private check: %d %d\n", sp->private_as, aspath_private_as_check (as)); } - aspath_unintern (asinout); - aspath_unintern (as4); + aspath_unintern (&asinout); + aspath_unintern (&as4); aspath_free (asconfeddel); aspath_free (asstr); @@ -1030,7 +1090,7 @@ parse_test (struct test_segment *t) printf ("\n"); if (asp) - aspath_unintern (asp); + aspath_unintern (&asp); } /* prepend testing */ @@ -1046,7 +1106,7 @@ prepend_test (struct tests *t) asp2 = make_aspath (t->test2->asdata, t->test2->len, 0); ascratch = aspath_dup (asp2); - aspath_unintern (asp2); + aspath_unintern (&asp2); asp2 = aspath_prepend (asp1, ascratch); @@ -1058,7 +1118,7 @@ prepend_test (struct tests *t) printf ("%s!\n", FAILED); printf ("\n"); - aspath_unintern (asp1); + aspath_unintern (&asp1); aspath_free (asp2); } @@ -1074,7 +1134,7 @@ empty_prepend_test (struct test_segment *t) asp2 = aspath_empty (); ascratch = aspath_dup (asp2); - aspath_unintern (asp2); + aspath_unintern (&asp2); asp2 = aspath_prepend (asp1, ascratch); @@ -1087,7 +1147,7 @@ empty_prepend_test (struct test_segment *t) printf ("\n"); if (asp1) - aspath_unintern (asp1); + aspath_unintern (&asp1); aspath_free (asp2); } @@ -1111,8 +1171,8 @@ as4_reconcile_test (struct tests *t) printf (FAILED "!\n"); printf ("\n"); - aspath_unintern (asp1); - aspath_unintern (asp2); + aspath_unintern (&asp1); + aspath_unintern (&asp2); aspath_free (ascratch); } @@ -1137,8 +1197,8 @@ aggregate_test (struct tests *t) printf (FAILED "!\n"); printf ("\n"); - aspath_unintern (asp1); - aspath_unintern (asp2); + aspath_unintern (&asp1); + aspath_unintern (&asp2); aspath_free (ascratch); /* aspath_unintern (ascratch);*/ } @@ -1185,8 +1245,8 @@ cmp_test () printf (OK "\n"); printf ("\n"); - aspath_unintern (asp1); - aspath_unintern (asp2); + aspath_unintern (&asp1); + aspath_unintern (&asp2); } } @@ -1212,24 +1272,32 @@ handle_attr_test (struct aspath_tests *t) stream_write (peer.ibuf, t->attrheader, t->len); datalen = aspath_put (peer.ibuf, asp, t->as4 == AS4_DATA); + if (t->old_segment) + { + char dummyaspath[] = { BGP_ATTR_FLAG_TRANS, BGP_ATTR_AS_PATH, + t->old_segment->len }; + stream_write (peer.ibuf, dummyaspath, sizeof (dummyaspath)); + stream_write (peer.ibuf, t->old_segment->asdata, t->old_segment->len); + datalen += sizeof (dummyaspath) + t->old_segment->len; + } ret = bgp_attr_parse (&peer, &attr, t->len + datalen, NULL, NULL); if (ret != t->result) { printf ("bgp_attr_parse returned %d, expected %d\n", ret, t->result); - printf ("datalen %d\n", datalen); + printf ("datalen %zd\n", datalen); failed++; } if (ret != 0) goto out; - if (attr.aspath == NULL) + if (t->shouldbe && attr.aspath == NULL) { - printf ("aspath is NULL!\n"); + printf ("aspath is NULL, but should be: %s\n", t->shouldbe); failed++; } - if (attr.aspath && strcmp (attr.aspath->str, t->shouldbe)) + if (t->shouldbe && attr.aspath && strcmp (attr.aspath->str, t->shouldbe)) { printf ("attr str and 'shouldbe' mismatched!\n" "attr str: %s\n" @@ -1237,12 +1305,17 @@ handle_attr_test (struct aspath_tests *t) attr.aspath->str, t->shouldbe); failed++; } + if (!t->shouldbe && attr.aspath) + { + printf ("aspath should be NULL, but is: %s\n", attr.aspath->str); + failed++; + } out: if (attr.aspath) - aspath_unintern (attr.aspath); + aspath_unintern (&attr.aspath); if (asp) - aspath_unintern (asp); + aspath_unintern (&asp); return failed - initfail; } @@ -1259,6 +1332,7 @@ main (void) int i = 0; bgp_master_init (); master = bm->master; + bgp_option_set (BGP_OPT_NO_LISTEN); bgp_attr_init (); while (test_segments[i].name)