3 # Copyright (c) 2019 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
12 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
23 Following tests are covered to test BGP Graceful Restart functionality.
24 Basic Common Test steps for all the test case below :
25 - Create topology (setup module)
26 Creating 7 routers topology
28 - Verify for bgp to converge
29 - Configure BGP Graceful Restart on both the routers.
32 Verify that EOR message is sent out only after initial convergence
33 Verify whether EOR message is received from all the peers after restart
35 Verify the selection deferral timer functionality when EOR is not sent
38 Verify that selection-deferral timer sets the maximum time to
39 avoid deadlock during which the best-path
41 Test Objective : Test GR scenarios on helper router by enabling
42 Graceful Restart for multiple address families.
44 Test Objective : Test GR scenarios by enabling Graceful Restart
45 for multiple address families..
47 Test Objective : Verify BGP-GR feature when restarting node
48 is a transit router for it's iBGP peers.
50 Test Objective : Verify that GR helper router deletes stale routes
51 received from restarting node, if GR capability is not present in
53 Test Objective : Verify that GR routers keeps all the routes
54 received from restarting node if both the routers are
56 Test Objective : Test GR scenarios on helper router by enabling
57 Graceful Restart for multiple address families.
59 Test Objective : Verify if helper node goes down before restarting
60 node comes up online, helper node sets the R-bit to avoid dead-lock
62 Test Objective : Change timers on the fly, and
63 verify if it takes immediate effect.
65 Test Objective : Helper router receives same prefixes from two
66 different routers (GR-restarting and GR-disabled). Keeps the
68 Test Objective : Restarting node doesn't preserve forwarding
69 state, helper router should not keep the stale entries.
71 Test Objective : Restarting node doesn't preserve the forwarding
72 state verify the behaviour on helper node, if it still keeps the
74 Test Objective : Restarting node is connected to multiple helper
75 nodes, one of them doesn't send EOR to restarting router. Verify
77 Test Objective : Verify if helper node restarts before sending the
78 EOR message, restarting node doesn't wait until stale path timer
80 Test Objective : Restarting node removes stale routes from Zebra
81 after receiving an EOR from helper router.
89 from time
import sleep
91 # Save the Current Working Directory to find configuration files.
92 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
93 sys
.path
.append(os
.path
.join("../"))
94 sys
.path
.append(os
.path
.join("../lib/"))
96 # pylint: disable=C0413
97 # Import topogen and topotest helpers
98 from lib
.topogen
import Topogen
, get_topogen
99 from lib
.topolog
import logger
101 # Required to instantiate the topology builder class.
103 # Import topoJson from lib, to create topology and initial configuration
104 from lib
.topojson
import build_config_from_json
105 from lib
.bgp
import (
108 verify_graceful_restart
,
113 verify_bgp_convergence
,
114 verify_gr_address_family
,
115 modify_bgp_config_when_bgpd_down
,
116 verify_graceful_restart_timers
,
117 verify_bgp_convergence_from_running_config
,
120 from lib
.common_config
import (
122 reset_config_on_routers
,
125 start_router_daemons
,
131 get_frr_ipv6_linklocal
,
132 required_linux_kernel_version
,
135 pytestmark
= [pytest
.mark
.bgpd
]
139 BGP_CONVERGENCE
= False
141 GR_SELECT_DEFER_TIMER
= 5
142 GR_STALEPATH_TIMER
= 5
143 PREFERRED_NEXT_HOP
= "link_local"
144 NEXT_HOP_4
= ["192.168.1.1", "192.168.4.2"]
145 NEXT_HOP_6
= ["fd00:0:0:1::1", "fd00:0:0:4::2"]
148 def setup_module(mod
):
150 Sets up the pytest environment
155 # Required linux kernel version for this suite to run.
156 result
= required_linux_kernel_version("4.16")
157 if result
is not True:
158 pytest
.skip("Kernel requirements are not met, kernel version should be >=4.16")
162 testsuite_run_time
= time
.asctime(time
.localtime(time
.time()))
163 logger
.info("Testsuite start time: {}".format(testsuite_run_time
))
164 logger
.info("=" * 40)
166 logger
.info("Running setup_module to create topology")
168 # This function initiates the topology build with Topogen...
169 json_file
= "{}/bgp_gr_topojson_topo2.json".format(CWD
)
170 tgen
= Topogen(json_file
, mod
.__name
__)
172 topo
= tgen
.json_topo
173 # ... and here it calls Mininet initialization functions.
175 # Starting topology, create tmp files which are loaded to routers
176 # to start daemons and then start routers
179 # Creating configuration from JSON
180 build_config_from_json(tgen
, topo
)
182 # Api call verify whether BGP is converged
183 ADDR_TYPES
= check_address_types()
185 for addr_type
in ADDR_TYPES
:
186 BGP_CONVERGENCE
= verify_bgp_convergence(tgen
, topo
)
187 assert BGP_CONVERGENCE
is True, "setup_module : Failed \n Error:" " {}".format(
191 logger
.info("Running setup_module() done")
194 def teardown_module(mod
):
196 Teardown the pytest environment
201 logger
.info("Running teardown_module to delete topology")
205 # Stop toplogy and Remove tmp files
209 "Testsuite end time: {}".format(time
.asctime(time
.localtime(time
.time())))
211 logger
.info("=" * 40)
214 def configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
, peer
):
216 This function groups the repetitive function calls into one function.
219 logger
.info("configure_gr_followed_by_clear: dut %s peer %s", dut
, peer
)
221 result
= create_router_bgp(tgen
, topo
, input_dict
)
222 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
224 for addr_type
in ADDR_TYPES
:
225 neighbor
= topo
["routers"][peer
]["links"][dut
][addr_type
].split("/")[0]
226 clear_bgp(tgen
, addr_type
, dut
, neighbor
=neighbor
)
228 for addr_type
in ADDR_TYPES
:
229 neighbor
= topo
["routers"][dut
]["links"][peer
][addr_type
].split("/")[0]
230 clear_bgp(tgen
, addr_type
, peer
, neighbor
=neighbor
)
232 result
= verify_bgp_convergence_from_running_config(tgen
)
233 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
238 def next_hop_per_address_family(tgen
, dut
, peer
, addr_type
, next_hop_dict
):
240 This function returns link_local or global next_hop per address-family
243 intferface
= topo
["routers"][peer
]["links"]["{}-link1".format(dut
)]["interface"]
244 if addr_type
== "ipv6" and "link_local" in PREFERRED_NEXT_HOP
:
245 next_hop
= get_frr_ipv6_linklocal(tgen
, peer
, intf
=intferface
)
247 next_hop
= next_hop_dict
[addr_type
]
252 def test_BGP_GR_TC_1_2_p0(request
):
254 Verify that EOR message is sent out only after initial convergence
255 Verify whether EOR message is received from all the peers after restart
259 tc_name
= request
.node
.name
260 write_test_header(tc_name
)
262 # Check router status
263 check_router_status(tgen
)
265 # Don't run this test if we have any failure.
266 if tgen
.routers_have_failure():
267 pytest
.skip(tgen
.errors
)
269 # Creating configuration from JSON
270 reset_config_on_routers(tgen
)
273 "Verify EOR Sent and Received : BGP_GR_TC_1_2 >> "
274 "BGP GR [Helper Mode]R3-----R1[Restart Mode] "
277 # Configure graceful-restart
287 "r3": {"graceful-restart-helper": True}
298 "r3": {"graceful-restart-helper": True}
309 "graceful-restart": {
310 "graceful-restart": True,
311 "preserve-fw-state": True,
317 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
324 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
333 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r3")
335 for addr_type
in ADDR_TYPES
:
336 result
= verify_graceful_restart(
337 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
339 assert result
is True, "Testcase {} : Failed \n Error {}".format(
343 # Verifying BGP RIB routes received from router R3
345 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
346 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
347 assert result
is True, "Testcase {} : Failed \n Error {}".format(
351 # Verifying RIB routes
352 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
353 assert result
is True, "Testcase {} : Failed \n Error {}".format(
357 logger
.info("R1 goes for reload")
358 kill_router_daemons(tgen
, "r1", ["bgpd"])
360 for addr_type
in ADDR_TYPES
:
361 # Verifying RIB routes
362 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
363 # Verifying RIB routes
364 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
365 assert result
is True, "Testcase {} : Failed \n Error {}".format(
369 logger
.info("Starting bgpd process")
370 start_router_daemons(tgen
, "r1", ["bgpd"])
371 logger
.info("R1 is UP Now")
373 for addr_type
in ADDR_TYPES
:
374 result
= verify_graceful_restart(
375 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
377 assert result
is True, "Testcase {} : Failed \n Error {}".format(
381 # Verifying BGP RIB routes received from router R3
382 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
383 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
384 assert result
is True, "Testcase {} : Failed \n Error {}".format(
388 # Verifying RIB routes
389 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
390 assert result
is True, "Testcase {} : Failed \n Error {}".format(
394 # Verifying EOR on restarting router
395 result
= verify_eor(tgen
, topo
, addr_type
, input_dict
, dut
="r3", peer
="r1")
396 assert result
is True, "Testcase {} : Failed \n Error {}".format(
400 write_test_footer(tc_name
)
403 def test_BGP_GR_TC_3_p0(request
):
405 Verify the selection deferral timer functionality when EOR is not sent
410 tc_name
= request
.node
.name
411 write_test_header(tc_name
)
413 # Check router status
414 check_router_status(tgen
)
416 # Don't run this test if we have any failure.
417 if tgen
.routers_have_failure():
418 pytest
.skip(tgen
.errors
)
420 # Creating configuration from JSON
421 reset_config_on_routers(tgen
)
424 " Verify route download to RIB: BGP_GR_TC_3 >> "
425 "BGP GR [Helper Mode]R1-----R2[Restart Mode] "
428 # Configure graceful-restart
432 "graceful-restart": {
441 "r1": {"graceful-restart-helper": True}
452 "r1": {"graceful-restart-helper": True}
463 "graceful-restart": {
464 "graceful-restart": True,
465 "preserve-fw-state": True,
466 "timer": {"select-defer-time": GR_SELECT_DEFER_TIMER
},
472 "r1": {"dest_link": {"r2": {"graceful-restart": True}}}
479 "r1": {"dest_link": {"r2": {"graceful-restart": True}}}
488 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
490 for addr_type
in ADDR_TYPES
:
491 result
= verify_graceful_restart(
492 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
494 assert result
is True, "Testcase {} : Failed \n Error {}".format(
498 # Verifying BGP RIB routes received from router R1
500 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
501 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
502 assert result
is True, "Testcase {} : Failed \n Error {}".format(
506 # Verifying RIB routes
507 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
508 assert result
is True, "Testcase {} : Failed \n Error {}".format(
512 logger
.info("R2 goes for reload ")
513 kill_router_daemons(tgen
, "r2", ["bgpd"])
515 logger
.info("R2 is about to come up now")
516 start_router_daemons(tgen
, "r2", ["bgpd"])
517 logger
.info("R2 is UP Now")
519 for addr_type
in ADDR_TYPES
:
520 # Verifying BGP RIB routes received from router R1
521 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
522 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
523 assert result
is True, "Testcase {} : Failed \n Error {}".format(
527 # Verify EOR on restarting router
529 tgen
, topo
, addr_type
, input_dict
, dut
="r2", peer
="r1", expected
=False
531 assert result
is not True, (
532 "Testcase {} : Failed \n "
533 "Expected: EOR should not be set to True in r2\n"
534 "Found: {}".format(tc_name
, result
)
538 "Waiting for selection deferral timer({} sec)..".format(GR_SELECT_DEFER_TIMER
)
540 sleep(GR_SELECT_DEFER_TIMER
)
542 for addr_type
in ADDR_TYPES
:
543 # Verifying RIB routes
544 result
= verify_rib(tgen
, addr_type
, "r2", input_dict_1
)
545 assert result
is True, "Testcase {} : Failed \n Error {}".format(
549 write_test_footer(tc_name
)
552 def test_BGP_GR_TC_11_p0(request
):
554 Verify that selection-deferral timer sets the maximum time to
555 avoid deadlock during which the best-path
556 selection process is deferred, after a peer session was restarted
560 tc_name
= request
.node
.name
561 write_test_header(tc_name
)
563 # Check router status
564 check_router_status(tgen
)
566 # Don't run this test if we have any failure.
567 if tgen
.routers_have_failure():
568 pytest
.skip(tgen
.errors
)
570 # Creating configuration from JSON
571 reset_config_on_routers(tgen
)
573 logger
.info("Verify EOR Sent after deferral timeout : BGP_GR_TC_11")
575 # Configure graceful-restart
579 "graceful-restart": {
580 "graceful-restart": True,
581 "select-defer-time": GR_SELECT_DEFER_TIMER
,
587 "r2": {"dest_link": {"r1": {"graceful-restart": True}}},
588 "r3": {"dest_link": {"r1": {"graceful-restart": True}}},
595 "r2": {"dest_link": {"r1": {"graceful-restart": True}}},
596 "r3": {"dest_link": {"r1": {"graceful-restart": True}}},
605 "graceful-restart": {"disable-eor": True},
612 "r3": {"graceful-restart-helper": True}
623 "r3": {"graceful-restart-helper": True}
634 result
= create_router_bgp(tgen
, topo
, input_dict
)
635 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
637 for addr_type
in ADDR_TYPES
:
638 clear_bgp(tgen
, addr_type
, "r1")
639 clear_bgp(tgen
, addr_type
, "r3")
641 result
= verify_bgp_convergence_from_running_config(tgen
, topo
)
642 assert result
is True, "Testcase {} : Failed \n Error: {}".format(tc_name
, result
)
644 for addr_type
in ADDR_TYPES
:
645 result
= verify_graceful_restart(
646 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
648 assert result
is True, "Testcase {} : Failed \n Error {}".format(
652 # Verifying BGP RIB routes received from router R1
654 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
655 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
656 assert result
is True, "Testcase {} : Failed \n Error {}".format(
660 # Verifying RIB routes
661 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
662 assert result
is True, "Testcase {} : Failed \n Error {}".format(
666 logger
.info("R1 goes for reload")
667 kill_router_daemons(tgen
, "r1", ["bgpd"])
669 logger
.info("Starting bgpd process")
670 start_router_daemons(tgen
, "r1", ["bgpd"])
671 logger
.info("R1 is UP Now")
673 for addr_type
in ADDR_TYPES
:
674 # Verify EOR on restarting router
676 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3", expected
=False
678 assert result
is not True, (
679 "Testcase {} : Failed \n "
680 "Expected: EOR should not be set to True in r1\n"
681 "Found: {}".format(tc_name
, result
)
685 "Waiting for selection deferral timer({} sec).. ".format(
686 GR_SELECT_DEFER_TIMER
+ 2
689 sleep(GR_SELECT_DEFER_TIMER
+ 2)
691 for addr_type
in ADDR_TYPES
:
692 # Verifying BGP RIB routes received from router R1
693 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r3"]}
694 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
695 assert result
is True, "Testcase {} : Failed \n Error {}".format(
699 # Verifying RIB routes
700 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
701 assert result
is True, "Testcase {} : Failed \n Error {}".format(
705 # Verifying EOR on restarting router
707 tgen
, topo
, addr_type
, input_dict
, dut
="r3", peer
="r1", expected
=False
709 assert result
is not True, (
710 "Testcase {} : Failed \n "
711 "Expected: EOR should not be set to True in r3\n"
712 "Found: {}".format(tc_name
, result
)
715 write_test_footer(tc_name
)
718 def test_BGP_GR_10_p2(request
):
720 Test Objective : Test GR scenarios on helper router by enabling
721 Graceful Restart for multiple address families.
725 tc_name
= request
.node
.name
726 write_test_header(tc_name
)
728 # Check router status
729 check_router_status(tgen
)
731 # Don't run this test if we have any failure.
732 if tgen
.routers_have_failure():
733 pytest
.skip(tgen
.errors
)
735 # Creating configuration from JSON
736 reset_config_on_routers(tgen
)
738 step("Test Setup: [Helper Mode]R3-----R1[Restart Mode] initialized")
740 # Configure graceful-restart
751 "next_hop_self": True,
752 "graceful-restart": True,
766 "next_hop_self": True,
767 "graceful-restart": True,
787 "graceful-restart-helper": True,
801 "graceful-restart-helper": True,
814 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r3")
816 for addr_type
in ADDR_TYPES
:
818 "Verifying GR config and operational state for addr_type {}".format(
823 result
= verify_graceful_restart(
824 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
826 assert result
is True, "Testcase {} : Failed \n Error {}".format(
830 # Verifying BGP RIB routes
832 input_topo
= {key
: topo
["routers"][key
] for key
in ["r1"]}
833 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_topo
)
834 assert result
is True, "Testcase {} : Failed \n Error {}".format(
838 # Verifying RIB routes before shutting down BGPd daemon
839 result
= verify_rib(tgen
, addr_type
, dut
, input_topo
)
840 assert result
is True, "Testcase {} : Failed \n Error {}".format(
844 # verify multi address family
845 result
= verify_gr_address_family(
853 assert result
is True, "Testcase {} : Failed \n Error {}".format(
857 # verify multi address family
858 result
= verify_gr_address_family(
866 assert result
is True, "Testcase {} : Failed \n Error {}".format(
870 # verify multi address family
871 result
= verify_gr_address_family(
879 assert result
is True, "Testcase {} : Failed \n Error {}".format(
883 # verify multi address family
884 result
= verify_gr_address_family(
892 assert result
is True, "Testcase {} : Failed \n Error {}".format(
896 step("Killing bgpd on r1")
898 # Kill BGPd daemon on R1
899 kill_router_daemons(tgen
, "r1", ["bgpd"])
901 for addr_type
in ADDR_TYPES
:
902 # Verifying BGP RIB routes
903 input_topo
= {key
: topo
["routers"][key
] for key
in ["r1"]}
904 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_topo
)
905 assert result
is True, "Testcase {} : Failed \n Error {}".format(
909 # Verifying RIB routes before shutting down BGPd daemon
910 result
= verify_rib(tgen
, addr_type
, dut
, input_topo
)
911 assert result
is True, "Testcase {} : Failed \n Error {}".format(
915 step("Starting bgpd on r1")
917 # Start BGPd daemon on R1
918 start_router_daemons(tgen
, "r1", ["bgpd"])
920 for addr_type
in ADDR_TYPES
:
921 # Verifying BGP RIB routes
922 input_topo
= {key
: topo
["routers"][key
] for key
in ["r1"]}
923 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_topo
)
924 assert result
is True, "Testcase {} : Failed \n Error {}".format(
928 # Verifying RIB routes before shutting down BGPd daemon
929 result
= verify_rib(tgen
, addr_type
, dut
, input_topo
)
930 assert result
is True, "Testcase {} : Failed \n Error {}".format(
934 write_test_footer(tc_name
)
937 def BGP_GR_16_p2(request
):
939 Test Objective : Verify BGP-GR feature when restarting node
940 is a transit router for it's iBGP peers.
944 tc_name
= request
.node
.name
945 write_test_header(tc_name
)
947 # Check router status
948 check_router_status(tgen
)
950 # Don't run this test if we have any failure.
951 if tgen
.routers_have_failure():
952 pytest
.skip(tgen
.errors
)
954 # Creating configuration from JSON
955 reset_config_on_routers(tgen
)
958 "[Step 1] : Test Setup " "[Helper Mode]R3-----R1[Restart Mode] initialized"
961 # Configure graceful-restart and timers
972 "graceful-restart": True,
973 "next_hop_self": True,
986 "graceful-restart": True,
987 "next_hop_self": True,
1005 "r3": {"graceful-restart-helper": True}
1016 "r3": {"graceful-restart-helper": True}
1027 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r3")
1029 for addr_type
in ADDR_TYPES
:
1030 result
= verify_graceful_restart(
1031 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r3"
1033 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1038 "[Step 2] : Test Setup "
1039 "[Helper Mode]R3-----R1[Restart Mode]"
1040 "--------R6[Helper Mode] initialized"
1043 # Configure graceful-restart and timers
1051 "r2": {"dest_link": {"r1": {"graceful-restart": True}}}
1058 "r2": {"dest_link": {"r1": {"graceful-restart": True}}}
1073 "r2": {"graceful-restart-helper": True}
1084 "r2": {"graceful-restart-helper": True}
1095 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
1097 for addr_type
in ADDR_TYPES
:
1098 result
= verify_graceful_restart(
1099 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1101 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1105 # Verifying BGP RIB routes
1107 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
1108 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1109 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1113 # Verifying RIB routes before shutting down BGPd daemon
1114 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1115 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1119 # Verifying BGP RIB routes
1120 input_dict_2
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1121 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_2
)
1122 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1126 # Verifying RIB routes before shutting down BGPd daemon
1127 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_2
)
1128 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1132 # Kill BGPd daemon on R1
1133 kill_router_daemons(tgen
, "r1", ["bgpd"])
1135 for addr_type
in ADDR_TYPES
:
1136 # Verifying BGP RIB routes
1137 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
1138 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1139 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1143 # Verifying RIB routes before shutting down BGPd daemon
1144 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1145 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1149 # Verifying BGP RIB routes
1150 input_dict_2
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1151 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_2
)
1152 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1156 # Verifying RIB routes before shutting down BGPd daemon
1157 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_2
)
1158 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1162 # Start BGPd daemon on R1
1163 start_router_daemons(tgen
, "r1", ["bgpd"])
1165 for addr_type
in ADDR_TYPES
:
1166 # Verifying BGP RIB routes
1167 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
1168 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1169 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1173 # Verifying RIB routes before shutting down BGPd daemon
1174 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1175 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1179 # Verifying BGP RIB routes
1180 input_dict_2
= {key
: topo
["routers"][key
] for key
in ["r2"]}
1181 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_2
)
1182 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1186 # Verifying RIB routes before shutting down BGPd daemon
1187 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_2
)
1188 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1192 result
= verify_bgp_convergence_from_running_config(tgen
, topo
)
1193 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1197 write_test_footer(tc_name
)
1200 def test_BGP_GR_18_p1(request
):
1202 Test Objective : Verify that GR helper router deletes stale routes
1203 received from restarting node, if GR capability is not present in
1204 restarting node's OPEN message.
1207 tgen
= get_topogen()
1208 tc_name
= request
.node
.name
1209 write_test_header(tc_name
)
1211 # Check router status
1212 check_router_status(tgen
)
1214 # Don't run this test if we have any failure.
1215 if tgen
.routers_have_failure():
1216 pytest
.skip(tgen
.errors
)
1218 # Creating configuration from JSON
1219 reset_config_on_routers(tgen
)
1222 "[Step 1] : Test Setup " "[Helper Mode]R6-----R1[Restart Mode] initialized"
1225 # Configure graceful-restart and timers
1233 "r6": {"dest_link": {"r1": {"graceful-restart": True}}}
1240 "r6": {"dest_link": {"r1": {"graceful-restart": True}}}
1255 "r6": {"graceful-restart-helper": True}
1266 "r6": {"graceful-restart-helper": True}
1277 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r6")
1279 for addr_type
in ADDR_TYPES
:
1280 result
= verify_graceful_restart(
1281 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r6"
1283 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1288 "[Step 2] : Test Setup "
1289 "[Helper Mode]R6-----R1[Restart Mode]"
1290 "--------R2[Helper Mode] initialized"
1293 # Configure graceful-restart and timers
1301 "r2": {"dest_link": {"r1": {"graceful-restart": True}}}
1308 "r2": {"dest_link": {"r1": {"graceful-restart": True}}}
1323 "r2": {"graceful-restart-helper": True}
1334 "r2": {"graceful-restart-helper": True}
1345 configure_gr_followed_by_clear(tgen
, topo
, input_dict
, tc_name
, dut
="r1", peer
="r2")
1347 for addr_type
in ADDR_TYPES
:
1348 result
= verify_graceful_restart(
1349 tgen
, topo
, addr_type
, input_dict
, dut
="r1", peer
="r2"
1351 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1355 # Verifying BGP RIB routes
1357 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
1358 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1359 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1363 # Verifying RIB routes before shutting down BGPd daemon
1364 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1365 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1369 # Verifying BGP RIB routes
1371 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
)
1372 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1376 # Verifying RIB routes before shutting down BGPd daemon
1377 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
)
1378 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1382 # Kill BGPd daemon on R1
1383 kill_router_daemons(tgen
, "r1", ["bgpd"])
1385 logger
.info("[Step 3] : Configure R1 to prevent sending EOR")
1387 # Modify graceful-restart config to prevent sending EOR
1388 input_dict_3
= {"r1": {"bgp": {"graceful-restart": {"disable-eor": True}}}}
1390 result
= modify_bgp_config_when_bgpd_down(tgen
, topo
, input_dict_3
)
1392 # Modify configuration to delete routes
1393 network
= {"ipv4": "101.0.20.1/32", "ipv6": "1::1/128"}
1394 for addr_type
in ADDR_TYPES
:
1401 "advertise_networks": [
1403 "network": network
[addr_type
],
1415 result
= modify_bgp_config_when_bgpd_down(tgen
, topo
, input_dict_3
)
1416 assert result
is True, "Testcase {} : Failed \n Error {}".format(
1420 # Modify graceful-restart config
1430 "r1": {"graceful-restart-disable": True}
1435 "r1": {"graceful-restart-disable": True}
1446 "r1": {"graceful-restart-disable": True}
1451 "r1": {"graceful-restart-disable": True}
1462 result
= modify_bgp_config_when_bgpd_down(tgen
, topo
, input_dict_3
)
1463 assert result
is True, "Testcase {} : Failed \n Error {}".format(tc_name
, result
)
1465 logger
.info("[Step 4] : Bring up the BGPd daemon on R1 for 30" " seconds..")
1467 # Start BGPd daemon on R1
1468 start_router_daemons(tgen
, "r1", ["bgpd"])
1470 for addr_type
in ADDR_TYPES
:
1471 # Verifying BGP RIB routes
1473 input_dict_1
= {key
: topo
["routers"][key
] for key
in ["r1"]}
1474 result
= verify_bgp_rib(tgen
, addr_type
, dut
, input_dict_1
, expected
=False)
1475 assert result
is not True, (
1476 "Testcase {} : Failed \n "
1477 "Expected: Routes should not be present in {} BGP RIB \n "
1478 "Found: {}".format(tc_name
, dut
, result
)
1481 # Verifying RIB routes before shutting down BGPd daemon
1482 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
, expected
=False)
1483 assert result
is not True, (
1484 "Testcase {} : Failed \n "
1485 "Expected: Routes should not be present in {} FIB \n "
1486 "Found: {}".format(tc_name
, dut
, result
)
1489 # Verifying BGP RIB routes
1491 assert result
is not True, (
1492 "Testcase {} : Failed \n "
1493 "Expected: Routes should not be present in {} BGP RIB \n "
1494 "Found: {}".format(tc_name
, dut
, result
)
1497 # Verifying RIB routes before shutting down BGPd daemon
1498 result
= verify_rib(tgen
, addr_type
, dut
, input_dict_1
, expected
=False)
1499 assert result
is not True, (
1500 "Testcase {} : Failed \n "
1501 "Expected: Routes should not be present in {} FIB \n "
1502 "Found: {}".format(tc_name
, dut
, result
)
1505 write_test_footer(tc_name
)
1508 if __name__
== "__main__":
1509 args
= ["-s"] + sys
.argv
[1:]
1510 sys
.exit(pytest
.main(args
))