]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/isis_lsp_bits_topo1/test_isis_lsp_bits_topo1.py
Merge pull request #8304 from mjstapp/fix_zmq_xref
[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 # Global multi-dimensional dictionary containing all expected outputs
88 outputs = {}
89
90
91 class TemplateTopo(Topo):
92 "Test topology builder"
93
94 def build(self, *_args, **_opts):
95 "Build function"
96 tgen = get_topogen(self)
97
98 #
99 # Define FRR Routers
100 #
101 for router in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
102 tgen.add_router(router)
103
104 #
105 # Define connections
106 #
107 switch = tgen.add_switch("s1")
108 switch.add_link(tgen.gears["rt1"], nodeif="eth-sw1")
109 switch.add_link(tgen.gears["rt2"], nodeif="eth-sw1")
110 switch.add_link(tgen.gears["rt3"], nodeif="eth-sw1")
111
112 switch = tgen.add_switch("s2")
113 switch.add_link(tgen.gears["rt2"], nodeif="eth-rt4")
114 switch.add_link(tgen.gears["rt4"], nodeif="eth-rt2")
115
116 switch = tgen.add_switch("s4")
117 switch.add_link(tgen.gears["rt3"], nodeif="eth-rt5")
118 switch.add_link(tgen.gears["rt5"], nodeif="eth-rt3")
119
120 switch = tgen.add_switch("s6")
121 switch.add_link(tgen.gears["rt4"], nodeif="eth-rt5")
122 switch.add_link(tgen.gears["rt5"], nodeif="eth-rt4")
123
124 switch = tgen.add_switch("s7")
125 switch.add_link(tgen.gears["rt4"], nodeif="eth-rt6")
126 switch.add_link(tgen.gears["rt6"], nodeif="eth-rt4")
127
128 switch = tgen.add_switch("s8")
129 switch.add_link(tgen.gears["rt5"], nodeif="eth-rt6")
130 switch.add_link(tgen.gears["rt6"], nodeif="eth-rt5")
131
132
133 def setup_module(mod):
134 "Sets up the pytest environment"
135 tgen = Topogen(TemplateTopo, mod.__name__)
136 tgen.start_topology()
137
138 router_list = tgen.routers()
139
140 # For all registered routers, load the zebra configuration file
141 for rname, router in router_list.items():
142 router.load_config(
143 TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
144 )
145 router.load_config(
146 TopoRouter.RD_ISIS, os.path.join(CWD, "{}/isisd.conf".format(rname))
147 )
148
149 tgen.start_router()
150
151
152 def teardown_module(mod):
153 "Teardown the pytest environment"
154 tgen = get_topogen()
155
156 # This function tears down the whole topology.
157 tgen.stop_topology()
158
159
160 def router_compare_json_output(rname, command, reference):
161 "Compare router JSON output"
162
163 logger.info('Comparing router "%s" "%s" output', rname, command)
164
165 tgen = get_topogen()
166 filename = "{}/{}/{}".format(CWD, rname, reference)
167 expected = json.loads(open(filename).read())
168
169 # Run test function until we get an result. Wait at most 60 seconds.
170 test_func = partial(topotest.router_json_cmp, tgen.gears[rname], command, expected)
171 _, diff = topotest.run_and_expect(test_func, None, count=120, wait=0.5)
172 assertmsg = '"{}" JSON output mismatches the expected result'.format(rname)
173 assert diff is None, assertmsg
174
175
176 #
177 # Step 1
178 #
179 # Test initial network convergence
180 # Attach-bit defaults to on, so expect default route pointing to L1|L2 router
181 #
182 def test_isis_adjacencies_step1():
183 logger.info("Test (step 1): check IS-IS adjacencies")
184 tgen = get_topogen()
185
186 # Skip if previous fatal error condition is raised
187 if tgen.routers_have_failure():
188 pytest.skip(tgen.errors)
189
190 for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
191 router_compare_json_output(
192 rname,
193 "show yang operational-data /frr-interface:lib isisd",
194 "step1/show_yang_interface_isis_adjacencies.ref",
195 )
196
197
198 def test_rib_ipv4_step1():
199 logger.info("Test (step 1): verify IPv4 RIB")
200 tgen = get_topogen()
201
202 # Skip if previous fatal error condition is raised
203 if tgen.routers_have_failure():
204 pytest.skip(tgen.errors)
205
206 for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
207 router_compare_json_output(
208 rname, "show ip route isis json", "step1/show_ip_route.ref"
209 )
210
211
212 def test_rib_ipv6_step1():
213 logger.info("Test (step 1): verify IPv6 RIB")
214 tgen = get_topogen()
215
216 # Skip if previous fatal error condition is raised
217 if tgen.routers_have_failure():
218 pytest.skip(tgen.errors)
219
220 for rname in ["rt1", "rt2", "rt3", "rt4", "rt5", "rt6"]:
221 router_compare_json_output(
222 rname, "show ipv6 route isis json", "step1/show_ipv6_route.ref"
223 )
224
225
226 #
227 # Step 2
228 #
229 # Action(s):
230 # -Disable sending Attach bit on RT2 and RT4
231 #
232 # Expected changes:
233 # -RT1 should remove the default route pointing to RT2
234 # -RT6 should remove the default route pointing to RT4
235 #
236 def test_rib_ipv4_step2():
237 logger.info("Test (step 2): verify IPv4 RIB")
238 tgen = get_topogen()
239
240 # Skip if previous fatal error condition is raised
241 if tgen.routers_have_failure():
242 pytest.skip(tgen.errors)
243
244 logger.info("Disabling setting the attached-bit on RT2 and RT4")
245 tgen.net["rt2"].cmd(
246 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit send"'
247 )
248 tgen.net["rt4"].cmd(
249 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit send"'
250 )
251
252 for rname in ["rt1", "rt6"]:
253 router_compare_json_output(
254 rname, "show ip route isis json", "step2/show_ip_route.ref"
255 )
256
257
258 def test_rib_ipv6_step2():
259 logger.info("Test (step 2): verify IPv6 RIB")
260 tgen = get_topogen()
261
262 # Skip if previous fatal error condition is raised
263 if tgen.routers_have_failure():
264 pytest.skip(tgen.errors)
265
266 for rname in ["rt1", "rt6"]:
267 router_compare_json_output(
268 rname, "show ipv6 route isis json", "step2/show_ipv6_route.ref"
269 )
270
271
272 #
273 # Step 3
274 #
275 # Action(s):
276 # -restore attach-bit, enable sending attach-bit
277 # -disble processing a LSP with attach bit set
278 #
279 # Expected changes:
280 # -RT1 and RT6 should not install a default route
281 #
282 def test_rib_ipv4_step3():
283 logger.info("Test (step 3): verify IPv4 RIB")
284 tgen = get_topogen()
285
286 # Skip if previous fatal error condition is raised
287 if tgen.routers_have_failure():
288 pytest.skip(tgen.errors)
289
290 logger.info("Enable setting the attached-bit on RT2 and RT4")
291 tgen.net["rt2"].cmd('vtysh -c "conf t" -c "router isis 1" -c "attached-bit send"')
292 tgen.net["rt4"].cmd('vtysh -c "conf t" -c "router isis 1" -c "attached-bit send"')
293
294 logger.info("Disable processing received attached-bit in LSP on RT1 and RT6")
295 tgen.net["rt1"].cmd(
296 'vtysh -c "conf t" -c "router isis 1" -c "attached-bit receive ignore"'
297 )
298 tgen.net["rt6"].cmd(
299 'vtysh -c "conf t" -c "router isis 1" -c "attached-bit receive ignore"'
300 )
301
302 for rname in ["rt1", "rt6"]:
303 router_compare_json_output(
304 rname, "show ip route isis json", "step3/show_ip_route.ref"
305 )
306
307
308 def test_rib_ipv6_step3():
309 logger.info("Test (step 3): verify IPv6 RIB")
310 tgen = get_topogen()
311
312 # Skip if previous fatal error condition is raised
313 if tgen.routers_have_failure():
314 pytest.skip(tgen.errors)
315
316 for rname in ["rt1", "rt6"]:
317 router_compare_json_output(
318 rname, "show ipv6 route isis json", "step3/show_ipv6_route.ref"
319 )
320
321
322 #
323 # Step 4
324 #
325 # Action(s):
326 # -restore back to default attach-bit config
327 #
328 # Expected changes:
329 # -RT1 and RT6 should add default route
330 # -no changes on other routers
331 #
332 def test_rib_ipv4_step4():
333 logger.info("Test (step 4): verify IPv4 RIB")
334 tgen = get_topogen()
335
336 # Skip if previous fatal error condition is raised
337 if tgen.routers_have_failure():
338 pytest.skip(tgen.errors)
339
340 logger.info(
341 "restore default processing on received attached-bit in LSP on RT1 and RT6"
342 )
343 tgen.net["rt1"].cmd(
344 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit receive ignore"'
345 )
346 tgen.net["rt6"].cmd(
347 'vtysh -c "conf t" -c "router isis 1" -c "no attached-bit receive ignore"'
348 )
349
350 for rname in ["rt1", "rt6"]:
351 router_compare_json_output(
352 rname, "show ip route isis json", "step4/show_ip_route.ref"
353 )
354
355
356 def test_rib_ipv6_step4():
357 logger.info("Test (step 4): verify IPv6 RIB")
358 tgen = get_topogen()
359
360 # Skip if previous fatal error condition is raised
361 if tgen.routers_have_failure():
362 pytest.skip(tgen.errors)
363
364 for rname in ["rt1", "rt6"]:
365 router_compare_json_output(
366 rname, "show ipv6 route isis json", "step4/show_ipv6_route.ref"
367 )
368
369
370 # Memory leak test template
371 def test_memory_leak():
372 "Run the memory leak test and report results."
373 tgen = get_topogen()
374 if not tgen.is_memleak_enabled():
375 pytest.skip("Memory leak test/report is disabled")
376
377 tgen.report_memory_leaks()
378
379
380 if __name__ == "__main__":
381 args = ["-s"] + sys.argv[1:]
382 sys.exit(pytest.main(args))