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