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