diff options
| author | Russ White <russ@riw.us> | 2025-04-03 08:25:32 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-03 08:25:32 -0400 |
| commit | ab67e5544e937c9cb5644ceadf1cf9acafe452f9 (patch) | |
| tree | f6eb4a7a3f89c8009ea91f745aae10ac33b676d5 /tests/topotests/lib/bgp.py | |
| parent | 112663772a6b7b0f17f6dcc10adcc7b75f7e3091 (diff) | |
| parent | 171231686d0208dde853766e2ed122de922ad1e6 (diff) | |
Merge pull request #18396 from pguibert6WIND/srv6l3vpn_to_bgp_vrf_redistribute
Add BGP redistribution in SRv6 BGP
Diffstat (limited to 'tests/topotests/lib/bgp.py')
| -rw-r--r-- | tests/topotests/lib/bgp.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 632aa4a10b..01fe2b3714 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -5,6 +5,7 @@ # ("NetDEF") in this file. # +import json import ipaddress import sys import traceback @@ -5658,3 +5659,34 @@ def bgp_configure_prefixes(router, asn, safi, prefixes, vrf=None, update=True): ] logger.debug(f"setting prefix: ipv{ip.version} {safi} {ip}") router.vtysh_cmd("".join(cmd)) + + +# compare exact fields of 'show bgp ipv4 vpn' and related commands +# after having removed some attributes that are not relevant. +def bgp_vpn_router_json_cmp_exact_filter(router, cmd, expected): + output = router.vtysh_cmd(cmd) + logger.info("{}: {}\n{}".format(router.name, cmd, output)) + + json_output = json.loads(output) + + # filter out tableVersion, version and nhVrfID + json_output.pop("tableVersion") + if "totalRoutes" in json_output: + json_output.pop("totalRoutes") + if "totalPaths" in json_output: + json_output.pop("totalPaths") + for rd, data in json_output["routes"]["routeDistinguishers"].items(): + for _, attrs in data.items(): + for attr in attrs: + if "nhVrfId" in attr: + attr.pop("nhVrfId") + if "version" in attr: + attr.pop("version") + + # filter out RD with no data (e.g. "444:3": {}) + json_tmp = deepcopy(json_output) + for rd, data in json_tmp["routes"]["routeDistinguishers"].items(): + if len(data.keys()) == 0: + json_output["routes"]["routeDistinguishers"].pop(rd) + + return topotest.json_cmp(json_output, expected, exact=True) |
