]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bfd_profiles_topo1/test_bfd_profiles_topo1.py
Merge pull request #8174 from mjstapp/backup_nht
[mirror_frr.git] / tests / topotests / bfd_profiles_topo1 / test_bfd_profiles_topo1.py
1 #!/usr/bin/env python
2
3 #
4 # test_bfd_profiles_topo1.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2020 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
9 #
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
13 # in all copies.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 test_bfd_profiles_topo1.py: Test the FRR BFD profile protocol integration.
27 """
28
29 import os
30 import sys
31 import json
32 from functools import partial
33 import pytest
34
35 # Save the Current Working Directory to find configuration files.
36 CWD = os.path.dirname(os.path.realpath(__file__))
37 sys.path.append(os.path.join(CWD, "../"))
38
39 # pylint: disable=C0413
40 # Import topogen and topotest helpers
41 from lib import topotest
42 from lib.topogen import Topogen, TopoRouter, get_topogen
43 from lib.topolog import logger
44
45 # Required to instantiate the topology builder class.
46 from mininet.topo import Topo
47
48 pytestmark = [pytest.mark.bfdd, pytest.mark.bgpd, pytest.mark.isisd, pytest.mark.ospfd]
49
50
51 class BFDProfTopo(Topo):
52 "Test topology builder"
53
54 def build(self, *_args, **_opts):
55 "Build function"
56 tgen = get_topogen(self)
57
58 # Create 6 routers
59 for routern in range(1, 7):
60 tgen.add_router("r{}".format(routern))
61
62 switch = tgen.add_switch("s1")
63 switch.add_link(tgen.gears["r1"])
64 switch.add_link(tgen.gears["r2"])
65
66 switch = tgen.add_switch("s2")
67 switch.add_link(tgen.gears["r2"])
68 switch.add_link(tgen.gears["r3"])
69
70 switch = tgen.add_switch("s3")
71 switch.add_link(tgen.gears["r3"])
72 switch.add_link(tgen.gears["r4"])
73
74 switch = tgen.add_switch("s4")
75 switch.add_link(tgen.gears["r4"])
76 switch.add_link(tgen.gears["r5"])
77
78 switch = tgen.add_switch("s5")
79 switch.add_link(tgen.gears["r1"])
80 switch.add_link(tgen.gears["r6"])
81
82
83 def setup_module(mod):
84 "Sets up the pytest environment"
85 tgen = Topogen(BFDProfTopo, mod.__name__)
86 tgen.start_topology()
87
88 router_list = tgen.routers()
89 for rname, router in router_list.items():
90 daemon_file = "{}/{}/bfdd.conf".format(CWD, rname)
91 if os.path.isfile(daemon_file):
92 router.load_config(TopoRouter.RD_BFD, daemon_file)
93
94 daemon_file = "{}/{}/bgpd.conf".format(CWD, rname)
95 if os.path.isfile(daemon_file):
96 router.load_config(TopoRouter.RD_BGP, daemon_file)
97
98 daemon_file = "{}/{}/isisd.conf".format(CWD, rname)
99 if os.path.isfile(daemon_file):
100 router.load_config(TopoRouter.RD_ISIS, daemon_file)
101
102 daemon_file = "{}/{}/ospfd.conf".format(CWD, rname)
103 if os.path.isfile(daemon_file):
104 router.load_config(TopoRouter.RD_OSPF, daemon_file)
105
106 daemon_file = "{}/{}/ospf6d.conf".format(CWD, rname)
107 if os.path.isfile(daemon_file):
108 router.load_config(TopoRouter.RD_OSPF6, daemon_file)
109
110 daemon_file = "{}/{}/zebra.conf".format(CWD, rname)
111 if os.path.isfile(daemon_file):
112 router.load_config(TopoRouter.RD_ZEBRA, daemon_file)
113
114 # Initialize all routers.
115 tgen.start_router()
116
117
118 def teardown_module(_mod):
119 "Teardown the pytest environment"
120 tgen = get_topogen()
121 tgen.stop_topology()
122
123
124 def test_wait_protocols_convergence():
125 "Wait for all protocols to converge"
126 tgen = get_topogen()
127 if tgen.routers_have_failure():
128 pytest.skip(tgen.errors)
129
130 logger.info("waiting for protocols to converge")
131
132 def expect_loopback_route(router, iptype, route, proto):
133 "Wait until route is present on RIB for protocol."
134 logger.info("waiting route {} in {}".format(route, router))
135 test_func = partial(
136 topotest.router_json_cmp,
137 tgen.gears[router],
138 "show {} route json".format(iptype),
139 {route: [{"protocol": proto}]},
140 )
141 _, result = topotest.run_and_expect(test_func, None, count=130, wait=1)
142 assertmsg = '"{}" OSPF convergence failure'.format(router)
143 assert result is None, assertmsg
144
145 # Wait for R1 <-> R6 convergence.
146 expect_loopback_route("r1", "ip", "10.254.254.6/32", "ospf")
147
148 # Wait for R6 <-> R1 convergence.
149 expect_loopback_route("r6", "ip", "10.254.254.1/32", "ospf")
150
151 # Wait for R2 <-> R3 convergence.
152 expect_loopback_route("r2", "ip", "10.254.254.3/32", "bgp")
153
154 # Wait for R3 <-> R2 convergence.
155 expect_loopback_route("r3", "ip", "10.254.254.2/32", "bgp")
156
157 # Wait for R3 <-> R4 convergence.
158 expect_loopback_route("r3", "ipv6", "2001:db8:3::/64", "isis")
159
160 # Wait for R4 <-> R3 convergence.
161 expect_loopback_route("r4", "ipv6", "2001:db8:1::/64", "isis")
162
163 # Wait for R4 <-> R5 convergence.
164 expect_loopback_route("r4", "ipv6", "2001:db8:3::/64", "ospf6")
165
166 # Wait for R5 <-> R4 convergence.
167 expect_loopback_route("r5", "ipv6", "2001:db8:2::/64", "ospf6")
168
169
170 def test_bfd_profile_values():
171 "Assert that the BFD peers can find themselves."
172 tgen = get_topogen()
173 if tgen.routers_have_failure():
174 pytest.skip(tgen.errors)
175
176 logger.info("waiting for bfd peers to go up and checking profile values")
177
178 for router in tgen.routers().values():
179 json_file = "{}/{}/bfd-peers-initial.json".format(CWD, router.name)
180 expected = json.loads(open(json_file).read())
181 test_func = partial(
182 topotest.router_json_cmp, router, "show bfd peers json", expected
183 )
184 _, result = topotest.run_and_expect(test_func, None, count=12, wait=0.5)
185 assertmsg = '"{}" JSON output mismatches'.format(router.name)
186 assert result is None, assertmsg
187
188
189 def test_memory_leak():
190 "Run the memory leak test and report results."
191 tgen = get_topogen()
192 if not tgen.is_memleak_enabled():
193 pytest.skip("Memory leak test/report is disabled")
194
195 tgen.report_memory_leaks()
196
197
198 if __name__ == "__main__":
199 args = ["-s"] + sys.argv[1:]
200 sys.exit(pytest.main(args))