From d4f6bcf127bb272d0474760c0b1e79159b00083e Mon Sep 17 00:00:00 2001 From: Rafael Zalamena Date: Wed, 21 Jun 2017 18:08:00 -0300 Subject: [PATCH] ospf: added a convergence test for link failure This new test simulates a link failure in router 3 and expects the OSPF routing table to converge accordingly in all nodes. --- .../ospf-topo1/r1/ospfroute_down.txt | 13 ++++++ .../ospf-topo1/r2/ospfroute_down.txt | 13 ++++++ .../ospf-topo1/r3/ospfroute_down.txt | 13 ++++++ .../ospf-topo1/r4/ospfroute_down.txt | 13 ++++++ tests/topotests/ospf-topo1/test_ospf_topo1.py | 46 +++++++++++++------ 5 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 tests/topotests/ospf-topo1/r1/ospfroute_down.txt create mode 100644 tests/topotests/ospf-topo1/r2/ospfroute_down.txt create mode 100644 tests/topotests/ospf-topo1/r3/ospfroute_down.txt create mode 100644 tests/topotests/ospf-topo1/r4/ospfroute_down.txt diff --git a/tests/topotests/ospf-topo1/r1/ospfroute_down.txt b/tests/topotests/ospf-topo1/r1/ospfroute_down.txt new file mode 100644 index 0000000000..5c07d81334 --- /dev/null +++ b/tests/topotests/ospf-topo1/r1/ospfroute_down.txt @@ -0,0 +1,13 @@ +============ OSPF network routing table ============ +N 10.0.1.0/24 [10] area: 0.0.0.0 + directly attached to r1-eth0 +N 10.0.2.0/24 [20] area: 0.0.0.0 + via 10.0.3.3, r1-eth1 +N 10.0.3.0/24 [10] area: 0.0.0.0 + directly attached to r1-eth1 + +============ OSPF router routing table ============= +R 10.0.255.2 [10] area: 0.0.0.0, ASBR + via 10.0.3.3, r1-eth1 + +============ OSPF external routing table =========== diff --git a/tests/topotests/ospf-topo1/r2/ospfroute_down.txt b/tests/topotests/ospf-topo1/r2/ospfroute_down.txt new file mode 100644 index 0000000000..b8411e19f3 --- /dev/null +++ b/tests/topotests/ospf-topo1/r2/ospfroute_down.txt @@ -0,0 +1,13 @@ +============ OSPF network routing table ============ +N 10.0.1.0/24 [20] area: 0.0.0.0 + via 10.0.3.2, r2-eth1 +N 10.0.2.0/24 [10] area: 0.0.0.0 + directly attached to r2-eth0 +N 10.0.3.0/24 [10] area: 0.0.0.0 + directly attached to r2-eth1 + +============ OSPF router routing table ============= +R 10.0.255.1 [10] area: 0.0.0.0, ASBR + via 10.0.3.2, r2-eth1 + +============ OSPF external routing table =========== diff --git a/tests/topotests/ospf-topo1/r3/ospfroute_down.txt b/tests/topotests/ospf-topo1/r3/ospfroute_down.txt new file mode 100644 index 0000000000..692a74aa6c --- /dev/null +++ b/tests/topotests/ospf-topo1/r3/ospfroute_down.txt @@ -0,0 +1,13 @@ +============ OSPF network routing table ============ +N 10.0.10.0/24 [10] area: 0.0.0.0 + directly attached to r3-eth1 +N 172.16.0.0/24 [10] area: 0.0.0.1 + directly attached to r3-eth2 +N 172.16.1.0/24 [20] area: 0.0.0.1 + via 172.16.0.1, r3-eth2 + +============ OSPF router routing table ============= +R 10.0.255.4 [10] area: 0.0.0.1, ASBR + via 172.16.0.1, r3-eth2 + +============ OSPF external routing table =========== diff --git a/tests/topotests/ospf-topo1/r4/ospfroute_down.txt b/tests/topotests/ospf-topo1/r4/ospfroute_down.txt new file mode 100644 index 0000000000..b0bd0eec78 --- /dev/null +++ b/tests/topotests/ospf-topo1/r4/ospfroute_down.txt @@ -0,0 +1,13 @@ +============ OSPF network routing table ============ +N IA 10.0.10.0/24 [20] area: 0.0.0.1 + via 172.16.0.2, r4-eth0 +N 172.16.0.0/24 [10] area: 0.0.0.1 + directly attached to r4-eth0 +N 172.16.1.0/24 [10] area: 0.0.0.1 + directly attached to r4-eth1 + +============ OSPF router routing table ============= +R 10.0.255.3 [10] area: 0.0.0.1, ABR, ASBR + via 172.16.0.2, r4-eth0 + +============ OSPF external routing table =========== diff --git a/tests/topotests/ospf-topo1/test_ospf_topo1.py b/tests/topotests/ospf-topo1/test_ospf_topo1.py index 4cb569da8e..352e6dde66 100755 --- a/tests/topotests/ospf-topo1/test_ospf_topo1.py +++ b/tests/topotests/ospf-topo1/test_ospf_topo1.py @@ -105,27 +105,47 @@ def teardown_module(mod): tgen = get_topogen() tgen.stop_topology() +# Shared test function to validate expected output. +def compare_show_ip_ospf(rname, expected): + """ + Calls 'show ip ospf route' for router `rname` and compare the obtained + result with the expected output. + """ + tgen = get_topogen() + current = tgen.gears[rname].vtysh_cmd('show ip ospf route') + return topotest.difflines(current, expected, + title1="Current output", + title2="Expected output") + def test_ospf_convergence(): "Test OSPF daemon convergence" + for rnum in range(1, 5): + router = 'r{}'.format(rnum) + + # Load expected results from the command + reffile = os.path.join(CWD, '{}/ospfroute.txt'.format(router)) + expected = open(reffile).read() + + # Run test function until we get an result. Wait at most 60 seconds. + test_func = partial(compare_show_ip_ospf, router, expected) + result, diff = topotest.run_and_expect(test_func, '', + count=20, wait=3) + assert result, 'OSPF did not converge on {}:\n{}'.format(router, diff) + +def test_ospf_link_down(): + "Test OSPF convergence after a link goes down" tgen = get_topogen() - # Define test function - def compare_show_ip_ospf(rname, expected): - """ - Calls 'show ip ospf route' for router `rname` and compare the obtained - result with the expected output. - """ - current = tgen.gears[rname].vtysh_cmd('show ip ospf route') - return topotest.difflines(current, expected, - title1="Current output", - title2="Expected output") - - # Run the file comparison for all routers + # Simulate a network down event on router3 switch3 interface. + router3 = tgen.gears['r3'] + router3.peer_link_enable('r3-eth0', False) + + # Expect convergence on all routers for rnum in range(1, 5): router = 'r{}'.format(rnum) # Load expected results from the command - reffile = os.path.join(CWD, '{}/ospfroute.txt'.format(router)) + reffile = os.path.join(CWD, '{}/ospfroute_down.txt'.format(router)) expected = open(reffile).read() # Run test function until we get an result. Wait at most 60 seconds. -- 2.39.5