]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/static_routing_with_ibgp/test_static_routes_topo4_ibgp.py
Merge pull request #8174 from mjstapp/backup_nht
[mirror_frr.git] / tests / topotests / static_routing_with_ibgp / test_static_routes_topo4_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 """
24
25 Following tests are covered in the script.
26
27 - Verify static route are blocked from route-map and prefix-list
28 applied in BGP nbrs
29 """
30
31 import sys
32 import json
33 import time
34 import os
35 import pytest
36 import platform
37 import ipaddress
38 from copy import deepcopy
39
40 # Save the Current Working Directory to find configuration files.
41 CWD = os.path.dirname(os.path.realpath(__file__))
42 sys.path.append(os.path.join(CWD, "../"))
43 sys.path.append(os.path.join(CWD, "../lib/"))
44 # pylint: disable=C0413
45 # Import topogen and topotest helpers
46 from mininet.topo import Topo
47 from lib.topogen import Topogen, get_topogen
48
49 from lib.common_config import (
50 start_topology,
51 write_test_header,
52 write_test_footer,
53 reset_config_on_routers,
54 verify_rib,
55 check_address_types,
56 step,
57 create_prefix_lists,
58 create_route_maps,
59 create_interfaces_cfg,
60 verify_prefix_lists,
61 verify_route_maps,
62 )
63 from lib.topolog import logger
64 from lib.bgp import (
65 verify_bgp_convergence,
66 create_router_bgp,
67 clear_bgp_and_verify,
68 clear_bgp,
69 )
70 from lib.topojson import build_topo_from_json, build_config_from_json
71 from lib.topotest import version_cmp
72
73 # Reading the data from JSON File for topology creation
74 jsonFile = "{}/static_routes_topo4_ibgp.json".format(CWD)
75 try:
76 with open(jsonFile, "r") as topoJson:
77 topo = json.load(topoJson)
78 except IOError:
79 assert False, "Could not read file {}".format(jsonFile)
80
81 # Global variables
82 BGP_CONVERGENCE = False
83 ADDR_TYPES = check_address_types()
84 NETWORK = {"ipv4": "2.2.2.2/32", "ipv6": "22:22::2/128"}
85 NEXT_HOP_IP = {}
86
87 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
88
89
90 class CreateTopo(Topo):
91 """
92 Test CreateTopo - topology 1.
93
94 * `Topo`: Topology object
95 """
96
97 def build(self, *_args, **_opts):
98 """Build function."""
99 tgen = get_topogen(self)
100
101 # Building topology from json file
102 build_topo_from_json(tgen, topo)
103
104
105 def setup_module(mod):
106 """
107 Set up the pytest environment.
108 * `mod`: module name
109 """
110 global topo
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...
118 tgen = Topogen(CreateTopo, mod.__name__)
119 # ... and here it calls Mininet initialization functions.
120
121 # Starting topology, create tmp files which are loaded to routers
122 # to start deamons and then start routers
123 start_topology(tgen)
124
125 # Creating configuration from JSON
126 build_config_from_json(tgen, topo)
127
128 if version_cmp(platform.release(), "4.19") < 0:
129 error_msg = (
130 'These tests will not run. (have kernel "{}", '
131 "requires kernel >= 4.19)".format(platform.release())
132 )
133 pytest.skip(error_msg)
134
135 # Checking BGP convergence
136 global BGP_CONVERGENCE
137 global ADDR_TYPES
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 BGP is converged
142 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
143 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
144 BGP_CONVERGENCE
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 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 #####################################################
170 #
171 # Tests starting
172 #
173 #####################################################
174 def test_static_routes_rmap_pfxlist_p0_tc7_ibgp(request):
175 """
176 Verify static route are blocked from route-map & prefix-list applied in BGP
177 nbrs
178
179 """
180 tc_name = request.node.name
181 write_test_header(tc_name)
182 tgen = get_topogen()
183 # Don't run this test if we have any failure.
184 if tgen.routers_have_failure():
185 pytest.skip(tgen.errors)
186 reset_config_on_routers(tgen)
187 step("Configure holddown timer = 1 keep alive = 3 in all the neighbors")
188 step("verify bgp convergence before starting test case")
189
190 bgp_convergence = verify_bgp_convergence(tgen, topo)
191 assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format(
192 tc_name, bgp_convergence
193 )
194
195 step(
196 "Configure 4 IPv4 and 4 IPv6 nbrs with password with mismatch "
197 " authentication between FRR routers "
198 )
199
200 for addr_type in ADDR_TYPES:
201 # Api call to modfiy BGP timerse
202 input_dict = {
203 "r2": {
204 "bgp": {
205 "local_as": "200",
206 "address_family": {
207 addr_type: {
208 "unicast": {
209 "neighbor": {
210 "r1": {
211 "dest_link": {
212 "r2-link0": {"password": "r2"},
213 "r2-link1": {"password": "r2"},
214 "r2-link2": {"password": "r2"},
215 "r2-link3": {"password": "r2"},
216 }
217 },
218 "r3": {
219 "dest_link": {
220 "r2-link0": {"password": "r2"},
221 "r2-link1": {"password": "r2"},
222 "r2-link2": {"password": "r2"},
223 "r2-link3": {"password": "r2"},
224 }
225 },
226 }
227 }
228 }
229 },
230 }
231 }
232 }
233 result = create_router_bgp(tgen, topo, deepcopy(input_dict))
234 assert result is True, "Testcase {} :Failed \n Error: {}".format(
235 tc_name, result
236 )
237 clear_bgp(tgen, addr_type, "r2")
238
239 step(" All BGP nbrs are down as authentication is mismatch on both" " the sides")
240
241 bgp_convergence = verify_bgp_convergence(tgen, topo, expected=False)
242 assert (
243 bgp_convergence is not True
244 ), "Testcase {} : " "Failed \n BGP nbrs must be down. Error: {}".format(
245 tc_name, bgp_convergence
246 )
247
248 step(
249 "Configure 4 IPv4 and 4 IPv6 nbrs with macthing password "
250 " authentication between FRR routers "
251 )
252 for addr_type in ADDR_TYPES:
253 input_dict = {
254 "r2": {
255 "bgp": {
256 "local_as": "200",
257 "address_family": {
258 addr_type: {
259 "unicast": {
260 "neighbor": {
261 "r1": {
262 "dest_link": {
263 "r2-link0": {"password": "r1"},
264 "r2-link1": {"password": "r1"},
265 "r2-link2": {"password": "r1"},
266 "r2-link3": {"password": "r1"},
267 }
268 },
269 "r3": {
270 "dest_link": {
271 "r2-link0": {"password": "r1"},
272 "r2-link1": {"password": "r1"},
273 "r2-link2": {"password": "r1"},
274 "r2-link3": {"password": "r1"},
275 }
276 },
277 }
278 }
279 }
280 },
281 }
282 }
283 }
284 result = create_router_bgp(tgen, topo, deepcopy(input_dict))
285 assert result is True, "Testcase {} :Failed \n Error: {}".format(
286 tc_name, result
287 )
288
289 step("All BGP nbrs are up as authentication is matched now")
290 bgp_convergence = verify_bgp_convergence(tgen, topo)
291 assert bgp_convergence is True, "Testcase {} : Failed \n " "Error: {}".format(
292 tc_name, bgp_convergence
293 )
294
295 step("Create prefix list P1 to permit VM3 & deny VM1 v4 & v6 routes")
296 step("Create prefix list P2 to permit VM6 IPv4 and IPv6 routes")
297 for addr_type in ADDR_TYPES:
298 input_dict_2 = {
299 "r2": {
300 "prefix_lists": {
301 addr_type: {
302 "pf_list_1_{}".format(addr_type): [
303 {
304 "seqid": 10,
305 "network": topo["routers"]["r2"]["links"]["vm3"][
306 addr_type
307 ],
308 "action": "permit",
309 },
310 {
311 "seqid": 20,
312 "network": topo["routers"]["r2"]["links"]["vm1"][
313 addr_type
314 ],
315 "action": "deny",
316 },
317 ],
318 "pf_list_2_{}".format(addr_type): [
319 {
320 "seqid": 10,
321 "network": topo["routers"]["r2"]["links"]["vm6"][
322 addr_type
323 ],
324 "action": "permit",
325 }
326 ],
327 }
328 }
329 }
330 }
331 result = create_prefix_lists(tgen, input_dict_2)
332 assert result is True, "Testcase {} : Failed \n Error: {}".format(
333 tc_name, result
334 )
335
336 step(
337 "Prefix list created with matching networks deny or permit "
338 "show ip prefix list"
339 )
340 result = verify_prefix_lists(tgen, input_dict_2)
341 assert result is not True, "Testcase {} : Failed \n" " Error: {}".format(
342 tc_name, result
343 )
344
345 step("Redistribute all the routes (connected, static)")
346 input_dict_2_r1 = {
347 "r1": {
348 "bgp": {
349 "address_family": {
350 addr_type: {
351 "unicast": {"redistribute": [{"redist_type": "static"}]}
352 }
353 }
354 }
355 }
356 }
357 result = create_router_bgp(tgen, topo, input_dict_2_r1)
358 assert result is True, "Testcase {} : Failed \n Error: {}".format(
359 tc_name, result
360 )
361
362 input_dict_2_r2 = {
363 "r2": {
364 "bgp": {
365 "address_family": {
366 addr_type: {
367 "unicast": {"redistribute": [{"redist_type": "static"}]}
368 }
369 }
370 }
371 }
372 }
373 result = create_router_bgp(tgen, topo, input_dict_2_r2)
374 assert result is True, "Testcase {} : Failed \n Error: {}".format(
375 tc_name, result
376 )
377
378 input_dict_2_r3 = {
379 "r3": {
380 "bgp": {
381 "address_family": {
382 addr_type: {
383 "unicast": {"redistribute": [{"redist_type": "static"}]}
384 }
385 }
386 }
387 }
388 }
389 result = create_router_bgp(tgen, topo, input_dict_2_r3)
390 assert result is True, "Testcase {} : Failed \n Error: {}".format(
391 tc_name, result
392 )
393
394 step("configure redistribute connected in Router BGP")
395
396 input_dict_2_r1 = {
397 "r1": {
398 "bgp": {
399 "address_family": {
400 addr_type: {
401 "unicast": {"redistribute": [{"redist_type": "connected"}]}
402 }
403 }
404 }
405 }
406 }
407 result = create_router_bgp(tgen, topo, input_dict_2_r1)
408 assert result is True, "Testcase {} : Failed \n Error: {}".format(
409 tc_name, result
410 )
411
412 input_dict_2_r3 = {
413 "r3": {
414 "bgp": {
415 "address_family": {
416 addr_type: {
417 "unicast": {"redistribute": [{"redist_type": "connected"}]}
418 }
419 }
420 }
421 }
422 }
423 result = create_router_bgp(tgen, topo, input_dict_2_r3)
424 assert result is True, "Testcase {} : Failed \n Error: {}".format(
425 tc_name, result
426 )
427
428 input_dict_2 = {
429 "r2": {
430 "bgp": {
431 "address_family": {
432 addr_type: {
433 "unicast": {"redistribute": [{"redist_type": "connected"}]}
434 }
435 }
436 }
437 }
438 }
439 result = create_router_bgp(tgen, topo, input_dict_2)
440 assert result is True, "Testcase {} : Failed \n Error: {}".format(
441 tc_name, result
442 )
443
444 step("Apply prefix list P1 on BGP neighbors 1 2 3 4 connected from " "frr r1")
445 # Configure prefix list to bgp neighbor
446 input_dict_4 = {
447 "r2": {
448 "bgp": {
449 "address_family": {
450 addr_type: {
451 "unicast": {
452 "neighbor": {
453 "r1": {
454 "dest_link": {
455 "r2-link0": {
456 "prefix_lists": [
457 {
458 "name": "pf_list_1_{}".format(
459 addr_type
460 ),
461 "direction": "out",
462 }
463 ]
464 },
465 "r2-link1": {
466 "prefix_lists": [
467 {
468 "name": "pf_list_1_{}".format(
469 addr_type
470 ),
471 "direction": "out",
472 }
473 ]
474 },
475 "r2-link2": {
476 "prefix_lists": [
477 {
478 "name": "pf_list_1_{}".format(
479 addr_type
480 ),
481 "direction": "out",
482 }
483 ]
484 },
485 "r2-link3": {
486 "prefix_lists": [
487 {
488 "name": "pf_list_1_{}".format(
489 addr_type
490 ),
491 "direction": "out",
492 }
493 ]
494 },
495 }
496 }
497 }
498 }
499 }
500 }
501 }
502 }
503 }
504 result = create_router_bgp(tgen, topo, input_dict_4)
505 assert result is True, "Testcase {} : Failed \n Error: {}".format(
506 tc_name, result
507 )
508
509 step("Apply prefix list P2 on BGP nbrs 5 & 6 connected from FRR-2")
510 # Configure prefix list to bgp neighbor
511 input_dict_4 = {
512 "r2": {
513 "bgp": {
514 "address_family": {
515 addr_type: {
516 "unicast": {
517 "neighbor": {
518 "r3": {
519 "dest_link": {
520 "r2-link0": {
521 "prefix_lists": [
522 {
523 "name": "pf_list_2_{}".format(
524 addr_type
525 ),
526 "direction": "out",
527 }
528 ]
529 },
530 "r2-link1": {
531 "prefix_lists": [
532 {
533 "name": "pf_list_2_{}".format(
534 addr_type
535 ),
536 "direction": "out",
537 }
538 ]
539 },
540 "r2-link2": {
541 "prefix_lists": [
542 {
543 "name": "pf_list_2_{}".format(
544 addr_type
545 ),
546 "direction": "out",
547 }
548 ]
549 },
550 "r2-link3": {
551 "prefix_lists": [
552 {
553 "name": "pf_list_2_{}".format(
554 addr_type
555 ),
556 "direction": "out",
557 }
558 ]
559 },
560 }
561 }
562 }
563 }
564 }
565 }
566 }
567 }
568 }
569 result = create_router_bgp(tgen, topo, input_dict_4)
570 assert result is True, "Testcase {} : Failed \n Error: {}".format(
571 tc_name, result
572 )
573
574 clear_bgp_and_verify(tgen, topo, "r2")
575
576 step(
577 "VM1 IPv4 and IPv6 Route which is denied using prefix list is "
578 "not present on FRR1 side routing table , also not able to "
579 "ping the routes show ip route"
580 )
581
582 dut = "r1"
583 protocol = "bgp"
584 ntwk_r2_vm1 = str(
585 ipaddress.ip_interface(
586 u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
587 ).network
588 )
589 input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
590 result4 = verify_rib(
591 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
592 )
593 assert result4 is not True, (
594 "Testcase {} : Failed , VM1 route is "
595 "not filtered out via prefix list. \n Error: {}".format(tc_name, result4)
596 )
597
598 step(
599 "VM4 and VM6 IPV4 and IPv6 address are present in local and "
600 "FRR2 routing table show ip bgp show ip route"
601 )
602
603 dut = "r2"
604 ntwk_r2_vm6 = str(
605 ipaddress.ip_interface(
606 u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
607 ).network
608 )
609 input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}}
610 result4 = verify_rib(tgen, addr_type, dut, input_dict)
611 assert result4 is True, "Testcase {} : Failed.\n Error: {}".format(
612 tc_name, result4
613 )
614
615 step("Remove prefix list from all the neighbors")
616 input_dict_4 = {
617 "r2": {
618 "bgp": {
619 "address_family": {
620 addr_type: {
621 "unicast": {
622 "neighbor": {
623 "r1": {
624 "dest_link": {
625 "r2-link0": {
626 "prefix_lists": [
627 {
628 "name": "pf_list_1_{}".format(
629 addr_type
630 ),
631 "direction": "out",
632 "delete": True,
633 }
634 ]
635 },
636 "r2-link1": {
637 "prefix_lists": [
638 {
639 "name": "pf_list_1_{}".format(
640 addr_type
641 ),
642 "direction": "out",
643 "delete": True,
644 }
645 ]
646 },
647 "r2-link2": {
648 "prefix_lists": [
649 {
650 "name": "pf_list_1_{}".format(
651 addr_type
652 ),
653 "direction": "out",
654 "delete": True,
655 }
656 ]
657 },
658 "r2-link3": {
659 "prefix_lists": [
660 {
661 "name": "pf_list_1_{}".format(
662 addr_type
663 ),
664 "direction": "out",
665 "delete": True,
666 }
667 ]
668 },
669 }
670 }
671 }
672 }
673 }
674 }
675 }
676 }
677 }
678 result = create_router_bgp(tgen, topo, input_dict_4)
679 assert result is True, "Testcase {} : Failed \n Error: {}".format(
680 tc_name, result
681 )
682
683 input_dict_4 = {
684 "r2": {
685 "bgp": {
686 "address_family": {
687 addr_type: {
688 "unicast": {
689 "neighbor": {
690 "r3": {
691 "dest_link": {
692 "r2-link0": {
693 "prefix_lists": [
694 {
695 "name": "pf_list_2_{}".format(
696 addr_type
697 ),
698 "direction": "out",
699 "delete": True,
700 }
701 ]
702 },
703 "r2-link1": {
704 "prefix_lists": [
705 {
706 "name": "pf_list_2_{}".format(
707 addr_type
708 ),
709 "direction": "out",
710 "delete": True,
711 }
712 ]
713 },
714 "r2-link2": {
715 "prefix_lists": [
716 {
717 "name": "pf_list_2_{}".format(
718 addr_type
719 ),
720 "direction": "out",
721 "delete": True,
722 }
723 ]
724 },
725 "r2-link3": {
726 "prefix_lists": [
727 {
728 "name": "pf_list_2_{}".format(
729 addr_type
730 ),
731 "direction": "out",
732 "delete": True,
733 }
734 ]
735 },
736 }
737 }
738 }
739 }
740 }
741 }
742 }
743 }
744 }
745 result = create_router_bgp(tgen, topo, input_dict_4)
746 assert result is True, "Testcase {} : Failed \n Error: {}".format(
747 tc_name, result
748 )
749
750 clear_bgp_and_verify(tgen, topo, "r2")
751
752 step("Create RouteMap_1 with prefix list P1 and weight 50")
753 # Create route map
754 rmap_dict = {
755 "r2": {
756 "route_maps": {
757 "rmap_pf_list_1_{}".format(addr_type): [
758 {
759 "action": "permit",
760 "set": {"weight": 50},
761 "match": {
762 addr_type: {
763 "prefix_lists": "pf_list_1_{}".format(addr_type)
764 }
765 },
766 }
767 ]
768 }
769 }
770 }
771 result = create_route_maps(tgen, rmap_dict)
772 assert result is True, "Testcase {} : Failed \n Error: {}".format(
773 tc_name, result
774 )
775
776 step("Create RouteMap_2 with prefix list P2 and weight 50")
777 # Create route map
778 rmap_dict = {
779 "r2": {
780 "route_maps": {
781 "rmap_pf_list_2_{}".format(addr_type): [
782 {
783 "action": "permit",
784 "set": {"weight": 50},
785 "match": {
786 addr_type: {
787 "prefix_lists": "pf_list_2_{}".format(addr_type)
788 }
789 },
790 }
791 ]
792 }
793 }
794 }
795 result = create_route_maps(tgen, rmap_dict)
796 assert result is True, "Testcase {} : Failed \n Error: {}".format(
797 tc_name, result
798 )
799
800 step("Verify Route-map created verify using show route-map")
801 # verify rmap_pf_list_1 and rmap_pf_list_2 are present in router r2
802 input_dict = {
803 "r2": {
804 "route_maps": [
805 "rmap_pf_list_1_{}".format(addr_type),
806 "rmap_pf_list_2_{}".format(addr_type),
807 ]
808 }
809 }
810 result = verify_route_maps(tgen, input_dict, expected=False)
811 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
812 tc_name, result
813 )
814
815 step("Apply policy RouteMap_1 nbrs 1 2 3 4 to FRR 1")
816 # Configure prefix list to bgp neighbor
817 input_dict_4 = {
818 "r2": {
819 "bgp": {
820 "address_family": {
821 addr_type: {
822 "unicast": {
823 "neighbor": {
824 "r1": {
825 "dest_link": {
826 "r2-link0": {
827 "route_maps": [
828 {
829 "name": "rmap_pf_list_1_"
830 "{}".format(addr_type),
831 "direction": "out",
832 }
833 ]
834 },
835 "r2-link1": {
836 "route_maps": [
837 {
838 "name": "rmap_pf_list_1_"
839 "{}".format(addr_type),
840 "direction": "out",
841 }
842 ]
843 },
844 "r2-link2": {
845 "route_maps": [
846 {
847 "name": "rmap_pf_list_1_"
848 "{}".format(addr_type),
849 "direction": "out",
850 }
851 ]
852 },
853 "r2-link3": {
854 "route_maps": [
855 {
856 "name": "rmap_pf_list_1_"
857 "{}".format(addr_type),
858 "direction": "out",
859 }
860 ]
861 },
862 }
863 }
864 }
865 }
866 }
867 }
868 }
869 }
870 }
871 result = create_router_bgp(tgen, topo, input_dict_4)
872 assert result is True, "Testcase {} : Failed \n Error: {}".format(
873 tc_name, result
874 )
875
876 step("Apply policy RouteMap_2 nbrs 5 and 6 to FRR2")
877 # Configure prefix list to bgp neighbor
878 input_dict_4 = {
879 "r2": {
880 "bgp": {
881 "address_family": {
882 addr_type: {
883 "unicast": {
884 "neighbor": {
885 "r3": {
886 "dest_link": {
887 "r2-link0": {
888 "route_maps": [
889 {
890 "name": "rmap_pf_list_2_"
891 "{}".format(addr_type),
892 "direction": "out",
893 }
894 ]
895 },
896 "r2-link1": {
897 "route_maps": [
898 {
899 "name": "rmap_pf_list_2_"
900 "{}".format(addr_type),
901 "direction": "out",
902 }
903 ]
904 },
905 "r2-link2": {
906 "route_maps": [
907 {
908 "name": "rmap_pf_list_2_"
909 "{}".format(addr_type),
910 "direction": "out",
911 }
912 ]
913 },
914 "r2-link3": {
915 "route_maps": [
916 {
917 "name": "rmap_pf_list_2_"
918 "{}".format(addr_type),
919 "direction": "out",
920 }
921 ]
922 },
923 }
924 }
925 }
926 }
927 }
928 }
929 }
930 }
931 }
932 result = create_router_bgp(tgen, topo, input_dict_4)
933 assert result is True, "Testcase {} : Failed \n Error: {}".format(
934 tc_name, result
935 )
936
937 step(
938 "After applying to BGP neighbors verify VM1 IPv4 and IPv6 Route"
939 " which is denied using prefix list is not present on FRR side"
940 " routing table , also not able to ping the routes show ip route"
941 " and VM4 and VM6 IPV4 and IPv6 address are present in local and"
942 " FRR routing table show ip bgp show ip route"
943 )
944
945 dut = "r1"
946 protocol = "bgp"
947 ntwk_r2_vm1 = str(
948 ipaddress.ip_interface(
949 u"{}".format(topo["routers"]["r2"]["links"]["vm1"][addr_type])
950 ).network
951 )
952 input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
953 result4 = verify_rib(
954 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
955 )
956 assert (
957 result4 is not True
958 ), "Testcase {} : Failed \n" "routes are still present \n Error: {}".format(
959 tc_name, result4
960 )
961
962 step("vm4 should be present in FRR1")
963 dut = "r1"
964 ntwk_r2_vm1 = str(
965 ipaddress.ip_interface(
966 u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
967 ).network
968 )
969 input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
970 result4 = verify_rib(tgen, addr_type, dut, input_dict)
971 assert result4 is True, (
972 "Testcase {} : Failed , VM1 route is "
973 "not filtered out via prefix list. \n Error: {}".format(tc_name, result4)
974 )
975
976 step("vm4 should be present in FRR2")
977 dut = "r2"
978 ntwk_r2_vm1 = str(
979 ipaddress.ip_interface(
980 u"{}".format(topo["routers"]["r1"]["links"]["vm4"][addr_type])
981 ).network
982 )
983 input_dict = {"r1": {"static_routes": [{"network": ntwk_r2_vm1}]}}
984 result4 = verify_rib(tgen, addr_type, dut, input_dict)
985 assert result4 is True, (
986 "Testcase {} : Failed , VM1 route is "
987 "not filtered out via prefix list. \n Error: {}".format(tc_name, result4)
988 )
989
990 dut = "r3"
991 protocol = "bgp"
992 ntwk_r2_vm6 = str(
993 ipaddress.ip_interface(
994 u"{}".format(topo["routers"]["r2"]["links"]["vm6"][addr_type])
995 ).network
996 )
997 input_dict = {"r3": {"static_routes": [{"network": ntwk_r2_vm6}]}}
998 result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
999 assert result4 is True, "Testcase {} : Failed.\n Error: {}".format(
1000 tc_name, result4
1001 )
1002
1003 write_test_footer(tc_name)
1004
1005
1006 if __name__ == "__main__":
1007 args = ["-s"] + sys.argv[1:]
1008 sys.exit(pytest.main(args))