]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/bgp_default_originate/test_bgp_default_originate_2links.py
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / tests / topotests / bgp_default_originate / test_bgp_default_originate_2links.py
1 #!/usr/bin/env python
2 #
3 # Copyright (c) 2022 by VMware, Inc. ("VMware")
4 # Used Copyright (c) 2018 by Network Device Education Foundation, Inc. ("NetDEF")
5 # in this file.
6 #
7 # Permission to use, copy, modify, and/or distribute this software
8 # for any purpose with or without fee is hereby granted, provided
9 # that the above copyright notice and this permission notice appear
10 # in all copies.
11 # Shreenidhi A R <rshreenidhi@vmware.com>
12 # THE SOFTWARE IS PROVIDED "AS IS" AND VMWARE DISCLAIMS ALL WARRANTIES
13 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL VMWARE BE LIABLE FOR
15 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
16 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
17 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
18 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
19 # OF THIS SOFTWARE.
20 #
21 """
22 Following tests are covered.
23 1. Verify default-originate route with default static and network command
24 2. Verify default-originate route with aggregate summary command
25 3. Verfiy default-originate behaviour in ecmp
26 """
27 import os
28 import sys
29 import time
30 import pytest
31 import datetime
32 from copy import deepcopy
33 from lib.topolog import logger
34
35 # pylint: disable=C0413
36 # Import topogen and topotest helpers
37 from lib.topogen import Topogen, get_topogen
38 from lib.topojson import build_config_from_json
39 from lib.topolog import logger
40
41 from lib.bgp import (
42 verify_bgp_convergence,
43 create_router_bgp,
44 verify_bgp_rib,
45 get_dut_as_number,
46 verify_rib_default_route,
47 verify_fib_default_route,
48 )
49 from lib.common_config import (
50 verify_fib_routes,
51 step,
52 create_prefix_lists,
53 run_frr_cmd,
54 create_route_maps,
55 shutdown_bringup_interface,
56 get_frr_ipv6_linklocal,
57 start_topology,
58 apply_raw_config,
59 write_test_header,
60 check_address_types,
61 write_test_footer,
62 reset_config_on_routers,
63 create_static_routes,
64 check_router_status,
65 )
66
67 # Save the Current Working Directory to find configuration files.
68 CWD = os.path.dirname(os.path.realpath(__file__))
69 sys.path.append(os.path.join(CWD, "../"))
70 sys.path.append(os.path.join(CWD, "../lib/"))
71
72 # Required to instantiate the topology builder class.
73
74 # pylint: disable=C0413
75 # Import topogen and topotest helpers
76
77 # Global variables
78 topo = None
79 NETWORK1_1 = {"ipv4": "198.51.1.1/32", "ipv6": "2001:DB8::1:1/128"}
80 NETWORK1_2 = {"ipv4": "198.51.1.2/32", "ipv6": "2001:DB8::1:2/128"}
81 NETWORK1_3 = {"ipv4": "198.51.1.3/32", "ipv6": "2001:DB8::1:3/128"}
82 NETWORK1_4 = {"ipv4": "198.51.1.4/32", "ipv6": "2001:DB8::1:4/128"}
83 NETWORK1_5 = {"ipv4": "198.51.1.5/32", "ipv6": "2001:DB8::1:5/128"}
84
85 ipv4_uptime_dict = {
86 "r2": {
87 "static_routes": [
88 {"network": "0.0.0.0/0"},
89 ]
90 }
91 }
92
93 ipv6_uptime_dict = {
94 "r2": {
95 "static_routes": [
96 {"network": "::/0"},
97 ]
98 }
99 }
100
101 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
102 NEXT_HOP_IP = {"ipv4": "Null0", "ipv6": "Null0"}
103
104 pytestmark = [pytest.mark.bgpd]
105
106
107 def setup_module(mod):
108 """
109 Sets up the pytest environment
110
111 * `mod`: module name
112 """
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 = "{}/bgp_default_originate_2links.json".format(CWD)
121 tgen = Topogen(json_file, mod.__name__)
122 global topo
123 topo = tgen.json_topo
124 # ... and here it calls Mininet initialization functions.
125
126 # Starting topology, create tmp files which are loaded to routers
127 # to start daemons and then start routers
128 start_topology(tgen)
129
130 # Creating configuration from JSON
131 build_config_from_json(tgen, topo)
132
133 global ADDR_TYPES
134 global BGP_CONVERGENCE
135 global DEFAULT_ROUTES
136 global DEFAULT_ROUTE_NXT_HOP_LINK1, DEFAULT_ROUTE_NXT_HOP_LINK2
137 ADDR_TYPES = check_address_types()
138 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
139 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
140 BGP_CONVERGENCE
141 )
142
143 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
144
145 interface = topo["routers"]["r1"]["links"]["r2-link1"]["interface"]
146 ipv6_link_local = get_frr_ipv6_linklocal(tgen, "r1", intf=interface)
147 ipv4_nxt_hop = topo["routers"]["r1"]["links"]["r2-link1"]["ipv4"].split("/")[0]
148 ipv6_nxt_hop = topo["routers"]["r1"]["links"]["r2-link1"]["ipv6"].split("/")[0]
149 DEFAULT_ROUTE_NXT_HOP_LINK1 = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local}
150
151 interface = topo["routers"]["r1"]["links"]["r2-link2"]["interface"]
152 ipv6_link_local = get_frr_ipv6_linklocal(tgen, "r1", intf=interface)
153 ipv4_nxt_hop = topo["routers"]["r1"]["links"]["r2-link2"]["ipv4"].split("/")[0]
154 ipv6_nxt_hop = topo["routers"]["r1"]["links"]["r2-link2"]["ipv6"].split("/")[0]
155 DEFAULT_ROUTE_NXT_HOP_LINK2 = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local}
156 logger.info("Running setup_module() done")
157
158
159 def teardown_module():
160 """Teardown the pytest environment"""
161
162 logger.info("Running teardown_module to delete topology")
163
164 tgen = get_topogen()
165
166 # Stop toplogy and Remove tmp files
167 tgen.stop_topology()
168
169 logger.info(
170 "Testsuite end time: {}".format(time.asctime(time.localtime(time.time())))
171 )
172 logger.info("=" * 40)
173
174
175 #####################################################
176 #
177 # Local API's
178 #
179 #####################################################
180
181
182 def get_rib_route_uptime(tgen, addr_type, dut, input_dict):
183 """
184 Verify route uptime in RIB using "show ip route"
185
186 Parameters
187 ----------
188 * `tgen` : topogen object
189 * `addr_type` : ip type, ipv4/ipv6
190 * `dut`: Device Under Test, for which user wants to test the data
191 * `input_dict` : input dict, has details of static routes
192 * `route_uptime`: uptime of the routes
193
194 Usage
195 -----
196 # Creating static routes for r1
197 input_dict_r1 = {
198 "r1": {
199 "static_routes": [
200 {
201 "network": "147.10.13.4/32"
202 },
203 {
204 "network": "147.10.12.0/24"
205 },
206 {
207 "network": "147.10.13.4/32"
208 },
209 {
210 "network": "147.10.13.4/32"
211 },
212 {
213 "network": "147.10.13.4/32"
214 }
215 ]
216 }
217 }
218
219
220 Returns
221 -------
222 errormsg(str) or True
223 """
224
225 logger.info("Entering lib API: get_rib_route_uptime()")
226 route_time = []
227 out_route_dict = {}
228 router_list = tgen.routers()
229 for routerInput in input_dict.keys():
230 for router, rnode in router_list.items():
231 if router != dut:
232 continue
233
234 logger.info("Checking router %s RIB:", router)
235
236 # Verifying RIB routes
237 if addr_type == "ipv4":
238 command = "show ip route"
239 else:
240 command = "show ipv6 route"
241
242 if "static_routes" in input_dict[routerInput]:
243 static_routes = input_dict[routerInput]["static_routes"]
244
245 for static_route in static_routes:
246 if "vrf" in static_route and static_route["vrf"] is not None:
247
248 logger.info(
249 "[DUT: {}]: Verifying routes for VRF:"
250 " {}".format(router, static_route["vrf"])
251 )
252 cmd = "{} vrf {}".format(command, static_route["vrf"])
253
254 else:
255 cmd = "{}".format(command)
256
257 cmd = "{} json".format(cmd)
258
259 rib_routes_json = run_frr_cmd(rnode, cmd, isjson=True)
260
261 if bool(rib_routes_json) is False:
262 errormsg = "No route found in rib of router {}..".format(router)
263 return errormsg
264 network = static_route["network"]
265 route_time.append(rib_routes_json[network][0]["uptime"])
266
267 logger.info("Exiting lib API: get_rib_route_uptime()")
268 return route_time
269
270
271 def verify_the_uptime(time_stamp_before, time_stamp_after, incremented=None):
272 """
273 time_stamp_before : string the time stamp captured
274 time_stamp_after : string the time stamp captured
275 """
276 uptime_before = datetime.datetime.strptime(time_stamp_before[0], "%H:%M:%S")
277 uptime_after = datetime.datetime.strptime(time_stamp_after[0], "%H:%M:%S")
278
279 if incremented == True:
280 if uptime_before < uptime_after:
281 logger.info(
282 " The Uptime [{}] is incremented than [{}].......PASSED ".format(
283 time_stamp_before, time_stamp_after
284 )
285 )
286 return True
287 else:
288 logger.error(
289 " The Uptime [{}] is expected to be incremented than [{}].......FAILED ".format(
290 time_stamp_before, time_stamp_after
291 )
292 )
293 return False
294 else:
295 logger.info(
296 " The Uptime [{}] is not incremented than [{}] ".format(
297 time_stamp_before, time_stamp_after
298 )
299 )
300 return True
301
302
303 def get_best_path_route_in_FIB(tgen, topo, dut, network):
304 """
305 API to verify the best route in FIB and return the ipv4 and ipv6 nexthop for the given route
306 command
307 =======
308 show ip route
309 show ipv6 route
310 params
311 ======
312 dut : device under test :
313 network ; route (ip) to which the best route to be retrieved
314 Returns
315 ========
316 on success : return dict with next hops for the best hop
317 on failure : return error message with boolean False
318 """
319 is_ipv4_best_path_found = False
320 is_ipv6_best_path_found = False
321 rnode = tgen.routers()[dut]
322 ipv4_show_bgp_json = run_frr_cmd(rnode, "sh ip bgp json ", isjson=True)
323 ipv6_show_bgp_json = run_frr_cmd(
324 rnode, "sh ip bgp ipv6 unicast json ", isjson=True
325 )
326 output_dict = {"ipv4": None, "ipv6": None}
327 ipv4_nxt_hop_count = len(ipv4_show_bgp_json["routes"][network["ipv4"]])
328 for index in range(ipv4_nxt_hop_count):
329 if "bestpath" in ipv4_show_bgp_json["routes"][network["ipv4"]][index].keys():
330 best_path_ip = ipv4_show_bgp_json["routes"][network["ipv4"]][index][
331 "nexthops"
332 ][0]["ip"]
333 output_dict["ipv4"] = best_path_ip
334 logger.info(
335 "[DUT [{}]] Best path for the route {} is {} ".format(
336 dut, network["ipv4"], best_path_ip
337 )
338 )
339 is_ipv4_best_path_found = True
340 else:
341 logger.error("ERROR....! No Best Path Found in BGP RIB.... FAILED")
342
343 ipv6_nxt_hop_count = len(ipv6_show_bgp_json["routes"][network["ipv6"]])
344 for index in range(ipv6_nxt_hop_count):
345 if "bestpath" in ipv6_show_bgp_json["routes"][network["ipv6"]][index].keys():
346 ip_add_count = len(
347 ipv6_show_bgp_json["routes"][network["ipv6"]][index]["nexthops"]
348 )
349 for i_index in range(ip_add_count):
350 if (
351 "global"
352 in ipv6_show_bgp_json["routes"][network["ipv6"]][index]["nexthops"][
353 i_index
354 ]["scope"]
355 ):
356 best_path_ip = ipv6_show_bgp_json["routes"][network["ipv6"]][index][
357 "nexthops"
358 ][i_index]["ip"]
359 output_dict["ipv6"] = best_path_ip
360 logger.info(
361 "[DUT [{}]] Best path for the route {} is {} ".format(
362 dut, network["ipv6"], best_path_ip
363 )
364 )
365
366 else:
367 logger.error("ERROR....! No Best Path Found in BGP RIB.... FAILED")
368 if is_ipv4_best_path_found:
369 return output_dict
370 else:
371 logger.error("ERROR...! Unable to find the Best Path in the RIB")
372 return False
373
374
375 #####################################################
376 #
377 # Testcases
378 #
379 #####################################################
380
381
382 def test_verify_bgp_default_originate_with_default_static_route_p1(request):
383 """
384 Summary: "Verify default-originate route with default static and network command "
385
386 """
387 tgen = get_topogen()
388 global BGP_CONVERGENCE, DEFAULT_ROUTE_NXT_HOP_LINK1, DEFAULT_ROUTE_NXT_HOP_LINK2, DEFAULT_ROUTES
389
390 if BGP_CONVERGENCE != True:
391 pytest.skip("skipped because of BGP Convergence failure")
392 # test case name
393 tc_name = request.node.name
394 write_test_header(tc_name)
395 if tgen.routers_have_failure():
396 check_router_status(tgen)
397 reset_config_on_routers(tgen)
398
399 step("Configure 2 link between R1 and R2")
400 step("Configure IPV4 and IPV6 EBGP between R1 and R2 both the links")
401 step("Configure default-originate on R1 IPv4 and IPv6 BGP session link-1 only ")
402 local_as = get_dut_as_number(tgen, dut="r1")
403 default_originate_config = {
404 "r1": {
405 "bgp": {
406 "local_as": local_as,
407 "address_family": {
408 "ipv4": {
409 "unicast": {
410 "default_originate": {"r2": {"dest-link": "r1-link1"}}
411 }
412 },
413 "ipv6": {
414 "unicast": {
415 "default_originate": {"r2": {"dest-link": "r1-link1"}}
416 }
417 },
418 },
419 }
420 }
421 }
422 result = create_router_bgp(tgen, topo, default_originate_config)
423 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
424
425 step("Verify IPv4/IPv6 default originate routes present on R2 nexthop as link-1")
426 for addr_type in ADDR_TYPES:
427 static_routes_input = {
428 "r2": {
429 "static_routes": [
430 {
431 "network": [DEFAULT_ROUTES[addr_type]],
432 "next_hop": DEFAULT_ROUTE_NXT_HOP_LINK1[addr_type],
433 }
434 ]
435 }
436 }
437
438 result = verify_fib_routes(
439 tgen,
440 addr_type,
441 "r2",
442 static_routes_input,
443 next_hop=DEFAULT_ROUTE_NXT_HOP_LINK1[addr_type],
444 )
445 assert result is True, "Testcase {} : Failed \n Error: {}".format(
446 tc_name, result
447 )
448
449 result = verify_bgp_rib(
450 tgen,
451 addr_type,
452 "r2",
453 static_routes_input,
454 next_hop=DEFAULT_ROUTE_NXT_HOP_LINK1[addr_type],
455 )
456 assert result is True, "Testcase {} : Failed \n Error: {}".format(
457 tc_name, result
458 )
459
460 step(
461 "Configure network command on R1 (0.0.0.0/0 and 0::0/0) for IPv4 and IPv6 address family "
462 )
463 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
464 for addr_type in ADDR_TYPES:
465 input_advertise = {
466 "r1": {
467 "bgp": {
468 "address_family": {
469 addr_type: {
470 "unicast": {
471 "advertise_networks": [
472 {"network": [DEFAULT_ROUTES[addr_type]]}
473 ]
474 }
475 }
476 }
477 }
478 }
479 }
480
481 result = create_router_bgp(tgen, topo, input_advertise)
482 assert result is True, "Testcase {} :Failed \n Error: {}".format(
483 tc_name, result
484 )
485
486 step("No change on IPv4/IPv6 default-originate route advertised from link1")
487 result = verify_rib_default_route(
488 tgen,
489 topo,
490 dut="r2",
491 routes=DEFAULT_ROUTES,
492 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
493 )
494 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
495 result = verify_fib_default_route(
496 tgen,
497 topo,
498 dut="r2",
499 routes=DEFAULT_ROUTES,
500 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
501 )
502 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
503
504 step("verify 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 ")
505 result = verify_rib_default_route(
506 tgen,
507 topo,
508 dut="r2",
509 routes=DEFAULT_ROUTES,
510 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
511 )
512 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
513 result = verify_fib_default_route(
514 tgen,
515 topo,
516 dut="r2",
517 routes=DEFAULT_ROUTES,
518 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
519 )
520 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
521
522 step(
523 "Before removing default originate from R1 link -1 IPv4 and IPv6 address family taking the uptime snapshot"
524 )
525 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
526 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
527
528 step("Remove default originate from R1 link -1 IPv4 and IPv6 address family ")
529 local_as = get_dut_as_number(tgen, dut="r1")
530 default_originate_config = {
531 "r1": {
532 "bgp": {
533 "local_as": local_as,
534 "address_family": {
535 "ipv4": {
536 "unicast": {
537 "default_originate": {
538 "r2": {"dest-link": "r1-link1", "delete": True}
539 }
540 }
541 },
542 "ipv6": {
543 "unicast": {
544 "default_originate": {
545 "r2": {"dest-link": "r1-link1", "delete": True}
546 }
547 }
548 },
549 },
550 }
551 }
552 }
553 result = create_router_bgp(tgen, topo, default_originate_config)
554 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
555
556 step("Routes must be learned from network command")
557 result = verify_rib_default_route(
558 tgen,
559 topo,
560 dut="r2",
561 routes=DEFAULT_ROUTES,
562 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
563 )
564 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
565 result = verify_fib_default_route(
566 tgen,
567 topo,
568 dut="r2",
569 routes=DEFAULT_ROUTES,
570 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
571 )
572 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
573
574 result = verify_rib_default_route(
575 tgen,
576 topo,
577 dut="r2",
578 routes=DEFAULT_ROUTES,
579 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
580 )
581 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
582 result = verify_fib_default_route(
583 tgen,
584 topo,
585 dut="r2",
586 routes=DEFAULT_ROUTES,
587 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
588 )
589 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
590
591 step("After removing the default originate on R1 taking the uptime snapshot")
592 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
593 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
594
595 step(
596 "After removing the default-originate uptime should get reset for link-1 learn route"
597 )
598 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=False)
599 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
600
601 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=False)
602 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
603
604 step("Taking uptime snapshot before configuring default - originate")
605 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
606 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
607
608 step(
609 "Configure default-originate on R1 link-1 again for IPv4 and IPv6 address family"
610 )
611 local_as = get_dut_as_number(tgen, dut="r1")
612 default_originate_config = {
613 "r1": {
614 "bgp": {
615 "local_as": local_as,
616 "address_family": {
617 "ipv4": {
618 "unicast": {
619 "default_originate": {
620 "r2": {
621 "dest-link": "r1-link1",
622 }
623 }
624 }
625 },
626 "ipv6": {
627 "unicast": {
628 "default_originate": {
629 "r2": {
630 "dest-link": "r1-link1",
631 }
632 }
633 }
634 },
635 },
636 }
637 }
638 }
639 result = create_router_bgp(tgen, topo, default_originate_config)
640 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
641
642 step("Verify No change on R2 routing and BGP table for both the links ")
643 result = verify_rib_default_route(
644 tgen,
645 topo,
646 dut="r2",
647 routes=DEFAULT_ROUTES,
648 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
649 )
650 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
651 result = verify_fib_default_route(
652 tgen,
653 topo,
654 dut="r2",
655 routes=DEFAULT_ROUTES,
656 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
657 )
658 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
659
660 result = verify_rib_default_route(
661 tgen,
662 topo,
663 dut="r2",
664 routes=DEFAULT_ROUTES,
665 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
666 )
667 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
668 result = verify_fib_default_route(
669 tgen,
670 topo,
671 dut="r2",
672 routes=DEFAULT_ROUTES,
673 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
674 )
675 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
676
677 step("Taking snapshot after configuring default - originate")
678 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
679 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
680
681 step(
682 "After configuring the default-originate uptime should not get reset for link-1 learn route"
683 )
684 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=True)
685 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
686
687 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=True)
688 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
689
690 step("Taking uptime snapshot before removing network 0.0.0.0 ")
691 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
692 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
693
694 step("Remove network command from R1 IPv4/IPv6 address family ")
695 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
696 for addr_type in ADDR_TYPES:
697 input_advertise = {
698 "r1": {
699 "bgp": {
700 "address_family": {
701 addr_type: {
702 "unicast": {
703 "advertise_networks": [
704 {
705 "network": [DEFAULT_ROUTES[addr_type]],
706 "delete": True,
707 }
708 ]
709 }
710 }
711 }
712 }
713 }
714 }
715
716 result = create_router_bgp(tgen, topo, input_advertise)
717 assert result is True, "Testcase {} :Failed \n Error: {}".format(
718 tc_name, result
719 )
720
721 step(
722 "Verify 0.0.0.0/0 and 0::0/0 route get removed from link-2 and default-originate IPv4/IPv6 route learn on link-1"
723 )
724 result = verify_rib_default_route(
725 tgen,
726 topo,
727 dut="r2",
728 routes=DEFAULT_ROUTES,
729 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
730 )
731 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
732 result = verify_fib_default_route(
733 tgen,
734 topo,
735 dut="r2",
736 routes=DEFAULT_ROUTES,
737 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
738 )
739 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
740
741 result = verify_rib_default_route(
742 tgen,
743 topo,
744 dut="r2",
745 routes=DEFAULT_ROUTES,
746 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
747 expected=False,
748 )
749 assert (
750 result is not True
751 ), "Testcase {} : Failed \n Route from link2 is not expected \n Error: {}".format(
752 tc_name, result
753 )
754 result = verify_fib_default_route(
755 tgen,
756 topo,
757 dut="r2",
758 routes=DEFAULT_ROUTES,
759 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
760 expected=False,
761 )
762 assert (
763 result is not True
764 ), "Testcase {} : Failed\n Route from link2 is not expected \n Error: {}".format(
765 tc_name, result
766 )
767
768 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
769 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
770
771 step(
772 "After removing default originate command on R1 verify that the uptime got reset on R2"
773 )
774
775 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=False)
776 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
777
778 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=False)
779 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
780
781 step("Taking uptime snapshot before configuring static route network")
782 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
783 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
784
785 step(
786 "Configure static default route for IPv4 and IPv6 (0.0.0.0/0 next-hop Null0 and 0::0/0 next-hop Null0) on R1"
787 )
788 static_routes_input = {
789 "r1": {
790 "static_routes": [
791 {
792 "network": "0.0.0.0/0",
793 "next_hop": NEXT_HOP_IP["ipv4"],
794 },
795 {
796 "network": "0::0/0",
797 "next_hop": NEXT_HOP_IP["ipv6"],
798 },
799 ]
800 }
801 }
802 result = create_static_routes(tgen, static_routes_input)
803 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
804
805 step("verifyIPv4 and IPv6 static routes are configure and up on R1 ")
806 for addr_type in ADDR_TYPES:
807 static_routes_input = {
808 "r1": {
809 "static_routes": [
810 {
811 "network": "0.0.0.0/0",
812 "next_hop": NEXT_HOP_IP["ipv4"],
813 },
814 {
815 "network": "0::0/0",
816 "next_hop": NEXT_HOP_IP["ipv6"],
817 },
818 ]
819 }
820 }
821 result = verify_fib_routes(tgen, addr_type, "r1", static_routes_input)
822 assert result is True, "Testcase {} : Failed \n Error: {}".format(
823 tc_name, result
824 )
825
826 step("Configure redistribute static on IPv4 and IPv6 address family")
827 redistribute_static = {
828 "r1": {
829 "bgp": {
830 "address_family": {
831 "ipv4": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
832 "ipv6": {"unicast": {"redistribute": [{"redist_type": "static"}]}},
833 }
834 }
835 }
836 }
837 result = create_router_bgp(tgen, topo, redistribute_static)
838 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
839
840 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
841 result = verify_rib_default_route(
842 tgen,
843 topo,
844 dut="r2",
845 routes=DEFAULT_ROUTES,
846 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
847 )
848 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
849 result = verify_fib_default_route(
850 tgen,
851 topo,
852 dut="r2",
853 routes=DEFAULT_ROUTES,
854 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
855 )
856 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
857
858 step("verify 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 ")
859 result = verify_rib_default_route(
860 tgen,
861 topo,
862 dut="r2",
863 routes=DEFAULT_ROUTES,
864 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
865 )
866 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
867 result = verify_fib_default_route(
868 tgen,
869 topo,
870 dut="r2",
871 routes=DEFAULT_ROUTES,
872 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
873 expected=False,
874 )
875 assert (
876 result is not True
877 ), "Testcase {} : Failed\n Best Path sould be advertised in routes\n Error: {}".format(
878 tc_name, result
879 )
880
881 step("Taking uptime snapshot before removing default originate")
882 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
883 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
884
885 step("Remove default-originate from link-1 from IPv4 and IPv6 neighbor ")
886 local_as = get_dut_as_number(tgen, dut="r1")
887 default_originate_config = {
888 "r1": {
889 "bgp": {
890 "local_as": local_as,
891 "address_family": {
892 "ipv4": {
893 "unicast": {
894 "default_originate": {
895 "r2": {"dest-link": "r1-link1", "delete": True}
896 }
897 }
898 },
899 "ipv6": {
900 "unicast": {
901 "default_originate": {
902 "r2": {"dest-link": "r1-link1", "delete": True}
903 }
904 }
905 },
906 },
907 }
908 }
909 }
910 result = create_router_bgp(tgen, topo, default_originate_config)
911 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
912
913 step("Taking uptime snapshot after removing default originate")
914 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
915 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
916
917 step("verify the up time , up time should get reset ")
918 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=False)
919 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
920
921 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=False)
922 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
923
924 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
925 result = verify_rib_default_route(
926 tgen,
927 topo,
928 dut="r2",
929 routes=DEFAULT_ROUTES,
930 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
931 )
932 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
933 result = verify_fib_default_route(
934 tgen,
935 topo,
936 dut="r2",
937 routes=DEFAULT_ROUTES,
938 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
939 )
940 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
941
942 result = verify_rib_default_route(
943 tgen,
944 topo,
945 dut="r2",
946 routes=DEFAULT_ROUTES,
947 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
948 )
949 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
950 result = verify_fib_default_route(
951 tgen,
952 topo,
953 dut="r2",
954 routes=DEFAULT_ROUTES,
955 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
956 )
957 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
958
959 step("Taking uptime snapshot before configuring default originate")
960 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
961 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
962
963 step(
964 " Configure default-originate on link-1 again for IPv4 and IPv6 address family"
965 )
966 local_as = get_dut_as_number(tgen, dut="r1")
967 default_originate_config = {
968 "r1": {
969 "bgp": {
970 "local_as": local_as,
971 "address_family": {
972 "ipv4": {
973 "unicast": {
974 "default_originate": {
975 "r2": {
976 "dest-link": "r1-link1",
977 }
978 }
979 }
980 },
981 "ipv6": {
982 "unicast": {
983 "default_originate": {
984 "r2": {
985 "dest-link": "r1-link1",
986 }
987 }
988 }
989 },
990 },
991 }
992 }
993 }
994 result = create_router_bgp(tgen, topo, default_originate_config)
995 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
996
997 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
998 result = verify_rib_default_route(
999 tgen,
1000 topo,
1001 dut="r2",
1002 routes=DEFAULT_ROUTES,
1003 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1004 )
1005 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1006 result = verify_fib_default_route(
1007 tgen,
1008 topo,
1009 dut="r2",
1010 routes=DEFAULT_ROUTES,
1011 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1012 )
1013 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1014
1015 result = verify_rib_default_route(
1016 tgen,
1017 topo,
1018 dut="r2",
1019 routes=DEFAULT_ROUTES,
1020 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
1021 )
1022 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1023 result = verify_fib_default_route(
1024 tgen,
1025 topo,
1026 dut="r2",
1027 routes=DEFAULT_ROUTES,
1028 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
1029 expected=False,
1030 )
1031 assert result is not True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1032
1033 step("Taking uptime snapshot after configuring default originate")
1034 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1035 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1036
1037 step("After configuring the default originate the uptime should not get reset ")
1038 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=False)
1039 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1040 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=False)
1041 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1042
1043 step("Taking uptime snapshot before removing redisctribute static ")
1044 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1045 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1046
1047 step("Remove redistribute static from IPv4 and IPv6 address family ")
1048 input_dict_1 = {
1049 "r1": {
1050 "bgp": {
1051 "local_as": get_dut_as_number(tgen, dut="r1"),
1052 "address_family": {
1053 "ipv4": {
1054 "unicast": {
1055 "redistribute": [{"redist_type": "static", "delete": True}]
1056 }
1057 },
1058 "ipv6": {
1059 "unicast": {
1060 "redistribute": [{"redist_type": "static", "delete": True}]
1061 }
1062 },
1063 },
1064 }
1065 }
1066 }
1067
1068 result = create_router_bgp(tgen, topo, input_dict_1)
1069 assert result is True, "Testcase {} :Failed \n Error: {}".format(tc_name, result)
1070
1071 step("Verify No change on IPv4/IPv6 default-originate route advertised from link1")
1072 result = verify_rib_default_route(
1073 tgen,
1074 topo,
1075 dut="r2",
1076 routes=DEFAULT_ROUTES,
1077 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1078 )
1079 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1080 result = verify_fib_default_route(
1081 tgen,
1082 topo,
1083 dut="r2",
1084 routes=DEFAULT_ROUTES,
1085 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1086 )
1087 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1088
1089 result = verify_rib_default_route(
1090 tgen,
1091 topo,
1092 dut="r2",
1093 routes=DEFAULT_ROUTES,
1094 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
1095 expected=False,
1096 )
1097 assert result is not True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1098 result = verify_fib_default_route(
1099 tgen,
1100 topo,
1101 dut="r2",
1102 routes=DEFAULT_ROUTES,
1103 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
1104 expected=False,
1105 )
1106 assert result is not True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1107
1108 step("Taking uptime snapshot before removing redisctribute static ")
1109 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1110 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1111
1112 step("After removing default originate the route uptime should get reset ")
1113 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=True)
1114 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1115
1116 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=True)
1117 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1118 write_test_footer(tc_name)
1119
1120
1121 def test_verify_bgp_default_originate_with_aggregate_summary_p1(request):
1122 """
1123 Summary: "Verify default-originate route with aggregate summary command"
1124 """
1125 tgen = get_topogen()
1126 global BGP_CONVERGENCE
1127 tc_name = request.node.name
1128 write_test_header(tc_name)
1129 if tgen.routers_have_failure():
1130 check_router_status(tgen)
1131 reset_config_on_routers(tgen)
1132 if BGP_CONVERGENCE != True:
1133 pytest.skip("skipped because of BGP Convergence failure")
1134
1135 step("After changing the BGP AS Path Verify the BGP Convergence")
1136 BGP_CONVERGENCE = verify_bgp_convergence(tgen, topo)
1137 assert BGP_CONVERGENCE is True, "setup_module :Failed \n Error: {}".format(
1138 BGP_CONVERGENCE
1139 )
1140
1141 step("Configure default-originate on R1 IPv4 and IPv6 BGP session link-1 only")
1142 local_as = get_dut_as_number(tgen, dut="r1")
1143 default_originate_config = {
1144 "r1": {
1145 "bgp": {
1146 "local_as": local_as,
1147 "address_family": {
1148 "ipv4": {
1149 "unicast": {
1150 "default_originate": {"r2": {"dest-link": "r1-link1"}}
1151 }
1152 },
1153 "ipv6": {
1154 "unicast": {
1155 "default_originate": {"r2": {"dest-link": "r1-link1"}}
1156 }
1157 },
1158 },
1159 }
1160 }
1161 }
1162 result = create_router_bgp(tgen, topo, default_originate_config)
1163 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1164
1165 step(
1166 "Verify IPv4/IPv6 default originate routes present on R2 nexthop as link-1,on R2"
1167 )
1168 result = verify_rib_default_route(
1169 tgen,
1170 topo,
1171 dut="r2",
1172 routes=DEFAULT_ROUTES,
1173 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1174 )
1175 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1176 result = verify_fib_default_route(
1177 tgen,
1178 topo,
1179 dut="r2",
1180 routes=DEFAULT_ROUTES,
1181 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1182 )
1183 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1184
1185 step("Configure 5 static route for IPv4 and IPv6 on R0")
1186 for addr_type in ADDR_TYPES:
1187 input_advertise = {
1188 "r1": {
1189 "bgp": {
1190 "address_family": {
1191 addr_type: {
1192 "unicast": {
1193 "advertise_networks": [
1194 {
1195 "network": [NETWORK1_1[addr_type]],
1196 "next_hop": NEXT_HOP_IP[addr_type],
1197 },
1198 {
1199 "network": [NETWORK1_2[addr_type]],
1200 "next_hop": NEXT_HOP_IP[addr_type],
1201 },
1202 {
1203 "network": [NETWORK1_3[addr_type]],
1204 "next_hop": NEXT_HOP_IP[addr_type],
1205 },
1206 {
1207 "network": [NETWORK1_4[addr_type]],
1208 "next_hop": NEXT_HOP_IP[addr_type],
1209 },
1210 {
1211 "network": [NETWORK1_5[addr_type]],
1212 "next_hop": NEXT_HOP_IP[addr_type],
1213 },
1214 ]
1215 }
1216 }
1217 }
1218 }
1219 }
1220 }
1221
1222 result = create_router_bgp(tgen, topo, input_advertise)
1223 assert result is True, "Testcase {} :Failed \n Error: {}".format(
1224 tc_name, result
1225 )
1226
1227 step("Before configuring the aggregate route taking uptime snapshot ")
1228 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1229 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1230
1231 step("Configure aggregate summary command for IPv4 and IPv6 address family ")
1232 local_as = get_dut_as_number(tgen, dut="r1")
1233 raw_config = {
1234 "r1": {
1235 "raw_config": [
1236 "router bgp {}".format(local_as),
1237 "address-family ipv4 unicast",
1238 "aggregate-address {} summary-only".format("0.0.0.0/0 "),
1239 "exit-address-family",
1240 "address-family ipv6 unicast",
1241 "aggregate-address {} summary-only".format("0::0/0"),
1242 "exit-address-family",
1243 ]
1244 }
1245 }
1246 result = apply_raw_config(tgen, raw_config)
1247 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1248
1249 step(
1250 "verify that no change on IPv4/IPv6 default-originate route advertised from link1 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 on R2"
1251 )
1252 result = verify_rib_default_route(
1253 tgen,
1254 topo,
1255 dut="r2",
1256 routes=DEFAULT_ROUTES,
1257 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1258 )
1259 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1260 result = verify_fib_default_route(
1261 tgen,
1262 topo,
1263 dut="r2",
1264 routes=DEFAULT_ROUTES,
1265 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1266 )
1267 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1268
1269 result = verify_rib_default_route(
1270 tgen,
1271 topo,
1272 dut="r2",
1273 routes=DEFAULT_ROUTES,
1274 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
1275 )
1276 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1277 result = verify_fib_default_route(
1278 tgen,
1279 topo,
1280 dut="r2",
1281 routes=DEFAULT_ROUTES,
1282 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
1283 )
1284 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1285
1286 step("After configuring the aggregate route taking uptime snapshot ")
1287 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1288 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1289
1290 step(
1291 "After Configuring the aggregate route uptime should get reset for link-1 learn route"
1292 )
1293 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=False)
1294 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1295
1296 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=False)
1297 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1298
1299 step("Before removing default originate taking uptime snapshot ")
1300 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1301 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1302
1303 step("Remove default originate from R1 link -1 IPv4 and IPv6 address family")
1304 local_as = get_dut_as_number(tgen, dut="r1")
1305 default_originate_config = {
1306 "r1": {
1307 "bgp": {
1308 "local_as": local_as,
1309 "address_family": {
1310 "ipv4": {
1311 "unicast": {
1312 "default_originate": {
1313 "r2": {"dest-link": "r1-link1", "delete": True}
1314 }
1315 }
1316 },
1317 "ipv6": {
1318 "unicast": {
1319 "default_originate": {
1320 "r2": {"dest-link": "r1-link1", "delete": True}
1321 }
1322 }
1323 },
1324 },
1325 }
1326 }
1327 }
1328 result = create_router_bgp(tgen, topo, default_originate_config)
1329 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1330
1331 step(
1332 "verify that no change on IPv4/IPv6 default-originate route advertised from link1 0.0.0.0/0 and 0::0/0 route also get advertised from link-2 on R2"
1333 )
1334 result = verify_rib_default_route(
1335 tgen,
1336 topo,
1337 dut="r2",
1338 routes=DEFAULT_ROUTES,
1339 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1340 )
1341 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1342 result = verify_fib_default_route(
1343 tgen,
1344 topo,
1345 dut="r2",
1346 routes=DEFAULT_ROUTES,
1347 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1348 )
1349 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1350
1351 step("After removing default origin taking uptime snapshot ")
1352 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1353 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1354
1355 step(
1356 "After removing the default-originate uptime should get reset for link-1 learn route"
1357 )
1358 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=False)
1359 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1360
1361 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=False)
1362 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1363
1364 step("Before Configuring default origin taking uptime snapshot ")
1365 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1366 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1367
1368 step(
1369 "Configure default-originate on R1 link-1 again for IPv4 and IPv6 address family"
1370 )
1371 local_as = get_dut_as_number(tgen, dut="r1")
1372 default_originate_config = {
1373 "r1": {
1374 "bgp": {
1375 "local_as": local_as,
1376 "address_family": {
1377 "ipv4": {
1378 "unicast": {
1379 "default_originate": {
1380 "r2": {
1381 "dest-link": "r1-link1",
1382 }
1383 }
1384 }
1385 },
1386 "ipv6": {
1387 "unicast": {
1388 "default_originate": {
1389 "r2": {
1390 "dest-link": "r1-link1",
1391 }
1392 }
1393 }
1394 },
1395 },
1396 }
1397 }
1398 }
1399 result = create_router_bgp(tgen, topo, default_originate_config)
1400 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1401
1402 step("After Configuring default originate taking uptime snapshot")
1403 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1404 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1405
1406 step(
1407 "After Configuring the default-originate uptime should get reset for link-1 learn route"
1408 )
1409 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=False)
1410 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1411
1412 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=False)
1413 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1414
1415 step("Before removing aggregate -summary command taking the uptime snapshot ")
1416 uptime_before_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1417 uptime_before_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1418
1419 step("remove aggregate summary command for IPv4 and IPv6 address family ")
1420 local_as = get_dut_as_number(tgen, dut="r1")
1421 raw_config = {
1422 "r1": {
1423 "raw_config": [
1424 "router bgp {}".format(local_as),
1425 "address-family ipv4 unicast",
1426 "no aggregate-address {} summary-only".format("0.0.0.0/0"),
1427 "exit-address-family",
1428 "address-family ipv6 unicast",
1429 "no aggregate-address {} summary-only".format("0::0/0"),
1430 "exit-address-family",
1431 ]
1432 }
1433 }
1434 result = apply_raw_config(tgen, raw_config)
1435 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1436
1437 step("Verify Default-originate IPv4/IPv6 route learn on link-1 ")
1438 result = verify_rib_default_route(
1439 tgen,
1440 topo,
1441 dut="r2",
1442 routes=DEFAULT_ROUTES,
1443 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1444 )
1445 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1446 result = verify_fib_default_route(
1447 tgen,
1448 topo,
1449 dut="r2",
1450 routes=DEFAULT_ROUTES,
1451 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK1,
1452 )
1453 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1454
1455 step("Verify 0.0.0.0/0 and 0::0/0 route get removed from link-2 ")
1456 result = verify_rib_default_route(
1457 tgen,
1458 topo,
1459 dut="r2",
1460 routes=DEFAULT_ROUTES,
1461 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
1462 expected=False,
1463 )
1464 assert result is not True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1465 result = verify_fib_default_route(
1466 tgen,
1467 topo,
1468 dut="r2",
1469 routes=DEFAULT_ROUTES,
1470 expected_nexthop=DEFAULT_ROUTE_NXT_HOP_LINK2,
1471 expected=False,
1472 )
1473 assert result is not True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1474
1475 step("After removing aggregate -summary command taking the uptime snapshot ")
1476 uptime_after_ipv4 = get_rib_route_uptime(tgen, "ipv4", "r2", ipv4_uptime_dict)
1477 uptime_after_ipv6 = get_rib_route_uptime(tgen, "ipv6", "r2", ipv6_uptime_dict)
1478
1479 step("After removing aggregate command uptime should get reset ")
1480 result = verify_the_uptime(uptime_before_ipv4, uptime_after_ipv4, incremented=False)
1481 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1482
1483 result = verify_the_uptime(uptime_before_ipv6, uptime_after_ipv6, incremented=False)
1484 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1485 write_test_footer(tc_name)
1486
1487
1488 def test_verify_default_originate_with_2way_ecmp_p2(request):
1489 """
1490 Summary: "Verify default-originate route with 3 way ECMP and traffic "
1491 """
1492
1493 tgen = get_topogen()
1494 global BGP_CONVERGENCE
1495 global DEFAULT_ROUTES
1496 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1497
1498 if BGP_CONVERGENCE != True:
1499 pytest.skip("skipped because of BGP Convergence failure")
1500 # test case name
1501 tc_name = request.node.name
1502 write_test_header(tc_name)
1503 if tgen.routers_have_failure():
1504 check_router_status(tgen)
1505 reset_config_on_routers(tgen)
1506
1507 step("Populating next-hops details")
1508 r1_r2_ipv4_neighbor_ips = []
1509 r1_r2_ipv6_neighbor_ips = []
1510 r1_link = None
1511 for index in range(1, 3):
1512 r1_link = "r1-link" + str(index)
1513 r1_r2_ipv4_neighbor_ips.append(
1514 topo["routers"]["r2"]["links"][r1_link]["ipv4"].split("/")[0]
1515 )
1516 r1_r2_ipv6_neighbor_ips.append(
1517 topo["routers"]["r2"]["links"][r1_link]["ipv6"].split("/")[0]
1518 )
1519
1520 step(
1521 "Configure default-originate on R1 for all the neighbor of IPv4 and IPv6 peers "
1522 )
1523 local_as = get_dut_as_number(tgen, dut="r1")
1524 for index in range(2):
1525 raw_config = {
1526 "r1": {
1527 "raw_config": [
1528 "router bgp {}".format(local_as),
1529 "address-family ipv4 unicast",
1530 "neighbor {} default-originate".format(
1531 r1_r2_ipv4_neighbor_ips[index]
1532 ),
1533 "exit-address-family",
1534 "address-family ipv6 unicast",
1535 "neighbor {} default-originate ".format(
1536 r1_r2_ipv6_neighbor_ips[index]
1537 ),
1538 "exit-address-family",
1539 ]
1540 }
1541 }
1542 result = apply_raw_config(tgen, raw_config)
1543 assert result is True, "Testcase {} : Failed Error: {}".format(tc_name, result)
1544
1545 step(
1546 "After configuring default-originate command , verify default routes are advertised on R2 "
1547 )
1548
1549 r2_link = None
1550 for index in range(1, 3):
1551 r2_link = "r2-link" + str(index)
1552 ipv4_nxt_hop = topo["routers"]["r1"]["links"][r2_link]["ipv4"].split("/")[0]
1553 interface = topo["routers"]["r1"]["links"][r2_link]["interface"]
1554 ipv6_link_local_nxt_hop = get_frr_ipv6_linklocal(tgen, "r1", intf=interface)
1555 DEFAULT_ROUTE_NXT_HOP = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local_nxt_hop}
1556
1557 result = verify_rib_default_route(
1558 tgen,
1559 topo,
1560 dut="r2",
1561 routes=DEFAULT_ROUTES,
1562 expected_nexthop=DEFAULT_ROUTE_NXT_HOP,
1563 )
1564 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1565 tc_name, result
1566 )
1567
1568 step("Ping R1 configure IPv4 and IPv6 loopback address from R2")
1569 pingaddr = topo["routers"]["r1"]["links"]["lo"]["ipv4"].split("/")[0]
1570 router = tgen.gears["r2"]
1571 output = router.run("ping -c 4 -w 4 {}".format(pingaddr))
1572 assert " 0% packet loss" in output, "Ping R1->R2 FAILED"
1573 logger.info("Ping from R1 to R2 ... success")
1574
1575 step("Shuting up the active route")
1576 network = {"ipv4": "0.0.0.0/0", "ipv6": "::/0"}
1577 ipv_dict = get_best_path_route_in_FIB(tgen, topo, dut="r2", network=network)
1578 dut_links = topo["routers"]["r1"]["links"]
1579 active_interface = None
1580 for key, values in dut_links.items():
1581 ipv4_address = dut_links[key]["ipv4"].split("/")[0]
1582 ipv6_address = dut_links[key]["ipv6"].split("/")[0]
1583 if ipv_dict["ipv4"] == ipv4_address and ipv_dict["ipv6"] == ipv6_address:
1584 active_interface = dut_links[key]["interface"]
1585
1586 logger.info(
1587 "Shutting down the interface {} on router {} ".format(active_interface, "r1")
1588 )
1589 shutdown_bringup_interface(tgen, "r1", active_interface, False)
1590
1591 step("Verify the complete convergence to fail after shutting the interface")
1592 result = verify_bgp_convergence(tgen, topo, expected=False)
1593 assert (
1594 result is not True
1595 ), " Testcase {} : After shuting down the interface Convergence is expected to be Failed".format(
1596 tc_name
1597 )
1598
1599 step(
1600 "Verify routes from active best path is not received from r1 after shuting the interface"
1601 )
1602 r2_link = None
1603 for index in range(1, 3):
1604 r2_link = "r2-link" + str(index)
1605 ipv4_nxt_hop = topo["routers"]["r1"]["links"][r2_link]["ipv4"].split("/")[0]
1606 interface = topo["routers"]["r1"]["links"][r2_link]["interface"]
1607 ipv6_link_local_nxt_hop = get_frr_ipv6_linklocal(tgen, "r1", intf=interface)
1608 DEFAULT_ROUTE_NXT_HOP = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local_nxt_hop}
1609 if index == 1:
1610 result = verify_rib_default_route(
1611 tgen,
1612 topo,
1613 dut="r2",
1614 routes=DEFAULT_ROUTES,
1615 expected_nexthop=DEFAULT_ROUTE_NXT_HOP,
1616 expected=False,
1617 )
1618 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
1619 tc_name, result
1620 )
1621 else:
1622 result = verify_rib_default_route(
1623 tgen,
1624 topo,
1625 dut="r2",
1626 routes=DEFAULT_ROUTES,
1627 expected_nexthop=DEFAULT_ROUTE_NXT_HOP,
1628 )
1629 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1630 tc_name, result
1631 )
1632
1633 step("Ping R1 configure IPv4 and IPv6 loopback address from R2")
1634 pingaddr = topo["routers"]["r1"]["links"]["lo"]["ipv4"].split("/")[0]
1635 router = tgen.gears["r2"]
1636 output = router.run("ping -c 4 -w 4 {}".format(pingaddr))
1637 assert " 0% packet loss" in output, "Ping R1->R2 FAILED"
1638 logger.info("Ping from R1 to R2 ... success")
1639
1640 step("No Shuting up the active route")
1641
1642 shutdown_bringup_interface(tgen, "r1", active_interface, True)
1643
1644 step("Verify the complete convergence after bringup the interface")
1645 result = verify_bgp_convergence(tgen, topo)
1646 assert (
1647 result is True
1648 ), " Testcase {} : After bringing up the interface complete convergence is expected ".format(
1649 tc_name
1650 )
1651
1652 step("Verify all the routes are received from r1 after no shuting the interface")
1653 r2_link = None
1654 for index in range(1, 3):
1655 r2_link = "r2-link" + str(index)
1656 ipv4_nxt_hop = topo["routers"]["r1"]["links"][r2_link]["ipv4"].split("/")[0]
1657 interface = topo["routers"]["r1"]["links"][r2_link]["interface"]
1658 ipv6_link_local_nxt_hop = get_frr_ipv6_linklocal(tgen, "r1", intf=interface)
1659 DEFAULT_ROUTE_NXT_HOP = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local_nxt_hop}
1660 if index == 1:
1661 result = verify_rib_default_route(
1662 tgen,
1663 topo,
1664 dut="r2",
1665 routes=DEFAULT_ROUTES,
1666 expected_nexthop=DEFAULT_ROUTE_NXT_HOP,
1667 )
1668 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1669 tc_name, result
1670 )
1671 else:
1672 result = verify_rib_default_route(
1673 tgen,
1674 topo,
1675 dut="r2",
1676 routes=DEFAULT_ROUTES,
1677 expected_nexthop=DEFAULT_ROUTE_NXT_HOP,
1678 )
1679 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1680 tc_name, result
1681 )
1682
1683 step(
1684 "Configure IPv4 and IPv6 route-map with deny option on R2 to filter default route 0.0.0.0/0 and 0::0/0"
1685 )
1686 DEFAULT_ROUTES = {"ipv4": "0.0.0.0/0", "ipv6": "0::0/0"}
1687 input_dict_3 = {
1688 "r2": {
1689 "prefix_lists": {
1690 "ipv4": {
1691 "Pv4": [
1692 {
1693 "seqid": "1",
1694 "network": DEFAULT_ROUTES["ipv4"],
1695 "action": "permit",
1696 }
1697 ]
1698 },
1699 "ipv6": {
1700 "Pv6": [
1701 {
1702 "seqid": "1",
1703 "network": DEFAULT_ROUTES["ipv6"],
1704 "action": "permit",
1705 }
1706 ]
1707 },
1708 }
1709 }
1710 }
1711 result = create_prefix_lists(tgen, input_dict_3)
1712 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1713
1714 input_dict_3 = {
1715 "r2": {
1716 "route_maps": {
1717 "RMv4": [
1718 {
1719 "action": "deny",
1720 "seq_id": "1",
1721 "match": {"ipv4": {"prefix_lists": "Pv4"}},
1722 },
1723 ],
1724 "RMv6": [
1725 {
1726 "action": "deny",
1727 "seq_id": "1",
1728 "match": {"ipv6": {"prefix_lists": "Pv6"}},
1729 },
1730 ],
1731 }
1732 }
1733 }
1734 result = create_route_maps(tgen, input_dict_3)
1735 assert result is True, "Testcase {} : Failed \n Error: {}".format(tc_name, result)
1736
1737 step("Apply route-map IN direction of R2 ( R2-R1) for IPv4 and IPv6 BGP neighbors")
1738 r2_link = None
1739 for index in range(1, 3):
1740 r2_link = "r2-link" + str(index)
1741 input_dict_4 = {
1742 "r2": {
1743 "bgp": {
1744 "address_family": {
1745 "ipv4": {
1746 "unicast": {
1747 "neighbor": {
1748 "r1": {
1749 "dest_link": {
1750 r2_link: {
1751 "route_maps": [
1752 {"name": "RMv4", "direction": "in"}
1753 ]
1754 },
1755 }
1756 }
1757 }
1758 }
1759 },
1760 "ipv6": {
1761 "unicast": {
1762 "neighbor": {
1763 "r1": {
1764 "dest_link": {
1765 r2_link: {
1766 "route_maps": [
1767 {"name": "RMv6", "direction": "in"}
1768 ]
1769 },
1770 }
1771 }
1772 }
1773 }
1774 },
1775 }
1776 }
1777 }
1778 }
1779 result = create_router_bgp(tgen, topo, input_dict_4)
1780 assert result is True, "Testcase {} : Failed \n Error: {}".format(
1781 tc_name, result
1782 )
1783
1784 step("After applying the route-map the routes are not expected in RIB ")
1785 r2_link = None
1786 for index in range(1, 3):
1787 r2_link = "r2-link" + str(index)
1788 ipv4_nxt_hop = topo["routers"]["r1"]["links"][r2_link]["ipv4"].split("/")[0]
1789 interface = topo["routers"]["r1"]["links"][r2_link]["interface"]
1790 ipv6_link_local_nxt_hop = get_frr_ipv6_linklocal(tgen, "r1", intf=interface)
1791 DEFAULT_ROUTE_NXT_HOP = {"ipv4": ipv4_nxt_hop, "ipv6": ipv6_link_local_nxt_hop}
1792
1793 result = verify_rib_default_route(
1794 tgen,
1795 topo,
1796 dut="r2",
1797 routes=DEFAULT_ROUTES,
1798 expected_nexthop=DEFAULT_ROUTE_NXT_HOP,
1799 expected=False,
1800 )
1801 assert result is not True, "Testcase {} : Failed \n Error: {}".format(
1802 tc_name, result
1803 )
1804
1805 write_test_footer(tc_name)
1806
1807
1808 if __name__ == "__main__":
1809 args = ["-s"] + sys.argv[1:]
1810 sys.exit(pytest.main(args))