]>
Commit | Line | Data |
---|---|---|
441875ea | 1 | #!/usr/bin/env python |
acddc0ed | 2 | # SPDX-License-Identifier: ISC |
441875ea | 3 | |
4 | # | |
5 | # Copyright (c) 2022 by VMware, Inc. ("VMware") | |
6 | # Used Copyright (c) 2018 by Network Device Education Foundation, | |
7 | # Inc. ("NetDEF") in this file. | |
8 | # | |
441875ea | 9 | |
10 | import sys | |
11 | import time | |
12 | import pytest | |
13 | import inspect | |
14 | import os | |
15 | from copy import deepcopy | |
16 | ||
17 | # Save the Current Working Directory to find configuration files. | |
18 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
19 | sys.path.append(os.path.join(CWD, "../")) | |
20 | sys.path.append(os.path.join(CWD, "../lib/")) | |
21 | ||
22 | """Following tests are covered to test bgp unique rid functionality. | |
23 | 1. Verify eBGP session when same and different router ID is configured. | |
24 | 2. Verify iBGP session when same and different router ID is configured. | |
25 | 3. Verify two different eBGP sessions initiated with same router ID. | |
26 | 4. Chaos - Verify bgp unique rid functionality in chaos scenarios. | |
27 | 5. Chaos - Verify bgp unique rid functionality when router reboots with same loopback id. | |
28 | 6. Chaos - Verify bgp unique rid functionality when router reboots without any ip addresses. | |
29 | """ | |
30 | ||
31 | ################################# | |
32 | # TOPOLOGY | |
33 | ################################# | |
34 | """ | |
35 | ||
36 | +-------+ | |
37 | +--------- | R2 | | |
38 | | +-------+ | |
39 | |iBGP | | |
40 | +-------+ | | |
41 | | R1 | |iBGP | |
42 | +-------+ | | |
43 | | | | |
44 | | iBGP +-------+ eBGP +-------+ | |
45 | +---------- | R3 |========= | R4 | | |
46 | +-------+ +-------+ | |
47 | | | |
48 | |eBGP | |
49 | | | |
50 | +-------+ | |
51 | | R5 | | |
52 | +-------+ | |
53 | ||
54 | ||
55 | """ | |
56 | ||
57 | # pylint: disable=C0413 | |
58 | # Import topogen and topotest helpers | |
59 | from lib.topogen import Topogen, get_topogen | |
60 | from lib.topojson import build_config_from_json | |
61 | from lib.topolog import logger | |
62 | ||
63 | pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd, pytest.mark.staticd] | |
64 | ||
65 | # Required to instantiate the topology builder class. | |
66 | from lib.common_config import ( | |
67 | start_topology, | |
68 | write_test_header, | |
69 | step, | |
70 | write_test_footer, | |
71 | verify_rib, | |
72 | check_address_types, | |
73 | reset_config_on_routers, | |
74 | check_router_status, | |
75 | stop_router, | |
76 | kill_router_daemons, | |
77 | start_router_daemons, | |
78 | start_router, | |
79 | ) | |
80 | from lib.topolog import logger | |
81 | from lib.bgp import ( | |
82 | verify_bgp_convergence, | |
83 | create_router_bgp, | |
84 | clear_bgp_and_verify, | |
85 | ) | |
86 | ||
87 | # Global variables | |
88 | topo = None | |
89 | bgp_convergence = False | |
90 | NETWORK = { | |
91 | "ipv4": [ | |
92 | "192.168.20.1/32", | |
93 | "192.168.20.2/32", | |
94 | "192.168.21.1/32", | |
95 | "192.168.21.2/32", | |
96 | "192.168.22.1/32", | |
97 | "192.168.22.2/32", | |
98 | ], | |
99 | "ipv6": [ | |
100 | "fc07:50::1/128", | |
101 | "fc07:50::2/128", | |
102 | "fc07:150::1/128", | |
103 | "fc07:150::2/128", | |
104 | "fc07:1::1/128", | |
105 | "fc07:1::2/128", | |
106 | ], | |
107 | } | |
108 | ||
109 | bgp_convergence = False | |
110 | ADDR_TYPES = check_address_types() | |
111 | routerid = {"ipv4": "10.10.10.14", "ipv6": "fd00:0:0:3::2"} | |
112 | ||
113 | ||
114 | def setup_module(mod): | |
115 | """setup_module. | |
116 | ||
117 | Set up the pytest environment | |
118 | * `mod`: module name | |
119 | """ | |
120 | global topo | |
121 | testsuite_run_time = time.asctime(time.localtime(time.time())) | |
122 | logger.info("Testsuite start time: {}".format(testsuite_run_time)) | |
123 | logger.info("=" * 40) | |
124 | ||
125 | logger.info("Running setup_module to create topology") | |
126 | ||
127 | # This function initiates the topology build with Topogen... | |
128 | json_file = "{}/bgp_unique_rid.json".format(CWD) | |
129 | tgen = Topogen(json_file, mod.__name__) | |
130 | global topo | |
131 | topo = tgen.json_topo | |
132 | # ... and here it calls Mininet initialization functions. | |
133 | ||
134 | # Starting topology, create tmp files which are loaded to routers | |
135 | # to start daemons and then start routers | |
136 | start_topology(tgen) | |
137 | ||
138 | # Creating configuration from JSON | |
139 | build_config_from_json(tgen, topo) | |
140 | ||
141 | # Checking BGP convergence | |
142 | global bgp_convergence | |
143 | global ADDR_TYPES | |
144 | ||
145 | # Don't run this test if we have any failure. | |
146 | if tgen.routers_have_failure(): | |
147 | pytest.skip(tgen.errors) | |
148 | ||
149 | # Api call verify whether BGP is converged | |
150 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
151 | assert bgp_convergence is True, "setup_module :Failed \n Error:" " {}".format( | |
152 | bgp_convergence | |
153 | ) | |
154 | logger.info("Running setup_module() done") | |
155 | ||
156 | ||
157 | def teardown_module(): | |
158 | """Teardown the pytest environment""" | |
159 | ||
160 | logger.info("Running teardown_module to delete topology") | |
161 | ||
162 | tgen = get_topogen() | |
163 | ||
164 | # Stop toplogy and Remove tmp files | |
165 | tgen.stop_topology() | |
166 | ||
167 | logger.info( | |
168 | "Testsuite end time: {}".format(time.asctime(time.localtime(time.time()))) | |
169 | ) | |
170 | logger.info("=" * 40) | |
171 | ||
172 | ||
173 | ##################################################### | |
174 | # Tests starting | |
175 | ##################################################### | |
176 | ||
177 | ||
178 | def test_bgp_unique_rid_ebgp_p0(): | |
179 | """ | |
180 | TC: 1 | |
181 | Verify eBGP session when same and different router ID is configured. | |
182 | """ | |
183 | tgen = get_topogen() | |
184 | global bgp_convergence | |
185 | ||
186 | if bgp_convergence is not True: | |
187 | pytest.skip("skipped because of BGP Convergence failure") | |
188 | ||
189 | # test case name | |
190 | tc_name = inspect.stack()[0][3] | |
191 | write_test_header(tc_name) | |
192 | if tgen.routers_have_failure(): | |
193 | check_router_status(tgen) | |
194 | ||
195 | step("Configure base config as per the topology") | |
196 | reset_config_on_routers(tgen) | |
197 | ||
198 | step( | |
199 | "Base config should be up, verify using BGP convergence on all \ | |
200 | the routers for IPv4 and IPv6 nbrs" | |
201 | ) | |
202 | ||
203 | result = verify_bgp_convergence(tgen, topo) | |
204 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
205 | ||
206 | step("Configure the same router id between R4 and R3 10.10.10.10") | |
207 | input_dict = { | |
208 | "r3": {"bgp": {"router_id": "10.10.10.10"}}, | |
209 | "r4": {"bgp": {"router_id": "10.10.10.10"}}, | |
210 | } | |
211 | result = create_router_bgp(tgen, topo, input_dict) | |
212 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
213 | ||
214 | step("Verify neighbours are in ESTAB state.") | |
215 | result = verify_bgp_convergence(tgen, topo) | |
216 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
217 | ||
218 | step("Configure the same router id between R5 and R3 (10.10.10.10)") | |
219 | input_dict = { | |
220 | "r3": {"bgp": {"router_id": "10.10.10.10"}}, | |
221 | "r5": {"bgp": {"router_id": "10.10.10.10"}}, | |
222 | } | |
223 | result = create_router_bgp(tgen, topo, input_dict) | |
224 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
225 | ||
226 | step("Verify neighbours are in ESTAB state.") | |
227 | result = verify_bgp_convergence(tgen, topo) | |
228 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
229 | ||
230 | step("modify the router id on r3 to different router id (11.11.11.11)") | |
231 | input_dict = {"r3": {"bgp": {"router_id": "11.11.11.11"}}} | |
232 | result = create_router_bgp(tgen, topo, input_dict) | |
233 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
234 | ||
235 | step("Verify neighbours are in ESTAB state.") | |
236 | result = verify_bgp_convergence(tgen, topo) | |
237 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
238 | ||
239 | step("Reset bgp process") | |
240 | step("Verify neighbours are in ESTAB state.") | |
241 | dut = "r3" | |
242 | result = clear_bgp_and_verify(tgen, topo, dut) | |
243 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
244 | ||
245 | step("Clear ip bgp process with *") | |
246 | step("Verify neighbours are in ESTAB state.") | |
247 | result = clear_bgp_and_verify(tgen, topo, dut) | |
248 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
249 | ||
250 | step("Configure neighbours between R3 and R4 in EVPN address family.") | |
251 | input_dict = { | |
252 | "r3": { | |
253 | "bgp": { | |
254 | "address_family": { | |
255 | "l2vpn": { | |
256 | "evpn": { | |
257 | "advertise": { | |
258 | "ipv4": {"unicast": {}}, | |
259 | "ipv6": {"unicast": {}}, | |
260 | } | |
261 | } | |
262 | } | |
263 | } | |
264 | } | |
265 | }, | |
266 | "r4": { | |
267 | "bgp": { | |
268 | "address_family": { | |
269 | "l2vpn": { | |
270 | "evpn": { | |
271 | "advertise": { | |
272 | "ipv4": {"unicast": {}}, | |
273 | "ipv6": {"unicast": {}}, | |
274 | } | |
275 | } | |
276 | } | |
277 | } | |
278 | } | |
279 | }, | |
280 | } | |
281 | result = create_router_bgp(tgen, topo, input_dict) | |
282 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
283 | ||
284 | step("Verify neighbours are in ESTAB state.") | |
285 | result = clear_bgp_and_verify(tgen, topo, dut) | |
286 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
287 | ||
288 | write_test_footer(tc_name) | |
289 | ||
290 | ||
291 | def test_bgp_unique_rid_ibgp_p0(): | |
292 | """ | |
293 | TC: 2 | |
294 | Verify iBGP session when same and different router ID is configured. | |
295 | """ | |
296 | tgen = get_topogen() | |
297 | global bgp_convergence | |
298 | ||
299 | if bgp_convergence is not True: | |
300 | pytest.skip("skipped because of BGP Convergence failure") | |
301 | ||
302 | # test case name | |
303 | tc_name = inspect.stack()[0][3] | |
304 | write_test_header(tc_name) | |
305 | if tgen.routers_have_failure(): | |
306 | check_router_status(tgen) | |
307 | ||
308 | step("Configure base config as per the topology") | |
309 | reset_config_on_routers(tgen) | |
310 | ||
311 | step( | |
312 | "Base config should be up, verify using BGP convergence on all \ | |
313 | the routers for IPv4 and IPv6 nbrs" | |
314 | ) | |
315 | ||
316 | result = verify_bgp_convergence(tgen, topo) | |
317 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
318 | ||
319 | step("Configure the same router id between R1 and R3 (10.10.10.10)") | |
320 | input_dict = { | |
321 | "r3": {"bgp": {"router_id": "10.10.10.10"}}, | |
322 | "r1": {"bgp": {"router_id": "10.10.10.10"}}, | |
323 | } | |
324 | result = create_router_bgp(tgen, topo, input_dict) | |
325 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
326 | ||
327 | step("Verify neighbours are in idle state.") | |
328 | result = verify_bgp_convergence(tgen, topo, expected=False) | |
329 | assert result is not True, "Testcase {} :Failed \n Error: {}".format( | |
330 | tc_name, result | |
331 | ) | |
332 | ||
333 | step("Configure the same router id between R2 and R3 (10.10.10.10)") | |
334 | input_dict = { | |
335 | "r3": {"bgp": {"router_id": "10.10.10.10"}}, | |
336 | "r2": {"bgp": {"router_id": "10.10.10.10"}}, | |
337 | } | |
338 | result = create_router_bgp(tgen, topo, input_dict) | |
339 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
340 | ||
341 | step("Verify neighbours are in idle state.") | |
342 | result = verify_bgp_convergence(tgen, topo, expected=False) | |
343 | assert result is not True, "Testcase {} :Failed \n Error: {}".format( | |
344 | tc_name, result | |
345 | ) | |
346 | ||
347 | step("modify the router id on r3 to different router id (11.11.11.11)") | |
348 | input_dict = {"r3": {"bgp": {"router_id": "11.11.11.11"}}} | |
349 | result = create_router_bgp(tgen, topo, input_dict) | |
350 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
351 | ||
352 | step("Verify neighbours are in ESTAB state.") | |
353 | result = verify_bgp_convergence(tgen, topo, dut="r3") | |
354 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
355 | ||
356 | step("Reset bgp process") | |
357 | step("Verify neighbours are in ESTAB state.") | |
358 | dut = "r3" | |
359 | result = clear_bgp_and_verify(tgen, topo, dut) | |
360 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
361 | ||
362 | step("Clear ip bgp process with *") | |
363 | result = clear_bgp_and_verify(tgen, topo, dut) | |
364 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
365 | ||
366 | write_test_footer(tc_name) | |
367 | ||
368 | ||
369 | def test_bgp_unique_rid_multi_bgp_nbrs_p0(): | |
370 | """ | |
371 | TC: 3 | |
372 | 3. Verify two different eBGP sessions initiated with same router ID | |
373 | ||
374 | """ | |
375 | tgen = get_topogen() | |
376 | global bgp_convergence, topo | |
377 | ||
378 | if bgp_convergence is not True: | |
379 | pytest.skip("skipped because of BGP Convergence failure") | |
380 | ||
381 | # test case name | |
382 | tc_name = inspect.stack()[0][3] | |
383 | write_test_header(tc_name) | |
384 | if tgen.routers_have_failure(): | |
385 | check_router_status(tgen) | |
386 | ||
387 | step("Configure base config as per the topology") | |
388 | reset_config_on_routers(tgen) | |
389 | ||
390 | step( | |
391 | "Base config should be up, verify using BGP convergence on all \ | |
392 | the routers for IPv4 and IPv6 nbrs" | |
393 | ) | |
394 | ||
395 | result = verify_bgp_convergence(tgen, topo) | |
396 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
397 | ||
398 | step("Configure the same router id between R3, R4 and R5 (10.10.10.10)") | |
399 | input_dict = { | |
400 | "r3": {"bgp": {"router_id": "10.10.10.10"}}, | |
401 | "r4": {"bgp": {"router_id": "10.10.10.10"}}, | |
402 | "r5": {"bgp": {"router_id": "10.10.10.10"}}, | |
403 | } | |
404 | result = create_router_bgp(tgen, topo, input_dict) | |
405 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
406 | ||
407 | step("Verify neighbours are in ESTAB state.") | |
408 | result = verify_bgp_convergence(tgen, topo) | |
409 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
410 | ||
411 | step( | |
412 | "Configure the same IP address on on R4 and R5 loopback address and \ | |
413 | change the neighborship to loopback neighbours between R3 to R4 \ | |
414 | and R3 to R5 respectively." | |
415 | ) | |
416 | ||
417 | topo1 = deepcopy(topo) | |
418 | ||
419 | for rtr in ["r4", "r5"]: | |
420 | topo1["routers"][rtr]["links"]["lo"]["ipv4"] = "192.168.1.1/32" | |
421 | ||
422 | topo1["routers"]["r3"]["links"]["lo"]["ipv4"] = "192.168.1.3/32" | |
423 | build_config_from_json(tgen, topo1, save_bkup=False) | |
424 | ||
425 | step( | |
426 | "change the neighborship to loopback neighbours between R3 to R4 and R3 to R5 respectively." | |
427 | ) | |
428 | for rtr in ["r4", "r5"]: | |
429 | configure_bgp_on_rtr = { | |
430 | "r3": { | |
431 | "bgp": { | |
432 | "address_family": { | |
433 | "ipv4": { | |
434 | "unicast": {"neighbor": {rtr: {"dest_link": {"lo": {}}}}} | |
435 | } | |
436 | } | |
437 | }, | |
438 | } | |
439 | } | |
440 | result = create_router_bgp(tgen, topo1, configure_bgp_on_rtr) | |
441 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
442 | tc_name, result | |
443 | ) | |
444 | ||
445 | bgp_convergence = verify_bgp_convergence(tgen, topo1, dut="r3") | |
446 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
447 | tc_name, bgp_convergence | |
448 | ) | |
449 | ||
450 | step("Change the IP address on the R4 loopback.") | |
451 | topo1["routers"]["r4"]["links"]["lo"]["ipv4"] = "192.168.1.4/32" | |
452 | build_config_from_json(tgen, topo1, save_bkup=False) | |
453 | ||
454 | step("Verify neighbours should be again in ESTAB state. (show ip bgp neighbours)") | |
455 | bgp_convergence = verify_bgp_convergence(tgen, topo1, dut="r3") | |
456 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
457 | tc_name, bgp_convergence | |
458 | ) | |
459 | ||
460 | step("Clear ip bgp process with *") | |
461 | result = clear_bgp_and_verify(tgen, topo, router="r3") | |
462 | assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result) | |
463 | ||
464 | write_test_footer(tc_name) | |
465 | ||
466 | ||
467 | def test_bgp_unique_rid_chaos1_p2(): | |
468 | """ | |
469 | TC: 4 | |
470 | 4. Chaos - Verify bgp unique rid functionality in chaos scenarios. | |
471 | ||
472 | """ | |
473 | tgen = get_topogen() | |
474 | global bgp_convergence | |
475 | ||
476 | if bgp_convergence is not True: | |
477 | pytest.skip("skipped because of BGP Convergence failure") | |
478 | ||
479 | # test case name | |
480 | tc_name = inspect.stack()[0][3] | |
481 | write_test_header(tc_name) | |
482 | if tgen.routers_have_failure(): | |
483 | check_router_status(tgen) | |
484 | ||
485 | step("Configure base config as per the topology") | |
486 | reset_config_on_routers(tgen) | |
487 | ||
488 | step( | |
489 | "Base config should be up, verify using BGP convergence on all \ | |
490 | the routers for IPv4 and IPv6 nbrs" | |
491 | ) | |
492 | ||
493 | result = verify_bgp_convergence(tgen, topo) | |
494 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
495 | ||
496 | step("Configure the same router id between R3, R4 and R5 (10.10.10.10)") | |
497 | input_dict = { | |
498 | "r3": {"bgp": {"router_id": "10.10.10.10"}}, | |
499 | "r4": {"bgp": {"router_id": "10.10.10.10"}}, | |
500 | "r5": {"bgp": {"router_id": "10.10.10.10"}}, | |
501 | } | |
502 | result = create_router_bgp(tgen, topo, input_dict) | |
503 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
504 | ||
505 | step("Verify neighbours are in ESTAB state.") | |
506 | result = verify_bgp_convergence(tgen, topo) | |
507 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
508 | ||
509 | step( | |
510 | "Verify eBGP session when same router ID is configured and bgpd process is restarted" | |
511 | ) | |
512 | ||
513 | # restart bgpd router and verify | |
514 | kill_router_daemons(tgen, "r3", ["bgpd"]) | |
515 | start_router_daemons(tgen, "r3", ["bgpd"]) | |
516 | ||
517 | step( | |
518 | "The session should be established between R3 & R4. " | |
519 | "Once after restart bgp, neighbor should come back up ." | |
520 | ) | |
521 | ||
522 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
523 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
524 | tc_name, bgp_convergence | |
525 | ) | |
526 | ||
527 | step( | |
528 | "Verify eBGP session when same router ID is configured and neighbor shutdown is issued and again no shutdown." | |
529 | ) | |
530 | ||
531 | input_dict = { | |
532 | "r3": { | |
533 | "bgp": { | |
534 | "local_as": "100", | |
535 | "address_family": { | |
536 | "ipv4": { | |
537 | "unicast": { | |
538 | "neighbor": { | |
539 | "r4": { | |
540 | "dest_link": { | |
541 | "r3-link1": {"shutdown": True}, | |
542 | "r3-link2": {"shutdown": True}, | |
543 | "r3-link3": {"shutdown": True}, | |
544 | "r3-link4": {"shutdown": True}, | |
545 | "r3-link5": {"shutdown": True}, | |
546 | "r3-link6": {"shutdown": True}, | |
547 | "r3-link7": {"shutdown": True}, | |
548 | } | |
549 | }, | |
550 | "r5": {"dest_link": {"r3": {"shutdown": True}}}, | |
551 | } | |
552 | } | |
553 | }, | |
554 | "ipv6": { | |
555 | "unicast": { | |
556 | "neighbor": { | |
557 | "r4": { | |
558 | "dest_link": { | |
559 | "r3-link1": {"shutdown": True}, | |
560 | "r3-link2": {"shutdown": True}, | |
561 | "r3-link3": {"shutdown": True}, | |
562 | "r3-link4": {"shutdown": True}, | |
563 | "r3-link5": {"shutdown": True}, | |
564 | "r3-link6": {"shutdown": True}, | |
565 | "r3-link7": {"shutdown": True}, | |
566 | } | |
567 | }, | |
568 | "r5": {"dest_link": {"r3": {"shutdown": True}}}, | |
569 | } | |
570 | } | |
571 | }, | |
572 | }, | |
573 | } | |
574 | } | |
575 | } | |
576 | result = create_router_bgp(tgen, topo, input_dict) | |
577 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
578 | ||
579 | input_dict = { | |
580 | "r3": { | |
581 | "bgp": { | |
582 | "local_as": "100", | |
583 | "address_family": { | |
584 | "ipv4": { | |
585 | "unicast": { | |
586 | "neighbor": { | |
587 | "r4": { | |
588 | "dest_link": { | |
589 | "r3-link1": {"shutdown": False}, | |
590 | "r3-link2": {"shutdown": False}, | |
591 | "r3-link3": {"shutdown": False}, | |
592 | "r3-link4": {"shutdown": False}, | |
593 | "r3-link5": {"shutdown": False}, | |
594 | "r3-link6": {"shutdown": False}, | |
595 | "r3-link7": {"shutdown": False}, | |
596 | } | |
597 | }, | |
598 | "r5": {"dest_link": {"r3": {"shutdown": False}}}, | |
599 | } | |
600 | } | |
601 | }, | |
602 | "ipv6": { | |
603 | "unicast": { | |
604 | "neighbor": { | |
605 | "r4": { | |
606 | "dest_link": { | |
607 | "r3-link1": {"shutdown": False}, | |
608 | "r3-link2": {"shutdown": False}, | |
609 | "r3-link3": {"shutdown": False}, | |
610 | "r3-link4": {"shutdown": False}, | |
611 | "r3-link5": {"shutdown": False}, | |
612 | "r3-link6": {"shutdown": False}, | |
613 | "r3-link7": {"shutdown": False}, | |
614 | } | |
615 | }, | |
616 | "r5": {"dest_link": {"r3": {"shutdown": False}}}, | |
617 | } | |
618 | } | |
619 | }, | |
620 | }, | |
621 | } | |
622 | } | |
623 | } | |
624 | result = create_router_bgp(tgen, topo, input_dict) | |
625 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
626 | ||
627 | step( | |
628 | "The session should be established between R3 & R4. " | |
629 | "Once after restart bgp, neighbor should come back up ." | |
630 | ) | |
631 | ||
632 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
633 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
634 | tc_name, bgp_convergence | |
635 | ) | |
636 | ||
637 | step( | |
638 | "Verify eBGP session when same router ID is configured and neighbor config is deleted & reconfigured." | |
639 | ) | |
640 | ||
641 | input_dict = { | |
642 | "r3": { | |
643 | "bgp": { | |
644 | "local_as": "100", | |
645 | "address_family": { | |
646 | "ipv4": { | |
647 | "unicast": { | |
648 | "neighbor": { | |
649 | "r4": { | |
650 | "dest_link": { | |
651 | "r3-link1": {}, | |
652 | "r3-link2": {}, | |
653 | "r3-link3": {}, | |
654 | "r3-link4": {}, | |
655 | "r3-link5": {}, | |
656 | "r3-link6": {}, | |
657 | "r3-link7": {}, | |
658 | } | |
659 | }, | |
660 | "r5": {"dest_link": {"r3": {}}}, | |
661 | } | |
662 | } | |
663 | }, | |
664 | "ipv6": { | |
665 | "unicast": { | |
666 | "neighbor": { | |
667 | "r4": { | |
668 | "dest_link": { | |
669 | "r3-link1": {}, | |
670 | "r3-link2": {}, | |
671 | "r3-link3": {}, | |
672 | "r3-link4": {}, | |
673 | "r3-link5": {}, | |
674 | "r3-link6": {}, | |
675 | "r3-link7": {}, | |
676 | } | |
677 | }, | |
678 | "r5": {"dest_link": {"r3": {}}}, | |
679 | } | |
680 | } | |
681 | }, | |
682 | }, | |
683 | } | |
684 | } | |
685 | } | |
686 | result = create_router_bgp(tgen, topo, input_dict) | |
687 | assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result) | |
688 | ||
689 | step( | |
690 | "The session should be established between R3 & R4. " | |
691 | "Once after restart bgp, neighbor should come back up ." | |
692 | ) | |
693 | ||
694 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
695 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
696 | tc_name, bgp_convergence | |
697 | ) | |
698 | ||
699 | step( | |
700 | "Verify eBGP session when same router ID is configured and FRR router is restarted." | |
701 | ) | |
702 | stop_router(tgen, "r3") | |
703 | start_router(tgen, "r3") | |
704 | ||
705 | step( | |
706 | "The session should be established between R3 & R4. " | |
707 | "Once after restart bgp, neighbor should come back up ." | |
708 | ) | |
709 | ||
710 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
711 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
712 | tc_name, bgp_convergence | |
713 | ) | |
714 | ||
715 | step( | |
716 | "Verify eBGP session when same router ID is configured and zebra process is restarted" | |
717 | ) | |
718 | ||
719 | kill_router_daemons(tgen, "r3", ["zebra"]) | |
720 | start_router_daemons(tgen, "r3", ["zebra"]) | |
721 | ||
722 | step( | |
723 | "The session should be established between R3 & R4. " | |
724 | "Once after restart bgp, neighbor should come back up ." | |
725 | ) | |
726 | ||
727 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
728 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
729 | tc_name, bgp_convergence | |
730 | ) | |
731 | ||
732 | write_test_footer(tc_name) | |
733 | ||
734 | ||
735 | def test_bgp_unique_rid_chaos3_p2(): | |
736 | """ | |
737 | TC: 4 | |
738 | 4. Chaos - Verify bgp unique rid functionality when router reboots with same loopback id. | |
739 | ||
740 | """ | |
741 | tgen = get_topogen() | |
742 | global bgp_convergence | |
743 | ||
744 | if bgp_convergence is not True: | |
745 | pytest.skip("skipped because of BGP Convergence failure") | |
746 | ||
747 | # test case name | |
748 | tc_name = inspect.stack()[0][3] | |
749 | write_test_header(tc_name) | |
750 | if tgen.routers_have_failure(): | |
751 | check_router_status(tgen) | |
752 | ||
753 | step("Configure base config as per the topology") | |
754 | reset_config_on_routers(tgen) | |
755 | ||
756 | global topo | |
757 | topo1 = deepcopy(topo) | |
758 | ||
759 | for rtr in topo["routers"].keys(): | |
760 | topo1["routers"][rtr]["links"]["lo"]["ipv4"] = "192.168.1.1/32" | |
761 | ||
762 | topo1["routers"]["r3"]["links"]["lo"]["ipv4"] = "192.168.1.3/32" | |
763 | build_config_from_json(tgen, topo1, save_bkup=False) | |
764 | ||
765 | step("verify bgp convergence before starting test case") | |
766 | ||
767 | bgp_convergence = verify_bgp_convergence(tgen, topo1) | |
768 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
769 | tc_name, bgp_convergence | |
770 | ) | |
771 | ||
772 | step( | |
773 | "Configure loopback on R1 to R5 with IP address 1.1.1.1 on all the routers. Change neighborship on all the routers using loopback neighborship ids." | |
774 | ) | |
775 | for rtr in ["r1", "r2", "r4", "r5"]: | |
776 | configure_bgp_on_rtr = { | |
777 | "r3": { | |
778 | "bgp": { | |
779 | "address_family": { | |
780 | "ipv4": { | |
781 | "unicast": {"neighbor": {rtr: {"dest_link": {"lo": {}}}}} | |
782 | } | |
783 | } | |
784 | }, | |
785 | } | |
786 | } | |
787 | result = create_router_bgp(tgen, topo1, configure_bgp_on_rtr) | |
788 | assert result is True, "Testcase {} : Failed \n Error: {}".format( | |
789 | tc_name, result | |
790 | ) | |
791 | ||
792 | bgp_convergence = verify_bgp_convergence(tgen, topo1, dut="r3") | |
793 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
794 | tc_name, bgp_convergence | |
795 | ) | |
796 | ||
797 | step("Reboot the router (restart frr) or using watch frr.") | |
798 | stop_router(tgen, "r3") | |
799 | start_router(tgen, "r3") | |
800 | ||
801 | step("Neighbors between R3, R4 and R3 to R5 should be in ESTB state.") | |
802 | bgp_convergence = verify_bgp_convergence(tgen, topo1, dut="r3") | |
803 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
804 | tc_name, bgp_convergence | |
805 | ) | |
806 | ||
807 | step("Clear bgp process.") | |
808 | clear_bgp_and_verify(tgen, topo, "r3") | |
809 | ||
810 | step("Neighbors between R3, R4 and R3 to R5 should be in ESTB state.") | |
811 | bgp_convergence = verify_bgp_convergence(tgen, topo1, dut="r3") | |
812 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
813 | tc_name, bgp_convergence | |
814 | ) | |
815 | ||
816 | write_test_footer(tc_name) | |
817 | ||
818 | ||
819 | def test_bgp_unique_rid_chaos4_p2(): | |
820 | """ | |
821 | TC: 6 | |
822 | 6. Chaos - Verify bgp unique rid functionality when router reboots without any ip addresses. | |
823 | ||
824 | """ | |
825 | tgen = get_topogen() | |
826 | global bgp_convergence | |
827 | ||
828 | if bgp_convergence is not True: | |
829 | pytest.skip("skipped because of BGP Convergence failure") | |
830 | ||
831 | # test case name | |
832 | tc_name = inspect.stack()[0][3] | |
833 | write_test_header(tc_name) | |
834 | if tgen.routers_have_failure(): | |
835 | check_router_status(tgen) | |
836 | ||
837 | reset_config_on_routers(tgen) | |
838 | ||
839 | global topo | |
840 | topo1 = deepcopy(topo) | |
841 | topo2 = deepcopy(topo) | |
842 | ||
843 | step( | |
844 | "Configure base config as per the topology without loopback as well as Ip address on any of the interface." | |
845 | ) | |
846 | for rtr in topo["routers"].keys(): | |
847 | for intf in topo["routers"][rtr]["links"].keys(): | |
848 | topo1["routers"][rtr]["links"][intf].pop("ipv4") | |
849 | topo1["routers"][rtr]["links"][intf].pop("ipv6") | |
850 | if intf is "lo": | |
851 | topo1["routers"][rtr]["links"][intf].pop("ipv4") | |
852 | ||
853 | build_config_from_json(tgen, topo1, save_bkup=False) | |
854 | ||
855 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
856 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
857 | tc_name, bgp_convergence | |
858 | ) | |
859 | ||
860 | step("Configure the ip addresses on the physical interfaces") | |
861 | build_config_from_json(tgen, topo2, save_bkup=False) | |
862 | ||
863 | step("All the neighbors should be in ESTAB state.") | |
864 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
865 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
866 | tc_name, bgp_convergence | |
867 | ) | |
868 | ||
869 | step("Configure loopback addresses with higher IP address ") | |
870 | build_config_from_json(tgen, topo, save_bkup=False) | |
871 | ||
872 | step("All the neighbors should be in ESTAB state.") | |
873 | bgp_convergence = verify_bgp_convergence(tgen, topo) | |
874 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
875 | tc_name, bgp_convergence | |
876 | ) | |
877 | ||
878 | step("Reboot the router (restart frr) or using watch frr.") | |
879 | stop_router(tgen, "r3") | |
880 | start_router(tgen, "r3") | |
881 | ||
882 | step("Neighbors between R3, R4 and R3 to R5 should be in ESTB state.") | |
883 | bgp_convergence = verify_bgp_convergence(tgen, topo, dut="r3") | |
884 | assert bgp_convergence is True, "Testcase {} : Failed \n Error: {}".format( | |
885 | tc_name, bgp_convergence | |
886 | ) | |
887 | ||
888 | write_test_footer(tc_name) | |
889 | ||
890 | ||
891 | if __name__ == "__main__": | |
892 | args = ["-s"] + sys.argv[1:] | |
893 | sys.exit(pytest.main(args)) |