]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2-4.py
*: manual SPDX License ID conversions
[mirror_frr.git] / tests / topotests / bgp_gr_functionality_topo2 / test_bgp_gr_functionality_topo2-4.py
CommitLineData
b0449478
DS
1#!/usr/bin/env python
2#
3# Copyright (c) 2019 by VMware, Inc. ("VMware")
4# Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
5# in this file.
6#
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
10# in all copies.
11#
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
19# OF THIS SOFTWARE.
20#
21
22"""
23Following tests are covered to test BGP Graceful Restart functionality.
24Basic Common Test steps for all the test case below :
25- Create topology (setup module)
26 Creating 7 routers topology
27- Bring up topology
28- Verify for bgp to converge
29- Configure BGP Graceful Restart on both the routers.
30
31TC_1_2:
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
34TC_3:
35 Verify the selection deferral timer functionality when EOR is not sent
36 by the helper router
37TC_11:
38 Verify that selection-deferral timer sets the maximum time to
39 avoid deadlock during which the best-path
40TC_10:
41 Test Objective : Test GR scenarios on helper router by enabling
42 Graceful Restart for multiple address families.
43TC_15:
44 Test Objective : Test GR scenarios by enabling Graceful Restart
45 for multiple address families..
46TC_16:
47 Test Objective : Verify BGP-GR feature when restarting node
48 is a transit router for it's iBGP peers.
49TC_18:
50 Test Objective : Verify that GR helper router deletes stale routes
51 received from restarting node, if GR capability is not present in
52TC_19:
53 Test Objective : Verify that GR routers keeps all the routes
54 received from restarting node if both the routers are
55TC_26:
56 Test Objective : Test GR scenarios on helper router by enabling
57 Graceful Restart for multiple address families.
58TC_28:
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
61TC_29:
62 Test Objective : Change timers on the fly, and
63 verify if it takes immediate effect.
64TC_33:
65 Test Objective : Helper router receives same prefixes from two
66 different routers (GR-restarting and GR-disabled). Keeps the
67TC_34_1:
68 Test Objective : Restarting node doesn't preserve forwarding
69 state, helper router should not keep the stale entries.
70TC_34_2:
71 Test Objective : Restarting node doesn't preserve the forwarding
72 state verify the behaviour on helper node, if it still keeps the
73TC_32:
74 Test Objective : Restarting node is connected to multiple helper
75 nodes, one of them doesn't send EOR to restarting router. Verify
76TC_37:
77 Test Objective : Verify if helper node restarts before sending the
78 EOR message, restarting node doesn't wait until stale path timer
79TC_30:
80 Test Objective : Restarting node removes stale routes from Zebra
81 after receiving an EOR from helper router.
82
83These tests have been broken up into 4 sub python scripts because
84the totality of run time for this script was greater than 10 minutes
85"""
86
87import os
88import sys
89import time
90import pytest
91from time import sleep
92
93# Save the Current Working Directory to find configuration files.
94CWD = os.path.dirname(os.path.realpath(__file__))
95sys.path.append(os.path.join("../"))
96sys.path.append(os.path.join("../lib/"))
97
98# pylint: disable=C0413
99# Import topogen and topotest helpers
100from lib.topogen import Topogen, get_topogen
101from lib.topolog import logger
102
103# Required to instantiate the topology builder class.
104
105# Import topoJson from lib, to create topology and initial configuration
106from lib.topojson import build_config_from_json
107from lib.bgp import (
108 clear_bgp,
109 verify_bgp_rib,
110 verify_graceful_restart,
111 create_router_bgp,
112 verify_r_bit,
113 verify_eor,
114 verify_f_bit,
115 verify_bgp_convergence,
116 verify_gr_address_family,
117 modify_bgp_config_when_bgpd_down,
118 verify_graceful_restart_timers,
119 verify_bgp_convergence_from_running_config,
120)
121
122from lib.common_config import (
123 write_test_header,
124 reset_config_on_routers,
125 start_topology,
126 kill_router_daemons,
127 start_router_daemons,
128 verify_rib,
129 check_address_types,
130 write_test_footer,
131 check_router_status,
132 step,
133 get_frr_ipv6_linklocal,
134 required_linux_kernel_version,
135)
136
137pytestmark = [pytest.mark.bgpd]
138
139
140# Global variables
141BGP_CONVERGENCE = False
142GR_RESTART_TIMER = 5
143GR_SELECT_DEFER_TIMER = 5
144GR_STALEPATH_TIMER = 5
145PREFERRED_NEXT_HOP = "link_local"
146NEXT_HOP_4 = ["192.168.1.1", "192.168.4.2"]
147NEXT_HOP_6 = ["fd00:0:0:1::1", "fd00:0:0:4::2"]
148
149
150def setup_module(mod):
151 """
152 Sets up the pytest environment
153
154 * `mod`: module name
155 """
156
157 # Required linux kernel version for this suite to run.
158 result = required_linux_kernel_version("4.16")
159 if result is not True:
d63c7094 160 pytest.skip("Kernel requirements are not met, kernel version should be >=4.16")
b0449478
DS
161
162 global ADDR_TYPES
163
164 testsuite_run_time = time.asctime(time.localtime(time.time()))
165 logger.info("Testsuite start time: {}".format(testsuite_run_time))
166 logger.info("=" * 40)
167
168 logger.info("Running setup_module to create topology")
169
170 # This function initiates the topology build with Topogen...
171 json_file = "{}/bgp_gr_topojson_topo2.json".format(CWD)
172 tgen = Topogen(json_file, mod.__name__)
173 global topo
174 topo = tgen.json_topo
175 # ... and here it calls Mininet initialization functions.
176
177 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 178 # to start daemons and then start routers
b0449478
DS
179 start_topology(tgen)
180
181 # Creating configuration from JSON
182 build_config_from_json(tgen, topo)
183
184 # Api call verify whether BGP is converged
185 ADDR_TYPES = check_address_types()
186
187 for addr_type in ADDR_TYPES:
188 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
189 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format(
190 BGP_CONVERGENCE
191 )
192
193 logger.info("Running setup_module() done")
194
195
196def teardown_module(mod):
197 """
198 Teardown the pytest environment
199
200 * `mod`: module name
201 """
202
203 logger.info("Running teardown_module to delete topology")
204
205 tgen = get_topogen()
206
207 # Stop toplogy and Remove tmp files
208 tgen.stop_topology()
209
210 logger.info(
211 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
212 )
213 logger.info("=" * 40)
214
215
216def configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut, peer):
217 """
218 This function groups the repetitive function calls into one function.
219 """
220
221 logger.info("configure_gr_followed_by_clear: dut %s peer %s", dut, peer)
222
223 result = create_router_bgp(tgen, topo, input_dict)
224 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
225
226 for addr_type in ADDR_TYPES:
227 neighbor = topo["routers"][peer]["links"][dut][addr_type].split("/")[0]
228 clear_bgp(tgen, addr_type, dut, neighbor=neighbor)
229
230 for addr_type in ADDR_TYPES:
231 neighbor = topo["routers"][dut]["links"][peer][addr_type].split("/")[0]
232 clear_bgp(tgen, addr_type, peer, neighbor=neighbor)
233
234 result = verify_bgp_convergence_from_running_config(tgen)
235 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
236
237 return True
238
239
240def next_hop_per_address_family(tgen, dut, peer, addr_type, next_hop_dict):
241 """
242 This function returns link_local or global next_hop per address-family
243 """
244
245 intferface = topo["routers"][peer]["links"]["{}-link1".format(dut)]["interface"]
246 if addr_type == "ipv6" and "link_local" in PREFERRED_NEXT_HOP:
247 next_hop = get_frr_ipv6_linklocal(tgen, peer, intf=intferface)
248 else:
249 next_hop = next_hop_dict[addr_type]
250
251 return next_hop
252
253
254def test_BGP_GR_TC_23_p1(request):
255 """
256 Verify that helper routers are deleting stale routes after stale route
257 timer's expiry. If all the routes are not received from restating node
258 after restart.
259 """
260
261 tgen = get_topogen()
262 tc_name = request.node.name
263 write_test_header(tc_name)
264
265 # Check router status
266 check_router_status(tgen)
267
268 # Don't run this test if we have any failure.
269 if tgen.routers_have_failure():
270 pytest.skip(tgen.errors)
271
272 # Creating configuration from JSON
273 reset_config_on_routers(tgen)
274
275 logger.info(
276 "Verify Stale Routes are deleted on helper: BGP_GR_TC_23 >> "
277 "BGP GR [Helper Mode]R1-----R2[Restart Mode] "
278 )
279
280 # Configure graceful-restart
281 input_dict = {
282 "r1": {
283 "bgp": {
284 "graceful-restart": {"timer": {"stalepath-time": GR_STALEPATH_TIMER}},
285 "address_family": {
286 "ipv4": {
287 "unicast": {
288 "neighbor": {
289 "r2": {
290 "dest_link": {
291 "r1": {"graceful-restart-helper": True}
292 }
293 }
294 }
295 }
296 },
297 "ipv6": {
298 "unicast": {
299 "neighbor": {
300 "r2": {
301 "dest_link": {
302 "r1": {"graceful-restart-helper": True}
303 }
304 }
305 }
306 }
307 },
308 },
309 }
310 },
311 "r2": {
312 "bgp": {
313 "graceful-restart": {
314 "graceful-restart": True,
315 "preserve-fw-state": True,
316 },
317 "address_family": {
318 "ipv4": {
319 "unicast": {
320 "neighbor": {
321 "r1": {"dest_link": {"r2": {"graceful-restart": True}}}
322 }
323 }
324 },
325 "ipv6": {
326 "unicast": {
327 "neighbor": {
328 "r1": {"dest_link": {"r2": {"graceful-restart": True}}}
329 }
330 }
331 },
332 },
333 }
334 },
335 }
336
337 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
338
339 for addr_type in ADDR_TYPES:
340 result = verify_graceful_restart(
341 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
342 )
343 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
344
345 # Verifying BGP RIB routes received from router R1
346 dut = "r1"
347 input_dict_1 = {key: topo["routers"][key] for key in ["r2"]}
348 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
349 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
350
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(tc_name, result)
354
355 logger.info("R2 goes for reload")
356 kill_router_daemons(tgen, "r2", ["bgpd"])
357
358 # Modify configuration to delete routes and include disable-eor
359 input_dict_3 = {"r2": {"bgp": {"graceful-restart": {"disable-eor": True}}}}
360
361 result = modify_bgp_config_when_bgpd_down(tgen, topo, input_dict_3)
362
363 # Modify configuration to delete routes and include disable-eor
364 network = {"ipv4": "102.0.20.1/32", "ipv6": "2::1/128"}
365 for addr_type in ADDR_TYPES:
366 input_dict_3 = {
367 "r2": {
368 "bgp": {
369 "address_family": {
370 addr_type: {
371 "unicast": {
372 "advertise_networks": [
373 {
374 "network": network[addr_type],
375 "no_of_network": 3,
376 "delete": True,
377 }
378 ]
379 }
380 }
381 }
382 }
383 }
384 }
385
386 result = modify_bgp_config_when_bgpd_down(tgen, topo, input_dict_3)
387 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
388
389 logger.info("BGPd comes up for r2")
390 start_router_daemons(tgen, "r2", ["bgpd"])
391
392 # Wait for stalepath timer
393 logger.info("Waiting for stalepath timer({} sec..)".format(GR_STALEPATH_TIMER))
394 sleep(GR_STALEPATH_TIMER)
395
396 for addr_type in ADDR_TYPES:
397 clear_bgp(tgen, addr_type, "r2")
398
399 # Verifying RIB routes
400 dut = "r1"
401 network = {"ipv4": "102.0.20.4/32", "ipv6": "2::4/128"}
402 for addr_type in ADDR_TYPES:
403 input_dict_1 = {
404 "r1": {
405 "bgp": {
406 "address_family": {
407 addr_type: {
408 "unicast": {
409 "advertise_networks": [
410 {"network": network[addr_type], "no_of_network": 2}
411 ]
412 }
413 }
414 }
415 }
416 }
417 }
418
419 # Verify EOR on helper router
420 result = verify_eor(
421 tgen, topo, addr_type, input_dict, dut="r1", peer="r2", expected=False
422 )
d63c7094
KK
423 assert result is not True, (
424 "Testcase {} : Failed \n "
425 "Expected: EOR should not be set to True in r2\n"
426 "Found: {}".format(tc_name, result)
b0449478
DS
427 )
428
429 # Verifying BGP RIB routes received from router R1
430 dut = "r1"
431 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
432 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
433
434 write_test_footer(tc_name)
435
436
437def test_BGP_GR_20_p1(request):
438 """
439 Test Objective : Verify that GR routers delete all the routes
440 received from a node if both the routers are configured as GR
441 helper node
442 """
443
444 tgen = get_topogen()
445 tc_name = request.node.name
446 write_test_header(tc_name)
447
448 # Check router status
449 check_router_status(tgen)
450
451 # Don't run this test if we have any failure.
452 if tgen.routers_have_failure():
453 pytest.skip(tgen.errors)
454
455 # Creating configuration from JSON
456 reset_config_on_routers(tgen)
457
458 logger.info(
3f1f5852 459 "[Step 1] : Test Setup " "[Restart Mode]R3-----R1[Restart Mode] Initialized"
b0449478
DS
460 )
461
462 # Configure graceful-restart
463 input_dict = {
464 "r1": {
465 "bgp": {
466 "address_family": {
467 "ipv4": {
468 "unicast": {
469 "neighbor": {
470 "r3": {
471 "dest_link": {
472 "r1": {"graceful-restart-helper": True}
473 }
474 }
475 }
476 }
477 },
478 "ipv6": {
479 "unicast": {
480 "neighbor": {
481 "r3": {
482 "dest_link": {
483 "r1": {"graceful-restart-helper": True}
484 }
485 }
486 }
487 }
488 },
489 }
490 }
491 },
492 "r3": {
493 "bgp": {
494 "address_family": {
495 "ipv4": {
496 "unicast": {
497 "neighbor": {
498 "r1": {
499 "dest_link": {
500 "r3": {"graceful-restart-helper": True}
501 }
502 }
503 }
504 }
505 },
506 "ipv6": {
507 "unicast": {
508 "neighbor": {
509 "r1": {
510 "dest_link": {
511 "r3": {"graceful-restart-helper": True}
512 }
513 }
514 }
515 }
516 },
517 }
518 }
519 },
520 }
521
522 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r3")
523
524 for addr_type in ADDR_TYPES:
525 result = verify_graceful_restart(
526 tgen, topo, addr_type, input_dict, dut="r1", peer="r3"
527 )
528 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
529
530 # Verifying BGP RIB routes
531 dut = "r3"
532 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
533 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
534 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
535
536 # Verifying RIB routes before shutting down BGPd daemon
537 result = verify_rib(tgen, addr_type, dut, input_dict_1)
538 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
539
540 # Kill BGPd daemon on R1
541 kill_router_daemons(tgen, "r1", ["bgpd"])
542
543 for addr_type in ADDR_TYPES:
544 # Verifying BGP RIB routes
545 dut = "r3"
546 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
547 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1, expected=False)
548 assert result is not True, (
549 "Testcase {} : Failed \n "
d63c7094
KK
550 "Expected: Routes should not be present in {} BGP RIB \n "
551 "Found: {}".format(tc_name, dut, result)
b0449478 552 )
b0449478
DS
553
554 # Verifying RIB routes before shutting down BGPd daemon
555 result = verify_rib(tgen, addr_type, dut, input_dict_1, expected=False)
556 assert result is not True, (
557 "Testcase {} : Failed \n "
d63c7094
KK
558 "Expected: Routes should not be present in {} FIB \n "
559 "Found: {}".format(tc_name, dut, result)
b0449478 560 )
b0449478
DS
561
562 # Start BGPd daemon on R1
563 start_router_daemons(tgen, "r1", ["bgpd"])
564
565 for addr_type in ADDR_TYPES:
566 result = verify_bgp_convergence(tgen, topo)
567 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
568
569 # Verifying BGP RIB routes
570 dut = "r3"
571 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
572 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
573 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
574
575 # Verifying RIB routes before shutting down BGPd daemon
576 result = verify_rib(tgen, addr_type, dut, input_dict_1)
577 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
578
579 write_test_footer(tc_name)
580
581
582def test_BGP_GR_21_p2(request):
583 """
584 Test Objective : VVerify BGP-GR feature when helper node is
585 a transit router for it's eBGP peers.
586 """
587
588 tgen = get_topogen()
589 tc_name = request.node.name
590 write_test_header(tc_name)
591
592 # Check router status
593 check_router_status(tgen)
594
595 # Don't run this test if we have any failure.
596 if tgen.routers_have_failure():
597 pytest.skip(tgen.errors)
598
599 # Creating configuration from JSON
600 reset_config_on_routers(tgen)
601
602 logger.info(
3f1f5852 603 "[Step 1] : Test Setup " "[Helper Mode]R6-----R1[Restart Mode] Initialized"
b0449478
DS
604 )
605
606 # Configure graceful-restart
607 input_dict = {
608 "r1": {
609 "bgp": {
610 "address_family": {
611 "ipv4": {
612 "unicast": {
613 "neighbor": {
614 "r6": {
615 "dest_link": {
616 "r1": {"graceful-restart-disable": True}
617 }
618 }
619 }
620 }
621 },
622 "ipv6": {
623 "unicast": {
624 "neighbor": {
625 "r6": {
626 "dest_link": {
627 "r1": {"graceful-restart-disable": True}
628 }
629 }
630 }
631 }
632 },
633 }
634 }
635 },
636 "r6": {
637 "bgp": {
638 "address_family": {
639 "ipv4": {
640 "unicast": {
641 "neighbor": {
642 "r1": {
643 "dest_link": {
644 "r6": {"graceful-restart-helper": True}
645 }
646 }
647 }
648 }
649 },
650 "ipv6": {
651 "unicast": {
652 "neighbor": {
653 "r1": {
654 "dest_link": {
655 "r6": {"graceful-restart-helper": True}
656 }
657 }
658 }
659 }
660 },
661 }
662 }
663 },
664 }
665
666 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r6")
667
668 for addr_type in ADDR_TYPES:
669 result = verify_graceful_restart(
670 tgen, topo, addr_type, input_dict, dut="r1", peer="r6"
671 )
672 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
673
674 logger.info(
675 "[Step 2] : Test Setup "
676 "[Restart Mode]R2-----[Helper Mode]R1[Disable Mode]"
3f1f5852 677 "--------R6[Helper Mode] Initialized"
b0449478
DS
678 )
679
680 # Configure graceful-restart
681 input_dict = {
682 "r1": {
683 "bgp": {
684 "address_family": {
685 "ipv4": {
686 "unicast": {
687 "neighbor": {
688 "r2": {
689 "dest_link": {
690 "r1": {"graceful-restart-helper": True}
691 }
692 }
693 }
694 }
695 },
696 "ipv6": {
697 "unicast": {
698 "neighbor": {
699 "r2": {
700 "dest_link": {
701 "r1": {"graceful-restart-helper": True}
702 }
703 }
704 }
705 }
706 },
707 }
708 }
709 },
710 "r2": {
711 "bgp": {
712 "graceful-restart": {
713 "graceful-restart": True,
714 }
715 }
716 },
717 }
718
719 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
720
721 for addr_type in ADDR_TYPES:
722 result = verify_graceful_restart(
723 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
724 )
725 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
726
727 # Verifying BGP RIB routes
728 dut = "r6"
729 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
730 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
731 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
732
733 # Verifying RIB routes before shutting down BGPd daemon
734 result = verify_rib(tgen, addr_type, dut, input_dict_1)
735 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
736
737 # Verifying BGP RIB routes
738 dut = "r6"
739 input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
740 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
741 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
742
743 # Verifying RIB routes before shutting down BGPd daemon
744 result = verify_rib(tgen, addr_type, dut, input_dict_2)
745 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
746
747 # Kill BGPd daemon on R1
748 kill_router_daemons(tgen, "r2", ["bgpd"])
749
750 for addr_type in ADDR_TYPES:
751 # Verifying BGP RIB routes
752 dut = "r6"
753 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
754 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
755 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
756
757 # Verifying RIB routes before shutting down BGPd daemon
758 result = verify_rib(tgen, addr_type, dut, input_dict_1)
759 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
760
761 # Verifying BGP RIB routes
762 dut = "r6"
763 input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
764 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
765 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
766
767 # Verifying RIB routes before shutting down BGPd daemon
768 result = verify_rib(tgen, addr_type, dut, input_dict_2)
769 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
770
771 # Start BGPd daemon on R1
772 start_router_daemons(tgen, "r2", ["bgpd"])
773
774 for addr_type in ADDR_TYPES:
775 result = verify_bgp_convergence(tgen, topo)
776 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
777
778 # Verifying BGP RIB routes
779 dut = "r6"
780 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
781 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
782 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
783
784 # Verifying RIB routes after bringing up BGPd daemon
785 result = verify_rib(tgen, addr_type, dut, input_dict_1)
786 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
787
788 # Verifying BGP RIB routes
789 dut = "r6"
790 input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
791 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
792 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
793
794 # Verifying RIB routes before shutting down BGPd daemon
795 result = verify_rib(tgen, addr_type, dut, input_dict_2)
796 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
797
798 write_test_footer(tc_name)
799
800
801def test_BGP_GR_22_p2(request):
802 """
803 Test Objective : Verify BGP-GR feature when helper node
804 is a transit router for it's iBGP peers.
805 """
806
807 tgen = get_topogen()
808 tc_name = request.node.name
809 write_test_header(tc_name)
810
811 # Check router status
812 check_router_status(tgen)
813
814 # Don't run this test if we have any failure.
815 if tgen.routers_have_failure():
816 pytest.skip(tgen.errors)
817
818 # Creating configuration from JSON
819 reset_config_on_routers(tgen)
820
821 logger.info(
3f1f5852 822 "[Step 1] : Test Setup " "[Helper Mode]R3-----R1[Restart Mode] Initialized"
b0449478
DS
823 )
824
825 # Configure graceful-restart
826 input_dict = {
827 "r1": {
828 "bgp": {
829 "address_family": {
830 "ipv4": {
831 "unicast": {
832 "neighbor": {
833 "r3": {
834 "dest_link": {
835 "r1": {
836 "graceful-restart-disable": True,
837 "next_hop_self": True,
838 }
839 }
840 }
841 }
842 }
843 },
844 "ipv6": {
845 "unicast": {
846 "neighbor": {
847 "r3": {
848 "dest_link": {
849 "r1": {
850 "graceful-restart-disable": True,
851 "next_hop_self": True,
852 }
853 }
854 }
855 }
856 }
857 },
858 }
859 }
860 },
861 "r3": {
862 "bgp": {
863 "address_family": {
864 "ipv4": {
865 "unicast": {
866 "neighbor": {
867 "r1": {
868 "dest_link": {
869 "r3": {"graceful-restart-helper": True}
870 }
871 }
872 }
873 }
874 },
875 "ipv6": {
876 "unicast": {
877 "neighbor": {
878 "r1": {
879 "dest_link": {
880 "r3": {"graceful-restart-helper": True}
881 }
882 }
883 }
884 }
885 },
886 }
887 }
888 },
889 }
890
891 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r3")
892
893 for addr_type in ADDR_TYPES:
894 result = verify_graceful_restart(
895 tgen, topo, addr_type, input_dict, dut="r1", peer="r3"
896 )
897 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
898
899 logger.info(
900 "[Step 2] : Test Setup "
901 "[Restart Mode]R2-----[Helper Mode]R1[Disable Mode]"
3f1f5852 902 "--------R3[Helper Mode] Initialized"
b0449478
DS
903 )
904
905 # Configure graceful-restart
906 input_dict = {
907 "r1": {
908 "bgp": {
909 "address_family": {
910 "ipv4": {
911 "unicast": {
912 "neighbor": {
913 "r2": {
914 "dest_link": {
915 "r1": {"graceful-restart-helper": True}
916 }
917 }
918 }
919 }
920 },
921 "ipv6": {
922 "unicast": {
923 "neighbor": {
924 "r2": {
925 "dest_link": {
926 "r1": {"graceful-restart-helper": True}
927 }
928 }
929 }
930 }
931 },
932 }
933 }
934 },
935 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
936 }
937
938 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
939
940 for addr_type in ADDR_TYPES:
941 result = verify_graceful_restart(
942 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
943 )
944 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
945
946 # Verifying BGP RIB routes
947 dut = "r3"
948 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
949 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
950 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
951
952 # Verifying RIB routes before shutting down BGPd daemon
953 result = verify_rib(tgen, addr_type, dut, input_dict_1)
954 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
955
956 # Verifying BGP RIB routes
957 dut = "r3"
958 input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
959 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
960 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
961
962 # Verifying RIB routes before shutting down BGPd daemon
963 result = verify_rib(tgen, addr_type, dut, input_dict_2)
964 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
965
966 # Kill BGPd daemon on R1
967 kill_router_daemons(tgen, "r2", ["bgpd"])
968
969 for addr_type in ADDR_TYPES:
970 # Verifying BGP RIB routes
971 dut = "r3"
972 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
973 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
974 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
975
976 # Verifying RIB routes before shutting down BGPd daemon
977 result = verify_rib(tgen, addr_type, dut, input_dict_1)
978 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
979
980 # Verifying BGP RIB routes
981 dut = "r3"
982 input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
983 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
984 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
985
986 # Verifying RIB routes before shutting down BGPd daemon
987 result = verify_rib(tgen, addr_type, dut, input_dict_2)
988 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
989
990 # Start BGPd daemon on R1
991 start_router_daemons(tgen, "r2", ["bgpd"])
992
993 for addr_type in ADDR_TYPES:
994 result = verify_bgp_convergence(tgen, topo)
995 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
996
997 # Verifying BGP RIB routes
998 dut = "r3"
999 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
1000 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
1001 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1002
1003 # Verifying RIB routes before shutting down BGPd daemon
1004 result = verify_rib(tgen, addr_type, dut, input_dict_1)
1005 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1006
1007 # Verifying BGP RIB routes
1008 dut = "r3"
1009 input_dict_2 = {key: topo["routers"][key] for key in ["r2"]}
1010 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_2)
1011 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1012
1013 # Verifying RIB routes before shutting down BGPd daemon
1014 result = verify_rib(tgen, addr_type, dut, input_dict_2)
1015 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1016
1017 write_test_footer(tc_name)
1018
1019
1020if __name__ == "__main__":
1021 args = ["-s"] + sys.argv[1:]
1022 sys.exit(pytest.main(args))