]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ripng_topo1/test_ripng_topo1.py
2 # SPDX-License-Identifier: ISC
6 # Part of NetDEF Topology Tests
8 # Copyright (c) 2017 by
9 # Network Device Education Foundation, Inc. ("NetDEF")
13 test_ripng_topo1.py: Test of RIPng Topology
21 from time
import sleep
24 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
25 from lib
import topotest
26 from lib
.topogen
import Topogen
, get_topogen
30 pytestmark
= [pytest
.mark
.ripd
]
32 #####################################################
34 ## Network Topology Definition
36 #####################################################
42 tgen
.add_router("r%s" % i
)
46 # First switch is for a dummy interface (for local network)
47 switch
= tgen
.add_switch("sw1")
48 switch
.add_link(tgen
.gears
["r1"])
51 # switch 2 switch is for connection to RIP router
52 switch
= tgen
.add_switch("sw2")
53 switch
.add_link(tgen
.gears
["r1"])
54 switch
.add_link(tgen
.gears
["r2"])
55 # switch 3 is between RIP routers
56 switch
= tgen
.add_switch("sw3")
57 switch
.add_link(tgen
.gears
["r2"])
58 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth1")
59 # switch 4 is stub on remote RIP router
60 switch
= tgen
.add_switch("sw4")
61 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth0")
63 switch
= tgen
.add_switch("sw5")
64 switch
.add_link(tgen
.gears
["r1"])
65 switch
= tgen
.add_switch("sw6")
66 switch
.add_link(tgen
.gears
["r1"])
69 #####################################################
73 #####################################################
76 def setup_module(module
):
77 print("\n\n** %s: Setup Topology" % module
.__name
__)
78 print("******************************************\n")
80 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
81 tgen
= Topogen(build_topo
, module
.__name
__)
89 net
["r%s" % i
].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir
, i
))
90 net
["r%s" % i
].loadConf("ripngd", "%s/r%s/ripngd.conf" % (thisDir
, i
))
91 tgen
.gears
["r%s" % i
].start()
93 # For debugging after starting FRR daemons, uncomment the next line
97 def teardown_module(module
):
98 print("\n\n** %s: Shutdown Topology" % module
.__name
__)
99 print("******************************************\n")
104 def test_router_running():
106 net
= get_topogen().net
108 # Skip if previous fatal error condition is raised
109 if fatal_error
!= "":
110 pytest
.skip(fatal_error
)
112 print("\n\n** Check if FRR is running on each Router node")
113 print("******************************************\n")
116 for i
in range(1, 4):
117 fatal_error
= net
["r%s" % i
].checkRouterRunning()
118 assert fatal_error
== "", fatal_error
121 def test_converge_protocols():
123 net
= get_topogen().net
125 # Skip if previous fatal error condition is raised
126 if fatal_error
!= "":
127 pytest
.skip(fatal_error
)
129 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
131 print("\n\n** Waiting for protocols convergence")
132 print("******************************************\n")
134 # Not really implemented yet - just sleep 11 secs for now
137 # Make sure that all daemons are running
138 for i
in range(1, 4):
139 fatal_error
= net
["r%s" % i
].checkRouterRunning()
140 assert fatal_error
== "", fatal_error
143 def test_ripng_status():
145 net
= get_topogen().net
147 # Skip if previous fatal error condition is raised
148 if fatal_error
!= "":
149 pytest
.skip(fatal_error
)
151 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
154 print("\n\n** Verifying RIPng status")
155 print("******************************************\n")
157 for i
in range(1, 4):
158 refTableFile
= "%s/r%s/ripng_status.ref" % (thisDir
, i
)
159 if os
.path
.isfile(refTableFile
):
160 # Read expected result from file
161 expected
= open(refTableFile
).read().rstrip()
162 # Fix newlines (make them all the same)
163 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
165 # Actual output from router
168 .cmd('vtysh -c "show ipv6 ripng status" 2> /dev/null')
171 # Mask out Link-Local mac address portion. They are random...
172 actual
= re
.sub(r
" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual
)
173 # Drop time in next due
174 actual
= re
.sub(r
"in [0-9]+ seconds", "in XX seconds", actual
)
175 # Drop time in last update
176 actual
= re
.sub(r
" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual
)
177 # Fix newlines (make them all the same)
178 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
181 diff
= topotest
.get_textdiff(
184 title1
="actual IPv6 RIPng status",
185 title2
="expected IPv6 RIPng status",
188 # Empty string if it matches, otherwise diff contains unified diff
191 "r%s failed IPv6 RIPng status check:\n%s\n" % (i
, diff
)
197 assert failures
== 0, "IPv6 RIPng status failed for router r%s:\n%s" % (
202 # Make sure that all daemons are running
203 for i
in range(1, 4):
204 fatal_error
= net
["r%s" % i
].checkRouterRunning()
205 assert fatal_error
== "", fatal_error
208 def test_ripng_routes():
210 net
= get_topogen().net
212 # Skip if previous fatal error condition is raised
213 if fatal_error
!= "":
214 pytest
.skip(fatal_error
)
216 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
218 # Verify RIPng Status
219 print("\n\n** Verifying RIPng routes")
220 print("******************************************\n")
222 for i
in range(1, 4):
223 refTableFile
= "%s/r%s/show_ipv6_ripng.ref" % (thisDir
, i
)
224 if os
.path
.isfile(refTableFile
):
225 # Read expected result from file
226 expected
= open(refTableFile
).read().rstrip()
227 # Fix newlines (make them all the same)
228 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
230 # Actual output from router
232 net
["r%s" % i
].cmd('vtysh -c "show ipv6 ripng" 2> /dev/null').rstrip()
235 actual
= re
.sub(r
" [0-9][0-9]:[0-5][0-9]", " XX:XX", actual
)
236 # Mask out Link-Local mac address portion. They are random...
238 r
" fe80::[0-9a-f: ]+", " fe80::XXXX:XXXX:XXXX:XXXX ", actual
240 # Remove trailing spaces on all lines
241 actual
= "\n".join([line
.rstrip() for line
in actual
.splitlines()])
243 # Fix newlines (make them all the same)
244 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
247 diff
= topotest
.get_textdiff(
250 title1
="actual SHOW IPv6 RIPng",
251 title2
="expected SHOW IPv6 RIPng",
254 # Empty string if it matches, otherwise diff contains unified diff
256 sys
.stderr
.write("r%s failed SHOW IPv6 RIPng check:\n%s\n" % (i
, diff
))
261 assert failures
== 0, "SHOW IPv6 RIPng failed for router r%s:\n%s" % (
266 # Make sure that all daemons are running
267 for i
in range(1, 4):
268 fatal_error
= net
["r%s" % i
].checkRouterRunning()
269 assert fatal_error
== "", fatal_error
272 def test_zebra_ipv6_routingTable():
274 net
= get_topogen().net
276 # Skip if previous fatal error condition is raised
277 if fatal_error
!= "":
278 pytest
.skip(fatal_error
)
280 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
282 # Verify OSPFv3 Routing Table
283 print("\n\n** Verifying Zebra IPv6 Routing Table")
284 print("******************************************\n")
286 for i
in range(1, 4):
287 refTableFile
= "%s/r%s/show_ipv6_route.ref" % (thisDir
, i
)
288 if os
.path
.isfile(refTableFile
):
289 # Read expected result from file
290 expected
= open(refTableFile
).read().rstrip()
291 # Fix newlines (make them all the same)
292 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
294 # Actual output from router
297 .cmd('vtysh -c "show ipv6 route" 2> /dev/null | grep "^R"')
300 # Mask out Link-Local mac address portion. They are random...
301 actual
= re
.sub(r
" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual
)
302 # Drop timers on end of line
303 actual
= re
.sub(r
", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual
)
304 # Fix newlines (make them all the same)
305 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
308 diff
= topotest
.get_textdiff(
311 title1
="actual Zebra IPv6 routing table",
312 title2
="expected Zebra IPv6 routing table",
315 # Empty string if it matches, otherwise diff contains unified diff
318 "r%s failed Zebra IPv6 Routing Table Check:\n%s\n" % (i
, diff
)
326 ), "Zebra IPv6 Routing Table verification failed for router r%s:\n%s" % (
331 # Make sure that all daemons are running
332 for i
in range(1, 4):
333 fatal_error
= net
["r%s" % i
].checkRouterRunning()
334 assert fatal_error
== "", fatal_error
337 def test_shutdown_check_stderr():
339 net
= get_topogen().net
341 # Skip if previous fatal error condition is raised
342 if fatal_error
!= "":
343 pytest
.skip(fatal_error
)
345 if os
.environ
.get("TOPOTESTS_CHECK_STDERR") is None:
347 "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n"
349 pytest
.skip("Skipping test for Stderr output")
351 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
353 print("\n\n** Verifying unexpected STDERR output from daemons")
354 print("******************************************\n")
356 net
["r1"].stopRouter()
358 log
= net
["r1"].getStdErr("ripngd")
360 print("\nRIPngd StdErr Log:\n" + log
)
361 log
= net
["r1"].getStdErr("zebra")
363 print("\nZebra StdErr Log:\n" + log
)
366 def test_shutdown_check_memleak():
368 net
= get_topogen().net
370 # Skip if previous fatal error condition is raised
371 if fatal_error
!= "":
372 pytest
.skip(fatal_error
)
374 if os
.environ
.get("TOPOTESTS_CHECK_MEMLEAK") is None:
376 "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n"
378 pytest
.skip("Skipping test for memory leaks")
380 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
382 net
["r1"].stopRouter()
383 net
["r1"].report_memory_leaks(
384 os
.environ
.get("TOPOTESTS_CHECK_MEMLEAK"), os
.path
.basename(__file__
)
388 if __name__
== "__main__":
390 # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli
391 # retval = pytest.main(["-s", "--tb=no"])
392 retval
= pytest
.main(["-s"])