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 7 routers topology
15 - Verify for bgp to converge
16 - Configure BGP Graceful Restart on both the routers.
19 Verify that EOR message is sent out only after initial convergence
20 Verify whether EOR message is received from all the peers after restart
22 Verify the selection deferral timer functionality when EOR is not sent
25 Verify that selection-deferral timer sets the maximum time to
26 avoid deadlock during which the best-path
28 Test Objective : Test GR scenarios on helper router by enabling
29 Graceful Restart for multiple address families.
31 Test Objective : Test GR scenarios by enabling Graceful Restart
32 for multiple address families..
34 Test Objective : Verify BGP-GR feature when restarting node
35 is a transit router for it's iBGP peers.
37 Test Objective : Verify that GR helper router deletes stale routes
38 received from restarting node, if GR capability is not present in
40 Test Objective : Verify that GR routers keeps all the routes
41 received from restarting node if both the routers are
43 Test Objective : Test GR scenarios on helper router by enabling
44 Graceful Restart for multiple address families.
46 Test Objective : Verify if helper node goes down before restarting
47 node comes up online, helper node sets the R-bit to avoid dead-lock
49 Test Objective : Change timers on the fly, and
50 verify if it takes immediate effect.
52 Test Objective : Helper router receives same prefixes from two
53 different routers (GR-restarting and GR-disabled). Keeps the
55 Test Objective : Restarting node doesn't preserve forwarding
56 state, helper router should not keep the stale entries.
58 Test Objective : Restarting node doesn't preserve the forwarding
59 state verify the behaviour on helper node, if it still keeps the
61 Test Objective : Restarting node is connected to multiple helper
62 nodes, one of them doesn't send EOR to restarting router. Verify
64 Test Objective : Verify if helper node restarts before sending the
65 EOR message, restarting node doesn't wait until stale path timer
67 Test Objective : Restarting node removes stale routes from Zebra
68 after receiving an EOR from helper router.
76 from time
import sleep
78 # Save the Current Working Directory to find configuration files.
79 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
80 sys
.path
.append(os
.path
.join("../"))
81 sys
.path
.append(os
.path
.join("../lib/"))
83 # pylint: disable=C0413
84 # Import topogen and topotest helpers
85 from lib
.topogen
import Topogen
, get_topogen
86 from lib
.topolog
import logger
88 # Required to instantiate the topology builder class.
90 # Import topoJson from lib, to create topology and initial configuration
91 from lib
.topojson
import build_config_from_json
95 verify_graceful_restart
,
100 verify_bgp_convergence
,
101 verify_gr_address_family
,
102 modify_bgp_config_when_bgpd_down
,
103 verify_graceful_restart_timers
,
104 verify_bgp_convergence_from_running_config
,
107 from lib
.common_config
import (
109 reset_config_on_routers
,
112 start_router_daemons
,
118 get_frr_ipv6_linklocal
,
119 required_linux_kernel_version
,
122 pytestmark
= [pytest
.mark
.bgpd
]
126 BGP_CONVERGENCE
= False
128 GR_SELECT_DEFER_TIMER
= 5
129 GR_STALEPATH_TIMER
= 5
130 PREFERRED_NEXT_HOP
= "link_local"
131 NEXT_HOP_4
= ["192.168.1.1", "192.168.4.2"]
132 NEXT_HOP_6
= ["fd00:0:0:1::1", "fd00:0:0:4::2"]
135 def setup_module(mod
):
137 Sets up the pytest environment
142 # Required linux kernel version for this suite to run.
143 result
= required_linux_kernel_version("4.16")
144 if result
is not True:
145 pytest
.skip("Kernel requirements are not met, kernel version should be >=4.16")
149 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
150 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
151 logger
.info("=" * 40)
153 logger
.info("Running setup_module to create topology")
155 # This function initiates the topology build with Topogen...
156 json_file
= "{}/bgp_gr_topojson_topo2.json".format(CWD
)
157 tgen
= Topogen(json_file
, mod
.__name
__)
159 topo
= tgen
.json_topo
160 # ... and here it calls Mininet initialization functions.
162 # Starting topology, create tmp files which are loaded to routers
163 # to start daemons and then start routers
166 # Creating configuration from JSON
167 build_config_from_json(tgen
, topo
)
169 # Api call verify whether BGP is converged
170 ADDR_TYPES
= check_address_types()
172 for addr_type
in ADDR_TYPES
:
173 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
174 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error:" " {}".format(
178 logger
.info("Running setup_module() done")
181 def teardown_module(mod
):
183 Teardown the pytest environment
188 logger
.info("Running teardown_module to delete topology")
192 # Stop toplogy and Remove tmp files
196 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
198 logger
.info("=" * 40)
201 def configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
, peer
):
203 This function groups the repetitive function calls into one function.
206 logger
.info("configure_gr_followed_by_clear: dut %s peer %s", dut
, peer
)
208 result
= create_router_bgp(tgen
, topo
, input_dict
)
209 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
211 for addr_type
in ADDR_TYPES
:
212 neighbor
= topo
["routers"][peer
]["links"][dut
][addr_type
].split("/")[0]
213 clear_bgp(tgen
, addr_type
, dut
, neighbor
=neighbor
)
215 for addr_type
in ADDR_TYPES
:
216 neighbor
= topo
["routers"][dut
]["links"][peer
][addr_type
].split("/")[0]
217 clear_bgp(tgen
, addr_type
, peer
, neighbor
=neighbor
)
219 result
= verify_bgp_convergence_from_running_config(tgen
)
220 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
225 def next_hop_per_address_family(tgen
, dut
, peer
, addr_type
, next_hop_dict
):
227 This function returns link_local or global next_hop per address-family
230 intferface
= topo
["routers"][peer
]["links"]["{}-link1".format(dut
)]["interface"]
231 if addr_type
== "ipv6" and "link_local" in PREFERRED_NEXT_HOP
:
232 next_hop
= get_frr_ipv6_linklocal(tgen
, peer
, intf
=intferface
)
234 next_hop
= next_hop_dict
[addr_type
]
239 def test_BGP_GR_chaos_34_1_p1(request
):
241 Test Objective : Restarting node doesn't preserve forwarding
242 state, helper router should not keep the stale entries.
246 tc_name
= request
.node
.name
247 write_test_header(tc_name
)
249 # Check router status
250 check_router_status(tgen
)
252 # Don't run this test if we have any failure.
253 if tgen
.routers_have_failure():
254 pytest
.skip(tgen
.errors
)
256 # Creating configuration from JSON
257 reset_config_on_routers(tgen
)
260 " Test Case : test_BGP_GR_chaos_31 "
262 "[Restart Mode]R1---R3[Helper Mode]"
265 # Configure graceful-restart
269 "graceful-restart": {
270 "preserve-fw-state": True,
271 "timer": {"restart-time": GR_RESTART_TIMER
},
277 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
284 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
299 "r3": {"graceful-restart-helper": True}
310 "r3": {"graceful-restart-helper": True}
321 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r3")
323 for addr_type
in ADDR_TYPES
:
324 result
= verify_graceful_restart(
325 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
327 assert result
is True, "Testcase {} : Failed \n Error {}".format(
331 # Verifying BGP RIB routes after starting BGPd daemon
333 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
334 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
335 assert result
is True, "Testcase {} : Failed \n Error {}".format(
339 # Verifying RIB routes
340 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
341 assert result
is True, "Testcase {} : Failed \n Error {}".format(
346 "[Step 1] : Remove the preserve-fw-state command"
347 " from restarting node R1's config"
350 # Configure graceful-restart to set f-bit as False
351 input_dict_2
= {"r1": {"bgp": {"graceful-restart": {"preserve-fw-state": False}}}}
353 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
354 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
356 logger
.info("[Step 2] : Reset the session between R1 and R3..")
359 for addr_type
in ADDR_TYPES
:
360 clear_bgp(tgen
, addr_type
, "r1")
362 result
= verify_bgp_convergence_from_running_config(tgen
, topo
)
363 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
365 for addr_type
in ADDR_TYPES
:
366 # Verify f-bit after starting BGPd daemon
367 result
= verify_f_bit(
368 tgen
, topo
, addr_type
, input_dict_2
, "r3", "r1", expected
=False
370 assert result
is not True, (
371 "Testcase {} : Failed \n "
372 "Expected: F-bit should not be set to True in r3\n"
373 "Found: {}".format(tc_name
, result
)
376 logger
.info("[Step 3] : Kill BGPd daemon on R1..")
378 # Kill BGPd daemon on R1
379 kill_router_daemons(tgen
, "r1", ["bgpd"])
381 # Waiting for GR_RESTART_TIMER
382 logger
.info("Waiting for {} sec..".format(GR_RESTART_TIMER
))
383 sleep(GR_RESTART_TIMER
)
385 for addr_type
in ADDR_TYPES
:
386 # Verifying BGP RIB routes
387 input_dict
= {key
: topo
["routers"][key
] for key
in ["r1"]}
388 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict
, expected
=False)
389 assert result
is not True, (
390 "Testcase {} : Failed \n "
391 "Expected: Routes should not be present in {} BGP RIB \n "
392 "Found: {}".format(tc_name
, dut
, result
)
395 # Verifying RIB routes
396 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, expected
=False)
397 assert result
is not True, (
398 "Testcase {} : Failed \n "
399 "Expected: Routes should not be present in {} FIB \n "
400 "Found: {}".format(tc_name
, dut
, result
)
403 # Start BGPd daemon on R1
404 start_router_daemons(tgen
, "r1", ["bgpd"])
406 write_test_footer(tc_name
)
409 def test_BGP_GR_chaos_32_p1(request
):
411 Test Objective : Restarting node is connected to multiple helper
412 nodes, one of them doesn't send EOR to restarting router. Verify
413 that only after SDT restarting node send EOR to all helper peers
414 excluding the prefixes originated by faulty router.
418 tc_name
= request
.node
.name
419 write_test_header(tc_name
)
421 # Check router status
422 check_router_status(tgen
)
424 # Don't run this test if we have any failure.
425 if tgen
.routers_have_failure():
426 pytest
.skip(tgen
.errors
)
428 # Creating configuration from JSON
429 reset_config_on_routers(tgen
)
432 " Test Case : test_BGP_GR_chaos_32 "
434 "[Restart Mode]R1---R3&R5[Helper Mode]"
438 "[Step 1] : Change the mode on R1 be a restarting" " node on global level"
441 # Configure graceful-restart
445 "graceful-restart": {"graceful-restart": True},
450 "r3": {"dest_link": {"r1": {"next_hop_self": True}}},
451 "r5": {"dest_link": {"r1": {"graceful-restart": True}}},
458 "r3": {"dest_link": {"r1": {"next_hop_self": True}}},
459 "r5": {"dest_link": {"r1": {"graceful-restart": True}}},
474 "r5": {"graceful-restart-helper": True}
485 "r5": {"graceful-restart-helper": True}
496 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r5")
498 for addr_type
in ADDR_TYPES
:
499 result
= verify_graceful_restart(
500 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r5"
502 assert result
is True, "Testcase {} : Failed \n Error {}".format(
506 # Verifying BGP RIB routes after starting BGPd daemon
508 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r5"]}
509 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
510 assert result
is True, "Testcase {} : Failed \n Error {}".format(
514 # Verifying RIB routes
515 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
516 assert result
is True, "Testcase {} : Failed \n Error {}".format(
520 logger
.info("[Step 2] : Kill BGPd daemon on R1..")
521 # Kill BGPd daemon on R1
522 kill_router_daemons(tgen
, "r1", ["bgpd"])
524 logger
.info("[Step 3] : Withdraw all the advertised prefixes from R5")
526 # Api call to delete advertised networks
527 network
= {"ipv4": "105.0.20.1/32", "ipv6": "5::1/128"}
528 for addr_type
in ADDR_TYPES
:
535 "advertise_networks": [
537 "network": network
[addr_type
],
549 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
550 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
555 "[Step 4] : Stop the helper router R5 from sending EOR" " message using CLI"
558 # Modify graceful-restart config to prevent sending EOR
559 input_dict_3
= {"r5": {"bgp": {"graceful-restart": {"disable-eor": True}}}}
561 result
= create_router_bgp(tgen
, topo
, input_dict_3
)
562 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
564 logger
.info("[Step 5] : Bring up the BGPd daemon on R1..")
566 # Start BGPd daemon on R1
567 start_router_daemons(tgen
, "r1", ["bgpd"])
569 for addr_type
in ADDR_TYPES
:
570 # Verify EOR is disabled
572 tgen
, topo
, addr_type
, input_dict_3
, dut
="r5", peer
="r1", expected
=False
574 assert result
is not True, (
575 "Testcase {} : Failed \n "
576 "Expected: EOR should not be set to True in r5\n"
577 "Found: {}".format(tc_name
, result
)
580 # Verifying BGP RIB routes after starting BGPd daemon
581 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r5"]}
582 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
, expected
=False)
583 assert result
is not True, (
584 "Testcase {} : Failed \n "
585 "Expected: Routes should not be present in {} BGP RIB \n "
586 "Found: {}".format(tc_name
, dut
, result
)
589 # Verifying RIB routes
590 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
, expected
=False)
591 assert result
is not True, (
592 "Testcase {} : Failed \n "
593 "Expected: Routes should not be present in {} FIB \n "
594 "Found: {}".format(tc_name
, dut
, result
)
597 write_test_footer(tc_name
)
600 def test_BGP_GR_chaos_37_p1(request
):
602 Test Objective : Verify if helper node restarts before sending the
603 EOR message, restarting node doesn't wait until stale path timer
604 expiry to do the best path selection and sends an EOR
608 tc_name
= request
.node
.name
609 write_test_header(tc_name
)
611 # Check router status
612 check_router_status(tgen
)
614 # Don't run this test if we have any failure.
615 if tgen
.routers_have_failure():
616 pytest
.skip(tgen
.errors
)
618 # Creating configuration from JSON
619 reset_config_on_routers(tgen
)
622 " Test Case : test_BGP_GR_chaos_37 "
624 "[Restart Mode]R1---R3[Helper Mode]"
628 "[Step 1] : Configure restarting router R3 to prevent " "sending an EOR.."
631 logger
.info("[Step 2] : Reset the session between R3 and R1..")
633 # Configure graceful-restart
641 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
648 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
657 "graceful-restart": {"disable-eor": True},
664 "r3": {"graceful-restart-helper": True}
675 "r3": {"graceful-restart-helper": True}
686 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r3")
688 for addr_type
in ADDR_TYPES
:
689 result
= verify_graceful_restart(
690 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
692 assert result
is True, "Testcase {} : Failed \n Error {}".format(
696 # Verify EOR is disabled
698 tgen
, topo
, addr_type
, input_dict
, dut
="r3", peer
="r1", expected
=False
700 assert result
is not True, (
701 "Testcase {} : Failed \n "
702 "Expected: EOR should not be set to True in r3\n"
703 "Found: {}".format(tc_name
, result
)
706 # Verifying BGP RIB routes after starting BGPd daemon
708 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
709 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
710 assert result
is True, "Testcase {} : Failed \n Error {}".format(
714 # Verifying RIB routes
715 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
716 assert result
is True, "Testcase {} : Failed \n Error {}".format(
720 logger
.info("[Step 3] : Kill BGPd daemon on R1..")
722 # Kill BGPd daemon on R1
723 kill_router_daemons(tgen
, "r1", ["bgpd"])
725 logger
.info("[Step 4] : Start BGPd daemon on R1..")
727 # Start BGPd daemon on R1
728 start_router_daemons(tgen
, "r1", ["bgpd"])
730 logger
.info("[Step 5] : Kill BGPd daemon on R3..")
732 # Kill BGPd daemon on R3
733 kill_router_daemons(tgen
, "r3", ["bgpd"])
735 # Modify graceful-restart config to prevent sending EOR
736 input_dict_2
= {"r3": {"bgp": {"graceful-restart": {"disable-eor": True}}}}
738 result
= modify_bgp_config_when_bgpd_down(tgen
, topo
, input_dict_2
)
739 assert result
is True, "Testcase {} : Failed \n Error {}".format(tc_name
, result
)
741 logger
.info("[Step 6] : Start BGPd daemon on R3..")
743 # Start BGPd daemon on R3
744 start_router_daemons(tgen
, "r3", ["bgpd"])
746 for addr_type
in ADDR_TYPES
:
748 result
= verify_r_bit(tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3")
749 assert result
is True, "Testcase {} : Failed \n Error {}".format(
753 # Verifying RIB routes
754 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
755 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
756 assert result
is True, "Testcase {} : Failed \n Error {}".format(
760 # Verify EOR is send from R1 to R3
761 input_dict_3
= {"r1": {"bgp": {"graceful-restart": {"disable-eor": True}}}}
764 tgen
, topo
, addr_type
, input_dict_3
, dut
="r1", peer
="r3", expected
=False
766 assert result
is not True, (
767 "Testcase {} : Failed \n "
768 "Expected: EOR should not be set to True in r1\n"
769 "Found: {}".format(tc_name
, result
)
772 write_test_footer(tc_name
)
775 def test_BGP_GR_chaos_30_p1(request
):
777 Test Objective : Restarting node removes stale routes from Zebra
778 after receiving an EOR from helper router.
782 tc_name
= request
.node
.name
783 write_test_header(tc_name
)
785 # Check router status
786 check_router_status(tgen
)
788 # Don't run this test if we have any failure.
789 if tgen
.routers_have_failure():
790 pytest
.skip(tgen
.errors
)
792 # Creating configuration from JSON
793 reset_config_on_routers(tgen
)
796 " Test Case : test_BGP_GR_chaos_30 "
797 "BGP GR [Helper Mode]R3-----R1[Restart Mode] "
800 # Configure graceful-restart and timers
804 "graceful-restart": {"preserve-fw-state": True},
809 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
816 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
831 "r3": {"graceful-restart-helper": True}
842 "r3": {"graceful-restart-helper": True}
853 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r3")
855 for addr_type
in ADDR_TYPES
:
856 result
= verify_graceful_restart(
857 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
859 assert result
is True, "Testcase {} : Failed \n Error {}".format(
863 for addr_type
in ADDR_TYPES
:
864 # Verifying BGP RIB routes before shutting down BGPd daemon
866 input_dict
= {key
: topo
["routers"][key
] for key
in ["r3"]}
867 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict
)
868 assert result
is True, "Testcase {} : Failed \n Error {}".format(
872 # Verifying RIB routes before shutting down BGPd daemon
873 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
)
874 assert result
is True, "Testcase {} : Failed \n Error {}".format(
878 logger
.info("[Step 2] : Kill BGPd daemon on R1..")
880 # Kill BGPd daemon on R1
881 kill_router_daemons(tgen
, "r1", ["bgpd"])
883 logger
.info("[Step 3] : Withdraw advertised prefixes from R3...")
885 # Api call to delete advertised networks
886 network
= {"ipv4": "103.0.20.1/32", "ipv6": "3::1/128"}
887 for addr_type
in ADDR_TYPES
:
894 "advertise_networks": [
896 "network": network
[addr_type
],
908 result
= create_router_bgp(tgen
, topo
, input_dict
)
909 assert result
is True, "Testcase {} : Failed \n Error: {}".format(
913 logger
.info("[Step 4] : Start BGPd daemon on R1..")
915 # Start BGPd daemon on R1
916 start_router_daemons(tgen
, "r1", ["bgpd"])
918 for addr_type
in ADDR_TYPES
:
919 # Verifying BGP RIB routes before shutting down BGPd daemon
920 input_dict
= {key
: topo
["routers"][key
] for key
in ["r3"]}
921 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict
, expected
=False)
922 assert result
is not True, (
923 "Testcase {} : Failed \n "
924 "Expected: Routes should not be present in {} BGP RIB \n "
925 "Found: {}".format(tc_name
, dut
, result
)
928 # Verifying RIB routes before shutting down BGPd daemon
929 result
= verify_rib(tgen
, addr_type
, dut
, input_dict
, expected
=False)
930 assert result
is not True, (
931 "Testcase {} : Failed \n "
932 "Expected: Routes should not be present in {} FIB \n "
933 "Found: {}".format(tc_name
, dut
, result
)
936 write_test_footer(tc_name
)
939 def test_BGP_GR_15_p2(request
):
941 Test Objective : Test GR scenarios by enabling Graceful Restart
942 for multiple address families..
946 tc_name
= request
.node
.name
947 write_test_header(tc_name
)
949 # Check router status
950 check_router_status(tgen
)
952 # Don't run this test if we have any failure.
953 if tgen
.routers_have_failure():
954 pytest
.skip(tgen
.errors
)
956 # Creating configuration from JSON
957 reset_config_on_routers(tgen
)
959 # Configure graceful-restart
967 "r6": {"dest_link": {"r1": {"graceful-restart": True}}}
974 "r6": {"dest_link": {"r1": {"graceful-restart": True}}}
989 "r6": {"graceful-restart-helper": True}
1000 "r6": {"graceful-restart-helper": True}
1011 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r6")
1013 for addr_type
in ADDR_TYPES
:
1014 result
= verify_graceful_restart(
1015 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r6"
1017 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1020 "[Step 2] : Test Setup "
1021 "[Helper Mode]R6-----R1[Restart Mode]"
1022 "--------R2[Helper Mode] Initialized"
1025 # Configure graceful-restart
1033 "r2": {"dest_link": {"r1": {"graceful-restart": True}}}
1040 "r2": {"dest_link": {"r1": {"graceful-restart": True}}}
1055 "r2": {"graceful-restart-helper": True}
1066 "r2": {"graceful-restart-helper": True}
1077 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
1079 for addr_type
in ADDR_TYPES
:
1080 result
= verify_graceful_restart(
1081 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1083 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1085 # Verifying BGP RIB routes
1087 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
1088 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1089 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1091 # Verifying RIB routes before shutting down BGPd daemon
1092 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1093 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1095 # Verifying BGP RIB routes
1097 input_dict_2
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1098 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_2
)
1099 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1101 # Verifying RIB routes before shutting down BGPd daemon
1102 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_2
)
1103 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1105 # Kill BGPd daemon on R1
1106 kill_router_daemons(tgen
, "r1", ["bgpd"])
1108 for addr_type
in ADDR_TYPES
:
1109 # Verifying BGP RIB routes
1111 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
1112 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1113 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1115 # Verifying RIB routes before shutting down BGPd daemon
1116 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1117 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1119 # Verifying BGP RIB routes
1121 input_dict_2
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1122 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_2
)
1123 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1125 # Verifying RIB routes before shutting down BGPd daemon
1126 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_2
)
1127 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1129 # Start BGPd daemon on R1
1130 start_router_daemons(tgen
, "r1", ["bgpd"])
1132 for addr_type
in ADDR_TYPES
:
1133 result
= verify_bgp_convergence(tgen
, topo
)
1134 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1136 # Verifying BGP RIB routes
1138 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
1139 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1140 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1142 # Verifying RIB routes before shutting down BGPd daemon
1143 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1144 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1146 # Verifying BGP RIB routes
1148 input_dict_2
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1149 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_2
)
1150 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1152 # Verifying RIB routes before shutting down BGPd daemon
1153 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_2
)
1154 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1156 write_test_footer(tc_name
)
1159 def BGP_GR_TC_7_p1(request
):
1161 Verify that BGP restarting node deletes all the routes received from peer
1162 if BGP Graceful capability is not present in BGP Open message from the
1166 tgen
= get_topogen()
1167 tc_name
= request
.node
.name
1168 write_test_header(tc_name
)
1170 # Check router status
1171 check_router_status(tgen
)
1173 # Don't run this test if we have any failure.
1174 if tgen
.routers_have_failure():
1175 pytest
.skip(tgen
.errors
)
1177 # Creating configuration from JSON
1178 reset_config_on_routers(tgen
)
1181 " Verify route download to RIB: BGP_GR_TC_7 >> "
1182 "BGP GR [Helper Mode]R3-----R1[Restart Mode] "
1185 # Configure graceful-restart
1195 "r3": {"graceful-restart-helper": True}
1206 "r3": {"graceful-restart-helper": True}
1217 "graceful-restart": {
1218 "graceful-restart": True,
1219 "preserve-fw-state": True,
1225 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
1232 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
1241 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r3")
1243 for addr_type
in ADDR_TYPES
:
1244 result
= verify_graceful_restart(
1245 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
1247 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1249 # Verifying BGP RIB routes received from router R1
1251 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
1252 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1253 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1255 # Verifying RIB routes
1256 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1257 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1259 logger
.info("R1 goes for reload")
1260 kill_router_daemons(tgen
, "r1", ["bgpd"])
1262 # Change the configuration on router R1
1272 "r3": {"graceful-restart-disable": True}
1283 "r3": {"graceful-restart-disable": True}
1294 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1295 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
1297 # Change the configuration on R1
1298 network
= {"ipv4": "103.0.20.1/32", "ipv6": "3::1/128"}
1299 for addr_type
in ADDR_TYPES
:
1306 "advertise_networks": [
1308 "network": network
[addr_type
],
1320 result
= create_router_bgp(tgen
, topo
, input_dict_2
)
1321 assert result
is True, "Testcase {} :Failed \n Error {}".format(tc_name
, result
)
1323 logger
.info("R1 is about to come up now")
1324 start_router_daemons(tgen
, "r1", ["bgpd"])
1325 logger
.info("R1 is UP Now")
1327 # Wait for RIB stale timeout
1328 logger
.info("Verify routes are not present" "in restart router")
1330 for addr_type
in ADDR_TYPES
:
1331 # Verifying RIB routes
1333 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
1334 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
, expected
=False)
1335 assert result
is not True, (
1336 "Testcase {} : Failed \n "
1337 "Expected: Routes should not be present in {} FIB \n "
1338 "Found: {}".format(tc_name
, dut
, result
)
1341 write_test_footer(tc_name
)
1344 if __name__
== "__main__":
1345 args
= ["-s"] + sys
.argv
[1:]
1346 sys
.exit(pytest
.main(args
))