]> git.proxmox.com Git - mirror_frr.git/blame - tests/topotests/bgp_gr_functionality_topo1/test_bgp_gr_functionality_topo1.py
Merge pull request #7504 from hohl/master
[mirror_frr.git] / tests / topotests / bgp_gr_functionality_topo1 / test_bgp_gr_functionality_topo1.py
CommitLineData
35ba1e3d
KK
1#!/usr/bin/env python
2#
3# Copyright (c) 2019 by VMware, Inc. ("VMware")
4# Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
5# in this file.
6#
7# Permission to use, copy, modify, and/or distribute this software
8# for any purpose with or without fee is hereby granted, provided
9# that the above copyright notice and this permission notice appear
10# in all copies.
11#
12# THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
13# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
15# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
19# OF THIS SOFTWARE.
20#
21
22"""
23Following tests are covered to test BGP Gracefull Restart functionality.
24Basic Common Test steps for all the test case below :
25- Create topology (setup module)
26 Creating 2 routers topology, r1, r2 in IBGP
27- Bring up topology
28- Verify for bgp to converge
29- Configure BGP Garceful Restart on both the routers.
30
311. Helper BGP router R1, mark and unmark IPV4 routes
32 as stale as the restarting router R2 come up within the restart time.
332. Helper BGP router R1, mark IPV4 routes as stale and
34 deletes them as the restarting router R2 did-not come up within restart
35 time.
363. Restart BGP router R1, detects it is connected to R2,
37 which is a helper router. Verify the restart capability i.e. R bit
38 are sent after R1 reloads and comes back.
394. Verify that the restarting node sets "R" bit while sending the
40 BGP open messages after the node restart, only if GR is enabled.
415. Verify if restarting node resets R bit in BGP open message
42 during normal BGP session flaps as well, even when GR restarting mode is enabled.
43 Here link flap happen due to interface UP/DOWN.
446. Verify if restarting node resets R bit in BGP open message
45 during normal BGP session flaps as well, even when GR restarting mode is enabled.
46 Here link flap happen due to neigh router restarts
477. Verify if restarting node resets R bit in BGP open message
48 during normal BGP session flaps when GR helper mode is enabled.
49 Here link flap happen due to interface UP/DOWN.
508. Verify if restarting node resets R bit in BGP open message
51 during normal BGP session flaps when GR helper mode is enabled.
52 Here link flap happen due to neigh router restarts.
539. Verify that restarting nodes set "F" bit while sending
54 the BGP open messages after it restarts, only when BGP GR is enabled.
5510. Verify that restarting nodes reset "F" bit while sending
56 the BGP open messages after it's restarts, when BGP GR is **NOT** enabled.
5711. Verify that only GR helper routers keep the stale
58 route entries, not any GR disabled router.
5912. Verify that GR helper routers keeps all the routes received
60 from restarting node if both the routers are configured as GR restarting node.
6113. Verify that GR helper routers delete all the routes
62 received from a node if both the routers are configured as GR helper node.
6314. Test Objective : After BGP neighborship is established and GR capability
64 is exchanged, transition helper router to disabled state.
6515.Test Objective : After BGP neighborship is established and GR capability
66 is exchanged, transition disabled router to helper state.
6716. Verify transition from Global Restarting to Disable and then
68 Global Disable to Restarting.
6917. Verify transition from Global Helper to Disable and then Global
70 Disable to Helper.
7118. Verify transition from Global Restart to Helper and then Global
72 Helper to Restart.
7319. Verify transition from Peer-level helper to Global Restarting.
7420. Verify transition from Peer-level restart to Global Restart.
7521. Verify transition from Peer-level disabled to Global Restart.
7622. Verify Peer-level inherit from Global Restarting mode.
7723. Verify transition from Peer-level helper to Global inherit helper.
7824. Verify transition from Peer-level restart to Global inherit helper.
7925. Verify transition from Peer-level disbale to Global inherit helper.
8026. Verify default GR functional mode is Helper.
8127. Verify transition from Peer-level Helper to Global Disable.
8228. Verify transition from Peer-level Restarting to Global Disable.
8329. Verify transition from Peer-level Disable to Global Disable.
8430. Verfiy Peer-level inherit from Global Disable mode.
85
86"""
87
88import os
89import sys
90import json
91import time
92import inspect
93import pytest
94from time import sleep
95
96# Save the Current Working Directory to find configuration files.
97CWD = os.path.dirname(os.path.realpath(__file__))
98sys.path.append(os.path.join("../"))
99sys.path.append(os.path.join("../lib/"))
100
101# pylint: disable=C0413
102# Import topogen and topotest helpers
103from lib import topotest
104from lib.topogen import Topogen, TopoRouter, get_topogen
105from lib.topolog import logger
3dfd384e 106
35ba1e3d
KK
107# Required to instantiate the topology builder class.
108from mininet.topo import Topo
109
110# Import topoJson from lib, to create topology and initial configuration
111from lib.topojson import build_topo_from_json, build_config_from_json
112from lib.bgp import (
113 clear_bgp,
114 verify_bgp_rib,
115 verify_graceful_restart,
116 create_router_bgp,
117 verify_r_bit,
118 verify_f_bit,
119 verify_bgp_convergence,
120 verify_graceful_restart_timers,
121)
122
123from lib.common_config import (
124 write_test_header,
125 reset_config_on_routers,
126 start_topology,
127 kill_router_daemons,
128 start_router_daemons,
129 verify_rib,
130 check_address_types,
131 write_test_footer,
132 check_router_status,
133 shutdown_bringup_interface,
134 step,
135 kill_mininet_routers_process,
136 get_frr_ipv6_linklocal,
137 create_route_maps,
701a0192 138 required_linux_kernel_version,
35ba1e3d
KK
139)
140
141# Reading the data from JSON File for topology and configuration creation
142jsonFile = "{}/bgp_gr_topojson_topo1.json".format(CWD)
143try:
144 with open(jsonFile, "r") as topoJson:
145 topo = json.load(topoJson)
146except IOError:
147 logger.info("Could not read file:", jsonFile)
148
149
150# Global variables
151NEXT_HOP_IP = {"ipv4": "192.168.1.10", "ipv6": "fd00:0:0:1::10"}
152NEXT_HOP_IP_1 = {"ipv4": "192.168.0.1", "ipv6": "fd00::1"}
153NEXT_HOP_IP_2 = {"ipv4": "192.168.0.2", "ipv6": "fd00::2"}
154BGP_CONVERGENCE = False
155GR_RESTART_TIMER = 20
156PREFERRED_NEXT_HOP = "link_local"
157
158
159class GenerateTopo(Topo):
160 """
161 Test topology builder
162
163 * `Topo`: Topology object
164 """
165
166 def build(self, *_args, **_opts):
167 "Build function"
168 tgen = get_topogen(self)
169
170 # This function only purpose is to create topology
171 # as defined in input json file.
172 #
173 # Create topology (setup module)
174 # Creating 2 routers topology, r1, r2in IBGP
175 # Bring up topology
176
177 # Building topology from json file
178 build_topo_from_json(tgen, topo)
179
180
181def setup_module(mod):
182 """
183 Sets up the pytest environment
184
185 * `mod`: module name
186 """
187
188 global ADDR_TYPES
189
3dfd384e 190 # Required linux kernel version for this suite to run.
701a0192 191 result = required_linux_kernel_version("4.15")
955212d9 192 if result is not True:
193 pytest.skip("Kernel requirements are not met")
3dfd384e 194
35ba1e3d
KK
195 testsuite_run_time = time.asctime(time.localtime(time.time()))
196 logger.info("Testsuite start time: {}".format(testsuite_run_time))
197 logger.info("=" * 40)
198
199 logger.info("Running setup_module to create topology")
200
201 # This function initiates the topology build with Topogen...
202 tgen = Topogen(GenerateTopo, mod.__name__)
203 # ... and here it calls Mininet initialization functions.
204
205 # Kill stale mininet routers and process
206 kill_mininet_routers_process(tgen)
207
208 # Starting topology, create tmp files which are loaded to routers
209 # to start deamons and then start routers
210 start_topology(tgen)
211
212 # Creating configuration from JSON
213 build_config_from_json(tgen, topo)
214
215 # Don't run this test if we have any failure.
216 if tgen.routers_have_failure():
217 pytest.skip(tgen.errors)
218
219 # Api call verify whether BGP is converged
220 ADDR_TYPES = check_address_types()
221
222 for addr_type in ADDR_TYPES:
223 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
224 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format(
225 BGP_CONVERGENCE
226 )
227
228 logger.info("Running setup_module() done")
229
230
231def teardown_module(mod):
232 """
233 Teardown the pytest environment
234
235 * `mod`: module name
236 """
237
238 logger.info("Running teardown_module to delete topology")
239
240 tgen = get_topogen()
241
242 # Stop toplogy and Remove tmp files
243 tgen.stop_topology()
244
245 logger.info(
246 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
247 )
248 logger.info("=" * 40)
249
250
251def configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut, peer):
252 """
253 This function groups the repetitive function calls into one function.
254 """
255
256 result = create_router_bgp(tgen, topo, input_dict)
257 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
258
259 for addr_type in ADDR_TYPES:
260 clear_bgp(tgen, addr_type, dut)
261
262 return True
263
264
265def next_hop_per_address_family(
266 tgen, dut, peer, addr_type, next_hop_dict, preferred_next_hop=PREFERRED_NEXT_HOP
267):
268 """
269 This function returns link_local or global next_hop per address-family
270 """
271
272 intferface = topo["routers"][peer]["links"]["{}-link1".format(dut)]["interface"]
273 if addr_type == "ipv6" and "link_local" in preferred_next_hop:
274 next_hop = get_frr_ipv6_linklocal(tgen, peer, intf=intferface)
275 else:
276 next_hop = next_hop_dict[addr_type]
277
278 return next_hop
279
280
281def test_BGP_GR_TC_46_p1(request):
282 """
283 Test Objective : transition from Peer-level helper to Global Restarting
284 Global Mode : GR Restarting
285 PerPeer Mode : GR Helper
286 GR Mode effective : GR Helper
287
288 """
289
290 tgen = get_topogen()
291 tc_name = request.node.name
292 write_test_header(tc_name)
293
294 # Check router status
295 check_router_status(tgen)
296
297 # Don't run this test if we have any failure.
298 if tgen.routers_have_failure():
299 pytest.skip(tgen.errors)
300
301 # Creating configuration from JSON
302 reset_config_on_routers(tgen)
303
304 step(
305 "Configure R1 and R2 as GR restarting node in global"
306 " and helper in per-Peer-level"
307 )
308
309 input_dict = {
310 "r1": {
311 "bgp": {
312 "graceful-restart": {"graceful-restart": True,},
313 "address_family": {
314 "ipv4": {
315 "unicast": {
316 "neighbor": {
317 "r2": {
318 "dest_link": {
319 "r1-link1": {"graceful-restart-helper": True}
320 }
321 }
322 }
323 }
324 },
325 "ipv6": {
326 "unicast": {
327 "neighbor": {
328 "r2": {
329 "dest_link": {
330 "r1-link1": {"graceful-restart-helper": True}
331 }
332 }
333 }
334 }
335 },
336 },
337 }
338 },
339 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
340 }
341
342 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
343
344 step("Verify on R2 that R1 advertises GR capabilities as a restarting node")
345
346 for addr_type in ADDR_TYPES:
347 result = verify_graceful_restart(
348 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
349 )
350 assert result is True, "Testcase {} : Failed \n Error {}".format(
351 tc_name, result
352 )
353
354 step("Kill BGP on R2")
355
356 kill_router_daemons(tgen, "r2", ["bgpd"])
357
358 step(
359 "Verify that R1 keeps the stale entries in RIB & FIB and R2 keeps stale entries in FIB using"
360 )
361
362 for addr_type in ADDR_TYPES:
363 protocol = "bgp"
364 next_hop = next_hop_per_address_family(
365 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
366 )
367 input_topo = {"r1": topo["routers"]["r1"]}
368 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
369 assert result is True, "Testcase {} : Failed \n Error {}".format(
370 tc_name, result
371 )
372
373 for addr_type in ADDR_TYPES:
374 next_hop = next_hop_per_address_family(
375 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
376 )
377 input_topo = {"r2": topo["routers"]["r2"]}
378 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
379 assert result is True, "Testcase {} : Failed \n Error {}".format(
380 tc_name, result
381 )
382
383 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
384 assert result is True, "Testcase {} : Failed \n Error {}".format(
385 tc_name, result
386 )
387
388 step(
389 "Bring up BGP on R1 and remove Peer-level GR config"
390 " from R1 following by a session reset"
391 )
392
393 start_router_daemons(tgen, "r2", ["bgpd"])
394
395 input_dict = {
396 "r1": {
397 "bgp": {
398 "address_family": {
399 "ipv4": {
400 "unicast": {
401 "neighbor": {
402 "r2": {
403 "dest_link": {
404 "r1-link1": {"graceful-restart-helper": False}
405 }
406 }
407 }
408 }
409 },
410 "ipv6": {
411 "unicast": {
412 "neighbor": {
413 "r2": {
414 "dest_link": {
415 "r1-link1": {"graceful-restart-helper": False}
416 }
417 }
418 }
419 }
420 },
421 }
422 }
423 }
424 }
425
426 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
427
428 step("Verify on R2 that R1 advertises GR capabilities as a restarting node")
429
430 input_dict = {
431 "r1": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
432 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
433 }
434
435 for addr_type in ADDR_TYPES:
436 result = verify_graceful_restart(
437 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
438 )
439 assert result is True, "Testcase {} : Failed \n Error {}".format(
440 tc_name, result
441 )
442
443 step("Kill BGP on R1")
444
445 kill_router_daemons(tgen, "r1", ["bgpd"])
446
447 step(
448 "Verify that R1 keeps the stale entries in FIB command and R2 keeps stale entries in RIB & FIB"
449 )
450
451 for addr_type in ADDR_TYPES:
452 protocol = "bgp"
453 next_hop = next_hop_per_address_family(
454 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
455 )
456 input_topo = {"r2": topo["routers"]["r2"]}
457 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
458 assert (
459 result is True
460 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
461 tc_name, result
462 )
463
464 for addr_type in ADDR_TYPES:
465 next_hop = next_hop_per_address_family(
466 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
467 )
468 input_topo = {"r1": topo["routers"]["r1"]}
469 result = verify_bgp_rib(tgen, addr_type, "r2", input_topo, next_hop)
470 assert result is True, "Testcase {} : Failed \n Error {}".format(
471 tc_name, result
472 )
473
474 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
475 assert (
476 result is True
477 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
478 tc_name, result
479 )
480
481 step("Start BGP on R1")
482
483 start_router_daemons(tgen, "r1", ["bgpd"])
484
485 write_test_footer(tc_name)
486
487
488def test_BGP_GR_TC_50_p1(request):
489 """
490 Test Objective : Transition from Peer-level helper to Global inherit helper
491 Global Mode : None
492 PerPeer Mode : Helper
493 GR Mode effective : GR Helper
494
495 """
496
497 tgen = get_topogen()
498 tc_name = request.node.name
499 write_test_header(tc_name)
500
501 # Check router status
502 check_router_status(tgen)
503
504 # Don't run this test if we have any failure.
505 if tgen.routers_have_failure():
506 pytest.skip(tgen.errors)
507
508 # Creating configuration from JSON
509 reset_config_on_routers(tgen)
510
511 step(
512 "Configure R1 as GR helper node at per Peer-level for R2"
513 " and configure R2 as global restarting node."
514 )
515
516 input_dict = {
517 "r1": {
518 "bgp": {
519 "address_family": {
520 "ipv4": {
521 "unicast": {
522 "neighbor": {
523 "r2": {
524 "dest_link": {
525 "r1-link1": {"graceful-restart-helper": True}
526 }
527 }
528 }
529 }
530 },
531 "ipv6": {
532 "unicast": {
533 "neighbor": {
534 "r2": {
535 "dest_link": {
536 "r1-link1": {"graceful-restart-helper": True}
537 }
538 }
539 }
540 }
541 },
542 }
543 }
544 },
545 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
546 }
547
548 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
549
550 step("Verify on R2 that R1 advertises GR capabilities as a helper node")
551
552 for addr_type in ADDR_TYPES:
553 result = verify_graceful_restart(
554 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
555 )
556 assert result is True, "Testcase {} : Failed \n Error {}".format(
557 tc_name, result
558 )
559
560 step("Kill BGP on R2")
561
562 kill_router_daemons(tgen, "r2", ["bgpd"])
563
564 step(
565 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
566 )
567
568 for addr_type in ADDR_TYPES:
569 protocol = "bgp"
570 next_hop = next_hop_per_address_family(
571 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
572 )
573 input_topo = {"r1": topo["routers"]["r1"]}
574 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
575 assert result is True, "Testcase {} : Failed \n Error {}".format(
576 tc_name, result
577 )
578
579 for addr_type in ADDR_TYPES:
580 next_hop = next_hop_per_address_family(
581 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
582 )
583 input_topo = {"r2": topo["routers"]["r2"]}
584 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
585 assert result is True, "Testcase {} : Failed \n Error {}".format(
586 tc_name, result
587 )
588
589 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
590 assert result is True, "Testcase {} : Failed \n Error {}".format(
591 tc_name, result
592 )
593
594 step("Bring up BGP on R2 and remove Peer-level GR config from R1 ")
595
596 start_router_daemons(tgen, "r2", ["bgpd"])
597
598 input_dict = {
599 "r1": {
600 "bgp": {
601 "address_family": {
602 "ipv4": {
603 "unicast": {
604 "neighbor": {
605 "r2": {
606 "dest_link": {
607 "r1-link1": {"graceful-restart-helper": False}
608 }
609 }
610 }
611 }
612 },
613 "ipv6": {
614 "unicast": {
615 "neighbor": {
616 "r2": {
617 "dest_link": {
618 "r1-link1": {"graceful-restart-helper": False}
619 }
620 }
621 }
622 }
623 },
624 }
625 }
626 }
627 }
628
629 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
630
631 step("Verify on R2 that R1 still advertises GR capabilities as a helper node")
632
633 input_dict = {
634 "r1": {"bgp": {"graceful-restart": {"graceful-restart-helper": True}}},
635 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
636 }
637
638 for addr_type in ADDR_TYPES:
639 result = verify_graceful_restart(
640 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
641 )
642 assert result is True, "Testcase {} : Failed \n Error {}".format(
643 tc_name, result
644 )
645
646 step("Kill BGP on R2")
647
648 kill_router_daemons(tgen, "r2", ["bgpd"])
649
650 step(
651 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
652 )
653
654 for addr_type in ADDR_TYPES:
655 protocol = "bgp"
656 next_hop = next_hop_per_address_family(
657 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
658 )
659 input_topo = {"r1": topo["routers"]["r1"]}
660 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
661 assert (
662 result is True
663 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
664 tc_name, result
665 )
666
667 for addr_type in ADDR_TYPES:
668 next_hop = next_hop_per_address_family(
669 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
670 )
671 input_topo = {"r2": topo["routers"]["r2"]}
672 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
673 assert result is True, "Testcase {} : Failed \n Error {}".format(
674 tc_name, result
675 )
676
677 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
678 assert (
679 result is True
680 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
681 tc_name, result
682 )
683
684 step("Start BGP on R2")
685
686 start_router_daemons(tgen, "r2", ["bgpd"])
687
688 write_test_footer(tc_name)
689
690
691def test_BGP_GR_TC_51_p1(request):
692 """
693 Test Objective : Transition from Peer-level restarting to Global inherit helper
694 Global Mode : None
695 PerPeer Mode : GR Restart
696 GR Mode effective : GR Restart
697
698 """
699
700 tgen = get_topogen()
701 tc_name = request.node.name
702 write_test_header(tc_name)
703
704 # Check router status
705 check_router_status(tgen)
706
707 # Don't run this test if we have any failure.
708 if tgen.routers_have_failure():
709 pytest.skip(tgen.errors)
710
711 # Creating configuration from JSON
712 reset_config_on_routers(tgen)
713
714 step("Configure R1 as GR restarting node at per Peer-level for R2")
715
716 input_dict = {
717 "r1": {
718 "bgp": {
719 "address_family": {
720 "ipv4": {
721 "unicast": {
722 "neighbor": {
723 "r2": {
724 "dest_link": {
725 "r1-link1": {"graceful-restart": True}
726 }
727 }
728 }
729 }
730 },
731 "ipv6": {
732 "unicast": {
733 "neighbor": {
734 "r2": {
735 "dest_link": {
736 "r1-link1": {"graceful-restart": True}
737 }
738 }
739 }
740 }
741 },
742 }
743 }
744 },
745 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
746 }
747
748 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
749 step("Verify on R2 that R1 advertises GR capabilities as a restarting node")
750
751 for addr_type in ADDR_TYPES:
752 result = verify_graceful_restart(
753 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
754 )
755 assert result is True, "Testcase {} : Failed \n Error {}".format(
756 tc_name, result
757 )
758
759 step("Kill BGP on R1")
760
761 kill_router_daemons(tgen, "r1", ["bgpd"])
762
763 step(
764 "Verify that R1 keeps the stale entries in FIB & R2 keeps stale entries in RIB & FIB"
765 )
766
767 for addr_type in ADDR_TYPES:
768 protocol = "bgp"
769 next_hop = next_hop_per_address_family(
770 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
771 )
772 input_topo = {"r2": topo["routers"]["r2"]}
773 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
774 assert result is True, "Testcase {} : Failed \n Error {}".format(
775 tc_name, result
776 )
777
778 for addr_type in ADDR_TYPES:
779 next_hop = next_hop_per_address_family(
780 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
781 )
782 input_topo = {"r1": topo["routers"]["r1"]}
783 result = verify_bgp_rib(tgen, addr_type, "r2", input_topo, next_hop)
784 assert result is True, "Testcase {} : Failed \n Error {}".format(
785 tc_name, result
786 )
787
788 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
789 assert result is True, "Testcase {} : Failed \n Error {}".format(
790 tc_name, result
791 )
792
793 step("Bring up BGP on R1 and remove Peer-level GR config")
794
795 start_router_daemons(tgen, "r1", ["bgpd"])
796
797 input_dict = {
798 "r1": {
799 "bgp": {
800 "address_family": {
801 "ipv4": {
802 "unicast": {
803 "neighbor": {
804 "r2": {
805 "dest_link": {
806 "r1-link1": {"graceful-restart": False}
807 }
808 }
809 }
810 }
811 },
812 "ipv6": {
813 "unicast": {
814 "neighbor": {
815 "r2": {
816 "dest_link": {
817 "r1-link1": {"graceful-restart": False}
818 }
819 }
820 }
821 }
822 },
823 }
824 }
825 }
826 }
827
828 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
829
830 step("Verify on R2 that R1 advertises GR capabilities as a helper node")
831
832 input_dict = {
833 "r1": {"bgp": {"graceful-restart": {"graceful-restart-helper": True}}},
834 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
835 }
836
837 for addr_type in ADDR_TYPES:
838 result = verify_graceful_restart(
839 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
840 )
841 assert result is True, "Testcase {} : Failed \n Error {}".format(
842 tc_name, result
843 )
844
845 step("Kill BGPd on R2")
846
847 kill_router_daemons(tgen, "r2", ["bgpd"])
848
849 step(
850 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
851 )
852
853 for addr_type in ADDR_TYPES:
854 protocol = "bgp"
855 next_hop = next_hop_per_address_family(
856 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
857 )
858 input_topo = {"r1": topo["routers"]["r1"]}
859 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
860 assert (
861 result is True
862 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
863 tc_name, result
864 )
865
866 for addr_type in ADDR_TYPES:
867 next_hop = next_hop_per_address_family(
868 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
869 )
870 input_topo = {"r2": topo["routers"]["r2"]}
871 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
872 assert result is True, "Testcase {} : Failed \n Error {}".format(
873 tc_name, result
874 )
875
876 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
877 assert (
878 result is True
879 ), "Testcase {} : Failed \n Routes are still present \n Error {}".format(
880 tc_name, result
881 )
882
883 step("Start BGP on R2")
884
885 start_router_daemons(tgen, "r2", ["bgpd"])
886
887 write_test_footer(tc_name)
888
889
890def test_BGP_GR_TC_53_p1(request):
891 """
892 Test Objective : Default GR functional mode is Helper.
893 Global Mode : None
894 PerPeer Mode : None
895 GR Mode effective : GR Helper
896
897 """
898
899 tgen = get_topogen()
900 tc_name = request.node.name
901 write_test_header(tc_name)
902
903 # Check router status
904 check_router_status(tgen)
905
906 # Don't run this test if we have any failure.
907 if tgen.routers_have_failure():
908 pytest.skip(tgen.errors)
909
910 # Creating configuration from JSON
911 reset_config_on_routers(tgen)
912
913 step("configure R2 as global restarting node")
914
915 input_dict = {"r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}}
916
917 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
918
919 step(
920 "Verify on R2 that R1 advertises GR capabilities as a helper node based on inherit"
921 )
922
923 input_dict = {
924 "r1": {"bgp": {"graceful-restart": {"graceful-restart-helper": True}}},
925 "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}},
926 }
927
928 for addr_type in ADDR_TYPES:
929 result = verify_graceful_restart(
930 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
931 )
932 assert result is True, "Testcase {} : Failed \n Error {}".format(
933 tc_name, result
934 )
935
936 step("Kill BGPd on R2")
937
938 kill_router_daemons(tgen, "r2", ["bgpd"])
939
940 step(
941 "Verify that R2 keeps the stale entries in FIB & R1 keeps stale entries in RIB & FIB"
942 )
943
944 for addr_type in ADDR_TYPES:
945 protocol = "bgp"
946 next_hop = next_hop_per_address_family(
947 tgen, "r2", "r1", addr_type, NEXT_HOP_IP_1
948 )
949 input_topo = {"r1": topo["routers"]["r1"]}
950 result = verify_rib(tgen, addr_type, "r2", input_topo, next_hop, protocol)
951 assert result is True, "Testcase {} : Failed \n Error {}".format(
952 tc_name, result
953 )
954
955 for addr_type in ADDR_TYPES:
956 next_hop = next_hop_per_address_family(
957 tgen, "r1", "r2", addr_type, NEXT_HOP_IP_2
958 )
959 input_topo = {"r2": topo["routers"]["r2"]}
960 result = verify_bgp_rib(tgen, addr_type, "r1", input_topo, next_hop)
961 assert result is True, "Testcase {} : Failed \n Error {}".format(
962 tc_name, result
963 )
964
965 result = verify_rib(tgen, addr_type, "r1", input_topo, next_hop, protocol)
966 assert result is True, "Testcase {} : Failed \n Error {}".format(
967 tc_name, result
968 )
969
970 step("Start BGP on R2")
971
972 start_router_daemons(tgen, "r2", ["bgpd"])
973
974 write_test_footer(tc_name)
975
976
977def test_BGP_GR_UTP_1_3_p0(request):
978 """
979 Test Objective : Helper BGP router R1, mark and unmark IPV4 routes
980 as stale as the restarting router R2 come up within the restart time
981
982 Test Objective : Helper BGP router R1, mark IPV4 routes as stale and
983 deletes them as the restarting router R2 did-not come up within
984 restart time.
985 """
986
987 tgen = get_topogen()
988 tc_name = request.node.name
989 write_test_header(tc_name)
990
991 # Don't run this test if we have any failure.
992 if tgen.routers_have_failure():
993 pytest.skip(tgen.errors)
994
995 # Create route-map to prefer global next-hop
996 input_dict = {
997 "r1": {
998 "route_maps": {
999 "rmap_global": [
1000 {"action": "permit", "set": {"ipv6": {"nexthop": "prefer-global"}}}
1001 ]
1002 }
1003 },
1004 "r2": {
1005 "route_maps": {
1006 "rmap_global": [
1007 {"action": "permit", "set": {"ipv6": {"nexthop": "prefer-global"}}}
1008 ]
1009 }
1010 },
1011 }
1012 result = create_route_maps(tgen, input_dict)
1013 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1014
1015 # Configure neighbor for route map
1016 input_dict_1 = {
1017 "r1": {
1018 "bgp": {
1019 "address_family": {
1020 "ipv6": {
1021 "unicast": {
1022 "neighbor": {
1023 "r2": {
1024 "dest_link": {
1025 "r1-link1": {
1026 "route_maps": [
1027 {
1028 "name": "rmap_global",
1029 "direction": "in",
1030 }
1031 ]
1032 }
1033 }
1034 }
1035 }
1036 }
1037 }
1038 }
1039 }
1040 },
1041 "r2": {
1042 "bgp": {
1043 "address_family": {
1044 "ipv6": {
1045 "unicast": {
1046 "neighbor": {
1047 "r1": {
1048 "dest_link": {
1049 "r2-link1": {
1050 "route_maps": [
1051 {
1052 "name": "rmap_global",
1053 "direction": "in",
1054 }
1055 ]
1056 }
1057 }
1058 }
1059 }
1060 }
1061 }
1062 }
1063 }
1064 },
1065 }
1066
1067 result = create_router_bgp(tgen, topo, input_dict_1)
1068 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1069
1070 # Configure graceful-restart
1071 input_dict = {
1072 "r1": {
1073 "bgp": {
1074 "address_family": {
1075 "ipv4": {
1076 "unicast": {
1077 "neighbor": {
1078 "r2": {
1079 "dest_link": {
1080 "r1-link1": {"graceful-restart-helper": True}
1081 }
1082 }
1083 }
1084 }
1085 },
1086 "ipv6": {
1087 "unicast": {
1088 "neighbor": {
1089 "r2": {
1090 "dest_link": {
1091 "r1-link1": {"graceful-restart-helper": True}
1092 }
1093 }
1094 }
1095 }
1096 },
1097 }
1098 }
1099 },
1100 "r2": {
1101 "bgp": {
1102 "graceful-restart": {"timer": {"restart-time": GR_RESTART_TIMER}},
1103 "address_family": {
1104 "ipv4": {
1105 "unicast": {
1106 "neighbor": {
1107 "r1": {
1108 "dest_link": {
1109 "r2-link1": {"graceful-restart": True}
1110 }
1111 }
1112 }
1113 }
1114 },
1115 "ipv6": {
1116 "unicast": {
1117 "neighbor": {
1118 "r1": {
1119 "dest_link": {
1120 "r2-link1": {"graceful-restart": True}
1121 }
1122 }
1123 }
1124 }
1125 },
1126 },
1127 }
1128 },
1129 }
1130
1131 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r2", peer="r1")
1132
1133 for addr_type in ADDR_TYPES:
1134 result = verify_graceful_restart(
1135 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
1136 )
1137 assert result is True, "Testcase {} : Failed \n Error {}".format(
1138 tc_name, result
1139 )
1140
1141 # Verifying BGP RIB routes
1142 dut = "r1"
1143 peer = "r2"
1144 next_hop = next_hop_per_address_family(
1145 tgen, dut, peer, addr_type, NEXT_HOP_IP_2, preferred_next_hop="global"
1146 )
1147 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1148 result = verify_bgp_rib(tgen, addr_type, dut, input_topo)
1149 assert result is True, "Testcase {} : Failed \n Error {}".format(
1150 tc_name, result
1151 )
1152
1153 # Verifying RIB routes
1154 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, "bgp")
1155 assert result is True, "Testcase {} : Failed \n Error {}".format(
1156 tc_name, result
1157 )
1158
1159 logger.info("[Phase 2] : R2 goes for reload ")
1160
1161 kill_router_daemons(tgen, "r2", ["bgpd"])
1162
1163 logger.info(
1164 "[Phase 3] : R2 is still down, restart time 120 sec."
1165 " So time verify the routes are present in BGP RIB"
1166 " and ZEBRA"
1167 )
1168
1169 for addr_type in ADDR_TYPES:
1170 # Verifying BGP RIB routes
1171 next_hop = next_hop_per_address_family(
1172 tgen, dut, peer, addr_type, NEXT_HOP_IP_2, preferred_next_hop="global"
1173 )
1174 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1175 assert result is True, "Testcase {} : Failed \n Error {}".format(
1176 tc_name, result
1177 )
1178
1179 # Verifying RIB routes
1180 protocol = "bgp"
1181 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1182 assert result is True, "Testcase {} : Failed \n Error {}".format(
1183 tc_name, result
1184 )
1185
1186 logger.info("[Phase 4] : sleep for {} sec".format(GR_RESTART_TIMER))
1187 sleep(GR_RESTART_TIMER)
1188
1189 logger.info("[Phase 5] : Verify the routes from r2 ")
1190
1191 for addr_type in ADDR_TYPES:
1192 # Verifying BGP RIB routes
1193 next_hop = NEXT_HOP_IP_2[addr_type]
1194 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1195 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, expected=False)
1196 assert result is not True, "Testcase {} : Failed \n Error {}".format(
1197 tc_name, result
1198 )
1199 logger.info(" Expected behavior: {}".format(result))
1200
1201 # Verifying RIB routes
1202 result = verify_rib(
1203 tgen, addr_type, dut, input_topo, next_hop, "bgp", expected=False
1204 )
1205 assert result is not True, "Testcase {} : Failed \n Error {}".format(
1206 tc_name, result
1207 )
1208 logger.info(" Expected behavior: {}".format(result))
1209
1210 logger.info("[Phase 5] : R2 is about to come up now ")
1211 start_router_daemons(tgen, "r2", ["bgpd"])
1212
1213 logger.info("[Phase 5] : R2 is UP Now ! ")
1214
1215 for addr_type in ADDR_TYPES:
1216 # Verifying GR stats
1217 result = verify_graceful_restart(
1218 tgen, topo, addr_type, input_dict, dut="r2", peer="r1"
1219 )
1220 assert result is True, "Testcase {} : Failed \n Error {}".format(
1221 tc_name, result
1222 )
1223
1224 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r1", peer="r2")
1225 assert result is True, "Testcase {} : Failed \n Error {}".format(
1226 tc_name, result
1227 )
1228
1229 # Verifying BGP RIB routes
1230 next_hop = next_hop_per_address_family(
1231 tgen, dut, peer, addr_type, NEXT_HOP_IP_2, preferred_next_hop="global"
1232 )
1233 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1234 assert result is True, "Testcase {} : Failed \n Error {}".format(
1235 tc_name, result
1236 )
1237
1238 # Verifying RIB routes
1239 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1240 assert result is True, "Testcase {} : Failed \n Error {}".format(
1241 tc_name, result
1242 )
1243
1244 write_test_footer(tc_name)
1245
1246
1247def test_BGP_GR_UTP_15_TC_9_p1(request):
1248 """
1249 Test Objective : Restart BGP router R1, detects it is connected to R2,
1250 which is a helper router. Verify the restart capability i.e. R bit
1251 are sent after R1 reloads and comes back.
1252
1253 Test Objective : Verify that restarting nodes reset "F" bit while sending
1254 the BGP open messages after it's restarts, when BGP GR is **NOT** enabled.
1255 """
1256
1257 tgen = get_topogen()
1258 tc_name = request.node.name
1259 write_test_header(tc_name)
1260
1261 # Checking router status, starting if not running
1262 check_router_status(tgen)
1263
1264 # Don't run this test if we have any failure.
1265 if tgen.routers_have_failure():
1266 pytest.skip(tgen.errors)
1267
1268 # Creating configuration from JSON
1269 # reset_config_on_routers(tgen)
1270
1271 # Create route-map to prefer global next-hop
1272 input_dict = {
1273 "r1": {
1274 "route_maps": {
1275 "rmap_global": [
1276 {"action": "permit", "set": {"ipv6": {"nexthop": "prefer-global"}}}
1277 ]
1278 }
1279 },
1280 "r2": {
1281 "route_maps": {
1282 "rmap_global": [
1283 {"action": "permit", "set": {"ipv6": {"nexthop": "prefer-global"}}}
1284 ]
1285 }
1286 },
1287 }
1288 result = create_route_maps(tgen, input_dict)
1289 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1290
1291 # Configure neighbor for route map
1292 input_dict_1 = {
1293 "r1": {
1294 "bgp": {
1295 "address_family": {
1296 "ipv6": {
1297 "unicast": {
1298 "neighbor": {
1299 "r2": {
1300 "dest_link": {
1301 "r1-link1": {
1302 "route_maps": [
1303 {
1304 "name": "rmap_global",
1305 "direction": "in",
1306 }
1307 ]
1308 }
1309 }
1310 }
1311 }
1312 }
1313 }
1314 }
1315 }
1316 },
1317 "r2": {
1318 "bgp": {
1319 "address_family": {
1320 "ipv6": {
1321 "unicast": {
1322 "neighbor": {
1323 "r1": {
1324 "dest_link": {
1325 "r2-link1": {
1326 "route_maps": [
1327 {
1328 "name": "rmap_global",
1329 "direction": "in",
1330 }
1331 ]
1332 }
1333 }
1334 }
1335 }
1336 }
1337 }
1338 }
1339 }
1340 },
1341 }
1342
1343 result = create_router_bgp(tgen, topo, input_dict_1)
1344 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1345
1346 logger.info(
1347 "[Phase 1] : Test Setup " "[Helper Mode]R1-----R2[Restart Mode] initialized "
1348 )
1349
1350 # Configure graceful-restart
1351 input_dict = {
1352 "r1": {
1353 "bgp": {
1354 "address_family": {
1355 "ipv4": {
1356 "unicast": {
1357 "neighbor": {
1358 "r2": {
1359 "dest_link": {
1360 "r1-link1": {"graceful-restart": True}
1361 }
1362 }
1363 }
1364 }
1365 },
1366 "ipv6": {
1367 "unicast": {
1368 "neighbor": {
1369 "r2": {
1370 "dest_link": {
1371 "r1-link1": {"graceful-restart": True}
1372 }
1373 }
1374 }
1375 }
1376 },
1377 }
1378 }
1379 },
1380 "r2": {
1381 "bgp": {
1382 "address_family": {
1383 "ipv4": {
1384 "unicast": {
1385 "neighbor": {
1386 "r1": {
1387 "dest_link": {
1388 "r2-link1": {"graceful-restart-helper": True}
1389 }
1390 }
1391 }
1392 }
1393 },
1394 "ipv6": {
1395 "unicast": {
1396 "neighbor": {
1397 "r1": {
1398 "dest_link": {
1399 "r2-link1": {"graceful-restart-helper": True}
1400 }
1401 }
1402 }
1403 }
1404 },
1405 }
1406 }
1407 },
1408 }
1409
1410 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
1411
1412 for addr_type in ADDR_TYPES:
1413 result = verify_graceful_restart(
1414 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1415 )
1416 assert result is True, "Testcase {} : Failed \n Error {}".format(
1417 tc_name, result
1418 )
1419
1420 # Verifying BGP RIB routes
1421 dut = "r1"
1422 peer = "r2"
1423 next_hop = next_hop_per_address_family(
1424 tgen, dut, peer, addr_type, NEXT_HOP_IP_2, preferred_next_hop="global"
1425 )
1426 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1427 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1428 assert result is True, "Testcase {} : Failed \n Error {}".format(
1429 tc_name, result
1430 )
1431
1432 # Verifying RIB routes
1433 protocol = "bgp"
1434 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1435 assert result is True, "Testcase {} : Failed \n Error {}".format(
1436 tc_name, result
1437 )
1438
1439 logger.info("[Phase 2] : R1 goes for reload ")
1440
1441 kill_router_daemons(tgen, "r1", ["bgpd"])
1442
1443 logger.info("[Phase 6] : R1 is about to come up now ")
1444 start_router_daemons(tgen, "r1", ["bgpd"])
1445
1446 for addr_type in ADDR_TYPES:
1447 # Verifying GR stats
1448 result = verify_graceful_restart(
1449 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1450 )
1451 assert result is True, "Testcase {} : Failed \n Error {}".format(
1452 tc_name, result
1453 )
1454
1455 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r2", peer="r1")
1456 assert result is True, "Testcase {} : Failed \n Error {}".format(
1457 tc_name, result
1458 )
1459
1460 # Verifying BGP RIB routes
1461 next_hop = next_hop_per_address_family(
1462 tgen, dut, peer, addr_type, NEXT_HOP_IP_2, preferred_next_hop="global"
1463 )
1464 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1465 assert result is True, "Testcase {} : Failed \n Error {}".format(
1466 tc_name, result
1467 )
1468
1469 # Verifying RIB routes
1470 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1471 assert result is True, "Testcase {} : Failed \n Error {}".format(
1472 tc_name, result
1473 )
1474
1475 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r1", peer="r2")
1476 assert result is True, "Testcase {} : Failed \n Error {}".format(
1477 tc_name, result
1478 )
1479
1480 result = verify_f_bit(
1481 tgen, topo, addr_type, input_dict, dut="r1", peer="r2", expected=False
1482 )
1483 assert result is not True, "Testcase {} : Failed \n Error {}".format(
1484 tc_name, result
1485 )
1486
1487 write_test_footer(tc_name)
1488
1489
1490def test_BGP_GR_UTP_35_p1(request):
1491 """
1492 Test Objective : Restart BGP router R1 connected to R2,
1493 which is a restart router.
1494 R1 should not send any GR capability in the open message,
1495 however it would process open message from R2 with GR -restart
1496 capability, but would not perform any BGP GR functionality.
1497 """
1498
1499 tgen = get_topogen()
1500 tc_name = request.node.name
1501 write_test_header(tc_name)
1502
1503 # Check router status
1504 check_router_status(tgen)
1505
1506 # Don't run this test if we have any failure.
1507 if tgen.routers_have_failure():
1508 pytest.skip(tgen.errors)
1509
1510 # Creating configuration from JSON
1511 reset_config_on_routers(tgen)
1512
1513 logger.info(
1514 "[Phase 1] : Test Setup" " [Disable Mode]R1-----R2[Restart Mode] initialized "
1515 )
1516
1517 # Configure graceful-restart
1518 input_dict = {
1519 "r1": {
1520 "bgp": {
1521 "address_family": {
1522 "ipv4": {
1523 "unicast": {
1524 "neighbor": {
1525 "r2": {
1526 "dest_link": {
1527 "r1-link1": {"graceful-restart-disable": True}
1528 }
1529 }
1530 }
1531 }
1532 },
1533 "ipv6": {
1534 "unicast": {
1535 "neighbor": {
1536 "r2": {
1537 "dest_link": {
1538 "r1-link1": {"graceful-restart-disable": True}
1539 }
1540 }
1541 }
1542 }
1543 },
1544 }
1545 }
1546 },
1547 "r2": {
1548 "bgp": {
1549 "address_family": {
1550 "ipv4": {
1551 "unicast": {
1552 "neighbor": {
1553 "r1": {
1554 "dest_link": {
1555 "r2-link1": {"graceful-restart": True}
1556 }
1557 }
1558 }
1559 }
1560 },
1561 "ipv6": {
1562 "unicast": {
1563 "neighbor": {
1564 "r1": {
1565 "dest_link": {
1566 "r2-link1": {"graceful-restart": True}
1567 }
1568 }
1569 }
1570 }
1571 },
1572 }
1573 }
1574 },
1575 }
1576
1577 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
1578
1579 for addr_type in ADDR_TYPES:
1580 result = verify_graceful_restart(
1581 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1582 )
1583 assert result is True, "Testcase {} : Failed \n Error {}".format(
1584 tc_name, result
1585 )
1586
1587 # Verifying BGP RIB routes
1588 dut = "r1"
1589 peer = "r2"
1590 next_hop = next_hop_per_address_family(
1591 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1592 )
1593 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1594 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1595 assert result is True, "Testcase {} : Failed \n Error {}".format(
1596 tc_name, result
1597 )
1598
1599 # Verifying RIB routes
1600 protocol = "bgp"
1601 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1602 assert result is True, "Testcase {} : Failed \n Error {}".format(
1603 tc_name, result
1604 )
1605
1606 logger.info("[Phase 2] : R1 goes for reload ")
1607
1608 kill_router_daemons(tgen, "r1", ["bgpd"])
1609
1610 logger.info("[Phase 3] : R1 is about to come up now ")
1611 start_router_daemons(tgen, "r1", ["bgpd"])
1612
1613 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
1614
1615 for addr_type in ADDR_TYPES:
1616 result = verify_graceful_restart(
1617 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1618 )
1619 assert result is True, "Testcase {} : Failed \n Error {}".format(
1620 tc_name, result
1621 )
1622
1623 # Verifying BGP RIB routes
1624 next_hop = next_hop_per_address_family(
1625 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1626 )
1627 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1628 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1629 assert result is True, "Testcase {} : Failed \n Error {}".format(
1630 tc_name, result
1631 )
1632
1633 # Verifying RIB routes
1634 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1635 assert result is True, "Testcase {} : Failed \n Error {}".format(
1636 tc_name, result
1637 )
1638
1639 write_test_footer(tc_name)
1640
1641
1642def test_BGP_GR_TC_4_p0(request):
1643 """
1644 Test Objective : Verify that the restarting node sets "R" bit while sending the
1645 BGP open messages after the node restart, only if GR is enabled.
1646 """
1647
1648 tgen = get_topogen()
1649 tc_name = request.node.name
1650 write_test_header(tc_name)
1651
1652 # Check router status
1653 check_router_status(tgen)
1654
1655 # Don't run this test if we have any failure.
1656 if tgen.routers_have_failure():
1657 pytest.skip(tgen.errors)
1658
1659 # Creating configuration from JSON
1660 reset_config_on_routers(tgen)
1661
1662 logger.info(
1663 "[Phase 1] : Test Setup" " [Restart Mode]R1-----R2[Helper Mode] initialized "
1664 )
1665
1666 # Configure graceful-restart
1667 input_dict = {
1668 "r1": {
1669 "bgp": {
1670 "address_family": {
1671 "ipv4": {
1672 "unicast": {
1673 "neighbor": {
1674 "r2": {
1675 "dest_link": {
1676 "r1-link1": {"graceful-restart": True}
1677 }
1678 }
1679 }
1680 }
1681 },
1682 "ipv6": {
1683 "unicast": {
1684 "neighbor": {
1685 "r2": {
1686 "dest_link": {
1687 "r1-link1": {"graceful-restart": True}
1688 }
1689 }
1690 }
1691 }
1692 },
1693 }
1694 }
1695 },
1696 "r2": {
1697 "bgp": {
1698 "address_family": {
1699 "ipv4": {
1700 "unicast": {
1701 "neighbor": {
1702 "r1": {
1703 "dest_link": {
1704 "r2-link1": {"graceful-restart-helper": True}
1705 }
1706 }
1707 }
1708 }
1709 },
1710 "ipv6": {
1711 "unicast": {
1712 "neighbor": {
1713 "r1": {
1714 "dest_link": {
1715 "r2-link1": {"graceful-restart-helper": True}
1716 }
1717 }
1718 }
1719 }
1720 },
1721 }
1722 }
1723 },
1724 }
1725
1726 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
1727
1728 for addr_type in ADDR_TYPES:
1729 result = verify_graceful_restart(
1730 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1731 )
1732 assert result is True, "Testcase {} : Failed \n Error {}".format(
1733 tc_name, result
1734 )
1735
1736 # Verifying BGP RIB routes
1737 dut = "r1"
1738 peer = "r2"
1739 next_hop = next_hop_per_address_family(
1740 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1741 )
1742 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1743 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1744 assert result is True, "Testcase {} : Failed \n Error {}".format(
1745 tc_name, result
1746 )
1747
1748 # Verifying RIB routes
1749 protocol = "bgp"
1750 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1751 assert result is True, "Testcase {} : Failed \n Error {}".format(
1752 tc_name, result
1753 )
1754
1755 logger.info("[Phase 2] : R2 goes for reload ")
1756
1757 kill_router_daemons(tgen, "r2", ["bgpd"])
1758
1759 logger.info(
1760 "[Phase 3] : R2 is still down, restart time {} sec."
1761 "So time verify the routes are present in BGP RIB and ZEBRA ".format(
1762 GR_RESTART_TIMER
1763 )
1764 )
1765
1766 for addr_type in ADDR_TYPES:
1767 # Verifying BGP RIB routes
1768 next_hop = next_hop_per_address_family(
1769 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1770 )
1771 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1772 result = verify_bgp_rib(
1773 tgen, addr_type, dut, input_topo, next_hop, expected=False
1774 )
1775 assert result is not True, "Testcase {} : Failed \n Error {}".format(
1776 tc_name, result
1777 )
1778 logger.info(" Expected behavior: {}".format(result))
1779
1780 # Verifying RIB routes
1781 result = verify_rib(
1782 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
1783 )
1784 assert result is not True, "Testcase {} : Failed \n Error {}".format(
1785 tc_name, result
1786 )
1787 logger.info(" Expected behavior: {}".format(result))
1788
1789 logger.info("[Phase 5] : R2 is about to come up now ")
1790 start_router_daemons(tgen, "r2", ["bgpd"])
1791
1792 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
1793
1794 for addr_type in ADDR_TYPES:
1795 result = verify_graceful_restart(
1796 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1797 )
1798 assert result is True, "Testcase {} : Failed \n Error {}".format(
1799 tc_name, result
1800 )
1801
1802 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r1", peer="r2")
1803 assert result is True, "Testcase {} : Failed \n Error {}".format(
1804 tc_name, result
1805 )
1806
1807 # Verifying BGP RIB routes
1808 next_hop = next_hop_per_address_family(
1809 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1810 )
1811 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1812 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1813 assert result is True, "Testcase {} : Failed \n Error {}".format(
1814 tc_name, result
1815 )
1816
1817 # Verifying RIB routes
1818 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1819 assert result is True, "Testcase {} : Failed \n Error {}".format(
1820 tc_name, result
1821 )
1822
1823 write_test_footer(tc_name)
1824
1825
1826def test_BGP_GR_TC_5_1_2_p1(request):
1827 """
1828 Test Objective : Verify if restarting node resets R bit in BGP open message
1829 during normal BGP session flaps as well, even when GR restarting mode is enabled.
1830 Here link flap happen due to interface UP/DOWN.
1831
1832 """
1833 tgen = get_topogen()
1834 tc_name = request.node.name
1835 write_test_header(tc_name)
1836
1837 # Check router status
1838 check_router_status(tgen)
1839
1840 # Don't run this test if we have any failure.
1841 if tgen.routers_have_failure():
1842 pytest.skip(tgen.errors)
1843
1844 # Creating configuration from JSON
1845 reset_config_on_routers(tgen)
1846
1847 logger.info(
1848 "[Phase 1] : Test Setup" " [Restart Mode]R1-----R2[Restart Mode] initialized "
1849 )
1850
1851 # Configure graceful-restart
1852 input_dict = {
1853 "r1": {
1854 "bgp": {
1855 "address_family": {
1856 "ipv4": {
1857 "unicast": {
1858 "neighbor": {
1859 "r2": {
1860 "dest_link": {
1861 "r1-link1": {"graceful-restart": True}
1862 }
1863 }
1864 }
1865 }
1866 },
1867 "ipv6": {
1868 "unicast": {
1869 "neighbor": {
1870 "r2": {
1871 "dest_link": {
1872 "r1-link1": {"graceful-restart": True}
1873 }
1874 }
1875 }
1876 }
1877 },
1878 }
1879 }
1880 },
1881 "r2": {
1882 "bgp": {
1883 "address_family": {
1884 "ipv4": {
1885 "unicast": {
1886 "neighbor": {
1887 "r1": {
1888 "dest_link": {
1889 "r2-link1": {"graceful-restart": True}
1890 }
1891 }
1892 }
1893 }
1894 },
1895 "ipv6": {
1896 "unicast": {
1897 "neighbor": {
1898 "r1": {
1899 "dest_link": {
1900 "r2-link1": {"graceful-restart": True}
1901 }
1902 }
1903 }
1904 }
1905 },
1906 }
1907 }
1908 },
1909 }
1910
1911 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
1912
1913 for addr_type in ADDR_TYPES:
1914 result = verify_graceful_restart(
1915 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1916 )
1917 assert result is True, "Testcase {} : Failed \n Error {}".format(
1918 tc_name, result
1919 )
1920
1921 # Verifying BGP RIB routes
1922 dut = "r1"
1923 peer = "r2"
1924 next_hop = next_hop_per_address_family(
1925 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1926 )
1927 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1928 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1929 assert result is True, "Testcase {} : Failed \n Error {}".format(
1930 tc_name, result
1931 )
1932
1933 # Verifying RIB routes
1934 protocol = "bgp"
1935 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1936 assert result is True, "Testcase {} : Failed \n Error {}".format(
1937 tc_name, result
1938 )
1939
1940 logger.info("[Phase 2] : Now flap the link running the BGP session ")
1941 # Shutdown interface
1942 intf = "r2-r1-eth0"
1943 shutdown_bringup_interface(tgen, "r2", intf)
1944
1945 # Bring up Interface
1946 shutdown_bringup_interface(tgen, dut, intf, ifaceaction=True)
1947
1948 for addr_type in ADDR_TYPES:
1949 result = verify_graceful_restart(
1950 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1951 )
1952 assert result is True, "Testcase {} : Failed \n Error {}".format(
1953 tc_name, result
1954 )
1955
1956 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r1", peer="r2")
1957 assert result is True, "Testcase {} : Failed \n Error {}".format(
1958 tc_name, result
1959 )
1960
1961 logger.info("[Phase 2] : Restart BGPd on router R2. ")
1962 kill_router_daemons(tgen, "r2", ["bgpd"])
1963
1964 start_router_daemons(tgen, "r2", ["bgpd"])
1965
1966 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
1967
1968 for addr_type in ADDR_TYPES:
1969 result = verify_graceful_restart(
1970 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
1971 )
1972 assert result is True, "Testcase {} : Failed \n Error {}".format(
1973 tc_name, result
1974 )
1975
1976 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r1", peer="r2")
1977 assert result is True, "Testcase {} : Failed \n Error {}".format(
1978 tc_name, result
1979 )
1980
1981 # Verifying BGP RIB routes
1982 next_hop = next_hop_per_address_family(
1983 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
1984 )
1985 input_topo = {key: topo["routers"][key] for key in ["r2"]}
1986 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
1987 assert result is True, "Testcase {} : Failed \n Error {}".format(
1988 tc_name, result
1989 )
1990
1991 # Verifying RIB routes
1992 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
1993 assert result is True, "Testcase {} : Failed \n Error {}".format(
1994 tc_name, result
1995 )
1996
1997 write_test_footer(tc_name)
1998
1999
2000def test_BGP_GR_TC_6_1_2_p1(request):
2001 """
2002 Test Objective : Verify if restarting node resets R bit in BGP
2003 open message during normal BGP session flaps when GR is disabled.
2004 """
2005
2006 tgen = get_topogen()
2007 tc_name = request.node.name
2008 write_test_header(tc_name)
2009
2010 # Check router status
2011 check_router_status(tgen)
2012
2013 # Don't run this test if we have any failure.
2014 if tgen.routers_have_failure():
2015 pytest.skip(tgen.errors)
2016
2017 # Creating configuration from JSON
2018 reset_config_on_routers(tgen)
2019
2020 logger.info(
2021 "[Phase 1] : Test Setup" "[Restart Mode]R1-----R2[Helper Mode] initialized "
2022 )
2023
2024 # Configure graceful-restart
2025 input_dict = {
2026 "r1": {
2027 "bgp": {
2028 "address_family": {
2029 "ipv4": {
2030 "unicast": {
2031 "neighbor": {
2032 "r2": {
2033 "dest_link": {
2034 "r1-link1": {"graceful-restart": True}
2035 }
2036 }
2037 }
2038 }
2039 },
2040 "ipv6": {
2041 "unicast": {
2042 "neighbor": {
2043 "r2": {
2044 "dest_link": {
2045 "r1-link1": {"graceful-restart": True}
2046 }
2047 }
2048 }
2049 }
2050 },
2051 }
2052 }
2053 },
2054 "r2": {
2055 "bgp": {
2056 "address_family": {
2057 "ipv4": {
2058 "unicast": {
2059 "neighbor": {
2060 "r1": {
2061 "dest_link": {
2062 "r2-link1": {"graceful-restart-helper": True}
2063 }
2064 }
2065 }
2066 }
2067 },
2068 "ipv6": {
2069 "unicast": {
2070 "neighbor": {
2071 "r1": {
2072 "dest_link": {
2073 "r2-link1": {"graceful-restart-helper": True}
2074 }
2075 }
2076 }
2077 }
2078 },
2079 }
2080 }
2081 },
2082 }
2083
2084 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2085
2086 for addr_type in ADDR_TYPES:
2087 result = verify_graceful_restart(
2088 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2089 )
2090 assert result is True, "Testcase {} : Failed \n Error {}".format(
2091 tc_name, result
2092 )
2093
2094 # Verifying BGP RIB routes
2095 dut = "r1"
2096 peer = "r2"
2097 next_hop = next_hop_per_address_family(
2098 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2099 )
2100 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2101 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2102 assert result is True, "Testcase {} : Failed \n Error {}".format(
2103 tc_name, result
2104 )
2105
2106 # Verifying RIB routes
2107 protocol = "bgp"
2108 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2109 assert result is True, "Testcase {} : Failed \n Error {}".format(
2110 tc_name, result
2111 )
2112
2113 logger.info("[Phase 1] : Changing mode" "[Disable Mode]R1-----R2[Helper Mode]")
2114
2115 # Configure graceful-restart
2116 input_dict = {
2117 "r1": {
2118 "bgp": {
2119 "address_family": {
2120 "ipv4": {
2121 "unicast": {
2122 "neighbor": {
2123 "r2": {
2124 "dest_link": {
2125 "r1-link1": {"graceful-restart-disable": True}
2126 }
2127 }
2128 }
2129 }
2130 },
2131 "ipv6": {
2132 "unicast": {
2133 "neighbor": {
2134 "r2": {
2135 "dest_link": {
2136 "r1-link1": {"graceful-restart-disable": True}
2137 }
2138 }
2139 }
2140 }
2141 },
2142 }
2143 }
2144 }
2145 }
2146
2147 result = create_router_bgp(tgen, topo, input_dict)
2148 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2149
2150 for addr_type in ADDR_TYPES:
2151 clear_bgp(tgen, addr_type, "r1")
2152 clear_bgp(tgen, addr_type, "r2")
2153
2154 # Verify GR stats
2155 input_dict = {
2156 "r2": {
2157 "bgp": {
2158 "address_family": {
2159 "ipv4": {
2160 "unicast": {
2161 "neighbor": {
2162 "r1": {
2163 "dest_link": {
2164 "r2-link1": {"graceful-restart-helper": True}
2165 }
2166 }
2167 }
2168 }
2169 },
2170 "ipv6": {
2171 "unicast": {
2172 "neighbor": {
2173 "r1": {
2174 "dest_link": {
2175 "r2-link1": {"graceful-restart-helper": True}
2176 }
2177 }
2178 }
2179 }
2180 },
2181 }
2182 }
2183 },
2184 "r1": {
2185 "bgp": {
2186 "address_family": {
2187 "ipv4": {
2188 "unicast": {
2189 "neighbor": {
2190 "r2": {
2191 "dest_link": {
2192 "r1-link1": {"graceful-restart-disable": True}
2193 }
2194 }
2195 }
2196 }
2197 },
2198 "ipv6": {
2199 "unicast": {
2200 "neighbor": {
2201 "r2": {
2202 "dest_link": {
2203 "r1-link1": {"graceful-restart-disable": True}
2204 }
2205 }
2206 }
2207 }
2208 },
2209 }
2210 }
2211 },
2212 }
2213
2214 # here the verify_graceful_restart fro the neighbor would be
2215 # "NotReceived" as the latest GR config is not yet applied.
2216 for addr_type in ADDR_TYPES:
2217 result = verify_graceful_restart(
2218 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2219 )
2220 assert result is True, "Testcase {} : Failed \n Error {}".format(
2221 tc_name, result
2222 )
2223
2224 logger.info("[Phase 2] : Now flap the link running the BGP session ")
2225 # Shutdown interface
2226 intf = "r2-r1-eth0"
2227 shutdown_bringup_interface(tgen, "r2", intf)
2228
2229 # Bring up Interface
2230 shutdown_bringup_interface(tgen, dut, intf, ifaceaction=True)
2231
2232 for addr_type in ADDR_TYPES:
2233 result = verify_graceful_restart(
2234 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2235 )
2236 assert result is True, "Testcase {} : Failed \n Error {}".format(
2237 tc_name, result
2238 )
2239
2240 result = verify_r_bit(
2241 tgen, topo, addr_type, input_dict, dut="r2", peer="r1", expected=False
2242 )
2243 assert result is not True, "Testcase {} : Failed \n Error {}".format(
2244 tc_name, result
2245 )
2246
2247 logger.info("Restart BGPd on R2 ")
2248 kill_router_daemons(tgen, "r2", ["bgpd"])
2249
2250 start_router_daemons(tgen, "r2", ["bgpd"])
2251
2252 for addr_type in ADDR_TYPES:
2253 result = verify_graceful_restart(
2254 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2255 )
2256 assert result is True, "Testcase {} : Failed \n Error {}".format(
2257 tc_name, result
2258 )
2259
2260 result = verify_r_bit(
2261 tgen, topo, addr_type, input_dict, dut="r2", peer="r1", expected=False
2262 )
2263 assert result is not True, "Testcase {} : Failed \n Error {}".format(
2264 tc_name, result
2265 )
2266
2267 write_test_footer(tc_name)
2268
2269
2270def test_BGP_GR_TC_8_p1(request):
2271 """
2272 Test Objective : Verify that restarting nodes set "F" bit while sending
2273 the BGP open messages after it restarts, only when BGP GR is enabled.
2274 """
2275
2276 tgen = get_topogen()
2277 tc_name = request.node.name
2278 write_test_header(tc_name)
2279
2280 # Check router status
2281 check_router_status(tgen)
2282
2283 # Don't run this test if we have any failure.
2284 if tgen.routers_have_failure():
2285 pytest.skip(tgen.errors)
2286
2287 # Creating configuration from JSON
2288 reset_config_on_routers(tgen)
2289
2290 logger.info(
2291 "[Phase 1] : Test Setup" " [Restart Mode]R1-----R2[Restart Mode] initialized "
2292 )
2293
2294 # Configure graceful-restart
2295 input_dict = {
2296 "r1": {
2297 "bgp": {
2298 "graceful-restart": {"preserve-fw-state": True},
2299 "address_family": {
2300 "ipv4": {
2301 "unicast": {
2302 "neighbor": {
2303 "r2": {
2304 "dest_link": {
2305 "r1-link1": {"graceful-restart": True}
2306 }
2307 }
2308 }
2309 }
2310 },
2311 "ipv6": {
2312 "unicast": {
2313 "neighbor": {
2314 "r2": {
2315 "dest_link": {
2316 "r1-link1": {"graceful-restart": True}
2317 }
2318 }
2319 }
2320 }
2321 },
2322 },
2323 }
2324 },
2325 "r2": {
2326 "bgp": {
2327 "address_family": {
2328 "ipv4": {
2329 "unicast": {
2330 "neighbor": {
2331 "r1": {
2332 "dest_link": {
2333 "r2-link1": {"graceful-restart": True}
2334 }
2335 }
2336 }
2337 }
2338 },
2339 "ipv6": {
2340 "unicast": {
2341 "neighbor": {
2342 "r1": {
2343 "dest_link": {
2344 "r2-link1": {"graceful-restart": True}
2345 }
2346 }
2347 }
2348 }
2349 },
2350 }
2351 }
2352 },
2353 }
2354
2355 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2356
2357 for addr_type in ADDR_TYPES:
2358 result = verify_graceful_restart(
2359 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2360 )
2361 assert result is True, "Testcase {} : Failed \n Error {}".format(
2362 tc_name, result
2363 )
2364
2365 # Verifying BGP RIB routes
2366 dut = "r1"
2367 peer = "r2"
2368 next_hop = next_hop_per_address_family(
2369 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2370 )
2371 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2372 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2373 assert result is True, "Testcase {} : Failed \n Error {}".format(
2374 tc_name, result
2375 )
2376
2377 # Verifying RIB routes
2378 protocol = "bgp"
2379 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2380 assert result is True, "Testcase {} : Failed \n Error {}".format(
2381 tc_name, result
2382 )
2383
2384 logger.info("[Phase 2] : R1 goes for reload ")
2385
2386 kill_router_daemons(tgen, "r1", ["bgpd"])
2387
2388 logger.info("[Phase 3] : R1 is about to come up now ")
2389 start_router_daemons(tgen, "r1", ["bgpd"])
2390
2391 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
2392
2393 for addr_type in ADDR_TYPES:
2394 result = verify_graceful_restart(
2395 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2396 )
2397 assert result is True, "Testcase {} : Failed \n Error {}".format(
2398 tc_name, result
2399 )
2400
2401 result = verify_r_bit(tgen, topo, addr_type, input_dict, dut="r2", peer="r1")
2402 assert result is True, "Testcase {} : Failed \n Error {}".format(
2403 tc_name, result
2404 )
2405
2406 result = verify_f_bit(tgen, topo, addr_type, input_dict, dut="r2", peer="r1")
2407 assert result is True, "Testcase {} : Failed \n Error {}".format(
2408 tc_name, result
2409 )
2410
2411 write_test_footer(tc_name)
2412
2413
2414def test_BGP_GR_TC_17_p1(request):
2415 """
2416 Test Objective : Verify that only GR helper routers keep the stale
2417 route entries, not any GR disabled router.
2418 """
2419
2420 tgen = get_topogen()
2421 tc_name = request.node.name
2422 write_test_header(tc_name)
2423
2424 # Check router status
2425 check_router_status(tgen)
2426
2427 # Don't run this test if we have any failure.
2428 if tgen.routers_have_failure():
2429 pytest.skip(tgen.errors)
2430
2431 # Creating configuration from JSON
2432 reset_config_on_routers(tgen)
2433
2434 logger.info("[Phase 1] : Test Setup [Disable]R1-----R2[Restart] initialized ")
2435
2436 # Configure graceful-restart
2437 input_dict = {
2438 "r1": {
2439 "bgp": {
2440 "graceful-restart": {
2441 "graceful-restart": True,
2442 "preserve-fw-state": True,
2443 },
2444 "address_family": {
2445 "ipv4": {
2446 "unicast": {
2447 "neighbor": {
2448 "r2": {
2449 "dest_link": {
2450 "r1-link1": {"graceful-restart-disable": True}
2451 }
2452 }
2453 }
2454 }
2455 },
2456 "ipv6": {
2457 "unicast": {
2458 "neighbor": {
2459 "r2": {
2460 "dest_link": {
2461 "r1-link1": {"graceful-restart-disable": True}
2462 }
2463 }
2464 }
2465 }
2466 },
2467 },
2468 }
2469 },
2470 "r2": {
2471 "bgp": {
2472 "address_family": {
2473 "ipv4": {
2474 "unicast": {
2475 "neighbor": {
2476 "r1": {
2477 "dest_link": {
2478 "r2-link1": {"graceful-restart": True}
2479 }
2480 }
2481 }
2482 }
2483 },
2484 "ipv6": {
2485 "unicast": {
2486 "neighbor": {
2487 "r1": {
2488 "dest_link": {
2489 "r2-link1": {"graceful-restart": True}
2490 }
2491 }
2492 }
2493 }
2494 },
2495 }
2496 }
2497 },
2498 }
2499
2500 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2501
2502 for addr_type in ADDR_TYPES:
2503 result = verify_graceful_restart(
2504 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2505 )
2506 assert result is True, "Testcase {} : Failed \n Error {}".format(
2507 tc_name, result
2508 )
2509
2510 # Verifying BGP RIB routes
2511 dut = "r1"
2512 peer = "r2"
2513 next_hop = next_hop_per_address_family(
2514 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2515 )
2516 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2517 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2518 assert result is True, "Testcase {} : Failed \n Error {}".format(
2519 tc_name, result
2520 )
2521
2522 # Verifying RIB routes
2523 protocol = "bgp"
2524 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2525 assert result is True, "Testcase {} : Failed \n Error {}".format(
2526 tc_name, result
2527 )
2528
2529 logger.info("[Phase 2] : R2 goes for reload ")
2530
2531 kill_router_daemons(tgen, "r2", ["bgpd"])
2532
2533 logger.info(
2534 "[Phase 3] : R2 is still down, restart time 120 sec."
2535 " So time verify the routes are present in BGP RIB and ZEBRA "
2536 )
2537
2538 for addr_type in ADDR_TYPES:
2539 # Verifying BGP RIB routes
2540 next_hop = next_hop_per_address_family(
2541 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2542 )
2543 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2544 result = verify_bgp_rib(
2545 tgen, addr_type, dut, input_topo, next_hop, expected=False
2546 )
2547 assert result is not True, "Testcase {} : Failed \n Error {}".format(
2548 tc_name, result
2549 )
2550 logger.info(" Expected behavior: {}".format(result))
2551
2552 # Verifying RIB routes
2553 result = verify_rib(
2554 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
2555 )
2556 assert result is not True, "Testcase {} : Failed \n Error {}".format(
2557 tc_name, result
2558 )
2559 logger.info(" Expected behavior: {}".format(result))
2560
2561 logger.info("[Phase 5] : R2 is about to come up now ")
2562 start_router_daemons(tgen, "r2", ["bgpd"])
2563
2564 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
2565
2566 for addr_type in ADDR_TYPES:
2567 result = verify_graceful_restart(
2568 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2569 )
2570 assert result is True, "Testcase {} : Failed \n Error {}".format(
2571 tc_name, result
2572 )
2573
2574 result = verify_r_bit(
2575 tgen, topo, addr_type, input_dict, dut="r1", peer="r2", expected=False
2576 )
2577 assert result is not True, "Testcase {} : Failed \n Error {}".format(
2578 tc_name, result
2579 )
2580
2581 # Verifying BGP RIB routes
2582 next_hop = next_hop_per_address_family(
2583 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2584 )
2585 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2586 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2587 assert result is True, "Testcase {} : Failed \n Error {}".format(
2588 tc_name, result
2589 )
2590
2591 # Verifying RIB routes
2592 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2593 assert result is True, "Testcase {} : Failed \n Error {}".format(
2594 tc_name, result
2595 )
2596
2597 write_test_footer(tc_name)
2598
2599
2600def test_BGP_GR_TC_19_p1(request):
2601 """
2602 Test Objective : Verify that GR helper routers keeps all the routes received
2603 from restarting node if both the routers are configured as GR restarting node.
2604 """
2605
2606 tgen = get_topogen()
2607 tc_name = request.node.name
2608 write_test_header(tc_name)
2609
2610 # Check router status
2611 check_router_status(tgen)
2612
2613 # Don't run this test if we have any failure.
2614 if tgen.routers_have_failure():
2615 pytest.skip(tgen.errors)
2616
2617 # Creating configuration from JSON
2618 reset_config_on_routers(tgen)
2619
2620 logger.info("[Phase 1] : Test Setup [Helper]R1-----R2[Restart] initialized ")
2621
2622 # Configure graceful-restart
2623 input_dict = {
2624 "r1": {
2625 "bgp": {
2626 "graceful-restart": {
2627 "graceful-restart": True,
2628 "preserve-fw-state": True,
2629 },
2630 "address_family": {
2631 "ipv4": {
2632 "unicast": {
2633 "neighbor": {
2634 "r2": {
2635 "dest_link": {
2636 "r1-link1": {"graceful-restart-helper": True}
2637 }
2638 }
2639 }
2640 }
2641 },
2642 "ipv6": {
2643 "unicast": {
2644 "neighbor": {
2645 "r2": {
2646 "dest_link": {
2647 "r1-link1": {"graceful-restart-helper": True}
2648 }
2649 }
2650 }
2651 }
2652 },
2653 },
2654 }
2655 },
2656 "r2": {
2657 "bgp": {
2658 "address_family": {
2659 "ipv4": {
2660 "unicast": {
2661 "neighbor": {
2662 "r1": {
2663 "dest_link": {
2664 "r2-link1": {"graceful-restart": True}
2665 }
2666 }
2667 }
2668 }
2669 },
2670 "ipv6": {
2671 "unicast": {
2672 "neighbor": {
2673 "r1": {
2674 "dest_link": {
2675 "r2-link1": {"graceful-restart": True}
2676 }
2677 }
2678 }
2679 }
2680 },
2681 }
2682 }
2683 },
2684 }
2685
2686 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2687
2688 for addr_type in ADDR_TYPES:
2689 result = verify_graceful_restart(
2690 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2691 )
2692 assert result is True, "Testcase {} : Failed \n Error {}".format(
2693 tc_name, result
2694 )
2695
2696 # Verifying BGP RIB routes
2697 dut = "r1"
2698 peer = "r2"
2699 next_hop = next_hop_per_address_family(
2700 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2701 )
2702 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2703 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2704 assert result is True, "Testcase {} : Failed \n Error {}".format(
2705 tc_name, result
2706 )
2707
2708 # Verifying RIB routes
2709 protocol = "bgp"
2710 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2711 assert result is True, "Testcase {} : Failed \n Error {}".format(
2712 tc_name, result
2713 )
2714
2715 logger.info(
2716 "[Phase 2] : R1's Gr state cahnge to Graceful"
2717 " Restart without resetting the session "
2718 )
2719
2720 # Configure graceful-restart
2721 input_dict = {
2722 "r1": {
2723 "bgp": {
2724 "address_family": {
2725 "ipv4": {
2726 "unicast": {
2727 "neighbor": {
2728 "r2": {
2729 "dest_link": {
2730 "r1-link1": {"graceful-restart": True}
2731 }
2732 }
2733 }
2734 }
2735 },
2736 "ipv6": {
2737 "unicast": {
2738 "neighbor": {
2739 "r2": {
2740 "dest_link": {
2741 "r1-link1": {"graceful-restart": True}
2742 }
2743 }
2744 }
2745 }
2746 },
2747 }
2748 }
2749 }
2750 }
2751
2752 result = create_router_bgp(tgen, topo, input_dict)
2753 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
2754
2755 logger.info(
2756 "[Phase 3] : R2 is still down, restart time 120 sec."
2757 " So time verify the routes are present in BGP RIB and ZEBRA "
2758 )
2759
2760 for addr_type in ADDR_TYPES:
2761 # Verifying BGP RIB routes
2762 next_hop = next_hop_per_address_family(
2763 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2764 )
2765 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2766 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2767 assert result is True, "Testcase {} : Failed \n Error {}".format(
2768 tc_name, result
2769 )
2770
2771 # Verifying RIB routes
2772 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2773 assert result is True, "Testcase {} : Failed \n Error {}".format(
2774 tc_name, result
2775 )
2776
2777 write_test_footer(tc_name)
2778
2779
2780def test_BGP_GR_TC_20_p1(request):
2781 """
2782 Test Objective : Verify that GR helper routers delete all the routes
2783 received from a node if both the routers are configured as GR helper node.
2784 """
2785 tgen = get_topogen()
2786 tc_name = request.node.name
2787 write_test_header(tc_name)
2788
2789 # Check router status
2790 check_router_status(tgen)
2791
2792 # Don't run this test if we have any failure.
2793 if tgen.routers_have_failure():
2794 pytest.skip(tgen.errors)
2795
2796 # Creating configuration from JSON
2797 reset_config_on_routers(tgen)
2798
2799 logger.info("[Phase 1] : Test Setup [Helper]R1-----R2[Helper] initialized ")
2800
2801 # Configure graceful-restart
2802 input_dict = {
2803 "r1": {
2804 "bgp": {
2805 "graceful-restart": {
2806 "graceful-restart": True,
2807 "preserve-fw-state": True,
2808 },
2809 "address_family": {
2810 "ipv4": {
2811 "unicast": {
2812 "neighbor": {
2813 "r2": {
2814 "dest_link": {
2815 "r1-link1": {"graceful-restart-helper": True}
2816 }
2817 }
2818 }
2819 }
2820 },
2821 "ipv6": {
2822 "unicast": {
2823 "neighbor": {
2824 "r2": {
2825 "dest_link": {
2826 "r1-link1": {"graceful-restart-helper": True}
2827 }
2828 }
2829 }
2830 }
2831 },
2832 },
2833 }
2834 },
2835 "r2": {
2836 "bgp": {
2837 "address_family": {
2838 "ipv4": {
2839 "unicast": {
2840 "neighbor": {
2841 "r1": {
2842 "dest_link": {
2843 "r2-link1": {"graceful-restart-helper": True}
2844 }
2845 }
2846 }
2847 }
2848 },
2849 "ipv6": {
2850 "unicast": {
2851 "neighbor": {
2852 "r1": {
2853 "dest_link": {
2854 "r2-link1": {"graceful-restart-helper": True}
2855 }
2856 }
2857 }
2858 }
2859 },
2860 }
2861 }
2862 },
2863 }
2864
2865 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
2866
2867 for addr_type in ADDR_TYPES:
2868 result = verify_graceful_restart(
2869 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
2870 )
2871 assert result is True, "Testcase {} : Failed \n Error {}".format(
2872 tc_name, result
2873 )
2874
2875 # Verifying BGP RIB routes
2876 dut = "r1"
2877 peer = "r2"
2878 next_hop = next_hop_per_address_family(
2879 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2880 )
2881 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2882 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2883 assert result is True, "Testcase {} : Failed \n Error {}".format(
2884 tc_name, result
2885 )
2886
2887 # Verifying RIB routes
2888 protocol = "bgp"
2889 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2890 assert result is True, "Testcase {} : Failed \n Error {}".format(
2891 tc_name, result
2892 )
2893
2894 kill_router_daemons(tgen, "r2", ["bgpd"])
2895
2896 for addr_type in ADDR_TYPES:
2897 # Verifying BGP RIB routes
2898 next_hop = next_hop_per_address_family(
2899 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2900 )
2901 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2902 result = verify_bgp_rib(
2903 tgen, addr_type, dut, input_topo, next_hop, expected=False
2904 )
2905 assert result is not True, "Testcase {} : Failed \n Error {}".format(
2906 tc_name, result
2907 )
2908 logger.info(" Expected behavior: {}".format(result))
2909
2910 # Verifying RIB routes
2911 result = verify_rib(
2912 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
2913 )
2914 assert result is not True, "Testcase {} : Failed \n Error {}".format(
2915 tc_name, result
2916 )
2917 logger.info(" Expected behavior: {}".format(result))
2918
2919 logger.info("[Phase 5] : R2 is about to come up now ")
2920
2921 start_router_daemons(tgen, "r2", ["bgpd"])
2922
2923 logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ")
2924
2925 for addr_type in ADDR_TYPES:
2926 # Verifying BGP RIB routes
2927 next_hop = next_hop_per_address_family(
2928 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
2929 )
2930 input_topo = {key: topo["routers"][key] for key in ["r2"]}
2931 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
2932 assert result is True, "Testcase {} : Failed \n Error {}".format(
2933 tc_name, result
2934 )
2935
2936 # Verifying RIB routes
2937 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
2938 assert result is True, "Testcase {} : Failed \n Error {}".format(
2939 tc_name, result
2940 )
2941
2942 write_test_footer(tc_name)
2943
2944
2945def test_BGP_GR_TC_31_1_p1(request):
2946 """
2947 After BGP neighborship is established and GR capability is exchanged,
2948 transition restarting router to disabled state and vice versa.
2949 """
2950
2951 tgen = get_topogen()
2952 tc_name = request.node.name
2953 write_test_header(tc_name)
2954
2955 # Check router status
2956 check_router_status(tgen)
2957
2958 # Don't run this test if we have any failure.
2959 if tgen.routers_have_failure():
2960 pytest.skip(tgen.errors)
2961
2962 # Creating configuration from JSON
2963 reset_config_on_routers(tgen)
2964
2965 logger.info(
2966 "[Phase 1] : Test Setup" " [Helper Mode]R2-----R1[Restart Mode] initialized "
2967 )
2968
2969 # Configure graceful-restart
2970 input_dict = {
2971 "r2": {
2972 "bgp": {
2973 "address_family": {
2974 "ipv4": {
2975 "unicast": {
2976 "neighbor": {
2977 "r1": {
2978 "dest_link": {
2979 "r2-link1": {"graceful-restart-helper": True}
2980 }
2981 }
2982 }
2983 }
2984 },
2985 "ipv6": {
2986 "unicast": {
2987 "neighbor": {
2988 "r1": {
2989 "dest_link": {
2990 "r2-link1": {"graceful-restart-helper": True}
2991 }
2992 }
2993 }
2994 }
2995 },
2996 }
2997 }
2998 },
2999 "r1": {
3000 "bgp": {
3001 "graceful-restart": {"preserve-fw-state": True},
3002 "address_family": {
3003 "ipv4": {
3004 "unicast": {
3005 "neighbor": {
3006 "r2": {
3007 "dest_link": {
3008 "r1-link1": {"graceful-restart": True}
3009 }
3010 }
3011 }
3012 }
3013 },
3014 "ipv6": {
3015 "unicast": {
3016 "neighbor": {
3017 "r2": {
3018 "dest_link": {
3019 "r1-link1": {"graceful-restart": True}
3020 }
3021 }
3022 }
3023 }
3024 },
3025 },
3026 }
3027 },
3028 }
3029
3030 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
3031
3032 for addr_type in ADDR_TYPES:
3033 result = verify_graceful_restart(
3034 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
3035 )
3036 assert result is True, "Testcase {} : Failed \n Error {}".format(
3037 tc_name, result
3038 )
3039
3040 # Verifying BGP RIB routes
3041 dut = "r1"
3042 peer = "r2"
3043 protocol = "bgp"
3044 next_hop = next_hop_per_address_family(
3045 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
3046 )
3047 input_topo = {key: topo["routers"][key] for key in ["r2"]}
3048 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
3049 assert result is True, "Testcase {} : Failed \n Error {}".format(
3050 tc_name, result
3051 )
3052
3053 # Verifying RIB routes
3054 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
3055 assert result is True, "Testcase {} : Failed \n Error {}".format(
3056 tc_name, result
3057 )
3058
3059 logger.info("[Phase 2] : R1 Goes from Restart to Disable Mode ")
3060
3061 # Configure graceful-restart
3062 input_dict = {
3063 "r1": {
3064 "bgp": {
3065 "address_family": {
3066 "ipv4": {
3067 "unicast": {
3068 "neighbor": {
3069 "r2": {
3070 "dest_link": {
3071 "r1-link1": {"graceful-restart-disable": True}
3072 }
3073 }
3074 }
3075 }
3076 },
3077 "ipv6": {
3078 "unicast": {
3079 "neighbor": {
3080 "r2": {
3081 "dest_link": {
3082 "r1-link1": {"graceful-restart-disable": True}
3083 }
3084 }
3085 }
3086 }
3087 },
3088 }
3089 }
3090 }
3091 }
3092
3093 result = create_router_bgp(tgen, topo, input_dict)
3094 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3095
3096 for addr_type in ADDR_TYPES:
3097 clear_bgp(tgen, addr_type, "r1")
3098 clear_bgp(tgen, addr_type, "r2")
3099
3100 # Verify GR stats
3101 input_dict = {
3102 "r1": {
3103 "bgp": {
3104 "address_family": {
3105 "ipv4": {
3106 "unicast": {
3107 "neighbor": {
3108 "r2": {
3109 "dest_link": {
3110 "r1-link1": {"graceful-restart-disable": True}
3111 }
3112 }
3113 }
3114 }
3115 },
3116 "ipv6": {
3117 "unicast": {
3118 "neighbor": {
3119 "r2": {
3120 "dest_link": {
3121 "r1-link1": {"graceful-restart-disable": True}
3122 }
3123 }
3124 }
3125 }
3126 },
3127 }
3128 }
3129 },
3130 "r2": {
3131 "bgp": {
3132 "address_family": {
3133 "ipv4": {
3134 "unicast": {
3135 "neighbor": {
3136 "r1": {
3137 "dest_link": {
3138 "r2-link1": {"graceful-restart-helper": True}
3139 }
3140 }
3141 }
3142 }
3143 },
3144 "ipv6": {
3145 "unicast": {
3146 "neighbor": {
3147 "r1": {
3148 "dest_link": {
3149 "r2-link1": {"graceful-restart-helper": True}
3150 }
3151 }
3152 }
3153 }
3154 },
3155 }
3156 }
3157 },
3158 }
3159
3160 for addr_type in ADDR_TYPES:
3161 result = verify_graceful_restart(
3162 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
3163 )
3164 assert result is True, "Testcase {} : Failed \n Error {}".format(
3165 tc_name, result
3166 )
3167
3168 logger.info("[Phase 2] : R1 goes for reload ")
3169
3170 kill_router_daemons(tgen, "r1", ["bgpd"])
3171
3172 logger.info(
3173 "[Phase 3] : R1 is still down, restart time 120 sec."
3174 " So time verify the routes are not present in BGP RIB and ZEBRA"
3175 )
3176
3177 for addr_type in ADDR_TYPES:
3178 # Verifying RIB routes
3179 next_hop = next_hop_per_address_family(
3180 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
3181 )
3182 input_topo = {key: topo["routers"][key] for key in ["r2"]}
3183 result = verify_rib(
3184 tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False
3185 )
3186 assert result is not True, "Testcase {} : Failed \n Error {}".format(
3187 tc_name, result
3188 )
3189
3190 logger.info("[Phase 4] : R1 is about to come up now ")
3191 start_router_daemons(tgen, "r1", ["bgpd"])
3192
3193 logger.info("[Phase 5] : R1 is UP now, so time to collect GR stats ")
3194
3195 for addr_type in ADDR_TYPES:
3196 result = verify_graceful_restart(
3197 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
3198 )
3199 assert result is True, "Testcase {} : Failed \n Error {}".format(
3200 tc_name, result
3201 )
3202
3203 # Verifying BGP RIB routes
3204 next_hop = next_hop_per_address_family(
3205 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
3206 )
3207 input_topo = {key: topo["routers"][key] for key in ["r2"]}
3208 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
3209 assert result is True, "Testcase {} : Failed \n Error {}".format(
3210 tc_name, result
3211 )
3212
3213 # Verifying RIB routes
3214 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
3215 assert result is True, "Testcase {} : Failed \n Error {}".format(
3216 tc_name, result
3217 )
3218
3219 write_test_footer(tc_name)
3220
3221
3222def test_BGP_GR_TC_31_2_p1(request):
3223 """
3224 After BGP neighborship is established and GR capability is exchanged,
3225 transition restarting router to disabled state and vice versa.
3226 """
3227
3228 tgen = get_topogen()
3229 tc_name = request.node.name
3230 write_test_header(tc_name)
3231
3232 # Check router status
3233 check_router_status(tgen)
3234
3235 # Don't run this test if we have any failure.
3236 if tgen.routers_have_failure():
3237 pytest.skip(tgen.errors)
3238
3239 # Creating configuration from JSON
3240 reset_config_on_routers(tgen)
3241
3242 logger.info(
3243 "[Phase 1] : Test Setup " "[Disable Mode]R1-----R2[Restart Mode] initialized "
3244 )
3245
3246 # Configure graceful-restart
3247 input_dict = {
3248 "r2": {
3249 "bgp": {
3250 "address_family": {
3251 "ipv4": {
3252 "unicast": {
3253 "neighbor": {
3254 "r1": {
3255 "dest_link": {
3256 "r2-link1": {"graceful-restart-helper": True}
3257 }
3258 }
3259 }
3260 }
3261 },
3262 "ipv6": {
3263 "unicast": {
3264 "neighbor": {
3265 "r1": {
3266 "dest_link": {
3267 "r2-link1": {"graceful-restart-helper": True}
3268 }
3269 }
3270 }
3271 }
3272 },
3273 }
3274 }
3275 },
3276 "r1": {
3277 "bgp": {
3278 "address_family": {
3279 "ipv4": {
3280 "unicast": {
3281 "neighbor": {
3282 "r2": {
3283 "dest_link": {
3284 "r1-link1": {"graceful-restart-disable": True}
3285 }
3286 }
3287 }
3288 }
3289 },
3290 "ipv6": {
3291 "unicast": {
3292 "neighbor": {
3293 "r2": {
3294 "dest_link": {
3295 "r1-link1": {"graceful-restart-disable": True}
3296 }
3297 }
3298 }
3299 }
3300 },
3301 }
3302 }
3303 },
3304 }
3305
3306 configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2")
3307
3308 for addr_type in ADDR_TYPES:
3309 result = verify_graceful_restart(
3310 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
3311 )
3312 assert result is True, "Testcase {} : Failed \n Error {}".format(
3313 tc_name, result
3314 )
3315
3316 # Verifying BGP RIB routes
3317 dut = "r1"
3318 peer = "r2"
3319 next_hop = next_hop_per_address_family(
3320 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
3321 )
3322 input_topo = {key: topo["routers"][key] for key in ["r2"]}
3323 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
3324 assert result is True, "Testcase {} : Failed \n Error {}".format(
3325 tc_name, result
3326 )
3327
3328 # Verifying RIB routes
3329 protocol = "bgp"
3330 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
3331 assert result is True, "Testcase {} : Failed \n Error {}".format(
3332 tc_name, result
3333 )
3334
3335 logger.info("[Phase 2] : R2 Goes from Disable to Restart Mode ")
3336
3337 # Configure graceful-restart
3338 input_dict = {
3339 "r1": {
3340 "bgp": {
3341 "graceful-restart": {"preserve-fw-state": True},
3342 "address_family": {
3343 "ipv4": {
3344 "unicast": {
3345 "neighbor": {
3346 "r2": {
3347 "dest_link": {
3348 "r1-link1": {"graceful-restart": True}
3349 }
3350 }
3351 }
3352 }
3353 },
3354 "ipv6": {
3355 "unicast": {
3356 "neighbor": {
3357 "r2": {
3358 "dest_link": {
3359 "r1-link1": {"graceful-restart": True}
3360 }
3361 }
3362 }
3363 }
3364 },
3365 },
3366 }
3367 }
3368 }
3369
3370 result = create_router_bgp(tgen, topo, input_dict)
3371 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
3372
3373 for addr_type in ADDR_TYPES:
3374 clear_bgp(tgen, addr_type, "r1")
3375 clear_bgp(tgen, addr_type, "r2")
3376
3377 # Verify GR stats
3378 input_dict = {
3379 "r2": {
3380 "bgp": {
3381 "address_family": {
3382 "ipv4": {
3383 "unicast": {
3384 "neighbor": {
3385 "r1": {
3386 "dest_link": {
3387 "r2-link1": {"graceful-restart-helper": True}
3388 }
3389 }
3390 }
3391 }
3392 },
3393 "ipv6": {
3394 "unicast": {
3395 "neighbor": {
3396 "r1": {
3397 "dest_link": {
3398 "r2-link1": {"graceful-restart-helper": True}
3399 }
3400 }
3401 }
3402 }
3403 },
3404 }
3405 }
3406 },
3407 "r1": {
3408 "bgp": {
3409 "address_family": {
3410 "ipv4": {
3411 "unicast": {
3412 "neighbor": {
3413 "r2": {
3414 "dest_link": {
3415 "r1-link1": {"graceful-restart": True}
3416 }
3417 }
3418 }
3419 }
3420 },
3421 "ipv6": {
3422 "unicast": {
3423 "neighbor": {
3424 "r2": {
3425 "dest_link": {
3426 "r1-link1": {"graceful-restart": True}
3427 }
3428 }
3429 }
3430 }
3431 },
3432 }
3433 }
3434 },
3435 }
3436
3437 # here the verify_graceful_restart fro the neighbor would be
3438 # "NotReceived" as the latest GR config is not yet applied.
3439 for addr_type in ADDR_TYPES:
3440 result = verify_graceful_restart(
3441 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
3442 )
3443 assert result is True, "Testcase {} : Failed \n Error {}".format(
3444 tc_name, result
3445 )
3446
3447 logger.info("[Phase 3] : R1 goes for reload ")
3448
3449 kill_router_daemons(tgen, "r1", ["bgpd"])
3450
3451 logger.info(
3452 "[Phase 4] : R1 is still down, restart time 120 sec."
3453 " So time verify the routes are present in BGP RIB and ZEBRA "
3454 )
3455
3456 for addr_type in ADDR_TYPES:
3457 # Verifying RIB routes
3458 next_hop = next_hop_per_address_family(
3459 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
3460 )
3461 input_topo = {key: topo["routers"][key] for key in ["r2"]}
3462 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
3463 assert result is True, "Testcase {} : Failed \n Error {}".format(
3464 tc_name, result
3465 )
3466
3467 logger.info("[Phase 6] : R1 is about to come up now ")
3468 start_router_daemons(tgen, "r1", ["bgpd"])
3469
3470 logger.info("[Phase 4] : R1 is UP now, so time to collect GR stats ")
3471
3472 for addr_type in ADDR_TYPES:
3473 result = verify_graceful_restart(
3474 tgen, topo, addr_type, input_dict, dut="r1", peer="r2"
3475 )
3476 assert result is True, "Testcase {} : Failed \n Error {}".format(
3477 tc_name, result
3478 )
3479
3480 # Verifying BGP RIB routes
3481 next_hop = next_hop_per_address_family(
3482 tgen, dut, peer, addr_type, NEXT_HOP_IP_2
3483 )
3484 input_topo = {key: topo["routers"][key] for key in ["r2"]}
3485 result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop)
3486 assert result is True, "Testcase {} : Failed \n Error {}".format(
3487 tc_name, result
3488 )
3489
3490 # Verifying RIB routes
3491 result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol)
3492 assert result is True, "Testcase {} : Failed \n Error {}".format(
3493 tc_name, result
3494 )
3495
3496 write_test_footer(tc_name)
3497
3498
3499if __name__ == "__main__":
3500 args = ["-s"] + sys.argv[1:]
3501 sys.exit(pytest.main(args))