]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python | |
2 | # SPDX-License-Identifier: ISC | |
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 | # | |
8 | ||
9 | """ | |
10 | Following tests are covered to test BGP Graceful Restart functionality. | |
11 | Basic 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 | ||
18 | 1. Transition from Peer-level helper to Global Restarting | |
19 | 2. Transition from Peer-level helper to Global inherit helper | |
20 | 3. Transition from Peer-level restarting to Global inherit helper | |
21 | 4. Default GR functional mode is Helper. | |
22 | 5. Verify that the restarting node sets "R" bit while sending the | |
23 | BGP open messages after the node restart, only if GR is enabled. | |
24 | 6. Verify if restarting node resets R bit in BGP open message | |
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. | |
27 | 7. Verify if restarting node resets R bit in BGP | |
28 | open message during normal BGP session flaps when GR is disabled. | |
29 | 8. Verify that restarting nodes set "F" bit while sending | |
30 | the BGP open messages after it restarts, only when BGP GR is enabled. | |
31 | 9. Verify that only GR helper routers keep the stale | |
32 | route entries, not any GR disabled router. | |
33 | 10. 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. | |
36 | 11. 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. | |
39 | 12. After BGP neighborship is established and GR capability is exchanged, | |
40 | transition restarting router to disabled state and vice versa. | |
41 | 13. After BGP neighborship is established and GR capability is exchanged, | |
42 | transition restarting router to disabled state and vice versa. | |
43 | 14. Verify that restarting nodes reset "F" bit while sending | |
44 | the BGP open messages after it's restarts, when BGP GR is **NOT** enabled. | |
45 | 15. Verify that only GR helper routers keep the stale | |
46 | route entries, not any GR disabled router. | |
47 | 16. Transition from Global Restarting to Disable and then Global | |
48 | Disable to Restarting. | |
49 | 17. Transition from Global Helper to Disable and then Global | |
50 | Disable to Helper. | |
51 | 18. 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 | |
55 | 19. Transition from Peer-level helper to Global Restarting, | |
56 | Global Mode : GR Restarting | |
57 | PerPeer Mode : GR Restarting | |
58 | GR Mode effective : GR Restarting | |
59 | 20. Transition from Peer-level restart to Global Restart | |
60 | Global Mode : GR Restarting | |
61 | PerPeer Mode : GR Restarting | |
62 | GR Mode effective : GR Restarting | |
63 | 21. Transition from Peer-level disabled to Global Restart | |
64 | Global Mode : GR Restarting | |
65 | PerPeer Mode : GR Disabled | |
66 | GR Mode effective : GR Disabled | |
67 | 22. Peer-level inherit from Global Restarting | |
68 | Global Mode : GR Restart | |
69 | PerPeer Mode : None | |
70 | GR Mode effective : GR Restart | |
71 | 23. Transition from Peer-level disable to Global inherit helper | |
72 | Global Mode : None | |
73 | PerPeer Mode : GR Disable | |
74 | GR Mode effective : GR Disable | |
75 | ||
76 | These tests have been broken up into 4 sub python scripts because | |
77 | the totality of this run was fairly significant. | |
78 | """ | |
79 | ||
80 | import os | |
81 | import sys | |
82 | import time | |
83 | import pytest | |
84 | ||
85 | # Save the Current Working Directory to find configuration files. | |
86 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
87 | sys.path.append(os.path.join("../")) | |
88 | sys.path.append(os.path.join("../lib/")) | |
89 | ||
90 | # pylint: disable=C0413 | |
91 | # Import topogen and topotest helpers | |
92 | from lib.topogen import Topogen, get_topogen | |
93 | from lib.topolog import logger | |
94 | ||
95 | # Required to instantiate the topology builder class. | |
96 | ||
97 | # Import topoJson from lib, to create topology and initial configuration | |
98 | from lib.topojson import build_config_from_json | |
99 | from 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, | |
106 | verify_bgp_convergence, | |
107 | verify_bgp_convergence_from_running_config, | |
108 | ) | |
109 | ||
110 | from 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, | |
122 | get_frr_ipv6_linklocal, | |
123 | required_linux_kernel_version, | |
124 | ) | |
125 | ||
126 | pytestmark = [pytest.mark.bgpd] | |
127 | ||
128 | ||
129 | # Global variables | |
130 | NEXT_HOP_IP = {"ipv4": "192.168.1.10", "ipv6": "fd00:0:0:1::10"} | |
131 | NEXT_HOP_IP_1 = {"ipv4": "192.168.0.1", "ipv6": "fd00::1"} | |
132 | NEXT_HOP_IP_2 = {"ipv4": "192.168.0.2", "ipv6": "fd00::2"} | |
133 | BGP_CONVERGENCE = False | |
134 | GR_RESTART_TIMER = 20 | |
135 | PREFERRED_NEXT_HOP = "link_local" | |
136 | ||
137 | ||
138 | def setup_module(mod): | |
139 | """ | |
140 | Sets up the pytest environment | |
141 | ||
142 | * `mod`: module name | |
143 | """ | |
144 | ||
145 | global ADDR_TYPES | |
146 | ||
147 | # Required linux kernel version for this suite to run. | |
148 | result = required_linux_kernel_version("4.16") | |
149 | if result is not True: | |
150 | pytest.skip("Kernel requirements are not met, kernel version should be >=4.16") | |
151 | ||
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... | |
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 | |
163 | # ... and here it calls Mininet initialization functions. | |
164 | ||
165 | # Starting topology, create tmp files which are loaded to routers | |
166 | # to start daemons and then start routers | |
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 | ||
179 | BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo) | |
180 | assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error:" " {}".format( | |
181 | BGP_CONVERGENCE | |
182 | ) | |
183 | ||
184 | logger.info("Running setup_module() done") | |
185 | ||
186 | ||
187 | def 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 | ||
207 | def 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: | |
216 | neighbor = topo["routers"][peer]["links"]["r1-link1"][addr_type].split("/")[0] | |
217 | clear_bgp(tgen, addr_type, dut, neighbor=neighbor) | |
218 | ||
219 | for addr_type in ADDR_TYPES: | |
220 | neighbor = topo["routers"][dut]["links"]["r2-link1"][addr_type].split("/")[0] | |
221 | clear_bgp(tgen, addr_type, peer, neighbor=neighbor) | |
222 | ||
223 | result = verify_bgp_convergence_from_running_config(tgen) | |
224 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
225 | ||
226 | return True | |
227 | ||
228 | ||
229 | def 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 | ||
245 | def BGP_GR_TC_50_p1(request): | |
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 | ||
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 | ||
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 | ||
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) | |
418 | ||
419 | result = verify_bgp_convergence_from_running_config(tgen) | |
420 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
421 | ||
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 | ||
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 | ||
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 | ||
512 | def test_BGP_GR_TC_19_p1(request): | |
513 | """ | |
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. | |
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 | ||
532 | logger.info("[Phase 1] : Test Setup [Helper]R1-----R2[Restart] initialized ") | |
533 | ||
534 | # Configure graceful-restart | |
535 | input_dict = { | |
536 | "r1": { | |
537 | "bgp": { | |
538 | "graceful-restart": { | |
539 | "graceful-restart": True, | |
540 | "preserve-fw-state": True, | |
541 | }, | |
542 | "address_family": { | |
543 | "ipv4": { | |
544 | "unicast": { | |
545 | "neighbor": { | |
546 | "r2": { | |
547 | "dest_link": { | |
548 | "r1-link1": {"graceful-restart-helper": True} | |
549 | } | |
550 | } | |
551 | } | |
552 | } | |
553 | }, | |
554 | "ipv6": { | |
555 | "unicast": { | |
556 | "neighbor": { | |
557 | "r2": { | |
558 | "dest_link": { | |
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} | |
588 | } | |
589 | } | |
590 | } | |
591 | } | |
592 | }, | |
593 | } | |
594 | } | |
595 | }, | |
596 | } | |
597 | ||
598 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
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 | ||
608 | # Verifying BGP RIB routes | |
609 | dut = "r1" | |
610 | peer = "r2" | |
611 | next_hop = next_hop_per_address_family( | |
612 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
613 | ) | |
614 | input_topo = {key: topo["routers"][key] for key in ["r2"]} | |
615 | result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop) | |
616 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
617 | tc_name, result | |
618 | ) | |
619 | ||
620 | # Verifying RIB routes | |
621 | protocol = "bgp" | |
622 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
623 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
624 | tc_name, result | |
625 | ) | |
626 | ||
627 | logger.info( | |
628 | "[Phase 2] : R1's Gr state cahnge to Graceful" | |
629 | " Restart without resetting the session " | |
630 | ) | |
631 | ||
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 | } | |
663 | ||
664 | result = create_router_bgp(tgen, topo, input_dict) | |
665 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
666 | ||
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 " | |
670 | ) | |
671 | ||
672 | for addr_type in ADDR_TYPES: | |
673 | # Verifying BGP RIB routes | |
674 | next_hop = next_hop_per_address_family( | |
675 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
676 | ) | |
677 | input_topo = {key: topo["routers"][key] for key in ["r2"]} | |
678 | result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop) | |
679 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
680 | tc_name, result | |
681 | ) | |
682 | ||
683 | # Verifying RIB routes | |
684 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
685 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
686 | tc_name, result | |
687 | ) | |
688 | ||
689 | write_test_footer(tc_name) | |
690 | ||
691 | ||
692 | def 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) | |
710 | ||
711 | logger.info("[Phase 1] : Test Setup [Helper]R1-----R2[Helper] initialized ") | |
712 | ||
713 | # Configure graceful-restart | |
714 | input_dict = { | |
715 | "r1": { | |
716 | "bgp": { | |
717 | "graceful-restart": { | |
718 | "graceful-restart": True, | |
719 | "preserve-fw-state": True, | |
720 | }, | |
721 | "address_family": { | |
722 | "ipv4": { | |
723 | "unicast": { | |
724 | "neighbor": { | |
725 | "r2": { | |
726 | "dest_link": { | |
727 | "r1-link1": {"graceful-restart-helper": True} | |
728 | } | |
729 | } | |
730 | } | |
731 | } | |
732 | }, | |
733 | "ipv6": { | |
734 | "unicast": { | |
735 | "neighbor": { | |
736 | "r2": { | |
737 | "dest_link": { | |
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} | |
767 | } | |
768 | } | |
769 | } | |
770 | } | |
771 | }, | |
772 | } | |
773 | } | |
774 | }, | |
775 | } | |
776 | ||
777 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
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 | ||
787 | # Verifying BGP RIB routes | |
788 | dut = "r1" | |
789 | peer = "r2" | |
790 | next_hop = next_hop_per_address_family( | |
791 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
792 | ) | |
793 | input_topo = {key: topo["routers"][key] for key in ["r2"]} | |
794 | result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop) | |
795 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
796 | tc_name, result | |
797 | ) | |
798 | ||
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( | |
803 | tc_name, result | |
804 | ) | |
805 | ||
806 | kill_router_daemons(tgen, "r2", ["bgpd"]) | |
807 | ||
808 | for addr_type in ADDR_TYPES: | |
809 | # Verifying BGP RIB routes | |
810 | next_hop = next_hop_per_address_family( | |
811 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
812 | ) | |
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 | |
816 | ) | |
817 | assert result is not True, ( | |
818 | "Testcase {} : Failed \n " | |
819 | "Expected: Routes should not be present in {} BGP RIB \n " | |
820 | "Found: {}".format(tc_name, dut, result) | |
821 | ) | |
822 | ||
823 | # Verifying RIB routes | |
824 | result = verify_rib( | |
825 | tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False | |
826 | ) | |
827 | assert result is not True, ( | |
828 | "Testcase {} : Failed \n " | |
829 | "Expected: Routes should not be present in {} FIB \n " | |
830 | "Found: {}".format(tc_name, dut, result) | |
831 | ) | |
832 | ||
833 | logger.info("[Phase 5] : R2 is about to come up now ") | |
834 | ||
835 | start_router_daemons(tgen, "r2", ["bgpd"]) | |
836 | ||
837 | logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ") | |
838 | ||
839 | for addr_type in ADDR_TYPES: | |
840 | # Verifying BGP RIB routes | |
841 | next_hop = next_hop_per_address_family( | |
842 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
843 | ) | |
844 | input_topo = {key: topo["routers"][key] for key in ["r2"]} | |
845 | result = verify_bgp_rib(tgen, addr_type, dut, input_topo, next_hop) | |
846 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
847 | tc_name, result | |
848 | ) | |
849 | ||
850 | # Verifying RIB routes | |
851 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
852 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
853 | tc_name, result | |
854 | ) | |
855 | ||
856 | write_test_footer(tc_name) | |
857 | ||
858 | ||
859 | def test_BGP_GR_TC_31_1_p1(request): | |
860 | """ | |
861 | After BGP neighborship is established and GR capability is exchanged, | |
862 | transition restarting router to disabled state and vice versa. | |
863 | """ | |
864 | ||
865 | tgen = get_topogen() | |
866 | tc_name = request.node.name | |
867 | write_test_header(tc_name) | |
868 | ||
869 | # Check router status | |
870 | check_router_status(tgen) | |
871 | ||
872 | # Don't run this test if we have any failure. | |
873 | if tgen.routers_have_failure(): | |
874 | pytest.skip(tgen.errors) | |
875 | ||
876 | # Creating configuration from JSON | |
877 | reset_config_on_routers(tgen) | |
878 | ||
879 | logger.info( | |
880 | "[Phase 1] : Test Setup" " [Helper Mode]R2-----R1[Restart Mode] initialized " | |
881 | ) | |
882 | ||
883 | # Configure graceful-restart | |
884 | input_dict = { | |
885 | "r2": { | |
886 | "bgp": { | |
887 | "address_family": { | |
888 | "ipv4": { | |
889 | "unicast": { | |
890 | "neighbor": { | |
891 | "r1": { | |
892 | "dest_link": { | |
893 | "r2-link1": {"graceful-restart-helper": True} | |
894 | } | |
895 | } | |
896 | } | |
897 | } | |
898 | }, | |
899 | "ipv6": { | |
900 | "unicast": { | |
901 | "neighbor": { | |
902 | "r1": { | |
903 | "dest_link": { | |
904 | "r2-link1": {"graceful-restart-helper": True} | |
905 | } | |
906 | } | |
907 | } | |
908 | } | |
909 | }, | |
910 | } | |
911 | } | |
912 | }, | |
913 | "r1": { | |
914 | "bgp": { | |
915 | "graceful-restart": {"preserve-fw-state": True}, | |
916 | "address_family": { | |
917 | "ipv4": { | |
918 | "unicast": { | |
919 | "neighbor": { | |
920 | "r2": { | |
921 | "dest_link": { | |
922 | "r1-link1": {"graceful-restart": True} | |
923 | } | |
924 | } | |
925 | } | |
926 | } | |
927 | }, | |
928 | "ipv6": { | |
929 | "unicast": { | |
930 | "neighbor": { | |
931 | "r2": { | |
932 | "dest_link": { | |
933 | "r1-link1": {"graceful-restart": True} | |
934 | } | |
935 | } | |
936 | } | |
937 | } | |
938 | }, | |
939 | }, | |
940 | } | |
941 | }, | |
942 | } | |
943 | ||
944 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
945 | ||
946 | for addr_type in ADDR_TYPES: | |
947 | result = verify_graceful_restart( | |
948 | tgen, topo, addr_type, input_dict, dut="r1", peer="r2" | |
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" | |
957 | protocol = "bgp" | |
958 | next_hop = next_hop_per_address_family( | |
959 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
960 | ) | |
961 | input_topo = {key: topo["routers"][key] for key in ["r2"]} | |
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 | ||
973 | logger.info("[Phase 2] : R1 Goes from Restart to Disable Mode ") | |
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": { | |
985 | "r1-link1": {"graceful-restart-disable": True} | |
986 | } | |
987 | } | |
988 | } | |
989 | } | |
990 | }, | |
991 | "ipv6": { | |
992 | "unicast": { | |
993 | "neighbor": { | |
994 | "r2": { | |
995 | "dest_link": { | |
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} | |
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": { | |
1055 | "r2-link1": {"graceful-restart-helper": True} | |
1056 | } | |
1057 | } | |
1058 | } | |
1059 | } | |
1060 | }, | |
1061 | "ipv6": { | |
1062 | "unicast": { | |
1063 | "neighbor": { | |
1064 | "r1": { | |
1065 | "dest_link": { | |
1066 | "r2-link1": {"graceful-restart-helper": True} | |
1067 | } | |
1068 | } | |
1069 | } | |
1070 | } | |
1071 | }, | |
1072 | } | |
1073 | } | |
1074 | }, | |
1075 | } | |
1076 | ||
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 | ||
1085 | logger.info("[Phase 2] : R1 goes for reload ") | |
1086 | ||
1087 | kill_router_daemons(tgen, "r1", ["bgpd"]) | |
1088 | ||
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 | ) | |
1093 | ||
1094 | for addr_type in ADDR_TYPES: | |
1095 | # Verifying RIB routes | |
1096 | next_hop = next_hop_per_address_family( | |
1097 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
1098 | ) | |
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 | |
1102 | ) | |
1103 | assert result is not True, ( | |
1104 | "Testcase {} : Failed \n " | |
1105 | "Expected: Routes should not be present in {} FIB \n " | |
1106 | "Found: {}".format(tc_name, dut, result) | |
1107 | ) | |
1108 | ||
1109 | logger.info("[Phase 4] : R1 is about to come up now ") | |
1110 | start_router_daemons(tgen, "r1", ["bgpd"]) | |
1111 | ||
1112 | logger.info("[Phase 5] : R1 is UP now, so time to collect GR stats ") | |
1113 | ||
1114 | for addr_type in ADDR_TYPES: | |
1115 | result = verify_graceful_restart( | |
1116 | tgen, topo, addr_type, input_dict, dut="r1", peer="r2" | |
1117 | ) | |
1118 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
1119 | tc_name, result | |
1120 | ) | |
1121 | ||
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) | |
1128 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
1129 | tc_name, result | |
1130 | ) | |
1131 | ||
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( | |
1135 | tc_name, result | |
1136 | ) | |
1137 | ||
1138 | write_test_footer(tc_name) | |
1139 | ||
1140 | ||
1141 | def test_BGP_GR_TC_31_2_p1(request): | |
1142 | """ | |
1143 | After BGP neighborship is established and GR capability is exchanged, | |
1144 | transition restarting router to disabled state and vice versa. | |
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( | |
1162 | "[Phase 1] : Test Setup " "[Disable Mode]R1-----R2[Restart Mode] initialized " | |
1163 | ) | |
1164 | ||
1165 | # Configure graceful-restart | |
1166 | input_dict = { | |
1167 | "r2": { | |
1168 | "bgp": { | |
1169 | "address_family": { | |
1170 | "ipv4": { | |
1171 | "unicast": { | |
1172 | "neighbor": { | |
1173 | "r1": { | |
1174 | "dest_link": { | |
1175 | "r2-link1": {"graceful-restart-helper": True} | |
1176 | } | |
1177 | } | |
1178 | } | |
1179 | } | |
1180 | }, | |
1181 | "ipv6": { | |
1182 | "unicast": { | |
1183 | "neighbor": { | |
1184 | "r1": { | |
1185 | "dest_link": { | |
1186 | "r2-link1": {"graceful-restart-helper": True} | |
1187 | } | |
1188 | } | |
1189 | } | |
1190 | } | |
1191 | }, | |
1192 | } | |
1193 | } | |
1194 | }, | |
1195 | "r1": { | |
1196 | "bgp": { | |
1197 | "address_family": { | |
1198 | "ipv4": { | |
1199 | "unicast": { | |
1200 | "neighbor": { | |
1201 | "r2": { | |
1202 | "dest_link": { | |
1203 | "r1-link1": {"graceful-restart-disable": True} | |
1204 | } | |
1205 | } | |
1206 | } | |
1207 | } | |
1208 | }, | |
1209 | "ipv6": { | |
1210 | "unicast": { | |
1211 | "neighbor": { | |
1212 | "r2": { | |
1213 | "dest_link": { | |
1214 | "r1-link1": {"graceful-restart-disable": True} | |
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 | ||
1254 | logger.info("[Phase 2] : R2 Goes from Disable to Restart Mode ") | |
1255 | ||
1256 | # Configure graceful-restart | |
1257 | input_dict = { | |
1258 | "r1": { | |
1259 | "bgp": { | |
1260 | "graceful-restart": {"preserve-fw-state": True}, | |
1261 | "address_family": { | |
1262 | "ipv4": { | |
1263 | "unicast": { | |
1264 | "neighbor": { | |
1265 | "r2": { | |
1266 | "dest_link": { | |
1267 | "r1-link1": {"graceful-restart": True} | |
1268 | } | |
1269 | } | |
1270 | } | |
1271 | } | |
1272 | }, | |
1273 | "ipv6": { | |
1274 | "unicast": { | |
1275 | "neighbor": { | |
1276 | "r2": { | |
1277 | "dest_link": { | |
1278 | "r1-link1": {"graceful-restart": True} | |
1279 | } | |
1280 | } | |
1281 | } | |
1282 | } | |
1283 | }, | |
1284 | }, | |
1285 | } | |
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: | |
1293 | neighbor = topo["routers"]["r2"]["links"]["r1-link1"][addr_type].split("/")[0] | |
1294 | clear_bgp(tgen, addr_type, "r1", neighbor=neighbor) | |
1295 | ||
1296 | result = verify_bgp_convergence_from_running_config(tgen) | |
1297 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
1298 | ||
1299 | # Verify GR stats | |
1300 | input_dict = { | |
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 | }, | |
1329 | "r1": { | |
1330 | "bgp": { | |
1331 | "address_family": { | |
1332 | "ipv4": { | |
1333 | "unicast": { | |
1334 | "neighbor": { | |
1335 | "r2": { | |
1336 | "dest_link": { | |
1337 | "r1-link1": {"graceful-restart": True} | |
1338 | } | |
1339 | } | |
1340 | } | |
1341 | } | |
1342 | }, | |
1343 | "ipv6": { | |
1344 | "unicast": { | |
1345 | "neighbor": { | |
1346 | "r2": { | |
1347 | "dest_link": { | |
1348 | "r1-link1": {"graceful-restart": True} | |
1349 | } | |
1350 | } | |
1351 | } | |
1352 | } | |
1353 | }, | |
1354 | } | |
1355 | } | |
1356 | }, | |
1357 | } | |
1358 | ||
1359 | # here the verify_graceful_restart fro the neighbor would be | |
1360 | # "NotReceived" as the latest GR config is not yet applied. | |
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 | ||
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"]) | |
1382 | ||
1383 | logger.info("[Phase 4] : R1 is UP now, so time to collect GR stats ") | |
1384 | ||
1385 | for addr_type in ADDR_TYPES: | |
1386 | result = verify_graceful_restart( | |
1387 | tgen, topo, addr_type, input_dict, dut="r1", peer="r2" | |
1388 | ) | |
1389 | assert result is True, "Testcase {} : Failed \n Error {}".format( | |
1390 | tc_name, result | |
1391 | ) | |
1392 | ||
1393 | # Verifying BGP RIB routes | |
1394 | next_hop = next_hop_per_address_family( | |
1395 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
1396 | ) | |
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( | |
1400 | tc_name, result | |
1401 | ) | |
1402 | ||
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 | ) | |
1408 | ||
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 ") | |
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 | ||
1442 | # Verifying BGP RIB routes | |
1443 | next_hop = next_hop_per_address_family( | |
1444 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
1445 | ) | |
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( | |
1455 | tc_name, result | |
1456 | ) | |
1457 | ||
1458 | write_test_footer(tc_name) | |
1459 | ||
1460 | ||
1461 | def test_BGP_GR_TC_9_p1(request): | |
1462 | """ | |
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. | |
1465 | """ | |
1466 | ||
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( | |
1482 | "[Phase 1] : Test Setup" " [Restart Mode]R1-----R2[Helper Mode] Initiliazed " | |
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 | }, | |
1512 | } | |
1513 | } | |
1514 | }, | |
1515 | "r2": { | |
1516 | "bgp": { | |
1517 | "graceful-restart": {"preserve-fw-state": True}, | |
1518 | "address_family": { | |
1519 | "ipv4": { | |
1520 | "unicast": { | |
1521 | "neighbor": { | |
1522 | "r1": { | |
1523 | "dest_link": { | |
1524 | "r2-link1": {"graceful-restart-helper": True} | |
1525 | } | |
1526 | } | |
1527 | } | |
1528 | } | |
1529 | }, | |
1530 | "ipv6": { | |
1531 | "unicast": { | |
1532 | "neighbor": { | |
1533 | "r1": { | |
1534 | "dest_link": { | |
1535 | "r2-link1": {"graceful-restart-helper": True} | |
1536 | } | |
1537 | } | |
1538 | } | |
1539 | } | |
1540 | }, | |
1541 | }, | |
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 | ) | |
1552 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
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) | |
1562 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
1563 | ||
1564 | # Verifying RIB routes | |
1565 | protocol = "bgp" | |
1566 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
1567 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
1568 | ||
1569 | logger.info("[Phase 2] : R2 goes for reload ") | |
1570 | kill_router_daemons(tgen, "r2", ["bgpd"]) | |
1571 | ||
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 | ) | |
1576 | ||
1577 | for addr_type in ADDR_TYPES: | |
1578 | # Verifying BGP RIB routes | |
1579 | next_hop = next_hop_per_address_family( | |
1580 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
1581 | ) | |
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 | |
1585 | ) | |
1586 | assert result is not True, ( | |
1587 | "Testcase {} : Failed \n " | |
1588 | "Expected: Routes should not be present in {} BGP RIB \n " | |
1589 | "Found: {}".format(tc_name, dut, result) | |
1590 | ) | |
1591 | ||
1592 | # Verifying RIB routes | |
1593 | protocol = "bgp" | |
1594 | result = verify_rib( | |
1595 | tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False | |
1596 | ) | |
1597 | assert result is not True, ( | |
1598 | "Testcase {} : Failed \n " | |
1599 | "Expected: Routes should not be present in {} FIB \n " | |
1600 | "Found: {}".format(tc_name, dut, result) | |
1601 | ) | |
1602 | ||
1603 | logger.info("[Phase 5] : R2 is about to come up now ") | |
1604 | start_router_daemons(tgen, "r2", ["bgpd"]) | |
1605 | ||
1606 | logger.info("[Phase 4] : R2 is UP now, so time to collect GR stats ") | |
1607 | ||
1608 | for addr_type in ADDR_TYPES: | |
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 | ||
1614 | result = verify_graceful_restart( | |
1615 | tgen, topo, addr_type, input_dict, dut="r1", peer="r2" | |
1616 | ) | |
1617 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
1618 | ||
1619 | result = verify_graceful_restart( | |
1620 | tgen, topo, addr_type, input_dict, dut="r2", peer="r1" | |
1621 | ) | |
1622 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
1623 | ||
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) | |
1626 | ||
1627 | result = verify_f_bit( | |
1628 | tgen, topo, addr_type, input_dict, dut="r1", peer="r2", expected=False | |
1629 | ) | |
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) | |
1634 | ) | |
1635 | ||
1636 | write_test_footer(tc_name) | |
1637 | ||
1638 | ||
1639 | def test_BGP_GR_TC_17_p1(request): | |
1640 | """ | |
1641 | Test Objective : Verify that only GR helper routers keep the stale | |
1642 | route entries, not any GR disabled router. | |
1643 | """ | |
1644 | ||
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 | ||
1659 | logger.info("[Phase 1] : Test Setup [Disable]R1-----R2[Restart] " "Initiliazed ") | |
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": { | |
1675 | "r1-link1": {"graceful-restart-disable": True} | |
1676 | } | |
1677 | } | |
1678 | } | |
1679 | } | |
1680 | }, | |
1681 | "ipv6": { | |
1682 | "unicast": { | |
1683 | "neighbor": { | |
1684 | "r2": { | |
1685 | "dest_link": { | |
1686 | "r1-link1": {"graceful-restart-disable": True} | |
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": { | |
1703 | "r2-link1": {"graceful-restart": True} | |
1704 | } | |
1705 | } | |
1706 | } | |
1707 | } | |
1708 | }, | |
1709 | "ipv6": { | |
1710 | "unicast": { | |
1711 | "neighbor": { | |
1712 | "r1": { | |
1713 | "dest_link": { | |
1714 | "r2-link1": {"graceful-restart": True} | |
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 | ) | |
1731 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
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) | |
1741 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
1742 | ||
1743 | # Verifying RIB routes | |
1744 | protocol = "bgp" | |
1745 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
1746 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
1747 | ||
1748 | logger.info("[Phase 2] : R2 goes for reload ") | |
1749 | ||
1750 | kill_router_daemons(tgen, "r2", ["bgpd"]) | |
1751 | ||
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 | ||
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 | ) | |
1766 | assert result is not True, ( | |
1767 | "Testcase {} : Failed \n " | |
1768 | "Expected: Routes should not be present in {} BGP RIB \n " | |
1769 | "Found: {}".format(tc_name, dut, result) | |
1770 | ) | |
1771 | ||
1772 | # Verifying RIB routes | |
1773 | protocol = "bgp" | |
1774 | result = verify_rib( | |
1775 | tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False | |
1776 | ) | |
1777 | assert result is not True, ( | |
1778 | "Testcase {} : Failed \n " | |
1779 | "Expected: Routes should not be present in {} FIB \n " | |
1780 | "Found: {}".format(tc_name, dut, result) | |
1781 | ) | |
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: | |
1789 | result = verify_bgp_convergence(tgen, topo) | |
1790 | assert ( | |
1791 | result is True | |
1792 | ), "BGP Convergence after BGPd restart" " :Failed \n Error:{}".format(result) | |
1793 | ||
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) | |
1798 | ||
1799 | result = verify_r_bit( | |
1800 | tgen, topo, addr_type, input_dict, dut="r1", peer="r2", expected=False | |
1801 | ) | |
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) | |
1806 | ) | |
1807 | ||
1808 | # Verifying BGP RIB routes | |
1809 | next_hop = next_hop_per_address_family( | |
1810 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
1811 | ) | |
1812 | input_topo = {key: topo["routers"][key] for key in ["r2"]} | |
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) | |
1815 | ||
1816 | # Verifying RIB routes | |
1817 | protocol = "bgp" | |
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 | ||
1821 | write_test_footer(tc_name) | |
1822 | ||
1823 | ||
1824 | def test_BGP_GR_TC_43_p1(request): | |
1825 | """ | |
1826 | Test Objective : Transition from Global Restarting to Disable | |
1827 | and then Global Disable to Restarting. | |
1828 | ||
1829 | """ | |
1830 | ||
1831 | tgen = get_topogen() | |
1832 | tc_name = request.node.name | |
1833 | write_test_header(tc_name) | |
1834 | ||
1835 | # Check router status | |
1836 | check_router_status(tgen) | |
1837 | ||
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") | |
1846 | ||
1847 | input_dict = { | |
1848 | "r1": { | |
1849 | "bgp": { | |
1850 | "graceful-restart": { | |
1851 | "graceful-restart": True, | |
1852 | } | |
1853 | } | |
1854 | }, | |
1855 | "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}, | |
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 | ||
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) | |
1881 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
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) | |
1891 | protocol = "bgp" | |
1892 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
1893 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
1894 | ||
1895 | step("Kill BGP on R1") | |
1896 | ||
1897 | kill_router_daemons(tgen, "r1", ["bgpd"]) | |
1898 | ||
1899 | step( | |
1900 | "Verify that R1 keeps BGP routes in zebra and R2 retains" | |
1901 | " the stale entry for received routes from R1" | |
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) | |
1913 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
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) | |
1923 | protocol = "bgp" | |
1924 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
1925 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
1926 | ||
1927 | step("Bring up BGPd on R1 and configure it as GR disabled node in global level") | |
1928 | ||
1929 | start_router_daemons(tgen, "r1", ["bgpd"]) | |
1930 | ||
1931 | input_dict = { | |
1932 | "r1": { | |
1933 | "bgp": { | |
1934 | "graceful-restart": { | |
1935 | "graceful-restart": False, | |
1936 | "graceful-restart-disable": True, | |
1937 | } | |
1938 | } | |
1939 | } | |
1940 | } | |
1941 | ||
1942 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
1943 | ||
1944 | step("Verify on R2 that R1 doesn't advertise any GR capabilities") | |
1945 | ||
1946 | input_dict = { | |
1947 | "r1": { | |
1948 | "bgp": { | |
1949 | "graceful-restart": { | |
1950 | "graceful-restart-disable": True, | |
1951 | } | |
1952 | } | |
1953 | }, | |
1954 | "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}, | |
1955 | } | |
1956 | ||
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) | |
1962 | ||
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) | |
1987 | protocol = "bgp" | |
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( | |
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" | |
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"]} | |
2008 | result = verify_rib( | |
2009 | tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False | |
2010 | ) | |
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) | |
2015 | ) | |
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 | |
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 " | |
2028 | "Expected: Routes should not be present in {} BGP RIB \n " | |
2029 | "Found: {}".format(tc_name, dut, result) | |
2030 | ) | |
2031 | ||
2032 | protocol = "bgp" | |
2033 | result = verify_rib( | |
2034 | tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False | |
2035 | ) | |
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) | |
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}}}} | |
2049 | ||
2050 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
2051 | ||
2052 | step("Verify on R2 that R1 advertises GR capabilities as a restarting node") | |
2053 | ||
2054 | input_dict = { | |
2055 | "r1": { | |
2056 | "bgp": { | |
2057 | "graceful-restart": { | |
2058 | "graceful-restart": True, | |
2059 | } | |
2060 | } | |
2061 | }, | |
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) | |
2070 | ||
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( | |
2111 | "Verify that R1 keeps BGP routes in zebra and R2" | |
2112 | " retains the stale entry for received routes from R1" | |
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 | ||
2148 | def test_BGP_GR_TC_44_p1(request): | |
2149 | """ | |
2150 | Test Objective : Transition from Global Helper to Disable | |
2151 | and then Global Disable to Helper. | |
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( | |
2170 | "Configure R2 as GR restating node in global level and" | |
2171 | " leave R1 without any GR related config" | |
2172 | ) | |
2173 | ||
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 | ||
2180 | input_dict = { | |
2181 | "r1": { | |
2182 | "bgp": { | |
2183 | "graceful-restart": { | |
2184 | "graceful-restart-helper": True, | |
2185 | } | |
2186 | } | |
2187 | }, | |
2188 | "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}, | |
2189 | } | |
2190 | ||
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) | |
2196 | ||
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: | |
2203 | dut = "r2" | |
2204 | peer = "r1" | |
2205 | protocol = "bgp" | |
2206 | next_hop = next_hop_per_address_family( | |
2207 | tgen, dut, peer, addr_type, NEXT_HOP_IP_1 | |
2208 | ) | |
2209 | input_topo = {"r1": topo["routers"]["r1"]} | |
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 | ||
2213 | dut = "r1" | |
2214 | peer = "r2" | |
2215 | next_hop = next_hop_per_address_family( | |
2216 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
2217 | ) | |
2218 | input_topo = {"r2": topo["routers"]["r2"]} | |
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 | ||
2224 | step("Kill BGP on R2") | |
2225 | ||
2226 | kill_router_daemons(tgen, "r2", ["bgpd"]) | |
2227 | ||
2228 | step("Verify that R1 keeps stale entry for BGP routes when BGPd on R2 is down") | |
2229 | ||
2230 | for addr_type in ADDR_TYPES: | |
2231 | dut = "r2" | |
2232 | peer = "r1" | |
2233 | protocol = "bgp" | |
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"]} | |
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 | |
2245 | ) | |
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) | |
2251 | ||
2252 | step("Bring up BGPd on R2 and configure R1 as GR disabled node in global level") | |
2253 | ||
2254 | start_router_daemons(tgen, "r2", ["bgpd"]) | |
2255 | ||
2256 | input_dict = { | |
2257 | "r1": { | |
2258 | "bgp": { | |
2259 | "graceful-restart": { | |
2260 | "graceful-restart-disable": True, | |
2261 | } | |
2262 | } | |
2263 | } | |
2264 | } | |
2265 | ||
2266 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
2267 | ||
2268 | step("Verify on R2 that R1 doesn't advertise any GR capabilities") | |
2269 | ||
2270 | input_dict = { | |
2271 | "r1": { | |
2272 | "bgp": { | |
2273 | "graceful-restart": { | |
2274 | "graceful-restart-disable": True, | |
2275 | } | |
2276 | } | |
2277 | }, | |
2278 | "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}, | |
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: | |
2292 | dut = "r2" | |
2293 | peer = "r1" | |
2294 | protocol = "bgp" | |
2295 | next_hop = next_hop_per_address_family( | |
2296 | tgen, dut, peer, addr_type, NEXT_HOP_IP_1 | |
2297 | ) | |
2298 | input_topo = {"r1": topo["routers"]["r1"]} | |
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 | ||
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: | |
2313 | dut = "r2" | |
2314 | peer = "r1" | |
2315 | protocol = "bgp" | |
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"]} | |
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 | ||
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 " | |
2338 | "Expected: Routes should not be present in {} BGP RIB \n " | |
2339 | "Found: {}".format(tc_name, dut, result) | |
2340 | ) | |
2341 | ||
2342 | result = verify_rib( | |
2343 | tgen, addr_type, dut, input_topo, next_hop, protocol, expected=False | |
2344 | ) | |
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) | |
2349 | ) | |
2350 | ||
2351 | step("Bring up BGPd on R2 and remove GR related config from R1 in global level") | |
2352 | ||
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) | |
2395 | ||
2396 | dut = "r1" | |
2397 | peer = "r2" | |
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"]} | |
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) | |
2404 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
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") | |
2412 | ||
2413 | for addr_type in ADDR_TYPES: | |
2414 | dut = "r2" | |
2415 | peer = "r1" | |
2416 | protocol = "bgp" | |
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"]} | |
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"]} | |
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) | |
2433 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
2434 | ||
2435 | write_test_footer(tc_name) | |
2436 | ||
2437 | ||
2438 | def test_BGP_GR_TC_45_p1(request): | |
2439 | """ | |
2440 | Test Objective : Transition from Global Restart to Helper | |
2441 | and then Global Helper to Restart. | |
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 | ||
2459 | step("Configure R1 and R2 as GR restarting node in global level") | |
2460 | ||
2461 | input_dict = { | |
2462 | "r1": {"bgp": {"graceful-restart": {"graceful-restart": True}}}, | |
2463 | "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}, | |
2464 | } | |
2465 | ||
2466 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
2467 | ||
2468 | step("Verify on R2 that R1 advertises GR capabilities as a restarting node") | |
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 | ||
2502 | step("Kill BGP on R1") | |
2503 | ||
2504 | kill_router_daemons(tgen, "r1", ["bgpd"]) | |
2505 | ||
2506 | step( | |
2507 | "Verify that R1 keeps BGP routes in zebra and R2" | |
2508 | " retains the stale entry for received routes from R1" | |
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 | ||
2533 | step("Bring up BGPd on R1 and remove GR related config in global level") | |
2534 | ||
2535 | start_router_daemons(tgen, "r1", ["bgpd"]) | |
2536 | ||
2537 | input_dict = { | |
2538 | "r1": { | |
2539 | "bgp": { | |
2540 | "graceful-restart": { | |
2541 | "graceful-restart": False, | |
2542 | } | |
2543 | } | |
2544 | } | |
2545 | } | |
2546 | ||
2547 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
2548 | ||
2549 | step("Verify on R2 that R1 advertises GR capabilities as a helper node") | |
2550 | ||
2551 | input_dict = { | |
2552 | "r1": { | |
2553 | "bgp": { | |
2554 | "graceful-restart": { | |
2555 | "graceful-restart-helper": True, | |
2556 | } | |
2557 | } | |
2558 | }, | |
2559 | "r2": {"bgp": {"graceful-restart": {"graceful-restart": True}}}, | |
2560 | } | |
2561 | ||
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) | |
2581 | assert ( | |
2582 | result is True | |
2583 | ), "Testcase {} :Failed \n Routes are still present \n Error {}".format( | |
2584 | tc_name, result | |
2585 | ) | |
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) | |
2596 | assert ( | |
2597 | result is True | |
2598 | ), "Testcase {} :Failed \n Routes are still present \n Error {}".format( | |
2599 | tc_name, result | |
2600 | ) | |
2601 | ||
2602 | step("Kill BGP on R2") | |
2603 | ||
2604 | kill_router_daemons(tgen, "r2", ["bgpd"]) | |
2605 | ||
2606 | step("Verify that R1 keeps stale entry for BGP routes when BGPd on R2 is down") | |
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) | |
2617 | assert ( | |
2618 | result is True | |
2619 | ), "Testcase {} :Failed \n Routes are still present \n Error {}".format( | |
2620 | tc_name, result | |
2621 | ) | |
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"]} | |
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 | |
2636 | ) | |
2637 | ||
2638 | step("Bring up BGPd on R2 and configure R1 as GR restarting node in global level") | |
2639 | ||
2640 | start_router_daemons(tgen, "r2", ["bgpd"]) | |
2641 | ||
2642 | input_dict = { | |
2643 | "r1": { | |
2644 | "bgp": { | |
2645 | "graceful-restart": { | |
2646 | "graceful-restart": True, | |
2647 | } | |
2648 | } | |
2649 | } | |
2650 | } | |
2651 | ||
2652 | configure_gr_followed_by_clear(tgen, topo, input_dict, tc_name, dut="r1", peer="r2") | |
2653 | ||
2654 | step("Verify on R2 that R1 advertises GR capabilities as a restarting node") | |
2655 | ||
2656 | input_dict = { | |
2657 | "r1": { | |
2658 | "bgp": { | |
2659 | "graceful-restart": { | |
2660 | "graceful-restart": True, | |
2661 | } | |
2662 | } | |
2663 | }, | |
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: | |
2678 | dut = "r1" | |
2679 | peer = "r2" | |
2680 | protocol = "bgp" | |
2681 | next_hop = next_hop_per_address_family( | |
2682 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
2683 | ) | |
2684 | input_topo = {"r2": topo["routers"]["r2"]} | |
2685 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
2686 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
2687 | ||
2688 | dut = "r2" | |
2689 | peer = "r1" | |
2690 | next_hop = next_hop_per_address_family( | |
2691 | tgen, dut, peer, addr_type, NEXT_HOP_IP_1 | |
2692 | ) | |
2693 | input_topo = {"r1": topo["routers"]["r1"]} | |
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) | |
2697 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
2698 | ||
2699 | step("Kill BGP on R1") | |
2700 | ||
2701 | kill_router_daemons(tgen, "r1", ["bgpd"]) | |
2702 | ||
2703 | step( | |
2704 | "Verify that R1 keeps BGP routes in zebra and R2" | |
2705 | " retains the stale entry for received routes from R1" | |
2706 | ) | |
2707 | ||
2708 | for addr_type in ADDR_TYPES: | |
2709 | dut = "r1" | |
2710 | peer = "r2" | |
2711 | protocol = "bgp" | |
2712 | next_hop = next_hop_per_address_family( | |
2713 | tgen, dut, peer, addr_type, NEXT_HOP_IP_2 | |
2714 | ) | |
2715 | input_topo = {"r2": topo["routers"]["r2"]} | |
2716 | result = verify_rib(tgen, addr_type, dut, input_topo, next_hop, protocol) | |
2717 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
2718 | ||
2719 | dut = "r2" | |
2720 | peer = "r1" | |
2721 | next_hop = next_hop_per_address_family( | |
2722 | tgen, dut, peer, addr_type, NEXT_HOP_IP_1 | |
2723 | ) | |
2724 | input_topo = {"r1": topo["routers"]["r1"]} | |
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) | |
2728 | assert result is True, "Testcase {} :Failed \n Error {}".format(tc_name, result) | |
2729 | ||
2730 | write_test_footer(tc_name) | |
2731 | ||
2732 | ||
2733 | if __name__ == "__main__": | |
2734 | args = ["-s"] + sys.argv[1:] | |
2735 | sys.exit(pytest.main(args)) |