]> git.proxmox.com Git - mirror_frr.git/blob - tests/topotests/rip_topo1/test_rip_topo1.py
88299c90df31e4da9c2fa1a2806bd7c069e01267
[mirror_frr.git] / tests / topotests / rip_topo1 / test_rip_topo1.py
1 #!/usr/bin/env python
2
3 #
4 # test_rip_topo1.py
5 # Part of NetDEF Topology Tests
6 #
7 # Copyright (c) 2017 by
8 # Network Device Education Foundation, Inc. ("NetDEF")
9 #
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
13 # in all copies.
14 #
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
22 # OF THIS SOFTWARE.
23 #
24
25 """
26 test_rip_topo1.py: Testing RIPv2
27
28 """
29
30 import os
31 import re
32 import sys
33 import pytest
34 from time import sleep
35
36
37
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
41
42 fatal_error = ""
43
44 pytestmark = [pytest.mark.ripd]
45
46 #####################################################
47 ##
48 ## Network Topology Definition
49 ##
50 #####################################################
51
52
53 def build_topo(tgen):
54 # Setup RIP Routers
55 for i in range(1, 4):
56 tgen.add_router("r%s" % i)
57
58 #
59 # On main router
60 # First switch is for a dummy interface (for local network)
61 switch = tgen.add_switch("sw1")
62 switch.add_link(tgen.gears["r1"])
63 #
64 # Switches for RIP
65
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
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")
75
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")
79
80 switch = tgen.add_switch("sw5")
81 switch.add_link(tgen.gears["r1"])
82
83 switch = tgen.add_switch("sw6")
84 switch.add_link(tgen.gears["r1"])
85
86
87 #####################################################
88 ##
89 ## Tests starting
90 ##
91 #####################################################
92
93
94 def setup_module(module):
95 print("\n\n** %s: Setup Topology" % module.__name__)
96 print("******************************************\n")
97
98 thisDir = os.path.dirname(os.path.realpath(__file__))
99 tgen = Topogen(build_topo, module.__name__)
100 tgen.start_topology()
101
102 net = tgen.net
103
104 # Starting Routers
105 #
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()
110
111 # For debugging after starting FRR daemons, uncomment the next line
112 # CLI(net)
113
114
115 def teardown_module(module):
116 print("\n\n** %s: Shutdown Topology" % module.__name__)
117 print("******************************************\n")
118 tgen = get_topogen()
119 tgen.stop_topology()
120
121
122 def test_router_running():
123 global fatal_error
124 net = get_topogen().net
125
126 # Skip if previous fatal error condition is raised
127 if fatal_error != "":
128 pytest.skip(fatal_error)
129
130 print("\n\n** Check if FRR is running on each Router node")
131 print("******************************************\n")
132
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
137
138 # For debugging after starting FRR daemons, uncomment the next line
139 # CLI(net)
140
141
142 def test_converge_protocols():
143 global fatal_error
144 net = get_topogen().net
145
146 # Skip if previous fatal error condition is raised
147 if fatal_error != "":
148 pytest.skip(fatal_error)
149
150 thisDir = os.path.dirname(os.path.realpath(__file__))
151
152 print("\n\n** Waiting for protocols convergence")
153 print("******************************************\n")
154
155 # Not really implemented yet - just sleep 11 secs for now
156 sleep(21)
157
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
162
163 # For debugging after starting FRR daemons, uncomment the next line
164 # CLI(net)
165
166
167 def test_rip_status():
168 global fatal_error
169 net = get_topogen().net
170
171 # Skip if previous fatal error condition is raised
172 if fatal_error != "":
173 pytest.skip(fatal_error)
174
175 thisDir = os.path.dirname(os.path.realpath(__file__))
176
177 # Verify RIP Status
178 print("\n\n** Verifing RIP status")
179 print("******************************************\n")
180 failures = 0
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)
188
189 # Actual output from router
190 actual = (
191 net["r%s" % i]
192 .cmd('vtysh -c "show ip rip status" 2> /dev/null')
193 .rstrip()
194 )
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)
201
202 # Generate Diff
203 diff = topotest.get_textdiff(
204 actual,
205 expected,
206 title1="actual IP RIP status",
207 title2="expected IP RIP status",
208 )
209
210 # Empty string if it matches, otherwise diff contains unified diff
211 if diff:
212 sys.stderr.write("r%s failed IP RIP status check:\n%s\n" % (i, diff))
213 failures += 1
214 else:
215 print("r%s ok" % i)
216
217 assert failures == 0, "IP RIP status failed for router r%s:\n%s" % (i, diff)
218
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
223
224 # For debugging after starting FRR daemons, uncomment the next line
225 # CLI(net)
226
227
228 def test_rip_routes():
229 global fatal_error
230 net = get_topogen().net
231
232 # Skip if previous fatal error condition is raised
233 if fatal_error != "":
234 pytest.skip(fatal_error)
235
236 thisDir = os.path.dirname(os.path.realpath(__file__))
237
238 # Verify RIP Status
239 print("\n\n** Verifing RIP routes")
240 print("******************************************\n")
241 failures = 0
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)
249
250 # Actual output from router
251 actual = net["r%s" % i].cmd('vtysh -c "show ip rip" 2> /dev/null').rstrip()
252 # Drop Time
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)
256
257 # Generate Diff
258 diff = topotest.get_textdiff(
259 actual,
260 expected,
261 title1="actual SHOW IP RIP",
262 title2="expected SHOW IP RIP",
263 )
264
265 # Empty string if it matches, otherwise diff contains unified diff
266 if diff:
267 sys.stderr.write("r%s failed SHOW IP RIP check:\n%s\n" % (i, diff))
268 failures += 1
269 else:
270 print("r%s ok" % i)
271
272 assert failures == 0, "SHOW IP RIP failed for router r%s:\n%s" % (i, diff)
273
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
278
279 # For debugging after starting FRR daemons, uncomment the next line
280 # CLI(net)
281
282
283 def test_zebra_ipv4_routingTable():
284 global fatal_error
285 net = get_topogen().net
286
287 # Skip if previous fatal error condition is raised
288 if fatal_error != "":
289 pytest.skip(fatal_error)
290
291 thisDir = os.path.dirname(os.path.realpath(__file__))
292
293 # Verify OSPFv3 Routing Table
294 print("\n\n** Verifing Zebra IPv4 Routing Table")
295 print("******************************************\n")
296 failures = 0
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)
304
305 # Actual output from router
306 actual = (
307 net["r%s" % i]
308 .cmd('vtysh -c "show ip route" 2> /dev/null | grep "^R"')
309 .rstrip()
310 )
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)
315
316 # Generate Diff
317 diff = topotest.get_textdiff(
318 actual,
319 expected,
320 title1="actual Zebra IPv4 routing table",
321 title2="expected Zebra IPv4 routing table",
322 )
323
324 # Empty string if it matches, otherwise diff contains unified diff
325 if diff:
326 sys.stderr.write(
327 "r%s failed Zebra IPv4 Routing Table Check:\n%s\n" % (i, diff)
328 )
329 failures += 1
330 else:
331 print("r%s ok" % i)
332
333 assert (
334 failures == 0
335 ), "Zebra IPv4 Routing Table verification failed for router r%s:\n%s" % (
336 i,
337 diff,
338 )
339
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
344
345 # For debugging after starting FRR daemons, uncomment the next line
346 # CLI(net)
347
348
349 def test_shutdown_check_stderr():
350 global fatal_error
351 net = get_topogen().net
352
353 # Skip if previous fatal error condition is raised
354 if fatal_error != "":
355 pytest.skip(fatal_error)
356
357 if os.environ.get("TOPOTESTS_CHECK_STDERR") is None:
358 pytest.skip("Skipping test for Stderr output and memory leaks")
359
360 thisDir = os.path.dirname(os.path.realpath(__file__))
361
362 print("\n\n** Verifing unexpected STDERR output from daemons")
363 print("******************************************\n")
364
365 net["r1"].stopRouter()
366
367 log = net["r1"].getStdErr("ripd")
368 if log:
369 print("\nRIPd StdErr Log:\n" + log)
370 log = net["r1"].getStdErr("zebra")
371 if log:
372 print("\nZebra StdErr Log:\n" + log)
373
374
375 if __name__ == "__main__":
376
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"])
380 sys.exit(retval)