|
| 1 | +#!/usr/bin/env python |
| 2 | +# SPDX-License-Identifier: ISC |
| 3 | + |
| 4 | +# Copyright (c) 2025 by |
| 5 | +# Donatas Abraitis <[email protected]> |
| 6 | +# |
| 7 | + |
| 8 | +import os |
| 9 | +import sys |
| 10 | +import json |
| 11 | +import pytest |
| 12 | +import functools |
| 13 | + |
| 14 | +pytestmark = pytest.mark.ospf6d |
| 15 | + |
| 16 | +CWD = os.path.dirname(os.path.realpath(__file__)) |
| 17 | +sys.path.append(os.path.join(CWD, "../")) |
| 18 | + |
| 19 | +# pylint: disable=C0413 |
| 20 | +from lib import topotest |
| 21 | +from lib.topogen import Topogen, get_topogen |
| 22 | + |
| 23 | + |
| 24 | +def setup_module(mod): |
| 25 | + topodef = {"s1": ("r1", "r2", "r3")} |
| 26 | + tgen = Topogen(topodef, mod.__name__) |
| 27 | + tgen.start_topology() |
| 28 | + |
| 29 | + router_list = tgen.routers() |
| 30 | + |
| 31 | + for _, (rname, router) in enumerate(router_list.items(), 1): |
| 32 | + router.load_frr_config(os.path.join(CWD, "{}/frr.conf".format(rname))) |
| 33 | + |
| 34 | + tgen.start_router() |
| 35 | + |
| 36 | + |
| 37 | +def teardown_module(): |
| 38 | + tgen = get_topogen() |
| 39 | + tgen.stop_topology() |
| 40 | + |
| 41 | + |
| 42 | +def test_ospf_forwarding_address_self(): |
| 43 | + tgen = get_topogen() |
| 44 | + |
| 45 | + if tgen.routers_have_failure(): |
| 46 | + pytest.skip(tgen.errors) |
| 47 | + |
| 48 | + r3 = tgen.gears["r3"] |
| 49 | + |
| 50 | + def _show_ospf_database_external(): |
| 51 | + output = json.loads(r3.vtysh_cmd("show ip ospf database external json")) |
| 52 | + expected = { |
| 53 | + "asExternalLinkStates": [ |
| 54 | + { |
| 55 | + "linkStateId": "172.16.10.0", |
| 56 | + "advertisingRouter": "172.16.0.1", |
| 57 | + "forwardAddress": "0.0.0.0", |
| 58 | + }, |
| 59 | + { |
| 60 | + "linkStateId": "172.16.10.0", |
| 61 | + "advertisingRouter": "172.16.0.2", |
| 62 | + "forwardAddress": "0.0.0.0", |
| 63 | + }, |
| 64 | + ] |
| 65 | + } |
| 66 | + return topotest.json_cmp(output, expected) |
| 67 | + |
| 68 | + test_func = functools.partial( |
| 69 | + _show_ospf_database_external, |
| 70 | + ) |
| 71 | + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) |
| 72 | + assert result is None, "OSPF external database is not as expected" |
| 73 | + |
| 74 | + def _show_ip_route(): |
| 75 | + output = json.loads(r3.vtysh_cmd("show ip route 172.16.10.0/24 json")) |
| 76 | + expected = { |
| 77 | + "172.16.10.0/24": [ |
| 78 | + { |
| 79 | + "protocol": "ospf", |
| 80 | + "installed": True, |
| 81 | + "internalNextHopNum": 2, |
| 82 | + "internalNextHopActiveNum": 2, |
| 83 | + "internalNextHopFibInstalledNum": 2, |
| 84 | + "nexthops": [ |
| 85 | + { |
| 86 | + "fib": True, |
| 87 | + "ip": "172.16.0.1", |
| 88 | + "interfaceName": "r3-eth0", |
| 89 | + }, |
| 90 | + { |
| 91 | + "fib": True, |
| 92 | + "ip": "172.16.0.2", |
| 93 | + "interfaceName": "r3-eth0", |
| 94 | + }, |
| 95 | + ], |
| 96 | + } |
| 97 | + ] |
| 98 | + } |
| 99 | + return topotest.json_cmp(output, expected) |
| 100 | + |
| 101 | + test_func = functools.partial( |
| 102 | + _show_ip_route, |
| 103 | + ) |
| 104 | + _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) |
| 105 | + assert result is None, "172.16.10.0/24 route does not have ECMP entries" |
| 106 | + |
| 107 | + |
| 108 | +if __name__ == "__main__": |
| 109 | + args = ["-s"] + sys.argv[1:] |
| 110 | + sys.exit(pytest.main(args)) |
0 commit comments