]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/ripng_topo1/test_ripng_topo1.py
5 # Part of NetDEF Topology Tests
7 # Copyright (c) 2017 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
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_ripng_topo1.py: Test of RIPng Topology
35 from time
import sleep
37 from functools
import partial
39 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
40 from lib
import topotest
41 from lib
.topogen
import Topogen
, get_topogen
45 pytestmark
= [pytest
.mark
.ripd
]
47 #####################################################
49 ## Network Topology Definition
51 #####################################################
57 tgen
.add_router("r%s" % i
)
61 # First switch is for a dummy interface (for local network)
62 switch
= tgen
.add_switch("sw1")
63 switch
.add_link(tgen
.gears
["r1"])
66 # switch 2 switch is for connection to RIP router
67 switch
= tgen
.add_switch("sw2")
68 switch
.add_link(tgen
.gears
["r1"])
69 switch
.add_link(tgen
.gears
["r2"])
70 # switch 3 is between RIP routers
71 switch
= tgen
.add_switch("sw3")
72 switch
.add_link(tgen
.gears
["r2"])
73 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth1")
74 # switch 4 is stub on remote RIP router
75 switch
= tgen
.add_switch("sw4")
76 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth0")
78 switch
= tgen
.add_switch("sw5")
79 switch
.add_link(tgen
.gears
["r1"])
80 switch
= tgen
.add_switch("sw6")
81 switch
.add_link(tgen
.gears
["r1"])
84 #####################################################
88 #####################################################
91 def setup_module(module
):
92 print("\n\n** %s: Setup Topology" % module
.__name
__)
93 print("******************************************\n")
95 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
96 tgen
= Topogen(build_topo
, module
.__name
__)
103 for i
in range(1, 4):
104 net
["r%s" % i
].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir
, i
))
105 net
["r%s" % i
].loadConf("ripngd", "%s/r%s/ripngd.conf" % (thisDir
, i
))
106 tgen
.gears
["r%s" % i
].start()
108 # For debugging after starting FRR daemons, uncomment the next line
112 def teardown_module(module
):
113 print("\n\n** %s: Shutdown Topology" % module
.__name
__)
114 print("******************************************\n")
119 def test_router_running():
121 net
= get_topogen().net
123 # Skip if previous fatal error condition is raised
124 if fatal_error
!= "":
125 pytest
.skip(fatal_error
)
127 print("\n\n** Check if FRR is running on each Router node")
128 print("******************************************\n")
131 for i
in range(1, 4):
132 fatal_error
= net
["r%s" % i
].checkRouterRunning()
133 assert fatal_error
== "", fatal_error
135 # For debugging after starting FRR daemons, uncomment the next line
139 def test_converge_protocols():
141 net
= get_topogen().net
143 # Skip if previous fatal error condition is raised
144 if fatal_error
!= "":
145 pytest
.skip(fatal_error
)
147 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
149 print("\n\n** Waiting for protocols convergence")
150 print("******************************************\n")
152 # Not really implemented yet - just sleep 11 secs for now
155 # Make sure that all daemons are running
156 for i
in range(1, 4):
157 fatal_error
= net
["r%s" % i
].checkRouterRunning()
158 assert fatal_error
== "", fatal_error
160 # For debugging after starting FRR daemons, uncomment the next line
164 def test_ripng_status():
166 net
= get_topogen().net
168 # Skip if previous fatal error condition is raised
169 if fatal_error
!= "":
170 pytest
.skip(fatal_error
)
172 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
175 print("\n\n** Verifying RIPng status")
176 print("******************************************\n")
178 for i
in range(1, 4):
179 refTableFile
= "%s/r%s/ripng_status.ref" % (thisDir
, i
)
180 if os
.path
.isfile(refTableFile
):
181 # Read expected result from file
182 expected
= open(refTableFile
).read().rstrip()
183 # Fix newlines (make them all the same)
184 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
186 # Actual output from router
189 .cmd('vtysh -c "show ipv6 ripng status" 2> /dev/null')
192 # Mask out Link-Local mac address portion. They are random...
193 actual
= re
.sub(r
" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual
)
194 # Drop time in next due
195 actual
= re
.sub(r
"in [0-9]+ seconds", "in XX seconds", actual
)
196 # Drop time in last update
197 actual
= re
.sub(r
" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual
)
198 # Fix newlines (make them all the same)
199 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
202 diff
= topotest
.get_textdiff(
205 title1
="actual IPv6 RIPng status",
206 title2
="expected IPv6 RIPng status",
209 # Empty string if it matches, otherwise diff contains unified diff
212 "r%s failed IPv6 RIPng status check:\n%s\n" % (i
, diff
)
218 assert failures
== 0, "IPv6 RIPng status failed for router r%s:\n%s" % (
223 # Make sure that all daemons are running
224 for i
in range(1, 4):
225 fatal_error
= net
["r%s" % i
].checkRouterRunning()
226 assert fatal_error
== "", fatal_error
228 # For debugging after starting FRR daemons, uncomment the next line
232 def test_ripng_routes():
234 net
= get_topogen().net
236 # Skip if previous fatal error condition is raised
237 if fatal_error
!= "":
238 pytest
.skip(fatal_error
)
240 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
242 # Verify RIPng Status
243 print("\n\n** Verifying RIPng routes")
244 print("******************************************\n")
246 for i
in range(1, 4):
247 refTableFile
= "%s/r%s/show_ipv6_ripng.ref" % (thisDir
, i
)
248 if os
.path
.isfile(refTableFile
):
249 # Read expected result from file
250 expected
= open(refTableFile
).read().rstrip()
251 # Fix newlines (make them all the same)
252 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
254 # Actual output from router
256 net
["r%s" % i
].cmd('vtysh -c "show ipv6 ripng" 2> /dev/null').rstrip()
259 actual
= re
.sub(r
" [0-9][0-9]:[0-5][0-9]", " XX:XX", actual
)
260 # Mask out Link-Local mac address portion. They are random...
262 r
" fe80::[0-9a-f: ]+", " fe80::XXXX:XXXX:XXXX:XXXX ", actual
264 # Remove trailing spaces on all lines
265 actual
= "\n".join([line
.rstrip() for line
in actual
.splitlines()])
267 # Fix newlines (make them all the same)
268 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
271 diff
= topotest
.get_textdiff(
274 title1
="actual SHOW IPv6 RIPng",
275 title2
="expected SHOW IPv6 RIPng",
278 # Empty string if it matches, otherwise diff contains unified diff
280 sys
.stderr
.write("r%s failed SHOW IPv6 RIPng check:\n%s\n" % (i
, diff
))
285 assert failures
== 0, "SHOW IPv6 RIPng failed for router r%s:\n%s" % (
290 # Make sure that all daemons are running
291 for i
in range(1, 4):
292 fatal_error
= net
["r%s" % i
].checkRouterRunning()
293 assert fatal_error
== "", fatal_error
295 # For debugging after starting FRR daemons, uncomment the next line
299 def test_zebra_ipv6_routingTable():
301 net
= get_topogen().net
303 # Skip if previous fatal error condition is raised
304 if fatal_error
!= "":
305 pytest
.skip(fatal_error
)
307 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
309 # Verify OSPFv3 Routing Table
310 print("\n\n** Verifying Zebra IPv6 Routing Table")
311 print("******************************************\n")
313 for i
in range(1, 4):
314 refTableFile
= "%s/r%s/show_ipv6_route.ref" % (thisDir
, i
)
315 if os
.path
.isfile(refTableFile
):
316 # Read expected result from file
317 expected
= open(refTableFile
).read().rstrip()
318 # Fix newlines (make them all the same)
319 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
321 # Actual output from router
324 .cmd('vtysh -c "show ipv6 route" 2> /dev/null | grep "^R"')
327 # Mask out Link-Local mac address portion. They are random...
328 actual
= re
.sub(r
" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual
)
329 # Drop timers on end of line
330 actual
= re
.sub(r
", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual
)
331 # Fix newlines (make them all the same)
332 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
335 diff
= topotest
.get_textdiff(
338 title1
="actual Zebra IPv6 routing table",
339 title2
="expected Zebra IPv6 routing table",
342 # Empty string if it matches, otherwise diff contains unified diff
345 "r%s failed Zebra IPv6 Routing Table Check:\n%s\n" % (i
, diff
)
353 ), "Zebra IPv6 Routing Table verification failed for router r%s:\n%s" % (
358 # Make sure that all daemons are running
359 for i
in range(1, 4):
360 fatal_error
= net
["r%s" % i
].checkRouterRunning()
361 assert fatal_error
== "", fatal_error
363 # For debugging after starting FRR daemons, uncomment the next line
367 def test_shutdown_check_stderr():
369 net
= get_topogen().net
371 # Skip if previous fatal error condition is raised
372 if fatal_error
!= "":
373 pytest
.skip(fatal_error
)
375 if os
.environ
.get("TOPOTESTS_CHECK_STDERR") is None:
377 "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n"
379 pytest
.skip("Skipping test for Stderr output")
381 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
383 print("\n\n** Verifying unexpected STDERR output from daemons")
384 print("******************************************\n")
386 net
["r1"].stopRouter()
388 log
= net
["r1"].getStdErr("ripngd")
390 print("\nRIPngd StdErr Log:\n" + log
)
391 log
= net
["r1"].getStdErr("zebra")
393 print("\nZebra StdErr Log:\n" + log
)
396 def test_shutdown_check_memleak():
398 net
= get_topogen().net
400 # Skip if previous fatal error condition is raised
401 if fatal_error
!= "":
402 pytest
.skip(fatal_error
)
404 if os
.environ
.get("TOPOTESTS_CHECK_MEMLEAK") is None:
406 "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n"
408 pytest
.skip("Skipping test for memory leaks")
410 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
412 net
["r1"].stopRouter()
413 net
["r1"].report_memory_leaks(
414 os
.environ
.get("TOPOTESTS_CHECK_MEMLEAK"), os
.path
.basename(__file__
)
418 if __name__
== "__main__":
420 # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli
421 # retval = pytest.main(["-s", "--tb=no"])
422 retval
= pytest
.main(["-s"])