]>
Commit | Line | Data |
---|---|---|
bcce6954 | 1 | #!/usr/bin/python |
acddc0ed | 2 | # SPDX-License-Identifier: ISC |
bcce6954 | 3 | |
4 | # | |
5 | # Copyright (c) 2020 by VMware, Inc. ("VMware") | |
6 | # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. | |
7 | # ("NetDEF") in this file. | |
8 | # | |
bcce6954 | 9 | |
10 | ||
11 | """OSPF Summarisation Functionality Automation.""" | |
12 | import os | |
13 | import sys | |
14 | import time | |
15 | import pytest | |
bcce6954 | 16 | |
17 | # Save the Current Working Directory to find configuration files. | |
18 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
19 | sys.path.append(os.path.join(CWD, "../")) | |
20 | sys.path.append(os.path.join(CWD, "../lib/")) | |
21 | ||
22 | # pylint: disable=C0413 | |
23 | # Import topogen and topotest helpers | |
bcce6954 | 24 | from lib.topogen import Topogen, get_topogen |
25 | import ipaddress | |
26 | from time import sleep | |
27 | ||
28 | # Import topoJson from lib, to create topology and initial configuration | |
29 | from lib.common_config import ( | |
30 | start_topology, | |
31 | write_test_header, | |
32 | kill_router_daemons, | |
33 | write_test_footer, | |
34 | reset_config_on_routers, | |
35 | stop_router, | |
36 | start_router, | |
37 | verify_rib, | |
38 | create_static_routes, | |
39 | step, | |
40 | start_router_daemons, | |
41 | create_route_maps, | |
42 | shutdown_bringup_interface, | |
bcce6954 | 43 | create_prefix_lists, |
44 | create_route_maps, | |
45 | create_interfaces_cfg, | |
46 | ) | |
47 | from lib.topolog import logger | |
4953ca97 | 48 | from lib.topojson import build_config_from_json |
bcce6954 | 49 | from lib.ospf import ( |
50 | verify_ospf_neighbor, | |
51 | clear_ospf, | |
52 | verify_ospf_rib, | |
53 | create_router_ospf, | |
54 | verify_ospf_summary, | |
55 | ) | |
56 | ||
6ff492b1 DS |
57 | pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] |
58 | ||
59 | ||
bcce6954 | 60 | # Global variables |
61 | topo = None | |
bcce6954 | 62 | |
63 | NETWORK = { | |
64 | "ipv4": [ | |
65 | "11.0.20.1/32", | |
66 | "11.0.20.2/32", | |
67 | "11.0.20.3/32", | |
68 | "11.0.20.4/32", | |
69 | "11.0.20.5/32", | |
70 | ] | |
71 | } | |
72 | NETWORK_11 = {"ipv4": ["11.0.20.6/32", "11.0.20.7/32"]} | |
73 | ||
74 | NETWORK2 = { | |
75 | "ipv4": [ | |
76 | "12.0.20.1/32", | |
77 | "12.0.20.2/32", | |
78 | "12.0.20.3/32", | |
79 | "12.0.20.4/32", | |
80 | "12.0.20.5/32", | |
81 | ] | |
82 | } | |
83 | SUMMARY = {"ipv4": ["11.0.0.0/8", "12.0.0.0/8", "11.0.0.0/24"]} | |
84 | """ | |
85 | TOPOOLOGY = | |
86 | Please view in a fixed-width font such as Courier. | |
87 | +---+ A0 +---+ | |
88 | +R1 +------------+R2 | | |
89 | +-+-+- +--++ | |
90 | | -- -- | | |
91 | | -- A0 -- | | |
92 | A0| ---- | | |
93 | | ---- | A0 | |
94 | | -- -- | | |
95 | | -- -- | | |
96 | +-+-+- +-+-+ | |
97 | +R0 +-------------+R3 | | |
98 | +---+ A0 +---+ | |
99 | ||
100 | TESTCASES = | |
101 | 1. OSPF summarisation functionality. | |
102 | 2. OSPF summarisation with metric type 2. | |
103 | 3. OSPF summarisation with Tag option | |
104 | 4. OSPF summarisation with advertise and no advertise option | |
105 | 5. OSPF summarisation Chaos. | |
106 | 6. OSPF summarisation with route map filtering. | |
107 | 7. OSPF summarisation with route map modification of metric type. | |
108 | 8. OSPF CLI Show verify ospf ASBR summary config and show commands behaviours. | |
109 | """ | |
110 | ||
111 | ||
bcce6954 | 112 | def setup_module(mod): |
113 | """ | |
114 | Sets up the pytest environment | |
115 | ||
116 | * `mod`: module name | |
117 | """ | |
bcce6954 | 118 | testsuite_run_time = time.asctime(time.localtime(time.time())) |
119 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
120 | logger.info("=" * 40) | |
121 | ||
122 | logger.info("Running setup_module to create topology") | |
123 | ||
124 | # This function initiates the topology build with Topogen... | |
e82b531d CH |
125 | json_file = "{}/ospf_asbr_summary_topo1.json".format(CWD) |
126 | tgen = Topogen(json_file, mod.__name__) | |
127 | global topo | |
128 | topo = tgen.json_topo | |
bcce6954 | 129 | # ... and here it calls Mininet initialization functions. |
130 | ||
bcce6954 | 131 | # Starting topology, create tmp files which are loaded to routers |
d60a3f0e | 132 | # to start daemons and then start routers |
991a971f | 133 | start_topology(tgen) |
bcce6954 | 134 | |
135 | # Creating configuration from JSON | |
136 | build_config_from_json(tgen, topo) | |
137 | ||
138 | # Don't run this test if we have any failure. | |
139 | if tgen.routers_have_failure(): | |
140 | pytest.skip(tgen.errors) | |
141 | # Api call verify whether OSPF is converged | |
142 | ospf_covergence = verify_ospf_neighbor(tgen, topo) | |
143 | assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( | |
144 | ospf_covergence | |
145 | ) | |
146 | ||
147 | logger.info("Running setup_module() done") | |
148 | ||
149 | ||
150 | def teardown_module(mod): | |
151 | """ | |
152 | Teardown the pytest environment. | |
153 | ||
154 | * `mod`: module name | |
155 | """ | |
156 | ||
157 | logger.info("Running teardown_module to delete topology") | |
158 | ||
159 | tgen = get_topogen() | |
160 | ||
161 | # Stop toplogy and Remove tmp files | |
162 | tgen.stop_topology() | |
163 | ||
164 | logger.info( | |
165 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
166 | ) | |
167 | logger.info("=" * 40) | |
168 | ||
169 | ||
170 | def red_static(dut, config=True): | |
171 | """ | |
172 | Local 'def' for Redstribute static routes inside ospf. | |
173 | ||
174 | Parameters | |
175 | ---------- | |
176 | * `dut` : DUT on which configs have to be made. | |
177 | * `config` : True or False, True by default for configure, set False for | |
178 | unconfiguration. | |
179 | """ | |
180 | global topo | |
181 | tgen = get_topogen() | |
182 | if config: | |
183 | ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "static"}]}}} | |
184 | else: | |
185 | ospf_red = { | |
186 | dut: {"ospf": {"redistribute": [{"redist_type": "static", "delete": True}]}} | |
187 | } | |
188 | result = create_router_ospf(tgen, topo, ospf_red) | |
189 | assert result is True, "Testcase : Failed \n Error: {}".format(result) | |
190 | ||
191 | ||
192 | def red_connected(dut, config=True): | |
193 | """ | |
194 | Local 'def' for Redstribute connected routes inside ospf | |
195 | ||
196 | Parameters | |
197 | ---------- | |
198 | * `dut` : DUT on which configs have to be made. | |
199 | * `config` : True or False, True by default for configure, set False for | |
200 | unconfiguration. | |
201 | """ | |
202 | global topo | |
203 | tgen = get_topogen() | |
204 | if config: | |
205 | ospf_red = {dut: {"ospf": {"redistribute": [{"redist_type": "connected"}]}}} | |
206 | else: | |
207 | ospf_red = { | |
208 | dut: { | |
209 | "ospf": {"redistribute": [{"redist_type": "connected", "delete": True}]} | |
210 | } | |
211 | } | |
212 | result = create_router_ospf(tgen, topo, ospf_red) | |
213 | assert result is True, "Testcase: Failed \n Error: {}".format(result) | |
214 | ||
215 | ||
216 | # ################################## | |
217 | # Test cases start here. | |
218 | # ################################## | |
219 | ||
220 | ||
221 | def test_ospf_type5_summary_tc43_p0(request): | |
222 | """OSPF summarisation with metric type 2.""" | |
223 | tc_name = request.node.name | |
224 | write_test_header(tc_name) | |
225 | tgen = get_topogen() | |
226 | ||
227 | # Don't run this test if we have any failure. | |
228 | if tgen.routers_have_failure(): | |
229 | pytest.skip(tgen.errors) | |
230 | ||
231 | global topo | |
232 | step("Bring up the base config as per the topology") | |
233 | reset_config_on_routers(tgen) | |
234 | ||
235 | protocol = "ospf" | |
236 | ||
237 | step( | |
238 | "Configure 5 static routes from the same network on R0" | |
239 | "5 static routes from different networks and redistribute in R0" | |
240 | ) | |
241 | input_dict_static_rtes = { | |
242 | "r0": { | |
243 | "static_routes": [ | |
244 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
245 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
246 | ] | |
247 | } | |
248 | } | |
249 | result = create_static_routes(tgen, input_dict_static_rtes) | |
250 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
251 | ||
252 | dut = "r0" | |
253 | red_static(dut) | |
254 | ||
255 | step("Verify that routes are learnt on R1.") | |
256 | dut = "r1" | |
257 | ||
258 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
259 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
260 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
261 | assert ( | |
262 | result is True | |
263 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
264 | ||
265 | step( | |
266 | "Configure External Route summary in R0 to summarise 5" " routes to one route." | |
267 | ) | |
268 | ospf_summ_r1 = { | |
269 | "r0": { | |
270 | "ospf": { | |
271 | "summary-address": [ | |
272 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
273 | ] | |
274 | } | |
275 | } | |
276 | } | |
277 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
278 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
279 | step( | |
280 | "Verify that external routes are summarised to configured summary " | |
281 | "address on R0 after 5 secs of delay timer expiry and only one " | |
282 | "route is sent to R1." | |
283 | ) | |
284 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
285 | dut = "r1" | |
286 | ||
287 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
288 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
289 | ||
290 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
291 | assert ( | |
292 | result is True | |
293 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
294 | ||
295 | step("Verify that show ip ospf summary should show the summaries.") | |
296 | input_dict = { | |
297 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
298 | "summaryAddress": SUMMARY["ipv4"][0], |
299 | "metricType": "E2", | |
300 | "metric": 20, | |
301 | "tag": 0, | |
302 | "externalRouteCount": 5, | |
bcce6954 | 303 | } |
304 | } | |
305 | dut = "r0" | |
306 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
307 | assert ( | |
308 | result is True | |
309 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
310 | ||
311 | step("Change the summary address mask to lower match (ex - 16 to 8)") | |
312 | ospf_summ_r1 = { | |
313 | "r0": { | |
314 | "ospf": { | |
315 | "summary-address": [ | |
316 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "16"} | |
317 | ] | |
318 | } | |
319 | } | |
320 | } | |
321 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
322 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
323 | ||
324 | input_dict = { | |
325 | "11.0.0.0/16": { | |
f932966b DA |
326 | "summaryAddress": "11.0.0.0/16", |
327 | "metricType": "E2", | |
328 | "metric": 20, | |
329 | "tag": 0, | |
330 | "externalRouteCount": 5, | |
bcce6954 | 331 | } |
332 | } | |
333 | dut = "r0" | |
334 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
335 | assert ( | |
336 | result is True | |
337 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
338 | ||
339 | step( | |
340 | "Verify that external routes(static / connected) are summarised" | |
341 | " to configured summary address with newly configured mask." | |
342 | ) | |
343 | ||
344 | input_dict_summary = {"r0": {"static_routes": [{"network": "11.0.0.0/16"}]}} | |
345 | dut = "r1" | |
346 | ||
347 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
348 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
349 | ||
350 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
351 | assert ( | |
352 | result is True | |
353 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
354 | ||
355 | step("Change the summary address mask to higher match (ex - 8 to 24)") | |
356 | ospf_summ_r1 = { | |
357 | "r0": { | |
358 | "ospf": { | |
359 | "summary-address": [ | |
360 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "24"} | |
361 | ] | |
362 | } | |
363 | } | |
364 | } | |
365 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
366 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
367 | ||
368 | input_dict = { | |
369 | "11.0.0.0/16": { | |
f932966b DA |
370 | "summaryAddress": "11.0.0.0/24", |
371 | "metricType": "E2", | |
372 | "metric": 20, | |
373 | "tag": 0, | |
374 | "externalRouteCount": 0, | |
bcce6954 | 375 | } |
376 | } | |
377 | dut = "r0" | |
378 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
379 | assert ( | |
380 | result is True | |
381 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
382 | ||
383 | step( | |
384 | "Verify that external routes(static / connected) are summarised" | |
385 | " to configured summary address with newly configured mask." | |
386 | ) | |
387 | step("Configure 2 summary address with different mask of same network.") | |
388 | step( | |
389 | "Verify that external routes(static / connected) are summarised " | |
390 | "to configured summary address with highest match." | |
391 | ) | |
392 | ||
393 | input_dict_summary = {"r0": {"static_routes": [{"network": "11.0.0.0/16"}]}} | |
394 | dut = "r1" | |
395 | ||
396 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
397 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
398 | ||
399 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
400 | assert ( | |
401 | result is True | |
402 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
403 | ||
404 | step(" Un configure one of the summary address.") | |
405 | ospf_summ_r1 = { | |
406 | "r0": { | |
407 | "ospf": { | |
408 | "summary-address": [ | |
409 | { | |
410 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
411 | "mask": "24", | |
412 | "delete": True, | |
413 | } | |
414 | ] | |
415 | } | |
416 | } | |
417 | } | |
418 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
419 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
420 | ||
421 | step( | |
422 | "Verify that external routes(static / connected) are summarised" | |
423 | " to configured summary address with newly configured mask." | |
424 | ) | |
425 | ||
426 | input_dict_summary = {"r0": {"static_routes": [{"network": "11.0.0.0/16"}]}} | |
427 | dut = "r1" | |
428 | ||
429 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
430 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
431 | ||
432 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
433 | assert ( | |
434 | result is True | |
435 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
436 | ||
437 | ospf_summ_r1 = { | |
438 | "r0": { | |
439 | "ospf": { | |
440 | "summary-address": [ | |
441 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "24"} | |
442 | ] | |
443 | } | |
444 | } | |
445 | } | |
446 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
447 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
448 | ||
449 | step( | |
450 | "Verify that external routes(static / connected) are summarised " | |
451 | "to configured summary address with highest match." | |
452 | ) | |
453 | input_dict_summary = {"r0": {"static_routes": [{"network": "11.0.0.0/16"}]}} | |
454 | dut = "r1" | |
455 | ||
456 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
457 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
458 | ||
459 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
460 | assert ( | |
461 | result is True | |
462 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
463 | ||
464 | write_test_footer(tc_name) | |
465 | ||
466 | ||
467 | def test_ospf_type5_summary_tc48_p0(request): | |
468 | """OSPF summarisation with route map modification of metric type.""" | |
469 | tc_name = request.node.name | |
470 | write_test_header(tc_name) | |
471 | tgen = get_topogen() | |
472 | ||
473 | # Don't run this test if we have any failure. | |
474 | if tgen.routers_have_failure(): | |
475 | pytest.skip(tgen.errors) | |
476 | ||
477 | global topo | |
478 | step("Bring up the base config as per the topology") | |
479 | reset_config_on_routers(tgen) | |
480 | ||
481 | protocol = "ospf" | |
482 | ||
483 | step( | |
484 | "Configure 5 static routes from the same network on R0" | |
485 | "5 static routes from different networks and redistribute in R0" | |
486 | ) | |
487 | input_dict_static_rtes = { | |
488 | "r0": { | |
489 | "static_routes": [ | |
490 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
491 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
492 | ] | |
493 | } | |
494 | } | |
495 | result = create_static_routes(tgen, input_dict_static_rtes) | |
496 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
497 | ||
498 | dut = "r0" | |
499 | red_static(dut) | |
500 | ||
501 | step("Verify that routes are learnt on R1.") | |
502 | dut = "r1" | |
503 | ||
504 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
505 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
506 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
507 | assert ( | |
508 | result is True | |
509 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
510 | ||
511 | step( | |
512 | "Configure External Route summary in R0 to summarise 5" " routes to one route." | |
513 | ) | |
514 | ||
515 | ospf_summ_r1 = { | |
516 | "r0": { | |
517 | "ospf": { | |
518 | "summary-address": [ | |
519 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
520 | ] | |
521 | } | |
522 | } | |
523 | } | |
524 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
525 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
526 | ||
527 | step( | |
528 | "Verify that external routes are summarised to configured summary " | |
529 | "address on R0 after 5 secs of delay timer expiry and only one " | |
530 | "route is sent to R1." | |
531 | ) | |
532 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
533 | dut = "r1" | |
534 | ||
535 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
536 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
537 | ||
538 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
539 | assert ( | |
540 | result is True | |
541 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
542 | ||
543 | step("Verify that show ip ospf summary should show the summaries.") | |
544 | input_dict = { | |
545 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
546 | "summaryAddress": SUMMARY["ipv4"][0], |
547 | "metricType": "E2", | |
548 | "metric": 20, | |
549 | "tag": 0, | |
550 | "externalRouteCount": 5, | |
bcce6954 | 551 | } |
552 | } | |
553 | dut = "r0" | |
554 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
555 | assert ( | |
556 | result is True | |
557 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
558 | ||
559 | step("Verify that originally advertised routes are withdraw from there" " peer.") | |
560 | input_dict = { | |
561 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
562 | } | |
563 | dut = "r1" | |
564 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
565 | assert ( | |
566 | result is not True | |
567 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
568 | tc_name, result | |
569 | ) | |
570 | ||
571 | result = verify_rib( | |
572 | tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False | |
573 | ) | |
574 | assert ( | |
575 | result is not True | |
576 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
577 | ||
578 | step( | |
579 | "Configure route map and & rule to permit configured summary address," | |
580 | " redistribute static & connected routes with the route map." | |
581 | ) | |
582 | step("Configure prefixlist to permit the static routes, add to route map.") | |
583 | # Create ip prefix list | |
584 | pfx_list = { | |
585 | "r0": { | |
586 | "prefix_lists": { | |
587 | "ipv4": { | |
588 | "pf_list_1_ipv4": [ | |
589 | {"seqid": 10, "network": "any", "action": "permit"} | |
590 | ] | |
591 | } | |
592 | } | |
593 | } | |
594 | } | |
595 | result = create_prefix_lists(tgen, pfx_list) | |
596 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
597 | ||
598 | routemaps = { | |
599 | "r0": { | |
600 | "route_maps": { | |
601 | "rmap_ipv4": [ | |
602 | { | |
603 | "action": "permit", | |
604 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
605 | } | |
606 | ] | |
607 | } | |
608 | } | |
609 | } | |
610 | result = create_route_maps(tgen, routemaps) | |
611 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
612 | ||
613 | ospf_red_r1 = { | |
614 | "r0": { | |
615 | "ospf": { | |
616 | "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv4"}] | |
617 | } | |
618 | } | |
619 | } | |
620 | result = create_router_ospf(tgen, topo, ospf_red_r1) | |
621 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
622 | ||
623 | step( | |
624 | "Verify that external routes are summarised to configured" | |
625 | "summary address on R0 and only one route is sent to R1. Verify that " | |
626 | "show ip ospf summary should show the configure summaries." | |
627 | ) | |
628 | ||
629 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
630 | dut = "r1" | |
631 | ||
632 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
633 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
634 | ||
635 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
636 | assert ( | |
637 | result is True | |
638 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
639 | ||
640 | input_dict = { | |
641 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
642 | "summaryAddress": SUMMARY["ipv4"][0], |
643 | "metricType": "E2", | |
644 | "metric": 20, | |
645 | "tag": 0, | |
646 | "externalRouteCount": 5, | |
bcce6954 | 647 | } |
648 | } | |
649 | dut = "r0" | |
650 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
651 | assert ( | |
652 | result is True | |
653 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
654 | ||
bcce6954 | 655 | write_test_footer(tc_name) |
656 | ||
657 | ||
e6a472a0 | 658 | def test_ospf_type5_summary_tc42_p0(request): |
659 | """OSPF summarisation functionality.""" | |
660 | tc_name = request.node.name | |
661 | write_test_header(tc_name) | |
662 | tgen = get_topogen() | |
663 | ||
664 | # Don't run this test if we have any failure. | |
665 | if tgen.routers_have_failure(): | |
666 | pytest.skip(tgen.errors) | |
667 | ||
668 | global topo | |
669 | step("Bring up the base config as per the topology") | |
670 | reset_config_on_routers(tgen) | |
671 | ||
672 | protocol = "ospf" | |
673 | ||
674 | step( | |
675 | "Configure 5 static routes from the same network on R0" | |
676 | "5 static routes from different networks and redistribute in R0" | |
677 | ) | |
678 | input_dict_static_rtes = { | |
679 | "r0": { | |
680 | "static_routes": [ | |
681 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
682 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
683 | ] | |
684 | } | |
685 | } | |
686 | result = create_static_routes(tgen, input_dict_static_rtes) | |
687 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
688 | ||
689 | dut = "r0" | |
690 | red_static(dut) | |
691 | ||
692 | step("Verify that routes are learnt on R1.") | |
693 | dut = "r1" | |
694 | ||
695 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
696 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
697 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
698 | assert ( | |
699 | result is True | |
700 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
701 | ||
702 | step( | |
703 | "Configure External Route summary in R0 to summarise 5" | |
704 | " routes to one route. with aggregate timer as 6 sec" | |
705 | ) | |
706 | ||
707 | ospf_summ_r1 = { | |
708 | "r0": { | |
709 | "ospf": { | |
710 | "summary-address": [ | |
711 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
712 | ], | |
713 | "aggr_timer": 6, | |
714 | } | |
715 | } | |
716 | } | |
717 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
718 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
719 | ||
720 | step( | |
721 | "Verify that external routes are summarised to configured summary " | |
722 | "address on R0 after 5 secs of delay timer expiry and only one " | |
723 | "route is sent to R1." | |
724 | ) | |
725 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
726 | dut = "r1" | |
727 | ||
728 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
729 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
730 | ||
731 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
732 | assert ( | |
733 | result is True | |
734 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
735 | ||
736 | step("Verify that show ip ospf summary should show the summaries.") | |
737 | input_dict = { | |
738 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
739 | "summaryAddress": SUMMARY["ipv4"][0], |
740 | "metricType": "E2", | |
741 | "metric": 20, | |
742 | "tag": 0, | |
743 | "externalRouteCount": 5, | |
e6a472a0 | 744 | } |
745 | } | |
746 | dut = "r0" | |
747 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
748 | assert ( | |
749 | result is True | |
750 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
751 | ||
752 | step("Verify that originally advertised routes are withdraw from there" " peer.") | |
753 | input_dict = { | |
754 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
755 | } | |
756 | dut = "r1" | |
757 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
758 | assert ( | |
759 | result is not True | |
760 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
761 | tc_name, result | |
762 | ) | |
763 | ||
764 | result = verify_rib( | |
765 | tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False | |
766 | ) | |
767 | assert ( | |
768 | result is not True | |
769 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
770 | ||
771 | step("Delete the configured summary") | |
772 | ospf_summ_r1 = { | |
773 | "r0": { | |
774 | "ospf": { | |
775 | "summary-address": [ | |
776 | { | |
777 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
778 | "mask": "8", | |
779 | "del_aggr_timer": True, | |
780 | "delete": True, | |
781 | } | |
782 | ] | |
783 | } | |
784 | } | |
785 | } | |
786 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
787 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
788 | ||
789 | step("Verify that summary lsa is withdrawn from R1 and deleted from R0.") | |
790 | dut = "r1" | |
791 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
792 | assert ( | |
793 | result is not True | |
794 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
795 | tc_name, result | |
796 | ) | |
797 | ||
798 | result = verify_rib( | |
799 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
800 | ) | |
801 | assert ( | |
802 | result is not True | |
803 | ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format( | |
804 | tc_name | |
805 | ) | |
806 | ||
807 | step("show ip ospf summary should not have any summary address.") | |
808 | input_dict = { | |
809 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
810 | "summaryAddress": SUMMARY["ipv4"][0], |
811 | "metricType": "E2", | |
812 | "metric": 20, | |
813 | "tag": 0, | |
814 | "externalRouteCount": 5, | |
e6a472a0 | 815 | } |
816 | } | |
817 | dut = "r0" | |
818 | result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False) | |
819 | assert ( | |
820 | result is not True | |
821 | ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name) | |
822 | ||
823 | dut = "r1" | |
824 | step("All 5 routes are advertised after deletion of configured summary.") | |
825 | ||
826 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
827 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
828 | ||
829 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
830 | assert ( | |
831 | result is True | |
832 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
833 | ||
834 | step("configure the summary again and delete static routes .") | |
835 | ospf_summ_r1 = { | |
836 | "r0": { | |
837 | "ospf": { | |
838 | "summary-address": [ | |
839 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
840 | ] | |
841 | } | |
842 | } | |
843 | } | |
844 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
845 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
846 | ||
847 | input_dict = { | |
848 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
849 | "summaryAddress": SUMMARY["ipv4"][0], |
850 | "metricType": "E2", | |
851 | "metric": 20, | |
852 | "tag": 0, | |
853 | "externalRouteCount": 5, | |
e6a472a0 | 854 | } |
855 | } | |
856 | dut = "r0" | |
857 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
858 | assert ( | |
859 | result is True | |
860 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
861 | ||
862 | input_dict = { | |
863 | "r0": { | |
864 | "static_routes": [ | |
865 | {"network": NETWORK["ipv4"], "next_hop": "blackhole", "delete": True} | |
866 | ] | |
867 | } | |
868 | } | |
869 | result = create_static_routes(tgen, input_dict) | |
870 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
871 | ||
872 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
873 | step("Verify that summary route is withdrawn from R1.") | |
874 | ||
875 | dut = "r1" | |
876 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) | |
877 | assert ( | |
878 | result is not True | |
879 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
880 | tc_name, result | |
881 | ) | |
882 | ||
883 | result = verify_rib( | |
884 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
885 | ) | |
886 | assert ( | |
887 | result is not True | |
888 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
889 | ||
890 | step("Add back static routes.") | |
891 | input_dict_static_rtes = { | |
892 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
893 | } | |
894 | result = create_static_routes(tgen, input_dict_static_rtes) | |
895 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
896 | ||
897 | step( | |
898 | "Verify that external routes are summarised to configured summary" | |
899 | " address on R0 and only one route is sent to R1." | |
900 | ) | |
901 | dut = "r1" | |
902 | ||
903 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes, expected=False) | |
904 | assert ( | |
905 | result is not True | |
906 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
907 | tc_name, result | |
908 | ) | |
909 | ||
910 | result = verify_rib( | |
911 | tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol, expected=False | |
912 | ) | |
913 | assert ( | |
914 | result is not True | |
915 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
916 | ||
917 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
918 | dut = "r1" | |
919 | ||
920 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
921 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
922 | ||
923 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
924 | assert ( | |
925 | result is True | |
926 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
927 | ||
928 | step("Verify that show ip ospf summary should show configure summaries.") | |
929 | ||
930 | input_dict = { | |
931 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
932 | "summaryAddress": SUMMARY["ipv4"][0], |
933 | "metricType": "E2", | |
934 | "metric": 20, | |
935 | "tag": 0, | |
936 | "externalRouteCount": 5, | |
e6a472a0 | 937 | } |
938 | } | |
939 | dut = "r0" | |
940 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
941 | assert ( | |
942 | result is True | |
943 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
944 | ||
945 | step("Configure new static route which is matching configured summary.") | |
946 | input_dict_static_rtes = { | |
947 | "r0": { | |
948 | "static_routes": [{"network": NETWORK_11["ipv4"], "next_hop": "blackhole"}] | |
949 | } | |
950 | } | |
951 | result = create_static_routes(tgen, input_dict_static_rtes) | |
952 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
953 | ||
954 | # step("verify that summary lsa is not refreshed.") | |
955 | # show ip ospf database command is not working, waiting for DEV fix. | |
956 | ||
957 | step("Delete one of the static route.") | |
958 | input_dict_static_rtes = { | |
959 | "r0": { | |
960 | "static_routes": [ | |
961 | {"network": NETWORK_11["ipv4"], "next_hop": "blackhole", "delete": True} | |
962 | ] | |
963 | } | |
964 | } | |
965 | result = create_static_routes(tgen, input_dict_static_rtes) | |
966 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
967 | ||
968 | # step("verify that summary lsa is not refreshed.") | |
969 | # show ip ospf database command is not working, waiting for DEV fix. | |
970 | ||
971 | # step("Verify that deleted static route is removed from ospf LSDB.") | |
972 | # show ip ospf database command is not working, waiting for DEV fix. | |
973 | ||
974 | step( | |
975 | "Configure redistribute connected and configure ospf external" | |
976 | " summary address to summarise the connected routes." | |
977 | ) | |
978 | ||
979 | dut = "r0" | |
980 | red_connected(dut) | |
981 | clear_ospf(tgen, dut) | |
982 | ||
983 | ip = topo["routers"]["r0"]["links"]["r3"]["ipv4"] | |
984 | ||
985 | ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network) | |
986 | ospf_summ_r1 = { | |
987 | "r0": { | |
988 | "ospf": {"summary-address": [{"prefix": ip_net.split("/")[0], "mask": "8"}]} | |
989 | } | |
990 | } | |
991 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
992 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
993 | ||
994 | step( | |
995 | "Verify that external routes are summarised to configured " | |
996 | "summary address on R0 and only one route is sent to R1." | |
997 | ) | |
998 | ||
999 | input_dict_summary = {"r0": {"static_routes": [{"network": "10.0.0.0/8"}]}} | |
1000 | dut = "r1" | |
1001 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
1002 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1003 | ||
1004 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
1005 | assert ( | |
1006 | result is True | |
1007 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1008 | ||
1009 | step("Shut one of the interface") | |
1010 | intf = topo["routers"]["r0"]["links"]["r3-link0"]["interface"] | |
1011 | shutdown_bringup_interface(tgen, dut, intf, False) | |
1012 | ||
1013 | # step("verify that summary lsa is not refreshed.") | |
1014 | # show ip ospf database command is not working, waiting for DEV fix. | |
1015 | ||
1016 | # step("Verify that deleted connected route is removed from ospf LSDB.") | |
1017 | # show ip ospf database command is not working, waiting for DEV fix. | |
1018 | ||
1019 | step("Un do shut the interface") | |
1020 | shutdown_bringup_interface(tgen, dut, intf, True) | |
1021 | ||
1022 | # step("verify that summary lsa is not refreshed.") | |
1023 | # show ip ospf database command is not working, waiting for DEV fix. | |
1024 | ||
1025 | # step("Verify that deleted connected route is removed from ospf LSDB.") | |
1026 | # show ip ospf database command is not working, waiting for DEV fix. | |
1027 | ||
1028 | step("Delete OSPF process.") | |
1029 | ospf_del = {"r0": {"ospf": {"delete": True}}} | |
1030 | result = create_router_ospf(tgen, topo, ospf_del) | |
1031 | assert result is True, "Testcase : Failed \n Error: {}".format(result) | |
1032 | ||
1033 | step("Reconfigure ospf process with summary") | |
1034 | reset_config_on_routers(tgen) | |
1035 | ||
1036 | input_dict_static_rtes = { | |
1037 | "r0": { | |
1038 | "static_routes": [ | |
1039 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
1040 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
1041 | ] | |
1042 | } | |
1043 | } | |
1044 | result = create_static_routes(tgen, input_dict_static_rtes) | |
1045 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1046 | ||
1047 | dut = "r0" | |
1048 | red_static(dut) | |
1049 | red_connected(dut) | |
1050 | ospf_summ_r1 = { | |
1051 | "r0": { | |
1052 | "ospf": { | |
1053 | "summary-address": [ | |
1054 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
1055 | ] | |
1056 | } | |
1057 | } | |
1058 | } | |
1059 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1060 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1061 | step( | |
1062 | "Verify that external routes are summarised to configured summary " | |
1063 | "address on R0 and only one route is sent to R1." | |
1064 | ) | |
1065 | ||
1066 | input_dict = { | |
1067 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1068 | "summaryAddress": SUMMARY["ipv4"][0], |
1069 | "metricType": "E2", | |
1070 | "metric": 20, | |
1071 | "tag": 0, | |
1072 | "externalRouteCount": 5, | |
e6a472a0 | 1073 | } |
1074 | } | |
1075 | dut = "r0" | |
1076 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
1077 | assert ( | |
1078 | result is True | |
1079 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
1080 | ||
1081 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
1082 | ||
1083 | dut = "r1" | |
1084 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
1085 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1086 | ||
1087 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
1088 | assert ( | |
1089 | result is True | |
1090 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1091 | ||
1092 | ospf_summ_r1 = { | |
1093 | "r0": { | |
1094 | "ospf": { | |
1095 | "summary-address": [ | |
1096 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
1097 | ] | |
1098 | } | |
1099 | } | |
1100 | } | |
1101 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1102 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1103 | ||
1104 | # step("verify that summary lsa is not refreshed.") | |
1105 | # show ip ospf database command is not working, waiting for DEV fix. | |
1106 | ||
1107 | step("Delete the redistribute command in ospf.") | |
1108 | dut = "r0" | |
1109 | red_connected(dut, config=False) | |
1110 | red_static(dut, config=False) | |
1111 | ||
1112 | step("Verify that summary route is withdrawn from the peer.") | |
1113 | ||
1114 | dut = "r1" | |
1115 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) | |
1116 | assert ( | |
1117 | result is not True | |
1118 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
1119 | tc_name, result | |
1120 | ) | |
1121 | ||
1122 | result = verify_rib( | |
1123 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
1124 | ) | |
1125 | assert ( | |
1126 | result is not True | |
1127 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
1128 | ||
1129 | ospf_summ_r1 = { | |
1130 | "r0": { | |
1131 | "ospf": { | |
1132 | "summary-address": [ | |
1133 | { | |
1134 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1135 | "mask": "8", | |
1136 | "metric": "1234", | |
1137 | } | |
1138 | ] | |
1139 | } | |
1140 | } | |
1141 | } | |
1142 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1143 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1144 | ||
1145 | write_test_footer(tc_name) | |
1146 | ||
1147 | ||
1148 | def test_ospf_type5_summary_tc45_p0(request): | |
1149 | """OSPF summarisation with Tag option""" | |
1150 | tc_name = request.node.name | |
1151 | write_test_header(tc_name) | |
1152 | tgen = get_topogen() | |
1153 | ||
1154 | # Don't run this test if we have any failure. | |
1155 | if tgen.routers_have_failure(): | |
1156 | pytest.skip(tgen.errors) | |
1157 | ||
1158 | global topo | |
1159 | step("Bring up the base config as per the topology") | |
1160 | step("Configure OSPF on all the routers of the topology.") | |
1161 | reset_config_on_routers(tgen) | |
1162 | ||
1163 | protocol = "ospf" | |
1164 | ||
1165 | step( | |
1166 | "Configure 5 static routes from the same network on R0" | |
1167 | "5 static routes from different networks and redistribute in R0" | |
1168 | ) | |
1169 | input_dict_static_rtes = { | |
1170 | "r0": { | |
1171 | "static_routes": [ | |
1172 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
1173 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
1174 | ] | |
1175 | } | |
1176 | } | |
1177 | result = create_static_routes(tgen, input_dict_static_rtes) | |
1178 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1179 | ||
1180 | dut = "r0" | |
1181 | red_static(dut) | |
1182 | ||
1183 | step("Verify that routes are learnt on R1.") | |
1184 | dut = "r1" | |
1185 | ||
1186 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
1187 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1188 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
1189 | assert ( | |
1190 | result is True | |
1191 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1192 | ||
1193 | step( | |
1194 | "Configure External Route summary in R0 to summarise 5" " routes to one route." | |
1195 | ) | |
1196 | ospf_summ_r1 = { | |
1197 | "r0": { | |
1198 | "ospf": { | |
1199 | "summary-address": [ | |
1200 | { | |
1201 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1202 | "mask": "8", | |
1203 | "tag": "1234", | |
1204 | } | |
1205 | ] | |
1206 | } | |
1207 | } | |
1208 | } | |
1209 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1210 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1211 | ||
1212 | step( | |
1213 | "Verify that external routes are summarised to configured summary" | |
1214 | " address on R0 and only one route is sent to R1 with configured tag." | |
1215 | ) | |
1216 | input_dict_summary = { | |
1217 | "r0": {"static_routes": [{"network": SUMMARY["ipv4"][0], "tag": "1234"}]} | |
1218 | } | |
1219 | dut = "r1" | |
1220 | ||
1221 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
1222 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1223 | ||
1224 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
1225 | assert ( | |
1226 | result is True | |
1227 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1228 | ||
1229 | step("Verify that show ip ospf summary should show the summaries with tag.") | |
1230 | input_dict = { | |
1231 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1232 | "summaryAddress": SUMMARY["ipv4"][0], |
1233 | "metricType": "E2", | |
1234 | "metric": 20, | |
1235 | "tag": 1234, | |
1236 | "externalRouteCount": 5, | |
e6a472a0 | 1237 | } |
1238 | } | |
1239 | dut = "r0" | |
1240 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
1241 | assert ( | |
1242 | result is True | |
1243 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
1244 | ||
1245 | step("Delete the configured summary") | |
1246 | ospf_summ_r1 = { | |
1247 | "r0": { | |
1248 | "ospf": { | |
1249 | "summary-address": [ | |
1250 | { | |
1251 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1252 | "mask": "8", | |
1253 | "tag": "1234", | |
1254 | "delete": True, | |
1255 | } | |
1256 | ] | |
1257 | } | |
1258 | } | |
1259 | } | |
1260 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1261 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1262 | ||
1263 | step("Verify that summary lsa is withdrawn from R1 and deleted from R0.") | |
1264 | dut = "r1" | |
0779f177 | 1265 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) |
e6a472a0 | 1266 | assert ( |
1267 | result is not True | |
1268 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
1269 | tc_name, result | |
1270 | ) | |
1271 | ||
1272 | result = verify_rib( | |
1273 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
1274 | ) | |
1275 | assert ( | |
1276 | result is not True | |
1277 | ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format( | |
1278 | tc_name | |
1279 | ) | |
1280 | ||
1281 | step("show ip ospf summary should not have any summary address.") | |
1282 | input_dict = { | |
1283 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1284 | "summaryAddress": SUMMARY["ipv4"][0], |
1285 | "metricType": "E2", | |
1286 | "metric": 20, | |
1287 | "tag": 1234, | |
1288 | "externalRouteCount": 5, | |
e6a472a0 | 1289 | } |
1290 | } | |
1291 | dut = "r0" | |
1292 | result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False) | |
1293 | assert ( | |
1294 | result is not True | |
1295 | ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name) | |
1296 | ||
1297 | step("Configure Min tag value") | |
1298 | ospf_summ_r1 = { | |
1299 | "r0": { | |
1300 | "ospf": { | |
1301 | "summary-address": [ | |
1302 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8", "tag": 1} | |
1303 | ] | |
1304 | } | |
1305 | } | |
1306 | } | |
1307 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1308 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1309 | input_dict_summary = { | |
1310 | "r0": {"static_routes": [{"network": SUMMARY["ipv4"][0], "tag": "1"}]} | |
1311 | } | |
1312 | dut = "r1" | |
1313 | ||
1314 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
1315 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1316 | ||
1317 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
1318 | assert ( | |
1319 | result is True | |
1320 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1321 | ||
1322 | step("Verify that show ip ospf summary should show the summaries with tag.") | |
1323 | input_dict = { | |
1324 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1325 | "summaryAddress": SUMMARY["ipv4"][0], |
1326 | "metricType": "E2", | |
1327 | "metric": 20, | |
1328 | "tag": 1, | |
1329 | "externalRouteCount": 5, | |
e6a472a0 | 1330 | } |
1331 | } | |
1332 | dut = "r0" | |
1333 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
1334 | assert ( | |
1335 | result is True | |
1336 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
1337 | ||
1338 | step("Configure Max Tag Value") | |
1339 | ospf_summ_r1 = { | |
1340 | "r0": { | |
1341 | "ospf": { | |
1342 | "summary-address": [ | |
1343 | { | |
1344 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1345 | "mask": "8", | |
1346 | "tag": 4294967295, | |
1347 | } | |
1348 | ] | |
1349 | } | |
1350 | } | |
1351 | } | |
1352 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1353 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1354 | ||
1355 | input_dict_summary = { | |
1356 | "r0": {"static_routes": [{"network": SUMMARY["ipv4"][0], "tag": "4294967295"}]} | |
1357 | } | |
1358 | dut = "r1" | |
1359 | ||
1360 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
1361 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1362 | ||
1363 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
1364 | assert ( | |
1365 | result is True | |
1366 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1367 | ||
1368 | step( | |
1369 | "Verify that boundary values tags are used for summary route" | |
1370 | " using show ip ospf route command." | |
1371 | ) | |
1372 | input_dict = { | |
1373 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1374 | "summaryAddress": SUMMARY["ipv4"][0], |
1375 | "metricType": "E2", | |
1376 | "metric": 20, | |
1377 | "tag": 4294967295, | |
1378 | "externalRouteCount": 5, | |
e6a472a0 | 1379 | } |
1380 | } | |
1381 | dut = "r0" | |
1382 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
1383 | assert ( | |
1384 | result is True | |
1385 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
1386 | ||
1387 | step("configure new static route with different tag.") | |
1388 | input_dict_static_rtes_11 = { | |
1389 | "r0": { | |
1390 | "static_routes": [ | |
1391 | {"network": NETWORK_11["ipv4"], "next_hop": "blackhole", "tag": "88888"} | |
1392 | ] | |
1393 | } | |
1394 | } | |
1395 | result = create_static_routes(tgen, input_dict_static_rtes_11) | |
1396 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1397 | ||
1398 | step("New tag has not been used by summary address.") | |
1399 | ||
1400 | input_dict_summary = { | |
1401 | "r0": {"static_routes": [{"network": SUMMARY["ipv4"][0], "tag": "88888"}]} | |
1402 | } | |
1403 | dut = "r1" | |
1404 | ||
1405 | result = verify_ospf_rib(tgen, dut, input_dict_summary, tag="88888", expected=False) | |
1406 | assert ( | |
1407 | result is not True | |
1408 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
1409 | tc_name, result | |
1410 | ) | |
1411 | ||
1412 | result = verify_rib( | |
1413 | tgen, | |
1414 | "ipv4", | |
1415 | dut, | |
1416 | input_dict_summary, | |
1417 | protocol=protocol, | |
1418 | tag="88888", | |
1419 | expected=False, | |
1420 | ) | |
1421 | assert ( | |
1422 | result is not True | |
1423 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
1424 | ||
1425 | step( | |
1426 | "Verify that boundary values tags are used for summary route" | |
1427 | " using show ip ospf route command." | |
1428 | ) | |
1429 | input_dict = { | |
1430 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1431 | "summaryAddress": SUMMARY["ipv4"][0], |
1432 | "metricType": "E2", | |
1433 | "metric": 20, | |
1434 | "tag": 88888, | |
1435 | "externalRouteCount": 5, | |
e6a472a0 | 1436 | } |
1437 | } | |
1438 | dut = "r0" | |
1439 | result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False) | |
1440 | assert ( | |
1441 | result is not True | |
1442 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
1443 | ||
1444 | step("Delete the configured summary address") | |
1445 | ospf_summ_r1 = { | |
1446 | "r0": { | |
1447 | "ospf": { | |
1448 | "summary-address": [ | |
1449 | { | |
1450 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1451 | "mask": "8", | |
1452 | "tag": 4294967295, | |
1453 | "delete": True, | |
1454 | } | |
1455 | ] | |
1456 | } | |
1457 | } | |
1458 | } | |
1459 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1460 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1461 | ||
1462 | step( | |
1463 | "Verify that 6 routes are advertised to neighbour with 5 routes" | |
1464 | " without any tag, 1 route with tag." | |
1465 | ) | |
1466 | ||
1467 | dut = "r1" | |
1468 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
1469 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1470 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
1471 | assert ( | |
1472 | result is True | |
1473 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1474 | ||
1475 | step("Verify that summary address is flushed from neighbor.") | |
1476 | ||
1477 | dut = "r1" | |
1478 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) | |
1479 | assert ( | |
1480 | result is not True | |
1481 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
1482 | tc_name, result | |
1483 | ) | |
1484 | ||
1485 | result = verify_rib( | |
1486 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
1487 | ) | |
1488 | assert ( | |
1489 | result is not True | |
1490 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
1491 | ||
1492 | step("Configure summary first & then configure matching static route.") | |
1493 | ||
1494 | input_dict_static_rtes = { | |
1495 | "r0": { | |
1496 | "static_routes": [ | |
1497 | {"network": NETWORK["ipv4"], "next_hop": "blackhole", "delete": True}, | |
1498 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole", "delete": True}, | |
1499 | ] | |
1500 | } | |
1501 | } | |
1502 | result = create_static_routes(tgen, input_dict_static_rtes) | |
1503 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1504 | ||
1505 | ospf_summ_r1 = { | |
1506 | "r0": { | |
1507 | "ospf": { | |
1508 | "summary-address": [ | |
1509 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
1510 | ] | |
1511 | } | |
1512 | } | |
1513 | } | |
1514 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1515 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1516 | ||
1517 | input_dict_static_rtes = { | |
1518 | "r0": { | |
1519 | "static_routes": [ | |
1520 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
1521 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
1522 | ] | |
1523 | } | |
1524 | } | |
1525 | result = create_static_routes(tgen, input_dict_static_rtes) | |
1526 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1527 | ||
1528 | step("Repeat steps 1 to 10 of summarisation in non Back bone area.") | |
1529 | reset_config_on_routers(tgen) | |
1530 | ||
1531 | step("Change the area id on the interface on R0") | |
1532 | input_dict = { | |
1533 | "r0": { | |
1534 | "links": { | |
1535 | "r1": { | |
1536 | "interface": topo["routers"]["r0"]["links"]["r1"]["interface"], | |
1537 | "ospf": {"area": "0.0.0.0"}, | |
1538 | "delete": True, | |
1539 | } | |
1540 | } | |
1541 | } | |
1542 | } | |
1543 | ||
1544 | result = create_interfaces_cfg(tgen, input_dict) | |
1545 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
1546 | ||
1547 | input_dict = { | |
1548 | "r0": { | |
1549 | "links": { | |
1550 | "r1": { | |
1551 | "interface": topo["routers"]["r0"]["links"]["r1"]["interface"], | |
1552 | "ospf": {"area": "0.0.0.1"}, | |
1553 | } | |
1554 | } | |
1555 | } | |
1556 | } | |
1557 | ||
1558 | result = create_interfaces_cfg(tgen, input_dict) | |
1559 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
1560 | ||
1561 | step("Change the area id on the interface ") | |
1562 | input_dict = { | |
1563 | "r1": { | |
1564 | "links": { | |
1565 | "r0": { | |
1566 | "interface": topo["routers"]["r1"]["links"]["r0"]["interface"], | |
1567 | "ospf": {"area": "0.0.0.0"}, | |
1568 | "delete": True, | |
1569 | } | |
1570 | } | |
1571 | } | |
1572 | } | |
1573 | ||
1574 | result = create_interfaces_cfg(tgen, input_dict) | |
1575 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
1576 | ||
1577 | input_dict = { | |
1578 | "r1": { | |
1579 | "links": { | |
1580 | "r0": { | |
1581 | "interface": topo["routers"]["r1"]["links"]["r0"]["interface"], | |
1582 | "ospf": {"area": "0.0.0.1"}, | |
1583 | } | |
1584 | } | |
1585 | } | |
1586 | } | |
1587 | ||
1588 | result = create_interfaces_cfg(tgen, input_dict) | |
1589 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
1590 | ||
1591 | ospf_covergence = verify_ospf_neighbor(tgen, topo) | |
1592 | assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( | |
1593 | ospf_covergence | |
1594 | ) | |
1595 | ||
1596 | step( | |
1597 | "Configure 5 static routes from the same network on R0" | |
1598 | "5 static routes from different networks and redistribute in R0" | |
1599 | ) | |
1600 | input_dict_static_rtes = { | |
1601 | "r0": { | |
1602 | "static_routes": [ | |
1603 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
1604 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
1605 | ] | |
1606 | } | |
1607 | } | |
1608 | result = create_static_routes(tgen, input_dict_static_rtes) | |
1609 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1610 | ||
1611 | dut = "r0" | |
1612 | red_static(dut) | |
1613 | ||
1614 | step("Verify that routes are learnt on R1.") | |
1615 | dut = "r1" | |
1616 | ||
1617 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
1618 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1619 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
1620 | assert ( | |
1621 | result is True | |
1622 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1623 | ||
1624 | step( | |
1625 | "Configure External Route summary in R0 to summarise 5" " routes to one route." | |
1626 | ) | |
1627 | ospf_summ_r1 = { | |
1628 | "r0": { | |
1629 | "ospf": { | |
1630 | "summary-address": [ | |
1631 | { | |
1632 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1633 | "mask": "8", | |
1634 | "tag": "1234", | |
1635 | } | |
1636 | ] | |
1637 | } | |
1638 | } | |
1639 | } | |
1640 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1641 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1642 | ||
1643 | step( | |
1644 | "Verify that external routes are summarised to configured summary" | |
1645 | " address on R0 and only one route is sent to R1 with configured tag." | |
1646 | ) | |
1647 | input_dict_summary = { | |
1648 | "r0": {"static_routes": [{"network": SUMMARY["ipv4"][0], "tag": "1234"}]} | |
1649 | } | |
1650 | dut = "r1" | |
1651 | ||
1652 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
1653 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1654 | ||
1655 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
1656 | assert ( | |
1657 | result is True | |
1658 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1659 | ||
1660 | step("Verify that show ip ospf summary should show the summaries with tag.") | |
1661 | input_dict = { | |
1662 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1663 | "summaryAddress": SUMMARY["ipv4"][0], |
1664 | "metricType": "E2", | |
1665 | "metric": 20, | |
1666 | "tag": 1234, | |
1667 | "externalRouteCount": 5, | |
e6a472a0 | 1668 | } |
1669 | } | |
1670 | dut = "r0" | |
1671 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
1672 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1673 | ||
1674 | step("Delete the configured summary") | |
1675 | ospf_summ_r1 = { | |
1676 | "r0": { | |
1677 | "ospf": { | |
1678 | "summary-address": [ | |
1679 | { | |
1680 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1681 | "mask": "8", | |
1682 | "delete": True, | |
1683 | } | |
1684 | ] | |
1685 | } | |
1686 | } | |
1687 | } | |
1688 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1689 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1690 | ||
1691 | step("Verify that summary lsa is withdrawn from R1 and deleted from R0.") | |
1692 | dut = "r1" | |
1693 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
1694 | assert ( | |
1695 | result is not True | |
1696 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
1697 | tc_name, result | |
1698 | ) | |
1699 | ||
1700 | result = verify_rib( | |
1701 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
1702 | ) | |
1703 | assert ( | |
1704 | result is not True | |
1705 | ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format( | |
1706 | tc_name | |
1707 | ) | |
1708 | ||
1709 | step("show ip ospf summary should not have any summary address.") | |
1710 | input_dict = { | |
1711 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1712 | "summaryAddress": SUMMARY["ipv4"][0], |
1713 | "metricType": "E2", | |
1714 | "metric": 20, | |
1715 | "tag": 1234, | |
1716 | "externalRouteCount": 5, | |
e6a472a0 | 1717 | } |
1718 | } | |
1719 | dut = "r0" | |
1720 | result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False) | |
1721 | assert ( | |
1722 | result is not True | |
1723 | ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name) | |
1724 | ||
1725 | step("Configure Min tag value") | |
1726 | ospf_summ_r1 = { | |
1727 | "r0": { | |
1728 | "ospf": { | |
1729 | "summary-address": [ | |
1730 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8", "tag": 1} | |
1731 | ] | |
1732 | } | |
1733 | } | |
1734 | } | |
1735 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1736 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1737 | input_dict_summary = { | |
1738 | "r0": {"static_routes": [{"network": SUMMARY["ipv4"][0], "tag": "1"}]} | |
1739 | } | |
1740 | dut = "r1" | |
1741 | ||
1742 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
1743 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1744 | ||
1745 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
1746 | assert ( | |
1747 | result is True | |
1748 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1749 | ||
1750 | step("Verify that show ip ospf summary should show the summaries with tag.") | |
1751 | input_dict = { | |
1752 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1753 | "summaryAddress": SUMMARY["ipv4"][0], |
1754 | "metricType": "E2", | |
1755 | "metric": 20, | |
1756 | "tag": 1, | |
1757 | "externalRouteCount": 5, | |
e6a472a0 | 1758 | } |
1759 | } | |
1760 | dut = "r0" | |
1761 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
1762 | assert ( | |
1763 | result is True | |
1764 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
1765 | ||
1766 | step("Configure Max Tag Value") | |
1767 | ospf_summ_r1 = { | |
1768 | "r0": { | |
1769 | "ospf": { | |
1770 | "summary-address": [ | |
1771 | { | |
1772 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1773 | "mask": "8", | |
1774 | "tag": 4294967295, | |
1775 | } | |
1776 | ] | |
1777 | } | |
1778 | } | |
1779 | } | |
1780 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1781 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1782 | ||
1783 | input_dict_summary = { | |
1784 | "r0": {"static_routes": [{"network": SUMMARY["ipv4"][0], "tag": "4294967295"}]} | |
1785 | } | |
1786 | dut = "r1" | |
1787 | ||
1788 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
1789 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1790 | ||
1791 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
1792 | assert ( | |
1793 | result is True | |
1794 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1795 | ||
1796 | step( | |
1797 | "Verify that boundary values tags are used for summary route" | |
1798 | " using show ip ospf route command." | |
1799 | ) | |
1800 | input_dict = { | |
1801 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1802 | "summaryAddress": SUMMARY["ipv4"][0], |
1803 | "metricType": "E2", | |
1804 | "metric": 20, | |
1805 | "tag": 4294967295, | |
1806 | "externalRouteCount": 5, | |
e6a472a0 | 1807 | } |
1808 | } | |
1809 | dut = "r0" | |
1810 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
1811 | assert ( | |
1812 | result is True | |
1813 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
1814 | ||
1815 | step("configure new static route with different tag.") | |
1816 | input_dict_static_rtes_11 = { | |
1817 | "r0": { | |
1818 | "static_routes": [ | |
1819 | {"network": NETWORK_11["ipv4"], "next_hop": "blackhole", "tag": "88888"} | |
1820 | ] | |
1821 | } | |
1822 | } | |
1823 | result = create_static_routes(tgen, input_dict_static_rtes_11) | |
1824 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1825 | ||
1826 | step("New tag has not been used by summary address.") | |
1827 | ||
1828 | input_dict_summary = { | |
1829 | "r0": {"static_routes": [{"network": SUMMARY["ipv4"][0], "tag": "88888"}]} | |
1830 | } | |
1831 | dut = "r1" | |
1832 | ||
1833 | result = verify_ospf_rib(tgen, dut, input_dict_summary, tag="88888", expected=False) | |
1834 | assert ( | |
1835 | result is not True | |
1836 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
1837 | tc_name, result | |
1838 | ) | |
1839 | ||
1840 | result = verify_rib( | |
1841 | tgen, | |
1842 | "ipv4", | |
1843 | dut, | |
1844 | input_dict_summary, | |
1845 | protocol=protocol, | |
1846 | tag="88888", | |
1847 | expected=False, | |
1848 | ) | |
1849 | assert ( | |
1850 | result is not True | |
1851 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
1852 | ||
1853 | step( | |
1854 | "Verify that boundary values tags are used for summary route" | |
1855 | " using show ip ospf route command." | |
1856 | ) | |
1857 | input_dict = { | |
1858 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
1859 | "summaryAddress": SUMMARY["ipv4"][0], |
1860 | "metricType": "E2", | |
1861 | "metric": 20, | |
1862 | "tag": 88888, | |
1863 | "externalRouteCount": 5, | |
e6a472a0 | 1864 | } |
1865 | } | |
1866 | dut = "r0" | |
1867 | result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False) | |
1868 | assert ( | |
1869 | result is not True | |
1870 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
1871 | ||
1872 | step("Delete the configured summary address") | |
1873 | ospf_summ_r1 = { | |
1874 | "r0": { | |
1875 | "ospf": { | |
1876 | "summary-address": [ | |
1877 | { | |
1878 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
1879 | "mask": "8", | |
1880 | "tag": 4294967295, | |
1881 | "delete": True, | |
1882 | } | |
1883 | ] | |
1884 | } | |
1885 | } | |
1886 | } | |
1887 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1888 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1889 | ||
1890 | step( | |
1891 | "Verify that 6 routes are advertised to neighbour with 5 routes" | |
1892 | " without any tag, 1 route with tag." | |
1893 | ) | |
1894 | ||
1895 | dut = "r1" | |
1896 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
1897 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1898 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
1899 | assert ( | |
1900 | result is True | |
1901 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
1902 | ||
1903 | step("Verify that summary address is flushed from neighbor.") | |
1904 | ||
1905 | dut = "r1" | |
1906 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) | |
1907 | assert ( | |
1908 | result is not True | |
1909 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
1910 | tc_name, result | |
1911 | ) | |
1912 | ||
1913 | result = verify_rib( | |
1914 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
1915 | ) | |
1916 | assert ( | |
1917 | result is not True | |
1918 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
1919 | ||
1920 | step("Configure summary first & then configure matching static route.") | |
1921 | ||
1922 | input_dict_static_rtes = { | |
1923 | "r0": { | |
1924 | "static_routes": [ | |
1925 | {"network": NETWORK["ipv4"], "next_hop": "blackhole", "delete": True}, | |
1926 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole", "delete": True}, | |
1927 | ] | |
1928 | } | |
1929 | } | |
1930 | result = create_static_routes(tgen, input_dict_static_rtes) | |
1931 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1932 | ||
1933 | ospf_summ_r1 = { | |
1934 | "r0": { | |
1935 | "ospf": { | |
1936 | "summary-address": [ | |
1937 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
1938 | ] | |
1939 | } | |
1940 | } | |
1941 | } | |
1942 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
1943 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1944 | ||
1945 | input_dict_static_rtes = { | |
1946 | "r0": { | |
1947 | "static_routes": [ | |
1948 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
1949 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
1950 | ] | |
1951 | } | |
1952 | } | |
1953 | result = create_static_routes(tgen, input_dict_static_rtes) | |
1954 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1955 | ||
1956 | write_test_footer(tc_name) | |
1957 | ||
1958 | ||
1959 | def test_ospf_type5_summary_tc46_p0(request): | |
1960 | """OSPF summarisation with advertise and no advertise option""" | |
1961 | tc_name = request.node.name | |
1962 | write_test_header(tc_name) | |
1963 | tgen = get_topogen() | |
1964 | ||
1965 | # Don't run this test if we have any failure. | |
1966 | if tgen.routers_have_failure(): | |
1967 | pytest.skip(tgen.errors) | |
1968 | ||
1969 | global topo | |
1970 | step("Bring up the base config as per the topology") | |
1971 | step("Configure OSPF on all the routers of the topology.") | |
1972 | reset_config_on_routers(tgen) | |
1973 | ||
1974 | protocol = "ospf" | |
1975 | ||
1976 | step( | |
1977 | "Configure 5 static routes from the same network on R0" | |
1978 | "5 static routes from different networks and redistribute in R0" | |
1979 | ) | |
1980 | input_dict_static_rtes = { | |
1981 | "r0": { | |
1982 | "static_routes": [ | |
1983 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
1984 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
1985 | ] | |
1986 | } | |
1987 | } | |
1988 | result = create_static_routes(tgen, input_dict_static_rtes) | |
1989 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1990 | ||
1991 | dut = "r0" | |
1992 | red_static(dut) | |
1993 | ||
1994 | step("Verify that routes are learnt on R1.") | |
1995 | dut = "r1" | |
1996 | ||
1997 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
1998 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1999 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
2000 | assert ( | |
2001 | result is True | |
2002 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2003 | ||
2004 | step( | |
2005 | "Configure External Route summary in R0 to summarise 5" | |
2006 | " routes to one route with no advertise option." | |
2007 | ) | |
2008 | ospf_summ_r1 = { | |
2009 | "r0": { | |
2010 | "ospf": { | |
2011 | "summary-address": [ | |
2012 | { | |
2013 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2014 | "mask": "8", | |
2015 | "advertise": False, | |
2016 | } | |
2017 | ] | |
2018 | } | |
2019 | } | |
2020 | } | |
2021 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2022 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2023 | ||
2024 | step( | |
2025 | "Verify that external routes are summarised to configured summary" | |
2026 | " address on R0 and summary route is not advertised to neighbor as" | |
2027 | " no advertise is configured.." | |
2028 | ) | |
2029 | ||
2030 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
2031 | dut = "r1" | |
2032 | ||
2033 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) | |
2034 | assert ( | |
2035 | result is not True | |
2036 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
2037 | tc_name, result | |
2038 | ) | |
2039 | ||
2040 | result = verify_rib( | |
2041 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
2042 | ) | |
2043 | assert ( | |
2044 | result is not True | |
2045 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
2046 | ||
2047 | step("Verify that show ip ospf summary should show the " "configured summaries.") | |
2048 | input_dict = { | |
2049 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
2050 | "summaryAddress": SUMMARY["ipv4"][0], |
2051 | "externalRouteCount": 5, | |
e6a472a0 | 2052 | } |
2053 | } | |
2054 | dut = "r0" | |
2055 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2056 | assert ( | |
2057 | result is True | |
2058 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
2059 | ||
2060 | step("Delete the configured summary") | |
2061 | ospf_summ_r1 = { | |
2062 | "r0": { | |
2063 | "ospf": { | |
2064 | "summary-address": [ | |
2065 | { | |
2066 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2067 | "mask": "8", | |
2068 | "delete": True, | |
2069 | } | |
2070 | ] | |
2071 | } | |
2072 | } | |
2073 | } | |
2074 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2075 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2076 | ||
2077 | step("Summary has 5 sec delay timer, sleep 5 secs...") | |
2078 | sleep(5) | |
2079 | ||
2080 | step("Verify that summary lsa is withdrawn from R1 and deleted from R0.") | |
2081 | dut = "r1" | |
2082 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
2083 | assert ( | |
2084 | result is not True | |
2085 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
2086 | tc_name, result | |
2087 | ) | |
2088 | ||
2089 | result = verify_rib( | |
2090 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
2091 | ) | |
2092 | assert ( | |
2093 | result is not True | |
2094 | ), "Testcase {} : Failed" "Error: Summary Route still present in RIB".format( | |
2095 | tc_name | |
2096 | ) | |
2097 | ||
2098 | step("show ip ospf summary should not have any summary address.") | |
2099 | input_dict = { | |
2100 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
2101 | "summaryAddress": SUMMARY["ipv4"][0], |
2102 | "metricType": "E2", | |
2103 | "metric": 20, | |
2104 | "tag": 1234, | |
2105 | "externalRouteCount": 5, | |
e6a472a0 | 2106 | } |
2107 | } | |
2108 | dut = "r0" | |
2109 | result = verify_ospf_summary(tgen, topo, dut, input_dict, expected=False) | |
2110 | assert ( | |
2111 | result is not True | |
2112 | ), "Testcase {} : Failed" "Error: Summary still present in DB".format(tc_name) | |
2113 | ||
2114 | step("Reconfigure summary with no advertise.") | |
2115 | ospf_summ_r1 = { | |
2116 | "r0": { | |
2117 | "ospf": { | |
2118 | "summary-address": [ | |
2119 | { | |
2120 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2121 | "mask": "8", | |
2122 | "advertise": False, | |
2123 | } | |
2124 | ] | |
2125 | } | |
2126 | } | |
2127 | } | |
2128 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2129 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2130 | ||
2131 | step( | |
2132 | "Verify that external routes are summarised to configured summary" | |
2133 | " address on R0 and summary route is not advertised to neighbor as" | |
2134 | " no advertise is configured.." | |
2135 | ) | |
2136 | ||
2137 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
2138 | dut = "r1" | |
2139 | ||
2140 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) | |
2141 | assert ( | |
2142 | result is not True | |
2143 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
2144 | tc_name, result | |
2145 | ) | |
2146 | ||
2147 | result = verify_rib( | |
2148 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
2149 | ) | |
2150 | assert ( | |
2151 | result is not True | |
2152 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
2153 | ||
2154 | step("Verify that show ip ospf summary should show the " "configured summaries.") | |
2155 | input_dict = { | |
2156 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
2157 | "summaryAddress": SUMMARY["ipv4"][0], |
2158 | "externalRouteCount": 5, | |
e6a472a0 | 2159 | } |
2160 | } | |
2161 | dut = "r0" | |
2162 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2163 | assert ( | |
2164 | result is True | |
2165 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
2166 | ||
2167 | step( | |
2168 | "Change summary address from no advertise to advertise " | |
2169 | "(summary-address 10.0.0.0 255.255.0.0)" | |
2170 | ) | |
2171 | ||
2172 | ospf_summ_r1 = { | |
2173 | "r0": { | |
2174 | "ospf": { | |
2175 | "summary-address": [ | |
2176 | { | |
2177 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2178 | "mask": "8", | |
2179 | "advertise": False, | |
2180 | } | |
2181 | ] | |
2182 | } | |
2183 | } | |
2184 | } | |
2185 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2186 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2187 | ||
2188 | ospf_summ_r1 = { | |
2189 | "r0": { | |
2190 | "ospf": { | |
2191 | "summary-address": [ | |
2192 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
2193 | ] | |
2194 | } | |
2195 | } | |
2196 | } | |
2197 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2198 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2199 | ||
2200 | step( | |
2201 | "Verify that external routes are summarised to configured summary " | |
2202 | "address on R0 after 5 secs of delay timer expiry and only one " | |
2203 | "route is sent to R1." | |
2204 | ) | |
2205 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
2206 | dut = "r1" | |
2207 | ||
2208 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2209 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2210 | ||
2211 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2212 | assert ( | |
2213 | result is True | |
2214 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2215 | ||
2216 | step("Verify that show ip ospf summary should show the summaries.") | |
2217 | input_dict = { | |
2218 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
2219 | "summaryAddress": SUMMARY["ipv4"][0], |
2220 | "metricType": "E2", | |
2221 | "metric": 20, | |
2222 | "tag": 0, | |
2223 | "externalRouteCount": 5, | |
e6a472a0 | 2224 | } |
2225 | } | |
2226 | dut = "r0" | |
2227 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2228 | assert ( | |
2229 | result is True | |
2230 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
2231 | ||
2232 | step("Verify that originally advertised routes are withdraw from there" " peer.") | |
2233 | input_dict = { | |
2234 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
2235 | } | |
2236 | dut = "r1" | |
2237 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
2238 | assert ( | |
2239 | result is not True | |
2240 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
2241 | tc_name, result | |
2242 | ) | |
2243 | ||
2244 | result = verify_rib( | |
2245 | tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False | |
2246 | ) | |
2247 | assert ( | |
2248 | result is not True | |
2249 | ), "Testcase {} : Failed" "Error: Routes is present in RIB".format(tc_name) | |
2250 | ||
2251 | write_test_footer(tc_name) | |
2252 | ||
2253 | ||
2254 | def test_ospf_type5_summary_tc47_p0(request): | |
2255 | """OSPF summarisation with route map filtering.""" | |
2256 | tc_name = request.node.name | |
2257 | write_test_header(tc_name) | |
2258 | tgen = get_topogen() | |
2259 | ||
2260 | # Don't run this test if we have any failure. | |
2261 | if tgen.routers_have_failure(): | |
2262 | pytest.skip(tgen.errors) | |
2263 | ||
2264 | global topo | |
2265 | step("Bring up the base config as per the topology") | |
2266 | reset_config_on_routers(tgen) | |
2267 | ||
2268 | protocol = "ospf" | |
2269 | ||
2270 | step( | |
2271 | "Configure 5 static routes from the same network on R0" | |
2272 | "5 static routes from different networks and redistribute in R0" | |
2273 | ) | |
2274 | input_dict_static_rtes = { | |
2275 | "r0": { | |
2276 | "static_routes": [ | |
2277 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
2278 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
2279 | ] | |
2280 | } | |
2281 | } | |
2282 | result = create_static_routes(tgen, input_dict_static_rtes) | |
2283 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2284 | ||
2285 | dut = "r0" | |
2286 | red_static(dut) | |
2287 | ||
2288 | step("Verify that routes are learnt on R1.") | |
2289 | dut = "r1" | |
2290 | ||
2291 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
2292 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2293 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
2294 | assert ( | |
2295 | result is True | |
2296 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2297 | ||
2298 | step( | |
2299 | "Configure External Route summary in R0 to summarise 5" " routes to one route." | |
2300 | ) | |
2301 | ||
2302 | ospf_summ_r1 = { | |
2303 | "r0": { | |
2304 | "ospf": { | |
2305 | "summary-address": [ | |
2306 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
2307 | ] | |
2308 | } | |
2309 | } | |
2310 | } | |
2311 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2312 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2313 | ||
2314 | step( | |
2315 | "Verify that external routes are summarised to configured summary " | |
2316 | "address on R0 after 5 secs of delay timer expiry and only one " | |
2317 | "route is sent to R1." | |
2318 | ) | |
2319 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
2320 | dut = "r1" | |
2321 | ||
2322 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2323 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2324 | ||
2325 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2326 | assert ( | |
2327 | result is True | |
2328 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2329 | ||
2330 | step("Verify that show ip ospf summary should show the summaries.") | |
2331 | input_dict = { | |
2332 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
2333 | "summaryAddress": SUMMARY["ipv4"][0], |
2334 | "metricType": "E2", | |
2335 | "metric": 20, | |
2336 | "tag": 0, | |
2337 | "externalRouteCount": 5, | |
e6a472a0 | 2338 | } |
2339 | } | |
2340 | dut = "r0" | |
2341 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2342 | assert ( | |
2343 | result is True | |
2344 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
2345 | ||
2346 | step("Verify that originally advertised routes are withdraw from there" " peer.") | |
2347 | input_dict = { | |
2348 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
2349 | } | |
2350 | dut = "r1" | |
2351 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
2352 | assert ( | |
2353 | result is not True | |
2354 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
2355 | tc_name, result | |
2356 | ) | |
2357 | ||
2358 | result = verify_rib( | |
2359 | tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False | |
2360 | ) | |
2361 | assert ( | |
2362 | result is not True | |
2363 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
2364 | ||
2365 | step( | |
2366 | "configure route map and add rule to permit configured static " | |
2367 | "routes, redistribute static & connected routes with the route map." | |
2368 | ) | |
2369 | ||
2370 | # Create ip prefix list | |
2371 | pfx_list = { | |
2372 | "r0": { | |
2373 | "prefix_lists": { | |
2374 | "ipv4": { | |
2375 | "pf_list_1_ipv4": [ | |
2376 | {"seqid": 10, "network": "any", "action": "permit"} | |
2377 | ] | |
2378 | } | |
2379 | } | |
2380 | } | |
2381 | } | |
2382 | result = create_prefix_lists(tgen, pfx_list) | |
2383 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2384 | ||
2385 | routemaps = { | |
2386 | "r0": { | |
2387 | "route_maps": { | |
2388 | "rmap_ipv4": [ | |
2389 | { | |
2390 | "action": "permit", | |
2391 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
2392 | "seq_id": 10, | |
2393 | } | |
2394 | ] | |
2395 | } | |
2396 | } | |
2397 | } | |
2398 | result = create_route_maps(tgen, routemaps) | |
2399 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2400 | ||
2401 | ospf_red_r1 = { | |
2402 | "r0": { | |
2403 | "ospf": { | |
2404 | "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv4"}] | |
2405 | } | |
2406 | } | |
2407 | } | |
2408 | result = create_router_ospf(tgen, topo, ospf_red_r1) | |
2409 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2410 | ||
2411 | step( | |
2412 | "Verify that external routes are summarised to configured" | |
2413 | "summary address on R0 and only one route is sent to R1. Verify that " | |
2414 | "show ip ospf summary should show the configure summaries." | |
2415 | ) | |
2416 | ||
2417 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
2418 | dut = "r1" | |
2419 | ||
2420 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2421 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2422 | ||
2423 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2424 | assert ( | |
2425 | result is True | |
2426 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2427 | ||
2428 | input_dict = { | |
2429 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
2430 | "summaryAddress": SUMMARY["ipv4"][0], |
2431 | "metricType": "E2", | |
2432 | "metric": 20, | |
2433 | "tag": 0, | |
2434 | "externalRouteCount": 5, | |
e6a472a0 | 2435 | } |
2436 | } | |
2437 | dut = "r0" | |
2438 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2439 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2440 | ||
2441 | step("Change the rule from permit to deny in configured route map.") | |
2442 | ||
2443 | routemaps = { | |
2444 | "r0": { | |
2445 | "route_maps": { | |
2446 | "rmap_ipv4": [ | |
2447 | { | |
2448 | "action": "deny", | |
2449 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
2450 | "seq_id": 10, | |
2451 | } | |
2452 | ] | |
2453 | } | |
2454 | } | |
2455 | } | |
2456 | result = create_route_maps(tgen, routemaps) | |
2457 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2458 | ||
2459 | step("summary route has 5 secs dealy, sleep 5 secs") | |
2460 | sleep(5) | |
2461 | step("Verify that advertised summary route is flushed from neighbor.") | |
2462 | dut = "r1" | |
2463 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) | |
2464 | assert ( | |
2465 | result is not True | |
2466 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
2467 | tc_name, result | |
2468 | ) | |
2469 | ||
2470 | result = verify_rib( | |
2471 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
2472 | ) | |
2473 | assert ( | |
2474 | result is not True | |
2475 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
2476 | ||
2477 | step("Delete the configured route map.") | |
2478 | ||
2479 | routemaps = { | |
2480 | "r0": { | |
2481 | "route_maps": { | |
2482 | "rmap_ipv4": [ | |
2483 | { | |
2484 | "action": "permit", | |
2485 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
2486 | "delete": True, | |
2487 | } | |
2488 | ] | |
2489 | } | |
2490 | } | |
2491 | } | |
2492 | result = create_route_maps(tgen, routemaps) | |
2493 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2494 | ||
2495 | ospf_red_r1 = {"r0": {"ospf": {"redistribute": [{"redist_type": "static"}]}}} | |
2496 | result = create_router_ospf(tgen, topo, ospf_red_r1) | |
2497 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2498 | ||
2499 | step( | |
2500 | "Verify that external routes are summarised to configured" | |
2501 | "summary address on R0 and only one route is sent to R1. Verify that " | |
2502 | "show ip ospf summary should show the configure summaries." | |
2503 | ) | |
2504 | ||
2505 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
2506 | dut = "r1" | |
2507 | ||
2508 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2509 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2510 | ||
2511 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2512 | assert ( | |
2513 | result is True | |
2514 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2515 | ||
2516 | input_dict = { | |
2517 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
2518 | "summaryAddress": SUMMARY["ipv4"][0], |
2519 | "metricType": "E2", | |
2520 | "metric": 20, | |
2521 | "tag": 0, | |
2522 | "externalRouteCount": 5, | |
e6a472a0 | 2523 | } |
2524 | } | |
2525 | dut = "r0" | |
2526 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2527 | assert ( | |
2528 | result is True | |
2529 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
2530 | ||
2531 | step("Reconfigure the route map with denying configure summary address.") | |
2532 | ||
2533 | routemaps = { | |
2534 | "r0": { | |
2535 | "route_maps": { | |
2536 | "rmap_ipv4": [ | |
2537 | { | |
2538 | "action": "permit", | |
2539 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
2540 | "seq_id": 10, | |
2541 | } | |
2542 | ] | |
2543 | } | |
2544 | } | |
2545 | } | |
2546 | result = create_route_maps(tgen, routemaps) | |
2547 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2548 | ||
2549 | # Create ip prefix list | |
2550 | pfx_list = { | |
2551 | "r0": { | |
2552 | "prefix_lists": { | |
2553 | "ipv4": { | |
2554 | "pf_list_1_ipv4": [ | |
2555 | {"seqid": 10, "network": SUMMARY["ipv4"][0], "action": "deny"} | |
2556 | ] | |
2557 | } | |
2558 | } | |
2559 | } | |
2560 | } | |
2561 | result = create_prefix_lists(tgen, pfx_list) | |
2562 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2563 | ||
2564 | step("Verify that advertised summary route is not flushed from neighbor.") | |
2565 | dut = "r1" | |
2566 | ||
2567 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2568 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2569 | ||
2570 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2571 | assert ( | |
2572 | result is True | |
2573 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2574 | ||
2575 | step("Redistribute static/connected routes without route map.") | |
2576 | ||
2577 | routemaps = { | |
2578 | "r0": { | |
2579 | "route_maps": { | |
2580 | "rmap_ipv4": [ | |
2581 | { | |
2582 | "action": "permit", | |
2583 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
2584 | "seq_id": 10, | |
2585 | "delete": True, | |
2586 | } | |
2587 | ] | |
2588 | } | |
2589 | } | |
2590 | } | |
2591 | result = create_route_maps(tgen, routemaps) | |
2592 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2593 | ||
2594 | step( | |
2595 | "Verify that external routes are summarised to configured" | |
2596 | "summary address on R0 and only one route is sent to R1. Verify that " | |
2597 | "show ip ospf summary should show the configure summaries." | |
2598 | ) | |
2599 | ||
2600 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
2601 | dut = "r1" | |
2602 | ||
2603 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2604 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2605 | ||
2606 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2607 | assert ( | |
2608 | result is True | |
2609 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2610 | ||
2611 | input_dict = { | |
2612 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
2613 | "summaryAddress": SUMMARY["ipv4"][0], |
2614 | "metricType": "E2", | |
2615 | "metric": 20, | |
2616 | "tag": 0, | |
2617 | "externalRouteCount": 5, | |
e6a472a0 | 2618 | } |
2619 | } | |
2620 | dut = "r0" | |
2621 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2622 | assert ( | |
2623 | result is True | |
2624 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
2625 | ||
2626 | step( | |
2627 | "Configure rule to deny all the routes in route map and configure" | |
2628 | " redistribute command in ospf using route map." | |
2629 | ) | |
2630 | ||
2631 | # Create ip prefix list | |
2632 | pfx_list = { | |
2633 | "r0": { | |
2634 | "prefix_lists": { | |
2635 | "ipv4": { | |
2636 | "pf_list_1_ipv4": [ | |
2637 | {"seqid": 10, "network": "any", "action": "deny"} | |
2638 | ] | |
2639 | } | |
2640 | } | |
2641 | } | |
2642 | } | |
2643 | result = create_prefix_lists(tgen, pfx_list) | |
2644 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2645 | ||
2646 | routemaps = { | |
2647 | "r0": { | |
2648 | "route_maps": { | |
2649 | "rmap_ipv4": [ | |
2650 | { | |
2651 | "action": "permit", | |
2652 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
2653 | "seq_id": 10, | |
2654 | } | |
2655 | ] | |
2656 | } | |
2657 | } | |
2658 | } | |
2659 | result = create_route_maps(tgen, routemaps) | |
2660 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2661 | ||
2662 | ospf_red_r1 = { | |
2663 | "r0": { | |
2664 | "ospf": { | |
2665 | "redistribute": [{"redist_type": "static", "route_map": "rmap_ipv4"}] | |
2666 | } | |
2667 | } | |
2668 | } | |
2669 | result = create_router_ospf(tgen, topo, ospf_red_r1) | |
2670 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2671 | ||
2672 | step("Verify that no summary route is originated.") | |
2673 | dut = "r1" | |
2674 | result = verify_ospf_rib(tgen, dut, input_dict_summary, expected=False) | |
2675 | assert ( | |
2676 | result is not True | |
2677 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
2678 | tc_name, result | |
2679 | ) | |
2680 | ||
2681 | result = verify_rib( | |
2682 | tgen, "ipv4", dut, input_dict_summary, protocol=protocol, expected=False | |
2683 | ) | |
2684 | assert ( | |
2685 | result is not True | |
2686 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
2687 | ||
2688 | routemaps = { | |
2689 | "r0": { | |
2690 | "route_maps": { | |
2691 | "rmap_ipv4": [ | |
2692 | { | |
2693 | "action": "permit", | |
2694 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
2695 | "seq_id": 10, | |
2696 | "delete": True, | |
2697 | } | |
2698 | ] | |
2699 | } | |
2700 | } | |
2701 | } | |
2702 | result = create_route_maps(tgen, routemaps) | |
2703 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2704 | ||
2705 | step( | |
2706 | "Configure cli in this order - 2 static routes, a route map to " | |
2707 | "permit those routes, summary address in ospf to match the " | |
2708 | "configured static route network, redistribute the static " | |
2709 | "routes with route map" | |
2710 | ) | |
2711 | ||
2712 | input_dict_static_rtes = { | |
2713 | "r0": { | |
2714 | "static_routes": [{"network": NETWORK2["ipv4"], "next_hop": "blackhole"}] | |
2715 | } | |
2716 | } | |
2717 | result = create_static_routes(tgen, input_dict_static_rtes) | |
2718 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2719 | ||
2720 | routemaps = { | |
2721 | "r0": { | |
2722 | "route_maps": { | |
2723 | "rmap_ipv4": [ | |
2724 | { | |
2725 | "action": "permit", | |
2726 | "match": {"ipv4": {"prefix_lists": "pf_list_1_ipv4"}}, | |
2727 | } | |
2728 | ] | |
2729 | } | |
2730 | } | |
2731 | } | |
2732 | result = create_route_maps(tgen, routemaps) | |
2733 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2734 | ||
2735 | ospf_summ_r1 = { | |
2736 | "r0": { | |
2737 | "ospf": { | |
2738 | "summary-address": [ | |
2739 | {"prefix": SUMMARY["ipv4"][1].split("/")[0], "mask": "8"} | |
2740 | ] | |
2741 | } | |
2742 | } | |
2743 | } | |
2744 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2745 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2746 | ||
2747 | # Create ip prefix list | |
2748 | pfx_list = { | |
2749 | "r0": { | |
2750 | "prefix_lists": { | |
2751 | "ipv4": { | |
2752 | "pf_list_1_ipv4": [ | |
2753 | {"seqid": 10, "network": "any", "action": "permit"} | |
2754 | ] | |
2755 | } | |
2756 | } | |
2757 | } | |
2758 | } | |
2759 | result = create_prefix_lists(tgen, pfx_list) | |
2760 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2761 | ||
2762 | step( | |
2763 | "Verify that external routes are summarised to configured summary " | |
2764 | "address on R0 after 5 secs of delay timer expiry and only one " | |
2765 | "route is sent to R1." | |
2766 | ) | |
2767 | input_dict_summary = {"r0": {"static_routes": [{"network": "12.0.0.0/8"}]}} | |
2768 | dut = "r1" | |
2769 | ||
2770 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2771 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2772 | ||
2773 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2774 | assert ( | |
2775 | result is True | |
2776 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2777 | ||
2778 | step("Verify that show ip ospf summary should show the summaries.") | |
2779 | input_dict = { | |
2780 | "12.0.0.0/8": { | |
f932966b DA |
2781 | "summaryAddress": "12.0.0.0/8", |
2782 | "metricType": "E2", | |
2783 | "metric": 20, | |
2784 | "tag": 0, | |
2785 | "externalRouteCount": 5, | |
e6a472a0 | 2786 | } |
2787 | } | |
2788 | dut = "r0" | |
2789 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2790 | assert ( | |
2791 | result is True | |
2792 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
2793 | ||
2794 | step("Change route map rule for 1 of the routes to deny.") | |
2795 | # Create ip prefix list | |
2796 | pfx_list = { | |
2797 | "r0": { | |
2798 | "prefix_lists": { | |
2799 | "ipv4": { | |
2800 | "pf_list_1_ipv4": [ | |
2801 | {"seqid": 10, "network": NETWORK2["ipv4"][0], "action": "deny"}, | |
2802 | {"seqid": 20, "network": "any", "action": "permit"}, | |
2803 | ] | |
2804 | } | |
2805 | } | |
2806 | } | |
2807 | } | |
2808 | result = create_prefix_lists(tgen, pfx_list) | |
2809 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2810 | ||
2811 | step( | |
2812 | "Verify that originated type 5 summary lsa is not refreshed because" | |
2813 | "of the route map events." | |
2814 | ) | |
2815 | ||
2816 | input_dict_summary = {"r0": {"static_routes": [{"network": "12.0.0.0/8"}]}} | |
2817 | dut = "r1" | |
2818 | ||
2819 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2820 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2821 | ||
2822 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2823 | assert ( | |
2824 | result is True | |
2825 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2826 | ||
2827 | step("add rule in route map to deny configured summary address.") | |
2828 | # Create ip prefix list | |
2829 | pfx_list = { | |
2830 | "r0": { | |
2831 | "prefix_lists": { | |
2832 | "ipv4": { | |
2833 | "pf_list_1_ipv4": [ | |
2834 | {"seqid": 10, "network": "12.0.0.0/8", "action": "deny"}, | |
2835 | {"seqid": 20, "network": "any", "action": "permit"}, | |
2836 | ] | |
2837 | } | |
2838 | } | |
2839 | } | |
2840 | } | |
2841 | result = create_prefix_lists(tgen, pfx_list) | |
2842 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2843 | ||
2844 | step( | |
2845 | "Verify that summary route is not denied, summary route should be" | |
2846 | " originated if matching prefixes are present." | |
2847 | ) | |
2848 | ||
2849 | input_dict_summary = {"r0": {"static_routes": [{"network": "12.0.0.0/8"}]}} | |
2850 | dut = "r1" | |
2851 | ||
2852 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
2853 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2854 | ||
2855 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
2856 | assert ( | |
2857 | result is True | |
2858 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
2859 | ||
2860 | write_test_footer(tc_name) | |
2861 | ||
2862 | ||
2863 | def test_ospf_type5_summary_tc51_p2(request): | |
2864 | """OSPF CLI Show. | |
2865 | ||
2866 | verify ospf ASBR summary config and show commands behaviours. | |
2867 | """ | |
2868 | tc_name = request.node.name | |
2869 | write_test_header(tc_name) | |
2870 | tgen = get_topogen() | |
2871 | ||
2872 | # Don't run this test if we have any failure. | |
2873 | if tgen.routers_have_failure(): | |
2874 | pytest.skip(tgen.errors) | |
2875 | ||
2876 | global topo | |
2877 | step("Bring up the base config as per the topology") | |
2878 | reset_config_on_routers(tgen) | |
2879 | ||
2880 | step("Configure all the supported OSPF ASBR summary commands on DUT.") | |
2881 | ospf_summ_r1 = { | |
2882 | "r0": { | |
2883 | "ospf": { | |
2884 | "summary-address": [ | |
2885 | { | |
2886 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2887 | "mask": "8", | |
2888 | "tag": 4294967295, | |
2889 | }, | |
2890 | { | |
2891 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2892 | "mask": "16", | |
2893 | "advertise": True, | |
2894 | }, | |
2895 | { | |
2896 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2897 | "mask": "24", | |
2898 | "advertise": False, | |
2899 | }, | |
2900 | { | |
2901 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2902 | "mask": "24", | |
2903 | "advertise": False, | |
2904 | }, | |
2905 | ] | |
2906 | } | |
2907 | } | |
2908 | } | |
2909 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2910 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2911 | ||
2912 | step("Configure and re configure all the commands 10 times in a loop.") | |
2913 | ||
2914 | for itrate in range(0, 10): | |
2915 | ospf_summ_r1 = { | |
2916 | "r0": { | |
2917 | "ospf": { | |
2918 | "summary-address": [ | |
2919 | { | |
2920 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2921 | "mask": "8", | |
2922 | "tag": 4294967295, | |
2923 | }, | |
2924 | { | |
2925 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2926 | "mask": "16", | |
2927 | "advertise": True, | |
2928 | }, | |
2929 | { | |
2930 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2931 | "mask": "24", | |
2932 | "advertise": False, | |
2933 | }, | |
2934 | { | |
2935 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2936 | "mask": "24", | |
2937 | "advertise": False, | |
2938 | }, | |
2939 | ] | |
2940 | } | |
2941 | } | |
2942 | } | |
2943 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2944 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
2945 | tc_name, result | |
2946 | ) | |
2947 | ||
2948 | ospf_summ_r1 = { | |
2949 | "r0": { | |
2950 | "ospf": { | |
2951 | "summary-address": [ | |
2952 | { | |
2953 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2954 | "mask": "8", | |
2955 | "tag": 4294967295, | |
2956 | "delete": True, | |
2957 | }, | |
2958 | { | |
2959 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2960 | "mask": "16", | |
2961 | "advertise": True, | |
2962 | "delete": True, | |
2963 | }, | |
2964 | { | |
2965 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2966 | "mask": "24", | |
2967 | "advertise": False, | |
2968 | "delete": True, | |
2969 | }, | |
2970 | { | |
2971 | "prefix": SUMMARY["ipv4"][0].split("/")[0], | |
2972 | "mask": "24", | |
2973 | "advertise": False, | |
2974 | "delete": True, | |
2975 | }, | |
2976 | ] | |
2977 | } | |
2978 | } | |
2979 | } | |
2980 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
2981 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
2982 | ||
2983 | step("Verify the show commands") | |
2984 | ||
2985 | input_dict = { | |
2986 | SUMMARY["ipv4"][2]: { | |
f932966b DA |
2987 | "summaryAddress": SUMMARY["ipv4"][2], |
2988 | "metricType": "E2", | |
2989 | "metric": 20, | |
2990 | "tag": 0, | |
2991 | "externalRouteCount": 0, | |
e6a472a0 | 2992 | } |
2993 | } | |
2994 | dut = "r0" | |
2995 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
2996 | assert ( | |
2997 | result is True | |
2998 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
2999 | ||
3000 | write_test_footer(tc_name) | |
3001 | ||
3002 | ||
3003 | def test_ospf_type5_summary_tc49_p2(request): | |
3004 | """OSPF summarisation Chaos.""" | |
3005 | tc_name = request.node.name | |
3006 | write_test_header(tc_name) | |
3007 | tgen = get_topogen() | |
3008 | ||
3009 | # Don't run this test if we have any failure. | |
3010 | if tgen.routers_have_failure(): | |
3011 | pytest.skip(tgen.errors) | |
3012 | ||
3013 | global topo | |
3014 | step("Bring up the base config as per the topology") | |
3015 | reset_config_on_routers(tgen) | |
3016 | ||
3017 | protocol = "ospf" | |
3018 | ||
3019 | step( | |
3020 | "Configure 5 static routes from the same network on R0" | |
3021 | "5 static routes from different networks and redistribute in R0" | |
3022 | ) | |
3023 | input_dict_static_rtes = { | |
3024 | "r0": { | |
3025 | "static_routes": [ | |
3026 | {"network": NETWORK["ipv4"], "next_hop": "blackhole"}, | |
3027 | {"network": NETWORK2["ipv4"], "next_hop": "blackhole"}, | |
3028 | ] | |
3029 | } | |
3030 | } | |
3031 | result = create_static_routes(tgen, input_dict_static_rtes) | |
3032 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
3033 | ||
3034 | dut = "r0" | |
3035 | red_static(dut) | |
3036 | ||
3037 | step("Verify that routes are learnt on R1.") | |
3038 | dut = "r1" | |
3039 | ||
3040 | result = verify_ospf_rib(tgen, dut, input_dict_static_rtes) | |
3041 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
3042 | result = verify_rib(tgen, "ipv4", dut, input_dict_static_rtes, protocol=protocol) | |
3043 | assert ( | |
3044 | result is True | |
3045 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
3046 | ||
3047 | step( | |
3048 | "Configure External Route summary in R0 to summarise 5" " routes to one route." | |
3049 | ) | |
3050 | ||
3051 | ospf_summ_r1 = { | |
3052 | "r0": { | |
3053 | "ospf": { | |
3054 | "summary-address": [ | |
3055 | {"prefix": SUMMARY["ipv4"][0].split("/")[0], "mask": "8"} | |
3056 | ] | |
3057 | } | |
3058 | } | |
3059 | } | |
3060 | result = create_router_ospf(tgen, topo, ospf_summ_r1) | |
3061 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
3062 | ||
3063 | step( | |
3064 | "Verify that external routes are summarised to configured summary " | |
3065 | "address on R0 after 5 secs of delay timer expiry and only one " | |
3066 | "route is sent to R1." | |
3067 | ) | |
3068 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
3069 | dut = "r1" | |
3070 | ||
3071 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
3072 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
3073 | ||
3074 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
3075 | assert ( | |
3076 | result is True | |
3077 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
3078 | ||
3079 | step("Verify that show ip ospf summary should show the summaries.") | |
3080 | input_dict = { | |
3081 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
3082 | "summaryAddress": SUMMARY["ipv4"][0], |
3083 | "metricType": "E2", | |
3084 | "metric": 20, | |
3085 | "tag": 0, | |
3086 | "externalRouteCount": 5, | |
e6a472a0 | 3087 | } |
3088 | } | |
3089 | dut = "r0" | |
3090 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
3091 | assert ( | |
3092 | result is True | |
3093 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
3094 | ||
3095 | step("Verify that originally advertised routes are withdraw from there" " peer.") | |
3096 | input_dict = { | |
3097 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
3098 | } | |
3099 | dut = "r1" | |
3100 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
3101 | assert ( | |
3102 | result is not True | |
3103 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
3104 | tc_name, result | |
3105 | ) | |
3106 | ||
3107 | result = verify_rib( | |
3108 | tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False | |
3109 | ) | |
3110 | assert ( | |
3111 | result is not True | |
3112 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
3113 | ||
3114 | step("Reload the FRR router") | |
3115 | # stop/start -> restart FRR router and verify | |
3116 | stop_router(tgen, "r0") | |
3117 | start_router(tgen, "r0") | |
3118 | ||
3119 | step( | |
3120 | "Verify that external routes are summarised to configured summary " | |
3121 | "address on R0 after 5 secs of delay timer expiry and only one " | |
3122 | "route is sent to R1." | |
3123 | ) | |
3124 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
3125 | dut = "r1" | |
3126 | ||
3127 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
3128 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
3129 | ||
3130 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
3131 | assert ( | |
3132 | result is True | |
3133 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
3134 | ||
3135 | step("Verify that show ip ospf summary should show the summaries.") | |
3136 | input_dict = { | |
3137 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
3138 | "summaryAddress": SUMMARY["ipv4"][0], |
3139 | "metricType": "E2", | |
3140 | "metric": 20, | |
3141 | "tag": 0, | |
3142 | "externalRouteCount": 5, | |
e6a472a0 | 3143 | } |
3144 | } | |
3145 | dut = "r0" | |
3146 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
3147 | assert ( | |
3148 | result is True | |
3149 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
3150 | ||
3151 | step("Verify that originally advertised routes are withdraw from there" " peer.") | |
3152 | input_dict = { | |
3153 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
3154 | } | |
3155 | dut = "r1" | |
3156 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
3157 | assert ( | |
3158 | result is not True | |
3159 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
3160 | tc_name, result | |
3161 | ) | |
3162 | ||
3163 | result = verify_rib( | |
3164 | tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False | |
3165 | ) | |
3166 | assert ( | |
3167 | result is not True | |
3168 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
3169 | ||
3170 | step("Kill OSPFd daemon on R0.") | |
3171 | kill_router_daemons(tgen, "r0", ["ospfd"]) | |
3172 | ||
3173 | step("Bring up OSPFd daemon on R0.") | |
3174 | start_router_daemons(tgen, "r0", ["ospfd"]) | |
3175 | ||
3176 | step("Verify OSPF neighbors are up after bringing back ospfd in R0") | |
3177 | # Api call verify whether OSPF is converged | |
3178 | ospf_covergence = verify_ospf_neighbor(tgen, topo) | |
3179 | assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( | |
3180 | ospf_covergence | |
3181 | ) | |
3182 | ||
3183 | step( | |
3184 | "Verify that external routes are summarised to configured summary " | |
3185 | "address on R0 after 5 secs of delay timer expiry and only one " | |
3186 | "route is sent to R1." | |
3187 | ) | |
3188 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
3189 | dut = "r1" | |
3190 | ||
3191 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
3192 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
3193 | ||
3194 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
3195 | assert ( | |
3196 | result is True | |
3197 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
3198 | ||
3199 | step("Verify that show ip ospf summary should show the summaries.") | |
3200 | input_dict = { | |
3201 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
3202 | "summaryAddress": SUMMARY["ipv4"][0], |
3203 | "metricType": "E2", | |
3204 | "metric": 20, | |
3205 | "tag": 0, | |
3206 | "externalRouteCount": 5, | |
e6a472a0 | 3207 | } |
3208 | } | |
3209 | dut = "r0" | |
3210 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
3211 | assert ( | |
3212 | result is True | |
3213 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
3214 | ||
3215 | step("Verify that originally advertised routes are withdraw from there" " peer.") | |
3216 | input_dict = { | |
3217 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
3218 | } | |
3219 | dut = "r1" | |
3220 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
3221 | assert ( | |
3222 | result is not True | |
3223 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
3224 | tc_name, result | |
3225 | ) | |
3226 | ||
3227 | result = verify_rib( | |
3228 | tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False | |
3229 | ) | |
3230 | assert ( | |
3231 | result is not True | |
3232 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
3233 | ||
3234 | step("restart zebrad") | |
3235 | kill_router_daemons(tgen, "r0", ["zebra"]) | |
3236 | ||
3237 | step("Bring up zebra daemon on R0.") | |
3238 | start_router_daemons(tgen, "r0", ["zebra"]) | |
3239 | ||
3240 | step( | |
3241 | "Verify that external routes are summarised to configured summary " | |
3242 | "address on R0 after 5 secs of delay timer expiry and only one " | |
3243 | "route is sent to R1." | |
3244 | ) | |
3245 | input_dict_summary = {"r0": {"static_routes": [{"network": SUMMARY["ipv4"][0]}]}} | |
3246 | dut = "r1" | |
3247 | ||
3248 | result = verify_ospf_rib(tgen, dut, input_dict_summary) | |
3249 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
3250 | ||
3251 | result = verify_rib(tgen, "ipv4", dut, input_dict_summary, protocol=protocol) | |
3252 | assert ( | |
3253 | result is True | |
3254 | ), "Testcase {} : Failed" "Error: Routes is missing in RIB".format(tc_name) | |
3255 | ||
3256 | step("Verify that show ip ospf summary should show the summaries.") | |
3257 | input_dict = { | |
3258 | SUMMARY["ipv4"][0]: { | |
f932966b DA |
3259 | "summaryAddress": SUMMARY["ipv4"][0], |
3260 | "metricType": "E2", | |
3261 | "metric": 20, | |
3262 | "tag": 0, | |
3263 | "externalRouteCount": 5, | |
e6a472a0 | 3264 | } |
3265 | } | |
3266 | dut = "r0" | |
3267 | result = verify_ospf_summary(tgen, topo, dut, input_dict) | |
3268 | assert ( | |
3269 | result is True | |
3270 | ), "Testcase {} : Failed" "Error: Summary missing in OSPF DB".format(tc_name) | |
3271 | ||
3272 | step("Verify that originally advertised routes are withdraw from there" " peer.") | |
3273 | input_dict = { | |
3274 | "r0": {"static_routes": [{"network": NETWORK["ipv4"], "next_hop": "blackhole"}]} | |
3275 | } | |
3276 | dut = "r1" | |
3277 | result = verify_ospf_rib(tgen, dut, input_dict, expected=False) | |
3278 | assert ( | |
3279 | result is not True | |
3280 | ), "Testcase {} : Failed \n Error: " "Routes still present in OSPF RIB {}".format( | |
3281 | tc_name, result | |
3282 | ) | |
3283 | ||
3284 | result = verify_rib( | |
3285 | tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False | |
3286 | ) | |
3287 | assert ( | |
3288 | result is not True | |
3289 | ), "Testcase {} : Failed" "Error: Routes still present in RIB".format(tc_name) | |
3290 | ||
3291 | write_test_footer(tc_name) | |
3292 | ||
3293 | ||
bcce6954 | 3294 | if __name__ == "__main__": |
3295 | args = ["-s"] + sys.argv[1:] | |
3296 | sys.exit(pytest.main(args)) |