]>
Commit | Line | Data |
---|---|---|
318c1fa3 PR |
1 | #!/usr/bin/env python |
2 | ||
3 | # | |
4 | # test_bgp_auth.py | |
5 | # Part of NetDEF Topology Tests | |
6 | # | |
7 | # Copyright (c) 2020 by Volta Networks | |
8 | # | |
9 | # Permission to use, copy, modify, and/or distribute this software | |
10 | # for any purpose with or without fee is hereby granted, provided | |
11 | # that the above copyright notice and this permission notice appear | |
12 | # in all copies. | |
13 | # | |
14 | # THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES | |
15 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
16 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR | |
17 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY | |
18 | # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
19 | # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | |
20 | # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
21 | # OF THIS SOFTWARE. | |
22 | # | |
23 | ||
24 | """ | |
25 | test_bgp_auth.py: Test BGP Md5 Authentication | |
26 | ||
27 | +------+ | |
28 | +--------| |--------+ | |
29 | | +------| R1 |------+ | | |
30 | | | -----| |----+ | | | |
31 | | | | +------+ | | | | |
32 | | | | | | | | |
33 | +------+ +------+ | |
34 | | |------------| | | |
35 | | R2 |------------| R3 | | |
36 | | |------------| | | |
37 | +------+ +------+ | |
38 | ||
39 | ||
40 | setup is 3 routers with 3 links between each each link in a different vrf | |
41 | Default, blue and red respectively | |
42 | Tests check various fiddling with passwords and checking that the peer | |
43 | establishment is as expected and passwords are not leaked across sockets | |
44 | for bgp instances | |
45 | """ | |
46 | ||
47 | import os | |
48 | import sys | |
49 | import json | |
50 | import platform | |
51 | from functools import partial | |
52 | import pytest | |
53 | from time import sleep | |
54 | ||
55 | # Save the Current Working Directory to find configuration files. | |
56 | CWD = os.path.dirname(os.path.realpath(__file__)) | |
57 | sys.path.append(os.path.join(CWD, "../")) | |
58 | ||
59 | # pylint: disable=C0413 | |
60 | # Import topogen and topotest helpers | |
61 | from lib import topotest | |
62 | from lib.topogen import Topogen, TopoRouter, get_topogen | |
63 | from lib.topolog import logger | |
64 | ||
65 | # Required to instantiate the topology builder class. | |
8db751b8 | 66 | from lib.micronet_compat import Topo |
318c1fa3 PR |
67 | |
68 | from lib.common_config import apply_raw_config | |
69 | ||
70 | ERROR_LIST = ["Malformed", "Failure", "Unknown", "Incomplete"] | |
71 | ||
3dedee4f DS |
72 | pytestmark = [pytest.mark.bgpd, pytest.mark.ospfd] |
73 | ||
318c1fa3 PR |
74 | |
75 | class InvalidCLIError(Exception): | |
76 | """Raise when the CLI command is wrong""" | |
77 | ||
78 | pass | |
79 | ||
80 | ||
81 | class TemplateTopo(Topo): | |
82 | "Test topology builder" | |
83 | ||
84 | def build(self, *_args, **_opts): | |
85 | "Build function" | |
86 | tgen = get_topogen(self) | |
87 | ||
88 | # This function only purpose is to define allocation and relationship | |
89 | # between routers, switches and hosts. | |
90 | # | |
91 | # | |
92 | # Create routers | |
93 | tgen.add_router("R1") | |
94 | tgen.add_router("R2") | |
95 | tgen.add_router("R3") | |
96 | ||
97 | # R1-R2 1 | |
98 | switch = tgen.add_switch("s1") | |
99 | switch.add_link(tgen.gears["R1"]) | |
100 | switch.add_link(tgen.gears["R2"]) | |
101 | ||
102 | # R1-R3 1 | |
103 | switch = tgen.add_switch("s2") | |
104 | switch.add_link(tgen.gears["R1"]) | |
105 | switch.add_link(tgen.gears["R3"]) | |
106 | ||
107 | # R2-R3 1 | |
108 | switch = tgen.add_switch("s3") | |
109 | switch.add_link(tgen.gears["R2"]) | |
110 | switch.add_link(tgen.gears["R3"]) | |
111 | ||
112 | # R1-R2 2 | |
113 | switch = tgen.add_switch("s4") | |
114 | switch.add_link(tgen.gears["R1"]) | |
115 | switch.add_link(tgen.gears["R2"]) | |
116 | ||
117 | # R1-R3 2 | |
118 | switch = tgen.add_switch("s5") | |
119 | switch.add_link(tgen.gears["R1"]) | |
120 | switch.add_link(tgen.gears["R3"]) | |
121 | ||
122 | # R2-R3 2 | |
123 | switch = tgen.add_switch("s6") | |
124 | switch.add_link(tgen.gears["R2"]) | |
125 | switch.add_link(tgen.gears["R3"]) | |
126 | ||
127 | # R1-R2 3 | |
128 | switch = tgen.add_switch("s7") | |
129 | switch.add_link(tgen.gears["R1"]) | |
130 | switch.add_link(tgen.gears["R2"]) | |
131 | ||
132 | # R1-R3 2 | |
133 | switch = tgen.add_switch("s8") | |
134 | switch.add_link(tgen.gears["R1"]) | |
135 | switch.add_link(tgen.gears["R3"]) | |
136 | ||
137 | # R2-R3 2 | |
138 | switch = tgen.add_switch("s9") | |
139 | switch.add_link(tgen.gears["R2"]) | |
140 | switch.add_link(tgen.gears["R3"]) | |
141 | ||
142 | ||
143 | def setup_module(mod): | |
144 | "Sets up the pytest environment" | |
145 | # This function initiates the topology build with Topogen... | |
146 | tgen = Topogen(TemplateTopo, mod.__name__) | |
147 | # ... and here it calls Mininet initialization functions. | |
148 | tgen.start_topology() | |
149 | ||
150 | r1 = tgen.gears["R1"] | |
151 | r2 = tgen.gears["R2"] | |
152 | r3 = tgen.gears["R3"] | |
153 | ||
154 | # blue vrf | |
155 | r1.run("ip link add blue type vrf table 1001") | |
156 | r1.run("ip link set up dev blue") | |
157 | r2.run("ip link add blue type vrf table 1001") | |
158 | r2.run("ip link set up dev blue") | |
159 | r3.run("ip link add blue type vrf table 1001") | |
160 | r3.run("ip link set up dev blue") | |
161 | ||
162 | r1.run("ip link add lo1 type dummy") | |
163 | r1.run("ip link set lo1 master blue") | |
164 | r1.run("ip link set up dev lo1") | |
165 | r2.run("ip link add lo1 type dummy") | |
166 | r2.run("ip link set up dev lo1") | |
167 | r2.run("ip link set lo1 master blue") | |
168 | r3.run("ip link add lo1 type dummy") | |
169 | r3.run("ip link set up dev lo1") | |
170 | r3.run("ip link set lo1 master blue") | |
171 | ||
172 | r1.run("ip link set R1-eth2 master blue") | |
173 | r1.run("ip link set R1-eth3 master blue") | |
174 | r2.run("ip link set R2-eth2 master blue") | |
175 | r2.run("ip link set R2-eth3 master blue") | |
176 | r3.run("ip link set R3-eth2 master blue") | |
177 | r3.run("ip link set R3-eth3 master blue") | |
178 | ||
179 | r1.run("ip link set up dev R1-eth2") | |
180 | r1.run("ip link set up dev R1-eth3") | |
181 | r2.run("ip link set up dev R2-eth2") | |
182 | r2.run("ip link set up dev R2-eth3") | |
183 | r3.run("ip link set up dev R3-eth2") | |
184 | r3.run("ip link set up dev R3-eth3") | |
185 | ||
186 | # red vrf | |
187 | r1.run("ip link add red type vrf table 1002") | |
188 | r1.run("ip link set up dev red") | |
189 | r2.run("ip link add red type vrf table 1002") | |
190 | r2.run("ip link set up dev red") | |
191 | r3.run("ip link add red type vrf table 1002") | |
192 | r3.run("ip link set up dev red") | |
193 | ||
194 | r1.run("ip link add lo2 type dummy") | |
195 | r1.run("ip link set lo2 master red") | |
196 | r1.run("ip link set up dev lo2") | |
197 | r2.run("ip link add lo2 type dummy") | |
198 | r2.run("ip link set up dev lo2") | |
199 | r2.run("ip link set lo2 master red") | |
200 | r3.run("ip link add lo2 type dummy") | |
201 | r3.run("ip link set up dev lo2") | |
202 | r3.run("ip link set lo2 master red") | |
203 | ||
204 | r1.run("ip link set R1-eth4 master red") | |
205 | r1.run("ip link set R1-eth5 master red") | |
206 | r2.run("ip link set R2-eth4 master red") | |
207 | r2.run("ip link set R2-eth5 master red") | |
208 | r3.run("ip link set R3-eth4 master red") | |
209 | r3.run("ip link set R3-eth5 master red") | |
210 | ||
211 | r1.run("ip link set up dev R1-eth4") | |
212 | r1.run("ip link set up dev R1-eth5") | |
213 | r2.run("ip link set up dev R2-eth4") | |
214 | r2.run("ip link set up dev R2-eth5") | |
215 | r3.run("ip link set up dev R3-eth4") | |
216 | r3.run("ip link set up dev R3-eth5") | |
217 | ||
218 | # This is a sample of configuration loading. | |
219 | router_list = tgen.routers() | |
220 | ||
221 | # For all registred routers, load the zebra configuration file | |
e5f0ed14 | 222 | for rname, router in router_list.items(): |
318c1fa3 PR |
223 | router.load_config( |
224 | TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname)) | |
225 | ) | |
226 | router.load_config( | |
227 | TopoRouter.RD_OSPF, os.path.join(CWD, "{}/ospfd.conf".format(rname)) | |
228 | ) | |
229 | router.load_config( | |
230 | TopoRouter.RD_BGP, os.path.join(CWD, "{}/bgpd.conf".format(rname)) | |
231 | ) | |
232 | ||
233 | # After loading the configurations, this function loads configured daemons. | |
234 | tgen.start_router() | |
235 | ||
236 | ||
237 | def teardown_module(mod): | |
238 | "Teardown the pytest environment" | |
239 | tgen = get_topogen() | |
240 | ||
241 | # This function tears down the whole topology. | |
242 | tgen.stop_topology() | |
243 | ||
244 | ||
245 | def vrf_str(vrf): | |
246 | if vrf == "": | |
247 | vrf_str = "" | |
248 | else: | |
249 | vrf_str = "vrf {}".format(vrf) | |
250 | ||
251 | return vrf_str | |
252 | ||
253 | ||
254 | def peer_name(rtr, prefix, vrf): | |
255 | "generate VRF string for CLI" | |
256 | if vrf == "": | |
257 | vrf_str = "" | |
258 | else: | |
259 | vrf_str = "_" + vrf | |
260 | ||
261 | if prefix == "yes": | |
262 | if rtr == "R2": | |
263 | return "TWO_GROUP" + vrf_str | |
264 | else: | |
265 | return "THREE_GROUP" + vrf_str | |
266 | else: | |
267 | if rtr == "R2": | |
268 | return "2.2.2.2" | |
269 | else: | |
270 | return "3.3.3.3" | |
271 | ||
272 | ||
273 | def print_diag(vrf): | |
274 | "print failure disagnostics" | |
701a0192 | 275 | |
318c1fa3 PR |
276 | tgen = get_topogen() |
277 | router_list = tgen.routers() | |
e5f0ed14 | 278 | for rname, router in router_list.items(): |
318c1fa3 PR |
279 | print(rname + ":") |
280 | print(router.vtysh_cmd("show run")) | |
281 | print(router.vtysh_cmd("show ip route {}".format(vrf_str(vrf)))) | |
282 | print(router.vtysh_cmd("show bgp {} neighbor".format(vrf_str(vrf)))) | |
283 | ||
284 | ||
285 | def configure(conf_file): | |
286 | "configure from a file" | |
287 | ||
288 | tgen = get_topogen() | |
289 | router_list = tgen.routers() | |
e5f0ed14 | 290 | for rname, router in router_list.items(): |
318c1fa3 PR |
291 | with open( |
292 | os.path.join(CWD, "{}/{}").format(router.name, conf_file), "r+" | |
293 | ) as cfg: | |
294 | new_config = cfg.read() | |
295 | ||
296 | output = router.vtysh_multicmd(new_config, pretty_output=False) | |
297 | for out_err in ERROR_LIST: | |
298 | if out_err.lower() in output.lower(): | |
299 | raise InvalidCLIError("%s" % output) | |
300 | ||
301 | ||
b32454e1 IR |
302 | def clear_bgp(): |
303 | "clear bgp configuration for a vrf" | |
318c1fa3 PR |
304 | |
305 | tgen = get_topogen() | |
306 | r1 = tgen.gears["R1"] | |
307 | r2 = tgen.gears["R2"] | |
308 | r3 = tgen.gears["R3"] | |
309 | ||
b32454e1 IR |
310 | r1.vtysh_cmd("conf t\nno router bgp 65001") |
311 | r2.vtysh_cmd("conf t\nno router bgp 65002") | |
312 | r3.vtysh_cmd("conf t\nno router bgp 65003") | |
313 | r1.vtysh_cmd("conf t\nno router bgp 65001 vrf blue") | |
314 | r2.vtysh_cmd("conf t\nno router bgp 65002 vrf blue") | |
315 | r3.vtysh_cmd("conf t\nno router bgp 65003 vrf blue") | |
316 | r1.vtysh_cmd("conf t\nno router bgp 65001 vrf red") | |
317 | r2.vtysh_cmd("conf t\nno router bgp 65002 vrf red") | |
318 | r3.vtysh_cmd("conf t\nno router bgp 65003 vrf red") | |
319 | ||
318c1fa3 | 320 | |
b32454e1 IR |
321 | def configure_bgp(conf_file): |
322 | "configure bgp from file" | |
318c1fa3 | 323 | |
b32454e1 IR |
324 | clear_bgp() |
325 | configure(conf_file) | |
326 | ||
327 | ||
328 | def clear_ospf(): | |
318c1fa3 PR |
329 | "clear ospf configuration for a vrf" |
330 | ||
331 | tgen = get_topogen() | |
332 | router_list = tgen.routers() | |
e5f0ed14 | 333 | for rname, router in router_list.items(): |
b32454e1 IR |
334 | router.vtysh_cmd("conf t\nno router ospf") |
335 | router.vtysh_cmd("conf t\nno router ospf vrf blue") | |
336 | router.vtysh_cmd("conf t\nno router ospf vrf red") | |
337 | ||
338 | ||
339 | def configure_ospf(conf_file): | |
340 | "configure bgp from file" | |
341 | ||
342 | clear_ospf() | |
343 | configure(conf_file) | |
318c1fa3 PR |
344 | |
345 | ||
346 | def check_neigh_state(router, peer, state, vrf=""): | |
347 | "check BGP neighbor state on a router" | |
701a0192 | 348 | |
318c1fa3 PR |
349 | count = 0 |
350 | matched = False | |
351 | neigh_output = "" | |
352 | while count < 125: | |
353 | if vrf == "": | |
354 | neigh_output = router.vtysh_cmd("show bgp neighbors {} json".format(peer)) | |
355 | else: | |
356 | neigh_output = router.vtysh_cmd( | |
357 | "show bgp vrf {} neighbors {} json".format(vrf, peer) | |
358 | ) | |
359 | neigh_output_json = json.loads(neigh_output) | |
650e0d1b PR |
360 | if peer in neigh_output_json.keys(): |
361 | if neigh_output_json[peer]["bgpState"] == state: | |
362 | matched = True | |
363 | break | |
318c1fa3 PR |
364 | count += 1 |
365 | sleep(1) | |
366 | ||
367 | assertmsg = "{} could not peer {} state expected {} got {} ".format( | |
368 | router.name, peer, state, neigh_output_json[peer]["bgpState"] | |
369 | ) | |
370 | if matched != True: | |
371 | print_diag(vrf) | |
372 | assert matched == True, assertmsg | |
373 | ||
374 | ||
375 | def check_all_peers_established(vrf=""): | |
376 | "standard check for extablished peers per vrf" | |
377 | ||
378 | tgen = get_topogen() | |
379 | r1 = tgen.gears["R1"] | |
380 | r2 = tgen.gears["R2"] | |
381 | r3 = tgen.gears["R3"] | |
382 | # do r1 last as he might be the dynamic one | |
383 | check_neigh_state(r2, "1.1.1.1", "Established", vrf) | |
384 | check_neigh_state(r2, "3.3.3.3", "Established", vrf) | |
385 | check_neigh_state(r3, "1.1.1.1", "Established", vrf) | |
386 | check_neigh_state(r3, "2.2.2.2", "Established", vrf) | |
387 | check_neigh_state(r1, "2.2.2.2", "Established", vrf) | |
388 | check_neigh_state(r1, "3.3.3.3", "Established", vrf) | |
389 | ||
390 | ||
391 | def check_vrf_peer_remove_passwords(vrf="", prefix="no"): | |
392 | "selectively remove passwords checking state" | |
393 | ||
394 | tgen = get_topogen() | |
395 | r1 = tgen.gears["R1"] | |
396 | r2 = tgen.gears["R2"] | |
397 | r3 = tgen.gears["R3"] | |
398 | ||
b32454e1 IR |
399 | check_all_peers_established(vrf) |
400 | ||
318c1fa3 PR |
401 | r1.vtysh_cmd( |
402 | "conf t\nrouter bgp 65001 {}\nno neighbor {} password".format( | |
403 | vrf_str(vrf), peer_name("R2", prefix, vrf) | |
404 | ) | |
405 | ) | |
406 | ||
407 | check_neigh_state(r2, "1.1.1.1", "Connect", vrf) | |
408 | check_neigh_state(r2, "3.3.3.3", "Established", vrf) | |
409 | check_neigh_state(r3, "1.1.1.1", "Established", vrf) | |
410 | check_neigh_state(r3, "2.2.2.2", "Established", vrf) | |
411 | # don't check dynamic downed peers - they are removed | |
412 | if prefix == "no": | |
413 | check_neigh_state(r1, "2.2.2.2", "Connect", vrf) | |
414 | check_neigh_state(r1, "3.3.3.3", "Established", vrf) | |
415 | ||
416 | r2.vtysh_cmd( | |
417 | "conf t\nrouter bgp 65002 {}\nno neighbor 1.1.1.1 password".format(vrf_str(vrf)) | |
418 | ) | |
419 | check_all_peers_established(vrf) | |
420 | ||
421 | r1.vtysh_cmd( | |
422 | "conf t\nrouter bgp 65001 {}\nno neighbor {} password".format( | |
423 | vrf_str(vrf), peer_name("R3", prefix, vrf) | |
424 | ) | |
425 | ) | |
426 | check_neigh_state(r2, "1.1.1.1", "Established", vrf) | |
427 | check_neigh_state(r2, "3.3.3.3", "Established", vrf) | |
428 | check_neigh_state(r3, "1.1.1.1", "Connect", vrf) | |
429 | check_neigh_state(r3, "2.2.2.2", "Established", vrf) | |
430 | check_neigh_state(r1, "2.2.2.2", "Established", vrf) | |
431 | # don't check dynamic downed peers - they are removed | |
432 | if prefix == "no": | |
433 | check_neigh_state(r1, "3.3.3.3", "Connect", vrf) | |
434 | ||
435 | r3.vtysh_cmd( | |
436 | "conf t\nrouter bgp 65003 {}\nno neighbor 1.1.1.1 password".format(vrf_str(vrf)) | |
437 | ) | |
438 | check_all_peers_established(vrf) | |
439 | ||
440 | r2.vtysh_cmd( | |
441 | "conf t\nrouter bgp 65002 {}\nno neighbor 3.3.3.3 password".format(vrf_str(vrf)) | |
442 | ) | |
443 | check_neigh_state(r2, "1.1.1.1", "Established", vrf) | |
444 | check_neigh_state(r2, "3.3.3.3", "Connect", vrf) | |
445 | check_neigh_state(r3, "1.1.1.1", "Established", vrf) | |
446 | check_neigh_state(r3, "2.2.2.2", "Connect", vrf) | |
447 | check_neigh_state(r1, "2.2.2.2", "Established", vrf) | |
448 | check_neigh_state(r1, "3.3.3.3", "Established", vrf) | |
449 | ||
450 | r3.vtysh_cmd( | |
451 | "conf t\nrouter bgp 65003 {}\nno neighbor 2.2.2.2 password".format(vrf_str(vrf)) | |
452 | ) | |
453 | check_all_peers_established(vrf) | |
454 | ||
455 | ||
456 | def check_vrf_peer_change_passwords(vrf="", prefix="no"): | |
457 | "selectively change passwords checking state" | |
458 | ||
459 | tgen = get_topogen() | |
460 | r1 = tgen.gears["R1"] | |
461 | r2 = tgen.gears["R2"] | |
462 | r3 = tgen.gears["R3"] | |
463 | check_all_peers_established(vrf) | |
464 | ||
465 | r1.vtysh_cmd( | |
466 | "conf t\nrouter bgp 65001 {}\nneighbor {} password change1".format( | |
467 | vrf_str(vrf), peer_name("R2", prefix, vrf) | |
468 | ) | |
469 | ) | |
470 | check_neigh_state(r2, "1.1.1.1", "Connect", vrf) | |
471 | check_neigh_state(r2, "3.3.3.3", "Established", vrf) | |
472 | check_neigh_state(r3, "1.1.1.1", "Established", vrf) | |
473 | check_neigh_state(r3, "2.2.2.2", "Established", vrf) | |
474 | # don't check dynamic downed peers - they are removed | |
475 | if prefix == "no": | |
476 | check_neigh_state(r1, "2.2.2.2", "Connect", vrf) | |
477 | check_neigh_state(r1, "3.3.3.3", "Established", vrf) | |
478 | ||
479 | r2.vtysh_cmd( | |
480 | "conf t\nrouter bgp 65002 {}\nneighbor 1.1.1.1 password change1".format( | |
481 | vrf_str(vrf) | |
482 | ) | |
483 | ) | |
484 | check_all_peers_established(vrf) | |
485 | ||
486 | r1.vtysh_cmd( | |
487 | "conf t\nrouter bgp 65001 {}\nneighbor {} password change2".format( | |
488 | vrf_str(vrf), peer_name("R3", prefix, vrf) | |
489 | ) | |
490 | ) | |
491 | check_neigh_state(r2, "1.1.1.1", "Established", vrf) | |
492 | check_neigh_state(r2, "3.3.3.3", "Established", vrf) | |
493 | check_neigh_state(r3, "1.1.1.1", "Connect", vrf) | |
494 | check_neigh_state(r3, "2.2.2.2", "Established", vrf) | |
495 | check_neigh_state(r1, "2.2.2.2", "Established", vrf) | |
496 | # don't check dynamic downed peers - they are removed | |
497 | if prefix == "no": | |
498 | check_neigh_state(r1, "3.3.3.3", "Connect", vrf) | |
499 | ||
500 | r3.vtysh_cmd( | |
501 | "conf t\nrouter bgp 65003 {}\nneighbor 1.1.1.1 password change2".format( | |
502 | vrf_str(vrf) | |
503 | ) | |
504 | ) | |
505 | check_all_peers_established(vrf) | |
506 | ||
507 | r2.vtysh_cmd( | |
508 | "conf t\nrouter bgp 65002 {}\nneighbor 3.3.3.3 password change3".format( | |
509 | vrf_str(vrf) | |
510 | ) | |
511 | ) | |
512 | check_neigh_state(r2, "1.1.1.1", "Established", vrf) | |
513 | check_neigh_state(r2, "3.3.3.3", "Connect", vrf) | |
514 | check_neigh_state(r3, "1.1.1.1", "Established", vrf) | |
515 | check_neigh_state(r3, "2.2.2.2", "Connect", vrf) | |
516 | check_neigh_state(r1, "2.2.2.2", "Established", vrf) | |
517 | check_neigh_state(r1, "3.3.3.3", "Established", vrf) | |
518 | ||
519 | r3.vtysh_cmd( | |
520 | "conf t\nrouter bgp 65003 {}\nneighbor 2.2.2.2 password change3".format( | |
521 | vrf_str(vrf) | |
522 | ) | |
523 | ) | |
524 | check_all_peers_established(vrf) | |
525 | ||
526 | ||
527 | def test_default_peer_established(): | |
528 | "default vrf 3 peers same password" | |
529 | ||
b32454e1 IR |
530 | configure_bgp("bgpd.conf") |
531 | configure_ospf("ospfd.conf") | |
318c1fa3 | 532 | check_all_peers_established() |
318c1fa3 PR |
533 | # tgen.mininet_cli() |
534 | ||
535 | ||
536 | def test_default_peer_remove_passwords(): | |
537 | "selectively remove passwords checking state" | |
538 | ||
b32454e1 IR |
539 | configure_bgp("bgpd.conf") |
540 | configure_ospf("ospfd.conf") | |
318c1fa3 | 541 | check_vrf_peer_remove_passwords() |
318c1fa3 PR |
542 | |
543 | ||
544 | def test_default_peer_change_passwords(): | |
545 | "selectively change passwords checking state" | |
546 | ||
b32454e1 IR |
547 | configure_bgp("bgpd.conf") |
548 | configure_ospf("ospfd.conf") | |
318c1fa3 | 549 | check_vrf_peer_change_passwords() |
318c1fa3 PR |
550 | |
551 | ||
552 | def test_default_prefix_peer_established(): | |
553 | "default vrf 3 peers same password with prefix config" | |
554 | ||
555 | # only supported in kernel > 5.3 | |
556 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
557 | return | |
558 | ||
b32454e1 IR |
559 | configure_bgp("bgpd_prefix.conf") |
560 | configure_ospf("ospfd.conf") | |
318c1fa3 | 561 | check_all_peers_established() |
318c1fa3 PR |
562 | # tgen.mininet_cli() |
563 | ||
564 | ||
565 | def test_prefix_peer_remove_passwords(): | |
566 | "selectively remove passwords checking state with prefix config" | |
567 | ||
568 | # only supported in kernel > 5.3 | |
569 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
570 | return | |
b32454e1 IR |
571 | |
572 | configure_bgp("bgpd_prefix.conf") | |
573 | configure_ospf("ospfd.conf") | |
318c1fa3 | 574 | check_vrf_peer_remove_passwords(prefix="yes") |
318c1fa3 PR |
575 | |
576 | ||
577 | def test_prefix_peer_change_passwords(): | |
578 | "selecively change passwords checkig state with prefix config" | |
579 | ||
580 | # only supported in kernel > 5.3 | |
581 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
582 | return | |
b32454e1 IR |
583 | |
584 | configure_bgp("bgpd_prefix.conf") | |
585 | configure_ospf("ospfd.conf") | |
318c1fa3 | 586 | check_vrf_peer_change_passwords(prefix="yes") |
318c1fa3 PR |
587 | |
588 | ||
589 | def test_vrf_peer_established(): | |
590 | "default vrf 3 peers same password with VRF config" | |
591 | ||
592 | # clean routers and load vrf config | |
b32454e1 IR |
593 | configure_bgp("bgpd_vrf.conf") |
594 | configure_ospf("ospfd_vrf.conf") | |
318c1fa3 | 595 | check_all_peers_established("blue") |
318c1fa3 PR |
596 | # tgen.mininet_cli() |
597 | ||
598 | ||
599 | def test_vrf_peer_remove_passwords(): | |
600 | "selectively remove passwords checking state with VRF config" | |
601 | ||
b32454e1 IR |
602 | configure_bgp("bgpd_vrf.conf") |
603 | configure_ospf("ospfd_vrf.conf") | |
318c1fa3 | 604 | check_vrf_peer_remove_passwords(vrf="blue") |
318c1fa3 PR |
605 | |
606 | ||
607 | def test_vrf_peer_change_passwords(): | |
608 | "selectively change passwords checking state with VRF config" | |
609 | ||
b32454e1 IR |
610 | configure_bgp("bgpd_vrf.conf") |
611 | configure_ospf("ospfd_vrf.conf") | |
318c1fa3 | 612 | check_vrf_peer_change_passwords(vrf="blue") |
318c1fa3 PR |
613 | |
614 | ||
615 | def test_vrf_prefix_peer_established(): | |
616 | "default vrf 3 peers same password with VRF prefix config" | |
617 | ||
618 | # only supported in kernel > 5.3 | |
619 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
318c1fa3 PR |
620 | return |
621 | ||
b32454e1 IR |
622 | configure_bgp("bgpd_vrf_prefix.conf") |
623 | configure_ospf("ospfd_vrf.conf") | |
318c1fa3 | 624 | check_all_peers_established("blue") |
318c1fa3 PR |
625 | |
626 | ||
627 | def test_vrf_prefix_peer_remove_passwords(): | |
628 | "selectively remove passwords checking state with VRF prefix config" | |
629 | ||
630 | # only supported in kernel > 5.3 | |
631 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
632 | return | |
633 | ||
b32454e1 IR |
634 | configure_bgp("bgpd_vrf_prefix.conf") |
635 | configure_ospf("ospfd_vrf.conf") | |
318c1fa3 | 636 | check_vrf_peer_remove_passwords(vrf="blue", prefix="yes") |
318c1fa3 PR |
637 | |
638 | ||
639 | def test_vrf_prefix_peer_change_passwords(): | |
640 | "selectively change passwords checking state with VRF prefix config" | |
641 | ||
318c1fa3 PR |
642 | # only supported in kernel > 5.3 |
643 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
318c1fa3 PR |
644 | return |
645 | ||
b32454e1 IR |
646 | configure_bgp("bgpd_vrf_prefix.conf") |
647 | configure_ospf("ospfd_vrf.conf") | |
318c1fa3 | 648 | check_vrf_peer_change_passwords(vrf="blue", prefix="yes") |
318c1fa3 PR |
649 | |
650 | ||
651 | def test_multiple_vrf_peer_established(): | |
652 | "default vrf 3 peers same password with multiple VRFs" | |
653 | ||
b32454e1 IR |
654 | configure_bgp("bgpd_multi_vrf.conf") |
655 | configure_ospf("ospfd_multi_vrf.conf") | |
318c1fa3 PR |
656 | check_all_peers_established("blue") |
657 | check_all_peers_established("red") | |
318c1fa3 PR |
658 | # tgen.mininet_cli() |
659 | ||
660 | ||
661 | def test_multiple_vrf_peer_remove_passwords(): | |
662 | "selectively remove passwords checking state with multiple VRFs" | |
663 | ||
b32454e1 IR |
664 | configure_bgp("bgpd_multi_vrf.conf") |
665 | configure_ospf("ospfd_multi_vrf.conf") | |
318c1fa3 PR |
666 | check_vrf_peer_remove_passwords("blue") |
667 | check_all_peers_established("red") | |
668 | check_vrf_peer_remove_passwords("red") | |
669 | check_all_peers_established("blue") | |
318c1fa3 PR |
670 | # tgen.mininet_cli() |
671 | ||
672 | ||
673 | def test_multiple_vrf_peer_change_passwords(): | |
674 | "selectively change passwords checking state with multiple VRFs" | |
675 | ||
b32454e1 IR |
676 | configure_bgp("bgpd_multi_vrf.conf") |
677 | configure_ospf("ospfd_multi_vrf.conf") | |
318c1fa3 PR |
678 | check_vrf_peer_change_passwords("blue") |
679 | check_all_peers_established("red") | |
680 | check_vrf_peer_change_passwords("red") | |
681 | check_all_peers_established("blue") | |
318c1fa3 PR |
682 | # tgen.mininet_cli() |
683 | ||
684 | ||
685 | def test_multiple_vrf_prefix_peer_established(): | |
686 | "default vrf 3 peers same password with multilpe VRFs and prefix config" | |
687 | ||
688 | # only supported in kernel > 5.3 | |
689 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
690 | return | |
691 | ||
b32454e1 IR |
692 | configure_bgp("bgpd_multi_vrf_prefix.conf") |
693 | configure_ospf("ospfd_multi_vrf.conf") | |
318c1fa3 PR |
694 | check_all_peers_established("blue") |
695 | check_all_peers_established("red") | |
318c1fa3 PR |
696 | # tgen.mininet_cli() |
697 | ||
698 | ||
699 | def test_multiple_vrf_prefix_peer_remove_passwords(): | |
700 | "selectively remove passwords checking state with multiple vrfs and prefix config" | |
701 | ||
702 | # only supported in kernel > 5.3 | |
703 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
704 | return | |
705 | ||
b32454e1 IR |
706 | configure_bgp("bgpd_multi_vrf_prefix.conf") |
707 | configure_ospf("ospfd_multi_vrf.conf") | |
318c1fa3 PR |
708 | check_vrf_peer_remove_passwords(vrf="blue", prefix="yes") |
709 | check_all_peers_established("red") | |
710 | check_vrf_peer_remove_passwords(vrf="red", prefix="yes") | |
711 | check_all_peers_established("blue") | |
318c1fa3 PR |
712 | # tgen.mininet_cli() |
713 | ||
714 | ||
715 | def test_multiple_vrf_prefix_peer_change_passwords(): | |
716 | "selectively change passwords checking state with multiple vrfs and prefix config" | |
717 | ||
718 | # only supported in kernel > 5.3 | |
719 | if topotest.version_cmp(platform.release(), "5.3") < 0: | |
318c1fa3 PR |
720 | return |
721 | ||
b32454e1 IR |
722 | configure_bgp("bgpd_multi_vrf_prefix.conf") |
723 | configure_ospf("ospfd_multi_vrf.conf") | |
318c1fa3 PR |
724 | check_vrf_peer_change_passwords(vrf="blue", prefix="yes") |
725 | check_all_peers_established("red") | |
726 | check_vrf_peer_change_passwords(vrf="red", prefix="yes") | |
727 | check_all_peers_established("blue") | |
318c1fa3 PR |
728 | # tgen.mininet_cli() |
729 | ||
730 | ||
731 | def test_memory_leak(): | |
732 | "Run the memory leak test and report results." | |
733 | tgen = get_topogen() | |
734 | if not tgen.is_memleak_enabled(): | |
735 | pytest.skip("Memory leak test/report is disabled") | |
736 | ||
737 | tgen.report_memory_leaks() | |
738 | ||
739 | ||
740 | if __name__ == "__main__": | |
741 | args = ["-s"] + sys.argv[1:] | |
742 | sys.exit(pytest.main(args)) |