tests: update & extend AS_PATH tests
NB: these tests test for current implementation state, not for RFC
conformance. In particular, behaviour with confederations in AS4_PATH
as well as reconcilation of short AS_PATH + AS4_PATH is currently NOT
conforming to RFC 4893/6793.
* tests/aspath_test.c: add capability to put both AS4_PATH & AS_PATH,
add test for AS4_PATH w/o AS_PATH, update confederation test
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/tests/aspath_test.c b/tests/aspath_test.c
index 9170455..7fdb5e2 100644
--- a/tests/aspath_test.c
+++ b/tests/aspath_test.c
@@ -443,6 +443,7 @@
const int cap; /* capabilities to set for peer */
const char attrheader [1024];
size_t len;
+ const struct test_segment *old_segment;
} aspath_tests [] =
{
/* 0 */
@@ -590,10 +591,10 @@
},
/* 11 */
{
- "4b AS_PATH: confed",
+ "4b AS4_PATH w/o AS_PATH",
&test_segments[6],
- "8466 3 52737 4096",
- AS4_DATA, -1,
+ NULL,
+ AS4_DATA, 0,
PEER_CAP_AS4_ADV,
{ BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
BGP_ATTR_AS4_PATH,
@@ -601,6 +602,20 @@
},
3,
},
+ /* 12 */
+ {
+ "4b AS4_PATH: confed",
+ &test_segments[6],
+ "8466 3 52737 4096 (123 456 789)",
+ AS4_DATA, 0,
+ PEER_CAP_AS4_ADV,
+ { BGP_ATTR_FLAG_TRANS|BGP_ATTR_FLAG_OPTIONAL,
+ BGP_ATTR_AS4_PATH,
+ 14,
+ },
+ 3,
+ &test_segments[0],
+ },
{ NULL, NULL, NULL, 0, 0, 0, { 0 }, 0 },
};
@@ -1212,6 +1227,14 @@
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);
@@ -1224,12 +1247,12 @@
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,6 +1260,11 @@
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)