test: Refactor routing tests

Make more in parallel and restructure code
This commit is contained in:
Mattias Walström
2024-05-23 08:45:05 +02:00
parent 06742cf825
commit 6df2c90d85
4 changed files with 64 additions and 73 deletions
+4 -3
View File
@@ -2,7 +2,8 @@
import infamy
import infamy.route as route
from infamy.util import until
from infamy.util import until, parallel
def config_target1(target, data, link):
target.put_config_dict("ietf-interfaces", {
"interfaces": {
@@ -161,8 +162,8 @@ with infamy.Test() as test:
_, target2_to_target1 = env.ltop.xlate("target2", "target1")
_, target1_to_target2 = env.ltop.xlate("target1", "target2")
config_target1(target1, target1data, target1_to_target2)
config_target2(target2, target2_to_target1)
parallel(config_target1(target1, target1data, target1_to_target2),
config_target2(target2, target2_to_target1))
with test.step("Wait for OSPF routes"):
print("Waiting for OSPF routes..")
until(lambda: route.ipv4_route_exist(target1, "192.168.200.1/32", source_protocol = "infix-routing:ospf"), attempts=200)
+41 -41
View File
@@ -28,7 +28,7 @@
import infamy
import infamy.route as route
from infamy.util import until
from infamy.util import until, parallel
def config_target1(target, ring1, ring2, cross, link):
target.put_config_dict("ietf-interfaces", {
"interfaces": {
@@ -564,11 +564,10 @@ with infamy.Test() as test:
_, dut2cross = env.ltop.xlate("dut2", "cross")
_, dut3cross = env.ltop.xlate("dut3", "cross")
_, dut4cross = env.ltop.xlate("dut4", "cross")
config_target1(dut1, dut1ring1, dut1ring2, dut1cross, dut1data)
config_target2(dut2, dut2ring1, dut2ring2, dut2cross, dut2data)
config_target3(dut3, dut3ring1, dut3ring2, dut3cross, dut3data)
config_target4(dut4, dut4ring1, dut4ring2, dut4cross, dut4data)
parallel(config_target1(dut1, dut1ring1, dut1ring2, dut1cross, dut1data),
config_target2(dut2, dut2ring1, dut2ring2, dut2cross, dut2data),
config_target3(dut3, dut3ring1, dut3ring2, dut3cross, dut3data),
config_target4(dut4, dut4ring1, dut4ring2, dut4cross, dut4data))
with test.step("Wait for neighbors"):
print("Waiting for neighbors to peer")
until(lambda: route.ospf_get_neighbor(dut1, "0.0.0.0", dut1ring1, "10.0.0.2"), attempts=200)
@@ -577,58 +576,59 @@ with infamy.Test() as test:
until(lambda: route.ospf_get_neighbor(dut2, "0.0.0.0", dut2ring2, "10.0.0.1"), attempts=200)
until(lambda: route.ospf_get_neighbor(dut2, "0.0.0.2", dut2cross, "10.0.0.4"), attempts=200)
with test.step("Wait for routes"):
with test.step("Wait for routes from OSPF"):
print("Waiting for routes from OSPF")
until(lambda: route.ipv4_route_exist(dut1, "10.0.0.2/32", nexthop="10.0.12.2", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut1, "10.0.0.3/32", nexthop="10.0.13.2", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut1, "10.0.0.4/32", nexthop="10.0.41.1", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut1, "192.168.4.0/24", nexthop="10.0.41.1", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut1, "10.0.24.0/30", nexthop="10.0.41.1", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut2, "10.0.0.1/32", nexthop="10.0.23.2", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut2, "10.0.0.3/32", nexthop="10.0.23.2", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut2, "10.0.0.4/32", nexthop="10.0.24.2", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut3, "0.0.0.0/0", nexthop="10.0.23.1", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut4, "10.0.0.3/32", nexthop="10.0.41.2", source_protocol = "infix-routing:ospf"), attempts=200)
until(lambda: route.ipv4_route_exist(dut2, "10.0.13.0/30", nexthop="10.0.23.2", source_protocol = "infix-routing:ospf"), attempts=200)
with test.step("Verify NSSA area"): # Should be only default route out of the area.
until(lambda: route.ipv4_route_exist(dut4, "11.0.8.0/24"), attempts=200)
until(lambda: route.ipv4_route_exist(dut4, "11.0.9.0/24"), attempts=200)
until(lambda: route.ipv4_route_exist(dut4, "11.0.10.0/24"), attempts=200)
until(lambda: route.ipv4_route_exist(dut4, "11.0.11.0/24"), attempts=200)
until(lambda: route.ipv4_route_exist(dut4, "11.0.12.0/24"), attempts=200)
until(lambda: route.ipv4_route_exist(dut3, "0.0.0.0/0"), attempts=200)
until(lambda: route.ipv4_route_exist(dut3, "10.0.12.0/30") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "10.0.12.0/30") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "11.0.8.0/24") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "11.0.9.0/24") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "11.0.10.0/24") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "11.0.11.0/24") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "11.0.12.0/24") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "11.0.13.0/24") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "11.0.14.0/24") == False, attempts=5)
until(lambda: route.ipv4_route_exist(dut3, "11.0.15.0/24") == False, attempts=5)
assert(route.ospf_is_area_nssa(dut3, "0.0.0.1"))
parallel(until(lambda: route.ipv4_route_exist(dut4, "11.0.8.0/24"), attempts=200),
until(lambda: route.ipv4_route_exist(dut4, "11.0.9.0/24"), attempts=200),
until(lambda: route.ipv4_route_exist(dut4, "11.0.10.0/24"), attempts=200),
until(lambda: route.ipv4_route_exist(dut4, "11.0.11.0/24"), attempts=200),
until(lambda: route.ipv4_route_exist(dut4, "11.0.12.0/24"), attempts=200),
until(lambda: route.ipv4_route_exist(dut3, "0.0.0.0/0"), attempts=200),
until(lambda: route.ipv4_route_exist(dut3, "10.0.12.0/30") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "10.0.12.0/30") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "11.0.8.0/24") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "11.0.9.0/24") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "11.0.10.0/24") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "11.0.11.0/24") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "11.0.12.0/24") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "11.0.13.0/24") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "11.0.14.0/24") == False, attempts=5),
until(lambda: route.ipv4_route_exist(dut3, "11.0.15.0/24") == False, attempts=5))
assert(route.ospf_is_area_nssa(dut3, "0.0.0.1"))
_, hport0 = env.ltop.xlate("host", "data3")
with infamy.IsolatedMacVlan(hport0) as ns0:
_, hport0 = env.ltop.xlate("host", "data3")
with infamy.IsolatedMacVlan(hport0) as ns0:
with test.step("Testing connectivitiy through NSSA area"):
ns0.addip("192.168.3.2")
ns0.addroute("0.0.0.0/0", "192.168.3.1")
trace=ns0.traceroute("10.0.0.3")
ns0.must_reach("11.0.8.1")
with test.step("Verify correct hops"):
_, hport0 = env.ltop.xlate("host", "data4")
with infamy.IsolatedMacVlan(hport0) as ns0:
ns0.addip("192.168.4.2")
ns0.addroute("0.0.0.0/0", "192.168.4.1")
_, hport0 = env.ltop.xlate("host", "data4")
with infamy.IsolatedMacVlan(hport0) as ns0:
ns0.addip("192.168.4.2")
ns0.addroute("0.0.0.0/0", "192.168.4.1")
with test.step("Verify correct hops"):
trace=ns0.traceroute("10.0.0.3")
assert(len(trace) == 3)
assert(trace[1][1] == "10.0.41.2")
assert(trace[2][1] == "10.0.0.3")
with test.step("Disable link between R1 and R4, and verify correct hops"):
disable_link(dut1, dut1ring2) # Here we should test with link breakers, to test BFD recouppling, for now disable the link
until(lambda: route.ipv4_route_exist(dut4, "10.0.0.3/32", nexthop="10.0.24.1", source_protocol = "infix-routing:ospf"), attempts=100)
until(lambda: route.ipv4_route_exist(dut4, "10.0.0.3/32", nexthop="10.0.41.2") == False, attempts = 10)
_, hport0 = env.ltop.xlate("host", "data4")
with infamy.IsolatedMacVlan(hport0) as ns0:
ns0.addip("192.168.4.2")
ns0.addroute("0.0.0.0/0", "192.168.4.1")
with test.step("Disable link between R1 and R4, and verify correct hops"):
disable_link(dut1, dut1ring2) # Here we should test with link breakers, to test BFD recouppling, for now disable the link
until(lambda: route.ipv4_route_exist(dut4, "10.0.0.3/32", nexthop="10.0.24.1", source_protocol = "infix-routing:ospf"), attempts=100)
until(lambda: route.ipv4_route_exist(dut4, "10.0.0.3/32", nexthop="10.0.41.2") == False, attempts = 10)
trace=ns0.traceroute("10.0.0.3")
assert(len(trace) == 3)
assert(trace[1][1] == "10.0.24.1")
@@ -3,7 +3,7 @@ import infamy
import time
import infamy.route as route
from infamy.util import until
from infamy.util import until, parallel
# This test tests passive interfaces and unnumbered interfaces.
@@ -166,8 +166,8 @@ with infamy.Test() as test:
_, target2_to_target1 = env.ltop.xlate("target2", "target1")
_, target1_to_target2 = env.ltop.xlate("target1", "target2")
config_target1(target1, target1data, target1_to_target2)
config_target2(target2, target2_to_target1)
parallel(lambda: config_target1(target1, target1data, target1_to_target2),
lambda: config_target2(target2, target2_to_target1))
with test.step("Wait for OSPF routes"):
print("Waiting for OSPF routes..")
until(lambda: route.ipv4_route_exist(target1, "192.168.200.1/32", source_protocol = "infix-routing:ospf"), attempts=200)
@@ -178,22 +178,17 @@ with infamy.Test() as test:
assert(route.ospf_get_interface_type(target1, "0.0.0.0", target1_to_target2) == "point-to-point")
assert(route.ospf_get_interface_type(target2, "0.0.0.0", target2_to_target1) == "point-to-point")
with test.step("Test passive interface"):
print("Verify that no hello packets are recieved from passive interfaces")
assert(route.ospf_get_interface_passive(target1, "0.0.0.0", target1data))
_, hport0 = env.ltop.xlate("host", "data1")
with infamy.IsolatedMacVlan(hport0) as ns0:
ns0.addip("192.168.10.2")
snif = infamy.Sniffer(ns0, "ip proto 89")
with snif:
time.sleep(15) # default hello time 10s
assert(snif.packets() == "")
with infamy.IsolatedMacVlan(hport0) as ns0:
ns0.addip("192.168.10.2")
ns0.addroute("192.168.200.1/32", "192.168.10.1")
with test.step("Test connectivity"):
_, hport0 = env.ltop.xlate("host", "data1")
with infamy.IsolatedMacVlan(hport0) as ns0:
ns0.addip("192.168.10.2")
ns0.addroute("192.168.200.1/32", "192.168.10.1")
with test.step("Test passive interface"):
assert(route.ospf_get_interface_passive(target1, "0.0.0.0", target1data))
print("Verify that no hello packets are recieved from passive interfaces")
ns0.must_not_receive("ip proto 89", timeout=15) # Default hello time 10s
with test.step("Test connectivity"):
ns0.must_reach("192.168.200.1")
test.succeed()
+7 -12
View File
@@ -21,7 +21,7 @@ import infamy
import time
import infamy.iface as iface
import infamy.route as route
from infamy.util import until
from infamy.util import until, parallel
def config_target1(target, data, link):
target.put_config_dict("ietf-interfaces", {
@@ -200,14 +200,9 @@ with infamy.Test() as test:
_, target2_to_target1 = env.ltop.xlate("target2", "target1")
_, target1_to_target2 = env.ltop.xlate("target1", "target2")
config_target1(target1, target1data, target1_to_target2)
config_target2(target2, target2_to_target1)
parallel(config_target1(target1, target1data, target1_to_target2),
config_target2(target2, target2_to_target1))
with test.step("Wait for links"):
until(lambda: iface.get_oper_up(target1, target1data))
until(lambda: iface.get_oper_up(target1, target1data))
until(lambda: iface.get_oper_up(target1, target1_to_target2))
until(lambda: iface.get_oper_up(target2, target2_to_target1))
with test.step("Wait for routes"):
until(lambda: route.ipv4_route_exist(target1, "192.168.200.1/32"))
until(lambda: route.ipv4_route_exist(target2, "0.0.0.0/0"))
@@ -230,11 +225,11 @@ with infamy.Test() as test:
with test.step("Remove static routes on dut1"):
config_remove_routes(target1);
until(lambda: route.ipv4_route_exist(target1, "192.168.200.1/32") == False)
until(lambda: route.ipv6_route_exist(target1, "2001:db8:3c4d:200::1/128") == False)
parallel(until(lambda: route.ipv4_route_exist(target1, "192.168.200.1/32") == False),
until(lambda: route.ipv6_route_exist(target1, "2001:db8:3c4d:200::1/128") == False))
with test.step("Verify that dut2 is no longer reachable"):
infamy.parallel(lambda: ns0.must_not_reach("192.168.200.1"),
lambda: ns0.must_not_reach("2001:db8:3c4d:200::1"))
infamy.parallel(ns0.must_not_reach("192.168.200.1"),
ns0.must_not_reach("2001:db8:3c4d:200::1"))
test.succeed()