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