]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/cspf_topo1/test_cspf_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2022 by Orange
8 # Author: Olivier Dugeon <olivier.dugeon@orange.com>
10 # Permission to use, copy, modify, and/or distribute this software
11 # for any purpose with or without fee is hereby granted, provided
12 # that the above copyright notice and this permission notice appear
15 # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
16 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
17 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
18 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
19 # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
21 # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 test_cspf_topo1.py: Test the FRR Constraint Shortest Path First algorithm.
36 10.0.0.0/24| |10.0.1.0/24
40 +------------+ +------------+
42 | R2 |r2-eth2 r3-eth0| R3 |
43 | 10.0.255.2 +------------------+ 10.0.255.3 |
45 +------------+ 2001:db8:3:/64 +------+-----+
51 r4-eth0| 2001:db8:5:/64|
55 | 10.0.255.4 +-------------------------+
64 from functools
import partial
66 # Save the Current Working Directory to find configuration files.
67 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
68 sys
.path
.append(os
.path
.join(CWD
, "../"))
70 # pylint: disable=C0413
72 # Import topogen and topotest helpers
73 from lib
import topotest
74 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
75 from lib
.topolog
import logger
80 pytestmark
= [pytest
.mark
.isisd
]
87 for routern
in range(1, 5):
88 tgen
.add_router("r{}".format(routern
))
90 # Interconect router 1 and 2 with 2 links
91 switch
= tgen
.add_switch("s1")
92 switch
.add_link(tgen
.gears
["r1"])
93 switch
.add_link(tgen
.gears
["r2"])
94 switch
= tgen
.add_switch("s2")
95 switch
.add_link(tgen
.gears
["r1"])
96 switch
.add_link(tgen
.gears
["r2"])
98 # Interconect router 3 and 2
99 switch
= tgen
.add_switch("s3")
100 switch
.add_link(tgen
.gears
["r3"])
101 switch
.add_link(tgen
.gears
["r2"])
103 # Interconect router 4 and 2
104 switch
= tgen
.add_switch("s4")
105 switch
.add_link(tgen
.gears
["r4"])
106 switch
.add_link(tgen
.gears
["r2"])
108 # Interconnect router 3 and 4
109 switch
= tgen
.add_switch("s5")
110 switch
.add_link(tgen
.gears
["r3"])
111 switch
.add_link(tgen
.gears
["r4"])
114 def setup_module(mod
):
115 "Sets up the pytest environment"
117 logger
.info("\n\n---- Starting CSPF tests ----\n")
119 tgen
= Topogen(build_topo
, mod
.__name
__)
120 tgen
.start_topology()
122 router_list
= tgen
.routers()
124 for rname
, router
in router_list
.items():
126 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
129 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
133 TopoRouter
.RD_SHARP
, os
.path
.join(CWD
, "{}/sharpd.conf".format("r1"))
136 # Initialize all routers.
140 def teardown_module():
141 "Teardown the pytest environment"
146 logger
.info("\n\n---- CSPF tests End ----\n")
149 def compare_ted_json_output(tgen
, rname
, fileref
):
150 "Compare TED JSON output"
152 logger
.info('Comparing router "%s" TED output', rname
)
154 filename
= "{}/reference/{}".format(CWD
, fileref
)
155 expected
= json
.loads(open(filename
).read())
156 command
= "show sharp ted json"
158 # Run test function until we get an result. Wait at most 60 seconds.
159 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
160 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=2)
161 assertmsg
= '"{}" TED JSON output mismatches the expected result'.format(rname
)
162 assert diff
is None, assertmsg
165 def compare_cspf_output(tgen
, rname
, fileref
, src
, dst
, cost
, bw
=""):
166 "Compare CSPF output"
168 logger
.info('Comparing router "%s" CSPF output', rname
)
170 filename
= "{}/reference/{}".format(CWD
, fileref
)
171 expected
= open(filename
).read()
172 command
= "show sharp cspf source {} destination {} {} {}".format(
176 # Run test function until we get an result. Wait at most 60 seconds.
178 topotest
.router_output_cmp
, tgen
.gears
[rname
], command
, expected
180 result
, diff
= topotest
.run_and_expect(test_func
, "", count
=2, wait
=2)
181 assert result
, "CSPF output mismatches the expected result on {}:\n{}".format(
186 def setup_testcase(msg
):
192 # Skip if previous fatal error condition is raised
193 if tgen
.routers_have_failure():
194 pytest
.skip(tgen
.errors
)
199 # Note that all routers must discover the same Network Topology, so the same TED.
203 "Step1: Check initial topology"
205 tgen
= setup_testcase("Step1: test initial IS-IS TE Data Base import")
206 tgen
.net
["r1"].cmd('vtysh -c "sharp import-te"')
208 compare_ted_json_output(tgen
, "r1", "sharp-ted.json")
212 "Step2: Test CSPF from r1 to r4 for IPv4 with various metric"
214 tgen
= setup_testcase("Step2: CSPF(r1, r4, IPv4)")
217 tgen
, "r1", "cspf-ipv4-metric.txt", "10.0.0.1", "10.0.255.4", "metric 50"
220 tgen
, "r1", "cspf-ipv4-te-metric.txt", "10.0.255.1", "10.0.4.4", "te-metric 50"
223 tgen
, "r1", "cspf-ipv4-delay.txt", "10.0.255.1", "10.0.255.4", "delay 50000"
228 "cspf-ipv4-delay.txt",
237 "Step3: Test CSPF from r1 to r4 for IPv6 with various metric"
239 tgen
= setup_testcase("Step2: CSPF(r1, r4, IPv6)")
244 "cspf-ipv6-metric.txt",
252 "cspf-ipv6-te-metric.txt",
258 tgen
, "r1", "cspf-ipv6-delay.txt", "2001:db8::1", "2001:db8::4", "delay 80000"
263 "cspf-ipv6-delay.txt",
272 "Step4: Test CSPF from r1 to r4 with no possible path"
274 tgen
= setup_testcase("Step2: CSPF(r1, r4, failure)")
277 tgen
, "r1", "cspf-failed.txt", "10.0.255.1", "10.0.255.4", "metric 10"
280 tgen
, "r1", "cspf-failed.txt", "2001:db8::1", "2001:db8::4", "te-metric 50"
283 tgen
, "r1", "cspf-failed.txt", "10.0.255.1", "10.0.255.4", "delay 5000"
295 tgen
, "r1", "cspf-failed-src.txt", "10.0.0.3", "10.0.255.4", "metric 10"
298 tgen
, "r1", "cspf-failed-dst.txt", "10.0.0.1", "10.0.4.40", "metric 10"
301 tgen
, "r1", "cspf-failed-same.txt", "10.0.0.1", "10.0.0.1", "metric 10"
305 def test_memory_leak():
306 "Run the memory leak test and report results."
309 if not tgen
.is_memleak_enabled():
310 pytest
.skip("Memory leak test/report is disabled")
312 tgen
.report_memory_leaks()
315 if __name__
== "__main__":
316 args
= ["-s"] + sys
.argv
[1:]
317 sys
.exit(pytest
.main(args
))