]>
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
34 from time
import sleep
37 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
38 from lib
import topotest
39 from lib
.topogen
import Topogen
, get_topogen
43 pytestmark
= [pytest
.mark
.ripd
]
45 #####################################################
47 ## Network Topology Definition
49 #####################################################
55 tgen
.add_router("r%s" % i
)
59 # First switch is for a dummy interface (for local network)
60 switch
= tgen
.add_switch("sw1")
61 switch
.add_link(tgen
.gears
["r1"])
64 # switch 2 switch is for connection to RIP router
65 switch
= tgen
.add_switch("sw2")
66 switch
.add_link(tgen
.gears
["r1"])
67 switch
.add_link(tgen
.gears
["r2"])
68 # switch 3 is between RIP routers
69 switch
= tgen
.add_switch("sw3")
70 switch
.add_link(tgen
.gears
["r2"])
71 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth1")
72 # switch 4 is stub on remote RIP router
73 switch
= tgen
.add_switch("sw4")
74 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth0")
76 switch
= tgen
.add_switch("sw5")
77 switch
.add_link(tgen
.gears
["r1"])
78 switch
= tgen
.add_switch("sw6")
79 switch
.add_link(tgen
.gears
["r1"])
82 #####################################################
86 #####################################################
89 def setup_module(module
):
90 print("\n\n** %s: Setup Topology" % module
.__name
__)
91 print("******************************************\n")
93 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
94 tgen
= Topogen(build_topo
, module
.__name
__)
101 for i
in range(1, 4):
102 net
["r%s" % i
].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir
, i
))
103 net
["r%s" % i
].loadConf("ripngd", "%s/r%s/ripngd.conf" % (thisDir
, i
))
104 tgen
.gears
["r%s" % i
].start()
106 # For debugging after starting FRR daemons, uncomment the next line
110 def teardown_module(module
):
111 print("\n\n** %s: Shutdown Topology" % module
.__name
__)
112 print("******************************************\n")
117 def test_router_running():
119 net
= get_topogen().net
121 # Skip if previous fatal error condition is raised
122 if fatal_error
!= "":
123 pytest
.skip(fatal_error
)
125 print("\n\n** Check if FRR is running on each Router node")
126 print("******************************************\n")
129 for i
in range(1, 4):
130 fatal_error
= net
["r%s" % i
].checkRouterRunning()
131 assert fatal_error
== "", fatal_error
133 # For debugging after starting FRR daemons, uncomment the next line
137 def test_converge_protocols():
139 net
= get_topogen().net
141 # Skip if previous fatal error condition is raised
142 if fatal_error
!= "":
143 pytest
.skip(fatal_error
)
145 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
147 print("\n\n** Waiting for protocols convergence")
148 print("******************************************\n")
150 # Not really implemented yet - just sleep 11 secs for now
153 # Make sure that all daemons are running
154 for i
in range(1, 4):
155 fatal_error
= net
["r%s" % i
].checkRouterRunning()
156 assert fatal_error
== "", fatal_error
158 # For debugging after starting FRR daemons, uncomment the next line
162 def test_ripng_status():
164 net
= get_topogen().net
166 # Skip if previous fatal error condition is raised
167 if fatal_error
!= "":
168 pytest
.skip(fatal_error
)
170 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
173 print("\n\n** Verifying RIPng status")
174 print("******************************************\n")
176 for i
in range(1, 4):
177 refTableFile
= "%s/r%s/ripng_status.ref" % (thisDir
, i
)
178 if os
.path
.isfile(refTableFile
):
179 # Read expected result from file
180 expected
= open(refTableFile
).read().rstrip()
181 # Fix newlines (make them all the same)
182 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
184 # Actual output from router
187 .cmd('vtysh -c "show ipv6 ripng status" 2> /dev/null')
190 # Mask out Link-Local mac address portion. They are random...
191 actual
= re
.sub(r
" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual
)
192 # Drop time in next due
193 actual
= re
.sub(r
"in [0-9]+ seconds", "in XX seconds", actual
)
194 # Drop time in last update
195 actual
= re
.sub(r
" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual
)
196 # Fix newlines (make them all the same)
197 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
200 diff
= topotest
.get_textdiff(
203 title1
="actual IPv6 RIPng status",
204 title2
="expected IPv6 RIPng status",
207 # Empty string if it matches, otherwise diff contains unified diff
210 "r%s failed IPv6 RIPng status check:\n%s\n" % (i
, diff
)
216 assert failures
== 0, "IPv6 RIPng status failed for router r%s:\n%s" % (
221 # Make sure that all daemons are running
222 for i
in range(1, 4):
223 fatal_error
= net
["r%s" % i
].checkRouterRunning()
224 assert fatal_error
== "", fatal_error
226 # For debugging after starting FRR daemons, uncomment the next line
230 def test_ripng_routes():
232 net
= get_topogen().net
234 # Skip if previous fatal error condition is raised
235 if fatal_error
!= "":
236 pytest
.skip(fatal_error
)
238 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
240 # Verify RIPng Status
241 print("\n\n** Verifying RIPng routes")
242 print("******************************************\n")
244 for i
in range(1, 4):
245 refTableFile
= "%s/r%s/show_ipv6_ripng.ref" % (thisDir
, i
)
246 if os
.path
.isfile(refTableFile
):
247 # Read expected result from file
248 expected
= open(refTableFile
).read().rstrip()
249 # Fix newlines (make them all the same)
250 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
252 # Actual output from router
254 net
["r%s" % i
].cmd('vtysh -c "show ipv6 ripng" 2> /dev/null').rstrip()
257 actual
= re
.sub(r
" [0-9][0-9]:[0-5][0-9]", " XX:XX", actual
)
258 # Mask out Link-Local mac address portion. They are random...
260 r
" fe80::[0-9a-f: ]+", " fe80::XXXX:XXXX:XXXX:XXXX ", actual
262 # Remove trailing spaces on all lines
263 actual
= "\n".join([line
.rstrip() for line
in actual
.splitlines()])
265 # Fix newlines (make them all the same)
266 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
269 diff
= topotest
.get_textdiff(
272 title1
="actual SHOW IPv6 RIPng",
273 title2
="expected SHOW IPv6 RIPng",
276 # Empty string if it matches, otherwise diff contains unified diff
278 sys
.stderr
.write("r%s failed SHOW IPv6 RIPng check:\n%s\n" % (i
, diff
))
283 assert failures
== 0, "SHOW IPv6 RIPng failed for router r%s:\n%s" % (
288 # Make sure that all daemons are running
289 for i
in range(1, 4):
290 fatal_error
= net
["r%s" % i
].checkRouterRunning()
291 assert fatal_error
== "", fatal_error
293 # For debugging after starting FRR daemons, uncomment the next line
297 def test_zebra_ipv6_routingTable():
299 net
= get_topogen().net
301 # Skip if previous fatal error condition is raised
302 if fatal_error
!= "":
303 pytest
.skip(fatal_error
)
305 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
307 # Verify OSPFv3 Routing Table
308 print("\n\n** Verifying Zebra IPv6 Routing Table")
309 print("******************************************\n")
311 for i
in range(1, 4):
312 refTableFile
= "%s/r%s/show_ipv6_route.ref" % (thisDir
, i
)
313 if os
.path
.isfile(refTableFile
):
314 # Read expected result from file
315 expected
= open(refTableFile
).read().rstrip()
316 # Fix newlines (make them all the same)
317 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
319 # Actual output from router
322 .cmd('vtysh -c "show ipv6 route" 2> /dev/null | grep "^R"')
325 # Mask out Link-Local mac address portion. They are random...
326 actual
= re
.sub(r
" fe80::[0-9a-f:]+", " fe80::XXXX:XXXX:XXXX:XXXX", actual
)
327 # Drop timers on end of line
328 actual
= re
.sub(r
", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual
)
329 # Fix newlines (make them all the same)
330 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
333 diff
= topotest
.get_textdiff(
336 title1
="actual Zebra IPv6 routing table",
337 title2
="expected Zebra IPv6 routing table",
340 # Empty string if it matches, otherwise diff contains unified diff
343 "r%s failed Zebra IPv6 Routing Table Check:\n%s\n" % (i
, diff
)
351 ), "Zebra IPv6 Routing Table verification failed for router r%s:\n%s" % (
356 # Make sure that all daemons are running
357 for i
in range(1, 4):
358 fatal_error
= net
["r%s" % i
].checkRouterRunning()
359 assert fatal_error
== "", fatal_error
361 # For debugging after starting FRR daemons, uncomment the next line
365 def test_shutdown_check_stderr():
367 net
= get_topogen().net
369 # Skip if previous fatal error condition is raised
370 if fatal_error
!= "":
371 pytest
.skip(fatal_error
)
373 if os
.environ
.get("TOPOTESTS_CHECK_STDERR") is None:
375 "SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n"
377 pytest
.skip("Skipping test for Stderr output")
379 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
381 print("\n\n** Verifying unexpected STDERR output from daemons")
382 print("******************************************\n")
384 net
["r1"].stopRouter()
386 log
= net
["r1"].getStdErr("ripngd")
388 print("\nRIPngd StdErr Log:\n" + log
)
389 log
= net
["r1"].getStdErr("zebra")
391 print("\nZebra StdErr Log:\n" + log
)
394 def test_shutdown_check_memleak():
396 net
= get_topogen().net
398 # Skip if previous fatal error condition is raised
399 if fatal_error
!= "":
400 pytest
.skip(fatal_error
)
402 if os
.environ
.get("TOPOTESTS_CHECK_MEMLEAK") is None:
404 "SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n"
406 pytest
.skip("Skipping test for memory leaks")
408 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
410 net
["r1"].stopRouter()
411 net
["r1"].report_memory_leaks(
412 os
.environ
.get("TOPOTESTS_CHECK_MEMLEAK"), os
.path
.basename(__file__
)
416 if __name__
== "__main__":
418 # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli
419 # retval = pytest.main(["-s", "--tb=no"])
420 retval
= pytest
.main(["-s"])