summaryrefslogtreecommitdiffstats
path: root/tests/topotests/lib/bgp.py
diff options
context:
space:
mode:
authorMartin Winter <mwinter@opensourcerouting.org>2020-12-22 23:11:37 +0100
committerGitHub <noreply@github.com>2020-12-22 23:11:37 +0100
commit90cd28e91ad58a617123390b9d507e4fda96fe80 (patch)
tree0632eec9cc57eb6223dbdcd685e256694fc83df0 /tests/topotests/lib/bgp.py
parentMerge pull request #7767 from mjstapp/fix_dplane_extra_info (diff)
parenttests: Optimised static routing testsuits (diff)
downloadfrr-90cd28e91ad58a617123390b9d507e4fda96fe80.tar.xz
frr-90cd28e91ad58a617123390b9d507e4fda96fe80.zip
Merge pull request #6212 from gpnaveen/static_routes
tests: Adding static routing topojson automation suites.
Diffstat (limited to 'tests/topotests/lib/bgp.py')
-rw-r--r--tests/topotests/lib/bgp.py101
1 files changed, 63 insertions, 38 deletions
diff --git a/tests/topotests/lib/bgp.py b/tests/topotests/lib/bgp.py
index 0462cfbff..68a7217dd 100644
--- a/tests/topotests/lib/bgp.py
+++ b/tests/topotests/lib/bgp.py
@@ -21,6 +21,7 @@
from copy import deepcopy
from time import sleep
import traceback
+import ipaddr
import ipaddress
import os
import sys
@@ -1615,8 +1616,6 @@ def clear_bgp(tgen, addr_type, router, vrf=None):
else:
run_frr_cmd(rnode, "clear bgp *")
- sleep(5)
-
logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
@@ -2115,8 +2114,8 @@ def verify_bgp_attributes(
errormsg(str) or True
"""
- logger.debug("Entering lib API: verify_bgp_attributes()")
- for router, rnode in tgen.routers().items():
+ logger.debug("Entering lib API: {}".format(sys._getframe().f_code.co_name))
+ for router, rnode in tgen.routers().iteritems():
if router != dut:
continue
@@ -2196,7 +2195,7 @@ def verify_bgp_attributes(
)
return errormsg
- logger.debug("Exiting lib API: verify_bgp_attributes()")
+ logger.debug("Exiting lib API: {}".format(sys._getframe().f_code.co_name))
return True
@@ -2516,8 +2515,9 @@ def verify_best_path_as_per_admin_distance(
return True
-@retry(attempts=6, wait=2, return_is_str=True)
-def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None, aspath=None):
+@retry(attempts=5, wait=2, return_is_str=True, initial_wait=2)
+def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None,
+aspath=None, multi_nh=None):
"""
This API is to verify whether bgp rib has any
matching route for a nexthop.
@@ -2552,6 +2552,7 @@ def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None, aspath=None)
additional_nexthops_in_required_nhs = []
list1 = []
list2 = []
+ found_hops = []
for routerInput in input_dict.keys():
for router, rnode in router_list.items():
if router != dut:
@@ -2618,44 +2619,73 @@ def verify_bgp_rib(tgen, addr_type, dut, input_dict, next_hop=None, aspath=None)
st_found = True
found_routes.append(st_rt)
- if next_hop:
+ if next_hop and multi_nh and st_found:
if not isinstance(next_hop, list):
next_hop = [next_hop]
list1 = next_hop
- found_hops = [
- rib_r["ip"]
- for rib_r in rib_routes_json["routes"][st_rt][0][
- "nexthops"
- ]
- ]
- list2 = found_hops
-
- missing_list_of_nexthops = set(list2).difference(list1)
- additional_nexthops_in_required_nhs = set(
- list1
- ).difference(list2)
+ for mnh in range(
+ 0, len(rib_routes_json["routes"][st_rt])
+ ):
+ found_hops.append(
+ [
+ rib_r["ip"]
+ for rib_r in rib_routes_json["routes"][
+ st_rt
+ ][mnh]["nexthops"]
+ ]
+ )
+ for mnh in found_hops:
+ for each_nh_in_multipath in mnh:
+ list2.append(each_nh_in_multipath)
+ if found_hops[0]:
+ missing_list_of_nexthops = set(list2).difference(
+ list1
+ )
+ additional_nexthops_in_required_nhs = set(
+ list1
+ ).difference(list2)
- if list2:
- if additional_nexthops_in_required_nhs:
- logger.info(
- "Missing nexthop %s for route"
- " %s in RIB of router %s\n",
- additional_nexthops_in_required_nhs,
- st_rt,
- dut,
- )
- errormsg = (
- "Nexthop {} is Missing for "
- "route {} in RIB of router {}\n".format(
+ if list2:
+ if additional_nexthops_in_required_nhs:
+ logger.info(
+ "Missing nexthop %s for route"
+ " %s in RIB of router %s\n",
additional_nexthops_in_required_nhs,
st_rt,
dut,
)
- )
return errormsg
else:
nh_found = True
+
+ elif next_hop and multi_nh is None:
+ if not isinstance(next_hop, list):
+ next_hop = [next_hop]
+ list1 = next_hop
+ found_hops = [rib_r["ip"] for rib_r in
+ rib_routes_json["routes"][
+ st_rt][0]["nexthops"]]
+ list2 = found_hops
+ missing_list_of_nexthops = \
+ set(list2).difference(list1)
+ additional_nexthops_in_required_nhs = \
+ set(list1).difference(list2)
+
+ if list2:
+ if additional_nexthops_in_required_nhs:
+ logger.info("Missing nexthop %s for route"\
+ " %s in RIB of router %s\n", \
+ additional_nexthops_in_required_nhs, \
+ st_rt, dut)
+ errormsg=("Nexthop {} is Missing for "\
+ "route {} in RIB of router {}\n".format(
+ additional_nexthops_in_required_nhs,
+ st_rt, dut))
+ return errormsg
+ else:
+ nh_found = True
+
if aspath:
found_paths = rib_routes_json["routes"][st_rt][0][
"path"
@@ -3678,7 +3708,6 @@ def verify_attributes_for_evpn_routes(
"""
API to verify rd and rt value using "sh bgp l2vpn evpn 10.1.1.1"
command.
-
Parameters
----------
* `tgen`: topogen object
@@ -3692,7 +3721,6 @@ def verify_attributes_for_evpn_routes(
* `ipLen` : IP prefix length
* `rd_peer` : Peer name from which RD will be auto-generated
* `rt_peer` : Peer name from which RT will be auto-generated
-
Usage
-----
input_dict_1 = {
@@ -4069,7 +4097,6 @@ def verify_evpn_routes(
"""
API to verify evpn routes using "sh bgp l2vpn evpn"
command.
-
Parameters
----------
* `tgen`: topogen object
@@ -4080,7 +4107,6 @@ def verify_evpn_routes(
* `route_type` : Route type 5 is supported as of now
* `EthTag` : Ethernet tag, by-default is 0
* `next_hop` : Prefered nexthop for the evpn routes
-
Usage
-----
input_dict_1 = {
@@ -4093,7 +4119,6 @@ def verify_evpn_routes(
}
}
result = verify_evpn_routes(tgen, topo, input_dict)
-
Returns
-------
errormsg(str) or True