]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_recursive_route_ebgp_multi_hop/test_bgp_recursive_route_ebgp_multi_hop.py
Merge pull request #12818 from imzyxwvu/fix/other-table-inactive
[mirror_frr.git] / tests / topotests / bgp_recursive_route_ebgp_multi_hop / test_bgp_recursive_route_ebgp_multi_hop.py
1 #!/usr/bin/python
2 # SPDX-License-Identifier: ISC
3 #
4 # Copyright (c) 2020 by VMware, Inc. ("VMware")
5 # Used Copyright (c) 2018 by Network Device Education Foundation,
6 # Inc. ("NetDEF") in this file.
7 #
8
9 """
10 Following tests are covered to test bgp recursive route and ebgp
11 multi-hop functionality:
12
13 1. Verify that BGP routes are installed in iBGP peer, only when there
14 is a recursive route for next-hop reachability.
15 2. Verify that any BGP prefix received with next hop as self-ip is
16 not installed in BGP RIB or FIB table.
17 3. Verify password authentication for eBGP and iBGP peers.
18 4. Verify that for a BGP prefix next-hop information doesn't change
19 when same prefix is received from another peer via recursive lookup.
20 5. Verify that BGP path attributes are present in CLI outputs and
21 JSON format, even if set to default.
22 6. Verifying the BGP peering between loopback and physical link's IP
23 of 2 peer routers.
24 7. Verify that BGP Active/Standby/Pre-emption/ECMP.
25 """
26
27 import os
28 import sys
29 import time
30 import pytest
31 from time import sleep
32
33 # Save the Current Working Directory to find configuration files.
34 CWD = os.path.dirname(os.path.realpath(__file__))
35 sys.path.append(os.path.join(CWD, "../"))
36
37 # pylint: disable=C0413
38 # Import topogen and topotest helpers
39 from lib.topogen import Topogen, get_topogen
40
41 # Import topoJson from lib, to create topology and initial configuration
42 from lib.common_config import (
43 start_topology,
44 write_test_header,
45 apply_raw_config,
46 write_test_footer,
47 reset_config_on_routers,
48 verify_rib,
49 create_static_routes,
50 check_address_types,
51 step,
52 create_route_maps,
53 create_interface_in_kernel,
54 shutdown_bringup_interface,
55 )
56 from lib.topolog import logger
57 from lib.bgp import (
58 verify_bgp_convergence,
59 create_router_bgp,
60 verify_bgp_rib,
61 verify_bgp_convergence_from_running_config,
62 modify_as_number,
63 verify_bgp_attributes,
64 clear_bgp,
65 )
66 from lib.topojson import build_config_from_json
67
68
69 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
70
71
72 # Global variables
73 BGP_CONVERGENCE = False
74 KEEP_ALIVE_TIMER = 2
75 HOLD_DOWN_TIMER = 6
76 ADDR_TYPES = check_address_types()
77 NETWORK = {
78 "ipv4": ["100.1.1.1/32", "100.1.1.2/32"],
79 "ipv6": ["100::1/128", "100::2/128"],
80 }
81
82 RECUR_NEXT_HOP = {
83 "N1": {"ipv4": "20.20.20.20/24", "ipv6": "20:20::20:20/120"},
84 "N2": {"ipv4": "30.30.30.30/24", "ipv6": "30:30::30:30/120"},
85 "N3": {"ipv4": "40.40.40.40/24", "ipv6": "40:40::40:40/120"},
86 }
87
88 CHANGED_NEXT_HOP = {
89 "4thOctate": {"ipv4": "10.0.1.250/24", "ipv6": "fd00:0:0:1::100/64"},
90 "3rdOctate": {"ipv4": "10.0.10.2/24", "ipv6": "fd00:0:0:10::2/64"},
91 }
92
93 Loopabck_IP = {
94 "Lo_R1": {"ipv4": "1.1.1.1/32", "ipv6": "1:1::1:1/128"},
95 "Lo_R4": {"ipv4": "4.4.4.4/32", "ipv6": "4:4::4:4/128"},
96 }
97
98
99 def setup_module(mod):
100 """
101 Sets up the pytest environment
102
103 * `mod`: module name
104 """
105
106 testsuite_run_time = time.asctime(time.localtime(time.time()))
107 logger.info("Testsuite start time: {}".format(testsuite_run_time))
108 logger.info("=" * 40)
109
110 logger.info("Running setup_module to create topology")
111
112 # This function initiates the topology build with Topogen...
113 json_file = "{}/bgp_recursive_route_ebgp_multi_hop.json".format(CWD)
114 tgen = Topogen(json_file, mod.__name__)
115 global topo
116 topo = tgen.json_topo
117 # ... and here it calls Mininet initialization functions.
118
119 # Starting topology, create tmp files which are loaded to routers
120 # to start daemons and then start routers
121 start_topology(tgen)
122
123 # Creating configuration from JSON
124 build_config_from_json(tgen, topo)
125
126 global BGP_CONVERGENCE
127 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
128 assert BGP_CONVERGENCE is True, "setup_module : Failed \n Error : {}".format(
129 BGP_CONVERGENCE
130 )
131
132 logger.info("Running setup_module() done")
133
134
135 def teardown_module():
136 """Teardown the pytest environment"""
137
138 logger.info("Running teardown_module to delete topology")
139
140 tgen = get_topogen()
141
142 # Stop toplogy and Remove tmp files
143 tgen.stop_topology()
144
145 logger.info(
146 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
147 )
148 logger.info("=" * 40)
149
150
151 #####################################################
152 #
153 # Tests starting
154 #
155 #####################################################
156
157
158 def test_recursive_routes_iBGP_peer_p1(request):
159 """
160 Verify that BGP routes are installed in iBGP peer, only
161 when there is a recursive route for next-hop reachability.
162 """
163
164 tc_name = request.node.name
165 write_test_header(tc_name)
166 tgen = get_topogen()
167
168 # Don"t run this test if we have any failure.
169 if tgen.routers_have_failure():
170 pytest.skip(tgen.errors)
171
172 step("Initial config :Configure BGP neighborship between R1 and R3.")
173 reset_config_on_routers(tgen)
174
175 dut = "r1"
176 protocol = "static"
177
178 step(
179 "Configure static routes on R1 pointing next-hop as connected"
180 "link between R1 & R3's IP"
181 )
182 for addr_type in ADDR_TYPES:
183 input_dict_4 = {
184 "r1": {
185 "static_routes": [
186 {
187 "network": NETWORK[addr_type],
188 "next_hop": topo["routers"]["r3"]["links"]["r1"][
189 addr_type
190 ].split("/")[0],
191 }
192 ]
193 }
194 }
195 result = create_static_routes(tgen, input_dict_4)
196
197 step(
198 "Verify on router R1 that these static routes are "
199 "installed in RIB+FIB of R1"
200 )
201 result = verify_rib(
202 tgen,
203 addr_type,
204 dut,
205 input_dict_4,
206 next_hop=topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0],
207 protocol=protocol,
208 )
209 assert result is True, "Testcase {} : Failed \n Error : {}".format(
210 tc_name, result
211 )
212
213 step("Redistribute these static routes in BGP on router R1")
214 input_dict_2 = {
215 "r1": {
216 "bgp": {
217 "address_family": {
218 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
219 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
220 }
221 }
222 }
223 }
224 result = create_router_bgp(tgen, topo, input_dict_2)
225
226 step(
227 "Verify on router R1 that these static routes are installed"
228 "in RIB table as well"
229 )
230 for addr_type in ADDR_TYPES:
231 input_dict_4 = {
232 "r1": {
233 "static_routes": [
234 {
235 "network": NETWORK[addr_type],
236 "next_hop": topo["routers"]["r3"]["links"]["r1"][
237 addr_type
238 ].split("/")[0],
239 }
240 ]
241 }
242 }
243 result = verify_bgp_rib(
244 tgen,
245 addr_type,
246 dut,
247 input_dict_4,
248 next_hop=topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0],
249 )
250 assert result is True, "Testcase {}: Failed \n Error : {}".format(
251 tc_name, result
252 )
253
254 step(
255 "Configure a static routes for next hop IP on R2 via multiple"
256 "recursive static routes"
257 )
258 dut = "r2"
259 create_interface_in_kernel(
260 tgen, dut, "lo", "40.40.40.50", netmask="255.255.255.0", create=True
261 )
262 create_interface_in_kernel(
263 tgen, dut, "lo", "40:40::40:50", netmask="120", create=True
264 )
265 for addr_type in ADDR_TYPES:
266 input_dict_3 = {
267 "r2": {
268 "static_routes": [
269 {
270 "network": topo["routers"]["r3"]["links"]["r1"][addr_type],
271 "next_hop": RECUR_NEXT_HOP["N1"][addr_type].split("/")[0],
272 },
273 {
274 "network": RECUR_NEXT_HOP["N1"][addr_type],
275 "next_hop": RECUR_NEXT_HOP["N2"][addr_type].split("/")[0],
276 },
277 {
278 "network": RECUR_NEXT_HOP["N2"][addr_type],
279 "next_hop": RECUR_NEXT_HOP["N3"][addr_type].split("/")[0],
280 },
281 ]
282 }
283 }
284 result = create_static_routes(tgen, input_dict_3)
285 assert result is True, "Testcase {}: Failed \n Error : {}".format(
286 tc_name, result
287 )
288
289 step("verify if redistributed routes are now installed in FIB of R2")
290 result = verify_rib(
291 tgen,
292 addr_type,
293 "r2",
294 input_dict_4,
295 next_hop=topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0],
296 protocol="bgp",
297 )
298 assert result is True, "Testcase {}: Failed \n Error : {}".format(
299 tc_name, result
300 )
301
302 step("Delete 1 route from static recursive for the next-hop IP")
303 dut = "r2"
304 for addr_type in ADDR_TYPES:
305 input_dict_3 = {
306 "r2": {
307 "static_routes": [
308 {
309 "network": RECUR_NEXT_HOP["N1"][addr_type],
310 "next_hop": RECUR_NEXT_HOP["N2"][addr_type].split("/")[0],
311 "delete": True,
312 }
313 ]
314 }
315 }
316 result = create_static_routes(tgen, input_dict_3)
317 assert result is True, "Testcase {}: Failed \n Error : {}".format(
318 tc_name, result
319 )
320
321 step("Verify that redistributed routes are withdrawn from FIB of R2")
322 result = verify_rib(
323 tgen,
324 addr_type,
325 dut,
326 input_dict_4,
327 next_hop=topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0],
328 protocol="bgp",
329 expected=False,
330 )
331 assert (
332 result is not True
333 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
334 tc_name, result
335 )
336
337 step("Reconfigure the same static route on R2 again")
338 dut = "r2"
339 for addr_type in ADDR_TYPES:
340 input_dict_3 = {
341 "r2": {
342 "static_routes": [
343 {
344 "network": RECUR_NEXT_HOP["N1"][addr_type],
345 "next_hop": RECUR_NEXT_HOP["N2"][addr_type].split("/")[0],
346 }
347 ]
348 }
349 }
350 result = create_static_routes(tgen, input_dict_3)
351 assert result is True, "Testcase {}: Failed \n Error : {}".format(
352 tc_name, result
353 )
354
355 step("Verify that redistributed routes are again installed" "in FIB of R2")
356 result = verify_rib(
357 tgen,
358 addr_type,
359 dut,
360 input_dict_4,
361 next_hop=topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0],
362 protocol="bgp",
363 )
364 assert result is True, "Testcase {}: Failed \n Error : {}".format(
365 tc_name, result
366 )
367
368 step("Configure static route with changed next-hop from same subnet")
369 for addr_type in ADDR_TYPES:
370 input_dict_4 = {
371 "r1": {
372 "static_routes": [
373 {
374 "network": NETWORK[addr_type],
375 "next_hop": topo["routers"]["r3"]["links"]["r1"][
376 addr_type
377 ].split("/")[0],
378 "delete": True,
379 },
380 {
381 "network": NETWORK[addr_type],
382 "next_hop": CHANGED_NEXT_HOP["4thOctate"][addr_type].split("/")[
383 0
384 ],
385 },
386 ]
387 }
388 }
389 result = create_static_routes(tgen, input_dict_4)
390 assert result is True, "Testcase {}: Failed \n Error : {}".format(
391 tc_name, result
392 )
393
394 result = verify_rib(tgen, addr_type, "r1", input_dict_4, protocol="static")
395 assert result is True, "Testcase {} : Failed \n Error : {}".format(
396 tc_name, result
397 )
398
399 step(
400 "Verify that redistributed routes are not withdrawn as changed"
401 "next-hop IP, belongs to the same subnet"
402 )
403 result = verify_rib(tgen, addr_type, "r2", input_dict_4, protocol="bgp")
404 assert result is True, "Testcase {} : Failed \n Error : {}".format(
405 tc_name, result
406 )
407
408 step("Configure static route with changed next-hop from different subnet")
409 dut = "r1"
410 create_interface_in_kernel(
411 tgen, dut, "lo10", "10.0.10.10", netmask="255.255.255.0", create=True
412 )
413 create_interface_in_kernel(
414 tgen, dut, "lo10", "fd00:0:0:10::104", netmask="64", create=True
415 )
416 for addr_type in ADDR_TYPES:
417 input_dict_4 = {
418 "r1": {
419 "static_routes": [
420 {
421 "network": NETWORK[addr_type],
422 "next_hop": CHANGED_NEXT_HOP["4thOctate"][addr_type].split("/")[
423 0
424 ],
425 "delete": True,
426 },
427 {
428 "network": NETWORK[addr_type],
429 "next_hop": CHANGED_NEXT_HOP["3rdOctate"][addr_type].split("/")[
430 0
431 ],
432 },
433 ]
434 }
435 }
436 result = create_static_routes(tgen, input_dict_4)
437 assert result is True, "Testcase {}: Failed \n Error : {}".format(
438 tc_name, result
439 )
440
441 result = verify_rib(tgen, addr_type, "r1", input_dict_4, protocol="static")
442 assert result is True, "Testcase {} : Failed \n Error : {}".format(
443 tc_name, result
444 )
445
446 step(
447 "Verify that redistributed routes are withdrawn as changed "
448 "next-hop IP, belongs to different subnet"
449 )
450 result = verify_rib(
451 tgen, addr_type, "r2", input_dict_4, protocol="bgp", expected=False
452 )
453 assert (
454 result is not True
455 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
456 tc_name, result
457 )
458
459 write_test_footer(tc_name)
460
461
462 def test_next_hop_as_self_ip_p1(request):
463 """
464 Verify that any BGP prefix received with next hop as
465 self-ip is not installed in BGP RIB or FIB table.
466 """
467
468 tc_name = request.node.name
469 write_test_header(tc_name)
470 tgen = get_topogen()
471
472 # Don"t run this test if we have any failure.
473 if tgen.routers_have_failure():
474 pytest.skip(tgen.errors)
475
476 step("Initial config :Configure BGP neighborship between R1 and R3.")
477 reset_config_on_routers(tgen)
478
479 step(
480 "Configure static routes on R1 with a next-hop IP belonging"
481 "to the same subnet of R2's link IP."
482 )
483 dut = "r1"
484 create_interface_in_kernel(
485 tgen,
486 dut,
487 "lo10",
488 topo["routers"]["r4"]["links"]["r2"]["ipv4"].split("/")[0],
489 netmask="255.255.255.0",
490 create=True,
491 )
492 create_interface_in_kernel(
493 tgen,
494 dut,
495 "lo10",
496 topo["routers"]["r4"]["links"]["r2"]["ipv6"].split("/")[0],
497 netmask="64",
498 create=True,
499 )
500 for addr_type in ADDR_TYPES:
501 input_dict_4 = {
502 "r1": {
503 "static_routes": [
504 {
505 "network": NETWORK[addr_type],
506 "next_hop": topo["routers"]["r2"]["links"]["r4"][
507 addr_type
508 ].split("/")[0],
509 }
510 ]
511 }
512 }
513 result = create_static_routes(tgen, input_dict_4)
514
515 step("Verify that static routes are installed in RIB and FIB of R1")
516 result = verify_rib(
517 tgen,
518 addr_type,
519 dut,
520 input_dict_4,
521 next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
522 protocol="static",
523 )
524 assert result is True, "Testcase {} : Failed \n Error : {}".format(
525 tc_name, result
526 )
527
528 step("Redistribute static routes into BGP on R1")
529 input_dict_2 = {
530 "r1": {
531 "bgp": {
532 "address_family": {
533 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
534 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
535 }
536 }
537 }
538 }
539 result = create_router_bgp(tgen, topo, input_dict_2)
540
541 step(
542 "Verify that R2 denies the prefixes received in update message,"
543 "as next-hop IP belongs to connected interface"
544 )
545 for addr_type in ADDR_TYPES:
546 input_dict_4 = {
547 "r1": {
548 "static_routes": [
549 {
550 "network": NETWORK[addr_type],
551 "next_hop": topo["routers"]["r2"]["links"]["r4"][
552 addr_type
553 ].split("/")[0],
554 }
555 ]
556 }
557 }
558 result = verify_bgp_rib(
559 tgen,
560 addr_type,
561 "r2",
562 input_dict_4,
563 next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
564 expected=False,
565 )
566 assert (
567 result is not True
568 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
569 tc_name, result
570 )
571
572 step("Shut interface on R2 that has IP from the subnet as BGP next-hop")
573 intf_r2_r4 = topo["routers"]["r2"]["links"]["r4"]["interface"]
574 shutdown_bringup_interface(tgen, "r2", intf_r2_r4)
575
576 for addr_type in ADDR_TYPES:
577 clear_bgp(tgen, addr_type, "r2")
578 step(
579 "Verify that redistributed routes now appear only in BGP table,"
580 "as next-hop IP is no more active on R2"
581 )
582 for addr_type in ADDR_TYPES:
583 input_dict_4 = {
584 "r1": {
585 "static_routes": [
586 {
587 "network": NETWORK[addr_type],
588 "next_hop": topo["routers"]["r2"]["links"]["r4"][
589 addr_type
590 ].split("/")[0],
591 }
592 ]
593 }
594 }
595 result = verify_bgp_rib(
596 tgen,
597 addr_type,
598 "r2",
599 input_dict_4,
600 next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
601 )
602 assert result is True, "Testcase {}: Failed \n Error : {}".format(
603 tc_name, result
604 )
605
606 step("No shutdown interface on R2 which was shut in previous step")
607 intf_r2_r4 = topo["routers"]["r2"]["links"]["r4"]["interface"]
608 shutdown_bringup_interface(tgen, "r2", intf_r2_r4, ifaceaction=True)
609
610 step(
611 "Verify that R2 dosn't install prefixes RIB to FIB as next-hop"
612 "interface is up now"
613 )
614 for addr_type in ADDR_TYPES:
615 input_dict_4 = {
616 "r1": {
617 "static_routes": [
618 {
619 "network": NETWORK[addr_type],
620 "next_hop": topo["routers"]["r2"]["links"]["r4"][
621 addr_type
622 ].split("/")[0],
623 }
624 ]
625 }
626 }
627 result = verify_bgp_rib(
628 tgen,
629 addr_type,
630 "r2",
631 input_dict_4,
632 next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
633 )
634 assert result is True, "Testcase {}: Failed \n Error : {}".format(
635 tc_name, result
636 )
637 result = verify_rib(
638 tgen,
639 addr_type,
640 "r2",
641 input_dict_4,
642 next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
643 expected=False,
644 )
645 assert (
646 result is not True
647 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
648 tc_name, result
649 )
650
651 write_test_footer(tc_name)
652
653
654 def test_next_hop_with_recursive_lookup_p1(request):
655 """
656 Verify that for a BGP prefix next-hop information doesn't change
657 when same prefix is received from another peer via recursive lookup.
658 """
659
660 tc_name = request.node.name
661 write_test_header(tc_name)
662 tgen = get_topogen()
663
664 # Don"t run this test if we have any failure.
665 if tgen.routers_have_failure():
666 pytest.skip(tgen.errors)
667
668 step("Initial config :Configure BGP neighborship between R1 and R3.")
669 reset_config_on_routers(tgen)
670
671 step("Verify that BGP peering comes up.")
672
673 result = verify_bgp_convergence_from_running_config(tgen)
674 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
675
676 step("Do redistribute connected on router R3.")
677 input_dict_1 = {
678 "r3": {
679 "bgp": {
680 "address_family": {
681 "ipv4": {
682 "unicast": {"redistribute": [{"redist_type": "connected"}]}
683 },
684 "ipv6": {
685 "unicast": {"redistribute": [{"redist_type": "connected"}]}
686 },
687 }
688 }
689 }
690 }
691
692 result = create_router_bgp(tgen, topo, input_dict_1)
693 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
694
695 step("Verify that R1 receives all connected")
696 for addr_type in ADDR_TYPES:
697 routes = {
698 "ipv4": ["1.0.3.17/32", "10.0.1.0/24", "10.0.3.0/24"],
699 "ipv6": ["2001:db8:f::3:17/128", "fd00:0:0:1::/64", "fd00:0:0:3::/64"],
700 }
701 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
702 result = verify_rib(tgen, addr_type, "r1", input_dict, protocol="bgp")
703 assert result is True, "Testcase {} : Failed \n Error : {}".format(
704 tc_name, result
705 )
706
707 step(
708 "Configure a BGP neighborship between R1 and R4, directly via "
709 "eBGP multi-hop."
710 )
711 r1_local_as = topo["routers"]["r1"]["bgp"]["local_as"]
712 r1_r3_addr = topo["routers"]["r1"]["links"]["r3"]
713 r4_local_as = topo["routers"]["r4"]["bgp"]["local_as"]
714 r4_r3_addr = topo["routers"]["r4"]["links"]["r3"]
715 ebgp_multi_hop = 3
716
717 for addr_type in ADDR_TYPES:
718 raw_config = {
719 "r1": {
720 "raw_config": [
721 "router bgp {}".format(r1_local_as),
722 "neighbor {} remote-as {}".format(
723 r4_r3_addr[addr_type].split("/")[0], r4_local_as
724 ),
725 "neighbor {} timers {} {}".format(
726 r4_r3_addr[addr_type].split("/")[0],
727 KEEP_ALIVE_TIMER,
728 HOLD_DOWN_TIMER,
729 ),
730 "neighbor {} ebgp-multihop {}".format(
731 r4_r3_addr[addr_type].split("/")[0], ebgp_multi_hop
732 ),
733 ]
734 },
735 "r4": {
736 "raw_config": [
737 "router bgp {}".format(r4_local_as),
738 "neighbor {} remote-as {}".format(
739 r1_r3_addr[addr_type].split("/")[0], r1_local_as
740 ),
741 "neighbor {} timers {} {}".format(
742 r1_r3_addr[addr_type].split("/")[0],
743 KEEP_ALIVE_TIMER,
744 HOLD_DOWN_TIMER,
745 ),
746 "neighbor {} ebgp-multihop {}".format(
747 r1_r3_addr[addr_type].split("/")[0], ebgp_multi_hop
748 ),
749 ]
750 },
751 }
752 result = apply_raw_config(tgen, raw_config)
753 assert result is True, "Testcase {} : Failed Error : {}".format(tc_name, result)
754
755 for addr_type in ADDR_TYPES:
756 if addr_type == "ipv4":
757 raw_config = {
758 "r1": {
759 "raw_config": [
760 "router bgp {}".format(r1_local_as),
761 "address-family {} unicast".format(addr_type),
762 "no neighbor {} activate".format(
763 r4_r3_addr["ipv6"].split("/")[0]
764 ),
765 ]
766 },
767 "r4": {
768 "raw_config": [
769 "router bgp {}".format(r4_local_as),
770 "address-family {} unicast".format(addr_type),
771 "no neighbor {} activate".format(
772 r1_r3_addr["ipv6"].split("/")[0]
773 ),
774 ]
775 },
776 }
777 else:
778 raw_config = {
779 "r1": {
780 "raw_config": [
781 "router bgp {}".format(r1_local_as),
782 "address-family {} unicast".format(addr_type),
783 "neighbor {} activate".format(
784 r4_r3_addr[addr_type].split("/")[0]
785 ),
786 ]
787 },
788 "r4": {
789 "raw_config": [
790 "router bgp {}".format(r4_local_as),
791 "address-family {} unicast".format(addr_type),
792 "neighbor {} activate".format(
793 r1_r3_addr[addr_type].split("/")[0]
794 ),
795 ]
796 },
797 }
798 result = apply_raw_config(tgen, raw_config)
799 assert result is True, "Testcase {} : Failed Error : {}".format(tc_name, result)
800
801 step("Verify that BGP session between R1 and R4 comes up" "(recursively via R3).")
802 result = verify_bgp_convergence_from_running_config(tgen)
803 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
804
805 step("Do redistribute connected on router R4.")
806 input_dict_1 = {
807 "r4": {
808 "bgp": {
809 "address_family": {
810 "ipv4": {
811 "unicast": {"redistribute": [{"redist_type": "connected"}]}
812 },
813 "ipv6": {
814 "unicast": {"redistribute": [{"redist_type": "connected"}]}
815 },
816 }
817 }
818 }
819 }
820
821 result = create_router_bgp(tgen, topo, input_dict_1)
822 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
823
824 step(
825 "Verify that R1 now receives BGP prefix of link r3-r4 via 2 "
826 "next-hops R3 and R4. however do not install with NHT R4 in FIB."
827 )
828 for addr_type in ADDR_TYPES:
829 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
830
831 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
832 next_hop = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
833
834 result = verify_rib(
835 tgen, addr_type, "r1", input_dict, protocol="bgp", next_hop=next_hop
836 )
837 assert result is True, "Testcase {} : Failed \n Error : {}".format(
838 tc_name, result
839 )
840
841 step("Clear bgp sessions from R1 using 'clear ip bgp *'")
842 for addr_type in ADDR_TYPES:
843 clear_bgp(tgen, addr_type, "r1")
844
845 step(
846 "Verify that prefix of link r3-r4 is again learned via 2 "
847 "next-hops (from R3 and R4 directly)"
848 )
849 for addr_type in ADDR_TYPES:
850 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
851
852 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
853 next_hop = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
854
855 result = verify_rib(
856 tgen, addr_type, "r1", input_dict, protocol="bgp", next_hop=next_hop
857 )
858 assert result is True, "Testcase {} : Failed \n Error : {}".format(
859 tc_name, result
860 )
861
862 step("Remove redistribution from router R3.")
863 input_dict_1 = {
864 "r3": {
865 "bgp": {
866 "local_as": "300",
867 "address_family": {
868 "ipv4": {
869 "unicast": {
870 "redistribute": [
871 {"redist_type": "connected", "delete": True}
872 ]
873 }
874 },
875 "ipv6": {
876 "unicast": {
877 "redistribute": [
878 {"redist_type": "connected", "delete": True}
879 ]
880 }
881 },
882 },
883 }
884 }
885 }
886
887 result = create_router_bgp(tgen, topo, input_dict_1)
888 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
889
890 step(
891 "Verify that peering between R1-R4 goes down and prefix "
892 "of link r3-r4, with NHT R4 is withdrawn."
893 )
894
895 logger.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER))
896 sleep(HOLD_DOWN_TIMER + 1)
897
898 result = verify_bgp_convergence_from_running_config(tgen, expected=False)
899 assert (
900 result is not True
901 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
902 tc_name, result
903 )
904 logger.info("Expected behaviour: {}".format(result))
905
906 for addr_type in ADDR_TYPES:
907 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
908
909 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
910 next_hop = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
911
912 result = verify_rib(
913 tgen, addr_type, "r1", input_dict, protocol="bgp", next_hop=next_hop
914 )
915 assert result is True, "Testcase {} : Failed \n Error : {}".format(
916 tc_name, result
917 )
918
919 step("Re-apply redistribution on R3.")
920
921 input_dict_1 = {
922 "r3": {
923 "bgp": {
924 "local_as": "300",
925 "address_family": {
926 "ipv4": {
927 "unicast": {"redistribute": [{"redist_type": "connected"}]}
928 },
929 "ipv6": {
930 "unicast": {"redistribute": [{"redist_type": "connected"}]}
931 },
932 },
933 }
934 }
935 }
936
937 result = create_router_bgp(tgen, topo, input_dict_1)
938 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
939
940 step(
941 "Verify that peering between R1-R4 goes down and prefix "
942 "of link r3-r4 with NHT R4 is withdrawn."
943 )
944
945 result = verify_bgp_convergence_from_running_config(tgen)
946 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
947
948 for addr_type in ADDR_TYPES:
949 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
950
951 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
952 next_hop = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
953
954 result = verify_rib(
955 tgen, addr_type, "r1", input_dict, protocol="bgp", next_hop=next_hop
956 )
957 assert result is True, "Testcase {} : Failed \n Error : {}".format(
958 tc_name, result
959 )
960
961 step("Remove redistribution from router R4.")
962
963 input_dict_1 = {
964 "r4": {
965 "bgp": {
966 "local_as": "400",
967 "address_family": {
968 "ipv4": {
969 "unicast": {
970 "redistribute": [
971 {"redist_type": "connected", "delete": True}
972 ]
973 }
974 },
975 "ipv6": {
976 "unicast": {
977 "redistribute": [
978 {"redist_type": "connected", "delete": True}
979 ]
980 }
981 },
982 },
983 }
984 }
985 }
986
987 result = create_router_bgp(tgen, topo, input_dict_1)
988 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
989
990 step(
991 "Verify that peering between R1-R4 doesn't go down but prefix "
992 "of link r3-r4 with NHT R4 is withdrawn."
993 )
994
995 logger.info("Sleeping for holddowntimer: {}".format(HOLD_DOWN_TIMER))
996 sleep(HOLD_DOWN_TIMER + 1)
997
998 result = verify_bgp_convergence_from_running_config(tgen)
999 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1000
1001 for addr_type in ADDR_TYPES:
1002 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1003
1004 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
1005 next_hop = topo["routers"]["r4"]["links"]["r3"][addr_type].split("/")[0]
1006
1007 result = verify_rib(
1008 tgen,
1009 addr_type,
1010 "r1",
1011 input_dict,
1012 protocol="bgp",
1013 next_hop=next_hop,
1014 expected=False,
1015 )
1016 assert (
1017 result is not True
1018 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1019 tc_name, result
1020 )
1021
1022 step("Re-apply redistribution on R4.")
1023
1024 input_dict_1 = {
1025 "r4": {
1026 "bgp": {
1027 "local_as": "400",
1028 "address_family": {
1029 "ipv4": {
1030 "unicast": {
1031 "redistribute": [
1032 {"redist_type": "connected", "delete": True}
1033 ]
1034 }
1035 },
1036 "ipv6": {
1037 "unicast": {
1038 "redistribute": [
1039 {"redist_type": "connected", "delete": True}
1040 ]
1041 }
1042 },
1043 },
1044 }
1045 }
1046 }
1047
1048 result = create_router_bgp(tgen, topo, input_dict_1)
1049 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1050
1051 step("Verify that prefix of link r3-r4 is re-learned via NHT R4.")
1052
1053 for addr_type in ADDR_TYPES:
1054 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1055
1056 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
1057 next_hop = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
1058
1059 result = verify_rib(
1060 tgen, addr_type, "r1", input_dict, protocol="bgp", next_hop=next_hop
1061 )
1062 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1063 tc_name, result
1064 )
1065
1066 step("Toggle the interface on R3.")
1067
1068 intf_r3_r4 = topo["routers"]["r3"]["links"]["r4"]["interface"]
1069 shutdown_bringup_interface(tgen, "r3", intf_r3_r4)
1070
1071 step(
1072 "Verify that peering between R1-R4 goes down and comes up when "
1073 "interface is toggled. Also prefix of link r3-r4(via both NHTs) is"
1074 " withdrawn and re-learned accordingly."
1075 )
1076
1077 result = verify_bgp_convergence_from_running_config(tgen, expected=False)
1078 assert (
1079 result is not True
1080 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1081 tc_name, result
1082 )
1083 logger.info("Expected behaviour: {}".format(result))
1084
1085 for addr_type in ADDR_TYPES:
1086 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1087
1088 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
1089 next_hop = topo["routers"]["r4"]["links"]["r3"][addr_type].split("/")[0]
1090
1091 result = verify_rib(
1092 tgen,
1093 addr_type,
1094 "r1",
1095 input_dict,
1096 protocol="bgp",
1097 next_hop=next_hop,
1098 expected=False,
1099 )
1100 assert (
1101 result is not True
1102 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1103 tc_name, result
1104 )
1105
1106 shutdown_bringup_interface(tgen, "r3", intf_r3_r4, True)
1107
1108 result = verify_bgp_convergence_from_running_config(tgen)
1109 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1110
1111 for addr_type in ADDR_TYPES:
1112 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1113
1114 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
1115 next_hop = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
1116
1117 result = verify_rib(
1118 tgen, addr_type, "r1", input_dict, protocol="bgp", next_hop=next_hop
1119 )
1120 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1121 tc_name, result
1122 )
1123
1124 step("Toggle the interface on R4.")
1125
1126 intf_r4_r3 = topo["routers"]["r4"]["links"]["r3"]["interface"]
1127 shutdown_bringup_interface(tgen, "r4", intf_r4_r3)
1128
1129 step(
1130 "Verify that peering between R1-R4 goes down and comes up when"
1131 "interface is toggled. Also prefix of link r3-r4(via R4)"
1132 " is withdrawn and re-learned accordingly."
1133 )
1134
1135 result = verify_bgp_convergence_from_running_config(tgen, expected=False)
1136 assert (
1137 result is not True
1138 ), "Testcase {} : Failed \n" "BGP is converged \n Error : {}".format(
1139 tc_name, result
1140 )
1141 logger.info("Expected behaviour: {}".format(result))
1142
1143 for addr_type in ADDR_TYPES:
1144 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1145
1146 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
1147 next_hop = topo["routers"]["r4"]["links"]["r3"][addr_type].split("/")[0]
1148
1149 result = verify_rib(
1150 tgen,
1151 addr_type,
1152 "r1",
1153 input_dict,
1154 protocol="bgp",
1155 next_hop=next_hop,
1156 expected=False,
1157 )
1158 assert (
1159 result is not True
1160 ), "Testcase {} : Failed \n " "Route is still present \n Error : {}".format(
1161 tc_name, result
1162 )
1163
1164 shutdown_bringup_interface(tgen, "r4", intf_r4_r3, True)
1165
1166 result = verify_bgp_convergence_from_running_config(tgen)
1167 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1168
1169 for addr_type in ADDR_TYPES:
1170 routes = {"ipv4": ["10.0.3.0/24"], "ipv6": ["fd00:0:0:3::/64"]}
1171
1172 input_dict = {"r1": {"static_routes": [{"network": routes[addr_type]}]}}
1173 next_hop = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
1174
1175 result = verify_rib(
1176 tgen, addr_type, "r1", input_dict, protocol="bgp", next_hop=next_hop
1177 )
1178 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1179 tc_name, result
1180 )
1181
1182 write_test_footer(tc_name)
1183
1184
1185 def test_BGP_path_attributes_default_values_p1(request):
1186 """
1187 Verify that BGP path attributes are present in CLI
1188 outputs and JSON format, even if set to default.
1189 """
1190
1191 tc_name = request.node.name
1192 write_test_header(tc_name)
1193 tgen = get_topogen()
1194
1195 # Don"t run this test if we have any failure.
1196 if tgen.routers_have_failure():
1197 pytest.skip(tgen.errors)
1198
1199 step("Initial config: Configure BGP neighborship, between R1-R2 & R1-R3")
1200 reset_config_on_routers(tgen)
1201
1202 step("Advertise a set of prefixes from R1 to both peers R2 and R3")
1203 for addr_type in ADDR_TYPES:
1204 input_dict_1 = {
1205 "r1": {
1206 "static_routes": [{"network": NETWORK[addr_type], "next_hop": "null0"}]
1207 }
1208 }
1209 result = create_static_routes(tgen, input_dict_1)
1210
1211 input_dict_2 = {
1212 "r1": {
1213 "bgp": {
1214 "address_family": {
1215 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1216 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1217 }
1218 }
1219 }
1220 }
1221 result = create_router_bgp(tgen, topo, input_dict_2)
1222
1223 step(
1224 "Verify that advertised prefixes are received on R4 and well"
1225 "known attributes are present in the CLI and JSON outputs with"
1226 "default values without any route-map config."
1227 )
1228 for addr_type in ADDR_TYPES:
1229 input_dict_3 = {"r4": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1230 result = verify_bgp_rib(
1231 tgen,
1232 addr_type,
1233 "r4",
1234 input_dict_3,
1235 next_hop=[
1236 topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
1237 topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
1238 ],
1239 )
1240 assert result is True, "Testcase {}: Failed \n Error : {}".format(
1241 tc_name, result
1242 )
1243
1244 for addr_type in ADDR_TYPES:
1245 input_dict_4 = {
1246 "r4": {
1247 "route_maps": {
1248 "rmap_pf": [{"set": {"origin": "incomplete", "aspath": "300 100"}}]
1249 }
1250 }
1251 }
1252
1253 result = verify_bgp_attributes(
1254 tgen,
1255 addr_type,
1256 "r4",
1257 NETWORK[addr_type],
1258 rmap_name="rmap_pf",
1259 input_dict=input_dict_4,
1260 )
1261 assert result is True, "Testcase {}: Failed \n Error : {}".format(
1262 tc_name, result
1263 )
1264
1265 step(
1266 "Configure a route-map to set below attribute value as 500"
1267 "and apply on R4 in an inbound direction"
1268 )
1269 for addr_type in ADDR_TYPES:
1270 input_dict_4 = {
1271 "r4": {
1272 "route_maps": {
1273 "Path_Attribue": [
1274 {
1275 "action": "permit",
1276 "set": {
1277 "path": {"as_num": 500, "as_action": "prepend"},
1278 "locPrf": 500,
1279 "origin": "egp",
1280 },
1281 }
1282 ]
1283 }
1284 }
1285 }
1286 result = create_route_maps(tgen, input_dict_4)
1287 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1288
1289 input_dict_5 = {
1290 "r4": {
1291 "bgp": {
1292 "address_family": {
1293 "ipv4": {
1294 "unicast": {
1295 "neighbor": {
1296 "r3": {
1297 "dest_link": {
1298 "r4": {
1299 "route_maps": [
1300 {
1301 "name": "Path_Attribue",
1302 "direction": "in",
1303 }
1304 ]
1305 }
1306 }
1307 }
1308 }
1309 }
1310 },
1311 "ipv6": {
1312 "unicast": {
1313 "neighbor": {
1314 "r3": {
1315 "dest_link": {
1316 "r4": {
1317 "route_maps": [
1318 {
1319 "name": "Path_Attribue",
1320 "direction": "in",
1321 }
1322 ]
1323 }
1324 }
1325 }
1326 }
1327 }
1328 },
1329 }
1330 }
1331 }
1332 }
1333
1334 result = create_router_bgp(tgen, topo, input_dict_5)
1335 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1336
1337 step(
1338 "Verify that once the route-map is applied all the attributes"
1339 "part of route-map, changes value to 500"
1340 )
1341 for addr_type in ADDR_TYPES:
1342 input_dict_4 = {
1343 "r4": {
1344 "route_maps": {
1345 "rmap_pf": [
1346 {
1347 "set": {
1348 "locPrf": 500,
1349 "aspath": "500 300 100",
1350 "origin": "EGP",
1351 }
1352 }
1353 ]
1354 }
1355 }
1356 }
1357 result = verify_bgp_attributes(
1358 tgen,
1359 addr_type,
1360 "r4",
1361 NETWORK[addr_type],
1362 rmap_name="rmap_pf",
1363 input_dict=input_dict_4,
1364 )
1365 assert result is True, "Testcase {}: Failed \n Error : {}".format(
1366 tc_name, result
1367 )
1368
1369 step("Remove the route-map from R4")
1370 input_dict_5 = {
1371 "r4": {
1372 "bgp": {
1373 "address_family": {
1374 "ipv4": {
1375 "unicast": {
1376 "neighbor": {
1377 "r3": {
1378 "dest_link": {
1379 "r4": {
1380 "route_maps": [
1381 {
1382 "name": "Path_Attribue",
1383 "direction": "in",
1384 "delete": True,
1385 }
1386 ]
1387 }
1388 }
1389 }
1390 }
1391 }
1392 },
1393 "ipv6": {
1394 "unicast": {
1395 "neighbor": {
1396 "r3": {
1397 "dest_link": {
1398 "r4": {
1399 "route_maps": [
1400 {
1401 "name": "Path_Attribue",
1402 "direction": "in",
1403 "delete": True,
1404 }
1405 ]
1406 }
1407 }
1408 }
1409 }
1410 }
1411 },
1412 }
1413 }
1414 }
1415 }
1416
1417 result = create_router_bgp(tgen, topo, input_dict_5)
1418 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1419
1420 step(
1421 "Verify on R4 that well known attributes are present in the CLI &"
1422 "JSON outputs again with default values without route-map config"
1423 )
1424 for addr_type in ADDR_TYPES:
1425 input_dict_4 = {
1426 "r4": {
1427 "route_maps": {
1428 "rmap_pf": [{"set": {"aspath": "300 100", "origin": "incomplete"}}]
1429 }
1430 }
1431 }
1432 result = verify_bgp_attributes(
1433 tgen,
1434 addr_type,
1435 "r4",
1436 NETWORK[addr_type],
1437 rmap_name="rmap_pf",
1438 input_dict=input_dict_4,
1439 nexthop=None,
1440 )
1441 assert result is True, "Testcase {}: Failed \n Error : {}".format(
1442 tc_name, result
1443 )
1444
1445 write_test_footer(tc_name)
1446
1447
1448 def test_BGP_peering_bw_loopback_and_physical_p1(request):
1449 """
1450 Verifying the BGP peering between loopback and
1451 physical link's IP of 2 peer routers.
1452 """
1453
1454 tc_name = request.node.name
1455 write_test_header(tc_name)
1456 tgen = get_topogen()
1457
1458 # Don"t run this test if we have any failure.
1459 if tgen.routers_have_failure():
1460 pytest.skip(tgen.errors)
1461
1462 step("Initial config :Configure BGP neighborship between R1 and R3.")
1463 reset_config_on_routers(tgen)
1464
1465 step("Configure a loopback interface on R1")
1466 dut = "r1"
1467 create_interface_in_kernel(
1468 tgen, dut, "lo10", "1.1.1.1", netmask="255.255.255.255", create=True
1469 )
1470 create_interface_in_kernel(
1471 tgen, dut, "lo10", "1:1::1:1", netmask="128", create=True
1472 )
1473
1474 step("Configure BGP session between R1's loopbak & R3")
1475 for addr_type in ADDR_TYPES:
1476 input_dict_1 = {
1477 "r3": {
1478 "static_routes": [
1479 {
1480 "network": Loopabck_IP["Lo_R1"][addr_type],
1481 "next_hop": topo["routers"]["r1"]["links"]["r3"][
1482 addr_type
1483 ].split("/")[0],
1484 }
1485 ]
1486 }
1487 }
1488 result = create_static_routes(tgen, input_dict_1)
1489 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1490 tc_name, result
1491 )
1492 result = verify_rib(
1493 tgen,
1494 addr_type,
1495 "r3",
1496 input_dict_1,
1497 protocol="static",
1498 next_hop=topo["routers"]["r1"]["links"]["r3"][addr_type].split("/")[0],
1499 )
1500 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1501 tc_name, result
1502 )
1503
1504 for addr_type in ADDR_TYPES:
1505 raw_config = {
1506 "r1": {
1507 "raw_config": [
1508 "router bgp {}".format(topo["routers"]["r1"]["bgp"]["local_as"]),
1509 "address-family {} unicast".format(addr_type),
1510 "neighbor {} update-source lo10".format(
1511 topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
1512 ),
1513 "neighbor {} timers 1 3".format(
1514 topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
1515 ),
1516 ]
1517 },
1518 "r3": {
1519 "raw_config": [
1520 "router bgp {}".format(topo["routers"]["r3"]["bgp"]["local_as"]),
1521 "address-family {} unicast".format(addr_type),
1522 "no neighbor {} remote-as {}".format(
1523 topo["routers"]["r1"]["links"]["r3"][addr_type].split("/")[0],
1524 topo["routers"]["r1"]["bgp"]["local_as"],
1525 ),
1526 "neighbor {} remote-as {}".format(
1527 Loopabck_IP["Lo_R1"][addr_type].split("/")[0],
1528 topo["routers"]["r1"]["bgp"]["local_as"],
1529 ),
1530 "neighbor {} ebgp-multihop 3".format(
1531 Loopabck_IP["Lo_R1"][addr_type].split("/")[0]
1532 ),
1533 ]
1534 },
1535 }
1536 result = apply_raw_config(tgen, raw_config)
1537 assert result is True, "Testcase {} : Failed Error : {}".format(tc_name, result)
1538
1539 for addr_type in ADDR_TYPES:
1540 if addr_type == "ipv6":
1541 raw_config = {
1542 "r3": {
1543 "raw_config": [
1544 "router bgp {}".format(
1545 topo["routers"]["r3"]["bgp"]["local_as"]
1546 ),
1547 "address-family {} unicast".format(addr_type),
1548 "neighbor {} activate".format(
1549 Loopabck_IP["Lo_R1"][addr_type].split("/")[0]
1550 ),
1551 ]
1552 }
1553 }
1554 else:
1555 raw_config = {
1556 "r3": {
1557 "raw_config": [
1558 "router bgp {}".format(
1559 topo["routers"]["r3"]["bgp"]["local_as"]
1560 ),
1561 "address-family {} unicast".format(addr_type),
1562 "no neighbor {} activate".format(
1563 Loopabck_IP["Lo_R1"]["ipv6"].split("/")[0]
1564 ),
1565 ]
1566 }
1567 }
1568 result = apply_raw_config(tgen, raw_config)
1569 assert result is True, "Testcase {} : Failed Error : {}".format(tc_name, result)
1570
1571 step("Verify that BGP neighborship between R1 and R3 comes up")
1572 result = verify_bgp_convergence_from_running_config(tgen)
1573 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1574
1575 step("Remove ebgp-multihop command from R3")
1576 for addr_type in ADDR_TYPES:
1577 raw_config = {
1578 "r3": {
1579 "raw_config": [
1580 "router bgp {}".format(topo["routers"]["r3"]["bgp"]["local_as"]),
1581 "no neighbor {} ebgp-multihop 3".format(
1582 Loopabck_IP["Lo_R1"][addr_type].split("/")[0]
1583 ),
1584 ]
1585 }
1586 }
1587 result = apply_raw_config(tgen, raw_config)
1588 assert result is True, "Testcase {} : Failed Error : {}".format(tc_name, result)
1589
1590 step("Verify that once eBGP multi-hop is removed, BGP session goes down")
1591 result = verify_bgp_convergence_from_running_config(tgen, expected=False)
1592 assert (
1593 result is not True
1594 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1595 tc_name, result
1596 )
1597
1598 step("Add ebgp-multihop command on R3 again")
1599 for addr_type in ADDR_TYPES:
1600 raw_config = {
1601 "r3": {
1602 "raw_config": [
1603 "router bgp {}".format(topo["routers"]["r3"]["bgp"]["local_as"]),
1604 "neighbor {} ebgp-multihop 3".format(
1605 Loopabck_IP["Lo_R1"][addr_type].split("/")[0]
1606 ),
1607 ]
1608 }
1609 }
1610 result = apply_raw_config(tgen, raw_config)
1611 assert result is True, "Testcase {} : Failed Error : {}".format(tc_name, result)
1612
1613 step("Verify that BGP neighborship between R1 and R3 comes up")
1614 result = verify_bgp_convergence_from_running_config(tgen)
1615 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1616
1617 step("Remove update-source command from R1")
1618 for addr_type in ADDR_TYPES:
1619 raw_config = {
1620 "r1": {
1621 "raw_config": [
1622 "router bgp {}".format(topo["routers"]["r1"]["bgp"]["local_as"]),
1623 "no neighbor {} update-source lo10".format(
1624 topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
1625 ),
1626 ]
1627 }
1628 }
1629 result = apply_raw_config(tgen, raw_config)
1630 assert result is True, "Testcase {} : Failed Error : {}".format(tc_name, result)
1631
1632 step("Verify that BGP session goes down, when update-source is removed")
1633 result = verify_bgp_convergence_from_running_config(tgen, expected=False)
1634 assert (
1635 result is not True
1636 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1637 tc_name, result
1638 )
1639
1640 step("Add update-source command on R1 again")
1641 for addr_type in ADDR_TYPES:
1642 raw_config = {
1643 "r1": {
1644 "raw_config": [
1645 "router bgp {}".format(topo["routers"]["r1"]["bgp"]["local_as"]),
1646 "neighbor {} update-source lo10".format(
1647 topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
1648 ),
1649 ]
1650 }
1651 }
1652 result = apply_raw_config(tgen, raw_config)
1653 assert result is True, "Testcase {} : Failed Error : {}".format(tc_name, result)
1654
1655 step("Verify that BGP neighborship between R1 and R3 comes up")
1656 result = verify_bgp_convergence_from_running_config(tgen)
1657 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1658
1659 step("Remove static route from R3")
1660 for addr_type in ADDR_TYPES:
1661 input_dict_1 = {
1662 "r3": {
1663 "static_routes": [
1664 {
1665 "network": Loopabck_IP["Lo_R1"][addr_type],
1666 "next_hop": topo["routers"]["r1"]["links"]["r3"][
1667 addr_type
1668 ].split("/")[0],
1669 "delete": True,
1670 }
1671 ]
1672 }
1673 }
1674 result = create_static_routes(tgen, input_dict_1)
1675 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1676 tc_name, result
1677 )
1678 result = verify_rib(
1679 tgen,
1680 addr_type,
1681 "r3",
1682 input_dict_1,
1683 protocol="static",
1684 next_hop=topo["routers"]["r1"]["links"]["r3"][addr_type].split("/")[0],
1685 expected=False,
1686 )
1687 assert (
1688 result is not True
1689 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
1690 tc_name, result
1691 )
1692
1693 sleep(3)
1694 step("Verify that BGP session goes down, when static route is removed")
1695 result = verify_bgp_convergence_from_running_config(tgen, expected=False)
1696 assert (
1697 result is not True
1698 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1699 tc_name, result
1700 )
1701
1702 step("Add static route on R3 again")
1703 for addr_type in ADDR_TYPES:
1704 input_dict_1 = {
1705 "r3": {
1706 "static_routes": [
1707 {
1708 "network": Loopabck_IP["Lo_R1"][addr_type],
1709 "next_hop": topo["routers"]["r1"]["links"]["r3"][
1710 addr_type
1711 ].split("/")[0],
1712 }
1713 ]
1714 }
1715 }
1716 result = create_static_routes(tgen, input_dict_1)
1717 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1718 tc_name, result
1719 )
1720 result = verify_rib(
1721 tgen,
1722 addr_type,
1723 "r3",
1724 input_dict_1,
1725 protocol="static",
1726 next_hop=topo["routers"]["r1"]["links"]["r3"][addr_type].split("/")[0],
1727 )
1728 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1729 tc_name, result
1730 )
1731
1732 step("Verify that BGP neighborship between R1 and R3 comes up")
1733 result = verify_bgp_convergence_from_running_config(tgen)
1734 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1735
1736 step("Toggle physical interface on R1")
1737 intf_r1_r3 = topo["routers"]["r1"]["links"]["r3"]["interface"]
1738 shutdown_bringup_interface(tgen, "r1", intf_r1_r3)
1739 sleep(3)
1740 step("Verify that BGP neighborship between R1 and R3 goes down")
1741 result = verify_bgp_convergence_from_running_config(tgen, expected=False)
1742 assert (
1743 result is not True
1744 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
1745 tc_name, result
1746 )
1747
1748 intf_r1_r3 = topo["routers"]["r1"]["links"]["r3"]["interface"]
1749 shutdown_bringup_interface(tgen, "r1", intf_r1_r3, True)
1750
1751 step("Verify that BGP neighborship between R1 and R3 comes up")
1752 result = verify_bgp_convergence_from_running_config(tgen)
1753 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1754
1755 write_test_footer(tc_name)
1756
1757
1758 def test_BGP_active_standby_preemption_and_ecmp_p1(request):
1759 """
1760 Verify that BGP Active/Standby/Pre-emption/ECMP.
1761 """
1762
1763 tc_name = request.node.name
1764 write_test_header(tc_name)
1765 tgen = get_topogen()
1766
1767 # Don"t run this test if we have any failure.
1768 if tgen.routers_have_failure():
1769 pytest.skip(tgen.errors)
1770
1771 step("Initial config :Configure BGP neighborship between R1 and R3.")
1772 reset_config_on_routers(tgen)
1773
1774 step("Change the AS number on R2 as 200")
1775 input_dict = {"r2": {"bgp": {"local_as": 200}}}
1776 result = modify_as_number(tgen, topo, input_dict)
1777 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1778
1779 step("Verify BGP converge after changing the AS number on R2")
1780 result = verify_bgp_convergence_from_running_config(tgen)
1781 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1782
1783 step("Advertise a set of prefixes from R1 to both peers R2 & R3")
1784 for addr_type in ADDR_TYPES:
1785 input_dict_1 = {
1786 "r1": {
1787 "static_routes": [{"network": NETWORK[addr_type], "next_hop": "null0"}]
1788 }
1789 }
1790 result = create_static_routes(tgen, input_dict_1)
1791 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1792 tc_name, result
1793 )
1794
1795 input_dict_2 = {
1796 "r1": {
1797 "bgp": {
1798 "address_family": {
1799 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1800 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
1801 }
1802 }
1803 }
1804 }
1805
1806 result = create_router_bgp(tgen, topo, input_dict_2)
1807 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1808
1809 step("Verify that R4 receives BGP prefixes via both peer routers R2 & R3")
1810 for addr_type in ADDR_TYPES:
1811 input_dict_3 = {"r4": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1812 result = verify_bgp_rib(
1813 tgen,
1814 addr_type,
1815 "r4",
1816 input_dict_3,
1817 next_hop=[
1818 topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
1819 topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
1820 ],
1821 )
1822 assert result is True, "Testcase {}: Failed \n Error : {}".format(
1823 tc_name, result
1824 )
1825
1826 step(
1827 "Configure a route-map to set as-path attribute and"
1828 "apply on R3 in an inbound direction:"
1829 )
1830
1831 input_dict_4 = {
1832 "r3": {
1833 "route_maps": {
1834 "Path_Attribue": [
1835 {
1836 "action": "permit",
1837 "set": {"path": {"as_num": 123, "as_action": "prepend"}},
1838 }
1839 ]
1840 }
1841 }
1842 }
1843 result = create_route_maps(tgen, input_dict_4)
1844 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1845
1846 input_dict_5 = {
1847 "r3": {
1848 "bgp": {
1849 "address_family": {
1850 "ipv4": {
1851 "unicast": {
1852 "neighbor": {
1853 "r1": {
1854 "dest_link": {
1855 "r3": {
1856 "route_maps": [
1857 {
1858 "name": "Path_Attribue",
1859 "direction": "in",
1860 }
1861 ]
1862 }
1863 }
1864 }
1865 }
1866 }
1867 },
1868 "ipv6": {
1869 "unicast": {
1870 "neighbor": {
1871 "r1": {
1872 "dest_link": {
1873 "r3": {
1874 "route_maps": [
1875 {
1876 "name": "Path_Attribue",
1877 "direction": "in",
1878 }
1879 ]
1880 }
1881 }
1882 }
1883 }
1884 }
1885 },
1886 }
1887 }
1888 }
1889 }
1890 result = create_router_bgp(tgen, topo, input_dict_5)
1891 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1892
1893 step("Verify on R4, BGP routes with shorter as-path are installed in FIB")
1894 for addr_type in ADDR_TYPES:
1895 dut = "r4"
1896 protocol = "bgp"
1897 input_dict_6 = {"r4": {"static_routes": [{"network": NETWORK[addr_type]}]}}
1898 result = verify_rib(
1899 tgen,
1900 addr_type,
1901 dut,
1902 input_dict_6,
1903 next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
1904 protocol=protocol,
1905 )
1906 assert result is True, "Testcase {} : Failed \n Error : {}".format(
1907 tc_name, result
1908 )
1909
1910 step("Shutdown BGP neighorship between R1-R2")
1911 dut = "r4"
1912 intf_r4_r2 = topo["routers"]["r4"]["links"]["r2"]["interface"]
1913 shutdown_bringup_interface(tgen, dut, intf_r4_r2)
1914
1915 step(
1916 "Verify that prefixes from next-hop via R2 are withdrawn"
1917 "and installed via next-hop as R3"
1918 )
1919 result = verify_rib(
1920 tgen,
1921 addr_type,
1922 dut,
1923 input_dict_2,
1924 next_hop=topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
1925 protocol=protocol,
1926 )
1927 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1928
1929 step("Do a no shut for BGP neighorship between R2-R4")
1930 shutdown_bringup_interface(tgen, dut, intf_r4_r2, ifaceaction=True)
1931
1932 step(
1933 "Verify that prefixes from next-hop via R3 are withdrawn"
1934 "from R4 and installed via next-hop as R2 (preemption)"
1935 )
1936 result = verify_rib(
1937 tgen,
1938 addr_type,
1939 dut,
1940 input_dict_2,
1941 next_hop=topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
1942 protocol=protocol,
1943 )
1944 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1945
1946 step("Remove the route-map from R3's neighbor statement")
1947 input_dict_5 = {
1948 "r3": {
1949 "bgp": {
1950 "address_family": {
1951 "ipv4": {
1952 "unicast": {
1953 "neighbor": {
1954 "r1": {
1955 "dest_link": {
1956 "r3": {
1957 "route_maps": [
1958 {
1959 "name": "Path_Attribue",
1960 "direction": "in",
1961 "delete": True,
1962 }
1963 ]
1964 }
1965 }
1966 }
1967 }
1968 }
1969 },
1970 "ipv6": {
1971 "unicast": {
1972 "neighbor": {
1973 "r1": {
1974 "dest_link": {
1975 "r3": {
1976 "route_maps": [
1977 {
1978 "name": "Path_Attribue",
1979 "direction": "in",
1980 "delete": True,
1981 }
1982 ]
1983 }
1984 }
1985 }
1986 }
1987 }
1988 },
1989 }
1990 }
1991 }
1992 }
1993 result = create_router_bgp(tgen, topo, input_dict_5)
1994 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
1995
1996 step("Configure multipath-relax and maximum-paths 2 on R4 for ECMP")
1997 input_dict_8 = {
1998 "r4": {
1999 "bgp": {
2000 "address_family": {
2001 "ipv4": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2002 "ipv6": {"unicast": {"maximum_paths": {"ebgp": 2}}},
2003 }
2004 }
2005 }
2006 }
2007 result = create_router_bgp(tgen, topo, input_dict_8)
2008 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2009
2010 maxpath_relax = {
2011 "r4": {"bgp": {"local_as": "400", "bestpath": {"aspath": "multipath-relax"}}}
2012 }
2013
2014 result = create_router_bgp(tgen, topo, maxpath_relax)
2015 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2016
2017 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2018 for addr_type in ADDR_TYPES:
2019 input_dict = {"r4": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2020 result = verify_rib(
2021 tgen,
2022 addr_type,
2023 "r4",
2024 input_dict,
2025 next_hop=[
2026 topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
2027 topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
2028 ],
2029 )
2030 assert result is True, "Testcase {} : Failed \n Error : {}".format(
2031 tc_name, result
2032 )
2033
2034 step("Remove multipath-relax command from R4")
2035
2036 del_maxpath_relax = {
2037 "r4": {
2038 "bgp": {
2039 "local_as": "400",
2040 "bestpath": {"aspath": "multipath-relax", "delete": True},
2041 }
2042 }
2043 }
2044
2045 result = create_router_bgp(tgen, topo, del_maxpath_relax)
2046 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2047
2048 step("Verify that ECMP is no longer happening on R4.")
2049 for addr_type in ADDR_TYPES:
2050 input_dict = {"r4": {"static_routes": [{"network": NETWORK[addr_type]}]}}
2051 result = verify_rib(
2052 tgen,
2053 addr_type,
2054 "r4",
2055 input_dict,
2056 next_hop=[
2057 topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
2058 topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
2059 ],
2060 expected=False,
2061 )
2062 assert (
2063 result is not True
2064 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
2065 tc_name, result
2066 )
2067
2068 step("Reconfigure multipath-relax command on R4")
2069 result = create_router_bgp(tgen, topo, maxpath_relax)
2070 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2071
2072 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2073 result = verify_rib(
2074 tgen,
2075 addr_type,
2076 "r4",
2077 input_dict,
2078 next_hop=[
2079 topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
2080 topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
2081 ],
2082 )
2083 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2084
2085 step("Remove maximum-path 2 command from R4")
2086 input_dict_8 = {
2087 "r4": {
2088 "bgp": {
2089 "address_family": {
2090 "ipv4": {
2091 "unicast": {
2092 "maximum_paths": {
2093 "ebgp": 1,
2094 }
2095 }
2096 },
2097 "ipv6": {
2098 "unicast": {
2099 "maximum_paths": {
2100 "ebgp": 1,
2101 }
2102 }
2103 },
2104 }
2105 }
2106 }
2107 }
2108 result = create_router_bgp(tgen, topo, input_dict_8)
2109 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2110
2111 step("Verify that ECMP is no longer happening on R4")
2112 result = verify_rib(
2113 tgen,
2114 addr_type,
2115 "r4",
2116 input_dict,
2117 next_hop=[
2118 topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
2119 topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
2120 ],
2121 expected=False,
2122 )
2123 assert (
2124 result is not True
2125 ), "Testcase {} : Failed \n " "Routes are still present \n Error: {}".format(
2126 tc_name, result
2127 )
2128
2129 step("Re-configure maximum-path 2 command on R4")
2130 input_dict_8 = {
2131 "r4": {
2132 "bgp": {
2133 "address_family": {
2134 "ipv4": {
2135 "unicast": {
2136 "maximum_paths": {
2137 "ebgp": 2,
2138 }
2139 }
2140 },
2141 "ipv6": {
2142 "unicast": {
2143 "maximum_paths": {
2144 "ebgp": 2,
2145 }
2146 }
2147 },
2148 }
2149 }
2150 }
2151 }
2152 result = create_router_bgp(tgen, topo, input_dict_8)
2153 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2154
2155 step("Verify FIB of R4, BGP prefixes with ECMP next-hop via R2 and R3")
2156 result = verify_rib(
2157 tgen,
2158 addr_type,
2159 "r4",
2160 input_dict,
2161 next_hop=[
2162 topo["routers"]["r2"]["links"]["r4"][addr_type].split("/")[0],
2163 topo["routers"]["r3"]["links"]["r4"][addr_type].split("/")[0],
2164 ],
2165 )
2166 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2167
2168 write_test_footer(tc_name)
2169
2170
2171 def test_password_authentication_for_eBGP_and_iBGP_peers_p1(request):
2172 """
2173 Verify password authentication for eBGP and iBGP peers.
2174 """
2175
2176 tc_name = request.node.name
2177 write_test_header(tc_name)
2178 tgen = get_topogen()
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 step("Initial config :Configure BGP neighborship between R1 and R3.")
2185 reset_config_on_routers(tgen)
2186
2187 step(
2188 "Add a static route on R1 for loopbacks IP's reachability of R2, R3"
2189 "and on R2 and R3 for loopback IP of R1"
2190 )
2191 for addr_type in ADDR_TYPES:
2192 nh1 = topo["routers"]["r3"]["links"]["r1"][addr_type].split("/")[0]
2193 nh2 = topo["routers"]["r1"]["links"]["r2"][addr_type].split("/")[0]
2194 nh3 = topo["routers"]["r1"]["links"]["r3"][addr_type].split("/")[0]
2195 nh4 = topo["routers"]["r2"]["links"]["r1"][addr_type].split("/")[0]
2196 input_dict_1 = {
2197 "r1": {
2198 "static_routes": [
2199 {
2200 "network": topo["routers"]["r3"]["links"]["lo"][addr_type],
2201 "next_hop": nh1,
2202 }
2203 ]
2204 }
2205 }
2206 input_dict_2 = {
2207 "r2": {
2208 "static_routes": [
2209 {
2210 "network": topo["routers"]["r1"]["links"]["lo"][addr_type],
2211 "next_hop": nh2,
2212 }
2213 ]
2214 }
2215 }
2216 input_dict_3 = {
2217 "r3": {
2218 "static_routes": [
2219 {
2220 "network": topo["routers"]["r1"]["links"]["lo"][addr_type],
2221 "next_hop": nh3,
2222 }
2223 ]
2224 }
2225 }
2226 input_dict_4 = {
2227 "r1": {
2228 "static_routes": [
2229 {
2230 "network": topo["routers"]["r2"]["links"]["lo"][addr_type],
2231 "next_hop": nh4,
2232 }
2233 ]
2234 }
2235 }
2236 dut_list = ["r1", "r2", "r3", "r1"]
2237 nexthop_list = [nh1, nh2, nh3, nh4]
2238 input_dict_list = [input_dict_1, input_dict_2, input_dict_3, input_dict_4]
2239 for dut, next_hop, input_dict in zip(dut_list, nexthop_list, input_dict_list):
2240 result = create_static_routes(tgen, input_dict)
2241 assert result is True, "Testcase {} : Failed \n Error : {}".format(
2242 tc_name, result
2243 )
2244
2245 step("Verify that static routes are installed in FIB of routers")
2246 result = verify_rib(
2247 tgen, addr_type, dut, input_dict, next_hop=next_hop, protocol="static"
2248 )
2249 assert result is True, "Testcase {} : Failed \n Error : {}".format(
2250 tc_name, result
2251 )
2252
2253 step("Configure BGP sessions between R1-R2 and R1-R3 over loopback IPs")
2254 for routerN in ["r1", "r3"]:
2255 for addr_type in ADDR_TYPES:
2256 if routerN == "r1":
2257 bgp_neighbor = "r3"
2258 elif routerN == "r3":
2259 bgp_neighbor = "r1"
2260 topo["routers"][routerN]["bgp"]["address_family"][addr_type]["unicast"][
2261 "neighbor"
2262 ][bgp_neighbor]["dest_link"] = {
2263 "lo": {"ebgp_multihop": 2, "source_link": "lo"}
2264 }
2265 build_config_from_json(tgen, topo, save_bkup=False)
2266
2267 for routerN in ["r1", "r2"]:
2268 for addr_type in ADDR_TYPES:
2269 if routerN == "r1":
2270 bgp_neighbor = "r2"
2271 elif routerN == "r2":
2272 bgp_neighbor = "r1"
2273 topo["routers"][routerN]["bgp"]["address_family"][addr_type]["unicast"][
2274 "neighbor"
2275 ][bgp_neighbor]["dest_link"] = {"lo": {"source_link": "lo"}}
2276 build_config_from_json(tgen, topo, save_bkup=False)
2277
2278 for routerN in ["r1", "r2", "r3"]:
2279 for addr_type in ADDR_TYPES:
2280 for bgp_neighbor in topo["routers"][routerN]["bgp"]["address_family"][
2281 addr_type
2282 ]["unicast"]["neighbor"].keys():
2283 if routerN in ["r1", "r2", "r3"] and bgp_neighbor == "r4":
2284 continue
2285 if addr_type == "ipv4":
2286 topo["routers"][routerN]["bgp"]["address_family"][addr_type][
2287 "unicast"
2288 ]["neighbor"][bgp_neighbor]["dest_link"] = {
2289 "lo": {"deactivate": "ipv6"}
2290 }
2291 elif addr_type == "ipv6":
2292 topo["routers"][routerN]["bgp"]["address_family"][addr_type][
2293 "unicast"
2294 ]["neighbor"][bgp_neighbor]["dest_link"] = {
2295 "lo": {"deactivate": "ipv4"}
2296 }
2297 build_config_from_json(tgen, topo, save_bkup=False)
2298
2299 result = verify_bgp_convergence(tgen, topo)
2300 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2301
2302 step("Configure authentication password on R1 for neighbor statements")
2303 for bgp_neighbor in ["r2", "r3"]:
2304 for addr_type in ADDR_TYPES:
2305 topo["routers"]["r1"]["bgp"]["address_family"][addr_type]["unicast"][
2306 "neighbor"
2307 ][bgp_neighbor]["dest_link"] = {"lo": {"password": "vmware"}}
2308 build_config_from_json(tgen, topo, save_bkup=False)
2309
2310 step(
2311 "Verify that both sessions go down as only R1 has password"
2312 "configured but not peer routers"
2313 )
2314 result = verify_bgp_convergence(tgen, topo, expected=False)
2315 assert (
2316 result is not True
2317 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2318 tc_name, result
2319 )
2320
2321 step("configure same password on R2 and R3")
2322 for routerN in ["r2", "r3"]:
2323 for addr_type in ADDR_TYPES:
2324 topo["routers"][routerN]["bgp"]["address_family"][addr_type]["unicast"][
2325 "neighbor"
2326 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2327 build_config_from_json(tgen, topo, save_bkup=False)
2328
2329 step("Verify that all BGP sessions come up due to identical passwords")
2330 result = verify_bgp_convergence(tgen, topo)
2331 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2332
2333 step("Configure same password on R2 and R3, but in CAPs.")
2334 for routerN in ["r2", "r3"]:
2335 for addr_type in ADDR_TYPES:
2336 topo["routers"][routerN]["bgp"]["address_family"][addr_type]["unicast"][
2337 "neighbor"
2338 ]["r1"]["dest_link"] = {"lo": {"password": "VMWARE"}}
2339 build_config_from_json(tgen, topo, save_bkup=False)
2340
2341 step(
2342 "Verify that BGP sessions do not come up as password"
2343 "strings are in CAPs on R2 and R3"
2344 )
2345 result = verify_bgp_convergence(tgen, topo, expected=False)
2346 assert (
2347 result is not True
2348 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2349 tc_name, result
2350 )
2351
2352 step("Configure same password on R2 and R3 without CAPs")
2353 for routerN in ["r2", "r3"]:
2354 for addr_type in ADDR_TYPES:
2355 topo["routers"][routerN]["bgp"]["address_family"][addr_type]["unicast"][
2356 "neighbor"
2357 ]["r1"]["dest_link"] = {"lo": {"password": "vmware"}}
2358 build_config_from_json(tgen, topo, save_bkup=False)
2359
2360 step("Verify all BGP sessions come up again due to identical passwords")
2361 result = verify_bgp_convergence(tgen, topo)
2362 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2363
2364 step("Remove password from R1")
2365 for bgp_neighbor in ["r2", "r3"]:
2366 for addr_type in ADDR_TYPES:
2367 topo["routers"]["r1"]["bgp"]["address_family"][addr_type]["unicast"][
2368 "neighbor"
2369 ][bgp_neighbor]["dest_link"] = {"lo": {"no_password": "vmware"}}
2370 build_config_from_json(tgen, topo, save_bkup=False)
2371
2372 step("Verify if password is removed from R1, both sessions go down again")
2373 result = verify_bgp_convergence(tgen, topo, expected=False)
2374 assert (
2375 result is not True
2376 ), "Testcase {} : Failed \n " "BGP is converged \n Error: {}".format(
2377 tc_name, result
2378 )
2379
2380 step("Configure alphanumeric password on R1 and peer routers R2,R3")
2381 for bgp_neighbor in ["r2", "r3"]:
2382 for addr_type in ADDR_TYPES:
2383 topo["routers"]["r1"]["bgp"]["address_family"][addr_type]["unicast"][
2384 "neighbor"
2385 ][bgp_neighbor]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2386 build_config_from_json(tgen, topo, save_bkup=False)
2387
2388 for routerN in ["r2", "r3"]:
2389 for addr_type in ADDR_TYPES:
2390 topo["routers"][routerN]["bgp"]["address_family"][addr_type]["unicast"][
2391 "neighbor"
2392 ]["r1"]["dest_link"] = {"lo": {"password": "Vmware@123"}}
2393 build_config_from_json(tgen, topo, save_bkup=False)
2394
2395 step(
2396 "Verify that sessions Come up irrespective of characters"
2397 "used in password string"
2398 )
2399 result = verify_bgp_convergence(tgen, topo)
2400 assert result is True, "Testcase {} : Failed \n Error : {}".format(tc_name, result)
2401
2402 write_test_footer(tc_name)
2403
2404
2405 if __name__ == "__main__":
2406 args = ["-s"] + sys.argv[1:]
2407 sys.exit(pytest.main(args))