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