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