]>
Commit | Line | Data |
---|---|---|
2448d002 | 1 | #!/usr/bin/python |
2 | # | |
3 | # Copyright (c) 2021 by VMware, Inc. ("VMware") | |
4 | # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. | |
5 | # ("NetDEF") in this file. | |
6 | # | |
7 | # Permission to use, copy, modify, and/or distribute this software | |
8 | # for any purpose with or without fee is hereby granted, provided | |
9 | # that the above copyright notice and this permission notice appear | |
10 | # in all copies. | |
11 | # | |
12 | # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES | |
13 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
14 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR | |
15 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY | |
16 | # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
17 | # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | |
18 | # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
19 | # OF THIS SOFTWARE. | |
20 | # | |
21 | ||
22 | ||
23 | """OSPF Basic Functionality Automation.""" | |
24 | import os | |
25 | import sys | |
26 | import time | |
27 | import pytest | |
2448d002 | 28 | |
29 | # Save the Current Working Directory to find configuration files. | |
30 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
31 | sys.path.append(os.path.join(CWD, "../")) | |
32 | sys.path.append(os.path.join(CWD, "../lib/")) | |
33 | ||
34 | # pylint: disable=C0413 | |
35 | # Import topogen and topotest helpers | |
2448d002 | 36 | from lib.topogen import Topogen, get_topogen |
37 | import ipaddress | |
2448d002 | 38 | |
39 | # Import topoJson from lib, to create topology and initial configuration | |
40 | from lib.common_config import ( | |
41 | start_topology, | |
42 | write_test_header, | |
43 | write_test_footer, | |
44 | reset_config_on_routers, | |
45 | verify_rib, | |
2448d002 | 46 | step, |
2448d002 | 47 | shutdown_bringup_interface, |
48 | create_interfaces_cfg, | |
2448d002 | 49 | get_frr_ipv6_linklocal, |
d1b5fa5b | 50 | check_router_status, |
51 | create_static_routes, | |
2448d002 | 52 | ) |
53 | ||
54 | from lib.topolog import logger | |
4953ca97 | 55 | from lib.topojson import build_config_from_json |
d1b5fa5b | 56 | from lib.bgp import create_router_bgp, verify_bgp_convergence |
2448d002 | 57 | from lib.ospf import ( |
58 | verify_ospf6_neighbor, | |
d1b5fa5b | 59 | clear_ospf, |
2448d002 | 60 | verify_ospf6_rib, |
d1b5fa5b | 61 | verify_ospf_database, |
2448d002 | 62 | create_router_ospf, |
2448d002 | 63 | config_ospf6_interface, |
d1b5fa5b | 64 | verify_ospf6_interface, |
2448d002 | 65 | ) |
66 | ||
2448d002 | 67 | |
6ff492b1 DS |
68 | pytestmark = [pytest.mark.ospfd, pytest.mark.staticd] |
69 | ||
70 | ||
2448d002 | 71 | # Global variables |
72 | topo = None | |
73 | ||
2448d002 | 74 | NETWORK = { |
75 | "ipv6": [ | |
76 | "11.0.20.1/32", | |
77 | "11.0.20.2/32", | |
78 | "11.0.20.3/32", | |
79 | "11.0.20.4/32", | |
80 | "11.0.20.5/32", | |
81 | ], | |
82 | "ipv6": ["2::1/128", "2::2/128", "2::3/128", "2::4/128", "2::5/128"], | |
83 | } | |
84 | TOPOOLOGY = """ | |
85 | Please view in a fixed-width font such as Courier. | |
86 | +---+ A1 +---+ | |
87 | +R1 +------------+R2 | | |
88 | +-+-+- +--++ | |
89 | | -- -- | | |
90 | | -- A0 -- | | |
91 | A0| ---- | | |
92 | | ---- | A2 | |
93 | | -- -- | | |
94 | | -- -- | | |
95 | +-+-+- +-+-+ | |
96 | +R0 +-------------+R3 | | |
97 | +---+ A3 +---+ | |
98 | """ | |
99 | ||
100 | TESTCASES = """ | |
101 | 1. OSPF Cost - verifying ospf interface cost functionality | |
102 | """ | |
103 | ||
104 | ||
2448d002 | 105 | def setup_module(mod): |
106 | """ | |
107 | Sets up the pytest environment | |
108 | ||
109 | * `mod`: module name | |
110 | """ | |
2448d002 | 111 | testsuite_run_time = time.asctime(time.localtime(time.time())) |
112 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
113 | logger.info("=" * 40) | |
114 | ||
115 | logger.info("Running setup_module to create topology") | |
116 | ||
117 | # This function initiates the topology build with Topogen... | |
e82b531d CH |
118 | json_file = "{}/ospfv3_rte_calc.json".format(CWD) |
119 | tgen = Topogen(json_file, mod.__name__) | |
120 | global topo | |
121 | topo = tgen.json_topo | |
2448d002 | 122 | # ... and here it calls Mininet initialization functions. |
123 | ||
2448d002 | 124 | # Starting topology, create tmp files which are loaded to routers |
d60a3f0e | 125 | # to start daemons and then start routers |
991a971f | 126 | start_topology(tgen) |
2448d002 | 127 | |
128 | # Creating configuration from JSON | |
129 | build_config_from_json(tgen, topo) | |
130 | ||
131 | # Don't run this test if we have any failure. | |
132 | if tgen.routers_have_failure(): | |
133 | pytest.skip(tgen.errors) | |
134 | ||
135 | ospf_covergence = verify_ospf6_neighbor(tgen, topo) | |
136 | assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( | |
137 | ospf_covergence | |
138 | ) | |
139 | ||
140 | logger.info("Running setup_module() done") | |
141 | ||
142 | ||
143 | def teardown_module(mod): | |
144 | """ | |
145 | Teardown the pytest environment. | |
146 | ||
147 | * `mod`: module name | |
148 | """ | |
149 | ||
150 | logger.info("Running teardown_module to delete topology") | |
151 | ||
152 | tgen = get_topogen() | |
153 | ||
154 | # Stop toplogy and Remove tmp files | |
155 | tgen.stop_topology() | |
156 | ||
157 | logger.info( | |
158 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
159 | ) | |
160 | logger.info("=" * 40) | |
161 | ||
162 | ||
163 | def get_llip(onrouter, intf): | |
164 | """ | |
dea6dce3 | 165 | API to get the link local ipv6 address of a particular interface |
2448d002 | 166 | |
167 | Parameters | |
168 | ---------- | |
169 | * `fromnode`: Source node | |
170 | * `tonode` : interface for which link local ip needs to be returned. | |
171 | ||
172 | Usage | |
173 | ----- | |
174 | result = get_llip('r1', 'r2-link0') | |
175 | ||
176 | Returns | |
177 | ------- | |
178 | 1) link local ipv6 address from the interface. | |
179 | 2) errormsg - when link local ip not found. | |
180 | """ | |
181 | tgen = get_topogen() | |
182 | intf = topo["routers"][onrouter]["links"][intf]["interface"] | |
183 | llip = get_frr_ipv6_linklocal(tgen, onrouter, intf) | |
184 | if llip: | |
185 | logger.info("llip ipv6 address to be set as NH is %s", llip) | |
186 | return llip | |
187 | return None | |
188 | ||
189 | ||
190 | def get_glipv6(onrouter, intf): | |
191 | """ | |
dea6dce3 | 192 | API to get the global ipv6 address of a particular interface |
2448d002 | 193 | |
194 | Parameters | |
195 | ---------- | |
196 | * `onrouter`: Source node | |
197 | * `intf` : interface for which link local ip needs to be returned. | |
198 | ||
199 | Usage | |
200 | ----- | |
201 | result = get_glipv6('r1', 'r2-link0') | |
202 | ||
203 | Returns | |
204 | ------- | |
205 | 1) global ipv6 address from the interface. | |
206 | 2) errormsg - when link local ip not found. | |
207 | """ | |
208 | glipv6 = (topo["routers"][onrouter]["links"][intf]["ipv6"]).split("/")[0] | |
209 | if glipv6: | |
210 | logger.info("Global ipv6 address to be set as NH is %s", glipv6) | |
211 | return glipv6 | |
212 | return None | |
213 | ||
214 | ||
215 | def red_static(dut, config=True): | |
216 | """Local def for Redstribute static routes inside ospf.""" | |
217 | global topo | |
218 | tgen = get_topogen() | |
219 | if config: | |
220 | ospf_red = {dut: {"ospf6": {"redistribute": [{"redist_type": "static"}]}}} | |
221 | else: | |
222 | ospf_red = { | |
223 | dut: { | |
224 | "ospf6": { | |
225 | "redistribute": [{"redist_type": "static", "del_action": True}] | |
226 | } | |
227 | } | |
228 | } | |
229 | result = create_router_ospf(tgen, topo, ospf_red) | |
230 | assert result is True, "Testcase : Failed \n Error: {}".format(result) | |
231 | ||
232 | ||
233 | def red_connected(dut, config=True): | |
234 | """Local def for Redstribute connected routes inside ospf.""" | |
235 | global topo | |
236 | tgen = get_topogen() | |
237 | if config: | |
238 | ospf_red = {dut: {"ospf6": {"redistribute": [{"redist_type": "connected"}]}}} | |
239 | else: | |
240 | ospf_red = { | |
241 | dut: { | |
242 | "ospf6": { | |
243 | "redistribute": [{"redist_type": "connected", "del_action": True}] | |
244 | } | |
245 | } | |
246 | } | |
247 | result = create_router_ospf(tgen, topo, ospf_red) | |
248 | assert result is True, "Testcase: Failed \n Error: {}".format(result) | |
249 | ||
250 | ||
251 | # ################################## | |
252 | # Test cases start here. | |
253 | # ################################## | |
d1b5fa5b | 254 | |
255 | ||
db56171c | 256 | def test_ospfv3_redistribution_tc5_p0(request): |
257 | """Test OSPF intra area route calculations.""" | |
258 | tc_name = request.node.name | |
259 | write_test_header(tc_name) | |
260 | tgen = get_topogen() | |
261 | ||
262 | # Don't run this test if we have any failure. | |
263 | if tgen.routers_have_failure(): | |
d1b5fa5b | 264 | check_router_status(tgen) |
db56171c | 265 | |
266 | global topo | |
267 | step("Bring up the base config.") | |
268 | reset_config_on_routers(tgen) | |
269 | ||
270 | step("Verify that OSPF neighbors are FULL.") | |
271 | ospf_covergence = verify_ospf6_neighbor(tgen, topo) | |
272 | assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( | |
273 | ospf_covergence | |
274 | ) | |
275 | ||
276 | step("verify intra area route is calculated for r0-r3 interface ip in R1") | |
277 | ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"] | |
278 | ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network) | |
279 | ||
280 | llip = get_llip("r0", "r1") | |
281 | assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, llip) | |
282 | ||
283 | nh = llip | |
284 | input_dict = { | |
d1b5fa5b | 285 | "r1": { |
286 | "static_routes": [ | |
287 | {"network": ip_net, "no_of_ip": 1, "routeType": "Network"} | |
288 | ] | |
289 | } | |
db56171c | 290 | } |
291 | ||
292 | dut = "r1" | |
293 | result = verify_ospf6_rib(tgen, dut, input_dict, next_hop=nh) | |
294 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
295 | ||
296 | protocol = "ospf" | |
297 | result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) | |
298 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
299 | ||
300 | step("Delete the ip address on newly configured loopback of R0") | |
301 | topo1 = { | |
302 | "r0": { | |
303 | "links": { | |
304 | "r3": { | |
305 | "ipv6": topo["routers"]["r0"]["links"]["r3"]["ipv6"], | |
306 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
307 | "delete": True, | |
308 | } | |
309 | } | |
310 | } | |
311 | } | |
312 | ||
313 | result = create_interfaces_cfg(tgen, topo1) | |
314 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
315 | ||
316 | dut = "r1" | |
317 | result = verify_ospf6_rib(tgen, dut, input_dict, next_hop=nh, expected=False) | |
318 | assert ( | |
319 | result is not True | |
320 | ), "Testcase {} : Failed \n Route present in RIB. Error: {}".format(tc_name, result) | |
321 | ||
322 | protocol = "ospf" | |
323 | result = verify_rib( | |
324 | tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh, expected=False | |
325 | ) | |
326 | assert ( | |
327 | result is not True | |
328 | ), "Testcase {} : Failed \n Route present in RIB. Error: {}".format(tc_name, result) | |
329 | ||
330 | step("Add back the deleted ip address on newly configured interface of R0") | |
331 | topo1 = { | |
332 | "r0": { | |
333 | "links": { | |
334 | "r3": { | |
335 | "ipv6": topo["routers"]["r0"]["links"]["r3"]["ipv6"], | |
336 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
337 | } | |
338 | } | |
339 | } | |
340 | } | |
341 | ||
342 | result = create_interfaces_cfg(tgen, topo1) | |
343 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
344 | ||
345 | dut = "r1" | |
346 | result = verify_ospf6_rib(tgen, dut, input_dict, next_hop=nh) | |
347 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
348 | ||
349 | protocol = "ospf" | |
350 | result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) | |
351 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
352 | ||
353 | step("Shut no shut interface on R0") | |
354 | dut = "r0" | |
355 | intf = topo["routers"]["r0"]["links"]["r3"]["interface"] | |
356 | shutdown_bringup_interface(tgen, dut, intf, False) | |
357 | ||
358 | step("un shut the OSPF interface on R0") | |
359 | dut = "r0" | |
360 | shutdown_bringup_interface(tgen, dut, intf, True) | |
361 | ||
362 | dut = "r1" | |
363 | result = verify_ospf6_rib(tgen, dut, input_dict) | |
364 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
365 | ||
366 | protocol = "ospf" | |
367 | result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) | |
368 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
369 | ||
370 | write_test_footer(tc_name) | |
371 | ||
372 | ||
373 | def test_ospfv3_redistribution_tc6_p0(request): | |
374 | """Test OSPF inter area route calculations.""" | |
375 | tc_name = request.node.name | |
376 | write_test_header(tc_name) | |
377 | tgen = get_topogen() | |
378 | ||
379 | # Don't run this test if we have any failure. | |
380 | if tgen.routers_have_failure(): | |
d1b5fa5b | 381 | check_router_status(tgen) |
db56171c | 382 | |
383 | global topo | |
384 | step("Bring up the base config.") | |
385 | reset_config_on_routers(tgen) | |
386 | ||
387 | step("Verify that OSPF neighbors are FULL.") | |
388 | ospf_covergence = verify_ospf6_neighbor(tgen, topo) | |
d1b5fa5b | 389 | assert ospf_covergence is True, "Testcase {} : Failed \n Error: {}".format( |
390 | tc_name, ospf_covergence | |
db56171c | 391 | ) |
392 | ||
393 | step("verify intra area route is calculated for r0-r3 interface ip in R1") | |
394 | ip = topo["routers"]["r0"]["links"]["r3"]["ipv6"] | |
395 | ip_net = str(ipaddress.ip_interface(u"{}".format(ip)).network) | |
396 | llip = get_llip("r0", "r1") | |
397 | assert llip is not None, "Testcase {} : Failed \n Error: {}".format(tc_name, llip) | |
398 | nh = llip | |
399 | input_dict = { | |
d1b5fa5b | 400 | "r1": { |
401 | "static_routes": [ | |
402 | {"network": ip_net, "no_of_ip": 1, "routeType": "Network"} | |
403 | ] | |
404 | } | |
db56171c | 405 | } |
406 | ||
407 | dut = "r1" | |
408 | result = verify_ospf6_rib(tgen, dut, input_dict, next_hop=nh) | |
409 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
410 | ||
411 | protocol = "ospf" | |
412 | result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) | |
413 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
414 | ||
415 | step("Delete the ip address on newly configured loopback of R0") | |
416 | topo1 = { | |
417 | "r0": { | |
418 | "links": { | |
419 | "r3": { | |
420 | "ipv6": topo["routers"]["r0"]["links"]["r3"]["ipv6"], | |
421 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
422 | "delete": True, | |
423 | } | |
424 | } | |
425 | } | |
426 | } | |
427 | ||
428 | result = create_interfaces_cfg(tgen, topo1) | |
429 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
430 | ||
431 | dut = "r1" | |
432 | result = verify_ospf6_rib(tgen, dut, input_dict, next_hop=nh, expected=False) | |
433 | assert ( | |
434 | result is not True | |
435 | ), "Testcase {} : Failed \n Route present in RIB. Error: {}".format(tc_name, result) | |
436 | ||
437 | protocol = "ospf" | |
438 | result = verify_rib( | |
439 | tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh, expected=False | |
440 | ) | |
441 | assert ( | |
442 | result is not True | |
443 | ), "Testcase {} : Failed \n Route present in RIB. Error: {}".format(tc_name, result) | |
444 | ||
445 | step("Add back the deleted ip address on newly configured interface of R0") | |
446 | topo1 = { | |
447 | "r0": { | |
448 | "links": { | |
449 | "r3": { | |
450 | "ipv6": topo["routers"]["r0"]["links"]["r3"]["ipv6"], | |
451 | "interface": topo["routers"]["r0"]["links"]["r3"]["interface"], | |
452 | } | |
453 | } | |
454 | } | |
455 | } | |
456 | ||
457 | result = create_interfaces_cfg(tgen, topo1) | |
458 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
459 | ||
460 | dut = "r1" | |
461 | result = verify_ospf6_rib(tgen, dut, input_dict, next_hop=nh) | |
462 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
463 | ||
464 | protocol = "ospf" | |
465 | result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) | |
466 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
467 | ||
468 | step("Shut no shut interface on R0") | |
469 | dut = "r0" | |
470 | intf = topo["routers"]["r0"]["links"]["r3"]["interface"] | |
471 | shutdown_bringup_interface(tgen, dut, intf, False) | |
472 | ||
db56171c | 473 | step("un shut the OSPF interface on R0") |
474 | dut = "r0" | |
475 | shutdown_bringup_interface(tgen, dut, intf, True) | |
476 | ||
477 | dut = "r1" | |
478 | result = verify_ospf6_rib(tgen, dut, input_dict) | |
479 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
480 | ||
481 | protocol = "ospf" | |
482 | result = verify_rib(tgen, "ipv6", dut, input_dict, protocol=protocol, next_hop=nh) | |
483 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
484 | ||
485 | write_test_footer(tc_name) | |
486 | ||
487 | ||
d1b5fa5b | 488 | def test_ospfv3_redistribution_tc8_p1(request): |
489 | """ | |
490 | Test OSPF redistribution of connected routes. | |
491 | ||
492 | Verify OSPF redistribution of connected routes when bgp multi hop | |
493 | neighbor is configured using ospf routes | |
494 | ||
495 | """ | |
496 | tc_name = request.node.name | |
497 | write_test_header(tc_name) | |
498 | tgen = get_topogen() | |
499 | global topo | |
500 | step("Bring up the base config.") | |
501 | step( | |
502 | "Configure loopback interface on all routers, and redistribut" | |
503 | "e connected routes into ospf" | |
504 | ) | |
505 | if tgen.routers_have_failure(): | |
506 | check_router_status(tgen) | |
507 | reset_config_on_routers(tgen) | |
508 | ||
509 | step( | |
510 | "verify that connected routes -loopback is found in all routers" | |
511 | "advertised/exchaged via ospf" | |
512 | ) | |
513 | for rtr in topo["routers"]: | |
514 | red_static(rtr) | |
515 | red_connected(rtr) | |
516 | ||
517 | for node in topo["routers"]: | |
518 | input_dict = { | |
519 | "r0": { | |
520 | "static_routes": [ | |
521 | { | |
522 | "network": topo["routers"][node]["links"]["lo"]["ipv6"], | |
523 | "no_of_ip": 1, | |
524 | } | |
525 | ] | |
526 | } | |
527 | } | |
528 | for rtr in topo["routers"]: | |
529 | result = verify_rib(tgen, "ipv6", rtr, input_dict) | |
530 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
531 | tc_name, result | |
532 | ) | |
533 | ||
534 | step("Configure E BGP multi hop using the loopback addresses.") | |
535 | as_num = 100 | |
536 | for node in topo["routers"]: | |
537 | as_num += 1 | |
538 | topo["routers"][node].update( | |
539 | { | |
540 | "bgp": { | |
541 | "local_as": as_num, | |
542 | "address_family": {"ipv6": {"unicast": {"neighbor": {}}}}, | |
543 | } | |
544 | } | |
545 | ) | |
546 | for node in topo["routers"]: | |
547 | for rtr in topo["routers"]: | |
548 | if node is not rtr: | |
549 | topo["routers"][node]["bgp"]["address_family"]["ipv6"]["unicast"][ | |
550 | "neighbor" | |
551 | ].update( | |
552 | { | |
553 | rtr: { | |
554 | "dest_link": { | |
555 | "lo": {"source_link": "lo", "ebgp_multihop": 2} | |
556 | } | |
557 | } | |
558 | } | |
559 | ) | |
560 | ||
561 | result = create_router_bgp(tgen, topo, topo["routers"]) | |
562 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
563 | ||
564 | # Modify router id | |
565 | input_dict = { | |
566 | "r0": {"bgp": {"router_id": "11.11.11.11"}}, | |
567 | "r1": {"bgp": {"router_id": "22.22.22.22"}}, | |
568 | "r2": {"bgp": {"router_id": "33.33.33.33"}}, | |
569 | "r3": {"bgp": {"router_id": "44.44.44.44"}}, | |
570 | } | |
571 | result = create_router_bgp(tgen, topo, input_dict) | |
572 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
573 | ||
574 | step("Verify that BGP neighbor is ESTABLISHED") | |
575 | result = verify_bgp_convergence(tgen, topo) | |
576 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
577 | step( | |
578 | "Configure couple of static routes in R0 and " | |
579 | "Redistribute static routes in R1 bgp." | |
580 | ) | |
581 | ||
582 | for rtr in topo["routers"]: | |
583 | ospf_red = { | |
584 | rtr: { | |
585 | "ospf6": {"redistribute": [{"redist_type": "static", "delete": True}]} | |
586 | } | |
587 | } | |
588 | result = create_router_ospf(tgen, topo, ospf_red) | |
589 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
590 | tc_name, result | |
591 | ) | |
592 | ||
593 | input_dict = { | |
594 | "r0": { | |
595 | "static_routes": [ | |
596 | { | |
597 | "network": NETWORK["ipv6"][0], | |
598 | "no_of_ip": 5, | |
599 | "next_hop": "Null0", | |
600 | } | |
601 | ] | |
602 | } | |
603 | } | |
604 | result = create_static_routes(tgen, input_dict) | |
605 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
606 | ||
607 | configure_bgp_on_r0 = { | |
608 | "r0": { | |
609 | "bgp": { | |
610 | "address_family": { | |
611 | "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}} | |
612 | } | |
613 | } | |
614 | } | |
615 | } | |
616 | result = create_router_bgp(tgen, topo, configure_bgp_on_r0) | |
617 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
618 | protocol = "bgp" | |
619 | for rtr in ["r1", "r2", "r3"]: | |
620 | result = verify_rib(tgen, "ipv6", rtr, input_dict, protocol=protocol) | |
621 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
622 | tc_name, result | |
623 | ) | |
624 | ||
625 | step("Clear ospf neighbours in R0") | |
626 | for rtr in topo["routers"]: | |
627 | clear_ospf(tgen, rtr) | |
628 | ||
629 | step("Verify that OSPF neighbours are reset and forms new adjacencies.") | |
630 | # Api call verify whether OSPF is converged | |
631 | ospf_covergence = verify_ospf6_neighbor(tgen, topo) | |
632 | assert ospf_covergence is True, "setup_module :Failed \n Error:" " {}".format( | |
633 | ospf_covergence | |
634 | ) | |
635 | ||
636 | step("Verify that BGP neighbours are reset and forms new adjacencies.") | |
637 | result = verify_bgp_convergence(tgen, topo) | |
638 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
639 | ||
640 | protocol = "bgp" | |
641 | for rtr in ["r1", "r2", "r3"]: | |
642 | result = verify_rib(tgen, "ipv6", rtr, input_dict, protocol=protocol) | |
643 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
644 | tc_name, result | |
645 | ) | |
646 | ||
647 | write_test_footer(tc_name) | |
648 | ||
649 | ||
2448d002 | 650 | def test_ospfv3_cost_tc52_p0(request): |
651 | """OSPF Cost - verifying ospf interface cost functionality""" | |
652 | tc_name = request.node.name | |
653 | write_test_header(tc_name) | |
654 | tgen = get_topogen() | |
655 | global topo | |
656 | step("Bring up the base config.") | |
d1b5fa5b | 657 | if tgen.routers_have_failure(): |
658 | check_router_status(tgen) | |
2448d002 | 659 | reset_config_on_routers(tgen) |
660 | ||
661 | step( | |
662 | "Configure ospf cost as 20 on interface between R0 and R1. " | |
663 | "Configure ospf cost as 30 between interface between R0 and R2." | |
664 | ) | |
665 | ||
666 | r0_ospf_cost = { | |
667 | "r0": {"links": {"r1": {"ospf6": {"cost": 20}}, "r2": {"ospf6": {"cost": 30}}}} | |
668 | } | |
669 | result = config_ospf6_interface(tgen, topo, r0_ospf_cost) | |
670 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
671 | ||
672 | step( | |
673 | "Verify that cost is updated in the ospf interface between" | |
674 | " r0 and r1 as 30 and r0 and r2 as 20" | |
675 | ) | |
676 | dut = "r0" | |
677 | result = verify_ospf6_interface(tgen, topo, dut=dut, input_dict=r0_ospf_cost) | |
678 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
679 | ||
680 | step( | |
681 | "Swap the costs between interfaces on r0, between r0 and r1 to 30" | |
682 | ", r0 and r2 to 20" | |
683 | ) | |
684 | ||
685 | r0_ospf_cost = { | |
686 | "r0": {"links": {"r1": {"ospf6": {"cost": 30}}, "r2": {"ospf6": {"cost": 20}}}} | |
687 | } | |
688 | result = config_ospf6_interface(tgen, topo, r0_ospf_cost) | |
689 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
690 | ||
691 | step( | |
692 | "Verify that cost is updated in the ospf interface between r0 " | |
693 | "and r1 as 30 and r0 and r2 as 20." | |
694 | ) | |
695 | result = verify_ospf6_interface(tgen, topo, dut=dut, input_dict=r0_ospf_cost) | |
696 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
697 | ||
698 | step(" Un configure cost from the interface r0 - r1.") | |
699 | ||
700 | r0_ospf_cost = { | |
701 | "r0": {"links": {"r1": {"ospf6": {"cost": 30, "del_action": True}}}} | |
702 | } | |
703 | result = config_ospf6_interface(tgen, topo, r0_ospf_cost) | |
704 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
705 | ||
706 | input_dict = { | |
707 | "r0": {"links": {"r1": {"ospf6": {"cost": 10}}, "r2": {"ospf6": {"cost": 20}}}} | |
708 | } | |
709 | step( | |
710 | "Verify that cost is updated in the ospf interface between r0" | |
711 | " and r1 as 10 and r0 and r2 as 20." | |
712 | ) | |
713 | ||
714 | result = verify_ospf6_interface(tgen, topo, dut=dut, input_dict=input_dict) | |
715 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
716 | ||
717 | step(" Un configure cost from the interface r0 - r2.") | |
718 | ||
719 | r0_ospf_cost = { | |
720 | "r0": {"links": {"r2": {"ospf6": {"cost": 20, "del_action": True}}}} | |
721 | } | |
722 | result = config_ospf6_interface(tgen, topo, r0_ospf_cost) | |
723 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
724 | ||
725 | step( | |
726 | "Verify that cost is updated in the ospf interface between r0" | |
727 | "and r1 as 10 and r0 and r2 as 10" | |
728 | ) | |
729 | ||
730 | input_dict = { | |
731 | "r0": {"links": {"r1": {"ospf6": {"cost": 10}}, "r2": {"ospf6": {"cost": 10}}}} | |
732 | } | |
733 | result = verify_ospf6_interface(tgen, topo, dut=dut, input_dict=input_dict) | |
734 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
735 | ||
736 | write_test_footer(tc_name) | |
737 | ||
738 | ||
d1b5fa5b | 739 | def test_ospfv3_def_rte_tc9_p0(request): |
740 | """OSPF default route - Verify OSPF default route origination.""" | |
741 | tc_name = request.node.name | |
742 | write_test_header(tc_name) | |
743 | tgen = get_topogen() | |
744 | global topo | |
745 | step("Bring up the base config.") | |
746 | step("Configure OSPF on all the routers of the topology.") | |
747 | if tgen.routers_have_failure(): | |
748 | check_router_status(tgen) | |
749 | reset_config_on_routers(tgen) | |
750 | ||
751 | step(" Configure default-information originate always on R0.") | |
752 | input_dict = {"r0": {"ospf6": {"default-information": {"originate": True}}}} | |
753 | result = create_router_ospf(tgen, topo, input_dict) | |
754 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
755 | ||
756 | dut = "r0" | |
757 | step(" Configure default-information originate always on R0.") | |
758 | input_dict = { | |
759 | "r0": { | |
760 | "ospf6": { | |
761 | "default-information": { | |
762 | "originate": True, | |
763 | "always": True, | |
764 | } | |
765 | } | |
766 | } | |
767 | } | |
768 | result = create_router_ospf(tgen, topo, input_dict) | |
769 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
770 | ||
771 | step("Verify that default route is originated in area always.") | |
772 | dut = "r1" | |
773 | ||
774 | step(" Configure default-information originate metric type 1 on R0.") | |
775 | input_dict = { | |
776 | "r0": { | |
777 | "ospf6": { | |
778 | "default-information": { | |
779 | "originate": True, | |
780 | "always": True, | |
781 | "metric-type": 1, | |
782 | } | |
783 | } | |
784 | } | |
785 | } | |
786 | ||
787 | step( | |
788 | "Verify that default route is originated in area when external " | |
789 | "routes are present in R0 with metric type as 1." | |
790 | ) | |
791 | dut = "r0" | |
792 | step( | |
793 | "Verify that on R1 default route with type 1 is installed" | |
794 | " (R1 is DUT in this case)" | |
795 | ) | |
796 | dut = "r1" | |
797 | step("Configure default-information originate metric type 2 on R0.") | |
798 | input_dict = { | |
799 | "r0": { | |
800 | "ospf6": { | |
801 | "default-information": { | |
802 | "originate": True, | |
803 | "always": True, | |
804 | "metric-type": 2, | |
805 | } | |
806 | } | |
807 | } | |
808 | } | |
809 | result = create_router_ospf(tgen, topo, input_dict) | |
810 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
811 | ||
812 | step( | |
813 | "Verify that default route is originated in area when external" | |
814 | " routes are present in R0 with metric type as 2." | |
815 | ) | |
816 | ||
817 | dut = "r1" | |
818 | step(" Configure default-information originate metric 100 on R0") | |
819 | input_dict = { | |
820 | "r0": { | |
821 | "ospf6": { | |
822 | "default-information": { | |
823 | "originate": True, | |
824 | "always": True, | |
825 | "metric-type": 2, | |
826 | "metric": 100, | |
827 | } | |
828 | } | |
829 | } | |
830 | } | |
831 | result = create_router_ospf(tgen, topo, input_dict) | |
832 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
833 | ||
834 | step("Verify that default route is originated with cost as 100 on R0.") | |
835 | ||
836 | dut = "r1" | |
837 | ||
838 | step("Delete the default-information command") | |
839 | input_dict = { | |
840 | "r0": { | |
841 | "ospf6": { | |
842 | "default-information": { | |
843 | "originate": True, | |
844 | "always": True, | |
845 | "delete": True, | |
846 | } | |
847 | } | |
848 | } | |
849 | } | |
850 | result = create_router_ospf(tgen, topo, input_dict) | |
851 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
852 | ||
853 | dut = "r0" | |
854 | step("Configure default-information originate always on R0.") | |
855 | input_dict = { | |
856 | "r0": { | |
857 | "ospf6": { | |
858 | "default-information": { | |
859 | "originate": True, | |
860 | "always": True, | |
861 | } | |
862 | } | |
863 | } | |
864 | } | |
865 | result = create_router_ospf(tgen, topo, input_dict) | |
866 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
867 | ||
868 | step("Configure default route originate with active def route in zebra") | |
869 | input_dict = { | |
870 | "r0": { | |
871 | "static_routes": [ | |
872 | { | |
873 | "network": "0::0/0", | |
874 | "no_of_ip": 1, | |
875 | "next_hop": "Null0", | |
876 | } | |
877 | ] | |
878 | } | |
879 | } | |
880 | result = create_static_routes(tgen, input_dict) | |
881 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
882 | ||
883 | input_dict = { | |
884 | "r0": { | |
885 | "ospf6": { | |
886 | "default-information": { | |
887 | "originate": True, | |
888 | } | |
889 | } | |
890 | } | |
891 | } | |
892 | result = create_router_ospf(tgen, topo, input_dict) | |
893 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
894 | ||
895 | step("Verify that default route is originated by R0.") | |
896 | dut = "r1" | |
897 | ||
898 | step("Delete static route") | |
899 | input_dict = { | |
900 | "r0": { | |
901 | "static_routes": [ | |
902 | { | |
903 | "network": "0::0/0", | |
904 | "no_of_ip": 1, | |
905 | "next_hop": "Null0", | |
906 | "delete": True, | |
907 | } | |
908 | ] | |
909 | } | |
910 | } | |
911 | result = create_static_routes(tgen, input_dict) | |
912 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
913 | ||
914 | write_test_footer(tc_name) | |
915 | ||
916 | ||
2448d002 | 917 | if __name__ == "__main__": |
918 | args = ["-s"] + sys.argv[1:] | |
919 | sys.exit(pytest.main(args)) |