]>
Commit | Line | Data |
---|---|---|
6d0dbb79 LB |
1 | #!/usr/bin/env python |
2 | ||
3 | # | |
4 | # test_bgp_multiview_topo1.py | |
5 | # Part of NetDEF Topology Tests | |
6 | # | |
7 | # Copyright (c) 2016 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_mpls_vpn_topo1.py: Simple FRR/Quagga MPLS VPN Test | |
27 | ||
28 | | | |
29 | +----+----+ | |
30 | | ce1 | | |
31 | | 99.0.0.1| CE Router | |
32 | +----+----+ | |
33 | 192.168.1. | .2 ce1-eth0 | |
34 | | .1 r1-eth4 | |
35 | +---------+ | |
36 | | r1 | | |
37 | | 1.1.1.1 | PE Router | |
38 | +----+----+ | |
39 | | .1 r1-eth0 | |
40 | | | |
41 | ~~~~~~~~~~~~~ | |
42 | ~~ sw0 ~~ | |
43 | ~~ 10.0.1.0/24 ~~ | |
44 | ~~~~~~~~~~~~~ | |
45 | |10.0.1.0/24 | |
46 | | | |
47 | | .2 r2-eth0 | |
48 | +----+----+ | |
49 | | r2 | | |
50 | | 2.2.2.2 | P router | |
51 | +--+---+--+ | |
52 | r2-eth2 .2 | | .2 r2-eth1 | |
53 | ______/ \______ | |
54 | / \ | |
55 | ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ | |
56 | ~~ sw2 ~~ ~~ sw1 ~~ | |
57 | ~~ 10.0.3.0/24 ~~ ~~ 10.0.2.0/24 ~~ | |
58 | ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ | |
59 | | / | | |
60 | \ _________/ | | |
61 | \ / \ | |
62 | r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 | |
63 | +----+--+---+ +----+----+ | |
64 | | r3 | | r4 | | |
65 | | 3.3.3.3 | | 4.4.4.4 | PE Routers | |
66 | +-----------+ +---------+ | |
67 | 192.168.1. | .1 192.168.1. | .1 rX-eth4 | |
68 | | .2 | .2 ceX-eth0 | |
69 | +-----+-----+ +----+-----+ | |
70 | | ce2 | | ce3 | | |
71 | | 99.0.0.2 | | 99.0.0.3 | CE Routers | |
72 | +-----+-----+ +----+-----+ | |
73 | | | | |
74 | ||
75 | """ | |
76 | ||
77 | import os | |
78 | import re | |
79 | import sys | |
80 | import pytest | |
81 | from time import sleep | |
82 | ||
83 | from mininet.topo import Topo | |
84 | from mininet.net import Mininet | |
85 | from mininet.node import Node, OVSSwitch, Host | |
86 | from mininet.log import setLogLevel, info | |
87 | from mininet.cli import CLI | |
88 | from mininet.link import Intf | |
89 | ||
90 | sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
91 | sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '/utilities') | |
92 | ||
93 | from lib import topotest | |
94 | ||
95 | from lutil import luStart, luInclude, luFinish, luNumFail | |
96 | ||
97 | fatal_error = "" | |
98 | ||
99 | # Expected version of CLI Output - Appendix to filename | |
100 | # empty string = current, latest output (default) | |
101 | # "-1" ... "-NNN" previous versions (incrementing with each version) | |
102 | cli_version = "" | |
103 | ||
104 | ##################################################### | |
105 | ## | |
106 | ## Network Topology Definition | |
107 | ## | |
108 | ##################################################### | |
109 | ||
110 | class NetworkTopo(Topo): | |
111 | "VPN Test Topology 1" | |
112 | ||
113 | def build(self, **_opts): | |
114 | ||
115 | # Setup Routers | |
116 | router = {} | |
117 | for i in range(1, 5): | |
118 | router[i] = topotest.addRouter(self, 'r%s' % i) | |
119 | ce = {} | |
120 | for i in range(1, 4): | |
121 | ce[i] = topotest.addRouter(self, 'ce%s' % i) | |
122 | ||
123 | self.addLink(ce[1], router[1], intfName1='ce1-eth0', intfName2='r1-eth4', addr1='00:11:01:00:00:00', addr2='00:11:00:01:00:04') | |
124 | self.addLink(ce[2], router[3], intfName1='ce2-eth0', intfName2='r3-eth4', addr1='00:11:02:00:00:00', addr2='00:11:00:03:00:04') | |
125 | self.addLink(ce[3], router[4], intfName1='ce3-eth0', intfName2='r4-eth4', addr1='00:11:03:00:00:00', addr2='00:11:00:04:00:04') | |
126 | # Setup Switches, add Interfaces and Connections | |
127 | switch = {} | |
128 | # First switch | |
129 | switch[0] = self.addSwitch('sw0', cls=topotest.LegacySwitch) | |
130 | self.addLink(switch[0], router[1], intfName2='r1-eth0', addr1='80:AA:00:00:00:00', addr2='00:11:00:01:00:00') | |
131 | self.addLink(switch[0], router[2], intfName2='r2-eth0', addr1='80:AA:00:00:00:01', addr2='00:11:00:02:00:00') | |
132 | # Second switch | |
133 | switch[1] = self.addSwitch('sw1', cls=topotest.LegacySwitch) | |
134 | self.addLink(switch[1], router[2], intfName2='r2-eth1', addr1='80:AA:00:01:00:00', addr2='00:11:00:02:00:01') | |
135 | self.addLink(switch[1], router[3], intfName2='r3-eth0', addr1='80:AA:00:01:00:01', addr2='00:11:00:03:00:00') | |
136 | self.addLink(switch[1], router[4], intfName2='r4-eth0', addr1='80:AA:00:01:00:02', addr2='00:11:00:04:00:00') | |
137 | # Third switch | |
138 | switch[2] = self.addSwitch('sw2', cls=topotest.LegacySwitch) | |
139 | self.addLink(switch[2], router[2], intfName2='r2-eth2', addr1='80:AA:00:02:00:00', addr2='00:11:00:02:00:02') | |
140 | self.addLink(switch[2], router[3], intfName2='r3-eth1', addr1='80:AA:00:02:00:01', addr2='00:11:00:03:00:01') | |
141 | ||
142 | ##################################################### | |
143 | ## | |
144 | ## Tests starting | |
145 | ## | |
146 | ##################################################### | |
147 | ||
148 | def setup_module(module): | |
149 | global topo, net | |
150 | global fatal_error | |
151 | global thisDir | |
152 | ||
153 | print("\n\n** %s: Setup Topology" % module.__name__) | |
154 | print("******************************************\n") | |
155 | ||
156 | print("Cleanup old Mininet runs") | |
157 | os.system('sudo mn -c > /dev/null 2>&1') | |
158 | ||
159 | thisDir = os.path.dirname(os.path.realpath(__file__)) | |
160 | topo = NetworkTopo() | |
161 | ||
162 | net = Mininet(controller=None, topo=topo) | |
163 | net.start() | |
164 | luStart(thisDir, net) | |
165 | ||
166 | # Starting Routers | |
167 | for i in range(1, 5): | |
168 | net['r%s' % i].loadConf('zebra', '%s/r%s/zebra.conf' % (thisDir, i)) | |
169 | net['r%s' % i].loadConf('ospfd', '%s/r%s/ospfd.conf' % (thisDir, i)) | |
170 | net['r%s' % i].loadConf('ldpd', '%s/r%s/ldpd.conf' % (thisDir, i)) | |
171 | net['r%s' % i].loadConf('bgpd', '%s/r%s/bgpd.conf' % (thisDir, i)) | |
172 | fatal_error = net['r%s' % i].startRouter() | |
173 | ||
174 | if fatal_error != "": | |
175 | break | |
176 | ||
177 | # Starting CE Routers | |
178 | for i in range(1, 4): | |
179 | net['ce%s' % i].loadConf('zebra', '%s/ce%s/zebra.conf' % (thisDir, i)) | |
180 | net['ce%s' % i].loadConf('bgpd', '%s/ce%s/bgpd.conf' % (thisDir, i)) | |
181 | fatal_error = net['ce%s' % i].startRouter() | |
182 | ||
183 | if fatal_error != "": | |
184 | break | |
185 | ||
186 | # For debugging after starting FRR/Quagga daemons, uncomment the next line | |
187 | #CLI(net) | |
188 | ||
189 | def teardown_module(module): | |
190 | global net | |
191 | ||
192 | print("\n\n** %s: Shutdown Topology" % module.__name__) | |
193 | print("******************************************\n") | |
194 | ||
195 | # End - Shutdown network | |
196 | net.stop() | |
197 | ||
198 | def test_add_vnc_routes(): | |
199 | global fatal_error | |
200 | global net | |
201 | global cli_version | |
202 | ||
203 | # Skip if previous fatal error condition is raised | |
204 | if (fatal_error != ""): | |
205 | pytest.skip(fatal_error) | |
206 | ||
207 | print("\n\n** Running main test cases") | |
208 | print("******************************\n") | |
209 | luInclude('teststart.py') | |
210 | # For debugging after starting FRR/Quagga daemons, uncomment the next line | |
211 | #CLI(net) | |
212 | ||
213 | luInclude('testfinish.py') | |
214 | # For debugging after starting FRR/Quagga daemons, uncomment the next line | |
215 | #CLI(net) | |
216 | ||
217 | # Make sure that all daemons are running | |
218 | numFail = luNumFail() | |
219 | if numFail > 0: | |
220 | fatal_error = '%d tests failed' % numFail | |
221 | assert fatal_error == "", fatal_error | |
222 | ||
223 | def test_shutdown_check_stderr(): | |
224 | global fatal_error | |
225 | global net | |
226 | ||
227 | # Skip if previous fatal error condition is raised | |
228 | if (fatal_error != ""): | |
229 | pytest.skip(fatal_error) | |
230 | ||
231 | if os.environ.get('TOPOTESTS_CHECK_STDERR') is None: | |
232 | print("SKIPPED final check on StdErr output: Disabled (TOPOTESTS_CHECK_STDERR undefined)\n") | |
233 | pytest.skip('Skipping test for Stderr output') | |
234 | ||
235 | thisDir = os.path.dirname(os.path.realpath(__file__)) | |
236 | ||
237 | print("\n\n** Verifying unexpected STDERR output from daemons") | |
238 | print("******************************************\n") | |
239 | ||
240 | for i in range(1, 5): | |
241 | net['r%s' % i].stopRouter() | |
242 | log = net['r%s' % i].getStdErr('bgpd') | |
243 | if log: | |
244 | print("\nRouter r%s BGPd StdErr Log:\n%s" % (i, log)) | |
245 | log = net['r%s' % i].getStdErr('ldpd') | |
246 | if log: | |
247 | print("\nRouter r%s LDPd StdErr Log:\n%s" % (i, log)) | |
248 | log = net['r%s' % i].getStdErr('ospfd') | |
249 | if log: | |
250 | print("\nRouter r%s OSPFd StdErr Log:\n%s" % (i, log)) | |
251 | log = net['r%s' % i].getStdErr('zebra') | |
252 | if log: | |
253 | print("\nRouter r%s Zebra StdErr Log:\n%s" % (i, log)) | |
254 | ||
255 | for i in range(1, 4): | |
256 | net['ce%s' % i].stopRouter() | |
257 | log = net['ce%s' % i].getStdErr('bgpd') | |
258 | if log: | |
259 | print("\nRouter r%s BGPd StdErr Log:\n%s" % (i, log)) | |
260 | log = net['ce%s' % i].getStdErr('zebra') | |
261 | if log: | |
262 | print("\nRouter r%s Zebra StdErr Log:\n%s" % (i, log)) | |
263 | ||
264 | ||
265 | def test_shutdown_check_memleak(): | |
266 | global fatal_error | |
267 | global net | |
268 | ||
269 | # Skip if previous fatal error condition is raised | |
270 | if (fatal_error != ""): | |
271 | pytest.skip(fatal_error) | |
272 | ||
273 | if os.environ.get('TOPOTESTS_CHECK_MEMLEAK') is None: | |
274 | print("SKIPPED final check on Memory leaks: Disabled (TOPOTESTS_CHECK_MEMLEAK undefined)\n") | |
275 | pytest.skip('Skipping test for memory leaks') | |
276 | ||
277 | thisDir = os.path.dirname(os.path.realpath(__file__)) | |
278 | ||
279 | for i in range(1, 5): | |
280 | net['r%s' % i].stopRouter() | |
281 | net['r%s' % i].report_memory_leaks(os.environ.get('TOPOTESTS_CHECK_MEMLEAK'), os.path.basename(__file__)) | |
282 | ||
283 | for i in range(1, 4): | |
284 | net['ce%s' % i].stopRouter() | |
285 | net['ce%s' % i].report_memory_leaks(os.environ.get('TOPOTESTS_CHECK_MEMLEAK'), os.path.basename(__file__)) | |
286 | ||
287 | if __name__ == '__main__': | |
288 | ||
289 | setLogLevel('info') | |
290 | # To suppress tracebacks, either use the following pytest call or add "--tb=no" to cli | |
291 | # retval = pytest.main(["-s", "--tb=no"]) | |
292 | retval = pytest.main(["-s"]) | |
293 | print(luFinish()) | |
294 | sys.exit(retval) |