Skip to content

Commit

Permalink
topotests: bmp, test syncro for pre/post-policy of imported bgps
Browse files Browse the repository at this point in the history
Add a test that controls that the configuration of an imported
BGP instance triggers a re-syncronisation.
Ensure that changing an attribute like route distinguisher
triggers also a re-syncronisation.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Jan 7, 2025
1 parent ffdb4cd commit 51cedaa
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 39 deletions.
34 changes: 34 additions & 0 deletions tests/topotests/bgp_bmp/bmp1import/bmp-update-loc-rib-step2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"loc-rib": {
"update": {
"172.31.0.77/32": {
"as_path": "",
"bgp_nexthop": "192.168.1.3",
"bmp_log_type": "update",
"ip_prefix": "172.31.0.77/32",
"is_filtered": false,
"origin": "IGP",
"peer_asn": 65501,
"peer_bgp_id": "192.168.0.1",
"peer_distinguisher": "666:22",
"peer_type": "loc-rib instance",
"policy": "loc-rib"
},
"2001::1125/128": {
"afi": 2,
"as_path": "",
"bmp_log_type": "update",
"ip_prefix": "2001::1125/128",
"is_filtered": false,
"nxhp_ip": "192:167::3",
"origin": "IGP",
"peer_asn": 65501,
"peer_bgp_id": "192.168.0.1",
"peer_distinguisher": "666:22",
"peer_type": "loc-rib instance",
"policy": "loc-rib",
"safi": 1
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"post-policy": {
"update": {
"172.31.0.77/32": {
"as_path": "",
"bgp_nexthop": "192.168.1.3",
"bmp_log_type": "update",
"ip_prefix": "172.31.0.77/32",
"ipv6": false,
"origin": "IGP",
"peer_asn": 65501,
"peer_bgp_id": "192.168.1.3",
"peer_distinguisher": "666:22",
"peer_ip": "192.168.1.3",
"peer_type": "route distinguisher instance",
"policy": "post-policy"
},
"2001::1125/128": {
"afi": 2,
"as_path": "",
"bmp_log_type": "update",
"ip_prefix": "2001::1125/128",
"ipv6": true,
"nxhp_ip": "192:167::3",
"origin": "IGP",
"peer_asn": 65501,
"peer_bgp_id": "192.168.1.3",
"peer_distinguisher": "666:22",
"peer_ip": "192:167::3",
"peer_type": "route distinguisher instance",
"policy": "post-policy",
"safi": 1
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"pre-policy": {
"update": {
"172.31.0.77/32": {
"as_path": "",
"bgp_nexthop": "192.168.1.3",
"bmp_log_type": "update",
"ip_prefix": "172.31.0.77/32",
"ipv6": false,
"origin": "IGP",
"peer_asn": 65501,
"peer_bgp_id": "192.168.1.3",
"peer_distinguisher": "666:22",
"peer_ip": "192.168.1.3",
"peer_type": "route distinguisher instance",
"policy": "pre-policy"
},
"2001::1125/128": {
"afi": 2,
"as_path": "",
"bmp_log_type": "update",
"ip_prefix": "2001::1125/128",
"ipv6": true,
"nxhp_ip": "192:167::3",
"origin": "IGP",
"peer_asn": 65501,
"peer_bgp_id": "192.168.1.3",
"peer_distinguisher": "666:22",
"peer_ip": "192:167::3",
"peer_type": "route distinguisher instance",
"policy": "pre-policy",
"safi": 1
}
}
}
}

This file was deleted.

96 changes: 93 additions & 3 deletions tests/topotests/bgp_bmp/test_bgp_bmp_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,32 @@ def test_bgp_convergence():
assert result is True, "BGP is not converging"


def _test_prefixes_syncro(policy, vrf=None, step=1):
"""
Check that the given policy has syncronised the previously received BGP
updates.
"""
tgen = get_topogen()

prefixes = ["172.31.0.77/32", "2001::1125/128"]
# check
test_func = partial(
bmp_check_for_prefixes,
prefixes,
"update",
policy,
step,
tgen.gears["bmp1import"],
os.path.join(tgen.logdir, "bmp1import"),
tgen.gears["r1import"],
f"{CWD}/bmp1import",
UPDATE_EXPECTED_JSON,
LOC_RIB,
)
success, res = topotest.run_and_expect(test_func, None, count=30, wait=1)
assert success, "Checking the updated prefixes has failed ! %s" % res


def _test_prefixes(policy, vrf=None, step=0):
"""
Setup the BMP monitor policy, Add and withdraw ipv4/v6 prefixes.
Expand Down Expand Up @@ -270,6 +296,63 @@ def test_peer_down():
assert success, "Checking the updated prefixes has been failed !."


def test_reconfigure_prefixes():
"""
Reconfigured BGP networks from R3. Check for BGP VRF update messages
"""

tgen = get_topogen()

prefixes = ["172.31.0.77/32", "2001::1125/128"]
bgp_configure_prefixes(
tgen.gears["r3"],
65501,
"unicast",
prefixes,
vrf=None,
update=True,
)

for ipver in [4, 6]:
ref_file = "{}/r1import/show-bgp-{}-ipv{}-{}-step{}.json".format(
CWD, "vrf1", ipver, "update", 1
)
expected = json.loads(open(ref_file).read())

test_func = partial(
topotest.router_json_cmp,
tgen.gears["r1import"],
f"show bgp vrf vrf1 ipv{ipver} json",
expected,
)
_, res = topotest.run_and_expect(test_func, None, count=30, wait=1)
assertmsg = f"r1: BGP IPv{ipver} convergence failed"
assert res is None, assertmsg


def test_monitor_syncro():
"""
Checking for BMP peers down messages
"""
tgen = get_topogen()

tgen.gears["r1import"].vtysh_cmd(
"""
configure terminal
router bgp 65501
bmp targets bmp1
bmp import-vrf-view vrf1
"""
)

logger.info("*** Unicast prefixes pre-policy logging ***")
_test_prefixes_syncro(PRE_POLICY, vrf="vrf1")
logger.info("*** Unicast prefixes post-policy logging ***")
_test_prefixes_syncro(POST_POLICY, vrf="vrf1")
logger.info("*** Unicast prefixes loc-rib logging ***")
_test_prefixes_syncro(LOC_RIB, vrf="vrf1")


def test_reconfigure_route_distinguisher_vrf1():
"""
Checking for BMP peers down messages
Expand All @@ -293,7 +376,7 @@ def test_reconfigure_route_distinguisher_vrf1():
"""
)
logger.info(
"checking for BMP peer down LOC-RIB message with route-distinguisher set to 444:1"
"Checking for BMP peer down LOC-RIB message with route-distinguisher set to 444:1"
)
test_func = partial(
bmp_check_for_peer_message,
Expand All @@ -310,7 +393,7 @@ def test_reconfigure_route_distinguisher_vrf1():
), "Checking the BMP peer down LOC-RIB message with route-distinguisher set to 444:1 failed !."

logger.info(
"checking for BMP peer up LOC-RIB messages with route-distinguisher set to 666:22"
"Checking for BMP peer up LOC-RIB messages with route-distinguisher set to 666:22"
)
test_func = partial(
bmp_check_for_peer_message,
Expand All @@ -327,7 +410,7 @@ def test_reconfigure_route_distinguisher_vrf1():
), "Checking the BMP peer up LOC-RIB message with route-distinguisher set to 666:22 failed !."

logger.info(
"checking for BMP peer up messages with route-distinguisher set to 666:22"
"Checking for BMP peer up messages with route-distinguisher set to 666:22"
)
peers = ["192.168.1.3", "192:167::3"]
test_func = partial(
Expand All @@ -344,6 +427,13 @@ def test_reconfigure_route_distinguisher_vrf1():
success
), "Checking the BMP peer up messages with route-distinguisher set to 666:22 failed !."

logger.info("*** Unicast prefixes pre-policy logging ***")
_test_prefixes_syncro(PRE_POLICY, vrf="vrf1", step=2)
logger.info("*** Unicast prefixes post-policy logging ***")
_test_prefixes_syncro(POST_POLICY, vrf="vrf1", step=2)
logger.info("*** Unicast prefixes loc-rib logging ***")
_test_prefixes_syncro(LOC_RIB, vrf="vrf1", step=2)


def test_bgp_routerid_changed():
"""
Expand Down

0 comments on commit 51cedaa

Please sign in to comment.