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