Skip to content

Commit

Permalink
tests: bmp tests for adj-rib-out and ecmp
Browse files Browse the repository at this point in the history
add add-path detection in nlri parsing
add bmpserver exception printing and log redirection to /var/log/bmpserver.log
add 3rd peer in topotest for ecmp

Signed-off-by: Maxence Younsi <[email protected]>
  • Loading branch information
mxyns committed Nov 27, 2023
1 parent 9bad0db commit c4572c5
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 126 deletions.
7 changes: 7 additions & 0 deletions tests/topotests/bgp_bmp/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ router bgp 65501
no bgp ebgp-requires-policy
neighbor 192.168.0.2 remote-as 65502
neighbor 192:168::2 remote-as 65502
neighbor 192.168.0.3 remote-as 65502
neighbor 192:168::3 remote-as 65502
!
bmp targets bmp1
bmp connect 192.0.178.10 port 1789 min-retry 100 max-retry 10000
Expand All @@ -13,10 +15,15 @@ router bgp 65501
neighbor 192.168.0.2 activate
neighbor 192.168.0.2 soft-reconfiguration inbound
no neighbor 192:168::2 activate
neighbor 192.168.0.3 activate
neighbor 192.168.0.3 soft-reconfiguration inbound
no neighbor 192:168::3 activate
exit-address-family
!
address-family ipv6 unicast
neighbor 192:168::2 activate
neighbor 192:168::2 soft-reconfiguration inbound
neighbor 192:168::3 activate
neighbor 192:168::3 soft-reconfiguration inbound
exit-address-family
!
19 changes: 19 additions & 0 deletions tests/topotests/bgp_bmp/r3/bgpd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
router bgp 65502
bgp router-id 192.168.0.3
bgp log-neighbor-changes
no bgp ebgp-requires-policy
no bgp network import-check
neighbor 192.168.0.1 remote-as 65501
neighbor 192:168::1 remote-as 65501
!
address-family ipv4 unicast
neighbor 192.168.0.1 activate
no neighbor 192:168::1 activate
redistribute connected
exit-address-family
!
address-family ipv6 unicast
neighbor 192:168::1 activate
redistribute connected
exit-address-family
!
8 changes: 8 additions & 0 deletions tests/topotests/bgp_bmp/r3/zebra.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface r3-eth0
ip address 192.168.0.3/24
ipv6 address 192:168::3/64
!
interface r3-eth1
ip address 172.31.0.3/24
ipv6 address 172:31::3/64
!
97 changes: 82 additions & 15 deletions tests/topotests/bgp_bmp/test_bgp_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
test_bgp_bmp.py: Test BGP BMP functionalities
+------+ +------+ +------+
| | | | | |
| BMP1 |------------| R1 |---------------| R2 |
| | | | | |
+------+ +------+ +------+
| | | | eth1 eth0 | |
| BMP1 |------------| R1 |-------+-------| R2 |
| | | | | | |
+------+ +------+ | +------+
|
| +------+
| eth0 | |
+--------| R3 |
| |
+------+
Setup two routers R1 and R2 with one link configured with IPv4 and
IPv6 addresses.
Expand Down Expand Up @@ -47,21 +53,30 @@
# remember the last sequence number of the logging messages
SEQ = 0

PRE_POLICY = "pre-policy"
POST_POLICY = "post-policy"
ADJ_IN_PRE_POLICY = "rib-in pre-policy"
ADJ_IN_POST_POLICY = "rib-in post-policy"
ADJ_OUT_PRE_POLICY = "rib-out pre-policy"
ADJ_OUT_POST_POLICY = "rib-out post-policy"
LOC_RIB = "loc-rib"

BMP_UPDATE = "update"
BMP_WITHDRAW = "withdraw"


def build_topo(tgen):
tgen.add_router("r1")
tgen.add_router("r2")
tgen.add_router("r3")
tgen.add_bmp_server("bmp1", ip="192.0.178.10", defaultRoute="via 192.0.178.1")

switch = tgen.add_switch("s1")
switch.add_link(tgen.gears["r1"])
switch.add_link(tgen.gears["bmp1"])

tgen.add_link(tgen.gears["r1"], tgen.gears["r2"], "r1-eth1", "r2-eth0")
switch = tgen.add_switch("s2")
switch.add_link(tgen.gears["r1"], nodeif="r1-eth1")
switch.add_link(tgen.gears["r2"], nodeif="r2-eth0")
switch.add_link(tgen.gears["r3"], nodeif="r3-eth0")


def setup_module(mod):
Expand Down Expand Up @@ -203,17 +218,55 @@ def unicast_prefixes(policy):

logger.info("checking for updated prefixes")
# check
test_func = partial(check_for_prefixes, prefixes, "update", policy)
test_func = partial(check_for_prefixes, prefixes, BMP_UPDATE, policy)
success, _ = topotest.run_and_expect(test_func, True, wait=0.5)
assert success, "Checking the updated prefixes has been failed !."

# withdraw prefixes
configure_prefixes(tgen, "r2", 65502, "unicast", prefixes, update=False)
logger.info("checking for withdrawed prefxies")
logger.info("checking for withdrawn prefixes")
# check
test_func = partial(check_for_prefixes, prefixes, "withdraw", policy)
test_func = partial(check_for_prefixes, prefixes, BMP_WITHDRAW, policy)
success, _ = topotest.run_and_expect(test_func, True, wait=0.5)
assert success, "Checking the withdrawed prefixes has been failed !."
assert success, "Checking the withdrawn prefixes has been failed !."


def multipath_unicast_prefixes(policy):
"""
Setup the BMP monitor policy, Add and withdraw ipv4/v6 prefixes.
Check if the previous actions are logged in the BMP server with the right
message type and the right policy.
For multipath we just check if we receive an update multiple times.
We can't check for the peer address because RFC9069 does not include it in Local-RIB Peer Type.
"""
tgen = get_topogen()
set_bmp_policy(tgen, "r1", 65501, "bmp1", "unicast", policy)

prefixes = ["172.31.0.15/32", "2111::1111/128"]

def check_prefixes(node, asn, bmp_log_type):
past_participle = "updated" if bmp_log_type == BMP_UPDATE else "withdrawn"

configure_prefixes(
tgen, node, asn, "unicast", prefixes, update=(bmp_log_type == BMP_UPDATE)
)
logger.info(f"checking for {past_participle} prefixes")

# check
test_func = partial(check_for_prefixes, prefixes, bmp_log_type, policy)
success, _ = topotest.run_and_expect(test_func, True, wait=0.5)

logger.debug(f"Full BMP Logs: \n{get_bmp_messages()}")
assert success, f"Checking the {past_participle} prefixes has been failed !."

# add prefixes
check_prefixes("r2", 65502, BMP_UPDATE)
check_prefixes("r3", 65502, BMP_UPDATE)

# withdraw prefixes
check_prefixes("r2", 65502, BMP_WITHDRAW)
check_prefixes("r3", 65502, BMP_WITHDRAW)


def test_bmp_server_logging():
Expand All @@ -232,16 +285,30 @@ def check_for_log_file():
assert success, "The BMP server is not logging"


def test_bmp_bgp_multipath():
"""
Add/withdraw bgp unicast prefixes on two peers and check the bmp logs.
"""

logger.info("*** Multipath unicast prefixes loc-rib logging ***")
multipath_unicast_prefixes(LOC_RIB)


def test_bmp_bgp_unicast():
"""
Add/withdraw bgp unicast prefixes and check the bmp logs.
"""
logger.info("*** Unicast prefixes pre-policy logging ***")
unicast_prefixes(PRE_POLICY)
logger.info("*** Unicast prefixes post-policy logging ***")
unicast_prefixes(POST_POLICY)

logger.info("*** Unicast prefixes adj-rib-in pre-policy logging ***")
unicast_prefixes(ADJ_IN_PRE_POLICY)
logger.info("*** Unicast prefixes adj-rib-in post-policy logging ***")
unicast_prefixes(ADJ_IN_POST_POLICY)
logger.info("*** Unicast prefixes loc-rib logging ***")
unicast_prefixes(LOC_RIB)
logger.info("*** Unicast prefixes adj-rib-out pre-policy logging ***")
unicast_prefixes(ADJ_OUT_PRE_POLICY)
logger.info("*** Unicast prefixes adj-rib-out post-policy logging ***")
unicast_prefixes(ADJ_OUT_POST_POLICY)


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit c4572c5

Please sign in to comment.