]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1-3.py
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / tests / topotests / bgp_gr_functionality_topo1 / test_bgp_gr_functionality_topo1-3.py
CommitLineData
35ba1e3d 1#!/usr/bin/env python
acddc0ed 2# SPDX-License-Identifier: ISC
35ba1e3d
KK
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#
35ba1e3d
KK
8
9"""
17be83bf 10Following tests are covered to test BGP Graceful Restart functionality.
35ba1e3d
KK
11Basic Common Test steps for all the test case below :
12- Create topology (setup module)
13 Creating 2 routers topology, r1, r2 in IBGP
14- Bring up topology
15- Verify for bgp to converge
16- Configure BGP Garceful Restart on both the routers.
17
17022899
KK
181. Transition from Peer-level helper to Global Restarting
192. Transition from Peer-level helper to Global inherit helper
203. Transition from Peer-level restarting to Global inherit helper
214. Default GR functional mode is Helper.
225. Verify that the restarting node sets "R" bit while sending the
35ba1e3d 23 BGP open messages after the node restart, only if GR is enabled.
35ba1e3d 246. Verify if restarting node resets R bit in BGP open message
17022899
KK
25 during normal BGP session flaps as well, even when GR restarting
26 mode is enabled. Here link flap happen due to interface UP/DOWN.
277. Verify if restarting node resets R bit in BGP
28 open message during normal BGP session flaps when GR is disabled.
298. Verify that restarting nodes set "F" bit while sending
35ba1e3d 30 the BGP open messages after it restarts, only when BGP GR is enabled.
17022899 319. Verify that only GR helper routers keep the stale
35ba1e3d 32 route entries, not any GR disabled router.
17022899
KK
3310. Verify that GR helper routers keeps all the routes received
34 from restarting node if both the routers are configured as
35 GR restarting node.
3611. Verify that GR helper routers delete all the routes
37 received from a node if both the routers are configured as GR
38 helper node.
3912. After BGP neighborship is established and GR capability is exchanged,
40 transition restarting router to disabled state and vice versa.
4113. After BGP neighborship is established and GR capability is exchanged,
42 transition restarting router to disabled state and vice versa.
4314. Verify that restarting nodes reset "F" bit while sending
44 the BGP open messages after it's restarts, when BGP GR is **NOT** enabled.
4515. Verify that only GR helper routers keep the stale
46 route entries, not any GR disabled router.
4716. Transition from Global Restarting to Disable and then Global
48 Disable to Restarting.
4917. Transition from Global Helper to Disable and then Global
35ba1e3d 50 Disable to Helper.
17022899
KK
5118. Transition from Global Restart to Helper and then Global
52 Helper to Restart, Global Mode : GR Restarting
53 PerPeer Mode : GR Helper
54 GR Mode effective : GR Helper
5519. Transition from Peer-level helper to Global Restarting,
56 Global Mode : GR Restarting
57 PerPeer Mode : GR Restarting
58 GR Mode effective : GR Restarting
5920. Transition from Peer-level restart to Global Restart
60 Global Mode : GR Restarting
61 PerPeer Mode : GR Restarting
62 GR Mode effective : GR Restarting
6321. Transition from Peer-level disabled to Global Restart
64 Global Mode : GR Restarting
65 PerPeer Mode : GR Disabled
66 GR Mode effective : GR Disabled
6722. Peer-level inherit from Global Restarting
68 Global Mode : GR Restart
69 PerPeer Mode : None
70 GR Mode effective : GR Restart
d94ee272 7123. Transition from Peer-level disable to Global inherit helper
17022899
KK
72 Global Mode : None
73 PerPeer Mode : GR Disable
74 GR Mode effective : GR Disable
b0449478
DS
75
76These tests have been broken up into 4 sub python scripts because
77the totality of this run was fairly significant.
35ba1e3d
KK
78"""
79
80import os
81import sys
35ba1e3d 82import time
35ba1e3d 83import pytest
35ba1e3d
KK
84
85# Save the Current Working Directory to find configuration files.
86CWD = os.path.dirname(os.path.realpath(__file__))
87sys.path.append(os.path.join("../"))
88sys.path.append(os.path.join("../lib/"))
89
90# pylint: disable=C0413
91# Import topogen and topotest helpers
4953ca97 92from lib.topogen import Topogen, get_topogen
35ba1e3d 93from lib.topolog import logger
3dfd384e 94
35ba1e3d 95# Required to instantiate the topology builder class.
35ba1e3d
KK
96
97# Import topoJson from lib, to create topology and initial configuration
4953ca97 98from lib.topojson import build_config_from_json
35ba1e3d
KK
99from lib.bgp import (
100 clear_bgp,
101 verify_bgp_rib,
102 verify_graceful_restart,
103 create_router_bgp,
104 verify_r_bit,
105 verify_f_bit,
17022899
KK
106 verify_bgp_convergence,
107 verify_bgp_convergence_from_running_config,
35ba1e3d
KK
108)
109
110from lib.common_config import (
111 write_test_header,
112 reset_config_on_routers,
113 start_topology,
114 kill_router_daemons,
115 start_router_daemons,
116 verify_rib,
117 check_address_types,
118 write_test_footer,
119 check_router_status,
120 shutdown_bringup_interface,
121 step,
35ba1e3d 122 get_frr_ipv6_linklocal,
0b25370e 123 required_linux_kernel_version,
35ba1e3d
KK
124)
125
bf3a0a9a
DS
126pytestmark = [pytest.mark.bgpd]
127
128
35ba1e3d
KK
129# Global variables
130NEXT_HOP_IP = {"ipv4": "192.168.1.10", "ipv6": "fd00:0:0:1::10"}
131NEXT_HOP_IP_1 = {"ipv4": "192.168.0.1", "ipv6": "fd00::1"}
132NEXT_HOP_IP_2 = {"ipv4": "192.168.0.2", "ipv6": "fd00::2"}
133BGP_CONVERGENCE = False
134GR_RESTART_TIMER = 20
135PREFERRED_NEXT_HOP = "link_local"
136
137
35ba1e3d
KK
138def setup_module(mod):
139 """
140 Sets up the pytest environment
141
142 * `mod`: module name
143 """
144
145 global ADDR_TYPES
146
3dfd384e 147 # Required linux kernel version for this suite to run.
17022899 148 result = required_linux_kernel_version("4.16")
955212d9 149 if result is not True:
d63c7094 150 pytest.skip("Kernel requirements are not met, kernel version should be >=4.16")
3dfd384e 151
35ba1e3d
KK
152 testsuite_run_time = time.asctime(time.localtime(time.time()))
153 logger.info("Testsuite start time: {}".format(testsuite_run_time))
154 logger.info("=" * 40)
155
156 logger.info("Running setup_module to create topology")
157
158 # This function initiates the topology build with Topogen...
e82b531d
CH
159 json_file = "{}/bgp_gr_topojson_topo1.json".format(CWD)
160 tgen = Topogen(json_file, mod.__name__)
161 global topo
162 topo = tgen.json_topo
35ba1e3d
KK
163 # ... and here it calls Mininet initialization functions.
164
35ba1e3d 165 # Starting topology, create tmp files which are loaded to routers
d60a3f0e 166 # to start daemons and then start routers
35ba1e3d
KK
167 start_topology(tgen)
168
169 # Creating configuration from JSON
170 build_config_from_json(tgen, topo)
171
172 # Don't run this test if we have any failure.
173 if tgen.routers_have_failure():
174 pytest.skip(tgen.errors)
175
176 # Api call verify whether BGP is converged
177 ADDR_TYPES = check_address_types()
178
17022899
KK
179 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
180 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format(
181 BGP_CONVERGENCE
182 )
35ba1e3d
KK
183
184 logger.info("Running setup_module() done")
185
186
187def teardown_module(mod):
188 """
189 Teardown the pytest environment
190
191 * `mod`: module name
192 """
193
194 logger.info("Running teardown_module to delete topology")
195
196 tgen = get_topogen()
197
198 # Stop toplogy and Remove tmp files
199 tgen.stop_topology()
200
201 logger.info(
202 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
203 )
204 logger.info("=" * 40)
205
206
207def configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut, peer):
208 """
209 This function groups the repetitive function calls into one function.
210 """
211
212 result = create_router_bgp(tgen, topo, input_dict)
213 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
214
215 for addr_type in ADDR_TYPES:
2268cf50
KK
216 neighbor = topo["routers"][peer]["links"]["r1-link1"][addr_type].split("/")[0]
217 clear_bgp(tgen, addr_type, dut, neighbor=neighbor)
35ba1e3d 218
17022899 219 for addr_type in ADDR_TYPES:
2268cf50
KK
220 neighbor = topo["routers"][dut]["links"]["r2-link1"][addr_type].split("/")[0]
221 clear_bgp(tgen, addr_type, peer, neighbor=neighbor)
17022899
KK
222
223 result = verify_bgp_convergence_from_running_config(tgen)
224 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
225
35ba1e3d
KK
226 return True
227
228
229def next_hop_per_address_family(
230 tgen, dut, peer, addr_type, next_hop_dict, preferred_next_hop=PREFERRED_NEXT_HOP
231):
232 """
233 This function returns link_local or global next_hop per address-family
234 """
235
236 intferface = topo["routers"][peer]["links"]["{}-link1".format(dut)]["interface"]
237 if addr_type == "ipv6" and "link_local" in preferred_next_hop:
238 next_hop = get_frr_ipv6_linklocal(tgen, peer, intf=intferface)
239 else:
240 next_hop = next_hop_dict[addr_type]
241
242 return next_hop
243
244
2268cf50 245def BGP_GR_TC_50_p1(request):
35ba1e3d
KK
246 """
247 Test Objective : Transition from Peer-level helper to Global inherit helper
248 Global Mode : None
249 PerPeer Mode : Helper
250 GR Mode effective : GR Helper
251
252 """
253
254 tgen = get_topogen()
255 tc_name = request.node.name
256 write_test_header(tc_name)
257
258 # Check router status
259 check_router_status(tgen)
260
261 # Don't run this test if we have any failure.
262 if tgen.routers_have_failure():
263 pytest.skip(tgen.errors)
264
265 # Creating configuration from JSON
266 reset_config_on_routers(tgen)
267
268 step(
269 "Configure R1 as GR helper node at per Peer-level for R2"
270 " and configure R2 as global restarting node."
271 )
272
273 input_dict = {
274 "r1": {
275 "bgp": {
276 "address_family": {
277 "ipv4": {
278 "unicast": {
279 "neighbor": {
280 "r2": {
281 "dest_link": {
282 "r1-link1": {"graceful-restart-helper": True}
283 }
284 }
285 }
286 }
287 },
288 "ipv6": {
289 "unicast": {
290 "neighbor": {
291 "r2": {
292 "dest_link": {
293 "r1-link1": {"graceful-restart-helper": True}
294 }
295 }
296 }
297 }
298 },
299 }
300 }
301 },
302 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
303 }
304
305 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
306
307 step("Verify on R2 that R1 advertises GR capabilities as a helper node")
308
309 for addr_type in ADDR_TYPES:
310 result = verify_graceful_restart(
311 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
312 )
313 assert result is True, "Testcase {} : Failed \n Error {}".format(
314 tc_name, result
315 )
316
17022899
KK
317 for addr_type in ADDR_TYPES:
318 protocol = "bgp"
319 next_hop = next_hop_per_address_family(
320 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
321 )
322 input_topo = {"r1": topo["routers"]["r1"]}
323 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
324 assert result is True, "Testcase {} : Failed \n Error {}".format(
325 tc_name, result
326 )
327
328 for addr_type in ADDR_TYPES:
329 next_hop = next_hop_per_address_family(
330 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
331 )
332 input_topo = {"r2": topo["routers"]["r2"]}
333 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
334 assert result is True, "Testcase {} : Failed \n Error {}".format(
335 tc_name, result
336 )
337
338 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
339 assert result is True, "Testcase {} : Failed \n Error {}".format(
340 tc_name, result
341 )
342
35ba1e3d
KK
343 step("Kill BGP on R2")
344
345 kill_router_daemons(tgen, "r2", ["bgpd"])
346
347 step(
348 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
349 )
350
351 for addr_type in ADDR_TYPES:
352 protocol = "bgp"
353 next_hop = next_hop_per_address_family(
354 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
355 )
356 input_topo = {"r1": topo["routers"]["r1"]}
357 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
358 assert result is True, "Testcase {} : Failed \n Error {}".format(
359 tc_name, result
360 )
361
362 for addr_type in ADDR_TYPES:
363 next_hop = next_hop_per_address_family(
364 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
365 )
366 input_topo = {"r2": topo["routers"]["r2"]}
367 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
368 assert result is True, "Testcase {} : Failed \n Error {}".format(
369 tc_name, result
370 )
371
372 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
373 assert result is True, "Testcase {} : Failed \n Error {}".format(
374 tc_name, result
375 )
376
377 step("Bring up BGP on R2 and remove Peer-level GR config from R1 ")
378
379 start_router_daemons(tgen, "r2", ["bgpd"])
380
381 input_dict = {
382 "r1": {
383 "bgp": {
384 "address_family": {
385 "ipv4": {
386 "unicast": {
387 "neighbor": {
388 "r2": {
389 "dest_link": {
390 "r1-link1": {"graceful-restart-helper": False}
391 }
392 }
393 }
394 }
395 },
396 "ipv6": {
397 "unicast": {
398 "neighbor": {
399 "r2": {
400 "dest_link": {
401 "r1-link1": {"graceful-restart-helper": False}
402 }
403 }
404 }
405 }
406 },
407 }
408 }
409 }
410 }
411
2268cf50
KK
412 result = create_router_bgp(tgen, topo, input_dict)
413 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
414
415 for addr_type in ADDR_TYPES:
416 neighbor = topo["routers"]["r2"]["links"]["r1-link1"][addr_type].split("/")[0]
417 clear_bgp(tgen, addr_type, "r1", neighbor=neighbor)
35ba1e3d 418
17022899
KK
419 result = verify_bgp_convergence_from_running_config(tgen)
420 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
421
35ba1e3d
KK
422 step("Verify on R2 that R1 still advertises GR capabilities as a helper node")
423
424 input_dict = {
425 "r1": {"bgp": {"graceful-restart": {"graceful-restart-helper": True}}},
426 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
427 }
428
429 for addr_type in ADDR_TYPES:
430 result = verify_graceful_restart(
431 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
432 )
433 assert result is True, "Testcase {} : Failed \n Error {}".format(
434 tc_name, result
435 )
436
17022899
KK
437 for addr_type in ADDR_TYPES:
438 protocol = "bgp"
439 next_hop = next_hop_per_address_family(
440 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
441 )
442 input_topo = {"r1": topo["routers"]["r1"]}
443 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
444 assert (
445 result is True
446 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
447 tc_name, result
448 )
449
450 for addr_type in ADDR_TYPES:
451 next_hop = next_hop_per_address_family(
452 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
453 )
454 input_topo = {"r2": topo["routers"]["r2"]}
455 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
456 assert result is True, "Testcase {} : Failed \n Error {}".format(
457 tc_name, result
458 )
459
460 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
461 assert (
462 result is True
463 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
464 tc_name, result
465 )
466
35ba1e3d
KK
467 step("Kill BGP on R2")
468
469 kill_router_daemons(tgen, "r2", ["bgpd"])
470
471 step(
472 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
473 )
474
475 for addr_type in ADDR_TYPES:
476 protocol = "bgp"
477 next_hop = next_hop_per_address_family(
478 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
479 )
480 input_topo = {"r1": topo["routers"]["r1"]}
481 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
482 assert (
483 result is True
484 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
485 tc_name, result
486 )
487
488 for addr_type in ADDR_TYPES:
489 next_hop = next_hop_per_address_family(
490 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
491 )
492 input_topo = {"r2": topo["routers"]["r2"]}
493 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
494 assert result is True, "Testcase {} : Failed \n Error {}".format(
495 tc_name, result
496 )
497
498 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
499 assert (
500 result is True
501 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
502 tc_name, result
503 )
504
505 step("Start BGP on R2")
506
507 start_router_daemons(tgen, "r2", ["bgpd"])
508
509 write_test_footer(tc_name)
510
511
b0449478 512def test_BGP_GR_TC_19_p1(request):
35ba1e3d 513 """
b0449478
DS
514 Test Objective : Verify that GR helper routers keeps all the routes received
515 from restarting node if both the routers are configured as GR restarting node.
35ba1e3d
KK
516 """
517
518 tgen = get_topogen()
519 tc_name = request.node.name
520 write_test_header(tc_name)
521
522 # Check router status
523 check_router_status(tgen)
524
525 # Don't run this test if we have any failure.
526 if tgen.routers_have_failure():
527 pytest.skip(tgen.errors)
528
529 # Creating configuration from JSON
530 reset_config_on_routers(tgen)
531
b0449478 532 logger.info("[Phase 1] : Test Setup [Helper]R1-----R2[Restart] initialized ")
35ba1e3d 533
b0449478 534 # Configure graceful-restart
35ba1e3d
KK
535 input_dict = {
536 "r1": {
537 "bgp": {
b0449478
DS
538 "graceful-restart": {
539 "graceful-restart": True,
540 "preserve-fw-state": True,
541 },
35ba1e3d
KK
542 "address_family": {
543 "ipv4": {
544 "unicast": {
545 "neighbor": {
546 "r2": {
547 "dest_link": {
b0449478 548 "r1-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
549 }
550 }
551 }
552 }
553 },
554 "ipv6": {
555 "unicast": {
556 "neighbor": {
557 "r2": {
558 "dest_link": {
b0449478
DS
559 "r1-link1": {"graceful-restart-helper": True}
560 }
561 }
562 }
563 }
564 },
565 },
566 }
567 },
568 "r2": {
569 "bgp": {
570 "address_family": {
571 "ipv4": {
572 "unicast": {
573 "neighbor": {
574 "r1": {
575 "dest_link": {
576 "r2-link1": {"graceful-restart": True}
577 }
578 }
579 }
580 }
581 },
582 "ipv6": {
583 "unicast": {
584 "neighbor": {
585 "r1": {
586 "dest_link": {
587 "r2-link1": {"graceful-restart": True}
35ba1e3d
KK
588 }
589 }
590 }
591 }
592 },
593 }
594 }
595 },
35ba1e3d
KK
596 }
597
598 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
35ba1e3d
KK
599
600 for addr_type in ADDR_TYPES:
601 result = verify_graceful_restart(
602 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
603 )
604 assert result is True, "Testcase {} : Failed \n Error {}".format(
605 tc_name, result
606 )
607
b0449478
DS
608 # Verifying BGP RIB routes
609 dut = "r1"
610 peer = "r2"
17022899 611 next_hop = next_hop_per_address_family(
b0449478 612 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
17022899 613 )
b0449478
DS
614 input_topo = {key: topo["routers"][key] for key in ["r2"]}
615 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
17022899
KK
616 assert result is True, "Testcase {} : Failed \n Error {}".format(
617 tc_name, result
618 )
619
b0449478
DS
620 # Verifying RIB routes
621 protocol = "bgp"
622 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
17022899
KK
623 assert result is True, "Testcase {} : Failed \n Error {}".format(
624 tc_name, result
625 )
626
b0449478
DS
627 logger.info(
628 "[Phase 2] : R1's Gr state cahnge to Graceful"
629 " Restart without resetting the session "
630 )
17022899 631
b0449478
DS
632 # Configure graceful-restart
633 input_dict = {
634 "r1": {
635 "bgp": {
636 "address_family": {
637 "ipv4": {
638 "unicast": {
639 "neighbor": {
640 "r2": {
641 "dest_link": {
642 "r1-link1": {"graceful-restart": True}
643 }
644 }
645 }
646 }
647 },
648 "ipv6": {
649 "unicast": {
650 "neighbor": {
651 "r2": {
652 "dest_link": {
653 "r1-link1": {"graceful-restart": True}
654 }
655 }
656 }
657 }
658 },
659 }
660 }
661 }
662 }
35ba1e3d 663
b0449478
DS
664 result = create_router_bgp(tgen, topo, input_dict)
665 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
35ba1e3d 666
b0449478
DS
667 logger.info(
668 "[Phase 3] : R2 is still down, restart time 120 sec."
669 " So time verify the routes are present in BGP RIB and ZEBRA "
35ba1e3d
KK
670 )
671
672 for addr_type in ADDR_TYPES:
b0449478 673 # Verifying BGP RIB routes
35ba1e3d 674 next_hop = next_hop_per_address_family(
b0449478 675 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
35ba1e3d 676 )
b0449478
DS
677 input_topo = {key: topo["routers"][key] for key in ["r2"]}
678 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
35ba1e3d
KK
679 assert result is True, "Testcase {} : Failed \n Error {}".format(
680 tc_name, result
681 )
682
b0449478
DS
683 # Verifying RIB routes
684 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
35ba1e3d
KK
685 assert result is True, "Testcase {} : Failed \n Error {}".format(
686 tc_name, result
687 )
688
b0449478 689 write_test_footer(tc_name)
35ba1e3d 690
35ba1e3d 691
b0449478
DS
692def test_BGP_GR_TC_20_p1(request):
693 """
694 Test Objective : Verify that GR helper routers delete all the routes
695 received from a node if both the routers are configured as GR helper node.
696 """
697 tgen = get_topogen()
698 tc_name = request.node.name
699 write_test_header(tc_name)
700
701 # Check router status
702 check_router_status(tgen)
703
704 # Don't run this test if we have any failure.
705 if tgen.routers_have_failure():
706 pytest.skip(tgen.errors)
707
708 # Creating configuration from JSON
709 reset_config_on_routers(tgen)
35ba1e3d 710
b0449478
DS
711 logger.info("[Phase 1] : Test Setup [Helper]R1-----R2[Helper] initialized ")
712
713 # Configure graceful-restart
35ba1e3d
KK
714 input_dict = {
715 "r1": {
716 "bgp": {
b0449478
DS
717 "graceful-restart": {
718 "graceful-restart": True,
719 "preserve-fw-state": True,
720 },
35ba1e3d
KK
721 "address_family": {
722 "ipv4": {
723 "unicast": {
724 "neighbor": {
725 "r2": {
726 "dest_link": {
b0449478 727 "r1-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
728 }
729 }
730 }
731 }
732 },
733 "ipv6": {
734 "unicast": {
735 "neighbor": {
736 "r2": {
737 "dest_link": {
b0449478
DS
738 "r1-link1": {"graceful-restart-helper": True}
739 }
740 }
741 }
742 }
743 },
744 },
745 }
746 },
747 "r2": {
748 "bgp": {
749 "address_family": {
750 "ipv4": {
751 "unicast": {
752 "neighbor": {
753 "r1": {
754 "dest_link": {
755 "r2-link1": {"graceful-restart-helper": True}
756 }
757 }
758 }
759 }
760 },
761 "ipv6": {
762 "unicast": {
763 "neighbor": {
764 "r1": {
765 "dest_link": {
766 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
767 }
768 }
769 }
770 }
771 },
772 }
773 }
b0449478 774 },
35ba1e3d
KK
775 }
776
b0449478 777 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
35ba1e3d
KK
778
779 for addr_type in ADDR_TYPES:
780 result = verify_graceful_restart(
781 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
782 )
783 assert result is True, "Testcase {} : Failed \n Error {}".format(
784 tc_name, result
785 )
786
b0449478
DS
787 # Verifying BGP RIB routes
788 dut = "r1"
789 peer = "r2"
17022899 790 next_hop = next_hop_per_address_family(
b0449478 791 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
17022899 792 )
b0449478
DS
793 input_topo = {key: topo["routers"][key] for key in ["r2"]}
794 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
17022899
KK
795 assert result is True, "Testcase {} : Failed \n Error {}".format(
796 tc_name, result
797 )
798
b0449478
DS
799 # Verifying RIB routes
800 protocol = "bgp"
801 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
802 assert result is True, "Testcase {} : Failed \n Error {}".format(
17022899
KK
803 tc_name, result
804 )
805
35ba1e3d
KK
806 kill_router_daemons(tgen, "r2", ["bgpd"])
807
35ba1e3d 808 for addr_type in ADDR_TYPES:
b0449478 809 # Verifying BGP RIB routes
35ba1e3d 810 next_hop = next_hop_per_address_family(
b0449478 811 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
35ba1e3d 812 )
b0449478
DS
813 input_topo = {key: topo["routers"][key] for key in ["r2"]}
814 result = verify_bgp_rib(
815 tgen, addr_type, dut, input_topo, next_hop, expected=False
17022899 816 )
b0449478
DS
817 assert result is not True, (
818 "Testcase {} : Failed \n "
d63c7094
KK
819 "Expected: Routes should not be present in {} BGP RIB \n "
820 "Found: {}".format(tc_name, dut, result)
17022899
KK
821 )
822
b0449478
DS
823 # Verifying RIB routes
824 result = verify_rib(
825 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
17022899 826 )
b0449478
DS
827 assert result is not True, (
828 "Testcase {} : Failed \n "
d63c7094
KK
829 "Expected: Routes should not be present in {} FIB \n "
830 "Found: {}".format(tc_name, dut, result)
17022899
KK
831 )
832
b0449478 833 logger.info("[Phase 5] : R2 is about to come up now ")
35ba1e3d 834
b0449478 835 start_router_daemons(tgen, "r2", ["bgpd"])
35ba1e3d 836
b0449478 837 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
35ba1e3d
KK
838
839 for addr_type in ADDR_TYPES:
b0449478 840 # Verifying BGP RIB routes
35ba1e3d 841 next_hop = next_hop_per_address_family(
b0449478 842 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
35ba1e3d 843 )
b0449478
DS
844 input_topo = {key: topo["routers"][key] for key in ["r2"]}
845 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
35ba1e3d
KK
846 assert result is True, "Testcase {} : Failed \n Error {}".format(
847 tc_name, result
848 )
849
b0449478
DS
850 # Verifying RIB routes
851 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
35ba1e3d
KK
852 assert result is True, "Testcase {} : Failed \n Error {}".format(
853 tc_name, result
854 )
855
35ba1e3d
KK
856 write_test_footer(tc_name)
857
858
b0449478 859def test_BGP_GR_TC_31_1_p1(request):
35ba1e3d 860 """
b0449478
DS
861 After BGP neighborship is established and GR capability is exchanged,
862 transition restarting router to disabled state and vice versa.
35ba1e3d
KK
863 """
864
865 tgen = get_topogen()
866 tc_name = request.node.name
867 write_test_header(tc_name)
868
17022899
KK
869 # Check router status
870 check_router_status(tgen)
871
35ba1e3d
KK
872 # Don't run this test if we have any failure.
873 if tgen.routers_have_failure():
874 pytest.skip(tgen.errors)
875
17022899
KK
876 # Creating configuration from JSON
877 reset_config_on_routers(tgen)
35ba1e3d 878
17022899 879 logger.info(
b0449478 880 "[Phase 1] : Test Setup" " [Helper Mode]R2-----R1[Restart Mode] initialized "
17022899
KK
881 )
882
883 # Configure graceful-restart
884 input_dict = {
b0449478 885 "r2": {
35ba1e3d
KK
886 "bgp": {
887 "address_family": {
17022899 888 "ipv4": {
35ba1e3d
KK
889 "unicast": {
890 "neighbor": {
b0449478 891 "r1": {
35ba1e3d 892 "dest_link": {
b0449478 893 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
894 }
895 }
896 }
897 }
17022899 898 },
35ba1e3d
KK
899 "ipv6": {
900 "unicast": {
901 "neighbor": {
b0449478 902 "r1": {
35ba1e3d 903 "dest_link": {
b0449478 904 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
905 }
906 }
907 }
908 }
909 },
910 }
911 }
912 },
b0449478 913 "r1": {
35ba1e3d 914 "bgp": {
b0449478 915 "graceful-restart": {"preserve-fw-state": True},
35ba1e3d
KK
916 "address_family": {
917 "ipv4": {
918 "unicast": {
919 "neighbor": {
b0449478 920 "r2": {
35ba1e3d 921 "dest_link": {
b0449478 922 "r1-link1": {"graceful-restart": True}
35ba1e3d
KK
923 }
924 }
925 }
926 }
927 },
928 "ipv6": {
929 "unicast": {
930 "neighbor": {
b0449478 931 "r2": {
35ba1e3d 932 "dest_link": {
b0449478 933 "r1-link1": {"graceful-restart": True}
35ba1e3d
KK
934 }
935 }
936 }
937 }
938 },
b0449478 939 },
35ba1e3d
KK
940 }
941 },
942 }
943
17022899 944 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
35ba1e3d
KK
945
946 for addr_type in ADDR_TYPES:
947 result = verify_graceful_restart(
17022899 948 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
35ba1e3d
KK
949 )
950 assert result is True, "Testcase {} : Failed \n Error {}".format(
951 tc_name, result
952 )
953
954 # Verifying BGP RIB routes
955 dut = "r1"
956 peer = "r2"
17022899 957 protocol = "bgp"
35ba1e3d 958 next_hop = next_hop_per_address_family(
17022899 959 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
35ba1e3d 960 )
17022899 961 input_topo = {key: topo["routers"][key] for key in ["r2"]}
35ba1e3d
KK
962 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
963 assert result is True, "Testcase {} : Failed \n Error {}".format(
964 tc_name, result
965 )
966
967 # Verifying RIB routes
968 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
969 assert result is True, "Testcase {} : Failed \n Error {}".format(
970 tc_name, result
971 )
972
b0449478 973 logger.info("[Phase 2] : R1 Goes from Restart to Disable Mode ")
35ba1e3d
KK
974
975 # Configure graceful-restart
976 input_dict = {
977 "r1": {
978 "bgp": {
979 "address_family": {
980 "ipv4": {
981 "unicast": {
982 "neighbor": {
983 "r2": {
984 "dest_link": {
b0449478 985 "r1-link1": {"graceful-restart-disable": True}
35ba1e3d
KK
986 }
987 }
988 }
989 }
990 },
991 "ipv6": {
992 "unicast": {
993 "neighbor": {
994 "r2": {
995 "dest_link": {
b0449478
DS
996 "r1-link1": {"graceful-restart-disable": True}
997 }
998 }
999 }
1000 }
1001 },
1002 }
1003 }
1004 }
1005 }
1006
1007 result = create_router_bgp(tgen, topo, input_dict)
1008 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1009
1010 for addr_type in ADDR_TYPES:
1011 neighbor = topo["routers"]["r2"]["links"]["r1-link1"][addr_type].split("/")[0]
1012 clear_bgp(tgen, addr_type, "r1", neighbor=neighbor)
1013
1014 result = verify_bgp_convergence_from_running_config(tgen)
1015 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1016
1017 # Verify GR stats
1018 input_dict = {
1019 "r1": {
1020 "bgp": {
1021 "address_family": {
1022 "ipv4": {
1023 "unicast": {
1024 "neighbor": {
1025 "r2": {
1026 "dest_link": {
1027 "r1-link1": {"graceful-restart-disable": True}
1028 }
1029 }
1030 }
1031 }
1032 },
1033 "ipv6": {
1034 "unicast": {
1035 "neighbor": {
1036 "r2": {
1037 "dest_link": {
1038 "r1-link1": {"graceful-restart-disable": True}
35ba1e3d
KK
1039 }
1040 }
1041 }
1042 }
1043 },
1044 }
1045 }
1046 },
1047 "r2": {
1048 "bgp": {
1049 "address_family": {
1050 "ipv4": {
1051 "unicast": {
1052 "neighbor": {
1053 "r1": {
1054 "dest_link": {
b0449478 1055 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
1056 }
1057 }
1058 }
1059 }
1060 },
1061 "ipv6": {
1062 "unicast": {
1063 "neighbor": {
1064 "r1": {
1065 "dest_link": {
b0449478 1066 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
1067 }
1068 }
1069 }
1070 }
1071 },
1072 }
1073 }
1074 },
1075 }
1076
35ba1e3d
KK
1077 for addr_type in ADDR_TYPES:
1078 result = verify_graceful_restart(
1079 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1080 )
1081 assert result is True, "Testcase {} : Failed \n Error {}".format(
1082 tc_name, result
1083 )
1084
b0449478 1085 logger.info("[Phase 2] : R1 goes for reload ")
35ba1e3d 1086
b0449478 1087 kill_router_daemons(tgen, "r1", ["bgpd"])
35ba1e3d 1088
b0449478
DS
1089 logger.info(
1090 "[Phase 3] : R1 is still down, restart time 120 sec."
1091 " So time verify the routes are not present in BGP RIB and ZEBRA"
1092 )
35ba1e3d
KK
1093
1094 for addr_type in ADDR_TYPES:
b0449478
DS
1095 # Verifying RIB routes
1096 next_hop = next_hop_per_address_family(
1097 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
35ba1e3d 1098 )
b0449478
DS
1099 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1100 result = verify_rib(
1101 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
35ba1e3d 1102 )
b0449478
DS
1103 assert result is not True, (
1104 "Testcase {} : Failed \n "
d63c7094
KK
1105 "Expected: Routes should not be present in {} FIB \n "
1106 "Found: {}".format(tc_name, dut, result)
35ba1e3d
KK
1107 )
1108
b0449478
DS
1109 logger.info("[Phase 4] : R1 is about to come up now ")
1110 start_router_daemons(tgen, "r1", ["bgpd"])
17022899 1111
b0449478 1112 logger.info("[Phase 5] : R1 is UP now, so time to collect GR stats ")
17022899
KK
1113
1114 for addr_type in ADDR_TYPES:
1115 result = verify_graceful_restart(
1116 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
35ba1e3d 1117 )
35ba1e3d
KK
1118 assert result is True, "Testcase {} : Failed \n Error {}".format(
1119 tc_name, result
1120 )
1121
17022899
KK
1122 # Verifying BGP RIB routes
1123 next_hop = next_hop_per_address_family(
1124 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1125 )
1126 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1127 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
35ba1e3d
KK
1128 assert result is True, "Testcase {} : Failed \n Error {}".format(
1129 tc_name, result
1130 )
1131
17022899
KK
1132 # Verifying RIB routes
1133 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1134 assert result is True, "Testcase {} : Failed \n Error {}".format(
35ba1e3d
KK
1135 tc_name, result
1136 )
1137
1138 write_test_footer(tc_name)
1139
1140
b0449478 1141def test_BGP_GR_TC_31_2_p1(request):
35ba1e3d 1142 """
b0449478
DS
1143 After BGP neighborship is established and GR capability is exchanged,
1144 transition restarting router to disabled state and vice versa.
35ba1e3d
KK
1145 """
1146
1147 tgen = get_topogen()
1148 tc_name = request.node.name
1149 write_test_header(tc_name)
1150
1151 # Check router status
1152 check_router_status(tgen)
1153
1154 # Don't run this test if we have any failure.
1155 if tgen.routers_have_failure():
1156 pytest.skip(tgen.errors)
1157
1158 # Creating configuration from JSON
1159 reset_config_on_routers(tgen)
1160
1161 logger.info(
b0449478 1162 "[Phase 1] : Test Setup " "[Disable Mode]R1-----R2[Restart Mode] initialized "
35ba1e3d
KK
1163 )
1164
1165 # Configure graceful-restart
1166 input_dict = {
b0449478 1167 "r2": {
35ba1e3d
KK
1168 "bgp": {
1169 "address_family": {
1170 "ipv4": {
1171 "unicast": {
1172 "neighbor": {
b0449478 1173 "r1": {
35ba1e3d 1174 "dest_link": {
b0449478 1175 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
1176 }
1177 }
1178 }
1179 }
1180 },
1181 "ipv6": {
1182 "unicast": {
1183 "neighbor": {
b0449478 1184 "r1": {
35ba1e3d 1185 "dest_link": {
b0449478 1186 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
1187 }
1188 }
1189 }
1190 }
1191 },
1192 }
1193 }
1194 },
b0449478 1195 "r1": {
35ba1e3d
KK
1196 "bgp": {
1197 "address_family": {
1198 "ipv4": {
1199 "unicast": {
1200 "neighbor": {
b0449478 1201 "r2": {
35ba1e3d 1202 "dest_link": {
b0449478 1203 "r1-link1": {"graceful-restart-disable": True}
35ba1e3d
KK
1204 }
1205 }
1206 }
1207 }
1208 },
1209 "ipv6": {
1210 "unicast": {
1211 "neighbor": {
b0449478 1212 "r2": {
35ba1e3d 1213 "dest_link": {
b0449478 1214 "r1-link1": {"graceful-restart-disable": True}
35ba1e3d
KK
1215 }
1216 }
1217 }
1218 }
1219 },
1220 }
1221 }
1222 },
1223 }
1224
1225 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
1226
1227 for addr_type in ADDR_TYPES:
1228 result = verify_graceful_restart(
1229 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1230 )
1231 assert result is True, "Testcase {} : Failed \n Error {}".format(
1232 tc_name, result
1233 )
1234
1235 # Verifying BGP RIB routes
1236 dut = "r1"
1237 peer = "r2"
1238 next_hop = next_hop_per_address_family(
1239 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1240 )
1241 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1242 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1243 assert result is True, "Testcase {} : Failed \n Error {}".format(
1244 tc_name, result
1245 )
1246
1247 # Verifying RIB routes
1248 protocol = "bgp"
1249 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1250 assert result is True, "Testcase {} : Failed \n Error {}".format(
1251 tc_name, result
1252 )
1253
b0449478 1254 logger.info("[Phase 2] : R2 Goes from Disable to Restart Mode ")
35ba1e3d
KK
1255
1256 # Configure graceful-restart
1257 input_dict = {
1258 "r1": {
1259 "bgp": {
b0449478 1260 "graceful-restart": {"preserve-fw-state": True},
35ba1e3d
KK
1261 "address_family": {
1262 "ipv4": {
1263 "unicast": {
1264 "neighbor": {
1265 "r2": {
1266 "dest_link": {
b0449478 1267 "r1-link1": {"graceful-restart": True}
35ba1e3d
KK
1268 }
1269 }
1270 }
1271 }
1272 },
1273 "ipv6": {
1274 "unicast": {
1275 "neighbor": {
1276 "r2": {
1277 "dest_link": {
b0449478 1278 "r1-link1": {"graceful-restart": True}
35ba1e3d
KK
1279 }
1280 }
1281 }
1282 }
1283 },
b0449478 1284 },
35ba1e3d 1285 }
17022899
KK
1286 }
1287 }
1288
1289 result = create_router_bgp(tgen, topo, input_dict)
1290 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1291
1292 for addr_type in ADDR_TYPES:
2268cf50
KK
1293 neighbor = topo["routers"]["r2"]["links"]["r1-link1"][addr_type].split("/")[0]
1294 clear_bgp(tgen, addr_type, "r1", neighbor=neighbor)
17022899 1295
2268cf50 1296 result = verify_bgp_convergence_from_running_config(tgen)
17022899
KK
1297 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1298
1299 # Verify GR stats
1300 input_dict = {
35ba1e3d
KK
1301 "r2": {
1302 "bgp": {
1303 "address_family": {
1304 "ipv4": {
1305 "unicast": {
1306 "neighbor": {
1307 "r1": {
1308 "dest_link": {
1309 "r2-link1": {"graceful-restart-helper": True}
1310 }
1311 }
1312 }
1313 }
1314 },
1315 "ipv6": {
1316 "unicast": {
1317 "neighbor": {
1318 "r1": {
1319 "dest_link": {
1320 "r2-link1": {"graceful-restart-helper": True}
1321 }
1322 }
1323 }
1324 }
1325 },
1326 }
1327 }
1328 },
17022899
KK
1329 "r1": {
1330 "bgp": {
1331 "address_family": {
1332 "ipv4": {
1333 "unicast": {
1334 "neighbor": {
1335 "r2": {
1336 "dest_link": {
b0449478 1337 "r1-link1": {"graceful-restart": True}
17022899
KK
1338 }
1339 }
1340 }
1341 }
1342 },
1343 "ipv6": {
1344 "unicast": {
1345 "neighbor": {
1346 "r2": {
1347 "dest_link": {
b0449478 1348 "r1-link1": {"graceful-restart": True}
17022899
KK
1349 }
1350 }
1351 }
1352 }
1353 },
1354 }
1355 }
1356 },
35ba1e3d
KK
1357 }
1358
17022899
KK
1359 # here the verify_graceful_restart fro the neighbor would be
1360 # "NotReceived" as the latest GR config is not yet applied.
35ba1e3d
KK
1361 for addr_type in ADDR_TYPES:
1362 result = verify_graceful_restart(
1363 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1364 )
1365 assert result is True, "Testcase {} : Failed \n Error {}".format(
1366 tc_name, result
1367 )
1368
b0449478
DS
1369 for addr_type in ADDR_TYPES:
1370 # Verifying RIB routes
1371 next_hop = next_hop_per_address_family(
1372 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1373 )
1374 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1375 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1376 assert result is True, "Testcase {} : Failed \n Error {}".format(
1377 tc_name, result
1378 )
1379
1380 logger.info("[Phase 6] : R1 is about to come up now ")
1381 start_router_daemons(tgen, "r1", ["bgpd"])
35ba1e3d 1382
b0449478 1383 logger.info("[Phase 4] : R1 is UP now, so time to collect GR stats ")
35ba1e3d
KK
1384
1385 for addr_type in ADDR_TYPES:
17022899
KK
1386 result = verify_graceful_restart(
1387 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
35ba1e3d 1388 )
17022899 1389 assert result is True, "Testcase {} : Failed \n Error {}".format(
35ba1e3d
KK
1390 tc_name, result
1391 )
35ba1e3d 1392
b0449478
DS
1393 # Verifying BGP RIB routes
1394 next_hop = next_hop_per_address_family(
1395 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
35ba1e3d 1396 )
b0449478
DS
1397 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1398 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1399 assert result is True, "Testcase {} : Failed \n Error {}".format(
35ba1e3d 1400 tc_name, result
0b25370e 1401 )
35ba1e3d 1402
b0449478
DS
1403 # Verifying RIB routes
1404 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1405 assert result is True, "Testcase {} : Failed \n Error {}".format(
1406 tc_name, result
1407 )
35ba1e3d 1408
b0449478
DS
1409 logger.info("[Phase 3] : R1 goes for reload ")
1410
1411 kill_router_daemons(tgen, "r1", ["bgpd"])
1412
1413 logger.info(
1414 "[Phase 4] : R1 is still down, restart time 120 sec."
1415 " So time verify the routes are present in BGP RIB and ZEBRA "
1416 )
1417
1418 for addr_type in ADDR_TYPES:
1419 # Verifying RIB routes
1420 next_hop = next_hop_per_address_family(
1421 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1422 )
1423 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1424 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1425 assert result is True, "Testcase {} : Failed \n Error {}".format(
1426 tc_name, result
1427 )
1428
1429 logger.info("[Phase 6] : R1 is about to come up now ")
1430 start_router_daemons(tgen, "r1", ["bgpd"])
1431
1432 logger.info("[Phase 4] : R1 is UP now, so time to collect GR stats ")
35ba1e3d
KK
1433
1434 for addr_type in ADDR_TYPES:
1435 result = verify_graceful_restart(
1436 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1437 )
1438 assert result is True, "Testcase {} : Failed \n Error {}".format(
1439 tc_name, result
1440 )
1441
b0449478
DS
1442 # Verifying BGP RIB routes
1443 next_hop = next_hop_per_address_family(
1444 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
35ba1e3d 1445 )
b0449478
DS
1446 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1447 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1448 assert result is True, "Testcase {} : Failed \n Error {}".format(
1449 tc_name, result
1450 )
1451
1452 # Verifying RIB routes
1453 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1454 assert result is True, "Testcase {} : Failed \n Error {}".format(
35ba1e3d 1455 tc_name, result
0b25370e 1456 )
35ba1e3d
KK
1457
1458 write_test_footer(tc_name)
1459
1460
b0449478 1461def test_BGP_GR_TC_9_p1(request):
35ba1e3d 1462 """
b0449478
DS
1463 Test Objective : Verify that restarting nodes reset "F" bit while sending
1464 the BGP open messages after it's restarts, when BGP GR is **NOT** enabled.
35ba1e3d 1465 """
17022899 1466
35ba1e3d
KK
1467 tgen = get_topogen()
1468 tc_name = request.node.name
1469 write_test_header(tc_name)
1470
1471 # Check router status
1472 check_router_status(tgen)
1473
1474 # Don't run this test if we have any failure.
1475 if tgen.routers_have_failure():
1476 pytest.skip(tgen.errors)
1477
1478 # Creating configuration from JSON
1479 reset_config_on_routers(tgen)
1480
1481 logger.info(
b0449478 1482 "[Phase 1] : Test Setup" " [Restart Mode]R1-----R2[Helper Mode] Initiliazed "
35ba1e3d
KK
1483 )
1484
1485 # Configure graceful-restart
1486 input_dict = {
1487 "r1": {
1488 "bgp": {
1489 "address_family": {
1490 "ipv4": {
1491 "unicast": {
1492 "neighbor": {
1493 "r2": {
1494 "dest_link": {
1495 "r1-link1": {"graceful-restart": True}
1496 }
1497 }
1498 }
1499 }
1500 },
1501 "ipv6": {
1502 "unicast": {
1503 "neighbor": {
1504 "r2": {
1505 "dest_link": {
1506 "r1-link1": {"graceful-restart": True}
1507 }
1508 }
1509 }
1510 }
1511 },
b0449478 1512 }
35ba1e3d
KK
1513 }
1514 },
1515 "r2": {
1516 "bgp": {
b0449478 1517 "graceful-restart": {"preserve-fw-state": True},
35ba1e3d
KK
1518 "address_family": {
1519 "ipv4": {
1520 "unicast": {
1521 "neighbor": {
1522 "r1": {
1523 "dest_link": {
b0449478 1524 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
1525 }
1526 }
1527 }
1528 }
1529 },
1530 "ipv6": {
1531 "unicast": {
1532 "neighbor": {
1533 "r1": {
1534 "dest_link": {
b0449478 1535 "r2-link1": {"graceful-restart-helper": True}
35ba1e3d
KK
1536 }
1537 }
1538 }
1539 }
1540 },
b0449478 1541 },
35ba1e3d
KK
1542 }
1543 },
1544 }
1545
1546 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
1547
1548 for addr_type in ADDR_TYPES:
1549 result = verify_graceful_restart(
1550 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1551 )
b0449478 1552 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d
KK
1553
1554 # Verifying BGP RIB routes
1555 dut = "r1"
1556 peer = "r2"
1557 next_hop = next_hop_per_address_family(
1558 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1559 )
1560 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1561 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
b0449478 1562 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d
KK
1563
1564 # Verifying RIB routes
1565 protocol = "bgp"
1566 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 1567 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d 1568
b0449478
DS
1569 logger.info("[Phase 2] : R2 goes for reload ")
1570 kill_router_daemons(tgen, "r2", ["bgpd"])
35ba1e3d 1571
b0449478
DS
1572 logger.info(
1573 "[Phase 3] : R2 is still down, restart time 120 sec."
1574 "So time verify the routes are present in BGP RIB and ZEBRA "
1575 )
35ba1e3d
KK
1576
1577 for addr_type in ADDR_TYPES:
b0449478
DS
1578 # Verifying BGP RIB routes
1579 next_hop = next_hop_per_address_family(
1580 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
35ba1e3d 1581 )
b0449478
DS
1582 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1583 result = verify_bgp_rib(
1584 tgen, addr_type, dut, input_topo, next_hop, expected=False
35ba1e3d 1585 )
b0449478
DS
1586 assert result is not True, (
1587 "Testcase {} : Failed \n "
d63c7094
KK
1588 "Expected: Routes should not be present in {} BGP RIB \n "
1589 "Found: {}".format(tc_name, dut, result)
35ba1e3d
KK
1590 )
1591
b0449478
DS
1592 # Verifying RIB routes
1593 protocol = "bgp"
1594 result = verify_rib(
1595 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
35ba1e3d 1596 )
b0449478
DS
1597 assert result is not True, (
1598 "Testcase {} : Failed \n "
d63c7094
KK
1599 "Expected: Routes should not be present in {} FIB \n "
1600 "Found: {}".format(tc_name, dut, result)
b0449478 1601 )
35ba1e3d 1602
b0449478
DS
1603 logger.info("[Phase 5] : R2 is about to come up now ")
1604 start_router_daemons(tgen, "r2", ["bgpd"])
35ba1e3d 1605
b0449478 1606 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
35ba1e3d
KK
1607
1608 for addr_type in ADDR_TYPES:
b0449478
DS
1609 result = verify_bgp_convergence(tgen, topo)
1610 assert (
1611 result is True
1612 ), "BGP Convergence after BGPd restart" " :Failed \n Error:{}".format(result)
1613
35ba1e3d
KK
1614 result = verify_graceful_restart(
1615 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1616 )
b0449478 1617 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d 1618
b0449478
DS
1619 result = verify_graceful_restart(
1620 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
35ba1e3d 1621 )
b0449478 1622 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d 1623
b0449478
DS
1624 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r1", peer="r2")
1625 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d 1626
b0449478
DS
1627 result = verify_f_bit(
1628 tgen, topo, addr_type, input_dict, dut="r1", peer="r2", expected=False
35ba1e3d 1629 )
d63c7094
KK
1630 assert result is not True, (
1631 "Testcase {} : Failed \n "
1632 "Expected: F-bit should not be set to True in r1\n"
1633 "Found: {}".format(tc_name, result)
35ba1e3d
KK
1634 )
1635
1636 write_test_footer(tc_name)
1637
1638
b0449478 1639def test_BGP_GR_TC_17_p1(request):
35ba1e3d 1640 """
b0449478
DS
1641 Test Objective : Verify that only GR helper routers keep the stale
1642 route entries, not any GR disabled router.
35ba1e3d 1643 """
b0449478 1644
35ba1e3d
KK
1645 tgen = get_topogen()
1646 tc_name = request.node.name
1647 write_test_header(tc_name)
1648
1649 # Check router status
1650 check_router_status(tgen)
1651
1652 # Don't run this test if we have any failure.
1653 if tgen.routers_have_failure():
1654 pytest.skip(tgen.errors)
1655
1656 # Creating configuration from JSON
1657 reset_config_on_routers(tgen)
1658
b0449478 1659 logger.info("[Phase 1] : Test Setup [Disable]R1-----R2[Restart] " "Initiliazed ")
35ba1e3d
KK
1660
1661 # Configure graceful-restart
1662 input_dict = {
1663 "r1": {
1664 "bgp": {
1665 "graceful-restart": {
1666 "graceful-restart": True,
1667 "preserve-fw-state": True,
1668 },
1669 "address_family": {
1670 "ipv4": {
1671 "unicast": {
1672 "neighbor": {
1673 "r2": {
1674 "dest_link": {
b0449478 1675 "r1-link1": {"graceful-restart-disable": True}
35ba1e3d
KK
1676 }
1677 }
1678 }
1679 }
1680 },
1681 "ipv6": {
1682 "unicast": {
1683 "neighbor": {
1684 "r2": {
1685 "dest_link": {
b0449478 1686 "r1-link1": {"graceful-restart-disable": True}
35ba1e3d
KK
1687 }
1688 }
1689 }
1690 }
1691 },
1692 },
1693 }
1694 },
1695 "r2": {
1696 "bgp": {
1697 "address_family": {
1698 "ipv4": {
1699 "unicast": {
1700 "neighbor": {
1701 "r1": {
1702 "dest_link": {
b0449478 1703 "r2-link1": {"graceful-restart": True}
35ba1e3d
KK
1704 }
1705 }
1706 }
1707 }
1708 },
1709 "ipv6": {
1710 "unicast": {
1711 "neighbor": {
1712 "r1": {
1713 "dest_link": {
b0449478 1714 "r2-link1": {"graceful-restart": True}
35ba1e3d
KK
1715 }
1716 }
1717 }
1718 }
1719 },
1720 }
1721 }
1722 },
1723 }
1724
1725 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
1726
1727 for addr_type in ADDR_TYPES:
1728 result = verify_graceful_restart(
1729 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1730 )
b0449478 1731 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d
KK
1732
1733 # Verifying BGP RIB routes
1734 dut = "r1"
1735 peer = "r2"
1736 next_hop = next_hop_per_address_family(
1737 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1738 )
1739 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1740 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
b0449478 1741 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d
KK
1742
1743 # Verifying RIB routes
1744 protocol = "bgp"
1745 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478
DS
1746 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1747
1748 logger.info("[Phase 2] : R2 goes for reload ")
35ba1e3d 1749
35ba1e3d
KK
1750 kill_router_daemons(tgen, "r2", ["bgpd"])
1751
b0449478
DS
1752 logger.info(
1753 "[Phase 3] : R2 is still down, restart time 120 sec."
1754 " So time verify the routes are present in BGP RIB and ZEBRA "
1755 )
1756
35ba1e3d
KK
1757 for addr_type in ADDR_TYPES:
1758 # Verifying BGP RIB routes
1759 next_hop = next_hop_per_address_family(
1760 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1761 )
1762 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1763 result = verify_bgp_rib(
1764 tgen, addr_type, dut, input_topo, next_hop, expected=False
1765 )
0b25370e
DS
1766 assert result is not True, (
1767 "Testcase {} : Failed \n "
d63c7094
KK
1768 "Expected: Routes should not be present in {} BGP RIB \n "
1769 "Found: {}".format(tc_name, dut, result)
0b25370e 1770 )
35ba1e3d
KK
1771
1772 # Verifying RIB routes
b0449478 1773 protocol = "bgp"
35ba1e3d
KK
1774 result = verify_rib(
1775 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
1776 )
0b25370e
DS
1777 assert result is not True, (
1778 "Testcase {} : Failed \n "
d63c7094
KK
1779 "Expected: Routes should not be present in {} FIB \n "
1780 "Found: {}".format(tc_name, dut, result)
0b25370e 1781 )
35ba1e3d
KK
1782
1783 logger.info("[Phase 5] : R2 is about to come up now ")
1784 start_router_daemons(tgen, "r2", ["bgpd"])
1785
1786 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
1787
1788 for addr_type in ADDR_TYPES:
b0449478 1789 result = verify_bgp_convergence(tgen, topo)
17022899
KK
1790 assert (
1791 result is True
b0449478 1792 ), "BGP Convergence after BGPd restart" " :Failed \n Error:{}".format(result)
17022899 1793
17022899
KK
1794 result = verify_graceful_restart(
1795 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1796 )
1797 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899 1798
b0449478
DS
1799 result = verify_r_bit(
1800 tgen, topo, addr_type, input_dict, dut="r1", peer="r2", expected=False
1801 )
d63c7094
KK
1802 assert result is not True, (
1803 "Testcase {} : Failed \n "
1804 "Expected: R-bit should not be set to True in r1\n"
1805 "Found: {}".format(tc_name, result)
17022899 1806 )
17022899 1807
b0449478 1808 # Verifying BGP RIB routes
17022899
KK
1809 next_hop = next_hop_per_address_family(
1810 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1811 )
b0449478 1812 input_topo = {key: topo["routers"][key] for key in ["r2"]}
17022899
KK
1813 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1814 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
b0449478
DS
1815
1816 # Verifying RIB routes
1817 protocol = "bgp"
17022899
KK
1818 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1819 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1820
b0449478 1821 write_test_footer(tc_name)
17022899 1822
17022899 1823
b0449478
DS
1824def test_BGP_GR_TC_43_p1(request):
1825 """
1826 Test Objective : Transition from Global Restarting to Disable
1827 and then Global Disable to Restarting.
17022899 1828
b0449478 1829 """
17022899 1830
b0449478
DS
1831 tgen = get_topogen()
1832 tc_name = request.node.name
1833 write_test_header(tc_name)
17022899 1834
b0449478
DS
1835 # Check router status
1836 check_router_status(tgen)
17022899 1837
b0449478
DS
1838 # Don't run this test if we have any failure.
1839 if tgen.routers_have_failure():
1840 pytest.skip(tgen.errors)
1841
1842 # Creating configuration from JSON
1843 reset_config_on_routers(tgen)
1844
1845 step("Configure R1 and R2 as GR restarting node in global level")
17022899
KK
1846
1847 input_dict = {
1848 "r1": {
1849 "bgp": {
b0449478
DS
1850 "graceful-restart": {
1851 "graceful-restart": True,
17022899
KK
1852 }
1853 }
b0449478
DS
1854 },
1855 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
17022899
KK
1856 }
1857
1858 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
1859
1860 step("Verify on R2 that R1 advertises GR capabilities as a restarting node")
1861
17022899
KK
1862 for addr_type in ADDR_TYPES:
1863 result = verify_graceful_restart(
1864 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1865 )
1866 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1867 result = verify_graceful_restart(
1868 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
1869 )
1870 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1871
1872 for addr_type in ADDR_TYPES:
1873 dut = "r1"
1874 peer = "r2"
1875 protocol = "bgp"
1876 next_hop = next_hop_per_address_family(
1877 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1878 )
1879 input_topo = {"r2": topo["routers"]["r2"]}
1880 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 1881 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899
KK
1882
1883 dut = "r2"
1884 peer = "r1"
1885 next_hop = next_hop_per_address_family(
1886 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
1887 )
1888 input_topo = {"r1": topo["routers"]["r1"]}
1889 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1890 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
b0449478 1891 protocol = "bgp"
17022899 1892 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 1893 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899
KK
1894
1895 step("Kill BGP on R1")
1896
1897 kill_router_daemons(tgen, "r1", ["bgpd"])
1898
1899 step(
b0449478
DS
1900 "Verify that R1 keeps BGP routes in zebra and R2 retains"
1901 " the stale entry for received routes from R1"
17022899
KK
1902 )
1903
1904 for addr_type in ADDR_TYPES:
1905 dut = "r1"
1906 peer = "r2"
1907 protocol = "bgp"
1908 next_hop = next_hop_per_address_family(
1909 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1910 )
1911 input_topo = {"r2": topo["routers"]["r2"]}
1912 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 1913 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899
KK
1914
1915 dut = "r2"
1916 peer = "r1"
1917 next_hop = next_hop_per_address_family(
1918 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
1919 )
1920 input_topo = {"r1": topo["routers"]["r1"]}
1921 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1922 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
b0449478 1923 protocol = "bgp"
17022899 1924 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 1925 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899 1926
b0449478 1927 step("Bring up BGPd on R1 and configure it as GR disabled node in global level")
17022899 1928
b0449478 1929 start_router_daemons(tgen, "r1", ["bgpd"])
17022899 1930
b0449478
DS
1931 input_dict = {
1932 "r1": {
1933 "bgp": {
1934 "graceful-restart": {
1935 "graceful-restart": False,
1936 "graceful-restart-disable": True,
1937 }
1938 }
1939 }
1940 }
17022899 1941
b0449478 1942 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
17022899 1943
b0449478 1944 step("Verify on R2 that R1 doesn't advertise any GR capabilities")
17022899
KK
1945
1946 input_dict = {
1947 "r1": {
1948 "bgp": {
9fa6ec14 1949 "graceful-restart": {
b0449478
DS
1950 "graceful-restart-disable": True,
1951 }
17022899
KK
1952 }
1953 },
1954 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
1955 }
1956
17022899
KK
1957 for addr_type in ADDR_TYPES:
1958 result = verify_graceful_restart(
1959 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1960 )
1961 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
b0449478 1962
17022899
KK
1963 result = verify_graceful_restart(
1964 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
1965 )
1966 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1967
1968 for addr_type in ADDR_TYPES:
1969 dut = "r1"
1970 peer = "r2"
1971 protocol = "bgp"
1972 next_hop = next_hop_per_address_family(
1973 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1974 )
1975 input_topo = {"r2": topo["routers"]["r2"]}
1976 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1977 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1978
1979 dut = "r2"
1980 peer = "r1"
1981 next_hop = next_hop_per_address_family(
1982 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
1983 )
1984 input_topo = {"r1": topo["routers"]["r1"]}
1985 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1986 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
b0449478 1987 protocol = "bgp"
17022899
KK
1988 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1989 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
1990
1991 step("Kill BGP on R1")
1992
1993 kill_router_daemons(tgen, "r1", ["bgpd"])
1994
1995 step(
b0449478
DS
1996 "Verify that R1 flush all BGP routes from RIB & FIB and FIB and R2"
1997 " does not retain stale entry for received routes from R1"
17022899
KK
1998 )
1999
2000 for addr_type in ADDR_TYPES:
2001 dut = "r1"
2002 peer = "r2"
2003 protocol = "bgp"
2004 next_hop = next_hop_per_address_family(
2005 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2006 )
2007 input_topo = {"r2": topo["routers"]["r2"]}
b0449478
DS
2008 result = verify_rib(
2009 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
2010 )
d63c7094
KK
2011 assert result is not True, (
2012 "Testcase {} : Failed \n "
2013 "Expected: Routes should not be present in {} FIB \n "
2014 "Found: {}".format(tc_name, dut, result)
b0449478 2015 )
17022899
KK
2016
2017 dut = "r2"
2018 peer = "r1"
2019 next_hop = next_hop_per_address_family(
2020 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
b0449478
DS
2021 )
2022 input_topo = {"r1": topo["routers"]["r1"]}
2023 result = verify_bgp_rib(
2024 tgen, addr_type, dut, input_topo, next_hop, expected=False
2025 )
2026 assert result is not True, (
2027 "Testcase {} : Failed \n "
d63c7094
KK
2028 "Expected: Routes should not be present in {} BGP RIB \n "
2029 "Found: {}".format(tc_name, dut, result)
b0449478 2030 )
d63c7094 2031
b0449478
DS
2032 protocol = "bgp"
2033 result = verify_rib(
2034 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
2035 )
d63c7094
KK
2036 assert result is not True, (
2037 "Testcase {} : Failed \n "
2038 "Expected: Routes should not be present in {} FIB \n "
2039 "Found: {}".format(tc_name, dut, result)
b0449478
DS
2040 )
2041
2042 step(
2043 "Bring up BGPd on R1 and configure it as GR" " restarting node in global level"
2044 )
2045
2046 start_router_daemons(tgen, "r1", ["bgpd"])
2047
2048 input_dict = {"r1": {"bgp": {"graceful-restart": {"graceful-restart": True}}}}
17022899
KK
2049
2050 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2051
b0449478 2052 step("Verify on R2 that R1 advertises GR capabilities as a restarting node")
17022899
KK
2053
2054 input_dict = {
9fa6ec14 2055 "r1": {
2056 "bgp": {
2057 "graceful-restart": {
2058 "graceful-restart": True,
2059 }
2060 }
2061 },
17022899
KK
2062 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
2063 }
2064
2065 for addr_type in ADDR_TYPES:
2066 result = verify_graceful_restart(
2067 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2068 )
2069 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
b0449478 2070
17022899
KK
2071 result = verify_graceful_restart(
2072 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
2073 )
2074 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2075
2076 for addr_type in ADDR_TYPES:
2077 dut = "r1"
2078 peer = "r2"
2079 protocol = "bgp"
2080 next_hop = next_hop_per_address_family(
2081 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2082 )
2083 input_topo = {"r2": topo["routers"]["r2"]}
2084 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2085 assert (
2086 result is True
2087 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2088 tc_name, result
2089 )
2090
2091 dut = "r2"
2092 peer = "r1"
2093 next_hop = next_hop_per_address_family(
2094 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2095 )
2096 input_topo = {"r1": topo["routers"]["r1"]}
2097 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2098 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2099 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2100 assert (
2101 result is True
2102 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2103 tc_name, result
2104 )
2105
2106 step("Kill BGP on R1")
2107
2108 kill_router_daemons(tgen, "r1", ["bgpd"])
2109
2110 step(
b0449478
DS
2111 "Verify that R1 keeps BGP routes in zebra and R2"
2112 " retains the stale entry for received routes from R1"
17022899
KK
2113 )
2114
2115 for addr_type in ADDR_TYPES:
2116 dut = "r1"
2117 peer = "r2"
2118 protocol = "bgp"
2119 next_hop = next_hop_per_address_family(
2120 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2121 )
2122 input_topo = {"r2": topo["routers"]["r2"]}
2123 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2124 assert (
2125 result is True
2126 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2127 tc_name, result
2128 )
2129
2130 dut = "r2"
2131 peer = "r1"
2132 next_hop = next_hop_per_address_family(
2133 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2134 )
2135 input_topo = {"r1": topo["routers"]["r1"]}
2136 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2137 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2138 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2139 assert (
2140 result is True
2141 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2142 tc_name, result
2143 )
2144
2145 write_test_footer(tc_name)
2146
2147
b0449478 2148def test_BGP_GR_TC_44_p1(request):
17022899 2149 """
b0449478
DS
2150 Test Objective : Transition from Global Helper to Disable
2151 and then Global Disable to Helper.
17022899
KK
2152
2153 """
2154
2155 tgen = get_topogen()
2156 tc_name = request.node.name
2157 write_test_header(tc_name)
2158
2159 # Check router status
2160 check_router_status(tgen)
2161
2162 # Don't run this test if we have any failure.
2163 if tgen.routers_have_failure():
2164 pytest.skip(tgen.errors)
2165
2166 # Creating configuration from JSON
2167 reset_config_on_routers(tgen)
2168
2169 step(
b0449478
DS
2170 "Configure R2 as GR restating node in global level and"
2171 " leave R1 without any GR related config"
17022899
KK
2172 )
2173
b0449478
DS
2174 input_dict = {"r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}}
2175
2176 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2177
2178 step("Verify on R2 that R1 advertises GR capabilities as a helper node")
2179
17022899
KK
2180 input_dict = {
2181 "r1": {
2182 "bgp": {
9fa6ec14 2183 "graceful-restart": {
b0449478
DS
2184 "graceful-restart-helper": True,
2185 }
17022899
KK
2186 }
2187 },
b0449478 2188 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
17022899
KK
2189 }
2190
17022899
KK
2191 for addr_type in ADDR_TYPES:
2192 result = verify_graceful_restart(
2193 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2194 )
2195 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
b0449478 2196
17022899
KK
2197 result = verify_graceful_restart(
2198 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
2199 )
2200 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2201
2202 for addr_type in ADDR_TYPES:
b0449478
DS
2203 dut = "r2"
2204 peer = "r1"
17022899
KK
2205 protocol = "bgp"
2206 next_hop = next_hop_per_address_family(
b0449478 2207 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
17022899 2208 )
b0449478 2209 input_topo = {"r1": topo["routers"]["r1"]}
17022899
KK
2210 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2211 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2212
b0449478
DS
2213 dut = "r1"
2214 peer = "r2"
17022899 2215 next_hop = next_hop_per_address_family(
b0449478 2216 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
17022899 2217 )
b0449478 2218 input_topo = {"r2": topo["routers"]["r2"]}
17022899
KK
2219 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2220 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2221 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2222 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2223
b0449478 2224 step("Kill BGP on R2")
17022899 2225
b0449478 2226 kill_router_daemons(tgen, "r2", ["bgpd"])
17022899 2227
b0449478 2228 step("Verify that R1 keeps stale entry for BGP routes when BGPd on R2 is down")
17022899
KK
2229
2230 for addr_type in ADDR_TYPES:
17022899
KK
2231 dut = "r2"
2232 peer = "r1"
b0449478 2233 protocol = "bgp"
17022899
KK
2234 next_hop = next_hop_per_address_family(
2235 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2236 )
2237 input_topo = {"r1": topo["routers"]["r1"]}
b0449478
DS
2238 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2239 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2240
2241 dut = "r1"
2242 peer = "r2"
2243 next_hop = next_hop_per_address_family(
2244 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
0b25370e 2245 )
b0449478
DS
2246 input_topo = {"r2": topo["routers"]["r2"]}
2247 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2248 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2249 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2250 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899 2251
b0449478 2252 step("Bring up BGPd on R2 and configure R1 as GR disabled node in global level")
17022899 2253
b0449478 2254 start_router_daemons(tgen, "r2", ["bgpd"])
17022899
KK
2255
2256 input_dict = {
2257 "r1": {
2258 "bgp": {
b0449478
DS
2259 "graceful-restart": {
2260 "graceful-restart-disable": True,
17022899
KK
2261 }
2262 }
2263 }
2264 }
2265
2266 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2267
b0449478 2268 step("Verify on R2 that R1 doesn't advertise any GR capabilities")
17022899
KK
2269
2270 input_dict = {
9fa6ec14 2271 "r1": {
2272 "bgp": {
2273 "graceful-restart": {
b0449478 2274 "graceful-restart-disable": True,
9fa6ec14 2275 }
2276 }
2277 },
b0449478 2278 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
17022899
KK
2279 }
2280
2281 for addr_type in ADDR_TYPES:
2282 result = verify_graceful_restart(
2283 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2284 )
2285 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2286 result = verify_graceful_restart(
2287 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
2288 )
2289 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2290
2291 for addr_type in ADDR_TYPES:
b0449478
DS
2292 dut = "r2"
2293 peer = "r1"
17022899
KK
2294 protocol = "bgp"
2295 next_hop = next_hop_per_address_family(
b0449478 2296 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
17022899 2297 )
b0449478 2298 input_topo = {"r1": topo["routers"]["r1"]}
17022899
KK
2299 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2300 assert (
2301 result is True
2302 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2303 tc_name, result
2304 )
2305
b0449478
DS
2306 step("Kill BGP on R2")
2307
2308 kill_router_daemons(tgen, "r2", ["bgpd"])
2309
2310 step("Verify that R1 does not retain stale entry for received routes from R2")
2311
2312 for addr_type in ADDR_TYPES:
17022899
KK
2313 dut = "r2"
2314 peer = "r1"
b0449478 2315 protocol = "bgp"
17022899
KK
2316 next_hop = next_hop_per_address_family(
2317 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2318 )
2319 input_topo = {"r1": topo["routers"]["r1"]}
17022899
KK
2320 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2321 assert (
2322 result is True
2323 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2324 tc_name, result
2325 )
2326
b0449478
DS
2327 dut = "r1"
2328 peer = "r2"
2329 next_hop = next_hop_per_address_family(
2330 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2331 )
2332 next_hop = NEXT_HOP_IP_2[addr_type]
2333 result = verify_bgp_rib(
2334 tgen, addr_type, dut, input_topo, next_hop, expected=False
2335 )
2336 assert result is not True, (
2337 "Testcase {} : Failed \n "
d63c7094
KK
2338 "Expected: Routes should not be present in {} BGP RIB \n "
2339 "Found: {}".format(tc_name, dut, result)
b0449478 2340 )
d63c7094 2341
b0449478
DS
2342 result = verify_rib(
2343 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
2344 )
d63c7094
KK
2345 assert result is not True, (
2346 "Testcase {} : Failed \n "
2347 "Expected: Routes should not be present in {} FIB \n "
2348 "Found: {}".format(tc_name, dut, result)
b0449478 2349 )
17022899 2350
b0449478 2351 step("Bring up BGPd on R2 and remove GR related config from R1 in global level")
17022899 2352
b0449478
DS
2353 start_router_daemons(tgen, "r2", ["bgpd"])
2354
2355 input_dict = {
2356 "r1": {"bgp": {"graceful-restart": {"graceful-restart-disable": False}}}
2357 }
2358
2359 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2360
2361 step("Verify on R2 that R1 advertises GR capabilities as a helper node")
2362
2363 input_dict = {
2364 "r1": {
2365 "bgp": {
2366 "graceful-restart": {
2367 "graceful-restart-helper": True,
2368 }
2369 }
2370 },
2371 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
2372 }
2373
2374 for addr_type in ADDR_TYPES:
2375 result = verify_graceful_restart(
2376 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2377 )
2378 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2379
2380 result = verify_graceful_restart(
2381 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
2382 )
2383 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2384
2385 for addr_type in ADDR_TYPES:
2386 dut = "r2"
2387 peer = "r1"
2388 protocol = "bgp"
2389 next_hop = next_hop_per_address_family(
2390 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2391 )
2392 input_topo = {"r1": topo["routers"]["r1"]}
2393 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2394 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899 2395
17022899
KK
2396 dut = "r1"
2397 peer = "r2"
17022899
KK
2398 next_hop = next_hop_per_address_family(
2399 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2400 )
2401 input_topo = {"r2": topo["routers"]["r2"]}
b0449478
DS
2402 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2403 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899 2404 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478
DS
2405 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2406
2407 step("Kill BGP on R2")
2408
2409 kill_router_daemons(tgen, "r2", ["bgpd"])
2410
2411 step("Verify that R1 keeps stale entry for BGP routes when BGPd on R2 is down")
17022899 2412
b0449478 2413 for addr_type in ADDR_TYPES:
17022899
KK
2414 dut = "r2"
2415 peer = "r1"
b0449478 2416 protocol = "bgp"
17022899
KK
2417 next_hop = next_hop_per_address_family(
2418 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2419 )
2420 input_topo = {"r1": topo["routers"]["r1"]}
b0449478
DS
2421 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2422 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2423
2424 dut = "r1"
2425 peer = "r2"
2426 next_hop = next_hop_per_address_family(
2427 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2428 )
2429 input_topo = {"r2": topo["routers"]["r2"]}
17022899
KK
2430 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2431 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2432 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 2433 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899
KK
2434
2435 write_test_footer(tc_name)
2436
2437
b0449478 2438def test_BGP_GR_TC_45_p1(request):
17022899 2439 """
b0449478
DS
2440 Test Objective : Transition from Global Restart to Helper
2441 and then Global Helper to Restart.
17022899
KK
2442
2443 """
2444
2445 tgen = get_topogen()
2446 tc_name = request.node.name
2447 write_test_header(tc_name)
2448
2449 # Check router status
2450 check_router_status(tgen)
2451
2452 # Don't run this test if we have any failure.
2453 if tgen.routers_have_failure():
2454 pytest.skip(tgen.errors)
2455
2456 # Creating configuration from JSON
2457 reset_config_on_routers(tgen)
2458
b0449478 2459 step("Configure R1 and R2 as GR restarting node in global level")
17022899
KK
2460
2461 input_dict = {
2462 "r1": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
b0449478 2463 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
17022899
KK
2464 }
2465
2466 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2467
b0449478 2468 step("Verify on R2 that R1 advertises GR capabilities as a restarting node")
17022899
KK
2469
2470 for addr_type in ADDR_TYPES:
2471 result = verify_graceful_restart(
2472 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2473 )
2474 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2475 result = verify_graceful_restart(
2476 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
2477 )
2478 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2479
2480 for addr_type in ADDR_TYPES:
2481 dut = "r1"
2482 peer = "r2"
2483 protocol = "bgp"
2484 next_hop = next_hop_per_address_family(
2485 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2486 )
2487 input_topo = {"r2": topo["routers"]["r2"]}
2488 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2489 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2490
2491 dut = "r2"
2492 peer = "r1"
2493 next_hop = next_hop_per_address_family(
2494 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2495 )
2496 input_topo = {"r1": topo["routers"]["r1"]}
2497 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2498 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2499 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2500 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2501
b0449478 2502 step("Kill BGP on R1")
17022899
KK
2503
2504 kill_router_daemons(tgen, "r1", ["bgpd"])
2505
2506 step(
b0449478
DS
2507 "Verify that R1 keeps BGP routes in zebra and R2"
2508 " retains the stale entry for received routes from R1"
17022899
KK
2509 )
2510
2511 for addr_type in ADDR_TYPES:
2512 dut = "r1"
2513 peer = "r2"
2514 protocol = "bgp"
2515 next_hop = next_hop_per_address_family(
2516 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2517 )
2518 input_topo = {"r2": topo["routers"]["r2"]}
2519 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2520 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2521
2522 dut = "r2"
2523 peer = "r1"
2524 next_hop = next_hop_per_address_family(
2525 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2526 )
2527 input_topo = {"r1": topo["routers"]["r1"]}
2528 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2529 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2530 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2531 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2532
b0449478 2533 step("Bring up BGPd on R1 and remove GR related config in global level")
17022899 2534
b0449478 2535 start_router_daemons(tgen, "r1", ["bgpd"])
17022899 2536
b0449478
DS
2537 input_dict = {
2538 "r1": {
2539 "bgp": {
2540 "graceful-restart": {
2541 "graceful-restart": False,
2542 }
2543 }
2544 }
2545 }
17022899 2546
b0449478 2547 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
17022899 2548
b0449478 2549 step("Verify on R2 that R1 advertises GR capabilities as a helper node")
17022899
KK
2550
2551 input_dict = {
2552 "r1": {
2553 "bgp": {
b0449478
DS
2554 "graceful-restart": {
2555 "graceful-restart-helper": True,
17022899
KK
2556 }
2557 }
2558 },
2559 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
2560 }
2561
17022899
KK
2562 for addr_type in ADDR_TYPES:
2563 result = verify_graceful_restart(
2564 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2565 )
2566 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2567 result = verify_graceful_restart(
2568 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
2569 )
2570 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2571
2572 for addr_type in ADDR_TYPES:
2573 dut = "r2"
2574 peer = "r1"
2575 protocol = "bgp"
2576 next_hop = next_hop_per_address_family(
2577 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2578 )
2579 input_topo = {"r1": topo["routers"]["r1"]}
2580 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478
DS
2581 assert (
2582 result is True
2583 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2584 tc_name, result
2585 )
17022899
KK
2586
2587 dut = "r1"
2588 peer = "r2"
2589 next_hop = next_hop_per_address_family(
2590 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2591 )
2592 input_topo = {"r2": topo["routers"]["r2"]}
2593 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2594 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2595 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478
DS
2596 assert (
2597 result is True
2598 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2599 tc_name, result
2600 )
17022899
KK
2601
2602 step("Kill BGP on R2")
2603
2604 kill_router_daemons(tgen, "r2", ["bgpd"])
2605
b0449478 2606 step("Verify that R1 keeps stale entry for BGP routes when BGPd on R2 is down")
17022899
KK
2607
2608 for addr_type in ADDR_TYPES:
2609 dut = "r2"
2610 peer = "r1"
2611 protocol = "bgp"
2612 next_hop = next_hop_per_address_family(
2613 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
2614 )
2615 input_topo = {"r1": topo["routers"]["r1"]}
2616 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478
DS
2617 assert (
2618 result is True
2619 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2620 tc_name, result
2621 )
17022899
KK
2622
2623 dut = "r1"
2624 peer = "r2"
2625 next_hop = next_hop_per_address_family(
2626 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2627 )
2628 input_topo = {"r2": topo["routers"]["r2"]}
b0449478
DS
2629 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2630 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2631 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2632 assert (
2633 result is True
2634 ), "Testcase {} :Failed \n Routes are still present \n Error {}".format(
2635 tc_name, result
0b25370e 2636 )
17022899 2637
b0449478 2638 step("Bring up BGPd on R2 and configure R1 as GR restarting node in global level")
17022899
KK
2639
2640 start_router_daemons(tgen, "r2", ["bgpd"])
2641
2642 input_dict = {
2643 "r1": {
2644 "bgp": {
b0449478
DS
2645 "graceful-restart": {
2646 "graceful-restart": True,
17022899
KK
2647 }
2648 }
2649 }
2650 }
2651
2652 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2653
b0449478 2654 step("Verify on R2 that R1 advertises GR capabilities as a restarting node")
17022899
KK
2655
2656 input_dict = {
b0449478
DS
2657 "r1": {
2658 "bgp": {
2659 "graceful-restart": {
2660 "graceful-restart": True,
2661 }
2662 }
2663 },
17022899
KK
2664 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
2665 }
2666
2667 for addr_type in ADDR_TYPES:
2668 result = verify_graceful_restart(
2669 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2670 )
2671 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2672 result = verify_graceful_restart(
2673 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
2674 )
2675 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2676
2677 for addr_type in ADDR_TYPES:
b0449478
DS
2678 dut = "r1"
2679 peer = "r2"
17022899
KK
2680 protocol = "bgp"
2681 next_hop = next_hop_per_address_family(
b0449478 2682 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
17022899 2683 )
b0449478 2684 input_topo = {"r2": topo["routers"]["r2"]}
17022899 2685 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 2686 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899 2687
b0449478
DS
2688 dut = "r2"
2689 peer = "r1"
17022899 2690 next_hop = next_hop_per_address_family(
b0449478 2691 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
17022899 2692 )
b0449478 2693 input_topo = {"r1": topo["routers"]["r1"]}
17022899
KK
2694 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2695 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2696 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 2697 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899 2698
b0449478 2699 step("Kill BGP on R1")
17022899 2700
b0449478 2701 kill_router_daemons(tgen, "r1", ["bgpd"])
17022899
KK
2702
2703 step(
b0449478
DS
2704 "Verify that R1 keeps BGP routes in zebra and R2"
2705 " retains the stale entry for received routes from R1"
17022899
KK
2706 )
2707
2708 for addr_type in ADDR_TYPES:
b0449478
DS
2709 dut = "r1"
2710 peer = "r2"
17022899
KK
2711 protocol = "bgp"
2712 next_hop = next_hop_per_address_family(
b0449478 2713 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
17022899 2714 )
b0449478 2715 input_topo = {"r2": topo["routers"]["r2"]}
17022899 2716 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 2717 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
17022899 2718
b0449478
DS
2719 dut = "r2"
2720 peer = "r1"
17022899 2721 next_hop = next_hop_per_address_family(
b0449478 2722 tgen, dut, peer, addr_type, NEXT_HOP_IP_1
17022899 2723 )
b0449478 2724 input_topo = {"r1": topo["routers"]["r1"]}
17022899
KK
2725 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2726 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
2727 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
b0449478 2728 assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result)
35ba1e3d
KK
2729
2730 write_test_footer(tc_name)
2731
2732
2733if __name__ == "__main__":
2734 args = ["-s"] + sys.argv[1:]
2735 sys.exit(pytest.main(args))