]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_route_map/test_route_map_topo2.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / bgp_route_map / test_route_map_topo2.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
KK
9
10"""Following tests are covered to test route-map functionality.
11TC_57:
12 Create route map to match prefix-list and permit inbound
13 and outbound prefixes and set criteria on match
14TC_52:
15 Test modify set/match clauses in a route-map to see
16 if it takes immediate effect.
17TC_61:
18 Delete the route maps.
19TC_50_1:
20 Test modify/remove prefix-lists referenced by a
21 route-map for match statement.
b9f80297 22TC_50_2:
468b867f
KK
23 Remove prefix-list referencec by route-map match cluase
24 and verifying it reflecting as intended
25TC_51:
26 Add and remove community-list referencec by route-map match cluase
27 and verifying it reflecting as intended
28TC_45:
b9f80297 29 Test multiple match statements as part of a route-map"s single
468b867f
KK
30 sequence number. (Logical OR-ed of multiple match statements)
31TC_44:
b9f80297 32 Test multiple match statements as part of a route-map"s single
468b867f
KK
33 sequence number. (Logical AND of multiple match statements)
34TC_41:
35 Test add/remove route-maps to specific neighbor and see if
36 it takes effect as intended
37TC_56:
38 Test clear BGP sessions and interface flaps to see if
39 route-map properties are intact.
40TC_46:
41 Verify if a blank sequence number can be create(without any
42 match/set clause) and check if it allows all the traffic/prefixes
43TC_48:
44 Create route map setting local preference and weight to eBGP peeer
45 and metric to ibgp peer and verifying it should not get advertised
46TC_43:
b9f80297 47 Test multiple set statements as part of a route-map"s
468b867f
KK
48 single sequence number.
49TC_54:
50 Verify route-maps continue clause functionality.
51TC_55:
52 Verify route-maps goto clause functionality.
53TC_53:
54 Verify route-maps call clause functionality.
55TC_58:
56 Create route map deny inbound and outbound prefixes on
57 match prefix list and set criteria on match
58TC_59:
59 Create route map to permit inbound prefixes with filter
60 match tag and set criteria
61TC_60
62 Create route map to deny outbound prefixes with filter match tag,
63 and set criteria
468b867f
KK
64
65#################################
66# TOPOLOGY
67#################################
468b867f
KK
68
69 +-------+
70 +--------- | R2 |
71 | +-------+
72 |iBGP |
73 +-------+ |
74 | R1 | |iBGP
75 +-------+ |
76 | |
77 | iBGP +-------+ eBGP +-------+
78 +---------- | R3 |----------| R4 |
79 +-------+ +-------+
80 |
81 |eBGP
82 |
83 +-------+
84 | R5 |
85 +-------+
86
87
88"""
89
90import sys
468b867f
KK
91import time
92import pytest
93import inspect
94import os
95from time import sleep
96
97# Save the Current Working Directory to find configuration files.
98CWD = os.path.dirname(os.path.realpath(__file__))
b9f80297 99sys.path.append(os.path.join(CWD, "../"))
468b867f
KK
100
101# pylint: disable=C0413
102# Import topogen and topotest helpers
468b867f 103from lib.topogen import Topogen, get_topogen
468b867f
KK
104
105# Required to instantiate the topology builder class.
106from lib.common_config import (
787e7624 107 start_topology,
108 write_test_header,
109 write_test_footer,
110 create_static_routes,
111 verify_rib,
112 delete_route_maps,
113 create_bgp_community_lists,
787e7624 114 create_route_maps,
115 create_prefix_lists,
116 verify_route_maps,
117 check_address_types,
118 verify_bgp_community,
119 shutdown_bringup_interface,
120 verify_prefix_lists,
121 reset_config_on_routers,
122 verify_create_community_list,
123)
468b867f
KK
124from lib.topolog import logger
125from lib.bgp import (
787e7624 126 verify_bgp_convergence,
127 create_router_bgp,
128 clear_bgp_and_verify,
129 verify_bgp_attributes,
130)
4953ca97 131from lib.topojson import build_config_from_json
468b867f 132
468b867f 133
e82b531d 134pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
468b867f
KK
135
136# Global variables
137# Global variables
138bgp_convergence = False
787e7624 139NETWORK = {"ipv4": ["11.0.20.1/32", "11.0.20.2/32"], "ipv6": ["2::1/128", "2::2/128"]}
468b867f
KK
140
141bgp_convergence = False
142BGP_CONVERGENCE = False
143ADDR_TYPES = check_address_types()
144
145
468b867f
KK
146def setup_module(mod):
147 """setup_module.
148
149 Set up the pytest environment
150 * `mod`: module name
151 """
152 testsuite_run_time = time.asctime(time.localtime(time.time()))
153 logger.info("Testsuite start time: {}".format(testsuite_run_time))
787e7624 154 logger.info("=" * 40)
468b867f
KK
155
156 logger.info("Running setup_module to create topology")
157
158 # This function initiates the topology build with Topogen...
e82b531d
CH
159 json_file = "{}/bgp_route_map_topo2.json".format(CWD)
160 tgen = Topogen(json_file, mod.__name__)
161 global topo
162 topo = tgen.json_topo
468b867f
KK
163 # ... and here it calls Mininet initialization functions.
164
165 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 166 # to start daemons and then start routers
468b867f
KK
167 start_topology(tgen)
168
169 # Creating configuration from JSON
170 build_config_from_json(tgen, topo)
171
172 # Checking BGP convergence
173 global bgp_convergence
174 global ADDR_TYPES
175
b9f80297 176 # Don"t run this test if we have any failure.
468b867f
KK
177 if tgen.routers_have_failure():
178 pytest.skip(tgen.errors)
179
180 # Api call verify whether BGP is converged
181 bgp_convergence = verify_bgp_convergence(tgen, topo)
787e7624 182 assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format(
183 bgp_convergence
184 )
468b867f
KK
185 logger.info("Running setup_module() done")
186
187
188def teardown_module(mod):
189 """teardown_module.
190
191 Teardown the pytest environment.
192 * `mod`: module name
193 """
194 logger.info("Running teardown_module to delete topology")
195 tgen = get_topogen()
196
197 # Stop toplogy and Remove tmp files
198 tgen.stop_topology()
199
787e7624 200 logger.info(
201 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
202 )
203 logger.info("=" * 40)
468b867f
KK
204
205
206#####################################################
207# Tests starting
208#####################################################
209
210
211def test_rmap_match_prefix_list_permit_in_and_outbound_prefixes_p0():
212 """
213 TC: 57
214 Create route map to match prefix-list and permit inbound
215 and outbound prefixes and set criteria on match
216 """
217 tgen = get_topogen()
218 global bgp_convergence
219
220 if bgp_convergence is not True:
b9f80297 221 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
222
223 # test case name
224 tc_name = inspect.stack()[0][3]
225 write_test_header(tc_name)
226 reset_config_on_routers(tgen)
227
228 # Create ip prefix list
229 input_dict_2 = {
b9f80297
KK
230 "r3": {
231 "prefix_lists": {
232 "ipv4": {
787e7624 233 "pf_list_1_ipv4": [
9fa6ec14 234 {
235 "seqid": 10,
236 "network": "any",
237 "action": "permit",
238 }
787e7624 239 ]
468b867f 240 },
b9f80297 241 "ipv6": {
787e7624 242 "pf_list_1_ipv6": [
9fa6ec14 243 {
244 "seqid": 10,
245 "network": "any",
246 "action": "permit",
247 }
787e7624 248 ]
249 },
468b867f
KK
250 }
251 }
252 }
253
254 result = create_prefix_lists(tgen, input_dict_2)
787e7624 255 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f 256 for addr_type in ADDR_TYPES:
787e7624 257 # Create route map
468b867f
KK
258 input_dict_3 = {
259 "r3": {
260 "route_maps": {
787e7624 261 "rmap_match_pf_1_{}".format(addr_type): [
262 {
263 "action": "permit",
264 "seq_id": "5",
265 "match": {
266 addr_type: {"prefix_lists": "pf_list_1_" + addr_type}
267 },
268 "set": {"locPrf": 150, "weight": 100},
468b867f 269 },
468b867f 270 ],
787e7624 271 "rmap_match_pf_2_{}".format(addr_type): [
272 {
273 "action": "permit",
274 "seq_id": "5",
275 "match": {
276 addr_type: {"prefix_lists": "pf_list_1_" + addr_type}
277 },
278 "set": {"metric": 50},
468b867f 279 },
787e7624 280 ],
468b867f
KK
281 }
282 }
283 }
284 result = create_route_maps(tgen, input_dict_3)
b9f80297 285 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 286 tc_name, result
287 )
468b867f
KK
288
289 # Configure neighbor for route map
290 input_dict_4 = {
787e7624 291 "r3": {
292 "bgp": {
293 "address_family": {
294 "ipv4": {
295 "unicast": {
296 "neighbor": {
297 "r1": {
298 "dest_link": {
299 "r3": {
300 "route_maps": [
301 {
302 "name": "rmap_match_pf_1_ipv4",
303 "direction": "in",
304 }
305 ]
306 }
307 }
308 },
309 "r4": {
310 "dest_link": {
311 "r3": {
312 "route_maps": [
313 {
314 "name": "rmap_match_pf_2_ipv4",
315 "direction": "out",
316 }
317 ]
318 }
319 }
320 },
321 }
322 }
323 },
324 "ipv6": {
325 "unicast": {
326 "neighbor": {
327 "r1": {
328 "dest_link": {
329 "r3": {
330 "route_maps": [
331 {
332 "name": "rmap_match_pf_1_ipv6",
333 "direction": "in",
334 }
335 ]
336 }
337 }
338 },
339 "r4": {
340 "dest_link": {
341 "r3": {
342 "route_maps": [
343 {
344 "name": "rmap_match_pf_2_ipv6",
345 "direction": "out",
346 }
347 ]
348 }
349 }
350 },
351 }
352 }
353 },
354 }
355 }
356 }
468b867f
KK
357 }
358
359 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 360 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
361
362 # Verifying RIB routes
b9f80297
KK
363 dut = "r3"
364 protocol = "bgp"
468b867f
KK
365 input_dict = topo["routers"]
366
367 # dual stack changes
368 for addr_type in ADDR_TYPES:
787e7624 369 result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 370 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 371 tc_name, result4
372 )
468b867f
KK
373
374 # Verifying BGP set attributes
b9f80297 375 dut = "r3"
468b867f 376 routes = {
787e7624 377 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
378 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
379 }
380 # dual stack changes
381 for addr_type in ADDR_TYPES:
382 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 383 result4 = verify_bgp_attributes(
384 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
385 )
b9f80297 386 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 387 tc_name, result4
388 )
468b867f
KK
389
390 # Verifying RIB routes
b9f80297
KK
391 dut = "r4"
392 protocol = "bgp"
468b867f
KK
393 # dual stack changes
394 for addr_type in ADDR_TYPES:
787e7624 395 result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 396 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 397 tc_name, result4
398 )
468b867f
KK
399
400 # Verifying BGP set attributes
b9f80297 401 dut = "r4"
468b867f 402 routes = {
787e7624 403 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
404 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
405 }
406 # dual stack changes
407 for addr_type in ADDR_TYPES:
408 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
787e7624 409 result = verify_bgp_attributes(
410 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
411 )
b9f80297 412 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 413 tc_name, result
414 )
468b867f
KK
415 write_test_footer(tc_name)
416
417 # Uncomment next line for debugging
418 # tgen.mininet_cli()
419
420
421def test_modify_set_match_clauses_in_rmap_p0():
422 """
423 TC_52:
424 Test modify set/match clauses in a route-map to see
425 if it takes immediate effect.
426 """
427
428 tgen = get_topogen()
429 global bgp_convergence
430
431 if bgp_convergence is not True:
b9f80297 432 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
433
434 # test case name
435 tc_name = inspect.stack()[0][3]
436 write_test_header(tc_name)
437 reset_config_on_routers(tgen)
438
439 # Create ip prefix list
440
441 input_dict_2 = {
b9f80297
KK
442 "r3": {
443 "prefix_lists": {
444 "ipv4": {
787e7624 445 "pf_list_1_ipv4": [
9fa6ec14 446 {
447 "seqid": 10,
448 "network": "any",
449 "action": "permit",
450 }
787e7624 451 ],
452 "pf_list_2_ipv4": [
453 {"seqid": 10, "network": "any", "action": "permit"}
454 ],
468b867f 455 },
b9f80297 456 "ipv6": {
787e7624 457 "pf_list_1_ipv6": [
9fa6ec14 458 {
459 "seqid": 10,
460 "network": "any",
461 "action": "permit",
462 }
787e7624 463 ],
464 "pf_list_2_ipv6": [
465 {"seqid": 10, "network": "any", "action": "permit"}
466 ],
467 },
468b867f
KK
468 }
469 }
787e7624 470 }
468b867f 471 result = create_prefix_lists(tgen, input_dict_2)
787e7624 472 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
473
474 # Create route map
475 for addr_type in ADDR_TYPES:
476 input_dict_3 = {
787e7624 477 "r3": {
478 "route_maps": {
479 "rmap_match_pf_1_{}".format(addr_type): [
480 {
481 "action": "permit",
482 "seq_id": "5",
483 "match": {
484 addr_type: {
485 "prefix_lists": "pf_list_1_{}".format(addr_type)
486 }
487 },
9fa6ec14 488 "set": {
489 "locPrf": 150,
490 },
468b867f 491 }
787e7624 492 ],
493 "rmap_match_pf_2_{}".format(addr_type): [
494 {
495 "action": "permit",
496 "seq_id": "5",
497 "match": {
498 addr_type: {
499 "prefix_lists": "pf_list_1_{}".format(addr_type)
500 }
501 },
502 "set": {"metric": 50},
468b867f 503 }
787e7624 504 ],
505 }
468b867f
KK
506 }
507 }
468b867f 508 result = create_route_maps(tgen, input_dict_3)
b9f80297 509 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 510 tc_name, result
511 )
468b867f
KK
512
513 # Configure neighbor for route map
514 input_dict_4 = {
787e7624 515 "r3": {
516 "bgp": {
517 "address_family": {
518 "ipv4": {
519 "unicast": {
520 "neighbor": {
521 "r1": {
522 "dest_link": {
523 "r3": {
524 "route_maps": [
525 {
526 "name": "rmap_match_pf_1_ipv4",
527 "direction": "in",
528 }
529 ]
530 }
531 }
532 },
533 "r4": {
534 "dest_link": {
535 "r3": {
536 "route_maps": [
537 {
538 "name": "rmap_match_pf_2_ipv4",
539 "direction": "out",
540 }
541 ]
542 }
543 }
544 },
545 }
546 }
547 },
548 "ipv6": {
549 "unicast": {
550 "neighbor": {
551 "r1": {
552 "dest_link": {
553 "r3": {
554 "route_maps": [
555 {
556 "name": "rmap_match_pf_1_ipv6",
557 "direction": "in",
558 }
559 ]
560 }
561 }
562 },
563 "r4": {
564 "dest_link": {
565 "r3": {
566 "route_maps": [
567 {
568 "name": "rmap_match_pf_2_ipv6",
569 "direction": "out",
570 }
571 ]
572 }
573 }
574 },
575 }
576 }
577 },
578 }
579 }
580 }
581 }
468b867f 582 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 583 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
584
585 # Verifying RIB routes
b9f80297
KK
586 dut = "r3"
587 protocol = "bgp"
468b867f
KK
588 input_dict = topo["routers"]
589 for addr_type in ADDR_TYPES:
787e7624 590 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 591 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 592 tc_name, result
593 )
468b867f
KK
594
595 # Verifying BGP set attributes
b9f80297 596 dut = "r3"
468b867f 597 routes = {
787e7624 598 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
599 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
600 }
601 # dual stack changes
602 for addr_type in ADDR_TYPES:
603 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 604 result4 = verify_bgp_attributes(
605 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
606 )
b9f80297 607 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 608 tc_name, result4
609 )
468b867f
KK
610
611 # Verifying RIB routes
b9f80297
KK
612 dut = "r4"
613 protocol = "bgp"
468b867f
KK
614 # dual stack changes
615 for addr_type in ADDR_TYPES:
787e7624 616 result4 = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 617 assert result4 is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 618 tc_name, result4
619 )
468b867f
KK
620
621 # Verifying BGP set attributes
b9f80297 622 dut = "r4"
468b867f 623 routes = {
787e7624 624 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
625 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
626 }
627 for addr_type in ADDR_TYPES:
628 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
787e7624 629 result = verify_bgp_attributes(
630 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
631 )
b9f80297 632 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 633 tc_name, result
634 )
468b867f
KK
635
636 # Modify set/match clause of in-used route map
637 for addr_type in ADDR_TYPES:
638 input_dict_3 = {
787e7624 639 "r3": {
640 "route_maps": {
641 "rmap_match_pf_1_{}".format(addr_type): [
642 {
643 "action": "permit",
644 "seq_id": "5",
645 "match": {
646 addr_type: {
647 "prefix_lists": "pf_list_1_{}".format(addr_type)
648 }
649 },
9fa6ec14 650 "set": {
651 "locPrf": 1000,
652 },
787e7624 653 }
654 ],
655 "rmap_match_pf_2_{}".format(addr_type): [
656 {
657 "action": "permit",
658 "seq_id": "5",
659 "match": {
660 addr_type: {
661 "prefix_lists": "pf_list_1_{}".format(addr_type)
662 }
663 },
664 "set": {"metric": 2000},
665 }
666 ],
468b867f 667 }
787e7624 668 }
468b867f
KK
669 }
670 result = create_route_maps(tgen, input_dict_3)
b9f80297 671 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 672 tc_name, result
673 )
468b867f
KK
674
675 # Verifying RIB routes
b9f80297
KK
676 dut = "r3"
677 protocol = "bgp"
468b867f 678 for addr_type in ADDR_TYPES:
787e7624 679 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 680 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 681 tc_name, result
682 )
468b867f
KK
683
684 # Verifying BGP set attributes
b9f80297 685 dut = "r3"
468b867f 686 routes = {
787e7624 687 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
688 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
689 }
690 for addr_type in ADDR_TYPES:
691 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 692 result = verify_bgp_attributes(
693 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
694 )
b9f80297 695 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 696 tc_name, result
697 )
468b867f
KK
698
699 # Verifying RIB routes
b9f80297
KK
700 dut = "r4"
701 protocol = "bgp"
468b867f 702 for addr_type in ADDR_TYPES:
787e7624 703 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 704 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 705 tc_name, result
706 )
468b867f
KK
707
708 # Verifying BGP set attributes
b9f80297 709 dut = "r4"
468b867f 710 routes = {
787e7624 711 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
712 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
713 }
714 for addr_type in ADDR_TYPES:
715 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
787e7624 716 result = verify_bgp_attributes(
717 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
718 )
b9f80297 719 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 720 tc_name, result
721 )
468b867f
KK
722
723 write_test_footer(tc_name)
724
725 # Uncomment next line for debugging
726 # tgen.mininet_cli()
727
728
729def test_delete_route_maps_p1():
730 """
731 TC_61:
732 Delete the route maps.
733 """
734
735 tgen = get_topogen()
736 global bgp_convergence
737
738 if bgp_convergence is not True:
b9f80297 739 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
740
741 # test case name
742 tc_name = inspect.stack()[0][3]
743 write_test_header(tc_name)
744 reset_config_on_routers(tgen)
745
746 # Create route map
747 for addr_type in ADDR_TYPES:
748 input_dict_3 = {
787e7624 749 "r3": {
750 "route_maps": {
751 "rmap_match_tag_1_{}".format(addr_type): [
752 {"action": "deny", "match": {addr_type: {"tag": "4001"}}}
753 ]
754 }
468b867f
KK
755 }
756 }
468b867f 757 result = create_route_maps(tgen, input_dict_3)
b9f80297 758 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 759 tc_name, result
760 )
468b867f
KK
761
762 # Delete route maps
763 for addr_type in ADDR_TYPES:
787e7624 764 input_dict = {"r3": {"route_maps": ["rmap_match_tag_1_{}".format(addr_type)]}}
468b867f 765 result = delete_route_maps(tgen, input_dict)
b9f80297 766 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 767 tc_name, result
768 )
468b867f
KK
769
770 result = verify_route_maps(tgen, input_dict)
787e7624 771 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
772 write_test_footer(tc_name)
773
774 # Uncomment next line for debugging
775 # tgen.mininet_cli()
776
777
778def test_modify_prefix_list_referenced_by_rmap_p0():
779 """
780 TC_50_1:
781 Test modify/remove prefix-lists referenced by a
782 route-map for match statement.
783 """
784
785 tgen = get_topogen()
786 global bgp_convergence
787
788 if bgp_convergence is not True:
b9f80297 789 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
790
791 # test case name
792 tc_name = inspect.stack()[0][3]
793 write_test_header(tc_name)
794 reset_config_on_routers(tgen)
795
796 # Create ip prefix list
797 input_dict_2 = {
b9f80297
KK
798 "r3": {
799 "prefix_lists": {
800 "ipv4": {
787e7624 801 "pf_list_1_ipv4": [
9fa6ec14 802 {
803 "seqid": 10,
804 "network": "any",
805 "action": "permit",
806 }
787e7624 807 ]
468b867f 808 },
b9f80297 809 "ipv6": {
787e7624 810 "pf_list_1_ipv6": [
9fa6ec14 811 {
812 "seqid": 100,
813 "network": "any",
814 "action": "permit",
815 }
787e7624 816 ]
817 },
468b867f
KK
818 }
819 }
787e7624 820 }
468b867f 821 result = create_prefix_lists(tgen, input_dict_2)
787e7624 822 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
823
824 # Create route map
825 for addr_type in ADDR_TYPES:
826 input_dict_3 = {
787e7624 827 "r3": {
828 "route_maps": {
829 "rmap_match_pf_1_{}".format(addr_type): [
830 {
831 "action": "permit",
832 "seq_id": "5",
833 "match": {
834 addr_type: {
835 "prefix_lists": "pf_list_1_{}".format(addr_type)
836 }
837 },
838 "set": {"locPrf": 150, "weight": 100},
468b867f 839 }
787e7624 840 ],
841 "rmap_match_pf_2_{}".format(addr_type): [
842 {
843 "action": "permit",
844 "seq_id": "5",
845 "match": {
846 addr_type: {
847 "prefix_lists": "pf_list_1_{}".format(addr_type)
848 }
849 },
850 "set": {"metric": 50},
468b867f 851 }
787e7624 852 ],
853 }
468b867f
KK
854 }
855 }
468b867f 856 result = create_route_maps(tgen, input_dict_3)
b9f80297 857 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 858 tc_name, result
859 )
468b867f
KK
860
861 # Configure neighbor for route map
862 input_dict_4 = {
787e7624 863 "r3": {
864 "bgp": {
865 "address_family": {
866 "ipv4": {
867 "unicast": {
868 "neighbor": {
869 "r1": {
870 "dest_link": {
871 "r3": {
872 "route_maps": [
873 {
874 "name": "rmap_match_pf_1_ipv4",
875 "direction": "in",
876 }
877 ]
878 }
879 }
880 },
881 "r4": {
882 "dest_link": {
883 "r3": {
884 "route_maps": [
885 {
886 "name": "rmap_match_pf_2_ipv4",
887 "direction": "out",
888 }
889 ]
890 }
891 }
892 },
893 }
894 }
895 },
896 "ipv6": {
897 "unicast": {
898 "neighbor": {
899 "r1": {
900 "dest_link": {
901 "r3": {
902 "route_maps": [
903 {
904 "name": "rmap_match_pf_1_ipv6",
905 "direction": "in",
906 }
907 ]
908 }
909 }
910 },
911 "r4": {
912 "dest_link": {
913 "r3": {
914 "route_maps": [
915 {
916 "name": "rmap_match_pf_2_ipv6",
917 "direction": "out",
918 }
919 ]
920 }
921 }
922 },
923 }
924 }
925 },
926 }
927 }
928 }
929 }
468b867f
KK
930
931 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 932 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
933
934 # Verifying RIB routes
b9f80297
KK
935 dut = "r3"
936 protocol = "bgp"
468b867f
KK
937 input_dict = topo["routers"]
938 for addr_type in ADDR_TYPES:
787e7624 939 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 940 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 941 tc_name, result
942 )
468b867f
KK
943
944 # Verifying BGP set attributes
b9f80297 945 dut = "r3"
468b867f 946 routes = {
787e7624 947 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
948 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
949 }
950 for addr_type in ADDR_TYPES:
951 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 952 result = verify_bgp_attributes(
953 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
954 )
b9f80297 955 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 956 tc_name, result
957 )
468b867f
KK
958
959 # Verifying RIB routes
b9f80297
KK
960 dut = "r4"
961 protocol = "bgp"
468b867f 962 for addr_type in ADDR_TYPES:
787e7624 963 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 964 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 965 tc_name, result
966 )
468b867f
KK
967
968 # Verifying BGP set attributes
b9f80297 969 dut = "r4"
468b867f 970 routes = {
787e7624 971 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
972 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
973 }
974
975 for addr_type in ADDR_TYPES:
976 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
787e7624 977 result = verify_bgp_attributes(
978 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
979 )
b9f80297 980 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 981 tc_name, result
982 )
468b867f
KK
983
984 # Modify ip prefix list
985 input_dict_2 = {
b9f80297
KK
986 "r3": {
987 "prefix_lists": {
988 "ipv4": {
787e7624 989 "pf_list_1_ipv4": [
990 {"seqid": 10, "network": "any", "action": "deny"}
991 ]
992 },
993 "ipv6": {
994 "pf_list_1_ipv6": [
995 {"seqid": 100, "network": "any", "action": "deny"}
996 ]
997 },
468b867f
KK
998 }
999 }
1000 }
1001 result = create_prefix_lists(tgen, input_dict_2)
787e7624 1002 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1003
1004 sleep(5)
1005 # Verifying RIB routes
b9f80297
KK
1006 dut = "r3"
1007 protocol = "bgp"
468b867f 1008 for addr_type in ADDR_TYPES:
787e7624 1009 result = verify_rib(
1010 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
1011 )
84ab3836
KK
1012 assert result is not True, (
1013 "Testcase {} : Failed \n "
d63c7094 1014 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
1015 "Found: {}".format(tc_name, dut, result)
1016 )
468b867f
KK
1017
1018 # Verifying RIB routes
b9f80297
KK
1019 dut = "r4"
1020 protocol = "bgp"
468b867f 1021 for addr_type in ADDR_TYPES:
787e7624 1022 result = verify_rib(
1023 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
1024 )
84ab3836
KK
1025 assert result is not True, (
1026 "Testcase {} : Failed \n "
d63c7094 1027 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
1028 "Found: {}".format(tc_name, dut, result)
1029 )
468b867f
KK
1030
1031 write_test_footer(tc_name)
1032
1033 # Uncomment next line for debugging
1034 # tgen.mininet_cli()
1035
1036
1037def test_remove_prefix_list_referenced_by_rmap_p0():
1038 """
b9f80297 1039 TC_50_2:
468b867f
KK
1040 Remove prefix-list referencec by route-map match cluase
1041 and verifying it reflecting as intended
1042 """
1043 tgen = get_topogen()
1044 global bgp_convergence
1045
1046 if bgp_convergence is not True:
b9f80297 1047 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
1048
1049 # test case name
1050 tc_name = inspect.stack()[0][3]
1051 write_test_header(tc_name)
1052 reset_config_on_routers(tgen)
1053
1054 # Create ip prefix list
1055 input_dict_2 = {
b9f80297
KK
1056 "r3": {
1057 "prefix_lists": {
1058 "ipv4": {
787e7624 1059 "pf_list_1_ipv4": [
1060 {"seqid": 10, "network": "any", "action": "permit"}
1061 ]
1062 },
b9f80297 1063 "ipv6": {
787e7624 1064 "pf_list_1_ipv6": [
1065 {"seqid": 100, "network": "any", "action": "permit"}
1066 ]
1067 },
468b867f
KK
1068 }
1069 }
468b867f
KK
1070 }
1071 result = create_prefix_lists(tgen, input_dict_2)
787e7624 1072 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1073
1074 # Create route map
1075 for addr_type in ADDR_TYPES:
1076 input_dict_3 = {
787e7624 1077 "r3": {
1078 "route_maps": {
1079 "rmap_match_pf_1_{}".format(addr_type): [
1080 {
1081 "action": "permit",
1082 "seq_id": "5",
1083 "match": {
1084 addr_type: {
1085 "prefix_lists": "pf_list_1_{}".format(addr_type)
1086 }
1087 },
9fa6ec14 1088 "set": {
1089 "locPrf": 150,
1090 },
468b867f 1091 }
787e7624 1092 ],
1093 "rmap_match_pf_2_{}".format(addr_type): [
1094 {
1095 "action": "permit",
1096 "seq_id": "5",
1097 "match": {
1098 addr_type: {
1099 "prefix_lists": "pf_list_1_{}".format(addr_type)
1100 }
1101 },
1102 "set": {"metric": 50},
1103 }
1104 ],
1105 }
468b867f
KK
1106 }
1107 }
468b867f 1108 result = create_route_maps(tgen, input_dict_3)
b9f80297 1109 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1110 tc_name, result
1111 )
468b867f
KK
1112
1113 # Configure neighbor for route map
1114 for addr_type in ADDR_TYPES:
1115 input_dict_4 = {
787e7624 1116 "r3": {
1117 "bgp": {
1118 "address_family": {
1119 "ipv4": {
1120 "unicast": {
1121 "neighbor": {
1122 "r1": {
1123 "dest_link": {
1124 "r3": {
1125 "route_maps": [
1126 {
1127 "name": "rmap_match_pf_1_ipv4",
1128 "direction": "in",
1129 }
1130 ]
1131 }
1132 }
1133 },
1134 "r4": {
1135 "dest_link": {
1136 "r3": {
1137 "route_maps": [
1138 {
1139 "name": "rmap_match_pf_2_ipv4",
1140 "direction": "out",
1141 }
1142 ]
1143 }
1144 }
1145 },
1146 }
1147 }
1148 },
1149 "ipv6": {
1150 "unicast": {
1151 "neighbor": {
1152 "r1": {
1153 "dest_link": {
1154 "r3": {
1155 "route_maps": [
1156 {
1157 "name": "rmap_match_pf_1_ipv6",
1158 "direction": "in",
1159 }
1160 ]
1161 }
1162 }
1163 },
1164 "r4": {
1165 "dest_link": {
1166 "r3": {
1167 "route_maps": [
1168 {
1169 "name": "rmap_match_pf_2_ipv6",
1170 "direction": "out",
1171 }
1172 ]
1173 }
1174 }
1175 },
1176 }
1177 }
1178 },
1179 }
1180 }
1181 }
1182 }
468b867f 1183 result = create_router_bgp(tgen, topo, input_dict_4)
b9f80297 1184 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1185 tc_name, result
1186 )
468b867f
KK
1187
1188 # Verifying RIB routes
b9f80297
KK
1189 dut = "r3"
1190 protocol = "bgp"
468b867f
KK
1191 input_dict = topo["routers"]
1192 for addr_type in ADDR_TYPES:
787e7624 1193 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 1194 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1195 tc_name, result
1196 )
468b867f
KK
1197
1198 # Verifying BGP set attributes
b9f80297 1199 dut = "r3"
468b867f 1200 routes = {
787e7624 1201 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1202 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
1203 }
1204 for addr_type in ADDR_TYPES:
1205 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 1206 result = verify_bgp_attributes(
1207 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
1208 )
b9f80297 1209 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1210 tc_name, result
1211 )
468b867f
KK
1212
1213 # Verifying RIB routes
b9f80297
KK
1214 dut = "r4"
1215 protocol = "bgp"
468b867f 1216 for addr_type in ADDR_TYPES:
787e7624 1217 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 1218 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1219 tc_name, result
1220 )
468b867f
KK
1221
1222 # Verifying BGP set attributes
b9f80297 1223 dut = "r4"
468b867f 1224 routes = {
787e7624 1225 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1226 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
1227 }
1228 for addr_type in ADDR_TYPES:
1229 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
787e7624 1230 result = verify_bgp_attributes(
1231 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
1232 )
b9f80297 1233 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1234 tc_name, result
1235 )
468b867f
KK
1236
1237 # Remove/Delete prefix list
1238 input_dict_3 = {
b9f80297
KK
1239 "r3": {
1240 "prefix_lists": {
1241 "ipv4": {
787e7624 1242 "pf_list_1_ipv4": [
1243 {
1244 "seqid": 10,
1245 "network": "any",
1246 "action": "permit",
1247 "delete": True,
1248 }
1249 ]
1250 },
b9f80297 1251 "ipv6": {
787e7624 1252 "pf_list_1_ipv6": [
1253 {
1254 "seqid": 100,
1255 "network": "any",
1256 "action": "permit",
1257 "delete": True,
1258 }
1259 ]
1260 },
468b867f
KK
1261 }
1262 }
468b867f
KK
1263 }
1264 result = create_prefix_lists(tgen, input_dict_3)
787e7624 1265 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1266
1267 result = verify_prefix_lists(tgen, input_dict_3)
787e7624 1268 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1269
1270 # Api call to clear bgp, so config changes would be reflected
b9f80297 1271 dut = "r3"
468b867f 1272 result = clear_bgp_and_verify(tgen, topo, dut)
787e7624 1273 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1274
1275 # Verifying RIB routes
b9f80297
KK
1276 dut = "r3"
1277 protocol = "bgp"
468b867f 1278 for addr_type in ADDR_TYPES:
787e7624 1279 result = verify_rib(
1280 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
1281 )
84ab3836
KK
1282 assert result is not True, (
1283 "Testcase {} : Failed \n "
d63c7094 1284 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
1285 "Found: {}".format(tc_name, dut, result)
1286 )
468b867f
KK
1287
1288 # Verifying RIB routes
b9f80297
KK
1289 dut = "r4"
1290 protocol = "bgp"
468b867f 1291 for addr_type in ADDR_TYPES:
787e7624 1292 result = verify_rib(
1293 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
1294 )
84ab3836
KK
1295 assert result is not True, (
1296 "Testcase {} : Failed \n "
d63c7094 1297 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
1298 "Found: {}".format(tc_name, dut, result)
1299 )
468b867f
KK
1300
1301 write_test_footer(tc_name)
1302
1303 # Uncomment next line for debugging
1304 # tgen.mininet_cli()
1305
1306
1307def test_add_and_remove_community_list_referenced_by_rmap_p0():
1308 """
1309 TC_51:
1310 Add and remove community-list referencec by route-map match cluase
1311 and verifying it reflecting as intended
1312 """
1313 tgen = get_topogen()
1314 global bgp_convergence
1315
1316 if bgp_convergence is not True:
b9f80297 1317 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
1318
1319 # test case name
1320 tc_name = inspect.stack()[0][3]
1321 write_test_header(tc_name)
1322 reset_config_on_routers(tgen)
1323
1324 # Creating configuration from JSON
1325 # build_config_from_json(tgen, topo)
1326
1327 # Create route map
1328 for addr_type in ADDR_TYPES:
1329 input_dict_5 = {
787e7624 1330 "r1": {
1331 "route_maps": {
1332 "rm_r1_out_{}".format(addr_type): [
1333 {
1334 "action": "permit",
1335 "set": {
1336 "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"}
1337 },
1338 }
1339 ]
1340 }
468b867f
KK
1341 }
1342 }
468b867f 1343 result = create_route_maps(tgen, input_dict_5)
b9f80297 1344 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1345 tc_name, result
1346 )
468b867f
KK
1347
1348 # Configure neighbor for route map
1349 input_dict_6 = {
787e7624 1350 "r1": {
1351 "bgp": {
1352 "address_family": {
1353 "ipv4": {
1354 "unicast": {
1355 "neighbor": {
1356 "r3": {
1357 "dest_link": {
1358 "r1": {
1359 "route_maps": [
1360 {
1361 "name": "rm_r1_out_ipv4",
1362 "direction": "out",
1363 }
1364 ]
1365 }
1366 }
1367 }
1368 }
1369 }
1370 },
1371 "ipv6": {
1372 "unicast": {
1373 "neighbor": {
1374 "r3": {
1375 "dest_link": {
1376 "r1": {
1377 "route_maps": [
1378 {
1379 "name": "rm_r1_out_ipv6",
1380 "direction": "out",
1381 }
1382 ]
1383 }
1384 }
1385 }
1386 }
1387 }
1388 },
1389 }
1390 }
1391 }
1392 }
468b867f
KK
1393
1394 result = create_router_bgp(tgen, topo, input_dict_6)
787e7624 1395 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1396
1397 for addr_type in ADDR_TYPES:
1398 # Create standard large commumity-list
787e7624 1399 input_dict_1 = {
1400 "r3": {
1401 "bgp_community_lists": [
1402 {
1403 "community_type": "standard",
1404 "action": "permit",
1405 "name": "rmap_lcomm_{}".format(addr_type),
1406 "value": "1:1:1 1:2:3 2:1:1 2:2:2",
1407 "large": True,
1408 }
1409 ]
468b867f 1410 }
787e7624 1411 }
1412 result = create_bgp_community_lists(tgen, input_dict_1)
1413 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1414 tc_name, result
1415 )
468b867f 1416
b9f80297
KK
1417 # Verify BGP large community is created
1418 result = verify_create_community_list(tgen, input_dict_1)
787e7624 1419 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
b9f80297 1420
468b867f 1421 for addr_type in ADDR_TYPES:
787e7624 1422 # Create route map
468b867f 1423 input_dict_2 = {
787e7624 1424 "r3": {
1425 "route_maps": {
1426 "rm_r3_in_{}".format(addr_type): [
1427 {
1428 "action": "permit",
1429 "match": {
1430 addr_type: {
1431 "large-community-list": {
1432 "id": "rmap_lcomm_" + addr_type
1433 }
1434 }
1435 },
1436 }
1437 ]
1438 }
1439 }
1440 }
1441 result = create_route_maps(tgen, input_dict_2)
1442 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1443 tc_name, result
1444 )
1445
1446 # Configure neighbor for route map
1447 input_dict_3 = {
468b867f 1448 "r3": {
787e7624 1449 "bgp": {
1450 "address_family": {
1451 "ipv4": {
1452 "unicast": {
1453 "neighbor": {
1454 "r1": {
1455 "dest_link": {
1456 "r3": {
1457 "route_maps": [
1458 {
1459 "name": "rm_r3_in_ipv4",
1460 "direction": "in",
1461 }
1462 ]
1463 }
1464 }
1465 }
1466 }
1467 }
1468 },
1469 "ipv6": {
1470 "unicast": {
1471 "neighbor": {
1472 "r1": {
1473 "dest_link": {
1474 "r3": {
1475 "route_maps": [
1476 {
1477 "name": "rm_r3_in_ipv6",
1478 "direction": "in",
1479 }
1480 ]
1481 }
1482 }
1483 }
1484 }
1485 }
1486 },
1487 }
468b867f
KK
1488 }
1489 }
787e7624 1490 }
468b867f
KK
1491 result = create_router_bgp(tgen, topo, input_dict_3)
1492
787e7624 1493 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1494
1495 sleep(5)
1496 # Verifying RIB routes
b9f80297
KK
1497 dut = "r3"
1498 protocol = "bgp"
468b867f
KK
1499 input_dict = topo["routers"]
1500 for addr_type in ADDR_TYPES:
787e7624 1501 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 1502 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1503 tc_name, result
1504 )
468b867f
KK
1505
1506 # Verify large-community-list
b9f80297 1507 dut = "r3"
468b867f 1508 networks = {
787e7624 1509 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1510 "ipv6": ["1::1/128", "1::2/128"],
468b867f 1511 }
787e7624 1512 input_dict_4 = {"largeCommunity": "1:1:1 1:2:3 2:1:1 2:2:2"}
468b867f 1513 for addr_type in ADDR_TYPES:
787e7624 1514 result = verify_bgp_community(
1515 tgen, addr_type, dut, networks[addr_type], input_dict_4
1516 )
b9f80297 1517 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1518 tc_name, result
1519 )
468b867f
KK
1520 write_test_footer(tc_name)
1521
1522 # Uncomment next line for debugging
1523 # tgen.mininet_cli()
1524
1525
1526def test_multiple_match_statement_in_route_map_logical_ORed_p0():
1527 """
1528 TC_45:
b9f80297 1529 Test multiple match statements as part of a route-map"s single
468b867f
KK
1530 sequence number. (Logical OR-ed of multiple match statements)
1531 """
1532 tgen = get_topogen()
1533 global bgp_convergence
1534
1535 if bgp_convergence is not True:
b9f80297 1536 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
1537
1538 # test case name
1539 tc_name = inspect.stack()[0][3]
1540 write_test_header(tc_name)
1541 reset_config_on_routers(tgen)
1542
1543 # Api call to advertise networks
1544 input_dict_nw1 = {
787e7624 1545 "r1": {
1546 "bgp": {
1547 "address_family": {
1548 "ipv4": {
1549 "unicast": {"advertise_networks": [{"network": "10.0.30.1/32"}]}
1550 },
1551 "ipv6": {
1552 "unicast": {"advertise_networks": [{"network": "1::1/128"}]}
1553 },
468b867f
KK
1554 }
1555 }
1556 }
787e7624 1557 }
468b867f
KK
1558
1559 result = create_router_bgp(tgen, topo, input_dict_nw1)
787e7624 1560 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1561
1562 # Api call to advertise networks
1563 input_dict_nw2 = {
787e7624 1564 "r1": {
1565 "bgp": {
1566 "address_family": {
1567 "ipv4": {
1568 "unicast": {"advertise_networks": [{"network": "20.0.30.1/32"}]}
1569 },
1570 "ipv6": {
1571 "unicast": {"advertise_networks": [{"network": "2::1/128"}]}
1572 },
468b867f
KK
1573 }
1574 }
1575 }
787e7624 1576 }
468b867f
KK
1577
1578 result = create_router_bgp(tgen, topo, input_dict_nw2)
787e7624 1579 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1580
1581 # Create ip prefix list
1582 input_dict_2 = {
b9f80297
KK
1583 "r3": {
1584 "prefix_lists": {
1585 "ipv4": {
787e7624 1586 "pf_list_1_ipv4": [
1587 {"seqid": 10, "network": "any", "action": "permit"}
1588 ]
1589 },
b9f80297 1590 "ipv6": {
787e7624 1591 "pf_list_1_ipv6": [
1592 {"seqid": 100, "network": "any", "action": "permit"}
1593 ]
1594 },
468b867f
KK
1595 }
1596 }
1597 }
1598 result = create_prefix_lists(tgen, input_dict_2)
787e7624 1599 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1600
1601 # Create ip prefix list
1602 input_dict_2 = {
b9f80297
KK
1603 "r3": {
1604 "prefix_lists": {
1605 "ipv4": {
787e7624 1606 "pf_list_2_ipv4": [
1607 {"seqid": 10, "network": "any", "action": "permit"}
1608 ]
1609 },
b9f80297 1610 "ipv6": {
787e7624 1611 "pf_list_2_ipv6": [
1612 {"seqid": 100, "network": "any", "action": "permit"}
1613 ]
1614 },
468b867f
KK
1615 }
1616 }
1617 }
1618 result = create_prefix_lists(tgen, input_dict_2)
787e7624 1619 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f 1620
787e7624 1621 input_dict_3_addr_type = {}
468b867f
KK
1622 # Create route map
1623 for addr_type in ADDR_TYPES:
1624 input_dict_3 = {
787e7624 1625 "r3": {
1626 "route_maps": {
1627 "rmap_match_pf_1_{}".format(addr_type): [
1628 {
1629 "action": "permit",
1630 "seq_id": "5",
1631 "match": {
1632 addr_type: {
1633 "prefix_lists": "pf_list_1_{}".format(addr_type)
1634 }
1635 },
1636 "set": {"locPrf": 150},
468b867f 1637 }
787e7624 1638 ]
1639 }
468b867f
KK
1640 }
1641 }
468b867f
KK
1642 input_dict_3_addr_type[addr_type] = input_dict_3
1643 result = create_route_maps(tgen, input_dict_3)
b9f80297 1644 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1645 tc_name, result
1646 )
468b867f
KK
1647
1648 # Create route map
1649 for addr_type in ADDR_TYPES:
1650 input_dict_3 = {
787e7624 1651 "r3": {
1652 "route_maps": {
1653 "rmap_match_pf_1_{}".format(addr_type): [
1654 {
1655 "action": "permit",
1656 "seq_id": "5",
1657 "match": {
1658 addr_type: {
1659 "prefix_lists": "pf_list_1_{}".format(addr_type)
1660 }
1661 },
1662 "set": {"locPrf": 200},
1663 }
1664 ]
1665 }
468b867f
KK
1666 }
1667 }
468b867f
KK
1668 input_dict_3_addr_type[addr_type] = input_dict_3
1669 result = create_route_maps(tgen, input_dict_3)
b9f80297 1670 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1671 tc_name, result
1672 )
468b867f
KK
1673
1674 # Configure neighbor for route map
1675 input_dict_6 = {
787e7624 1676 "r3": {
1677 "bgp": {
1678 "address_family": {
1679 "ipv4": {
1680 "unicast": {
1681 "neighbor": {
1682 "r1": {
1683 "dest_link": {
1684 "r3": {
1685 "route_maps": [
1686 {
1687 "name": "rmap_match_pf_1_ipv4",
1688 "direction": "in",
1689 }
1690 ]
1691 }
1692 }
1693 }
1694 }
1695 }
1696 },
1697 "ipv6": {
1698 "unicast": {
1699 "neighbor": {
1700 "r1": {
1701 "dest_link": {
1702 "r3": {
1703 "route_maps": [
1704 {
1705 "name": "rmap_match_pf_1_ipv6",
1706 "direction": "in",
1707 }
1708 ]
1709 }
1710 }
1711 }
1712 }
1713 }
1714 },
1715 }
1716 }
1717 }
1718 }
468b867f
KK
1719
1720 result = create_router_bgp(tgen, topo, input_dict_6)
787e7624 1721 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1722
1723 # Verifying RIB routes
b9f80297
KK
1724 dut = "r3"
1725 protocol = "bgp"
468b867f
KK
1726 input_dict = topo["routers"]
1727 for addr_type in ADDR_TYPES:
787e7624 1728 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 1729 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1730 tc_name, result
1731 )
468b867f
KK
1732
1733 # Verifying BGP set attributes
b9f80297 1734 dut = "r3"
787e7624 1735 routes = {"ipv4": ["10.0.30.1/32"], "ipv6": ["1::1/128"]}
468b867f
KK
1736 for addr_type in ADDR_TYPES:
1737 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 1738 result = verify_bgp_attributes(
1739 tgen,
1740 addr_type,
1741 dut,
1742 routes[addr_type],
1743 rmap_name,
1744 input_dict_3_addr_type[addr_type],
1745 )
1746 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1747 tc_name, result
1748 )
468b867f
KK
1749
1750 # Verifying BGP set attributes
787e7624 1751 routes = {"ipv4": ["20.0.30.1/32"], "ipv6": ["2::1/128"]}
468b867f 1752 for addr_type in ADDR_TYPES:
787e7624 1753 result = verify_bgp_attributes(
1754 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
1755 )
b9f80297 1756 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1757 tc_name, result
1758 )
468b867f
KK
1759
1760 write_test_footer(tc_name)
1761
1762 # Uncomment next line for debugging
1763 # tgen.mininet_cli()
1764
1765
b9f80297 1766def test_multiple_match_statement_in_route_map_logical_ANDed_p1():
468b867f
KK
1767 """
1768 TC_44:
b9f80297 1769 Test multiple match statements as part of a route-map"s single
468b867f
KK
1770 sequence number. (Logical AND of multiple match statements)
1771 """
1772 tgen = get_topogen()
1773 global bgp_convergence
1774
1775 if bgp_convergence is not True:
b9f80297 1776 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
1777
1778 # test case name
1779 tc_name = inspect.stack()[0][3]
1780 write_test_header(tc_name)
1781 reset_config_on_routers(tgen)
1782
1783 # Create route map
1784 for addr_type in ADDR_TYPES:
1785 input_dict_5 = {
1786 "r1": {
1787 "route_maps": {
787e7624 1788 "rm_r1_out_{}".format(addr_type): [
1789 {
1790 "action": "permit",
1791 "set": {
1792 "large_community": {"num": "1:1:1 1:2:3 2:1:1 2:2:2"}
1793 },
468b867f 1794 }
787e7624 1795 ]
468b867f
KK
1796 }
1797 }
1798 }
1799 result = create_route_maps(tgen, input_dict_5)
b9f80297 1800 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1801 tc_name, result
1802 )
468b867f
KK
1803
1804 # Configure neighbor for route map
1805 for addr_type in ADDR_TYPES:
1806 input_dict_6 = {
787e7624 1807 "r1": {
1808 "bgp": {
1809 "address_family": {
1810 addr_type: {
1811 "unicast": {
1812 "neighbor": {
1813 "r3": {
1814 "dest_link": {
1815 "r1": {
1816 "route_maps": [
1817 {
1818 "name": "rm_r1_out_{}".format(
1819 addr_type
1820 ),
1821 "direction": "out",
1822 }
1823 ]
1824 }
1825 }
1826 }
1827 }
1828 }
1829 }
1830 }
1831 }
1832 }
468b867f
KK
1833 }
1834 result = create_router_bgp(tgen, topo, input_dict_6)
b9f80297 1835 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1836 tc_name, result
1837 )
468b867f
KK
1838
1839 # Create ip prefix list
1840 input_dict_2 = {
b9f80297
KK
1841 "r3": {
1842 "prefix_lists": {
1843 "ipv4": {
787e7624 1844 "pf_list_1_ipv4": [
1845 {"seqid": 10, "network": "any", "action": "permit"}
1846 ]
468b867f 1847 },
b9f80297 1848 "ipv6": {
787e7624 1849 "pf_list_1_ipv6": [
1850 {"seqid": 100, "network": "any", "action": "permit"}
1851 ]
1852 },
468b867f
KK
1853 }
1854 }
1855 }
1856 result = create_prefix_lists(tgen, input_dict_2)
1857
787e7624 1858 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
1859
1860 for addr_type in ADDR_TYPES:
787e7624 1861 # Create standard large commumity-list
468b867f
KK
1862 input_dict_1 = {
1863 "r3": {
1864 "bgp_community_lists": [
1865 {
1866 "community_type": "standard",
1867 "action": "permit",
1868 "name": "rmap_lcomm_{}".format(addr_type),
1869 "value": "1:1:1 1:2:3 2:1:1 2:2:2",
787e7624 1870 "large": True,
468b867f
KK
1871 }
1872 ]
1873 }
1874 }
1875 result = create_bgp_community_lists(tgen, input_dict_1)
b9f80297 1876 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1877 tc_name, result
1878 )
468b867f 1879
b9f80297
KK
1880 # Verify BGP large community is created
1881 result = verify_create_community_list(tgen, input_dict_1)
787e7624 1882 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
b9f80297 1883
468b867f
KK
1884 # Create route map
1885 for addr_type in ADDR_TYPES:
1886 input_dict_3 = {
1887 "r3": {
1888 "route_maps": {
787e7624 1889 "rmap_match_pf_1_{}".format(addr_type): [
1890 {
1891 "action": "permit",
1892 "seq_id": "5",
1893 "match": {
1894 addr_type: {
1895 "prefix_lists": "pf_list_1_{}".format(addr_type)
1896 }
1897 },
9fa6ec14 1898 "set": {
1899 "locPrf": 150,
1900 },
468b867f 1901 }
787e7624 1902 ]
468b867f
KK
1903 }
1904 }
1905 }
1906 result = create_route_maps(tgen, input_dict_3)
b9f80297 1907 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1908 tc_name, result
1909 )
468b867f
KK
1910
1911 for addr_type in ADDR_TYPES:
787e7624 1912 # Create route map
468b867f
KK
1913 input_dict_3 = {
1914 "r3": {
1915 "route_maps": {
787e7624 1916 "rmap_match_pf_1_{}".format(addr_type): [
1917 {
1918 "action": "permit",
1919 "seq_id": "5",
1920 "match": {
1921 addr_type: {
1922 "large_community_list": {
1923 "id": "rmap_lcomm_" + addr_type
1924 }
1925 }
1926 },
9fa6ec14 1927 "set": {
1928 "locPrf": 150,
1929 },
468b867f 1930 }
787e7624 1931 ]
468b867f
KK
1932 }
1933 }
1934 }
1935 result = create_route_maps(tgen, input_dict_3)
b9f80297 1936 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1937 tc_name, result
1938 )
468b867f
KK
1939 # Configure neighbor for route map
1940 for addr_type in ADDR_TYPES:
1941 input_dict_4 = {
787e7624 1942 "r3": {
1943 "bgp": {
1944 "address_family": {
1945 addr_type: {
1946 "unicast": {
1947 "neighbor": {
1948 "r1": {
1949 "dest_link": {
1950 "r3": {
1951 "route_maps": [
1952 {
1953 "name": "rmap_match_pf_1_{}".format(
1954 addr_type
1955 ),
1956 "direction": "in",
1957 }
1958 ]
1959 }
1960 }
1961 }
1962 }
1963 }
1964 }
1965 }
1966 }
1967 }
468b867f
KK
1968 }
1969 result = create_router_bgp(tgen, topo, input_dict_4)
b9f80297 1970 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1971 tc_name, result
1972 )
468b867f
KK
1973 # sleep(10)
1974 # Verifying RIB routes
b9f80297
KK
1975 dut = "r3"
1976 protocol = "bgp"
468b867f
KK
1977 input_dict = topo["routers"]
1978 for addr_type in ADDR_TYPES:
1979 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 1980 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1981 tc_name, result
1982 )
468b867f
KK
1983
1984 # Verifying BGP set attributes
b9f80297 1985 dut = "r3"
468b867f 1986 routes = {
787e7624 1987 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
1988 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
1989 }
1990 for addr_type in ADDR_TYPES:
1991 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 1992 result = verify_bgp_attributes(
1993 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
1994 )
b9f80297 1995 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 1996 tc_name, result
1997 )
468b867f
KK
1998
1999 write_test_footer(tc_name)
2000
2001 # Uncomment next line for debugging
2002 # tgen.mininet_cli()
2003
2004
2005def test_add_remove_rmap_to_specific_neighbor_p0():
2006 """
2007 TC_41:
2008 Test add/remove route-maps to specific neighbor and see if
2009 it takes effect as intended
2010 """
2011 tgen = get_topogen()
2012 global bgp_convergence
2013
2014 if bgp_convergence is not True:
b9f80297 2015 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
2016
2017 # test case name
2018 tc_name = inspect.stack()[0][3]
2019 write_test_header(tc_name)
2020 reset_config_on_routers(tgen)
2021
2022 # Create ip prefix list
2023 input_dict_2 = {
b9f80297
KK
2024 "r3": {
2025 "prefix_lists": {
787e7624 2026 "ipv4": {
2027 "pf_list_1_ipv4": [
2028 {"seqid": 10, "network": "any", "action": "deny"}
2029 ]
2030 },
2031 "ipv6": {
2032 "pf_list_1_ipv6": [
2033 {"seqid": 100, "network": "any", "action": "deny"}
2034 ]
2035 },
468b867f
KK
2036 }
2037 }
2038 }
2039 result = create_prefix_lists(tgen, input_dict_2)
787e7624 2040 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2041
2042 # Create route map
2043 for addr_type in ADDR_TYPES:
2044 input_dict_3 = {
787e7624 2045 "r3": {
2046 "route_maps": {
2047 "rmap_match_pf_1_{}".format(addr_type): [
2048 {
2049 "action": "permit",
2050 "seq_id": "5",
2051 "match": {
2052 addr_type: {
2053 "prefix_lists": "pf_list_1_{}".format(addr_type)
2054 }
2055 },
9fa6ec14 2056 "set": {
2057 "locPrf": 150,
2058 },
787e7624 2059 }
2060 ]
2061 }
468b867f
KK
2062 }
2063 }
468b867f 2064 result = create_route_maps(tgen, input_dict_3)
b9f80297 2065 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2066 tc_name, result
2067 )
468b867f
KK
2068
2069 # Configure neighbor for route map
2070 input_dict_4 = {
b9f80297 2071 "r3": {
468b867f
KK
2072 "bgp": {
2073 "address_family": {
2074 "ipv4": {
2075 "unicast": {
2076 "neighbor": {
2077 "r1": {
2078 "dest_link": {
2079 "r3": {
787e7624 2080 "route_maps": [
2081 {
2082 "name": "rmap_match_pf_1_ipv4",
2083 "direction": "in",
2084 }
2085 ]
468b867f
KK
2086 }
2087 }
2088 }
2089 }
2090 }
2091 },
2092 "ipv6": {
2093 "unicast": {
2094 "neighbor": {
2095 "r1": {
2096 "dest_link": {
2097 "r3": {
787e7624 2098 "route_maps": [
2099 {
2100 "name": "rmap_match_pf_1_ipv6",
2101 "direction": "in",
2102 }
2103 ]
468b867f
KK
2104 }
2105 }
2106 }
2107 }
2108 }
787e7624 2109 },
468b867f
KK
2110 }
2111 }
2112 }
2113 }
2114
2115 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 2116 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2117
2118 # Verifying RIB routes
b9f80297
KK
2119 dut = "r3"
2120 protocol = "bgp"
468b867f
KK
2121 input_dict = topo["routers"]
2122 for addr_type in ADDR_TYPES:
787e7624 2123 result = verify_rib(
2124 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
2125 )
84ab3836
KK
2126 assert result is not True, (
2127 "Testcase {} : Failed \n "
d63c7094 2128 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
2129 "Found: {}".format(tc_name, dut, result)
2130 )
468b867f
KK
2131
2132 # Remove applied rmap from neighbor
2133 input_dict_4 = {
b9f80297 2134 "r3": {
468b867f
KK
2135 "bgp": {
2136 "address_family": {
2137 "ipv4": {
2138 "unicast": {
2139 "neighbor": {
2140 "r1": {
2141 "dest_link": {
2142 "r3": {
787e7624 2143 "route_maps": [
2144 {
2145 "name": "rmap_match_pf_1_ipv4",
b9f80297 2146 "direction": "in",
787e7624 2147 "delete": True,
2148 }
2149 ]
468b867f
KK
2150 }
2151 }
2152 }
2153 }
2154 }
2155 },
2156 "ipv6": {
2157 "unicast": {
2158 "neighbor": {
2159 "r1": {
2160 "dest_link": {
2161 "r3": {
787e7624 2162 "route_maps": [
2163 {
2164 "name": "rmap_match_pf_1_ipv6",
b9f80297 2165 "direction": "in",
787e7624 2166 "delete": True,
2167 }
2168 ]
468b867f
KK
2169 }
2170 }
2171 }
2172 }
2173 }
787e7624 2174 },
468b867f
KK
2175 }
2176 }
2177 }
2178 }
2179
2180 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 2181 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2182
2183 # Verifying RIB routes
b9f80297
KK
2184 dut = "r3"
2185 protocol = "bgp"
468b867f
KK
2186 input_dict = topo["routers"]
2187 for addr_type in ADDR_TYPES:
2188 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2189 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2190 tc_name, result
2191 )
468b867f
KK
2192
2193 write_test_footer(tc_name)
2194
2195 # Uncomment next line for debugging
2196 # tgen.mininet_cli()
2197
2198
2199def test_clear_bgp_and_flap_interface_to_verify_rmap_properties_p0():
2200 """
2201 TC_56:
2202 Test clear BGP sessions and interface flaps to see if
2203 route-map properties are intact.
2204 """
2205 tgen = get_topogen()
2206 global bgp_convergence
2207
2208 if bgp_convergence is not True:
b9f80297 2209 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
2210
2211 # test case name
2212 tc_name = inspect.stack()[0][3]
2213 write_test_header(tc_name)
2214 reset_config_on_routers(tgen)
2215
2216 # Create ip prefix list
2217 input_dict_2 = {
b9f80297
KK
2218 "r3": {
2219 "prefix_lists": {
2220 "ipv4": {
787e7624 2221 "pf_list_1_ipv4": [
2222 {"seqid": 10, "network": "any", "action": "permit"}
2223 ]
2224 },
b9f80297 2225 "ipv6": {
787e7624 2226 "pf_list_1_ipv6": [
2227 {"seqid": 100, "network": "any", "action": "permit"}
2228 ]
2229 },
468b867f
KK
2230 }
2231 }
2232 }
2233 result = create_prefix_lists(tgen, input_dict_2)
787e7624 2234 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2235
2236 # Create route map
2237 for addr_type in ADDR_TYPES:
2238 input_dict_3 = {
787e7624 2239 "r3": {
2240 "route_maps": {
2241 "rmap_match_pf_1_{}".format(addr_type): [
2242 {
2243 "action": "permit",
2244 "seq_id": "5",
2245 "match": {
2246 addr_type: {
2247 "prefix_lists": "pf_list_1_{}".format(addr_type)
2248 }
2249 },
2250 "set": {"locPrf": 150, "weight": 100},
2251 }
2252 ]
2253 }
468b867f
KK
2254 }
2255 }
468b867f 2256 result = create_route_maps(tgen, input_dict_3)
b9f80297 2257 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2258 tc_name, result
2259 )
468b867f
KK
2260
2261 # Configure neighbor for route map
2262 input_dict_4 = {
b9f80297 2263 "r3": {
468b867f
KK
2264 "bgp": {
2265 "address_family": {
2266 "ipv4": {
2267 "unicast": {
2268 "neighbor": {
2269 "r1": {
2270 "dest_link": {
2271 "r3": {
787e7624 2272 "route_maps": [
2273 {
2274 "name": "rmap_match_pf_1_ipv4",
2275 "direction": "in",
2276 }
2277 ]
468b867f
KK
2278 }
2279 }
2280 }
2281 }
2282 }
2283 },
2284 "ipv6": {
2285 "unicast": {
2286 "neighbor": {
2287 "r1": {
2288 "dest_link": {
2289 "r3": {
787e7624 2290 "route_maps": [
2291 {
2292 "name": "rmap_match_pf_1_ipv6",
2293 "direction": "in",
2294 }
2295 ]
468b867f
KK
2296 }
2297 }
2298 }
2299 }
2300 }
787e7624 2301 },
468b867f
KK
2302 }
2303 }
2304 }
2305 }
2306
2307 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 2308 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2309
2310 # Verifying RIB routes
b9f80297
KK
2311 dut = "r3"
2312 protocol = "bgp"
468b867f
KK
2313 input_dict = topo["routers"]
2314 for addr_type in ADDR_TYPES:
2315 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2316 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2317 tc_name, result
2318 )
468b867f
KK
2319
2320 # Verifying BGP set attributes
b9f80297 2321 dut = "r3"
468b867f 2322 routes = {
787e7624 2323 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2324 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
2325 }
2326 for addr_type in ADDR_TYPES:
2327 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 2328 result = verify_bgp_attributes(
2329 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2330 )
b9f80297 2331 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2332 tc_name, result
2333 )
468b867f
KK
2334
2335 # clear bgp, so config changes would be reflected
b9f80297 2336 dut = "r3"
468b867f 2337 result = clear_bgp_and_verify(tgen, topo, dut)
787e7624 2338 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2339
2340 # Verifying RIB routes
b9f80297
KK
2341 dut = "r3"
2342 protocol = "bgp"
468b867f
KK
2343 input_dict = topo["routers"]
2344 for addr_type in ADDR_TYPES:
2345 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2346 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2347 tc_name, result
2348 )
468b867f
KK
2349
2350 # Verifying BGP set attributes
b9f80297 2351 dut = "r3"
468b867f 2352 routes = {
787e7624 2353 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2354 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
2355 }
2356 for addr_type in ADDR_TYPES:
2357 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 2358 result = verify_bgp_attributes(
2359 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2360 )
b9f80297 2361 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2362 tc_name, result
2363 )
468b867f
KK
2364
2365 # Flap interface to see if route-map properties are intact
2366 # Shutdown interface
2367 dut = "r3"
2368 intf = "r3-r1-eth0"
2369 shutdown_bringup_interface(tgen, dut, intf, False)
2370
2371 sleep(5)
2372
2373 # Bringup interface
2374 dut = "r3"
2375 intf = "r3-r1-eth0"
2376 shutdown_bringup_interface(tgen, dut, intf, True)
2377
2378 # Verify BGP convergence once interface is up
2379 result = verify_bgp_convergence(tgen, topo)
787e7624 2380 assert result is True, "setup_module :Failed \n Error:" " {}".format(result)
468b867f
KK
2381
2382 # Verifying RIB routes
b9f80297
KK
2383 dut = "r3"
2384 protocol = "bgp"
468b867f
KK
2385 input_dict = topo["routers"]
2386 for addr_type in ADDR_TYPES:
2387 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2388 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2389 tc_name, result
2390 )
468b867f
KK
2391
2392 # Verifying BGP set attributes
b9f80297 2393 dut = "r3"
468b867f 2394 routes = {
787e7624 2395 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2396 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
2397 }
2398 for addr_type in ADDR_TYPES:
2399 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 2400 result = verify_bgp_attributes(
2401 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2402 )
b9f80297 2403 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2404 tc_name, result
2405 )
468b867f
KK
2406
2407 write_test_footer(tc_name)
2408
2409 # Uncomment next line for debugging
2410 # tgen.mininet_cli()
2411
2412
2413def test_rmap_without_match_and_set_clause_p0():
2414 """
2415 TC_46:
2416 Verify if a blank sequence number can be create(without any
2417 match/set clause) and check if it allows all the traffic/prefixes
2418 """
2419 tgen = get_topogen()
2420 global bgp_convergence
2421
2422 if bgp_convergence is not True:
b9f80297 2423 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
2424
2425 # test case name
2426 tc_name = inspect.stack()[0][3]
2427 write_test_header(tc_name)
2428 reset_config_on_routers(tgen)
2429
2430 # Create route map
2431 for addr_type in ADDR_TYPES:
2432 input_dict_3 = {
787e7624 2433 "r3": {
2434 "route_maps": {
2435 "rmap_no_match_set_1_{}".format(addr_type): [
2436 {"action": "permit", "seq_id": "5"}
2437 ],
2438 "rmap_no_match_set_2_{}".format(addr_type): [
2439 {"action": "deny", "seq_id": "5"}
2440 ],
2441 }
468b867f
KK
2442 }
2443 }
468b867f 2444 result = create_route_maps(tgen, input_dict_3)
b9f80297 2445 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2446 tc_name, result
2447 )
468b867f
KK
2448
2449 # Configure neighbor for route map
2450 input_dict_4 = {
b9f80297 2451 "r3": {
468b867f
KK
2452 "bgp": {
2453 "address_family": {
2454 "ipv4": {
2455 "unicast": {
2456 "neighbor": {
2457 "r1": {
2458 "dest_link": {
2459 "r3": {
787e7624 2460 "route_maps": [
2461 {
2462 "name": "rmap_no_match_set_1_ipv4",
2463 "direction": "in",
2464 }
2465 ]
468b867f
KK
2466 }
2467 }
2468 },
2469 "r4": {
2470 "dest_link": {
2471 "r3": {
787e7624 2472 "route_maps": [
2473 {
2474 "name": "rmap_no_match_set_2_ipv4",
2475 "direction": "out",
2476 }
2477 ]
468b867f
KK
2478 }
2479 }
787e7624 2480 },
468b867f
KK
2481 }
2482 }
2483 },
2484 "ipv6": {
2485 "unicast": {
2486 "neighbor": {
2487 "r1": {
2488 "dest_link": {
2489 "r3": {
787e7624 2490 "route_maps": [
2491 {
2492 "name": "rmap_no_match_set_1_ipv6",
2493 "direction": "in",
2494 }
2495 ]
468b867f
KK
2496 }
2497 }
2498 },
2499 "r4": {
2500 "dest_link": {
2501 "r3": {
787e7624 2502 "route_maps": [
2503 {
2504 "name": "rmap_no_match_set_2_ipv6",
2505 "direction": "out",
2506 }
2507 ]
468b867f
KK
2508 }
2509 }
787e7624 2510 },
468b867f
KK
2511 }
2512 }
787e7624 2513 },
468b867f
KK
2514 }
2515 }
2516 }
2517 }
2518
2519 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 2520 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2521
2522 # Verifying RIB routes
b9f80297
KK
2523 dut = "r3"
2524 protocol = "bgp"
468b867f
KK
2525 input_dict = topo["routers"]
2526 for addr_type in ADDR_TYPES:
2527 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2528 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2529 tc_name, result
2530 )
468b867f
KK
2531
2532 # Verifying RIB routes
b9f80297
KK
2533 dut = "r4"
2534 protocol = "bgp"
468b867f 2535 for addr_type in ADDR_TYPES:
787e7624 2536 result = verify_rib(
2537 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
2538 )
84ab3836
KK
2539 assert result is not True, (
2540 "Testcase {} : Failed \n "
d63c7094 2541 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
2542 "Found: {}".format(tc_name, dut, result)
2543 )
468b867f
KK
2544
2545 write_test_footer(tc_name)
468b867f
KK
2546 # Uncomment next line for debugging
2547 # tgen.mininet_cli()
2548
2549
2550def test_set_localpref_weight_to_ebgp_and_med_to_ibgp_peers_p0():
2551 """
2552 TC_48:
2553 Create route map setting local preference and weight to eBGP peeer
2554 and metric to ibgp peer and verifying it should not get advertised
2555 """
2556 tgen = get_topogen()
2557 global bgp_convergence
2558
2559 if bgp_convergence is not True:
b9f80297 2560 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
2561
2562 # test case name
2563 tc_name = inspect.stack()[0][3]
2564 write_test_header(tc_name)
2565 reset_config_on_routers(tgen)
2566
2567 # Create ip prefix list
2568 input_dict_2 = {
b9f80297
KK
2569 "r3": {
2570 "prefix_lists": {
787e7624 2571 "ipv4": {
2572 "pf_list_1_ipv4": [
2573 {"seqid": 10, "network": "any", "action": "permit"}
2574 ]
2575 },
2576 "ipv6": {
2577 "pf_list_1_ipv6": [
2578 {"seqid": 100, "network": "any", "action": "permit"}
2579 ]
2580 },
468b867f
KK
2581 }
2582 }
2583 }
2584 result = create_prefix_lists(tgen, input_dict_2)
787e7624 2585 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2586
2587 # Create route map
787e7624 2588 input_dict_3_addr_type = {}
468b867f
KK
2589 for addr_type in ADDR_TYPES:
2590 input_dict_3 = {
2591 "r3": {
2592 "route_maps": {
787e7624 2593 "rmap_match_pf_1_{}".format(addr_type): [
2594 {
468b867f
KK
2595 "action": "permit",
2596 "match": {
2597 addr_type: {
787e7624 2598 "prefix_lists": "pf_list_1_{}".format(addr_type)
468b867f
KK
2599 }
2600 },
787e7624 2601 "set": {"metric": 50},
2602 }
2603 ],
2604 "rmap_match_pf_2_{}".format(addr_type): [
2605 {
2606 "action": "permit",
2607 "match": {
2608 addr_type: {
2609 "prefix_lists": "pf_list_1_{}".format(addr_type)
468b867f 2610 }
787e7624 2611 },
2612 "set": {"locPrf": 150},
2613 }
2614 ],
2615 "rmap_match_pf_3_{}".format(addr_type): [
2616 {
468b867f
KK
2617 "action": "permit",
2618 "match": {
2619 addr_type: {
787e7624 2620 "prefix_lists": "pf_list_1_{}".format(addr_type)
2621 }
2622 },
2623 "set": {"weight": 1000},
468b867f 2624 }
787e7624 2625 ],
2626 }
2627 }
2628 }
468b867f
KK
2629 input_dict_3_addr_type[addr_type] = input_dict_3
2630 result = create_route_maps(tgen, input_dict_3)
b9f80297 2631 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2632 tc_name, result
2633 )
468b867f
KK
2634
2635 # Configure neighbor for route map
2636 input_dict_4 = {
b9f80297 2637 "r3": {
468b867f
KK
2638 "bgp": {
2639 "address_family": {
2640 "ipv4": {
2641 "unicast": {
2642 "neighbor": {
2643 "r1": {
2644 "dest_link": {
2645 "r3": {
787e7624 2646 "route_maps": [
2647 {
2648 "name": "rmap_match_pf_1_ipv4",
2649 "direction": "in",
2650 }
2651 ]
468b867f
KK
2652 }
2653 }
2654 },
2655 "r4": {
2656 "dest_link": {
2657 "r3": {
787e7624 2658 "route_maps": [
2659 {
2660 "name": "rmap_match_pf_2_ipv4",
2661 "direction": "out",
2662 }
2663 ]
468b867f
KK
2664 }
2665 }
2666 },
2667 "r5": {
2668 "dest_link": {
2669 "r3": {
787e7624 2670 "route_maps": [
2671 {
2672 "name": "rmap_match_pf_3_ipv4",
2673 "direction": "out",
2674 }
2675 ]
468b867f
KK
2676 }
2677 }
787e7624 2678 },
468b867f
KK
2679 }
2680 }
2681 },
2682 "ipv6": {
2683 "unicast": {
2684 "neighbor": {
2685 "r1": {
2686 "dest_link": {
2687 "r3": {
787e7624 2688 "route_maps": [
2689 {
2690 "name": "rmap_match_pf_1_ipv6",
2691 "direction": "in",
2692 }
2693 ]
468b867f
KK
2694 }
2695 }
2696 },
2697 "r4": {
2698 "dest_link": {
2699 "r3": {
787e7624 2700 "route_maps": [
2701 {
2702 "name": "rmap_match_pf_2_ipv6",
2703 "direction": "out",
2704 }
2705 ]
468b867f
KK
2706 }
2707 }
2708 },
2709 "r5": {
2710 "dest_link": {
2711 "r3": {
787e7624 2712 "route_maps": [
2713 {
2714 "name": "rmap_match_pf_3_ipv6",
2715 "direction": "out",
2716 }
2717 ]
468b867f
KK
2718 }
2719 }
787e7624 2720 },
468b867f
KK
2721 }
2722 }
787e7624 2723 },
468b867f
KK
2724 }
2725 }
2726 }
2727 }
2728
2729 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 2730 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2731
2732 # Verifying RIB routes
b9f80297
KK
2733 dut = "r3"
2734 protocol = "bgp"
468b867f
KK
2735 input_dict = topo["routers"]
2736 for addr_type in ADDR_TYPES:
787e7624 2737 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2738 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2739 tc_name, result
2740 )
468b867f
KK
2741
2742 # Verifying BGP set attributes
b9f80297 2743 dut = "r3"
468b867f 2744 routes = {
787e7624 2745 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2746 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
2747 }
2748 rmap_name = "rmap_match_pf_1"
2749 for addr_type in ADDR_TYPES:
2750 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 2751 result = verify_bgp_attributes(
2752 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2753 )
b9f80297 2754 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2755 tc_name, result
2756 )
468b867f
KK
2757
2758 # Verifying RIB routes
b9f80297
KK
2759 dut = "r4"
2760 protocol = "bgp"
468b867f 2761 for addr_type in ADDR_TYPES:
787e7624 2762 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2763 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2764 tc_name, result
2765 )
468b867f
KK
2766
2767 # Verifying BGP set attributes
b9f80297 2768 dut = "r4"
468b867f 2769 routes = {
787e7624 2770 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2771 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
2772 }
2773 rmap_name = "rmap_match_pf_2"
2774 for addr_type in ADDR_TYPES:
2775 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
2776
787e7624 2777 result = verify_bgp_attributes(
2778 tgen,
2779 addr_type,
2780 dut,
2781 routes[addr_type],
2782 rmap_name,
2783 input_dict_3_addr_type[addr_type],
2784 expected=False,
2785 )
84ab3836
KK
2786 assert result is not True, (
2787 "Testcase {} : Failed \n "
d63c7094 2788 "Expected: BGP attributes should not be set in {} FIB \n "
84ab3836
KK
2789 "Found: {}".format(tc_name, dut, result)
2790 )
468b867f
KK
2791
2792 # Verifying RIB routes
b9f80297
KK
2793 dut = "r5"
2794 protocol = "bgp"
468b867f 2795 for addr_type in ADDR_TYPES:
787e7624 2796 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2797 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2798 tc_name, result
2799 )
468b867f 2800 # Verifying BGP set attributes
b9f80297 2801 dut = "r5"
468b867f 2802 routes = {
787e7624 2803 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2804 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
2805 }
2806
2807 rmap_name = "rmap_match_pf_3"
2808 for addr_type in ADDR_TYPES:
2809 rmap_name = "rmap_match_pf_3_{}".format(addr_type)
787e7624 2810 result = verify_bgp_attributes(
2811 tgen,
2812 addr_type,
2813 dut,
2814 routes[addr_type],
2815 rmap_name,
2816 input_dict_3_addr_type[addr_type],
2817 expected=False,
2818 )
84ab3836
KK
2819 assert result is not True, (
2820 "Testcase {} : Failed \n "
d63c7094 2821 "Expected: BGP attributes should not be set in {} FIB \n "
84ab3836
KK
2822 "Found: {}".format(tc_name, dut, result)
2823 )
468b867f
KK
2824
2825 write_test_footer(tc_name)
2826
2827 # Uncomment next line for debugging
2828 # tgen.mininet_cli()
2829
2830
2831def test_multiple_set_on_single_sequence_in_rmap_p0():
2832 """
2833 TC_43:
b9f80297 2834 Test multiple set statements as part of a route-map"s
468b867f
KK
2835 single sequence number.
2836 """
2837 tgen = get_topogen()
2838 global bgp_convergence
2839
2840 if bgp_convergence is not True:
b9f80297 2841 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
2842
2843 # test case name
2844 tc_name = inspect.stack()[0][3]
2845 write_test_header(tc_name)
2846 reset_config_on_routers(tgen)
2847
2848 # Create ip prefix list
2849 input_dict_2 = {
b9f80297
KK
2850 "r3": {
2851 "prefix_lists": {
2852 "ipv4": {
787e7624 2853 "pf_list_1_ipv4": [
2854 {"seqid": 10, "network": "any", "action": "permit"}
2855 ]
468b867f 2856 },
b9f80297 2857 "ipv6": {
787e7624 2858 "pf_list_1_ipv6": [
2859 {"seqid": 100, "network": "any", "action": "permit"}
2860 ]
2861 },
468b867f
KK
2862 }
2863 }
2864 }
2865 result = create_prefix_lists(tgen, input_dict_2)
787e7624 2866 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2867
2868 # Create route map
2869 for addr_type in ADDR_TYPES:
2870 input_dict_3 = {
787e7624 2871 "r3": {
2872 "route_maps": {
2873 "rmap_match_pf_1_{}".format(addr_type): [
2874 {
2875 "action": "permit",
2876 "match": {
2877 addr_type: {
2878 "prefix_lists": "pf_list_1_{}".format(addr_type)
2879 }
2880 },
2881 "set": {"locPrf": 150, "weight": 100, "metric": 50},
2882 }
2883 ]
2884 }
468b867f
KK
2885 }
2886 }
468b867f 2887 result = create_route_maps(tgen, input_dict_3)
b9f80297 2888 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2889 tc_name, result
2890 )
468b867f
KK
2891
2892 # Configure neighbor for route map
2893 input_dict_4 = {
787e7624 2894 "r3": {
2895 "bgp": {
2896 "address_family": {
2897 "ipv4": {
2898 "unicast": {
2899 "neighbor": {
2900 "r1": {
2901 "dest_link": {
2902 "r3": {
2903 "route_maps": [
2904 {
2905 "name": "rmap_match_pf_1_ipv4",
2906 "direction": "in",
2907 }
2908 ]
2909 }
2910 }
2911 }
2912 }
2913 }
2914 },
2915 "ipv6": {
2916 "unicast": {
2917 "neighbor": {
2918 "r1": {
2919 "dest_link": {
2920 "r3": {
2921 "route_maps": [
2922 {
2923 "name": "rmap_match_pf_1_ipv6",
2924 "direction": "in",
2925 }
2926 ]
2927 }
2928 }
2929 }
2930 }
2931 }
2932 },
2933 }
2934 }
2935 }
2936 }
468b867f 2937 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 2938 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
2939
2940 # Verifying RIB routes
b9f80297
KK
2941 dut = "r3"
2942 protocol = "bgp"
468b867f
KK
2943 input_dict = topo["routers"]
2944 for addr_type in ADDR_TYPES:
2945 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 2946 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2947 tc_name, result
2948 )
468b867f
KK
2949
2950 # Verifying BGP set attributes
b9f80297 2951 dut = "r3"
468b867f 2952 routes = {
787e7624 2953 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
2954 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
2955 }
2956
2957 rmap_name = "rmap_match_pf_1"
2958 for addr_type in ADDR_TYPES:
2959 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 2960 result = verify_bgp_attributes(
2961 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
2962 )
b9f80297 2963 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 2964 tc_name, result
2965 )
468b867f
KK
2966
2967 write_test_footer(tc_name)
2968
2969 # Uncomment next line for debugging
2970 # tgen.mininet_cli()
2971
2972
2973def test_route_maps_with_continue_clause_p0():
2974 """
2975 TC_54:
2976 Verify route-maps continue clause functionality.
2977 """
2978 tgen = get_topogen()
2979 global bgp_convergence
2980
2981 if bgp_convergence is not True:
b9f80297 2982 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
2983
2984 # test case name
2985 tc_name = inspect.stack()[0][3]
2986 write_test_header(tc_name)
2987 reset_config_on_routers(tgen)
2988
2989 # Create ip prefix list
2990 input_dict_2 = {
b9f80297
KK
2991 "r3": {
2992 "prefix_lists": {
2993 "ipv4": {
787e7624 2994 "pf_list_1_ipv4": [
2995 {"seqid": 10, "network": "any", "action": "permit"}
2996 ]
2997 },
b9f80297 2998 "ipv6": {
787e7624 2999 "pf_list_1_ipv6": [
3000 {"seqid": 100, "network": "any", "action": "permit"}
3001 ]
3002 },
468b867f
KK
3003 }
3004 }
3005 }
3006 result = create_prefix_lists(tgen, input_dict_2)
787e7624 3007 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3008
3009 # Create route map
3010 for addr_type in ADDR_TYPES:
3011 input_dict_3 = {
787e7624 3012 "r3": {
3013 "route_maps": {
3014 "rmap_match_pf_1_{}".format(addr_type): [
3015 {
3016 "action": "permit",
3017 "seq_id": "10",
3018 "match": {
3019 addr_type: {
3020 "prefix_lists": "pf_list_1_{}".format(addr_type)
3021 }
3022 },
3023 "set": {"locPrf": 150},
3024 "continue": "30",
468b867f 3025 },
787e7624 3026 {
3027 "action": "permit",
3028 "seq_id": "20",
3029 "match": {
3030 addr_type: {
3031 "prefix_lists": "pf_list_1_{}".format(addr_type)
3032 }
3033 },
3034 "set": {"metric": 200},
468b867f 3035 },
787e7624 3036 {
3037 "action": "permit",
3038 "seq_id": "30",
3039 "match": {
3040 addr_type: {
3041 "prefix_lists": "pf_list_1_{}".format(addr_type)
3042 }
3043 },
3044 "set": {"metric": 100},
468b867f 3045 },
787e7624 3046 ]
3047 }
468b867f
KK
3048 }
3049 }
468b867f 3050 result = create_route_maps(tgen, input_dict_3)
b9f80297 3051 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3052 tc_name, result
3053 )
468b867f
KK
3054
3055 # Configure neighbor for route map
3056 input_dict_4 = {
787e7624 3057 "r3": {
3058 "bgp": {
3059 "address_family": {
3060 "ipv4": {
3061 "unicast": {
3062 "neighbor": {
3063 "r1": {
3064 "dest_link": {
3065 "r3": {
3066 "route_maps": [
3067 {
3068 "name": "rmap_match_pf_1_ipv4",
3069 "direction": "in",
3070 }
3071 ]
3072 }
3073 }
3074 }
3075 }
3076 }
3077 },
3078 "ipv6": {
3079 "unicast": {
3080 "neighbor": {
3081 "r1": {
3082 "dest_link": {
3083 "r3": {
3084 "route_maps": [
3085 {
3086 "name": "rmap_match_pf_1_ipv6",
3087 "direction": "in",
3088 }
3089 ]
3090 }
3091 }
3092 }
3093 }
3094 }
3095 },
3096 }
3097 }
3098 }
3099 }
468b867f 3100 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 3101 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3102
3103 # Verifying RIB routes
b9f80297
KK
3104 dut = "r3"
3105 protocol = "bgp"
468b867f
KK
3106 input_dict = topo["routers"]
3107 for addr_type in ADDR_TYPES:
787e7624 3108 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 3109 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3110 tc_name, result
3111 )
468b867f
KK
3112
3113 # Verifying BGP set attributes
b9f80297 3114 dut = "r3"
468b867f
KK
3115 rmap_name = "rmap_match_pf_1"
3116 routes = {
787e7624 3117 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3118 "ipv6": ["1::1/128", "1::2/128"],
468b867f 3119 }
787e7624 3120 seq_id = {"ipv4": ["10", "30"], "ipv6": ["10", "30"]}
468b867f
KK
3121 for addr_type in ADDR_TYPES:
3122 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 3123 result = verify_bgp_attributes(
3124 tgen,
3125 addr_type,
3126 dut,
3127 routes[addr_type],
3128 rmap_name,
3129 input_dict_3,
3130 seq_id[addr_type],
3131 )
3132 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3133 tc_name, result
3134 )
468b867f
KK
3135
3136 write_test_footer(tc_name)
3137
3138 # Uncomment next line for debugging
3139 # tgen.mininet_cli()
3140
3141
3142def test_route_maps_with_goto_clause_p0():
3143 """
3144 TC_55:
3145 Verify route-maps goto clause functionality.
3146 """
3147 tgen = get_topogen()
3148 global bgp_convergence
3149
3150 if bgp_convergence is not True:
b9f80297 3151 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
3152
3153 # test case name
3154 tc_name = inspect.stack()[0][3]
3155 write_test_header(tc_name)
3156 reset_config_on_routers(tgen)
3157
3158 # Create ip prefix list
3159 input_dict_2 = {
b9f80297
KK
3160 "r3": {
3161 "prefix_lists": {
3162 "ipv4": {
787e7624 3163 "pf_list_1_ipv4": [
3164 {"seqid": 10, "network": "any", "action": "permit"}
3165 ]
3166 },
b9f80297 3167 "ipv6": {
787e7624 3168 "pf_list_1_ipv6": [
3169 {"seqid": 100, "network": "any", "action": "permit"}
3170 ]
3171 },
468b867f
KK
3172 }
3173 }
3174 }
3175 result = create_prefix_lists(tgen, input_dict_2)
787e7624 3176 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3177
3178 # Create route map
3179 for addr_type in ADDR_TYPES:
3180 input_dict_3 = {
787e7624 3181 "r3": {
3182 "route_maps": {
3183 "rmap_match_pf_1_{}".format(addr_type): [
3184 {
3185 "action": "permit",
3186 "seq_id": "10",
3187 "match": {
3188 addr_type: {
3189 "prefix_lists": "pf_list_1_{}".format(addr_type)
3190 }
3191 },
3192 "goto": "30",
3193 },
3194 {
3195 "action": "permit",
3196 "seq_id": "20",
3197 "match": {
3198 addr_type: {
3199 "prefix_lists": "pf_list_1_{}".format(addr_type)
3200 }
3201 },
3202 "set": {"metric": 100},
3203 },
3204 {
3205 "action": "permit",
3206 "seq_id": "30",
3207 "match": {
3208 addr_type: {
3209 "prefix_lists": "pf_list_1_{}".format(addr_type)
3210 }
3211 },
3212 "set": {"metric": 200},
3213 },
3214 ]
3215 }
3216 }
3217 }
3218 result = create_route_maps(tgen, input_dict_3)
3219 # tgen.mininet_cli()
3220 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3221 tc_name, result
3222 )
3223
3224 # Configure neighbor for route map
3225 input_dict_4 = {
468b867f 3226 "r3": {
787e7624 3227 "bgp": {
3228 "address_family": {
3229 "ipv4": {
3230 "unicast": {
3231 "neighbor": {
3232 "r1": {
3233 "dest_link": {
3234 "r3": {
3235 "route_maps": [
3236 {
3237 "name": "rmap_match_pf_1_ipv4",
3238 "direction": "in",
3239 }
3240 ]
3241 }
3242 }
3243 }
3244 }
468b867f 3245 }
468b867f 3246 },
787e7624 3247 "ipv6": {
3248 "unicast": {
3249 "neighbor": {
3250 "r1": {
3251 "dest_link": {
3252 "r3": {
3253 "route_maps": [
3254 {
3255 "name": "rmap_match_pf_1_ipv6",
3256 "direction": "in",
3257 }
3258 ]
3259 }
3260 }
3261 }
3262 }
468b867f
KK
3263 }
3264 },
787e7624 3265 }
468b867f
KK
3266 }
3267 }
787e7624 3268 }
468b867f 3269 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 3270 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3271
3272 # Verifying RIB routes
b9f80297
KK
3273 dut = "r3"
3274 protocol = "bgp"
468b867f
KK
3275 input_dict = topo["routers"]
3276 for addr_type in ADDR_TYPES:
3277 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 3278 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3279 tc_name, result
3280 )
468b867f
KK
3281
3282 # Verifying BGP set attributes
b9f80297 3283 dut = "r3"
468b867f
KK
3284 rmap_name = "rmap_match_pf_1"
3285 routes = {
787e7624 3286 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3287 "ipv6": ["1::1/128", "1::2/128"],
468b867f 3288 }
787e7624 3289 seq_id = {"ipv4": ["10", "30"], "ipv6": ["10", "30"]}
468b867f
KK
3290 for addr_type in ADDR_TYPES:
3291 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 3292 result = verify_bgp_attributes(
3293 tgen,
3294 addr_type,
3295 dut,
3296 routes[addr_type],
3297 rmap_name,
3298 input_dict_3,
3299 seq_id[addr_type],
3300 )
3301 assert result is True, "Testcase {} : Failed \n Error: {}".format(
3302 tc_name, result
3303 )
468b867f
KK
3304
3305 write_test_footer(tc_name)
3306
3307 # Uncomment next line for debugging
3308 # tgen.mininet_cli()
3309
3310
3311def test_route_maps_with_call_clause_p0():
3312 """
3313 TC_53:
3314 Verify route-maps call clause functionality.
3315 """
3316 tgen = get_topogen()
3317 global bgp_convergence
3318
3319 if bgp_convergence is not True:
b9f80297 3320 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
3321
3322 # test case name
3323 tc_name = inspect.stack()[0][3]
3324 write_test_header(tc_name)
3325 reset_config_on_routers(tgen)
3326
3327 # Create ip prefix list
3328 input_dict_2 = {
b9f80297
KK
3329 "r3": {
3330 "prefix_lists": {
3331 "ipv4": {
787e7624 3332 "pf_list_1_ipv4": [
3333 {"seqid": 10, "network": "any", "action": "permit"}
3334 ]
3335 },
b9f80297 3336 "ipv6": {
787e7624 3337 "pf_list_1_ipv6": [
3338 {"seqid": 100, "network": "any", "action": "permit"}
3339 ]
3340 },
468b867f
KK
3341 }
3342 }
3343 }
3344 result = create_prefix_lists(tgen, input_dict_2)
787e7624 3345 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3346
3347 # Create route map
3348 for addr_type in ADDR_TYPES:
3349 input_dict_3 = {
787e7624 3350 "r3": {
3351 "route_maps": {
3352 "rmap_match_pf_1_{}".format(addr_type): [
3353 {
3354 "action": "permit",
3355 "match": {
3356 addr_type: {
3357 "prefix_lists": "pf_list_1_{}".format(addr_type)
3358 }
3359 },
3360 "set": {"locPrf": 150},
3361 "call": "rmap_match_pf_2_{}".format(addr_type),
3362 }
3363 ],
3364 "rmap_match_pf_2_{}".format(addr_type): [
3365 {
3366 "action": "permit",
3367 "match": {
3368 addr_type: {
3369 "prefix_lists": "pf_list_1_{}".format(addr_type)
3370 }
3371 },
3372 "set": {"metric": 200},
3373 }
3374 ],
3375 }
468b867f
KK
3376 }
3377 }
468b867f 3378 result = create_route_maps(tgen, input_dict_3)
b9f80297 3379 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3380 tc_name, result
3381 )
468b867f
KK
3382
3383 # Configure neighbor for route map
3384 input_dict_4 = {
787e7624 3385 "r3": {
3386 "bgp": {
3387 "address_family": {
3388 "ipv4": {
3389 "unicast": {
3390 "neighbor": {
3391 "r1": {
3392 "dest_link": {
3393 "r3": {
3394 "route_maps": [
3395 {
3396 "name": "rmap_match_pf_1_ipv4",
3397 "direction": "in",
3398 }
3399 ]
3400 }
3401 }
3402 }
3403 }
3404 }
3405 },
3406 "ipv6": {
3407 "unicast": {
3408 "neighbor": {
3409 "r1": {
3410 "dest_link": {
3411 "r3": {
3412 "route_maps": [
3413 {
3414 "name": "rmap_match_pf_1_ipv6",
3415 "direction": "in",
3416 }
3417 ]
3418 }
3419 }
3420 }
3421 }
3422 }
3423 },
3424 }
3425 }
3426 }
3427 }
468b867f 3428 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 3429 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3430
3431 # Verifying RIB routes
b9f80297
KK
3432 dut = "r3"
3433 protocol = "bgp"
468b867f
KK
3434 input_dict = topo["routers"]
3435 for addr_type in ADDR_TYPES:
3436 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 3437 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3438 tc_name, result
3439 )
468b867f
KK
3440
3441 # Verifying BGP set attributes
b9f80297 3442 dut = "r3"
468b867f 3443 routes = {
787e7624 3444 "ipv4": ["10.0.20.1/32", "10.0.20.2/32"],
3445 "ipv6": ["1::1/128", "1::2/128"],
468b867f
KK
3446 }
3447 rmap_name = "rmap_match_pf_1"
3448 for addr_type in ADDR_TYPES:
3449 rmap_name = "rmap_match_pf_1_{}".format(addr_type)
787e7624 3450 result = verify_bgp_attributes(
3451 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
3452 )
b9f80297 3453 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3454 tc_name, result
3455 )
468b867f
KK
3456
3457 rmap_name = "rmap_match_pf_2"
3458 for addr_type in ADDR_TYPES:
3459 rmap_name = "rmap_match_pf_2_{}".format(addr_type)
787e7624 3460 result = verify_bgp_attributes(
3461 tgen, addr_type, dut, routes[addr_type], rmap_name, input_dict_3
3462 )
b9f80297 3463 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3464 tc_name, result
3465 )
468b867f
KK
3466
3467 write_test_footer(tc_name)
3468
3469 # Uncomment next line for debugging
3470 # tgen.mininet_cli()
3471
3472
3473def test_create_rmap_match_prefix_list_to_deny_in_and_outbound_prefixes_p0():
3474 """
3475 TC_58:
3476 Create route map deny inbound and outbound prefixes on
3477 match prefix list and set criteria on match
3478 """
3479 tgen = get_topogen()
3480 global bgp_convergence
3481
3482 if bgp_convergence is not True:
b9f80297 3483 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
3484
3485 # test case name
3486 tc_name = inspect.stack()[0][3]
3487 write_test_header(tc_name)
3488 reset_config_on_routers(tgen)
3489
3490 # Create ip prefix list
3491 input_dict_2 = {
b9f80297
KK
3492 "r3": {
3493 "prefix_lists": {
3494 "ipv4": {
787e7624 3495 "pf_list_1_ipv4": [
3496 {"seqid": 10, "network": "any", "action": "permit"}
3497 ]
3498 },
b9f80297 3499 "ipv6": {
787e7624 3500 "pf_list_1_ipv6": [
3501 {"seqid": 100, "network": "any", "action": "permit"}
3502 ]
3503 },
468b867f
KK
3504 }
3505 }
3506 }
3507 result = create_prefix_lists(tgen, input_dict_2)
787e7624 3508 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3509
3510 # Create route map
3511 for addr_type in ADDR_TYPES:
3512 input_dict_3 = {
787e7624 3513 "r3": {
3514 "route_maps": {
3515 "rmap_match_pf_1_{}".format(addr_type): [
3516 {
3517 "action": "deny",
3518 "match": {
3519 addr_type: {
3520 "prefix_lists": "pf_list_1_{}".format(addr_type)
3521 }
3522 },
9fa6ec14 3523 "set": {
3524 "locPrf": 150,
3525 },
787e7624 3526 }
3527 ],
3528 "rmap_match_pf_2_{}".format(addr_type): [
3529 {
3530 "action": "deny",
3531 "match": {
3532 addr_type: {
3533 "prefix_lists": "pf_list_1_{}".format(addr_type)
3534 }
3535 },
3536 "set": {"metric": 50},
3537 }
3538 ],
3539 }
468b867f
KK
3540 }
3541 }
468b867f 3542 result = create_route_maps(tgen, input_dict_3)
b9f80297 3543 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3544 tc_name, result
3545 )
468b867f
KK
3546
3547 # Configure neighbor for route map
3548 input_dict_4 = {
787e7624 3549 "r3": {
3550 "bgp": {
3551 "address_family": {
3552 "ipv4": {
3553 "unicast": {
3554 "neighbor": {
3555 "r1": {
3556 "dest_link": {
3557 "r3": {
3558 "route_maps": [
3559 {
3560 "name": "rmap_match_pf_1_ipv4",
3561 "direction": "in",
3562 }
3563 ]
3564 }
3565 }
3566 },
3567 "r4": {
3568 "dest_link": {
3569 "r3": {
3570 "route_maps": [
3571 {
3572 "name": "rmap_match_pf_2_ipv6",
3573 "direction": "out",
3574 }
3575 ]
3576 }
3577 }
3578 },
3579 }
3580 }
3581 },
3582 "ipv6": {
3583 "unicast": {
3584 "neighbor": {
3585 "r1": {
3586 "dest_link": {
3587 "r3": {
3588 "route_maps": [
3589 {
3590 "name": "rmap_match_pf_1_ipv4",
3591 "direction": "in",
3592 }
3593 ]
3594 }
3595 }
3596 },
3597 "r4": {
3598 "dest_link": {
3599 "r3": {
3600 "route_maps": [
3601 {
3602 "name": "rmap_match_pf_2_ipv6",
3603 "direction": "out",
3604 }
3605 ]
3606 }
3607 }
3608 },
3609 }
3610 }
3611 },
3612 }
3613 }
3614 }
3615 }
468b867f 3616 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 3617 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3618
3619 # Verifying RIB routes
b9f80297
KK
3620 dut = "r3"
3621 protocol = "bgp"
468b867f
KK
3622 input_dict = topo["routers"]
3623 for addr_type in ADDR_TYPES:
787e7624 3624 result = verify_rib(
3625 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
3626 )
84ab3836
KK
3627 assert result is not True, (
3628 "Testcase {} : Failed \n "
d63c7094 3629 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
3630 "Found: {}".format(tc_name, dut, result)
3631 )
468b867f
KK
3632
3633 # Verifying RIB routes
b9f80297
KK
3634 dut = "r4"
3635 protocol = "bgp"
468b867f 3636 for addr_type in ADDR_TYPES:
787e7624 3637 result = verify_rib(
3638 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
3639 )
84ab3836
KK
3640 assert result is not True, (
3641 "Testcase {} : Failed \n "
d63c7094 3642 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
3643 "Found: {}".format(tc_name, dut, result)
3644 )
468b867f
KK
3645
3646 write_test_footer(tc_name)
3647
3648 # Uncomment next line for debugging
3649 # tgen.mininet_cli()
3650
3651
3652def test_create_rmap_to_match_tag_permit_inbound_prefixes_p0():
3653 """
3654 TC_59:
3655 Create route map to permit inbound prefixes with filter
3656 match tag and set criteria
3657 """
3658 tgen = get_topogen()
3659 global bgp_convergence
3660
3661 if bgp_convergence is not True:
b9f80297 3662 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
3663
3664 # test case name
3665 tc_name = inspect.stack()[0][3]
3666 write_test_header(tc_name)
3667 reset_config_on_routers(tgen)
3668
3669 for addr_type in ADDR_TYPES:
3670 # Create Static routes
3671 input_dict = {
3672 "r1": {
3673 "static_routes": [
787e7624 3674 {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001}
468b867f
KK
3675 ]
3676 }
3677 }
3678
3679 result = create_static_routes(tgen, input_dict)
3680 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3681 tc_name, result
3682 )
468b867f
KK
3683
3684 # Api call to redistribute static routes
3685 input_dict_1 = {
3686 "r1": {
3687 "bgp": {
3688 "local_as": 100,
3689 "address_family": {
3690 "ipv4": {
3691 "unicast": {
3692 "redistribute": [
3693 {"redist_type": "static"},
787e7624 3694 {"redist_type": "connected"},
468b867f
KK
3695 ]
3696 }
3697 },
3698 "ipv6": {
3699 "unicast": {
3700 "redistribute": [
3701 {"redist_type": "static"},
787e7624 3702 {"redist_type": "connected"},
468b867f
KK
3703 ]
3704 }
787e7624 3705 },
3706 },
468b867f
KK
3707 }
3708 }
3709 }
3710
3711 result = create_router_bgp(tgen, topo, input_dict_1)
3712 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3713 tc_name, result
3714 )
468b867f
KK
3715
3716 # Create route map
3717 input_dict_3 = {
787e7624 3718 "r1": {
3719 "route_maps": {
3720 "rmap_match_tag_1_{}".format(addr_type): [
3721 {"action": "permit", "match": {addr_type: {"tag": "4001"}}}
3722 ]
3723 }
468b867f
KK
3724 }
3725 }
468b867f 3726 result = create_route_maps(tgen, input_dict_3)
b9f80297 3727 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3728 tc_name, result
3729 )
468b867f
KK
3730
3731 # Configure neighbor for route map
3732 input_dict_4 = {
787e7624 3733 "r1": {
3734 "bgp": {
3735 "address_family": {
3736 "ipv4": {
3737 "unicast": {
3738 "neighbor": {
3739 "r3": {
3740 "dest_link": {
3741 "r1": {
3742 "route_maps": [
3743 {
3744 "name": "rmap_match_tag_1_ipv4",
3745 "direction": "out",
3746 }
3747 ]
3748 }
3749 }
3750 }
3751 }
3752 }
3753 },
3754 "ipv6": {
3755 "unicast": {
3756 "neighbor": {
3757 "r3": {
3758 "dest_link": {
3759 "r1": {
3760 "route_maps": [
3761 {
3762 "name": "rmap_match_tag_1_ipv6",
3763 "direction": "out",
3764 }
3765 ]
3766 }
3767 }
3768 }
3769 }
3770 }
3771 },
3772 }
3773 }
3774 }
3775 }
468b867f 3776 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 3777 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3778
3779 # Verifying RIB routes
b9f80297
KK
3780 dut = "r3"
3781 protocol = "bgp"
468b867f
KK
3782
3783 for addr_type in ADDR_TYPES:
3784 input_dict = {
3785 "r1": {
3786 "static_routes": [
787e7624 3787 {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001}
468b867f
KK
3788 ]
3789 }
3790 }
787e7624 3791 result = verify_rib(tgen, addr_type, dut, input_dict, protocol=protocol)
b9f80297 3792 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3793 tc_name, result
3794 )
468b867f
KK
3795
3796 write_test_footer(tc_name)
3797
3798 # Uncomment next line for debugging
3799 # tgen.mininet_cli()
3800
3801
3802def test_create_rmap_to_match_tag_deny_outbound_prefixes_p0():
3803 """
3804 TC_60
3805 Create route map to deny outbound prefixes with filter match tag,
3806 and set criteria
3807 """
3808 tgen = get_topogen()
3809 global bgp_convergence
3810
3811 if bgp_convergence is not True:
b9f80297 3812 pytest.skip("skipped because of BGP Convergence failure")
468b867f
KK
3813
3814 # test case name
3815 tc_name = inspect.stack()[0][3]
3816 write_test_header(tc_name)
3817 reset_config_on_routers(tgen)
3818
3819 for addr_type in ADDR_TYPES:
3820 # Create Static routes
3821 input_dict = {
3822 "r1": {
3823 "static_routes": [
787e7624 3824 {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001}
468b867f
KK
3825 ]
3826 }
3827 }
3828
3829 result = create_static_routes(tgen, input_dict)
3830 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3831 tc_name, result
3832 )
468b867f
KK
3833
3834 # Api call to redistribute static routes
3835 input_dict_1 = {
3836 "r1": {
3837 "bgp": {
3838 "local_as": 100,
3839 "address_family": {
3840 "ipv4": {
3841 "unicast": {
3842 "redistribute": [
3843 {"redist_type": "static"},
787e7624 3844 {"redist_type": "connected"},
468b867f
KK
3845 ]
3846 }
3847 },
3848 "ipv6": {
3849 "unicast": {
3850 "redistribute": [
3851 {"redist_type": "static"},
787e7624 3852 {"redist_type": "connected"},
468b867f
KK
3853 ]
3854 }
787e7624 3855 },
3856 },
468b867f
KK
3857 }
3858 }
3859 }
3860
3861 result = create_router_bgp(tgen, topo, input_dict_1)
3862 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3863 tc_name, result
3864 )
468b867f
KK
3865
3866 # Create route map
3867 input_dict_3 = {
787e7624 3868 "r1": {
3869 "route_maps": {
3870 "rmap_match_tag_1_{}".format(addr_type): [
3871 {"action": "deny", "match": {addr_type: {"tag": "4001"}}}
3872 ]
3873 }
468b867f
KK
3874 }
3875 }
468b867f 3876 result = create_route_maps(tgen, input_dict_3)
b9f80297 3877 assert result is True, "Testcase {} : Failed \n Error: {}".format(
787e7624 3878 tc_name, result
3879 )
468b867f
KK
3880
3881 # Configure neighbor for route map
3882 input_dict_4 = {
787e7624 3883 "r1": {
3884 "bgp": {
3885 "address_family": {
3886 "ipv4": {
3887 "unicast": {
3888 "neighbor": {
3889 "r3": {
3890 "dest_link": {
3891 "r1": {
3892 "route_maps": [
3893 {
3894 "name": "rmap_match_tag_1_ipv4",
3895 "direction": "out",
3896 }
3897 ]
3898 }
3899 }
3900 }
3901 }
3902 }
3903 },
3904 "ipv6": {
3905 "unicast": {
3906 "neighbor": {
3907 "r3": {
3908 "dest_link": {
3909 "r1": {
3910 "route_maps": [
3911 {
3912 "name": "rmap_match_tag_1_ipv6",
3913 "direction": "out",
3914 }
3915 ]
3916 }
3917 }
3918 }
3919 }
3920 }
3921 },
3922 }
3923 }
3924 }
468b867f
KK
3925 }
3926 result = create_router_bgp(tgen, topo, input_dict_4)
787e7624 3927 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
468b867f
KK
3928
3929 # Verifying RIB routes
b9f80297
KK
3930 dut = "r3"
3931 protocol = "bgp"
468b867f
KK
3932
3933 for addr_type in ADDR_TYPES:
3934 input_dict = {
3935 "r1": {
3936 "static_routes": [
787e7624 3937 {"network": NETWORK[addr_type], "next_hop": "Null0", "tag": 4001}
468b867f
KK
3938 ]
3939 }
3940 }
787e7624 3941 result = verify_rib(
3942 tgen, addr_type, dut, input_dict, protocol=protocol, expected=False
3943 )
84ab3836
KK
3944 assert result is not True, (
3945 "Testcase {} : Failed \n "
d63c7094 3946 "Expected: Routes should not be present in {} FIB \n "
84ab3836
KK
3947 "Found: {}".format(tc_name, dut, result)
3948 )
468b867f
KK
3949
3950 write_test_footer(tc_name)
3951
3952 # Uncomment next line for debugging
3953 # tgen.mininet_cli()
3954
787e7624 3955
b9f80297 3956if __name__ == "__main__":
468b867f
KK
3957 args = ["-s"] + sys.argv[1:]
3958 sys.exit(pytest.main(args))