]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_prefix_list_topo1/test_prefix_lists.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_prefix_list_topo1 / test_prefix_lists.py
1 #!/usr/bin/python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # Copyright (c) 2019 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation,
7 # Inc. ("NetDEF") in this file.
8 #
9
10 """
11 Following tests are covered to test prefix-list functionality:
12
13 Test steps
14 - Create topology (setup module)
15 Creating 4 routers topology, r1, r2, r3 are in IBGP and
16 r3, r4 are in EBGP
17 - Bring up topology
18 - Verify for bgp to converge
19
20 IP prefix-list tests
21 - Test ip prefix-lists IN permit
22 - Test ip prefix-lists OUT permit
23 - Test ip prefix-lists IN deny and permit any
24 - Test delete ip prefix-lists
25 - Test ip prefix-lists OUT deny and permit any
26 - Test modify ip prefix-lists IN permit to deny
27 - Test modify ip prefix-lists IN deny to permit
28 - Test modify ip prefix-lists OUT permit to deny
29 - Test modify prefix-lists OUT deny to permit
30 - Test ip prefix-lists implicit deny
31 """
32
33 import sys
34 import time
35 import os
36 import pytest
37
38 # Save the Current Working Directory to find configuration files.
39 CWD = os.path.dirname(os.path.realpath(__file__))
40 sys.path.append(os.path.join(CWD, "../"))
41
42 # pylint: disable=C0413
43 # Import topogen and topotest helpers
44 from lib.topogen import Topogen, get_topogen
45
46 # Import topoJson from lib, to create topology and initial configuration
47 from lib.common_config import (
48 start_topology,
49 write_test_header,
50 write_test_footer,
51 reset_config_on_routers,
52 verify_rib,
53 create_static_routes,
54 create_prefix_lists,
55 verify_prefix_lists,
56 )
57 from lib.topolog import logger
58 from lib.bgp import verify_bgp_convergence, create_router_bgp, clear_bgp_and_verify
59 from lib.topojson import build_config_from_json
60
61
62 pytestmark = [pytest.mark.bgpd]
63
64
65 # Global variables
66 bgp_convergence = False
67
68
69 def setup_module(mod):
70 """
71 Sets up the pytest environment
72
73 * `mod`: module name
74 """
75
76 testsuite_run_time = time.asctime(time.localtime(time.time()))
77 logger.info("Testsuite start time: {}".format(testsuite_run_time))
78 logger.info("=" * 40)
79
80 logger.info("Running setup_module to create topology")
81
82 # This function initiates the topology build with Topogen...
83 json_file = "{}/prefix_lists.json".format(CWD)
84 tgen = Topogen(json_file, mod.__name__)
85 global topo
86 topo = tgen.json_topo
87 # ... and here it calls Mininet initialization functions.
88
89 # Starting topology, create tmp files which are loaded to routers
90 # to start daemons and then start routers
91 start_topology(tgen)
92
93 # Creating configuration from JSON
94 build_config_from_json(tgen, topo)
95
96 # Checking BGP convergence
97 global BGP_CONVERGENCE
98
99 # Don't run this test if we have any failure.
100 if tgen.routers_have_failure():
101 pytest.skip(tgen.errors)
102
103 # Api call verify whether BGP is converged
104 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
105 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
106 BGP_CONVERGENCE
107 )
108
109 logger.info("Running setup_module() done")
110
111
112 def teardown_module(mod):
113 """
114 Teardown the pytest environment
115
116 * `mod`: module name
117 """
118
119 logger.info("Running teardown_module to delete topology")
120
121 tgen = get_topogen()
122
123 # Stop toplogy and Remove tmp files
124 tgen.stop_topology()
125
126 logger.info(
127 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
128 )
129 logger.info("=" * 40)
130
131
132 #####################################################
133 #
134 # Tests starting
135 #
136 #####################################################
137
138
139 def test_ip_prefix_lists_in_permit(request):
140 """
141 Create ip prefix list and test permit prefixes IN direction
142 """
143
144 tgen = get_topogen()
145 if BGP_CONVERGENCE is not True:
146 pytest.skip("skipped because of BGP Convergence failure")
147
148 # test case name
149 tc_name = request.node.name
150 write_test_header(tc_name)
151
152 # Create Static routes
153 input_dict = {
154 "r1": {
155 "static_routes": [
156 {"network": "20.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"}
157 ]
158 }
159 }
160 result = create_static_routes(tgen, input_dict)
161 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
162
163 # Create ip prefix list
164 input_dict_2 = {
165 "r3": {
166 "prefix_lists": {
167 "ipv4": {
168 "pf_list_1": [{"seqid": 10, "network": "any", "action": "permit"}]
169 }
170 }
171 }
172 }
173 result = create_prefix_lists(tgen, input_dict_2)
174 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
175
176 # Configure bgp neighbor with prefix list
177 input_dict_3 = {
178 "r1": {
179 "bgp": {
180 "address_family": {
181 "ipv4": {
182 "unicast": {
183 "redistribute": [
184 {"redist_type": "static"},
185 {"redist_type": "connected"},
186 ]
187 }
188 }
189 }
190 }
191 },
192 "r3": {
193 "bgp": {
194 "address_family": {
195 "ipv4": {
196 "unicast": {
197 "neighbor": {
198 "r1": {
199 "dest_link": {
200 "r3": {
201 "prefix_lists": [
202 {"name": "pf_list_1", "direction": "in"}
203 ]
204 }
205 }
206 }
207 }
208 }
209 }
210 }
211 }
212 },
213 }
214 result = create_router_bgp(tgen, topo, input_dict_3)
215 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
216
217 # Verifying RIB routes
218 dut = "r3"
219 protocol = "bgp"
220 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
221 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
222
223 write_test_footer(tc_name)
224
225
226 def test_ip_prefix_lists_out_permit(request):
227 """
228 Create ip prefix list and test permit prefixes out direction
229 """
230
231 tgen = get_topogen()
232 if BGP_CONVERGENCE is not True:
233 pytest.skip("skipped because of BGP Convergence failure")
234
235 # test case name
236 tc_name = request.node.name
237 write_test_header(tc_name)
238
239 # Creating configuration from JSON
240 reset_config_on_routers(tgen)
241
242 # Create Static routes
243 input_dict = {
244 "r1": {
245 "static_routes": [
246 {"network": "10.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"}
247 ]
248 }
249 }
250 result = create_static_routes(tgen, input_dict)
251 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
252
253 # Create Static routes
254 input_dict_1 = {
255 "r1": {
256 "static_routes": [
257 {"network": "20.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"}
258 ]
259 }
260 }
261 result = create_static_routes(tgen, input_dict_1)
262 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
263
264 input_dict_5 = {
265 "r3": {
266 "static_routes": [
267 {"network": "10.0.0.2/30", "no_of_ip": 1, "next_hop": "10.0.0.9"}
268 ]
269 }
270 }
271 result = create_static_routes(tgen, input_dict_5)
272 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
273
274 # Api call to redistribute static routes
275
276 # Create ip prefix list
277 input_dict_2 = {
278 "r1": {
279 "prefix_lists": {
280 "ipv4": {
281 "pf_list_1": [
282 {"seqid": 10, "network": "20.0.20.1/32", "action": "permit"}
283 ]
284 }
285 }
286 }
287 }
288 result = create_prefix_lists(tgen, input_dict_2)
289 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
290
291 # Configure prefix list to bgp neighbor
292 # Configure bgp neighbor with prefix list
293 input_dict_3 = {
294 "r1": {
295 "bgp": {
296 "address_family": {
297 "ipv4": {
298 "unicast": {
299 "neighbor": {
300 "r3": {
301 "dest_link": {
302 "r1": {
303 "prefix_lists": [
304 {
305 "name": "pf_list_1",
306 "direction": "out",
307 }
308 ]
309 }
310 }
311 }
312 },
313 "redistribute": [
314 {"redist_type": "static"},
315 {"redist_type": "connected"},
316 ],
317 }
318 }
319 }
320 }
321 }
322 }
323
324 result = create_router_bgp(tgen, topo, input_dict_3)
325 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
326
327 # Verifying RIB routes
328 dut = "r3"
329 protocol = "bgp"
330 result = verify_rib(tgen, "ipv4", dut, input_dict_1, protocol=protocol)
331 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
332
333 result = verify_rib(
334 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
335 )
336 assert result is not True, (
337 "Testcase {} : Failed \n "
338 "Expected: Routes should not be present in {} FIB \n "
339 "Found: {}".format(tc_name, dut, result)
340 )
341
342 write_test_footer(tc_name)
343
344
345 def test_ip_prefix_lists_in_deny_and_permit_any(request):
346 """
347 Create ip prefix list and test permit/deny prefixes IN direction
348 """
349
350 tgen = get_topogen()
351 if BGP_CONVERGENCE is not True:
352 pytest.skip("skipped because of BGP Convergence failure")
353
354 # test case name
355 tc_name = request.node.name
356 write_test_header(tc_name)
357
358 # Creating configuration from JSON
359 reset_config_on_routers(tgen)
360
361 # Create Static Routes
362 input_dict = {
363 "r1": {
364 "static_routes": [
365 {"network": "10.0.20.1/32", "no_of_ip": 1, "next_hop": "10.0.0.2"}
366 ]
367 }
368 }
369 result = create_static_routes(tgen, input_dict)
370 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
371
372 # Api call to redistribute static routes
373 # Create ip prefix list
374 input_dict_2 = {
375 "r1": {
376 "prefix_lists": {
377 "ipv4": {
378 "pf_list_1": [
379 {"seqid": "10", "network": "10.0.20.1/32", "action": "deny"},
380 {"seqid": "11", "network": "any", "action": "permit"},
381 ]
382 }
383 }
384 }
385 }
386 result = create_prefix_lists(tgen, input_dict_2)
387 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
388
389 # Configure bgp neighbor with prefix list
390 input_dict_3 = {
391 "r1": {
392 "bgp": {
393 "address_family": {
394 "ipv4": {
395 "unicast": {
396 "redistribute": [
397 {"redist_type": "static"},
398 {"redist_type": "connected"},
399 ]
400 }
401 }
402 }
403 }
404 },
405 "r3": {
406 "bgp": {
407 "address_family": {
408 "ipv4": {
409 "unicast": {
410 "neighbor": {
411 "r1": {
412 "dest_link": {
413 "r3": {
414 "prefix_lists": [
415 {"name": "pf_list_1", "direction": "in"}
416 ]
417 }
418 }
419 }
420 }
421 }
422 }
423 }
424 }
425 },
426 }
427 # Configure prefix list to bgp neighbor
428 result = create_router_bgp(tgen, topo, input_dict_3)
429 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
430
431 # Verifying RIB routes
432 dut = "r3"
433 protocol = "bgp"
434 result = verify_rib(
435 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
436 )
437 assert result is not True, (
438 "Testcase {} : Failed \n "
439 "Expected: Routes should not be present in {} BGP RIB \n "
440 "Found: {}".format(tc_name, dut, result)
441 )
442
443 write_test_footer(tc_name)
444
445
446 def test_delete_prefix_lists(request):
447 """
448 Delete ip prefix list
449 """
450
451 tgen = get_topogen()
452 if BGP_CONVERGENCE is not True:
453 pytest.skip("skipped because of BGP Convergence failure")
454
455 # test case name
456 tc_name = request.node.name
457 write_test_header(tc_name)
458
459 # Creating configuration from JSON
460 reset_config_on_routers(tgen)
461
462 # Create ip prefix list
463 input_dict_2 = {
464 "r1": {
465 "prefix_lists": {
466 "ipv4": {
467 "pf_list_1": [
468 {"seqid": "10", "network": "10.0.20.1/32", "action": "deny"}
469 ]
470 }
471 }
472 }
473 }
474 result = create_prefix_lists(tgen, input_dict_2)
475 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
476
477 result = verify_prefix_lists(tgen, input_dict_2)
478 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
479 tc_name, result
480 )
481
482 # Delete prefix list
483 input_dict_2 = {
484 "r1": {
485 "prefix_lists": {
486 "ipv4": {
487 "pf_list_1": [
488 {
489 "seqid": "10",
490 "network": "10.0.20.1/32",
491 "action": "deny",
492 "delete": True,
493 }
494 ]
495 }
496 }
497 }
498 }
499 result = create_prefix_lists(tgen, input_dict_2)
500 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
501
502 result = verify_prefix_lists(tgen, input_dict_2)
503 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
504
505 write_test_footer(tc_name)
506
507
508 def test_ip_prefix_lists_out_deny_and_permit_any(request):
509 """
510 Create ip prefix list and test deny/permit any prefixes OUT direction
511 """
512
513 tgen = get_topogen()
514 if BGP_CONVERGENCE is not True:
515 pytest.skip("skipped because of BGP Convergence failure")
516
517 # test case name
518 tc_name = request.node.name
519 write_test_header(tc_name)
520
521 # Creating configuration from JSON
522 reset_config_on_routers(tgen)
523
524 # Create Static Routes
525 input_dict = {
526 "r1": {
527 "static_routes": [
528 {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"}
529 ]
530 }
531 }
532 result = create_static_routes(tgen, input_dict)
533 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
534
535 # Create Static Routes
536 input_dict_1 = {
537 "r2": {
538 "static_routes": [
539 {"network": "20.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.1"}
540 ]
541 }
542 }
543 result = create_static_routes(tgen, input_dict_1)
544 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
545
546 # Api call to redistribute static routes
547
548 # Create ip prefix list
549 input_dict_3 = {
550 "r3": {
551 "prefix_lists": {
552 "ipv4": {
553 "pf_list_1": [
554 {
555 "seqid": "10",
556 "network": "10.0.0.0/8",
557 "le": "32",
558 "action": "deny",
559 },
560 {"seqid": "11", "network": "any", "action": "permit"},
561 ]
562 }
563 }
564 }
565 }
566 result = create_prefix_lists(tgen, input_dict_3)
567 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
568
569 # Configure prefix list to bgp neighbor
570 input_dict_4 = {
571 "r1": {
572 "bgp": {
573 "address_family": {
574 "ipv4": {
575 "unicast": {
576 "redistribute": [
577 {"redist_type": "static"},
578 {"redist_type": "connected"},
579 ]
580 }
581 }
582 }
583 }
584 },
585 "r2": {
586 "bgp": {
587 "address_family": {
588 "ipv4": {
589 "unicast": {
590 "redistribute": [
591 {"redist_type": "static"},
592 {"redist_type": "connected"},
593 ]
594 }
595 }
596 }
597 }
598 },
599 "r3": {
600 "bgp": {
601 "address_family": {
602 "ipv4": {
603 "unicast": {
604 "neighbor": {
605 "r4": {
606 "dest_link": {
607 "r3": {
608 "prefix_lists": [
609 {
610 "name": "pf_list_1",
611 "direction": "out",
612 }
613 ]
614 }
615 }
616 }
617 }
618 }
619 }
620 }
621 }
622 },
623 }
624 result = create_router_bgp(tgen, topo, input_dict_4)
625 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
626
627 # Verifying RIB routes
628 dut = "r4"
629 protocol = "bgp"
630 result = verify_rib(tgen, "ipv4", dut, input_dict_1, protocol=protocol)
631 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
632
633 # Verifying RIB routes
634 dut = "r4"
635 protocol = "bgp"
636 result = verify_rib(
637 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
638 )
639 assert result is not True, (
640 "Testcase {} : Failed \n "
641 "Expected: Routes should not be present in {} BGP RIB \n "
642 "Found: {}".format(tc_name, dut, result)
643 )
644
645 write_test_footer(tc_name)
646
647
648 def test_modify_prefix_lists_in_permit_to_deny(request):
649 """
650 Modify ip prefix list and test permit to deny prefixes IN direction
651 """
652
653 tgen = get_topogen()
654 if BGP_CONVERGENCE is not True:
655 pytest.skip("skipped because of BGP Convergence failure")
656
657 # test case name
658 tc_name = request.node.name
659 write_test_header(tc_name)
660
661 # Creating configuration from JSON
662 reset_config_on_routers(tgen)
663
664 # Create Static Routes
665 input_dict = {
666 "r1": {
667 "static_routes": [
668 {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"}
669 ]
670 }
671 }
672 result = create_static_routes(tgen, input_dict)
673 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
674
675 # Api call to redistribute static routes
676
677 # Create ip prefix list
678 input_dict_2 = {
679 "r3": {
680 "prefix_lists": {
681 "ipv4": {
682 "pf_list_1": [
683 {
684 "seqid": "10",
685 "network": "10.0.0.0/8",
686 "le": "32",
687 "action": "permit",
688 }
689 ]
690 }
691 }
692 }
693 }
694 result = create_prefix_lists(tgen, input_dict_2)
695 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
696
697 # Configure prefix list to bgp neighbor
698 input_dict_3 = {
699 "r1": {
700 "bgp": {
701 "address_family": {
702 "ipv4": {
703 "unicast": {
704 "redistribute": [
705 {"redist_type": "static"},
706 {"redist_type": "connected"},
707 ]
708 }
709 }
710 }
711 }
712 },
713 "r3": {
714 "bgp": {
715 "address_family": {
716 "ipv4": {
717 "unicast": {
718 "neighbor": {
719 "r1": {
720 "dest_link": {
721 "r3": {
722 "prefix_lists": [
723 {"name": "pf_list_1", "direction": "in"}
724 ]
725 }
726 }
727 }
728 }
729 }
730 }
731 }
732 }
733 },
734 }
735 result = create_router_bgp(tgen, topo, input_dict_3)
736 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
737
738 # Verifying RIB routes
739 dut = "r3"
740 protocol = "bgp"
741 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
742 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
743
744 # Modify prefix list
745 input_dict_1 = {
746 "r3": {
747 "prefix_lists": {
748 "ipv4": {
749 "pf_list_1": [
750 {
751 "seqid": "10",
752 "network": "10.0.0.0/8",
753 "le": "32",
754 "action": "deny",
755 },
756 {"seqid": "11", "network": "any", "action": "permit"},
757 ]
758 }
759 }
760 }
761 }
762 result = create_prefix_lists(tgen, input_dict_1)
763 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
764
765 # Api call to clear bgp, so config changes would be reflected
766 dut = "r3"
767 result = clear_bgp_and_verify(tgen, topo, dut)
768 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
769
770 # Verifying RIB routes
771 dut = "r3"
772 protocol = "bgp"
773 result = verify_rib(
774 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
775 )
776 assert result is not True, (
777 "Testcase {} : Failed \n "
778 "Expected: Routes should not be present in {} BGP RIB \n "
779 "Found: {}".format(tc_name, dut, result)
780 )
781
782 write_test_footer(tc_name)
783
784
785 def test_modify_prefix_lists_in_deny_to_permit(request):
786 """
787 Modify ip prefix list and test deny to permit prefixes IN direction
788 """
789
790 tgen = get_topogen()
791 if BGP_CONVERGENCE is not True:
792 pytest.skip("skipped because of BGP Convergence failure")
793
794 # test case name
795 tc_name = request.node.name
796 write_test_header(tc_name)
797
798 # Creating configuration from JSON
799 reset_config_on_routers(tgen)
800
801 # Create Static Routes
802 input_dict = {
803 "r1": {
804 "static_routes": [
805 {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"}
806 ]
807 }
808 }
809 result = create_static_routes(tgen, input_dict)
810 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
811
812 # Api call to redistribute static routes
813
814 # Create ip prefix list
815 input_dict_1 = {
816 "r3": {
817 "prefix_lists": {
818 "ipv4": {
819 "pf_list_1": [
820 {
821 "seqid": "10",
822 "network": "10.0.0.0/8",
823 "le": "32",
824 "action": "deny",
825 },
826 {"seqid": "11", "network": "any", "action": "permit"},
827 ]
828 }
829 }
830 }
831 }
832 result = create_prefix_lists(tgen, input_dict_1)
833 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
834
835 # Configure prefix list to bgp neighbor
836 input_dict_2 = {
837 "r1": {
838 "bgp": {
839 "address_family": {
840 "ipv4": {
841 "unicast": {
842 "redistribute": [
843 {"redist_type": "static"},
844 {"redist_type": "connected"},
845 ]
846 }
847 }
848 }
849 }
850 },
851 "r3": {
852 "bgp": {
853 "address_family": {
854 "ipv4": {
855 "unicast": {
856 "neighbor": {
857 "r1": {
858 "dest_link": {
859 "r3": {
860 "prefix_lists": [
861 {"name": "pf_list_1", "direction": "in"}
862 ]
863 }
864 }
865 }
866 }
867 }
868 }
869 }
870 }
871 },
872 }
873 result = create_router_bgp(tgen, topo, input_dict_2)
874 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
875
876 # Verifying RIB routes
877 dut = "r3"
878 protocol = "bgp"
879 result = verify_rib(
880 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
881 )
882 assert result is not True, (
883 "Testcase {} : Failed \n "
884 "Expected: Routes should not be present in {} BGP RIB \n "
885 "Found: {}".format(tc_name, dut, result)
886 )
887
888 # Modify ip prefix list
889 input_dict_1 = {
890 "r3": {
891 "prefix_lists": {
892 "ipv4": {
893 "pf_list_1": [
894 {
895 "seqid": "10",
896 "network": "10.0.0.0/8",
897 "le": "32",
898 "action": "permit",
899 }
900 ]
901 }
902 }
903 }
904 }
905 result = create_prefix_lists(tgen, input_dict_1)
906 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
907
908 # Api call to clear bgp, so config changes would be reflected
909 dut = "r3"
910 result = clear_bgp_and_verify(tgen, topo, dut)
911 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
912
913 # Verifying RIB routes
914 dut = "r3"
915 protocol = "bgp"
916 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
917 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
918
919 write_test_footer(tc_name)
920
921
922 def test_modify_prefix_lists_out_permit_to_deny(request):
923 """
924 Modify ip prefix list and test permit to deny prefixes OUT direction
925 """
926
927 tgen = get_topogen()
928 if BGP_CONVERGENCE is not True:
929 pytest.skip("skipped because of BGP Convergence failure")
930
931 # test case name
932 tc_name = request.node.name
933 write_test_header(tc_name)
934
935 # Creating configuration from JSON
936 reset_config_on_routers(tgen)
937
938 # Create Static Routes
939 input_dict = {
940 "r1": {
941 "static_routes": [
942 {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"}
943 ]
944 }
945 }
946 result = create_static_routes(tgen, input_dict)
947 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
948
949 # Api call to redistribute static routes
950
951 # Create ip prefix list
952 input_dict_1 = {
953 "r3": {
954 "prefix_lists": {
955 "ipv4": {
956 "pf_list_1": [
957 {
958 "seqid": "10",
959 "network": "10.0.0.0/8",
960 "le": "32",
961 "action": "permit",
962 }
963 ]
964 }
965 }
966 }
967 }
968 result = create_prefix_lists(tgen, input_dict_1)
969 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
970
971 # Configure prefix list to bgp neighbor
972 input_dict_2 = {
973 "r1": {
974 "bgp": {
975 "address_family": {
976 "ipv4": {
977 "unicast": {
978 "redistribute": [
979 {"redist_type": "static"},
980 {"redist_type": "connected"},
981 ]
982 }
983 }
984 }
985 }
986 },
987 "r3": {
988 "bgp": {
989 "address_family": {
990 "ipv4": {
991 "unicast": {
992 "neighbor": {
993 "r4": {
994 "dest_link": {
995 "r3": {
996 "prefix_lists": [
997 {
998 "name": "pf_list_1",
999 "direction": "out",
1000 }
1001 ]
1002 }
1003 }
1004 }
1005 }
1006 }
1007 }
1008 }
1009 }
1010 },
1011 }
1012 result = create_router_bgp(tgen, topo, input_dict_2)
1013 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1014
1015 # Verifying RIB routes
1016 dut = "r4"
1017 protocol = "bgp"
1018 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
1019 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1020
1021 # Modify ip prefix list
1022 input_dict_1 = {
1023 "r3": {
1024 "prefix_lists": {
1025 "ipv4": {
1026 "pf_list_1": [
1027 {
1028 "seqid": "10",
1029 "network": "10.0.0.0/8",
1030 "le": "32",
1031 "action": "deny",
1032 },
1033 {"seqid": "11", "network": "any", "action": "permit"},
1034 ]
1035 }
1036 }
1037 }
1038 }
1039 result = create_prefix_lists(tgen, input_dict_1)
1040 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1041
1042 # Api call to clear bgp, so config changes would be reflected
1043 dut = "r3"
1044 result = clear_bgp_and_verify(tgen, topo, dut)
1045 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1046
1047 # Verifying RIB routes
1048 dut = "r4"
1049 protocol = "bgp"
1050 result = verify_rib(
1051 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
1052 )
1053 assert result is not True, (
1054 "Testcase {} : Failed \n "
1055 "Expected: Routes should not be present in {} BGP RIB \n "
1056 "Found: {}".format(tc_name, dut, result)
1057 )
1058
1059 write_test_footer(tc_name)
1060
1061
1062 def test_modify_prefix_lists_out_deny_to_permit(request):
1063 """
1064 Modify ip prefix list and test deny to permit prefixes OUT direction
1065 """
1066
1067 tgen = get_topogen()
1068 if BGP_CONVERGENCE is not True:
1069 pytest.skip("skipped because of BGP Convergence failure")
1070
1071 # test case name
1072 tc_name = request.node.name
1073 write_test_header(tc_name)
1074
1075 # Creating configuration from JSON
1076 reset_config_on_routers(tgen)
1077
1078 # Create Static Routes
1079 input_dict = {
1080 "r1": {
1081 "static_routes": [
1082 {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"}
1083 ]
1084 }
1085 }
1086 result = create_static_routes(tgen, input_dict)
1087 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1088
1089 # Api call to redistribute static routes
1090 # Create ip prefix list
1091 input_dict_1 = {
1092 "r3": {
1093 "prefix_lists": {
1094 "ipv4": {
1095 "pf_list_1": [
1096 {
1097 "seqid": "10",
1098 "network": "10.0.0.0/8",
1099 "le": "32",
1100 "action": "deny",
1101 },
1102 {"seqid": "11", "network": "any", "action": "permit"},
1103 ]
1104 }
1105 }
1106 }
1107 }
1108 result = create_prefix_lists(tgen, input_dict_1)
1109 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1110
1111 # Configure prefix list to bgp neighbor
1112 input_dict_2 = {
1113 "r1": {
1114 "bgp": {
1115 "address_family": {
1116 "ipv4": {
1117 "unicast": {
1118 "redistribute": [
1119 {"redist_type": "static"},
1120 {"redist_type": "connected"},
1121 ]
1122 }
1123 }
1124 }
1125 }
1126 },
1127 "r3": {
1128 "bgp": {
1129 "address_family": {
1130 "ipv4": {
1131 "unicast": {
1132 "neighbor": {
1133 "r4": {
1134 "dest_link": {
1135 "r3": {
1136 "prefix_lists": [
1137 {
1138 "name": "pf_list_1",
1139 "direction": "out",
1140 }
1141 ]
1142 }
1143 }
1144 }
1145 }
1146 }
1147 }
1148 }
1149 }
1150 },
1151 }
1152 result = create_router_bgp(tgen, topo, input_dict_2)
1153 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1154
1155 # Verifying RIB routes
1156 dut = "r4"
1157 protocol = "bgp"
1158 result = verify_rib(
1159 tgen, "ipv4", dut, input_dict, protocol=protocol, expected=False
1160 )
1161 assert result is not True, (
1162 "Testcase {} : Failed \n "
1163 "Expected: Routes should not be present in {} BGP RIB \n "
1164 "Found: {}".format(tc_name, dut, result)
1165 )
1166
1167 # Modify ip prefix list
1168 input_dict_1 = {
1169 "r3": {
1170 "prefix_lists": {
1171 "ipv4": {
1172 "pf_list_1": [
1173 {
1174 "seqid": "10",
1175 "network": "10.0.0.0/8",
1176 "le": "32",
1177 "action": "permit",
1178 }
1179 ]
1180 }
1181 }
1182 }
1183 }
1184 result = create_prefix_lists(tgen, input_dict_1)
1185 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1186
1187 # Api call to clear bgp, so config changes would be reflected
1188 dut = "r3"
1189 result = clear_bgp_and_verify(tgen, topo, dut)
1190 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1191
1192 # Verifying RIB routes
1193 dut = "r4"
1194 protocol = "bgp"
1195 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
1196 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1197
1198 write_test_footer(tc_name)
1199
1200
1201 def test_ip_prefix_lists_implicit_deny(request):
1202 """
1203 Create ip prefix list and test implicit deny
1204 """
1205
1206 tgen = get_topogen()
1207 if BGP_CONVERGENCE is not True:
1208 pytest.skip("skipped because of BGP Convergence failure")
1209
1210 # test case name
1211 tc_name = request.node.name
1212 write_test_header(tc_name)
1213
1214 # Creating configuration from JSON
1215 reset_config_on_routers(tgen)
1216
1217 # Create Static Routes
1218 input_dict = {
1219 "r1": {
1220 "static_routes": [
1221 {"network": "10.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.2"}
1222 ]
1223 }
1224 }
1225 result = create_static_routes(tgen, input_dict)
1226 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1227
1228 # Create Static Routes
1229 input_dict_1 = {
1230 "r2": {
1231 "static_routes": [
1232 {"network": "20.0.20.1/32", "no_of_ip": 9, "next_hop": "10.0.0.1"}
1233 ]
1234 }
1235 }
1236 result = create_static_routes(tgen, input_dict)
1237 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1238
1239 # Api call to redistribute static routes
1240 # Create ip prefix list
1241 input_dict_3 = {
1242 "r3": {
1243 "prefix_lists": {
1244 "ipv4": {
1245 "pf_list_1": [
1246 {
1247 "seqid": "10",
1248 "network": "10.0.0.0/8",
1249 "le": "32",
1250 "action": "permit",
1251 }
1252 ]
1253 }
1254 }
1255 }
1256 }
1257 result = create_prefix_lists(tgen, input_dict_3)
1258 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1259
1260 # Configure prefix list to bgp neighbor
1261 input_dict_4 = {
1262 "r1": {
1263 "bgp": {
1264 "address_family": {
1265 "ipv4": {
1266 "unicast": {
1267 "redistribute": [
1268 {"redist_type": "static"},
1269 {"redist_type": "connected"},
1270 ]
1271 }
1272 }
1273 }
1274 }
1275 },
1276 "r2": {
1277 "bgp": {
1278 "address_family": {
1279 "ipv4": {
1280 "unicast": {
1281 "redistribute": [
1282 {"redist_type": "static"},
1283 {"redist_type": "connected"},
1284 ]
1285 }
1286 }
1287 }
1288 }
1289 },
1290 "r3": {
1291 "bgp": {
1292 "address_family": {
1293 "ipv4": {
1294 "unicast": {
1295 "neighbor": {
1296 "r4": {
1297 "dest_link": {
1298 "r3": {
1299 "prefix_lists": [
1300 {
1301 "name": "pf_list_1",
1302 "direction": "out",
1303 }
1304 ]
1305 }
1306 }
1307 }
1308 }
1309 }
1310 }
1311 }
1312 }
1313 },
1314 }
1315 result = create_router_bgp(tgen, topo, input_dict_4)
1316 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1317
1318 # Verifying RIB routes
1319 dut = "r4"
1320 protocol = "bgp"
1321 result = verify_rib(tgen, "ipv4", dut, input_dict, protocol=protocol)
1322 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1323
1324 # Verifying RIB routes
1325 dut = "r4"
1326 protocol = "bgp"
1327 result = verify_rib(
1328 tgen, "ipv4", dut, input_dict_1, protocol=protocol, expected=False
1329 )
1330 assert result is not True, (
1331 "Testcase {} : Failed \n "
1332 "Expected: Routes should not be present in {} BGP RIB \n "
1333 "Found: {}".format(tc_name, dut, result)
1334 )
1335
1336 write_test_footer(tc_name)
1337
1338
1339 if __name__ == "__main__":
1340 args = ["-s"] + sys.argv[1:]
1341 sys.exit(pytest.main(args))