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