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