mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-07-27 02:20:54 +00:00
topotests: bgp_vpnv4_ebgp, check 'extcommunity rt' presence
Add a test to check that the presence of a route-map at exportation with a 'set extcommunity rt' is enough to allow the prefix to be exported. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
parent
b43ea569d9
commit
309e692d10
@ -48,6 +48,10 @@ sys.path.append(os.path.join(CWD, "../"))
|
|||||||
# pylint: disable=C0413
|
# pylint: disable=C0413
|
||||||
# Import topogen and topotest helpers
|
# Import topogen and topotest helpers
|
||||||
from lib import topotest
|
from lib import topotest
|
||||||
|
from lib.bgpcheck import (
|
||||||
|
check_show_bgp_vpn_prefix_found,
|
||||||
|
check_show_bgp_vpn_prefix_not_found,
|
||||||
|
)
|
||||||
from lib.topogen import Topogen, TopoRouter, get_topogen
|
from lib.topogen import Topogen, TopoRouter, get_topogen
|
||||||
from lib.topolog import logger
|
from lib.topolog import logger
|
||||||
from lib.checkping import check_ping
|
from lib.checkping import check_ping
|
||||||
@ -259,62 +263,6 @@ def mpls_table_check_entry(router, out_label, out_nexthop):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def check_show_bgp_vpn_prefix_found(
|
|
||||||
router, ipversion, prefix, rd, label=None, nexthop=None
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Check if a given vpn prefix is present in the BGP RIB
|
|
||||||
* 'router': the router to check BGP VPN RIB
|
|
||||||
* 'ipversion': The ip version to check: ipv4 or ipv6
|
|
||||||
* 'prefix': the IP prefix to check
|
|
||||||
* 'rd': the route distinguisher to check
|
|
||||||
* 'label: the label to check
|
|
||||||
"""
|
|
||||||
output = json.loads(
|
|
||||||
router.vtysh_cmd("show bgp {} vpn {} json".format(ipversion, prefix))
|
|
||||||
)
|
|
||||||
if label:
|
|
||||||
if nexthop:
|
|
||||||
expected = {
|
|
||||||
rd: {
|
|
||||||
"prefix": prefix,
|
|
||||||
"paths": [{"remoteLabel": label, "nexthops": [{"ip": nexthop}]}],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
expected = {rd: {"prefix": prefix, "paths": [{"remoteLabel": label}]}}
|
|
||||||
else:
|
|
||||||
if nexthop:
|
|
||||||
expected = {
|
|
||||||
rd: {"prefix": prefix, "paths": [{"nexthops": [{"ip": nexthop}]}]}
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
expected = {rd: {"prefix": prefix}}
|
|
||||||
return topotest.json_cmp(output, expected)
|
|
||||||
|
|
||||||
|
|
||||||
def check_show_bgp_vpn_prefix_not_found(router, ipversion, prefix, rd, label=None):
|
|
||||||
"""
|
|
||||||
Check if a given vpn prefix is not present in the BGP RIB
|
|
||||||
* 'router': the router to check BGP VPN RIB
|
|
||||||
* 'ipversion': The ip version to check: ipv4 or ipv6
|
|
||||||
* 'prefix': the IP prefix to check
|
|
||||||
* 'rd': the route distinguisher to check
|
|
||||||
* 'label: the label to check
|
|
||||||
"""
|
|
||||||
output = json.loads(
|
|
||||||
router.vtysh_cmd("show bgp {} vpn {} json".format(ipversion, prefix))
|
|
||||||
)
|
|
||||||
if label:
|
|
||||||
expected = {rd: {"prefix": prefix, "paths": [{"remoteLabel": label}]}}
|
|
||||||
else:
|
|
||||||
expected = {rd: {"prefix": prefix}}
|
|
||||||
ret = topotest.json_cmp(output, expected)
|
|
||||||
if ret is None:
|
|
||||||
return "not good"
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def check_show_mpls_table_entry_label_not_found(router, inlabel):
|
def check_show_mpls_table_entry_label_not_found(router, inlabel):
|
||||||
output = json.loads(router.vtysh_cmd("show mpls table {} json".format(inlabel)))
|
output = json.loads(router.vtysh_cmd("show mpls table {} json".format(inlabel)))
|
||||||
expected = {"inLabel": inlabel, "installed": True}
|
expected = {"inLabel": inlabel, "installed": True}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
bgp route-map delay-timer 1
|
||||||
router bgp 65500
|
router bgp 65500
|
||||||
bgp router-id 192.0.2.1
|
bgp router-id 192.0.2.1
|
||||||
no bgp ebgp-requires-policy
|
no bgp ebgp-requires-policy
|
||||||
|
@ -25,6 +25,10 @@ sys.path.append(os.path.join(CWD, "../"))
|
|||||||
# pylint: disable=C0413
|
# pylint: disable=C0413
|
||||||
# Import topogen and topotest helpers
|
# Import topogen and topotest helpers
|
||||||
from lib import topotest
|
from lib import topotest
|
||||||
|
from lib.bgpcheck import (
|
||||||
|
check_show_bgp_vpn_prefix_found,
|
||||||
|
check_show_bgp_vpn_prefix_not_found,
|
||||||
|
)
|
||||||
from lib.topogen import Topogen, TopoRouter, get_topogen
|
from lib.topogen import Topogen, TopoRouter, get_topogen
|
||||||
from lib.topolog import logger
|
from lib.topolog import logger
|
||||||
|
|
||||||
@ -214,6 +218,87 @@ def test_protocols_convergence():
|
|||||||
assert result is None, assertmsg
|
assert result is None, assertmsg
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_route_target_empty():
|
||||||
|
"""
|
||||||
|
Check that when removing 'rt vpn export' command, exported prefix is removed
|
||||||
|
"""
|
||||||
|
tgen = get_topogen()
|
||||||
|
if tgen.routers_have_failure():
|
||||||
|
pytest.skip(tgen.errors)
|
||||||
|
router = tgen.gears["r1"]
|
||||||
|
logger.info("r1, Remove 'rt vpn export 52:100' command")
|
||||||
|
router.vtysh_cmd(
|
||||||
|
"configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nno rt vpn export 52:100\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
prefix = "172.31.0.1/32"
|
||||||
|
logger.info("r1, check that exported prefix {} is removed".format(prefix))
|
||||||
|
test_func = partial(
|
||||||
|
check_show_bgp_vpn_prefix_not_found,
|
||||||
|
router,
|
||||||
|
"ipv4",
|
||||||
|
prefix,
|
||||||
|
"444:1",
|
||||||
|
)
|
||||||
|
success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
|
||||||
|
assert success, "{}, vpnv4 update {} still present".format(router.name, prefix)
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_route_target_with_routemap_with_export_route_target():
|
||||||
|
"""
|
||||||
|
Check that when removing 'rt vpn export' command, exported prefix is added back
|
||||||
|
"""
|
||||||
|
tgen = get_topogen()
|
||||||
|
if tgen.routers_have_failure():
|
||||||
|
pytest.skip(tgen.errors)
|
||||||
|
router = tgen.gears["r1"]
|
||||||
|
logger.info("r1, configuring route target with route-map with export route target")
|
||||||
|
router.vtysh_cmd(
|
||||||
|
"configure terminal\nrouter bgp 65500 vrf vrf1\naddress-family ipv4 unicast\nroute-map vpn export rmap\n"
|
||||||
|
)
|
||||||
|
router.vtysh_cmd(
|
||||||
|
"configure terminal\nroute-map rmap permit 1\nset extcommunity rt 52:100\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
prefix = "172.31.0.1/32"
|
||||||
|
logger.info("r1, check that exported prefix {} is added back".format(prefix))
|
||||||
|
test_func = partial(
|
||||||
|
check_show_bgp_vpn_prefix_found,
|
||||||
|
router,
|
||||||
|
"ipv4",
|
||||||
|
prefix,
|
||||||
|
"444:1",
|
||||||
|
)
|
||||||
|
success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
|
||||||
|
assert success, "{}, vpnv4 update {} still not present".format(router.name, prefix)
|
||||||
|
|
||||||
|
|
||||||
|
def test_export_route_target_with_routemap_without_export_route_target():
|
||||||
|
"""
|
||||||
|
Check that when removing 'set extcommunity rt' command, prefix is removed
|
||||||
|
"""
|
||||||
|
tgen = get_topogen()
|
||||||
|
if tgen.routers_have_failure():
|
||||||
|
pytest.skip(tgen.errors)
|
||||||
|
router = tgen.gears["r1"]
|
||||||
|
logger.info("r1, removing 'set extcommunity rt 52:100.")
|
||||||
|
router.vtysh_cmd(
|
||||||
|
"configure terminal\nroute-map rmap permit 1\nno set extcommunity rt\n"
|
||||||
|
)
|
||||||
|
|
||||||
|
prefix = "172.31.0.1/32"
|
||||||
|
logger.info("r1, check that exported prefix {} is removed".format(prefix))
|
||||||
|
test_func = partial(
|
||||||
|
check_show_bgp_vpn_prefix_not_found,
|
||||||
|
router,
|
||||||
|
"ipv4",
|
||||||
|
prefix,
|
||||||
|
"444:1",
|
||||||
|
)
|
||||||
|
success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5)
|
||||||
|
assert success, "{}, vpnv4 update {} still present".format(router.name, prefix)
|
||||||
|
|
||||||
|
|
||||||
def test_memory_leak():
|
def test_memory_leak():
|
||||||
"Run the memory leak test and report results."
|
"Run the memory leak test and report results."
|
||||||
tgen = get_topogen()
|
tgen = get_topogen()
|
||||||
|
63
tests/topotests/lib/bgpcheck.py
Normal file
63
tests/topotests/lib/bgpcheck.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
# Copyright 2023, 6wind
|
||||||
|
import json
|
||||||
|
|
||||||
|
from lib import topotest
|
||||||
|
|
||||||
|
|
||||||
|
def check_show_bgp_vpn_prefix_not_found(router, ipversion, prefix, rd, label=None):
|
||||||
|
"""
|
||||||
|
Check if a given vpn prefix is not present in the BGP RIB
|
||||||
|
* 'router': the router to check BGP VPN RIB
|
||||||
|
* 'ipversion': The ip version to check: ipv4 or ipv6
|
||||||
|
* 'prefix': the IP prefix to check
|
||||||
|
* 'rd': the route distinguisher to check
|
||||||
|
* 'label: the label to check
|
||||||
|
"""
|
||||||
|
output = json.loads(
|
||||||
|
router.vtysh_cmd("show bgp {} vpn {} json".format(ipversion, prefix))
|
||||||
|
)
|
||||||
|
if label:
|
||||||
|
expected = {rd: {"prefix": prefix, "paths": [{"remoteLabel": label}]}}
|
||||||
|
else:
|
||||||
|
expected = {rd: {"prefix": prefix}}
|
||||||
|
ret = topotest.json_cmp(output, expected)
|
||||||
|
if ret is None:
|
||||||
|
return "not good"
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def check_show_bgp_vpn_prefix_found(
|
||||||
|
router, ipversion, prefix, rd, label=None, nexthop=None
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
Check if a given vpn prefix is present in the BGP RIB
|
||||||
|
* 'router': the router to check BGP VPN RIB
|
||||||
|
* 'ipversion': The ip version to check: ipv4 or ipv6
|
||||||
|
* 'prefix': the IP prefix to check
|
||||||
|
* 'rd': the route distinguisher to check
|
||||||
|
* 'label: the label to check
|
||||||
|
"""
|
||||||
|
output = json.loads(
|
||||||
|
router.vtysh_cmd("show bgp {} vpn {} json".format(ipversion, prefix))
|
||||||
|
)
|
||||||
|
if label:
|
||||||
|
if nexthop:
|
||||||
|
expected = {
|
||||||
|
rd: {
|
||||||
|
"prefix": prefix,
|
||||||
|
"paths": [{"remoteLabel": label, "nexthops": [{"ip": nexthop}]}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
expected = {rd: {"prefix": prefix, "paths": [{"remoteLabel": label}]}}
|
||||||
|
else:
|
||||||
|
if nexthop:
|
||||||
|
expected = {
|
||||||
|
rd: {"prefix": prefix, "paths": [{"nexthops": [{"ip": nexthop}]}]}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
expected = {rd: {"prefix": prefix}}
|
||||||
|
return topotest.json_cmp(output, expected)
|
Loading…
Reference in New Issue
Block a user