]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py
Merge pull request #8182 from mjstapp/topotest_start_tgen
[mirror_frr.git] / tests / topotests / isis_lsp_bits_topo1 / test_isis_lsp_bits_topo1.py
1 #!/usr/bin/env python
2
3 #
4 # test_isis_lsp_bits_topo1.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2021 by Volta Networks
8 #
9 # Permission to use, copy, modify, and/or distribute this software
10 # for any purpose with or without fee is hereby granted, provided
11 # that the above copyright notice and this permission notice appear
12 # in all copies.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
18 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
20 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 # OF THIS SOFTWARE.
22 #
23
24 """
25 test_isis_lsp_bits_topo1.py:
26
27 +---------+
28 | |
29 | RT1 |
30 | 1.1.1.1 |
31 | L1 |
32 +---------+
33 |eth-sw1
34 |
35 |
36 |
37 +---------+ | +---------+
38 | | | | |
39 | RT2 |eth-sw1 | eth-sw1| RT3 |
40 | 2.2.2.2 +----------+----------+ 3.3.3.3 |
41 | L1|L2 | 10.0.1.0/24 | L1|L2 |
42 +---------+ +---------+
43 eth-rt4| eth-rt5|
44 | |
45 10.0.2.0/24| |10.0.4.0/24
46 | |
47 eth-rt2| eth-rt3|
48 +---------+ +---------+
49 | | | |
50 | RT4 | 10.0.6.0/24 | RT5 |
51 | 4.4.4.4 +---------------------+ 5.5.5.5 |
52 | L1|L2 |eth-rt5 eth-rt4| L1|L2 |
53 +---------+ +---------+
54 eth-rt6| |eth-rt6
55 | |
56 10.0.7.0/24| |10.0.8.0/24
57 | +---------+ |
58 | | | |
59 | | RT6 | |
60 +----------+ 6.6.6.6 +-----------+
61 eth-rt4| L1 |eth-rt5
62 +---------+
63 """
64
65 import os
66 import sys
67 import pytest
68 import json
69 import re
70 import tempfile
71 from time import sleep
72 from functools import partial
73
74 # Save the Current Working Directory to find configuration files.
75 CWD = os.path.dirname(os.path.realpath(__file__))
76 sys.path.append(os.path.join(CWD, "../"))
77
78 # pylint: disable=C0413
79 # Import topogen and topotest helpers
80 from lib import topotest
81 from lib.topogen import Topogen, TopoRouter, get_topogen
82 from lib.topolog import logger
83
84 # Required to instantiate the topology builder class.
85 from mininet.topo import Topo
86
87 pytestmark = [pytest.mark.isisd]
88
89
90 # Global multi-dimensional dictionary containing all expected outputs
91 outputs = {}
92
93
94 class TemplateTopo(Topo):
95 "Test topology builder"
96
97 def build(self, *_args, **_opts):
98 "Build function"
99 tgen = get_topogen(self)
100
101 #
102 # Define FRR Routers
103 #
104 for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
105 tgen.add_router(router)
106
107 #
108 # Define connections
109 #
110 switch = tgen.add_switch("s1")
111 switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1")
112 switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1")
113 switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1")
114
115 switch = tgen.add_switch("s2")
116 switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4")
117 switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2")
118
119 switch = tgen.add_switch("s4")
120 switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5")
121 switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3")
122
123 switch = tgen.add_switch("s6")
124 switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5")
125 switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4")
126
127 switch = tgen.add_switch("s7")
128 switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6")
129 switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4")
130
131 switch = tgen.add_switch("s8")
132 switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6")
133 switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5")
134
135
136 def setup_module(mod):
137 "Sets up the pytest environment"
138 tgen = Topogen(TemplateTopo, mod.__name__)
139 tgen.start_topology()
140
141 router_list = tgen.routers()
142
143 # For all registered routers, load the zebra configuration file
144 for rname, router in router_list.items():
145 router.load_config(
146 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
147 )
148 router.load_config(
149 TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
150 )
151
152 tgen.start_router()
153
154
155 def teardown_module(mod):
156 "Teardown the pytest environment"
157 tgen = get_topogen()
158
159 # This function tears down the whole topology.
160 tgen.stop_topology()
161
162
163 def router_compare_json_output(rname, command, reference):
164 "Compare router JSON output"
165
166 logger.info('Comparing router "%s" "%s" output', rname, command)
167
168 tgen = get_topogen()
169 filename = "{}/{}/{}".format(CWD, rname, reference)
170 expected = json.loads(open(filename).read())
171
172 # Run test function until we get an result. Wait at most 60 seconds.
173 test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected)
174 _, diff = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
175 assertmsg = '"{}" JSON output mismatches the expected result'.format(rname)
176 assert diff is None, assertmsg
177
178
179 #
180 # Step 1
181 #
182 # Test initial network convergence
183 # Attach-bit defaults to on, so expect default route pointing to L1|L2 router
184 #
185 def test_isis_adjacencies_step1():
186 logger.info("Test (step 1): check IS-IS adjacencies")
187 tgen = get_topogen()
188
189 # Skip if previous fatal error condition is raised
190 if tgen.routers_have_failure():
191 pytest.skip(tgen.errors)
192
193 for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
194 router_compare_json_output(
195 rname,
196 "show yang operational-data /frr-interface:lib isisd",
197 "step1/show_yang_interface_isis_adjacencies.ref",
198 )
199
200
201 def test_rib_ipv4_step1():
202 logger.info("Test (step 1): verify IPv4 RIB")
203 tgen = get_topogen()
204
205 # Skip if previous fatal error condition is raised
206 if tgen.routers_have_failure():
207 pytest.skip(tgen.errors)
208
209 for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
210 router_compare_json_output(
211 rname, "show ip route isis json", "step1/show_ip_route.ref"
212 )
213
214
215 def test_rib_ipv6_step1():
216 logger.info("Test (step 1): verify IPv6 RIB")
217 tgen = get_topogen()
218
219 # Skip if previous fatal error condition is raised
220 if tgen.routers_have_failure():
221 pytest.skip(tgen.errors)
222
223 for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
224 router_compare_json_output(
225 rname, "show ipv6 route isis json", "step1/show_ipv6_route.ref"
226 )
227
228
229 #
230 # Step 2
231 #
232 # Action(s):
233 # -Disable sending Attach bit on RT2 and RT4
234 #
235 # Expected changes:
236 # -RT1 should remove the default route pointing to RT2
237 # -RT6 should remove the default route pointing to RT4
238 #
239 def test_rib_ipv4_step2():
240 logger.info("Test (step 2): verify IPv4 RIB")
241 tgen = get_topogen()
242
243 # Skip if previous fatal error condition is raised
244 if tgen.routers_have_failure():
245 pytest.skip(tgen.errors)
246
247 logger.info("Disabling setting the attached-bit on RT2 and RT4")
248 tgen.net["rt2"].cmd(
249 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit send"'
250 )
251 tgen.net["rt4"].cmd(
252 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit send"'
253 )
254
255 for rname in ["rt1", "rt6"]:
256 router_compare_json_output(
257 rname, "show ip route isis json", "step2/show_ip_route.ref"
258 )
259
260
261 def test_rib_ipv6_step2():
262 logger.info("Test (step 2): verify IPv6 RIB")
263 tgen = get_topogen()
264
265 # Skip if previous fatal error condition is raised
266 if tgen.routers_have_failure():
267 pytest.skip(tgen.errors)
268
269 for rname in ["rt1", "rt6"]:
270 router_compare_json_output(
271 rname, "show ipv6 route isis json", "step2/show_ipv6_route.ref"
272 )
273
274
275 #
276 # Step 3
277 #
278 # Action(s):
279 # -restore attach-bit, enable sending attach-bit
280 # -disble processing a LSP with attach bit set
281 #
282 # Expected changes:
283 # -RT1 and RT6 should not install a default route
284 #
285 def test_rib_ipv4_step3():
286 logger.info("Test (step 3): verify IPv4 RIB")
287 tgen = get_topogen()
288
289 # Skip if previous fatal error condition is raised
290 if tgen.routers_have_failure():
291 pytest.skip(tgen.errors)
292
293 logger.info("Enable setting the attached-bit on RT2 and RT4")
294 tgen.net["rt2"].cmd('vtysh -c "conf t" -c "router isis 1" -c "attached-bit send"')
295 tgen.net["rt4"].cmd('vtysh -c "conf t" -c "router isis 1" -c "attached-bit send"')
296
297 logger.info("Disable processing received attached-bit in LSP on RT1 and RT6")
298 tgen.net["rt1"].cmd(
299 'vtysh -c "conf t" -c "router isis 1" -c "attached-bit receive ignore"'
300 )
301 tgen.net["rt6"].cmd(
302 'vtysh -c "conf t" -c "router isis 1" -c "attached-bit receive ignore"'
303 )
304
305 for rname in ["rt1", "rt6"]:
306 router_compare_json_output(
307 rname, "show ip route isis json", "step3/show_ip_route.ref"
308 )
309
310
311 def test_rib_ipv6_step3():
312 logger.info("Test (step 3): verify IPv6 RIB")
313 tgen = get_topogen()
314
315 # Skip if previous fatal error condition is raised
316 if tgen.routers_have_failure():
317 pytest.skip(tgen.errors)
318
319 for rname in ["rt1", "rt6"]:
320 router_compare_json_output(
321 rname, "show ipv6 route isis json", "step3/show_ipv6_route.ref"
322 )
323
324
325 #
326 # Step 4
327 #
328 # Action(s):
329 # -restore back to default attach-bit config
330 #
331 # Expected changes:
332 # -RT1 and RT6 should add default route
333 # -no changes on other routers
334 #
335 def test_rib_ipv4_step4():
336 logger.info("Test (step 4): verify IPv4 RIB")
337 tgen = get_topogen()
338
339 # Skip if previous fatal error condition is raised
340 if tgen.routers_have_failure():
341 pytest.skip(tgen.errors)
342
343 logger.info(
344 "restore default processing on received attached-bit in LSP on RT1 and RT6"
345 )
346 tgen.net["rt1"].cmd(
347 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit receive ignore"'
348 )
349 tgen.net["rt6"].cmd(
350 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit receive ignore"'
351 )
352
353 for rname in ["rt1", "rt6"]:
354 router_compare_json_output(
355 rname, "show ip route isis json", "step4/show_ip_route.ref"
356 )
357
358
359 def test_rib_ipv6_step4():
360 logger.info("Test (step 4): verify IPv6 RIB")
361 tgen = get_topogen()
362
363 # Skip if previous fatal error condition is raised
364 if tgen.routers_have_failure():
365 pytest.skip(tgen.errors)
366
367 for rname in ["rt1", "rt6"]:
368 router_compare_json_output(
369 rname, "show ipv6 route isis json", "step4/show_ipv6_route.ref"
370 )
371
372
373 # Memory leak test template
374 def test_memory_leak():
375 "Run the memory leak test and report results."
376 tgen = get_topogen()
377 if not tgen.is_memleak_enabled():
378 pytest.skip("Memory leak test/report is disabled")
379
380 tgen.report_memory_leaks()
381
382
383 if __name__ == "__main__":
384 args = ["-s"] + sys.argv[1:]
385 sys.exit(pytest.main(args))