tests: Add tests for overriding BGP peer attrs

This commit introduces unit tests for BGP peer attributes and checks all
three involved components, which are:

- CLI Configuration Input: The appropriate commands to configure the
attribute on either a peer or peer-group are being executed the same way
an end user would do it.

- CLI Configuration Output: The output of 'show running-config' is being
checked for presence/absence of expected configuration strings.

- Internal Data Structures: The internal data structures for maintaining
flag/filter states (value + override + invert) are being checked after
each operation to ensure the override has been implemented properly.

All attributes to be tested must be defined within the 'peer_attrs'
structure, which contains all peer attributes as of today and checks
them with both IPv4 Unicast and IPv6 Unicast. More address families are
supposed to be introduced at a later point in time.

Each attribute is being checked in its own 'clean' BGP environment, so
everything gets reset after each attribute to avoid any weird edge
cases. The 'correct' BGP startup and shutdown routine was taken from
'bgp_main.c' to ensure that we are not leaking any memory or acting
different than the real 'bgpd' would do.

Signed-off-by: Pascal Mathis <mail@pascalmathis.com>
This commit is contained in:
Pascal Mathis 2018-05-27 17:52:19 +02:00
parent 27c05d4d43
commit 9d4f56237a
No known key found for this signature in database
GPG Key ID: E208DBA7BFC9B28C
4 changed files with 1243 additions and 0 deletions

1
tests/.gitignore vendored
View File

@ -25,6 +25,7 @@ __pycache__
/bgpd/test_mp_attr
/bgpd/test_mpath
/bgpd/test_packet
/bgpd/test_peer_attr
/isisd/test_fuzz_isis_tlv
/isisd/test_fuzz_isis_tlv_tests.h
/isisd/test_isis_vertex_queue

View File

@ -18,6 +18,7 @@ TESTS_BGPD = \
bgpd/test_aspath \
bgpd/test_capability \
bgpd/test_packet \
bgpd/test_peer_attr \
bgpd/test_ecommunity \
bgpd/test_mp_attr \
bgpd/test_mpath
@ -140,6 +141,7 @@ lib_cli_test_commands_SOURCES = lib/cli/test_commands_defun.c \
bgpd_test_aspath_SOURCES = bgpd/test_aspath.c
bgpd_test_capability_SOURCES = bgpd/test_capability.c
bgpd_test_packet_SOURCES = bgpd/test_packet.c
bgpd_test_peer_attr_SOURCES = bgpd/test_peer_attr.c
bgpd_test_ecommunity_SOURCES = bgpd/test_ecommunity.c
bgpd_test_mp_attr_SOURCES = bgpd/test_mp_attr.c
bgpd_test_mpath_SOURCES = bgpd/test_mpath.c
@ -179,6 +181,7 @@ lib_cli_test_commands_LDADD = $(ALL_TESTS_LDADD)
bgpd_test_aspath_LDADD = $(BGP_TEST_LDADD)
bgpd_test_capability_LDADD = $(BGP_TEST_LDADD)
bgpd_test_packet_LDADD = $(BGP_TEST_LDADD)
bgpd_test_peer_attr_LDADD = $(BGP_TEST_LDADD)
bgpd_test_ecommunity_LDADD = $(BGP_TEST_LDADD)
bgpd_test_mp_attr_LDADD = $(BGP_TEST_LDADD)
bgpd_test_mpath_LDADD = $(BGP_TEST_LDADD)
@ -193,6 +196,7 @@ EXTRA_DIST = \
bgpd/test_ecommunity.py \
bgpd/test_mp_attr.py \
bgpd/test_mpath.py \
bgpd/test_peer_attr.py \
helpers/python/frrsix.py \
helpers/python/frrtest.py \
isisd/test_fuzz_isis_tlv.py \

1144
tests/bgpd/test_peer_attr.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,94 @@
import frrtest
class TestFlag(frrtest.TestMultiOut):
program = './test_peer_attr'
# List of tests can be generated by executing:
# $> ./test_peer_attr 2>&1 | sed -n 's/\\/\\\\/g; s/\S\+ \[test\] \(.\+\)/TestFlag.okfail(\x27\1\x27)/pg'
#
TestFlag.okfail('peer\\ipv4-unicast\\addpath-tx-all-paths')
TestFlag.okfail('peer\\ipv6-unicast\\addpath-tx-all-paths')
TestFlag.okfail('peer\\ipv4-unicast\\addpath-tx-bestpath-per-AS')
TestFlag.okfail('peer\\ipv6-unicast\\addpath-tx-bestpath-per-AS')
TestFlag.okfail('peer\\ipv4-unicast\\allowas-in')
TestFlag.okfail('peer\\ipv6-unicast\\allowas-in')
TestFlag.okfail('peer\\ipv4-unicast\\allowas-in origin')
TestFlag.okfail('peer\\ipv6-unicast\\allowas-in origin')
TestFlag.okfail('peer\\ipv4-unicast\\as-override')
TestFlag.okfail('peer\\ipv6-unicast\\as-override')
TestFlag.okfail('peer\\ipv4-unicast\\attribute-unchanged as-path')
TestFlag.okfail('peer\\ipv6-unicast\\attribute-unchanged as-path')
TestFlag.okfail('peer\\ipv4-unicast\\attribute-unchanged next-hop')
TestFlag.okfail('peer\\ipv6-unicast\\attribute-unchanged next-hop')
TestFlag.okfail('peer\\ipv4-unicast\\attribute-unchanged med')
TestFlag.okfail('peer\\ipv6-unicast\\attribute-unchanged med')
TestFlag.okfail('peer\\ipv4-unicast\\attribute-unchanged as-path next-hop')
TestFlag.okfail('peer\\ipv6-unicast\\attribute-unchanged as-path next-hop')
TestFlag.okfail('peer\\ipv4-unicast\\attribute-unchanged as-path med')
TestFlag.okfail('peer\\ipv6-unicast\\attribute-unchanged as-path med')
TestFlag.okfail('peer\\ipv4-unicast\\attribute-unchanged as-path next-hop med')
TestFlag.okfail('peer\\ipv6-unicast\\attribute-unchanged as-path next-hop med')
TestFlag.okfail('peer\\ipv4-unicast\\capability orf prefix-list send')
TestFlag.okfail('peer\\ipv6-unicast\\capability orf prefix-list send')
TestFlag.okfail('peer\\ipv4-unicast\\capability orf prefix-list receive')
TestFlag.okfail('peer\\ipv6-unicast\\capability orf prefix-list receive')
TestFlag.okfail('peer\\ipv4-unicast\\capability orf prefix-list both')
TestFlag.okfail('peer\\ipv6-unicast\\capability orf prefix-list both')
TestFlag.okfail('peer\\ipv4-unicast\\default-originate')
TestFlag.okfail('peer\\ipv6-unicast\\default-originate')
TestFlag.okfail('peer\\ipv4-unicast\\default-originate route-map')
TestFlag.okfail('peer\\ipv6-unicast\\default-originate route-map')
TestFlag.okfail('peer\\ipv4-unicast\\distribute-list')
TestFlag.okfail('peer\\ipv6-unicast\\distribute-list')
TestFlag.okfail('peer\\ipv4-unicast\\distribute-list')
TestFlag.okfail('peer\\ipv6-unicast\\distribute-list')
TestFlag.okfail('peer\\ipv4-unicast\\filter-list')
TestFlag.okfail('peer\\ipv6-unicast\\filter-list')
TestFlag.okfail('peer\\ipv4-unicast\\filter-list')
TestFlag.okfail('peer\\ipv6-unicast\\filter-list')
TestFlag.okfail('peer\\ipv4-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv6-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv4-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv6-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv4-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv6-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv4-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv6-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv4-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv6-unicast\\maximum-prefix')
TestFlag.okfail('peer\\ipv4-unicast\\next-hop-self')
TestFlag.okfail('peer\\ipv6-unicast\\next-hop-self')
TestFlag.okfail('peer\\ipv4-unicast\\next-hop-self force')
TestFlag.okfail('peer\\ipv6-unicast\\next-hop-self force')
TestFlag.okfail('peer\\ipv4-unicast\\prefix-list')
TestFlag.okfail('peer\\ipv6-unicast\\prefix-list')
TestFlag.okfail('peer\\ipv4-unicast\\prefix-list')
TestFlag.okfail('peer\\ipv6-unicast\\prefix-list')
TestFlag.okfail('peer\\ipv4-unicast\\remove-private-AS')
TestFlag.okfail('peer\\ipv6-unicast\\remove-private-AS')
TestFlag.okfail('peer\\ipv4-unicast\\remove-private-AS all')
TestFlag.okfail('peer\\ipv6-unicast\\remove-private-AS all')
TestFlag.okfail('peer\\ipv4-unicast\\remove-private-AS replace-AS')
TestFlag.okfail('peer\\ipv6-unicast\\remove-private-AS replace-AS')
TestFlag.okfail('peer\\ipv4-unicast\\remove-private-AS all replace-AS')
TestFlag.okfail('peer\\ipv6-unicast\\remove-private-AS all replace-AS')
TestFlag.okfail('peer\\ipv4-unicast\\route-map')
TestFlag.okfail('peer\\ipv6-unicast\\route-map')
TestFlag.okfail('peer\\ipv4-unicast\\route-map')
TestFlag.okfail('peer\\ipv6-unicast\\route-map')
TestFlag.okfail('peer\\ipv4-unicast\\route-reflector-client')
TestFlag.okfail('peer\\ipv6-unicast\\route-reflector-client')
TestFlag.okfail('peer\\ipv4-unicast\\route-server-client')
TestFlag.okfail('peer\\ipv6-unicast\\route-server-client')
TestFlag.okfail('peer\\ipv4-unicast\\send-community')
TestFlag.okfail('peer\\ipv6-unicast\\send-community')
TestFlag.okfail('peer\\ipv4-unicast\\send-community extended')
TestFlag.okfail('peer\\ipv6-unicast\\send-community extended')
TestFlag.okfail('peer\\ipv4-unicast\\send-community large')
TestFlag.okfail('peer\\ipv6-unicast\\send-community large')
TestFlag.okfail('peer\\ipv4-unicast\\soft-reconfiguration inbound')
TestFlag.okfail('peer\\ipv6-unicast\\soft-reconfiguration inbound')
TestFlag.okfail('peer\\ipv4-unicast\\unsuppress-map')
TestFlag.okfail('peer\\ipv6-unicast\\unsuppress-map')
TestFlag.okfail('peer\\ipv4-unicast\\weight')
TestFlag.okfail('peer\\ipv6-unicast\\weight')