diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py index 7ec584bf5f..a8354f4c77 100644 --- a/tests/topotests/lib/bgp.py +++ b/tests/topotests/lib/bgp.py @@ -112,6 +112,8 @@ def create_router_bgp(tgen, topo, input_dict=None, build=False): input_dict = deepcopy(topo) else: topo = topo["routers"] + input_dict = deepcopy(input_dict) + for router in input_dict.keys(): if "bgp" not in input_dict[router]: logger.debug("Router %s: 'bgp' not present in input_dict", router) @@ -220,7 +222,7 @@ def __create_bgp_unicast_neighbor(tgen, topo, input_dict, router, logger.debug("Entering lib API: __create_bgp_unicast_neighbor()") add_neigh = True - if "router bgp "in config_data: + if "router bgp" in config_data: add_neigh = False bgp_data = input_dict[router]["bgp"]["address_family"] @@ -1366,7 +1368,7 @@ def verify_bgp_attributes(tgen, addr_type, dut, static_routes, rmap_name, logger.debug("Exiting lib API: verify_bgp_attributes()") return True -@retry(attempts=3, wait=2, return_is_str=True) +@retry(attempts=4, wait=2, return_is_str=True, initial_wait=2) def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict, attribute): """ @@ -1422,16 +1424,14 @@ def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict, rnode = tgen.routers()[router] - # TODO get addr_type from address - # Verifying show bgp json command = "show bgp {} json".format(addr_type) - sleep(2) + sleep(5) logger.info("Verifying router %s RIB for best path:", router) sh_ip_bgp_json = run_frr_cmd(rnode, command, isjson=True) for route_val in input_dict.values(): - net_data = route_val["bgp"]["address_family"]["ipv4"]["unicast"] + net_data = route_val["bgp"]["address_family"][addr_type]["unicast"] networks = net_data["advertise_networks"] for network in networks: route = network["network"] @@ -1503,8 +1503,8 @@ def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict, if route in rib_routes_json: st_found = True # Verify next_hop in rib_routes_json - if rib_routes_json[route][0]["nexthops"][0]["ip"] == \ - _next_hop: + if rib_routes_json[route][0]["nexthops"][0]["ip"] in \ + attribute_dict: nh_found = True else: errormsg = "Incorrect Nexthop for BGP route {} in " \ @@ -1526,7 +1526,6 @@ def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict, return True -@retry(attempts=3, wait=2, return_is_str=True) def verify_best_path_as_per_admin_distance(tgen, addr_type, router, input_dict, attribute): """ @@ -1568,7 +1567,7 @@ def verify_best_path_as_per_admin_distance(tgen, addr_type, router, input_dict, rnode = tgen.routers()[router] - sleep(2) + sleep(5) logger.info("Verifying router %s RIB for best path:", router) # Show ip route cmd diff --git a/tests/topotests/lib/common_config.py b/tests/topotests/lib/common_config.py index 38b97cba2d..9f2fef52ea 100644 --- a/tests/topotests/lib/common_config.py +++ b/tests/topotests/lib/common_config.py @@ -1202,6 +1202,7 @@ def create_route_maps(tgen, input_dict, build=False): "large_comm_list", {}) set_action = set_data.setdefault("set_action", None) nexthop = set_data.setdefault("nexthop", None) + origin = set_data.setdefault("origin", None) # Local Preference if local_preference: @@ -1212,6 +1213,10 @@ def create_route_maps(tgen, input_dict, build=False): if metric: rmap_data.append("set metric {} \n".format(metric)) + # Origin + if origin: + rmap_data.append("set origin {} \n".format(origin)) + # AS Path Prepend if as_path: as_num = as_path.setdefault("as_num", None) @@ -1628,9 +1633,10 @@ def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None): static_routes = input_dict[routerInput]["static_routes"] st_found = False nh_found = False - found_routes = [] - missing_routes = [] for static_route in static_routes: + found_routes = [] + missing_routes = [] + network = static_route["network"] if "no_of_ip" in static_route: no_of_ip = static_route["no_of_ip"] @@ -1667,6 +1673,7 @@ def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None): return errormsg else: missing_routes.append(st_rt) + if nh_found: logger.info("Found next_hop %s for all routes in RIB of" " router %s\n", next_hop, dut) @@ -1679,37 +1686,69 @@ def verify_rib(tgen, addr_type, dut, input_dict, next_hop=None, protocol=None): logger.info("Verified routes in router %s RIB, found routes" " are: %s\n", dut, found_routes) - advertise_network = input_dict[routerInput].setdefault( - "advertise_networks", {}) - if advertise_network: - found_routes = [] - missing_routes = [] - found = False - for advertise_network_dict in advertise_network: - start_ip = advertise_network_dict["network"] - if "no_of_network" in advertise_network_dict: - no_of_network = advertise_network_dict["no_of_network"] - else: - no_of_network = 0 + continue - # Generating IPs for verification - ip_list = generate_ips(start_ip, no_of_network) - for st_rt in ip_list: - st_rt = str(ipaddr.IPNetwork(unicode(st_rt))) + if "bgp" in input_dict[routerInput]: + if 'advertise_networks' in input_dict[routerInput]["bgp"]\ + ["address_family"][addr_type]["unicast"]: - if st_rt in rib_routes_json: - found = True - found_routes.append(st_rt) + found_routes = [] + missing_routes = [] + advertise_network = input_dict[routerInput]["bgp"]\ + ["address_family"][addr_type]["unicast"]\ + ["advertise_networks"] + + for advertise_network_dict in advertise_network: + start_ip = advertise_network_dict["network"] + if "no_of_network" in advertise_network_dict: + no_of_network = advertise_network_dict["no_of_network"] else: - missing_routes.append(st_rt) + no_of_network = 1 - if not found and len(missing_routes) > 0: - errormsg = "Missing route in RIB of router {}, are: {}" \ - " \n".format(dut, missing_routes) - return errormsg + # Generating IPs for verification + ip_list = generate_ips(start_ip, no_of_network) + for st_rt in ip_list: + st_rt = str(ipaddr.IPNetwork(unicode(st_rt))) - logger.info("Verified routes in router %s RIB, found routes" - " are: %s", dut, found_routes) + found = False + nh_found = False + if st_rt in rib_routes_json: + found = True + found_routes.append(st_rt) + + if next_hop: + if type(next_hop) is not list: + next_hop = [next_hop] + + for index, nh in enumerate(next_hop): + if rib_routes_json[st_rt][0]\ + ['nexthops'][index]['ip'] == nh: + nh_found = True + else: + errormsg=("Nexthop {} is Missing" + " for {} route {} in " + "RIB of router {}\n".\ + format(next_hop, + protocol, + st_rt, dut)) + return errormsg + + else: + missing_routes.append(st_rt) + + if nh_found: + logger.info("Found next_hop {} for all routes in RIB" + " of router {}\n".format(next_hop, dut)) + + if not found and len(missing_routes) > 0: + errormsg = ("Missing {} route in RIB of router {}, " + "routes: {} \n".\ + format(addr_type, dut, missing_routes)) + return errormsg + + logger.info("Verified {} routes in router {} RIB, found" + " routes are: {}\n".\ + format(addr_type, dut, found_routes)) logger.debug("Exiting lib API: verify_rib()") return True