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