]>
git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/rip_topo1/test_rip_topo1.py
88299c90df31e4da9c2fa1a2806bd7c069e01267
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
38 sys
.path
.append(os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
39 from lib
import topotest
40 from lib
.topogen
import Topogen
, get_topogen
44 pytestmark
= [pytest
.mark
.ripd
]
46 #####################################################
48 ## Network Topology Definition
50 #####################################################
56 tgen
.add_router("r%s" % i
)
60 # First switch is for a dummy interface (for local network)
61 switch
= tgen
.add_switch("sw1")
62 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"])
71 # switch 3 is between RIP routers
72 switch
= tgen
.add_switch("sw3")
73 switch
.add_link(tgen
.gears
["r2"])
74 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth1")
76 # switch 4 is stub on remote RIP router
77 switch
= tgen
.add_switch("sw4")
78 switch
.add_link(tgen
.gears
["r3"], nodeif
="r3-eth0")
80 switch
= tgen
.add_switch("sw5")
81 switch
.add_link(tgen
.gears
["r1"])
83 switch
= tgen
.add_switch("sw6")
84 switch
.add_link(tgen
.gears
["r1"])
87 #####################################################
91 #####################################################
94 def setup_module(module
):
95 print("\n\n** %s: Setup Topology" % module
.__name
__)
96 print("******************************************\n")
98 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
99 tgen
= Topogen(build_topo
, module
.__name
__)
100 tgen
.start_topology()
106 for i
in range(1, 4):
107 net
["r%s" % i
].loadConf("zebra", "%s/r%s/zebra.conf" % (thisDir
, i
))
108 net
["r%s" % i
].loadConf("ripd", "%s/r%s/ripd.conf" % (thisDir
, i
))
109 tgen
.gears
["r%s" % i
].start()
111 # For debugging after starting FRR daemons, uncomment the next line
115 def teardown_module(module
):
116 print("\n\n** %s: Shutdown Topology" % module
.__name
__)
117 print("******************************************\n")
122 def test_router_running():
124 net
= get_topogen().net
126 # Skip if previous fatal error condition is raised
127 if fatal_error
!= "":
128 pytest
.skip(fatal_error
)
130 print("\n\n** Check if FRR is running on each Router node")
131 print("******************************************\n")
133 # Make sure that all daemons are running
134 for i
in range(1, 4):
135 fatal_error
= net
["r%s" % i
].checkRouterRunning()
136 assert fatal_error
== "", fatal_error
138 # For debugging after starting FRR daemons, uncomment the next line
142 def test_converge_protocols():
144 net
= get_topogen().net
146 # Skip if previous fatal error condition is raised
147 if fatal_error
!= "":
148 pytest
.skip(fatal_error
)
150 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
152 print("\n\n** Waiting for protocols convergence")
153 print("******************************************\n")
155 # Not really implemented yet - just sleep 11 secs for now
158 # Make sure that all daemons are still running
159 for i
in range(1, 4):
160 fatal_error
= net
["r%s" % i
].checkRouterRunning()
161 assert fatal_error
== "", fatal_error
163 # For debugging after starting FRR daemons, uncomment the next line
167 def test_rip_status():
169 net
= get_topogen().net
171 # Skip if previous fatal error condition is raised
172 if fatal_error
!= "":
173 pytest
.skip(fatal_error
)
175 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
178 print("\n\n** Verifing RIP status")
179 print("******************************************\n")
181 for i
in range(1, 4):
182 refTableFile
= "%s/r%s/rip_status.ref" % (thisDir
, i
)
183 if os
.path
.isfile(refTableFile
):
184 # Read expected result from file
185 expected
= open(refTableFile
).read().rstrip()
186 # Fix newlines (make them all the same)
187 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
189 # Actual output from router
192 .cmd('vtysh -c "show ip rip status" 2> /dev/null')
195 # Drop time in next due
196 actual
= re
.sub(r
"in [0-9]+ seconds", "in XX seconds", actual
)
197 # Drop time in last update
198 actual
= re
.sub(r
" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual
)
199 # Fix newlines (make them all the same)
200 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
203 diff
= topotest
.get_textdiff(
206 title1
="actual IP RIP status",
207 title2
="expected IP RIP status",
210 # Empty string if it matches, otherwise diff contains unified diff
212 sys
.stderr
.write("r%s failed IP RIP status check:\n%s\n" % (i
, diff
))
217 assert failures
== 0, "IP RIP status failed for router r%s:\n%s" % (i
, diff
)
219 # Make sure that all daemons are still running
220 for i
in range(1, 4):
221 fatal_error
= net
["r%s" % i
].checkRouterRunning()
222 assert fatal_error
== "", fatal_error
224 # For debugging after starting FRR daemons, uncomment the next line
228 def test_rip_routes():
230 net
= get_topogen().net
232 # Skip if previous fatal error condition is raised
233 if fatal_error
!= "":
234 pytest
.skip(fatal_error
)
236 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
239 print("\n\n** Verifing RIP routes")
240 print("******************************************\n")
242 for i
in range(1, 4):
243 refTableFile
= "%s/r%s/show_ip_rip.ref" % (thisDir
, i
)
244 if os
.path
.isfile(refTableFile
):
245 # Read expected result from file
246 expected
= open(refTableFile
).read().rstrip()
247 # Fix newlines (make them all the same)
248 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
250 # Actual output from router
251 actual
= net
["r%s" % i
].cmd('vtysh -c "show ip rip" 2> /dev/null').rstrip()
253 actual
= re
.sub(r
"[0-9][0-9]:[0-5][0-9]", "XX:XX", actual
)
254 # Fix newlines (make them all the same)
255 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
258 diff
= topotest
.get_textdiff(
261 title1
="actual SHOW IP RIP",
262 title2
="expected SHOW IP RIP",
265 # Empty string if it matches, otherwise diff contains unified diff
267 sys
.stderr
.write("r%s failed SHOW IP RIP check:\n%s\n" % (i
, diff
))
272 assert failures
== 0, "SHOW IP RIP failed for router r%s:\n%s" % (i
, diff
)
274 # Make sure that all daemons are still running
275 for i
in range(1, 4):
276 fatal_error
= net
["r%s" % i
].checkRouterRunning()
277 assert fatal_error
== "", fatal_error
279 # For debugging after starting FRR daemons, uncomment the next line
283 def test_zebra_ipv4_routingTable():
285 net
= get_topogen().net
287 # Skip if previous fatal error condition is raised
288 if fatal_error
!= "":
289 pytest
.skip(fatal_error
)
291 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
293 # Verify OSPFv3 Routing Table
294 print("\n\n** Verifing Zebra IPv4 Routing Table")
295 print("******************************************\n")
297 for i
in range(1, 4):
298 refTableFile
= "%s/r%s/show_ip_route.ref" % (thisDir
, i
)
299 if os
.path
.isfile(refTableFile
):
300 # Read expected result from file
301 expected
= open(refTableFile
).read().rstrip()
302 # Fix newlines (make them all the same)
303 expected
= ("\n".join(expected
.splitlines()) + "\n").splitlines(1)
305 # Actual output from router
308 .cmd('vtysh -c "show ip route" 2> /dev/null | grep "^R"')
311 # Drop timers on end of line
312 actual
= re
.sub(r
", [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", "", actual
)
313 # Fix newlines (make them all the same)
314 actual
= ("\n".join(actual
.splitlines()) + "\n").splitlines(1)
317 diff
= topotest
.get_textdiff(
320 title1
="actual Zebra IPv4 routing table",
321 title2
="expected Zebra IPv4 routing table",
324 # Empty string if it matches, otherwise diff contains unified diff
327 "r%s failed Zebra IPv4 Routing Table Check:\n%s\n" % (i
, diff
)
335 ), "Zebra IPv4 Routing Table verification failed for router r%s:\n%s" % (
340 # Make sure that all daemons are still running
341 for i
in range(1, 4):
342 fatal_error
= net
["r%s" % i
].checkRouterRunning()
343 assert fatal_error
== "", fatal_error
345 # For debugging after starting FRR daemons, uncomment the next line
349 def test_shutdown_check_stderr():
351 net
= get_topogen().net
353 # Skip if previous fatal error condition is raised
354 if fatal_error
!= "":
355 pytest
.skip(fatal_error
)
357 if os
.environ
.get("TOPOTESTS_CHECK_STDERR") is None:
358 pytest
.skip("Skipping test for Stderr output and memory leaks")
360 thisDir
= os
.path
.dirname(os
.path
.realpath(__file__
))
362 print("\n\n** Verifing unexpected STDERR output from daemons")
363 print("******************************************\n")
365 net
["r1"].stopRouter()
367 log
= net
["r1"].getStdErr("ripd")
369 print("\nRIPd StdErr Log:\n" + log
)
370 log
= net
["r1"].getStdErr("zebra")
372 print("\nZebra StdErr Log:\n" + log
)
375 if __name__
== "__main__":
377 # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli
378 # retval = pytest.main(["-s", "--tb=no"])
379 retval
= pytest
.main(["-s"])