]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/cspf_topo1/test_cspf_topo1.py
2 # SPDX-License-Identifier: ISC
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2022 by Orange
9 # Author: Olivier Dugeon <olivier.dugeon@orange.com>
13 test_cspf_topo1.py: Test the FRR Constraint Shortest Path First algorithm.
23 10.0.0.0/24| |10.0.1.0/24
27 +------------+ +------------+
29 | R2 |r2-eth2 r3-eth0| R3 |
30 | 10.0.255.2 +------------------+ 10.0.255.3 |
32 +------------+ 2001:db8:3:/64 +------+-----+
38 r4-eth0| 2001:db8:5:/64|
42 | 10.0.255.4 +-------------------------+
51 from functools
import partial
53 # Save the Current Working Directory to find configuration files.
54 CWD
= os
.path
.dirname(os
.path
.realpath(__file__
))
55 sys
.path
.append(os
.path
.join(CWD
, "../"))
57 # pylint: disable=C0413
59 # Import topogen and topotest helpers
60 from lib
import topotest
61 from lib
.topogen
import Topogen
, TopoRouter
, get_topogen
62 from lib
.topolog
import logger
67 pytestmark
= [pytest
.mark
.isisd
]
74 for routern
in range(1, 5):
75 tgen
.add_router("r{}".format(routern
))
77 # Interconect router 1 and 2 with 2 links
78 switch
= tgen
.add_switch("s1")
79 switch
.add_link(tgen
.gears
["r1"])
80 switch
.add_link(tgen
.gears
["r2"])
81 switch
= tgen
.add_switch("s2")
82 switch
.add_link(tgen
.gears
["r1"])
83 switch
.add_link(tgen
.gears
["r2"])
85 # Interconect router 3 and 2
86 switch
= tgen
.add_switch("s3")
87 switch
.add_link(tgen
.gears
["r3"])
88 switch
.add_link(tgen
.gears
["r2"])
90 # Interconect router 4 and 2
91 switch
= tgen
.add_switch("s4")
92 switch
.add_link(tgen
.gears
["r4"])
93 switch
.add_link(tgen
.gears
["r2"])
95 # Interconnect router 3 and 4
96 switch
= tgen
.add_switch("s5")
97 switch
.add_link(tgen
.gears
["r3"])
98 switch
.add_link(tgen
.gears
["r4"])
101 def setup_module(mod
):
102 "Sets up the pytest environment"
104 logger
.info("\n\n---- Starting CSPF tests ----\n")
106 tgen
= Topogen(build_topo
, mod
.__name
__)
107 tgen
.start_topology()
109 router_list
= tgen
.routers()
111 for rname
, router
in router_list
.items():
113 TopoRouter
.RD_ZEBRA
, os
.path
.join(CWD
, "{}/zebra.conf".format(rname
))
116 TopoRouter
.RD_ISIS
, os
.path
.join(CWD
, "{}/isisd.conf".format(rname
))
120 TopoRouter
.RD_SHARP
, os
.path
.join(CWD
, "{}/sharpd.conf".format("r1"))
123 # Initialize all routers.
127 def teardown_module():
128 "Teardown the pytest environment"
133 logger
.info("\n\n---- CSPF tests End ----\n")
136 def compare_ted_json_output(tgen
, rname
, fileref
):
137 "Compare TED JSON output"
139 logger
.info('Comparing router "%s" TED output', rname
)
141 filename
= "{}/reference/{}".format(CWD
, fileref
)
142 expected
= json
.loads(open(filename
).read())
143 command
= "show sharp ted json"
145 # Run test function until we get an result. Wait at most 60 seconds.
146 test_func
= partial(topotest
.router_json_cmp
, tgen
.gears
[rname
], command
, expected
)
147 _
, diff
= topotest
.run_and_expect(test_func
, None, count
=60, wait
=2)
148 assertmsg
= '"{}" TED JSON output mismatches the expected result'.format(rname
)
149 assert diff
is None, assertmsg
152 def compare_cspf_output(tgen
, rname
, fileref
, src
, dst
, cost
, bw
=""):
153 "Compare CSPF output"
155 logger
.info('Comparing router "%s" CSPF output', rname
)
157 filename
= "{}/reference/{}".format(CWD
, fileref
)
158 expected
= open(filename
).read()
159 command
= "show sharp cspf source {} destination {} {} {}".format(
163 # Run test function until we get an result. Wait at most 60 seconds.
165 topotest
.router_output_cmp
, tgen
.gears
[rname
], command
, expected
167 result
, diff
= topotest
.run_and_expect(test_func
, "", count
=5, wait
=2)
168 assert result
, "CSPF output mismatches the expected result on {}:\n{}".format(
173 def setup_testcase(msg
):
179 # Skip if previous fatal error condition is raised
180 if tgen
.routers_have_failure():
181 pytest
.skip(tgen
.errors
)
186 # Note that all routers must discover the same Network Topology, so the same TED.
190 "Step1: Check initial topology"
192 tgen
= setup_testcase("Step1: test initial IS-IS TE Data Base import")
193 tgen
.net
["r1"].cmd('vtysh -c "sharp import-te"')
195 compare_ted_json_output(tgen
, "r1", "sharp-ted.json")
199 "Step2: Test CSPF from r1 to r4 for IPv4 with various metric"
201 tgen
= setup_testcase("Step2: CSPF(r1, r4, IPv4)")
204 tgen
, "r1", "cspf-ipv4-metric.txt", "10.0.0.1", "10.0.255.4", "metric 50"
207 tgen
, "r1", "cspf-ipv4-te-metric.txt", "10.0.255.1", "10.0.4.4", "te-metric 50"
210 tgen
, "r1", "cspf-ipv4-delay.txt", "10.0.255.1", "10.0.255.4", "delay 50000"
215 "cspf-ipv4-delay.txt",
224 "Step3: Test CSPF from r1 to r4 for IPv6 with various metric"
226 tgen
= setup_testcase("Step2: CSPF(r1, r4, IPv6)")
231 "cspf-ipv6-metric.txt",
239 "cspf-ipv6-te-metric.txt",
245 tgen
, "r1", "cspf-ipv6-delay.txt", "2001:db8::1", "2001:db8::4", "delay 80000"
250 "cspf-ipv6-delay.txt",
259 "Step4: Test CSPF from r1 to r4 with no possible path"
261 tgen
= setup_testcase("Step2: CSPF(r1, r4, failure)")
264 tgen
, "r1", "cspf-failed.txt", "10.0.255.1", "10.0.255.4", "metric 10"
267 tgen
, "r1", "cspf-failed.txt", "2001:db8::1", "2001:db8::4", "te-metric 50"
270 tgen
, "r1", "cspf-failed.txt", "10.0.255.1", "10.0.255.4", "delay 5000"
282 tgen
, "r1", "cspf-failed-src.txt", "10.0.0.3", "10.0.255.4", "metric 10"
285 tgen
, "r1", "cspf-failed-dst.txt", "10.0.0.1", "10.0.4.40", "metric 10"
288 tgen
, "r1", "cspf-failed-same.txt", "10.0.0.1", "10.0.0.1", "metric 10"
292 def test_memory_leak():
293 "Run the memory leak test and report results."
296 if not tgen
.is_memleak_enabled():
297 pytest
.skip("Memory leak test/report is disabled")
299 tgen
.report_memory_leaks()
302 if __name__
== "__main__":
303 args
= ["-s"] + sys
.argv
[1:]
304 sys
.exit(pytest
.main(args
))