]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_tilfa_topo1/test_ospf_tilfa_topo1.py
2 # SPDX-License-Identifier: ISC
5 # test_ospf_tilfa_topo1.py
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2020 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
13 test_ospf_tilfa_topo1.py:
15 This topology is intentionally kept simple, its main purpose is to verify that
16 generated backup label stacks are inserted correctly into the RIB. For fancy
17 topologies please use the unit test framework provided in `/tests/ospfd`.
20 +---------+ +---------+
22 10.0.1.0/24 eth+rt1| RT2 |eth+rt4 eth+rt2| RT2 |
23 +---------------------+ 2.2.2.2 +---------------------+ 4.4.4.4 |
25 |eth+rt2 +---------+ +---------+
32 |eth+rt3 +---------+ +---------+
34 +---------------------+ RT3 +---------------------+ RT5 |
35 10.0.2.0/24 eth+rt1| 3.3.3.3 |eth+rt5 eth-rt3| 5.5.5.5 |
37 +---------+ +---------+
44 from functools
import partial
46 # Save the Current Working Directory to find configuration files.
47 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
48 sys
.path
.append(os
.path
.join(CWD
, "../"))
50 # pylint: disable=C0413
51 # Import topogen and topotest helpers
52 from lib
import topotest
53 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
54 from lib
.topolog
import logger
56 # Required to instantiate the topology builder class.
58 pytestmark
= [pytest
.mark
.ospfd
]
67 for router
in ["rt1", "rt2", "rt3", "rt4", "rt5"]:
68 tgen
.add_router(router
)
73 switch
= tgen
.add_switch("s1")
74 switch
.add_link(tgen
.gears
["rt1"], nodeif
="eth-rt2")
75 switch
.add_link(tgen
.gears
["rt2"], nodeif
="eth-rt1")
77 switch
= tgen
.add_switch("s2")
78 switch
.add_link(tgen
.gears
["rt1"], nodeif
="eth-rt3")
79 switch
.add_link(tgen
.gears
["rt3"], nodeif
="eth-rt1")
81 switch
= tgen
.add_switch("s3")
82 switch
.add_link(tgen
.gears
["rt2"], nodeif
="eth-rt4")
83 switch
.add_link(tgen
.gears
["rt4"], nodeif
="eth-rt2")
85 switch
= tgen
.add_switch("s4")
86 switch
.add_link(tgen
.gears
["rt3"], nodeif
="eth-rt5")
87 switch
.add_link(tgen
.gears
["rt5"], nodeif
="eth-rt3")
89 switch
= tgen
.add_switch("s5")
90 switch
.add_link(tgen
.gears
["rt4"], nodeif
="eth-rt5")
91 switch
.add_link(tgen
.gears
["rt5"], nodeif
="eth-rt4")
94 def setup_module(mod
):
95 "Sets up the pytest environment"
96 tgen
= Topogen(build_topo
, mod
.__name
__)
99 router_list
= tgen
.routers()
101 # For all registered routers, load the zebra configuration file
102 for rname
, router
in router_list
.items():
104 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
107 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "{}/ospfd.conf".format(rname
))
113 def teardown_module(mod
):
114 "Teardown the pytest environment"
117 # This function tears down the whole topology.
121 def router_compare_json_output(rname
, command
, reference
):
122 "Compare router JSON output"
124 logger
.info('Comparing router "%s" "%s" output', rname
, command
)
127 filename
= "{}/{}/{}".format(CWD
, rname
, reference
)
128 expected
= json
.loads(open(filename
).read())
130 # Run test function until we get an result. Wait at most 60 seconds.
131 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
132 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=120, wait
=0.5)
133 assertmsg
= '"{}" JSON output mismatches the expected result'.format(rname
)
134 assert diff
is None, assertmsg
137 def test_ospf_initial_convergence_step1():
138 logger
.info("Test (step 1): check initial convergence")
141 # Skip if previous fatal error condition is raised
142 if tgen
.routers_have_failure():
143 pytest
.skip(tgen
.errors
)
145 router_compare_json_output(
147 "show ip route json",
148 "step1/show_ip_route_initial.ref",
152 def test_ospf_link_protection_step2():
153 logger
.info("Test (step 2): check OSPF link protection")
156 # Skip if previous fatal error condition is raised
157 if tgen
.routers_have_failure():
158 pytest
.skip(tgen
.errors
)
160 # enable TI-LFA link protection on all interfaces
161 tgen
.net
["rt1"].cmd('vtysh -c "conf t" -c "router ospf" -c "fast-reroute ti-lfa"')
163 router_compare_json_output(
165 "show ip route json",
166 "step2/show_ip_route_link_protection.ref",
169 # disable TI-LFA link protection on all interfaces
171 'vtysh -c "conf t" -c "router ospf" -c "no fast-reroute ti-lfa"'
174 # check if we got back to the initial route table
175 router_compare_json_output(
177 "show ip route json",
178 "step2/show_ip_route_initial.ref",
182 def test_ospf_node_protection_step3():
183 logger
.info("Test (step 3): check OSPF node protection")
186 # Skip if previous fatal error condition is raised
187 if tgen
.routers_have_failure():
188 pytest
.skip(tgen
.errors
)
190 # enable TI-LFA node protection on all interfaces
192 'vtysh -c "conf t" -c "router ospf" -c "fast-reroute ti-lfa node-protection"'
195 router_compare_json_output(
197 "show ip route json",
198 "step3/show_ip_route_node_protection.ref",
201 # disable TI-LFA node protection on all interfaces
203 'vtysh -c "conf t" -c "router ospf" -c "no fast-reroute ti-lfa node-protection"'
206 # check if we got back to the initial route table
207 router_compare_json_output(
209 "show ip route json",
210 "step3/show_ip_route_initial.ref",
214 # Memory leak test template
215 def test_memory_leak():
216 "Run the memory leak test and report results."
218 if not tgen
.is_memleak_enabled():
219 pytest
.skip("Memory leak test/report is disabled")
221 tgen
.report_memory_leaks()
224 if __name__
== "__main__":
225 args
= ["-s"] + sys
.argv
[1:]
226 sys
.exit(pytest
.main(args
))