mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-04 12:25:58 +00:00
tests: Enhance BGP Path attribute APIs
Modified affacted APIs to supported BGP Path attributes modification and verification Signed-off-by: Kuldeep Kashyap <kuldeepkas@gmail.com>
This commit is contained in:
parent
acf061a9ab
commit
c7bb8a05ff
@ -112,6 +112,8 @@ def create_router_bgp(tgen, topo, input_dict=None, build=False):
|
|||||||
input_dict = deepcopy(topo)
|
input_dict = deepcopy(topo)
|
||||||
else:
|
else:
|
||||||
topo = topo["routers"]
|
topo = topo["routers"]
|
||||||
|
input_dict = deepcopy(input_dict)
|
||||||
|
|
||||||
for router in input_dict.keys():
|
for router in input_dict.keys():
|
||||||
if "bgp" not in input_dict[router]:
|
if "bgp" not in input_dict[router]:
|
||||||
logger.debug("Router %s: 'bgp' not present 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()")
|
logger.debug("Entering lib API: __create_bgp_unicast_neighbor()")
|
||||||
|
|
||||||
add_neigh = True
|
add_neigh = True
|
||||||
if "router bgp "in config_data:
|
if "router bgp" in config_data:
|
||||||
add_neigh = False
|
add_neigh = False
|
||||||
bgp_data = input_dict[router]["bgp"]["address_family"]
|
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()")
|
logger.debug("Exiting lib API: verify_bgp_attributes()")
|
||||||
return True
|
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,
|
def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict,
|
||||||
attribute):
|
attribute):
|
||||||
"""
|
"""
|
||||||
@ -1422,16 +1424,14 @@ def verify_best_path_as_per_bgp_attribute(tgen, addr_type, router, input_dict,
|
|||||||
|
|
||||||
rnode = tgen.routers()[router]
|
rnode = tgen.routers()[router]
|
||||||
|
|
||||||
# TODO get addr_type from address
|
|
||||||
# Verifying show bgp json
|
|
||||||
command = "show bgp {} json".format(addr_type)
|
command = "show bgp {} json".format(addr_type)
|
||||||
|
|
||||||
sleep(2)
|
sleep(5)
|
||||||
logger.info("Verifying router %s RIB for best path:", router)
|
logger.info("Verifying router %s RIB for best path:", router)
|
||||||
sh_ip_bgp_json = run_frr_cmd(rnode, command, isjson=True)
|
sh_ip_bgp_json = run_frr_cmd(rnode, command, isjson=True)
|
||||||
|
|
||||||
for route_val in input_dict.values():
|
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"]
|
networks = net_data["advertise_networks"]
|
||||||
for network in networks:
|
for network in networks:
|
||||||
route = network["network"]
|
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:
|
if route in rib_routes_json:
|
||||||
st_found = True
|
st_found = True
|
||||||
# Verify next_hop in rib_routes_json
|
# Verify next_hop in rib_routes_json
|
||||||
if rib_routes_json[route][0]["nexthops"][0]["ip"] == \
|
if rib_routes_json[route][0]["nexthops"][0]["ip"] in \
|
||||||
_next_hop:
|
attribute_dict:
|
||||||
nh_found = True
|
nh_found = True
|
||||||
else:
|
else:
|
||||||
errormsg = "Incorrect Nexthop for BGP route {} in " \
|
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
|
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,
|
def verify_best_path_as_per_admin_distance(tgen, addr_type, router, input_dict,
|
||||||
attribute):
|
attribute):
|
||||||
"""
|
"""
|
||||||
@ -1568,7 +1567,7 @@ def verify_best_path_as_per_admin_distance(tgen, addr_type, router, input_dict,
|
|||||||
|
|
||||||
rnode = tgen.routers()[router]
|
rnode = tgen.routers()[router]
|
||||||
|
|
||||||
sleep(2)
|
sleep(5)
|
||||||
logger.info("Verifying router %s RIB for best path:", router)
|
logger.info("Verifying router %s RIB for best path:", router)
|
||||||
|
|
||||||
# Show ip route cmd
|
# Show ip route cmd
|
||||||
|
@ -1202,6 +1202,7 @@ def create_route_maps(tgen, input_dict, build=False):
|
|||||||
"large_comm_list", {})
|
"large_comm_list", {})
|
||||||
set_action = set_data.setdefault("set_action", None)
|
set_action = set_data.setdefault("set_action", None)
|
||||||
nexthop = set_data.setdefault("nexthop", None)
|
nexthop = set_data.setdefault("nexthop", None)
|
||||||
|
origin = set_data.setdefault("origin", None)
|
||||||
|
|
||||||
# Local Preference
|
# Local Preference
|
||||||
if local_preference:
|
if local_preference:
|
||||||
@ -1212,6 +1213,10 @@ def create_route_maps(tgen, input_dict, build=False):
|
|||||||
if metric:
|
if metric:
|
||||||
rmap_data.append("set metric {} \n".format(metric))
|
rmap_data.append("set metric {} \n".format(metric))
|
||||||
|
|
||||||
|
# Origin
|
||||||
|
if origin:
|
||||||
|
rmap_data.append("set origin {} \n".format(origin))
|
||||||
|
|
||||||
# AS Path Prepend
|
# AS Path Prepend
|
||||||
if as_path:
|
if as_path:
|
||||||
as_num = as_path.setdefault("as_num", None)
|
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"]
|
static_routes = input_dict[routerInput]["static_routes"]
|
||||||
st_found = False
|
st_found = False
|
||||||
nh_found = False
|
nh_found = False
|
||||||
found_routes = []
|
|
||||||
missing_routes = []
|
|
||||||
for static_route in static_routes:
|
for static_route in static_routes:
|
||||||
|
found_routes = []
|
||||||
|
missing_routes = []
|
||||||
|
|
||||||
network = static_route["network"]
|
network = static_route["network"]
|
||||||
if "no_of_ip" in static_route:
|
if "no_of_ip" in static_route:
|
||||||
no_of_ip = static_route["no_of_ip"]
|
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
|
return errormsg
|
||||||
else:
|
else:
|
||||||
missing_routes.append(st_rt)
|
missing_routes.append(st_rt)
|
||||||
|
|
||||||
if nh_found:
|
if nh_found:
|
||||||
logger.info("Found next_hop %s for all routes in RIB of"
|
logger.info("Found next_hop %s for all routes in RIB of"
|
||||||
" router %s\n", next_hop, dut)
|
" 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"
|
logger.info("Verified routes in router %s RIB, found routes"
|
||||||
" are: %s\n", dut, found_routes)
|
" are: %s\n", dut, found_routes)
|
||||||
|
|
||||||
advertise_network = input_dict[routerInput].setdefault(
|
continue
|
||||||
"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
|
|
||||||
|
|
||||||
# Generating IPs for verification
|
if "bgp" in input_dict[routerInput]:
|
||||||
ip_list = generate_ips(start_ip, no_of_network)
|
if 'advertise_networks' in input_dict[routerInput]["bgp"]\
|
||||||
for st_rt in ip_list:
|
["address_family"][addr_type]["unicast"]:
|
||||||
st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
|
|
||||||
|
|
||||||
if st_rt in rib_routes_json:
|
found_routes = []
|
||||||
found = True
|
missing_routes = []
|
||||||
found_routes.append(st_rt)
|
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:
|
else:
|
||||||
missing_routes.append(st_rt)
|
no_of_network = 1
|
||||||
|
|
||||||
if not found and len(missing_routes) > 0:
|
# Generating IPs for verification
|
||||||
errormsg = "Missing route in RIB of router {}, are: {}" \
|
ip_list = generate_ips(start_ip, no_of_network)
|
||||||
" \n".format(dut, missing_routes)
|
for st_rt in ip_list:
|
||||||
return errormsg
|
st_rt = str(ipaddr.IPNetwork(unicode(st_rt)))
|
||||||
|
|
||||||
logger.info("Verified routes in router %s RIB, found routes"
|
found = False
|
||||||
" are: %s", dut, found_routes)
|
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()")
|
logger.debug("Exiting lib API: verify_rib()")
|
||||||
return True
|
return True
|
||||||
|
Loading…
Reference in New Issue
Block a user