2 # SPDX-License-Identifier: ISC
4 # Copyright (c) 2019 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
10 Following tests are covered to test BGP Graceful Restart functionality.
11 Basic Common Test steps for all the test case below :
12 - Create topology (setup module)
13 Creating 2 routers topology, r1, r2 in IBGP
15 - Verify for bgp to converge
16 - Configure BGP Garceful Restart on both the routers.
18 1. Transition from Peer-level helper to Global Restarting
19 2. Transition from Peer-level helper to Global inherit helper
20 3. Transition from Peer-level restarting to Global inherit helper
21 4. Default GR functional mode is Helper.
22 5. Verify that the restarting node sets "R" bit while sending the
23 BGP open messages after the node restart, only if GR is enabled.
24 6. Verify if restarting node resets R bit in BGP open message
25 during normal BGP session flaps as well, even when GR restarting
26 mode is enabled. Here link flap happen due to interface UP/DOWN.
27 7. Verify if restarting node resets R bit in BGP
28 open message during normal BGP session flaps when GR is disabled.
29 8. Verify that restarting nodes set "F" bit while sending
30 the BGP open messages after it restarts, only when BGP GR is enabled.
31 9. Verify that only GR helper routers keep the stale
32 route entries, not any GR disabled router.
33 10. Verify that GR helper routers keeps all the routes received
34 from restarting node if both the routers are configured as
36 11. Verify that GR helper routers delete all the routes
37 received from a node if both the routers are configured as GR
39 12. After BGP neighborship is established and GR capability is exchanged,
40 transition restarting router to disabled state and vice versa.
41 13. After BGP neighborship is established and GR capability is exchanged,
42 transition restarting router to disabled state and vice versa.
43 14. Verify that restarting nodes reset "F" bit while sending
44 the BGP open messages after it's restarts, when BGP GR is **NOT** enabled.
45 15. Verify that only GR helper routers keep the stale
46 route entries, not any GR disabled router.
47 16. Transition from Global Restarting to Disable and then Global
48 Disable to Restarting.
49 17. Transition from Global Helper to Disable and then Global
51 18. Transition from Global Restart to Helper and then Global
52 Helper to Restart, Global Mode : GR Restarting
53 PerPeer Mode : GR Helper
54 GR Mode effective : GR Helper
55 19. Transition from Peer-level helper to Global Restarting,
56 Global Mode : GR Restarting
57 PerPeer Mode : GR Restarting
58 GR Mode effective : GR Restarting
59 20. Transition from Peer-level restart to Global Restart
60 Global Mode : GR Restarting
61 PerPeer Mode : GR Restarting
62 GR Mode effective : GR Restarting
63 21. Transition from Peer-level disabled to Global Restart
64 Global Mode : GR Restarting
65 PerPeer Mode : GR Disabled
66 GR Mode effective : GR Disabled
67 22. Peer-level inherit from Global Restarting
68 Global Mode : GR Restart
70 GR Mode effective : GR Restart
71 23. Transition from Peer-level disable to Global inherit helper
73 PerPeer Mode : GR Disable
74 GR Mode effective : GR Disable
76 These tests have been broken up into 4 sub python scripts because
77 the totality of this run was fairly significant.
85 # Save the Current Working Directory to find configuration files.
86 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
87 sys
.path
.append(os
.path
.join("../"))
88 sys
.path
.append(os
.path
.join("../lib/"))
90 # pylint: disable=C0413
91 # Import topogen and topotest helpers
92 from lib
.topogen
import Topogen
, get_topogen
93 from lib
.topolog
import logger
95 # Required to instantiate the topology builder class.
97 # Import topoJson from lib, to create topology and initial configuration
98 from lib
.topojson
import build_config_from_json
102 verify_graceful_restart
,
106 verify_bgp_convergence
,
107 verify_bgp_convergence_from_running_config
,
110 from lib
.common_config
import (
112 reset_config_on_routers
,
115 start_router_daemons
,
120 shutdown_bringup_interface
,
122 get_frr_ipv6_linklocal
,
123 required_linux_kernel_version
,
126 pytestmark
= [pytest
.mark
.bgpd
]
130 NEXT_HOP_IP
= {"ipv4": "192.168.1.10", "ipv6": "fd00:0:0:1::10"}
131 NEXT_HOP_IP_1
= {"ipv4": "192.168.0.1", "ipv6": "fd00::1"}
132 NEXT_HOP_IP_2
= {"ipv4": "192.168.0.2", "ipv6": "fd00::2"}
133 BGP_CONVERGENCE
= False
134 GR_RESTART_TIMER
= 20
135 PREFERRED_NEXT_HOP
= "link_local"
138 def setup_module(mod
):
140 Sets up the pytest environment
147 # Required linux kernel version for this suite to run.
148 result
= required_linux_kernel_version("4.16")
149 if result
is not True:
150 pytest
.skip("Kernel requirements are not met, kernel version should be >=4.16")
152 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
153 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
154 logger
.info("=" * 40)
156 logger
.info("Running setup_module to create topology")
158 # This function initiates the topology build with Topogen...
159 json_file
= "{}/bgp_gr_topojson_topo1.json".format(CWD
)
160 tgen
= Topogen(json_file
, mod
.__name
__)
162 topo
= tgen
.json_topo
163 # ... and here it calls Mininet initialization functions.
165 # Starting topology, create tmp files which are loaded to routers
166 # to start daemons and then start routers
169 # Creating configuration from JSON
170 build_config_from_json(tgen
, topo
)
172 # Don't run this test if we have any failure.
173 if tgen
.routers_have_failure():
174 pytest
.skip(tgen
.errors
)
176 # Api call verify whether BGP is converged
177 ADDR_TYPES
= check_address_types()
179 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
180 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error:" " {}".format(
184 logger
.info("Running setup_module() done")
187 def teardown_module(mod
):
189 Teardown the pytest environment
194 logger
.info("Running teardown_module to delete topology")
198 # Stop toplogy and Remove tmp files
202 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
204 logger
.info("=" * 40)
207 def configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
, peer
):
209 This function groups the repetitive function calls into one function.
212 result
= create_router_bgp(tgen
, topo
, input_dict
)
213 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
215 for addr_type
in ADDR_TYPES
:
216 neighbor
= topo
["routers"][peer
]["links"]["r1-link1"][addr_type
].split("/")[0]
217 clear_bgp(tgen
, addr_type
, dut
, neighbor
=neighbor
)
219 for addr_type
in ADDR_TYPES
:
220 neighbor
= topo
["routers"][dut
]["links"]["r2-link1"][addr_type
].split("/")[0]
221 clear_bgp(tgen
, addr_type
, peer
, neighbor
=neighbor
)
223 result
= verify_bgp_convergence_from_running_config(tgen
)
224 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
229 def next_hop_per_address_family(
230 tgen
, dut
, peer
, addr_type
, next_hop_dict
, preferred_next_hop
=PREFERRED_NEXT_HOP
233 This function returns link_local or global next_hop per address-family
236 intferface
= topo
["routers"][peer
]["links"]["{}-link1".format(dut
)]["interface"]
237 if addr_type
== "ipv6" and "link_local" in preferred_next_hop
:
238 next_hop
= get_frr_ipv6_linklocal(tgen
, peer
, intf
=intferface
)
240 next_hop
= next_hop_dict
[addr_type
]
245 def BGP_GR_TC_50_p1(request
):
247 Test Objective : Transition from Peer-level helper to Global inherit helper
249 PerPeer Mode : Helper
250 GR Mode effective : GR Helper
255 tc_name
= request
.node
.name
256 write_test_header(tc_name
)
258 # Check router status
259 check_router_status(tgen
)
261 # Don't run this test if we have any failure.
262 if tgen
.routers_have_failure():
263 pytest
.skip(tgen
.errors
)
265 # Creating configuration from JSON
266 reset_config_on_routers(tgen
)
269 "Configure R1 as GR helper node at per Peer-level for R2"
270 " and configure R2 as global restarting node."
282 "r1-link1": {"graceful-restart-helper": True}
293 "r1-link1": {"graceful-restart-helper": True}
302 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
305 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
307 step("Verify on R2 that R1 advertises GR capabilities as a helper node")
309 for addr_type
in ADDR_TYPES
:
310 result
= verify_graceful_restart(
311 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
313 assert result
is True, "Testcase {} : Failed \n Error {}".format(
317 for addr_type
in ADDR_TYPES
:
319 next_hop
= next_hop_per_address_family(
320 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
322 input_topo
= {"r1": topo
["routers"]["r1"]}
323 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
324 assert result
is True, "Testcase {} : Failed \n Error {}".format(
328 for addr_type
in ADDR_TYPES
:
329 next_hop
= next_hop_per_address_family(
330 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
332 input_topo
= {"r2": topo
["routers"]["r2"]}
333 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
)
334 assert result
is True, "Testcase {} : Failed \n Error {}".format(
338 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
339 assert result
is True, "Testcase {} : Failed \n Error {}".format(
343 step("Kill BGP on R2")
345 kill_router_daemons(tgen
, "r2", ["bgpd"])
348 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
351 for addr_type
in ADDR_TYPES
:
353 next_hop
= next_hop_per_address_family(
354 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
356 input_topo
= {"r1": topo
["routers"]["r1"]}
357 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
358 assert result
is True, "Testcase {} : Failed \n Error {}".format(
362 for addr_type
in ADDR_TYPES
:
363 next_hop
= next_hop_per_address_family(
364 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
366 input_topo
= {"r2": topo
["routers"]["r2"]}
367 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
)
368 assert result
is True, "Testcase {} : Failed \n Error {}".format(
372 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
373 assert result
is True, "Testcase {} : Failed \n Error {}".format(
377 step("Bring up BGP on R2 and remove Peer-level GR config from R1 ")
379 start_router_daemons(tgen
, "r2", ["bgpd"])
390 "r1-link1": {"graceful-restart-helper": False}
401 "r1-link1": {"graceful-restart-helper": False}
412 result
= create_router_bgp(tgen
, topo
, input_dict
)
413 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
415 for addr_type
in ADDR_TYPES
:
416 neighbor
= topo
["routers"]["r2"]["links"]["r1-link1"][addr_type
].split("/")[0]
417 clear_bgp(tgen
, addr_type
, "r1", neighbor
=neighbor
)
419 result
= verify_bgp_convergence_from_running_config(tgen
)
420 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
422 step("Verify on R2 that R1 still advertises GR capabilities as a helper node")
425 "r1": {"bgp": {"graceful-restart": {"graceful-restart-helper": True}}},
426 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
429 for addr_type
in ADDR_TYPES
:
430 result
= verify_graceful_restart(
431 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
433 assert result
is True, "Testcase {} : Failed \n Error {}".format(
437 for addr_type
in ADDR_TYPES
:
439 next_hop
= next_hop_per_address_family(
440 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
442 input_topo
= {"r1": topo
["routers"]["r1"]}
443 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
446 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
450 for addr_type
in ADDR_TYPES
:
451 next_hop
= next_hop_per_address_family(
452 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
454 input_topo
= {"r2": topo
["routers"]["r2"]}
455 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
)
456 assert result
is True, "Testcase {} : Failed \n Error {}".format(
460 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
463 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
467 step("Kill BGP on R2")
469 kill_router_daemons(tgen
, "r2", ["bgpd"])
472 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
475 for addr_type
in ADDR_TYPES
:
477 next_hop
= next_hop_per_address_family(
478 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
480 input_topo
= {"r1": topo
["routers"]["r1"]}
481 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
484 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
488 for addr_type
in ADDR_TYPES
:
489 next_hop
= next_hop_per_address_family(
490 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
492 input_topo
= {"r2": topo
["routers"]["r2"]}
493 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
)
494 assert result
is True, "Testcase {} : Failed \n Error {}".format(
498 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
501 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
505 step("Start BGP on R2")
507 start_router_daemons(tgen
, "r2", ["bgpd"])
509 write_test_footer(tc_name
)
512 def test_BGP_GR_TC_51_p1(request
):
514 Test Objective : Transition from Peer-level restarting to Global inherit helper
516 PerPeer Mode : GR Restart
517 GR Mode effective : GR Restart
522 tc_name
= request
.node
.name
523 write_test_header(tc_name
)
525 # Check router status
526 check_router_status(tgen
)
528 # Don't run this test if we have any failure.
529 if tgen
.routers_have_failure():
530 pytest
.skip(tgen
.errors
)
532 # Creating configuration from JSON
533 reset_config_on_routers(tgen
)
535 step("Configure R1 as GR restarting node at per Peer-level for R2")
546 "r1-link1": {"graceful-restart": True}
557 "r1-link1": {"graceful-restart": True}
566 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
569 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
570 step("Verify on R2 that R1 advertises GR capabilities as a restarting node")
572 for addr_type
in ADDR_TYPES
:
573 result
= verify_graceful_restart(
574 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
576 assert result
is True, "Testcase {} : Failed \n Error {}".format(
580 for addr_type
in ADDR_TYPES
:
582 next_hop
= next_hop_per_address_family(
583 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
585 input_topo
= {"r2": topo
["routers"]["r2"]}
586 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
587 assert result
is True, "Testcase {} : Failed \n Error {}".format(
591 for addr_type
in ADDR_TYPES
:
592 next_hop
= next_hop_per_address_family(
593 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
595 input_topo
= {"r1": topo
["routers"]["r1"]}
596 result
= verify_bgp_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
)
597 assert result
is True, "Testcase {} : Failed \n Error {}".format(
601 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
602 assert result
is True, "Testcase {} : Failed \n Error {}".format(
606 step("Kill BGP on R1")
608 kill_router_daemons(tgen
, "r1", ["bgpd"])
611 "Verify that R1 keeps the stale entries in FIB & R2 keeps stale entries in RIB & FIB"
614 for addr_type
in ADDR_TYPES
:
616 next_hop
= next_hop_per_address_family(
617 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
619 input_topo
= {"r2": topo
["routers"]["r2"]}
620 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
621 assert result
is True, "Testcase {} : Failed \n Error {}".format(
625 for addr_type
in ADDR_TYPES
:
626 next_hop
= next_hop_per_address_family(
627 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
629 input_topo
= {"r1": topo
["routers"]["r1"]}
630 result
= verify_bgp_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
)
631 assert result
is True, "Testcase {} : Failed \n Error {}".format(
635 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
636 assert result
is True, "Testcase {} : Failed \n Error {}".format(
640 step("Bring up BGP on R1 and remove Peer-level GR config")
642 start_router_daemons(tgen
, "r1", ["bgpd"])
653 "r1-link1": {"graceful-restart": False}
664 "r1-link1": {"graceful-restart": False}
675 result
= create_router_bgp(tgen
, topo
, input_dict
)
676 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
678 for addr_type
in ADDR_TYPES
:
679 neighbor
= topo
["routers"]["r2"]["links"]["r1-link1"][addr_type
].split("/")[0]
680 clear_bgp(tgen
, addr_type
, "r1", neighbor
=neighbor
)
682 result
= verify_bgp_convergence_from_running_config(tgen
)
683 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
685 step("Verify on R2 that R1 advertises GR capabilities as a helper node")
688 "r1": {"bgp": {"graceful-restart": {"graceful-restart-helper": True}}},
689 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
692 for addr_type
in ADDR_TYPES
:
693 result
= verify_graceful_restart(
694 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
696 assert result
is True, "Testcase {} : Failed \n Error {}".format(
700 for addr_type
in ADDR_TYPES
:
702 next_hop
= next_hop_per_address_family(
703 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
705 input_topo
= {"r1": topo
["routers"]["r1"]}
706 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
709 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
713 for addr_type
in ADDR_TYPES
:
714 next_hop
= next_hop_per_address_family(
715 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
717 input_topo
= {"r2": topo
["routers"]["r2"]}
718 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
)
719 assert result
is True, "Testcase {} : Failed \n Error {}".format(
723 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
726 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
730 step("Kill BGPd on R2")
732 kill_router_daemons(tgen
, "r2", ["bgpd"])
735 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
738 for addr_type
in ADDR_TYPES
:
740 next_hop
= next_hop_per_address_family(
741 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
743 input_topo
= {"r1": topo
["routers"]["r1"]}
744 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
747 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
751 for addr_type
in ADDR_TYPES
:
752 next_hop
= next_hop_per_address_family(
753 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
755 input_topo
= {"r2": topo
["routers"]["r2"]}
756 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
)
757 assert result
is True, "Testcase {} : Failed \n Error {}".format(
761 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
764 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
768 step("Start BGP on R2")
770 start_router_daemons(tgen
, "r2", ["bgpd"])
772 write_test_footer(tc_name
)
775 def test_BGP_GR_TC_53_p1(request
):
777 Test Objective : Default GR functional mode is Helper.
780 GR Mode effective : GR Helper
785 tc_name
= request
.node
.name
786 write_test_header(tc_name
)
788 # Check router status
789 check_router_status(tgen
)
791 # Don't run this test if we have any failure.
792 if tgen
.routers_have_failure():
793 pytest
.skip(tgen
.errors
)
795 # Creating configuration from JSON
796 reset_config_on_routers(tgen
)
798 step("configure R2 as global restarting node")
800 input_dict
= {"r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}}
802 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
805 "Verify on R2 that R1 advertises GR capabilities as a helper node based on inherit"
809 "r1": {"bgp": {"graceful-restart": {"graceful-restart-helper": True}}},
810 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
813 for addr_type
in ADDR_TYPES
:
814 result
= verify_graceful_restart(
815 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
817 assert result
is True, "Testcase {} : Failed \n Error {}".format(
821 for addr_type
in ADDR_TYPES
:
823 next_hop
= next_hop_per_address_family(
824 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
826 input_topo
= {"r1": topo
["routers"]["r1"]}
827 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
828 assert result
is True, "Testcase {} : Failed \n Error {}".format(
832 for addr_type
in ADDR_TYPES
:
833 next_hop
= next_hop_per_address_family(
834 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
836 input_topo
= {"r2": topo
["routers"]["r2"]}
837 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
)
838 assert result
is True, "Testcase {} : Failed \n Error {}".format(
842 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
843 assert result
is True, "Testcase {} : Failed \n Error {}".format(
847 step("Kill BGPd on R2")
849 kill_router_daemons(tgen
, "r2", ["bgpd"])
852 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
855 for addr_type
in ADDR_TYPES
:
857 next_hop
= next_hop_per_address_family(
858 tgen
, "r2", "r1", addr_type
, NEXT_HOP_IP_1
860 input_topo
= {"r1": topo
["routers"]["r1"]}
861 result
= verify_rib(tgen
, addr_type
, "r2", input_topo
, next_hop
, protocol
)
862 assert result
is True, "Testcase {} : Failed \n Error {}".format(
866 for addr_type
in ADDR_TYPES
:
867 next_hop
= next_hop_per_address_family(
868 tgen
, "r1", "r2", addr_type
, NEXT_HOP_IP_2
870 input_topo
= {"r2": topo
["routers"]["r2"]}
871 result
= verify_bgp_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
)
872 assert result
is True, "Testcase {} : Failed \n Error {}".format(
876 result
= verify_rib(tgen
, addr_type
, "r1", input_topo
, next_hop
, protocol
)
877 assert result
is True, "Testcase {} : Failed \n Error {}".format(
881 step("Start BGP on R2")
883 start_router_daemons(tgen
, "r2", ["bgpd"])
885 write_test_footer(tc_name
)
888 def test_BGP_GR_TC_4_p0(request
):
890 Test Objective : Verify that the restarting node sets "R" bit while sending the
891 BGP open messages after the node restart, only if GR is enabled.
895 tc_name
= request
.node
.name
896 write_test_header(tc_name
)
898 # Check router status
899 check_router_status(tgen
)
901 # Don't run this test if we have any failure.
902 if tgen
.routers_have_failure():
903 pytest
.skip(tgen
.errors
)
905 # Creating configuration from JSON
906 reset_config_on_routers(tgen
)
909 "[Phase 1] : Test Setup" " [Restart Mode]R1-----R2[Helper Mode] initialized "
912 # Configure graceful-restart
922 "r1-link1": {"graceful-restart": True}
933 "r1-link1": {"graceful-restart": True}
950 "r2-link1": {"graceful-restart-helper": True}
961 "r2-link1": {"graceful-restart-helper": True}
972 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
974 for addr_type
in ADDR_TYPES
:
975 result
= verify_graceful_restart(
976 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
978 assert result
is True, "Testcase {} : Failed \n Error {}".format(
982 # Verifying BGP RIB routes
985 next_hop
= next_hop_per_address_family(
986 tgen
, dut
, peer
, addr_type
, NEXT_HOP_IP_2
988 input_topo
= {key
: topo
["routers"][key
] for key
in ["r2"]}
989 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
)
990 assert result
is True, "Testcase {} : Failed \n Error {}".format(
994 # Verifying RIB routes
996 result
= verify_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
, protocol
)
997 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1001 logger
.info("[Phase 2] : R2 goes for reload ")
1003 kill_router_daemons(tgen
, "r2", ["bgpd"])
1006 "[Phase 3] : R2 is still down, restart time {} sec."
1007 "So time verify the routes are present in BGP RIB and ZEBRA ".format(
1012 for addr_type
in ADDR_TYPES
:
1013 # Verifying BGP RIB routes
1014 next_hop
= next_hop_per_address_family(
1015 tgen
, dut
, peer
, addr_type
, NEXT_HOP_IP_2
1017 input_topo
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1018 result
= verify_bgp_rib(
1019 tgen
, addr_type
, dut
, input_topo
, next_hop
, expected
=False
1021 assert result
is not True, (
1022 "Testcase {} : Failed \n "
1023 "Expected: Routes should not be present in {} BGP RIB \n "
1024 "Found: {}".format(tc_name
, dut
, result
)
1027 # Verifying RIB routes
1028 result
= verify_rib(
1029 tgen
, addr_type
, dut
, input_topo
, next_hop
, protocol
, expected
=False
1031 assert result
is not True, (
1032 "Testcase {} : Failed \n "
1033 "Expected: Routes should not be present in {} FIB \n "
1034 "Found: {}".format(tc_name
, dut
, result
)
1037 logger
.info("[Phase 5] : R2 is about to come up now ")
1038 start_router_daemons(tgen
, "r2", ["bgpd"])
1040 logger
.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
1042 for addr_type
in ADDR_TYPES
:
1043 result
= verify_graceful_restart(
1044 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1046 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1050 result
= verify_r_bit(tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2")
1051 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1055 # Verifying BGP RIB routes
1056 next_hop
= next_hop_per_address_family(
1057 tgen
, dut
, peer
, addr_type
, NEXT_HOP_IP_2
1059 input_topo
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1060 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
)
1061 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1065 # Verifying RIB routes
1066 result
= verify_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
, protocol
)
1067 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1071 write_test_footer(tc_name
)
1074 def test_BGP_GR_TC_5_1_2_p1(request
):
1076 Test Objective : Verify if restarting node resets R bit in BGP open message
1077 during normal BGP session flaps as well, even when GR restarting mode is enabled.
1078 Here link flap happen due to interface UP/DOWN.
1081 tgen
= get_topogen()
1082 tc_name
= request
.node
.name
1083 write_test_header(tc_name
)
1085 # Check router status
1086 check_router_status(tgen
)
1088 # Don't run this test if we have any failure.
1089 if tgen
.routers_have_failure():
1090 pytest
.skip(tgen
.errors
)
1092 # Creating configuration from JSON
1093 reset_config_on_routers(tgen
)
1096 "[Phase 1] : Test Setup" " [Restart Mode]R1-----R2[Restart Mode] initialized "
1099 # Configure graceful-restart
1109 "r1-link1": {"graceful-restart": True}
1120 "r1-link1": {"graceful-restart": True}
1137 "r2-link1": {"graceful-restart": True}
1148 "r2-link1": {"graceful-restart": True}
1159 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
1161 for addr_type
in ADDR_TYPES
:
1162 result
= verify_graceful_restart(
1163 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1165 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1169 # Verifying BGP RIB routes
1172 next_hop
= next_hop_per_address_family(
1173 tgen
, dut
, peer
, addr_type
, NEXT_HOP_IP_2
1175 input_topo
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1176 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
)
1177 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1181 # Verifying RIB routes
1183 result
= verify_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
, protocol
)
1184 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1188 logger
.info("[Phase 2] : Now flap the link running the BGP session ")
1189 # Shutdown interface
1191 shutdown_bringup_interface(tgen
, "r2", intf
)
1193 # Bring up Interface
1194 shutdown_bringup_interface(tgen
, "r2", intf
, ifaceaction
=True)
1196 for addr_type
in ADDR_TYPES
:
1197 result
= verify_graceful_restart(
1198 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1200 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1204 result
= verify_r_bit(tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2")
1205 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1209 logger
.info("[Phase 2] : Restart BGPd on router R2. ")
1210 kill_router_daemons(tgen
, "r2", ["bgpd"])
1212 start_router_daemons(tgen
, "r2", ["bgpd"])
1214 logger
.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
1216 for addr_type
in ADDR_TYPES
:
1217 result
= verify_graceful_restart(
1218 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1220 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1224 result
= verify_r_bit(tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2")
1225 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1229 # Verifying BGP RIB routes
1230 next_hop
= next_hop_per_address_family(
1231 tgen
, dut
, peer
, addr_type
, NEXT_HOP_IP_2
1233 input_topo
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1234 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
)
1235 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1239 # Verifying RIB routes
1240 result
= verify_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
, protocol
)
1241 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1245 write_test_footer(tc_name
)
1248 def test_BGP_GR_TC_6_1_2_p1(request
):
1250 Test Objective : Verify if restarting node resets R bit in BGP
1251 open message during normal BGP session flaps when GR is disabled.
1254 tgen
= get_topogen()
1255 tc_name
= request
.node
.name
1256 write_test_header(tc_name
)
1258 # Check router status
1259 check_router_status(tgen
)
1261 # Don't run this test if we have any failure.
1262 if tgen
.routers_have_failure():
1263 pytest
.skip(tgen
.errors
)
1265 # Creating configuration from JSON
1266 reset_config_on_routers(tgen
)
1269 "[Phase 1] : Test Setup" "[Restart Mode]R1-----R2[Helper Mode] initialized "
1272 # Configure graceful-restart
1282 "r1-link1": {"graceful-restart": True}
1293 "r1-link1": {"graceful-restart": True}
1310 "r2-link1": {"graceful-restart-helper": True}
1321 "r2-link1": {"graceful-restart-helper": True}
1332 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
1334 for addr_type
in ADDR_TYPES
:
1335 result
= verify_graceful_restart(
1336 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1338 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1342 # Verifying BGP RIB routes
1345 next_hop
= next_hop_per_address_family(
1346 tgen
, dut
, peer
, addr_type
, NEXT_HOP_IP_2
1348 input_topo
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1349 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
)
1350 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1354 # Verifying RIB routes
1356 result
= verify_rib(tgen
, addr_type
, dut
, input_topo
, next_hop
, protocol
)
1357 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1361 logger
.info("[Phase 1] : Changing mode" "[Disable Mode]R1-----R2[Helper Mode]")
1363 # Configure graceful-restart
1373 "r1-link1": {"graceful-restart-disable": True}
1384 "r1-link1": {"graceful-restart-disable": True}
1395 result
= create_router_bgp(tgen
, topo
, input_dict
)
1396 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1398 for addr_type
in ADDR_TYPES
:
1399 neighbor
= topo
["routers"]["r2"]["links"]["r1-link1"][addr_type
].split("/")[0]
1400 clear_bgp(tgen
, addr_type
, "r1", neighbor
=neighbor
)
1402 result
= verify_bgp_convergence_from_running_config(tgen
)
1403 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1415 "r2-link1": {"graceful-restart-helper": True}
1426 "r2-link1": {"graceful-restart-helper": True}
1443 "r1-link1": {"graceful-restart-disable": True}
1454 "r1-link1": {"graceful-restart-disable": True}
1465 # here the verify_graceful_restart fro the neighbor would be
1466 # "NotReceived" as the latest GR config is not yet applied.
1467 for addr_type
in ADDR_TYPES
:
1468 result
= verify_graceful_restart(
1469 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1471 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1475 logger
.info("[Phase 2] : Now flap the link running the BGP session ")
1476 # Shutdown interface
1478 shutdown_bringup_interface(tgen
, "r2", intf
)
1480 # Bring up Interface
1481 shutdown_bringup_interface(tgen
, "r2", intf
, ifaceaction
=True)
1483 for addr_type
in ADDR_TYPES
:
1484 result
= verify_graceful_restart(
1485 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1487 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1491 result
= verify_r_bit(
1492 tgen
, topo
, addr_type
, input_dict
, dut
="r2", peer
="r1", expected
=False
1494 assert result
is not True, (
1495 "Testcase {} : Failed \n "
1496 "Expected: R-bit should not be set to True in r2\n"
1497 "Found: {}".format(tc_name
, result
)
1500 logger
.info("Restart BGPd on R2 ")
1501 kill_router_daemons(tgen
, "r2", ["bgpd"])
1503 start_router_daemons(tgen
, "r2", ["bgpd"])
1505 for addr_type
in ADDR_TYPES
:
1506 result
= verify_graceful_restart(
1507 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1509 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1513 result
= verify_r_bit(
1514 tgen
, topo
, addr_type
, input_dict
, dut
="r2", peer
="r1", expected
=False
1516 assert result
is not True, (
1517 "Testcase {} : Failed \n "
1518 "Expected: R-bit should not be set to True in r2\n"
1519 "Found: {}".format(tc_name
, result
)
1522 write_test_footer(tc_name
)
1525 if __name__
== "__main__":
1526 args
= ["-s"] + sys
.argv
[1:]
1527 sys
.exit(pytest
.main(args
))