]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/static_routing_with_ibgp/test_static_routes_topo3_ibgp.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / static_routing_with_ibgp / test_static_routes_topo3_ibgp.py
1 #!/usr/bin/python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # Copyright (c) 2020 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation,
7 # Inc. ("NetDEF") in this file.
8 #
9 """
10 -Verify static route ECMP functionality with 8 next hop
11
12 -Verify static route functionality with 8 next hop different AD value
13
14 -Verify static route with tag option
15
16 -Verify BGP did not install the static route when it receive route
17 with local next hop
18
19 """
20 import sys
21 import time
22 import os
23 import pytest
24 import platform
25 import random
26
27
28 # Save the Current Working Directory to find configuration files.
29 CWD = os.path.dirname(os.path.realpath(__file__))
30 sys.path.append(os.path.join(CWD, "../"))
31 sys.path.append(os.path.join(CWD, "../lib/"))
32 # pylint: disable=C0413
33 # Import topogen and topotest helpers
34 from lib.topogen import Topogen, get_topogen
35 from lib.topotest import version_cmp
36
37 from lib.common_config import (
38 start_topology,
39 write_test_header,
40 write_test_footer,
41 reset_config_on_routers,
42 verify_rib,
43 create_static_routes,
44 check_address_types,
45 step,
46 shutdown_bringup_interface,
47 stop_router,
48 start_router,
49 )
50 from lib.topolog import logger
51 from lib.bgp import verify_bgp_convergence, create_router_bgp, verify_bgp_rib
52 from lib.topojson import build_config_from_json
53
54 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
55
56 # Global variables
57 BGP_CONVERGENCE = False
58 ADDR_TYPES = check_address_types()
59 NETWORK = {
60 "ipv4": [
61 "11.0.20.1/32",
62 "11.0.20.2/32",
63 "11.0.20.3/32",
64 "11.0.20.4/32",
65 "11.0.20.5/32",
66 "11.0.20.6/32",
67 "11.0.20.7/32",
68 "11.0.20.8/32",
69 ],
70 "ipv6": [
71 "2::1/128",
72 "2::2/128",
73 "2::3/128",
74 "2::4/128",
75 "2::5/128",
76 "2::6/128",
77 "2::7/128",
78 "2::8/128",
79 ],
80 }
81 PREFIX1 = {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"}
82 NETWORK2 = {"ipv4": ["11.0.20.1/32"], "ipv6": ["2::1/128"]}
83 NEXT_HOP_IP = []
84
85
86 def setup_module(mod):
87 """
88
89 Set up the pytest environment.
90
91 * `mod`: module name
92 """
93 testsuite_run_time = time.asctime(time.localtime(time.time()))
94 logger.info("Testsuite start time: {}".format(testsuite_run_time))
95 logger.info("=" * 40)
96
97 logger.info("Running setup_module to create topology")
98
99 # This function initiates the topology build with Topogen...
100 json_file = "{}/static_routes_topo3_ibgp.json".format(CWD)
101 tgen = Topogen(json_file, mod.__name__)
102 global topo
103 topo = tgen.json_topo
104 # ... and here it calls Mininet initialization functions.
105
106 # Starting topology, create tmp files which are loaded to routers
107 # to start daemons and then start routers
108 start_topology(tgen)
109
110 # Creating configuration from JSON
111 build_config_from_json(tgen, topo)
112
113 if version_cmp(platform.release(), "4.19") < 0:
114 error_msg = (
115 'These tests will not run. (have kernel "{}", '
116 "requires kernel >= 4.19)".format(platform.release())
117 )
118 pytest.skip(error_msg)
119
120 # Checking BGP convergence
121 global BGP_CONVERGENCE
122 global ADDR_TYPES
123
124 # Don't run this test if we have any failure.
125 if tgen.routers_have_failure():
126 pytest.skip(tgen.errors)
127 # Api call verify whether BGP is converged
128 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
129 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
130 BGP_CONVERGENCE
131 )
132
133 logger.info("Running setup_module() done")
134
135
136 def teardown_module(mod):
137 """
138 Teardown the pytest environment
139
140 * `mod`: module name
141 """
142
143 logger.info("Running teardown_module to delete topology")
144
145 tgen = get_topogen()
146
147 # Stop toplogy and Remove tmp files
148 tgen.stop_topology()
149
150 logger.info(
151 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
152 )
153 logger.info("=" * 40)
154
155
156 def populate_nh():
157 NEXT_HOP_IP = {
158 "nh1": {
159 "ipv4": topo["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0],
160 "ipv6": topo["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0],
161 },
162 "nh2": {
163 "ipv4": topo["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
164 "ipv6": topo["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0],
165 },
166 "nh3": {
167 "ipv4": topo["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0],
168 "ipv6": topo["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0],
169 },
170 "nh4": {
171 "ipv4": topo["routers"]["r1"]["links"]["r2-link3"]["ipv4"].split("/")[0],
172 "ipv6": topo["routers"]["r1"]["links"]["r2-link3"]["ipv6"].split("/")[0],
173 },
174 "nh5": {
175 "ipv4": topo["routers"]["r1"]["links"]["r2-link4"]["ipv4"].split("/")[0],
176 "ipv6": topo["routers"]["r1"]["links"]["r2-link4"]["ipv6"].split("/")[0],
177 },
178 "nh6": {
179 "ipv4": topo["routers"]["r1"]["links"]["r2-link5"]["ipv4"].split("/")[0],
180 "ipv6": topo["routers"]["r1"]["links"]["r2-link5"]["ipv6"].split("/")[0],
181 },
182 "nh7": {
183 "ipv4": topo["routers"]["r1"]["links"]["r2-link6"]["ipv4"].split("/")[0],
184 "ipv6": topo["routers"]["r1"]["links"]["r2-link6"]["ipv6"].split("/")[0],
185 },
186 "nh8": {
187 "ipv4": topo["routers"]["r1"]["links"]["r2-link7"]["ipv4"].split("/")[0],
188 "ipv6": topo["routers"]["r1"]["links"]["r2-link7"]["ipv6"].split("/")[0],
189 },
190 }
191 return NEXT_HOP_IP
192
193
194 #####################################################
195 #
196 # Tests starting
197 #
198 #####################################################
199
200
201 def test_staticroute_with_ecmp_p0_tc3_ibgp(request):
202 """
203 Verify static route ECMP functionality with 8 next hop'
204
205 """
206 tc_name = request.node.name
207 write_test_header(tc_name)
208 tgen = get_topogen()
209
210 # Don't run this test if we have any failure.
211 if tgen.routers_have_failure():
212 pytest.skip(tgen.errors)
213
214 reset_config_on_routers(tgen)
215 NEXT_HOP_IP = populate_nh()
216
217 step("Configure 8 interfaces / links between R1 and R2,")
218 step(
219 "Configure IPv4 static route in R2 with 8 next hop"
220 "N1(21.1.1.2), N2(22.1.1.2), N3(23.1.1.2), N4(24.1.1.2),"
221 "N5(25.1.1.2), N6(26.1.1.2), N7(27.1.1.2),N8(28.1.1.2), Static"
222 "route next-hop present on R1"
223 )
224
225 step("Configure IBGP IPv4 peering between R2 and R3 router.")
226
227 for addr_type in ADDR_TYPES:
228 # Enable static routes
229 for nhp in range(1, 9):
230 input_dict_4 = {
231 "r2": {
232 "static_routes": [
233 {
234 "network": PREFIX1[addr_type],
235 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
236 }
237 ]
238 }
239 }
240 logger.info("Configure static routes")
241 result = create_static_routes(tgen, input_dict_4)
242 assert result is True, "Testcase {} : Failed \n Error: {}".format(
243 tc_name, result
244 )
245 logger.info("Verifying %s routes on r2", addr_type)
246 nh = [
247 NEXT_HOP_IP["nh1"][addr_type],
248 NEXT_HOP_IP["nh2"][addr_type],
249 NEXT_HOP_IP["nh3"][addr_type],
250 NEXT_HOP_IP["nh4"][addr_type],
251 NEXT_HOP_IP["nh5"][addr_type],
252 NEXT_HOP_IP["nh6"][addr_type],
253 NEXT_HOP_IP["nh7"][addr_type],
254 NEXT_HOP_IP["nh8"][addr_type],
255 ]
256
257 dut = "r2"
258 protocol = "static"
259 result = verify_rib(
260 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
261 )
262 assert (
263 result is True
264 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
265 step("Configure redistribute static in BGP on R2 router")
266 for addr_type in ADDR_TYPES:
267 input_dict_2 = {
268 "r2": {
269 "bgp": {
270 "address_family": {
271 addr_type: {
272 "unicast": {"redistribute": [{"redist_type": "static"}]}
273 }
274 }
275 }
276 }
277 }
278 result = create_router_bgp(tgen, topo, input_dict_2)
279 assert result is True, "Testcase {} : Failed \n Error: {}".format(
280 tc_name, result
281 )
282
283 step(
284 "Remove the static route configured with nexthop N1 to N8, one"
285 "by one from running config"
286 )
287 for addr_type in ADDR_TYPES:
288 # delete static routes
289 for nhp in range(1, 9):
290 input_dict_4 = {
291 "r2": {
292 "static_routes": [
293 {
294 "network": PREFIX1[addr_type],
295 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
296 "delete": True,
297 }
298 ]
299 }
300 }
301
302 logger.info("Configure static routes")
303 result = create_static_routes(tgen, input_dict_4)
304 assert result is True, "Testcase {} : Failed \n Error: {}".format(
305 tc_name, result
306 )
307
308 result = verify_rib(
309 tgen,
310 addr_type,
311 dut,
312 input_dict_4,
313 next_hop=nh,
314 protocol=protocol,
315 expected=False,
316 )
317 assert (
318 result is not True
319 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
320 tc_name
321 )
322
323 step("Configure the static route with nexthop N1 to N8, one by" "one")
324
325 for addr_type in ADDR_TYPES:
326 # add static routes
327 for nhp in range(1, 9):
328 input_dict_4 = {
329 "r2": {
330 "static_routes": [
331 {
332 "network": PREFIX1[addr_type],
333 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
334 }
335 ]
336 }
337 }
338
339 logger.info("Configure static routes")
340 result = create_static_routes(tgen, input_dict_4)
341 assert result is True, "Testcase {} : Failed \n Error: {}".format(
342 tc_name, result
343 )
344
345 result = verify_rib(
346 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
347 )
348 assert (
349 result is True
350 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
351
352 step("Random shut of the nexthop interfaces")
353 randnum = random.randint(0, 7)
354 for addr_type in ADDR_TYPES:
355 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
356 shutdown_bringup_interface(tgen, dut, intf, False)
357 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
358 input_dict_5 = {
359 "r2": {
360 "static_routes": [
361 {
362 "network": PREFIX1[addr_type],
363 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
364 }
365 ]
366 }
367 }
368 result = verify_rib(
369 tgen,
370 addr_type,
371 dut,
372 input_dict_5,
373 next_hop=nhip,
374 protocol=protocol,
375 expected=False,
376 )
377 assert (
378 result is not True
379 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
380 tc_name
381 )
382
383 step("Random no shut of the nexthop interfaces")
384 for addr_type in ADDR_TYPES:
385 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
386 shutdown_bringup_interface(tgen, dut, intf, True)
387 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
388 result = verify_rib(
389 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
390 )
391 assert (
392 result is True
393 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
394
395 step("Reload the FRR router")
396 # stop/start -> restart FRR router and verify
397 stop_router(tgen, "r2")
398 start_router(tgen, "r2")
399
400 result = verify_rib(
401 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
402 )
403 assert (
404 result is True
405 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
406
407 write_test_footer(tc_name)
408
409
410 def test_staticroute_with_ecmp_with_diff_AD_p0_tc4_ibgp(request):
411 """
412 Verify static route ECMP functionality with 8 next hop
413
414 """
415 tc_name = request.node.name
416 write_test_header(tc_name)
417 tgen = get_topogen()
418
419 # Don't run this test if we have any failure.
420 if tgen.routers_have_failure():
421 pytest.skip(tgen.errors)
422
423 reset_config_on_routers(tgen)
424
425 step("Configure 8 interfaces / links between R1 and R2,")
426 step("Configure IBGP IPv4 peering between R2 and R3 router.")
427 NEXT_HOP_IP = populate_nh()
428 nh_all = {}
429 for addr_type in ADDR_TYPES:
430 nh_all[addr_type] = []
431 for nhp in range(1, 9):
432 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
433 step(
434 "Configure IPv4 static route in R2 with 8 next hop"
435 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
436 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
437 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
438 "present on R1"
439 )
440 for addr_type in ADDR_TYPES:
441 for nhp in range(1, 9):
442 input_dict_4 = {
443 "r2": {
444 "static_routes": [
445 {
446 "network": PREFIX1[addr_type],
447 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
448 "admin_distance": 10 * nhp,
449 }
450 ]
451 }
452 }
453 logger.info("Configure static routes")
454 result = create_static_routes(tgen, input_dict_4)
455 assert result is True, "Testcase {} : Failed \n Error: {}".format(
456 tc_name, result
457 )
458 logger.info("Verifying %s routes on r2", addr_type)
459
460 step(
461 "On R2, static route installed in RIB using "
462 "show ip route with 8 next hop, lowest AD nexthop is active"
463 )
464 step("On R2, static route with lowest AD nexthop installed in FIB")
465 input_dict_4 = {
466 "r2": {
467 "static_routes": [
468 {
469 "network": PREFIX1[addr_type],
470 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
471 "admin_distance": 10,
472 }
473 ]
474 }
475 }
476 dut = "r2"
477 protocol = "static"
478 nh = NEXT_HOP_IP["nh1"][addr_type]
479 result = verify_rib(
480 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
481 )
482 assert result is True, (
483 "Testcase {} : Failed \nError: Route with "
484 " lowest AD is missing in RIB".format(tc_name)
485 )
486
487 nh = []
488 for nhp in range(2, 9):
489 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
490 result = verify_rib(
491 tgen,
492 addr_type,
493 dut,
494 input_dict_4,
495 next_hop=nh,
496 protocol=protocol,
497 fib=True,
498 expected=False,
499 )
500 assert result is not True, (
501 "Testcase {} : Failed \nError: Routes "
502 " with high AD are active in RIB".format(tc_name)
503 )
504
505 step("Configure redistribute static in BGP on R2 router")
506 for addr_type in ADDR_TYPES:
507 input_dict_2 = {
508 "r2": {
509 "bgp": {
510 "address_family": {
511 addr_type: {
512 "unicast": {"redistribute": [{"redist_type": "static"}]}
513 }
514 }
515 }
516 }
517 }
518
519 logger.info("Configuring redistribute static")
520 result = create_router_bgp(tgen, topo, input_dict_2)
521 assert result is True, "Testcase {} : Failed \n Error: {}".format(
522 tc_name, result
523 )
524
525 step(
526 "After configuring them, route is always active with lowest AD"
527 "value and all the nexthop populated in RIB and FIB again "
528 )
529 input_dict_4 = {
530 "r2": {
531 "static_routes": [
532 {
533 "network": PREFIX1[addr_type],
534 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
535 "admin_distance": 10,
536 }
537 ]
538 }
539 }
540 dut = "r2"
541 protocol = "static"
542 nh = NEXT_HOP_IP["nh1"][addr_type]
543 result = verify_rib(
544 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
545 )
546 assert result is True, (
547 "Testcase {} : Failed \nError: Route with "
548 " lowest AD is missing in RIB".format(tc_name)
549 )
550
551 step(
552 "Remove the static route configured with nexthop N1 to N8, one"
553 "by one from running config"
554 )
555
556 for addr_type in ADDR_TYPES:
557 # delete static routes
558 for nhp in range(1, 9):
559 input_dict_4 = {
560 "r2": {
561 "static_routes": [
562 {
563 "network": PREFIX1[addr_type],
564 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
565 "admin_distance": 10 * nhp,
566 "delete": True,
567 }
568 ]
569 }
570 }
571
572 logger.info("Configure static routes")
573 result = create_static_routes(tgen, input_dict_4)
574 assert result is True, "Testcase {} : Failed \n Error: {}".format(
575 tc_name, result
576 )
577
578 step(
579 "After removing the static route with N1 to N8 one by one, "
580 "route become active with next preferred nexthop and nexthop which "
581 "got removed is not shown in RIB and FIB"
582 )
583 result = verify_rib(
584 tgen,
585 addr_type,
586 dut,
587 input_dict_4,
588 next_hop=nh_all[addr_type],
589 protocol=protocol,
590 expected=False,
591 )
592 assert (
593 result is not True
594 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
595 tc_name
596 )
597
598 step("Configure the static route with nexthop N1 to N8, one by" "one")
599 for addr_type in ADDR_TYPES:
600 # add static routes
601 for nhp in range(1, 9):
602 input_dict_4 = {
603 "r2": {
604 "static_routes": [
605 {
606 "network": PREFIX1[addr_type],
607 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
608 "admin_distance": 10 * nhp,
609 }
610 ]
611 }
612 }
613 logger.info("Configure static routes")
614 result = create_static_routes(tgen, input_dict_4)
615 assert result is True, "Testcase {} : Failed \n Error: {}".format(
616 tc_name, result
617 )
618
619 step("On R2, static route with lowest AD nexthop installed in FIB")
620 input_dict_4 = {
621 "r2": {
622 "static_routes": [
623 {
624 "network": PREFIX1[addr_type],
625 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
626 "admin_distance": 10,
627 }
628 ]
629 }
630 }
631 dut = "r2"
632 protocol = "static"
633 nh = NEXT_HOP_IP["nh1"][addr_type]
634 result = verify_rib(
635 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
636 )
637 assert result is True, (
638 "Testcase {} : Failed \nError: Route with "
639 " lowest AD is missing in RIB".format(tc_name)
640 )
641
642 nh = []
643 for nhp in range(2, 9):
644 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
645 result = verify_rib(
646 tgen,
647 addr_type,
648 dut,
649 input_dict_4,
650 next_hop=nh,
651 protocol=protocol,
652 fib=True,
653 expected=False,
654 )
655 assert result is not True, (
656 "Testcase {} : Failed \nError: Routes "
657 " with high AD are active in RIB".format(tc_name)
658 )
659
660 step("Random shut of the nexthop interfaces")
661 randnum = random.randint(0, 7)
662 for addr_type in ADDR_TYPES:
663 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
664 shutdown_bringup_interface(tgen, dut, intf, False)
665 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
666 input_dict_5 = {
667 "r2": {
668 "static_routes": [
669 {
670 "network": PREFIX1[addr_type],
671 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
672 }
673 ]
674 }
675 }
676 result = verify_rib(
677 tgen,
678 addr_type,
679 dut,
680 input_dict_5,
681 next_hop=nhip,
682 protocol=protocol,
683 expected=False,
684 )
685 assert (
686 result is not True
687 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
688 tc_name
689 )
690
691 step("Random no shut of the nexthop interfaces")
692 for addr_type in ADDR_TYPES:
693 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
694 shutdown_bringup_interface(tgen, dut, intf, True)
695 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
696 result = verify_rib(
697 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
698 )
699 assert (
700 result is True
701 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
702
703 step("Reload the FRR router")
704 # stop/start -> restart FRR router and verify
705 stop_router(tgen, "r2")
706 start_router(tgen, "r2")
707
708 step(
709 "After reload of FRR router, static route installed "
710 "in RIB and FIB properly ."
711 )
712 for addr_type in ADDR_TYPES:
713 input_dict_4 = {
714 "r2": {
715 "static_routes": [
716 {
717 "network": PREFIX1[addr_type],
718 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
719 "admin_distance": 10,
720 }
721 ]
722 }
723 }
724 dut = "r2"
725 protocol = "static"
726 nh = NEXT_HOP_IP["nh1"][addr_type]
727 result = verify_rib(
728 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
729 )
730 assert result is True, (
731 "Testcase {} : Failed \nError: Route with "
732 " lowest AD is missing in RIB".format(tc_name)
733 )
734
735 nh = []
736 for nhp in range(2, 9):
737 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
738 result = verify_rib(
739 tgen,
740 addr_type,
741 dut,
742 input_dict_4,
743 next_hop=nh,
744 protocol=protocol,
745 fib=True,
746 expected=False,
747 )
748 assert result is not True, (
749 "Testcase {} : Failed \nError: Routes "
750 " with high AD are active in RIB".format(tc_name)
751 )
752
753 step("Remove the redistribute static knob")
754
755 for addr_type in ADDR_TYPES:
756 input_dict_2 = {
757 "r2": {
758 "bgp": {
759 "address_family": {
760 addr_type: {
761 "unicast": {
762 "redistribute": [
763 {"redist_type": "static", "delete": True}
764 ]
765 }
766 }
767 }
768 }
769 }
770 }
771
772 logger.info("Remove redistribute static")
773 result = create_router_bgp(tgen, topo, input_dict_2)
774 assert result is True, "Testcase {} : Failed \n Error: {}".format(
775 tc_name, result
776 )
777 step("verify that routes are deleted from R3 routing table")
778 dut = "r3"
779 protocol = "bgp"
780 result = verify_rib(
781 tgen,
782 addr_type,
783 dut,
784 input_dict_4,
785 next_hop=nh,
786 protocol=protocol,
787 expected=False,
788 )
789 assert result is not True, (
790 "Testcase {} : Failed \nError: Routes are"
791 " still present in RIB of R3".format(tc_name)
792 )
793
794 write_test_footer(tc_name)
795
796
797 def test_bgp_local_nexthop_p1_tc14_ibgp(request):
798 """
799 Verify BGP did not install the static route when it receive route
800 with local next hop
801
802 """
803 tc_name = request.node.name
804 write_test_header(tc_name)
805 tgen = get_topogen()
806
807 step("Configure BGP IPv4 session between R2 and R3")
808 step("Configure IPv4 static route on R2")
809 reset_config_on_routers(tgen)
810
811 for addr_type in ADDR_TYPES:
812 # Enable static routes
813 input_dict_4 = {
814 "r2": {
815 "static_routes": [
816 {
817 "network": NETWORK[addr_type],
818 "next_hop": topo["routers"]["r3"]["links"]["r2-link0"][
819 addr_type
820 ].split("/")[0],
821 }
822 ]
823 }
824 }
825
826 logger.info("Configure static routes")
827 result = create_static_routes(tgen, input_dict_4)
828 assert result is True, "Testcase {} : Failed \n Error: {}".format(
829 tc_name, result
830 )
831
832 step("Configure redistribute static in the BGP")
833
834 input_dict_2 = {
835 "r2": {
836 "bgp": {
837 "address_family": {
838 addr_type: {
839 "unicast": {"redistribute": [{"redist_type": "static"}]}
840 }
841 }
842 }
843 }
844 }
845 result = create_router_bgp(tgen, topo, input_dict_2)
846 assert result is True, "Testcase {} : Failed \n Error: {}".format(
847 tc_name, result
848 )
849
850 step("Verify R2 BGP table has IPv4 route")
851 dut = "r2"
852 result = verify_rib(tgen, addr_type, dut, input_dict_4)
853 assert (
854 result is True
855 ), "Testcase {} : Failed \nError: Routes is" " missing in RIB of R2".format(
856 tc_name
857 )
858
859 step(" Verify route did not install in the R3 BGP table, RIB/FIB")
860 dut = "r3"
861 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4, expected=False)
862 assert result is not True, (
863 "Testcase {} : Failed \nError: Routes is"
864 " still present in BGP RIB of R2".format(tc_name)
865 )
866
867 result = verify_rib(tgen, addr_type, dut, input_dict_4, expected=False)
868 assert result is not True, (
869 "Testcase {} : Failed \nError: Routes is"
870 " still present in RIB of R2".format(tc_name)
871 )
872
873 write_test_footer(tc_name)
874
875
876 if __name__ == "__main__":
877 args = ["-s"] + sys.argv[1:]
878 sys.exit(pytest.main(args))