]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / bfd_profiles_topo1 / test_bfd_profiles_topo1.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # test_bfd_profiles_topo1.py
6 # Part of NetDEF Topology Tests
7 #
8 # Copyright (c) 2020 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
10 #
11
12 """
13 test_bfd_profiles_topo1.py: Test the FRR BFD profile protocol integration.
14 """
15
16 import os
17 import sys
18 import json
19 from functools import partial
20 import pytest
21
22 # Save the Current Working Directory to find configuration files.
23 CWD = os.path.dirname(os.path.realpath(__file__))
24 sys.path.append(os.path.join(CWD, "../"))
25
26 # pylint: disable=C0413
27 # Import topogen and topotest helpers
28 from lib import topotest
29 from lib.topogen import Topogen, TopoRouter, get_topogen
30 from lib.topolog import logger
31
32 pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.ospfd]
33
34
35 def setup_module(mod):
36 "Sets up the pytest environment"
37
38 topodef = {
39 "s1": ("r1", "r2"),
40 "s2": ("r2", "r3"),
41 "s3": ("r3", "r4"),
42 "s4": ("r4", "r5"),
43 "s5": ("r1", "r6"),
44 }
45 tgen = Topogen(topodef, mod.__name__)
46 tgen.start_topology()
47
48 router_list = tgen.routers()
49 for rname, router in router_list.items():
50 daemon_file = "{}/{}/bfdd.conf".format(CWD, rname)
51 if os.path.isfile(daemon_file):
52 router.load_config(TopoRouter.RD_BFD, daemon_file)
53
54 daemon_file = "{}/{}/bgpd.conf".format(CWD, rname)
55 if os.path.isfile(daemon_file):
56 router.load_config(TopoRouter.RD_BGP, daemon_file)
57
58 daemon_file = "{}/{}/isisd.conf".format(CWD, rname)
59 if os.path.isfile(daemon_file):
60 router.load_config(TopoRouter.RD_ISIS, daemon_file)
61
62 daemon_file = "{}/{}/ospfd.conf".format(CWD, rname)
63 if os.path.isfile(daemon_file):
64 router.load_config(TopoRouter.RD_OSPF, daemon_file)
65
66 daemon_file = "{}/{}/ospf6d.conf".format(CWD, rname)
67 if os.path.isfile(daemon_file):
68 router.load_config(TopoRouter.RD_OSPF6, daemon_file)
69
70 daemon_file = "{}/{}/zebra.conf".format(CWD, rname)
71 if os.path.isfile(daemon_file):
72 router.load_config(TopoRouter.RD_ZEBRA, daemon_file)
73
74 # Initialize all routers.
75 tgen.start_router()
76
77
78 def teardown_module(_mod):
79 "Teardown the pytest environment"
80 tgen = get_topogen()
81 tgen.stop_topology()
82
83
84 def test_wait_protocols_convergence():
85 "Wait for all protocols to converge"
86 tgen = get_topogen()
87 if tgen.routers_have_failure():
88 pytest.skip(tgen.errors)
89
90 logger.info("waiting for protocols to converge")
91
92 def expect_loopback_route(router, iptype, route, proto):
93 "Wait until route is present on RIB for protocol."
94 logger.info("waiting route {} in {}".format(route, router))
95 test_func = partial(
96 topotest.router_json_cmp,
97 tgen.gears[router],
98 "show {} route json".format(iptype),
99 {route: [{"protocol": proto}]},
100 )
101 _, result = topotest.run_and_expect(test_func, None, count=130, wait=1)
102 assertmsg = '"{}" OSPF convergence failure'.format(router)
103 assert result is None, assertmsg
104
105 # Wait for R1 <-> R6 convergence.
106 expect_loopback_route("r1", "ip", "10.254.254.6/32", "ospf")
107
108 # Wait for R6 <-> R1 convergence.
109 expect_loopback_route("r6", "ip", "10.254.254.1/32", "ospf")
110
111 # Wait for R2 <-> R3 convergence.
112 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
113
114 # Wait for R3 <-> R2 convergence.
115 expect_loopback_route("r3", "ip", "10.254.254.2/32", "bgp")
116
117 # Wait for R3 <-> R4 convergence.
118 expect_loopback_route("r3", "ipv6", "2001:db8:3::/64", "isis")
119
120 # Wait for R4 <-> R3 convergence.
121 expect_loopback_route("r4", "ipv6", "2001:db8:1::/64", "isis")
122
123 # Wait for R4 <-> R5 convergence.
124 expect_loopback_route("r4", "ipv6", "2001:db8:3::/64", "ospf6")
125
126 # Wait for R5 <-> R4 convergence.
127 expect_loopback_route("r5", "ipv6", "2001:db8:2::/64", "ospf6")
128
129
130 def test_bfd_profile_values():
131 "Assert that the BFD peers can find themselves."
132 tgen = get_topogen()
133 if tgen.routers_have_failure():
134 pytest.skip(tgen.errors)
135
136 logger.info("waiting for bfd peers to go up and checking profile values")
137
138 for router in tgen.routers().values():
139 json_file = "{}/{}/bfd-peers-initial.json".format(CWD, router.name)
140 expected = json.loads(open(json_file).read())
141 test_func = partial(
142 topotest.router_json_cmp, router, "show bfd peers json", expected
143 )
144 _, result = topotest.run_and_expect(test_func, None, count=12, wait=0.5)
145 assertmsg = '"{}" JSON output mismatches'.format(router.name)
146 assert result is None, assertmsg
147
148
149 def test_memory_leak():
150 "Run the memory leak test and report results."
151 tgen = get_topogen()
152 if not tgen.is_memleak_enabled():
153 pytest.skip("Memory leak test/report is disabled")
154
155 tgen.report_memory_leaks()
156
157
158 if __name__ == "__main__":
159 args = ["-s"] + sys.argv[1:]
160 sys.exit(pytest.main(args))