]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_ibgp_nbr.py
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tests / topotests / bgp_ipv4_over_ipv6 / test_rfc5549_ebgp_ibgp_nbr.py
1 #!/usr/bin/env python
2 # SPDX-License-Identifier: ISC
3
4 #
5 # Copyright (c) 2021 by VMware, Inc. ("VMware")
6 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc.
7 # ("NetDEF") in this file.
8 #
9
10
11 """RFC5549 Automation."""
12 import os
13 import sys
14 import time
15 import pytest
16 from copy import deepcopy
17
18 # Save the Current Working Directory to find configuration files.
19 CWD = os.path.dirname(os.path.realpath(__file__))
20 sys.path.append(os.path.join(CWD, "../"))
21 sys.path.append(os.path.join(CWD, "../../"))
22
23 # pylint: disable=C0413
24 # Import topogen and topotest helpers
25 from lib.topogen import Topogen, get_topogen
26
27 from lib.common_config import (
28 start_topology,
29 write_test_header,
30 get_frr_ipv6_linklocal,
31 write_test_footer,
32 verify_rib,
33 create_static_routes,
34 check_address_types,
35 reset_config_on_routers,
36 step,
37 )
38 from lib.topolog import logger
39 from lib.bgp import (
40 verify_bgp_convergence,
41 create_router_bgp,
42 verify_bgp_rib,
43 )
44 from lib.topojson import build_config_from_json
45
46
47 pytestmark = [pytest.mark.bgpd, pytest.mark.staticd]
48
49 # Global variables
50 topo = None
51
52 # Global variables
53 NETWORK = {
54 "ipv4": [
55 "11.0.20.1/32",
56 "11.0.20.2/32",
57 "11.0.20.3/32",
58 "11.0.20.4/32",
59 "11.0.20.5/32",
60 ],
61 "ipv6": ["1::1/128", "1::2/128", "1::3/128", "1::4/128", "1::5/128"],
62 }
63 MASK = {"ipv4": "32", "ipv6": "128"}
64 NEXT_HOP = {
65 "ipv4": ["10.0.0.1", "10.0.1.1", "10.0.2.1", "10.0.3.1", "10.0.4.1"],
66 "ipv6": ["Null0", "Null0", "Null0", "Null0", "Null0"],
67 }
68 NO_OF_RTES = 2
69 NETWORK_CMD_IP = "1.0.1.17/32"
70 ADDR_TYPES = check_address_types()
71 TOPOOLOGY = """
72 Please view in a fixed-width font such as Courier.
73
74 +----+
75 | R4 |
76 | |
77 +--+-+
78 | ipv4 nbr
79 no bgp ebgp/ibgp |
80 | ebgp/ibgp
81 +----+ 5links +----+ 8links +--+-+ +----+
82 |R0 +----------+ R1 +------------+ R2 | ipv6 nbr |R3 |
83 | +----------+ +------------+ +-------------+ |
84 +----+ +----+ ipv6 nbr +----+ +----+
85 """
86
87 TESTCASES = """
88 1. Verify Ipv4 route next hop is changed when advertised using
89 next hop -self command
90 2. Verify IPv4 route advertised to peer when IPv6 BGP session established
91 using peer-group
92 3. Verify IPv4 routes received with IPv6 nexthop are getting advertised
93 to another IBGP peer without changing the nexthop
94 4. Verify IPv4 routes advertised with correct nexthop when nexthop
95 unchange is configure on EBGP peers
96 """
97
98
99 def setup_module(mod):
100 """Set up the pytest environment."""
101
102 global topo
103 testsuite_run_time = time.asctime(time.localtime(time.time()))
104 logger.info("Testsuite start time: {}".format(testsuite_run_time))
105 logger.info("=" * 40)
106
107 logger.info("Running setup_module to create topology")
108
109 # This function initiates the topology build with Topogen...
110 json_file = "{}/rfc5549_ebgp_ibgp_nbr.json".format(CWD)
111 tgen = Topogen(json_file, mod.__name__)
112 global topo
113 topo = tgen.json_topo
114
115 # Starting topology, create tmp files which are loaded to routers
116 # to start daemons and then start routers
117 start_topology(tgen)
118
119 # Creating configuration from JSON
120 build_config_from_json(tgen, topo)
121 # Don't run this test if we have any failure.
122 if tgen.routers_have_failure():
123 pytest.skip(tgen.errors)
124
125 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
126 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error:" " {}".format(
127 BGP_CONVERGENCE
128 )
129 logger.info("Running setup_module() done")
130
131
132 def teardown_module():
133 """
134 Teardown the pytest environment.
135
136 * `mod`: module name
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
146 def get_llip(onrouter, intf):
147 """
148 API to get the link local ipv6 address of a particular interface
149
150 Parameters
151 ----------
152 * `fromnode`: Source node
153 * `tonode` : interface for which link local ip needs to be returned.
154
155 Usage
156 -----
157 result = get_llip('r1', 'r2-link0')
158
159 Returns
160 -------
161 1) link local ipv6 address from the interface.
162 2) errormsg - when link local ip not found.
163 """
164 tgen = get_topogen()
165 intf = topo["routers"][onrouter]["links"][intf]["interface"]
166 llip = get_frr_ipv6_linklocal(tgen, onrouter, intf)
167 if llip:
168 logger.info("llip ipv6 address to be set as NH is %s", llip)
169 return llip
170 return None
171
172
173 def get_glipv6(onrouter, intf):
174 """
175 API to get the global ipv6 address of a particular interface
176
177 Parameters
178 ----------
179 * `onrouter`: Source node
180 * `intf` : interface for which link local ip needs to be returned.
181
182 Usage
183 -----
184 result = get_glipv6('r1', 'r2-link0')
185
186 Returns
187 -------
188 1) global ipv6 address from the interface.
189 2) errormsg - when link local ip not found.
190 """
191 glipv6 = (topo["routers"][onrouter]["links"][intf]["ipv6"]).split("/")[0]
192 if glipv6:
193 logger.info("Global ipv6 address to be set as NH is %s", glipv6)
194 return glipv6
195 return None
196
197
198 # ##################################
199 # Test cases start here.
200 # ##################################
201 def test_ibgp_to_ibgp_p1(request):
202 """
203
204 Test Capability extended nexthop.
205
206 Verify IPv4 routes received with IPv6 nexthop are getting advertised to
207 another IBGP peer without changing the nexthop
208 """
209 tc_name = request.node.name
210 write_test_header(tc_name)
211 tgen = get_topogen()
212 # Don't run this test if we have any failure.
213 if tgen.routers_have_failure():
214 pytest.skip(tgen.errors)
215 reset_config_on_routers(tgen)
216 global topo
217 topo23 = deepcopy(topo)
218 build_config_from_json(tgen, topo23, save_bkup=False)
219
220 step("Configure IPv6 EBGP session between R1 and R2 with " "global IPv6 address")
221 step("Configure IPv6 IBGP session betn R2 & R3 using IPv6 global address")
222 step("Enable capability extended-nexthop on both the IPv6 BGP peers")
223 step("Activate same IPv6 nbr from IPv4 unicast family")
224 step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
225 step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")
226
227 # verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.
228 bgp_convergence = verify_bgp_convergence(tgen, topo23)
229 assert bgp_convergence is True, "Testcase :Failed \n Error:" " {}".format(
230 bgp_convergence
231 )
232
233 step(" Configure 5 IPv4 static" " routes on R1, Nexthop as different links of R0")
234 for rte in range(0, NO_OF_RTES):
235 # Create Static routes
236 input_dict = {
237 "r1": {
238 "static_routes": [
239 {
240 "network": NETWORK["ipv4"][rte],
241 "no_of_ip": 1,
242 "next_hop": NEXT_HOP["ipv4"][rte],
243 }
244 ]
245 }
246 }
247 result = create_static_routes(tgen, input_dict)
248 assert result is True, "Testcase {} : Failed \n Error: {}".format(
249 tc_name, result
250 )
251
252 step(
253 "Advertise static routes from IPv4 unicast family and IPv6 "
254 "unicast family respectively from R1 using red static cmd "
255 "Advertise loopback from IPv4 unicast family using network command "
256 "from R1"
257 )
258
259 configure_bgp_on_r1 = {
260 "r1": {
261 "bgp": {
262 "address_family": {
263 "ipv4": {
264 "unicast": {
265 "redistribute": [{"redist_type": "static"}],
266 "advertise_networks": [
267 {"network": NETWORK_CMD_IP, "no_of_network": 1}
268 ],
269 }
270 }
271 }
272 }
273 }
274 }
275 result = create_router_bgp(tgen, topo23, configure_bgp_on_r1)
276 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
277 step(
278 "IPv4 routes advertised using static and network command are "
279 " received on R2 BGP and routing table , "
280 "verify using show ip bgp, show ip route for IPv4 routes ."
281 )
282
283 gllip = get_llip("r1", "r2-link0")
284 assert gllip is not None, "Testcase {} : Failed \n Error: {}".format(
285 tc_name, result
286 )
287
288 dut = "r2"
289 protocol = "bgp"
290 # verify the routes with nh as ext_nh
291 verify_nh_for_static_rtes = {
292 "r1": {
293 "static_routes": [
294 {
295 "network": NETWORK["ipv4"][0],
296 "no_of_ip": NO_OF_RTES,
297 "next_hop": gllip,
298 }
299 ]
300 }
301 }
302 bgp_rib = verify_bgp_rib(
303 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip
304 )
305 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
306 result = verify_rib(
307 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip, protocol=protocol
308 )
309 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
310
311 configure_bgp_on_r2 = {
312 "r2": {
313 "bgp": {
314 "address_family": {
315 "ipv6": {
316 "unicast": {
317 "neighbor": {
318 "r3": {
319 "dest_link": {
320 "r2": {
321 "activate": "ipv4",
322 "capability": "extended-nexthop",
323 }
324 }
325 }
326 }
327 }
328 }
329 }
330 }
331 }
332 }
333 result = create_router_bgp(tgen, topo, configure_bgp_on_r2)
334 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
335
336 configure_bgp_on_r3 = {
337 "r3": {
338 "bgp": {
339 "address_family": {
340 "ipv6": {
341 "unicast": {
342 "neighbor": {
343 "r2": {
344 "dest_link": {
345 "r3": {
346 "activate": "ipv4",
347 "capability": "extended-nexthop",
348 }
349 }
350 }
351 }
352 }
353 }
354 }
355 }
356 }
357 }
358 result = create_router_bgp(tgen, topo, configure_bgp_on_r3)
359 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
360
361 step(
362 "IPv4 routes installed on R3 with global address without "
363 "changing the nexthop ( nexthop should IPv6 link local which is"
364 " received from R1)"
365 )
366 gipv6 = get_glipv6("r1", "r2-link0")
367 dut = "r3"
368 verify_nh_for_static_rtes = {
369 "r1": {
370 "static_routes": [
371 {
372 "network": NETWORK["ipv4"][0],
373 "no_of_ip": NO_OF_RTES,
374 "next_hop": gipv6,
375 }
376 ]
377 }
378 }
379 bgp_rib = verify_bgp_rib(
380 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gipv6
381 )
382 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
383 write_test_footer(tc_name)
384
385
386 def test_ext_nh_cap_red_static_network_ibgp_peer_p1(request):
387 """
388
389 Test Extended capability next hop, with ibgp peer.
390
391 Verify IPv4 routes advertise using "redistribute static" and
392 "network command" are received on EBGP peer with IPv6 nexthop
393 """
394 tc_name = request.node.name
395 write_test_header(tc_name)
396 tgen = get_topogen()
397 # Don't run this test if we have any failure.
398 if tgen.routers_have_failure():
399 pytest.skip(tgen.errors)
400 reset_config_on_routers(tgen)
401 step(
402 " Configure IPv6 EBGP session between R1 & R2 with global IPv6 address"
403 " Enable capability extended-nexthop on the nbr from both the routers"
404 " Activate same IPv6 nbr from IPv4 unicast family"
405 )
406 configure_bgp_on_r2 = {
407 "r2": {
408 "bgp": {
409 "default_ipv4_unicast": "False",
410 "address_family": {
411 "ipv6": {
412 "unicast": {
413 "neighbor": {
414 "r3": {
415 "dest_link": {
416 "r2": {
417 "capability": "extended-nexthop",
418 "activate": "ipv4",
419 "next_hop_self": True,
420 "activate": "ipv4",
421 }
422 }
423 }
424 }
425 }
426 }
427 },
428 }
429 }
430 }
431 result = create_router_bgp(tgen, topo, configure_bgp_on_r2)
432 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
433
434 configure_bgp_on_r3 = {
435 "r3": {
436 "bgp": {
437 "address_family": {
438 "ipv6": {
439 "unicast": {
440 "neighbor": {
441 "r2": {
442 "dest_link": {
443 "r3": {
444 "capability": "extended-nexthop",
445 "activate": "ipv4",
446 }
447 }
448 }
449 }
450 }
451 }
452 }
453 }
454 }
455 }
456 result = create_router_bgp(tgen, topo, configure_bgp_on_r3)
457 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
458 for rte in range(0, NO_OF_RTES):
459 # Create Static routes
460 input_dict = {
461 "r1": {
462 "static_routes": [
463 {
464 "network": NETWORK["ipv4"][rte],
465 "no_of_ip": 1,
466 "next_hop": NEXT_HOP["ipv4"][rte],
467 }
468 ]
469 }
470 }
471 result = create_static_routes(tgen, input_dict)
472 assert result is True, "Testcase {} : Failed \n Error: {}".format(
473 tc_name, result
474 )
475
476 configure_bgp_on_r1 = {
477 "r1": {
478 "bgp": {
479 "default_ipv4_unicast": "False",
480 "address_family": {
481 "ipv4": {
482 "unicast": {
483 "redistribute": [{"redist_type": "static"}],
484 "advertise_networks": [
485 {"network": NETWORK_CMD_IP, "no_of_network": 1}
486 ],
487 }
488 }
489 },
490 }
491 }
492 }
493 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
494 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
495
496 gllip = get_llip("r1", "r2-link0")
497 assert gllip is not None, "Testcase {} : Failed \n Error: {}".format(
498 tc_name, result
499 )
500
501 dut = "r2"
502 protocol = "bgp"
503 verify_nh_for_static_rtes = {
504 "r1": {
505 "static_routes": [
506 {
507 "network": NETWORK["ipv4"][0],
508 "no_of_ip": NO_OF_RTES,
509 "next_hop": gllip,
510 }
511 ]
512 }
513 }
514 result = verify_rib(
515 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip, protocol=protocol
516 )
517 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
518
519 verify_nh_for_nw_cmd_rtes = {
520 "r1": {
521 "static_routes": [
522 {
523 "network": NETWORK_CMD_IP,
524 "no_of_ip": 1,
525 "next_hop": gllip,
526 }
527 ]
528 }
529 }
530
531 result = verify_rib(
532 tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=gllip, protocol=protocol
533 )
534 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
535
536 gllip = get_glipv6("r2", "r3")
537 assert gllip is not None, "Testcase {} : Failed \n Error: {}".format(
538 tc_name, result
539 )
540
541 dut = "r3"
542 protocol = "bgp"
543 # verify the routes with nh as ext_nh
544 verify_nh_for_static_rtes = {
545 "r1": {
546 "static_routes": [
547 {
548 "network": NETWORK["ipv4"][0],
549 "no_of_ip": NO_OF_RTES,
550 "next_hop": gllip,
551 }
552 ]
553 }
554 }
555 result = verify_rib(
556 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip, protocol=protocol
557 )
558 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
559 verify_nh_for_nw_cmd_rtes = {
560 "r1": {
561 "static_routes": [
562 {
563 "network": NETWORK_CMD_IP,
564 "no_of_ip": 1,
565 "next_hop": gllip,
566 }
567 ]
568 }
569 }
570 bgp_rib = verify_bgp_rib(
571 tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=gllip
572 )
573 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
574 result = verify_rib(
575 tgen, "ipv4", dut, verify_nh_for_nw_cmd_rtes, next_hop=gllip, protocol=protocol
576 )
577 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
578
579 write_test_footer(tc_name)
580
581
582 def test_bgp_peer_group_p1(request):
583 """
584 Test extended capability next hop with peer groups.
585
586 Verify IPv4 routes received with IPv6 nexthop are getting advertised to
587 another IBGP peer without changing the nexthop
588 """
589 tc_name = request.node.name
590 write_test_header(tc_name)
591 tgen = get_topogen()
592 # Don't run this test if we have any failure.
593 if tgen.routers_have_failure():
594 pytest.skip(tgen.errors)
595 reset_config_on_routers(tgen)
596 global topo
597 topo1 = deepcopy(topo)
598 step("Configure IPv6 EBGP session between R1 and R2 with " "global IPv6 address")
599 step("Configure IPv6 IBGP session betn R2 & R3 using IPv6 global address")
600 step("Enable capability extended-nexthop on both the IPv6 BGP peers")
601 step("Activate same IPv6 nbr from IPv4 unicast family")
602 step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
603 configure_bgp_on_r1 = {
604 "r1": {
605 "bgp": {
606 "default_ipv4_unicast": "False",
607 "peer-group": {
608 "rfc5549": {"capability": "extended-nexthop", "remote-as": "200"}
609 },
610 }
611 }
612 }
613 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
614 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
615 configure_bgp_on_r1 = {
616 "r1": {
617 "bgp": {
618 "address_family": {
619 "ipv6": {
620 "unicast": {
621 "neighbor": {
622 "r2": {
623 "dest_link": {
624 "r1-link0": {
625 "activate": "ipv4",
626 "capability": "extended-nexthop",
627 "peer-group": "rfc5549",
628 }
629 }
630 }
631 }
632 }
633 }
634 }
635 }
636 }
637 }
638 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
639 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
640 configure_bgp_on_r2 = {
641 "r2": {
642 "bgp": {
643 "default_ipv4_unicast": "False",
644 "peer-group": {
645 "rfc5549": {"capability": "extended-nexthop", "remote-as": "100"}
646 },
647 }
648 }
649 }
650 result = create_router_bgp(tgen, topo, configure_bgp_on_r2)
651 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
652 configure_bgp_on_r2 = {
653 "r2": {
654 "bgp": {
655 "address_family": {
656 "ipv6": {
657 "unicast": {
658 "neighbor": {
659 "r1": {
660 "dest_link": {
661 "r2-link0": {
662 "capability": "extended-nexthop",
663 "activate": "ipv4",
664 "peer-group": "rfc5549",
665 }
666 }
667 },
668 "r3": {"dest_link": {"r2": {}}},
669 }
670 }
671 }
672 }
673 }
674 }
675 }
676 result = create_router_bgp(tgen, topo, configure_bgp_on_r2)
677 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
678
679 configure_bgp_on_r3 = {
680 "r3": {
681 "bgp": {
682 "address_family": {
683 "ipv4": {"unicast": {"neighbor": {"r2": {"dest_link": {"r3": {}}}}}}
684 }
685 }
686 }
687 }
688 result = create_router_bgp(tgen, topo, configure_bgp_on_r3)
689 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
690
691 step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")
692 bgp_convergence = verify_bgp_convergence(tgen, topo)
693 assert bgp_convergence is True, "Testcase :Failed \n Error:" " {}".format(
694 bgp_convergence
695 )
696
697 step(" Configure 2 IPv4 static" " routes on R1, Nexthop as different links of R0")
698 for rte in range(0, NO_OF_RTES):
699 # Create Static routes
700 input_dict = {
701 "r1": {
702 "static_routes": [
703 {
704 "network": NETWORK["ipv4"][rte],
705 "no_of_ip": 1,
706 "next_hop": NEXT_HOP["ipv4"][rte],
707 }
708 ]
709 }
710 }
711 result = create_static_routes(tgen, input_dict)
712 assert result is True, "Testcase {} : Failed \n Error: {}".format(
713 tc_name, result
714 )
715
716 step(
717 "Advertise static routes from IPv4 unicast family and IPv6 "
718 "unicast family respectively from R1 using red static cmd "
719 "Advertise loopback from IPv4 unicast family using network command "
720 "from R1"
721 )
722
723 configure_bgp_on_r1 = {
724 "r1": {
725 "bgp": {
726 "address_family": {
727 "ipv4": {
728 "unicast": {
729 "redistribute": [{"redist_type": "static"}],
730 "advertise_networks": [
731 {"network": NETWORK_CMD_IP, "no_of_network": 1}
732 ],
733 }
734 }
735 }
736 }
737 }
738 }
739 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
740 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
741 step(
742 "IPv4 routes advertised using static and network command are "
743 " received on R2 BGP and routing table , "
744 "verify using show ip bgp, show ip route for IPv4 routes ."
745 )
746
747 gllip = get_llip("r1", "r2-link0")
748 assert gllip is not None, "Testcase {} : Failed \n Error: {}".format(
749 tc_name, result
750 )
751
752 dut = "r2"
753 protocol = "bgp"
754 verify_nh_for_static_rtes = {
755 "r1": {
756 "static_routes": [
757 {
758 "network": NETWORK["ipv4"][0],
759 "no_of_ip": NO_OF_RTES,
760 "next_hop": gllip,
761 }
762 ]
763 }
764 }
765 bgp_rib = verify_bgp_rib(
766 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip
767 )
768 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
769 result = verify_rib(
770 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip, protocol=protocol
771 )
772 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
773
774 step("Enable cap ext nh on r1 and r2 and activate in ipv4 addr family")
775 configure_bgp_on_r1 = {
776 "r1": {
777 "bgp": {
778 "default_ipv4_unicast": "False",
779 "peer-group": {
780 "rfc5549": {"capability": "extended-nexthop", "remote-as": "200"}
781 },
782 }
783 }
784 }
785 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
786 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
787 configure_bgp_on_r1 = {
788 "r1": {
789 "bgp": {
790 "address_family": {
791 "ipv6": {
792 "unicast": {
793 "neighbor": {
794 "r2": {
795 "dest_link": {
796 "r1-link0": {
797 "activate": "ipv4",
798 "capability": "extended-nexthop",
799 "peer-group": "rfc5549",
800 }
801 }
802 }
803 }
804 }
805 }
806 }
807 }
808 }
809 }
810 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
811 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
812 configure_bgp_on_r2 = {
813 "r2": {
814 "bgp": {
815 "default_ipv4_unicast": "False",
816 "peer-group": {
817 "rfc5549": {"capability": "extended-nexthop", "remote-as": "100"}
818 },
819 }
820 }
821 }
822 result = create_router_bgp(tgen, topo, configure_bgp_on_r2)
823 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
824 configure_bgp_on_r2 = {
825 "r2": {
826 "bgp": {
827 "address_family": {
828 "ipv6": {
829 "unicast": {
830 "neighbor": {
831 "r1": {
832 "dest_link": {
833 "r2-link0": {
834 "capability": "extended-nexthop",
835 "activate": "ipv4",
836 "peer-group": "rfc5549",
837 }
838 }
839 },
840 "r3": {"dest_link": {"r2": {}}},
841 }
842 }
843 }
844 }
845 }
846 }
847 }
848 result = create_router_bgp(tgen, topo, configure_bgp_on_r2)
849 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
850
851 configure_bgp_on_r3 = {
852 "r3": {
853 "bgp": {
854 "address_family": {
855 "ipv4": {"unicast": {"neighbor": {"r2": {"dest_link": {"r3": {}}}}}}
856 }
857 }
858 }
859 }
860 result = create_router_bgp(tgen, topo, configure_bgp_on_r3)
861 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
862
863 step("Verify bgp convergence as ipv6 nbr is enabled on ipv4 addr family.")
864 bgp_convergence = verify_bgp_convergence(tgen, topo)
865 assert bgp_convergence is True, "Testcase :Failed \n Error:" " {}".format(
866 bgp_convergence
867 )
868
869 step(" Configure 2 IPv4 static" " routes on R1, Nexthop as different links of R0")
870 for rte in range(0, NO_OF_RTES):
871 input_dict = {
872 "r1": {
873 "static_routes": [
874 {
875 "network": NETWORK["ipv4"][rte],
876 "no_of_ip": 1,
877 "next_hop": NEXT_HOP["ipv4"][rte],
878 }
879 ]
880 }
881 }
882 result = create_static_routes(tgen, input_dict)
883 assert result is True, "Testcase {} : Failed \n Error: {}".format(
884 tc_name, result
885 )
886
887 step(
888 "Advertise static routes from IPv4 unicast family and IPv6 "
889 "unicast family respectively from R1 using red static cmd "
890 "Advertise loopback from IPv4 unicast family using network command "
891 "from R1"
892 )
893
894 configure_bgp_on_r1 = {
895 "r1": {
896 "bgp": {
897 "address_family": {
898 "ipv4": {
899 "unicast": {
900 "redistribute": [{"redist_type": "static"}],
901 "advertise_networks": [
902 {"network": NETWORK_CMD_IP, "no_of_network": 1}
903 ],
904 }
905 }
906 }
907 }
908 }
909 }
910 result = create_router_bgp(tgen, topo, configure_bgp_on_r1)
911 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
912 step(
913 "IPv4 routes advertised using static and network command are "
914 " received on R2 BGP and routing table , "
915 "verify using show ip bgp, show ip route for IPv4 routes ."
916 )
917
918 gllip = get_llip("r1", "r2-link0")
919 assert gllip is not None, "Testcase {} : Failed \n Error: {}".format(
920 tc_name, result
921 )
922
923 dut = "r2"
924 protocol = "bgp"
925 verify_nh_for_static_rtes = {
926 "r1": {
927 "static_routes": [
928 {
929 "network": NETWORK["ipv4"][0],
930 "no_of_ip": NO_OF_RTES,
931 "next_hop": gllip,
932 }
933 ]
934 }
935 }
936 bgp_rib = verify_bgp_rib(
937 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip
938 )
939 assert bgp_rib is True, "Testcase {} : Failed \n Error: {}".format(tc_name, bgp_rib)
940 result = verify_rib(
941 tgen, "ipv4", dut, verify_nh_for_static_rtes, next_hop=gllip, protocol=protocol
942 )
943 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
944
945 write_test_footer(tc_name)
946
947
948 if __name__ == "__main__":
949 args = ["-s"] + sys.argv[1:]
950 sys.exit(pytest.main(args))