]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/static_routing_with_ebgp/test_static_routes_topo2_ebgp.py
*: manual SPDX License ID conversions
[mirror_frr.git] / tests / topotests / static_routing_with_ebgp / test_static_routes_topo2_ebgp.py
CommitLineData
0705f312 1#!/usr/bin/python
2
3#
4# Copyright (c) 2020 by VMware, Inc. ("VMware")
5# Used Copyright (c) 2018 by Network Device Education Foundation,
6# Inc. ("NetDEF") in this file.
7#
8# Permission to use, copy, modify, and/or distribute this software
9# for any purpose with or without fee is hereby granted, provided
10# that the above copyright notice and this permission notice appear
11# in all copies.
12#
13# THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
14# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
16# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
17# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
18# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
19# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20# OF THIS SOFTWARE.
21#
22
23
24"""
25 -Verify static route functionality with 8 next hop different AD value
26 and BGP ECMP
27
28 -Verify 8 static route functionality with 8 next hop different AD
29
30 -Verify static route with 8 next hop with different AD value and 8
31 EBGP neighbors
32
33 -Verify static route with 8 next hop with different AD value and 8
34 IBGP neighbors
35
36 -Delete the static route and verify the RIB and FIB state
37
38 -Verify 8 static route functionality with 8 ECMP next hop
39"""
40import sys
0705f312 41import time
42import os
43import pytest
d33a0fcf 44import platform
0705f312 45import random
d33a0fcf 46from lib.topotest import version_cmp
0705f312 47
48# Save the Current Working Directory to find configuration files.
49CWD = os.path.dirname(os.path.realpath(__file__))
50sys.path.append(os.path.join(CWD, "../"))
51sys.path.append(os.path.join(CWD, "../lib/"))
52# pylint: disable=C0413
53# Import topogen and topotest helpers
0705f312 54from lib.topogen import Topogen, get_topogen
55
56# Import topoJson from lib, to create topology and initial configuration
57from lib.common_config import (
58 start_topology,
59 write_test_header,
60 write_test_footer,
61 reset_config_on_routers,
62 verify_rib,
63 create_static_routes,
64 check_address_types,
65 step,
0705f312 66 shutdown_bringup_interface,
67 stop_router,
68 start_router,
69)
70from lib.topolog import logger
71from lib.bgp import verify_bgp_convergence, create_router_bgp, verify_bgp_rib
4953ca97 72from lib.topojson import build_config_from_json
0705f312 73
efb62eed
DS
74pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
75
0705f312 76# Global variables
77BGP_CONVERGENCE = False
78ADDR_TYPES = check_address_types()
79NETWORK = {
80 "ipv4": [
81 "11.0.20.1/32",
82 "11.0.20.2/32",
83 "11.0.20.3/32",
84 "11.0.20.4/32",
85 "11.0.20.5/32",
86 "11.0.20.6/32",
87 "11.0.20.7/32",
88 "11.0.20.8/32",
89 ],
90 "ipv6": [
91 "2::1/128",
92 "2::2/128",
93 "2::3/128",
94 "2::4/128",
95 "2::5/128",
96 "2::6/128",
97 "2::7/128",
98 "2::8/128",
99 ],
100}
101PREFIX1 = {"ipv4": "110.0.20.1/32", "ipv6": "20::1/128"}
102PREFIX2 = {"ipv4": "110.0.20.2/32", "ipv6": "20::2/128"}
103NEXT_HOP_IP = []
104topo_diag = """
105 Please view in a fixed-width font such as Courier.
106 +------+ +------+ +------+
107 | +--------------+ +--------------+ |
108 | | | | | |
109 | R1 +---8 links----+ R2 +---8 links----+ R3 |
110 | | | | | |
111 | +--------------+ +--------------+ |
112 +------+ +------+ +------+
113
114"""
115
116
0705f312 117def setup_module(mod):
118 """
119
120 Set up the pytest environment.
121
122 * `mod`: module name
123 """
0705f312 124 testsuite_run_time = time.asctime(time.localtime(time.time()))
125 logger.info("Testsuite start time: {}".format(testsuite_run_time))
126 logger.info("=" * 40)
127
128 logger.info("Running setup_module to create topology")
129
130 # This function initiates the topology build with Topogen...
e82b531d
CH
131 json_file = "{}/static_routes_topo2_ebgp.json".format(CWD)
132 tgen = Topogen(json_file, mod.__name__)
133 global topo
134 topo = tgen.json_topo
0705f312 135 # ... and here it calls Mininet initialization functions.
136
137 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 138 # to start daemons and then start routers
0705f312 139 start_topology(tgen)
140
141 # Creating configuration from JSON
142 build_config_from_json(tgen, topo)
143
5980ad0a
DS
144 if version_cmp(platform.release(), "4.19") < 0:
145 error_msg = (
146 'These tests will not run. (have kernel "{}", '
147 "requires kernel >= 4.19)".format(platform.release())
148 )
d33a0fcf 149 pytest.skip(error_msg)
150
0705f312 151 # Checking BGP convergence
152 global BGP_CONVERGENCE
153 global ADDR_TYPES
154 # Don't run this test if we have any failure.
155 if tgen.routers_have_failure():
156 pytest.skip(tgen.errors)
157 # Api call verify whether BGP is converged
158 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
159 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
160 BGP_CONVERGENCE
161 )
162
163 logger.info("Running setup_module() done")
164
165
166def teardown_module(mod):
167 """
168 Teardown the pytest environment
169
170 * `mod`: module name
171 """
172
173 logger.info("Running teardown_module to delete topology")
174
175 tgen = get_topogen()
176
177 # Stop toplogy and Remove tmp files
178 tgen.stop_topology()
179
180 logger.info(
181 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
182 )
183 logger.info("=" * 40)
184
185
186def populate_nh():
187 NEXT_HOP_IP = {
188 "nh1": {
189 "ipv4": topo["routers"]["r1"]["links"]["r2-link0"]["ipv4"].split("/")[0],
190 "ipv6": topo["routers"]["r1"]["links"]["r2-link0"]["ipv6"].split("/")[0],
191 },
192 "nh2": {
193 "ipv4": topo["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0],
194 "ipv6": topo["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0],
195 },
196 "nh3": {
197 "ipv4": topo["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0],
198 "ipv6": topo["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0],
199 },
200 "nh4": {
201 "ipv4": topo["routers"]["r1"]["links"]["r2-link3"]["ipv4"].split("/")[0],
202 "ipv6": topo["routers"]["r1"]["links"]["r2-link3"]["ipv6"].split("/")[0],
203 },
204 "nh5": {
205 "ipv4": topo["routers"]["r1"]["links"]["r2-link4"]["ipv4"].split("/")[0],
206 "ipv6": topo["routers"]["r1"]["links"]["r2-link4"]["ipv6"].split("/")[0],
207 },
208 "nh6": {
209 "ipv4": topo["routers"]["r1"]["links"]["r2-link5"]["ipv4"].split("/")[0],
210 "ipv6": topo["routers"]["r1"]["links"]["r2-link5"]["ipv6"].split("/")[0],
211 },
212 "nh7": {
213 "ipv4": topo["routers"]["r1"]["links"]["r2-link6"]["ipv4"].split("/")[0],
214 "ipv6": topo["routers"]["r1"]["links"]["r2-link6"]["ipv6"].split("/")[0],
215 },
216 "nh8": {
217 "ipv4": topo["routers"]["r1"]["links"]["r2-link7"]["ipv4"].split("/")[0],
218 "ipv6": topo["routers"]["r1"]["links"]["r2-link7"]["ipv6"].split("/")[0],
219 },
220 }
221 return NEXT_HOP_IP
222
223
224#####################################################
225#
226# Testcases
227#
228#####################################################
229
230
231def test_static_rte_with_8ecmp_nh_p1_tc9_ebgp(request):
232 """
233 Verify 8 static route functionality with 8 ECMP next hop
234
235 """
236 tc_name = request.node.name
237 write_test_header(tc_name)
238 tgen = get_topogen()
239 # Don't run this test if we have any failure.
240 if tgen.routers_have_failure():
241 pytest.skip(tgen.errors)
242 NEXT_HOP_IP = populate_nh()
243 step("Configure 8 interfaces / links between R1 and R2")
244 step("Configure 8 interfaces / links between R2 and R3")
245 step("Configure 8 IBGP IPv4 peering between R2 and R3 router.")
246 reset_config_on_routers(tgen)
247
248 step(
249 "Configure 8 IPv4 static route in R2 with 8 next hop"
250 "N1(21.1.1.2) , N2(22.1.1.2) , N3(23.1.1.2) , N4(24.1.1.2) ,"
251 "N5(25.1.1.2) , N6(26.1.1.2) , N7(27.1.1.2) , N8(28.1.1.2) ,"
252 "Static route next-hop present on R1"
253 )
254 nh_all = {}
255 for addr_type in ADDR_TYPES:
256 # Enable static routes
257 for nhp in range(1, 9):
258 input_dict_4 = {
259 "r2": {
260 "static_routes": [
261 {
262 "network": PREFIX1[addr_type],
263 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
264 }
265 ]
266 }
267 }
268 logger.info("Configure static routes")
269 result = create_static_routes(tgen, input_dict_4)
270 assert result is True, "Testcase {} : Failed \n Error: {}".format(
271 tc_name, result
272 )
273 logger.info("Verifying %s routes on r2", addr_type)
274 nh_all[addr_type] = [
275 NEXT_HOP_IP["nh1"][addr_type],
276 NEXT_HOP_IP["nh2"][addr_type],
277 NEXT_HOP_IP["nh3"][addr_type],
278 NEXT_HOP_IP["nh4"][addr_type],
279 NEXT_HOP_IP["nh5"][addr_type],
280 NEXT_HOP_IP["nh6"][addr_type],
281 NEXT_HOP_IP["nh7"][addr_type],
282 NEXT_HOP_IP["nh8"][addr_type],
283 ]
284
285 dut = "r2"
286 protocol = "static"
287 result = verify_rib(
288 tgen,
289 addr_type,
290 dut,
291 input_dict_4,
292 next_hop=nh_all[addr_type],
293 protocol=protocol,
294 )
d7265db9
MS
295 assert (
296 result is True
297 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 298
299 step("Configure redistribute static in BGP on R2 router")
300 for addr_type in ADDR_TYPES:
301 input_dict_2 = {
302 "r2": {
303 "bgp": {
304 "address_family": {
305 addr_type: {
306 "unicast": {"redistribute": [{"redist_type": "static"}]}
307 }
308 }
309 }
310 }
311 }
312 result = create_router_bgp(tgen, topo, input_dict_2)
313 assert result is True, "Testcase {} : Failed \n Error: {}".format(
314 tc_name, result
315 )
316
317 dut = "r3"
318 protocol = "bgp"
319 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_4)
d7265db9
MS
320 assert (
321 result is True
322 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 323
324 step(
325 "Remove the static route configured with nexthop N1 to N8, one"
326 "by one from running config"
327 )
328 dut = "r2"
329 protocol = "static"
330 step(
331 "After removing the static route with N1 to N8 one by one , "
332 "verify that entry is removed from RIB and FIB of R3 "
333 )
334 for addr_type in ADDR_TYPES:
335 for nhp in range(1, 9):
336 input_dict_4 = {
337 "r2": {
338 "static_routes": [
339 {
340 "network": PREFIX1[addr_type],
341 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
342 "delete": True,
343 }
344 ]
345 }
346 }
347 logger.info("Configure static routes")
348 result = create_static_routes(tgen, input_dict_4)
349 assert result is True, "Testcase {} : Failed \n Error: {}".format(
350 tc_name, result
351 )
352
353 step(
354 "After removing the static route with N1 to N8 one by one , "
355 "verify that entry is removed from RIB and FIB of R3 "
356 )
357 nh = NEXT_HOP_IP["nh" + str(nhp)][addr_type]
358 result = verify_rib(
359 tgen,
360 addr_type,
361 dut,
362 input_dict_4,
363 next_hop=nh,
364 protocol=protocol,
365 expected=False,
366 )
d7265db9
MS
367 assert (
368 result is not True
369 ), "Testcase {} : Failed\nError: Routes is" " still present in RIB".format(
370 tc_name
371 )
0705f312 372
373 step("Configure the static route with nexthop N1 to N8, one by one")
374 for addr_type in ADDR_TYPES:
375 for nhp in range(1, 9):
376 input_dict_4 = {
377 "r2": {
378 "static_routes": [
379 {
380 "network": PREFIX1[addr_type],
381 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
382 }
383 ]
384 }
385 }
386 logger.info("Configure static routes")
387 result = create_static_routes(tgen, input_dict_4)
388 assert result is True, "Testcase {} : Failed \n Error: {}".format(
389 tc_name, result
390 )
391
392 nh = NEXT_HOP_IP["nh" + str(nhp)][addr_type]
393 result = verify_rib(
394 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol
395 )
d7265db9
MS
396 assert (
397 result is True
398 ), "Testcase {} : Failed\nError: Routes are" " missing in RIB".format(
399 tc_name
400 )
0705f312 401
0705f312 402 protocol = "static"
0705f312 403 step("Random shut of the nexthop interfaces")
404 randnum = random.randint(0, 7)
405 # Shutdown interface
406 dut = "r2"
407 step(
408 " interface which is about to be shut no shut between r1 and r2 is " "%s",
409 topo["routers"]["r2"]["links"]["r1-link{}".format(randnum)]["interface"],
410 )
411 intf = topo["routers"]["r2"]["links"]["r1-link{}".format(randnum)]["interface"]
412 shutdown_bringup_interface(tgen, dut, intf, False)
413
0705f312 414 step("Random no shut of the nexthop interfaces")
415 # Bringup interface
416 shutdown_bringup_interface(tgen, dut, intf, True)
417
418 step(
419 "After random shut/no shut of nexthop , only that "
420 "nexthop deleted/added from all the routes , other nexthop remain "
421 "unchanged"
422 )
423 dut = "r2"
424 protocol = "static"
425 for addr_type in ADDR_TYPES:
426 input_dict_4 = {
427 "r2": {
428 "static_routes": [
429 {
430 "network": PREFIX1[addr_type],
431 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
432 }
433 ]
434 }
435 }
436 result = verify_rib(
437 tgen,
438 addr_type,
439 dut,
440 input_dict_4,
441 next_hop=nh_all[addr_type],
442 protocol=protocol,
443 )
d7265db9
MS
444 assert (
445 result is True
446 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 447
448 step("Remove random static route with all the nexthop")
449 dut = "r2"
450 randnum = random.randint(1, 7)
451 for addr_type in ADDR_TYPES:
452 input_dict_4 = {
453 "r2": {
454 "static_routes": [
455 {
456 "network": PREFIX1[addr_type],
457 "next_hop": NEXT_HOP_IP["nh" + str(randnum)][addr_type],
458 "delete": True,
459 }
460 ]
461 }
462 }
463 logger.info("Configure static routes")
464 result = create_static_routes(tgen, input_dict_4)
465 assert result is True, "Testcase {} : Failed \n Error: {}".format(
466 tc_name, result
467 )
468
469 step(
470 "After delete of random route , that route only got deleted from"
471 " RIB/FIB other route are showing properly"
472 )
473 nh = NEXT_HOP_IP["nh{}".format(randnum)][addr_type]
474 result = verify_rib(
475 tgen,
476 addr_type,
477 dut,
478 input_dict_4,
479 next_hop=nh,
480 protocol=protocol,
481 expected=False,
482 )
d7265db9
MS
483 assert (
484 result is not True
485 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 486
487 for addr_type in ADDR_TYPES:
488 input_dict_4 = {
489 "r2": {
490 "static_routes": [
491 {
492 "network": PREFIX1[addr_type],
493 "next_hop": NEXT_HOP_IP["nh" + str(randnum)][addr_type],
494 }
495 ]
496 }
497 }
498 logger.info("Configure static routes")
499 result = create_static_routes(tgen, input_dict_4)
500 assert result is True, "Testcase {} : Failed \n Error: {}".format(
501 tc_name, result
502 )
503
504 step("Reload the FRR router")
505 # stop/start -> restart FRR router and verify
506 stop_router(tgen, "r2")
0705f312 507 start_router(tgen, "r2")
508
509 step(
510 "After reload of FRR router , static route "
511 "installed in RIB and FIB properly ."
512 )
513 for addr_type in ADDR_TYPES:
514 # Enable static routes
515 nhp = 1
516 input_dict_4 = {
517 "r2": {
518 "static_routes": [
519 {
520 "network": PREFIX1[addr_type],
521 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
522 }
523 ]
524 }
525 }
526 logger.info("Verifying %s routes on r2", addr_type)
527 dut = "r2"
528 protocol = "static"
529 result = verify_rib(
530 tgen,
531 addr_type,
532 dut,
533 input_dict_4,
534 next_hop=nh_all[addr_type],
535 protocol=protocol,
536 )
d7265db9
MS
537 assert (
538 result is True
539 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 540
0705f312 541 step("Remove the redistribute static knob")
542 for addr_type in ADDR_TYPES:
543 input_dict_2 = {
544 "r2": {
545 "bgp": {
546 "address_family": {
547 addr_type: {
548 "unicast": {
549 "redistribute": [
550 {"redist_type": "static", "delete": True}
551 ]
552 }
553 }
554 }
555 }
556 }
557 }
558 result = create_router_bgp(tgen, topo, input_dict_2)
559 assert result is True, "Testcase {} : Failed \n Error: {}".format(
560 tc_name, result
561 )
562
563 step(
564 "After removing the BGP neighbor or redistribute static knob , "
565 "verify route got clear from RIB and FIB of R3 routes "
566 )
567 dut = "r3"
568 protocol = "bgp"
569 result = verify_rib(
570 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
571 )
d7265db9
MS
572 assert (
573 result is not True
574 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
575 tc_name
576 )
0705f312 577
578 write_test_footer(tc_name)
579
580
581def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc6_ebgp(request):
582 """
583 Verify static route functionality with 8 next hop different AD
584 value and BGP ECMP
585
586 """
587 tc_name = request.node.name
588 write_test_header(tc_name)
589 tgen = get_topogen()
590 # Don't run this test if we have any failure.
591 if tgen.routers_have_failure():
592 pytest.skip(tgen.errors)
593
594 step("Configure 8 interfaces / links between R1 and R2 ,")
595 step("Configure 8 interlaces/links between R2 and R3")
596 step(
597 "Configure IBGP IPv4 peering over loopback interface between"
598 "R2 and R3 router."
599 )
600 step("Configure redistribute static in BGP on R2 router")
601 reset_config_on_routers(tgen)
602 NEXT_HOP_IP = populate_nh()
603 nh_all = {}
604 for addr_type in ADDR_TYPES:
605 nh_all[addr_type] = []
606 for nhp in range(1, 9):
607 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
608 step(
609 "Configure IPv4 static route in R2 with 8 next hop"
610 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
611 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
612 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
613 "present on R1"
614 )
615 for addr_type in ADDR_TYPES:
616 for nhp in range(1, 9):
617 input_dict_4 = {
618 "r2": {
619 "static_routes": [
620 {
621 "network": PREFIX1[addr_type],
622 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
623 "admin_distance": 10 * nhp,
624 }
625 ]
626 }
627 }
628 logger.info("Configure static routes")
629 result = create_static_routes(tgen, input_dict_4)
630 assert result is True, "Testcase {} : Failed \n Error: {}".format(
631 tc_name, result
632 )
633 logger.info("Verifying %s routes on r2", addr_type)
634
635 step(
636 "On R2, static route installed in RIB using "
637 "show ip route with 8 next hop , lowest AD nexthop is active"
638 )
639 input_dict_4 = {
640 "r2": {
641 "static_routes": [
642 {
643 "network": PREFIX1[addr_type],
644 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
645 "admin_distance": 10,
646 }
647 ]
648 }
649 }
650 dut = "r2"
651 protocol = "static"
652 nh = NEXT_HOP_IP["nh1"][addr_type]
653 result = verify_rib(
654 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
655 )
d7265db9
MS
656 assert (
657 result is True
658 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 659
660 nh = []
661 for nhp in range(2, 9):
662 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
663 result = verify_rib(
664 tgen,
665 addr_type,
666 dut,
667 input_dict_4,
668 next_hop=nh,
669 protocol=protocol,
670 fib=True,
ed776e38 671 retry_timeout=6,
0705f312 672 expected=False,
0705f312 673 )
d7265db9
MS
674 assert (
675 result is not True
676 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
0705f312 677
678 step(
679 "Remove the static route configured with nexthop N1 to N8, one"
680 "by one from running config"
681 )
682
683 for addr_type in ADDR_TYPES:
684 # delete static routes
685 for nhp in range(1, 9):
686 input_dict_4 = {
687 "r2": {
688 "static_routes": [
689 {
690 "network": PREFIX1[addr_type],
691 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
692 "admin_distance": 10 * nhp,
693 "delete": True,
694 }
695 ]
696 }
697 }
698
699 logger.info("Configure static routes")
700 result = create_static_routes(tgen, input_dict_4)
701 assert result is True, "Testcase {} : Failed \n Error: {}".format(
702 tc_name, result
703 )
704
705 step(
706 "After removing the static route with N1 to N8 one by one , "
707 "route become active with next preferred nexthop and nexthop which "
708 "got removed is not shown in RIB and FIB"
709 )
710 result = verify_rib(
711 tgen,
712 addr_type,
713 dut,
714 input_dict_4,
715 next_hop=nh_all[addr_type],
716 protocol=protocol,
717 expected=False,
718 )
d7265db9
MS
719 assert (
720 result is not True
721 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
722 tc_name
723 )
0705f312 724
725 step("Configure the static route with nexthop N1 to N8, one by one")
726
727 for addr_type in ADDR_TYPES:
728 # add static routes
729 for nhp in range(1, 9):
730 input_dict_4 = {
731 "r2": {
732 "static_routes": [
733 {
734 "network": PREFIX1[addr_type],
735 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
736 "admin_distance": 10 * nhp,
737 }
738 ]
739 }
740 }
741 logger.info("Configure static routes")
742 result = create_static_routes(tgen, input_dict_4)
743 assert result is True, "Testcase {} : Failed \n Error: {}".format(
744 tc_name, result
745 )
746
747 step(
748 " After configuring them, route is always active with lowest AD"
749 " value and all the nexthop populated in RIB and FIB again"
750 )
751 for addr_type in ADDR_TYPES:
752 input_dict_4 = {
753 "r2": {
754 "static_routes": [
755 {
756 "network": PREFIX1[addr_type],
757 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
758 "admin_distance": 10,
759 }
760 ]
761 }
762 }
763 dut = "r2"
764 protocol = "static"
765 nh = NEXT_HOP_IP["nh1"][addr_type]
766 result = verify_rib(
767 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
768 )
d7265db9
MS
769 assert (
770 result is True
771 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 772 nh = []
773 for nhp in range(2, 9):
774 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
775 result = verify_rib(
776 tgen,
777 addr_type,
778 dut,
779 input_dict_4,
780 next_hop=nh,
781 protocol=protocol,
782 fib=True,
783 expected=False,
ed776e38 784 retry_timeout=6,
0705f312 785 )
d7265db9
MS
786 assert (
787 result is not True
788 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
0705f312 789
0705f312 790 step("Random shut of the nexthop interfaces")
791 randnum = random.randint(0, 7)
792 for addr_type in ADDR_TYPES:
793 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
794 shutdown_bringup_interface(tgen, dut, intf, False)
795 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
796 input_dict_5 = {
797 "r2": {
798 "static_routes": [
799 {
800 "network": PREFIX1[addr_type],
801 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
802 }
803 ]
804 }
805 }
806 result = verify_rib(
807 tgen,
808 addr_type,
809 dut,
810 input_dict_5,
811 next_hop=nhip,
812 protocol=protocol,
813 expected=False,
814 )
d7265db9
MS
815 assert (
816 result is not True
817 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
818 tc_name
819 )
0705f312 820
821 step("Random no shut of the nexthop interfaces")
822 for addr_type in ADDR_TYPES:
823 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
824 shutdown_bringup_interface(tgen, dut, intf, True)
825 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
826 result = verify_rib(
827 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
828 )
d7265db9
MS
829 assert (
830 result is True
831 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
0705f312 832
833 dut = "r2"
0705f312 834 protocol = "static"
0705f312 835 for addr_type in ADDR_TYPES:
836 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
837 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
838 assert (
839 result is True
840 ), "Testcase {}: Failed \n " "Error: Routes are missing in RIB".format(tc_name)
841
842 protocol = "bgp"
843 dut = "r3"
844 for addr_type in ADDR_TYPES:
845 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
846 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
847 assert (
848 result is True
849 ), "Testcase {}: Failed \n " "Error: Routes are missing in RIB".format(tc_name)
850
851 step("Reload the FRR router")
852 # stop/start -> restart FRR router and verify
853 stop_router(tgen, "r2")
ee51a3d9 854
0705f312 855 start_router(tgen, "r2")
856
857 for addr_type in ADDR_TYPES:
858 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
859 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
5980ad0a
DS
860 assert (
861 result is True
862 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
863 tc_name
0705f312 864 )
865
0705f312 866 write_test_footer(tc_name)
867
868
869def test_static_route_8nh_diff_AD_ebgp_ecmp_p1_tc8_ebgp(request):
870 """
871 Verify static route with 8 next hop with different AD value and 8
872 EBGP neighbors
873 """
874 tc_name = request.node.name
875 write_test_header(tc_name)
876 tgen = get_topogen()
877 # Don't run this test if we have any failure.
878 if tgen.routers_have_failure():
879 pytest.skip(tgen.errors)
880
881 step("Configure 8 interfaces / links between R1 and R2")
882 step("Configure 8 interlaces/links between R2 and R3")
883 step("Configure 8 EBGP IPv4 peering between R2 and R3")
884
885 reset_config_on_routers(tgen)
886 NEXT_HOP_IP = populate_nh()
887
888 step("Configure redistribute static in BGP on R2 router")
889 for addr_type in ADDR_TYPES:
890 input_dict_2 = {
891 "r2": {
892 "bgp": {
893 "address_family": {
894 addr_type: {
895 "unicast": {"redistribute": [{"redist_type": "static"}]}
896 }
897 }
898 }
899 }
900 }
901 result = create_router_bgp(tgen, topo, input_dict_2)
902 assert result is True, "Testcase {} : Failed \n Error: {}".format(
903 tc_name, result
904 )
905
906 step(
907 "Configure IPv4 static route in R2 with 8 next hop"
908 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
909 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
910 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80, Static route next-hop"
911 "present on R1"
912 )
913 nh_all = {}
914 for addr_type in ADDR_TYPES:
915 nh_all[addr_type] = []
916 for nhp in range(1, 9):
917 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
918 for addr_type in ADDR_TYPES:
919 for nhp in range(1, 9):
920 input_dict_4 = {
921 "r2": {
922 "static_routes": [
923 {
924 "network": PREFIX1[addr_type],
925 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
926 "admin_distance": 10 * nhp,
927 }
928 ]
929 }
930 }
931 logger.info("Configure static routes")
932 result = create_static_routes(tgen, input_dict_4)
933 assert result is True, "Testcase {} : Failed \n Error: {}".format(
934 tc_name, result
935 )
936 logger.info("Verifying %s routes on r2", addr_type)
937
938 step(
939 "On R2, static route installed in RIB using "
940 "show ip route with 8 next hop , lowest AD nexthop is active"
941 )
942 input_dict_4 = {
943 "r2": {
944 "static_routes": [
945 {
946 "network": PREFIX1[addr_type],
947 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
948 "admin_distance": 10,
949 }
950 ]
951 }
952 }
953 dut = "r2"
954 protocol = "static"
955 nh = NEXT_HOP_IP["nh1"][addr_type]
956 result = verify_rib(
957 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
958 )
d7265db9
MS
959 assert (
960 result is True
961 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 962
963 nh = []
964 for nhp in range(2, 9):
965 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
966 result = verify_rib(
967 tgen,
968 addr_type,
969 dut,
970 input_dict_4,
971 next_hop=nh,
972 protocol=protocol,
973 fib=True,
974 expected=False,
975 )
d7265db9
MS
976 assert (
977 result is not True
978 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
0705f312 979
980 step(
981 "Remove the static route configured with nexthop N1 to N8, one"
982 "by one from running config"
983 )
984
985 for addr_type in ADDR_TYPES:
986 # delete static routes
987 for nhp in range(1, 9):
988 input_dict_4 = {
989 "r2": {
990 "static_routes": [
991 {
992 "network": PREFIX1[addr_type],
993 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
994 "admin_distance": 10 * nhp,
995 "delete": True,
996 }
997 ]
998 }
999 }
1000
1001 logger.info("Configure static routes")
1002 result = create_static_routes(tgen, input_dict_4)
1003 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1004 tc_name, result
1005 )
1006
1007 step(
1008 "After removing the static route with N1 to N8 one by one , "
1009 "route become active with next preferred nexthop and nexthop which "
1010 "got removed is not shown in RIB and FIB"
1011 )
1012 result = verify_rib(
1013 tgen,
1014 addr_type,
1015 dut,
1016 input_dict_4,
1017 next_hop=nh_all[addr_type],
1018 protocol=protocol,
1019 expected=False,
1020 )
d7265db9
MS
1021 assert (
1022 result is not True
1023 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1024 tc_name
1025 )
0705f312 1026
1027 step("Configure the static route with nexthop N1 to N8, one by one")
1028
1029 for addr_type in ADDR_TYPES:
1030 # add static routes
1031 for nhp in range(1, 9):
1032 input_dict_4 = {
1033 "r2": {
1034 "static_routes": [
1035 {
1036 "network": PREFIX1[addr_type],
1037 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1038 "admin_distance": 10 * nhp,
1039 }
1040 ]
1041 }
1042 }
1043 logger.info("Configure static routes")
1044 result = create_static_routes(tgen, input_dict_4)
1045 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1046 tc_name, result
1047 )
1048
1049 step(
1050 " After configuring them, route is always active with lowest AD"
1051 " value and all the nexthop populated in RIB and FIB again"
1052 )
1053 for addr_type in ADDR_TYPES:
1054 input_dict_4 = {
1055 "r2": {
1056 "static_routes": [
1057 {
1058 "network": PREFIX1[addr_type],
1059 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1060 "admin_distance": 10,
1061 }
1062 ]
1063 }
1064 }
1065 dut = "r2"
1066 protocol = "static"
1067 nh = NEXT_HOP_IP["nh1"][addr_type]
1068 result = verify_rib(
1069 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1070 )
d7265db9
MS
1071 assert (
1072 result is True
1073 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 1074 nh = []
1075 for nhp in range(2, 9):
1076 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1077 result = verify_rib(
1078 tgen,
1079 addr_type,
1080 dut,
1081 input_dict_4,
1082 next_hop=nh,
1083 protocol=protocol,
1084 fib=True,
1085 expected=False,
1086 )
d7265db9
MS
1087 assert (
1088 result is not True
1089 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
0705f312 1090
0705f312 1091 step("Random shut of the nexthop interfaces")
1092 randnum = random.randint(0, 7)
1093 for addr_type in ADDR_TYPES:
1094 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1095 shutdown_bringup_interface(tgen, dut, intf, False)
1096 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1097 input_dict_5 = {
1098 "r2": {
1099 "static_routes": [
1100 {
1101 "network": PREFIX1[addr_type],
1102 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
1103 }
1104 ]
1105 }
1106 }
1107 result = verify_rib(
1108 tgen,
1109 addr_type,
1110 dut,
1111 input_dict_5,
1112 next_hop=nhip,
1113 protocol=protocol,
1114 expected=False,
1115 )
d7265db9
MS
1116 assert (
1117 result is not True
1118 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
1119 tc_name
1120 )
0705f312 1121
1122 step("Random no shut of the nexthop interfaces")
1123 for addr_type in ADDR_TYPES:
1124 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1125 shutdown_bringup_interface(tgen, dut, intf, True)
1126 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1127 result = verify_rib(
1128 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
1129 )
d7265db9
MS
1130 assert (
1131 result is True
1132 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
0705f312 1133
1134 dut = "r2"
0705f312 1135 protocol = "static"
0705f312 1136
1137 step("Reload the FRR router")
1138 # stop/start -> restart FRR router and verify
1139 stop_router(tgen, "r2")
ee51a3d9 1140
0705f312 1141 start_router(tgen, "r2")
1142
1143 for addr_type in ADDR_TYPES:
1144 input_dict_4 = {"r2": {"static_routes": [{"network": PREFIX1[addr_type]}]}}
1145 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
5980ad0a
DS
1146 assert (
1147 result is True
1148 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
1149 tc_name
0705f312 1150 )
1151
0705f312 1152 write_test_footer(tc_name)
1153
1154
1155def test_static_route_8nh_diff_AD_bgp_ecmp_p1_tc10_ebgp(request):
1156 """
1157 Verify 8 static route functionality with 8 next hop different AD'
1158
1159 """
1160 tc_name = request.node.name
1161 write_test_header(tc_name)
1162 tgen = get_topogen()
1163 # Don't run this test if we have any failure.
1164 if tgen.routers_have_failure():
1165 pytest.skip(tgen.errors)
1166 NEXT_HOP_IP = populate_nh()
1167
1168 step("Configure 8 interfaces / links between R1 and R2 ")
1169 step("Configure 8 IBGP IPv4 peering between R2 and R3 router.")
1170 reset_config_on_routers(tgen)
1171
1172 step(
1173 "Configure IPv4 static route in R2 with 8 next hop"
1174 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
1175 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
1176 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80"
1177 )
1178 step(
1179 "Configure nexthop AD in such way for static route S1 , N1 is"
1180 "preferred and for S2 , N2 is preferred and so on .."
1181 )
1182 nh_all = {}
1183 for addr_type in ADDR_TYPES:
1184 nh_all[addr_type] = []
1185 for nhp in range(1, 9):
1186 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1187
1188 for addr_type in ADDR_TYPES:
1189 for nhp in range(1, 9):
1190 input_dict_4 = {
1191 "r2": {
1192 "static_routes": [
1193 {
1194 "network": PREFIX1[addr_type],
1195 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1196 "admin_distance": 10 * nhp,
1197 }
1198 ]
1199 }
1200 }
1201 logger.info("Configure static routes")
1202 result = create_static_routes(tgen, input_dict_4)
1203 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1204 tc_name, result
1205 )
1206 second_rte = {
1207 "r2": {
1208 "static_routes": [
1209 {
1210 "network": PREFIX2[addr_type],
1211 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1212 "admin_distance": 10 * nhp,
1213 }
1214 ]
1215 }
1216 }
1217 logger.info("Configure static routes")
1218 result = create_static_routes(tgen, second_rte)
1219 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1220 tc_name, result
1221 )
1222 logger.info("Verifying %s routes on r2", addr_type)
1223
1224 step(
1225 "On R2, static route installed in RIB using "
1226 "show ip route with 8 next hop , lowest AD nexthop is active"
1227 )
1228 input_dict_4 = {
1229 "r2": {
1230 "static_routes": [
1231 {
1232 "network": PREFIX1[addr_type],
1233 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1234 "admin_distance": 10,
1235 }
1236 ]
1237 }
1238 }
1239 dut = "r2"
1240 protocol = "static"
1241 nh = NEXT_HOP_IP["nh1"][addr_type]
1242 result = verify_rib(
1243 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1244 )
d7265db9
MS
1245 assert (
1246 result is True
1247 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 1248
1249 step("Verify that highest AD nexthop are inactive")
1250 nh = []
1251 for nhp in range(2, 9):
1252 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1253 result = verify_rib(
1254 tgen,
1255 addr_type,
1256 dut,
1257 input_dict_4,
1258 next_hop=nh,
1259 protocol=protocol,
1260 fib=True,
1261 expected=False,
ed776e38 1262 retry_timeout=6,
0705f312 1263 )
d7265db9
MS
1264 assert (
1265 result is not True
1266 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
0705f312 1267
1268 step("Configure redistribute static in BGP on R2 router")
1269 for addr_type in ADDR_TYPES:
1270 input_dict_2 = {
1271 "r2": {
1272 "bgp": {
1273 "address_family": {
1274 addr_type: {
1275 "unicast": {"redistribute": [{"redist_type": "static"}]}
1276 }
1277 }
1278 }
1279 }
1280 }
1281 result = create_router_bgp(tgen, topo, input_dict_2)
1282 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1283 tc_name, result
1284 )
1285
1286 step(
1287 "Remove the static route configured with nexthop N1 to N8, one"
1288 "by one from running config"
1289 )
1290
1291 for addr_type in ADDR_TYPES:
1292 # delete static routes
1293 for nhp in range(1, 9):
1294 input_dict_4 = {
1295 "r2": {
1296 "static_routes": [
1297 {
1298 "network": PREFIX1[addr_type],
1299 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1300 "admin_distance": 10 * nhp,
1301 "delete": True,
1302 }
1303 ]
1304 }
1305 }
1306
1307 logger.info("Configure static routes")
1308 result = create_static_routes(tgen, input_dict_4)
1309 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1310 tc_name, result
1311 )
1312
1313 step(
1314 "After removing the static route with N1 to N8 one by one , "
1315 "route become active with next preferred nexthop and nexthop which"
1316 "got removed is not shown in RIB and FIB"
1317 )
1318
1319 result = verify_rib(
1320 tgen,
1321 addr_type,
1322 dut,
1323 input_dict_4,
1324 next_hop=nh,
1325 protocol=protocol,
1326 expected=False,
1327 )
d7265db9
MS
1328 assert (
1329 result is not True
1330 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1331 tc_name
1332 )
0705f312 1333
1334 step("Configure the static route with nexthop N1 to N8, one by one")
1335 for addr_type in ADDR_TYPES:
1336 # add static routes
1337 for nhp in range(1, 9):
1338 input_dict_4 = {
1339 "r2": {
1340 "static_routes": [
1341 {
1342 "network": PREFIX1[addr_type],
1343 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1344 "admin_distance": 10 * nhp,
1345 }
1346 ]
1347 }
1348 }
1349
1350 logger.info("Configure static routes")
1351 result = create_static_routes(tgen, input_dict_4)
1352 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1353 tc_name, result
1354 )
1355
1356 step(
1357 " After configuring them, route is always active with lowest AD"
1358 " value and all the nexthop populated in RIB and FIB again"
1359 )
1360 for addr_type in ADDR_TYPES:
5980ad0a
DS
1361 input_dict_4 = {
1362 "r2": {
1363 "static_routes": [
1364 {
1365 "network": PREFIX1[addr_type],
1366 }
1367 ]
1368 }
1369 }
0705f312 1370 nh = NEXT_HOP_IP["nh1"][addr_type]
1371 result = verify_rib(
1372 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1373 )
d7265db9
MS
1374 assert result is True, (
1375 "Testcase {} : Failed \nError: Route with "
1376 "lowest AD is missing in RIB".format(tc_name)
1377 )
0705f312 1378
0705f312 1379 step("Random shut of the nexthop interfaces")
1380 randnum = random.randint(0, 7)
1381 for addr_type in ADDR_TYPES:
1382 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1383 shutdown_bringup_interface(tgen, dut, intf, False)
1384 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1385 input_dict_5 = {
1386 "r2": {
1387 "static_routes": [
1388 {
1389 "network": PREFIX1[addr_type],
1390 "next_hop": NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type],
1391 }
1392 ]
1393 }
1394 }
1395 result = verify_rib(
1396 tgen,
1397 addr_type,
1398 dut,
1399 input_dict_5,
1400 next_hop=nhip,
1401 protocol=protocol,
1402 expected=False,
1403 )
d7265db9
MS
1404 assert (
1405 result is not True
1406 ), "Testcase {} : Failed \n" "Error: Routes are still present in RIB".format(
1407 tc_name
1408 )
0705f312 1409
1410 step("Random no shut of the nexthop interfaces")
1411 for addr_type in ADDR_TYPES:
1412 intf = topo["routers"]["r2"]["links"]["r1-link" + str(randnum)]["interface"]
1413 shutdown_bringup_interface(tgen, dut, intf, True)
1414 nhip = NEXT_HOP_IP["nh" + str(randnum + 1)][addr_type]
1415 result = verify_rib(
1416 tgen, addr_type, dut, input_dict_5, next_hop=nhip, protocol=protocol
1417 )
d7265db9
MS
1418 assert (
1419 result is True
1420 ), "Testcase {} : Failed \n" "Error: Routes are missing in RIB".format(tc_name)
0705f312 1421
1422 step("Remove random static route with all the nexthop")
1423 for addr_type in ADDR_TYPES:
1424 # delete static routes
1425 for nhp in range(1, 9):
1426 input_dict_4 = {
1427 "r2": {
1428 "static_routes": [
1429 {
1430 "network": PREFIX1[addr_type],
1431 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1432 "admin_distance": 10 * nhp,
1433 "delete": True,
1434 }
1435 ]
1436 }
1437 }
1438 logger.info("Configure static routes")
1439 result = create_static_routes(tgen, input_dict_4)
1440 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1441 tc_name, result
1442 )
1443
1444 step(
1445 "After removing the static route with N1 to N8 one by one , "
1446 "route become active with next preferred nexthop and nexthop "
1447 "which got removed is not shown in RIB and FIB"
1448 )
1449 nh = NEXT_HOP_IP["nh" + str(nhp)][addr_type]
1450 result = verify_rib(
1451 tgen,
1452 addr_type,
1453 dut,
1454 input_dict_4,
1455 next_hop=nh,
1456 protocol=protocol,
1457 expected=False,
1458 )
d7265db9
MS
1459 assert result is not True, (
1460 "Testcase {} : Failed \nError: Route "
1461 " is still present in RIB".format(tc_name)
1462 )
0705f312 1463
1464 step("Reconfigure the deleted routes and verify they are installed")
1465 for nhp in range(1, 9):
1466 input_dict_4 = {
1467 "r2": {
1468 "static_routes": [
1469 {
1470 "network": PREFIX1[addr_type],
1471 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1472 "admin_distance": 10 * nhp,
1473 }
1474 ]
1475 }
1476 }
1477 logger.info("Configure static routes")
1478 result = create_static_routes(tgen, input_dict_4)
1479 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1480 tc_name, result
1481 )
1482
1483 dut = "r2"
1484 protocol = "static"
1485 nh = NEXT_HOP_IP["nh1"][addr_type]
1486 result = verify_rib(tgen, addr_type, dut, input_dict_4, protocol=protocol)
d7265db9
MS
1487 assert result is True, (
1488 "Testcase {} : Failed \nError: Route "
1489 " is still present in RIB".format(tc_name)
1490 )
0705f312 1491
1492 step("Reload the FRR router")
1493 # stop/start -> restart FRR router and verify
1494 stop_router(tgen, "r2")
ee51a3d9 1495
0705f312 1496 start_router(tgen, "r2")
1497
1498 step("After reloading, verify that routes are still present in R2.")
1499 result = verify_rib(
1500 tgen,
1501 addr_type,
1502 dut,
1503 second_rte,
1504 next_hop=nh,
1505 protocol=protocol,
1506 fib=True,
1507 )
5980ad0a
DS
1508 assert (
1509 result is True
1510 ), "Testcase {} : Failed \nError: Route " " is missing in RIB".format(
1511 tc_name
0705f312 1512 )
1513
0705f312 1514 write_test_footer(tc_name)
1515
1516
1517def test_static_route_delete_p0_tc11_ebgp(request):
1518 """
1519 Delete the static route and verify the RIB and FIB state
1520 """
1521 tc_name = request.node.name
1522 write_test_header(tc_name)
1523 tgen = get_topogen()
1524 # Don't run this test if we have any failure.
1525 if tgen.routers_have_failure():
1526 pytest.skip(tgen.errors)
1527 NEXT_HOP_IP = populate_nh()
1528
1529 step("Configure 8 interfaces / links between R1 and R2 ")
1530 step("Configure 8 IBGP IPv4 peering between R2 and R3 router.")
1531 reset_config_on_routers(tgen)
1532
1533 step(
1534 "Configure IPv4 static route in R2 with 8 next hop"
1535 "N1(21.1.1.2) AD 10, N2(22.1.1.2) AD 20, N3(23.1.1.2) AD 30,"
1536 "N4(24.1.1.2) AD 40, N5(25.1.1.2) AD 50, N6(26.1.1.2) AD 60,"
1537 "N7(27.1.1.2) AD 70, N8(28.1.1.2) AD 80"
1538 )
1539 step(
1540 "Configure nexthop AD in such way for static route S1 , N1 is"
1541 "preferred and for S2 , N2 is preferred and so on .."
1542 )
1543 nh_all = {}
1544 for addr_type in ADDR_TYPES:
1545 nh_all[addr_type] = []
1546 for nhp in range(1, 9):
1547 nh_all[addr_type].append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1548
1549 for addr_type in ADDR_TYPES:
1550 for nhp in range(1, 9):
1551 input_dict_4 = {
1552 "r2": {
1553 "static_routes": [
1554 {
1555 "network": PREFIX1[addr_type],
1556 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1557 "admin_distance": 10 * nhp,
1558 }
1559 ]
1560 }
1561 }
1562 logger.info("Configure static routes")
1563 result = create_static_routes(tgen, input_dict_4)
1564 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1565 tc_name, result
1566 )
1567 second_rte = {
1568 "r2": {
1569 "static_routes": [
1570 {
1571 "network": PREFIX2[addr_type],
1572 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1573 "admin_distance": 10 * nhp,
1574 }
1575 ]
1576 }
1577 }
1578 logger.info("Configure static routes")
1579 result = create_static_routes(tgen, second_rte)
1580 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1581 tc_name, result
1582 )
1583 logger.info("Verifying %s routes on r2", addr_type)
1584
1585 step(
1586 "On R2, static route installed in RIB using "
1587 "show ip route with 8 next hop , lowest AD nexthop is active"
1588 )
1589 input_dict_4 = {
1590 "r2": {
1591 "static_routes": [
1592 {
1593 "network": PREFIX1[addr_type],
1594 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1595 "admin_distance": 10,
1596 }
1597 ]
1598 }
1599 }
1600 dut = "r2"
1601 protocol = "static"
1602 nh = NEXT_HOP_IP["nh1"][addr_type]
1603 result = verify_rib(
1604 tgen, addr_type, dut, input_dict_4, next_hop=nh, protocol=protocol, fib=True
1605 )
d7265db9
MS
1606 assert (
1607 result is True
1608 ), "Testcase {} : Failed \nError: Routes are" " missing in RIB".format(tc_name)
0705f312 1609
1610 step("Verify that highest AD nexthop are inactive")
1611 nh = []
1612 for nhp in range(2, 9):
1613 nh.append(NEXT_HOP_IP["nh" + str(nhp)][addr_type])
1614 result = verify_rib(
1615 tgen,
1616 addr_type,
1617 dut,
1618 input_dict_4,
1619 next_hop=nh,
1620 protocol=protocol,
1621 fib=True,
1622 expected=False,
1623 )
d7265db9
MS
1624 assert (
1625 result is not True
1626 ), "Testcase {} : Failed \nError: Routes " " are missing in RIB".format(tc_name)
0705f312 1627
1628 step("Configure redistribute static in BGP on R2 router")
1629 for addr_type in ADDR_TYPES:
1630 input_dict_2 = {
1631 "r2": {
1632 "bgp": {
1633 "address_family": {
1634 addr_type: {
1635 "unicast": {"redistribute": [{"redist_type": "static"}]}
1636 }
1637 }
1638 }
1639 }
1640 }
1641 result = create_router_bgp(tgen, topo, input_dict_2)
1642 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1643 tc_name, result
1644 )
1645
1646 step("Remove the redistribute static knob")
1647 for addr_type in ADDR_TYPES:
1648 input_dict_2 = {
1649 "r2": {
1650 "bgp": {
1651 "address_family": {
1652 addr_type: {
1653 "unicast": {
1654 "redistribute": [
1655 {"redist_type": "static", "delete": True}
1656 ]
1657 }
1658 }
1659 }
1660 }
1661 }
1662 }
1663 result = create_router_bgp(tgen, topo, input_dict_2)
1664 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1665 tc_name, result
1666 )
1667
1668 step(
1669 "Verify after removing the redistribute static from BGP all the"
1670 "routes got delete from RIB and FIB of R3 "
1671 )
1672
1673 dut = "r3"
1674 protocol = "bgp"
1675 result = verify_rib(
1676 tgen, addr_type, dut, input_dict_4, protocol=protocol, expected=False
1677 )
d7265db9
MS
1678 assert (
1679 result is not True
1680 ), "Testcase {} : Failed \nError: Routes are" " still present in RIB".format(
1681 tc_name
1682 )
0705f312 1683
1684 for addr_type in ADDR_TYPES:
1685 for nhp in range(1, 9):
1686 input_dict_4 = {
1687 "r2": {
1688 "static_routes": [
1689 {
1690 "network": PREFIX1[addr_type],
1691 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1692 "admin_distance": 10 * nhp,
1693 "delete": True,
1694 }
1695 ]
1696 }
1697 }
1698 logger.info("Configure static routes")
1699 result = create_static_routes(tgen, input_dict_4)
1700 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1701 tc_name, result
1702 )
1703 second_rte = {
1704 "r2": {
1705 "static_routes": [
1706 {
1707 "network": PREFIX2[addr_type],
1708 "next_hop": NEXT_HOP_IP["nh" + str(nhp)][addr_type],
1709 "admin_distance": 10 * nhp,
1710 }
1711 ]
1712 }
1713 }
1714 logger.info("Configure static routes")
1715 result = create_static_routes(tgen, second_rte)
1716 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1717 tc_name, result
1718 )
1719 logger.info("Verifying %s routes on r2", addr_type)
1720
1721 step(
1722 " After removing all the routes and nexthop from R2 , "
1723 " verify R2 RIB and FIB is cleared"
1724 )
1725 input_dict_4 = {
1726 "r2": {
1727 "static_routes": [
1728 {
1729 "network": PREFIX1[addr_type],
1730 "next_hop": NEXT_HOP_IP["nh1"][addr_type],
1731 "admin_distance": 10,
1732 }
1733 ]
1734 }
1735 }
1736 dut = "r2"
1737 protocol = "static"
1738 nh = NEXT_HOP_IP["nh1"][addr_type]
1739 result = verify_rib(
1740 tgen,
1741 addr_type,
1742 dut,
1743 input_dict_4,
1744 next_hop=nh,
1745 protocol=protocol,
1746 fib=True,
1747 expected=False,
1748 )
d7265db9
MS
1749 assert (
1750 result is not True
1751 ), "Testcase {} : Failed \nError: Routes are" " still active in RIB".format(
1752 tc_name
1753 )
aa59a709 1754
0705f312 1755 write_test_footer(tc_name)
1756
1757
1758if __name__ == "__main__":
1759 args = ["-s"] + sys.argv[1:]
1760 sys.exit(pytest.main(args))