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