diff --git a/test/case/ietf_routing/ospf_basic/test.py b/test/case/ietf_routing/ospf_basic/test.py index 4fedecd4..432a2787 100755 --- a/test/case/ietf_routing/ospf_basic/test.py +++ b/test/case/ietf_routing/ospf_basic/test.py @@ -171,8 +171,8 @@ with infamy.Test() as test: config_target2(R2, R2link)) with test.step("Wait for OSPF routes"): print("Waiting for OSPF routes..") - until(lambda: route.ipv4_route_exist(R1, "192.168.200.1/32", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R2, "192.168.100.1/32", source_protocol="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R1, "192.168.200.1/32", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R2, "192.168.100.1/32", proto="ietf-ospf:ospfv2"), attempts=200) with test.step("Test connectivity from PC:data to 192.168.200.1"): _, hport0 = env.ltop.xlate("PC", "data") diff --git a/test/case/ietf_routing/ospf_multiarea/test.py b/test/case/ietf_routing/ospf_multiarea/test.py index 2439b7f2..df43da8c 100755 --- a/test/case/ietf_routing/ospf_multiarea/test.py +++ b/test/case/ietf_routing/ospf_multiarea/test.py @@ -550,17 +550,17 @@ with infamy.Test() as test: with test.step("Wait for routes from OSPF on all routers"): print("Waiting for routes from OSPF") - until(lambda: route.ipv4_route_exist(R1, "10.0.0.2/32", nexthop="10.0.12.2", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R1, "10.0.0.3/32", nexthop="10.0.13.2", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R1, "10.0.0.4/32", nexthop="10.0.41.1", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R1, "192.168.4.0/24", nexthop="10.0.41.1", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R1, "10.0.24.0/30", nexthop="10.0.41.1", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R2, "10.0.0.1/32", nexthop="10.0.23.2", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R2, "10.0.0.3/32", nexthop="10.0.23.2", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R2, "10.0.0.4/32", nexthop="10.0.24.2", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R3, "0.0.0.0/0", nexthop="10.0.23.1", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R4, "10.0.0.3/32", nexthop="10.0.41.2", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R2, "10.0.13.0/30", nexthop="10.0.23.2", source_protocol="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R1, "10.0.0.2/32", nexthop="10.0.12.2", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R1, "10.0.0.3/32", nexthop="10.0.13.2", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R1, "10.0.0.4/32", nexthop="10.0.41.1", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R1, "192.168.4.0/24", nexthop="10.0.41.1", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R1, "10.0.24.0/30", nexthop="10.0.41.1", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R2, "10.0.0.1/32", nexthop="10.0.23.2", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R2, "10.0.0.3/32", nexthop="10.0.23.2", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R2, "10.0.0.4/32", nexthop="10.0.24.2", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R3, "0.0.0.0/0", nexthop="10.0.23.1", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R4, "10.0.0.3/32", nexthop="10.0.41.2", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R2, "10.0.13.0/30", nexthop="10.0.23.2", proto="ietf-ospf:ospfv2"), attempts=200) with test.step("Verify Area 0.0.0.1 on R3 is NSSA area"): assert(route.ospf_is_area_nssa(R3, "0.0.0.1")) @@ -602,7 +602,7 @@ with infamy.Test() as test: disable_link(R1, R1ring2) with test.step("Verify that the route to 10.0.0.3 from PC:data4, go through 10.0.24.1"): - until(lambda: route.ipv4_route_exist(R4, "10.0.0.3/32", nexthop="10.0.24.1", source_protocol="ietf-ospf:ospfv2"), attempts=100) + until(lambda: route.ipv4_route_exist(R4, "10.0.0.3/32", nexthop="10.0.24.1", proto="ietf-ospf:ospfv2"), attempts=100) until(lambda: route.ipv4_route_exist(R4, "10.0.0.3/32", nexthop="10.0.41.2") is False, attempts=10) trace = ns0.traceroute("10.0.0.3") assert len(trace) == 3 diff --git a/test/case/ietf_routing/ospf_unnumbered_interface/test.py b/test/case/ietf_routing/ospf_unnumbered_interface/test.py index 1512cb55..01290d7d 100755 --- a/test/case/ietf_routing/ospf_unnumbered_interface/test.py +++ b/test/case/ietf_routing/ospf_unnumbered_interface/test.py @@ -166,9 +166,9 @@ with infamy.Test() as test: lambda: config_target2(R2, R2link)) with test.step("Wait for OSPF routes"): print("Waiting for OSPF routes..") - until(lambda: route.ipv4_route_exist(R1, "192.168.200.1/32", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R2, "192.168.100.1/32", source_protocol="ietf-ospf:ospfv2"), attempts=200) - until(lambda: route.ipv4_route_exist(R2, "192.168.10.0/24", source_protocol="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R1, "192.168.200.1/32", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R2, "192.168.100.1/32", proto="ietf-ospf:ospfv2"), attempts=200) + until(lambda: route.ipv4_route_exist(R2, "192.168.10.0/24", proto="ietf-ospf:ospfv2"), attempts=200) with test.step("Check interface type"): assert(route.ospf_get_interface_type(R1, "0.0.0.0", R1link) == "point-to-point") diff --git a/test/infamy/route.py b/test/infamy/route.py index 180782f8..84bb96db 100644 --- a/test/infamy/route.py +++ b/test/infamy/route.py @@ -13,19 +13,22 @@ def _get_routes(target, protocol): return {} -def _exist_route(target, prefix, nexthop, ip, source_protocol): +def _exist_route(target, dest, nexthop=None, ip=None, proto=None, pref=None): routes = _get_routes(target, ip) for r in routes: # netconf presents destination-prefix, restconf prefix with model - p = r.get("destination-prefix") or \ + dst = r.get("destination-prefix") or \ r.get(f"ietf-{ip}-unicast-routing:destination-prefix") - if p != prefix: + if dst != dest: continue - if source_protocol and r.get("source-protocol") != source_protocol: + if proto is not None and r.get("source-protocol") != proto: return False - if nexthop: + if pref is not None and r.get("route-preference") != pref: + return False + + if nexthop is not None: nh = r["next-hop"] if not nh: return False @@ -53,12 +56,12 @@ def _exist_route(target, prefix, nexthop, ip, source_protocol): return False -def ipv4_route_exist(target, prefix, nexthop=None, source_protocol=None): - return _exist_route(target, prefix, nexthop, "ipv4", source_protocol) +def ipv4_route_exist(target, dest, nexthop=None, proto=None, pref=None): + return _exist_route(target, dest, nexthop=nexthop, ip="ipv4", proto=proto, pref=pref) -def ipv6_route_exist(target, prefix, nexthop=None, source_protocol=None): - return _exist_route(target, prefix, nexthop, "ipv6", source_protocol) +def ipv6_route_exist(target, dest, nexthop=None, proto=None, pref=None): + return _exist_route(target, dest, nexthop=nexthop, ip="ipv6", proto=proto, pref=pref) def _get_ospf_status(target):