]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/rip_topo1/test_rip_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_rip_topo1.py: Testing RIPv2
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"])
65 # switch 2 switch is for connection to RIP router
66 switch
= tgen
.add_switch("sw2")
67 switch
.add_link(tgen
.gears
["r1"])
68 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")
75 # switch 4 is stub on remote RIP router
76 switch
= tgen
.add_switch("sw4")
77 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth0")
79 switch
= tgen
.add_switch("sw5")
80 switch
.add_link(tgen
.gears
["r1"])
82 switch
= tgen
.add_switch("sw6")
83 switch
.add_link(tgen
.gears
["r1"])
86 #####################################################
90 #####################################################
93 def setup_module(module
):
94 print("\n\n** %s: Setup Topology" % module
.__name
__)
95 print("******************************************\n")
97 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
98 tgen
= Topogen(build_topo
, module
.__name
__)
105 for i
in range(1, 4):
106 net
["r%s" % i
].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir
, i
))
107 net
["r%s" % i
].loadConf("ripd", "%s/r%s/ripd.conf" % (thisDir
, i
))
108 tgen
.gears
["r%s" % i
].start()
110 # For debugging after starting FRR daemons, uncomment the next line
114 def teardown_module(module
):
115 print("\n\n** %s: Shutdown Topology" % module
.__name
__)
116 print("******************************************\n")
121 def test_router_running():
123 net
= get_topogen().net
125 # Skip if previous fatal error condition is raised
126 if fatal_error
!= "":
127 pytest
.skip(fatal_error
)
129 print("\n\n** Check if FRR is running on each Router node")
130 print("******************************************\n")
132 # Make sure that all daemons are running
133 for i
in range(1, 4):
134 fatal_error
= net
["r%s" % i
].checkRouterRunning()
135 assert fatal_error
== "", fatal_error
138 def test_converge_protocols():
140 net
= get_topogen().net
142 # Skip if previous fatal error condition is raised
143 if fatal_error
!= "":
144 pytest
.skip(fatal_error
)
146 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
148 print("\n\n** Waiting for protocols convergence")
149 print("******************************************\n")
151 # Not really implemented yet - just sleep 11 secs for now
154 # Make sure that all daemons are still running
155 for i
in range(1, 4):
156 fatal_error
= net
["r%s" % i
].checkRouterRunning()
157 assert fatal_error
== "", fatal_error
160 def test_rip_status():
162 net
= get_topogen().net
164 # Skip if previous fatal error condition is raised
165 if fatal_error
!= "":
166 pytest
.skip(fatal_error
)
168 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
171 print("\n\n** Verifing RIP status")
172 print("******************************************\n")
174 for i
in range(1, 4):
175 refTableFile
= "%s/r%s/rip_status.ref" % (thisDir
, i
)
176 if os
.path
.isfile(refTableFile
):
177 # Read expected result from file
178 expected
= open(refTableFile
).read().rstrip()
179 # Fix newlines (make them all the same)
180 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
182 # Actual output from router
185 .cmd('vtysh -c "show ip rip status" 2> /dev/null')
188 # Drop time in next due
189 actual
= re
.sub(r
"in [0-9]+ seconds", "in XX seconds", actual
)
190 # Drop time in last update
191 actual
= re
.sub(r
" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual
)
192 # Fix newlines (make them all the same)
193 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
196 diff
= topotest
.get_textdiff(
199 title1
="actual IP RIP status",
200 title2
="expected IP RIP status",
203 # Empty string if it matches, otherwise diff contains unified diff
205 sys
.stderr
.write("r%s failed IP RIP status check:\n%s\n" % (i
, diff
))
210 assert failures
== 0, "IP RIP status failed for router r%s:\n%s" % (i
, diff
)
212 # Make sure that all daemons are still running
213 for i
in range(1, 4):
214 fatal_error
= net
["r%s" % i
].checkRouterRunning()
215 assert fatal_error
== "", fatal_error
218 def test_rip_routes():
220 net
= get_topogen().net
222 # Skip if previous fatal error condition is raised
223 if fatal_error
!= "":
224 pytest
.skip(fatal_error
)
226 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
229 print("\n\n** Verifing RIP routes")
230 print("******************************************\n")
232 for i
in range(1, 4):
233 refTableFile
= "%s/r%s/show_ip_rip.ref" % (thisDir
, i
)
234 if os
.path
.isfile(refTableFile
):
235 # Read expected result from file
236 expected
= open(refTableFile
).read().rstrip()
237 # Fix newlines (make them all the same)
238 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
240 # Actual output from router
241 actual
= net
["r%s" % i
].cmd('vtysh -c "show ip rip" 2> /dev/null').rstrip()
243 actual
= re
.sub(r
"[0-9][0-9]:[0-5][0-9]", "XX:XX", actual
)
244 # Fix newlines (make them all the same)
245 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
248 diff
= topotest
.get_textdiff(
251 title1
="actual SHOW IP RIP",
252 title2
="expected SHOW IP RIP",
255 # Empty string if it matches, otherwise diff contains unified diff
257 sys
.stderr
.write("r%s failed SHOW IP RIP check:\n%s\n" % (i
, diff
))
262 assert failures
== 0, "SHOW IP RIP failed for router r%s:\n%s" % (i
, diff
)
264 # Make sure that all daemons are still running
265 for i
in range(1, 4):
266 fatal_error
= net
["r%s" % i
].checkRouterRunning()
267 assert fatal_error
== "", fatal_error
270 def test_zebra_ipv4_routingTable():
272 net
= get_topogen().net
274 # Skip if previous fatal error condition is raised
275 if fatal_error
!= "":
276 pytest
.skip(fatal_error
)
278 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
280 # Verify OSPFv3 Routing Table
281 print("\n\n** Verifing Zebra IPv4 Routing Table")
282 print("******************************************\n")
284 for i
in range(1, 4):
285 refTableFile
= "%s/r%s/show_ip_route.ref" % (thisDir
, i
)
286 if os
.path
.isfile(refTableFile
):
287 # Read expected result from file
288 expected
= open(refTableFile
).read().rstrip()
289 # Fix newlines (make them all the same)
290 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
292 # Actual output from router
295 .cmd('vtysh -c "show ip route" 2> /dev/null | grep "^R"')
298 # Drop timers on end of line
299 actual
= re
.sub(r
", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual
)
300 # Fix newlines (make them all the same)
301 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
304 diff
= topotest
.get_textdiff(
307 title1
="actual Zebra IPv4 routing table",
308 title2
="expected Zebra IPv4 routing table",
311 # Empty string if it matches, otherwise diff contains unified diff
314 "r%s failed Zebra IPv4 Routing Table Check:\n%s\n" % (i
, diff
)
322 ), "Zebra IPv4 Routing Table verification failed for router r%s:\n%s" % (
327 # Make sure that all daemons are still running
328 for i
in range(1, 4):
329 fatal_error
= net
["r%s" % i
].checkRouterRunning()
330 assert fatal_error
== "", fatal_error
333 def test_shutdown_check_stderr():
335 net
= get_topogen().net
337 # Skip if previous fatal error condition is raised
338 if fatal_error
!= "":
339 pytest
.skip(fatal_error
)
341 if os
.environ
.get("TOPOTESTS_CHECK_STDERR") is None:
342 pytest
.skip("Skipping test for Stderr output and memory leaks")
344 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
346 print("\n\n** Verifing unexpected STDERR output from daemons")
347 print("******************************************\n")
349 net
["r1"].stopRouter()
351 log
= net
["r1"].getStdErr("ripd")
353 print("\nRIPd StdErr Log:\n" + log
)
354 log
= net
["r1"].getStdErr("zebra")
356 print("\nZebra StdErr Log:\n" + log
)
359 if __name__
== "__main__":
361 # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli
362 # retval = pytest.main(["-s", "--tb=no"])
363 retval
= pytest
.main(["-s"])