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