]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_gr_functionality_topo2/test_bgp_gr_functionality_topo2-2.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / bgp_gr_functionality_topo2 / test_bgp_gr_functionality_topo2-2.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
70"""
71
72import os
73import sys
74import time
75import pytest
76from time import sleep
77
78# Save the Current Working Directory to find configuration files.
79CWD = os.path.dirname(os.path.realpath(__file__))
80sys.path.append(os.path.join("../"))
81sys.path.append(os.path.join("../lib/"))
82
83# pylint: disable=C0413
84# Import topogen and topotest helpers
85from lib.topogen import Topogen, get_topogen
86from lib.topolog import logger
87
88# Required to instantiate the topology builder class.
89
90# Import topoJson from lib, to create topology and initial configuration
91from lib.topojson import build_config_from_json
92from lib.bgp import (
93 clear_bgp,
94 verify_bgp_rib,
95 verify_graceful_restart,
96 create_router_bgp,
97 verify_r_bit,
98 verify_eor,
99 verify_f_bit,
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,
105)
106
107from lib.common_config import (
108 write_test_header,
109 reset_config_on_routers,
110 start_topology,
111 kill_router_daemons,
112 start_router_daemons,
113 verify_rib,
114 check_address_types,
115 write_test_footer,
116 check_router_status,
117 step,
118 get_frr_ipv6_linklocal,
119 required_linux_kernel_version,
120)
121
122pytestmark = [pytest.mark.bgpd]
123
124
125# Global variables
126BGP_CONVERGENCE = False
127GR_RESTART_TIMER = 5
128GR_SELECT_DEFER_TIMER = 5
129GR_STALEPATH_TIMER = 5
130PREFERRED_NEXT_HOP = "link_local"
131NEXT_HOP_4 = ["192.168.1.1", "192.168.4.2"]
132NEXT_HOP_6 = ["fd00:0:0:1::1", "fd00:0:0:4::2"]
133
134
135def setup_module(mod):
136 """
137 Sets up the pytest environment
138
139 * `mod`: module name
140 """
141
142 # Required linux kernel version for this suite to run.
143 result = required_linux_kernel_version("4.16")
144 if result is not True:
d63c7094 145 pytest.skip("Kernel requirements are not met, kernel version should be >=4.16")
b0449478
DS
146
147 global ADDR_TYPES
148
149 testsuite_run_time = time.asctime(time.localtime(time.time()))
150 logger.info("Testsuite start time: {}".format(testsuite_run_time))
151 logger.info("=" * 40)
152
153 logger.info("Running setup_module to create topology")
154
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__)
158 global topo
159 topo = tgen.json_topo
160 # ... and here it calls Mininet initialization functions.
161
162 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 163 # to start daemons and then start routers
b0449478
DS
164 start_topology(tgen)
165
166 # Creating configuration from JSON
167 build_config_from_json(tgen, topo)
168
169 # Api call verify whether BGP is converged
170 ADDR_TYPES = check_address_types()
171
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(
175 BGP_CONVERGENCE
176 )
177
178 logger.info("Running setup_module() done")
179
180
181def teardown_module(mod):
182 """
183 Teardown the pytest environment
184
185 * `mod`: module name
186 """
187
188 logger.info("Running teardown_module to delete topology")
189
190 tgen = get_topogen()
191
192 # Stop toplogy and Remove tmp files
193 tgen.stop_topology()
194
195 logger.info(
196 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
197 )
198 logger.info("=" * 40)
199
200
201def configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut, peer):
202 """
203 This function groups the repetitive function calls into one function.
204 """
205
206 logger.info("configure_gr_followed_by_clear: dut %s peer %s", dut, peer)
207
208 result = create_router_bgp(tgen, topo, input_dict)
209 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
210
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)
214
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)
218
219 result = verify_bgp_convergence_from_running_config(tgen)
220 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
221
222 return True
223
224
225def next_hop_per_address_family(tgen, dut, peer, addr_type, next_hop_dict):
226 """
227 This function returns link_local or global next_hop per address-family
228 """
229
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)
233 else:
234 next_hop = next_hop_dict[addr_type]
235
236 return next_hop
237
238
239def test_BGP_GR_26_p2(request):
240 """
241 Test Objective : Test GR scenarios on helper router by enabling
242 Graceful Restart for multiple address families.
243 """
244
245 tgen = get_topogen()
246 tc_name = request.node.name
247 write_test_header(tc_name)
248
249 # Check router status
250 check_router_status(tgen)
251
252 # Don't run this test if we have any failure.
253 if tgen.routers_have_failure():
254 pytest.skip(tgen.errors)
255
256 # Creating configuration from JSON
257 reset_config_on_routers(tgen)
258
259 logger.info(
260 "[Step 1] : Test Setup " "[Helper Mode]R3-----R1[Restart Mode] initialized"
261 )
262
263 # Configure graceful-restart
264 input_dict = {
265 "r1": {
266 "bgp": {
267 "address_family": {
268 "ipv4": {
269 "unicast": {
270 "neighbor": {
271 "r3": {
272 "dest_link": {
273 "r1": {
274 "graceful-restart": True,
275 "next_hop_self": True,
276 "activate": "ipv6",
277 }
278 }
279 }
280 }
281 }
282 },
283 "ipv6": {
284 "unicast": {
285 "neighbor": {
286 "r3": {
287 "dest_link": {
288 "r1": {
289 "graceful-restart": True,
290 "next_hop_self": True,
291 "activate": "ipv4",
292 }
293 }
294 }
295 }
296 }
297 },
298 }
299 }
300 },
301 "r3": {
302 "bgp": {
303 "address_family": {
304 "ipv4": {
305 "unicast": {
306 "neighbor": {
307 "r1": {
308 "dest_link": {
309 "r3": {
310 "graceful-restart-helper": True,
311 "activate": "ipv6",
312 }
313 }
314 }
315 }
316 }
317 },
318 "ipv6": {
319 "unicast": {
320 "neighbor": {
321 "r1": {
322 "dest_link": {
323 "r3": {
324 "graceful-restart-helper": True,
325 "activate": "ipv4",
326 }
327 }
328 }
329 }
330 }
331 },
332 }
333 }
334 },
335 }
336
337 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r3")
338
339 for addr_type in ADDR_TYPES:
340 result = verify_graceful_restart(
341 tgen, topo, addr_type, input_dict, dut="r3", peer="r1"
342 )
343 assert result is True, "Testcase {} : Failed \n Error {}".format(
344 tc_name, result
345 )
346
347 # Verifying BGP RIB routes
348 dut = "r3"
349 input_topo = {key: topo["routers"][key] for key in ["r1"]}
350 result = verify_bgp_rib(tgen, addr_type, dut, input_topo)
351 assert result is True, "Testcase {} : Failed \n Error {}".format(
352 tc_name, result
353 )
354
355 # Verifying RIB routes before shutting down BGPd daemon
356 result = verify_rib(tgen, addr_type, dut, input_topo)
357 assert result is True, "Testcase {} : Failed \n Error {}".format(
358 tc_name, result
359 )
360
361 # Kill BGPd daemon on R1
362 kill_router_daemons(tgen, "r1", ["bgpd"])
363
364 for addr_type in ADDR_TYPES:
365 # Verifying BGP RIB routes
366 input_topo = {key: topo["routers"][key] for key in ["r1"]}
367 result = verify_bgp_rib(tgen, addr_type, dut, input_topo)
368 assert result is True, "Testcase {} : Failed \n Error {}".format(
369 tc_name, result
370 )
371
372 # Verifying RIB routes before shutting down BGPd daemon
373 result = verify_rib(tgen, addr_type, dut, input_topo)
374 assert result is True, "Testcase {} : Failed \n Error {}".format(
375 tc_name, result
376 )
377
378 # Start BGPd daemon on R1
379 start_router_daemons(tgen, "r1", ["bgpd"])
380
381 for addr_type in ADDR_TYPES:
382 # Verifying BGP RIB routes
383 input_topo = {key: topo["routers"][key] for key in ["r1"]}
384 result = verify_bgp_rib(tgen, addr_type, dut, input_topo)
385 assert result is True, "Testcase {} : Failed \n Error {}".format(
386 tc_name, result
387 )
388
389 # Verifying RIB routes before shutting down BGPd daemon
390 result = verify_rib(tgen, addr_type, dut, input_topo)
391 assert result is True, "Testcase {} : Failed \n Error {}".format(
392 tc_name, result
393 )
394
395 # verify multi address family
396 result = verify_gr_address_family(
397 tgen,
398 topo,
399 addr_type,
400 "ipv4Unicast",
401 dut="r1",
402 peer="r3",
403 )
404 assert result is True, "Testcase {} : Failed \n Error {}".format(
405 tc_name, result
406 )
407
408 # verify multi address family
409 result = verify_gr_address_family(
410 tgen,
411 topo,
412 addr_type,
413 "ipv6Unicast",
414 dut="r1",
415 peer="r3",
416 )
417 assert result is True, "Testcase {} : Failed \n Error {}".format(
418 tc_name, result
419 )
420
421 # verify multi address family
422 result = verify_gr_address_family(
423 tgen,
424 topo,
425 addr_type,
426 "ipv4Unicast",
427 dut="r3",
428 peer="r1",
429 )
430 assert result is True, "Testcase {} : Failed \n Error {}".format(
431 tc_name, result
432 )
433
434 # verify multi address family
435 result = verify_gr_address_family(
436 tgen,
437 topo,
438 addr_type,
439 "ipv6Unicast",
440 dut="r3",
441 peer="r1",
442 )
443 assert result is True, "Testcase {} : Failed \n Error {}".format(
444 tc_name, result
445 )
446
447 write_test_footer(tc_name)
448
449
450def test_BGP_GR_chaos_28_p1(request):
451 """
452 Test Objective : Verify if helper node goes down before restarting
453 node comes up online, helper node sets the R-bit to avoid dead-lock
454 till SDT expiry.
455 """
456
457 tgen = get_topogen()
458 tc_name = request.node.name
459 write_test_header(tc_name)
460
461 # Check router status
462 check_router_status(tgen)
463
464 # Don't run this test if we have any failure.
465 if tgen.routers_have_failure():
466 pytest.skip(tgen.errors)
467
468 # Creating configuration from JSON
469 reset_config_on_routers(tgen)
470
471 logger.info(
472 "Test Case: test_BGP_GR_chaos_28 :"
473 "[Helper Mode]R3-----R1[Restart Mode] initialized"
474 )
475
476 # Configure graceful-restart
477 input_dict = {
478 "r1": {
479 "bgp": {
480 "address_family": {
481 "ipv4": {
482 "unicast": {
483 "neighbor": {
484 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
485 }
486 }
487 },
488 "ipv6": {
489 "unicast": {
490 "neighbor": {
491 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
492 }
493 }
494 },
495 }
496 }
497 },
498 "r3": {
499 "bgp": {
500 "address_family": {
501 "ipv4": {
502 "unicast": {
503 "neighbor": {
504 "r1": {
505 "dest_link": {
506 "r3": {"graceful-restart-helper": True}
507 }
508 }
509 }
510 }
511 },
512 "ipv6": {
513 "unicast": {
514 "neighbor": {
515 "r1": {
516 "dest_link": {
517 "r3": {"graceful-restart-helper": True}
518 }
519 }
520 }
521 }
522 },
523 }
524 }
525 },
526 }
527
528 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r3")
529
530 for addr_type in ADDR_TYPES:
531 result = verify_graceful_restart(
532 tgen, topo, addr_type, input_dict, dut="r1", peer="r3"
533 )
534 assert result is True, "Testcase {} : Failed \n Error {}".format(
535 tc_name, result
536 )
537
538 logger.info("[Step 1] : Kill BGPd daemon on R1..")
539
540 # Kill BGPd daemon on R1
541 kill_router_daemons(tgen, "r1", ["bgpd"])
542
543 logger.info("[Step 2] : Kill BGPd daemon on R3..")
544
545 # Kill BGPd daemon on R3
546 kill_router_daemons(tgen, "r3", ["bgpd"])
547
548 logger.info("[Step 3] : Start BGPd daemon on R1..")
549
550 # Start BGPd daemon on R1
551 start_router_daemons(tgen, "r1", ["bgpd"])
552
553 logger.info("[Step 4] : Start BGPd daemon on R3..")
554
555 # Start BGPd daemon on R3
556 start_router_daemons(tgen, "r3", ["bgpd"])
557
558 # Verify r_bit
559 for addr_type in ADDR_TYPES:
560 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r3", peer="r1")
561 assert result is True, "Testcase {} : Failed \n Error {}".format(
562 tc_name, result
563 )
564
565 write_test_footer(tc_name)
566
567
568def test_BGP_GR_chaos_29_p1(request):
569 """
570 Test Objective : Change timers on the fly, and
571 verify if it takes immediate effect.
572 """
573
574 tgen = get_topogen()
575 tc_name = request.node.name
576 write_test_header(tc_name)
577
578 # Check router status
579 check_router_status(tgen)
580
581 # Don't run this test if we have any failure.
582 if tgen.routers_have_failure():
583 pytest.skip(tgen.errors)
584
585 # Creating configuration from JSON
586 reset_config_on_routers(tgen)
587
588 logger.info(
589 " Test Case : test_BGP_GR_chaos_29"
590 " BGP GR [Helper Mode]R3-----R1[Restart Mode]"
591 " and [restart-time 150]R1 initialized"
592 )
593
594 # Configure graceful-restart and timers
595 input_dict = {
596 "r1": {
597 "bgp": {
598 "graceful-restart": {"timer": {"restart-time": GR_RESTART_TIMER}},
599 "address_family": {
600 "ipv4": {
601 "unicast": {
602 "neighbor": {
603 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
604 }
605 }
606 },
607 "ipv6": {
608 "unicast": {
609 "neighbor": {
610 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
611 }
612 }
613 },
614 },
615 }
616 },
617 "r3": {
618 "bgp": {
619 "address_family": {
620 "ipv4": {
621 "unicast": {
622 "neighbor": {
623 "r1": {
624 "dest_link": {
625 "r3": {"graceful-restart-helper": True}
626 }
627 }
628 }
629 }
630 },
631 "ipv6": {
632 "unicast": {
633 "neighbor": {
634 "r1": {
635 "dest_link": {
636 "r3": {"graceful-restart-helper": True}
637 }
638 }
639 }
640 }
641 },
642 }
643 }
644 },
645 }
646
647 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r3")
648
649 for addr_type in ADDR_TYPES:
650 result = verify_graceful_restart(
651 tgen, topo, addr_type, input_dict, dut="r1", peer="r3"
652 )
653 assert result is True, "Testcase {} : Failed \n Error {}".format(
654 tc_name, result
655 )
656
657 # Verify graceful-restart timers
658 input_dict_2 = {
659 "r1": {
660 "bgp": {
661 "graceful-restart": {"timer": {"restart-time": GR_RESTART_TIMER + 5}}
662 }
663 }
664 }
665
666 result = create_router_bgp(tgen, topo, input_dict_2)
667 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
668
669 for addr_type in ADDR_TYPES:
670 input_dict_2 = {
671 "r1": {
672 "bgp": {
673 "graceful-restart": {"timer": {"restart-time": GR_RESTART_TIMER}}
674 }
675 }
676 }
677
678 result = verify_graceful_restart_timers(
679 tgen, topo, addr_type, input_dict_2, dut="r3", peer="r1"
680 )
681 assert result is True, "Testcase {} : Failed \n Error {}".format(
682 tc_name, result
683 )
684
685 for addr_type in ADDR_TYPES:
686 # Verifying BGP RIB routes before shutting down BGPd daemon
687 dut = "r3"
688 input_dict = {key: topo["routers"][key] for key in ["r1"]}
689 result = verify_bgp_rib(tgen, addr_type, dut, input_dict)
690 assert result is True, "Testcase {} : Failed \n Error {}".format(
691 tc_name, result
692 )
693
694 # Verifying RIB routes before shutting down BGPd daemon
695 result = verify_rib(tgen, addr_type, dut, input_dict)
696 assert result is True, "Testcase {} : Failed \n Error {}".format(
697 tc_name, result
698 )
699
700 logger.info("[Step 2] : Kill BGPd daemon on R1..")
701
702 # Kill BGPd daemon on R1
703 kill_router_daemons(tgen, "r1", ["bgpd"])
704
705 logger.info("[Step 3] : Wait for {} seconds..".format(GR_RESTART_TIMER))
706
707 # Waiting for GR_RESTART_TIMER
708 sleep(GR_RESTART_TIMER)
709
710 for addr_type in ADDR_TYPES:
711 # Verifying BGP RIB routes before shutting down BGPd daemon
712 input_dict = {key: topo["routers"][key] for key in ["r1"]}
713 result = verify_bgp_rib(tgen, addr_type, dut, input_dict, expected=False)
714 assert result is not True, (
715 "Testcase {} : Failed \n "
d63c7094
KK
716 "Expected: Routes should not be present in {} BGP RIB \n "
717 "Found: {}".format(tc_name, dut, result)
b0449478 718 )
b0449478
DS
719
720 # Verifying RIB routes before shutting down BGPd daemon
721 result = verify_rib(tgen, addr_type, dut, input_dict, expected=False)
722 assert result is not True, (
723 "Testcase {} : Failed \n "
d63c7094
KK
724 "Expected: Routes should not be present in {} FIB \n "
725 "Found: {}".format(tc_name, dut, result)
b0449478 726 )
b0449478
DS
727
728 logger.info("[Step 4] : Start BGPd daemon on R1..")
729
730 # Start BGPd daemon on R1
731 start_router_daemons(tgen, "r1", ["bgpd"])
732
733 write_test_footer(tc_name)
734
735
736def test_BGP_GR_chaos_33_p1(request):
737 """
738 Test Objective : Helper router receives same prefixes from two
739 different routers (GR-restarting and GR-disabled). Keeps the
740 stale entry only for GR-restarting node(next-hop is correct).
741 """
742
743 tgen = get_topogen()
744 tc_name = request.node.name
745 write_test_header(tc_name)
746
747 # Check router status
748 check_router_status(tgen)
749
750 # Don't run this test if we have any failure.
751 if tgen.routers_have_failure():
752 pytest.skip(tgen.errors)
753
754 # Creating configuration from JSON
755 reset_config_on_routers(tgen)
756
757 logger.info(
758 " Test Case : test_BGP_GR_chaos_33 "
759 "BGP GR "
760 "[Restart Mode]R1--R3[Helper Mode]--R4[Disabled Mode]"
761 )
762
763 # Configure graceful-restart
764 input_dict = {
765 "r1": {
766 "bgp": {
767 "address_family": {
768 "ipv4": {
769 "unicast": {
770 "neighbor": {
771 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
772 }
773 }
774 },
775 "ipv6": {
776 "unicast": {
777 "neighbor": {
778 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
779 }
780 }
781 },
782 }
783 }
784 },
785 "r3": {
786 "bgp": {
787 "address_family": {
788 "ipv4": {
789 "unicast": {
790 "neighbor": {
791 "r1": {
792 "dest_link": {
793 "r3": {"graceful-restart-helper": True}
794 }
795 }
796 }
797 }
798 },
799 "ipv6": {
800 "unicast": {
801 "neighbor": {
802 "r1": {
803 "dest_link": {
804 "r3": {"graceful-restart-helper": True}
805 }
806 }
807 }
808 }
809 },
810 }
811 }
812 },
813 "r4": {
814 "bgp": {
815 "address_family": {
816 "ipv4": {
817 "unicast": {
818 "neighbor": {
819 "r3": {
820 "dest_link": {
821 "r4": {"graceful-restart-disable": True}
822 }
823 }
824 }
825 }
826 },
827 "ipv6": {
828 "unicast": {
829 "neighbor": {
830 "r3": {
831 "dest_link": {
832 "r4": {"graceful-restart-disable": True}
833 }
834 }
835 }
836 }
837 },
838 }
839 }
840 },
841 }
842
843 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r3")
844
845 for addr_type in ADDR_TYPES:
846 result = verify_graceful_restart(
847 tgen, topo, addr_type, input_dict, dut="r1", peer="r3"
848 )
849 assert result is True, "Testcase {} : Failed \n Error {}".format(
850 tc_name, result
851 )
852
853 logger.info("[Step 2] : Advertise same networks from R1 and R4..")
854
855 # Api call to delete advertised networks
856 input_dict_2 = {
857 "r1": {
858 "bgp": {
859 "address_family": {
860 "ipv4": {
861 "unicast": {
862 "advertise_networks": [
863 {
864 "network": "200.0.20.1/32",
865 "no_of_network": 2,
866 }
867 ]
868 }
869 },
870 "ipv6": {
871 "unicast": {
872 "advertise_networks": [
873 {"network": "2001::1/128", "no_of_network": 2}
874 ]
875 }
876 },
877 }
878 }
879 },
880 "r4": {
881 "bgp": {
882 "address_family": {
883 "ipv4": {
884 "unicast": {
885 "advertise_networks": [
886 {"network": "200.0.20.1/32", "no_of_network": 2}
887 ]
888 }
889 },
890 "ipv6": {
891 "unicast": {
892 "advertise_networks": [
893 {"network": "2001::1/128", "no_of_network": 2}
894 ]
895 }
896 },
897 }
898 }
899 },
900 }
901
902 result = create_router_bgp(tgen, topo, input_dict_2)
903 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
904
905 for addr_type in ADDR_TYPES:
906 # Verifying RIB routes
907 dut = "r3"
908 peer1 = "r1"
909 peer2 = "r4"
910 intf1 = topo["routers"][peer1]["links"][dut]["interface"]
911 intf2 = topo["routers"][peer2]["links"][dut]["interface"]
912
913 if addr_type == "ipv4":
914 next_hop_4 = NEXT_HOP_4
915 result = verify_rib(tgen, addr_type, dut, input_dict_2, next_hop_4)
916 assert result is True, "Testcase {} : Failed \n Error {}".format(
917 tc_name, result
918 )
919
920 if addr_type == "ipv6":
921 if "link_local" in PREFERRED_NEXT_HOP:
922 next_hop1 = get_frr_ipv6_linklocal(tgen, peer1, intf=intf1)
923 next_hop2 = get_frr_ipv6_linklocal(tgen, peer2, intf=intf2)
924
925 next_hop_6 = [next_hop1, next_hop2]
926 else:
927 next_hop_6 = NEXT_HOP_6
928
929 result = verify_rib(tgen, addr_type, dut, input_dict_2, next_hop_6)
930 assert result is True, "Testcase {} : Failed \n Error {}".format(
931 tc_name, result
932 )
933
934 logger.info("[Step 3] : Kill BGPd daemon on R1 and R4..")
935
936 # Kill BGPd daemon on R1
937 kill_router_daemons(tgen, "r1", ["bgpd"])
938
939 # Kill BGPd daemon on R4
940 kill_router_daemons(tgen, "r4", ["bgpd"])
941
942 for addr_type in ADDR_TYPES:
943 # Verifying RIB routes
944 next_hop_6 = ["fd00:0:0:1::1"]
945 if addr_type == "ipv4":
946 next_hop_4 = NEXT_HOP_4[0]
947
948 result = verify_rib(tgen, addr_type, dut, input_dict_2, next_hop_4)
949 assert result is True, "Testcase {} : Failed \n Error {}".format(
950 tc_name, result
951 )
952
953 if addr_type == "ipv6":
954 if "link_local" in PREFERRED_NEXT_HOP:
955 next_hop_6 = get_frr_ipv6_linklocal(tgen, peer1, intf=intf1)
956 else:
957 next_hop_6 = NEXT_HOP_6[0]
958
959 result = verify_rib(tgen, addr_type, dut, input_dict_2, next_hop_6)
960
961 # Verifying RIB routes
962 if addr_type == "ipv4":
963 next_hop_4 = NEXT_HOP_4[1]
964 result = verify_rib(
965 tgen, addr_type, dut, input_dict_2, next_hop_4, expected=False
966 )
967 assert result is not True, (
968 "Testcase {} : Failed \n "
d63c7094
KK
969 "Expected: Routes should not be present in {} FIB \n "
970 "Found: {}".format(tc_name, dut, result)
b0449478 971 )
b0449478
DS
972
973 if addr_type == "ipv6":
974 if "link_local" in PREFERRED_NEXT_HOP:
975 next_hop_6 = get_frr_ipv6_linklocal(tgen, peer2, intf=intf2)
976 else:
977 next_hop_6 = NEXT_HOP_6[1]
978
979 result = verify_rib(
980 tgen, addr_type, dut, input_dict_2, next_hop_6, expected=False
981 )
982 assert result is not True, (
983 "Testcase {} : Failed \n "
d63c7094
KK
984 "Expected: Routes should not be present in {} FIB \n "
985 "Found: {}".format(tc_name, dut, result)
b0449478 986 )
b0449478
DS
987
988 logger.info("[Step 4] : Start BGPd daemon on R1 and R4..")
989
990 # Start BGPd daemon on R1
991 start_router_daemons(tgen, "r1", ["bgpd"])
992
993 # Start BGPd daemon on R4
994 start_router_daemons(tgen, "r4", ["bgpd"])
995
996 write_test_footer(tc_name)
997
998
999def test_BGP_GR_chaos_34_2_p1(request):
1000 """
1001 Test Objective : Restarting node doesn't preserve the forwarding
1002 state verify the behaviour on helper node, if it still keeps the
1003 stale routes.
1004 """
1005
1006 tgen = get_topogen()
1007 tc_name = request.node.name
1008 write_test_header(tc_name)
1009
1010 # Check router status
1011 check_router_status(tgen)
1012
1013 # Don't run this test if we have any failure.
1014 if tgen.routers_have_failure():
1015 pytest.skip(tgen.errors)
1016
1017 # Creating configuration from JSON
1018 reset_config_on_routers(tgen)
1019
1020 logger.info(
1021 " Test Case : test_BGP_GR_chaos_34 "
1022 "BGP GR "
1023 "[Restart Mode]R1---R3[Helper Mode]"
1024 )
1025
1026 logger.info("[Step 1] : Configure restarting" " router R1 to prevent ")
1027 logger.info("[Step 2] : Reset the session" " between R1 and R3..")
1028
1029 # Configure graceful-restart
1030 input_dict = {
1031 "r1": {
1032 "bgp": {
1033 "graceful-restart": {"preserve-fw-state": True, "disable-eor": True},
1034 "address_family": {
1035 "ipv4": {
1036 "unicast": {
1037 "neighbor": {
1038 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
1039 }
1040 }
1041 },
1042 "ipv6": {
1043 "unicast": {
1044 "neighbor": {
1045 "r3": {"dest_link": {"r1": {"graceful-restart": True}}}
1046 }
1047 }
1048 },
1049 },
1050 }
1051 },
1052 "r3": {
1053 "bgp": {
1054 "address_family": {
1055 "ipv4": {
1056 "unicast": {
1057 "neighbor": {
1058 "r1": {
1059 "dest_link": {
1060 "r3": {"graceful-restart-helper": True}
1061 }
1062 }
1063 }
1064 }
1065 },
1066 "ipv6": {
1067 "unicast": {
1068 "neighbor": {
1069 "r1": {
1070 "dest_link": {
1071 "r3": {"graceful-restart-helper": True}
1072 }
1073 }
1074 }
1075 }
1076 },
1077 }
1078 }
1079 },
1080 }
1081
1082 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r3")
1083
1084 for addr_type in ADDR_TYPES:
1085 result = verify_graceful_restart(
1086 tgen, topo, addr_type, input_dict, dut="r1", peer="r3"
1087 )
1088 assert result is True, "Testcase {} : Failed \n Error {}".format(
1089 tc_name, result
1090 )
1091
1092 # Verify f-bit before killing BGPd daemon
1093 result = verify_f_bit(tgen, topo, addr_type, input_dict, "r3", "r1")
1094 assert result is True, "Testcase {} : Failed \n Error {}".format(
1095 tc_name, result
1096 )
1097
1098 # Verifying BGP RIB routes after starting BGPd daemon
1099 dut = "r3"
1100 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
1101 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1)
1102 assert result is True, "Testcase {} : Failed \n Error {}".format(
1103 tc_name, result
1104 )
1105
1106 # Verifying RIB routes
1107 result = verify_rib(tgen, addr_type, dut, input_dict_1)
1108 assert result is True, "Testcase {} : Failed \n Error {}".format(
1109 tc_name, result
1110 )
1111
1112 logger.info("[Step 3] : Kill BGPd daemon on R1..")
1113
1114 # Kill BGPd daemon on R1
1115 kill_router_daemons(tgen, "r1", ["bgpd"])
1116
1117 logger.info("[Step 4] : Withdraw/delete the prefixes " "originated from R1..")
1118
1119 # Api call to delete advertised networks
1120 network = {"ipv4": "101.0.20.1/32", "ipv6": "1::1/128"}
1121 for addr_type in ADDR_TYPES:
1122 input_dict_2 = {
1123 "r1": {
1124 "bgp": {
1125 "address_family": {
1126 addr_type: {
1127 "unicast": {
1128 "advertise_networks": [
1129 {
1130 "network": network[addr_type],
1131 "no_of_network": 5,
1132 "delete": True,
1133 }
1134 ]
1135 }
1136 }
1137 }
1138 }
1139 }
1140 }
1141
1142 result = modify_bgp_config_when_bgpd_down(tgen, topo, input_dict_2)
1143 assert result is True, "Testcase {} : Failed \n Error {}".format(
1144 tc_name, result
1145 )
1146
1147 logger.info("[Step 5] : Remove the CLI from R1's config to " "set the F-bit..")
1148
1149 # Modify graceful-restart config not to set f-bit
1150 # and write to /etc/frr
1151 input_dict_2 = {"r1": {"bgp": {"graceful-restart": {"preserve-fw-state": False}}}}
1152
1153 result = modify_bgp_config_when_bgpd_down(tgen, topo, input_dict_2)
1154 assert result is True, "Testcase {} : Failed \n Error {}".format(tc_name, result)
1155
1156 logger.info("[Step 6] : Bring up the BGPd daemon on R1 again..")
1157
1158 # Start BGPd daemon on R1
1159 start_router_daemons(tgen, "r1", ["bgpd"])
1160
1161 for addr_type in ADDR_TYPES:
1162 # Verify f-bit after starting BGPd daemon
1163 result = verify_f_bit(
1164 tgen, topo, addr_type, input_dict, "r3", "r1", expected=False
1165 )
d63c7094
KK
1166 assert result is not True, (
1167 "Testcase {} : Failed \n "
1168 "Expected: F-bit should not be set to True in r3\n"
1169 "Found: {}".format(tc_name, result)
b0449478 1170 )
b0449478
DS
1171
1172 # Verifying BGP RIB routes after starting BGPd daemon
1173 input_dict_1 = {key: topo["routers"][key] for key in ["r1"]}
1174 result = verify_bgp_rib(tgen, addr_type, dut, input_dict_1, expected=False)
1175 assert result is not True, (
1176 "Testcase {} : Failed \n "
d63c7094
KK
1177 "Expected: Routes should not be present in {} BGP RIB \n "
1178 "Found: {}".format(tc_name, dut, result)
b0449478 1179 )
b0449478
DS
1180
1181 # Verifying RIB routes
1182 result = verify_rib(tgen, addr_type, dut, input_dict_1, expected=False)
1183 assert result is not True, (
1184 "Testcase {} : Failed \n "
d63c7094
KK
1185 "Expected: Routes should not be present in {} FIB \n "
1186 "Found: {}".format(tc_name, dut, result)
b0449478 1187 )
b0449478
DS
1188
1189 write_test_footer(tc_name)
1190
1191
1192if __name__ == "__main__":
1193 args = ["-s"] + sys.argv[1:]
1194 sys.exit(pytest.main(args))