]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ospf_te_topo1/test_ospf_te_topo1.py
2 # SPDX-License-Identifier: ISC
5 # test_ospf_te_topo1.py
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2021 by Orange
9 # Author: Olivier Dugeon <olivier.dugeon@orange.com>
13 test_ospf_te_topo1.py: Test the FRR OSPF with Traffic Engineering.
23 10.0.0.0/24| |10.0.1.0/24
26 +------------+ +------------+
28 | R2 |r2-eth2 r3-eth0| R3 |
29 | 10.0.255.2 +------------------+ 10.0.255.3 |
31 +------------+ +------+-----+
34 10.0.4.0/24| 10.0.5.0/24|
37 +------------+ ASBR 10.0.255.5
49 from functools
import partial
51 # Save the Current Working Directory to find configuration files.
52 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
53 sys
.path
.append(os
.path
.join(CWD
, "../"))
55 # pylint: disable=C0413
56 # Required to instantiate the topology builder class.
58 # Import topogen and topotest helpers
59 from lib
import topotest
60 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
61 from lib
.topolog
import logger
66 pytestmark
= [pytest
.mark
.ospfd
]
73 for routern
in range(1, 5):
74 tgen
.add_router("r{}".format(routern
))
76 # Interconect router 1 and 2 with 2 links
77 switch
= tgen
.add_switch("s1")
78 switch
.add_link(tgen
.gears
["r1"])
79 switch
.add_link(tgen
.gears
["r2"])
80 switch
= tgen
.add_switch("s2")
81 switch
.add_link(tgen
.gears
["r1"])
82 switch
.add_link(tgen
.gears
["r2"])
84 # Interconect router 3 and 2
85 switch
= tgen
.add_switch("s3")
86 switch
.add_link(tgen
.gears
["r3"])
87 switch
.add_link(tgen
.gears
["r2"])
89 # Interconect router 4 and 2
90 switch
= tgen
.add_switch("s4")
91 switch
.add_link(tgen
.gears
["r4"])
92 switch
.add_link(tgen
.gears
["r2"])
94 # Interconnect router 3 with next AS
95 switch
= tgen
.add_switch("s5")
96 switch
.add_link(tgen
.gears
["r3"])
99 def setup_module(mod
):
100 "Sets up the pytest environment"
102 logger
.info("\n\n---- Starting OSPF TE tests ----\n")
104 tgen
= Topogen(build_topo
, mod
.__name
__)
105 tgen
.start_topology()
107 router_list
= tgen
.routers()
109 for rname
, router
in router_list
.items():
111 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
114 TopoRouter
.RD_OSPF
, os
.path
.join(CWD
, "{}/ospfd.conf".format(rname
))
117 # Initialize all routers.
121 def teardown_module():
122 "Teardown the pytest environment"
127 logger
.info("\n\n---- OSPF TE tests End ----\n")
130 def compare_ted_json_output(tgen
, rname
, fileref
):
131 "Compare TED JSON output"
133 logger
.info('Comparing router "%s" TED output', rname
)
135 filename
= "{}/reference/{}".format(CWD
, fileref
)
136 expected
= json
.loads(open(filename
).read())
137 command
= "show ip ospf mpls-te database json"
139 # Run test function until we get an result. Wait at most 60 seconds.
140 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
141 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=2)
142 assertmsg
= '"{}" TED JSON output mismatches the expected result'.format(rname
)
143 assert diff
is None, assertmsg
146 def setup_testcase(msg
):
152 # Skip if previous fatal error condition is raised
153 if tgen
.routers_have_failure():
154 pytest
.skip(tgen
.errors
)
159 # Note that all routers must discover the same Network Topology, so the same TED.
163 "Step1: Check initial topology"
165 tgen
= setup_testcase("Step1: test initial OSPF TE Data Base")
167 for rname
in ["r1", "r2", "r3", "r4"]:
168 compare_ted_json_output(tgen
, rname
, "ted_step1.json")
172 "Step2: Shutdown interface between r1 and r2 and verify that \
173 corresponding Edges are removed from the TED on all routers "
175 tgen
= setup_testcase("Step2: Shutdown interface between r1 & r2")
177 tgen
.net
["r1"].cmd('vtysh -c "conf t" -c "interface r1-eth1" -c "shutdown"')
178 tgen
.net
["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth1" -c "shutdown"')
180 for rname
in ["r1", "r2", "r3", "r4"]:
181 compare_ted_json_output(tgen
, rname
, "ted_step2.json")
185 "Step3: Disable Inter-AS on r3 and verify that corresponding Edge and \
186 remote ASBR are removed from the TED on all routers"
188 tgen
= setup_testcase("Step3: Disable Inter-AS on r3")
190 tgen
.net
["r3"].cmd('vtysh -c "conf t" -c "router ospf" -c "no mpls-te inter-as"')
191 for rname
in ["r1", "r2", "r3", "r4"]:
192 compare_ted_json_output(tgen
, rname
, "ted_step3.json")
196 "Step4: Enable Segment Routing on r1 and r2 and verify that corresponding \
197 Edges are updated with Adjacency SID and Subnets with Prefix SID in the \
200 tgen
= setup_testcase("Step4: Enable Segment Routing on r1 & r2")
202 tgen
.net
["r1"].cmd('vtysh -c "conf t" -c "router ospf" -c "segment-routing on"')
204 'vtysh -c "conf t" -c "router ospf" -c "segment-routing global-block 20000 23999"'
207 'vtysh -c "conf t" -c "router ospf" -c "segment-routing prefix 10.0.255.1/32 index 10"'
209 tgen
.net
["r2"].cmd('vtysh -c "conf t" -c "router ospf" -c "segment-routing on"')
211 'vtysh -c "conf t" -c "router ospf" -c "segment-routing node-msd 16"'
214 'vtysh -c "conf t" -c "router ospf" -c "segment-routing global-block 16000 23999 local-block 5000 6999"'
217 'vtysh -c "conf t" -c "router ospf" -c "segment-routing prefix 10.0.255.2/32 index 20 explicit-null"'
220 for rname
in ["r1", "r2", "r3", "r4"]:
221 compare_ted_json_output(tgen
, rname
, "ted_step4.json")
225 "Step5: Re-enable interface between r1 & r2 and verify that corresponding \
226 Edges are added in the TED on all routers"
228 tgen
= setup_testcase("Step5: Re-enable interface between r1 & r2")
230 tgen
.net
["r1"].cmd('vtysh -c "conf t" -c "interface r1-eth1" -c "no shutdown"')
231 tgen
.net
["r2"].cmd('vtysh -c "conf t" -c "interface r2-eth1" -c "no shutdown"')
233 for rname
in ["r1", "r2", "r3", "r4"]:
234 compare_ted_json_output(tgen
, rname
, "ted_step5.json")
238 "Step6: Set delay and jitter for interface r4-eth0 on r4, remove use-bw \
239 for interface r2-eth3 on r2 and verify that corresponding Edges are \
240 updated in the TED on all routers"
242 tgen
= setup_testcase("Step6: Modify link parameters on r2 & r4")
245 'vtysh -c "conf t" -c "interface r2-eth3" -c "link-params" -c "no use-bw"'
248 'vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay 20000"'
251 'vtysh -c "conf t" -c "interface r4-eth0" -c "link-params" -c "delay-variation 10000"'
254 for rname
in ["r1", "r2", "r3", "r4"]:
255 compare_ted_json_output(tgen
, rname
, "ted_step6.json")
259 "Step7: Disable OSPF on r4 and verify that corresponding Vertex, Edges and \
260 Subnets are removed from the TED on all remaining routers"
262 tgen
= setup_testcase("Step7: Disable OSPF on r4")
264 tgen
.net
["r4"].cmd('vtysh -c "conf t" -c "no router ospf"')
266 for rname
in ["r1", "r2", "r3"]:
267 compare_ted_json_output(tgen
, rname
, "ted_step7.json")
270 def test_memory_leak():
271 "Run the memory leak test and report results."
274 if not tgen
.is_memleak_enabled():
275 pytest
.skip("Memory leak test/report is disabled")
277 tgen
.report_memory_leaks()
280 if __name__
== "__main__":
281 args
= ["-s"] + sys
.argv
[1:]
282 sys
.exit(pytest
.main(args
))