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